@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.
1 lines • 60.3 kB
JavaScript
import{c as ht,d as gt}from"./chunk-KEET32BV.js";import{t as Bt}from"./chunk-BACKCNIG.js";import"./chunk-JFNRCHYR.js";import"./chunk-U4YN7DB7.js";import{a as kt}from"./chunk-ZATQYC4Y.js";import"./chunk-3HGEDPEP.js";import"./chunk-JDLRIKAZ.js";import"./chunk-3J52NZMN.js";import{b as Nt}from"./chunk-4ACOV475.js";import"./chunk-WTYACTR5.js";import{a as Ft}from"./chunk-6E3N35RF.js";import{a as fe}from"./chunk-KEM6PWSD.js";import{a as vt}from"./chunk-UJRDSNTY.js";import{I as At,Y as Pt,r as pt,t as ut,v as ft}from"./chunk-KU45CEXD.js";import{$ as ge,$f as se,Ab as nt,Bb as it,Bf as Oe,C as $e,Db as ot,E as j,Eb as rt,Ed as St,Ee as h,Fa as D,Fb as at,Gc as pe,He as Ct,Ib as st,Ii as Lt,J as he,Jb as U,Kb as ee,Kc as lt,L as ae,Lc as mt,M as je,Ma as Je,Me as _t,Nf as It,Nh as te,Of as bt,Pa as E,Pc as dt,Rf as yt,T as A,Ta as Ye,Ua as ne,Va as Ze,Xg as we,Y as Ie,Yg as Me,Yh as Rt,Zf as $,_a as W,_g as Dt,a as p,aa as We,ac as Te,b as S,bb as Qe,bi as X,ca as _,ci as G,db as ie,di as T,ei as wt,g as le,ha as b,ia as y,ja as Xe,jg as xe,jh as Ot,l as re,la as Ge,lb as x,lh as Le,li as K,mb as O,me as De,mi as J,nb as L,ng as Re,ni as Ne,o as Ue,ob as qe,oe as w,p as me,pc as ct,pe as Et,qa as Ke,r as P,sb as be,si as H,tb as ye,ti as Mt,ub as et,v as f,vb as oe,vh as M,w as de,wb as tt,wg as Tt,xb as R,yh as xt,yi as ue,zb as v}from"./chunk-GR3NESUB.js";var k=(()=>{let l=class l{constructor(e,t,n,o,s,a,r,c,d,u,I,C,z){this.analyticsService=e,this.configService=t,this.docService=n,this.databaseService=o,this.commonDbService=s,this.authService=a,this.domService=r,this.afAuth=c,this.iamService=d,this.dialog=u,this.loggingService=I,this.userPermissionService=C,this.serviceBook=z,this.areaAnnotationById$=new re({}),this.documentPaths=null,this.areaEnabled$=new re(!0),this.allowedElementIds$=new re([]),this.addAreaMode$=new re(!1),this.notificationService=null,this.loggingService.log("%c[WB] Creating CLASS: AreaService","color: blue;"),this.serviceBook.observe(xt).subscribe(g=>this.notificationService=g),this.databaseService.getDb().pipe(j(g=>!!g),he(1)).subscribe(g=>{g&&this.getDocumentPaths()},g=>{this.loggingService.catch("Error in AreaService getDb subscription: ",g)}),this.domService.onWindowPointerMove$().subscribe(g=>{if(this.addAreaMode$.value){this.highlightElement&&this.domService.removeHighlightFromElement(this.highlightElement);let V=this.domService.getBackgroundElement(g.clientX,g.clientY);V&&(this.isElementInsideAllowedElements(V)?Re(g.target)?this.domService.removeClassFromElement(document.body,"show-pin-cursor"):(this.domService.addClassToElement(document.body,"show-pin-cursor"),this.highlightElement=V,this.domService.highlightElement(this.highlightElement,h.CURSOR.AREA_PIN)):this.domService.removeClassFromElement(document.body,"show-pin-cursor"))}},g=>{this.loggingService.catch("Error in AreaService onWindowPointerMove$ subscription: ",g)}),this.domService.onWindowKeyupEsc$().subscribe(g=>{this.addAreaMode$.value&&this.disableAddAreaMode()},g=>{this.loggingService.catch("Error in AreaService onWindowKeyupEsc$ subscription: ",g)}),this.domService.onDocumentClick$().subscribe(g=>{if(g&&this.addAreaMode$.value){if(g.preventDefault(),g.stopPropagation(),!Re(g.target)){let V=this.domService.getBackgroundElement(g.clientX,g.clientY);V&&this.isElementInsideAllowedElements(V)&&this.addArea(g)}this.disableAddAreaMode()}},g=>{this.loggingService.catch("Error in AreaService onDocumentClick$ subscription: ",g)}),this.addAreaMode$.subscribe(g=>{this.highlightElement&&this.domService.removeHighlightFromElement(this.highlightElement),g?this.domService.addClassToElement(document.body,"snippyly-add-area-mode"):(this.domService.removeClassFromElement(document.body,"snippyly-add-area-mode"),this.domService.removeClassFromElement(document.body,"show-pin-cursor"))},g=>{this.loggingService.catch("Error in AreaService addAreaMode$ subscription: ",g)}),this.domService.onWindowKeyupBackspace$().subscribe(g=>{this.deleteAreaPinAnnotations("keyupBackspace")},g=>{this.loggingService.catch("Error in AreaService onWindowKeyupBackspace$ subscription: ",g)}),this.domService.onWindowKeyupDelete$().subscribe(g=>{this.deleteAreaPinAnnotations("keyupDelete")},g=>{this.loggingService.catch("Error in AreaService onWindowKeyupDelete$ subscription: ",g)})}clearCache(){this.loggingService.log("%c[WB] Calling FUNCTION: clearCache in AreaService","color: green;");try{this.areaAnnotationById$.next({}),this.areaEnabled$.next(!0),this.allowedElementIds$.next([]),this.addAreaMode$.next(!1),this.highlightElement=null}catch(e){this.loggingService.catch("Error in AreaService clearCache: ",e)}}getDocumentPaths(){this.loggingService.log("%c[WB] Calling FUNCTION: getDocumentPaths","color: green;"),this.docService.getDocumentPaths$()}setAllowedElementIds(e){this.allowedElementIds$.next(e||[])}getAllowedElementIds(){return this.allowedElementIds$.asObservable()}getAllAreaAnnotations(e,t,n){this.loggingService.log("%c[WB] Calling FUNCTION: getAllAreaAnnotations","color: green;");let o,s;try{if(e&&(s=Oe(e)),t&&typeof t=="object"){let a=yt(t);o=Oe(JSON.stringify(a))}}catch(a){this.loggingService.catch("Error in AreaService getAllAreaAnnotations: ",a)}return this.authService.getAuthState$().pipe(j(a=>!!a),A(a=>this.isFeatureAllowed({firebaseUser:a,annotations:[],filteredAnnotations:[]})),A(a=>a.featureAllowed?this.iamService.isUserAllowed$().pipe(f(r=>(a.featureAllowed=r,a))):P(a)),A(a=>a.featureAllowed?this.authService.isPlanExpired$().pipe(f(r=>(a.featureAllowed=!r,a))):P(a)),A(a=>a.featureAllowed?P(a).pipe(A(r=>this.docService.getDocumentPaths$().pipe(f(c=>(this.documentPaths=c,r.documentPaths=c,r)))),A(r=>s?this.getDataFromDocumentIds([s]).pipe(f(c=>(r.annotations=c||[],p({},r)))):this.docService.getDocumentIds$().pipe(A(c=>{let d=c?.length>0?c.map(u=>u.documentId):[this.documentPaths?.documentId??""];return this.getDataFromDocumentIds(d).pipe(f(u=>(r.annotations=u||[],p({},r))))}))),A(r=>this.docService.getLocation$().pipe(f(c=>(r.location=c,r)))),A(r=>this.docService.getLocations$().pipe(f(c=>(r.customLocations=c,r)))),f(r=>{if(r.filteredAnnotations=[],s&&!o)return r.filteredAnnotations=r.annotations?.slice(),r;{let c=[],d=[];return o?c.push(o):(c.push(r?.location?.locationId),c.push(...Object.values(r?.customLocations||[]).map(u=>u.locationId)),r?.location?.location?.id&&d.push(r?.location?.location?.id)),r.filteredAnnotations=this.filterAnnotationsByLocationIds(r?.annotations,c,d),r}}),A(r=>n?P(r):r?.annotations?.length?this.domService.onWindowResize$().pipe(f(()=>r)):P(r)),A(r=>n?P(r):r?.annotations?.length?this.domService.onDomChange$("AreaService getAllAreaAnnotations").pipe(f(()=>r)):P(r)),f(r=>(r.filteredAnnotations=r.filteredAnnotations?.map(c=>{let d=Object.assign({},c);return d.areaProperties=this.calculateAreaAnnotationPosition(d),d}),r)),A(r=>r?.filteredAnnotations?P(r?.filteredAnnotations||[]):P([])),A(r=>{if(this.authService.isFeatureAllowed(w.COMMENT))return P(r);{let c=r?.filter(d=>!d?.targetAnnotations?.filter(u=>u?.type===w.COMMENT)?.length);return P(c)}})):P([])),ae(Ot))}isFeatureAllowed(e){return this.configService.getConfig$().pipe(j(t=>!!t),f(t=>S(p({},e),{config:t})),A(t=>this.authService.getUser$().pipe(f(n=>S(p({},t),{user:n})))),A(t=>It(t.config,t.user,w.AREA)?P(S(p({},t),{featureAllowed:!0})):(this.loggingService.warn("Area feature is not allowed."),P(S(p({},t),{featureAllowed:!1})))),ae((t,n)=>t?.featureAllowed===n?.featureAllowed))}getDataFromDocumentIds(e,t){return this.getDataFromDocuments({documentIds:e,filters:t})}getDataFromDocuments(e){if(this.configService.getApiKey()){let{documentIds:t,filters:n}=e;if(t?.some(r=>!r)||!this.documentPaths)return P([]);let o=this.docService.getDocumentPaths()?.veltFolderId,s=P([]),a={useCollectionGroup:!0,isCollection:!0,useQuery:!0};if(this.commonDbService.shouldUseFirestore()||(a.documentId=t?.length?t[0]:void 0,a.organizationId=this.documentPaths?.organizationId),this.userPermissionService?.getIsContextEnabled()){let r=[h.DEFAULT_VELT_CONTEXT,...this.docService.getProcessedDocContext()],c=[];for(let d=0;d<(r?.length??0);d+=h.LISTENER_CONTEXT_BATCH_SIZE)c.push(r?.slice(d,d+h.LISTENER_CONTEXT_BATCH_SIZE)??[]);s=de(c.map(d=>this.commonDbService.dbListener({feature:"allAreas",properties:S(p({},a),{firestoreQuery:[Ne(H("metadata.apiKey","==",this.configService?.getApiKey()),H("metadata.documentId","in",t),H("metadata.organizationId","==",this.documentPaths?.organizationId),...o?[H("metadata.veltFolderId","==",o)]:[],...d?.length?[H("context.accessFields","array-contains-any",d)]:[])]})}).pipe(Ie()))).pipe(f(d=>Le(d)))}else{let r=[];for(let c=0;c<(t?.length??0);c+=h.LISTENER_BATCH_SIZE)r.push(t?.slice(c,c+h.LISTENER_BATCH_SIZE)??[]);s=de(r.map(c=>this.commonDbService.dbListener({feature:"allAreas",properties:S(p({},a),{firestoreQuery:[Ne(H("metadata.apiKey","==",this.configService?.getApiKey()),H("metadata.documentId","in",c),H("metadata.organizationId","==",this.documentPaths?.organizationId),...o?[H("metadata.veltFolderId","==",o)]:[])]})}).pipe(Ie()))).pipe(f(c=>Le(c)))}return s.pipe(f(({data:r,operation:c})=>{let d=[];return r&&(d=Object.values(r??{}).filter(u=>typeof u=="object")),{data:d,operation:c}}),f(({data:r,operation:c})=>{if(!t)return{data:r,documentMap:{},operation:c};let d=r.reduce((u,I)=>{let C=I.metadata?.documentId;return C&&(u[C]||(u[C]=[]),u[C].push(I)),u},{});return{data:r,documentMap:d,operation:c}}),f(({data:r,documentMap:c,operation:d})=>{if(!n)if(d?.type==="removed"){if(d?.ids?.length){let u=this.areaAnnotationById$.value;d?.ids?.forEach(I=>{delete u?.[I]}),this.areaAnnotationById$.next(u)}}else Object.entries(c??{}).forEach(([u,I])=>{this.setAreaAnnotationsByOrganizationIdAndDocumentId({organizationId:this.documentPaths?.organizationId,documentId:u,annotations:I})});return r}))}else return P([])}setAreaAnnotationsByOrganizationIdAndDocumentId({organizationId:e,documentId:t,annotations:n,queryHash:o}){try{if(t){e||(e=h.NO_ORGANIZATION_ID),o||(o=h.DEFAULT_QUERY_HASH);let s={};n?.forEach(r=>{r?.annotationId&&(s[r?.annotationId]=r)});let a=p(p({},this.areaAnnotationById$.value),s);this.areaAnnotationById$.next(a)}}catch(s){this.loggingService.catch("Error in AreaService setAreaAnnotationsByOrganizationIdAndDocumentId:",s)}}getAnnotationById(e){try{return this.areaAnnotationById$.value?.[e]?this.areaAnnotationById$.value?.[e]:void 0}catch(t){this.loggingService.catch("Error in AreaService getAnnotationById: ",t);return}}filterAnnotationsByLocationIds(e,t,n){try{return e.filter(o=>t.includes(o.locationId)||n?.includes(o?.location?.id)||t?.find(s=>s==o?.location?.id)||n?.find(s=>s==o?.locationId+""))}catch(o){return this.loggingService.catch("Error in AreaService filterAnnotationsByLocations:",o),[]}}calculateAreaAnnotationPosition(e,t=!1){try{if(e.targetElements?.length){let n=e.targetElements[0],o=e.targetElements[1];if(n?.xpath&&o?.xpath||n?.anchor&&o?.anchor){let s=null,a=null;if(n?.anchor){let r=this.domService.resolveAnchorRecord(n.anchor);r?.element&&r?.element instanceof HTMLElement&&!$(r.element)&&this.domService.isElementVisible(r.element)&&se(r.element)&&(s=r.element)}else n?.xpath&&(s=this.domService.getElementFromXPath(n.xpath),s&&$(s)&&(s=null),this.domService.isXpathWithId(n.xpath)||(!s&&n.cfXpath&&(s=this.domService.getElementFromXPath(n.cfXpath),s&&$(s)&&(s=null)),!s&&n.fXpath&&(s=this.domService.getElementFromXPath(n.fXpath),s&&$(s)&&(s=null))));if(o?.anchor){let r=this.domService.resolveAnchorRecord(o.anchor);r?.element&&r?.element instanceof HTMLElement&&!$(r.element)&&this.domService.isElementVisible(r.element)&&se(r.element)&&(a=r.element)}else o?.xpath&&(a=this.domService.getElementFromXPath(o.xpath),a&&$(a)&&(a=null),this.domService.isXpathWithId(o.xpath)||(!a&&o.cfXpath&&(a=this.domService.getElementFromXPath(o.cfXpath),a&&$(a)&&(a=null)),!a&&o.fXpath&&(a=this.domService.getElementFromXPath(o.fXpath),a&&$(a)&&(a=null))));if(s&&a){let r=we(s,a);if(r){let c=s,d=a,u=c.getBoundingClientRect(),I=d.getBoundingClientRect(),C=t?u.width:c.offsetWidth||u.width,z=t?u.height:c.offsetHeight||u.height,g=t?I.width:d.offsetWidth||I.width,V=t?I.height:d.offsetHeight||I.height,Ce={};C&&z&&(Ce={top:z*n.topPercentage/100,left:C*n.leftPercentage/100});let _e={};g&&V&&(_e={top:V*o.topPercentage/100,left:g*o.leftPercentage/100});let Ve=!t,N=Me(Ce.left,Ce.top,s,r,Ve),B=Me(_e.left,_e.top,a,r,Ve),Y,Z,Q,q,F={};N.x>B.x?N.y>B.y?(q={x:N.x,y:N.y},Y={x:B.x,y:B.y},F.handle1=q,F.handle2=Y):(Z={x:N.x,y:N.y},Q={x:B.x,y:B.y},F.handle1=Z,F.handle2=Q):N.y>B.y?(Q={x:N.x,y:N.y},Z={x:B.x,y:B.y},F.handle1=Q,F.handle2=Z):(Y={x:N.x,y:N.y},q={x:B.x,y:B.y},F.handle1=Y,F.handle2=q);let $t={topLeft:Y||{x:Q?.x,y:Z?.y},bottomRight:q||{x:Z?.x,y:Q?.y},topRight:Z||{x:q?.x,y:Y?.y},bottomLeft:Q||{x:Y?.x,y:q?.y}};return F.coordinates=$t,F.targetElement=this.domService.getXPath(r),F}}}}return}catch(n){this.loggingService.catch("Error in AreaService calculateAreaAnnotationPosition:",n);return}}addArea(e,t=[],n,o,s,a){this.loggingService.log("%c[WB] Calling FUNCTION: addArea","color: green;");try{let r=this.authService.getUser();if(r)if(r.isReadOnly||r.isAnonymous)this.loggingService.catch("Anonymous/Readonly users cannot add areas.");else{let c=new _t;o&&(c.annotationId=o),c.from=r,c.color=h.DEFAULT_ANNOTATION_COLOR,c.lastUpdated=this.timestamp,n&&(c.targetAnnotations=[n]),c.props=new Ct;let d=this.domService.getCurrentWindowSizeValue();if(c.props.screenWidth=d.screenWidth,c.props.screenHeight=d.screenHeight,c.props.screenScrollHeight=d.screenScrollHeight,c.props.viewportWidth=window.innerWidth,c.props.viewportHeight=window.innerHeight,e||t?.length>0){let C=e?this.getPointsForAreaPinAnnotation(e):t;c.targetElements=[],C.forEach(z=>{c.targetElements.push(this.domService.getTargetElementForCursorPosition(e,void 0,void 0,void 0,void 0,!0,{clientX:z.x,clientY:z.y}))})}this.setLocationToAreaAnnotation(c),s&&(c.locationId=s.locationId,c.location=s.location),c.pageInfo=xe(),c.pageInfo&&(c.pageInfo.screenWidth=this.domService.getCurrentWindowSizeValue()?.screenWidth);let u=this.getElementForAreaAnnotation(c),I=this.docService.getBaseMetadata("area",{element:u});if(c?.metadata||(c.metadata={}),c.metadata=p(p({},c.metadata),I),a?.access&&a?.accessFields){if(!this.userPermissionService?.hasUserContextAccess({userId:r.userId,accessFields:a.accessFields})){this.loggingService.catch("User does not have context access to add area annotation.",void 0,void 0,!0);return}c.context={access:a.access,accessFields:a.accessFields}}return this.saveAreaToDb(c),c}return}catch(r){this.loggingService.catch("Error in AreaService addArea: ",r);return}}setLocationToAreaAnnotation(e){try{let t=this.docService.getLocation();t?(e.locationId=t.locationId,e.location=t.location):(delete e.locationId,delete e.location)}catch(t){this.loggingService.catch("Error in AreaService setLocationToAreaAnnotation:",t)}}getElementForAreaAnnotation(e){try{let t,n,o;if(e.targetElements?.length){if(e.targetElements[0]?.anchor){let s=this.domService.resolveAnchorRecord(e.targetElements[0].anchor);s?.element&&this.domService.isElementVisible(s.element)&&se(s.element)&&(n=s.element)}else e.targetElements[0]?.xpath&&(n=this.domService.getElementFromXPath(e.targetElements[0].xpath));if(e.targetElements[1]?.anchor){let s=this.domService.resolveAnchorRecord(e.targetElements[1].anchor);s?.element&&this.domService.isElementVisible(s.element)&&se(s.element)&&(o=s.element)}else e.targetElements[1]?.xpath&&(o=this.domService.getElementFromXPath(e.targetElements[1].xpath))}return n&&o&&(t=we(n,o)),t}catch(t){return this.loggingService.catch("Error in AreaService getElementForAreaAnnotation: ",t),null}}saveAreaToDb(e){this.loggingService.log("%c[WB] Calling FUNCTION: saveAreaToDb","color: green;");try{this.authService.getUser()&&this.authService.isFeatureAllowed(w.AREA)&&de([this.docService.getDocumentPaths$(),this.databaseService.getDb()]).pipe(j(([t,n])=>!!t&&!!n),he(1),A(([t,n])=>{if(this.documentPaths=t,this.documentPaths?.area){e.annotationId||(e.annotationId=this.commonDbService.generateDocumentId()),e.pageInfo&&(e.pageInfo.areaUrl=this.generateAreaUrl(e));let o=JSON.parse(JSON.stringify(e));if(o.position=null,!o?.metadata?.documentId){o?.metadata||(o.metadata={});let r=this.docService.getBaseMetadata("area");o.metadata=p(p({},o?.metadata),r)}this.domService.toggleAnnotationSelection(o),this.analyticsService.trackEvent(M.Events.Area.AREA_ADDED,{annotationId:e.annotationId});let{documentId:s,organizationId:a}=this.getDocumentIdAndOrganizationIdFromAreaAnnotation(e);return this.commonDbService.setData({feature:"area",properties:{id:e.annotationId,documentId:s,organizationId:a},data:JSON.parse(JSON.stringify(o))})}else return P(null)})).subscribe(()=>{},t=>{this.loggingService.catch("Error in AreaService saveAreaToDb subscription: ",t)})}catch(t){this.loggingService.catch("Error in AreaService saveAreaToDb: ",t)}}getDocumentIdAndOrganizationIdFromAreaAnnotation(e){try{return{documentId:e?.metadata?.documentId,organizationId:e?.metadata?.organizationId}}catch(t){return this.loggingService.catch("Error in AreaService getDocumentIdAndOrganizationIdFromAreaAnnotation: ",t),{}}}updateArea(e,t=!1,n){try{n&&this.setLocationToAreaAnnotation(e),t&&this.updateNotificationsDatabase(e,De.UPDATED),this.updateAreaToDb(e)}catch(o){this.loggingService.catch("Error in AreaService updateArea: ",o)}}updateAreaToDb(e){this.loggingService.log("%c[WB] Calling FUNCTION: updateAreaToDb","color: green;");try{if(this.domService.updateSelectedAnnotationInMap([e]),this.authService.getUser()&&this.authService.isFeatureAllowed(w.AREA)){let t=JSON.parse(JSON.stringify(e));if(t.position=null,!t?.metadata?.documentId){t?.metadata||(t.metadata={});let s=this.docService.getBaseMetadata("area");t.metadata=p(p({},t?.metadata),s)}let{documentId:n,organizationId:o}=this.getDocumentIdAndOrganizationIdFromAreaAnnotation(e);this.commonDbService.setData({feature:"area",properties:{id:e.annotationId,documentId:n,organizationId:o},data:JSON.parse(JSON.stringify(t))})}}catch(t){this.loggingService.catch("Error in AreaService updateAreaToDb: ",t)}}deleteAreaPinAnnotations(e){try{let t=this.domService.getSelectedAnnotationsMap(),n=this.authService.getUser(),o=[];Object.keys(t??{}).forEach(s=>le(this,null,function*(){let a=t[s];a.type==="area"&&n&&a.from&&(n?.isAdmin||a.from.userId===n.userId)&&o.push(a)})),o?.length&&(this.analyticsService.trackEvent(M.Events.Area.AREA_DELETE_TRIGGERED,{triggerType:e,annotationId:o.map(s=>s.annotationId).join()}),this.dialog.open(Nt,{panelClass:"velt-mat-dialog-container",data:{title:"Delete area?",message:"This selected area will be deleted.",yesButton:"Delete",noButton:"Cancel",variant:"area"}}).afterClosed().pipe(he(1)).subscribe(s=>{s&&(o.forEach(a=>le(this,null,function*(){yield this.deleteAreaPinAnnotation(a)})),setTimeout(()=>{document.querySelectorAll(`[${h.SNIPPYLY_HIGHLIGHT}]`).forEach(r=>{this.domService.removeHighlightFromElement(r)})},100))})),this.domService.resetSelectedAnnotationsMap(!0,"area")}catch(t){this.loggingService.catch("Error in AreaService deleteAreaPinAnnotations: ",t)}}getAreaAnnotationsByOrganizationIdAndDocumentId({organizationId:e,documentId:t}){try{let n={};return Object.values(this.areaAnnotationById$.value??{}).forEach(o=>{o?.metadata?.documentId==t&&o?.metadata?.organizationId==e&&(n[o?.annotationId]=o)}),Object.values(n??{})}catch(n){return this.loggingService.catch("Error in AreaService getAreaAnnotationsByOrganizationIdAndDocumentId:",n),[]}}onDeleteTargetAnnotation(e,t){try{if(this.docService.getDocumentId()&&this.areaAnnotationById$.value){let o=Object.values(this.areaAnnotationById$.value||{}),s;t?s=o.find(a=>a?.annotationId===t):s=o.find(a=>a?.targetAnnotations?.find(r=>r?.annotationId===e)),s&&(s.targetAnnotations=s.targetAnnotations?.filter(a=>a?.annotationId!==e),s.targetAnnotations?.length?this.updateAreaToDb(s):this.deleteAreaPinAnnotation(s))}}catch(n){this.loggingService.catch("Error in AreaService onDeleteTargetAnnotation: ",n)}}deleteAreaPinAnnotation(e){if(this.authService.isFeatureAllowed(w.AREA)&&this.documentPaths?.area&&e?.annotationId){this.updateNotificationsDatabase(e,De.DELETED),this.analyticsService.trackEvent(M.Events.Area.AREA_DELETED,{annotationId:e.annotationId});let{documentId:t,organizationId:n}=this.getDocumentIdAndOrganizationIdFromAreaAnnotation(e);return this.commonDbService.deleteData({feature:"area",properties:{id:e.annotationId,documentId:t,organizationId:n}})}else return Promise.resolve()}enableArea(){try{this.areaEnabled$.next(!0)}catch(e){this.loggingService.catch("Error in AreaService enableArea: ",e)}}disableArea(){try{this.areaEnabled$.next(!1)}catch(e){this.loggingService.catch("Error in AreaService disableArea: ",e)}}getAreaEnabled$(){try{return this.areaEnabled$.asObservable()}catch(e){return this.loggingService.catch("Error in AreaService getAreaEnabled$: ",e),P(!1)}}getAreaEnabled(){try{return this.areaEnabled$.value}catch(e){return this.loggingService.catch("Error in AreaService getAreaEnabled: ",e),!1}}enableAddAreaMode(){this.authService.isFeatureAllowed(w.AREA)?(this.analyticsService.trackEvent(M.Events.Area.AREA_ADD_MODE_ENABLED),this.addAreaMode$.next(!0)):this.loggingService.catch("Error in AreaService enableAddAreaMode: ","Area feature is not enabled.")}disableAddAreaMode(){this.analyticsService.trackEvent(M.Events.Area.AREA_ADD_MODE_DISABLED),this.addAreaMode$.next(!1)}addAreaModeChange(){return this.addAreaMode$.asObservable()}getPointsForAreaPinAnnotation(e){let t=[],n=e,o=n?.touches?.length?n.touches[0]?.clientX:n.clientX,s=n?.touches?.length?n.touches[0]?.clientY:n.clientY;return t.push({x:o,y:s}),t.push({x:o+100,y:s+100}),t}get timestamp(){return this.commonDbService.getServerTimestamp()}isElementInsideAllowedElements(e){try{return this.domService.isElementInsideListedElementIds(e,this.allowedElementIds$.value)}catch(t){return this.loggingService.catch("Error in AreaService isElementInsideAllowedElements: ",t),!1}}updateNotificationsDatabase(e,t){try{let n={annotationData:e,actionType:t,notificationSource:"area"};this.notificationService?.updateNotificationDatabase(n)}catch(n){this.loggingService.catch("Error in AreaService updateNotificationsDatabase: ",n)}}getAreaUrl(e){try{return e?.pageInfo?.areaUrl?e.pageInfo.areaUrl:(e?.pageInfo||(e.pageInfo=xe(),e.pageInfo&&(e.pageInfo.screenWidth=this.domService.getCurrentWindowSizeValue()?.screenWidth)),e.pageInfo.areaUrl=this.generateAreaUrl(e),this.updateArea(e),e.pageInfo?.areaUrl)}catch(t){this.loggingService.catch("Error in AreaService getAreaUrl: ",t);return}}generateAreaUrl(e){let t;try{t=new URL(e?.pageInfo?.url||window.location.href)}catch(n){this.loggingService.catch("Error in AreaService generateAreaUrl: ",n),t=new URL(window.location.href)}return t.searchParams.delete(h.URL_PARAMS.TAG_ID),t.searchParams.append(h.URL_PARAMS.TAG_ID,e.annotationId),t.href}generateAreaAnnotationId(){return le(this,null,function*(){try{if(this.docService.getDocumentPaths()?.area){let t=this.commonDbService.generateDocumentId();return yield Tt(10),t||""}else return""}catch(e){return this.loggingService.catch("Error in AreaService generateAreaAnnotationId: ",e),""}})}};l.\u0275fac=function(t){return new(t||l)(_(G),_(wt),_(ue),_(Mt),_(Lt),_(J),_(K),_(St),_(fe),_(Pt),_(T),_(kt),_(X))},l.\u0275prov=ge({token:l,factory:l.\u0275fac,providedIn:"root"});let m=l;return m})();var Ht=()=>({bottom:"calc(100% - 8px)",color:"green"});function Gt(m,l){if(m&1){let i=oe();O(0,"div",8),R("click",function(){b(i);let t=v(3);return y(t.togglePinSelection())}),O(1,"velt-comment-pin-embed",9),R("saveComment",function(t){b(i);let n=v(3);return y(n.saveComment(n.veltEmit(t)))}),L()()}if(m&2){let i=v(2).ngIf,e=v();x("id","comment-pin-container-"+(i.commentPinAnnotation==null?null:i.commentPinAnnotation.annotationId)),D(),U("left",8,"px"),x("ngStyle",Te(9,Ht))("annotationDragging",i.isResizing)("annotation",i.commentPinAnnotation)("commentPinSelected",i.selectedAnnotationsMap[i.commentPinAnnotation==null?null:i.commentPinAnnotation.annotationId]&&e.objectKeys(i.selectedAnnotationsMap).length===1)("multipleCommentPinSelected",i.selectedAnnotationsMap[i.commentPinAnnotation==null?null:i.commentPinAnnotation.annotationId]&&e.objectKeys(i.selectedAnnotationsMap).length>1)("user",e.user)}}function Kt(m,l){if(m&1){let i=oe();O(0,"div",8),R("click",function(){b(i);let t=v(3);return y(t.togglePinSelection())}),O(1,"velt-comment-pin-embed",9),R("saveComment",function(t){b(i);let n=v(3);return y(n.saveComment(n.veltEmit(t)))}),L()()}if(m&2){let i=v(2).ngIf,e=v();x("id","comment-pin-container-"+(i.multiThreadCommentAnnotation==null?null:i.multiThreadCommentAnnotation.annotationId)),D(),U("left",8,"px"),x("ngStyle",Te(9,Ht))("annotationDragging",i.isResizing)("annotation",i.multiThreadCommentAnnotation)("commentPinSelected",!!i.selectedAnnotationsMap[i.multiThreadCommentAnnotation==null?null:i.multiThreadCommentAnnotation.annotationId])("multipleCommentPinSelected",i.selectedAnnotationsMap[i.multiThreadCommentAnnotation==null?null:i.multiThreadCommentAnnotation.annotationId]&&e.objectKeys(i.selectedAnnotationsMap).length>1)("user",e.user)}}function Jt(m,l){if(m&1){let i=oe();be(0),O(1,"div",1),R("click",function(){b(i);let t=v(2);return y(t.togglePinSelection())}),L(),O(2,"div",2),R("click",function(){b(i);let t=v(2);return y(t.togglePinSelection())}),L(),O(3,"div",3),R("click",function(){b(i);let t=v(2);return y(t.togglePinSelection())}),L(),O(4,"div",4),R("click",function(){b(i);let t=v(2);return y(t.togglePinSelection())}),L(),O(5,"div",5),R("cdkDragStarted",function(){b(i);let t=v(2);return y(t.onResizeHandleDragStart("topLeft"))})("cdkDragMoved",function(t){b(i);let n=v(2);return y(n.onResizeHandleDragMove(t,"topLeft"))})("cdkDragEnded",function(){b(i);let t=v(2);return y(t.onResizeHandleDragEnd("topLeft"))})("click",function(){b(i);let t=v(2);return y(t.togglePinSelection())}),L(),O(6,"div",6),R("cdkDragStarted",function(){b(i);let t=v(2);return y(t.onResizeHandleDragStart("bottomRight"))})("cdkDragMoved",function(t){b(i);let n=v(2);return y(n.onResizeHandleDragMove(t,"bottomRight"))})("cdkDragEnded",function(){b(i);let t=v(2);return y(t.onResizeHandleDragEnd("bottomRight"))})("click",function(){b(i);let t=v(2);return y(t.togglePinSelection())}),W(7,Gt,2,10,"div",7)(8,Kt,2,10,"div",7),L(),ye()}if(m&2){let i=v().ngIf,e=v();D(),U("border-color",i.areaAnnotationColor)("width",e.LINE_THICKNESS,"px")("height",(i.areaProperties==null||i.areaProperties.coordinates==null||i.areaProperties.coordinates.bottomLeft==null?null:i.areaProperties.coordinates.bottomLeft.y)-(i.areaProperties==null||i.areaProperties.coordinates==null||i.areaProperties.coordinates.topLeft==null?null:i.areaProperties.coordinates.topLeft.y),"px")("left",(i.areaProperties==null||i.areaProperties.coordinates==null||i.areaProperties.coordinates.topLeft==null?null:i.areaProperties.coordinates.topLeft.x)+(i.isResizing?i.resizingOffset.left:i.offsetLeft),"px")("top",(i.areaProperties==null||i.areaProperties.coordinates==null||i.areaProperties.coordinates.topLeft==null?null:i.areaProperties.coordinates.topLeft.y)+(i.isResizing?i.resizingOffset.top:i.offsetTop),"px"),D(),U("border-color",i.areaAnnotationColor)("height",e.LINE_THICKNESS,"px")("width",(i.areaProperties==null||i.areaProperties.coordinates==null||i.areaProperties.coordinates.bottomRight==null?null:i.areaProperties.coordinates.bottomRight.x)-(i.areaProperties==null||i.areaProperties.coordinates==null||i.areaProperties.coordinates.topLeft==null?null:i.areaProperties.coordinates.topLeft.x),"px")("left",(i.areaProperties==null||i.areaProperties.coordinates==null||i.areaProperties.coordinates.topLeft==null?null:i.areaProperties.coordinates.topLeft.x)+(i.isResizing?i.resizingOffset.left:i.offsetLeft),"px")("top",(i.areaProperties==null||i.areaProperties.coordinates==null||i.areaProperties.coordinates.topLeft==null?null:i.areaProperties.coordinates.topLeft.y)+(i.isResizing?i.resizingOffset.top:i.offsetTop),"px"),D(),U("border-color",i.areaAnnotationColor)("width",e.LINE_THICKNESS,"px")("height",(i.areaProperties==null||i.areaProperties.coordinates==null||i.areaProperties.coordinates.bottomRight==null?null:i.areaProperties.coordinates.bottomRight.y)-(i.areaProperties==null||i.areaProperties.coordinates==null||i.areaProperties.coordinates.topRight==null?null:i.areaProperties.coordinates.topRight.y),"px")("left",(i.areaProperties==null||i.areaProperties.coordinates==null||i.areaProperties.coordinates.bottomRight==null?null:i.areaProperties.coordinates.bottomRight.x)+(i.isResizing?i.resizingOffset.left:i.offsetLeft),"px")("top",(i.areaProperties==null||i.areaProperties.coordinates==null||i.areaProperties.coordinates.topRight==null?null:i.areaProperties.coordinates.topRight.y)+(i.isResizing?i.resizingOffset.top:i.offsetTop),"px"),D(),U("border-color",i.areaAnnotationColor)("height",e.LINE_THICKNESS,"px")("width",(i.areaProperties==null||i.areaProperties.coordinates==null||i.areaProperties.coordinates.topRight==null?null:i.areaProperties.coordinates.topRight.x)-(i.areaProperties==null||i.areaProperties.coordinates==null||i.areaProperties.coordinates.bottomLeft==null?null:i.areaProperties.coordinates.bottomLeft.x),"px")("left",(i.areaProperties==null||i.areaProperties.coordinates==null||i.areaProperties.coordinates.bottomLeft==null?null:i.areaProperties.coordinates.bottomLeft.x)+(i.isResizing?i.resizingOffset.left:i.offsetLeft),"px")("top",(i.areaProperties==null||i.areaProperties.coordinates==null||i.areaProperties.coordinates.bottomLeft==null?null:i.areaProperties.coordinates.bottomLeft.y)+(i.isResizing?i.resizingOffset.top:i.offsetTop),"px"),D(),U("background-color",i.areaAnnotationColor)("width",e.DRAG_HANDLE_SIZE,"px")("height",e.DRAG_HANDLE_SIZE,"px")("left",(i.areaProperties==null||i.areaProperties.handle1==null?null:i.areaProperties.handle1.x)+(i.isResizing?i.resizingOffset.left:i.offsetLeft)-e.DRAG_HANDLE_SIZE/2,"px")("top",(i.areaProperties==null||i.areaProperties.handle1==null?null:i.areaProperties.handle1.y)+(i.isResizing?i.resizingOffset.top:i.offsetTop)-e.DRAG_HANDLE_SIZE/2,"px"),ee("drag-disabled",!i.pinDragEnabled||(i.areaPinAnnotation==null||i.areaPinAnnotation.from==null?null:i.areaPinAnnotation.from.userId)!==(e.user==null?null:e.user.userId)),x("cdkDragDisabled",!i.pinDragEnabled||(i.areaPinAnnotation==null||i.areaPinAnnotation.from==null?null:i.areaPinAnnotation.from.userId)!==(e.user==null?null:e.user.userId)),D(),U("background-color",i.areaAnnotationColor)("width",e.DRAG_HANDLE_SIZE,"px")("height",e.DRAG_HANDLE_SIZE,"px")("left",(i.areaProperties==null||i.areaProperties.handle2==null?null:i.areaProperties.handle2.x)+(i.isResizing?i.resizingOffset.left:i.offsetLeft)-e.DRAG_HANDLE_SIZE/2,"px")("top",(i.areaProperties==null||i.areaProperties.handle2==null?null:i.areaProperties.handle2.y)+(i.isResizing?i.resizingOffset.top:i.offsetTop)-e.DRAG_HANDLE_SIZE/2,"px"),ee("drag-disabled",!i.pinDragEnabled||(i.areaPinAnnotation==null||i.areaPinAnnotation.from==null?null:i.areaPinAnnotation.from.userId)!==(e.user==null?null:e.user.userId)),x("cdkDragDisabled",!i.pinDragEnabled||(i.areaPinAnnotation==null||i.areaPinAnnotation.from==null?null:i.areaPinAnnotation.from.userId)!==(e.user==null?null:e.user.userId)),D(),x("ngIf",i.commentPinAnnotation),D(),x("ngIf",i.multiThreadCommentAnnotation)}}function Yt(m,l){if(m&1&&(be(0),W(1,Jt,9,68,"ng-container",0),ye()),m&2){let i=l.ngIf,e=v();D(),x("ngIf",!i.hideAreaAnnotation||e.selected)}}var He=(()=>{let l=class l{get resizing(){return this.componentConfigSignal().isResizing}onMouseEnter(){this.setAreaPinHover(!0)}onMouseLeave(){this.setAreaPinHover(!1)}constructor(e,t,n,o,s,a,r){this.analyticsService=e,this.authService=t,this.serviceBook=n,this.docService=o,this.domService=s,this.areaService=a,this.loggingService=r,this.multipleAreaPinsSelected=!1,this.avatarErrorImage="",this.objectKeys=Object.keys,this.subscriptions=[],this.annotationDragging=!1,this.dragPosition=null,this.LINE_THICKNESS=0,this.DRAG_HANDLE_SIZE=10,this.skipValueUpdate=!1,this.areaPinHover=!1,this.resolvedCommentsOnDom=!1,this.componentConfigSignal=Ke({hideAreaAnnotation:!1,selected:!1,areaAnnotationColor:"#625DF5",areaProperties:void 0,resizingOffset:{top:0,left:0},offsetLeft:0,offsetTop:0,isResizing:!1,areaPinAnnotation:void 0,user:void 0,commentPinAnnotation:void 0,selectedAnnotationsMap:{},pinDragEnabled:!0}),this.selected=!1,this.veltElement=!0,this.commentService=null,this.serviceBook.observe(te).subscribe(c=>{this.commentService=c}),this.subscriptions.push(this.authService.getUser$().subscribe(c=>{this.user=c},c=>{this.catchError("Error in AreaPinPortalComponent getUser$ subscription: ",c)})),this.subscriptions.push(this.serviceBook.observe(te).pipe(A(c=>c?c.getPinDrag$():me)).subscribe(c=>{this.componentConfigSignal.update(d=>S(p({},d),{pinDragEnabled:c}))},c=>{this.catchError("Error in AreaPinPortalComponent getPinDrag$ subscription: ",c)})),this.subscriptions.push(this.domService.getSelectedAnnotationsMap$().subscribe(c=>{this.componentConfigSignal.update(d=>(d=S(p({},d),{selectedAnnotationsMap:c}),d)),this.componentConfigSignal().areaPinAnnotation?.annotationId&&this.componentConfigSignal().selectedAnnotationsMap&&(this.selected=!!this.componentConfigSignal().selectedAnnotationsMap[this.componentConfigSignal().areaPinAnnotation.annotationId],this.componentConfigSignal().commentPinAnnotation?this.selected=!!this.componentConfigSignal().selectedAnnotationsMap[this.componentConfigSignal().commentPinAnnotation?.annotationId]:this.componentConfigSignal().multiThreadCommentAnnotation&&(this.selected=!!this.componentConfigSignal().selectedAnnotationsMap[this.componentConfigSignal().multiThreadCommentAnnotation?.annotationId])),this.updateAreaActiveAttributeOnElement()},c=>{this.catchError("Error in AreaPinPortalComponent getSelectedAnnotationsMap$ subscription: ",c)}))}ngOnInit(){}ngAfterViewInit(){try{let e=this.componentConfigSignal().areaPinAnnotation.targetAnnotations?.find(n=>n?.type===w.COMMENT)?.annotationId,t=this.componentConfigSignal().areaPinAnnotation.targetAnnotations?.find(n=>n?.type===w.MULTI_THREAD)?.annotationId;e?(this.componentConfigSignal.update(n=>(n=S(p({},n),{hideAreaAnnotation:!0}),n)),this.subscriptions.push(this.serviceBook.observe(te).pipe(A(n=>n?n.getCommentAnnotationByAnnotationId(e):me),A(n=>(this.commentService?.getResolvedCommentsOnDom$()??P(!0)).pipe(f(o=>(this.resolvedCommentsOnDom=o,n))))).subscribe(n=>{this.componentConfigSignal.update(o=>(o=S(p({},o),{commentPinAnnotation:n}),o.commentPinAnnotation?(o.areaAnnotationColor=o.commentPinAnnotation?.status.color,!this.resolvedCommentsOnDom&&!(this.commentService?.getFilterCommentsOnDom()&&this.commentService?.getCommentsFromSidebarMap())&&o.commentPinAnnotation?.status.type==="terminal"?o.hideAreaAnnotation=!0:o.hideAreaAnnotation=!1):o.hideAreaAnnotation=!0,o))}))):t?(this.componentConfigSignal.update(n=>(n=S(p({},n),{hideAreaAnnotation:!0}),n)),this.subscriptions.push(this.serviceBook.observe(te).pipe(A(n=>n?n.getMultiThreadCommentAnnotationByAnnotationId(t):me),A(n=>(this.commentService?.getResolvedCommentsOnDom$()??P(!0)).pipe(f(o=>(this.resolvedCommentsOnDom=o,n))))).subscribe(n=>{this.componentConfigSignal.update(o=>(o=S(p({},o),{multiThreadCommentAnnotation:n}),o.hideAreaAnnotation=!1,o))}))):this.componentConfigSignal.update(n=>(n=S(p({},n),{areaAnnotationColor:this.componentConfigSignal().areaPinAnnotation?.from?.color||"#625DF5"}),n)),this.componentConfigSignal().areaPinAnnotation?.targetElements?.length&&this.componentConfigSignal().areaPinAnnotation?.targetElements?.forEach(n=>{if(n?.xpath){let o=this.domService.getElementFromXPath(n?.xpath);!o&&n?.cfXpath&&(o=this.domService.getElementFromXPath(n?.cfXpath)),!o&&n?.fXpath&&(o=this.domService.getElementFromXPath(n?.fXpath)),o&&this.detectPositionChange(o)}})}catch(e){this.catchError("Error in AreaPinPortalComponent ngAfterViewInit: ",e)}}setAreaPinAnnotation(e){try{this.componentConfigSignal.update(t=>(!this.skipValueUpdate&&!t.isResizing&&(t=S(p({},t),{areaPinAnnotation:e}),this.id=e.annotationId,t.isResizing||(t.areaProperties=e.areaProperties)),t))}catch(t){this.catchError("Error in AreaPinPortalComponent setAreaPinAnnotation: ",t)}}setOffsetLeft(e){try{this.componentConfigSignal.update(t=>(t=S(p({},t),{offsetLeft:e}),t))}catch(t){this.catchError("Error in AreaPinPortalComponent setOffsetLeft: ",t)}}setOffsetTop(e){try{this.componentConfigSignal.update(t=>(t=S(p({},t),{offsetTop:e}),t))}catch(t){this.catchError("Error in AreaPinPortalComponent setOffsetTop: ",t)}}togglePinSelection(){try{let e=!0;this.componentConfigSignal().commentPinAnnotation&&(e=!(this.domService.getDraftCommentAnnotationDialogs()||[])?.length,this.domService.resetSelectedAnnotationsMap(!0,"comments")),e&&(this.domService.toggleAnnotationSelection(this.componentConfigSignal().areaPinAnnotation),this.componentConfigSignal().commentPinAnnotation?this.domService.toggleAnnotationSelection(this.componentConfigSignal().commentPinAnnotation):this.componentConfigSignal().multiThreadCommentAnnotation&&this.domService.toggleAnnotationSelection(this.componentConfigSignal().multiThreadCommentAnnotation))}catch(e){this.catchError("Error in AreaPinPortalComponent togglePinSelection: ",e)}}saveComment(e){try{this.componentConfigSignal().commentPinAnnotation?this.commentService?.saveComment(this.componentConfigSignal().commentPinAnnotation,e):this.componentConfigSignal().multiThreadCommentAnnotation&&this.commentService?.saveComment(this.componentConfigSignal().multiThreadCommentAnnotation,e)}catch(t){this.catchError("Error in AreaPinPortalComponent saveComment: ",t)}}veltEmit(e){return typeof CustomEvent<"u"&&e instanceof CustomEvent?e.detail:e}calculateResizingOffset(e){try{if(!e)return{top:0,left:0};let t=e.getBoundingClientRect(),n=t.left+window.scrollX;return{top:t.top+window.scrollY,left:n}}catch(t){return this.catchError("Error in AreaPinPortalComponent calculateResizingOffset: ",t),{top:0,left:0}}}onResizeHandleDragStart(e){try{document.body.classList.add(h.BODY_CLASSES.VELT_PIN_DRAGGING);let t=document.getElementById(this.componentConfigSignal().areaPinAnnotation.annotationId);t&&(this.parentElement=t.parentElement,document.body.appendChild(t)),this.componentConfigSignal.update(r=>(r=S(p({},r),{isResizing:!0}),r));let n=this.domService.getElementFromXPath(this.componentConfigSignal().areaProperties?.targetElement),o=this.calculateResizingOffset(n),s=JSON.parse(JSON.stringify(this.componentConfigSignal().areaPinAnnotation)),a=this.areaService.calculateAreaAnnotationPosition(s,!0);this.componentConfigSignal.update(r=>(r=p(S(p({},r),{resizingOffset:o}),a?{areaProperties:a}:{}),r))}catch(t){this.catchError("Error in AreaPinPortalComponent onResizeHandleDragStart: ",t)}}onResizeHandleDragMove(e,t){try{let n=this.domService.getTargetElementForCursorPosition(e.event);if(this.componentConfigSignal().commentPinAnnotation){let o=this.domService.getElementFromXPath(n?.xpath);if(o&&!this.commentService?.isElementInsideAllowedElements(o))return}if(n){let o=JSON.parse(JSON.stringify(this.componentConfigSignal().areaPinAnnotation)),s=o.targetElements||[];switch(t){case"topLeft":s[0]=n;break;case"bottomRight":s[1]=n;break;default:break}o.targetElements=s;let a=this.areaService.calculateAreaAnnotationPosition(o,!0),r=this.componentConfigSignal().areaProperties?.targetElement,c=a?.targetElement,d=r!==c,u,I;if(d&&a?.targetElement){let C=this.domService.getElementFromXPath(a.targetElement),z=this.calculateResizingOffset(C);u=z.top,I=z.left}else{let C=this.componentConfigSignal().resizingOffset;u=C.top,I=C.left}this.componentConfigSignal.update(C=>(C=S(p({},C),{areaProperties:a,resizingOffset:{top:u,left:I},areaPinAnnotationOnResize:o}),C))}}catch(n){this.catchError("Error in AreaPinComponent onResizeHandleDragMove: ",n)}}onResizeHandleDragEnd(e){try{document.body.classList.remove(h.BODY_CLASSES.VELT_PIN_DRAGGING);let t=document.getElementById(this.componentConfigSignal().areaPinAnnotation.annotationId);t&&this.parentElement&&(this.parentElement.appendChild(t),t.style.opacity="0");let n=this.componentConfigSignal().areaPinAnnotationOnResize||this.componentConfigSignal().areaPinAnnotation;if(n){let a=this.areaService.calculateAreaAnnotationPosition(n,!1);a&&this.componentConfigSignal.update(r=>(r=S(p({},r),{areaProperties:a}),r))}this.componentConfigSignal.update(a=>(a=S(p({},a),{isResizing:!1}),a)),this.skipValueUpdate=!0;let o=this.domService.getElementFromXPath(this.componentConfigSignal().areaProperties?.targetElement),s=this.docService.getAdditionalDocumentIdFromElement(o)||this.docService.getDocumentPaths()?.clientDocumentId;!this.componentConfigSignal().areaPinAnnotation?.metadata?.clientDocumentId||this.componentConfigSignal().areaPinAnnotation?.metadata?.clientDocumentId==s?(this.componentConfigSignal.update(a=>(a=p({},a),a.areaPinAnnotationOnResize&&(a.areaPinAnnotation=JSON.parse(JSON.stringify(a.areaPinAnnotationOnResize))),delete a.areaPinAnnotationOnResize,a)),this.areaService.updateArea(this.componentConfigSignal().areaPinAnnotation,!1),this.analyticsService.trackEvent(M.Events.Area.AREA_DRAGGED,{annotationId:this.componentConfigSignal().areaPinAnnotation.annotationId})):this.componentConfigSignal.update(a=>(a=p({},a),a.areaProperties=a.areaPinAnnotation.areaProperties,a)),setTimeout(()=>{this.skipValueUpdate=!1,t&&(t.style.opacity="1")},50)}catch(t){this.catchError("Error in AreaPinComponent onResizeHandleDragEnd: ",t)}}detectPositionChange(e){try{let t=$e(0,Ue).pipe(f(()=>{let n=e.getBoundingClientRect();return{top:n.top,left:n.left}}),ae((n,o)=>n.top===o.top&&n.left===o.left),je());this.subscriptions.push(t.subscribe(()=>{this.componentConfigSignal.update(n=>(n=S(p({},n),{areaProperties:this.areaService.calculateAreaAnnotationPosition(n.areaPinAnnotation)}),n))},n=>{}))}catch(t){this.catchError("Error in AreaPinPortalComponent detectPositionChange: ",t)}}setAreaPinHover(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: setAreaPinHover","color: green;"),e&&this.targetElement&&!this.domService.isElementVisibleOnScreen(this.targetElement)&&(e=!1),this.areaPinHover=e,this.updateAreaActiveAttributeOnElement()}catch(t){this.catchError("Error in AreaPinPortalComponent setAreaPinHover: ",t)}}updateAreaActiveAttributeOnElement(){try{this.loggingService.log("%c[WB] Calling FUNCTION: updateAreaActiveAttributeOnElement","color: green;"),this.selected||this.areaPinHover?this.targetElement&&(this.targetElement?.hasAttribute(h.ATTRIBUTES.VELT_AREA_PIN_ACTIVE)||this.targetElement?.setAttribute(h.ATTRIBUTES.VELT_AREA_PIN_ACTIVE,"true")):this.targetElement&&this.targetElement?.hasAttribute(h.ATTRIBUTES.VELT_AREA_PIN_ACTIVE)&&this.targetElement?.removeAttribute(h.ATTRIBUTES.VELT_AREA_PIN_ACTIVE)}catch(e){this.catchError("Error in AreaPinPortalComponent updateAreaActiveAttributeOnElement: ",e)}}ngOnDestroy(){this.loggingService.log("%c[WB] Calling FUNCTION: ngOnDestroy","color: green;");try{this.unsubscribe(),this.componentConfigSignal()?.isResizing&&document.body.classList.remove(h.BODY_CLASSES.VELT_PIN_DRAGGING)}catch(e){this.catchError("Error in AreaPinPortalComponent ondestroy: ",e)}}unsubscribe(){this.loggingService.log("%c[WB] Calling FUNCTION: unsubscribe","color: green;");try{this.subscriptions.map(e=>{e.unsubscribe()}),this.subscriptions=[]}catch(e){this.catchError("Error in AreaPinPortalComponent unsubscribe: ",e)}}catchError(e,t,n){try{this.loggingService.catch(e,t,S(p({},n||{}),{annotationId:this.componentConfigSignal()?.areaPinAnnotation?.annotationId}))}catch{}}};l.\u0275fac=function(t){return new(t||l)(E(G),E(J),E(X),E(ue),E(K),E(k),E(T))},l.\u0275cmp=ne({type:l,selectors:[["snippyly-area-pin-portal"]],hostVars:6,hostBindings:function(t,n){t&1&&R("mouseenter",function(){return n.onMouseEnter()})("mouseleave",function(){return n.onMouseLeave()}),t&2&&(tt("id",n.id),ie("data-velt-element",n.veltElement),ee("selected",n.selected)("resizing",n.resizing))},inputs:{multipleAreaPinsSelected:"multipleAreaPinsSelected",avatarErrorImage:"avatarErrorImage",user:"user",targetElement:"targetElement"},standalone:!1,decls:1,vars:1,consts:[[4,"ngIf"],["id","line1",1,"line","vertical",3,"click"],["id","line2",1,"line","horizontal",3,"click"],["id","line3",1,"line","vertical",3,"click"],["id","line4",1,"line","horizontal",3,"click"],["id","handle1","cdkDrag","",1,"handle",3,"cdkDragStarted","cdkDragMoved","cdkDragEnded","click","cdkDragDisabled"],["id","handle2","cdkDrag","",1,"handle",3,"cdkDragStarted","cdkDragMoved","cdkDragEnded","click","cdkDragDisabled"],[3,"id","click",4,"ngIf"],[3,"click","id"],[3,"saveComment","ngStyle","annotationDragging","annotation","commentPinSelected","multipleCommentPinSelected","user"]],template:function(t,n){t&1&&W(0,Yt,2,1,"ng-container",0),t&2&&x("ngIf",n.componentConfigSignal())},dependencies:[pe,lt,ht],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%]{position:absolute!important;top:0!important;left:0!important;box-sizing:border-box!important;-webkit-tap-highlight-color:rgba(255,255,255,0)!important;outline:none!important;margin:0!important;padding:0!important;height:unset!important;width:unset!important;text-align:left!important;z-index:var(--velt-comment-pin-z-index)!important}*[_ngcontent-%COMP%]{box-sizing:border-box;-webkit-tap-highlight-color:rgba(255,255,255,0)!important;outline:none!important;margin:0!important;padding:0!important;height:unset;width:unset;text-align:left!important;line-height:1.5!important;color:#000!important;font-size:calc((1rem + 0px) * var(--velt-base-rem-unit));-webkit-text-fill-color:initial!important}*[_ngcontent-%COMP%]:empty{display:revert!important}.line[_ngcontent-%COMP%]{position:absolute;opacity:.4;transition:opacity .2s ease-in-out}.line.vertical[_ngcontent-%COMP%]{border-left:1px dashed;border-right:1px dashed}.line.horizontal[_ngcontent-%COMP%]{border-top:1px dashed;border-bottom:1px dashed}.handle[_ngcontent-%COMP%]{position:absolute;transform:none!important;border-radius:100%}.handle[_ngcontent-%COMP%]:not(.drag-disabled){cursor:grab}#handle1[_ngcontent-%COMP%]{opacity:.4;transition:opacity,transform .2s ease-in-out}#handle2[_ngcontent-%COMP%]{background-color:transparent!important}.resizing[_nghost-%COMP%] div[_ngcontent-%COMP%]{z-index:1}.resizing[_nghost-%COMP%] .handle[_ngcontent-%COMP%]{cursor:grabbing}[_nghost-%COMP%]:hover #handle1[_ngcontent-%COMP%], .resizing[_nghost-%COMP%] #handle1[_ngcontent-%COMP%], .selected[_nghost-%COMP%] #handle1[_ngcontent-%COMP%]{opacity:1;transform:scale(2)!important}[_nghost-%COMP%]:hover .line[_ngcontent-%COMP%], .resizing[_nghost-%COMP%] .line[_ngcontent-%COMP%], .selected[_nghost-%COMP%] .line[_ngcontent-%COMP%]{opacity:1}snippyly-comment-pin[_ngcontent-%COMP%], velt-comment-pin-embed[_ngcontent-%COMP%], snippyly-comment-pin-embed[_ngcontent-%COMP%]{position:absolute;bottom:calc(100% - 8px)}.s-metadata[_ngcontent-%COMP%]{position:fixed;bottom:10px;right:10px;background:#fff;font-size:14px;border:1px solid;padding:10px;box-shadow:1px 1px 1px 1px;border-radius:4px}.s-metadata[_ngcontent-%COMP%] table[_ngcontent-%COMP%]{border-collapse:collapse}.s-metadata[_ngcontent-%COMP%] table[_ngcontent-%COMP%] td[_ngcontent-%COMP%], .s-metadata[_ngcontent-%COMP%] table[_ngcontent-%COMP%] th[_ngcontent-%COMP%]{border:1px solid;padding:4px 8px}"],changeDetection:0});let m=l;return m})();var Vt=(()=>{let l=class l{constructor(e,t,n,o,s){this.domService=e,this.componentFactoryResolver=t,this.injector=n,this.appRef=o,this.loggingService=s,this.areasPinById={}}setAreaPin(e){try{if(!this.areasPinById[e.annotationId])this.setPinPortal(e);else{let t=this.areasPinById[e.annotationId].portalRef?.instance?.componentConfigSignal().isResizing;if(e.areaProperties?.targetElement===this.areasPinById[e.annotationId]?.annotation?.areaProperties?.targetElement||t){let n=this.areasPinById[e.annotationId].portalRef,o=this.areasPinById[e.annotationId].userTargetElement,s=this.areasPinById[e.annotationId].pinHostElement;if(document.body.contains(o)&&document.body.contains(s))n&&(n.instance.setAreaPinAnnotation(JSON.parse(JSON.stringify(e))),this.updateElementOffset(e));else{let a=this.areasPinById[e.annotationId].pinHostDomPortalOutlet;a&&(this.removeAreaPinHostAttributes(e.annotationId,this.areasPinById[e.annotationId].pinHostElement),a.detach(),delete this.areasPinById[e.annotationId],this.setPinPortal(e))}}else{let n=this.areasPinById[e.annotationId].pinHostDomPortalOutlet;n&&(this.removeAreaPinHostAttributes(e.annotationId,this.areasPinById[e.annotationId].pinHostElement),n.detach(),delete this.areasPinById[e.annotationId],this.setPinPortal(e))}}}catch(t){this.loggingService.catch("Error in AreaPinPortalService setAreaPin: ",t)}}setPinPortal(e){try{if(e?.areaProperties?.targetElement){let t=this.domService.getElementFromXPath(e?.areaProperties?.targetElement);if(t){let n=this.domService.getHostElement(t),o=new pt(He),s=new ut(n,this.appRef,this.injector),a=s.attach(o);a.instance.setAreaPinAnnotation(JSON.parse(JSON.stringify(e))),a.instance.targetElement=t,this.areasPinById[e.annotationId]={pinHostDomPortalOutlet:s,pinPortal:o,portalRef:a,annotation:JSON.parse(JSON.stringify(e)),userTargetElement:t,pinHostElement:n},this.setAreaPinHostAttributes(e.annotationId,n),this.updateElementOffset(e)}}}catch(t){this.loggingService.catch("Error in AreaPinPortalService setPinPortal: ",t)}}setAreaPinHostAttributes(e,t){try{let n=t.getAttribute(h.ATTRIBUTES.VELT_AREA_PIN_HOST);if(n){let o=n.split(",");o.includes(e)||(o.push(e),t.setAttribute(h.ATTRIBUTES.VELT_AREA_PIN_HOST,o.join(",")))}else t.setAttribute(h.ATTRIBUTES.VELT_AREA_PIN_HOST,e);this.domService.isElementOriginally