@veltdev/sdk-dev 4.5.4-beta.4 → 4.5.4-beta.5
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-dev",
|
|
3
|
-
"version": "4.5.4-beta.
|
|
3
|
+
"version": "4.5.4-beta.5",
|
|
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.4-beta.
|
|
1
|
+
var SNIPPYLY_VERSION = '4.5.4-beta.5';
|
|
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 g1e=Object.create;var VO=Object.defineProperty,u1e=Object.defineProperties,h1e=Object.getOwnPropertyDescriptor,f1e=Object.getOwnPropertyDescriptors,v1e=Object.getOwnPropertyNames,BO=Object.getOwnPropertySymbols,KW=Object.getPrototypeOf,e8=Object.prototype.hasOwnProperty,ZW=Object.prototype.propertyIsEnumerable,C1e=Reflect.get;var YW=(i,o,n)=>o in i?VO(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(BO)for(var n of BO(o))ZW.call(o,n)&&YW(i,n,o[n]);return i},T=(i,o)=>u1e(i,f1e(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&&BO)for(var e of BO(i))o.indexOf(e)<0&&ZW.call(i,e)&&(n[e]=i[e]);return n};var _1e=(i,o)=>()=>(o||i((o={exports:{}}).exports,o),o.exports),UO=(i,o)=>{for(var n in o)VO(i,n,{get:o[n],enumerable:!0})},y1e=(i,o,n,e)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of v1e(o))!e8.call(i,t)&&t!==n&&VO(i,t,{get:()=>o[t],enumerable:!(e=h1e(o,t))||e.enumerable});return i};var XW=(i,o,n)=>(n=i!=null?g1e(KW(i)):{},y1e(o||!i||!i.__esModule?VO(n,"default",{value:i,enumerable:!0}):n,i));var rp=(i,o,n)=>C1e(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=_1e((Wyo,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] Creating CLASS: HeartbeatService","color: blue;"),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),Zt(()=>this.sendHeartbeat())).subscribe();let e=En([this.databaseService.getDb().pipe(Le(t=>!!t)),this.authService.getUser$(),this.docService.getDocumentPaths$()]).pipe(Di(),Zt(([[t,r,a],[s,c,p]])=>{if(c&&p){let u=this.domService.getTabId();if(u){let C=this.generateHeartbeatId(c.userId,u),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&&ol(Pi(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&&ol(Pi(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.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{if(this.loggingService.log("%c[WB] Calling HeartbeatService FUNCTION: sendHeartbeat","color: green;"),sessionStorage.getItem("veltSkipHeartbeat"))return;let e=this.authService.getUser(),t=this.docService.getDocumentPaths(),r=this.domService.getTabId();if(e&&t&&r){let a=new Ak,s=Date.now();a.createdTimestamp=s,a.lastUpdatedTimestamp=s,a.userId=e.userId,a.veltUserId=yt(e.userId),a.tabId=r,a.id=this.generateHeartbeatId(e.userId,r),a.metadata=this.docService.getBaseMetadata();let p=a.metadata.documentId;this.commonDbService.updateData({feature:"heartbeat",properties:{id:a.id,skipFirestore:!0,rtdbTransaction:!0,rtdbTransactionCallback:(u,C)=>(u?.createdTimestamp&&(C.createdTimestamp=u.createdTimestamp),C)},data:a}),p&&this.commonDbService.updateData({feature:"heartbeatByDocument",properties:{id:a.id,skipFirestore:!0,rtdbTransaction:!0,documentId:p,rtdbTransactionCallback:(u,C)=>(u?.createdTimestamp&&(C.createdTimestamp=u.createdTimestamp),C)},data:a})}}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",u=e?.lastUpdatedTimestamp?.$gte??Date.now()-15e3,C=e?.limit??50;return c.rtdbQuery=[Lm(p),Bm(u),lS(C)],this.commonDbService.dbListener({feature:s,properties:c}).pipe(Zt(E=>{console.log("[DEBUG_VELT_SDK] HeartbeatService getHeartbeatData",E)}),Le(E=>!!E?.data),ce(E=>E?.data),ce(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),ce(p=>p?.data),St((p,u)=>p?.lastUpdatedTimestamp===u?.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}}};o.\u0275fac=function(t){return new(t||o)(J(Ve),J(mn),J(Cn),J(rt),J(Be),J(y),J(Gl),J(Gd),J(Nt))},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}getRecentHeartbeats(e,t=30){try{if(!e||e.length===0)return[];let r=Date.now()-t*1e3;return e.filter(a=>a.lastUpdatedTimestamp&&a.lastUpdatedTimestamp>r)}catch(r){return this.loggingService.catch("Error in getRecentHeartbeats: ",r),[]}}getOldestHeartbeat(e,t=10){try{if(!e||e.length===0)return null;let r=Date.now()-t*1e3,a=e.filter(s=>s?.lastUpdatedTimestamp>r);return a.length===0?null:a.reduce((s,c)=>!s||c.createdTimestamp<s.createdTimestamp?c:s,a[0])}catch(r){return this.loggingService.catch("Error in getOldestHeartbeat: ",r),null}}getMostRecentHeartbeat(e){try{return!e||e.length===0?null:e.reduce((t,r)=>!t||r.lastUpdatedTimestamp>t.lastUpdatedTimestamp?r:t,e[0])}catch(t){return this.loggingService.catch("Error in getMostRecentHeartbeat: ",t),null}}hasRecentHeartbeat(e,t,r=30){try{return this.getRecentHeartbeats(e,r).some(s=>s.userId===t)}catch(a){return this.loggingService.catch("Error in hasRecentHeartbeat: ",a),!1}}hasRecentHeartbeatOnTab(e,t,r,a=30){try{return this.getRecentHeartbeats(e,a).some(c=>c.userId===t&&c.tabId===r)}catch(s){return this.loggingService.catch("Error in hasRecentHeartbeatOnTab: ",s),!1}}getHeartbeatCountByUser(e){try{let t=new Map;return!e||e.length===0||e.forEach(r=>{if(r.userId){let a=t.get(r.userId)||0;t.set(r.userId,a+1)}}),t}catch(t){return this.loggingService.catch("Error in getHeartbeatCountByUser: ",t),new Map}}isEditorActiveByHeartbeat(e,t,r,a,s=30){try{if(!e||e.length===0||!t||!r||!a)return!1;let p=this.getRecentHeartbeats(e,s).find(u=>u.userId===t&&u.tabId===r);return!!(p&&p.lastUpdatedTimestamp>a)}catch(c){return this.loggingService.catch("Error in isEditorActiveByHeartbeat: ",c),!1}}findOldestActiveSessionFromHeartbeats(e){try{if(!e||e.length===0)return null;let t=C=>(Date.now()-C)/1e3+" ago",r=this.authService.getUser(),a=this.domService.getTabId();this.semDebuggerMode()&&console.table(e?.map(C=>({userId:C?.userId,tabId:C?.tabId,lastUpdatedTimestamp:t(C?.lastUpdatedTimestamp),createdTimestamp:t(C?.createdTimestamp),isCurrentTab:C?.tabId===a,currentTabId:a})));let s=e.filter(C=>C.lastUpdatedTimestamp>Date.now()-1e4);if(s.length===0)return null;let c=[...s].sort((C,E)=>C.createdTimestamp-E.createdTimestamp),p=c[0],u=c[1];return p?.userId===r?.userId&&p?.tabId===a?this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] findOldestActiveSession oldest is me","color: green;"):u?.userId===r?.userId&&u?.tabId===a?this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] findOldestActiveSession secondOldest is me","color: blue;"):this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] findOldestActiveSession neither oldest nor secondOldest is me","color: red;"),p??null}catch(t){return this.loggingService.catch("Error in findOldestActiveSessionFromHeartbeats: ",t),null}}determineEditorStatusNew(e){return Q(this,null,function*(){try{this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] [3] determineEditorStatusNew start **************"),this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] [3.1] SD determineEditorStatusNew context",e&&typeof e=="object"?JSON.parse(JSON.stringify(e)):e);let{singleEditorModeData:r,heartbeatData:a,externalUserPresence:s,currentUser:c,currentTabId:p}=e,u=JSON.parse(JSON.stringify(r||{})),C=()=>Q(this,null,function*(){let z=s?.userIds?.[0],W;z&&(yield this.usersService.resolveUsers({userIds:[z],forceResolve:!0}),W=this.usersService.getUserById(z)),W?(u.editor=W,u.tabId=`differentUserPresentOnTab_${p}`):(u.editor={userId:`anonymous_${c?.userId}`,name:"Anonymous"},u.tabId=`differentUserPresentOnTab_${p}`)}),E=()=>{u.editor=c,u.tabId=`sameUserPresentOnTab_${p}`},D=!1;if(r?.editor){if(a?.length){let z=a?.find(W=>W.userId===r?.editor?.userId&&W.tabId===r?.tabId);if(z&&z.lastUpdatedTimestamp>Date.now()-1e4)this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.9] Server data present, editor heartbeat recent: keep current editor","color: blue;");else{this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.10] Server data present, editor heartbeat not recent","color: red;");let W=this.getOldestHeartbeat(a,20);this.semDebuggerMode()&&console.log(`%c[DEBUG_VELT_SDK] [3.11] Server data present, computed oldest: user ${W?.userId} tab ${W?.tabId}, created ${W?.createdTimestamp}, my user ${c.userId} my tab ${p}`,"color: yellow;"),W&&W.userId===c.userId&&W.tabId===p?(this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.12] Server data present, not recent editor, I am oldest: set undefined","color: green;"),D=!0):this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.13] Server data present, not recent editor, I am not oldest: keep current","color: red;")}}else s&&(s.differentUserPresentOnTab?(yield C(),this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.14] Server data present, different user present: set as viewer","color: blue;"),D=!1):s.sameUserPresentOnTab?(E(),this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.15] Server data present, same user on different tab: set as viewer (editor on diff tab)","color: blue;"),D=!1):this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.16] Server data present, no external presence: keep as is","color: darkgrey;"));!a?.length&&!s&&this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.17] Server data present, no heartbeat, no user presence: keep as is","color: darkgrey;")}else{if(a?.length){let z=this.getOldestHeartbeat(a,20);this.semDebuggerMode()&&console.log(`%c[DEBUG_VELT_SDK] [3.2] [No server data], computed oldest: user ${z?.userId} tab ${z?.tabId}, created ${z?.createdTimestamp}, my user ${c.userId} my tab ${p}`,"color: purple;"),z&&z.userId===c.userId&&z.tabId===p?(this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.3] [No server data], heartbeat check: I am the oldest, setting undefined","color: green;"),D=!0):this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.4] [No server data], heartbeat check: I am not the oldest","color: red;")}else s&&(s.differentUserPresentOnTab?(yield C(),this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.5] [No server data], different user present: set as viewer","color: blue;"),D=!1):s.sameUserPresentOnTab?(E(),this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.6] [No server data], same user on different tab: set as viewer (editor on diff tab)","color: blue;"),D=!1):(this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.7] [No server data], no external presence: eligible for editor","color: green;"),D=!0));!a?.length&&!s&&(this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.8] [No server data], no heartbeat, no user presence: default to undefined","color: darkgrey;"),D=!0)}let L;return D?(this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.18] Final decision: shouldSetUndefined true","color: green;"),L={shouldSetUndefined:!0}):(this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.19] Final decision: return data","color: blue;"),L={data:u}),this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] [3.20] determineEditorStatusNew returnValue",L),this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] [3] determineEditorStatusNew end **************"),L}catch(t){return this.loggingService.catch("Error in determineEditorStatusNew: ",t),{data:void 0,shouldSetUndefined:void 0}}})}semDebuggerMode(){try{return localStorage.getItem("vSemDebuggerMode")==="true"}catch(e){return this.loggingService.catch("Error in semDebuggerMode: ",e),!1}}};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 Ki=(()=>{let o=class o{constructor(e,t,r,a,s,c,p,u,C,E,D,L,z,W,te){this.afAuth=e,this.analyticsService=t,this.authService=r,this.configService=a,this.databaseService=s,this.docService=c,this.domService=p,this.heartbeatService=u,this.iamService=C,this.loggingService=E,this.commonDbService=D,this.liveStateActionsService=L,this.liveStateUtilsService=z,this.usersService=W,this.singleEditorDecisionEngine=te,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 g0),this.autoSyncState$=new ve(!1),this.serverConnectionState$=new ve(ls.PENDING_INIT),this.externalUserPresence$=new ve(null),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),this.getSingleEditorMode$().subscribe(me=>{me?this.heartbeatService.enableHeartbeat():this.heartbeatService.disableHeartbeat()}),this.databaseService.getDb().pipe(Le(me=>!!me),at(1)).subscribe(me=>{me&&(this.db=me,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)}))},me=>{this.loggingService.catch("Error in LiveStateService getDb subscription: ",me)}),this.liveStateAutoSyncStateData$.pipe(Le(me=>Object.keys(me||{}).length>0),St((me,ye)=>JSON.stringify(me||{})===JSON.stringify(ye||{}))).subscribe(me=>{me&&(this.getAutoSyncState()&&(!this.autoSyncStateHistory&&me?.history&&this.updateLiveStateSyncInputDataLocally(me.history),me?.current&&this.updateLiveStateSyncInputDataLocally({[me.current.liveStateDataId]:me.current})),!this.autoSyncStateHistory&&me?.history&&(this.autoSyncStateHistory=me.history))}),this.docService.addPreDocumentIdChangeFunction("live-state-service",me=>(this.updateExternalUserPresence(null),this.isUserEditor()?.isEditor&&(!this.getSingleEditorModeConfig()?.singleTabEditor||this.isUserEditor()?.isEditorOnCurrentTab)?this.removeEditorAccess({metadata:{from:"addPreDocumentIdChangeFunction-liveStateService",reason:"Document id changed"},documentPaths:me}):Promise.resolve())),this.singleEditorLiveStateData$.pipe(Di()).subscribe(([me,ye])=>{try{let Oe=ye?.requestEditorAccess?.status,ze=me?.requestEditorAccess?.status,Ne=this.authService.getUser();if(Oe==="pending"){if(Ne?.userId===ye?.editor?.userId){let Ie={viewer:ya(ye?.requestEditorAccess?.user)??void 0,editor:ya(ye?.editor)??void 0,timestamp:new Date().getTime(),status:"requested"};this.liveStateActionsService?.onAccessRequested(Ie)}return}if(Oe==="cancelled"){if(Ne?.userId===ye?.editor?.userId){let Ie={viewer:ya(ye?.requestEditorAccess?.user)??void 0,editor:ya(ye?.editor)??void 0,timestamp:new Date().getTime(),status:"canceled"};this.liveStateActionsService?.onAccessRequestCanceled(Ie)}return}if(ze==="pending"&&!Oe){if(me?.requestEditorAccess?.user?.userId===ye?.editor?.userId){if(me?.requestEditorAccess?.user?.userId===Ne?.userId){let Ie={viewer:ya(me?.editor)??void 0,editor:ya(ye?.editor)??void 0,timestamp:new Date().getTime(),status:"accepted"};this.liveStateActionsService?.onAccessAccepted(Ie)}return}if(me?.requestEditorAccess?.user?.userId!==ye?.editor?.userId){if(me?.requestEditorAccess?.user?.userId===Ne?.userId){let Ie={viewer:ya(me?.requestEditorAccess?.user)??void 0,editor:ya(ye?.editor)??void 0,timestamp:new Date().getTime(),status:"rejected"};this.liveStateActionsService?.onAccessRejected(Ie)}return}}}catch(Oe){this.loggingService.catch("Error in LiveStateService singleEditorLiveStateData$ subscription: ",Oe)}}),this.isUserEditor$().pipe(St(pn)).subscribe(me=>{try{if(me){this.analyticsService.trackEvent(X.Events.LiveStateSync.SEM_USER_EDITOR_STATS,{isEditor:me?.isEditor,isEditorOnCurrentTab:me?.isEditorOnCurrentTab});let ye=this.singleEditorLiveStateData$.value;if(me?.isEditor)if(me?.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(me){this.loggingService.catch("Error in LiveStateService constructor: ",me)}}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),Zt(()=>this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] \u{1F504} Heartbeat search triggered.")),he(()=>{let t=this.heartbeatService.getHeartbeatData({documentId:this.documentPaths?.documentId}).pipe(at(1),he(r=>{let a=this.singleEditorDecisionEngine.findOldestActiveSessionFromHeartbeats(r);return a?(this.semDebuggerMode()&&console.log(`[DEBUG_VELT_SDK] \u2705 Found oldest session to monitor: ${a.userId}`),this.monitorSession$(a.userId,a.tabId)):(this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] \u274C No oldest session found. Continuing process with null heartbeat."),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=>{let a=!r?.id||Date.now()-r?.lastUpdatedTimestamp>1e4;return a?(this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] \u26A0\uFE0F Primary editor is stale. Finding fallback...",r,"isStale",a),t):(this.semDebuggerMode()&&console.log(`[DEBUG_VELT_SDK] \u2705 Primary editor is active. Monitoring: ${e.userId}`,r,"isStale",a),this.monitorSession$(e.userId,e.tabId))}))}),St((t,r)=>this.isHeartbeatSimilar(t,r)))}monitorSession$(e,t){return console.log("[DEBUG_VELT_SDK] monitorSession$ userId",e,"tabId",t),this.heartbeatService.getSpecificHeartbeat({userId:e,tabId:t,documentId:this.documentPaths?.documentId}).pipe(he(a=>a?.id?(this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] \u2764\uFE0F Heartbeat received",a),se(a)):(this.semDebuggerMode()&&console.log(`[DEBUG_VELT_SDK] \u203C\uFE0F Session document removed for ${e}. Triggering restart immediately.`),this.heartbeatRestart$.next(),_l)),M8({each:1e4,with:()=>(this.semDebuggerMode()&&console.log(`[DEBUG_VELT_SDK] \u203C\uFE0F Session timed out for ${e}. Triggering restart.`),this.heartbeatRestart$.next(),_l)}))}isHeartbeatSimilar(e,t){return!e&&!t?!0:!e||!t?!1:e.userId===t.userId&&e.tabId===t.tabId}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(ce(t=>(e.featureAllowed=t,e))):se(e)),he(e=>e.featureAllowed?this.authService.isPlanExpired$().pipe(ce(t=>(e.featureAllowed=!t,e))):se(e)),he(e=>e.featureAllowed?se(e).pipe(he(t=>this.docService.getDocumentPaths$().pipe(ce(r=>(this.documentPaths=r,t.documentPaths=r,t)))),he(t=>t?.documentPaths?se(t).pipe(Zt(r=>{this.serverConnectionState$?.value===ls.PENDING_INIT&&r?.documentPaths?.liveState&&this.serverConnectionState$.next(ls.PENDING_DATA)}),he(r=>this.domService.onNetworkStatusChange$().pipe(Le(a=>a),ce(()=>r))),he(r=>this.getDataFromDocumentId().pipe(ce(a=>(this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK][1] getDataFromDocumentId data",a,this.docService.getDocumentPaths()),r.singleEditorModeData=a,I({},r))))),he(r=>this.getSingleEditorMode$().pipe(ce(()=>r))),ce(r=>([ls.ONLINE,ls.OFFLINE].includes(this.serverConnectionState$?.value)||this.serverConnectionState$.next(ls.ONLINE),r)),he(r=>this.getSingleEditorMode()?this.getExternalUserPresence$().pipe(ce(a=>T(I({},r),{externalUserPresence:a}))):se(r))):se(T(I({},t),{liveStateData:{}}))),he(t=>{if(this.getSingleEditorMode()){let r=t?.singleEditorModeData?.editor,a=t?.singleEditorModeData?.tabId;return console.log("[DEBUG_VELT_SDK] editor",r,"tabId",a),this.getActiveHeartbeatStream$({userId:r?.userId,tabId:a}).pipe(ce(s=>{let c=s?.id?[s]:null;return T(I({},t),{heartbeatData:c})}))}else return se(t)}),Zt(t=>{let r=t?.heartbeatData;if(!r)this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK][1] heartbeatData is null");else{this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK][1] heartbeatData length:",r?.length);let a=s=>(Date.now()-s)/1e3+" ago";this.semDebuggerMode()&&console.table(r?.map(s=>({userId:s?.userId,tabId:s?.tabId,lastUpdatedTimestamp:a(s?.lastUpdatedTimestamp),createdTimestamp:a(s?.createdTimestamp),isCurrentTab:s?.tabId===this.tabId,currentTabId:this.tabId})))}}),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:X.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_EMPTY_DATA_STATS,properties:{previousSingleEditorModeData:s,currentSingleEditorModeData:t?.singleEditorModeData}})}return this.updateSingleEditorLiveSyncDataNew(t?.singleEditorModeData||{},t?.externalUserPresence??null,t?.heartbeatData??null),se(t)}else return se(t)})):se({})))}updateSingleEditorLiveSyncDataNew(e,t,r){return Q(this,null,function*(){try{this.loggingService.log("%c[WB] Calling FUNCTION: updateSingleEditorLiveSyncData","color: green;"),vi(e,{})&&!this.keydownSubscription&&this.detectKeydownOnInput();let a=JSON.parse(JSON.stringify(e)),s=yield this.singleEditorDecisionEngine.determineEditorStatusNew({singleEditorModeData:a,externalUserPresence:t,heartbeatData:r,currentUser:this.authService.getUser(),currentTabId:this.tabId});this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] [10] LiveStateService updateSingleEditorLiveSyncDataNew newData",s?.shouldSetUndefined,s?.data,"heartbeatData length:",r?.length),this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] \u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B");let c;if(this.domService.getNetworkStatus()||(c=null),e=s?.data??{},s?.shouldSetUndefined||(c=null),this.docService.getDocumentPaths()||(c=null),this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] [11] LiveStateService updateSingleEditorLiveSyncDataNew editorEmptyStateValue",e,c,this.isEditor$?.value,this.docService.getDocumentPaths()),e&&!e?.editor&&this.isEditor$?.value!==c&&this.isEditor$.next(c),vi(this.singleEditorLiveStateData,e))return;{this.singleEditorLiveStateData=e,this.singleEditorLiveStateData$.next(e);let p;if(this.singleEditorLiveStateData&&typeof this.singleEditorLiveStateData=="object"&&(p=this.liveStateUtilsService.formatLiveStateSingleEditorModeData(JSON.parse(JSON.stringify(this.singleEditorLiveStateData)))),this.analyticsService.trackEvent(X.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_STATS,{singleEditorLiveStateData:p}),this.singleEditorLiveStateData?.editor){let u=this.authService.getUser();this.singleEditorLiveStateData?.editor?.userId!==u?.userId?this.makeReader():this.makeEditor()}else this.isEditor$?.value!==c&&this.isEditor$.next(c),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{}})}updateSingleEditorLiveSyncData(a,s){return Q(this,arguments,function*(e,t,r=[]){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: updateSingleEditorLiveSyncData","color: green;"),vi(e,{})){let u=yield this.fetchSingleEditorLiveStateDataFromDatabase();if(!vi(u,e)&&(r.push({eventName:X.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_MISMATCH,properties:{serverData:u,localData:e}}),u&&typeof u=="object")){let C=yield this.liveStateUtilsService.resolveAndMergeSingleEditorLiveStateDataWithUser(JSON.parse(JSON.stringify(u)));e=JSON.parse(JSON.stringify(C))}}vi(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 u=this.authService.getUser();if(t?.sameUserPresentOnTab)e.editor=u,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_${u?.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),vi(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 u;if(this.singleEditorLiveStateData&&typeof this.singleEditorLiveStateData=="object"&&(u=this.liveStateUtilsService.formatLiveStateSingleEditorModeData(JSON.parse(JSON.stringify(this.singleEditorLiveStateData)))),this.analyticsService.trackEvent(X.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_STATS,{singleEditorLiveStateData:u}),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};vi(a,s)||this.analyticsService.trackEvent(X.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),ce(t=>T(I({},e),{config:t})),he(t=>this.authService.getUser$().pipe(ce(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),ce(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(pn))}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(ce(a=>(r.featureAllowed=a,r))):se(r)),he(r=>r.featureAllowed?this.authService.isPlanExpired$().pipe(ce(a=>(r.featureAllowed=!a,r))):se(r)),he(r=>r.featureAllowed?se(r).pipe(he(a=>this.docService.getDocumentPaths$().pipe(ce(s=>(this.documentPaths=s,a.documentPaths=s,a)))),he(a=>{let s=t?.listenToNewChangesOnly?1:0;return this.getLiveStateDataFromDatabase$(e).pipe(Gs(s))}),ce(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],u=p?.data;if(p?.isDataStringified&&typeof u=="string")try{u=JSON.parse(u)}catch{}s[p.liveStateDataId]=u}}),s}return a})):se(void 0).pipe(Le(Boolean))),St((r,a)=>JSON.stringify(r||{})===JSON.stringify(a||{})),Le(r=>r!==void 0),ce(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(ce(a=>a?.data),ce(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 u=yield this.commonDbService.getData({feature:"liveStateCustom",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",id:s,skipFirestore:!0}});if(u?.isDataStringified){let C=JSON.parse(u?.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=ui(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;"),console.log("[DEBUG_VELT_SDK] LiveStateService setUserAsEditor config",e,this.user,this.documentPaths?.liveStateSingleEditorMode,this.docService.getDocumentPaths()),this.user&&this.documentPaths?.liveStateSingleEditorMode){if(this.analyticsService.trackEvent(X.Events.LiveStateSync.SET_USER_AS_EDITOR_TRIGGERED,{editorUserId:this.user?.userSnippylyId,tabId:this.tabId}),!e?.skipEditorCheck){let r=yield this.fetchSingleEditorLiveStateDataFromDatabase();if(this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] LiveStateService setUserAsEditor currentSingleEditorLiveStateData line 1362: ",r),r?.editor?.userId&&r?.tabId){let a=yield P8(this.heartbeatService.getSpecificHeartbeat({userId:r?.editor?.userId,tabId:r?.tabId,documentId:this.documentPaths?.documentId}));this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] LiveStateService setUserAsEditor heartbeatData line 1392: ",a);let s=null;a&&(s=this.singleEditorDecisionEngine.findOldestActiveSessionFromHeartbeats([a]),this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] LiveStateService setUserAsEditor oldestHeartbeat line 1396: ",s)),s||(r=null,this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] LiveStateService setUserAsEditor currentSingleEditorLiveStateData line 1400: ",r))}else r=null,this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] LiveStateService setUserAsEditor currentSingleEditorLiveStateData line 1404: ",r);if(this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] LiveStateService setUserAsEditor currentSingleEditorLiveStateData line 1406: ",r),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(X.Events.LiveStateSync.SET_USER_AS_EDITOR_ERROR,{error:s,singleEditorLiveStateData:c}),this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] [12] LiveStateService setUserAsEditor errorEvent",s),{error:s}}}let t={editor:this.user,tabId:this.tabId,editorAt:this.timestamp};console.log("[DEBUG_VELT_SDK] LiveStateService setUserAsEditor singleEditorLiveStateData",t,{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0}),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(X.Events.LiveStateSync.REQUEST_EDITOR_ACCESS_TRIGGERED),new Ut(e=>{let t=null;try{if(this.user&&this.documentPaths?.liveStateSingleEditorMode){let r=this.getEditorAccessTimeout(),a=Pi(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(X.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(X.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(X.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(X.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(X.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(X.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(X.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(X.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(pn))}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(ce(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(ce(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;"),console.log("[DEBUG_VELT_SDK] LiveStateService removeEditorAccess would have been called!",e,this.user,this.documentPaths?.liveStateSingleEditorMode),this.analyticsService.trackEvent(X.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(pn))}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(ce(t=>(e.featureAllowed=t,e))):se(e)),he(e=>e.featureAllowed?this.authService.isPlanExpired$().pipe(ce(t=>(e.featureAllowed=!t,e))):se(e)),he(e=>e.featureAllowed?se(e).pipe(he(t=>this.docService.getDocumentPaths$().pipe(Le(r=>!!r),ce(r=>(this.documentPaths=r,t.documentPaths=r,t)))),Zt(t=>{this.serverConnectionState$?.value===ls.PENDING_INIT&&t?.documentPaths?.liveState&&this.serverConnectionState$.next(ls.PENDING_DATA)}),he(t=>this.domService.onNetworkStatusChange$().pipe(Le(r=>r),ce(()=>t))),he(t=>this.getLiveStateAutoSyncStateDataFromDocumentId().pipe(ce(r=>(t.liveStateData=r,I({},t))))),ce(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),ce(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(pn))}enableSingleEditorMode(e){try{if(this.singleEditorMode$.value===!0)return;this.singleEditorMode$.next(!0),e?this.singleEditorModeConfig$.next(e):this.singleEditorModeConfig$.next(new Mk)}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(pn))}getExternalUserPresence(){return this.externalUserPresence$.value}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=ui(e,"input").pipe(cr(300)).subscribe(p=>{let u={value:p?.target?.value,tagName:p?.target?.tagName,type:p?.target?.type};this.setLiveStateSyncInputData(p?.target,u)});break;case"textarea":s=ui(e,"input").pipe(cr(300)).subscribe(p=>{let u={value:p?.target?.value,tagName:p?.target?.tagName};this.setLiveStateSyncInputData(p?.target,u)});break;default:e.getAttribute("contenteditable")&&(s=ui(e,"input").pipe(cr(300)).subscribe(p=>{let u={innerText:p?.target?.innerText,innerHTML:this.domService.sanitizeHtml(p?.target?.innerHTML),tagName:p?.target?.tagName,isContentEditable:!0};this.setLiveStateSyncInputData(p?.target,u)}));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(Zt(e=>{try{if(this.documentPaths?.liveStateSingleEditorMode){let t=Pi(this.db,`${this.documentPaths?.liveStateSingleEditorMode}`);e?.isEditor&&(!this.getSingleEditorModeConfig()?.singleTabEditor||e?.isEditorOnCurrentTab)?ol(t).remove():ol(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(ce(t=>e))),Zt(e=>Q(this,null,function*(){try{if(this.docService.getDocumentPaths()?.liveState&&e){let r=Pi(this.db,".info/connected"),a=!0;$p(r,s=>{let c=s.val();if(a&&c===!1){a=!1;return}a=!1,c===!1?this.serverConnectionState$.next(ls.OFFLINE):this.serverConnectionState$.value===ls.OFFLINE&&this.serverConnectionState$.next(ls.ONLINE)})}}catch(t){this.loggingService.catch("Error in updateServerStateOnDatabaseDisconnect:",t)}})))}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()}semDebuggerMode(){try{return localStorage.getItem("vSemDebuggerMode")==="true"}catch(e){return this.loggingService.catch("Error in LiveStateService semDebuggerMode: ",e),!1}}};o.\u0275fac=function(t){return new(t||o)(J(Ai),J(et),J(Ve),J(Nt),J(Cn),J(rt),J(Be),J(Ide),J(_n),J(y),J(mn),J(f9),J(Kk),J(kn),J(Ede))},o.\u0275prov=Ae({token:o,factory:o.\u0275fac,providedIn:"root"});let i=o;return i})();var v9=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.on=this._on}_getLiveStateData(o,n){this.getService(y).log("%c[WB] Calling FUNCTION: getLiveStateData","color: green;");try{return this.trackEvent(X.Events.LiveStateSync.GET_LIVE_STATE_DATA_TRIGGERED),this.getService(Ki).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(Ki).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(X.Events.LiveStateSync.ENABLE_SINGLE_EDITOR_MODE_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.DISABLE_SINGLE_EDITOR_MODE_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.IS_USER_EDITOR_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.GET_EDITOR_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.SET_USER_AS_EDITOR_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.RESET_USER_ACCESS_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.SINGLE_EDITOR_MODE_CONTAINER_IDS_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.ENABLE_AUTO_SYNC_STATE_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.DISABLE_AUTO_SYNC_STATE_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.REQUEST_EDITOR_ACCESS_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.IS_EDITOR_ACCESS_REQUESTED_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.ACCEPT_EDITOR_ACCESS_REQUEST_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.REJECT_EDITOR_ACCESS_REQUEST_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.CANCEL_EDITOR_ACCESS_REQUEST_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.EDIT_CURRENT_TAB_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.SET_EDITOR_ACCESS_TIMEOUT_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.ENABLE_EDITOR_ACCESS_TRANSFER_ON_TIMEOUT_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.DISABLE_EDITOR_ACCESS_TRANSFER_ON_TIMEOUT_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.ENABLE_DEFAULT_SINGLE_EDITOR_UI_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.DISABLE_DEFAULT_SINGLE_EDITOR_UI_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.GET_EDITOR_ACCESS_TIMER_TRIGGERED),this.getService(Ki).getEditorAccessTimer$()}catch(o){return this.getService(y).catch("Error in _getEditorAccessTimer: ",o),se(new g0)}}_onServerConnectionStateChange(){this.getService(y).log("%c[WB] Calling FUNCTION: onServerConnectionStateChange","color: green;");try{return this.trackEvent(X.Events.LiveStateSync.ON_SERVER_CONNECTION_STATE_CHANGE_TRIGGERED),this.getService(Ki).onServerConnectionStateChange$()}catch(o){return this.getService(y).catch("Error in _onServerConnectionStateChange: ",o),se(ls.PENDING_INIT)}}_updateUserPresence(o){this.getService(y).log("%c[WB] Calling FUNCTION: updateUserPresence","color: green;");try{this.trackEvent(X.Events.LiveStateSync.UPDATE_USER_PRESENCE_TRIGGERED,{payload:{userPresence:o}}),this.getService(Ki).updateExternalUserPresence(o)}catch(n){this.getService(y).catch("Error in _updateUserPresence: ",n)}}_on(o){this.getService(y).log("%c[WB] Calling FUNCTION: on","color: green;");try{return this.trackEvent(X.Events.LiveStateSync.ON_ACTION_TRIGGERED,{payload:{action:o}}),this.getService(f9).onAction(o)}catch(n){return this.getService(y).catch("Error in _on: ",n),se(null)}}};var C9=(()=>{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 _9=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.on=this._on}_openHistoryPanel(){this.getService(y).log("%c[WB] Calling FUNCTION: _openHistoryPanel","color: green;");try{this.trackEvent(X.Events.Notifications.OPEN_HISTORY_PANEL_TRIGGERED),this.getService(un).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(X.Events.Notifications.CLOSE_HISTORY_PANEL_TRIGGERED),this.getService(un).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(X.Events.Notifications.TOGGLE_HISTORY_PANEL_TRIGGERED),this.getService(un).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(X.Events.Notifications.GET_NOTIFICATIONS_DATA_TRIGGERED),this.getService(un).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(X.Events.Notifications.SET_MAX_DAYS_TRIGGERED,{payload:{days:o}}),this.getService(un).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(X.Events.Notifications.SET_TAB_CONFIG_TRIGGERED,{payload:{tabConfig:o}}),this.getService(un).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(X.Events.Notifications.ENABLE_READ_NOTIFICATIONS_ON_FOR_YOU_TAB_TRIGGERED),this.getService(un).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(X.Events.Notifications.DISABLE_READ_NOTIFICATIONS_ON_FOR_YOU_TAB_TRIGGERED),this.getService(un).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(X.Events.Notifications.SET_ALL_NOTIFICATIONS_AS_READ_TRIGGERED,{payload:{config:o}}),this.getService(un).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(X.Events.Notifications.GET_UNREAD_NOTIFICATIONS_COUNT_TRIGGERED),this.getService(un).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(X.Events.Notifications.MARK_NOTIFICATION_AS_READ_BY_ID_TRIGGERED,{payload:{notificationId:o}}),this.getService(un).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(X.Events.Notifications.SET_SETTINGS_TRIGGERED,{payload:{config:o}}),this.getService(un).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(X.Events.Notifications.GET_SETTINGS_TRIGGERED),this.getService(un).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(X.Events.Notifications.MUTE_ALL_NOTIFICATIONS_TRIGGERED),this.getService(un).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(X.Events.Notifications.ENABLE_SETTINGS_TRIGGERED),this.getService(un).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(X.Events.Notifications.ENABLE_SELF_NOTIFICATIONS_TRIGGERED),this.getService(un).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(X.Events.Notifications.DISABLE_SELF_NOTIFICATIONS_TRIGGERED),this.getService(un).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(X.Events.Notifications.DISABLE_SETTINGS_TRIGGERED),this.getService(un).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(X.Events.Notifications.SET_SETTINGS_INITIAL_CONFIG_TRIGGERED,{payload:{settings:o}}),this.getService(un).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(X.Events.Notifications.ON_ACTION_TRIGGERED,{payload:{action:o}}),this.getService(C9).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(X.Events.Notifications.OPEN_NOTIFICATIONS_PANEL_TRIGGERED),this.getService(un).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(X.Events.Notifications.CLOSE_NOTIFICATIONS_PANEL_TRIGGERED),this.getService(un).closeNotificationsPanel()}catch(o){this.getService(y).catch("Error in closeNotificationsPanel: ",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(X.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(X.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(ce(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 y9=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(X.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(X.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(X.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(X.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(X.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(X.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(X.Events.Presence.ENABLE_SELF_TRIGGERED),this.getService(Wl).enableIncludeSelf()}catch(o){this.getService(y).catch("Error in _enableSelf: ",o)}}_disableSelf(){try{this.trackEvent(X.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(X.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(X.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 S9=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(X.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(X.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(X.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 fg=(()=>{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(Yi),J(xn))},o.\u0275prov=Ae({token:o,factory:o.\u0275fac,providedIn:"root"});let i=o;return i})();var b9=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.on=this._on}_initRecording(o,n){this.getService(y).log("%c[WB] Calling FUNCTION: initRecording","color: green;");try{return this.trackEvent(X.Events.Recording.INIT_RECORDING_TRIGGERED,{payload:{type:o,panelId:n}}),this.getService(xn).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(X.Events.Recording.ON_RECORDED_DATA_TRIGGERED),this.getService(xn).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(X.Events.Recording.ENABLE_DARK_MODE_TRIGGERED),this.getService(Yi).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(X.Events.Recording.DISABLE_DARK_MODE_TRIGGERED),this.getService(Yi).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(X.Events.Recording.ENABLE_RECORDING_COUNTDOWN_TRIGGERED),this.getService(xn).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(X.Events.Recording.DISABLE_RECORDING_COUNTDOWN_TRIGGERED),this.getService(xn).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(X.Events.Recording.GET_RECORDING_DATA_BY_RECORDER_ID_TRIGGERED,{payload:{recorderId:o}}),this.getService(Yi).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(X.Events.Recording.GET_RECORDINGS_TRIGGERED,{payload:{query:o}}),this.getService(Yi).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(X.Events.Recording.GET_RECORDING_DATA_TRIGGERED,{payload:{query:o}}),this.getService(Yi).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(X.Events.Recording.FETCH_RECORDINGS_TRIGGERED,{payload:{query:o}}),this.getService(Yi).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(X.Events.Recording.DELETE_RECORDING_TRIGGERED,{payload:{query:o}}),this.getService(Yi).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(X.Events.Recording.ENABLE_RECORDING_TRANSCRIPTION_TRIGGERED),this.getService(Yi).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(X.Events.Recording.DISABLE_RECORDING_TRANSCRIPTION_TRIGGERED),this.getService(Yi).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(X.Events.Recording.ON_ACTION_TRIGGERED,{payload:{action:o}}),this.getService(fg).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(X.Events.Recording.ENABLE_VIDEO_EDITOR_TRIGGERED),this.getService(xn).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(X.Events.Recording.DISABLE_VIDEO_EDITOR_TRIGGERED),this.getService(xn).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(X.Events.Recording.SET_RECORDING_QUALITY_CONSTRAINTS_TRIGGERED,{payload:{constraints:o}}),this.getService(xn).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(X.Events.Recording.SET_RECORDING_ENCODING_OPTIONS_TRIGGERED,{payload:{options:o}}),this.getService(xn).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(X.Events.Recording.DOWNLOAD_LATEST_VIDEO_TRIGGERED,{payload:{recorderId:o}}),this.getService(Yi).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(X.Events.Recording.ENABLE_RECORDING_MIC_TRIGGERED),this.getService(xn).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(X.Events.Recording.DISABLE_RECORDING_MIC_TRIGGERED),this.getService(xn).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(X.Events.Recording.ENABLE_ONBOARDING_TOOLTIP_TRIGGERED),this.getService(xn).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(X.Events.Recording.DISABLE_ONBOARDING_TOOLTIP_TRIGGERED),this.getService(xn).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(X.Events.Recording.ENABLE_RETAKE_ON_VIDEO_EDITOR_TRIGGERED),this.getService(xn).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(X.Events.Recording.DISABLE_RETAKE_ON_VIDEO_EDITOR_TRIGGERED),this.getService(xn).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(X.Events.Recording.ASK_DEVICE_PERMISSION_TRIGGERED),this.getService(xn).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(X.Events.Recording.SET_MAX_LENGTH_TRIGGERED,{payload:{seconds:o}}),this.getService(xn).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(X.Events.Recording.OPEN_PICTURE_IN_PICTURE_TRIGGERED),yield this.getService(xn).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(X.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(X.Events.Recording.REQUEST_SCREEN_PERMISSION_TRIGGERED),this.getService(xn).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(X.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(X.Events.Recording.DISABLE_PICTURE_IN_PICTURE_TRIGGERED),this.getService(Ga).disablePictureInPicture()}catch(o){this.getService(y).catch("Error in _disablePictureInPicture: ",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 u=document.querySelectorAll(j.TAGS.SNIPPYLY_REWRITER);if(!document.querySelectorAll(j.TAGS.VELT_REWRITER)?.length&&!u?.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(X.Events.Rewriter.REWRITER_ENABLED,{isMobileDevice:this.domService.isMobileDevice()})})}}else{let u=document.querySelectorAll(j.TAGS.SNIPPYLY_REWRITER);u?.length&&u.forEach(E=>{E.remove()});let C=document.querySelectorAll(j.TAGS.VELT_REWRITER);C?.length&&C.forEach(E=>{E.remove()})}}catch(u){this.loggingService.catch("Error in rewriterEnabled$: ",u)}},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 Lk;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(X.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(ce(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] Creating CLASS: HeartbeatService","color: blue;"),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),Zt(()=>this.sendHeartbeat())).subscribe();let e=En([this.databaseService.getDb().pipe(Le(t=>!!t)),this.authService.getUser$(),this.docService.getDocumentPaths$()]).pipe(Di(),Zt(([[t,r,a],[s,c,p]])=>{if(c&&p){let u=this.domService.getTabId();if(u){let C=this.generateHeartbeatId(c.userId,u),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&&ol(Pi(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&&ol(Pi(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.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{if(this.loggingService.log("%c[WB] Calling HeartbeatService FUNCTION: sendHeartbeat","color: green;"),sessionStorage.getItem("veltSkipHeartbeat"))return;let e=this.authService.getUser(),t=this.docService.getDocumentPaths(),r=this.domService.getTabId();if(e&&t&&r){let a=new Ak,s=Date.now();a.createdTimestamp=s,a.lastUpdatedTimestamp=s,a.userId=e.userId,a.veltUserId=yt(e.userId),a.tabId=r,a.id=this.generateHeartbeatId(e.userId,r),a.metadata=this.docService.getBaseMetadata();let p=a.metadata.documentId;this.commonDbService.updateData({feature:"heartbeat",properties:{id:a.id,skipFirestore:!0,rtdbTransaction:!0,rtdbTransactionCallback:(u,C)=>(u?.createdTimestamp&&(C.createdTimestamp=u.createdTimestamp),C)},data:a}),p&&this.commonDbService.updateData({feature:"heartbeatByDocument",properties:{id:a.id,skipFirestore:!0,rtdbTransaction:!0,documentId:p,rtdbTransactionCallback:(u,C)=>(u?.createdTimestamp&&(C.createdTimestamp=u.createdTimestamp),C)},data:a})}}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",u=e?.lastUpdatedTimestamp?.$gte??Date.now()-15e3,C=e?.limit??50;return c.rtdbQuery=[Lm(p),Bm(u),lS(C)],this.commonDbService.dbListener({feature:s,properties:c}).pipe(Zt(E=>{console.log("[DEBUG_VELT_SDK] HeartbeatService getHeartbeatData",E)}),Le(E=>!!E?.data),ce(E=>E?.data),ce(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),ce(p=>p?.data),St((p,u)=>p?.lastUpdatedTimestamp===u?.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}}};o.\u0275fac=function(t){return new(t||o)(J(Ve),J(mn),J(Cn),J(rt),J(Be),J(y),J(Gl),J(Gd),J(Nt))},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=C=>(Date.now()-C)/1e3+" ago",r=this.authService.getUser(),a=this.domService.getTabId();this.semDebuggerMode()&&console.table(e?.map(C=>({userId:C?.userId,tabId:C?.tabId,lastUpdatedTimestamp:t(C?.lastUpdatedTimestamp),createdTimestamp:t(C?.createdTimestamp),isCurrentTab:C?.tabId===a,currentTabId:a})));let s=e.filter(C=>C.lastUpdatedTimestamp>Date.now()-1e4);if(s.length===0)return null;let c=[...s].sort((C,E)=>C.createdTimestamp-E.createdTimestamp),p=c[0],u=c[1];return p?.userId===r?.userId&&p?.tabId===a?this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] findOldestActiveSession oldest is me","color: green;"):u?.userId===r?.userId&&u?.tabId===a?this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] findOldestActiveSession secondOldest is me","color: blue;"):this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] findOldestActiveSession neither oldest nor secondOldest is me","color: red;"),p??null}catch(t){return this.loggingService.catch("Error in findOldestActiveSessionFromHeartbeats: ",t),null}}determineEditorStatusNew(e){return Q(this,null,function*(){try{this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] [3] determineEditorStatusNew start **************"),this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] [3.1] SD determineEditorStatusNew context",e&&typeof e=="object"?JSON.parse(JSON.stringify(e)):e);let{singleEditorModeData:r,heartbeatData:a,externalUserPresence:s,currentUser:c,currentTabId:p}=e,u=JSON.parse(JSON.stringify(r||{})),C=()=>Q(this,null,function*(){let z=s?.userIds?.[0],W;z&&(yield this.usersService.resolveUsers({userIds:[z],forceResolve:!0}),W=this.usersService.getUserById(z)),W?(u.editor=W,u.tabId=`differentUserPresentOnTab_${p}`):(u.editor={userId:`anonymous_${c?.userId}`,name:"Anonymous"},u.tabId=`differentUserPresentOnTab_${p}`)}),E=()=>{u.editor=c,u.tabId=`sameUserPresentOnTab_${p}`},D=!1;if(r?.editor){if(a?.length){let z=a?.find(W=>W.userId===r?.editor?.userId&&W.tabId===r?.tabId);if(z&&z.lastUpdatedTimestamp>Date.now()-1e4)this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.9] Server data present, editor heartbeat recent: keep current editor","color: blue;");else{this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.10] Server data present, editor heartbeat not recent","color: red;");let W=this.findOldestActiveSessionFromHeartbeats(a);this.semDebuggerMode()&&console.log(`%c[DEBUG_VELT_SDK] [3.11] Server data present, computed oldest: user ${W?.userId} tab ${W?.tabId}, created ${W?.createdTimestamp}, my user ${c.userId} my tab ${p}`,"color: yellow;"),W&&W.userId===c.userId&&W.tabId===p?(this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.12] Server data present, not recent editor, I am oldest: set undefined","color: green;"),D=!0):this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.13] Server data present, not recent editor, I am not oldest: keep current","color: red;")}}else s&&(s.differentUserPresentOnTab?(yield C(),this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.14] Server data present, different user present: set as viewer","color: blue;"),D=!1):s.sameUserPresentOnTab?(E(),this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.15] Server data present, same user on different tab: set as viewer (editor on diff tab)","color: blue;"),D=!1):this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.16] Server data present, no external presence: keep as is","color: darkgrey;"));!a?.length&&!s&&this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.17] Server data present, no heartbeat, no user presence: keep as is","color: darkgrey;")}else{if(a?.length){let z=this.findOldestActiveSessionFromHeartbeats(a);this.semDebuggerMode()&&console.log(`%c[DEBUG_VELT_SDK] [3.2] [No server data], computed oldest: user ${z?.userId} tab ${z?.tabId}, created ${z?.createdTimestamp}, my user ${c.userId} my tab ${p}`,"color: purple;"),z&&z.userId===c.userId&&z.tabId===p?(this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.3] [No server data], heartbeat check: I am the oldest, setting undefined","color: green;"),D=!0):this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.4] [No server data], heartbeat check: I am not the oldest","color: red;")}else s&&(s.differentUserPresentOnTab?(yield C(),this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.5] [No server data], different user present: set as viewer","color: blue;"),D=!1):s.sameUserPresentOnTab?(E(),this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.6] [No server data], same user on different tab: set as viewer (editor on diff tab)","color: blue;"),D=!1):(this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.7] [No server data], no external presence: eligible for editor","color: green;"),D=!0));!a?.length&&!s&&(this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.8] [No server data], no heartbeat, no user presence: default to undefined","color: darkgrey;"),D=!0)}let L;return D?(this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.18] Final decision: shouldSetUndefined true","color: green;"),L={shouldSetUndefined:!0}):(this.semDebuggerMode()&&console.log("%c[DEBUG_VELT_SDK] [3.19] Final decision: return data","color: blue;"),L={data:u}),this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] [3.20] determineEditorStatusNew returnValue",L),this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] [3] determineEditorStatusNew end **************"),L}catch(t){return this.loggingService.catch("Error in determineEditorStatusNew: ",t),{data:void 0,shouldSetUndefined:void 0}}})}semDebuggerMode(){try{return localStorage.getItem("vSemDebuggerMode")==="true"}catch(e){return this.loggingService.catch("Error in semDebuggerMode: ",e),!1}}};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 Ki=(()=>{let o=class o{constructor(e,t,r,a,s,c,p,u,C,E,D,L,z,W,te){this.afAuth=e,this.analyticsService=t,this.authService=r,this.configService=a,this.databaseService=s,this.docService=c,this.domService=p,this.heartbeatService=u,this.iamService=C,this.loggingService=E,this.commonDbService=D,this.liveStateActionsService=L,this.liveStateUtilsService=z,this.usersService=W,this.singleEditorDecisionEngine=te,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 g0),this.autoSyncState$=new ve(!1),this.serverConnectionState$=new ve(ls.PENDING_INIT),this.externalUserPresence$=new ve(null),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),this.getSingleEditorMode$().subscribe(me=>{me?this.heartbeatService.enableHeartbeat():this.heartbeatService.disableHeartbeat()}),this.databaseService.getDb().pipe(Le(me=>!!me),at(1)).subscribe(me=>{me&&(this.db=me,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)}))},me=>{this.loggingService.catch("Error in LiveStateService getDb subscription: ",me)}),this.liveStateAutoSyncStateData$.pipe(Le(me=>Object.keys(me||{}).length>0),St((me,ye)=>JSON.stringify(me||{})===JSON.stringify(ye||{}))).subscribe(me=>{me&&(this.getAutoSyncState()&&(!this.autoSyncStateHistory&&me?.history&&this.updateLiveStateSyncInputDataLocally(me.history),me?.current&&this.updateLiveStateSyncInputDataLocally({[me.current.liveStateDataId]:me.current})),!this.autoSyncStateHistory&&me?.history&&(this.autoSyncStateHistory=me.history))}),this.docService.addPreDocumentIdChangeFunction("live-state-service",me=>(this.updateExternalUserPresence(null),this.isUserEditor()?.isEditor&&(!this.getSingleEditorModeConfig()?.singleTabEditor||this.isUserEditor()?.isEditorOnCurrentTab)?this.removeEditorAccess({metadata:{from:"addPreDocumentIdChangeFunction-liveStateService",reason:"Document id changed"},documentPaths:me}):Promise.resolve())),this.authService.addPreSignOutFuction("live-state-signout",this.signOutUser.bind(this)),this.singleEditorLiveStateData$.pipe(Di()).subscribe(([me,ye])=>{try{let Oe=ye?.requestEditorAccess?.status,ze=me?.requestEditorAccess?.status,Ne=this.authService.getUser();if(Oe==="pending"){if(Ne?.userId===ye?.editor?.userId){let Ie={viewer:ya(ye?.requestEditorAccess?.user)??void 0,editor:ya(ye?.editor)??void 0,timestamp:new Date().getTime(),status:"requested"};this.liveStateActionsService?.onAccessRequested(Ie)}return}if(Oe==="cancelled"){if(Ne?.userId===ye?.editor?.userId){let Ie={viewer:ya(ye?.requestEditorAccess?.user)??void 0,editor:ya(ye?.editor)??void 0,timestamp:new Date().getTime(),status:"canceled"};this.liveStateActionsService?.onAccessRequestCanceled(Ie)}return}if(ze==="pending"&&!Oe){if(me?.requestEditorAccess?.user?.userId===ye?.editor?.userId){if(me?.requestEditorAccess?.user?.userId===Ne?.userId){let Ie={viewer:ya(me?.editor)??void 0,editor:ya(ye?.editor)??void 0,timestamp:new Date().getTime(),status:"accepted"};this.liveStateActionsService?.onAccessAccepted(Ie)}return}if(me?.requestEditorAccess?.user?.userId!==ye?.editor?.userId){if(me?.requestEditorAccess?.user?.userId===Ne?.userId){let Ie={viewer:ya(me?.requestEditorAccess?.user)??void 0,editor:ya(ye?.editor)??void 0,timestamp:new Date().getTime(),status:"rejected"};this.liveStateActionsService?.onAccessRejected(Ie)}return}}}catch(Oe){this.loggingService.catch("Error in LiveStateService singleEditorLiveStateData$ subscription: ",Oe)}}),this.isUserEditor$().pipe(St(pn)).subscribe(me=>{try{if(me){this.analyticsService.trackEvent(X.Events.LiveStateSync.SEM_USER_EDITOR_STATS,{isEditor:me?.isEditor,isEditorOnCurrentTab:me?.isEditorOnCurrentTab});let ye=this.singleEditorLiveStateData$.value;if(me?.isEditor)if(me?.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(me){this.loggingService.catch("Error in LiveStateService constructor: ",me)}}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),Zt(()=>this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] \u{1F504} Heartbeat search triggered.")),he(()=>{let t=this.heartbeatService.getHeartbeatData({documentId:this.documentPaths?.documentId}).pipe(at(1),he(r=>{let a=this.singleEditorDecisionEngine.findOldestActiveSessionFromHeartbeats(r);return a?(this.semDebuggerMode()&&console.log(`[DEBUG_VELT_SDK] \u2705 Found oldest session to monitor: ${a.userId}`),this.monitorSession$(a.userId,a.tabId)):(this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] \u274C No oldest session found. Continuing process with null heartbeat."),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=>{let a=!r?.id||Date.now()-r?.lastUpdatedTimestamp>1e4;return a?(this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] \u26A0\uFE0F Primary editor is stale. Finding fallback...",r,"isStale",a),t):(this.semDebuggerMode()&&console.log(`[DEBUG_VELT_SDK] \u2705 Primary editor is active. Monitoring: ${e.userId}`,r,"isStale",a),this.monitorSession$(e.userId,e.tabId))}))}),St((t,r)=>this.isHeartbeatSimilar(t,r)))}monitorSession$(e,t){return console.log("[DEBUG_VELT_SDK] monitorSession$ userId",e,"tabId",t),this.heartbeatService.getSpecificHeartbeat({userId:e,tabId:t,documentId:this.documentPaths?.documentId}).pipe(he(a=>a?.id?(this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] \u2764\uFE0F Heartbeat received",a),se(a)):(this.semDebuggerMode()&&console.log(`[DEBUG_VELT_SDK] \u203C\uFE0F Session document removed for ${e}. Triggering restart immediately.`),this.heartbeatRestart$.next(),_l)),M8({each:1e4,with:()=>(this.semDebuggerMode()&&console.log(`[DEBUG_VELT_SDK] \u203C\uFE0F Session timed out for ${e}. Triggering restart.`),this.heartbeatRestart$.next(),_l)}))}isHeartbeatSimilar(e,t){return!e&&!t?!0:!e||!t?!1:e.userId===t.userId&&e.tabId===t.tabId}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(ce(t=>(e.featureAllowed=t,e))):se(e)),he(e=>e.featureAllowed?this.authService.isPlanExpired$().pipe(ce(t=>(e.featureAllowed=!t,e))):se(e)),he(e=>e.featureAllowed?se(e).pipe(he(t=>this.docService.getDocumentPaths$().pipe(ce(r=>(this.documentPaths=r,t.documentPaths=r,t)))),he(t=>t?.documentPaths?se(t).pipe(Zt(r=>{this.serverConnectionState$?.value===ls.PENDING_INIT&&r?.documentPaths?.liveState&&this.serverConnectionState$.next(ls.PENDING_DATA)}),he(r=>this.domService.onNetworkStatusChange$().pipe(Le(a=>a),ce(()=>r))),he(r=>this.getDataFromDocumentId().pipe(ce(a=>(this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK][1] getDataFromDocumentId data",a,this.docService.getDocumentPaths()),r.singleEditorModeData=a,I({},r))))),he(r=>this.getSingleEditorMode$().pipe(ce(()=>r))),ce(r=>([ls.ONLINE,ls.OFFLINE].includes(this.serverConnectionState$?.value)||this.serverConnectionState$.next(ls.ONLINE),r)),he(r=>this.getSingleEditorMode()?this.getExternalUserPresence$().pipe(ce(a=>T(I({},r),{externalUserPresence:a}))):se(r))):se(T(I({},t),{liveStateData:{}}))),he(t=>{if(this.getSingleEditorMode()){let r=t?.singleEditorModeData?.editor,a=t?.singleEditorModeData?.tabId;return console.log("[DEBUG_VELT_SDK] editor",r,"tabId",a),this.getActiveHeartbeatStream$({userId:r?.userId,tabId:a}).pipe(ce(s=>{let c=s?.id?[s]:null;return T(I({},t),{heartbeatData:c})}))}else return se(t)}),Zt(t=>{let r=t?.heartbeatData;if(!r)this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK][1] heartbeatData is null");else{this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK][1] heartbeatData length:",r?.length);let a=s=>(Date.now()-s)/1e3+" ago";this.semDebuggerMode()&&console.table(r?.map(s=>({userId:s?.userId,tabId:s?.tabId,lastUpdatedTimestamp:a(s?.lastUpdatedTimestamp),createdTimestamp:a(s?.createdTimestamp),isCurrentTab:s?.tabId===this.tabId,currentTabId:this.tabId})))}}),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:X.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_EMPTY_DATA_STATS,properties:{previousSingleEditorModeData:s,currentSingleEditorModeData:t?.singleEditorModeData}})}return this.updateSingleEditorLiveSyncDataNew(t?.singleEditorModeData||{},t?.externalUserPresence??null,t?.heartbeatData??null,t),se(t)}else return se(t)})):se({})))}updateSingleEditorLiveSyncDataNew(e,t,r,a){return Q(this,null,function*(){try{this.loggingService.log("%c[WB] Calling FUNCTION: updateSingleEditorLiveSyncData","color: green;"),vi(e,{})&&!this.keydownSubscription&&this.detectKeydownOnInput();let s=JSON.parse(JSON.stringify(e)),c=yield this.singleEditorDecisionEngine.determineEditorStatusNew({singleEditorModeData:s,externalUserPresence:t,heartbeatData:r,currentUser:this.authService.getUser(),currentTabId:this.tabId});this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] [10] LiveStateService updateSingleEditorLiveSyncDataNew newData",c?.shouldSetUndefined,c?.data,"heartbeatData length:",r?.length),this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] \u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B\u2B1B");let p;this.domService.getNetworkStatus()||(p=null),e=c?.data??{},c?.shouldSetUndefined||(p=null);let u=a?a?.documentPaths:this.docService.getDocumentPaths();if(u||(p=null),this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] [11] LiveStateService updateSingleEditorLiveSyncDataNew editorEmptyStateValue",e,p,this.isEditor$?.value,u),e&&!e?.editor&&this.isEditor$?.value!==p&&this.isEditor$.next(p),vi(this.singleEditorLiveStateData,e))return;{this.singleEditorLiveStateData=e,this.singleEditorLiveStateData$.next(e);let C;if(this.singleEditorLiveStateData&&typeof this.singleEditorLiveStateData=="object"&&(C=this.liveStateUtilsService.formatLiveStateSingleEditorModeData(JSON.parse(JSON.stringify(this.singleEditorLiveStateData)))),this.analyticsService.trackEvent(X.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_STATS,{singleEditorLiveStateData:C}),this.singleEditorLiveStateData?.editor){let E=this.authService.getUser();this.singleEditorLiveStateData?.editor?.userId!==E?.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{}})}updateSingleEditorLiveSyncData(a,s){return Q(this,arguments,function*(e,t,r=[]){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: updateSingleEditorLiveSyncData","color: green;"),vi(e,{})){let u=yield this.fetchSingleEditorLiveStateDataFromDatabase();if(!vi(u,e)&&(r.push({eventName:X.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_MISMATCH,properties:{serverData:u,localData:e}}),u&&typeof u=="object")){let C=yield this.liveStateUtilsService.resolveAndMergeSingleEditorLiveStateDataWithUser(JSON.parse(JSON.stringify(u)));e=JSON.parse(JSON.stringify(C))}}vi(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 u=this.authService.getUser();if(t?.sameUserPresentOnTab)e.editor=u,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_${u?.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),vi(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 u;if(this.singleEditorLiveStateData&&typeof this.singleEditorLiveStateData=="object"&&(u=this.liveStateUtilsService.formatLiveStateSingleEditorModeData(JSON.parse(JSON.stringify(this.singleEditorLiveStateData)))),this.analyticsService.trackEvent(X.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_STATS,{singleEditorLiveStateData:u}),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};vi(a,s)||this.analyticsService.trackEvent(X.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),ce(t=>T(I({},e),{config:t})),he(t=>this.authService.getUser$().pipe(ce(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),ce(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(pn))}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(ce(a=>(r.featureAllowed=a,r))):se(r)),he(r=>r.featureAllowed?this.authService.isPlanExpired$().pipe(ce(a=>(r.featureAllowed=!a,r))):se(r)),he(r=>r.featureAllowed?se(r).pipe(he(a=>this.docService.getDocumentPaths$().pipe(ce(s=>(this.documentPaths=s,a.documentPaths=s,a)))),he(a=>{let s=t?.listenToNewChangesOnly?1:0;return this.getLiveStateDataFromDatabase$(e).pipe(Gs(s))}),ce(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],u=p?.data;if(p?.isDataStringified&&typeof u=="string")try{u=JSON.parse(u)}catch{}s[p.liveStateDataId]=u}}),s}return a})):se(void 0).pipe(Le(Boolean))),St((r,a)=>JSON.stringify(r||{})===JSON.stringify(a||{})),Le(r=>r!==void 0),ce(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(ce(a=>a?.data),ce(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 u=yield this.commonDbService.getData({feature:"liveStateCustom",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",id:s,skipFirestore:!0}});if(u?.isDataStringified){let C=JSON.parse(u?.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=ui(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;"),console.log("[DEBUG_VELT_SDK] LiveStateService setUserAsEditor config",e,this.user,this.documentPaths?.liveStateSingleEditorMode,this.docService.getDocumentPaths()),this.user&&this.documentPaths?.liveStateSingleEditorMode){if(this.analyticsService.trackEvent(X.Events.LiveStateSync.SET_USER_AS_EDITOR_TRIGGERED,{editorUserId:this.user?.userSnippylyId,tabId:this.tabId}),!e?.skipEditorCheck){let r=yield this.fetchSingleEditorLiveStateDataFromDatabase();if(this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] LiveStateService setUserAsEditor currentSingleEditorLiveStateData line 1362: ",r),r?.editor?.userId&&r?.tabId){let a=yield P8(this.heartbeatService.getSpecificHeartbeat({userId:r?.editor?.userId,tabId:r?.tabId,documentId:this.documentPaths?.documentId}));this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] LiveStateService setUserAsEditor heartbeatData line 1392: ",a);let s=null;a&&(s=this.singleEditorDecisionEngine.findOldestActiveSessionFromHeartbeats([a]),this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] LiveStateService setUserAsEditor oldestHeartbeat line 1396: ",s)),s||(r=null,this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] LiveStateService setUserAsEditor currentSingleEditorLiveStateData line 1400: ",r))}else r=null,this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] LiveStateService setUserAsEditor currentSingleEditorLiveStateData line 1404: ",r);if(this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] LiveStateService setUserAsEditor currentSingleEditorLiveStateData line 1406: ",r),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(X.Events.LiveStateSync.SET_USER_AS_EDITOR_ERROR,{error:s,singleEditorLiveStateData:c}),this.semDebuggerMode()&&console.log("[DEBUG_VELT_SDK] [12] LiveStateService setUserAsEditor errorEvent",s),{error:s}}}let t={editor:this.user,tabId:this.tabId,editorAt:this.timestamp};console.log("[DEBUG_VELT_SDK] LiveStateService setUserAsEditor singleEditorLiveStateData",t,{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0}),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(X.Events.LiveStateSync.REQUEST_EDITOR_ACCESS_TRIGGERED),new Ut(e=>{let t=null;try{if(this.user&&this.documentPaths?.liveStateSingleEditorMode){let r=this.getEditorAccessTimeout(),a=Pi(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(X.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(X.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(X.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(X.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(X.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(X.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(X.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(X.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(pn))}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(ce(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(ce(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;"),console.log("[DEBUG_VELT_SDK] LiveStateService removeEditorAccess would have been called!",e,this.user,this.documentPaths?.liveStateSingleEditorMode),this.analyticsService.trackEvent(X.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(pn))}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(ce(t=>(e.featureAllowed=t,e))):se(e)),he(e=>e.featureAllowed?this.authService.isPlanExpired$().pipe(ce(t=>(e.featureAllowed=!t,e))):se(e)),he(e=>e.featureAllowed?se(e).pipe(he(t=>this.docService.getDocumentPaths$().pipe(Le(r=>!!r),ce(r=>(this.documentPaths=r,t.documentPaths=r,t)))),Zt(t=>{this.serverConnectionState$?.value===ls.PENDING_INIT&&t?.documentPaths?.liveState&&this.serverConnectionState$.next(ls.PENDING_DATA)}),he(t=>this.domService.onNetworkStatusChange$().pipe(Le(r=>r),ce(()=>t))),he(t=>this.getLiveStateAutoSyncStateDataFromDocumentId().pipe(ce(r=>(t.liveStateData=r,I({},t))))),ce(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),ce(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(pn))}enableSingleEditorMode(e){try{if(this.singleEditorMode$.value===!0)return;this.singleEditorMode$.next(!0),e?this.singleEditorModeConfig$.next(e):this.singleEditorModeConfig$.next(new Mk)}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(pn))}getExternalUserPresence(){return this.externalUserPresence$.value}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=ui(e,"input").pipe(cr(300)).subscribe(p=>{let u={value:p?.target?.value,tagName:p?.target?.tagName,type:p?.target?.type};this.setLiveStateSyncInputData(p?.target,u)});break;case"textarea":s=ui(e,"input").pipe(cr(300)).subscribe(p=>{let u={value:p?.target?.value,tagName:p?.target?.tagName};this.setLiveStateSyncInputData(p?.target,u)});break;default:e.getAttribute("contenteditable")&&(s=ui(e,"input").pipe(cr(300)).subscribe(p=>{let u={innerText:p?.target?.innerText,innerHTML:this.domService.sanitizeHtml(p?.target?.innerHTML),tagName:p?.target?.tagName,isContentEditable:!0};this.setLiveStateSyncInputData(p?.target,u)}));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(Zt(e=>{try{if(this.documentPaths?.liveStateSingleEditorMode){let t=Pi(this.db,`${this.documentPaths?.liveStateSingleEditorMode}`);e?.isEditor&&(!this.getSingleEditorModeConfig()?.singleTabEditor||e?.isEditorOnCurrentTab)?ol(t).remove():ol(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(ce(t=>e))),Zt(e=>Q(this,null,function*(){try{if(this.docService.getDocumentPaths()?.liveState&&e){let r=Pi(this.db,".info/connected"),a=!0;$p(r,s=>{let c=s.val();if(a&&c===!1){a=!1;return}a=!1,c===!1?this.serverConnectionState$.next(ls.OFFLINE):this.serverConnectionState$.value===ls.OFFLINE&&this.serverConnectionState$.next(ls.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()}semDebuggerMode(){try{return localStorage.getItem("vSemDebuggerMode")==="true"}catch(e){return this.loggingService.catch("Error in LiveStateService semDebuggerMode: ",e),!1}}};o.\u0275fac=function(t){return new(t||o)(J(Ai),J(et),J(Ve),J(Nt),J(Cn),J(rt),J(Be),J(Ide),J(_n),J(y),J(mn),J(f9),J(Kk),J(kn),J(Ede))},o.\u0275prov=Ae({token:o,factory:o.\u0275fac,providedIn:"root"});let i=o;return i})();var v9=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.on=this._on}_getLiveStateData(o,n){this.getService(y).log("%c[WB] Calling FUNCTION: getLiveStateData","color: green;");try{return this.trackEvent(X.Events.LiveStateSync.GET_LIVE_STATE_DATA_TRIGGERED),this.getService(Ki).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(Ki).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(X.Events.LiveStateSync.ENABLE_SINGLE_EDITOR_MODE_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.DISABLE_SINGLE_EDITOR_MODE_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.IS_USER_EDITOR_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.GET_EDITOR_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.SET_USER_AS_EDITOR_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.RESET_USER_ACCESS_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.SINGLE_EDITOR_MODE_CONTAINER_IDS_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.ENABLE_AUTO_SYNC_STATE_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.DISABLE_AUTO_SYNC_STATE_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.REQUEST_EDITOR_ACCESS_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.IS_EDITOR_ACCESS_REQUESTED_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.ACCEPT_EDITOR_ACCESS_REQUEST_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.REJECT_EDITOR_ACCESS_REQUEST_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.CANCEL_EDITOR_ACCESS_REQUEST_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.EDIT_CURRENT_TAB_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.SET_EDITOR_ACCESS_TIMEOUT_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.ENABLE_EDITOR_ACCESS_TRANSFER_ON_TIMEOUT_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.DISABLE_EDITOR_ACCESS_TRANSFER_ON_TIMEOUT_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.ENABLE_DEFAULT_SINGLE_EDITOR_UI_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.DISABLE_DEFAULT_SINGLE_EDITOR_UI_TRIGGERED),this.getService(Ki).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(X.Events.LiveStateSync.GET_EDITOR_ACCESS_TIMER_TRIGGERED),this.getService(Ki).getEditorAccessTimer$()}catch(o){return this.getService(y).catch("Error in _getEditorAccessTimer: ",o),se(new g0)}}_onServerConnectionStateChange(){this.getService(y).log("%c[WB] Calling FUNCTION: onServerConnectionStateChange","color: green;");try{return this.trackEvent(X.Events.LiveStateSync.ON_SERVER_CONNECTION_STATE_CHANGE_TRIGGERED),this.getService(Ki).onServerConnectionStateChange$()}catch(o){return this.getService(y).catch("Error in _onServerConnectionStateChange: ",o),se(ls.PENDING_INIT)}}_updateUserPresence(o){this.getService(y).log("%c[WB] Calling FUNCTION: updateUserPresence","color: green;");try{this.trackEvent(X.Events.LiveStateSync.UPDATE_USER_PRESENCE_TRIGGERED,{payload:{userPresence:o}}),this.getService(Ki).updateExternalUserPresence(o)}catch(n){this.getService(y).catch("Error in _updateUserPresence: ",n)}}_on(o){this.getService(y).log("%c[WB] Calling FUNCTION: on","color: green;");try{return this.trackEvent(X.Events.LiveStateSync.ON_ACTION_TRIGGERED,{payload:{action:o}}),this.getService(f9).onAction(o)}catch(n){return this.getService(y).catch("Error in _on: ",n),se(null)}}};var C9=(()=>{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 _9=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.on=this._on}_openHistoryPanel(){this.getService(y).log("%c[WB] Calling FUNCTION: _openHistoryPanel","color: green;");try{this.trackEvent(X.Events.Notifications.OPEN_HISTORY_PANEL_TRIGGERED),this.getService(un).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(X.Events.Notifications.CLOSE_HISTORY_PANEL_TRIGGERED),this.getService(un).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(X.Events.Notifications.TOGGLE_HISTORY_PANEL_TRIGGERED),this.getService(un).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(X.Events.Notifications.GET_NOTIFICATIONS_DATA_TRIGGERED),this.getService(un).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(X.Events.Notifications.SET_MAX_DAYS_TRIGGERED,{payload:{days:o}}),this.getService(un).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(X.Events.Notifications.SET_TAB_CONFIG_TRIGGERED,{payload:{tabConfig:o}}),this.getService(un).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(X.Events.Notifications.ENABLE_READ_NOTIFICATIONS_ON_FOR_YOU_TAB_TRIGGERED),this.getService(un).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(X.Events.Notifications.DISABLE_READ_NOTIFICATIONS_ON_FOR_YOU_TAB_TRIGGERED),this.getService(un).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(X.Events.Notifications.SET_ALL_NOTIFICATIONS_AS_READ_TRIGGERED,{payload:{config:o}}),this.getService(un).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(X.Events.Notifications.GET_UNREAD_NOTIFICATIONS_COUNT_TRIGGERED),this.getService(un).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(X.Events.Notifications.MARK_NOTIFICATION_AS_READ_BY_ID_TRIGGERED,{payload:{notificationId:o}}),this.getService(un).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(X.Events.Notifications.SET_SETTINGS_TRIGGERED,{payload:{config:o}}),this.getService(un).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(X.Events.Notifications.GET_SETTINGS_TRIGGERED),this.getService(un).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(X.Events.Notifications.MUTE_ALL_NOTIFICATIONS_TRIGGERED),this.getService(un).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(X.Events.Notifications.ENABLE_SETTINGS_TRIGGERED),this.getService(un).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(X.Events.Notifications.ENABLE_SELF_NOTIFICATIONS_TRIGGERED),this.getService(un).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(X.Events.Notifications.DISABLE_SELF_NOTIFICATIONS_TRIGGERED),this.getService(un).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(X.Events.Notifications.DISABLE_SETTINGS_TRIGGERED),this.getService(un).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(X.Events.Notifications.SET_SETTINGS_INITIAL_CONFIG_TRIGGERED,{payload:{settings:o}}),this.getService(un).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(X.Events.Notifications.ON_ACTION_TRIGGERED,{payload:{action:o}}),this.getService(C9).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(X.Events.Notifications.OPEN_NOTIFICATIONS_PANEL_TRIGGERED),this.getService(un).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(X.Events.Notifications.CLOSE_NOTIFICATIONS_PANEL_TRIGGERED),this.getService(un).closeNotificationsPanel()}catch(o){this.getService(y).catch("Error in closeNotificationsPanel: ",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(X.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(X.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(ce(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 y9=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(X.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(X.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(X.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(X.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(X.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(X.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(X.Events.Presence.ENABLE_SELF_TRIGGERED),this.getService(Wl).enableIncludeSelf()}catch(o){this.getService(y).catch("Error in _enableSelf: ",o)}}_disableSelf(){try{this.trackEvent(X.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(X.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(X.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 S9=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(X.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(X.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(X.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 fg=(()=>{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(Yi),J(xn))},o.\u0275prov=Ae({token:o,factory:o.\u0275fac,providedIn:"root"});let i=o;return i})();var b9=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.on=this._on}_initRecording(o,n){this.getService(y).log("%c[WB] Calling FUNCTION: initRecording","color: green;");try{return this.trackEvent(X.Events.Recording.INIT_RECORDING_TRIGGERED,{payload:{type:o,panelId:n}}),this.getService(xn).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(X.Events.Recording.ON_RECORDED_DATA_TRIGGERED),this.getService(xn).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(X.Events.Recording.ENABLE_DARK_MODE_TRIGGERED),this.getService(Yi).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(X.Events.Recording.DISABLE_DARK_MODE_TRIGGERED),this.getService(Yi).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(X.Events.Recording.ENABLE_RECORDING_COUNTDOWN_TRIGGERED),this.getService(xn).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(X.Events.Recording.DISABLE_RECORDING_COUNTDOWN_TRIGGERED),this.getService(xn).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(X.Events.Recording.GET_RECORDING_DATA_BY_RECORDER_ID_TRIGGERED,{payload:{recorderId:o}}),this.getService(Yi).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(X.Events.Recording.GET_RECORDINGS_TRIGGERED,{payload:{query:o}}),this.getService(Yi).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(X.Events.Recording.GET_RECORDING_DATA_TRIGGERED,{payload:{query:o}}),this.getService(Yi).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(X.Events.Recording.FETCH_RECORDINGS_TRIGGERED,{payload:{query:o}}),this.getService(Yi).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(X.Events.Recording.DELETE_RECORDING_TRIGGERED,{payload:{query:o}}),this.getService(Yi).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(X.Events.Recording.ENABLE_RECORDING_TRANSCRIPTION_TRIGGERED),this.getService(Yi).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(X.Events.Recording.DISABLE_RECORDING_TRANSCRIPTION_TRIGGERED),this.getService(Yi).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(X.Events.Recording.ON_ACTION_TRIGGERED,{payload:{action:o}}),this.getService(fg).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(X.Events.Recording.ENABLE_VIDEO_EDITOR_TRIGGERED),this.getService(xn).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(X.Events.Recording.DISABLE_VIDEO_EDITOR_TRIGGERED),this.getService(xn).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(X.Events.Recording.SET_RECORDING_QUALITY_CONSTRAINTS_TRIGGERED,{payload:{constraints:o}}),this.getService(xn).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(X.Events.Recording.SET_RECORDING_ENCODING_OPTIONS_TRIGGERED,{payload:{options:o}}),this.getService(xn).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(X.Events.Recording.DOWNLOAD_LATEST_VIDEO_TRIGGERED,{payload:{recorderId:o}}),this.getService(Yi).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(X.Events.Recording.ENABLE_RECORDING_MIC_TRIGGERED),this.getService(xn).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(X.Events.Recording.DISABLE_RECORDING_MIC_TRIGGERED),this.getService(xn).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(X.Events.Recording.ENABLE_ONBOARDING_TOOLTIP_TRIGGERED),this.getService(xn).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(X.Events.Recording.DISABLE_ONBOARDING_TOOLTIP_TRIGGERED),this.getService(xn).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(X.Events.Recording.ENABLE_RETAKE_ON_VIDEO_EDITOR_TRIGGERED),this.getService(xn).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(X.Events.Recording.DISABLE_RETAKE_ON_VIDEO_EDITOR_TRIGGERED),this.getService(xn).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(X.Events.Recording.ASK_DEVICE_PERMISSION_TRIGGERED),this.getService(xn).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(X.Events.Recording.SET_MAX_LENGTH_TRIGGERED,{payload:{seconds:o}}),this.getService(xn).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(X.Events.Recording.OPEN_PICTURE_IN_PICTURE_TRIGGERED),yield this.getService(xn).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(X.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(X.Events.Recording.REQUEST_SCREEN_PERMISSION_TRIGGERED),this.getService(xn).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(X.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(X.Events.Recording.DISABLE_PICTURE_IN_PICTURE_TRIGGERED),this.getService(Ga).disablePictureInPicture()}catch(o){this.getService(y).catch("Error in _disablePictureInPicture: ",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 u=document.querySelectorAll(j.TAGS.SNIPPYLY_REWRITER);if(!document.querySelectorAll(j.TAGS.VELT_REWRITER)?.length&&!u?.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(X.Events.Rewriter.REWRITER_ENABLED,{isMobileDevice:this.domService.isMobileDevice()})})}}else{let u=document.querySelectorAll(j.TAGS.SNIPPYLY_REWRITER);u?.length&&u.forEach(E=>{E.remove()});let C=document.querySelectorAll(j.TAGS.VELT_REWRITER);C?.length&&C.forEach(E=>{E.remove()})}}catch(u){this.loggingService.catch("Error in rewriterEnabled$: ",u)}},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 Lk;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(X.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(ce(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}
|