@veltdev/sdk
Version:
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.
2 lines (1 loc) • 41.1 kB
JavaScript
import{a as et}from"./chunk-T5PFG7WD.js";import{t as qe}from"./chunk-BACKCNIG.js";import"./chunk-JFNRCHYR.js";import"./chunk-U4YN7DB7.js";import"./chunk-3HGEDPEP.js";import"./chunk-JDLRIKAZ.js";import"./chunk-3J52NZMN.js";import"./chunk-4ACOV475.js";import{b as Ke,d as Qe}from"./chunk-WTYACTR5.js";import{a as Ze}from"./chunk-6E3N35RF.js";import{G as Le,H as Ae,I as we,r as ke,t as Ue,v as Ne}from"./chunk-KU45CEXD.js";import{$ as he,Cf as Fe,Db as _e,E as N,Eb as Ie,Ed as Re,Ee as y,Fa as p,Fb as ye,Fc as Oe,Gc as Pe,Hi as Ye,I as le,Ib as Q,Ii as Je,J as se,Jb as R,L as ae,M as ce,Ma as pe,Nb as z,Nf as te,Ob as Ce,Pa as j,Pb as q,Pc as De,T,Ta as Se,Ua as fe,Va as Ee,W as G,X as ge,Zf as ie,_a as x,a as b,aa as me,ac as Te,ag as ne,b as I,bb as be,bc as xe,bg as $e,ca as E,ci as Ge,db as L,di as g,ei as je,g as oe,kc as W,l as k,la as de,lb as _,lc as V,lf as F,li as ze,mb as w,mf as X,mi as We,nb as B,nf as H,ob as K,oe as ee,pc as Z,qa as ue,r as C,rg as Be,sb as O,sg as He,tb as P,tg as Me,ti as Ve,v as U,vh as S,wa as ve,yi as Xe,zb as v}from"./chunk-GR3NESUB.js";var ct=["selectionElementPortalOverlay"],gt=()=>["velt-overlay-panel"],ht=s=>[s];function mt(s,n){if(s&1&&(O(0),w(1,"span",10),z(2),W(3,"translate"),B(),P()),s&2){let r=v(),e=r.$implicit,t=r.index,i=v(5);p(),R("--velt-selection-color",e==null||e.user==null?null:e.user.color),L("data-testid",i.componentId+"-user-name-"+t),p(),Ce(V(3,4,(e==null||e.user==null?null:e.user.name)||(e==null||e.user==null?null:e.user.email)))}}function dt(s,n){if(s&1&&(O(0),x(1,mt,4,6,"ng-container",3),P()),s&2){let r=n.index,e=v(5);p(),_("ngIf",r<e.maxCount)}}function ut(s,n){if(s&1&&(w(0,"span",11),z(1),B()),s&2){let r=v(4).ngIf,e=v();R("--velt-selection-color",(r.selections[0]==null||r.selections[0].user==null?null:r.selections[0].user.color)||"white"),L("data-testid",e.componentId+"-additional-count")("aria-label",(r.selections==null?null:r.selections.length)-e.maxCount+" additional users"),p(),q("+",(r.selections==null?null:r.selections.length)-e.maxCount)}}function vt(s,n){if(s&1&&(O(0),w(1,"div",7),W(2,"translate"),x(3,dt,2,1,"ng-container",8)(4,ut,2,5,"span",9),B(),P()),s&2){let r=v(3).ngIf,e=v();p(),L("data-testid",e.componentId+"-label-container")("aria-label",V(2,4,"Selected users")),p(2),_("ngForOf",r.selections),p(),_("ngIf",(r.selections==null?null:r.selections.length)>e.maxCount)}}function pt(s,n){if(s&1&&(O(0),K(1,"snippyly-user-avatar",13),P()),s&2){let r=v(),e=r.$implicit,t=r.index;p(),R("--velt-selection-color",e==null||e.user==null?null:e.user.color)("--velt-selection-user-index",t),_("size",20)("user",e==null?null:e.user)}}function St(s,n){if(s&1&&(O(0),x(1,pt,2,6,"ng-container",3),P()),s&2){let r=n.index,e=v(5);p(),_("ngIf",r<e.maxCount)}}function ft(s,n){if(s&1&&(w(0,"div",14),W(1,"translate"),w(2,"span",15),z(3),B()()),s&2){let r=v(4).ngIf,e=v();R("--velt-selection-user-index",r.selections==null?null:r.selections.length)("background-color",(r.selections[(r.selections==null?null:r.selections.length)-1]==null||r.selections[(r.selections==null?null:r.selections.length)-1].user==null?null:r.selections[(r.selections==null?null:r.selections.length)-1].user.color)||"white"),L("data-testid",e.componentId+"-additional-avatars")("aria-label",(r.selections==null?null:r.selections.length)-e.maxCount+" "+V(1,7,"additional users")),p(3),q("+",(r.selections==null?null:r.selections.length)-e.maxCount)}}function Et(s,n){if(s&1&&x(0,St,2,1,"ng-container",8)(1,ft,4,9,"div",12),s&2){let r=v(3).ngIf,e=v();_("ngForOf",r.selections),p(),_("ngIf",(r.selections==null?null:r.selections.length)>e.maxCount)}}function bt(s,n){if(s&1&&x(0,vt,5,6,"ng-container",6)(1,Et,2,2,"ng-template",null,2,Z),s&2){let r=Q(2),e=v(2).ngIf,t=v();_("ngIf",(e==null?null:e.userIndicatorType)===(t.userIndicatorTypes==null?null:t.userIndicatorTypes.Label))("ngIfElse",r)}}function _t(s,n){if(s&1&&(O(0),K(1,"div",4,0),x(3,bt,3,2,"ng-template",5,1,Z),P()),s&2){let r=Q(2),e=v().ngIf,t=v();p(),R("top",(e==null||e.position==null?null:e.position.top)+t.offsetTop,"px")("left",(e==null||e.position==null?null:e.position.left)+t.offsetLeft,"px"),_("id","selection-element-contianer-"+(t.highlight.user==null?null:t.highlight.user.userSnippylyId)),L("data-testid",t.componentId),p(2),_("cdkConnectedOverlayOrigin",r)("cdkConnectedOverlayOpen",!0)("cdkConnectedOverlayLockPosition",!1)("cdkConnectedOverlayGrowAfterOpen",!0)("cdkConnectedOverlayDisableClose",!0)("cdkConnectedOverlayPanelClass",Te(13,gt))("cdkConnectedOverlayPositions",xe(14,ht,e==null?null:e.overlayPosition))}}function It(s,n){if(s&1&&(O(0),x(1,_t,5,16,"ng-container",3),P()),s&2){let r=n.ngIf;p(),_("ngIf",r==null?null:r.position)}}var re=(()=>{let n=class n{get highlight(){return this._highlight}set highlight(e){this._highlight=e,this.calculatePosition()}constructor(e,t,i){this.loggingService=e,this.selectionService=t,this.elementRef=i,this._highlight=new F,this.position=null,this.userIndicatorTypes=H,this.offsetLeft=0,this.offsetTop=0,this.maxCount=1,this.componentConfigSignal=ue({userIndicatorPosition:X.End,userIndicatorType:H.Avatar,position:null,overlayPosition:{originX:"end",originY:"top",overlayX:"end",overlayY:"top"},selections:[]}),this.veltElement=!0,this.componentId="velt-selection-element";try{this.loggingService.log("%c[WB] Creating CLASS: SelectionElementPortalComponent","color: blue;");let o=this.selectionService.getUserIndicatorPosition(),h=this.selectionService.getUserIndicatorType();this.componentConfigSignal.update(d=>(d=I(b({},d),{userIndicatorPosition:o,userIndicatorType:h}),d)),this.setOverlayPosition(o)}catch(o){this.loggingService.log("Error in SelectionElementPortalComponent constructor: ",o)}}ngOnInit(){try{this.setupA11yAttributes()}catch(e){this.loggingService.catch("Error in SelectionElementPortalComponent ngOnInit:",e)}}setupA11yAttributes(){try{let e=this.elementRef.nativeElement;e.setAttribute("data-testid",this.componentId+"-container"),e.setAttribute("role","complementary"),e.setAttribute("aria-label","Selection portal")}catch(e){this.loggingService.catch("Error in SelectionElementPortalComponent setupA11yAttributes:",e)}}setSelections(e){try{this.componentConfigSignal.update(t=>(t=I(b({},t),{selections:e}),t))}catch(t){this.loggingService.catch("Error in SelectionElementPortalComponent setSelections: ",t)}}addSelection(e){try{this.componentConfigSignal.update(t=>(t=b({},t),t.selections.push(e),t))}catch(t){this.loggingService.catch("Error in SelectionElementPortalComponent addSelection: ",t)}}ngAfterViewInit(){try{this.loggingService.log("%c[WB] Calling SelectionElementPortalComponent FUNCTION: ngAfterViewInit","color: green;"),this.updateOverlayPosition()}catch(e){this.loggingService.catch("Error in ngAfterViewInit: ",e)}}setOverlayPosition(e){try{this.loggingService.log("%c[WB] Calling SelectionElementPortalComponent FUNCTION: setOverlayPosition","color: green;"),e==="start"?this.componentConfigSignal.update(t=>(t=I(b({},t),{overlayPosition:{originX:"start",originY:"top",overlayX:"start",overlayY:"top"}}),t)):this.componentConfigSignal.update(t=>(t=I(b({},t),{overlayPosition:{originX:"end",originY:"top",overlayX:"end",overlayY:"top"}}),t)),this.updateOverlayPosition()}catch(t){this.loggingService.catch("Error in SelectionElementPortalComponent setOverlayPosition: ",t)}}updateOverlayPosition(){try{this.loggingService.log("%c[WB] Calling SelectionElementPortalComponent FUNCTION: updateOverlayPosition","color: green;"),this.selectionElementPortalOverlay&&this.selectionElementPortalOverlay?.overlayRef?.updatePosition()}catch(e){this.loggingService.catch("Error in SelectionElementPortalComponent updateOverlayPosition: ",e)}}calculatePosition(){try{if(this.loggingService.log("%c[WB] Calling SelectionElementPortalComponent FUNCTION: calculatePosition","color: green;"),this.highlight?.targetElement){let e=Be(this.highlight.targetElement);if(e){let t=e.iterateNext(),i,o=null,h=null;try{i=JSON.parse(t?.getAttribute(y.ATTRIBUTES.VELT_SELECTION_CONFIG)||"{}"),o=t?.getAttribute(y.ATTRIBUTES.VELT_LIVE_SELECTION_USER_INDICATOR_POSITION)||this.componentConfigSignal().userIndicatorPosition,o&&this.setOverlayPosition(o),h=t?.getAttribute(y.ATTRIBUTES.VELT_LIVE_SELECTION_USER_INDICATOR_TYPE)||this.componentConfigSignal().userIndicatorType,this.componentConfigSignal.update(a=>(a=I(b({},a),{userIndicatorPosition:o,userIndicatorType:h}),a))}catch{}let d;if(i?.horizontal&&(d=i.horizontal),o==="start"?d="top-start":d="top-right",t){let a=t.getBoundingClientRect();if(a&&a.width&&a.height)switch(d){case"left":this.position={top:a.height/2-16,left:-4};break;case"left-start":this.position={top:0,left:-4};break;case"top-start":this.position={top:-32,left:0};break;case"top-right":this.position={top:-32,left:a.width};break;case"bottom-left":this.position={top:a.height+4,left:0};break;case"bottom-right":this.position={top:a.height+4,left:a.width-32};break;case"center-left":this.position={top:a.height/2-16,left:-32};break;case"center-right":this.position={top:a.height/2-16,left:a.width+4};break;default:this.position={top:-32,left:a.width}}else this.position=null}else this.position=null}else this.position=null}this.componentConfigSignal.update(e=>(e=I(b({},e),{position:this.position}),e))}catch(e){this.loggingService.catch("Error in SelectionElementPortalComponent calculatePosition: ",e)}}};n.\u0275fac=function(t){return new(t||n)(j(g),j(f),j(ve))},n.\u0275cmp=fe({type:n,selectors:[["app-selection-element-portal"]],viewQuery:function(t,i){if(t&1&&_e(ct,5),t&2){let o;Ie(o=ye())&&(i.selectionElementPortalOverlay=o.first)}},hostVars:1,hostBindings:function(t,i){t&2&&L("data-velt-element",i.veltElement)},inputs:{highlight:"highlight",offsetLeft:"offsetLeft",offsetTop:"offsetTop"},standalone:!1,decls:1,vars:1,consts:[["trigger","cdkOverlayOrigin"],["selectionElementPortalOverlay","cdkConnectedOverlay"],["defaultAvatarTypeTemplate",""],[4,"ngIf"],["cdkOverlayOrigin","","role","presentation",1,"selection-element-portal",3,"id"],["cdkConnectedOverlay","",3,"cdkConnectedOverlayOrigin","cdkConnectedOverlayOpen","cdkConnectedOverlayLockPosition","cdkConnectedOverlayGrowAfterOpen","cdkConnectedOverlayDisableClose","cdkConnectedOverlayPanelClass","cdkConnectedOverlayPositions"],[4,"ngIf","ngIfElse"],["role","list",1,"velt-live-selection-element-user-name-container"],[4,"ngFor","ngForOf"],["class","velt-live-selection-element-user-name-plus","role","listitem",3,"--velt-selection-color",4,"ngIf"],["role","listitem",1,"velt-live-selection-element-user-name"],["role","listitem",1,"velt-live-selection-element-user-name-plus"],["class","photo-container","role","listitem",3,"--velt-selection-user-index","background-color",4,"ngIf"],[1,"photo-container","selection-user-avatar",3,"size","user"],["role","listitem",1,"photo-container"],[1,"s-selection-element-avatar-initial"]],template:function(t,i){t&1&&x(0,It,2,1,"ng-container",3),t&2&&_("ngIf",i.componentConfigSignal())},dependencies:[Oe,Pe,Ae,Le,Qe,Ke],styles:["html[_ngcontent-%COMP%]{--velt-base-rem-unit: 1}*[data-snippyly-element=true][_ngcontent-%COMP%], *[data-velt-element=true][_ngcontent-%COMP%]{font-family:var(--velt-default-font-family)}velt-wireframe[_ngcontent-%COMP%]{display:none!important}body.velt-pin-dragging[_ngcontent-%COMP%] iframe[_ngcontent-%COMP%]{pointer-events:none!important}[_nghost-%COMP%]{--velt-green: var(--velt-light-mode-green);--velt-magenta: var(--velt-light-mode-magenta);--velt-amber: var(--velt-light-mode-amber);--velt-purple: var(--velt-light-mode-purple);--velt-cyan: var(--velt-light-mode-cyan);--velt-orange: var(--velt-light-mode-orange);--velt-black: var(--velt-light-mode-black);--velt-white: var(--velt-light-mode-white);--velt-gray: var(--velt-light-mode-gray);--velt-error: var(--velt-light-mode-error);--velt-error-hover: var(--velt-light-mode-error-hover);--velt-error-foreground: var(--velt-light-mode-error-foreground);--velt-error-light: var(--velt-light-mode-error-light);--velt-error-transparent: var(--velt-light-mode-error-transparent);--velt-warning: var(--velt-light-mode-warning);--velt-warning-hover: var(--velt-light-mode-warning-hover);--velt-warning-foreground: var(--velt-light-mode-warning-foreground);--velt-warning-light: var(--velt-light-mode-warning-light);--velt-warning-transparent: var(--velt-light-mode-warning-transparent);--velt-agent-accent: #4495ff;--velt-agent-accent-transparent: rgba(68, 149, 255, .2);--velt-success: var(--velt-light-mode-success);--velt-success-hover: var(--velt-light-mode-success-hover);--velt-success-foreground: var(--velt-light-mode-success-foreground);--velt-success-light: var(--velt-light-mode-success-light);--velt-success-transparent: var(--velt-light-mode-success-transparent);--velt-accent: var(--velt-light-mode-accent);--velt-accent-text: var(--velt-light-mode-accent-text);--velt-accent-hover: var(--velt-light-mode-accent-hover);--velt-accent-foreground: var(--velt-light-mode-accent-foreground);--velt-accent-light: var(--velt-light-mode-accent-light);--velt-accent-transparent: var(--velt-light-mode-accent-transparent);--velt-text-0: var(--velt-light-mode-text-0);--velt-text-1: var(--velt-light-mode-text-1);--velt-text-2: var(--velt-light-mode-text-2);--velt-text-3: var(--velt-light-mode-text-3);--velt-text-4: var(--velt-light-mode-text-4);--velt-text-5: var(--velt-light-mode-text-5);--velt-text-6: var(--velt-light-mode-text-6);--velt-text-7: var(--velt-light-mode-text-7);--velt-text-8: var(--velt-light-mode-text-8);--velt-text-9: var(--velt-light-mode-text-9);--velt-text-10: var(--velt-light-mode-text-10);--velt-text-11: var(--velt-light-mode-text-11);--velt-text-12: var(--velt-light-mode-text-12);--velt-background-0: var(--velt-light-mode-background-0);--velt-background-1: var(--velt-light-mode-background-1);--velt-background-2: var(--velt-light-mode-background-2);--velt-background-3: var(--velt-light-mode-background-3);--velt-background-4: var(--velt-light-mode-background-4);--velt-background-5: var(--velt-light-mode-background-5);--velt-background-6: var(--velt-light-mode-background-6);--velt-background-7: var(--velt-light-mode-background-7);--velt-background-8: var(--velt-light-mode-background-8);--velt-background-9: var(--velt-light-mode-background-9);--velt-background-10: var(--velt-light-mode-background-10);--velt-border-0: var(--velt-light-mode-border-0);--velt-border-1: var(--velt-light-mode-border-1);--velt-border-2: var(--velt-light-mode-border-2);--velt-border-3: var(--velt-light-mode-border-3);--velt-border-4: var(--velt-light-mode-border-4);--velt-border-5: var(--velt-light-mode-border-5);--velt-border-6: var(--velt-light-mode-border-6);--velt-border-7: var(--velt-light-mode-border-7);--velt-border-8: var(--velt-light-mode-border-8);--velt-border-9: var(--velt-light-mode-border-9);--velt-border-10: var(--velt-light-mode-border-10);--velt-background-transparent: var(--velt-light-mode-background-transparent);--velt-border-transparent: var(--velt-light-mode-border-transparent);--velt-animation-transparent: var(--velt-light-mode-animation-transparent);position:absolute;top:0;left:0;box-sizing:border-box;-webkit-tap-highlight-color:rgba(255,255,255,0);outline:none;margin:0;padding:0;height:unset;width:unset;text-align:left}*[_ngcontent-%COMP%]{box-sizing:border-box;-webkit-tap-highlight-color:rgba(255,255,255,0);outline:none;margin:0;padding:0;height:unset;width:unset;text-align:left;line-height:1.5;color:#000;font-size:calc((1rem + 0px) * var(--velt-base-rem-unit))}*[_ngcontent-%COMP%]:empty{display:revert}.selection-element-portal[_ngcontent-%COMP%]{display:none;position:absolute;top:0;left:0;white-space:nowrap;z-index:1;font-size:var(--velt-font-size-xs)}.photo-container[_ngcontent-%COMP%]{display:flex;align-items:center;justify-content:center;width:calc((1.5rem + 0px) * var(--velt-base-rem-unit));height:calc((1.5rem + 0px) * var(--velt-base-rem-unit));box-sizing:border-box;background-clip:padding-box;border-radius:50%;color:var(--velt-light-mode-white);border:2px solid var(--velt-selection-color);margin-left:-5px;z-index:calc(var(--velt-selection-user-index, 0) * -1)}.photo-container[_ngcontent-%COMP%] .s-selection-element-avatar-initial[_ngcontent-%COMP%]{color:var(--velt-light-mode-white)}.photo-container[_ngcontent-%COMP%] img[_ngcontent-%COMP%]{width:100%;height:100%;border-radius:50%;object-fit:cover} snippyly-user-avatar.selection-user-avatar .s-user-avatar-initial{font-size:var(--velt-font-size-md)}.velt-live-selection-element-user-name-container[_ngcontent-%COMP%]{display:flex;gap:var(--velt-spacing-xs);margin-top:5px}.velt-live-selection-element-user-name-container[_ngcontent-%COMP%] .velt-live-selection-element-user-name[_ngcontent-%COMP%]{color:var(--velt-light-mode-white);display:flex;background:var(--velt-selection-color);padding:var(--velt-spacing-xs) var(--velt-spacing-sm);font-size:var(--velt-spacing-md);font-style:normal;font-weight:400;line-height:100%;border-radius:var(--velt-border-radius-md);font-family:var(--velt-default-font-family)}.velt-live-selection-element-user-name-container[_ngcontent-%COMP%] .velt-live-selection-element-user-name-plus[_ngcontent-%COMP%]{color:var(--velt-light-mode-white);display:flex;background:var(--velt-selection-color);padding:var(--velt-spacing-x);font-size:var(--velt-font-size-xs);font-style:normal;font-weight:400;line-height:100%;border-radius:var(--velt-border-radius-md);font-family:var(--velt-default-font-family)}"],changeDetection:0});let s=n;return s})();var f=(()=>{let n=class n{constructor(e,t,i,o,h,d,a,D,J,nt,rt,ot,lt){this.afAuth=e,this.analyticsService=t,this.authService=i,this.configService=o,this.databaseService=h,this.docService=d,this.domService=a,this.componentFactoryResolver=D,this.injector=J,this.appRef=nt,this.loggingService=rt,this.commonDbService=ot,this.realtimeAdapter=lt,this.documentPaths=null,this.textSelections={},this.enableSelections$=new k(!1),this.userIndicatorEnabled$=new k(!0),this.userIndicatorPosition$=new k(X.End),this.userIndicatorType$=new k(H.Avatar),this.defaultElementsTrackingEnabled$=new k(!0),this.defaultStylingEnabled$=new k(!0),this.inactivityTime=300*1e3,this.userIdleStateDetectionSubscription=null,this.elementSelections={},this.databaseService.getDb().pipe(N(l=>!!l),se(1)).subscribe(l=>{l&&(this.updateOnDocumentFocusChange(),this.updateOnUserDbConnectionStateChange(l).subscribe(()=>{},m=>{this.loggingService.catch("Error in SelectionService constructor updateOnUserDbConnectionStateChange: ",m)}))},l=>{this.loggingService.catch("Error in SelectionService getDb subscription: ",l)}),this.authService.getUser$().subscribe(l=>{l?this.detectUserIdleState():this.unsubscribeUserIdleStateDetectionSubscription()}),this.docService.getDocumentPaths$().subscribe(l=>{this.documentPaths=l},l=>{this.loggingService.catch("Error in SelectionService getDocumentPaths subscription: ",l)}),this.domService.onDocumentClick$().subscribe(l=>{try{if(this.enableSelections$.value&&this.isFeatureAllowed()&&l?.target&&!window.getSelection()?.toString()){let m=this.getSelectionEnabledElement(l.target);if(m&&!ie(m)){let u=this.domService.getXPath(m);if(u){let c=new F;c.type="click",c.targetElement=u,c.timestamp=this.timestamp,this.setSelection(c)}}else this.removeSelection()}}catch(m){this.loggingService.catch("Error in SelectionService onDocumentClick$: ",m)}},l=>{this.loggingService.catch("Error in SelectionService onDocumentClick$ subscription: ",l)}),this.domService.onDocumentFocus$().subscribe(l=>{try{if(this.enableSelections$.value&&this.isFeatureAllowed()&&l?.target){let m=this.getSelectionEnabledElement(l.target);if(m&&!ie(m)){let u=this.domService.getXPath(m);if(u){let c=new F;c.type="focus",c.targetElement=u,c.timestamp=this.timestamp,this.setSelection(c)}}else this.removeSelection()}}catch(m){this.loggingService.catch("Error in SelectionService onDocumentFocus$: ",m)}},l=>{this.loggingService.catch("Error in SelectionService onDocumentFocus$ subscription: ",l)}),this.domService.onWindowKeyupEsc$().subscribe(l=>{this.removeSelection()},l=>{this.loggingService.catch("Error in SelectionService onWindowKeyupEsc$ subscription: ",l)}),this.enableSelections$.pipe(T(()=>this.isFeatureAllowed$({})),N(l=>l?.config&&l?.user)).subscribe(l=>{(!l?.featureAllowed||!this.enableSelections$.value)&&this.removeSelection()},l=>{this.loggingService.catch("Error in SelectionService enableSelections$ subscription: ",l)}),this.domService.onSelectionChange$().subscribe(()=>{try{if(this.enableSelections$.value&&this.isFeatureAllowed()&&window.getSelection()?.toString()){let l=window.getSelection()?.getRangeAt(0);if(l.commonAncestorContainer&&!l?.collapsed){let m=He([l]),u=new F;u.type="selection",u.targetTextRange=m?.length?m[0]:null,u.timestamp=this.timestamp,this.setSelection(u)}}}catch(l){this.loggingService.catch("Error in SelectionService onSelectionChange$: ",l)}},l=>{this.loggingService.catch("Error in SelectionService onSelectionChange$ subscription: ",l)}),this.authService.getUser$().subscribe(l=>{this.user=l},l=>{this.loggingService.catch("Error in SelectionService getUser$ subscription: ",l)}),this.getSelectionsOnCurrentDocument().pipe(ce()).subscribe(([l,m])=>{try{if(l){let u=[];Object.keys(l).forEach(c=>{let A=l[c],$=m?m[c]:null;!ne(A,$)&&c!==this.getUserIdHash(this.user)&&u.push(A)}),u.forEach(c=>{if(c.targetElement){let A=this.elementSelections[c?.targetElement]?.portalRef,M=(this.elementSelections[c?.targetElement]?.selections||[]).filter(st=>this.getUserIdHash(st.user)!==this.getUserIdHash(c?.user));M?.length?(A.instance.setSelections(M.slice()),this.elementSelections[c?.targetElement].selections=M.slice(),this.highlightElement(M[0])):(this.removeHighlightFromElement(c),this.removeSelectionElement(c))}else c.targetTextRange&&this.removeHighlightFromText(c)})}if(m){let u=[];Object.keys(m).forEach(c=>{let A=l?l[c]:null,$=m[c];!ne(A,$)&&c!==this.getUserIdHash(this.user)&&u.push($)}),u.forEach(c=>{c.targetElement?(this.highlightElement(c),this.getUserIndicatorEnabled()&&this.setElementHighlight(c)):c.targetTextRange&&this.highlightText(c)})}}catch(u){this.loggingService.catch("Error in SelectionService getSelectionsOnCurrentDocument: ",u)}},l=>{this.loggingService.catch("Error in SelectionService getSelectionsOnCurrentDocument subscription: ",l)}),this.authService.addPreSignOutFuction("highlight-signout",this.signOutUser.bind(this))}detectUserIdleState(){try{this.unsubscribeUserIdleStateDetectionSubscription();let e=!1;this.userIdleStateDetectionSubscription=this.domService.onWindowPointerMove$().pipe(ge(2e3),G(()=>{e&&(e=!1)}),le(this.inactivityTime),G(()=>{this.removeSelection(),e=!0})).subscribe()}catch(e){this.loggingService.catch("Error in detectUserIdleState: ",e)}}unsubscribeUserIdleStateDetectionSubscription(){try{this.userIdleStateDetectionSubscription&&(this.userIdleStateDetectionSubscription.unsubscribe(),this.userIdleStateDetectionSubscription=null)}catch(e){this.loggingService.catch("Error in unsubscribeUserIdleStateDetectionSubscription: ",e)}}isFeatureAllowed(){return te(this.configService.getConfig(),this.authService.getUser(),ee.LIVE_SELECTION)}updateOnDocumentFocusChange(){this.loggingService.log("%c[WB] Calling FUNCTION: updateOnDocumentFocusChange","color: green;");try{document&&document.addEventListener("visibilitychange",e=>{this.user&&document.visibilityState==="hidden"&&this.removeSelection()})}catch(e){this.loggingService.catch("Error in updateOnDocumentFocusChange:",e)}}getSelectionsOnCurrentDocument(){return this.loggingService.log("%c[WB] Calling FUNCTION: getSelectionsOnCurrentDocument","color: green;"),this.authService.getAuthState$().pipe(N(e=>!!e),T(e=>this.isFeatureAllowed$({firebaseUser:e})),T(e=>e.featureAllowed?C(e).pipe(T(t=>this.docService.getDocumentPaths$().pipe(U(i=>(this.documentPaths=i,t)))),T(t=>t?.user?t?.user?.isAnonymous?C(null):this.documentPaths?this.databaseService.getDb().pipe(N(i=>!!i),T(i=>this.documentPaths?.selection?this.commonDbService.dbListener({feature:"allSelections",properties:{documentId:this.documentPaths?.documentId,organizationId:this.documentPaths?.organizationId,skipFirestore:!0}}).pipe(U(o=>o?.data),U(o=>this.filterActiveSelections(o))):C(null))):C(null):C(null))):C(null)))}isFeatureAllowed$(e){return this.configService.getConfig$().pipe(N(t=>!!t),U(t=>I(b({},e),{config:t})),T(t=>this.authService.getUser$().pipe(U(i=>(this.user=i,I(b({},t),{user:i}))))),T(t=>te(t.config,t.user,ee.LIVE_SELECTION)?C(I(b({},t),{featureAllowed:!0})):(this.loggingService.warn("Live Selection feature is not allowed."),C(I(b({},t),{featureAllowed:!1})))),ae((t,i)=>t?.featureAllowed===i?.featureAllowed))}filterActiveSelections(e){this.loggingService.log("%c[WB] Calling FUNCTION: filterOnlineUsers","color: green;");try{if(e&&typeof e=="object"&&Object.keys(e).length){let t={},i=this.commonDbService.getServerTimestamp();return Object.keys(e).forEach(o=>{let h=e[o];h?.timestamp&&Math.abs(i-h.timestamp)<this.inactivityTime&&(t[o]=h)}),t}return e}catch(t){return this.loggingService.catch("Error in filterOnlineUsers:",t),e}}setSelection(e){try{if(this.user?.userId&&this.documentPaths?.selection){e.user=this.user;let t=JSON.parse(JSON.stringify(e));t&&!t?.timestamp&&(t.timestamp=this.timestamp),this.commonDbService.updateData({feature:"selection",properties:{documentId:this.documentPaths?.documentId,organizationId:this.documentPaths?.organizationId,userId:this.getUserIdHash(this.user)??"",skipFirestore:!0},data:t})}}catch(t){this.loggingService.catch("Error in SelectionService setSelection: ",t)}}removeSelection(){try{this.user?.userId&&this.documentPaths?.selection&&this.commonDbService.deleteData({feature:"selection",properties:{documentId:this.documentPaths?.documentId,organizationId:this.documentPaths?.organizationId,userId:this.getUserIdHash(this.user)??"",skipFirestore:!0}})}catch(e){this.loggingService.catch("Error in SelectionService removeSelection: ",e)}}updateOnUserDbConnectionStateChange(e){return this.loggingService.log("%c[WB] Calling FUNCTION: updateOnUserDbConnectionStateChange","color: green;"),this.authService.getAuthState$().pipe(N(t=>!!t),T(t=>this.docService.getDocumentPaths$().pipe(U(i=>t))),G(t=>oe(this,null,function*(){try{if(this.documentPaths&&t){let i=yield this.authService.getIdTokenResultForUser(t,!0).catch(h=>null);if(!i)return;let{user:o}=i.claims;if(o&&this.documentPaths?.selection){let h=this.getUserIdHash(o);if(h){let d=`${this.documentPaths.selection}/${h}`,a=this.realtimeAdapter.rtdbRef(e,d);this.realtimeAdapter.rtdbOnDisconnectRemove("selection",a).catch(D=>{this.loggingService.catch("Error in SelectionService updateOnUserDbConnectionStateChange onDisconnect:",D)})}}}}catch(i){this.loggingService.catch("Error in SelectionService updateOnUserDbConnectionStateChange:",i)}})))}highlightElement(e){try{let t=this.domService.getXPath(e.targetElement);if(t){let i=t.iterateNext();if(i){let o=["input","textarea","select","button"],h;try{i?.getAttribute(y.ATTRIBUTES.VELT_SELECTION_CONFIG)&&(h=JSON.parse(i?.getAttribute(y.ATTRIBUTES.VELT_SELECTION_CONFIG)||"{}"))}catch{}(!h||h?.border)&&this.domService.highlightUserElement(i,e?.user?.color,e?.user?.name,this.getDefaultStylingEnabled())}}}catch(t){this.loggingService.catch("Error in SelectionService highlightElement: ",t)}}removeHighlightFromElement(e){try{let t=this.domService.getXPath(e.targetElement);if(t){let i=t.iterateNext();i&&this.domService.removeHighlightUserFromElement(i)}}catch(t){this.loggingService.catch("Error in SelectionService removeHighlightFromElement: ",t)}}highlightText(e){try{if(e?.targetTextRange){let t=$e(e.targetTextRange?.text,this.domService.getXPath(e.targetTextRange?.commonAncestorContainer).iterateNext(),e.targetTextRange?.occurrence),i=new Range;try{i.setStart(t[0].textNode,t[0].startOffset||0),i.setEnd(t[t.length-1].textNode,t[t.length-1].endOffset||0)}catch{}if(i.toString()===e.targetTextRange?.text){let o=et(i,y.TAGS.SNIPPYLY_HIGHLIGHT_USER_TEXT),h=[],d=this.getSelectionUserMarker(e.user);if(o&&o.length&&(o.forEach(a=>{a?.textContent?.trim()&&(this.domService.addClassToElement(a,a.tagName?.toLowerCase()),this.domService.addClassToElement(a,y.VELT_LIVE_SELECTION_ON_TEXT),this.getDefaultStylingEnabled()&&this.domService.addClassToElement(a,y.VELT_LIVE_SELECTION_ON_TEXT_DEFAULT),e.user?.color&&a.style.setProperty(y.VELT_SELECTION_COLOR,e.user?.color+"55"),h.push({element:a,textNode:a.childNodes[0]}))}),d)){let a=o.filter(J=>J?.textContent?.trim()),D=a?.length?a[a?.length-1]:null;D&&D.parentNode.insertBefore(d,D.nextSibling)}this.textSelections[this.getUserIdHash(e?.user)]={textNodes:h,marker:d}}}}catch(t){this.loggingService.catch("Error in SelectionService highlightText: ",t)}}removeHighlightFromText(e){try{let t=this.getUserIdHash(e?.user);t&&this.textSelections[t]?.textNodes?.length&&(this.textSelections[t].textNodes.forEach(i=>{i?.element&&i?.textNode&&i.element.replaceWith(i.textNode),i.textNode&&i.textNode.parentNode?.normalize()}),this.textSelections[t]?.marker&&this.textSelections[t]?.marker?.remove())}catch(t){this.loggingService.catch("Error in SelectionService removeHighlightFromText: ",t)}}getSelectionUserMarker(e){try{let t=document.createElement("span");t.classList.add("snippyly-user-marker","active"),t.setAttribute("data-name",e?.name+""),t.style.setProperty("--velt-selection-marker-color",e?.color||"#000");let i=document.createElement("span");i.classList.add("snippyly-user-marker-line");let o=document.createElement("span");return o.classList.add("snippyly-user-marker-dot"),i.appendChild(o),t.appendChild(i),setTimeout(()=>{t?.classList?.remove("active")},1e3),t}catch(t){return this.loggingService.catch("Error in SelectionService getSelectionUserMarker: ",t),null}}signOutUser(e){return new Promise((t,i)=>{try{this.documentPaths?.selection&&e?this.commonDbService.getData({feature:"selection",properties:{documentId:this.documentPaths?.documentId,organizationId:this.documentPaths?.organizationId,userId:e.uid,skipFirestore:!0}}).then(o=>{o&&this.commonDbService.deleteData({feature:"selection",errorCallback:h=>{i(h)},callback:()=>{t(null)},properties:{documentId:this.documentPaths?.documentId,organizationId:this.documentPaths?.organizationId,userId:this.getUserIdHash(this.user)??"",skipFirestore:!0}}),t(null)}).catch(o=>{this.loggingService.catch("Error in SelectionService signOutUser subscription: ",o),i(o)}):t(null)}catch(o){this.loggingService.catch("Error in SelectionService signOutUser:",o),i(o)}})}setInactivityTime(e){try{this.inactivityTime=e,this.analyticsService.trackEvent(S.Events.Selection.SELECTION_SET_CUSTOM_INACTIVITY_TIMER,{inactivityTime:this.inactivityTime}),this.detectUserIdleState()}catch(t){this.loggingService.catch("Error in SelectionService setInactivityTime: ",t)}}getInactivityTime(){return this.inactivityTime}enableSelections(e){try{this.enableSelections$.next(e)}catch(t){this.loggingService.catch("Error in SelectionService enableSelections: ",t)}}enableUserIndicator(){try{if(this.userIndicatorEnabled$.value===!0)return;this.userIndicatorEnabled$.next(!0)}catch(e){this.loggingService.catch("Error in SelectionService enableUserIndicator: ",e)}}disableUserIndicator(){try{if(this.userIndicatorEnabled$.value===!1)return;this.userIndicatorEnabled$.next(!1)}catch(e){this.loggingService.catch("Error in SelectionService disableUserIndicator: ",e)}}getUserIndicatorEnabled$(){return this.userIndicatorEnabled$.asObservable()}getUserIndicatorEnabled(){return this.userIndicatorEnabled$.value}setUserIndicatorPosition(e){try{this.userIndicatorPosition$.next(e)}catch(t){this.loggingService.catch("Error in SelectionService setUserIndicatorPosition: ",t)}}getUserIndicatorPosition$(){return this.userIndicatorPosition$.asObservable()}getUserIndicatorPosition(){return this.userIndicatorPosition$.value}setUserIndicatorType(e){try{this.userIndicatorType$.next(e)}catch(t){this.loggingService.catch("Error in SelectionService setUserIndicatorType: ",t)}}getUserIndicatorType$(){return this.userIndicatorType$.asObservable()}getUserIndicatorType(){return this.userIndicatorType$.value}enableDefaultElementsTracking(){try{if(this.defaultElementsTrackingEnabled$.value===!0)return;this.defaultElementsTrackingEnabled$.next(!0)}catch(e){this.loggingService.catch("Error in SelectionService enableDefaultElementsTracking: ",e)}}disableDefaultElementsTracking(){try{if(this.defaultElementsTrackingEnabled$.value===!1)return;this.defaultElementsTrackingEnabled$.next(!1)}catch(e){this.loggingService.catch("Error in SelectionService disableDefaultElementsTracking: ",e)}}getDefaultElementsTrackingEnabled$(){return this.defaultElementsTrackingEnabled$.asObservable()}getDefaultElementsTrackingEnabled(){return this.defaultElementsTrackingEnabled$.value}enableDefaultStyling(){try{if(this.defaultStylingEnabled$.value===!0)return;this.defaultStylingEnabled$.next(!0)}catch(e){this.loggingService.catch("Error in SelectionService enableDefaultStyling: ",e)}}disableDefaultStyling(){try{if(this.defaultStylingEnabled$.value===!1)return;this.defaultStylingEnabled$.next(!1)}catch(e){this.loggingService.catch("Error in SelectionService disableDefaultStyling: ",e)}}getDefaultStylingEnabled$(){return this.defaultStylingEnabled$.asObservable()}getDefaultStylingEnabled(){return this.defaultStylingEnabled$.value}getSelectionEnabledElement(e){try{let t=this.getDefaultElementsTrackingEnabled();return t&&y.SELECTION_ENABLED_ELEMENTS[e.tagName?.toLowerCase()]?e:Me(e,t)}catch(t){return this.loggingService.catch("Error in SelectionService isElementAllowed: ",t),null}}setElementHighlight(e){try{if(!this.elementSelections[e.targetElement])this.setSelectionElement(e);else{let t=this.elementSelections[e.targetElement].portalRef;this.elementSelections[e.targetElement].selections?.find(o=>this.getUserIdHash(o.user)===this.getUserIdHash(e?.user))||(t.instance.addSelection(e),this.elementSelections[e.targetElement].selections.push(e))}}catch(t){this.loggingService.catch("Error in SelectionService setElementSelection: ",t)}}setSelectionElement(e){try{let t=this.domService.getXPath(e.targetElement);if(t){let i=t.iterateNext();if(i){let o=this.domService.getHostElement(i),h=new ke(re),d=new Ue(o,this.appRef,this.injector),a=d.attach(h);a.instance.highlight=e,a.instance.setSelections([e]),this.elementSelections[e.targetElement]={selectionHostDomPortalOutlet:d,selectionElementPortal:h,portalRef:a,selections:[JSON.parse(JSON.stringify(e))],userTargetElement:i,selectionHostElement:o,targetElement:e.targetElement},this.updateElementOffset(e)}}}catch(t){this.loggingService.catch("Error in SelectionService setSelectionElement: ",t)}}updateElementOffset(e){try{let{portalRef:t,userTargetElement:i,selectionHostElement:o}=this.elementSelections[e.targetElement],h=this.domService.getElementOffset(i,o);t.instance.offsetLeft=h.offsetLeft,t.instance.offsetTop=h.offsetTop}catch(t){this.loggingService.catch("Error in SelectionService updateElementOffset: ",t)}}checkElementHighlightsToRemove(e){try{let t=e.map(i=>i.targetElement);Object.keys(this.elementSelections).forEach(i=>{if(!t.includes(i)){let o=this.elementSelections[i];o&&(o.selectionHostDomPortalOutlet.detach(),this.domService.removeHighlightFromElement(o.selectionHostElement)),delete this.elementSelections[i]}})}catch(t){this.loggingService.catch("Error in SelectionService checkElementHighlightsToRemove: ",t)}}removeSelectionElement(e){try{let t=this.elementSelections[e.targetElement];t&&(t.selectionHostDomPortalOutlet.detach(),this.domService.removeHighlightFromElement(t.selectionHostElement)),delete this.elementSelections[e.targetElement]}catch(t){this.loggingService.catch("Error in SelectionService removeSelectionElement: ",t)}}getUserIdHash(e){try{return e?.userId?Fe(e?.userId):null}catch(t){return this.loggingService.catch("Error in SelectionService getUserIdHash: ",t),null}}get timestamp(){return this.commonDbService.getServerTimestamp()}};n.\u0275fac=function(t){return new(t||n)(E(Re),E(Ge),E(We),E(je),E(Ve),E(Xe),E(ze),E(pe),E(de),E(be),E(g),E(Je),E(Ye))},n.\u0275prov=he({token:n,factory:n.\u0275fac,providedIn:"root"});let s=n;return s})();var Y=class extends Ze{constructor(n){super(n),this.getService(g).log("%c[WB] Creating CLASS: SelectionElement","color: blue;"),this.enableLiveSelection=this._enableLiveSelection,this.disableLiveSelection=this._disableLiveSelection,this.enableUserIndicator=this._enableUserIndicator,this.disableUserIndicator=this._disableUserIndicator,this.setUserIndicatorPosition=this._setUserIndicatorPosition,this.setUserIndicatorType=this._setUserIndicatorType,this.enableDefaultElementsTracking=this._enableDefaultElementsTracking,this.disableDefaultElementsTracking=this._disableDefaultElementsTracking,this.enableDefaultStyling=this._enableDefaultStyling,this.disableDefaultStyling=this._disableDefaultStyling,this.getLiveSelectionData=this._getLiveSelectionData,this.setInactivityTime=this._setInactivityTime}_enableLiveSelection(){this.getService(g).log("%c[WB] Calling FUNCTION: _enableLiveSelection","color: green;");try{this.trackEvent(S.Events.Selection.ENABLE_LIVE_SELECTION_TRIGGERED),this.getService(f).enableSelections(!0)}catch(n){this.getService(g).catch("Error in enableLiveSelection: ",n)}}_disableLiveSelection(){this.getService(g).log("%c[WB] Calling FUNCTION: _disableLiveSelection","color: green;");try{this.trackEvent(S.Events.Selection.DISABLE_LIVE_SELECTION_TRIGGERED),this.getService(f).enableSelections(!1)}catch(n){this.getService(g).catch("Error in disableLiveSelection: ",n)}}_enableUserIndicator(){this.getService(g).log("%c[WB] Calling FUNCTION: enableUserIndicator","color: green;");try{this.trackEvent(S.Events.Selection.ENABLE_USER_INDICATOR_TRIGGERED),this.getService(f).enableUserIndicator()}catch(n){this.getService(g).catch("Error in _enableUserIndicator: ",n)}}_disableUserIndicator(){this.getService(g).log("%c[WB] Calling FUNCTION: disableUserIndicator","color: green;");try{this.trackEvent(S.Events.Selection.DISABLE_USER_INDICATOR_TRIGGERED),this.getService(f).disableUserIndicator()}catch(n){this.getService(g).catch("Error in _disableUserIndicator: ",n)}}_setUserIndicatorPosition(n){this.getService(g).log("%c[WB] Calling FUNCTION: setUserIndicatorPosition","color: green;");try{this.trackEvent(S.Events.Selection.SET_USER_INDICATOR_POSITION_TRIGGERED,{payload:{position:n}}),this.getService(f).setUserIndicatorPosition(n)}catch(r){this.getService(g).catch("Error in _setUserIndicatorPosition: ",r)}}_setUserIndicatorType(n){this.getService(g).log("%c[WB] Calling FUNCTION: setUserIndicatorType","color: green;");try{this.trackEvent(S.Events.Selection.SET_USER_INDICATOR_TYPE_TRIGGERED,{payload:{type:n}}),this.getService(f).setUserIndicatorType(n)}catch(r){this.getService(g).catch("Error in _setUserIndicatorType: ",r)}}_enableDefaultElementsTracking(){this.getService(g).log("%c[WB] Calling FUNCTION: enableDefaultElementsTracking","color: green;");try{this.trackEvent(S.Events.Selection.ENABLE_DEFAULT_ELEMENTS_TRACKING_TRIGGERED),this.getService(f).enableDefaultElementsTracking()}catch(n){this.getService(g).catch("Error in _enableDefaultElementsTracking: ",n)}}_disableDefaultElementsTracking(){this.getService(g).log("%c[WB] Calling FUNCTION: disableDefaultElementsTracking","color: green;");try{this.trackEvent(S.Events.Selection.DISABLE_DEFAULT_ELEMENTS_TRACKING_TRIGGERED),this.getService(f).disableDefaultElementsTracking()}catch(n){this.getService(g).catch("Error in _disableDefaultElementsTracking: ",n)}}_enableDefaultStyling(){this.getService(g).log("%c[WB] Calling FUNCTION: enableDefaultStyling","color: green;");try{this.trackEvent(S.Events.Selection.ENABLE_DEFAULT_STYLING_TRIGGERED),this.getService(f).enableDefaultStyling()}catch(n){this.getService(g).catch("Error in _enableDefaultStyling: ",n)}}_disableDefaultStyling(){this.getService(g).log("%c[WB] Calling FUNCTION: disableDefaultStyling","color: green;");try{this.trackEvent(S.Events.Selection.DISABLE_DEFAULT_STYLING_TRIGGERED),this.getService(f).disableDefaultStyling()}catch(n){this.getService(g).catch("Error in _disableDefaultStyling: ",n)}}_getLiveSelectionData(){this.getService(g).log("%c[WB] Calling FUNCTION: getLiveSelectionData","color: green;");try{return this.trackEvent(S.Events.Selection.GET_LIVE_SELECTION_DATA_TRIGGERED),this.getService(f).getSelectionsOnCurrentDocument()}catch(n){return this.getService(g).catch("Error in _getLiveSelectionData: ",n),C(null)}}_setInactivityTime(n){this.getService(g).log("%c[WB] Calling FUNCTION: _setInactivityTime","color: green;");try{this.trackEvent(S.Events.Selection.SET_INACTIVITY_TIME_TRIGGERED,{payload:{time:n}}),!isNaN(n)&&n>0?this.getService(f).setInactivityTime(n):this.getService(g).catch("Error in setInactivityTime: ","Provided value must be a positive number greater than zero.")}catch(r){this.getService(g).catch("Error in setInactivityTime: ",r)}}};var it=(()=>{let n=class n{};n.\u0275fac=function(t){return new(t||n)},n.\u0275mod=Ee({type:n}),n.\u0275inj=me({imports:[De,we,Ne,qe]});let s=n;return s})();function Ct(s){return s.get(g).log("%c[WB] Loading selection feature chunk","color: blue;"),Se(it,s),new Y(s)}export{Ct as default};