@veltdev/sdk 4.5.6-beta.1 → 4.5.6-beta.2
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/package.json +1 -1
- package/velt.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veltdev/sdk",
|
|
3
|
-
"version": "4.5.6-beta.
|
|
3
|
+
"version": "4.5.6-beta.2",
|
|
4
4
|
"description": "Velt is an SDK to add collaborative features to your product within minutes. Example: Comments like Figma, Frame.io, Google docs or sheets, Recording like Loom, Huddles like Slack and much more.",
|
|
5
5
|
"homepage": "https://velt.dev",
|
|
6
6
|
"keywords": [
|
package/velt.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var SNIPPYLY_VERSION = '4.5.6-beta.
|
|
1
|
+
var SNIPPYLY_VERSION = '4.5.6-beta.2';
|
|
2
2
|
(function(m,w){"use strict";function rt(){var e=K.splice(0,K.length);for(ie=0;e.length;)e.shift().call(null,e.shift())}function me(e,t){for(var n=0,r=e.length;n<r;n++)Te(e[n],t)}function ot(e){for(var t,n=0,r=e.length;n<r;n++)t=e[n],U(t,q[pe(t)])}function fe(e){return function(t){Lt(t)&&(Te(t,e),L.length&&me(t.querySelectorAll(L),e))}}function pe(e){var t=le.call(e,"is"),n=e.nodeName.toUpperCase(),r=v.call(D,t?Y+t.toUpperCase():x+n);return t&&-1<r&&!De(n,t)?-1:r}function De(e,t){return-1<L.indexOf(e+'[is="'+t+'"]')}function Ie(e){var t=e.currentTarget,n=e.attrChange,r=e.attrName,o=e.target,l=e[W]||2,a=e[He]||3;!ce||o&&o!==t||!t[y]||r==="style"||e.prevValue===e.newValue&&(e.newValue!==""||n!==l&&n!==a)||t[y](r,n===l?null:e.prevValue,n===a?null:e.newValue)}function Fe(e){var t=fe(e);return function(n){K.push(t,n.target),ie&&clearTimeout(ie),ie=setTimeout(rt,1)}}function de(e){nt&&(nt=!1,e.currentTarget.removeEventListener(Ze,de)),L.length&&me((e.target||u).querySelectorAll(L),e.detail===E?E:b),R&&at()}function lt(e,t){var n=this;Ye.call(n,e,t),Me.call(n,{target:n})}function Se(e,t,n){var r=t.apply(e,n),o=pe(r);return-1<o&&U(r,q[o]),n.pop()&&L.length&&ot(r.querySelectorAll(L)),r}function he(e,t){Tt(e,t),$?$.observe(e,gt):(ue&&(e.setAttribute=lt,e[H]=Ee(e),e[g](st,Me)),e[g](N,Ie)),e[k]&&ce&&(e.created=!0,e[k](),e.created=!1)}function at(){for(var e,t=0,n=G.length;t<n;t++)e=G[t],V.contains(e)||(n--,G.splice(t--,1),Te(e,E))}function Ve(e){throw new Error("A "+e+" type is already registered")}function Te(e,t){var n,r,o=pe(e);-1<o&&!Mt.call(e,"TEMPLATE")&&(Q(e,q[o]),o=0,t!==b||e[b]?t!==E||e[E]||(e[b]=!1,e[E]=!0,r="disconnected",o=1):(e[E]=!1,e[b]=!0,r="connected",o=1,R&&v.call(G,e)<0&&G.push(e)),o&&(n=e[t+O]||e[r+O])&&n.call(e))}function z(){}function Pe(e,t,n){var r=n&&n[_]||"",o=t.prototype,l=Ce(o),a=t.observedAttributes||ye,s={prototype:l};oe(l,k,{value:function(){if(te)te=!1;else if(!this[B]){this[B]=!0,new t(this),o[k]&&o[k].call(this);var i=j[ne.get(t)];(!Z||i.create.length>1)&&_e(this)}}}),oe(l,y,{value:function(i){-1<v.call(a,i)&&o[y]&&o[y].apply(this,arguments)}}),o[qe]&&oe(l,ut,{value:o[qe]}),o[Be]&&oe(l,ct,{value:o[Be]}),r&&(s[_]=r),e=e.toUpperCase(),j[e]={constructor:t,create:r?[r,re(e)]:[e]},ne.set(t,e),u[S](e.toLowerCase(),s),Le(e),P[e].r()}function Re(e){var t=j[e.toUpperCase()];return t&&t.constructor}function Ue(e){return typeof e=="string"?e:e&&e.is||""}function _e(e){for(var t,n=e[y],r=n?e.attributes:ye,o=r.length;o--;)t=r[o],n.call(e,t.name||t.nodeName,null,t.value||t.nodeValue)}function Le(e){return e=e.toUpperCase(),e in P||(P[e]={},P[e].p=new Xe(function(t){P[e].r=t})),P[e].p}function ke(){C&&delete m.customElements,I(m,"customElements",{configurable:!0,value:new z}),I(m,"CustomElementRegistry",{configurable:!0,value:z});for(var e=it.get(/^HTML[A-Z]*[a-z]/),t=e.length;t--;function(n){var r=m[n];if(r){m[n]=function(o){var l,a;return o||(o=this),o[B]||(te=!0,l=j[ne.get(o.constructor)],a=Z&&l.create.length===1,o=a?Reflect.construct(r,ye,l.constructor):u.createElement.apply(u,l.create),o[B]=!0,te=!1,a||_e(o)),o},m[n].prototype=r.prototype;try{r.prototype.constructor=m[n]}catch{dt=!0,I(r,B,{value:m[n]})}}}(e[t]));u.createElement=function(n,r){var o=Ue(r);return o?Ae.call(this,n,re(o)):Ae.call(this,n)},et||(Oe=!0,u[S](""))}var u=m.document,T=m.Object,it=function(e){var t,n,r,o,l=/^[A-Z]+[a-z]/,a=function(p){var f,h=[];for(f in i)p.test(f)&&h.push(f);return h},s=function(p,f){(f=f.toLowerCase())in i||(i[p]=(i[p]||[]).concat(f),i[f]=i[f.toUpperCase()]=p)},i=(T.create||T)(null),c={};for(n in e)for(o in e[n])for(r=e[n][o],i[o]=r,t=0;t<r.length;t++)i[r[t].toLowerCase()]=i[r[t].toUpperCase()]=o;return c.get=function(p){return typeof p=="string"?i[p]||(l.test(p)?[]:""):a(p)},c.set=function(p,f){return l.test(p)?s(p,f):s(f,p),c},c}({collections:{HTMLAllCollection:["all"],HTMLCollection:["forms"],HTMLFormControlsCollection:["elements"],HTMLOptionsCollection:["options"]},elements:{Element:["element"],HTMLAnchorElement:["a"],HTMLAppletElement:["applet"],HTMLAreaElement:["area"],HTMLAttachmentElement:["attachment"],HTMLAudioElement:["audio"],HTMLBRElement:["br"],HTMLBaseElement:["base"],HTMLBodyElement:["body"],HTMLButtonElement:["button"],HTMLCanvasElement:["canvas"],HTMLContentElement:["content"],HTMLDListElement:["dl"],HTMLDataElement:["data"],HTMLDataListElement:["datalist"],HTMLDetailsElement:["details"],HTMLDialogElement:["dialog"],HTMLDirectoryElement:["dir"],HTMLDivElement:["div"],HTMLDocument:["document"],HTMLElement:["element","abbr","address","article","aside","b","bdi","bdo","cite","code","command","dd","dfn","dt","em","figcaption","figure","footer","header","i","kbd","mark","nav","noscript","rp","rt","ruby","s","samp","section","small","strong","sub","summary","sup","u","var","wbr"],HTMLEmbedElement:["embed"],HTMLFieldSetElement:["fieldset"],HTMLFontElement:["font"],HTMLFormElement:["form"],HTMLFrameElement:["frame"],HTMLFrameSetElement:["frameset"],HTMLHRElement:["hr"],HTMLHeadElement:["head"],HTMLHeadingElement:["h1","h2","h3","h4","h5","h6"],HTMLHtmlElement:["html"],HTMLIFrameElement:["iframe"],HTMLImageElement:["img"],HTMLInputElement:["input"],HTMLKeygenElement:["keygen"],HTMLLIElement:["li"],HTMLLabelElement:["label"],HTMLLegendElement:["legend"],HTMLLinkElement:["link"],HTMLMapElement:["map"],HTMLMarqueeElement:["marquee"],HTMLMediaElement:["media"],HTMLMenuElement:["menu"],HTMLMenuItemElement:["menuitem"],HTMLMetaElement:["meta"],HTMLMeterElement:["meter"],HTMLModElement:["del","ins"],HTMLOListElement:["ol"],HTMLObjectElement:["object"],HTMLOptGroupElement:["optgroup"],HTMLOptionElement:["option"],HTMLOutputElement:["output"],HTMLParagraphElement:["p"],HTMLParamElement:["param"],HTMLPictureElement:["picture"],HTMLPreElement:["pre"],HTMLProgressElement:["progress"],HTMLQuoteElement:["blockquote","q","quote"],HTMLScriptElement:["script"],HTMLSelectElement:["select"],HTMLShadowElement:["shadow"],HTMLSlotElement:["slot"],HTMLSourceElement:["source"],HTMLSpanElement:["span"],HTMLStyleElement:["style"],HTMLTableCaptionElement:["caption"],HTMLTableCellElement:["td","th"],HTMLTableColElement:["col","colgroup"],HTMLTableElement:["table"],HTMLTableRowElement:["tr"],HTMLTableSectionElement:["thead","tbody","tfoot"],HTMLTemplateElement:["template"],HTMLTextAreaElement:["textarea"],HTMLTimeElement:["time"],HTMLTitleElement:["title"],HTMLTrackElement:["track"],HTMLUListElement:["ul"],HTMLUnknownElement:["unknown","vhgroupv","vkeygen"],HTMLVideoElement:["video"]},nodes:{Attr:["node"],Audio:["audio"],CDATASection:["node"],CharacterData:["node"],Comment:["#comment"],Document:["#document"],DocumentFragment:["#document-fragment"],DocumentType:["node"],HTMLDocument:["#document"],Image:["img"],Option:["option"],ProcessingInstruction:["node"],ShadowRoot:["#shadow-root"],Text:["#text"],XMLDocument:["xml"]}});typeof w!="object"&&(w={type:w||"auto"});var K,Me,X,Ee,$,ve,Q,U,A,S="registerElement",xe=1e5*m.Math.random()>>0,H="__"+S+xe,g="addEventListener",b="attached",O="Callback",E="detached",_="extends",y="attributeChanged"+O,ut=b+O,qe="connected"+O,Be="disconnected"+O,k="created"+O,ct=E+O,W="ADDITION",He="REMOVAL",N="DOMAttrModified",Ze="DOMContentLoaded",st="DOMSubtreeModified",x="<",Y="=",mt=/^[A-Z][._A-Z0-9]*-[-._A-Z0-9]*$/,ft=["ANNOTATION-XML","COLOR-PROFILE","FONT-FACE","FONT-FACE-SRC","FONT-FACE-URI","FONT-FACE-FORMAT","FONT-FACE-NAME","MISSING-GLYPH"],D=[],q=[],L="",V=u.documentElement,v=D.indexOf||function(e){for(var t=this.length;t--&&this[t]!==e;);return t},ge=T.prototype,be=ge.hasOwnProperty,J=ge.isPrototypeOf,I=T.defineProperty,ye=[],ee=T.getOwnPropertyDescriptor,je=T.getOwnPropertyNames,pt=T.getPrototypeOf,Ge=T.setPrototypeOf,ze=!!T.__proto__,dt=!1,B="__dreCEv1",C=m.customElements,Z=!/^force/.test(w.type)&&!!(C&&C.define&&C.get&&C.whenDefined),Ke=T.create||T,ht=m.Map||function(){var e,t=[],n=[];return{get:function(r){return n[v.call(t,r)]},set:function(r,o){e=v.call(t,r),e<0?n[t.push(r)-1]=o:n[e]=o}}},Xe=m.Promise||function(e){function t(l){for(r=!0;n.length;)n.shift()(l)}var n=[],r=!1,o={catch:function(){return o},then:function(l){return n.push(l),r&&setTimeout(t,1),o}};return e(t),o},te=!1,j=Ke(null),P=Ke(null),ne=new ht,re=function(e){return e.toLowerCase()},Ce=T.create||function e(t){return t?(e.prototype=t,new e):this},Tt=Ge||(ze?function(e,t){return e.__proto__=t,e}:je&&ee?function(){function e(t,n){for(var r,o=je(n),l=0,a=o.length;l<a;l++)r=o[l],be.call(t,r)||I(t,r,ee(n,r))}return function(t,n){do e(t,n);while((n=pt(n))&&!J.call(n,t));return t}}():function(e,t){for(var n in t)e[n]=t[n];return e}),F=m.MutationObserver||m.WebKitMutationObserver,$e=m.HTMLAnchorElement,d=(m.HTMLElement||m.Element||m.Node).prototype,R=!J.call(d,V),oe=R?function(e,t,n){return e[t]=n.value,e}:I,Lt=R?function(e){return e.nodeType===1}:function(e){return J.call(d,e)},G=R&&[],Qe=d.attachShadow,We=d.cloneNode,Mt=d.closest||function(e){for(var t=this;t&&t.nodeName!==e;)t=t.parentNode;return t},we=d.dispatchEvent,le=d.getAttribute,Et=d.hasAttribute,vt=d.removeAttribute,Ye=d.setAttribute,ae=u.createElement,Ht=u.importNode,Ae=ae,gt=F&&{attributes:!0,characterData:!0,attributeOldValue:!0},Je=F||function(e){ue=!1,V.removeEventListener(N,Je)},ie=0,et=S in u&&!/^force-all/.test(w.type),tt=!0,Oe=!1,ue=!0,nt=!0,ce=!0;if(F&&(A=u.createElement("div"),A.innerHTML="<div><div></div></div>",new F(function(e,t){if(e[0]&&e[0].type=="childList"&&!e[0].removedNodes[0].childNodes.length){A=ee(d,"innerHTML");var n=A&&A.set;n&&I(d,"innerHTML",{set:function(r){for(;this.lastChild;)this.removeChild(this.lastChild);n.call(this,r)}})}t.disconnect(),A=null}).observe(A,{childList:!0,subtree:!0}),A.innerHTML=""),et||(Ge||ze?(Q=function(e,t){J.call(t,e)||he(e,t)},U=he):(Q=function(e,t){e[H]||(e[H]=T(!0),he(e,t))},U=Q),R?(ue=!1,function(){var e=ee(d,g),t=e.value,n=function(l){var a=new CustomEvent(N,{bubbles:!0});a.attrName=l,a.prevValue=le.call(this,l),a.newValue=null,a[He]=a.attrChange=2,vt.call(this,l),we.call(this,a)},r=function(l,a){var s=Et.call(this,l),i=s&&le.call(this,l),c=new CustomEvent(N,{bubbles:!0});Ye.call(this,l,a),c.attrName=l,c.prevValue=s?i:null,c.newValue=a,s?c.MODIFICATION=c.attrChange=1:c[W]=c.attrChange=0,we.call(this,c)},o=function(l){var a,s=l.currentTarget,i=s[H],c=l.propertyName;i.hasOwnProperty(c)&&(i=i[c],a=new CustomEvent(N,{bubbles:!0}),a.attrName=i.name,a.prevValue=i.value||null,a.newValue=i.value=s[c]||null,a.prevValue==null?a[W]=a.attrChange=0:a.MODIFICATION=a.attrChange=1,we.call(s,a))};e.value=function(l,a,s){l===N&&this[y]&&this.setAttribute!==r&&(this[H]={className:{name:"class",value:this.className}},this.setAttribute=r,this.removeAttribute=n,t.call(this,"propertychange",o)),t.call(this,l,a,s)},I(d,g,e)}()):F||(V[g](N,Je),V.setAttribute(H,1),V.removeAttribute(H),ue&&(Me=function(e){var t,n,r,o=this;if(o===e.target){t=o[H],o[H]=n=Ee(o);for(r in n){if(!(r in t))return X(0,o,r,t[r],n[r],W);if(n[r]!==t[r])return X(1,o,r,t[r],n[r],"MODIFICATION")}for(r in t)if(!(r in n))return X(2,o,r,t[r],n[r],He)}},X=function(e,t,n,r,o,l){var a={attrChange:e,currentTarget:t,attrName:n,prevValue:r,newValue:o};a[l]=e,Ie(a)},Ee=function(e){for(var t,n,r={},o=e.attributes,l=0,a=o.length;l<a;l++)t=o[l],(n=t.name)!=="setAttribute"&&(r[n]=t.value);return r})),u[S]=function(e,t){if(n=e.toUpperCase(),tt&&(tt=!1,F?($=function(i,c){function p(f,h){for(var M=0,se=f.length;M<se;h(f[M++]));}return new F(function(f){for(var h,M,se,Ne=0,bt=f.length;Ne<bt;Ne++)h=f[Ne],h.type==="childList"?(p(h.addedNodes,i),p(h.removedNodes,c)):(M=h.target,ce&&M[y]&&h.attributeName!=="style"&&(se=le.call(M,h.attributeName))!==h.oldValue&&M[y](h.attributeName,h.oldValue,se))})}(fe(b),fe(E)),ve=function(i){return $.observe(i,{childList:!0,subtree:!0}),i},ve(u),Qe&&(d.attachShadow=function(){return ve(Qe.apply(this,arguments))})):(K=[],u[g]("DOMNodeInserted",Fe(b)),u[g]("DOMNodeRemoved",Fe(E))),u[g](Ze,de),u[g]("readystatechange",de),u.importNode=function(i,c){switch(i.nodeType){case 1:return Se(u,Ht,[i,!!c]);case 11:for(var p=u.createDocumentFragment(),f=i.childNodes,h=f.length,M=0;M<h;M++)p.appendChild(u.importNode(f[M],!!c));return p;default:return We.call(i,!!c)}},d.cloneNode=function(i){return Se(this,We,[!!i])}),Oe)return Oe=!1;if(-2<v.call(D,Y+n)+v.call(D,x+n)&&Ve(e),!mt.test(n)||-1<v.call(ft,n))throw new Error("The type "+e+" is invalid");var n,r,o=function(){return a?u.createElement(s,n):u.createElement(s)},l=t||ge,a=be.call(l,_),s=a?t[_].toUpperCase():n;return a&&-1<v.call(D,x+s)&&Ve(s),r=D.push((a?Y:x)+n)-1,L=L.concat(L.length?",":"",a?s+'[is="'+e.toLowerCase()+'"]':s),o.prototype=q[r]=be.call(l,"prototype")?l.prototype:Ce(d),L.length&&me(u.querySelectorAll(L),b),o},u.createElement=Ae=function(e,t){var n=Ue(t),r=n?ae.call(u,e,re(n)):ae.call(u,e),o=""+e,l=v.call(D,(n?Y:x)+(n||o).toUpperCase()),a=-1<l;return n&&(r.setAttribute("is",n=n.toLowerCase()),a&&(a=De(o.toUpperCase(),n))),ce=!u.createElement.innerHTMLHelper,a&&U(r,q[l]),r}),addEventListener("beforeunload",function(){delete u.createElement,delete u.importNode,delete u[S]},!1),z.prototype={constructor:z,define:Z?function(e,t,n){if(n)Pe(e,t,n);else{var r=e.toUpperCase();j[r]={constructor:t,create:[r]},ne.set(t,r),C.define(e,t)}}:Pe,get:Z?function(e){return C.get(e)||Re(e)}:Re,whenDefined:Z?function(e){return Xe.race([C.whenDefined(e),Le(e)])}:Le},!C||/^force/.test(w.type))ke();else if(!w.noBuiltIn)try{(function(e,t,n){var r=new RegExp(`^<a\\s+is=('|")`+n+"\\1></a>$");if(t[_]="a",e.prototype=Ce($e.prototype),e.prototype.constructor=e,m.customElements.define(n,e,t),!r.test(u.createElement("a",{is:n}).outerHTML)||!r.test(new e().outerHTML))throw t})(function e(){return Reflect.construct($e,[],e)},{},"document-register-element-a"+xe)}catch{ke()}if(!w.noBuiltIn)try{if(ae.call(u,"a","a").outerHTML.indexOf("is")<0)throw{}}catch{re=function(t){return{is:t.toLowerCase()}}}})(window);
|
|
3
3
|
|
|
4
4
|
var p1e=Object.create;var UO=Object.defineProperty,g1e=Object.defineProperties,u1e=Object.getOwnPropertyDescriptor,h1e=Object.getOwnPropertyDescriptors,f1e=Object.getOwnPropertyNames,VO=Object.getOwnPropertySymbols,KW=Object.getPrototypeOf,e8=Object.prototype.hasOwnProperty,ZW=Object.prototype.propertyIsEnumerable,v1e=Reflect.get;var YW=(i,o,n)=>o in i?UO(i,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[o]=n,I=(i,o)=>{for(var n in o||={})e8.call(o,n)&&YW(i,n,o[n]);if(VO)for(var n of VO(o))ZW.call(o,n)&&YW(i,n,o[n]);return i},T=(i,o)=>g1e(i,h1e(o));var Z_=(i,o)=>{var n={};for(var e in i)e8.call(i,e)&&o.indexOf(e)<0&&(n[e]=i[e]);if(i!=null&&VO)for(var e of VO(i))o.indexOf(e)<0&&ZW.call(i,e)&&(n[e]=i[e]);return n};var C1e=(i,o)=>()=>(o||i((o={exports:{}}).exports,o),o.exports),jO=(i,o)=>{for(var n in o)UO(i,n,{get:o[n],enumerable:!0})},_1e=(i,o,n,e)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of f1e(o))!e8.call(i,t)&&t!==n&&UO(i,t,{get:()=>o[t],enumerable:!(e=u1e(o,t))||e.enumerable});return i};var XW=(i,o,n)=>(n=i!=null?p1e(KW(i)):{},_1e(o||!i||!i.__esModule?UO(n,"default",{value:i,enumerable:!0}):n,i));var op=(i,o,n)=>v1e(KW(i),n,o);var Q=(i,o,n)=>new Promise((e,t)=>{var r=c=>{try{s(n.next(c))}catch(p){t(p)}},a=c=>{try{s(n.throw(c))}catch(p){t(p)}},s=c=>c.done?e(c.value):Promise.resolve(c.value).then(r,a);s((n=n.apply(i,o)).next())});var gW=C1e((Jyo,pW)=>{"use strict";var Et={};Et.generateIdentifier=function(){return Math.random().toString(36).substring(2,12)};Et.localCName=Et.generateIdentifier();Et.splitLines=function(i){return i.trim().split(`
|
|
@@ -484,7 +484,7 @@ This typically indicates that your device does not have a healthy Internet conne
|
|
|
484
484
|
if (intervalId) clearInterval(intervalId);
|
|
485
485
|
}
|
|
486
486
|
});
|
|
487
|
-
`;if(typeof Worker<"u"){let r=new Blob([t],{type:"application/javascript"});return new Worker(URL.createObjectURL(r))}return}catch(t){this.loggingService.catch("Error in HeartbeatService setupWebWorker: ",t);return}}setupHeartbeat(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: setupHeartbeat","color: green;"),this.worker=this.setupWebWorker(this.HEARTBEAT_DURATION),this.worker){this.worker.onmessage=()=>{this.authService.getUser()&&this.sendHeartbeat()};let t=this.authService.getUser$().subscribe(r=>{r?(this.worker?.postMessage("start"),this.sendHeartbeat()):this.worker?.postMessage("stop")});this.subscriptions.push(t)}else{let t=this.authService.getUser$().pipe(he(r=>r?hm(this.HEARTBEAT_DURATION).pipe(Qi(0)):_l)).subscribe(()=>this.sendHeartbeat());this.subscriptions.push(t)}this.docService.getDocumentPaths$().pipe(Le(t=>!!t),sn(()=>this.sendHeartbeat())).subscribe();let e=vn([this.databaseService.getDb().pipe(Le(t=>!!t)),this.authService.getUser$(),this.docService.getDocumentPaths$()]).pipe(Di(),sn(([[t,r,a],[s,c,p]])=>{if(c&&p){let g=this.domService.getTabId();if(g){let C=this.generateHeartbeatId(c.userId,g),E={id:C,organizationId:p.organizationId},D=this.commonDbUtils.getDocumentPath({feature:"heartbeat",properties:E,defaultDocumentPaths:p,apiKey:this.configService.getApiKey(),useFirestore:!1});if(D&&s&&il(Mi(s,D)).set(null),p.documentId){let L={id:C,documentId:p.documentId,organizationId:p.organizationId},z=this.commonDbUtils.getDocumentPath({feature:"heartbeatByDocument",properties:L,defaultDocumentPaths:p,apiKey:this.configService.getApiKey(),useFirestore:!1});z&&s&&il(Mi(s,z)).set(null)}if(a&&a.documentId&&a.documentId!==p.documentId){let L={id:C,documentId:a.documentId,organizationId:a.organizationId,skipFirestore:!0};this.commonDbService.deleteData({feature:"heartbeatByDocument",properties:L})}}}})).subscribe();this.subscriptions.push(e)}catch(e){this.loggingService.catch("Error in HeartbeatService setupHeartbeat: ",e)}}teardownHeartbeat(){try{this.loggingService.log("%c[WB] Calling FUNCTION: teardownHeartbeat","color: green;"),this.worker&&(this.worker.postMessage("stop"),this.worker.terminate(),this.worker=void 0),this.subscriptions.forEach(e=>e.unsubscribe()),this.subscriptions=[]}catch(e){this.loggingService.catch("Error in HeartbeatService teardownHeartbeat: ",e)}}sendHeartbeat(){try{this.loggingService.log("%c[WB] Calling HeartbeatService FUNCTION: sendHeartbeat","color: green;");let e=this.authService.getUser(),t=this.docService.getDocumentPaths(),r=this.domService.getTabId();if(e&&t&&r){let a=Date.now(),s={id:this.generateHeartbeatId(e.userId,r),createdTimestamp:a,lastUpdatedTimestamp:a,userId:e.userId,veltUserId:yt(e.userId),tabId:r,metadata:this.docService.getBaseMetadata()},p=s.metadata.documentId;this.commonDbService.updateData({feature:"heartbeat",properties:{id:s.id,skipFirestore:!0,rtdbTransaction:!0,rtdbTransactionCallback:(g,C)=>(g?.createdTimestamp&&(C.createdTimestamp=g.createdTimestamp),C)},data:s}),p&&this.commonDbService.updateData({feature:"heartbeatByDocument",properties:{id:s.id,skipFirestore:!0,rtdbTransaction:!0,documentId:p,rtdbTransactionCallback:(g,C)=>(g?.createdTimestamp&&(C.createdTimestamp=g.createdTimestamp),C)},data:s})}}catch(e){this.loggingService.catch("Error in HeartbeatService sendHeartbeat: ",e)}}generateHeartbeatId(e,t){return yt(e+"_"+t)}getHeartbeatData(e){try{let t=this.docService.getDocumentPaths(),r=e?.organizationId||t?.organizationId,a=e?.documentId,s,c={organizationId:r,skipFirestore:!0,useQuery:!0};if(a?(s="allHeartbeatsByDocument",c.documentId=a):s="allHeartbeats",!t)return se(null);let p=e?.orderBy??"lastUpdatedTimestamp",g=e?.lastUpdatedTimestamp?.$gte??Date.now()-15e3,C=e?.limit??50;return c.rtdbQuery=[Lm(p),Bm(g),lS(C)],this.commonDbService.dbListener({feature:s,properties:c}).pipe(Le(E=>!!E?.data),de(E=>E?.data),de(E=>E?Object.values(E??{}).map(D=>D):null))}catch(t){return this.loggingService.catch("Error in HeartbeatService getHeartbeatData: ",t),se(null)}}getSpecificHeartbeat(e){try{let t=this.generateHeartbeatId(e.userId,e.tabId),a=this.docService.getDocumentPaths()?.organizationId;if(!a)return se(null);let s,c={id:t,organizationId:a,skipFirestore:!0};return e.documentId?(s="heartbeatByDocument",c.documentId=e.documentId):s="heartbeat",this.commonDbService.dbListener({feature:s,properties:c}).pipe(Le(p=>!!p?.data),de(p=>p?.data),St((p,g)=>p?.lastUpdatedTimestamp===g?.lastUpdatedTimestamp))}catch(t){return this.loggingService.catch("Error in HeartbeatService getSpecificHeartbeat: ",t),se(null)}}removeDocumentHeartbeat(e){return Q(this,null,function*(){try{let t=this.authService.getUser()?.userId,r=this.domService.getTabId();if(t&&r&&e?.documentId){let a=this.generateHeartbeatId(t,r);yield this.commonDbService.deleteData({feature:"heartbeatByDocument",properties:{id:a,documentId:e.documentId,organizationId:e.organizationId,skipFirestore:!0}})}return Promise.resolve()}catch(t){return this.loggingService.catch("Error in HeartbeatService removeDocumentHeartbeat: ",t),Promise.resolve()}})}enableHeartbeat(){try{if(this.heartbeatEnabled$.value===!0)return;this.heartbeatEnabled$.next(!0)}catch(e){this.loggingService.catch("Error in HeartbeatService enableHeartbeat: ",e)}}disableHeartbeat(){try{if(this.heartbeatEnabled$.value===!1)return;this.heartbeatEnabled$.next(!1)}catch(e){this.loggingService.catch("Error in HeartbeatService disableHeartbeat: ",e)}}getHeartbeatEnabled$(){try{return this.heartbeatEnabled$.asObservable()}catch(e){return this.loggingService.catch("Error in HeartbeatService getHeartbeatEnabled$: ",e),se(!1)}}getHeartbeatEnabled(){try{return this.heartbeatEnabled$.value}catch(e){return this.loggingService.catch("Error in HeartbeatService getHeartbeatEnabled: ",e),!1}}ngOnDestroy(){try{this.teardownHeartbeat()}catch(e){this.loggingService.catch("Error in HeartbeatService ngOnDestroy: ",e)}}};o.\u0275fac=function(t){return new(t||o)(J(Ve),J(an),J(yn),J(it),J(Be),J(y),J(Gl),J(Gd),J(kt))},o.\u0275prov=Ae({token:o,factory:o.\u0275fac,providedIn:"root"});let i=o;return i})();var Ede=(()=>{let o=class o{constructor(e,t,r,a){this.authService=e,this.domService=t,this.loggingService=r,this.usersService=a}findOldestActiveSessionFromHeartbeats(e){try{if(!e||e.length===0)return null;let t=this.authService.getUser(),r=this.domService.getTabId(),a=e.filter(p=>p.lastUpdatedTimestamp>Date.now()-1e4);return a.length===0?null:[...a].sort((p,g)=>p.createdTimestamp-g.createdTimestamp)[0]??null}catch(t){return this.loggingService.catch("Error in findOldestActiveSessionFromHeartbeats: ",t),null}}determineEditorStatus(e){return Q(this,null,function*(){try{let{singleEditorModeData:t,heartbeatData:r,externalUserPresence:a,currentUser:s,currentTabId:c}=e,p=JSON.parse(JSON.stringify(t||{})),g={steps:[],timestamp:Date.now()},C=()=>Q(this,null,function*(){let z=a?.userIds?.[0],W;z&&(yield this.usersService.resolveUsers({userIds:[z],forceResolve:!0}),W=this.usersService.getUserById(z)),W?(p.editor=W,p.tabId=`differentUserPresentOnTab_${c}`):(p.editor={userId:`anonymous_${s?.userId}`,name:"Anonymous"},p.tabId=`differentUserPresentOnTab_${c}`)}),E=()=>{p.editor=s,p.tabId=`sameUserPresentOnTab_${c}`},D=!1;if(t?.editor){if(g.steps?.push("SingleEditorModeData: Editor is available."),r?.length){g.steps?.push("Heartbeat data is available.");let z=r?.find(W=>W.userId===t?.editor?.userId&&W.tabId===t?.tabId);if(z&&z.lastUpdatedTimestamp>Date.now()-1e4)g.steps?.push("Editor user heartbeat is recent.");else{g.steps?.push("Editor user heartbeat is not available or not recent.");let W=this.findOldestActiveSessionFromHeartbeats(r);W&&W.userId===s.userId&&W.tabId===c?(g.steps?.push("Current user is the oldest active session."),D=!0):g.steps?.push("Current user is not the oldest active session.")}}else a&&(g.steps?.push("External user presence is available."),a.differentUserPresentOnTab?(g.steps?.push("External user presence: Different user is present on the tab."),yield C(),D=!1):a.sameUserPresentOnTab?(g.steps?.push("External user presence: Same user is present on the tab."),E(),D=!1):g.steps?.push("External user presence: No user is present on the tab."));!r?.length&&!a&&g.steps?.push("No heartbeat data and no external user presence is available.")}else{if(g.steps?.push("SingleEditorModeData: Editor not available."),r?.length){g.steps?.push("Heartbeat data is available.");let z=this.findOldestActiveSessionFromHeartbeats(r);z&&z.userId===s.userId&&z.tabId===c?(g.steps?.push("Current user is the oldest active session."),D=!0):g.steps?.push("Current user is not the oldest active session.")}else a&&(g.steps?.push("External user presence is available."),a.differentUserPresentOnTab?(g.steps?.push("External user presence: Different user is present on the tab."),yield C(),D=!1):a.sameUserPresentOnTab?(g.steps?.push("External user presence: Same user is present on the tab."),E(),D=!1):(g.steps?.push("External user presence: No user is present on the tab."),D=!0));!r?.length&&!a&&(g.steps?.push("No heartbeat data and no external user presence is available."),D=!0)}let L;return D?L={shouldSetUndefined:!0}:L={data:p},g.singleEditorModeData=t,g.singleEditorModeDataEditorAvailable=!!t?.editor,g.heartbeatData=r,g.externalUserPresence=a,g.currentUser=s,g.currentTabId=c,g.returnValue=L,g.shouldSetUndefined=D,g.steps?.push("Execution completed."),g=this.cleanStats(g),T(I({},L),{stats:g})}catch(t){return this.loggingService.catch("Error in determineEditorStatus: ",t),{data:e?.singleEditorModeData??void 0}}})}cleanStats(e){try{let t=e&&typeof e=="object"?JSON.parse(JSON.stringify(e)):e;return t?.singleEditorModeData?.editor&&(t.singleEditorModeData=T(I({},t.singleEditorModeData),{editor:{userId:t.singleEditorModeData?.editor?.userId}})),t?.returnValue?.data?.editor&&(t.returnValue.data=T(I({},t.returnValue.data),{editor:{userId:t.returnValue.data?.editor?.userId}})),t}catch{return e}}};o.\u0275fac=function(t){return new(t||o)(J(Ve),J(Be),J(y),J(kn))},o.\u0275prov=Ae({token:o,factory:o.\u0275fac,providedIn:"root"});let i=o;return i})();var ji=(()=>{let o=class o{constructor(e,t,r,a,s,c,p,g,C,E,D,L,z,W,ee){this.afAuth=e,this.analyticsService=t,this.authService=r,this.configService=a,this.databaseService=s,this.docService=c,this.domService=p,this.heartbeatService=g,this.iamService=C,this.loggingService=E,this.commonDbService=D,this.liveStateActionsService=L,this.liveStateUtilsService=z,this.usersService=W,this.singleEditorDecisionEngine=ee,this.db=os(),this.liveStateAutoSyncStateData$=new ve(null),this.liveStateDataMapDraft={},this.singleEditorMode$=new ve(!1),this.singleEditorModeConfig$=new ve(null),this.singleEditorLiveStateData$=new ve(null),this.singleEditorLiveStateData={},this.editorAccessTimeout$=new ve(j.LIVE_STATE_REQUEST_EDITOR_ACCESS_WAIT_TIME),this.editorAccessTransferOnTimeOut$=new ve(!0),this.defaultSingleEditorUIEnabled$=new ve(!0),this.editorAccessTimer$=new ve(new u0),this.autoSyncState$=new ve(!1),this.serverConnectionState$=new ve(al.PENDING_INIT),this.externalUserPresence$=new ve(null),this.heartbeat$=new ve(!0),this.user=null,this.keydownSubscription=null,this.isEditor$=new ve(null),this.preventEventsOnElementMap={},this.PREVENT_EVENTS=["click","mouseup","mousedown"],this.autoSyncStateHistory=null,this.singleEditorModeContainerIds$=new ve([]),this.inputChangeSubscriptionMap={},this.childListMutationSubscription=null,this.tabId=this.domService.getTabId(),this.heartbeatRestart$=new ve(void 0);try{this.loggingService.log("%c[WB] Creating CLASS: LiveStateService","color: blue;"),this.analyticsService.setLiveStateService(this),vn([this.getSingleEditorMode$(),this.heartbeat$]).subscribe(([le,ye])=>{le&&ye?this.heartbeatService.enableHeartbeat():this.heartbeatService.disableHeartbeat()}),this.databaseService.getDb().pipe(Le(le=>!!le),at(1)).subscribe(le=>{le&&(this.db=le,this.getUser(),this.getDocumentPaths(),this.subscribeLiveStateData().subscribe(),this.subscribeAutoSyncState().subscribe(),this.singleEditorMode$.subscribe(ye=>{ye&&this.detectKeydownOnInput()}),this.autoSyncState$.subscribe(ye=>{ye?(this.detectLiveSyncInputs(),this.observeElementAddedOnDom()):(this.unsubscribeInputChanges(),this.childListMutationSubscription?.unsubscribe(),this.childListMutationSubscription=null)}),this.updateOnDatabaseDisconnect().subscribe(()=>{},ye=>{this.loggingService.catch("Error in LiveStateService constructor updateOnDatabaseDisconnect: ",ye)}),this.updateServerStateOnDatabaseDisconnect().subscribe(()=>{},ye=>{this.loggingService.catch("Error in LiveStateService constructor updateServerStateOnDatabaseDisconnect: ",ye)}))},le=>{this.loggingService.catch("Error in LiveStateService getDb subscription: ",le)}),this.liveStateAutoSyncStateData$.pipe(Le(le=>Object.keys(le||{}).length>0),St((le,ye)=>JSON.stringify(le||{})===JSON.stringify(ye||{}))).subscribe(le=>{le&&(this.getAutoSyncState()&&(!this.autoSyncStateHistory&&le?.history&&this.updateLiveStateSyncInputDataLocally(le.history),le?.current&&this.updateLiveStateSyncInputDataLocally({[le.current.liveStateDataId]:le.current})),!this.autoSyncStateHistory&&le?.history&&(this.autoSyncStateHistory=le.history))}),this.docService.addPreDocumentIdChangeFunction("live-state-service",le=>(this.updateExternalUserPresence(null),this.isUserEditor()?.isEditor&&(!this.getSingleEditorModeConfig()?.singleTabEditor||this.isUserEditor()?.isEditorOnCurrentTab)?this.removeEditorAccess({metadata:{from:"addPreDocumentIdChangeFunction-liveStateService",reason:"Document id changed"},documentPaths:le}):Promise.resolve())),this.authService.addPreSignOutFuction("live-state-signout",this.signOutUser.bind(this)),this.singleEditorLiveStateData$.pipe(Di()).subscribe(([le,ye])=>{try{let Oe=ye?.requestEditorAccess?.status,ze=le?.requestEditorAccess?.status,Ne=this.authService.getUser();if(Oe==="pending"){if(Ne?.userId===ye?.editor?.userId){let Ee={viewer:ya(ye?.requestEditorAccess?.user)??void 0,editor:ya(ye?.editor)??void 0,timestamp:new Date().getTime(),status:"requested"};this.liveStateActionsService?.onAccessRequested(Ee)}return}if(Oe==="cancelled"){if(Ne?.userId===ye?.editor?.userId){let Ee={viewer:ya(ye?.requestEditorAccess?.user)??void 0,editor:ya(ye?.editor)??void 0,timestamp:new Date().getTime(),status:"canceled"};this.liveStateActionsService?.onAccessRequestCanceled(Ee)}return}if(ze==="pending"&&!Oe){if(le?.requestEditorAccess?.user?.userId===ye?.editor?.userId){if(le?.requestEditorAccess?.user?.userId===Ne?.userId){let Ee={viewer:ya(le?.editor)??void 0,editor:ya(ye?.editor)??void 0,timestamp:new Date().getTime(),status:"accepted"};this.liveStateActionsService?.onAccessAccepted(Ee)}return}if(le?.requestEditorAccess?.user?.userId!==ye?.editor?.userId){if(le?.requestEditorAccess?.user?.userId===Ne?.userId){let Ee={viewer:ya(le?.requestEditorAccess?.user)??void 0,editor:ya(ye?.editor)??void 0,timestamp:new Date().getTime(),status:"rejected"};this.liveStateActionsService?.onAccessRejected(Ee)}return}}}catch(Oe){this.loggingService.catch("Error in LiveStateService singleEditorLiveStateData$ subscription: ",Oe)}}),this.isUserEditor$().pipe(St(gn)).subscribe(le=>{try{if(le){this.analyticsService.trackEvent(Z.Events.LiveStateSync.SEM_USER_EDITOR_STATS,{isEditor:le?.isEditor,isEditorOnCurrentTab:le?.isEditorOnCurrentTab});let ye=this.singleEditorLiveStateData$.value;if(le?.isEditor)if(le?.isEditorOnCurrentTab){let Oe={editor:ya(ye?.editor)??void 0,timestamp:new Date().getTime(),role:"editor"};this.liveStateActionsService?.onEditorAssigned(Oe)}else{let Oe={editor:ya(ye?.editor)??void 0,timestamp:new Date().getTime(),role:"editorOnDifferentTab"};this.liveStateActionsService?.onEditorOnDifferentTabDetected(Oe)}else{let Oe={viewer:ya(this.authService.getUser())??void 0,timestamp:new Date().getTime(),role:"viewer"};this.liveStateActionsService?.onViewerAssigned(Oe)}}}catch(ye){this.loggingService.catch("Error in LiveStateService isUserEditor$ subscription: ",ye)}})}catch(le){this.loggingService.catch("Error in LiveStateService constructor: ",le)}}observeElementAddedOnDom(){try{this.loggingService.log("%c[WB] Calling FUNCTION: observeElementAddedOnDom","color: green;"),this.childListMutationSubscription&&(this.childListMutationSubscription.unsubscribe(),this.childListMutationSubscription=null),this.childListMutationSubscription=this.domService.getChildListMutation$().subscribe(e=>{e?.length&&e.forEach(t=>{let r=Array.from(t.addedNodes||[]).filter(a=>a instanceof HTMLElement);r?.forEach(a=>{i$(a,!0)?.forEach(p=>{typeof p?.getAttribute=="function"&&p?.getAttribute(j.ATTRIBUTES.VELT_SYNC_STATE)&&this.subscribeInputChanges(p)})}),r?.length&&this.isEditor$?.value?.isEditor===!1&&(this.disableInputElements(),this.disableElementEvents())})},e=>{this.loggingService.catch("Error in LiveStateService domService getChildListMutation$ subscription: ",e)})}catch(e){this.loggingService.catch("Error in LiveStateService observeElementAddedOnDom: ",e)}}detectKeydownOnInput(){try{this.loggingService.log("%c[WB] Calling FUNCTION: detectKeydownOnInput","color: green;"),this.unsubscribeKeydownSubscription(),this.keydownSubscription=this.domService.onWindowKeydown$().pipe(Le(e=>e?.target instanceof HTMLInputElement||e?.target instanceof HTMLTextAreaElement||e?.target instanceof HTMLSelectElement),Le(e=>!!this.isElementInsideSingleEditorModeContainerElements(e?.target)),at(1)).subscribe(e=>{this.unsubscribeKeydownSubscription(),this.getSingleEditorModeConfig()?.customMode||this.setUserAsEditor({skipEditorCheck:!0})},e=>{this.loggingService.catch("Error in LiveStateService detectKeydownOnInput subscription: ",e)})}catch(e){this.loggingService.catch("Error in LiveStateService detectKeydownOnInput: ",e)}}unsubscribeKeydownSubscription(){try{this.loggingService.log("%c[WB] Calling FUNCTION: unsubscribeKeydownSubscription","color: green;"),this.keydownSubscription&&(this.keydownSubscription.unsubscribe(),this.keydownSubscription=null)}catch(e){this.loggingService.catch("Error in LiveStateService unsubscribeKeydownSubscription: ",e)}}getDocumentPaths(){try{this.loggingService.log("%c[WB] Calling FUNCTION: getDocumentPaths","color: green;"),this.docService.getDocumentPaths$().subscribe(e=>{this.documentPaths=e,this.updateLiveStateDataFromDraft()})}catch(e){this.loggingService.catch("Error in LiveStateService getDocumentPaths: ",e)}}getUser(){try{this.loggingService.log("%c[WB] Calling FUNCTION: getUser","color: green;"),this.authService.getUser$().subscribe(e=>{this.user=e,this.updateLiveStateDataFromDraft()})}catch(e){this.loggingService.catch("Error in LiveStateService getUser: ",e)}}updateLiveStateDataFromDraft(){try{this.loggingService.log("%c[WB] Calling FUNCTION: updateLiveStateDataFromDraft","color: green;"),this.liveStateDataMapDraft?.custom&&this.user&&this.documentPaths&&(Object.keys(this.liveStateDataMapDraft.custom).forEach(e=>{this.setLiveStateData(e,this.liveStateDataMapDraft.custom[e])}),this.liveStateDataMapDraft={})}catch(e){this.loggingService.catch("Error in LiveStateService updateLiveStateDataFromDraft: ",e)}}getActiveHeartbeatStream$(e){return this.heartbeatRestart$.pipe(at(50),he(()=>{let t=this.heartbeatService.getHeartbeatData({documentId:this.documentPaths?.documentId}).pipe(at(1),he(r=>{let a=this.singleEditorDecisionEngine.findOldestActiveSessionFromHeartbeats(r);return a?this.monitorSession$(a.userId,a.tabId):se(null)}));return!e?.userId||!e?.tabId?t:this.heartbeatService.getSpecificHeartbeat({userId:e.userId,tabId:e.tabId,documentId:this.documentPaths?.documentId}).pipe(at(1),he(r=>!r?.id||Date.now()-r?.lastUpdatedTimestamp>1e4?t:this.monitorSession$(e.userId,e.tabId)))}),St((t,r)=>this.isHeartbeatSimilar(t,r)))}monitorSession$(e,t){return this.heartbeatService.getSpecificHeartbeat({userId:e,tabId:t,documentId:this.documentPaths?.documentId}).pipe(he(a=>a?.id?se(a):(this.heartbeatRestart$.next(),_l)),M8({each:1e4,with:()=>(this.heartbeatRestart$.next(),_l)}))}isHeartbeatSimilar(e,t){try{return!e&&!t?!0:!e||!t?!1:e?.userId===t?.userId&&e?.tabId===t?.tabId}catch{return!1}}subscribeLiveStateData(){return this.loggingService.log("%c[WB] Calling FUNCTION: getOnlineUsersOnCurrentDocument","color: green;"),Qn(this.afAuth).pipe(Le(e=>!!e),he(e=>this.isFeatureAllowed({firebaseUser:e,liveStateData:{}})),he(e=>e.featureAllowed?this.iamService.isUserAllowed$().pipe(de(t=>(e.featureAllowed=t,e))):se(e)),he(e=>e.featureAllowed?this.authService.isPlanExpired$().pipe(de(t=>(e.featureAllowed=!t,e))):se(e)),he(e=>e.featureAllowed?se(e).pipe(he(t=>this.docService.getDocumentPaths$().pipe(de(r=>(this.documentPaths=r,t.documentPaths=r,t)))),he(t=>t?.documentPaths?se(t).pipe(sn(r=>{this.serverConnectionState$?.value===al.PENDING_INIT&&r?.documentPaths?.liveState&&this.serverConnectionState$.next(al.PENDING_DATA)}),he(r=>this.domService.onNetworkStatusChange$().pipe(Le(a=>a),de(()=>r))),he(r=>this.getDataFromDocumentId().pipe(de(a=>(r.singleEditorModeData=a,I({},r))))),he(r=>this.getSingleEditorMode$().pipe(de(()=>r))),de(r=>([al.ONLINE,al.OFFLINE].includes(this.serverConnectionState$?.value)||this.serverConnectionState$.next(al.ONLINE),r)),he(r=>this.getSingleEditorMode()?this.getExternalUserPresence$().pipe(de(a=>T(I({},r),{externalUserPresence:a}))):se(r))):se(T(I({},t),{liveStateData:{}}))),he(t=>this.getSingleEditorMode()?this.heartbeatService.getHeartbeatEnabled$().pipe(he(r=>{if(r){let a=t?.singleEditorModeData?.editor,s=t?.singleEditorModeData?.tabId;return this.getActiveHeartbeatStream$({userId:a?.userId,tabId:s}).pipe(de(c=>{let p=c?.id?[c]:null;return T(I({},t),{heartbeatData:p})}))}else return se(T(I({},t),{heartbeatData:null}))})):se(t)),he(t=>{if(this.getSingleEditorMode()){let r=[];if(!(Object.keys(t?.singleEditorModeData||{}).length>0)){let s=this.singleEditorLiveStateData$.value&&typeof this.singleEditorLiveStateData$.value=="object"?JSON.parse(JSON.stringify(this.singleEditorLiveStateData$.value)):this.singleEditorLiveStateData$.value;r.push({eventName:Z.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_EMPTY_DATA_STATS,properties:{previousSingleEditorModeData:s,currentSingleEditorModeData:t?.singleEditorModeData}})}return this.updateSingleEditorLiveSyncData(t?.singleEditorModeData||{},t?.externalUserPresence??null,t?.heartbeatData??null,t,r),se(t)}else return se(t)})):se({})))}updateSingleEditorLiveSyncData(e,t,r,a,s){return Q(this,null,function*(){try{this.loggingService.log("%c[WB] Calling FUNCTION: updateSingleEditorLiveSyncData","color: green;"),Ci(e,{})&&!this.keydownSubscription&&this.detectKeydownOnInput();let c=JSON.parse(JSON.stringify(e)),p=yield this.singleEditorDecisionEngine.determineEditorStatus({singleEditorModeData:c,externalUserPresence:t,heartbeatData:r,currentUser:this.authService.getUser(),currentTabId:this.tabId});p?.stats&&s?.push({eventName:Z.Events.LiveStateSync.SEM_SINGLE_EDITOR_DETERMINE_EDITOR_STATUS,properties:{stats:p?.stats}});let g;if(this.domService.getNetworkStatus()||(g=null),e=p?.data??{},p?.shouldSetUndefined||(g=null),(a?a?.documentPaths:this.docService.getDocumentPaths())||(g=null),e&&!e?.editor&&this.isEditor$?.value!==g&&this.isEditor$.next(g),Ci(this.singleEditorLiveStateData,e))return;{t&&this.compareServerAndExternalData(c,t),s&&s?.length>0&&s.forEach(D=>{D?.eventName&&this.analyticsService.trackEvent(D.eventName,D.properties)}),this.singleEditorLiveStateData=e,this.singleEditorLiveStateData$.next(e);let E;if(this.singleEditorLiveStateData&&typeof this.singleEditorLiveStateData=="object"&&(E=this.liveStateUtilsService.formatLiveStateSingleEditorModeData(JSON.parse(JSON.stringify(this.singleEditorLiveStateData)))),this.analyticsService.trackEvent(Z.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_STATS,{singleEditorLiveStateData:E}),this.singleEditorLiveStateData?.editor){let D=this.authService.getUser();this.singleEditorLiveStateData?.editor?.userId!==D?.userId?this.makeReader():this.makeEditor()}else this.isEditor$?.value!==g&&this.isEditor$.next(g),this.enableInputElements(),this.enableElementEvents();this.editorAccessTimerInterval&&this.singleEditorLiveStateData?.requestEditorAccess?.status!=="pending"&&this.clearEditorAccessTimerInterval(),this.requestAccessTimer&&this.singleEditorLiveStateData?.requestEditorAccess?.status!=="pending"?this.clearRequestAccessTimer():this.singleEditorLiveStateData?.requestEditorAccess?.status==="pending"&&this.isUserEditor()?.isEditor&&this.isUserEditor()?.isEditorOnCurrentTab&&this.setRequestAccessTimer(this.singleEditorLiveStateData?.requestEditorAccess?.editorAccessTimeout||j.LIVE_STATE_REQUEST_EDITOR_ACCESS_WAIT_TIME)}}catch{}})}updateSingleEditorLiveSyncDataOld(a,s){return Q(this,arguments,function*(e,t,r=[]){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: updateSingleEditorLiveSyncData","color: green;"),Ci(e,{})){let g=yield this.fetchSingleEditorLiveStateDataFromDatabase();if(!Ci(g,e)&&(r.push({eventName:Z.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_MISMATCH,properties:{serverData:g,localData:e}}),g&&typeof g=="object")){let C=yield this.liveStateUtilsService.resolveAndMergeSingleEditorLiveStateDataWithUser(JSON.parse(JSON.stringify(g)));e=JSON.parse(JSON.stringify(C))}}Ci(e,{})&&!this.keydownSubscription&&this.detectKeydownOnInput();let c=e&&typeof e=="object"?JSON.parse(JSON.stringify(e)):e;if(t&&(e&&typeof e=="object"&&(e=JSON.parse(JSON.stringify(e))),!e?.editor)){let g=this.authService.getUser();if(t?.sameUserPresentOnTab)e.editor=g,e.tabId=`sameUserPresentOnTab_${this.tabId}`;else if(t?.differentUserPresentOnTab){let C=t?.userIds?.[0],E;C&&(yield this.usersService.resolveUsers({userIds:[C],forceResolve:!0}),E=this.usersService.getUserById(C)),E?(e.editor=E,e.tabId=`differentUserPresentOnTab_${this.tabId}`):(e.editor={userId:`anonymous_${g?.userId}`,name:"Anonymous"},e.tabId=`differentUserPresentOnTab_${this.tabId}`)}}let p;if(this.domService.getNetworkStatus()||(p=null),e&&!e?.editor&&this.isEditor$?.value!==p&&!t?.sameUserPresentOnTab&&!t?.differentUserPresentOnTab&&this.isEditor$.next(p),Ci(this.singleEditorLiveStateData,e))return;{t&&this.compareServerAndExternalData(c,t),r?.length>0&&r.forEach(C=>{C?.eventName&&this.analyticsService.trackEvent(C.eventName,C.properties)}),this.singleEditorLiveStateData=e,this.singleEditorLiveStateData$.next(e);let g;if(this.singleEditorLiveStateData&&typeof this.singleEditorLiveStateData=="object"&&(g=this.liveStateUtilsService.formatLiveStateSingleEditorModeData(JSON.parse(JSON.stringify(this.singleEditorLiveStateData)))),this.analyticsService.trackEvent(Z.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_STATS,{singleEditorLiveStateData:g}),this.singleEditorLiveStateData?.editor){let C=this.authService.getUser();this.singleEditorLiveStateData?.editor?.userId!==C?.userId?this.makeReader():this.makeEditor()}else this.isEditor$?.value!==p&&this.isEditor$.next(p),this.enableInputElements(),this.enableElementEvents();this.editorAccessTimerInterval&&this.singleEditorLiveStateData?.requestEditorAccess?.status!=="pending"&&this.clearEditorAccessTimerInterval(),this.requestAccessTimer&&this.singleEditorLiveStateData?.requestEditorAccess?.status!=="pending"?this.clearRequestAccessTimer():this.singleEditorLiveStateData?.requestEditorAccess?.status==="pending"&&this.isUserEditor()?.isEditor&&this.isUserEditor()?.isEditorOnCurrentTab&&this.setRequestAccessTimer(this.singleEditorLiveStateData?.requestEditorAccess?.editorAccessTimeout||j.LIVE_STATE_REQUEST_EDITOR_ACCESS_WAIT_TIME)}}catch{}})}compareServerAndExternalData(e,t){try{if(t){let r=this.authService.getUser(),a={isEditor:e?.editor?.userId===r?.userId,isEditorOnCurrentTab:e?.editor?.userId===r?.userId&&e?.tabId===this.tabId},s={isEditor:t?.sameUserPresentOnTab&&!t?.differentUserPresentOnTab,isEditorOnCurrentTab:!1};Ci(a,s)||this.analyticsService.trackEvent(Z.Events.LiveStateSync.SEM_SINGLE_EDITOR_DATA_MISMATCH_WITH_EXTERNAL,{serverUserEditorAccess:a,externalUserEditorAccess:s,serverData:e,externalData:t})}}catch(r){this.loggingService.catch("Error in LiveStateService compareServerAndExternalData: ",r)}}isFeatureAllowed(e){return this.configService.getConfig$().pipe(Le(t=>!!t),de(t=>T(I({},e),{config:t})),he(t=>this.authService.getUser$().pipe(de(r=>T(I({},t),{user:r})))),he(t=>ao(t.config,t.user,Re.LIVE_STATE_SYNC)?se(T(I({},t),{featureAllowed:!0})):(this.loggingService.warn("Live state sync feature is not allowed."),se(T(I({},t),{featureAllowed:!1})))),St((t,r)=>t?.featureAllowed===r?.featureAllowed))}getDataFromDocumentId(e){return this.databaseService.getDb().pipe(Le(t=>!!t),he(t=>(this.db=t,this.configService?.getApiKey()&&this.documentPaths?.liveState?this.commonDbService.dbListener({feature:"liveStateSingleEditorMode",properties:{documentId:e??this.documentPaths?.documentId,organizationId:this.documentPaths?.organizationId,skipFirestore:!0}}).pipe(Le(r=>!!r?.data),de(r=>r?.data&&typeof r?.data=="object"?JSON.parse(JSON.stringify(r?.data)):r?.data),Pn(r=>(this.loggingService.catch("Error in LiveStateService getDataFromDocumentId: ",r),se({})))):se({}))),St(gn))}getLiveStateData$(e,t){try{return this.loggingService.log("%c[WB] Calling FUNCTION: getLiveStateData$","color: green;"),Qn(this.afAuth).pipe(Le(r=>!!r),he(r=>this.isFeatureAllowed({firebaseUser:r,liveStateData:{}})),he(r=>r.featureAllowed?this.iamService.isUserAllowed$().pipe(de(a=>(r.featureAllowed=a,r))):se(r)),he(r=>r.featureAllowed?this.authService.isPlanExpired$().pipe(de(a=>(r.featureAllowed=!a,r))):se(r)),he(r=>r.featureAllowed?se(r).pipe(he(a=>this.docService.getDocumentPaths$().pipe(de(s=>(this.documentPaths=s,a.documentPaths=s,a)))),he(a=>{let s=t?.listenToNewChangesOnly?1:0;return this.getLiveStateDataFromDatabase$(e).pipe(zs(s))}),de(a=>{if(a)if(e){let s=yt(e+""),c=a?.[s];if(c){let p=c?.data;if(c?.tabId&&this.tabId&&c?.tabId===this.tabId)return;if(c?.isDataStringified&&typeof p=="string")try{p=JSON.parse(p)}catch{}return p}else return}else{let s={};return Object.keys(a||{}).forEach(c=>{if(a[c]?.liveStateDataId){let p=a[c],g=p?.data;if(p?.isDataStringified&&typeof g=="string")try{g=JSON.parse(g)}catch{}s[p.liveStateDataId]=g}}),s}return a})):se(void 0).pipe(Le(Boolean))),St((r,a)=>JSON.stringify(r||{})===JSON.stringify(a||{})),Le(r=>r!==void 0),de(r=>r))}catch(r){return this.loggingService.catch("Error in LiveStateService getLiveStateData$: ",r),se(null)}}getLiveStateDataFromDatabase$(e){try{return this.databaseService.getDb().pipe(Le(t=>!!t),he(t=>{this.db=t;let r=e?yt(e+""):void 0;return this.configService?.getApiKey()&&this.documentPaths?.liveState?this.commonDbService.dbListener({feature:r?"liveStateCustom":"allLiveStateCustoms",properties:{documentId:this.documentPaths?.documentId,organizationId:this.documentPaths?.organizationId,id:r,skipFirestore:!0}}).pipe(de(a=>a?.data),de(a=>{if(a)return r?{[r]:a}:a}),Pn(a=>(this.loggingService.catch("Error in LiveStateService getLiveStateDataFromDatabase$: ",a),se(null)))):se(void 0)}))}catch(t){return this.loggingService.catch("Error in LiveStateService getLiveStateDataFromDatabase$: ",t),se(void 0)}}setLiveStateData(e,t,r){return Q(this,null,function*(){this.loggingService.log("%c[WB] Calling FUNCTION: setLiveStateData","color: green;");try{let a=this.authService.getUser();if(e&&this.documentPaths?.liveState&&a){let s=yt(e+""),c=!1;try{if(r?.merge&&typeof t=="object"){let g=yield this.commonDbService.getData({feature:"liveStateCustom",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",id:s,skipFirestore:!0}});if(g?.isDataStringified){let C=JSON.parse(g?.data);typeof t=="object"&&(t=I(I({},C),t))}}}catch{}try{typeof t=="object"&&(t=JSON.stringify(t),c=!0)}catch{}let p={id:s,lastUpdated:this.timestamp,liveStateDataId:e,data:t,updatedBy:a,tabId:this.tabId,isDataStringified:c};yield this.commonDbService.setData({feature:"liveStateCustom",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",id:s,skipFirestore:!0},data:JSON.parse(JSON.stringify(p))})}else this.loggingService.warn("liveStateDataId or documentPaths or user is null"),this.liveStateDataMapDraft?.custom||(this.liveStateDataMapDraft.custom={}),e&&(this.liveStateDataMapDraft.custom[e]=t)}catch(a){this.loggingService.catch("Error in LiveStateService _setLiveStateData: ",a)}})}getFormElements(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: getInputElements","color: green;"),document.querySelectorAll("input, textarea, select, button, [contenteditable]")}catch(e){return this.loggingService.catch("Error in LiveStateService getInputElements: ",e),null}}disableInputElements(){try{this.loggingService.log("%c[WB] Calling FUNCTION: disableInputElements","color: green;"),this.getFormElements()?.forEach(t=>{if(this.isElementInsideSingleEditorModeContainerElements(t)&&!this.isSingleEditorModeDisabledForElement(t)&&!Xi(t)){let r=t?.hasAttribute("disabled");t?.hasAttribute("contenteditable")&&(r=t?.getAttribute("contenteditable")==="false"),r||(t.setAttribute("disabled","true"),t.setAttribute(j.ATTRIBUTES.VELT_SYNC_ACCESS_AUTO,"true"),t?.hasAttribute("contenteditable")&&t.setAttribute("contenteditable","false"))}})}catch(e){this.loggingService.catch("Error in LiveStateService disableInputElements: ",e)}}enableInputElements(){try{this.loggingService.log("%c[WB] Calling FUNCTION: enableInputElements","color: green;"),this.getFormElements()?.forEach(t=>{t?.hasAttribute(j.ATTRIBUTES.VELT_SYNC_ACCESS_AUTO)&&(t.removeAttribute("disabled"),t.removeAttribute(j.ATTRIBUTES.VELT_SYNC_ACCESS_AUTO),t?.getAttribute("contenteditable")&&t.setAttribute("contenteditable","true"))})}catch(e){this.loggingService.catch("Error in LiveStateService enableInputElements: ",e)}}disableElementEvents(){try{this.loggingService.log("%c[WB] Calling FUNCTION: disableElementEvents","color: green;"),document.querySelectorAll(`[${j.ATTRIBUTES.VELT_SYNC_ACCESS}]`)?.forEach(t=>{let r=this.domService.getXPath(t);r&&!this.preventEventsOnElementMap[r]&&(this.preventEventsOnElementMap[r]={element:t,events:{}},this.PREVENT_EVENTS.forEach(a=>{let s=hi(t,a,{capture:!0}).subscribe(c=>{try{c.preventDefault(),c.stopPropagation()}catch(p){this.loggingService.catch("Error in LiveStateService disableElementEvents subscription: ",p)}});this.preventEventsOnElementMap[r]?.events[a]?.unsubscribe(),this.preventEventsOnElementMap[r].events[a]=s}))})}catch(e){this.loggingService.catch("Error in LiveStateService disableElementClicks: ",e)}}enableElementEvents(){try{this.loggingService.log("%c[WB] Calling FUNCTION: enableElementEvents","color: green;"),Object.keys(this.preventEventsOnElementMap).forEach(e=>{let t=this.preventEventsOnElementMap[e];Object.keys(t.events||{}).forEach(r=>{t?.events[r]?.unsubscribe()})}),this.preventEventsOnElementMap={}}catch(e){this.loggingService.catch("Error in LiveStateService enableElementClicks: ",e)}}setUserAsEditor(e){return Q(this,null,function*(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: setUserAsEditor","color: green;"),this.user&&this.documentPaths?.liveStateSingleEditorMode){if(this.analyticsService.trackEvent(Z.Events.LiveStateSync.SET_USER_AS_EDITOR_TRIGGERED,{editorUserId:this.user?.userSnippylyId,tabId:this.tabId}),!e?.skipEditorCheck){let r=yield this.fetchSingleEditorLiveStateDataFromDatabase();if(r?.editor?.userId&&r?.tabId){let a=yield P8(this.heartbeatService.getSpecificHeartbeat({userId:r?.editor?.userId,tabId:r?.tabId,documentId:this.documentPaths?.documentId})),s=null;a&&(s=this.singleEditorDecisionEngine.findOldestActiveSessionFromHeartbeats([a])),s||(r=null)}else r=null;if(r?.editor){let a=this.authService.getUser(),s=null;a?.userId===r?.editor?.userId?r?.tabId===this.tabId?s={code:"same_user_editor_current_tab",message:"Same user is already editor in current tab.",source:"setUserAsEditor"}:s={code:"same_user_editor_different_tab",message:"Same user is already editor in different tab.",source:"setUserAsEditor"}:s={code:"another_user_editor",message:"Another user is already editor.",source:"setUserAsEditor"};let c;return r&&typeof r=="object"&&(c=this.liveStateUtilsService.formatLiveStateSingleEditorModeData(JSON.parse(JSON.stringify(r)))),this.analyticsService.trackEvent(Z.Events.LiveStateSync.SET_USER_AS_EDITOR_ERROR,{error:s,singleEditorLiveStateData:c}),{error:s}}}let t={editor:this.user,tabId:this.tabId,editorAt:this.timestamp};this.commonDbService.setData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(t))})}}catch(t){this.loggingService.catch("Error in LiveStateService setUserAsEditor: ",t)}})}fetchSingleEditorLiveStateDataFromDatabase(){return Q(this,null,function*(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: fetchSingleEditorLiveStateDataFromDatabase","color: green;"),yield this.commonDbService.getData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0}})}catch(e){return this.loggingService.catch("Error in LiveStateService fetchSingleEditorLiveStateDataFromDatabase: ",e),null}})}setRequestAccessTimer(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: setRequestAccessTimer","color: green;"),this.requestAccessTimer||(this.requestAccessTimer=setTimeout(()=>{this.getEditorAccessTransferOnTimeOut()&&this.acceptEditorAccessRequest(),this.clearRequestAccessTimer()},e*1e3),this.setEditorAccessTimerInterval(e))}catch(t){this.loggingService.catch("Error in LiveStateService setRequestAccessTimer: ",t)}}clearRequestAccessTimer(){try{this.loggingService.log("%c[WB] Calling FUNCTION: clearRequestAccessTimer","color: green;"),this.requestAccessTimer&&(clearTimeout(this.requestAccessTimer),this.requestAccessTimer=null)}catch(e){this.loggingService.catch("Error in LiveStateService clearRequestAccessTimer: ",e)}}requestEditorAccess(){this.loggingService.log("%c[WB] Calling FUNCTION: requestEditorAccess","color: green;");try{return this.analyticsService.trackEvent(Z.Events.LiveStateSync.REQUEST_EDITOR_ACCESS_TRIGGERED),new Ut(e=>{let t=null;try{if(this.user&&this.documentPaths?.liveStateSingleEditorMode){let r=this.getEditorAccessTimeout(),a=Mi(this.db,`${this.documentPaths?.liveStateSingleEditorMode}`),s={requestEditorAccess:{user:this.user,requestedAt:this.timestamp,status:"pending",editorAccessTimeout:r,tabId:this.tabId}};this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},errorCallback:c=>{this.loggingService.catch("Error in LiveStateService requestEditorAccess: ",c),e.next(null),e.complete()},callback:()=>{r&&(this.requestAccessTimer=setTimeout(()=>{this.getEditorAccessTransferOnTimeOut()&&this.setUserAsEditor({skipEditorCheck:!0})},(r+3)*1e3),this.setEditorAccessTimerInterval(r+3)),t=this.getSingleEditorLiveStateData$().subscribe(c=>{c&&(c?.requestEditorAccess?c?.requestEditorAccess?.status==="cancelled"&&(e.next(null),e.complete()):c?.editor?.userId===this.user?.userId?(e.next(!0),e.complete()):(e.next(!1),e.complete()))})},data:JSON.parse(JSON.stringify(s))})}else e.next(!1),e.complete()}catch(r){this.loggingService.catch("Error in LiveStateService requestEditorAccess: ",r),e.next(null),e.complete()}return()=>{t&&t?.unsubscribe()}})}catch(e){return this.loggingService.catch("Error in LiveStateService requestEditorAccess: ",e),se(null)}}makeEditor(){try{this.loggingService.log("%c[WB] Calling FUNCTION: makeEditor","color: green;");let e=this.singleEditorLiveStateData?.tabId===this.tabId;this.analyticsService.trackEvent(Z.Events.LiveStateSync.SEM_MAKE_EDITOR_TRIGGERED,{editorUserId:this.singleEditorLiveStateData?.editor?.userId,tabId:this.tabId,editorTabId:this.singleEditorLiveStateData?.tabId,isEditor:!0,isEditorOnCurrentTab:e}),this.isEditor$.next({isEditor:!0,isEditorOnCurrentTab:e}),this.getSingleEditorModeConfig()?.customMode||(!this.getSingleEditorModeConfig()?.singleTabEditor||e?(this.enableInputElements(),this.enableElementEvents()):(this.disableInputElements(),this.disableElementEvents())),this.fetchSingleEditorLiveStateDataFromDatabase().then(t=>{this.analyticsService.trackEvent(Z.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_ON_MAKE_EDITOR,{editorUserId:this.singleEditorLiveStateData?.editor?.userId,tabId:this.tabId,editorTabId:this.singleEditorLiveStateData?.tabId,isEditor:!0,isEditorOnCurrentTab:e,singleEditorLiveStateDataOnServer:t})}).catch(t=>{})}catch(e){this.loggingService.catch("Error in LiveStateService makeEditor: ",e)}}makeReader(){try{this.loggingService.log("%c[WB] Calling FUNCTION: makeReader","color: green;"),this.analyticsService.trackEvent(Z.Events.LiveStateSync.SEM_MAKE_READER_TRIGGERED,{editorUserId:this.singleEditorLiveStateData?.editor?.userId,tabId:this.tabId,editorTabId:this.singleEditorLiveStateData?.tabId,isEditor:!1,isEditorOnCurrentTab:!1}),this.isEditor$.next({isEditor:!1,isEditorOnCurrentTab:!1}),this.getSingleEditorModeConfig()?.customMode||(this.disableInputElements(),this.disableElementEvents()),this.fetchSingleEditorLiveStateDataFromDatabase().then(e=>{this.analyticsService.trackEvent(Z.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_ON_MAKE_READER,{editorUserId:this.singleEditorLiveStateData?.editor?.userId,tabId:this.tabId,editorTabId:this.singleEditorLiveStateData?.tabId,isEditor:!1,isEditorOnCurrentTab:!1,singleEditorLiveStateDataOnServer:e})}).catch(e=>{})}catch(e){this.loggingService.catch("Error in makeReader: ",e)}}acceptEditorAccessRequest(){return Q(this,null,function*(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: acceptEditorAccessRequest","color: green;"),this.user&&this.singleEditorLiveStateData?.requestEditorAccess&&this.isUserEditor()?.isEditor&&this.documentPaths?.liveStateSingleEditorMode){let e=this.singleEditorLiveStateData?.requestEditorAccess?.user,t=this.singleEditorLiveStateData?.requestEditorAccess?.tabId;if(e&&t){let r={editor:e,requestEditorAccess:null,tabId:t,editorAt:this.timestamp};this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(r))}),this.analyticsService.trackEvent(Z.Events.LiveStateSync.ACCEPT_EDITOR_ACCESS_REQUEST_TRIGGERED,{editorUserId:e?.userSnippylyId,tabId:t})}}}catch(e){this.loggingService.catch("Error in acceptEditorAccessRequest: ",e)}})}rejectEditorAccessRequest(){return Q(this,null,function*(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: rejectEditorAccessRequest","color: green;"),this.user&&this.singleEditorLiveStateData?.requestEditorAccess&&this.isUserEditor()?.isEditor&&this.documentPaths?.liveStateSingleEditorMode){let e={requestEditorAccess:null};this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(e))}),this.analyticsService.trackEvent(Z.Events.LiveStateSync.REJECT_EDITOR_ACCESS_REQUEST_TRIGGERED)}}catch(e){this.loggingService.catch("Error in LiveStateService rejectEditorAccessRequest: ",e)}})}cancelEditorAccessRequest(){return Q(this,null,function*(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: cancelEditorAccessRequest","color: green;"),this.user&&this.singleEditorLiveStateData?.requestEditorAccess&&this.documentPaths?.liveStateSingleEditorMode){let e={requestEditorAccess:T(I({},this.singleEditorLiveStateData?.requestEditorAccess),{status:"cancelled"})};this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(e))}),e={requestEditorAccess:null},this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(e))}),this.analyticsService.trackEvent(Z.Events.LiveStateSync.CANCEL_EDITOR_ACCESS_REQUEST_TRIGGERED)}}catch(e){this.loggingService.catch("Error in LiveStateService cancelEditorAccessRequest: ",e)}})}editCurrentTab(){return Q(this,null,function*(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: editCurrentTab","color: green;"),this.user&&this.isUserEditor()?.isEditor&&!this.isUserEditor()?.isEditorOnCurrentTab&&this.documentPaths?.liveStateSingleEditorMode){let e={tabId:this.tabId,editor:this.user,editorAt:this.timestamp};this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(e))}),this.analyticsService.trackEvent(Z.Events.LiveStateSync.EDIT_CURRENT_TAB_TRIGGERED,{tabId:this.tabId})}}catch(e){this.loggingService.catch("Error in LiveStateService editCurrentTab: ",e)}})}isUserEditor$(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: isUserEditor$","color: green;"),this.isEditor$.asObservable().pipe(St(gn))}catch(e){return this.loggingService.catch("Error in LiveStateService isUserEditor$: ",e),se(null)}}isUserEditor(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: isUserEditor","color: green;"),this.isEditor$.value}catch(e){return this.loggingService.catch("Error in LiveStateService isUserEditor: ",e),null}}getEditor$(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: getEditor$","color: green;"),this.getSingleEditorLiveStateData$().pipe(de(e=>e?.editor||null),St())}catch(e){return this.loggingService.catch("Error in LiveStateService getEditor$: ",e),se(null)}}isEditorAccessRequested$(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: isEditorAccessRequested$","color: green;"),this.isUserEditor$().pipe(he(e=>e?.isEditor?this.singleEditorLiveStateData$.pipe(de(t=>t?.requestEditorAccess?{requestStatus:"requested",requestedBy:t?.requestEditorAccess?.user}:null)):se(null)),St((e,t)=>JSON.stringify(e||{})===JSON.stringify(t||{})))}catch(e){return this.loggingService.catch("Error in LiveStateService isEditorAccessRequested$: ",e),se(null)}}removeEditorAccess(e){return Q(this,null,function*(){try{this.loggingService.log("%c[WB] Calling FUNCTION: removeEditorAccess","color: green;"),this.analyticsService.trackEvent(Z.Events.LiveStateSync.REMOVE_EDITOR_ACCESS,{removeEditorAccessMetadata:e?.metadata});let t=e?.documentPaths??this.documentPaths;(this.user||this.authService.getAuthUser())&&t?.liveStateSingleEditorMode&&(yield this.commonDbService.deleteData({feature:"liveStateSingleEditorMode",properties:{documentId:t?.documentId??"",organizationId:t?.organizationId??"",skipFirestore:!0}}))}catch(t){this.loggingService.catch("Error in LiveStateService removeEditorAccess: ",t)}})}getSingleEditorLiveStateData$(){return this.singleEditorLiveStateData$.asObservable().pipe(St(gn))}subscribeAutoSyncState(){return this.loggingService.log("%c[WB] Calling FUNCTION: getOnlineUsersOnCurrentDocument","color: green;"),Qn(this.afAuth).pipe(Le(e=>!!e),he(e=>this.isFeatureAllowed({firebaseUser:e,liveStateData:{}})),he(e=>e.featureAllowed?this.iamService.isUserAllowed$().pipe(de(t=>(e.featureAllowed=t,e))):se(e)),he(e=>e.featureAllowed?this.authService.isPlanExpired$().pipe(de(t=>(e.featureAllowed=!t,e))):se(e)),he(e=>e.featureAllowed?se(e).pipe(he(t=>this.docService.getDocumentPaths$().pipe(Le(r=>!!r),de(r=>(this.documentPaths=r,t.documentPaths=r,t)))),he(t=>this.domService.onNetworkStatusChange$().pipe(Le(r=>r),de(()=>t))),he(t=>this.getLiveStateAutoSyncStateDataFromDocumentId().pipe(de(r=>(t.liveStateData=r,I({},t))))),de(t=>{if(t.liveStateData)this.liveStateAutoSyncStateData$.next(t.liveStateData);else{let r=this.liveStateAutoSyncStateData$.value;r&&Object.keys(r).length>0&&this.liveStateAutoSyncStateData$.next({})}return t})):se({})))}getLiveStateAutoSyncStateDataFromDocumentId(e){return this.databaseService.getDb().pipe(Le(t=>!!t),he(t=>(this.db=t,this.configService?.getApiKey()&&this.documentPaths?.liveState?this.commonDbService.dbListener({feature:"liveStateAutoSyncState",properties:{documentId:e??this.documentPaths?.documentId,organizationId:this.documentPaths?.organizationId,skipFirestore:!0}}).pipe(Le(r=>!!r?.data),de(r=>r?.data&&typeof r?.data=="object"?JSON.parse(JSON.stringify(r?.data)):r?.data),Pn(r=>(this.loggingService.catch("Error in LiveStateService getLiveStateAutoSyncStateDataFromDocumentId: ",r),se({})))):se({}))),St(gn))}enableSingleEditorMode(e){try{if(this.singleEditorMode$.value===!0)return;this.singleEditorMode$.next(!0),e?this.singleEditorModeConfig$.next(e):this.singleEditorModeConfig$.next(new Pk)}catch(t){this.loggingService.catch("Error in LiveStateService enableSingleEditorMode: ",t)}}disableSingleEditorMode(){try{if(this.singleEditorMode$.value===!1)return;this.singleEditorMode$.next(!1)}catch(e){this.loggingService.catch("Error in LiveStateService disableSingleEditorMode: ",e)}}getSingleEditorMode$(){return this.singleEditorMode$.asObservable()}getSingleEditorMode(){return this.singleEditorMode$.value}getSingleEditorModeConfig$(){return this.singleEditorModeConfig$.asObservable()}getSingleEditorModeConfig(){return this.singleEditorModeConfig$.value}enableAutoSyncState(){try{if(this.autoSyncState$.value===!0)return;this.autoSyncState$.next(!0)}catch(e){this.loggingService.catch("Error in LiveStateService enableAutoSyncState: ",e)}}disableAutoSyncState(){try{if(this.autoSyncState$.value===!1)return;this.autoSyncState$.next(!1)}catch(e){this.loggingService.catch("Error in LiveStateService disableAutoSyncState: ",e)}}getAutoSyncState$(){return this.autoSyncState$.asObservable()}getAutoSyncState(){return this.autoSyncState$.value}setEditorAccessTimeout(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: setEditorAccessTimeout","color: green;"),e&&this.editorAccessTimeout$.next(e)}catch(t){this.loggingService.catch("Error in LiveStateService setEditorAccessTimeout: ",t)}}getEditorAccessTimeout$(){return this.editorAccessTimeout$.asObservable()}getEditorAccessTimeout(){return this.editorAccessTimeout$.value}enableEditorAccessTransferOnTimeOut(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: enableEditorAccessTransferOnTimeOut","color: green;"),this.editorAccessTransferOnTimeOut$.value===!0)return;this.editorAccessTransferOnTimeOut$.next(!0)}catch(e){this.loggingService.catch("Error in LiveStateService enableEditorAccessTransferOnTimeOut: ",e)}}disableEditorAccessTransferOnTimeOut(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: disableEditorAccessTransferOnTimeOut","color: green;"),this.editorAccessTransferOnTimeOut$.value===!1)return;this.editorAccessTransferOnTimeOut$.next(!1)}catch(e){this.loggingService.catch("Error in LiveStateService disableEditorAccessTransferOnTimeOut: ",e)}}getEditorAccessTransferOnTimeOut$(){return this.editorAccessTransferOnTimeOut$.asObservable()}getEditorAccessTransferOnTimeOut(){return this.editorAccessTransferOnTimeOut$.value}enableDefaultSingleEditorUI(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: enableDefaultSingleEditorUI","color: green;"),this.defaultSingleEditorUIEnabled$.value===!0)return;this.defaultSingleEditorUIEnabled$.next(!0)}catch(e){this.loggingService.catch("Error in LiveStateService enableDefaultSingleEditorUI: ",e)}}disableDefaultSingleEditorUI(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: disableDefaultSingleEditorUI","color: green;"),this.defaultSingleEditorUIEnabled$.value===!1)return;this.defaultSingleEditorUIEnabled$.next(!1)}catch(e){this.loggingService.catch("Error in LiveStateService disableDefaultSingleEditorUI: ",e)}}getDefaultSingleEditorUIEnabled$(){return this.defaultSingleEditorUIEnabled$.asObservable()}getDefaultSingleEditorUIEnabled(){return this.defaultSingleEditorUIEnabled$.value}setEditorAccessTimerInterval(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: setEditorAccessTimerInterval","color: green;"),this.clearEditorAccessTimerInterval(),e>0&&(this.editorAccessTimer$.next({state:"inProgress",durationLeft:e}),this.editorAccessTimerInterval=setInterval(()=>{try{e-=1,e<0?this.clearEditorAccessTimerInterval():e?this.editorAccessTimer$.next({state:"inProgress",durationLeft:e}):this.editorAccessTimer$.next({state:"completed"})}catch(t){this.loggingService.catch("Error in LiveStateService setEditorAccessTimerCountdown interval: ",t),this.clearEditorAccessTimerInterval()}},1e3))}catch(t){this.loggingService.catch("Error in LiveStateService setEditorAccessTimerCountdown: ",t),this.clearEditorAccessTimerInterval()}}clearEditorAccessTimerInterval(){try{this.loggingService.log("%c[WB] Calling FUNCTION: clearEditorAccessTimerInterval","color: green;"),this.editorAccessTimerInterval&&(clearInterval(this.editorAccessTimerInterval),this.editorAccessTimerInterval=null,this.editorAccessTimer$.next({state:"idle"}))}catch(e){this.loggingService.catch("Error in LiveStateService clearEditorAccessTimerInterval: ",e)}}getEditorAccessTimer$(){return this.editorAccessTimer$.asObservable()}onServerConnectionStateChange$(){return this.serverConnectionState$.asObservable()}updateExternalUserPresence(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: updateExternalUserPresence","color: green;"),this.externalUserPresence$.next(e)}catch(t){this.loggingService.catch("Error in LiveStateService updateExternalUserPresence: ",t)}}getExternalUserPresence$(){return this.externalUserPresence$.asObservable().pipe(St(gn))}getExternalUserPresence(){return this.externalUserPresence$.value}enableHeartbeat(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: enableHeartbeat","color: green;"),this.heartbeat$.value===!0)return;this.heartbeat$.next(!0)}catch(e){this.loggingService.catch("Error in LiveStateService enableHeartbeat: ",e)}}disableHeartbeat(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: disableHeartbeat","color: green;"),this.heartbeat$.value===!1)return;this.heartbeat$.next(!1)}catch(e){this.loggingService.catch("Error in LiveStateService disableHeartbeat: ",e)}}detectLiveSyncInputs(){try{document.querySelectorAll(`[${j.ATTRIBUTES.VELT_SYNC_STATE}]`)?.forEach(t=>{this.subscribeInputChanges(t)})}catch(e){this.loggingService.catch("Error in LiveStateService detectLiveSyncInputs: ",e)}}subscribeInputChanges(e){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: subscribeInputChanges","color: green;"),e){let t=e.tagName,r=this.domService.getXPath(e),a=yt(r);if(this.inputChangeSubscriptionMap[a])this.loggingService.warn("subscription already exists",a,e);else{this.inputChangeSubscriptionMap[a]={id:a,element:e};let s;switch(t?.toLowerCase()){case"input":s=hi(e,"input").pipe(cr(300)).subscribe(p=>{let g={value:p?.target?.value,tagName:p?.target?.tagName,type:p?.target?.type};this.setLiveStateSyncInputData(p?.target,g)});break;case"textarea":s=hi(e,"input").pipe(cr(300)).subscribe(p=>{let g={value:p?.target?.value,tagName:p?.target?.tagName};this.setLiveStateSyncInputData(p?.target,g)});break;default:e.getAttribute("contenteditable")&&(s=hi(e,"input").pipe(cr(300)).subscribe(p=>{let g={innerText:p?.target?.innerText,innerHTML:this.domService.sanitizeHtml(p?.target?.innerHTML),tagName:p?.target?.tagName,isContentEditable:!0};this.setLiveStateSyncInputData(p?.target,g)}));break}s&&(this.inputChangeSubscriptionMap[a]?.subscriptions||(this.inputChangeSubscriptionMap[a]={subscriptions:[]}),this.inputChangeSubscriptionMap[a].subscriptions?.push(s))}}}catch(t){this.loggingService.catch("Error in LiveStateService subscribeInputChanges: ",t)}}unsubscribeInputChanges(){try{this.loggingService.log("%c[WB] Calling FUNCTION: unsubscribeInputChanges","color: green;"),Object.keys(this.inputChangeSubscriptionMap).forEach(e=>{this.inputChangeSubscriptionMap[e]?.subscriptions?.forEach(r=>{r.unsubscribe()})}),this.inputChangeSubscriptionMap={}}catch(e){this.loggingService.catch("Error in LiveStateService unsubscribeInputChanges: ",e)}}setLiveStateSyncInputData(e,t){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: setLiveStateSyncInputData","color: green;"),this.user&&this.documentPaths?.liveState){let r=this.domService.getXPath(e),a=yt(r),s={id:a,lastUpdated:this.timestamp,liveStateDataId:r,data:t,updatedBy:this.user,tabId:this.tabId};this.commonDbService.updateData({feature:"liveStateAutoSyncStateCurrent",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0},data:JSON.parse(JSON.stringify(s))}),this.commonDbService.updateData({feature:"liveStateAutoSyncStateHistoryId",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",id:a,skipFirestore:!0},data:JSON.parse(JSON.stringify(s))})}}catch(r){this.loggingService.catch("Error in LiveStateService setLiveStateSyncInputData: ",r)}}updateLiveStateSyncInputDataLocally(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: updateLiveStateSyncInputDataLocally","color: green;"),this.user&&Object.keys(e).forEach(t=>{let r=e[t],a=this.domService.getElementFromXPath(r?.liveStateDataId),s=!1;if(r?.updatedBy?.userSnippylyId!==this.user?.userSnippylyId)s=!0;else{let c=r?.tabId&&this.tabId&&r?.tabId!==this.tabId,p=a?.contains(document.activeElement);c&&!Bae()&&!p&&(s=!0)}if(s&&a)switch(a.value=r?.data?.value,a.tagName?.toLowerCase()){case"input":a.value=r?.data?.value;break;case"textarea":a.value=r?.data?.value;break;default:a.getAttribute("contenteditable")&&(a.innerHTML=this.domService.sanitizeHtml(r?.data?.innerHTML))}})}catch(t){this.loggingService.catch("Error in LiveStateService updateLiveStateSyncInputDataLocally: ",t)}}setSingleEditorModeContainerIds(e){this.singleEditorModeContainerIds$.next(e||[])}getSingleEditorModeContainerIds(){return this.singleEditorModeContainerIds$.asObservable()}isElementInsideSingleEditorModeContainerElements(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: isElementInsideSingleEditorModeContainerElements","color: green;");let t=this.singleEditorModeContainerIds$.value,r=document.querySelectorAll(`[${j.ATTRIBUTES.VELT_SINGLE_EDITOR_MODE_CONTAINER}]`);if(!t?.length&&!r?.length)return!0;if(t?.length)for(let a=0;a<t.length;a++){let s=document.getElementById(t[a]);if(s&&s.contains(e))return!0}if(r?.length)for(let a=0;a<r.length;a++){let s=r[a];if(s&&s.contains(e))return!0}return!1}catch(t){return this.loggingService.catch("Error in LiveStateService isElementInsideSingleEditorModeContainerElements: ",t),!1}}isSingleEditorModeDisabledForElement(e){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: isSingleEditorModeDisabledForElement","color: green;"),e){if(e.getAttribute(j.ATTRIBUTES.VELT_SYNC_ACCESS_DISABLED))return!0;{let r=e?.parentElement;if(r)return this.isSingleEditorModeDisabledForElement(r)}}return!1}catch(t){return this.loggingService.catch("Error in LiveStateService isSingleEditorModeDisabledForElement: ",t),!1}}updateOnDatabaseDisconnect(){return this.loggingService.log("%c[WB] Calling FUNCTION: updateOnDatabaseDisconnect","color: green;"),this.isUserEditor$().pipe(sn(e=>{try{if(this.documentPaths?.liveStateSingleEditorMode){let t=Mi(this.db,`${this.documentPaths?.liveStateSingleEditorMode}`);e?.isEditor&&(!this.getSingleEditorModeConfig()?.singleTabEditor||e?.isEditorOnCurrentTab)?il(t).remove():il(t).cancel()}}catch(t){this.loggingService.catch("Error in LiveStateService updateOnDatabaseDisconnect tap: ",t)}}))}updateServerStateOnDatabaseDisconnect(){return this.loggingService.log("%c[WB] Calling FUNCTION: updateServerStateOnDatabaseDisconnect","color: green;"),Qn(this.afAuth).pipe(Le(e=>!!e),he(e=>this.docService.getDocumentPaths$().pipe(de(t=>e))),sn(e=>Q(this,null,function*(){try{if(this.docService.getDocumentPaths()?.liveState&&e){let r=Mi(this.db,".info/connected"),a=!0;jp(r,s=>{let c=s.val();if(a&&c===!1){a=!1;return}a=!1,c===!1?this.serverConnectionState$.next(al.OFFLINE):this.serverConnectionState$.value===al.OFFLINE&&this.serverConnectionState$.next(al.ONLINE)})}}catch(t){this.loggingService.catch("Error in updateServerStateOnDatabaseDisconnect:",t)}})))}signOutUser(e){return new Promise((t,r)=>{try{this.documentPaths?.liveStateSingleEditorMode&&e?this.commonDbService.getData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId,organizationId:this.documentPaths?.organizationId,skipFirestore:!0}}).then(a=>{a&&this.isUserEditor()?.isEditor&&(!this.getSingleEditorModeConfig()?.singleTabEditor||this.isUserEditor()?.isEditorOnCurrentTab)&&this.removeEditorAccess({metadata:{from:"signOutUser-liveStateService",reason:"User signed out"}}),t(null)}).catch(a=>{this.loggingService.catch("Error in signOutUser subscription: ",a),r(a)}):t(null)}catch(a){this.loggingService.catch("Error in signOutUser:",a),r(a)}})}getSemStats(){try{let e=!!this.authService?.getUser(),t=!!this.docService?.getDocumentPaths(),r=this.singleEditorMode$.value,a=!!this.singleEditorModeConfig$.value,s=this.isUserEditor(),c;this.singleEditorLiveStateData$.value&&typeof this.singleEditorLiveStateData$.value=="object"&&(c=this.liveStateUtilsService?.formatLiveStateSingleEditorModeData(JSON.parse(JSON.stringify(this.singleEditorLiveStateData$.value))));let p=this.getExternalUserPresence();return{userAvailable:e,documentPathsAvailable:t,singleEditorModeEnabled:r,singleEditorModeConfig:a,isEditor:s,singleEditorLiveStateData:c,userPresence:p}}catch(e){this.loggingService.catch("Error in LiveStateService getSemStats: ",e)}}get timestamp(){return this.commonDbService.getServerTimestamp()}};o.\u0275fac=function(t){return new(t||o)(J(Pi),J(et),J(Ve),J(kt),J(yn),J(it),J(Be),J(Ide),J(Sn),J(y),J(an),J(h9),J(Yk),J(kn),J(Ede))},o.\u0275prov=Ae({token:o,factory:o.\u0275fac,providedIn:"root"});let i=o;return i})();var f9=class extends ci{constructor(o){super(o),this.getService(y).log("%c[WB] Creating CLASS: LiveStateElement","color: blue;"),this.getLiveStateData$=this._getLiveStateData,this.getLiveStateData=this._getLiveStateData,this.setLiveStateData=this._setLiveStateData,this.enableSingleEditorMode=this._enableSingleEditorMode,this.disableSingleEditorMode=this._disableSingleEditorMode,this.isUserEditor$=this._isUserEditor,this.isUserEditor=this._isUserEditor,this.getEditor=this._getEditor,this.setUserAsEditor=this._setUserAsEditor,this.resetUserAccess=this._resetUserAccess,this.singleEditorModeContainerIds=this._singleEditorModeContainerIds,this.enableAutoSyncState=this._enableAutoSyncState,this.disableAutoSyncState=this._disableAutoSyncState,this.requestEditorAccess=this._requestEditorAccess,this.isEditorAccessRequested=this._isEditorAccessRequested,this.acceptEditorAccessRequest=this._acceptEditorAccessRequest,this.rejectEditorAccessRequest=this._rejectEditorAccessRequest,this.cancelEditorAccessRequest=this._cancelEditorAccessRequest,this.editCurrentTab=this._editCurrentTab,this.setEditorAccessTimeout=this._setEditorAccessTimeout,this.enableEditorAccessTransferOnTimeOut=this._enableEditorAccessTransferOnTimeOut,this.disableEditorAccessTransferOnTimeOut=this._disableEditorAccessTransferOnTimeOut,this.enableDefaultSingleEditorUI=this._enableDefaultSingleEditorUI,this.disableDefaultSingleEditorUI=this._disableDefaultSingleEditorUI,this.getEditorAccessTimer=this._getEditorAccessTimer,this.onServerConnectionStateChange=this._onServerConnectionStateChange,this.updateUserPresence=this._updateUserPresence,this.enableHeartbeat=this._enableHeartbeat,this.disableHeartbeat=this._disableHeartbeat,this.on=this._on}_getLiveStateData(o,n){this.getService(y).log("%c[WB] Calling FUNCTION: getLiveStateData","color: green;");try{return this.trackEvent(Z.Events.LiveStateSync.GET_LIVE_STATE_DATA_TRIGGERED),this.getService(ji).getLiveStateData$(o,n)}catch(e){return this.getService(y).catch("Error in _getLiveStateData: ",e),se(null)}}_setLiveStateData(o,n,e){this.getService(y).log("%c[WB] Calling FUNCTION: setLiveStateData","color: green;");try{return this.getService(ji).setLiveStateData(o,n,e)}catch(t){return this.getService(y).catch("Error in _setLiveStateData: ",t),Promise.resolve()}}_enableSingleEditorMode(o){this.getService(y).log("%c[WB] Calling FUNCTION: enableSingleEditorMode","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.ENABLE_SINGLE_EDITOR_MODE_TRIGGERED),this.getService(ji).enableSingleEditorMode(o)}catch(n){this.getService(y).catch("Error in _enableSingleEditorMode: ",n)}}_disableSingleEditorMode(){this.getService(y).log("%c[WB] Calling FUNCTION: disableSingleEditorMode","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.DISABLE_SINGLE_EDITOR_MODE_TRIGGERED),this.getService(ji).disableSingleEditorMode()}catch(o){this.getService(y).catch("Error in _disableSingleEditorMode: ",o)}}_isUserEditor(){this.getService(y).log("%c[WB] Calling FUNCTION: isUserEditor$","color: green;");try{return this.trackEvent(Z.Events.LiveStateSync.IS_USER_EDITOR_TRIGGERED),this.getService(ji).isUserEditor$()}catch(o){return this.getService(y).catch("Error in _isUserEditor$: ",o),se(null)}}_getEditor(){this.getService(y).log("%c[WB] Calling FUNCTION: getEditor","color: green;");try{return this.trackEvent(Z.Events.LiveStateSync.GET_EDITOR_TRIGGERED),this.getService(ji).getEditor$()}catch(o){return this.getService(y).catch("Error in _getEditor: ",o),se(null)}}_setUserAsEditor(){this.getService(y).log("%c[WB] Calling FUNCTION: setUserAsEditor","color: green;");try{return this.trackEvent(Z.Events.LiveStateSync.SET_USER_AS_EDITOR_TRIGGERED),this.getService(ji).setUserAsEditor()}catch(o){return this.getService(y).catch("Error in _setUserAsEditor: ",o),Promise.resolve()}}_resetUserAccess(){this.getService(y).log("%c[WB] Calling FUNCTION: resetUserAccess","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.RESET_USER_ACCESS_TRIGGERED),this.getService(ji).removeEditorAccess({metadata:{from:"resetUserAccess-liveStateSyncElement",reason:"Client called"}})}catch(o){this.getService(y).catch("Error in _resetUserAccess: ",o)}}_singleEditorModeContainerIds(o){this.getService(y).log("%c[WB] Calling FUNCTION: singleEditorModeContainerIds","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.SINGLE_EDITOR_MODE_CONTAINER_IDS_TRIGGERED),this.getService(ji).setSingleEditorModeContainerIds(o)}catch(n){this.getService(y).catch("Error in _singleEditorModeContainerIds: ",n)}}_enableAutoSyncState(){this.getService(y).log("%c[WB] Calling FUNCTION: enableAutoSyncState","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.ENABLE_AUTO_SYNC_STATE_TRIGGERED),this.getService(ji).enableAutoSyncState()}catch(o){this.getService(y).catch("Error in _enableAutoSyncState: ",o)}}_disableAutoSyncState(){this.getService(y).log("%c[WB] Calling FUNCTION: disableAutoSyncState","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.DISABLE_AUTO_SYNC_STATE_TRIGGERED),this.getService(ji).disableAutoSyncState()}catch(o){this.getService(y).catch("Error in _disableAutoSyncState: ",o)}}_requestEditorAccess(){this.getService(y).log("%c[WB] Calling FUNCTION: requestEditorAccess","color: green;");try{return this.trackEvent(Z.Events.LiveStateSync.REQUEST_EDITOR_ACCESS_TRIGGERED),this.getService(ji).requestEditorAccess()}catch(o){return this.getService(y).catch("Error in _requestEditorAccess: ",o),se(null)}}_isEditorAccessRequested(){this.getService(y).log("%c[WB] Calling FUNCTION: isEditorAccessRequested","color: green;");try{return this.trackEvent(Z.Events.LiveStateSync.IS_EDITOR_ACCESS_REQUESTED_TRIGGERED),this.getService(ji).isEditorAccessRequested$()}catch(o){return this.getService(y).catch("Error in _isEditorAccessRequested: ",o),se(null)}}_acceptEditorAccessRequest(){this.getService(y).log("%c[WB] Calling FUNCTION: acceptEditorAccessRequest","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.ACCEPT_EDITOR_ACCESS_REQUEST_TRIGGERED),this.getService(ji).acceptEditorAccessRequest()}catch(o){this.getService(y).catch("Error in _acceptEditorAccessRequest: ",o)}}_rejectEditorAccessRequest(){this.getService(y).log("%c[WB] Calling FUNCTION: rejectEditorAccessRequest","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.REJECT_EDITOR_ACCESS_REQUEST_TRIGGERED),this.getService(ji).rejectEditorAccessRequest()}catch(o){this.getService(y).catch("Error in _rejectEditorAccessRequest: ",o)}}_cancelEditorAccessRequest(){this.getService(y).log("%c[WB] Calling FUNCTION: cancelEditorAccessRequest","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.CANCEL_EDITOR_ACCESS_REQUEST_TRIGGERED),this.getService(ji).cancelEditorAccessRequest()}catch(o){this.getService(y).catch("Error in _cancelEditorAccessRequest: ",o)}}_editCurrentTab(){this.getService(y).log("%c[WB] Calling FUNCTION: editCurrentTab","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.EDIT_CURRENT_TAB_TRIGGERED),this.getService(ji).editCurrentTab()}catch(o){this.getService(y).catch("Error in _editCurrentTab: ",o)}}_setEditorAccessTimeout(o){this.getService(y).log("%c[WB] Calling FUNCTION: setEditorAccessTimeout","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.SET_EDITOR_ACCESS_TIMEOUT_TRIGGERED),this.getService(ji).setEditorAccessTimeout(o)}catch(n){this.getService(y).catch("Error in _setEditorAccessTimeout: ",n)}}_enableEditorAccessTransferOnTimeOut(){this.getService(y).log("%c[WB] Calling FUNCTION: enableEditorAccessTransferOnTimeOut","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.ENABLE_EDITOR_ACCESS_TRANSFER_ON_TIMEOUT_TRIGGERED),this.getService(ji).enableEditorAccessTransferOnTimeOut()}catch(o){this.getService(y).catch("Error in _enableEditorAccessTransferOnTimeOut: ",o)}}_disableEditorAccessTransferOnTimeOut(){this.getService(y).log("%c[WB] Calling FUNCTION: disableEditorAccessTransferOnTimeOut","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.DISABLE_EDITOR_ACCESS_TRANSFER_ON_TIMEOUT_TRIGGERED),this.getService(ji).disableEditorAccessTransferOnTimeOut()}catch(o){this.getService(y).catch("Error in _disableEditorAccessTransferOnTimeOut: ",o)}}_enableDefaultSingleEditorUI(){this.getService(y).log("%c[WB] Calling FUNCTION: enableDefaultSingleEditorUI","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.ENABLE_DEFAULT_SINGLE_EDITOR_UI_TRIGGERED),this.getService(ji).enableDefaultSingleEditorUI()}catch(o){this.getService(y).catch("Error in _enableDefaultSingleEditorUI: ",o)}}_disableDefaultSingleEditorUI(){this.getService(y).log("%c[WB] Calling FUNCTION: disableDefaultSingleEditorUI","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.DISABLE_DEFAULT_SINGLE_EDITOR_UI_TRIGGERED),this.getService(ji).disableDefaultSingleEditorUI()}catch(o){this.getService(y).catch("Error in _disableDefaultSingleEditorUI: ",o)}}_getEditorAccessTimer(){this.getService(y).log("%c[WB] Calling FUNCTION: getEditorAccessTimer","color: green;");try{return this.trackEvent(Z.Events.LiveStateSync.GET_EDITOR_ACCESS_TIMER_TRIGGERED),this.getService(ji).getEditorAccessTimer$()}catch(o){return this.getService(y).catch("Error in _getEditorAccessTimer: ",o),se(new u0)}}_onServerConnectionStateChange(){this.getService(y).log("%c[WB] Calling FUNCTION: onServerConnectionStateChange","color: green;");try{return this.trackEvent(Z.Events.LiveStateSync.ON_SERVER_CONNECTION_STATE_CHANGE_TRIGGERED),this.getService(ji).onServerConnectionStateChange$()}catch(o){return this.getService(y).catch("Error in _onServerConnectionStateChange: ",o),se(al.PENDING_INIT)}}_updateUserPresence(o){this.getService(y).log("%c[WB] Calling FUNCTION: updateUserPresence","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.UPDATE_USER_PRESENCE_TRIGGERED,{payload:{userPresence:o}}),this.getService(ji).updateExternalUserPresence(o)}catch(n){this.getService(y).catch("Error in _updateUserPresence: ",n)}}_enableHeartbeat(){this.getService(y).log("%c[WB] Calling FUNCTION: enableHeartbeat","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.ENABLE_HEARTBEAT_TRIGGERED),this.getService(ji).enableHeartbeat()}catch(o){this.getService(y).catch("Error in _enableHeartbeat: ",o)}}_disableHeartbeat(){this.getService(y).log("%c[WB] Calling FUNCTION: disableHeartbeat","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.DISABLE_HEARTBEAT_TRIGGERED),this.getService(ji).disableHeartbeat()}catch(o){this.getService(y).catch("Error in _disableHeartbeat: ",o)}}_on(o){this.getService(y).log("%c[WB] Calling FUNCTION: on","color: green;");try{return this.trackEvent(Z.Events.LiveStateSync.ON_ACTION_TRIGGERED,{payload:{action:o}}),this.getService(h9).onAction(o)}catch(n){return this.getService(y).catch("Error in _on: ",n),se(null)}}};var v9=(()=>{let o=class o{constructor(e){this.loggingService=e,this.actionSubjects=new Map,this.defaultSource="internal",this.isUserAdmin=!1,this.subscriptions=[],this.loggingService.log("%c[WB] Creating CLASS: CommentActionsService","color: blue;")}triggerSettingsUpdatedEvent(e){try{this.triggerAction(uae.SETTINGS_UPDATED,e)}catch(t){this.loggingService.catch("Error in NotificationsActionsService triggerAddCommentAnnotationEvent: ",t)}}triggerAction(e,t){try{this.actionSubjects.has(e)||this.actionSubjects.set(e,new tt),this.actionSubjects.get(e)?.next(t)}catch(r){this.loggingService.catch("Error in NotificationsActionsService triggerAction: ",r)}}onAction(e){try{return this.actionSubjects.has(e)||this.actionSubjects.set(e,new tt),this.actionSubjects.get(e)?.asObservable()}catch(t){return this.loggingService.catch("Error in NotificationsActionsService onAction: ",t),se(null)}}};o.\u0275fac=function(t){return new(t||o)(J(y))},o.\u0275prov=Ae({token:o,factory:o.\u0275fac,providedIn:"root"});let i=o;return i})();var C9=class extends ci{constructor(o){super(o),this.getService(y).log("%c[WB] Creating CLASS: ViewsElement","color: blue;"),this.openHistoryPanel=this._openHistoryPanel,this.closeHistoryPanel=this._closeHistoryPanel,this.toggleHistoryPanel=this._toggleHistoryPanel,this.getNotificationsData=this._getNotificationsData,this.setMaxDays=this._setMaxDays,this.setTabConfig=this._setTabConfig,this.enableReadNotificationsOnForYouTab=this._enableReadNotificationsOnForYouTab,this.disableReadNotificationsOnForYouTab=this._disableReadNotificationsOnForYouTab,this.setAllNotificationsAsRead=this._setAllNotificationsAsRead,this.getUnreadNotificationsCount=this._getUnreadNotificationsCount,this.markNotificationAsReadById=this._markNotificationAsReadById,this.setSettings=this._setSettings,this.getSettings=this._getSettings,this.muteAllNotifications=this._muteAllNotifications,this.enableSettings=this._enableSettings,this.enableSelfNotifications=this._enableSelfNotifications,this.disableSelfNotifications=this._disableSelfNotifications,this.disableSettings=this._disableSettings,this.setSettingsInitialConfig=this._setSettingsInitialConfig,this.openNotificationsPanel=this._openNotificationsPanel,this.closeNotificationsPanel=this._closeNotificationsPanel,this.enableCurrentDocumentOnly=this._enableCurrentDocumentOnly,this.disableCurrentDocumentOnly=this._disableCurrentDocumentOnly,this.on=this._on}_openHistoryPanel(){this.getService(y).log("%c[WB] Calling FUNCTION: _openHistoryPanel","color: green;");try{this.trackEvent(Z.Events.Notifications.OPEN_HISTORY_PANEL_TRIGGERED),this.getService(pn).setHistoryPanelVisibility(!0,!0)}catch(o){this.getService(y).catch("Error in openHistoryPanel: ",o)}}_closeHistoryPanel(){this.getService(y).log("%c[WB] Calling FUNCTION: _closeHistoryPanel","color: green;");try{this.trackEvent(Z.Events.Notifications.CLOSE_HISTORY_PANEL_TRIGGERED),this.getService(pn).setHistoryPanelVisibility(!1,!0)}catch(o){this.getService(y).catch("Error in closeHistoryPanel: ",o)}}_toggleHistoryPanel(){this.getService(y).log("%c[WB] Calling FUNCTION: _toggleHistoryPanel","color: green;");try{this.trackEvent(Z.Events.Notifications.TOGGLE_HISTORY_PANEL_TRIGGERED),this.getService(pn).toggleHistoryPanelVisibility(!0)}catch(o){this.getService(y).catch("Error in toggleHistoryPanel: ",o)}}_getNotificationsData(o){this.getService(y).log("%c[WB] Calling FUNCTION: _getNotificationsData","color: green;");try{return this.trackEvent(Z.Events.Notifications.GET_NOTIFICATIONS_DATA_TRIGGERED),this.getService(pn).getNotifications$(o)}catch(n){return this.getService(y).catch("Error in getNotificationsData: ",n),se([])}}_setMaxDays(o){this.getService(y).log("%c[WB] Calling FUNCTION: _setMaxDays","color: green;");try{this.trackEvent(Z.Events.Notifications.SET_MAX_DAYS_TRIGGERED,{payload:{days:o}}),this.getService(pn).setMaxDays(o)}catch(n){this.getService(y).catch("Error in setMaxDays: ",n)}}_setTabConfig(o){this.getService(y).log("%c[WB] Calling FUNCTION: _setTabConfig","color: green;");try{this.trackEvent(Z.Events.Notifications.SET_TAB_CONFIG_TRIGGERED,{payload:{tabConfig:o}}),this.getService(pn).setTabConfig(o)}catch(n){this.getService(y).catch("Error in setTabConfig: ",n)}}_enableReadNotificationsOnForYouTab(){this.getService(y).log("%c[WB] Calling FUNCTION: _enableReadNotificationsOnForYouTab","color: green;");try{this.trackEvent(Z.Events.Notifications.ENABLE_READ_NOTIFICATIONS_ON_FOR_YOU_TAB_TRIGGERED),this.getService(pn).enableReadNotificationsOnForYouTab()}catch(o){this.getService(y).catch("Error in enableReadNotificationsOnForYouTab: ",o)}}_disableReadNotificationsOnForYouTab(){this.getService(y).log("%c[WB] Calling FUNCTION: _disableReadNotificationsOnForYouTab","color: green;");try{this.trackEvent(Z.Events.Notifications.DISABLE_READ_NOTIFICATIONS_ON_FOR_YOU_TAB_TRIGGERED),this.getService(pn).disableReadNotificationsOnForYouTab()}catch(o){this.getService(y).catch("Error in disableReadNotificationsOnForYouTab: ",o)}}_setAllNotificationsAsRead(o){this.getService(y).log("%c[WB] Calling FUNCTION: _setAllNotificationsAsRead","color: green;");try{this.trackEvent(Z.Events.Notifications.SET_ALL_NOTIFICATIONS_AS_READ_TRIGGERED,{payload:{config:o}}),this.getService(pn).setAllNotificationsAsRead(o)}catch(n){this.getService(y).catch("Error in setAllNotificationsAsRead: ",n)}}_getUnreadNotificationsCount(){this.getService(y).log("%c[WB] Calling FUNCTION: _getUnreadNotificationsCount","color: green;");try{return this.trackEvent(Z.Events.Notifications.GET_UNREAD_NOTIFICATIONS_COUNT_TRIGGERED),this.getService(pn).getUnreadNotificationsCount$()}catch(o){return this.getService(y).catch("Error in getUnreadNotificationsCount: ",o),se({forYou:null,all:null})}}_markNotificationAsReadById(o){this.getService(y).log("%c[WB] Calling FUNCTION: _markNotificationAsReadById","color: green;");try{this.trackEvent(Z.Events.Notifications.MARK_NOTIFICATION_AS_READ_BY_ID_TRIGGERED,{payload:{notificationId:o}}),this.getService(pn).markNotificationAsReadById(o)}catch(n){this.getService(y).catch("Error in markNotificationAsReadById: ",n)}}_setSettings(o){this.getService(y).log("%c[WB] Calling FUNCTION: _setSettings","color: green;");try{this.trackEvent(Z.Events.Notifications.SET_SETTINGS_TRIGGERED,{payload:{config:o}}),this.getService(pn).setSettingsConfigWithDB(o)}catch(n){this.getService(y).catch("Error in setSettings: ",n)}}_getSettings(){this.getService(y).log("%c[WB] Calling FUNCTION: _getSettings","color: green;");try{return this.trackEvent(Z.Events.Notifications.GET_SETTINGS_TRIGGERED),this.getService(pn).getSettingsConfig$()}catch(o){return this.getService(y).catch("Error in getSettings: ",o),se(null)}}_muteAllNotifications(){this.getService(y).log("%c[WB] Calling FUNCTION: _muteAllNotifications","color: green;");try{this.trackEvent(Z.Events.Notifications.MUTE_ALL_NOTIFICATIONS_TRIGGERED),this.getService(pn).setMuteAllNotifications()}catch(o){this.getService(y).catch("Error in muteAllNotifications: ",o)}}_enableSettings(){this.getService(y).log("%c[WB] Calling FUNCTION: _enableSettings","color: green;");try{this.trackEvent(Z.Events.Notifications.ENABLE_SETTINGS_TRIGGERED),this.getService(pn).enableSettings()}catch(o){this.getService(y).catch("Error in enableSettings: ",o)}}_enableSelfNotifications(){this.getService(y).log("%c[WB] Calling FUNCTION: _enableSelfNotifications","color: green;");try{this.trackEvent(Z.Events.Notifications.ENABLE_SELF_NOTIFICATIONS_TRIGGERED),this.getService(pn).enableSelfNotifications()}catch(o){this.getService(y).catch("Error in enableSelfNotifications: ",o)}}_disableSelfNotifications(){this.getService(y).log("%c[WB] Calling FUNCTION: _disableSelfNotifications","color: green;");try{this.trackEvent(Z.Events.Notifications.DISABLE_SELF_NOTIFICATIONS_TRIGGERED),this.getService(pn).disableSelfNotifications()}catch(o){this.getService(y).catch("Error in disableSelfNotifications: ",o)}}_disableSettings(){this.getService(y).log("%c[WB] Calling FUNCTION: _disableSettings","color: green;");try{this.trackEvent(Z.Events.Notifications.DISABLE_SETTINGS_TRIGGERED),this.getService(pn).disableSettings()}catch(o){this.getService(y).catch("Error in disableSettings: ",o)}}_setSettingsInitialConfig(o){this.getService(y).log("%c[WB] Calling FUNCTION: _setSettingsInitialConfig","color: green;");try{this.trackEvent(Z.Events.Notifications.SET_SETTINGS_INITIAL_CONFIG_TRIGGERED,{payload:{settings:o}}),this.getService(pn).setSettingsInitialConfig(o)}catch(n){this.getService(y).catch("Error in setSettingsInitialConfig: ",n)}}_on(o){this.getService(y).log("%c[WB] Calling FUNCTION: on","color: green;");try{return this.trackEvent(Z.Events.Notifications.ON_ACTION_TRIGGERED,{payload:{action:o}}),this.getService(v9).onAction(o)}catch(n){return this.getService(y).catch("Error in _on: ",n),se(null)}}_openNotificationsPanel(){this.getService(y).log("%c[WB] Calling FUNCTION: _openNotificationsPanel","color: green;");try{this.trackEvent(Z.Events.Notifications.OPEN_NOTIFICATIONS_PANEL_TRIGGERED),this.getService(pn).openNotificationsPanel()}catch(o){this.getService(y).catch("Error in openNotificationsPanel: ",o)}}_closeNotificationsPanel(){this.getService(y).log("%c[WB] Calling FUNCTION: _closeNotificationsPanel","color: green;");try{this.trackEvent(Z.Events.Notifications.CLOSE_NOTIFICATIONS_PANEL_TRIGGERED),this.getService(pn).closeNotificationsPanel()}catch(o){this.getService(y).catch("Error in closeNotificationsPanel: ",o)}}_enableCurrentDocumentOnly(){this.getService(y).log("%c[WB] Calling FUNCTION: _enableCurrentDocumentOnly","color: green;");try{this.trackEvent(Z.Events.Notifications.ENABLE_CURRENT_DOCUMENT_ONLY_TRIGGERED),this.getService(pn).enableCurrentDocumentOnly()}catch(o){this.getService(y).catch("Error in enableCurrentDocumentOnly: ",o)}}_disableCurrentDocumentOnly(){this.getService(y).log("%c[WB] Calling FUNCTION: _disableCurrentDocumentOnly","color: green;");try{this.trackEvent(Z.Events.Notifications.DISABLE_CURRENT_DOCUMENT_ONLY_TRIGGERED),this.getService(pn).disableCurrentDocumentOnly()}catch(o){this.getService(y).catch("Error in disableCurrentDocumentOnly: ",o)}}};var Xz=(()=>{let o=class o{constructor(e,t,r){this.analyticsService=e,this.loggingService=t,this.presenceService=r,this.actionSubjects=new Map,this.subscriptions=[];try{this.presenceService.setPresenceActionsService(this)}catch(a){this.loggingService.catch("Error in PresenceActionsService constructor: ",a)}}onMultipleUsersOnline(e){try{this.loggingService.log("%c[WB] Calling PresenceActionsService FUNCTION: onMultipleUsersOnline","color: green;"),this.triggerAction(jj.MULTIPLE_USERS_ONLINE,e),this.analyticsService.trackEvent(Z.Events.Presence.MULTIPLE_USERS_ONLINE,{totalUsers:e?.users?.length,presenceSnippylyUserIds:e?.users?.map(t=>t.userSnippylyId),presenceClientUserIds:e?.users?.map(t=>t.userId)})}catch(t){this.loggingService.catch("Error in PresenceActionsService onMultipleUsersOnline: ",t)}}onUserStateChange(e){try{this.loggingService.log("%c[WB] Calling PresenceActionsService FUNCTION: onUserStateChange","color: green;"),this.triggerAction(jj.USER_STATE_CHANGE,e),this.analyticsService.trackEvent(Z.Events.Presence.ON_USER_STATE_CHANGE,{userSnippylyId:e?.user?.userSnippylyId,userId:e?.user?.userId,state:e?.state})}catch(t){this.loggingService.catch("Error in PresenceActionsService onUserStateChange: ",t)}}getData(e){try{return this.loggingService.log("%c[WB] Calling PresenceActionsService FUNCTION: getData","color: green;"),this.presenceService.getOnlineUsersOnCurrentDocument(e).pipe(de(t=>({data:t})))}catch(t){return this.loggingService.catch("Error in PresenceActionsService getData: ",t),se({data:null})}}triggerAction(e,t){try{this.actionSubjects.has(e)||this.actionSubjects.set(e,new tt),this.actionSubjects.get(e)?.next(t)}catch(r){this.loggingService.catch("Error in PresenceActionsService triggerAction: ",r)}}onAction(e){try{return this.actionSubjects.has(e)||this.actionSubjects.set(e,new tt),this.actionSubjects.get(e)?.asObservable()}catch(t){return this.loggingService.catch("Error in PresenceActionsService onAction: ",t),se(null)}}};o.\u0275fac=function(t){return new(t||o)(J(et),J(y),J(Wl))},o.\u0275prov=Ae({token:o,factory:o.\u0275fac,providedIn:"root"});let i=o;return i})();var _9=class extends ci{constructor(o){super(o),this.getService(y).log("%c[WB] Creating CLASS: PresenceElement","color: blue;"),this.getOnlineUsersOnCurrentDocument=this._getOnlineUsersOnCurrentDocument,this.setInactivityTime=this._setInactivityTime,this.enableFlockMode=this._enableFlockMode,this.disableFlockMode=this._disableFlockMode,this.startFollowingUser=this._startFollowingUser,this.stopFollowingUser=this._stopFollowingUser,this.enableSelf=this._enableSelf,this.disableSelf=this._disableSelf,this.getData=this._getData,this.on=this._on}_getOnlineUsersOnCurrentDocument(){this.getService(y).log("%c[WB] Calling FUNCTION: getOnlineUsers","color: green;");try{return this.trackEvent(Z.Events.Presence.GET_ONLINE_USERS_ON_CURRENT_DOCUMENT_TRIGGERED),this.getService(Wl).getOnlineUsersOnCurrentDocument()}catch(o){return this.getService(y).catch("Error in _getOnlineUsersOnCurrentDocument: ",o),se(null)}}_setInactivityTime(o){this.getService(y).log("%c[WB] Calling FUNCTION: _setInactivityTime","color: green;");try{this.trackEvent(Z.Events.Presence.SET_INACTIVITY_TIME_TRIGGERED,{payload:{time:o}}),isNaN(o)?this.getService(y).catch("Error in setInactivityTime: ","Provided value is not a number."):this.getService(Wl).setInactivityTime(o)}catch(n){this.getService(y).catch("Error in setInactivityTime: ",n)}}_disableFlockMode(){try{this.trackEvent(Z.Events.Presence.DISABLE_FLOCK_MODE_TRIGGERED),this.getService(Gc).disableFlockMode()}catch(o){this.getService(y).catch("Error in _disableFlockMode: ",o)}}_enableFlockMode(o){try{this.trackEvent(Z.Events.Presence.ENABLE_FLOCK_MODE_TRIGGERED,{payload:{options:o}}),this.getService(Gc).enableFlockMode(o)}catch(n){this.getService(y).catch("Error in _enableFlockMode: ",n)}}_stopFollowingUser(){try{this.trackEvent(Z.Events.Presence.STOP_FOLLOWING_USER_TRIGGERED),this.getService(Gc).stopFollowingUser()}catch(o){this.getService(y).catch("Error in _stopFollowingUser: ",o)}}_startFollowingUser(o){try{this.trackEvent(Z.Events.Presence.START_FOLLOWING_USER_TRIGGERED,{payload:{externalId:o}});let n=this.getService(Wl).getPresenceUserFromExternalId(o);return n&&n.userSnippylyId&&n.name!==void 0?(this.getService(Gc).startFollowingUser(n.userSnippylyId,n.name),{success:!0,msg:"Joined flock session."}):{success:!1,msg:"User could not be found."}}catch(n){return this.getService(y).catch("Error in _startFollowingUser: ",n),{success:!1,msg:"Unknown error.",raw:n}}}_enableSelf(){try{this.trackEvent(Z.Events.Presence.ENABLE_SELF_TRIGGERED),this.getService(Wl).enableIncludeSelf()}catch(o){this.getService(y).catch("Error in _enableSelf: ",o)}}_disableSelf(){try{this.trackEvent(Z.Events.Presence.DISABLE_SELF_TRIGGERED),this.getService(Wl).disableIncludeSelf()}catch(o){this.getService(y).catch("Error in _disableSelf: ",o)}}_getData(o){this.getService(y).log("%c[WB] Calling FUNCTION: getData","color: green;");try{return this.trackEvent(Z.Events.Presence.GET_PRESENCE_DATA_TRIGGERED,{payload:{query:o}}),o&&typeof o=="object"&&(o=I({},o),o?.documentId&&(o.documentId=ia(o.documentId)),o?.organizationId&&(o.organizationId=Ua(o.organizationId))),this.getService(Xz).getData(o)}catch(n){return this.getService(y).catch("Error in _getData: ",n),se({data:null})}}_on(o){this.getService(y).log("%c[WB] Calling FUNCTION: on","color: green;");try{return this.trackEvent(Z.Events.Presence.ON_ACTION_TRIGGERED,{payload:{action:o}}),this.getService(Xz).onAction(o)}catch(n){return this.getService(y).catch("Error in _on: ",n),se(null)}}};var y9=class extends ci{constructor(o){super(o),this.getService(y).log("%c[WB] Creating CLASS: ReactionElement","color: blue;"),this.enableDarkMode=this._enableDarkMode,this.disableDarkMode=this._disableDarkMode,this.setCustomReactions=this._setCustomReactions}_enableDarkMode(){this.getService(y).log("%c[WB] Calling FUNCTION: enableDarkMode","color: green;");try{this.trackEvent(Z.Events.Reactions.ENABLE_DARK_MODE_TRIGGERED),this.getService(ar).enableDarkMode()}catch(o){this.getService(y).catch("Error in _enableDarkMode: ",o)}}_disableDarkMode(){this.getService(y).log("%c[WB] Calling FUNCTION: disableDarkMode","color: green;");try{this.trackEvent(Z.Events.Reactions.DISABLE_DARK_MODE_TRIGGERED),this.getService(ar).disableDarkMode()}catch(o){this.getService(y).catch("Error in _disableDarkMode: ",o)}}_setCustomReactions(o){this.getService(y).log("%c[WB] Calling FUNCTION: setCustomReactions","color: green;");try{this.trackEvent(Z.Events.Reactions.SET_CUSTOM_REACTIONS_TRIGGERED,{payload:{reactions:o}}),this.getService(ar).setCustomReactions(o)}catch(n){this.getService(y).catch("Error in _setCustomReactions: ",n)}}};var hg=(()=>{let o=class o{constructor(e,t,r){this.loggingService=e,this.recorderAnnotationService=t,this.recorderService=r,this.actionSubjects=new Map,this.subscriptions=[];try{this.recorderAnnotationService.setRecorderActionsService(this),this.recorderService.setRecorderActionsService(this)}catch(a){this.loggingService.catch("Error in RecorderActionsService constructor: ",a)}}onTranscriptionDone(e){try{this.triggerAction(Vl.TRANSCRIPTION_DONE,e)}catch(t){this.loggingService.catch("Error in RecorderActionsService onTranscriptionDone: ",t)}}onRecordingDone(e){try{this.triggerAction(Vl.RECORDING_DONE,e)}catch(t){this.loggingService.catch("Error in RecorderActionsService onRecordingDone: ",t)}}onRecordingEditDone(e){try{this.triggerAction(Vl.RECORDING_EDIT_DONE,e)}catch(t){this.loggingService.catch("Error in RecorderActionsService onRecordingEditDone: ",t)}}onRecordingStarted(e){try{this.triggerAction(Vl.RECORDING_STARTED,e)}catch(t){this.loggingService.catch("Error in RecorderActionsService onRecordingStarted: ",t)}}onRecordingPaused(e){try{this.triggerAction(Vl.RECORDING_PAUSED,e)}catch(t){this.loggingService.catch("Error in RecorderActionsService onRecordingPaused: ",t)}}onRecordingCancelled(e){try{this.triggerAction(Vl.RECORDING_CANCELLED,e)}catch(t){this.loggingService.catch("Error in RecorderActionsService onRecordingCancelled: ",t)}}onRecordingStopped(e){try{this.triggerAction(Vl.RECORDING_STOPPED,e)}catch(t){this.loggingService.catch("Error in RecorderActionsService onRecordingStopped: ",t)}}onRecordingResumed(e){try{this.triggerAction(Vl.RECORDING_RESUMED,e)}catch(t){this.loggingService.catch("Error in RecorderActionsService onRecordingResumed: ",t)}}onDeleteRecording(e){try{this.triggerAction(Vl.DELETE_RECORDING,e)}catch(t){this.loggingService.catch("Error in RecorderActionsService onDeleteRecording: ",t)}}onError(e){try{this.triggerAction(Vl.ERROR,e)}catch(t){this.loggingService.catch("Error in RecorderActionsService onError: ",t)}}onRecordingSaveInitiated(e){try{this.triggerAction(Vl.RECORDING_SAVE_INITIATED,e)}catch(t){this.loggingService.catch("Error in RecorderActionsService onRecordingSaveInitiated: ",t)}}triggerAction(e,t){try{this.actionSubjects.has(e)||this.actionSubjects.set(e,new tt),this.actionSubjects.get(e)?.next(t)}catch(r){this.loggingService.catch("Error in RecorderActionsService triggerAction: ",r)}}onAction(e){try{return this.actionSubjects.has(e)||this.actionSubjects.set(e,new tt),this.actionSubjects.get(e)?.asObservable()}catch(t){return this.loggingService.catch("Error in RecorderActionsService onAction: ",t),se(null)}}};o.\u0275fac=function(t){return new(t||o)(J(y),J(Ki),J(_n))},o.\u0275prov=Ae({token:o,factory:o.\u0275fac,providedIn:"root"});let i=o;return i})();var S9=class extends ci{constructor(o){super(o),this.getService(y).log("%c[WB] Creating CLASS: RecorderElement","color: blue;"),this.initRecording=this._initRecording,this.onRecordedData=this._onRecordedData,this.enableDarkMode=this._enableDarkMode,this.disableDarkMode=this._disableDarkMode,this.enableRecordingCountdown=this._enableRecordingCountdown,this.disableRecordingCountdown=this._disableRecordingCountdown,this.getRecordingDataByRecorderId=this._getRecordingDataByRecorderId,this.enableRecordingTranscription=this._enableRecordingTranscription,this.disableRecordingTranscription=this._disableRecordingTranscription,this.getRecordingData=this._getRecordingData,this.enableVideoEditor=this._enableVideoEditor,this.disableVideoEditor=this._disableVideoEditor,this.getRecordings=this._getRecordings,this.fetchRecordings=this._fetchRecordings,this.deleteRecordings=this._deleteRecordings,this.setRecordingQualityConstraints=this._setRecordingQualityConstraints,this.setRecordingEncodingOptions=this._setRecordingEncodingOptions,this.downloadLatestVideo=this._downloadLatestVideo,this.enableRecordingMic=this._enableRecordingMic,this.disableRecordingMic=this._disableRecordingMic,this.enableOnboardingTooltip=this._enableOnboardingTooltip,this.disableOnboardingTooltip=this._disableOnboardingTooltip,this.enableRetakeOnVideoEditor=this._enableRetakeOnVideoEditor,this.disableRetakeOnVideoEditor=this._disableRetakeOnVideoEditor,this.askDevicePermission=this._askDevicePermission,this.setMaxLength=this._setMaxLength,this.openPictureInPicture=this._openPictureInPicture,this.exitPictureInPicture=this._exitPictureInPicture,this.requestScreenPermission=this._requestScreenPermission,this.enablePictureInPicture=this._enablePictureInPicture,this.disablePictureInPicture=this._disablePictureInPicture,this.enablePlaybackOnPreviewClick=this._enablePlaybackOnPreviewClick,this.disablePlaybackOnPreviewClick=this._disablePlaybackOnPreviewClick,this.on=this._on}_initRecording(o,n){this.getService(y).log("%c[WB] Calling FUNCTION: initRecording","color: green;");try{return this.trackEvent(Z.Events.Recording.INIT_RECORDING_TRIGGERED,{payload:{type:o,panelId:n}}),this.getService(_n).initRecording(o,n)}catch(e){return this.getService(y).catch("Error in _initRecording: ",e),se(null)}}_onRecordedData(){this.getService(y).log("%c[WB] Calling FUNCTION: onRecordedData","color: green;");try{return this.trackEvent(Z.Events.Recording.ON_RECORDED_DATA_TRIGGERED),this.getService(_n).onRecordedData()}catch(o){return this.getService(y).catch("Error in _onRecordedData: ",o),se(null)}}_enableDarkMode(){this.getService(y).log("%c[WB] Calling FUNCTION: enableDarkMode","color: green;");try{this.trackEvent(Z.Events.Recording.ENABLE_DARK_MODE_TRIGGERED),this.getService(Ki).setRecorderContainerDarkMode(!0)}catch(o){this.getService(y).catch("Error in _enableDarkMode: ",o)}}_disableDarkMode(){this.getService(y).log("%c[WB] Calling FUNCTION: disableDarkMode","color: green;");try{this.trackEvent(Z.Events.Recording.DISABLE_DARK_MODE_TRIGGERED),this.getService(Ki).setRecorderContainerDarkMode(!1)}catch(o){this.getService(y).catch("Error in _disableDarkMode: ",o)}}_enableRecordingCountdown(){this.getService(y).log("%c[WB] Calling FUNCTION: enableRecordingCountdown","color: green;");try{this.trackEvent(Z.Events.Recording.ENABLE_RECORDING_COUNTDOWN_TRIGGERED),this.getService(_n).enableRecordingCountdown()}catch(o){this.getService(y).catch("Error in _enableRecordingCountdown: ",o)}}_disableRecordingCountdown(){this.getService(y).log("%c[WB] Calling FUNCTION: disableRecordingCountdown","color: green;");try{this.trackEvent(Z.Events.Recording.DISABLE_RECORDING_COUNTDOWN_TRIGGERED),this.getService(_n).disableRecordingCountdown()}catch(o){this.getService(y).catch("Error in _disableRecordingCountdown: ",o)}}_getRecordingDataByRecorderId(o){this.getService(y).log("%c[WB] Calling FUNCTION: getRecordingDataByRecorderId","color: green;");try{return this.trackEvent(Z.Events.Recording.GET_RECORDING_DATA_BY_RECORDER_ID_TRIGGERED,{payload:{recorderId:o}}),this.getService(Ki).getRecorderDataByRecorderId(o)}catch(n){return this.getService(y).catch("Error in _getRecordingDataByRecorderId: ",n),se(null)}}_getRecordings(o){this.getService(y).log("%c[WB] Calling FUNCTION: getRecordings","color: green;");try{return this.trackEvent(Z.Events.Recording.GET_RECORDINGS_TRIGGERED,{payload:{query:o}}),this.getService(Ki).getRecordings(o)}catch(n){return this.getService(y).catch("Error in _getRecordings: ",n),se([])}}_getRecordingData(o){this.getService(y).log("%c[WB] Calling FUNCTION: getRecordingData","color: green;");try{return this.trackEvent(Z.Events.Recording.GET_RECORDING_DATA_TRIGGERED,{payload:{query:o}}),this.getService(Ki).getRecorderDataByRecorderIds(o)}catch(n){return this.getService(y).catch("Error in _getRecordingData: ",n),Promise.resolve({data:null})}}_fetchRecordings(o){this.getService(y).log("%c[WB] Calling FUNCTION: fetchRecordings","color: green;");try{return this.trackEvent(Z.Events.Recording.FETCH_RECORDINGS_TRIGGERED,{payload:{query:o}}),this.getService(Ki).fetchRecorderDataByRecorderIds(o)}catch(n){return this.getService(y).catch("Error in _fetchRecordings: ",n),Promise.resolve([])}}_deleteRecordings(o){this.getService(y).log("%c[WB] Calling FUNCTION: deleteRecording","color: green;");try{return this.trackEvent(Z.Events.Recording.DELETE_RECORDING_TRIGGERED,{payload:{query:o}}),this.getService(Ki).deleteRecorderDataByRecorderIds(o)}catch(n){return this.getService(y).catch("Error in _deleteRecording: ",n),Promise.resolve([])}}_enableRecordingTranscription(){this.getService(y).log("%c[WB] Calling FUNCTION: enableRecordingTranscription","color: green;");try{this.trackEvent(Z.Events.Recording.ENABLE_RECORDING_TRANSCRIPTION_TRIGGERED),this.getService(Ki).enableRecordingTranscription()}catch(o){this.getService(y).catch("Error in _enableRecordingTranscription: ",o)}}_disableRecordingTranscription(){this.getService(y).log("%c[WB] Calling FUNCTION: disableRecordingTranscription","color: green;");try{this.trackEvent(Z.Events.Recording.DISABLE_RECORDING_TRANSCRIPTION_TRIGGERED),this.getService(Ki).disableRecordingTranscription()}catch(o){this.getService(y).catch("Error in _disableRecordingTranscription: ",o)}}_on(o){this.getService(y).log("%c[WB] Calling FUNCTION: on","color: green;");try{return this.trackEvent(Z.Events.Recording.ON_ACTION_TRIGGERED,{payload:{action:o}}),this.getService(hg).onAction(o)}catch(n){return this.getService(y).catch("Error in _on: ",n),se(null)}}_enableVideoEditor(){this.getService(y).log("%c[WB] Calling FUNCTION: enableVideoEditor","color: green;");try{this.trackEvent(Z.Events.Recording.ENABLE_VIDEO_EDITOR_TRIGGERED),this.getService(_n).enableVideoEditor()}catch(o){this.getService(y).catch("Error in _enableVideoEditor: ",o)}}_disableVideoEditor(){this.getService(y).log("%c[WB] Calling FUNCTION: disableVideoEditor","color: green;");try{this.trackEvent(Z.Events.Recording.DISABLE_VIDEO_EDITOR_TRIGGERED),this.getService(_n).disableVideoEditor()}catch(o){this.getService(y).catch("Error in _disableVideoEditor: ",o)}}_setRecordingQualityConstraints(o){this.getService(y).log("%c[WB] Calling FUNCTION: setRecordingQualityConstraints","color: green;");try{this.trackEvent(Z.Events.Recording.SET_RECORDING_QUALITY_CONSTRAINTS_TRIGGERED,{payload:{constraints:o}}),this.getService(_n).setRecordingQualityConstraints(o)}catch(n){this.getService(y).catch("Error in _setRecordingQualityConstraints: ",n)}}_setRecordingEncodingOptions(o){this.getService(y).log("%c[WB] Calling FUNCTION: setRecordingEncodingOptions","color: green;");try{this.trackEvent(Z.Events.Recording.SET_RECORDING_ENCODING_OPTIONS_TRIGGERED,{payload:{options:o}}),this.getService(_n).setRecordingEncodingOptions(o)}catch(n){this.getService(y).catch("Error in _setRecordingEncodingOptions: ",n)}}_downloadLatestVideo(o){this.getService(y).log("%c[WB] Calling FUNCTION: downloadLatestVideo","color: green;");try{return this.trackEvent(Z.Events.Recording.DOWNLOAD_LATEST_VIDEO_TRIGGERED,{payload:{recorderId:o}}),this.getService(Ki).downloadLatestVideo(o)}catch(n){return this.getService(y).catch("Error in _downloadLatestVideo: ",n),Promise.resolve(!1)}}_enableRecordingMic(){this.getService(y).log("%c[WB] Calling FUNCTION: enableRecordingMic","color: green;");try{this.trackEvent(Z.Events.Recording.ENABLE_RECORDING_MIC_TRIGGERED),this.getService(_n).enableRecordingMic()}catch(o){this.getService(y).catch("Error in _enableRecordingMic: ",o)}}_disableRecordingMic(){this.getService(y).log("%c[WB] Calling FUNCTION: disableRecordingMic","color: green;");try{this.trackEvent(Z.Events.Recording.DISABLE_RECORDING_MIC_TRIGGERED),this.getService(_n).disableRecordingMic()}catch(o){this.getService(y).catch("Error in _disableRecordingMic: ",o)}}_enableOnboardingTooltip(){this.getService(y).log("%c[WB] Calling FUNCTION: enableOnboardingTooltip","color: green;");try{this.trackEvent(Z.Events.Recording.ENABLE_ONBOARDING_TOOLTIP_TRIGGERED),this.getService(_n).enableOnboardingTooltip()}catch(o){this.getService(y).catch("Error in _enableOnboardingTooltip: ",o);return}}_disableOnboardingTooltip(){this.getService(y).log("%c[WB] Calling FUNCTION: disableOnboardingTooltip","color: green;");try{this.trackEvent(Z.Events.Recording.DISABLE_ONBOARDING_TOOLTIP_TRIGGERED),this.getService(_n).disableOnboardingTooltip()}catch(o){this.getService(y).catch("Error in _disableOnboardingTooltip: ",o);return}}_enableRetakeOnVideoEditor(){this.getService(y).log("%c[WB] Calling FUNCTION: enableRetakeOnVideoEditor","color: green;");try{this.trackEvent(Z.Events.Recording.ENABLE_RETAKE_ON_VIDEO_EDITOR_TRIGGERED),this.getService(_n).enableRetakeOnVideoEditor()}catch(o){this.getService(y).catch("Error in _enableRetakeOnVideoEditor: ",o)}}_disableRetakeOnVideoEditor(){this.getService(y).log("%c[WB] Calling FUNCTION: disableRetakeOnVideoEditor","color: green;");try{this.trackEvent(Z.Events.Recording.DISABLE_RETAKE_ON_VIDEO_EDITOR_TRIGGERED),this.getService(_n).disableRetakeOnVideoEditor()}catch(o){this.getService(y).catch("Error in _disableRetakeOnVideoEditor: ",o)}}_askDevicePermission(o){this.getService(y).log("%c[WB] Calling FUNCTION: askDevicePermission","color: green;");try{this.trackEvent(Z.Events.Recording.ASK_DEVICE_PERMISSION_TRIGGERED),this.getService(_n).askDevicePermission(o)}catch(n){this.getService(y).catch("Error in _askDevicePermission: ",n)}}_setMaxLength(o){this.getService(y).log("%c[WB] Calling FUNCTION: setMaxLength","color: green;");try{this.trackEvent(Z.Events.Recording.SET_MAX_LENGTH_TRIGGERED,{payload:{seconds:o}}),this.getService(_n).setMaxRecordingLength(o)}catch(n){this.getService(y).catch("Error in _setMaxLength: ",n)}}_openPictureInPicture(){return Q(this,null,function*(){this.getService(y).log("%c[WB] Calling FUNCTION: openPictureInPicture","color: green;");try{this.trackEvent(Z.Events.Recording.OPEN_PICTURE_IN_PICTURE_TRIGGERED),yield this.getService(_n).openPictureInPicture()}catch(o){this.getService(y).catch("Error in _openPictureInPicture: ",o)}})}_exitPictureInPicture(){return Q(this,null,function*(){this.getService(y).log("%c[WB] Calling FUNCTION: exitPictureInPicture","color: green;");try{this.trackEvent(Z.Events.Recording.EXIT_PICTURE_IN_PICTURE_TRIGGERED),yield this.getService(Ga).exitPictureInPicture()}catch(o){this.getService(y).catch("Error in _exitPictureInPicture: ",o)}})}_requestScreenPermission(){return Q(this,null,function*(){this.getService(y).log("%c[WB] Calling FUNCTION: requestScreenPermission","color: green;");try{return this.trackEvent(Z.Events.Recording.REQUEST_SCREEN_PERMISSION_TRIGGERED),this.getService(_n).requestScreenPermission()}catch(o){return this.getService(y).catch("Error in _requestScreenPermission: ",o),null}})}_enablePictureInPicture(){this.getService(y).log("%c[WB] Calling FUNCTION: enablePictureInPicture","color: green;");try{this.trackEvent(Z.Events.Recording.ENABLE_PICTURE_IN_PICTURE_TRIGGERED),this.getService(Ga).enablePictureInPicture()}catch(o){this.getService(y).catch("Error in _enablePictureInPicture: ",o)}}_disablePictureInPicture(){this.getService(y).log("%c[WB] Calling FUNCTION: disablePictureInPicture","color: green;");try{this.trackEvent(Z.Events.Recording.DISABLE_PICTURE_IN_PICTURE_TRIGGERED),this.getService(Ga).disablePictureInPicture()}catch(o){this.getService(y).catch("Error in _disablePictureInPicture: ",o)}}_enablePlaybackOnPreviewClick(){this.getService(y).log("%c[WB] Calling FUNCTION: enablePlaybackOnPreviewClick","color: green;");try{this.trackEvent(Z.Events.Recording.ENABLE_PLAYBACK_ON_PREVIEW_CLICK_TRIGGERED),this.getService(_n).enablePlaybackOnPreviewClick()}catch(o){this.getService(y).catch("Error in _enablePlaybackOnPreviewClick: ",o)}}_disablePlaybackOnPreviewClick(){this.getService(y).log("%c[WB] Calling FUNCTION: disablePlaybackOnPreviewClick","color: green;");try{this.trackEvent(Z.Events.Recording.DISABLE_PLAYBACK_ON_PREVIEW_CLICK_TRIGGERED),this.getService(_n).disablePlaybackOnPreviewClick()}catch(o){this.getService(y).catch("Error in _disablePlaybackOnPreviewClick: ",o)}}};var Wc=(()=>{let o=class o{constructor(e,t,r,a,s,c){this.analyticsService=e,this.authService=t,this.configService=r,this.domService=a,this.loggingService=s,this.functions=c,this.rewriterAnnotations$=new ve([]),this.rewriterOptions$=new ve({}),this.rewriterEnabled$=new ve(!1),this.lastOpenAIPromptCalledAt=0,this.getRewriterEnabled$().subscribe(p=>{try{if(p){let g=document.querySelectorAll(j.TAGS.SNIPPYLY_REWRITER);if(!document.querySelectorAll(j.TAGS.VELT_REWRITER)?.length&&!g?.length){let E=document.createElement(j.TAGS.VELT_REWRITER);document.body.appendChild(E),this.authService.getUser$().pipe(Le(D=>!!D),at(1)).subscribe(D=>{this.analyticsService.trackEvent(Z.Events.Rewriter.REWRITER_ENABLED,{isMobileDevice:this.domService.isMobileDevice()})})}}else{let g=document.querySelectorAll(j.TAGS.SNIPPYLY_REWRITER);g?.length&&g.forEach(E=>{E.remove()});let C=document.querySelectorAll(j.TAGS.VELT_REWRITER);C?.length&&C.forEach(E=>{E.remove()})}}catch(g){this.loggingService.catch("Error in rewriterEnabled$: ",g)}},p=>{this.loggingService.catch("Error in rewriterEnabled$ subscription: ",p)})}getRewriterAnnotations$(){try{return this.rewriterAnnotations$.asObservable()}catch(e){return this.loggingService.catch("Error in getRewriterAnnotations$(): ",e),se([])}}addRewriter(e,t,r){this.loggingService.log("%c[WB] Calling FUNCTION: addRewriter","color: green;");try{let a=this.authService.getUser();if(a)if(a.isReadOnly||a.isAnonymous)this.loggingService.catch("Anonymous/Readonly users cannot add rewriters.");else{let s=new Fk;s.from=a,s.color=j.DEFAULT_ANNOTATION_COLOR,t&&(s.targetTextRange=t),r&&(s.rewriterType=r),this.saveRewriterToDb(s)}}catch(a){this.loggingService.catch("Error in RewriterService addRewriter: ",a)}}saveRewriterToDb(e){this.loggingService.log("%c[WB] Calling FUNCTION: saveRewriterToDb","color: green;");try{e?.annotationId||(e.annotationId=Math.random().toString(36).substring(2)+Date.now().toString(36));let t=this.rewriterAnnotations$.getValue();t.push(e),this.rewriterAnnotations$.next(t),this.domService.toggleAnnotationSelection(e)}catch(t){this.loggingService.catch("Error in RewriterService saveRewriterToDb: ",t)}}removeRewriter(e){try{let t=this.rewriterAnnotations$.getValue(),r=t.findIndex(a=>a.annotationId===e.annotationId);r>-1&&(t.splice(r,1),this.rewriterAnnotations$.next(t))}catch(t){this.loggingService.catch("Error in RewriterService removeRewriter: ",t)}}getRewriterOptions(e,t,r){try{if(this.lastOpenAIPromptCalledAt&&Date.now()-this.lastOpenAIPromptCalledAt<1e3)return this.lastOpenAIPromptCalledAt=Date.now(),se([]);this.lastOpenAIPromptCalledAt=Date.now();let a=br(this.functions,Er({url:ri.cloudFunction.chatgptCompletion,apiProxyDomain:this.configService?.getApiProxyDomain()}),{timeout:20*60*1e3}),s=t?.[0]?.role==="system"?t?.[0]?.content:null;return this.analyticsService.trackEvent(Z.Events.Rewriter.REWRITE_PROMPT_SUBMITTED,{isMobileDevice:this.domService.isMobileDevice(),prompt:s,type:e}),Zi(a({messages:t,type:e,apiKey:this.configService.getApiKey(),sdkVersion:oa(),sdkType:this.configService.getSdkType()})).pipe(de(c=>c?.data?c.data:[]))}catch(a){return this.loggingService.catch("Error in RewriterService getRewriterOptions: ",a),se([])}}enableRewriter(){try{this.rewriterEnabled$.next(!0)}catch(e){this.loggingService.catch("Error in RewriterService enableRewriter: ",e)}}disableRewriter(){try{this.rewriterEnabled$.next(!1)}catch(e){this.loggingService.catch("Error in RewriterService disableRewriter: ",e)}}getRewriterEnabled$(){try{return this.rewriterEnabled$.asObservable()}catch(e){return this.loggingService.catch("Error in RewriterService getRewriterEnabled$: ",e),se(!1)}}resetRewriter(){try{this.domService.resetSelectedAnnotationsMap(!1,"rewriter"),this.rewriterAnnotations$.next([])}catch(e){this.loggingService.catch("Error in RewriterService resetRewriter: ",e)}}getChatGPTInput(e,t,r=[]){try{let a="";return e&&(a=`
|
|
487
|
+
`;if(typeof Worker<"u"){let r=new Blob([t],{type:"application/javascript"});return new Worker(URL.createObjectURL(r))}return}catch(t){this.loggingService.catch("Error in HeartbeatService setupWebWorker: ",t);return}}setupHeartbeat(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: setupHeartbeat","color: green;"),this.worker=this.setupWebWorker(this.HEARTBEAT_DURATION),this.worker){this.worker.onmessage=()=>{this.authService.getUser()&&this.sendHeartbeat()};let t=this.authService.getUser$().subscribe(r=>{r?(this.worker?.postMessage("start"),this.sendHeartbeat()):this.worker?.postMessage("stop")});this.subscriptions.push(t)}else{let t=this.authService.getUser$().pipe(he(r=>r?hm(this.HEARTBEAT_DURATION).pipe(Qi(0)):_l)).subscribe(()=>this.sendHeartbeat());this.subscriptions.push(t)}this.docService.getDocumentPaths$().pipe(Le(t=>!!t),sn(()=>this.sendHeartbeat())).subscribe();let e=vn([this.databaseService.getDb().pipe(Le(t=>!!t)),this.authService.getUser$(),this.docService.getDocumentPaths$()]).pipe(Di(),sn(([[t,r,a],[s,c,p]])=>{if(c&&p){let g=this.domService.getTabId();if(g){let C=this.generateHeartbeatId(c.userId,g),E={id:C,organizationId:p.organizationId},D=this.commonDbUtils.getDocumentPath({feature:"heartbeat",properties:E,defaultDocumentPaths:p,apiKey:this.configService.getApiKey(),useFirestore:!1});if(D&&s&&il(Mi(s,D)).set(null),p.documentId){let L={id:C,documentId:p.documentId,organizationId:p.organizationId},z=this.commonDbUtils.getDocumentPath({feature:"heartbeatByDocument",properties:L,defaultDocumentPaths:p,apiKey:this.configService.getApiKey(),useFirestore:!1});z&&s&&il(Mi(s,z)).set(null)}if(a&&a.documentId&&a.documentId!==p.documentId){let L={id:C,documentId:a.documentId,organizationId:a.organizationId,skipFirestore:!0};this.commonDbService.deleteData({feature:"heartbeatByDocument",properties:L})}}}})).subscribe();this.subscriptions.push(e)}catch(e){this.loggingService.catch("Error in HeartbeatService setupHeartbeat: ",e)}}teardownHeartbeat(){try{this.loggingService.log("%c[WB] Calling FUNCTION: teardownHeartbeat","color: green;"),this.worker&&(this.worker.postMessage("stop"),this.worker.terminate(),this.worker=void 0),this.subscriptions.forEach(e=>e.unsubscribe()),this.subscriptions=[]}catch(e){this.loggingService.catch("Error in HeartbeatService teardownHeartbeat: ",e)}}sendHeartbeat(){try{this.loggingService.log("%c[WB] Calling HeartbeatService FUNCTION: sendHeartbeat","color: green;");let e=this.authService.getUser(),t=this.docService.getDocumentPaths(),r=this.domService.getTabId();if(e&&t&&r){let a=Date.now(),s={id:this.generateHeartbeatId(e.userId,r),createdTimestamp:a,lastUpdatedTimestamp:a,userId:e.userId,veltUserId:yt(e.userId),tabId:r,metadata:this.docService.getBaseMetadata()},p=s.metadata.documentId;this.commonDbService.updateData({feature:"heartbeat",properties:{id:s.id,skipFirestore:!0,rtdbTransaction:!0,rtdbTransactionCallback:(g,C)=>(g?.createdTimestamp&&(C.createdTimestamp=g.createdTimestamp),C)},data:s}),p&&this.commonDbService.updateData({feature:"heartbeatByDocument",properties:{id:s.id,skipFirestore:!0,rtdbTransaction:!0,documentId:p,rtdbTransactionCallback:(g,C)=>(g?.createdTimestamp&&(C.createdTimestamp=g.createdTimestamp),C)},data:s})}}catch(e){this.loggingService.catch("Error in HeartbeatService sendHeartbeat: ",e)}}generateHeartbeatId(e,t){return yt(e+"_"+t)}getHeartbeatData(e){try{let t=this.docService.getDocumentPaths(),r=e?.organizationId||t?.organizationId,a=e?.documentId,s,c={organizationId:r,skipFirestore:!0,useQuery:!0};if(a?(s="allHeartbeatsByDocument",c.documentId=a):s="allHeartbeats",!t)return se(null);let p=e?.orderBy??"lastUpdatedTimestamp",g=e?.lastUpdatedTimestamp?.$gte??Date.now()-15e3,C=e?.limit??50;return c.rtdbQuery=[Lm(p),Bm(g),lS(C)],this.commonDbService.dbListener({feature:s,properties:c}).pipe(Le(E=>!!E?.data),de(E=>E?.data),de(E=>E?Object.values(E??{}).map(D=>D):null))}catch(t){return this.loggingService.catch("Error in HeartbeatService getHeartbeatData: ",t),se(null)}}getSpecificHeartbeat(e){try{let t=this.generateHeartbeatId(e.userId,e.tabId),a=this.docService.getDocumentPaths()?.organizationId;if(!a)return se(null);let s,c={id:t,organizationId:a,skipFirestore:!0};return e.documentId?(s="heartbeatByDocument",c.documentId=e.documentId):s="heartbeat",this.commonDbService.dbListener({feature:s,properties:c}).pipe(Le(p=>!!p?.data),de(p=>p?.data),St((p,g)=>p?.lastUpdatedTimestamp===g?.lastUpdatedTimestamp))}catch(t){return this.loggingService.catch("Error in HeartbeatService getSpecificHeartbeat: ",t),se(null)}}removeDocumentHeartbeat(e){return Q(this,null,function*(){try{let t=this.authService.getUser()?.userId,r=this.domService.getTabId();if(t&&r&&e?.documentId){let a=this.generateHeartbeatId(t,r);yield this.commonDbService.deleteData({feature:"heartbeatByDocument",properties:{id:a,documentId:e.documentId,organizationId:e.organizationId,skipFirestore:!0}})}return Promise.resolve()}catch(t){return this.loggingService.catch("Error in HeartbeatService removeDocumentHeartbeat: ",t),Promise.resolve()}})}enableHeartbeat(){try{if(this.heartbeatEnabled$.value===!0)return;this.heartbeatEnabled$.next(!0)}catch(e){this.loggingService.catch("Error in HeartbeatService enableHeartbeat: ",e)}}disableHeartbeat(){try{if(this.heartbeatEnabled$.value===!1)return;this.heartbeatEnabled$.next(!1)}catch(e){this.loggingService.catch("Error in HeartbeatService disableHeartbeat: ",e)}}getHeartbeatEnabled$(){try{return this.heartbeatEnabled$.asObservable()}catch(e){return this.loggingService.catch("Error in HeartbeatService getHeartbeatEnabled$: ",e),se(!1)}}getHeartbeatEnabled(){try{return this.heartbeatEnabled$.value}catch(e){return this.loggingService.catch("Error in HeartbeatService getHeartbeatEnabled: ",e),!1}}ngOnDestroy(){try{this.teardownHeartbeat()}catch(e){this.loggingService.catch("Error in HeartbeatService ngOnDestroy: ",e)}}};o.\u0275fac=function(t){return new(t||o)(J(Ve),J(an),J(yn),J(it),J(Be),J(y),J(Gl),J(Gd),J(kt))},o.\u0275prov=Ae({token:o,factory:o.\u0275fac,providedIn:"root"});let i=o;return i})();var Ede=(()=>{let o=class o{constructor(e,t,r,a){this.authService=e,this.domService=t,this.loggingService=r,this.usersService=a}findOldestActiveSessionFromHeartbeats(e){try{if(!e||e.length===0)return null;let t=this.authService.getUser(),r=this.domService.getTabId(),a=e.filter(p=>p.lastUpdatedTimestamp>Date.now()-1e4);return a.length===0?null:[...a].sort((p,g)=>p.createdTimestamp-g.createdTimestamp)[0]??null}catch(t){return this.loggingService.catch("Error in findOldestActiveSessionFromHeartbeats: ",t),null}}determineEditorStatus(e){return Q(this,null,function*(){try{let{singleEditorModeData:t,heartbeatData:r,externalUserPresence:a,currentUser:s,currentTabId:c}=e,p=JSON.parse(JSON.stringify(t||{})),g={steps:[],timestamp:Date.now()},C=()=>Q(this,null,function*(){let z=a?.userIds?.[0],W;z&&(yield this.usersService.resolveUsers({userIds:[z],forceResolve:!0}),W=this.usersService.getUserById(z)),W?(p.editor=W,p.tabId=`differentUserPresentOnTab_${c}`):(p.editor={userId:`anonymous_${s?.userId}`,name:"Anonymous"},p.tabId=`differentUserPresentOnTab_${c}`)}),E=()=>{p.editor=s,p.tabId=`sameUserPresentOnTab_${c}`},D=!1;if(t?.editor){if(g.steps?.push("SingleEditorModeData: Editor is available."),r?.length){g.steps?.push("Heartbeat data is available.");let z=r?.find(W=>W.userId===t?.editor?.userId&&W.tabId===t?.tabId);if(z&&z.lastUpdatedTimestamp>Date.now()-1e4)g.steps?.push("Editor user heartbeat is recent.");else{g.steps?.push("Editor user heartbeat is not available or not recent.");let W=this.findOldestActiveSessionFromHeartbeats(r);W&&W.userId===s.userId&&W.tabId===c?(g.steps?.push("Current user is the oldest active session."),D=!0):g.steps?.push("Current user is not the oldest active session.")}}!r?.length&&!a&&g.steps?.push("No heartbeat data and no external user presence is available.")}else{if(g.steps?.push("SingleEditorModeData: Editor not available."),r?.length){g.steps?.push("Heartbeat data is available.");let z=this.findOldestActiveSessionFromHeartbeats(r);z&&z.userId===s.userId&&z.tabId===c?(g.steps?.push("Current user is the oldest active session."),D=!0):g.steps?.push("Current user is not the oldest active session.")}else a&&(g.steps?.push("External user presence is available."),a.differentUserPresentOnTab?(g.steps?.push("External user presence: Different user is present on the tab."),yield C(),D=!1):a.sameUserPresentOnTab?(g.steps?.push("External user presence: Same user is present on the tab."),E(),D=!1):(g.steps?.push("External user presence: No user is present on the tab."),D=!0));!r?.length&&!a&&(g.steps?.push("No heartbeat data and no external user presence is available."),D=!0)}let L;return D?L={shouldSetUndefined:!0}:L={data:p},g.singleEditorModeData=t,g.singleEditorModeDataEditorAvailable=!!t?.editor,g.heartbeatData=r,g.externalUserPresence=a,g.currentUser=s,g.currentTabId=c,g.returnValue=L,g.shouldSetUndefined=D,g.steps?.push("Execution completed."),g=this.cleanStats(g),T(I({},L),{stats:g})}catch(t){return this.loggingService.catch("Error in determineEditorStatus: ",t),{data:e?.singleEditorModeData??void 0}}})}cleanStats(e){try{let t=e&&typeof e=="object"?JSON.parse(JSON.stringify(e)):e;return t?.singleEditorModeData?.editor&&(t.singleEditorModeData=T(I({},t.singleEditorModeData),{editor:{userId:t.singleEditorModeData?.editor?.userId}})),t?.returnValue?.data?.editor&&(t.returnValue.data=T(I({},t.returnValue.data),{editor:{userId:t.returnValue.data?.editor?.userId}})),t}catch{return e}}};o.\u0275fac=function(t){return new(t||o)(J(Ve),J(Be),J(y),J(kn))},o.\u0275prov=Ae({token:o,factory:o.\u0275fac,providedIn:"root"});let i=o;return i})();var ji=(()=>{let o=class o{constructor(e,t,r,a,s,c,p,g,C,E,D,L,z,W,ee){this.afAuth=e,this.analyticsService=t,this.authService=r,this.configService=a,this.databaseService=s,this.docService=c,this.domService=p,this.heartbeatService=g,this.iamService=C,this.loggingService=E,this.commonDbService=D,this.liveStateActionsService=L,this.liveStateUtilsService=z,this.usersService=W,this.singleEditorDecisionEngine=ee,this.db=os(),this.liveStateAutoSyncStateData$=new ve(null),this.liveStateDataMapDraft={},this.singleEditorMode$=new ve(!1),this.singleEditorModeConfig$=new ve(null),this.singleEditorLiveStateData$=new ve(null),this.singleEditorLiveStateData={},this.editorAccessTimeout$=new ve(j.LIVE_STATE_REQUEST_EDITOR_ACCESS_WAIT_TIME),this.editorAccessTransferOnTimeOut$=new ve(!0),this.defaultSingleEditorUIEnabled$=new ve(!0),this.editorAccessTimer$=new ve(new u0),this.autoSyncState$=new ve(!1),this.serverConnectionState$=new ve(al.PENDING_INIT),this.externalUserPresence$=new ve(null),this.heartbeat$=new ve(!0),this.user=null,this.keydownSubscription=null,this.isEditor$=new ve(null),this.preventEventsOnElementMap={},this.PREVENT_EVENTS=["click","mouseup","mousedown"],this.autoSyncStateHistory=null,this.singleEditorModeContainerIds$=new ve([]),this.inputChangeSubscriptionMap={},this.childListMutationSubscription=null,this.tabId=this.domService.getTabId(),this.heartbeatRestart$=new ve(void 0);try{this.loggingService.log("%c[WB] Creating CLASS: LiveStateService","color: blue;"),this.analyticsService.setLiveStateService(this),vn([this.getSingleEditorMode$(),this.heartbeat$]).subscribe(([le,ye])=>{le&&ye?this.heartbeatService.enableHeartbeat():this.heartbeatService.disableHeartbeat()}),this.databaseService.getDb().pipe(Le(le=>!!le),at(1)).subscribe(le=>{le&&(this.db=le,this.getUser(),this.getDocumentPaths(),this.subscribeLiveStateData().subscribe(),this.subscribeAutoSyncState().subscribe(),this.singleEditorMode$.subscribe(ye=>{ye&&this.detectKeydownOnInput()}),this.autoSyncState$.subscribe(ye=>{ye?(this.detectLiveSyncInputs(),this.observeElementAddedOnDom()):(this.unsubscribeInputChanges(),this.childListMutationSubscription?.unsubscribe(),this.childListMutationSubscription=null)}),this.updateOnDatabaseDisconnect().subscribe(()=>{},ye=>{this.loggingService.catch("Error in LiveStateService constructor updateOnDatabaseDisconnect: ",ye)}),this.updateServerStateOnDatabaseDisconnect().subscribe(()=>{},ye=>{this.loggingService.catch("Error in LiveStateService constructor updateServerStateOnDatabaseDisconnect: ",ye)}))},le=>{this.loggingService.catch("Error in LiveStateService getDb subscription: ",le)}),this.liveStateAutoSyncStateData$.pipe(Le(le=>Object.keys(le||{}).length>0),St((le,ye)=>JSON.stringify(le||{})===JSON.stringify(ye||{}))).subscribe(le=>{le&&(this.getAutoSyncState()&&(!this.autoSyncStateHistory&&le?.history&&this.updateLiveStateSyncInputDataLocally(le.history),le?.current&&this.updateLiveStateSyncInputDataLocally({[le.current.liveStateDataId]:le.current})),!this.autoSyncStateHistory&&le?.history&&(this.autoSyncStateHistory=le.history))}),this.docService.addPreDocumentIdChangeFunction("live-state-service",le=>(this.updateExternalUserPresence(null),this.isUserEditor()?.isEditor&&(!this.getSingleEditorModeConfig()?.singleTabEditor||this.isUserEditor()?.isEditorOnCurrentTab)?this.removeEditorAccess({metadata:{from:"addPreDocumentIdChangeFunction-liveStateService",reason:"Document id changed"},documentPaths:le}):Promise.resolve())),this.authService.addPreSignOutFuction("live-state-signout",this.signOutUser.bind(this)),this.singleEditorLiveStateData$.pipe(Di()).subscribe(([le,ye])=>{try{let Oe=ye?.requestEditorAccess?.status,ze=le?.requestEditorAccess?.status,Ne=this.authService.getUser();if(Oe==="pending"){if(Ne?.userId===ye?.editor?.userId){let Ee={viewer:ya(ye?.requestEditorAccess?.user)??void 0,editor:ya(ye?.editor)??void 0,timestamp:new Date().getTime(),status:"requested"};this.liveStateActionsService?.onAccessRequested(Ee)}return}if(Oe==="cancelled"){if(Ne?.userId===ye?.editor?.userId){let Ee={viewer:ya(ye?.requestEditorAccess?.user)??void 0,editor:ya(ye?.editor)??void 0,timestamp:new Date().getTime(),status:"canceled"};this.liveStateActionsService?.onAccessRequestCanceled(Ee)}return}if(ze==="pending"&&!Oe){if(le?.requestEditorAccess?.user?.userId===ye?.editor?.userId){if(le?.requestEditorAccess?.user?.userId===Ne?.userId){let Ee={viewer:ya(le?.editor)??void 0,editor:ya(ye?.editor)??void 0,timestamp:new Date().getTime(),status:"accepted"};this.liveStateActionsService?.onAccessAccepted(Ee)}return}if(le?.requestEditorAccess?.user?.userId!==ye?.editor?.userId){if(le?.requestEditorAccess?.user?.userId===Ne?.userId){let Ee={viewer:ya(le?.requestEditorAccess?.user)??void 0,editor:ya(ye?.editor)??void 0,timestamp:new Date().getTime(),status:"rejected"};this.liveStateActionsService?.onAccessRejected(Ee)}return}}}catch(Oe){this.loggingService.catch("Error in LiveStateService singleEditorLiveStateData$ subscription: ",Oe)}}),this.isUserEditor$().pipe(St(gn)).subscribe(le=>{try{if(le){this.analyticsService.trackEvent(Z.Events.LiveStateSync.SEM_USER_EDITOR_STATS,{isEditor:le?.isEditor,isEditorOnCurrentTab:le?.isEditorOnCurrentTab});let ye=this.singleEditorLiveStateData$.value;if(le?.isEditor)if(le?.isEditorOnCurrentTab){let Oe={editor:ya(ye?.editor)??void 0,timestamp:new Date().getTime(),role:"editor"};this.liveStateActionsService?.onEditorAssigned(Oe)}else{let Oe={editor:ya(ye?.editor)??void 0,timestamp:new Date().getTime(),role:"editorOnDifferentTab"};this.liveStateActionsService?.onEditorOnDifferentTabDetected(Oe)}else{let Oe={viewer:ya(this.authService.getUser())??void 0,timestamp:new Date().getTime(),role:"viewer"};this.liveStateActionsService?.onViewerAssigned(Oe)}}}catch(ye){this.loggingService.catch("Error in LiveStateService isUserEditor$ subscription: ",ye)}})}catch(le){this.loggingService.catch("Error in LiveStateService constructor: ",le)}}observeElementAddedOnDom(){try{this.loggingService.log("%c[WB] Calling FUNCTION: observeElementAddedOnDom","color: green;"),this.childListMutationSubscription&&(this.childListMutationSubscription.unsubscribe(),this.childListMutationSubscription=null),this.childListMutationSubscription=this.domService.getChildListMutation$().subscribe(e=>{e?.length&&e.forEach(t=>{let r=Array.from(t.addedNodes||[]).filter(a=>a instanceof HTMLElement);r?.forEach(a=>{i$(a,!0)?.forEach(p=>{typeof p?.getAttribute=="function"&&p?.getAttribute(j.ATTRIBUTES.VELT_SYNC_STATE)&&this.subscribeInputChanges(p)})}),r?.length&&this.isEditor$?.value?.isEditor===!1&&(this.disableInputElements(),this.disableElementEvents())})},e=>{this.loggingService.catch("Error in LiveStateService domService getChildListMutation$ subscription: ",e)})}catch(e){this.loggingService.catch("Error in LiveStateService observeElementAddedOnDom: ",e)}}detectKeydownOnInput(){try{this.loggingService.log("%c[WB] Calling FUNCTION: detectKeydownOnInput","color: green;"),this.unsubscribeKeydownSubscription(),this.keydownSubscription=this.domService.onWindowKeydown$().pipe(Le(e=>e?.target instanceof HTMLInputElement||e?.target instanceof HTMLTextAreaElement||e?.target instanceof HTMLSelectElement),Le(e=>!!this.isElementInsideSingleEditorModeContainerElements(e?.target)),at(1)).subscribe(e=>{this.unsubscribeKeydownSubscription(),this.getSingleEditorModeConfig()?.customMode||this.setUserAsEditor({skipEditorCheck:!0})},e=>{this.loggingService.catch("Error in LiveStateService detectKeydownOnInput subscription: ",e)})}catch(e){this.loggingService.catch("Error in LiveStateService detectKeydownOnInput: ",e)}}unsubscribeKeydownSubscription(){try{this.loggingService.log("%c[WB] Calling FUNCTION: unsubscribeKeydownSubscription","color: green;"),this.keydownSubscription&&(this.keydownSubscription.unsubscribe(),this.keydownSubscription=null)}catch(e){this.loggingService.catch("Error in LiveStateService unsubscribeKeydownSubscription: ",e)}}getDocumentPaths(){try{this.loggingService.log("%c[WB] Calling FUNCTION: getDocumentPaths","color: green;"),this.docService.getDocumentPaths$().subscribe(e=>{this.documentPaths=e,this.updateLiveStateDataFromDraft()})}catch(e){this.loggingService.catch("Error in LiveStateService getDocumentPaths: ",e)}}getUser(){try{this.loggingService.log("%c[WB] Calling FUNCTION: getUser","color: green;"),this.authService.getUser$().subscribe(e=>{this.user=e,this.updateLiveStateDataFromDraft()})}catch(e){this.loggingService.catch("Error in LiveStateService getUser: ",e)}}updateLiveStateDataFromDraft(){try{this.loggingService.log("%c[WB] Calling FUNCTION: updateLiveStateDataFromDraft","color: green;"),this.liveStateDataMapDraft?.custom&&this.user&&this.documentPaths&&(Object.keys(this.liveStateDataMapDraft.custom).forEach(e=>{this.setLiveStateData(e,this.liveStateDataMapDraft.custom[e])}),this.liveStateDataMapDraft={})}catch(e){this.loggingService.catch("Error in LiveStateService updateLiveStateDataFromDraft: ",e)}}getActiveHeartbeatStream$(e){return this.heartbeatRestart$.pipe(at(50),he(()=>{let t=this.heartbeatService.getHeartbeatData({documentId:this.documentPaths?.documentId}).pipe(at(1),he(r=>{let a=this.singleEditorDecisionEngine.findOldestActiveSessionFromHeartbeats(r);return a?this.monitorSession$(a.userId,a.tabId):se(null)}));return!e?.userId||!e?.tabId?t:this.heartbeatService.getSpecificHeartbeat({userId:e.userId,tabId:e.tabId,documentId:this.documentPaths?.documentId}).pipe(at(1),he(r=>!r?.id||Date.now()-r?.lastUpdatedTimestamp>1e4?t:this.monitorSession$(e.userId,e.tabId)))}),St((t,r)=>this.isHeartbeatSimilar(t,r)))}monitorSession$(e,t){return this.heartbeatService.getSpecificHeartbeat({userId:e,tabId:t,documentId:this.documentPaths?.documentId}).pipe(he(a=>a?.id?se(a):(this.heartbeatRestart$.next(),_l)),M8({each:1e4,with:()=>(this.heartbeatRestart$.next(),_l)}))}isHeartbeatSimilar(e,t){try{return!e&&!t?!0:!e||!t?!1:e?.userId===t?.userId&&e?.tabId===t?.tabId}catch{return!1}}subscribeLiveStateData(){return this.loggingService.log("%c[WB] Calling FUNCTION: getOnlineUsersOnCurrentDocument","color: green;"),Qn(this.afAuth).pipe(Le(e=>!!e),he(e=>this.isFeatureAllowed({firebaseUser:e,liveStateData:{}})),he(e=>e.featureAllowed?this.iamService.isUserAllowed$().pipe(de(t=>(e.featureAllowed=t,e))):se(e)),he(e=>e.featureAllowed?this.authService.isPlanExpired$().pipe(de(t=>(e.featureAllowed=!t,e))):se(e)),he(e=>e.featureAllowed?se(e).pipe(he(t=>this.docService.getDocumentPaths$().pipe(de(r=>(this.documentPaths=r,t.documentPaths=r,t)))),he(t=>t?.documentPaths?se(t).pipe(sn(r=>{this.serverConnectionState$?.value===al.PENDING_INIT&&r?.documentPaths?.liveState&&this.serverConnectionState$.next(al.PENDING_DATA)}),he(r=>this.domService.onNetworkStatusChange$().pipe(Le(a=>a),de(()=>r))),he(r=>this.getDataFromDocumentId().pipe(de(a=>(r.singleEditorModeData=a,I({},r))))),he(r=>this.getSingleEditorMode$().pipe(de(()=>r))),de(r=>([al.ONLINE,al.OFFLINE].includes(this.serverConnectionState$?.value)||this.serverConnectionState$.next(al.ONLINE),r)),he(r=>this.getSingleEditorMode()?this.getExternalUserPresence$().pipe(de(a=>T(I({},r),{externalUserPresence:a}))):se(r))):se(T(I({},t),{liveStateData:{}}))),he(t=>this.getSingleEditorMode()?this.heartbeatService.getHeartbeatEnabled$().pipe(he(r=>{if(r){let a=t?.singleEditorModeData?.editor,s=t?.singleEditorModeData?.tabId;return this.getActiveHeartbeatStream$({userId:a?.userId,tabId:s}).pipe(de(c=>{let p=c?.id?[c]:null;return T(I({},t),{heartbeatData:p})}))}else return se(T(I({},t),{heartbeatData:null}))})):se(t)),he(t=>{if(this.getSingleEditorMode()){let r=[];if(!(Object.keys(t?.singleEditorModeData||{}).length>0)){let s=this.singleEditorLiveStateData$.value&&typeof this.singleEditorLiveStateData$.value=="object"?JSON.parse(JSON.stringify(this.singleEditorLiveStateData$.value)):this.singleEditorLiveStateData$.value;r.push({eventName:Z.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_EMPTY_DATA_STATS,properties:{previousSingleEditorModeData:s,currentSingleEditorModeData:t?.singleEditorModeData}})}return this.updateSingleEditorLiveSyncData(t?.singleEditorModeData||{},t?.externalUserPresence??null,t?.heartbeatData??null,t,r),se(t)}else return se(t)})):se({})))}updateSingleEditorLiveSyncData(e,t,r,a,s){return Q(this,null,function*(){try{this.loggingService.log("%c[WB] Calling FUNCTION: updateSingleEditorLiveSyncData","color: green;"),Ci(e,{})&&!this.keydownSubscription&&this.detectKeydownOnInput();let c=JSON.parse(JSON.stringify(e)),p=yield this.singleEditorDecisionEngine.determineEditorStatus({singleEditorModeData:c,externalUserPresence:t,heartbeatData:r,currentUser:this.authService.getUser(),currentTabId:this.tabId});p?.stats&&s?.push({eventName:Z.Events.LiveStateSync.SEM_SINGLE_EDITOR_DETERMINE_EDITOR_STATUS,properties:{stats:p?.stats}});let g;if(this.domService.getNetworkStatus()||(g=null),e=p?.data??{},p?.shouldSetUndefined||(g=null),(a?a?.documentPaths:this.docService.getDocumentPaths())||(g=null),e&&!e?.editor&&this.isEditor$?.value!==g&&this.isEditor$.next(g),Ci(this.singleEditorLiveStateData,e))return;{t&&this.compareServerAndExternalData(c,t),s&&s?.length>0&&s.forEach(D=>{D?.eventName&&this.analyticsService.trackEvent(D.eventName,D.properties)}),this.singleEditorLiveStateData=e,this.singleEditorLiveStateData$.next(e);let E;if(this.singleEditorLiveStateData&&typeof this.singleEditorLiveStateData=="object"&&(E=this.liveStateUtilsService.formatLiveStateSingleEditorModeData(JSON.parse(JSON.stringify(this.singleEditorLiveStateData)))),this.analyticsService.trackEvent(Z.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_STATS,{singleEditorLiveStateData:E}),this.singleEditorLiveStateData?.editor){let D=this.authService.getUser();this.singleEditorLiveStateData?.editor?.userId!==D?.userId?this.makeReader():this.makeEditor()}else this.isEditor$?.value!==g&&this.isEditor$.next(g),this.enableInputElements(),this.enableElementEvents();this.editorAccessTimerInterval&&this.singleEditorLiveStateData?.requestEditorAccess?.status!=="pending"&&this.clearEditorAccessTimerInterval(),this.requestAccessTimer&&this.singleEditorLiveStateData?.requestEditorAccess?.status!=="pending"?this.clearRequestAccessTimer():this.singleEditorLiveStateData?.requestEditorAccess?.status==="pending"&&this.isUserEditor()?.isEditor&&this.isUserEditor()?.isEditorOnCurrentTab&&this.setRequestAccessTimer(this.singleEditorLiveStateData?.requestEditorAccess?.editorAccessTimeout||j.LIVE_STATE_REQUEST_EDITOR_ACCESS_WAIT_TIME)}}catch{}})}updateSingleEditorLiveSyncDataOld(a,s){return Q(this,arguments,function*(e,t,r=[]){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: updateSingleEditorLiveSyncData","color: green;"),Ci(e,{})){let g=yield this.fetchSingleEditorLiveStateDataFromDatabase();if(!Ci(g,e)&&(r.push({eventName:Z.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_MISMATCH,properties:{serverData:g,localData:e}}),g&&typeof g=="object")){let C=yield this.liveStateUtilsService.resolveAndMergeSingleEditorLiveStateDataWithUser(JSON.parse(JSON.stringify(g)));e=JSON.parse(JSON.stringify(C))}}Ci(e,{})&&!this.keydownSubscription&&this.detectKeydownOnInput();let c=e&&typeof e=="object"?JSON.parse(JSON.stringify(e)):e;if(t&&(e&&typeof e=="object"&&(e=JSON.parse(JSON.stringify(e))),!e?.editor)){let g=this.authService.getUser();if(t?.sameUserPresentOnTab)e.editor=g,e.tabId=`sameUserPresentOnTab_${this.tabId}`;else if(t?.differentUserPresentOnTab){let C=t?.userIds?.[0],E;C&&(yield this.usersService.resolveUsers({userIds:[C],forceResolve:!0}),E=this.usersService.getUserById(C)),E?(e.editor=E,e.tabId=`differentUserPresentOnTab_${this.tabId}`):(e.editor={userId:`anonymous_${g?.userId}`,name:"Anonymous"},e.tabId=`differentUserPresentOnTab_${this.tabId}`)}}let p;if(this.domService.getNetworkStatus()||(p=null),e&&!e?.editor&&this.isEditor$?.value!==p&&!t?.sameUserPresentOnTab&&!t?.differentUserPresentOnTab&&this.isEditor$.next(p),Ci(this.singleEditorLiveStateData,e))return;{t&&this.compareServerAndExternalData(c,t),r?.length>0&&r.forEach(C=>{C?.eventName&&this.analyticsService.trackEvent(C.eventName,C.properties)}),this.singleEditorLiveStateData=e,this.singleEditorLiveStateData$.next(e);let g;if(this.singleEditorLiveStateData&&typeof this.singleEditorLiveStateData=="object"&&(g=this.liveStateUtilsService.formatLiveStateSingleEditorModeData(JSON.parse(JSON.stringify(this.singleEditorLiveStateData)))),this.analyticsService.trackEvent(Z.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_STATS,{singleEditorLiveStateData:g}),this.singleEditorLiveStateData?.editor){let C=this.authService.getUser();this.singleEditorLiveStateData?.editor?.userId!==C?.userId?this.makeReader():this.makeEditor()}else this.isEditor$?.value!==p&&this.isEditor$.next(p),this.enableInputElements(),this.enableElementEvents();this.editorAccessTimerInterval&&this.singleEditorLiveStateData?.requestEditorAccess?.status!=="pending"&&this.clearEditorAccessTimerInterval(),this.requestAccessTimer&&this.singleEditorLiveStateData?.requestEditorAccess?.status!=="pending"?this.clearRequestAccessTimer():this.singleEditorLiveStateData?.requestEditorAccess?.status==="pending"&&this.isUserEditor()?.isEditor&&this.isUserEditor()?.isEditorOnCurrentTab&&this.setRequestAccessTimer(this.singleEditorLiveStateData?.requestEditorAccess?.editorAccessTimeout||j.LIVE_STATE_REQUEST_EDITOR_ACCESS_WAIT_TIME)}}catch{}})}compareServerAndExternalData(e,t){try{if(t){let r=this.authService.getUser(),a={isEditor:e?.editor?.userId===r?.userId,isEditorOnCurrentTab:e?.editor?.userId===r?.userId&&e?.tabId===this.tabId},s={isEditor:t?.sameUserPresentOnTab&&!t?.differentUserPresentOnTab,isEditorOnCurrentTab:!1};Ci(a,s)||this.analyticsService.trackEvent(Z.Events.LiveStateSync.SEM_SINGLE_EDITOR_DATA_MISMATCH_WITH_EXTERNAL,{serverUserEditorAccess:a,externalUserEditorAccess:s,serverData:e,externalData:t})}}catch(r){this.loggingService.catch("Error in LiveStateService compareServerAndExternalData: ",r)}}isFeatureAllowed(e){return this.configService.getConfig$().pipe(Le(t=>!!t),de(t=>T(I({},e),{config:t})),he(t=>this.authService.getUser$().pipe(de(r=>T(I({},t),{user:r})))),he(t=>ao(t.config,t.user,Re.LIVE_STATE_SYNC)?se(T(I({},t),{featureAllowed:!0})):(this.loggingService.warn("Live state sync feature is not allowed."),se(T(I({},t),{featureAllowed:!1})))),St((t,r)=>t?.featureAllowed===r?.featureAllowed))}getDataFromDocumentId(e){return this.databaseService.getDb().pipe(Le(t=>!!t),he(t=>(this.db=t,this.configService?.getApiKey()&&this.documentPaths?.liveState?this.commonDbService.dbListener({feature:"liveStateSingleEditorMode",properties:{documentId:e??this.documentPaths?.documentId,organizationId:this.documentPaths?.organizationId,skipFirestore:!0}}).pipe(Le(r=>!!r?.data),de(r=>r?.data&&typeof r?.data=="object"?JSON.parse(JSON.stringify(r?.data)):r?.data),Pn(r=>(this.loggingService.catch("Error in LiveStateService getDataFromDocumentId: ",r),se({})))):se({}))),St(gn))}getLiveStateData$(e,t){try{return this.loggingService.log("%c[WB] Calling FUNCTION: getLiveStateData$","color: green;"),Qn(this.afAuth).pipe(Le(r=>!!r),he(r=>this.isFeatureAllowed({firebaseUser:r,liveStateData:{}})),he(r=>r.featureAllowed?this.iamService.isUserAllowed$().pipe(de(a=>(r.featureAllowed=a,r))):se(r)),he(r=>r.featureAllowed?this.authService.isPlanExpired$().pipe(de(a=>(r.featureAllowed=!a,r))):se(r)),he(r=>r.featureAllowed?se(r).pipe(he(a=>this.docService.getDocumentPaths$().pipe(de(s=>(this.documentPaths=s,a.documentPaths=s,a)))),he(a=>{let s=t?.listenToNewChangesOnly?1:0;return this.getLiveStateDataFromDatabase$(e).pipe(zs(s))}),de(a=>{if(a)if(e){let s=yt(e+""),c=a?.[s];if(c){let p=c?.data;if(c?.tabId&&this.tabId&&c?.tabId===this.tabId)return;if(c?.isDataStringified&&typeof p=="string")try{p=JSON.parse(p)}catch{}return p}else return}else{let s={};return Object.keys(a||{}).forEach(c=>{if(a[c]?.liveStateDataId){let p=a[c],g=p?.data;if(p?.isDataStringified&&typeof g=="string")try{g=JSON.parse(g)}catch{}s[p.liveStateDataId]=g}}),s}return a})):se(void 0).pipe(Le(Boolean))),St((r,a)=>JSON.stringify(r||{})===JSON.stringify(a||{})),Le(r=>r!==void 0),de(r=>r))}catch(r){return this.loggingService.catch("Error in LiveStateService getLiveStateData$: ",r),se(null)}}getLiveStateDataFromDatabase$(e){try{return this.databaseService.getDb().pipe(Le(t=>!!t),he(t=>{this.db=t;let r=e?yt(e+""):void 0;return this.configService?.getApiKey()&&this.documentPaths?.liveState?this.commonDbService.dbListener({feature:r?"liveStateCustom":"allLiveStateCustoms",properties:{documentId:this.documentPaths?.documentId,organizationId:this.documentPaths?.organizationId,id:r,skipFirestore:!0}}).pipe(de(a=>a?.data),de(a=>{if(a)return r?{[r]:a}:a}),Pn(a=>(this.loggingService.catch("Error in LiveStateService getLiveStateDataFromDatabase$: ",a),se(null)))):se(void 0)}))}catch(t){return this.loggingService.catch("Error in LiveStateService getLiveStateDataFromDatabase$: ",t),se(void 0)}}setLiveStateData(e,t,r){return Q(this,null,function*(){this.loggingService.log("%c[WB] Calling FUNCTION: setLiveStateData","color: green;");try{let a=this.authService.getUser();if(e&&this.documentPaths?.liveState&&a){let s=yt(e+""),c=!1;try{if(r?.merge&&typeof t=="object"){let g=yield this.commonDbService.getData({feature:"liveStateCustom",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",id:s,skipFirestore:!0}});if(g?.isDataStringified){let C=JSON.parse(g?.data);typeof t=="object"&&(t=I(I({},C),t))}}}catch{}try{typeof t=="object"&&(t=JSON.stringify(t),c=!0)}catch{}let p={id:s,lastUpdated:this.timestamp,liveStateDataId:e,data:t,updatedBy:a,tabId:this.tabId,isDataStringified:c};yield this.commonDbService.setData({feature:"liveStateCustom",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",id:s,skipFirestore:!0},data:JSON.parse(JSON.stringify(p))})}else this.loggingService.warn("liveStateDataId or documentPaths or user is null"),this.liveStateDataMapDraft?.custom||(this.liveStateDataMapDraft.custom={}),e&&(this.liveStateDataMapDraft.custom[e]=t)}catch(a){this.loggingService.catch("Error in LiveStateService _setLiveStateData: ",a)}})}getFormElements(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: getInputElements","color: green;"),document.querySelectorAll("input, textarea, select, button, [contenteditable]")}catch(e){return this.loggingService.catch("Error in LiveStateService getInputElements: ",e),null}}disableInputElements(){try{this.loggingService.log("%c[WB] Calling FUNCTION: disableInputElements","color: green;"),this.getFormElements()?.forEach(t=>{if(this.isElementInsideSingleEditorModeContainerElements(t)&&!this.isSingleEditorModeDisabledForElement(t)&&!Xi(t)){let r=t?.hasAttribute("disabled");t?.hasAttribute("contenteditable")&&(r=t?.getAttribute("contenteditable")==="false"),r||(t.setAttribute("disabled","true"),t.setAttribute(j.ATTRIBUTES.VELT_SYNC_ACCESS_AUTO,"true"),t?.hasAttribute("contenteditable")&&t.setAttribute("contenteditable","false"))}})}catch(e){this.loggingService.catch("Error in LiveStateService disableInputElements: ",e)}}enableInputElements(){try{this.loggingService.log("%c[WB] Calling FUNCTION: enableInputElements","color: green;"),this.getFormElements()?.forEach(t=>{t?.hasAttribute(j.ATTRIBUTES.VELT_SYNC_ACCESS_AUTO)&&(t.removeAttribute("disabled"),t.removeAttribute(j.ATTRIBUTES.VELT_SYNC_ACCESS_AUTO),t?.getAttribute("contenteditable")&&t.setAttribute("contenteditable","true"))})}catch(e){this.loggingService.catch("Error in LiveStateService enableInputElements: ",e)}}disableElementEvents(){try{this.loggingService.log("%c[WB] Calling FUNCTION: disableElementEvents","color: green;"),document.querySelectorAll(`[${j.ATTRIBUTES.VELT_SYNC_ACCESS}]`)?.forEach(t=>{let r=this.domService.getXPath(t);r&&!this.preventEventsOnElementMap[r]&&(this.preventEventsOnElementMap[r]={element:t,events:{}},this.PREVENT_EVENTS.forEach(a=>{let s=hi(t,a,{capture:!0}).subscribe(c=>{try{c.preventDefault(),c.stopPropagation()}catch(p){this.loggingService.catch("Error in LiveStateService disableElementEvents subscription: ",p)}});this.preventEventsOnElementMap[r]?.events[a]?.unsubscribe(),this.preventEventsOnElementMap[r].events[a]=s}))})}catch(e){this.loggingService.catch("Error in LiveStateService disableElementClicks: ",e)}}enableElementEvents(){try{this.loggingService.log("%c[WB] Calling FUNCTION: enableElementEvents","color: green;"),Object.keys(this.preventEventsOnElementMap).forEach(e=>{let t=this.preventEventsOnElementMap[e];Object.keys(t.events||{}).forEach(r=>{t?.events[r]?.unsubscribe()})}),this.preventEventsOnElementMap={}}catch(e){this.loggingService.catch("Error in LiveStateService enableElementClicks: ",e)}}setUserAsEditor(e){return Q(this,null,function*(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: setUserAsEditor","color: green;"),this.user&&this.documentPaths?.liveStateSingleEditorMode){if(this.analyticsService.trackEvent(Z.Events.LiveStateSync.SET_USER_AS_EDITOR_TRIGGERED,{editorUserId:this.user?.userSnippylyId,tabId:this.tabId}),!e?.skipEditorCheck){let r=yield this.fetchSingleEditorLiveStateDataFromDatabase();if(r?.editor?.userId&&r?.tabId){let a=yield P8(this.heartbeatService.getSpecificHeartbeat({userId:r?.editor?.userId,tabId:r?.tabId,documentId:this.documentPaths?.documentId})),s=null;a&&(s=this.singleEditorDecisionEngine.findOldestActiveSessionFromHeartbeats([a])),s||(r=null)}else r=null;if(r?.editor){let a=this.authService.getUser(),s=null;a?.userId===r?.editor?.userId?r?.tabId===this.tabId?s={code:"same_user_editor_current_tab",message:"Same user is already editor in current tab.",source:"setUserAsEditor"}:s={code:"same_user_editor_different_tab",message:"Same user is already editor in different tab.",source:"setUserAsEditor"}:s={code:"another_user_editor",message:"Another user is already editor.",source:"setUserAsEditor"};let c;return r&&typeof r=="object"&&(c=this.liveStateUtilsService.formatLiveStateSingleEditorModeData(JSON.parse(JSON.stringify(r)))),this.analyticsService.trackEvent(Z.Events.LiveStateSync.SET_USER_AS_EDITOR_ERROR,{error:s,singleEditorLiveStateData:c}),{error:s}}}let t={editor:this.user,tabId:this.tabId,editorAt:this.timestamp};this.commonDbService.setData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(t))})}}catch(t){this.loggingService.catch("Error in LiveStateService setUserAsEditor: ",t)}})}fetchSingleEditorLiveStateDataFromDatabase(){return Q(this,null,function*(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: fetchSingleEditorLiveStateDataFromDatabase","color: green;"),yield this.commonDbService.getData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0}})}catch(e){return this.loggingService.catch("Error in LiveStateService fetchSingleEditorLiveStateDataFromDatabase: ",e),null}})}setRequestAccessTimer(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: setRequestAccessTimer","color: green;"),this.requestAccessTimer||(this.requestAccessTimer=setTimeout(()=>{this.getEditorAccessTransferOnTimeOut()&&this.acceptEditorAccessRequest(),this.clearRequestAccessTimer()},e*1e3),this.setEditorAccessTimerInterval(e))}catch(t){this.loggingService.catch("Error in LiveStateService setRequestAccessTimer: ",t)}}clearRequestAccessTimer(){try{this.loggingService.log("%c[WB] Calling FUNCTION: clearRequestAccessTimer","color: green;"),this.requestAccessTimer&&(clearTimeout(this.requestAccessTimer),this.requestAccessTimer=null)}catch(e){this.loggingService.catch("Error in LiveStateService clearRequestAccessTimer: ",e)}}requestEditorAccess(){this.loggingService.log("%c[WB] Calling FUNCTION: requestEditorAccess","color: green;");try{return this.analyticsService.trackEvent(Z.Events.LiveStateSync.REQUEST_EDITOR_ACCESS_TRIGGERED),new Ut(e=>{let t=null;try{if(this.user&&this.documentPaths?.liveStateSingleEditorMode){let r=this.getEditorAccessTimeout(),a=Mi(this.db,`${this.documentPaths?.liveStateSingleEditorMode}`),s={requestEditorAccess:{user:this.user,requestedAt:this.timestamp,status:"pending",editorAccessTimeout:r,tabId:this.tabId}};this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},errorCallback:c=>{this.loggingService.catch("Error in LiveStateService requestEditorAccess: ",c),e.next(null),e.complete()},callback:()=>{r&&(this.requestAccessTimer=setTimeout(()=>{this.getEditorAccessTransferOnTimeOut()&&this.setUserAsEditor({skipEditorCheck:!0})},(r+3)*1e3),this.setEditorAccessTimerInterval(r+3)),t=this.getSingleEditorLiveStateData$().subscribe(c=>{c&&(c?.requestEditorAccess?c?.requestEditorAccess?.status==="cancelled"&&(e.next(null),e.complete()):c?.editor?.userId===this.user?.userId?(e.next(!0),e.complete()):(e.next(!1),e.complete()))})},data:JSON.parse(JSON.stringify(s))})}else e.next(!1),e.complete()}catch(r){this.loggingService.catch("Error in LiveStateService requestEditorAccess: ",r),e.next(null),e.complete()}return()=>{t&&t?.unsubscribe()}})}catch(e){return this.loggingService.catch("Error in LiveStateService requestEditorAccess: ",e),se(null)}}makeEditor(){try{this.loggingService.log("%c[WB] Calling FUNCTION: makeEditor","color: green;");let e=this.singleEditorLiveStateData?.tabId===this.tabId;this.analyticsService.trackEvent(Z.Events.LiveStateSync.SEM_MAKE_EDITOR_TRIGGERED,{editorUserId:this.singleEditorLiveStateData?.editor?.userId,tabId:this.tabId,editorTabId:this.singleEditorLiveStateData?.tabId,isEditor:!0,isEditorOnCurrentTab:e}),this.isEditor$.next({isEditor:!0,isEditorOnCurrentTab:e}),this.getSingleEditorModeConfig()?.customMode||(!this.getSingleEditorModeConfig()?.singleTabEditor||e?(this.enableInputElements(),this.enableElementEvents()):(this.disableInputElements(),this.disableElementEvents())),this.fetchSingleEditorLiveStateDataFromDatabase().then(t=>{this.analyticsService.trackEvent(Z.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_ON_MAKE_EDITOR,{editorUserId:this.singleEditorLiveStateData?.editor?.userId,tabId:this.tabId,editorTabId:this.singleEditorLiveStateData?.tabId,isEditor:!0,isEditorOnCurrentTab:e,singleEditorLiveStateDataOnServer:t})}).catch(t=>{})}catch(e){this.loggingService.catch("Error in LiveStateService makeEditor: ",e)}}makeReader(){try{this.loggingService.log("%c[WB] Calling FUNCTION: makeReader","color: green;"),this.analyticsService.trackEvent(Z.Events.LiveStateSync.SEM_MAKE_READER_TRIGGERED,{editorUserId:this.singleEditorLiveStateData?.editor?.userId,tabId:this.tabId,editorTabId:this.singleEditorLiveStateData?.tabId,isEditor:!1,isEditorOnCurrentTab:!1}),this.isEditor$.next({isEditor:!1,isEditorOnCurrentTab:!1}),this.getSingleEditorModeConfig()?.customMode||(this.disableInputElements(),this.disableElementEvents()),this.fetchSingleEditorLiveStateDataFromDatabase().then(e=>{this.analyticsService.trackEvent(Z.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_ON_MAKE_READER,{editorUserId:this.singleEditorLiveStateData?.editor?.userId,tabId:this.tabId,editorTabId:this.singleEditorLiveStateData?.tabId,isEditor:!1,isEditorOnCurrentTab:!1,singleEditorLiveStateDataOnServer:e})}).catch(e=>{})}catch(e){this.loggingService.catch("Error in makeReader: ",e)}}acceptEditorAccessRequest(){return Q(this,null,function*(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: acceptEditorAccessRequest","color: green;"),this.user&&this.singleEditorLiveStateData?.requestEditorAccess&&this.isUserEditor()?.isEditor&&this.documentPaths?.liveStateSingleEditorMode){let e=this.singleEditorLiveStateData?.requestEditorAccess?.user,t=this.singleEditorLiveStateData?.requestEditorAccess?.tabId;if(e&&t){let r={editor:e,requestEditorAccess:null,tabId:t,editorAt:this.timestamp};this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(r))}),this.analyticsService.trackEvent(Z.Events.LiveStateSync.ACCEPT_EDITOR_ACCESS_REQUEST_TRIGGERED,{editorUserId:e?.userSnippylyId,tabId:t})}}}catch(e){this.loggingService.catch("Error in acceptEditorAccessRequest: ",e)}})}rejectEditorAccessRequest(){return Q(this,null,function*(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: rejectEditorAccessRequest","color: green;"),this.user&&this.singleEditorLiveStateData?.requestEditorAccess&&this.isUserEditor()?.isEditor&&this.documentPaths?.liveStateSingleEditorMode){let e={requestEditorAccess:null};this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(e))}),this.analyticsService.trackEvent(Z.Events.LiveStateSync.REJECT_EDITOR_ACCESS_REQUEST_TRIGGERED)}}catch(e){this.loggingService.catch("Error in LiveStateService rejectEditorAccessRequest: ",e)}})}cancelEditorAccessRequest(){return Q(this,null,function*(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: cancelEditorAccessRequest","color: green;"),this.user&&this.singleEditorLiveStateData?.requestEditorAccess&&this.documentPaths?.liveStateSingleEditorMode){let e={requestEditorAccess:T(I({},this.singleEditorLiveStateData?.requestEditorAccess),{status:"cancelled"})};this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(e))}),e={requestEditorAccess:null},this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(e))}),this.analyticsService.trackEvent(Z.Events.LiveStateSync.CANCEL_EDITOR_ACCESS_REQUEST_TRIGGERED)}}catch(e){this.loggingService.catch("Error in LiveStateService cancelEditorAccessRequest: ",e)}})}editCurrentTab(){return Q(this,null,function*(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: editCurrentTab","color: green;"),this.user&&this.isUserEditor()?.isEditor&&!this.isUserEditor()?.isEditorOnCurrentTab&&this.documentPaths?.liveStateSingleEditorMode){let e={tabId:this.tabId,editor:this.user,editorAt:this.timestamp};this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(e))}),this.analyticsService.trackEvent(Z.Events.LiveStateSync.EDIT_CURRENT_TAB_TRIGGERED,{tabId:this.tabId})}}catch(e){this.loggingService.catch("Error in LiveStateService editCurrentTab: ",e)}})}isUserEditor$(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: isUserEditor$","color: green;"),this.isEditor$.asObservable().pipe(St(gn))}catch(e){return this.loggingService.catch("Error in LiveStateService isUserEditor$: ",e),se(null)}}isUserEditor(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: isUserEditor","color: green;"),this.isEditor$.value}catch(e){return this.loggingService.catch("Error in LiveStateService isUserEditor: ",e),null}}getEditor$(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: getEditor$","color: green;"),this.getSingleEditorLiveStateData$().pipe(de(e=>e?.editor||null),St())}catch(e){return this.loggingService.catch("Error in LiveStateService getEditor$: ",e),se(null)}}isEditorAccessRequested$(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: isEditorAccessRequested$","color: green;"),this.isUserEditor$().pipe(he(e=>e?.isEditor?this.singleEditorLiveStateData$.pipe(de(t=>t?.requestEditorAccess?{requestStatus:"requested",requestedBy:t?.requestEditorAccess?.user}:null)):se(null)),St((e,t)=>JSON.stringify(e||{})===JSON.stringify(t||{})))}catch(e){return this.loggingService.catch("Error in LiveStateService isEditorAccessRequested$: ",e),se(null)}}removeEditorAccess(e){return Q(this,null,function*(){try{this.loggingService.log("%c[WB] Calling FUNCTION: removeEditorAccess","color: green;"),this.analyticsService.trackEvent(Z.Events.LiveStateSync.REMOVE_EDITOR_ACCESS,{removeEditorAccessMetadata:e?.metadata});let t=e?.documentPaths??this.documentPaths;(this.user||this.authService.getAuthUser())&&t?.liveStateSingleEditorMode&&(yield this.commonDbService.deleteData({feature:"liveStateSingleEditorMode",properties:{documentId:t?.documentId??"",organizationId:t?.organizationId??"",skipFirestore:!0}}))}catch(t){this.loggingService.catch("Error in LiveStateService removeEditorAccess: ",t)}})}getSingleEditorLiveStateData$(){return this.singleEditorLiveStateData$.asObservable().pipe(St(gn))}subscribeAutoSyncState(){return this.loggingService.log("%c[WB] Calling FUNCTION: getOnlineUsersOnCurrentDocument","color: green;"),Qn(this.afAuth).pipe(Le(e=>!!e),he(e=>this.isFeatureAllowed({firebaseUser:e,liveStateData:{}})),he(e=>e.featureAllowed?this.iamService.isUserAllowed$().pipe(de(t=>(e.featureAllowed=t,e))):se(e)),he(e=>e.featureAllowed?this.authService.isPlanExpired$().pipe(de(t=>(e.featureAllowed=!t,e))):se(e)),he(e=>e.featureAllowed?se(e).pipe(he(t=>this.docService.getDocumentPaths$().pipe(Le(r=>!!r),de(r=>(this.documentPaths=r,t.documentPaths=r,t)))),he(t=>this.domService.onNetworkStatusChange$().pipe(Le(r=>r),de(()=>t))),he(t=>this.getLiveStateAutoSyncStateDataFromDocumentId().pipe(de(r=>(t.liveStateData=r,I({},t))))),de(t=>{if(t.liveStateData)this.liveStateAutoSyncStateData$.next(t.liveStateData);else{let r=this.liveStateAutoSyncStateData$.value;r&&Object.keys(r).length>0&&this.liveStateAutoSyncStateData$.next({})}return t})):se({})))}getLiveStateAutoSyncStateDataFromDocumentId(e){return this.databaseService.getDb().pipe(Le(t=>!!t),he(t=>(this.db=t,this.configService?.getApiKey()&&this.documentPaths?.liveState?this.commonDbService.dbListener({feature:"liveStateAutoSyncState",properties:{documentId:e??this.documentPaths?.documentId,organizationId:this.documentPaths?.organizationId,skipFirestore:!0}}).pipe(Le(r=>!!r?.data),de(r=>r?.data&&typeof r?.data=="object"?JSON.parse(JSON.stringify(r?.data)):r?.data),Pn(r=>(this.loggingService.catch("Error in LiveStateService getLiveStateAutoSyncStateDataFromDocumentId: ",r),se({})))):se({}))),St(gn))}enableSingleEditorMode(e){try{if(this.singleEditorMode$.value===!0)return;this.singleEditorMode$.next(!0),e?this.singleEditorModeConfig$.next(e):this.singleEditorModeConfig$.next(new Pk)}catch(t){this.loggingService.catch("Error in LiveStateService enableSingleEditorMode: ",t)}}disableSingleEditorMode(){try{if(this.singleEditorMode$.value===!1)return;this.singleEditorMode$.next(!1)}catch(e){this.loggingService.catch("Error in LiveStateService disableSingleEditorMode: ",e)}}getSingleEditorMode$(){return this.singleEditorMode$.asObservable()}getSingleEditorMode(){return this.singleEditorMode$.value}getSingleEditorModeConfig$(){return this.singleEditorModeConfig$.asObservable()}getSingleEditorModeConfig(){return this.singleEditorModeConfig$.value}enableAutoSyncState(){try{if(this.autoSyncState$.value===!0)return;this.autoSyncState$.next(!0)}catch(e){this.loggingService.catch("Error in LiveStateService enableAutoSyncState: ",e)}}disableAutoSyncState(){try{if(this.autoSyncState$.value===!1)return;this.autoSyncState$.next(!1)}catch(e){this.loggingService.catch("Error in LiveStateService disableAutoSyncState: ",e)}}getAutoSyncState$(){return this.autoSyncState$.asObservable()}getAutoSyncState(){return this.autoSyncState$.value}setEditorAccessTimeout(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: setEditorAccessTimeout","color: green;"),e&&this.editorAccessTimeout$.next(e)}catch(t){this.loggingService.catch("Error in LiveStateService setEditorAccessTimeout: ",t)}}getEditorAccessTimeout$(){return this.editorAccessTimeout$.asObservable()}getEditorAccessTimeout(){return this.editorAccessTimeout$.value}enableEditorAccessTransferOnTimeOut(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: enableEditorAccessTransferOnTimeOut","color: green;"),this.editorAccessTransferOnTimeOut$.value===!0)return;this.editorAccessTransferOnTimeOut$.next(!0)}catch(e){this.loggingService.catch("Error in LiveStateService enableEditorAccessTransferOnTimeOut: ",e)}}disableEditorAccessTransferOnTimeOut(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: disableEditorAccessTransferOnTimeOut","color: green;"),this.editorAccessTransferOnTimeOut$.value===!1)return;this.editorAccessTransferOnTimeOut$.next(!1)}catch(e){this.loggingService.catch("Error in LiveStateService disableEditorAccessTransferOnTimeOut: ",e)}}getEditorAccessTransferOnTimeOut$(){return this.editorAccessTransferOnTimeOut$.asObservable()}getEditorAccessTransferOnTimeOut(){return this.editorAccessTransferOnTimeOut$.value}enableDefaultSingleEditorUI(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: enableDefaultSingleEditorUI","color: green;"),this.defaultSingleEditorUIEnabled$.value===!0)return;this.defaultSingleEditorUIEnabled$.next(!0)}catch(e){this.loggingService.catch("Error in LiveStateService enableDefaultSingleEditorUI: ",e)}}disableDefaultSingleEditorUI(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: disableDefaultSingleEditorUI","color: green;"),this.defaultSingleEditorUIEnabled$.value===!1)return;this.defaultSingleEditorUIEnabled$.next(!1)}catch(e){this.loggingService.catch("Error in LiveStateService disableDefaultSingleEditorUI: ",e)}}getDefaultSingleEditorUIEnabled$(){return this.defaultSingleEditorUIEnabled$.asObservable()}getDefaultSingleEditorUIEnabled(){return this.defaultSingleEditorUIEnabled$.value}setEditorAccessTimerInterval(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: setEditorAccessTimerInterval","color: green;"),this.clearEditorAccessTimerInterval(),e>0&&(this.editorAccessTimer$.next({state:"inProgress",durationLeft:e}),this.editorAccessTimerInterval=setInterval(()=>{try{e-=1,e<0?this.clearEditorAccessTimerInterval():e?this.editorAccessTimer$.next({state:"inProgress",durationLeft:e}):this.editorAccessTimer$.next({state:"completed"})}catch(t){this.loggingService.catch("Error in LiveStateService setEditorAccessTimerCountdown interval: ",t),this.clearEditorAccessTimerInterval()}},1e3))}catch(t){this.loggingService.catch("Error in LiveStateService setEditorAccessTimerCountdown: ",t),this.clearEditorAccessTimerInterval()}}clearEditorAccessTimerInterval(){try{this.loggingService.log("%c[WB] Calling FUNCTION: clearEditorAccessTimerInterval","color: green;"),this.editorAccessTimerInterval&&(clearInterval(this.editorAccessTimerInterval),this.editorAccessTimerInterval=null,this.editorAccessTimer$.next({state:"idle"}))}catch(e){this.loggingService.catch("Error in LiveStateService clearEditorAccessTimerInterval: ",e)}}getEditorAccessTimer$(){return this.editorAccessTimer$.asObservable()}onServerConnectionStateChange$(){return this.serverConnectionState$.asObservable()}updateExternalUserPresence(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: updateExternalUserPresence","color: green;"),this.externalUserPresence$.next(e)}catch(t){this.loggingService.catch("Error in LiveStateService updateExternalUserPresence: ",t)}}getExternalUserPresence$(){return this.externalUserPresence$.asObservable().pipe(St(gn))}getExternalUserPresence(){return this.externalUserPresence$.value}enableHeartbeat(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: enableHeartbeat","color: green;"),this.heartbeat$.value===!0)return;this.heartbeat$.next(!0)}catch(e){this.loggingService.catch("Error in LiveStateService enableHeartbeat: ",e)}}disableHeartbeat(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: disableHeartbeat","color: green;"),this.heartbeat$.value===!1)return;this.heartbeat$.next(!1)}catch(e){this.loggingService.catch("Error in LiveStateService disableHeartbeat: ",e)}}detectLiveSyncInputs(){try{document.querySelectorAll(`[${j.ATTRIBUTES.VELT_SYNC_STATE}]`)?.forEach(t=>{this.subscribeInputChanges(t)})}catch(e){this.loggingService.catch("Error in LiveStateService detectLiveSyncInputs: ",e)}}subscribeInputChanges(e){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: subscribeInputChanges","color: green;"),e){let t=e.tagName,r=this.domService.getXPath(e),a=yt(r);if(this.inputChangeSubscriptionMap[a])this.loggingService.warn("subscription already exists",a,e);else{this.inputChangeSubscriptionMap[a]={id:a,element:e};let s;switch(t?.toLowerCase()){case"input":s=hi(e,"input").pipe(cr(300)).subscribe(p=>{let g={value:p?.target?.value,tagName:p?.target?.tagName,type:p?.target?.type};this.setLiveStateSyncInputData(p?.target,g)});break;case"textarea":s=hi(e,"input").pipe(cr(300)).subscribe(p=>{let g={value:p?.target?.value,tagName:p?.target?.tagName};this.setLiveStateSyncInputData(p?.target,g)});break;default:e.getAttribute("contenteditable")&&(s=hi(e,"input").pipe(cr(300)).subscribe(p=>{let g={innerText:p?.target?.innerText,innerHTML:this.domService.sanitizeHtml(p?.target?.innerHTML),tagName:p?.target?.tagName,isContentEditable:!0};this.setLiveStateSyncInputData(p?.target,g)}));break}s&&(this.inputChangeSubscriptionMap[a]?.subscriptions||(this.inputChangeSubscriptionMap[a]={subscriptions:[]}),this.inputChangeSubscriptionMap[a].subscriptions?.push(s))}}}catch(t){this.loggingService.catch("Error in LiveStateService subscribeInputChanges: ",t)}}unsubscribeInputChanges(){try{this.loggingService.log("%c[WB] Calling FUNCTION: unsubscribeInputChanges","color: green;"),Object.keys(this.inputChangeSubscriptionMap).forEach(e=>{this.inputChangeSubscriptionMap[e]?.subscriptions?.forEach(r=>{r.unsubscribe()})}),this.inputChangeSubscriptionMap={}}catch(e){this.loggingService.catch("Error in LiveStateService unsubscribeInputChanges: ",e)}}setLiveStateSyncInputData(e,t){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: setLiveStateSyncInputData","color: green;"),this.user&&this.documentPaths?.liveState){let r=this.domService.getXPath(e),a=yt(r),s={id:a,lastUpdated:this.timestamp,liveStateDataId:r,data:t,updatedBy:this.user,tabId:this.tabId};this.commonDbService.updateData({feature:"liveStateAutoSyncStateCurrent",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0},data:JSON.parse(JSON.stringify(s))}),this.commonDbService.updateData({feature:"liveStateAutoSyncStateHistoryId",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",id:a,skipFirestore:!0},data:JSON.parse(JSON.stringify(s))})}}catch(r){this.loggingService.catch("Error in LiveStateService setLiveStateSyncInputData: ",r)}}updateLiveStateSyncInputDataLocally(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: updateLiveStateSyncInputDataLocally","color: green;"),this.user&&Object.keys(e).forEach(t=>{let r=e[t],a=this.domService.getElementFromXPath(r?.liveStateDataId),s=!1;if(r?.updatedBy?.userSnippylyId!==this.user?.userSnippylyId)s=!0;else{let c=r?.tabId&&this.tabId&&r?.tabId!==this.tabId,p=a?.contains(document.activeElement);c&&!Bae()&&!p&&(s=!0)}if(s&&a)switch(a.value=r?.data?.value,a.tagName?.toLowerCase()){case"input":a.value=r?.data?.value;break;case"textarea":a.value=r?.data?.value;break;default:a.getAttribute("contenteditable")&&(a.innerHTML=this.domService.sanitizeHtml(r?.data?.innerHTML))}})}catch(t){this.loggingService.catch("Error in LiveStateService updateLiveStateSyncInputDataLocally: ",t)}}setSingleEditorModeContainerIds(e){this.singleEditorModeContainerIds$.next(e||[])}getSingleEditorModeContainerIds(){return this.singleEditorModeContainerIds$.asObservable()}isElementInsideSingleEditorModeContainerElements(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: isElementInsideSingleEditorModeContainerElements","color: green;");let t=this.singleEditorModeContainerIds$.value,r=document.querySelectorAll(`[${j.ATTRIBUTES.VELT_SINGLE_EDITOR_MODE_CONTAINER}]`);if(!t?.length&&!r?.length)return!0;if(t?.length)for(let a=0;a<t.length;a++){let s=document.getElementById(t[a]);if(s&&s.contains(e))return!0}if(r?.length)for(let a=0;a<r.length;a++){let s=r[a];if(s&&s.contains(e))return!0}return!1}catch(t){return this.loggingService.catch("Error in LiveStateService isElementInsideSingleEditorModeContainerElements: ",t),!1}}isSingleEditorModeDisabledForElement(e){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: isSingleEditorModeDisabledForElement","color: green;"),e){if(e.getAttribute(j.ATTRIBUTES.VELT_SYNC_ACCESS_DISABLED))return!0;{let r=e?.parentElement;if(r)return this.isSingleEditorModeDisabledForElement(r)}}return!1}catch(t){return this.loggingService.catch("Error in LiveStateService isSingleEditorModeDisabledForElement: ",t),!1}}updateOnDatabaseDisconnect(){return this.loggingService.log("%c[WB] Calling FUNCTION: updateOnDatabaseDisconnect","color: green;"),this.isUserEditor$().pipe(sn(e=>{try{if(this.documentPaths?.liveStateSingleEditorMode){let t=Mi(this.db,`${this.documentPaths?.liveStateSingleEditorMode}`);e?.isEditor&&(!this.getSingleEditorModeConfig()?.singleTabEditor||e?.isEditorOnCurrentTab)?il(t).remove():il(t).cancel()}}catch(t){this.loggingService.catch("Error in LiveStateService updateOnDatabaseDisconnect tap: ",t)}}))}updateServerStateOnDatabaseDisconnect(){return this.loggingService.log("%c[WB] Calling FUNCTION: updateServerStateOnDatabaseDisconnect","color: green;"),Qn(this.afAuth).pipe(Le(e=>!!e),he(e=>this.docService.getDocumentPaths$().pipe(de(t=>e))),sn(e=>Q(this,null,function*(){try{if(this.docService.getDocumentPaths()?.liveState&&e){let r=Mi(this.db,".info/connected"),a=!0;jp(r,s=>{let c=s.val();if(a&&c===!1){a=!1;return}a=!1,c===!1?this.serverConnectionState$.next(al.OFFLINE):this.serverConnectionState$.value===al.OFFLINE&&this.serverConnectionState$.next(al.ONLINE)})}}catch(t){this.loggingService.catch("Error in updateServerStateOnDatabaseDisconnect:",t)}})))}signOutUser(e){return new Promise((t,r)=>{try{this.documentPaths?.liveStateSingleEditorMode&&e?this.commonDbService.getData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId,organizationId:this.documentPaths?.organizationId,skipFirestore:!0}}).then(a=>{a&&this.isUserEditor()?.isEditor&&(!this.getSingleEditorModeConfig()?.singleTabEditor||this.isUserEditor()?.isEditorOnCurrentTab)&&this.removeEditorAccess({metadata:{from:"signOutUser-liveStateService",reason:"User signed out"}}),t(null)}).catch(a=>{this.loggingService.catch("Error in signOutUser subscription: ",a),r(a)}):t(null)}catch(a){this.loggingService.catch("Error in signOutUser:",a),r(a)}})}getSemStats(){try{let e=!!this.authService?.getUser(),t=!!this.docService?.getDocumentPaths(),r=this.singleEditorMode$.value,a=!!this.singleEditorModeConfig$.value,s=this.isUserEditor(),c;this.singleEditorLiveStateData$.value&&typeof this.singleEditorLiveStateData$.value=="object"&&(c=this.liveStateUtilsService?.formatLiveStateSingleEditorModeData(JSON.parse(JSON.stringify(this.singleEditorLiveStateData$.value))));let p=this.getExternalUserPresence();return{userAvailable:e,documentPathsAvailable:t,singleEditorModeEnabled:r,singleEditorModeConfig:a,isEditor:s,singleEditorLiveStateData:c,userPresence:p}}catch(e){this.loggingService.catch("Error in LiveStateService getSemStats: ",e)}}get timestamp(){return this.commonDbService.getServerTimestamp()}};o.\u0275fac=function(t){return new(t||o)(J(Pi),J(et),J(Ve),J(kt),J(yn),J(it),J(Be),J(Ide),J(Sn),J(y),J(an),J(h9),J(Yk),J(kn),J(Ede))},o.\u0275prov=Ae({token:o,factory:o.\u0275fac,providedIn:"root"});let i=o;return i})();var f9=class extends ci{constructor(o){super(o),this.getService(y).log("%c[WB] Creating CLASS: LiveStateElement","color: blue;"),this.getLiveStateData$=this._getLiveStateData,this.getLiveStateData=this._getLiveStateData,this.setLiveStateData=this._setLiveStateData,this.enableSingleEditorMode=this._enableSingleEditorMode,this.disableSingleEditorMode=this._disableSingleEditorMode,this.isUserEditor$=this._isUserEditor,this.isUserEditor=this._isUserEditor,this.getEditor=this._getEditor,this.setUserAsEditor=this._setUserAsEditor,this.resetUserAccess=this._resetUserAccess,this.singleEditorModeContainerIds=this._singleEditorModeContainerIds,this.enableAutoSyncState=this._enableAutoSyncState,this.disableAutoSyncState=this._disableAutoSyncState,this.requestEditorAccess=this._requestEditorAccess,this.isEditorAccessRequested=this._isEditorAccessRequested,this.acceptEditorAccessRequest=this._acceptEditorAccessRequest,this.rejectEditorAccessRequest=this._rejectEditorAccessRequest,this.cancelEditorAccessRequest=this._cancelEditorAccessRequest,this.editCurrentTab=this._editCurrentTab,this.setEditorAccessTimeout=this._setEditorAccessTimeout,this.enableEditorAccessTransferOnTimeOut=this._enableEditorAccessTransferOnTimeOut,this.disableEditorAccessTransferOnTimeOut=this._disableEditorAccessTransferOnTimeOut,this.enableDefaultSingleEditorUI=this._enableDefaultSingleEditorUI,this.disableDefaultSingleEditorUI=this._disableDefaultSingleEditorUI,this.getEditorAccessTimer=this._getEditorAccessTimer,this.onServerConnectionStateChange=this._onServerConnectionStateChange,this.updateUserPresence=this._updateUserPresence,this.enableHeartbeat=this._enableHeartbeat,this.disableHeartbeat=this._disableHeartbeat,this.on=this._on}_getLiveStateData(o,n){this.getService(y).log("%c[WB] Calling FUNCTION: getLiveStateData","color: green;");try{return this.trackEvent(Z.Events.LiveStateSync.GET_LIVE_STATE_DATA_TRIGGERED),this.getService(ji).getLiveStateData$(o,n)}catch(e){return this.getService(y).catch("Error in _getLiveStateData: ",e),se(null)}}_setLiveStateData(o,n,e){this.getService(y).log("%c[WB] Calling FUNCTION: setLiveStateData","color: green;");try{return this.getService(ji).setLiveStateData(o,n,e)}catch(t){return this.getService(y).catch("Error in _setLiveStateData: ",t),Promise.resolve()}}_enableSingleEditorMode(o){this.getService(y).log("%c[WB] Calling FUNCTION: enableSingleEditorMode","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.ENABLE_SINGLE_EDITOR_MODE_TRIGGERED),this.getService(ji).enableSingleEditorMode(o)}catch(n){this.getService(y).catch("Error in _enableSingleEditorMode: ",n)}}_disableSingleEditorMode(){this.getService(y).log("%c[WB] Calling FUNCTION: disableSingleEditorMode","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.DISABLE_SINGLE_EDITOR_MODE_TRIGGERED),this.getService(ji).disableSingleEditorMode()}catch(o){this.getService(y).catch("Error in _disableSingleEditorMode: ",o)}}_isUserEditor(){this.getService(y).log("%c[WB] Calling FUNCTION: isUserEditor$","color: green;");try{return this.trackEvent(Z.Events.LiveStateSync.IS_USER_EDITOR_TRIGGERED),this.getService(ji).isUserEditor$()}catch(o){return this.getService(y).catch("Error in _isUserEditor$: ",o),se(null)}}_getEditor(){this.getService(y).log("%c[WB] Calling FUNCTION: getEditor","color: green;");try{return this.trackEvent(Z.Events.LiveStateSync.GET_EDITOR_TRIGGERED),this.getService(ji).getEditor$()}catch(o){return this.getService(y).catch("Error in _getEditor: ",o),se(null)}}_setUserAsEditor(){this.getService(y).log("%c[WB] Calling FUNCTION: setUserAsEditor","color: green;");try{return this.trackEvent(Z.Events.LiveStateSync.SET_USER_AS_EDITOR_TRIGGERED),this.getService(ji).setUserAsEditor()}catch(o){return this.getService(y).catch("Error in _setUserAsEditor: ",o),Promise.resolve()}}_resetUserAccess(){this.getService(y).log("%c[WB] Calling FUNCTION: resetUserAccess","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.RESET_USER_ACCESS_TRIGGERED),this.getService(ji).removeEditorAccess({metadata:{from:"resetUserAccess-liveStateSyncElement",reason:"Client called"}})}catch(o){this.getService(y).catch("Error in _resetUserAccess: ",o)}}_singleEditorModeContainerIds(o){this.getService(y).log("%c[WB] Calling FUNCTION: singleEditorModeContainerIds","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.SINGLE_EDITOR_MODE_CONTAINER_IDS_TRIGGERED),this.getService(ji).setSingleEditorModeContainerIds(o)}catch(n){this.getService(y).catch("Error in _singleEditorModeContainerIds: ",n)}}_enableAutoSyncState(){this.getService(y).log("%c[WB] Calling FUNCTION: enableAutoSyncState","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.ENABLE_AUTO_SYNC_STATE_TRIGGERED),this.getService(ji).enableAutoSyncState()}catch(o){this.getService(y).catch("Error in _enableAutoSyncState: ",o)}}_disableAutoSyncState(){this.getService(y).log("%c[WB] Calling FUNCTION: disableAutoSyncState","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.DISABLE_AUTO_SYNC_STATE_TRIGGERED),this.getService(ji).disableAutoSyncState()}catch(o){this.getService(y).catch("Error in _disableAutoSyncState: ",o)}}_requestEditorAccess(){this.getService(y).log("%c[WB] Calling FUNCTION: requestEditorAccess","color: green;");try{return this.trackEvent(Z.Events.LiveStateSync.REQUEST_EDITOR_ACCESS_TRIGGERED),this.getService(ji).requestEditorAccess()}catch(o){return this.getService(y).catch("Error in _requestEditorAccess: ",o),se(null)}}_isEditorAccessRequested(){this.getService(y).log("%c[WB] Calling FUNCTION: isEditorAccessRequested","color: green;");try{return this.trackEvent(Z.Events.LiveStateSync.IS_EDITOR_ACCESS_REQUESTED_TRIGGERED),this.getService(ji).isEditorAccessRequested$()}catch(o){return this.getService(y).catch("Error in _isEditorAccessRequested: ",o),se(null)}}_acceptEditorAccessRequest(){this.getService(y).log("%c[WB] Calling FUNCTION: acceptEditorAccessRequest","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.ACCEPT_EDITOR_ACCESS_REQUEST_TRIGGERED),this.getService(ji).acceptEditorAccessRequest()}catch(o){this.getService(y).catch("Error in _acceptEditorAccessRequest: ",o)}}_rejectEditorAccessRequest(){this.getService(y).log("%c[WB] Calling FUNCTION: rejectEditorAccessRequest","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.REJECT_EDITOR_ACCESS_REQUEST_TRIGGERED),this.getService(ji).rejectEditorAccessRequest()}catch(o){this.getService(y).catch("Error in _rejectEditorAccessRequest: ",o)}}_cancelEditorAccessRequest(){this.getService(y).log("%c[WB] Calling FUNCTION: cancelEditorAccessRequest","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.CANCEL_EDITOR_ACCESS_REQUEST_TRIGGERED),this.getService(ji).cancelEditorAccessRequest()}catch(o){this.getService(y).catch("Error in _cancelEditorAccessRequest: ",o)}}_editCurrentTab(){this.getService(y).log("%c[WB] Calling FUNCTION: editCurrentTab","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.EDIT_CURRENT_TAB_TRIGGERED),this.getService(ji).editCurrentTab()}catch(o){this.getService(y).catch("Error in _editCurrentTab: ",o)}}_setEditorAccessTimeout(o){this.getService(y).log("%c[WB] Calling FUNCTION: setEditorAccessTimeout","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.SET_EDITOR_ACCESS_TIMEOUT_TRIGGERED),this.getService(ji).setEditorAccessTimeout(o)}catch(n){this.getService(y).catch("Error in _setEditorAccessTimeout: ",n)}}_enableEditorAccessTransferOnTimeOut(){this.getService(y).log("%c[WB] Calling FUNCTION: enableEditorAccessTransferOnTimeOut","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.ENABLE_EDITOR_ACCESS_TRANSFER_ON_TIMEOUT_TRIGGERED),this.getService(ji).enableEditorAccessTransferOnTimeOut()}catch(o){this.getService(y).catch("Error in _enableEditorAccessTransferOnTimeOut: ",o)}}_disableEditorAccessTransferOnTimeOut(){this.getService(y).log("%c[WB] Calling FUNCTION: disableEditorAccessTransferOnTimeOut","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.DISABLE_EDITOR_ACCESS_TRANSFER_ON_TIMEOUT_TRIGGERED),this.getService(ji).disableEditorAccessTransferOnTimeOut()}catch(o){this.getService(y).catch("Error in _disableEditorAccessTransferOnTimeOut: ",o)}}_enableDefaultSingleEditorUI(){this.getService(y).log("%c[WB] Calling FUNCTION: enableDefaultSingleEditorUI","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.ENABLE_DEFAULT_SINGLE_EDITOR_UI_TRIGGERED),this.getService(ji).enableDefaultSingleEditorUI()}catch(o){this.getService(y).catch("Error in _enableDefaultSingleEditorUI: ",o)}}_disableDefaultSingleEditorUI(){this.getService(y).log("%c[WB] Calling FUNCTION: disableDefaultSingleEditorUI","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.DISABLE_DEFAULT_SINGLE_EDITOR_UI_TRIGGERED),this.getService(ji).disableDefaultSingleEditorUI()}catch(o){this.getService(y).catch("Error in _disableDefaultSingleEditorUI: ",o)}}_getEditorAccessTimer(){this.getService(y).log("%c[WB] Calling FUNCTION: getEditorAccessTimer","color: green;");try{return this.trackEvent(Z.Events.LiveStateSync.GET_EDITOR_ACCESS_TIMER_TRIGGERED),this.getService(ji).getEditorAccessTimer$()}catch(o){return this.getService(y).catch("Error in _getEditorAccessTimer: ",o),se(new u0)}}_onServerConnectionStateChange(){this.getService(y).log("%c[WB] Calling FUNCTION: onServerConnectionStateChange","color: green;");try{return this.trackEvent(Z.Events.LiveStateSync.ON_SERVER_CONNECTION_STATE_CHANGE_TRIGGERED),this.getService(ji).onServerConnectionStateChange$()}catch(o){return this.getService(y).catch("Error in _onServerConnectionStateChange: ",o),se(al.PENDING_INIT)}}_updateUserPresence(o){this.getService(y).log("%c[WB] Calling FUNCTION: updateUserPresence","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.UPDATE_USER_PRESENCE_TRIGGERED,{payload:{userPresence:o}}),this.getService(ji).updateExternalUserPresence(o)}catch(n){this.getService(y).catch("Error in _updateUserPresence: ",n)}}_enableHeartbeat(){this.getService(y).log("%c[WB] Calling FUNCTION: enableHeartbeat","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.ENABLE_HEARTBEAT_TRIGGERED),this.getService(ji).enableHeartbeat()}catch(o){this.getService(y).catch("Error in _enableHeartbeat: ",o)}}_disableHeartbeat(){this.getService(y).log("%c[WB] Calling FUNCTION: disableHeartbeat","color: green;");try{this.trackEvent(Z.Events.LiveStateSync.DISABLE_HEARTBEAT_TRIGGERED),this.getService(ji).disableHeartbeat()}catch(o){this.getService(y).catch("Error in _disableHeartbeat: ",o)}}_on(o){this.getService(y).log("%c[WB] Calling FUNCTION: on","color: green;");try{return this.trackEvent(Z.Events.LiveStateSync.ON_ACTION_TRIGGERED,{payload:{action:o}}),this.getService(h9).onAction(o)}catch(n){return this.getService(y).catch("Error in _on: ",n),se(null)}}};var v9=(()=>{let o=class o{constructor(e){this.loggingService=e,this.actionSubjects=new Map,this.defaultSource="internal",this.isUserAdmin=!1,this.subscriptions=[],this.loggingService.log("%c[WB] Creating CLASS: CommentActionsService","color: blue;")}triggerSettingsUpdatedEvent(e){try{this.triggerAction(uae.SETTINGS_UPDATED,e)}catch(t){this.loggingService.catch("Error in NotificationsActionsService triggerAddCommentAnnotationEvent: ",t)}}triggerAction(e,t){try{this.actionSubjects.has(e)||this.actionSubjects.set(e,new tt),this.actionSubjects.get(e)?.next(t)}catch(r){this.loggingService.catch("Error in NotificationsActionsService triggerAction: ",r)}}onAction(e){try{return this.actionSubjects.has(e)||this.actionSubjects.set(e,new tt),this.actionSubjects.get(e)?.asObservable()}catch(t){return this.loggingService.catch("Error in NotificationsActionsService onAction: ",t),se(null)}}};o.\u0275fac=function(t){return new(t||o)(J(y))},o.\u0275prov=Ae({token:o,factory:o.\u0275fac,providedIn:"root"});let i=o;return i})();var C9=class extends ci{constructor(o){super(o),this.getService(y).log("%c[WB] Creating CLASS: ViewsElement","color: blue;"),this.openHistoryPanel=this._openHistoryPanel,this.closeHistoryPanel=this._closeHistoryPanel,this.toggleHistoryPanel=this._toggleHistoryPanel,this.getNotificationsData=this._getNotificationsData,this.setMaxDays=this._setMaxDays,this.setTabConfig=this._setTabConfig,this.enableReadNotificationsOnForYouTab=this._enableReadNotificationsOnForYouTab,this.disableReadNotificationsOnForYouTab=this._disableReadNotificationsOnForYouTab,this.setAllNotificationsAsRead=this._setAllNotificationsAsRead,this.getUnreadNotificationsCount=this._getUnreadNotificationsCount,this.markNotificationAsReadById=this._markNotificationAsReadById,this.setSettings=this._setSettings,this.getSettings=this._getSettings,this.muteAllNotifications=this._muteAllNotifications,this.enableSettings=this._enableSettings,this.enableSelfNotifications=this._enableSelfNotifications,this.disableSelfNotifications=this._disableSelfNotifications,this.disableSettings=this._disableSettings,this.setSettingsInitialConfig=this._setSettingsInitialConfig,this.openNotificationsPanel=this._openNotificationsPanel,this.closeNotificationsPanel=this._closeNotificationsPanel,this.enableCurrentDocumentOnly=this._enableCurrentDocumentOnly,this.disableCurrentDocumentOnly=this._disableCurrentDocumentOnly,this.on=this._on}_openHistoryPanel(){this.getService(y).log("%c[WB] Calling FUNCTION: _openHistoryPanel","color: green;");try{this.trackEvent(Z.Events.Notifications.OPEN_HISTORY_PANEL_TRIGGERED),this.getService(pn).setHistoryPanelVisibility(!0,!0)}catch(o){this.getService(y).catch("Error in openHistoryPanel: ",o)}}_closeHistoryPanel(){this.getService(y).log("%c[WB] Calling FUNCTION: _closeHistoryPanel","color: green;");try{this.trackEvent(Z.Events.Notifications.CLOSE_HISTORY_PANEL_TRIGGERED),this.getService(pn).setHistoryPanelVisibility(!1,!0)}catch(o){this.getService(y).catch("Error in closeHistoryPanel: ",o)}}_toggleHistoryPanel(){this.getService(y).log("%c[WB] Calling FUNCTION: _toggleHistoryPanel","color: green;");try{this.trackEvent(Z.Events.Notifications.TOGGLE_HISTORY_PANEL_TRIGGERED),this.getService(pn).toggleHistoryPanelVisibility(!0)}catch(o){this.getService(y).catch("Error in toggleHistoryPanel: ",o)}}_getNotificationsData(o){this.getService(y).log("%c[WB] Calling FUNCTION: _getNotificationsData","color: green;");try{return this.trackEvent(Z.Events.Notifications.GET_NOTIFICATIONS_DATA_TRIGGERED),this.getService(pn).getNotifications$(o)}catch(n){return this.getService(y).catch("Error in getNotificationsData: ",n),se([])}}_setMaxDays(o){this.getService(y).log("%c[WB] Calling FUNCTION: _setMaxDays","color: green;");try{this.trackEvent(Z.Events.Notifications.SET_MAX_DAYS_TRIGGERED,{payload:{days:o}}),this.getService(pn).setMaxDays(o)}catch(n){this.getService(y).catch("Error in setMaxDays: ",n)}}_setTabConfig(o){this.getService(y).log("%c[WB] Calling FUNCTION: _setTabConfig","color: green;");try{this.trackEvent(Z.Events.Notifications.SET_TAB_CONFIG_TRIGGERED,{payload:{tabConfig:o}}),this.getService(pn).setTabConfig(o)}catch(n){this.getService(y).catch("Error in setTabConfig: ",n)}}_enableReadNotificationsOnForYouTab(){this.getService(y).log("%c[WB] Calling FUNCTION: _enableReadNotificationsOnForYouTab","color: green;");try{this.trackEvent(Z.Events.Notifications.ENABLE_READ_NOTIFICATIONS_ON_FOR_YOU_TAB_TRIGGERED),this.getService(pn).enableReadNotificationsOnForYouTab()}catch(o){this.getService(y).catch("Error in enableReadNotificationsOnForYouTab: ",o)}}_disableReadNotificationsOnForYouTab(){this.getService(y).log("%c[WB] Calling FUNCTION: _disableReadNotificationsOnForYouTab","color: green;");try{this.trackEvent(Z.Events.Notifications.DISABLE_READ_NOTIFICATIONS_ON_FOR_YOU_TAB_TRIGGERED),this.getService(pn).disableReadNotificationsOnForYouTab()}catch(o){this.getService(y).catch("Error in disableReadNotificationsOnForYouTab: ",o)}}_setAllNotificationsAsRead(o){this.getService(y).log("%c[WB] Calling FUNCTION: _setAllNotificationsAsRead","color: green;");try{this.trackEvent(Z.Events.Notifications.SET_ALL_NOTIFICATIONS_AS_READ_TRIGGERED,{payload:{config:o}}),this.getService(pn).setAllNotificationsAsRead(o)}catch(n){this.getService(y).catch("Error in setAllNotificationsAsRead: ",n)}}_getUnreadNotificationsCount(){this.getService(y).log("%c[WB] Calling FUNCTION: _getUnreadNotificationsCount","color: green;");try{return this.trackEvent(Z.Events.Notifications.GET_UNREAD_NOTIFICATIONS_COUNT_TRIGGERED),this.getService(pn).getUnreadNotificationsCount$()}catch(o){return this.getService(y).catch("Error in getUnreadNotificationsCount: ",o),se({forYou:null,all:null})}}_markNotificationAsReadById(o){this.getService(y).log("%c[WB] Calling FUNCTION: _markNotificationAsReadById","color: green;");try{this.trackEvent(Z.Events.Notifications.MARK_NOTIFICATION_AS_READ_BY_ID_TRIGGERED,{payload:{notificationId:o}}),this.getService(pn).markNotificationAsReadById(o)}catch(n){this.getService(y).catch("Error in markNotificationAsReadById: ",n)}}_setSettings(o){this.getService(y).log("%c[WB] Calling FUNCTION: _setSettings","color: green;");try{this.trackEvent(Z.Events.Notifications.SET_SETTINGS_TRIGGERED,{payload:{config:o}}),this.getService(pn).setSettingsConfigWithDB(o)}catch(n){this.getService(y).catch("Error in setSettings: ",n)}}_getSettings(){this.getService(y).log("%c[WB] Calling FUNCTION: _getSettings","color: green;");try{return this.trackEvent(Z.Events.Notifications.GET_SETTINGS_TRIGGERED),this.getService(pn).getSettingsConfig$()}catch(o){return this.getService(y).catch("Error in getSettings: ",o),se(null)}}_muteAllNotifications(){this.getService(y).log("%c[WB] Calling FUNCTION: _muteAllNotifications","color: green;");try{this.trackEvent(Z.Events.Notifications.MUTE_ALL_NOTIFICATIONS_TRIGGERED),this.getService(pn).setMuteAllNotifications()}catch(o){this.getService(y).catch("Error in muteAllNotifications: ",o)}}_enableSettings(){this.getService(y).log("%c[WB] Calling FUNCTION: _enableSettings","color: green;");try{this.trackEvent(Z.Events.Notifications.ENABLE_SETTINGS_TRIGGERED),this.getService(pn).enableSettings()}catch(o){this.getService(y).catch("Error in enableSettings: ",o)}}_enableSelfNotifications(){this.getService(y).log("%c[WB] Calling FUNCTION: _enableSelfNotifications","color: green;");try{this.trackEvent(Z.Events.Notifications.ENABLE_SELF_NOTIFICATIONS_TRIGGERED),this.getService(pn).enableSelfNotifications()}catch(o){this.getService(y).catch("Error in enableSelfNotifications: ",o)}}_disableSelfNotifications(){this.getService(y).log("%c[WB] Calling FUNCTION: _disableSelfNotifications","color: green;");try{this.trackEvent(Z.Events.Notifications.DISABLE_SELF_NOTIFICATIONS_TRIGGERED),this.getService(pn).disableSelfNotifications()}catch(o){this.getService(y).catch("Error in disableSelfNotifications: ",o)}}_disableSettings(){this.getService(y).log("%c[WB] Calling FUNCTION: _disableSettings","color: green;");try{this.trackEvent(Z.Events.Notifications.DISABLE_SETTINGS_TRIGGERED),this.getService(pn).disableSettings()}catch(o){this.getService(y).catch("Error in disableSettings: ",o)}}_setSettingsInitialConfig(o){this.getService(y).log("%c[WB] Calling FUNCTION: _setSettingsInitialConfig","color: green;");try{this.trackEvent(Z.Events.Notifications.SET_SETTINGS_INITIAL_CONFIG_TRIGGERED,{payload:{settings:o}}),this.getService(pn).setSettingsInitialConfig(o)}catch(n){this.getService(y).catch("Error in setSettingsInitialConfig: ",n)}}_on(o){this.getService(y).log("%c[WB] Calling FUNCTION: on","color: green;");try{return this.trackEvent(Z.Events.Notifications.ON_ACTION_TRIGGERED,{payload:{action:o}}),this.getService(v9).onAction(o)}catch(n){return this.getService(y).catch("Error in _on: ",n),se(null)}}_openNotificationsPanel(){this.getService(y).log("%c[WB] Calling FUNCTION: _openNotificationsPanel","color: green;");try{this.trackEvent(Z.Events.Notifications.OPEN_NOTIFICATIONS_PANEL_TRIGGERED),this.getService(pn).openNotificationsPanel()}catch(o){this.getService(y).catch("Error in openNotificationsPanel: ",o)}}_closeNotificationsPanel(){this.getService(y).log("%c[WB] Calling FUNCTION: _closeNotificationsPanel","color: green;");try{this.trackEvent(Z.Events.Notifications.CLOSE_NOTIFICATIONS_PANEL_TRIGGERED),this.getService(pn).closeNotificationsPanel()}catch(o){this.getService(y).catch("Error in closeNotificationsPanel: ",o)}}_enableCurrentDocumentOnly(){this.getService(y).log("%c[WB] Calling FUNCTION: _enableCurrentDocumentOnly","color: green;");try{this.trackEvent(Z.Events.Notifications.ENABLE_CURRENT_DOCUMENT_ONLY_TRIGGERED),this.getService(pn).enableCurrentDocumentOnly()}catch(o){this.getService(y).catch("Error in enableCurrentDocumentOnly: ",o)}}_disableCurrentDocumentOnly(){this.getService(y).log("%c[WB] Calling FUNCTION: _disableCurrentDocumentOnly","color: green;");try{this.trackEvent(Z.Events.Notifications.DISABLE_CURRENT_DOCUMENT_ONLY_TRIGGERED),this.getService(pn).disableCurrentDocumentOnly()}catch(o){this.getService(y).catch("Error in disableCurrentDocumentOnly: ",o)}}};var Xz=(()=>{let o=class o{constructor(e,t,r){this.analyticsService=e,this.loggingService=t,this.presenceService=r,this.actionSubjects=new Map,this.subscriptions=[];try{this.presenceService.setPresenceActionsService(this)}catch(a){this.loggingService.catch("Error in PresenceActionsService constructor: ",a)}}onMultipleUsersOnline(e){try{this.loggingService.log("%c[WB] Calling PresenceActionsService FUNCTION: onMultipleUsersOnline","color: green;"),this.triggerAction(jj.MULTIPLE_USERS_ONLINE,e),this.analyticsService.trackEvent(Z.Events.Presence.MULTIPLE_USERS_ONLINE,{totalUsers:e?.users?.length,presenceSnippylyUserIds:e?.users?.map(t=>t.userSnippylyId),presenceClientUserIds:e?.users?.map(t=>t.userId)})}catch(t){this.loggingService.catch("Error in PresenceActionsService onMultipleUsersOnline: ",t)}}onUserStateChange(e){try{this.loggingService.log("%c[WB] Calling PresenceActionsService FUNCTION: onUserStateChange","color: green;"),this.triggerAction(jj.USER_STATE_CHANGE,e),this.analyticsService.trackEvent(Z.Events.Presence.ON_USER_STATE_CHANGE,{userSnippylyId:e?.user?.userSnippylyId,userId:e?.user?.userId,state:e?.state})}catch(t){this.loggingService.catch("Error in PresenceActionsService onUserStateChange: ",t)}}getData(e){try{return this.loggingService.log("%c[WB] Calling PresenceActionsService FUNCTION: getData","color: green;"),this.presenceService.getOnlineUsersOnCurrentDocument(e).pipe(de(t=>({data:t})))}catch(t){return this.loggingService.catch("Error in PresenceActionsService getData: ",t),se({data:null})}}triggerAction(e,t){try{this.actionSubjects.has(e)||this.actionSubjects.set(e,new tt),this.actionSubjects.get(e)?.next(t)}catch(r){this.loggingService.catch("Error in PresenceActionsService triggerAction: ",r)}}onAction(e){try{return this.actionSubjects.has(e)||this.actionSubjects.set(e,new tt),this.actionSubjects.get(e)?.asObservable()}catch(t){return this.loggingService.catch("Error in PresenceActionsService onAction: ",t),se(null)}}};o.\u0275fac=function(t){return new(t||o)(J(et),J(y),J(Wl))},o.\u0275prov=Ae({token:o,factory:o.\u0275fac,providedIn:"root"});let i=o;return i})();var _9=class extends ci{constructor(o){super(o),this.getService(y).log("%c[WB] Creating CLASS: PresenceElement","color: blue;"),this.getOnlineUsersOnCurrentDocument=this._getOnlineUsersOnCurrentDocument,this.setInactivityTime=this._setInactivityTime,this.enableFlockMode=this._enableFlockMode,this.disableFlockMode=this._disableFlockMode,this.startFollowingUser=this._startFollowingUser,this.stopFollowingUser=this._stopFollowingUser,this.enableSelf=this._enableSelf,this.disableSelf=this._disableSelf,this.getData=this._getData,this.on=this._on}_getOnlineUsersOnCurrentDocument(){this.getService(y).log("%c[WB] Calling FUNCTION: getOnlineUsers","color: green;");try{return this.trackEvent(Z.Events.Presence.GET_ONLINE_USERS_ON_CURRENT_DOCUMENT_TRIGGERED),this.getService(Wl).getOnlineUsersOnCurrentDocument()}catch(o){return this.getService(y).catch("Error in _getOnlineUsersOnCurrentDocument: ",o),se(null)}}_setInactivityTime(o){this.getService(y).log("%c[WB] Calling FUNCTION: _setInactivityTime","color: green;");try{this.trackEvent(Z.Events.Presence.SET_INACTIVITY_TIME_TRIGGERED,{payload:{time:o}}),isNaN(o)?this.getService(y).catch("Error in setInactivityTime: ","Provided value is not a number."):this.getService(Wl).setInactivityTime(o)}catch(n){this.getService(y).catch("Error in setInactivityTime: ",n)}}_disableFlockMode(){try{this.trackEvent(Z.Events.Presence.DISABLE_FLOCK_MODE_TRIGGERED),this.getService(Gc).disableFlockMode()}catch(o){this.getService(y).catch("Error in _disableFlockMode: ",o)}}_enableFlockMode(o){try{this.trackEvent(Z.Events.Presence.ENABLE_FLOCK_MODE_TRIGGERED,{payload:{options:o}}),this.getService(Gc).enableFlockMode(o)}catch(n){this.getService(y).catch("Error in _enableFlockMode: ",n)}}_stopFollowingUser(){try{this.trackEvent(Z.Events.Presence.STOP_FOLLOWING_USER_TRIGGERED),this.getService(Gc).stopFollowingUser()}catch(o){this.getService(y).catch("Error in _stopFollowingUser: ",o)}}_startFollowingUser(o){try{this.trackEvent(Z.Events.Presence.START_FOLLOWING_USER_TRIGGERED,{payload:{externalId:o}});let n=this.getService(Wl).getPresenceUserFromExternalId(o);return n&&n.userSnippylyId&&n.name!==void 0?(this.getService(Gc).startFollowingUser(n.userSnippylyId,n.name),{success:!0,msg:"Joined flock session."}):{success:!1,msg:"User could not be found."}}catch(n){return this.getService(y).catch("Error in _startFollowingUser: ",n),{success:!1,msg:"Unknown error.",raw:n}}}_enableSelf(){try{this.trackEvent(Z.Events.Presence.ENABLE_SELF_TRIGGERED),this.getService(Wl).enableIncludeSelf()}catch(o){this.getService(y).catch("Error in _enableSelf: ",o)}}_disableSelf(){try{this.trackEvent(Z.Events.Presence.DISABLE_SELF_TRIGGERED),this.getService(Wl).disableIncludeSelf()}catch(o){this.getService(y).catch("Error in _disableSelf: ",o)}}_getData(o){this.getService(y).log("%c[WB] Calling FUNCTION: getData","color: green;");try{return this.trackEvent(Z.Events.Presence.GET_PRESENCE_DATA_TRIGGERED,{payload:{query:o}}),o&&typeof o=="object"&&(o=I({},o),o?.documentId&&(o.documentId=ia(o.documentId)),o?.organizationId&&(o.organizationId=Ua(o.organizationId))),this.getService(Xz).getData(o)}catch(n){return this.getService(y).catch("Error in _getData: ",n),se({data:null})}}_on(o){this.getService(y).log("%c[WB] Calling FUNCTION: on","color: green;");try{return this.trackEvent(Z.Events.Presence.ON_ACTION_TRIGGERED,{payload:{action:o}}),this.getService(Xz).onAction(o)}catch(n){return this.getService(y).catch("Error in _on: ",n),se(null)}}};var y9=class extends ci{constructor(o){super(o),this.getService(y).log("%c[WB] Creating CLASS: ReactionElement","color: blue;"),this.enableDarkMode=this._enableDarkMode,this.disableDarkMode=this._disableDarkMode,this.setCustomReactions=this._setCustomReactions}_enableDarkMode(){this.getService(y).log("%c[WB] Calling FUNCTION: enableDarkMode","color: green;");try{this.trackEvent(Z.Events.Reactions.ENABLE_DARK_MODE_TRIGGERED),this.getService(ar).enableDarkMode()}catch(o){this.getService(y).catch("Error in _enableDarkMode: ",o)}}_disableDarkMode(){this.getService(y).log("%c[WB] Calling FUNCTION: disableDarkMode","color: green;");try{this.trackEvent(Z.Events.Reactions.DISABLE_DARK_MODE_TRIGGERED),this.getService(ar).disableDarkMode()}catch(o){this.getService(y).catch("Error in _disableDarkMode: ",o)}}_setCustomReactions(o){this.getService(y).log("%c[WB] Calling FUNCTION: setCustomReactions","color: green;");try{this.trackEvent(Z.Events.Reactions.SET_CUSTOM_REACTIONS_TRIGGERED,{payload:{reactions:o}}),this.getService(ar).setCustomReactions(o)}catch(n){this.getService(y).catch("Error in _setCustomReactions: ",n)}}};var hg=(()=>{let o=class o{constructor(e,t,r){this.loggingService=e,this.recorderAnnotationService=t,this.recorderService=r,this.actionSubjects=new Map,this.subscriptions=[];try{this.recorderAnnotationService.setRecorderActionsService(this),this.recorderService.setRecorderActionsService(this)}catch(a){this.loggingService.catch("Error in RecorderActionsService constructor: ",a)}}onTranscriptionDone(e){try{this.triggerAction(Vl.TRANSCRIPTION_DONE,e)}catch(t){this.loggingService.catch("Error in RecorderActionsService onTranscriptionDone: ",t)}}onRecordingDone(e){try{this.triggerAction(Vl.RECORDING_DONE,e)}catch(t){this.loggingService.catch("Error in RecorderActionsService onRecordingDone: ",t)}}onRecordingEditDone(e){try{this.triggerAction(Vl.RECORDING_EDIT_DONE,e)}catch(t){this.loggingService.catch("Error in RecorderActionsService onRecordingEditDone: ",t)}}onRecordingStarted(e){try{this.triggerAction(Vl.RECORDING_STARTED,e)}catch(t){this.loggingService.catch("Error in RecorderActionsService onRecordingStarted: ",t)}}onRecordingPaused(e){try{this.triggerAction(Vl.RECORDING_PAUSED,e)}catch(t){this.loggingService.catch("Error in RecorderActionsService onRecordingPaused: ",t)}}onRecordingCancelled(e){try{this.triggerAction(Vl.RECORDING_CANCELLED,e)}catch(t){this.loggingService.catch("Error in RecorderActionsService onRecordingCancelled: ",t)}}onRecordingStopped(e){try{this.triggerAction(Vl.RECORDING_STOPPED,e)}catch(t){this.loggingService.catch("Error in RecorderActionsService onRecordingStopped: ",t)}}onRecordingResumed(e){try{this.triggerAction(Vl.RECORDING_RESUMED,e)}catch(t){this.loggingService.catch("Error in RecorderActionsService onRecordingResumed: ",t)}}onDeleteRecording(e){try{this.triggerAction(Vl.DELETE_RECORDING,e)}catch(t){this.loggingService.catch("Error in RecorderActionsService onDeleteRecording: ",t)}}onError(e){try{this.triggerAction(Vl.ERROR,e)}catch(t){this.loggingService.catch("Error in RecorderActionsService onError: ",t)}}onRecordingSaveInitiated(e){try{this.triggerAction(Vl.RECORDING_SAVE_INITIATED,e)}catch(t){this.loggingService.catch("Error in RecorderActionsService onRecordingSaveInitiated: ",t)}}triggerAction(e,t){try{this.actionSubjects.has(e)||this.actionSubjects.set(e,new tt),this.actionSubjects.get(e)?.next(t)}catch(r){this.loggingService.catch("Error in RecorderActionsService triggerAction: ",r)}}onAction(e){try{return this.actionSubjects.has(e)||this.actionSubjects.set(e,new tt),this.actionSubjects.get(e)?.asObservable()}catch(t){return this.loggingService.catch("Error in RecorderActionsService onAction: ",t),se(null)}}};o.\u0275fac=function(t){return new(t||o)(J(y),J(Ki),J(_n))},o.\u0275prov=Ae({token:o,factory:o.\u0275fac,providedIn:"root"});let i=o;return i})();var S9=class extends ci{constructor(o){super(o),this.getService(y).log("%c[WB] Creating CLASS: RecorderElement","color: blue;"),this.initRecording=this._initRecording,this.onRecordedData=this._onRecordedData,this.enableDarkMode=this._enableDarkMode,this.disableDarkMode=this._disableDarkMode,this.enableRecordingCountdown=this._enableRecordingCountdown,this.disableRecordingCountdown=this._disableRecordingCountdown,this.getRecordingDataByRecorderId=this._getRecordingDataByRecorderId,this.enableRecordingTranscription=this._enableRecordingTranscription,this.disableRecordingTranscription=this._disableRecordingTranscription,this.getRecordingData=this._getRecordingData,this.enableVideoEditor=this._enableVideoEditor,this.disableVideoEditor=this._disableVideoEditor,this.getRecordings=this._getRecordings,this.fetchRecordings=this._fetchRecordings,this.deleteRecordings=this._deleteRecordings,this.setRecordingQualityConstraints=this._setRecordingQualityConstraints,this.setRecordingEncodingOptions=this._setRecordingEncodingOptions,this.downloadLatestVideo=this._downloadLatestVideo,this.enableRecordingMic=this._enableRecordingMic,this.disableRecordingMic=this._disableRecordingMic,this.enableOnboardingTooltip=this._enableOnboardingTooltip,this.disableOnboardingTooltip=this._disableOnboardingTooltip,this.enableRetakeOnVideoEditor=this._enableRetakeOnVideoEditor,this.disableRetakeOnVideoEditor=this._disableRetakeOnVideoEditor,this.askDevicePermission=this._askDevicePermission,this.setMaxLength=this._setMaxLength,this.openPictureInPicture=this._openPictureInPicture,this.exitPictureInPicture=this._exitPictureInPicture,this.requestScreenPermission=this._requestScreenPermission,this.enablePictureInPicture=this._enablePictureInPicture,this.disablePictureInPicture=this._disablePictureInPicture,this.enablePlaybackOnPreviewClick=this._enablePlaybackOnPreviewClick,this.disablePlaybackOnPreviewClick=this._disablePlaybackOnPreviewClick,this.on=this._on}_initRecording(o,n){this.getService(y).log("%c[WB] Calling FUNCTION: initRecording","color: green;");try{return this.trackEvent(Z.Events.Recording.INIT_RECORDING_TRIGGERED,{payload:{type:o,panelId:n}}),this.getService(_n).initRecording(o,n)}catch(e){return this.getService(y).catch("Error in _initRecording: ",e),se(null)}}_onRecordedData(){this.getService(y).log("%c[WB] Calling FUNCTION: onRecordedData","color: green;");try{return this.trackEvent(Z.Events.Recording.ON_RECORDED_DATA_TRIGGERED),this.getService(_n).onRecordedData()}catch(o){return this.getService(y).catch("Error in _onRecordedData: ",o),se(null)}}_enableDarkMode(){this.getService(y).log("%c[WB] Calling FUNCTION: enableDarkMode","color: green;");try{this.trackEvent(Z.Events.Recording.ENABLE_DARK_MODE_TRIGGERED),this.getService(Ki).setRecorderContainerDarkMode(!0)}catch(o){this.getService(y).catch("Error in _enableDarkMode: ",o)}}_disableDarkMode(){this.getService(y).log("%c[WB] Calling FUNCTION: disableDarkMode","color: green;");try{this.trackEvent(Z.Events.Recording.DISABLE_DARK_MODE_TRIGGERED),this.getService(Ki).setRecorderContainerDarkMode(!1)}catch(o){this.getService(y).catch("Error in _disableDarkMode: ",o)}}_enableRecordingCountdown(){this.getService(y).log("%c[WB] Calling FUNCTION: enableRecordingCountdown","color: green;");try{this.trackEvent(Z.Events.Recording.ENABLE_RECORDING_COUNTDOWN_TRIGGERED),this.getService(_n).enableRecordingCountdown()}catch(o){this.getService(y).catch("Error in _enableRecordingCountdown: ",o)}}_disableRecordingCountdown(){this.getService(y).log("%c[WB] Calling FUNCTION: disableRecordingCountdown","color: green;");try{this.trackEvent(Z.Events.Recording.DISABLE_RECORDING_COUNTDOWN_TRIGGERED),this.getService(_n).disableRecordingCountdown()}catch(o){this.getService(y).catch("Error in _disableRecordingCountdown: ",o)}}_getRecordingDataByRecorderId(o){this.getService(y).log("%c[WB] Calling FUNCTION: getRecordingDataByRecorderId","color: green;");try{return this.trackEvent(Z.Events.Recording.GET_RECORDING_DATA_BY_RECORDER_ID_TRIGGERED,{payload:{recorderId:o}}),this.getService(Ki).getRecorderDataByRecorderId(o)}catch(n){return this.getService(y).catch("Error in _getRecordingDataByRecorderId: ",n),se(null)}}_getRecordings(o){this.getService(y).log("%c[WB] Calling FUNCTION: getRecordings","color: green;");try{return this.trackEvent(Z.Events.Recording.GET_RECORDINGS_TRIGGERED,{payload:{query:o}}),this.getService(Ki).getRecordings(o)}catch(n){return this.getService(y).catch("Error in _getRecordings: ",n),se([])}}_getRecordingData(o){this.getService(y).log("%c[WB] Calling FUNCTION: getRecordingData","color: green;");try{return this.trackEvent(Z.Events.Recording.GET_RECORDING_DATA_TRIGGERED,{payload:{query:o}}),this.getService(Ki).getRecorderDataByRecorderIds(o)}catch(n){return this.getService(y).catch("Error in _getRecordingData: ",n),Promise.resolve({data:null})}}_fetchRecordings(o){this.getService(y).log("%c[WB] Calling FUNCTION: fetchRecordings","color: green;");try{return this.trackEvent(Z.Events.Recording.FETCH_RECORDINGS_TRIGGERED,{payload:{query:o}}),this.getService(Ki).fetchRecorderDataByRecorderIds(o)}catch(n){return this.getService(y).catch("Error in _fetchRecordings: ",n),Promise.resolve([])}}_deleteRecordings(o){this.getService(y).log("%c[WB] Calling FUNCTION: deleteRecording","color: green;");try{return this.trackEvent(Z.Events.Recording.DELETE_RECORDING_TRIGGERED,{payload:{query:o}}),this.getService(Ki).deleteRecorderDataByRecorderIds(o)}catch(n){return this.getService(y).catch("Error in _deleteRecording: ",n),Promise.resolve([])}}_enableRecordingTranscription(){this.getService(y).log("%c[WB] Calling FUNCTION: enableRecordingTranscription","color: green;");try{this.trackEvent(Z.Events.Recording.ENABLE_RECORDING_TRANSCRIPTION_TRIGGERED),this.getService(Ki).enableRecordingTranscription()}catch(o){this.getService(y).catch("Error in _enableRecordingTranscription: ",o)}}_disableRecordingTranscription(){this.getService(y).log("%c[WB] Calling FUNCTION: disableRecordingTranscription","color: green;");try{this.trackEvent(Z.Events.Recording.DISABLE_RECORDING_TRANSCRIPTION_TRIGGERED),this.getService(Ki).disableRecordingTranscription()}catch(o){this.getService(y).catch("Error in _disableRecordingTranscription: ",o)}}_on(o){this.getService(y).log("%c[WB] Calling FUNCTION: on","color: green;");try{return this.trackEvent(Z.Events.Recording.ON_ACTION_TRIGGERED,{payload:{action:o}}),this.getService(hg).onAction(o)}catch(n){return this.getService(y).catch("Error in _on: ",n),se(null)}}_enableVideoEditor(){this.getService(y).log("%c[WB] Calling FUNCTION: enableVideoEditor","color: green;");try{this.trackEvent(Z.Events.Recording.ENABLE_VIDEO_EDITOR_TRIGGERED),this.getService(_n).enableVideoEditor()}catch(o){this.getService(y).catch("Error in _enableVideoEditor: ",o)}}_disableVideoEditor(){this.getService(y).log("%c[WB] Calling FUNCTION: disableVideoEditor","color: green;");try{this.trackEvent(Z.Events.Recording.DISABLE_VIDEO_EDITOR_TRIGGERED),this.getService(_n).disableVideoEditor()}catch(o){this.getService(y).catch("Error in _disableVideoEditor: ",o)}}_setRecordingQualityConstraints(o){this.getService(y).log("%c[WB] Calling FUNCTION: setRecordingQualityConstraints","color: green;");try{this.trackEvent(Z.Events.Recording.SET_RECORDING_QUALITY_CONSTRAINTS_TRIGGERED,{payload:{constraints:o}}),this.getService(_n).setRecordingQualityConstraints(o)}catch(n){this.getService(y).catch("Error in _setRecordingQualityConstraints: ",n)}}_setRecordingEncodingOptions(o){this.getService(y).log("%c[WB] Calling FUNCTION: setRecordingEncodingOptions","color: green;");try{this.trackEvent(Z.Events.Recording.SET_RECORDING_ENCODING_OPTIONS_TRIGGERED,{payload:{options:o}}),this.getService(_n).setRecordingEncodingOptions(o)}catch(n){this.getService(y).catch("Error in _setRecordingEncodingOptions: ",n)}}_downloadLatestVideo(o){this.getService(y).log("%c[WB] Calling FUNCTION: downloadLatestVideo","color: green;");try{return this.trackEvent(Z.Events.Recording.DOWNLOAD_LATEST_VIDEO_TRIGGERED,{payload:{recorderId:o}}),this.getService(Ki).downloadLatestVideo(o)}catch(n){return this.getService(y).catch("Error in _downloadLatestVideo: ",n),Promise.resolve(!1)}}_enableRecordingMic(){this.getService(y).log("%c[WB] Calling FUNCTION: enableRecordingMic","color: green;");try{this.trackEvent(Z.Events.Recording.ENABLE_RECORDING_MIC_TRIGGERED),this.getService(_n).enableRecordingMic()}catch(o){this.getService(y).catch("Error in _enableRecordingMic: ",o)}}_disableRecordingMic(){this.getService(y).log("%c[WB] Calling FUNCTION: disableRecordingMic","color: green;");try{this.trackEvent(Z.Events.Recording.DISABLE_RECORDING_MIC_TRIGGERED),this.getService(_n).disableRecordingMic()}catch(o){this.getService(y).catch("Error in _disableRecordingMic: ",o)}}_enableOnboardingTooltip(){this.getService(y).log("%c[WB] Calling FUNCTION: enableOnboardingTooltip","color: green;");try{this.trackEvent(Z.Events.Recording.ENABLE_ONBOARDING_TOOLTIP_TRIGGERED),this.getService(_n).enableOnboardingTooltip()}catch(o){this.getService(y).catch("Error in _enableOnboardingTooltip: ",o);return}}_disableOnboardingTooltip(){this.getService(y).log("%c[WB] Calling FUNCTION: disableOnboardingTooltip","color: green;");try{this.trackEvent(Z.Events.Recording.DISABLE_ONBOARDING_TOOLTIP_TRIGGERED),this.getService(_n).disableOnboardingTooltip()}catch(o){this.getService(y).catch("Error in _disableOnboardingTooltip: ",o);return}}_enableRetakeOnVideoEditor(){this.getService(y).log("%c[WB] Calling FUNCTION: enableRetakeOnVideoEditor","color: green;");try{this.trackEvent(Z.Events.Recording.ENABLE_RETAKE_ON_VIDEO_EDITOR_TRIGGERED),this.getService(_n).enableRetakeOnVideoEditor()}catch(o){this.getService(y).catch("Error in _enableRetakeOnVideoEditor: ",o)}}_disableRetakeOnVideoEditor(){this.getService(y).log("%c[WB] Calling FUNCTION: disableRetakeOnVideoEditor","color: green;");try{this.trackEvent(Z.Events.Recording.DISABLE_RETAKE_ON_VIDEO_EDITOR_TRIGGERED),this.getService(_n).disableRetakeOnVideoEditor()}catch(o){this.getService(y).catch("Error in _disableRetakeOnVideoEditor: ",o)}}_askDevicePermission(o){this.getService(y).log("%c[WB] Calling FUNCTION: askDevicePermission","color: green;");try{this.trackEvent(Z.Events.Recording.ASK_DEVICE_PERMISSION_TRIGGERED),this.getService(_n).askDevicePermission(o)}catch(n){this.getService(y).catch("Error in _askDevicePermission: ",n)}}_setMaxLength(o){this.getService(y).log("%c[WB] Calling FUNCTION: setMaxLength","color: green;");try{this.trackEvent(Z.Events.Recording.SET_MAX_LENGTH_TRIGGERED,{payload:{seconds:o}}),this.getService(_n).setMaxRecordingLength(o)}catch(n){this.getService(y).catch("Error in _setMaxLength: ",n)}}_openPictureInPicture(){return Q(this,null,function*(){this.getService(y).log("%c[WB] Calling FUNCTION: openPictureInPicture","color: green;");try{this.trackEvent(Z.Events.Recording.OPEN_PICTURE_IN_PICTURE_TRIGGERED),yield this.getService(_n).openPictureInPicture()}catch(o){this.getService(y).catch("Error in _openPictureInPicture: ",o)}})}_exitPictureInPicture(){return Q(this,null,function*(){this.getService(y).log("%c[WB] Calling FUNCTION: exitPictureInPicture","color: green;");try{this.trackEvent(Z.Events.Recording.EXIT_PICTURE_IN_PICTURE_TRIGGERED),yield this.getService(Ga).exitPictureInPicture()}catch(o){this.getService(y).catch("Error in _exitPictureInPicture: ",o)}})}_requestScreenPermission(){return Q(this,null,function*(){this.getService(y).log("%c[WB] Calling FUNCTION: requestScreenPermission","color: green;");try{return this.trackEvent(Z.Events.Recording.REQUEST_SCREEN_PERMISSION_TRIGGERED),this.getService(_n).requestScreenPermission()}catch(o){return this.getService(y).catch("Error in _requestScreenPermission: ",o),null}})}_enablePictureInPicture(){this.getService(y).log("%c[WB] Calling FUNCTION: enablePictureInPicture","color: green;");try{this.trackEvent(Z.Events.Recording.ENABLE_PICTURE_IN_PICTURE_TRIGGERED),this.getService(Ga).enablePictureInPicture()}catch(o){this.getService(y).catch("Error in _enablePictureInPicture: ",o)}}_disablePictureInPicture(){this.getService(y).log("%c[WB] Calling FUNCTION: disablePictureInPicture","color: green;");try{this.trackEvent(Z.Events.Recording.DISABLE_PICTURE_IN_PICTURE_TRIGGERED),this.getService(Ga).disablePictureInPicture()}catch(o){this.getService(y).catch("Error in _disablePictureInPicture: ",o)}}_enablePlaybackOnPreviewClick(){this.getService(y).log("%c[WB] Calling FUNCTION: enablePlaybackOnPreviewClick","color: green;");try{this.trackEvent(Z.Events.Recording.ENABLE_PLAYBACK_ON_PREVIEW_CLICK_TRIGGERED),this.getService(_n).enablePlaybackOnPreviewClick()}catch(o){this.getService(y).catch("Error in _enablePlaybackOnPreviewClick: ",o)}}_disablePlaybackOnPreviewClick(){this.getService(y).log("%c[WB] Calling FUNCTION: disablePlaybackOnPreviewClick","color: green;");try{this.trackEvent(Z.Events.Recording.DISABLE_PLAYBACK_ON_PREVIEW_CLICK_TRIGGERED),this.getService(_n).disablePlaybackOnPreviewClick()}catch(o){this.getService(y).catch("Error in _disablePlaybackOnPreviewClick: ",o)}}};var Wc=(()=>{let o=class o{constructor(e,t,r,a,s,c){this.analyticsService=e,this.authService=t,this.configService=r,this.domService=a,this.loggingService=s,this.functions=c,this.rewriterAnnotations$=new ve([]),this.rewriterOptions$=new ve({}),this.rewriterEnabled$=new ve(!1),this.lastOpenAIPromptCalledAt=0,this.getRewriterEnabled$().subscribe(p=>{try{if(p){let g=document.querySelectorAll(j.TAGS.SNIPPYLY_REWRITER);if(!document.querySelectorAll(j.TAGS.VELT_REWRITER)?.length&&!g?.length){let E=document.createElement(j.TAGS.VELT_REWRITER);document.body.appendChild(E),this.authService.getUser$().pipe(Le(D=>!!D),at(1)).subscribe(D=>{this.analyticsService.trackEvent(Z.Events.Rewriter.REWRITER_ENABLED,{isMobileDevice:this.domService.isMobileDevice()})})}}else{let g=document.querySelectorAll(j.TAGS.SNIPPYLY_REWRITER);g?.length&&g.forEach(E=>{E.remove()});let C=document.querySelectorAll(j.TAGS.VELT_REWRITER);C?.length&&C.forEach(E=>{E.remove()})}}catch(g){this.loggingService.catch("Error in rewriterEnabled$: ",g)}},p=>{this.loggingService.catch("Error in rewriterEnabled$ subscription: ",p)})}getRewriterAnnotations$(){try{return this.rewriterAnnotations$.asObservable()}catch(e){return this.loggingService.catch("Error in getRewriterAnnotations$(): ",e),se([])}}addRewriter(e,t,r){this.loggingService.log("%c[WB] Calling FUNCTION: addRewriter","color: green;");try{let a=this.authService.getUser();if(a)if(a.isReadOnly||a.isAnonymous)this.loggingService.catch("Anonymous/Readonly users cannot add rewriters.");else{let s=new Fk;s.from=a,s.color=j.DEFAULT_ANNOTATION_COLOR,t&&(s.targetTextRange=t),r&&(s.rewriterType=r),this.saveRewriterToDb(s)}}catch(a){this.loggingService.catch("Error in RewriterService addRewriter: ",a)}}saveRewriterToDb(e){this.loggingService.log("%c[WB] Calling FUNCTION: saveRewriterToDb","color: green;");try{e?.annotationId||(e.annotationId=Math.random().toString(36).substring(2)+Date.now().toString(36));let t=this.rewriterAnnotations$.getValue();t.push(e),this.rewriterAnnotations$.next(t),this.domService.toggleAnnotationSelection(e)}catch(t){this.loggingService.catch("Error in RewriterService saveRewriterToDb: ",t)}}removeRewriter(e){try{let t=this.rewriterAnnotations$.getValue(),r=t.findIndex(a=>a.annotationId===e.annotationId);r>-1&&(t.splice(r,1),this.rewriterAnnotations$.next(t))}catch(t){this.loggingService.catch("Error in RewriterService removeRewriter: ",t)}}getRewriterOptions(e,t,r){try{if(this.lastOpenAIPromptCalledAt&&Date.now()-this.lastOpenAIPromptCalledAt<1e3)return this.lastOpenAIPromptCalledAt=Date.now(),se([]);this.lastOpenAIPromptCalledAt=Date.now();let a=br(this.functions,Er({url:ri.cloudFunction.chatgptCompletion,apiProxyDomain:this.configService?.getApiProxyDomain()}),{timeout:20*60*1e3}),s=t?.[0]?.role==="system"?t?.[0]?.content:null;return this.analyticsService.trackEvent(Z.Events.Rewriter.REWRITE_PROMPT_SUBMITTED,{isMobileDevice:this.domService.isMobileDevice(),prompt:s,type:e}),Zi(a({messages:t,type:e,apiKey:this.configService.getApiKey(),sdkVersion:oa(),sdkType:this.configService.getSdkType()})).pipe(de(c=>c?.data?c.data:[]))}catch(a){return this.loggingService.catch("Error in RewriterService getRewriterOptions: ",a),se([])}}enableRewriter(){try{this.rewriterEnabled$.next(!0)}catch(e){this.loggingService.catch("Error in RewriterService enableRewriter: ",e)}}disableRewriter(){try{this.rewriterEnabled$.next(!1)}catch(e){this.loggingService.catch("Error in RewriterService disableRewriter: ",e)}}getRewriterEnabled$(){try{return this.rewriterEnabled$.asObservable()}catch(e){return this.loggingService.catch("Error in RewriterService getRewriterEnabled$: ",e),se(!1)}}resetRewriter(){try{this.domService.resetSelectedAnnotationsMap(!1,"rewriter"),this.rewriterAnnotations$.next([])}catch(e){this.loggingService.catch("Error in RewriterService resetRewriter: ",e)}}getChatGPTInput(e,t,r=[]){try{let a="";return e&&(a=`
|
|
488
488
|
${a}
|
|
489
489
|
<|im_start|>system
|
|
490
490
|
${e}
|