@gamention/pulse-elements 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/pulse-elements.cjs +133 -105
- package/dist/pulse-elements.js +440 -348
- package/package.json +2 -2
package/dist/pulse-elements.cjs
CHANGED
|
@@ -18,19 +18,19 @@
|
|
|
18
18
|
* @license
|
|
19
19
|
* Copyright 2021 Google LLC
|
|
20
20
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
21
|
-
*/let Ct=class extends Event{constructor(e,t){super("context-provider",{bubbles:!0,composed:!0}),this.context=e,this.contextTarget=t}},
|
|
21
|
+
*/let Ct=class extends Event{constructor(e,t){super("context-provider",{bubbles:!0,composed:!0}),this.context=e,this.contextTarget=t}},He=class extends kt{constructor(e,t,i){var s,o;super(t.context!==void 0?t.initialValue:i),this.onContextRequest=r=>{if(r.context!==this.context)return;const l=r.contextTarget??r.composedPath()[0];l!==this.host&&(r.stopPropagation(),this.addCallback(r.callback,l,r.subscribe))},this.onProviderRequest=r=>{if(r.context!==this.context||(r.contextTarget??r.composedPath()[0])===this.host)return;const l=new Set;for(const[a,{consumerHost:c}]of this.subscriptions)l.has(a)||(l.add(a),c.dispatchEvent(new ht(this.context,c,a,!0)));r.stopPropagation()},this.host=e,t.context!==void 0?this.context=t.context:this.context=t,this.attachListeners(),(o=(s=this.host).addController)==null||o.call(s,this)}attachListeners(){this.host.addEventListener("context-request",this.onContextRequest),this.host.addEventListener("context-provider",this.onProviderRequest)}hostConnected(){this.host.dispatchEvent(new Ct(this.context,this.host))}};/**
|
|
22
22
|
* @license
|
|
23
23
|
* Copyright 2017 Google LLC
|
|
24
24
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
25
|
-
*/function Et({context:n}){return(e,t)=>{const i=new WeakMap;if(typeof t=="object")return{get(){return e.get.call(this)},set(s){return i.get(this).setValue(s),e.set.call(this,s)},init(s){return i.set(this,new
|
|
25
|
+
*/function Et({context:n}){return(e,t)=>{const i=new WeakMap;if(typeof t=="object")return{get(){return e.get.call(this)},set(s){return i.get(this).setValue(s),e.set.call(this,s)},init(s){return i.set(this,new He(this,{context:n,initialValue:s})),s}};{e.constructor.addInitializer((r=>{i.set(r,new He(r,{context:n}))}));const s=Object.getOwnPropertyDescriptor(e,t);let o;if(s===void 0){const r=new WeakMap;o={get(){return r.get(this)},set(l){i.get(this).setValue(l),r.set(this,l)},configurable:!0,enumerable:!0}}else{const r=s.set;o={...s,set(l){i.get(this).setValue(l),r==null||r.call(this,l)}}}return void Object.defineProperty(e,t,o)}}}/**
|
|
26
26
|
* @license
|
|
27
27
|
* Copyright 2022 Google LLC
|
|
28
28
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
29
|
-
*/function oe({context:n,subscribe:e}){return(t,i)=>{typeof i=="object"?i.addInitializer((function(){new De(this,{context:n,callback:s=>{t.set.call(this,s)},subscribe:e})})):t.constructor.addInitializer((s=>{new De(s,{context:n,callback:o=>{s[i]=o},subscribe:e})}))}}var Pt=Object.defineProperty,_t=(n,e,t)=>e in n?Pt(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,y=(n,e,t)=>_t(n,typeof e!="symbol"?e+"":e,t);const Tt="ws://localhost:4567";let Se=class{constructor(){y(this,"handlers",new Map)}on(e,t){this.handlers.has(e)||this.handlers.set(e,new Set);const i=this.handlers.get(e);return i.add(t),()=>i.delete(t)}off(e,t){var i;(i=this.handlers.get(e))==null||i.delete(t)}emit(e,t){var i;(i=this.handlers.get(e))==null||i.forEach(s=>s(t))}removeAll(){this.handlers.clear()}},St=class extends Se{constructor(e){super(),y(this,"ws",null),y(this,"endpoint"),y(this,"reconnectAttempt",0),y(this,"reconnectTimer",null),y(this,"_state","disconnected"),this.endpoint=e??Tt}get state(){return this._state}connect(){this.ws||(this._state="connecting",this.emit("state",this._state),this.ws=new WebSocket(this.endpoint),this.ws.addEventListener("open",()=>{this._state="connected",this.reconnectAttempt=0,this.emit("state",this._state)}),this.ws.addEventListener("message",e=>{const t=JSON.parse(e.data);this.emit("message",t)}),this.ws.addEventListener("close",()=>{this.ws=null,this._state="disconnected",this.emit("state",this._state),this.scheduleReconnect()}),this.ws.addEventListener("error",()=>{var e;(e=this.ws)==null||e.close()}))}disconnect(){var e;this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.reconnectAttempt=0,(e=this.ws)==null||e.close(),this.ws=null,this._state="disconnected",this.emit("state",this._state)}send(e){var t;((t=this.ws)==null?void 0:t.readyState)===WebSocket.OPEN&&this.ws.send(JSON.stringify(e))}scheduleReconnect(){const e=Math.min(1e3*2**this.reconnectAttempt,3e4);this.reconnectAttempt++,this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.connect()},e)}},At=class extends Se{constructor(){super(...arguments),y(this,"baseUrl",""),y(this,"_user",null),y(this,"_users",new Map),y(this,"_presence",new Map),y(this,"_threads",new Map),y(this,"_reactions",new Map),y(this,"_notifications",[]),y(this,"_activityLogs",[]),y(this,"_typing",new Map),y(this,"_viewports",new Map),y(this,"_selections",new Map)}get user(){return this._user}get presence(){return[...this._presence.values()]}get threads(){return[...this._threads.values()]}get notifications(){return this._notifications}get unreadCount(){return this._notifications.filter(e=>!e.read).length}get activityLogs(){return this._activityLogs}getUser(e){return this._users.get(e)}getReactions(e){return this._reactions.get(e)??[]}getTypingUsers(e){const t=this._typing.get(e);if(!t)return[];const i=Date.now(),s=[];for(const[o,r]of t)i-r<3e3&&s.push(o);return s}get viewports(){return this._viewports}getViewport(e){return this._viewports.get(e)}get selections(){return this._selections}resolveUrl(e){return!this.baseUrl||!e||e.startsWith("http://")||e.startsWith("https://")?e:`${this.baseUrl}${e}`}resolveAttachments(e){return e.map(t=>({...t,url:this.resolveUrl(t.url),thumbnailUrl:t.thumbnailUrl?this.resolveUrl(t.thumbnailUrl):void 0}))}resolveComment(e){return!e.attachments||e.attachments.length===0?e:{...e,attachments:this.resolveAttachments(e.attachments)}}resolveThread(e){return{...e,comments:e.comments.map(t=>this.resolveComment(t))}}handleMessage(e){switch(e.type){case"auth:ok":this._user=e.user,this._users.clear();for(const t of e.users)this._users.set(t.id,t);this._presence.clear();for(const t of e.presence)this._presence.set(t.user.id,t),this._users.set(t.user.id,t.user);this._users.set(e.user.id,e.user),this._threads.clear();for(const t of e.threads)this._threads.set(t.id,this.resolveThread(t));this._notifications=e.notifications,this._reactions.clear();for(const t of e.reactions){const i=this._reactions.get(t.targetId)??[];i.push(t),this._reactions.set(t.targetId,i)}this._activityLogs=[...e.activityLogs],this.emit("auth",e.user),this.emit("presence",this.presence),this.emit("threads",this.threads),this.emit("notifications",this._notifications),this.emit("reactions",null),this.emit("activity-logs",this._activityLogs);break;case"presence:join":this._presence.set(e.user.user.id,e.user),this._users.set(e.user.user.id,e.user.user),this.emit("presence",this.presence);break;case"presence:leave":this._presence.delete(e.userId),this._viewports.delete(e.userId),this._selections.delete(e.userId);for(const t of this._typing.values())t.delete(e.userId);this.emit("presence",this.presence);break;case"presence:update":{const t=this._presence.get(e.userId);t&&(t.status=e.status,this.emit("presence",this.presence));break}case"cursor:move":this.emit("cursor",{userId:e.userId,position:e.position});break;case"click:perform":this.emit("click",{userId:e.userId,position:e.position});break;case"thread:created":this._threads.set(e.thread.id,this.resolveThread(e.thread)),this.emit("threads",this.threads);break;case"comment:created":{const t=this._threads.get(e.threadId);t&&(t.comments.push(this.resolveComment(e.comment)),t.updatedAt=e.comment.createdAt,this.emit("threads",this.threads));break}case"comment:edited":{const t=this._threads.get(e.threadId);if(t){const i=t.comments.findIndex(s=>s.id===e.comment.id);i!==-1&&(t.comments[i]=this.resolveComment(e.comment)),this.emit("threads",this.threads)}break}case"comment:deleted":{const t=this._threads.get(e.threadId);t&&(t.comments=t.comments.filter(i=>i.id!==e.commentId),t.comments.length===0&&this._threads.delete(e.threadId),this.emit("threads",this.threads));break}case"thread:resolved":{const t=this._threads.get(e.threadId);t&&(t.resolved=e.resolved,this.emit("threads",this.threads));break}case"thread:deleted":this._threads.delete(e.threadId),this.emit("threads",this.threads);break;case"reaction:added":{const t=this._reactions.get(e.reaction.targetId)??[];t.push(e.reaction),this._reactions.set(e.reaction.targetId,t),this.emit("reactions",{targetId:e.reaction.targetId,reactions:t});break}case"reaction:removed":{const t=this._reactions.get(e.targetId);if(t){const i=t.filter(s=>s.id!==e.reactionId);this._reactions.set(e.targetId,i),this.emit("reactions",{targetId:e.targetId,reactions:i})}break}case"notification":this._notifications.unshift(e.notification),this.emit("notifications",this._notifications);break;case"typing:indicator":{this._typing.has(e.threadId)||this._typing.set(e.threadId,new Map),this._typing.get(e.threadId).set(e.userId,Date.now()),this.emit("typing",{threadId:e.threadId,userId:e.userId});break}case"viewport:update":{this._viewports.set(e.userId,{scrollX:e.scrollX,scrollY:e.scrollY,viewportWidth:e.viewportWidth,viewportHeight:e.viewportHeight,pageWidth:e.pageWidth,pageHeight:e.pageHeight}),this.emit("viewport",{userId:e.userId});break}case"selection:update":this._selections.set(e.userId,e.selection),this.emit("selection",{userId:e.userId,selection:e.selection});break;case"emoji:drop":this.emit("emoji-drop",{userId:e.userId,emoji:e.emoji,position:e.position});break;case"draw:stroke":this.emit("draw-stroke",{userId:e.userId,points:e.points,color:e.color,width:e.width});break;case"draw:clear":this.emit("draw-clear",{userId:e.userId});break;case"activity:logged":this._activityLogs.unshift(e.activityLog),this._activityLogs.length>100&&(this._activityLogs=this._activityLogs.slice(0,100)),this.emit("activity-logs",this._activityLogs);break;case"error":this.emit("error",e);break}}reset(){this._user=null,this._users.clear(),this._presence.clear(),this._threads.clear(),this._reactions.clear(),this._notifications=[],this._activityLogs=[],this._typing.clear(),this._viewports.clear(),this._selections.clear()}},pt=class extends Se{constructor(e){var t;super(),y(this,"state"),y(this,"connection"),y(this,"config"),y(this,"heartbeatTimer",null),y(this,"lastCursorSend",0),y(this,"pendingCursor",null),y(this,"cursorTimer",null),this.config=e,this.state=new At,this.state.baseUrl=(e.endpoint??"").replace(/^ws(s?):/,"http$1:").replace(/\/$/,"");const i=((t=e.endpoint)==null?void 0:t.replace(/^http/,"ws"))??void 0;this.connection=new St(i),this.connection.on("message",s=>{this.state.handleMessage(s),this.emit(s.type,s)}),this.connection.on("state",s=>{this.emit("connection",s),s==="connected"?(this.authenticate(),this.startHeartbeat()):s==="disconnected"&&this.stopHeartbeat()})}get connectionState(){return this.connection.state}connect(){this.connection.connect()}disconnect(){this.stopHeartbeat(),this.connection.disconnect(),this.state.reset()}authenticate(){this.send({type:"auth",apiKey:this.config.apiKey,token:this.config.token,room:this.config.room})}send(e){this.connection.send(e)}moveCursor(e){const t=Date.now();this.pendingCursor=e,t-this.lastCursorSend>=50?this.flushCursor():this.cursorTimer||(this.cursorTimer=setTimeout(()=>{this.cursorTimer=null,this.flushCursor()},50))}flushCursor(){this.pendingCursor&&(this.send({type:"cursor:move",position:this.pendingCursor}),this.lastCursorSend=Date.now(),this.pendingCursor=null)}updatePresence(e){this.send({type:"presence:update",status:e})}startHeartbeat(){this.heartbeatTimer=setInterval(()=>{this.send({type:"presence:update",status:"online"})},3e4)}stopHeartbeat(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}createThread(e,t={}){const i=crypto.randomUUID();return this.send({type:"thread:create",id:i,body:e,mentions:t.mentions??[],position:t.position??null,attachmentIds:t.attachmentIds}),i}reply(e,t,i=[],s){const o=crypto.randomUUID();return this.send({type:"comment:create",threadId:e,id:o,body:t,mentions:i,attachmentIds:s}),o}editComment(e,t,i=[]){this.send({type:"comment:edit",commentId:e,body:t,mentions:i})}deleteComment(e){this.send({type:"comment:delete",commentId:e})}resolveThread(e,t=!0){this.send({type:"thread:resolve",threadId:e,resolved:t})}addReaction(e,t,i){this.send({type:"reaction:add",targetId:e,targetType:t,emoji:i})}removeReaction(e){this.send({type:"reaction:remove",reactionId:e})}markRead(e){this.send({type:"notification:read",notificationId:e})}markAllRead(){this.send({type:"notification:read-all"})}performClick(e){this.send({type:"click:perform",position:e})}sendTyping(e){this.send({type:"typing:start",threadId:e})}updateViewport(e){this.send({type:"viewport:update",...e})}updateSelection(e){this.send({type:"selection:update",selection:e})}dropEmoji(e,t){this.send({type:"emoji:drop",emoji:e,position:t})}drawStroke(e,t,i){this.send({type:"draw:stroke",points:e,color:t,width:i})}clearDrawing(){this.send({type:"draw:clear"})}async uploadFile(e){const t=(this.config.endpoint??window.location.origin).replace(/^ws(s?):/,"http$1:"),i=new FormData;i.append("file",e);const s=await fetch(`${t}/api/v1/upload`,{method:"POST",headers:{"X-Pulse-Key":this.config.apiKey,"X-Pulse-Token":this.config.token},body:i});if(!s.ok){const r=await s.json().catch(()=>({error:"Upload failed"}));throw new Error(r.error??"Upload failed")}const o=await s.json();return o.url&&!o.url.startsWith("http")&&(o.url=`${t}${o.url}`),o.thumbnailUrl&&!o.thumbnailUrl.startsWith("http")&&(o.thumbnailUrl=`${t}${o.thumbnailUrl}`),o}setAppearOffline(e){e?(this.stopHeartbeat(),this.send({type:"presence:update",status:"idle"})):(this.startHeartbeat(),this.send({type:"presence:update",status:"online"}))}};/**
|
|
29
|
+
*/function oe({context:n,subscribe:e}){return(t,i)=>{typeof i=="object"?i.addInitializer((function(){new De(this,{context:n,callback:s=>{t.set.call(this,s)},subscribe:e})})):t.constructor.addInitializer((s=>{new De(s,{context:n,callback:o=>{s[i]=o},subscribe:e})}))}}var Pt=Object.defineProperty,_t=(n,e,t)=>e in n?Pt(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,$=(n,e,t)=>_t(n,typeof e!="symbol"?e+"":e,t);const Tt="ws://localhost:4567";let Se=class{constructor(){$(this,"handlers",new Map)}on(e,t){this.handlers.has(e)||this.handlers.set(e,new Set);const i=this.handlers.get(e);return i.add(t),()=>i.delete(t)}off(e,t){var i;(i=this.handlers.get(e))==null||i.delete(t)}emit(e,t){var i;(i=this.handlers.get(e))==null||i.forEach(s=>s(t))}removeAll(){this.handlers.clear()}},St=class extends Se{constructor(e){super(),$(this,"ws",null),$(this,"endpoint"),$(this,"reconnectAttempt",0),$(this,"reconnectTimer",null),$(this,"_state","disconnected"),this.endpoint=e??Tt}get state(){return this._state}connect(){this.ws||(this._state="connecting",this.emit("state",this._state),this.ws=new WebSocket(this.endpoint),this.ws.addEventListener("open",()=>{this._state="connected",this.reconnectAttempt=0,this.emit("state",this._state)}),this.ws.addEventListener("message",e=>{const t=JSON.parse(e.data);this.emit("message",t)}),this.ws.addEventListener("close",()=>{this.ws=null,this._state="disconnected",this.emit("state",this._state),this.scheduleReconnect()}),this.ws.addEventListener("error",()=>{var e;(e=this.ws)==null||e.close()}))}disconnect(){var e;this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.reconnectAttempt=0,(e=this.ws)==null||e.close(),this.ws=null,this._state="disconnected",this.emit("state",this._state)}send(e){var t;((t=this.ws)==null?void 0:t.readyState)===WebSocket.OPEN&&this.ws.send(JSON.stringify(e))}scheduleReconnect(){const e=Math.min(1e3*2**this.reconnectAttempt,3e4);this.reconnectAttempt++,this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.connect()},e)}},At=class extends Se{constructor(){super(...arguments),$(this,"baseUrl",""),$(this,"_user",null),$(this,"_users",new Map),$(this,"_presence",new Map),$(this,"_threads",new Map),$(this,"_reactions",new Map),$(this,"_notifications",[]),$(this,"_activityLogs",[]),$(this,"_typing",new Map),$(this,"_viewports",new Map),$(this,"_selections",new Map)}get user(){return this._user}removeComment(e){for(const[t,i]of this._threads){const s=i.comments.findIndex(o=>o.id===e);if(s!==-1){i.comments.splice(s,1),i.comments.length===0&&this._threads.delete(t),this.emit("threads",this.threads);return}}}get presence(){return[...this._presence.values()]}get threads(){return[...this._threads.values()]}get notifications(){return this._notifications}get unreadCount(){return this._notifications.filter(e=>!e.read).length}get activityLogs(){return this._activityLogs}getUser(e){return this._users.get(e)}getReactions(e){return this._reactions.get(e)??[]}getTypingUsers(e){const t=this._typing.get(e);if(!t)return[];const i=Date.now(),s=[];for(const[o,r]of t)i-r<3e3&&s.push(o);return s}get viewports(){return this._viewports}getViewport(e){return this._viewports.get(e)}get selections(){return this._selections}resolveUrl(e){return!this.baseUrl||!e||e.startsWith("http://")||e.startsWith("https://")?e:`${this.baseUrl}${e}`}resolveAttachments(e){return e.map(t=>({...t,url:this.resolveUrl(t.url),thumbnailUrl:t.thumbnailUrl?this.resolveUrl(t.thumbnailUrl):void 0}))}resolveComment(e){return!e.attachments||e.attachments.length===0?e:{...e,attachments:this.resolveAttachments(e.attachments)}}resolveThread(e){return{...e,comments:e.comments.map(t=>this.resolveComment(t))}}handleMessage(e){switch(e.type){case"auth:ok":this._user=e.user,this._users.clear();for(const t of e.users)this._users.set(t.id,t);this._presence.clear();for(const t of e.presence)this._presence.set(t.user.id,t),this._users.set(t.user.id,t.user);this._users.set(e.user.id,e.user),this._threads.clear();for(const t of e.threads)this._threads.set(t.id,this.resolveThread(t));this._notifications=e.notifications,this._reactions.clear();for(const t of e.reactions){const i=this._reactions.get(t.targetId)??[];i.push(t),this._reactions.set(t.targetId,i)}this._activityLogs=[...e.activityLogs],this.emit("auth",e.user),this.emit("presence",this.presence),this.emit("threads",this.threads),this.emit("notifications",this._notifications),this.emit("reactions",null),this.emit("activity-logs",this._activityLogs);break;case"presence:join":this._presence.set(e.user.user.id,e.user),this._users.set(e.user.user.id,e.user.user),this.emit("presence",this.presence);break;case"presence:leave":this._presence.delete(e.userId),this._viewports.delete(e.userId),this._selections.delete(e.userId);for(const t of this._typing.values())t.delete(e.userId);this.emit("presence",this.presence);break;case"presence:update":{const t=this._presence.get(e.userId);t&&(t.status=e.status,this.emit("presence",this.presence));break}case"cursor:move":this.emit("cursor",{userId:e.userId,position:e.position});break;case"click:perform":this.emit("click",{userId:e.userId,position:e.position});break;case"thread:created":this._threads.set(e.thread.id,this.resolveThread(e.thread)),this.emit("threads",this.threads);break;case"comment:created":{const t=this._threads.get(e.threadId);t&&(t.comments.push(this.resolveComment(e.comment)),t.updatedAt=e.comment.createdAt,this.emit("threads",this.threads));break}case"comment:edited":{const t=this._threads.get(e.threadId);if(t){const i=t.comments.findIndex(s=>s.id===e.comment.id);i!==-1&&(t.comments[i]=this.resolveComment(e.comment)),this.emit("threads",this.threads)}break}case"comment:deleted":{const t=this._threads.get(e.threadId);t&&(t.comments=t.comments.filter(i=>i.id!==e.commentId),t.comments.length===0&&this._threads.delete(e.threadId),this.emit("threads",this.threads));break}case"thread:resolved":{const t=this._threads.get(e.threadId);t&&(t.resolved=e.resolved,this.emit("threads",this.threads));break}case"thread:deleted":this._threads.delete(e.threadId),this.emit("threads",this.threads);break;case"reaction:added":{const t=this._reactions.get(e.reaction.targetId)??[];t.push(e.reaction),this._reactions.set(e.reaction.targetId,t),this.emit("reactions",{targetId:e.reaction.targetId,reactions:t});break}case"reaction:removed":{const t=this._reactions.get(e.targetId);if(t){const i=t.filter(s=>s.id!==e.reactionId);this._reactions.set(e.targetId,i),this.emit("reactions",{targetId:e.targetId,reactions:i})}break}case"notification":this._notifications.unshift(e.notification),this.emit("notifications",this._notifications);break;case"typing:indicator":{this._typing.has(e.threadId)||this._typing.set(e.threadId,new Map),this._typing.get(e.threadId).set(e.userId,Date.now()),this.emit("typing",{threadId:e.threadId,userId:e.userId});break}case"viewport:update":{this._viewports.set(e.userId,{scrollX:e.scrollX,scrollY:e.scrollY,viewportWidth:e.viewportWidth,viewportHeight:e.viewportHeight,pageWidth:e.pageWidth,pageHeight:e.pageHeight}),this.emit("viewport",{userId:e.userId});break}case"selection:update":this._selections.set(e.userId,e.selection),this.emit("selection",{userId:e.userId,selection:e.selection});break;case"emoji:drop":this.emit("emoji-drop",{userId:e.userId,emoji:e.emoji,position:e.position});break;case"draw:stroke":this.emit("draw-stroke",{userId:e.userId,points:e.points,color:e.color,width:e.width});break;case"draw:clear":this.emit("draw-clear",{userId:e.userId});break;case"activity:logged":this._activityLogs.unshift(e.activityLog),this._activityLogs.length>100&&(this._activityLogs=this._activityLogs.slice(0,100)),this.emit("activity-logs",this._activityLogs);break;case"error":this.emit("error",e);break}}reset(){this._user=null,this._users.clear(),this._presence.clear(),this._threads.clear(),this._reactions.clear(),this._notifications=[],this._activityLogs=[],this._typing.clear(),this._viewports.clear(),this._selections.clear()}},pt=class extends Se{constructor(e){var t;super(),$(this,"state"),$(this,"connection"),$(this,"config"),$(this,"heartbeatTimer",null),$(this,"lastCursorSend",0),$(this,"pendingCursor",null),$(this,"cursorTimer",null),this.config=e,this.state=new At,this.state.baseUrl=(e.endpoint??"").replace(/^ws(s?):/,"http$1:").replace(/\/$/,"");const i=((t=e.endpoint)==null?void 0:t.replace(/^http/,"ws"))??void 0;this.connection=new St(i),this.connection.on("message",s=>{this.state.handleMessage(s),this.emit(s.type,s)}),this.connection.on("state",s=>{this.emit("connection",s),s==="connected"?(this.authenticate(),this.startHeartbeat()):s==="disconnected"&&this.stopHeartbeat()})}get connectionState(){return this.connection.state}connect(){this.connection.connect()}disconnect(){this.stopHeartbeat(),this.connection.disconnect(),this.state.reset()}authenticate(){this.send({type:"auth",apiKey:this.config.apiKey,token:this.config.token,room:this.config.room})}send(e){this.connection.send(e)}moveCursor(e){const t=Date.now();this.pendingCursor=e,t-this.lastCursorSend>=50?this.flushCursor():this.cursorTimer||(this.cursorTimer=setTimeout(()=>{this.cursorTimer=null,this.flushCursor()},50))}flushCursor(){this.pendingCursor&&(this.send({type:"cursor:move",position:this.pendingCursor}),this.lastCursorSend=Date.now(),this.pendingCursor=null)}updatePresence(e){this.send({type:"presence:update",status:e})}startHeartbeat(){this.heartbeatTimer=setInterval(()=>{this.send({type:"presence:update",status:"online"})},3e4)}stopHeartbeat(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}createThread(e,t={}){const i=crypto.randomUUID();return this.send({type:"thread:create",id:i,body:e,mentions:t.mentions??[],position:t.position??null,attachmentIds:t.attachmentIds}),i}reply(e,t,i=[],s){const o=crypto.randomUUID();return this.send({type:"comment:create",threadId:e,id:o,body:t,mentions:i,attachmentIds:s}),o}editComment(e,t,i=[]){this.send({type:"comment:edit",commentId:e,body:t,mentions:i})}deleteComment(e){this.state.removeComment(e),this.send({type:"comment:delete",commentId:e})}resolveThread(e,t=!0){this.send({type:"thread:resolve",threadId:e,resolved:t})}addReaction(e,t,i){this.send({type:"reaction:add",targetId:e,targetType:t,emoji:i})}removeReaction(e){this.send({type:"reaction:remove",reactionId:e})}markRead(e){this.send({type:"notification:read",notificationId:e})}markAllRead(){this.send({type:"notification:read-all"})}performClick(e){this.send({type:"click:perform",position:e})}sendTyping(e){this.send({type:"typing:start",threadId:e})}updateViewport(e){this.send({type:"viewport:update",...e})}updateSelection(e){this.send({type:"selection:update",selection:e})}dropEmoji(e,t){this.send({type:"emoji:drop",emoji:e,position:t})}drawStroke(e,t,i){this.send({type:"draw:stroke",points:e,color:t,width:i})}clearDrawing(){this.send({type:"draw:clear"})}async uploadFile(e){const t=(this.config.endpoint??window.location.origin).replace(/^ws(s?):/,"http$1:"),i=new FormData;i.append("file",e);const s=await fetch(`${t}/api/v1/upload`,{method:"POST",headers:{"X-Pulse-Key":this.config.apiKey,"X-Pulse-Token":this.config.token},body:i});if(!s.ok){const r=await s.json().catch(()=>({error:"Upload failed"}));throw new Error(r.error??"Upload failed")}const o=await s.json();return o.url&&!o.url.startsWith("http")&&(o.url=`${t}${o.url}`),o.thumbnailUrl&&!o.thumbnailUrl.startsWith("http")&&(o.thumbnailUrl=`${t}${o.thumbnailUrl}`),o}setAppearOffline(e){e?(this.stopHeartbeat(),this.send({type:"presence:update",status:"idle"})):(this.startHeartbeat(),this.send({type:"presence:update",status:"online"}))}};/**
|
|
30
30
|
* @license
|
|
31
31
|
* Copyright 2019 Google LLC
|
|
32
32
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
33
|
-
*/const he=globalThis,Ae=he.ShadowRoot&&(he.ShadyCSS===void 0||he.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,Ie=Symbol(),
|
|
33
|
+
*/const he=globalThis,Ae=he.ShadowRoot&&(he.ShadyCSS===void 0||he.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,Ie=Symbol(),Ne=new WeakMap;let ut=class{constructor(e,t,i){if(this._$cssResult$=!0,i!==Ie)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this.t=t}get styleSheet(){let e=this.o;const t=this.t;if(Ae&&e===void 0){const i=t!==void 0&&t.length===1;i&&(e=Ne.get(t)),e===void 0&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),i&&Ne.set(t,e))}return e}toString(){return this.cssText}};const It=n=>new ut(typeof n=="string"?n:n+"",void 0,Ie),A=(n,...e)=>{const t=n.length===1?n[0]:e.reduce((i,s,o)=>i+(r=>{if(r._$cssResult$===!0)return r.cssText;if(typeof r=="number")return r;throw Error("Value passed to 'css' function must be a 'css' function result: "+r+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(s)+n[o+1],n[0]);return new ut(t,n,Ie)},Mt=(n,e)=>{if(Ae)n.adoptedStyleSheets=e.map(t=>t instanceof CSSStyleSheet?t:t.styleSheet);else for(const t of e){const i=document.createElement("style"),s=he.litNonce;s!==void 0&&i.setAttribute("nonce",s),i.textContent=t.cssText,n.appendChild(i)}},Be=Ae?n=>n:n=>n instanceof CSSStyleSheet?(e=>{let t="";for(const i of e.cssRules)t+=i.cssText;return It(t)})(n):n;/**
|
|
34
34
|
* @license
|
|
35
35
|
* Copyright 2017 Google LLC
|
|
36
36
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
* @license
|
|
39
39
|
* Copyright 2017 Google LLC
|
|
40
40
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
41
|
-
*/const J=globalThis,Ve=n=>n,me=J.trustedTypes,qe=me?me.createPolicy("lit-html",{createHTML:n=>n}):void 0,ft="$lit$",j=`lit$${Math.random().toFixed(9).slice(2)}$`,mt="?"+j,
|
|
41
|
+
*/const J=globalThis,Ve=n=>n,me=J.trustedTypes,qe=me?me.createPolicy("lit-html",{createHTML:n=>n}):void 0,ft="$lit$",j=`lit$${Math.random().toFixed(9).slice(2)}$`,mt="?"+j,Ht=`<${mt}>`,N=document,ee=()=>N.createComment(""),te=n=>n===null||typeof n!="object"&&typeof n!="function",Oe=Array.isArray,Nt=n=>Oe(n)||typeof(n==null?void 0:n[Symbol.iterator])=="function",we=`[
|
|
42
42
|
\f\r]`,G=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,Xe=/-->/g,Ye=/>/g,U=RegExp(`>|${we}(?:([^\\s"'>=/]+)(${we}*=${we}*(?:[^
|
|
43
|
-
\f\r"'\`<>=]|("|')|))|$)`,"g"),Ke=/'/g,Ge=/"/g,gt=/^(?:script|style|textarea|title)$/i,bt=n=>(e,...t)=>({_$litType$:n,strings:e,values:t}),h=bt(1),Bt=bt(2),B=Symbol.for("lit-noChange"),
|
|
43
|
+
\f\r"'\`<>=]|("|')|))|$)`,"g"),Ke=/'/g,Ge=/"/g,gt=/^(?:script|style|textarea|title)$/i,bt=n=>(e,...t)=>({_$litType$:n,strings:e,values:t}),h=bt(1),Bt=bt(2),B=Symbol.for("lit-noChange"),m=Symbol.for("lit-nothing"),Ze=new WeakMap,D=N.createTreeWalker(N,129);function vt(n,e){if(!Oe(n)||!n.hasOwnProperty("raw"))throw Error("invalid template strings array");return qe!==void 0?qe.createHTML(e):e}const Ft=(n,e)=>{const t=n.length-1,i=[];let s,o=e===2?"<svg>":e===3?"<math>":"",r=G;for(let l=0;l<t;l++){const a=n[l];let c,p,d=-1,f=0;for(;f<a.length&&(r.lastIndex=f,p=r.exec(a),p!==null);)f=r.lastIndex,r===G?p[1]==="!--"?r=Xe:p[1]!==void 0?r=Ye:p[2]!==void 0?(gt.test(p[2])&&(s=RegExp("</"+p[2],"g")),r=U):p[3]!==void 0&&(r=U):r===U?p[0]===">"?(r=s??G,d=-1):p[1]===void 0?d=-2:(d=r.lastIndex-p[2].length,c=p[1],r=p[3]===void 0?U:p[3]==='"'?Ge:Ke):r===Ge||r===Ke?r=U:r===Xe||r===Ye?r=G:(r=U,s=void 0);const u=r===U&&n[l+1].startsWith("/>")?" ":"";o+=r===G?a+Ht:d>=0?(i.push(c),a.slice(0,d)+ft+a.slice(d)+j+u):a+j+(d===-2?l:u)}return[vt(n,o+(n[t]||"<?>")+(e===2?"</svg>":e===3?"</math>":"")),i]};class ie{constructor({strings:e,_$litType$:t},i){let s;this.parts=[];let o=0,r=0;const l=e.length-1,a=this.parts,[c,p]=Ft(e,t);if(this.el=ie.createElement(c,i),D.currentNode=this.el.content,t===2||t===3){const d=this.el.content.firstChild;d.replaceWith(...d.childNodes)}for(;(s=D.nextNode())!==null&&a.length<l;){if(s.nodeType===1){if(s.hasAttributes())for(const d of s.getAttributeNames())if(d.endsWith(ft)){const f=p[r++],u=s.getAttribute(d).split(j),g=/([.?@])?(.*)/.exec(f);a.push({type:1,index:o,name:g[2],strings:u,ctor:g[1]==="."?Vt:g[1]==="?"?qt:g[1]==="@"?Xt:be}),s.removeAttribute(d)}else d.startsWith(j)&&(a.push({type:6,index:o}),s.removeAttribute(d));if(gt.test(s.tagName)){const d=s.textContent.split(j),f=d.length-1;if(f>0){s.textContent=me?me.emptyScript:"";for(let u=0;u<f;u++)s.append(d[u],ee()),D.nextNode(),a.push({type:2,index:++o});s.append(d[f],ee())}}}else if(s.nodeType===8)if(s.data===mt)a.push({type:2,index:o});else{let d=-1;for(;(d=s.data.indexOf(j,d+1))!==-1;)a.push({type:7,index:o}),d+=j.length-1}o++}}static createElement(e,t){const i=N.createElement("template");return i.innerHTML=e,i}}function V(n,e,t=n,i){var r,l;if(e===B)return e;let s=i!==void 0?(r=t._$Co)==null?void 0:r[i]:t._$Cl;const o=te(e)?void 0:e._$litDirective$;return(s==null?void 0:s.constructor)!==o&&((l=s==null?void 0:s._$AO)==null||l.call(s,!1),o===void 0?s=void 0:(s=new o(n),s._$AT(n,t,i)),i!==void 0?(t._$Co??(t._$Co=[]))[i]=s:t._$Cl=s),s!==void 0&&(e=V(n,s._$AS(n,e.values),s,i)),e}class Wt{constructor(e,t){this._$AV=[],this._$AN=void 0,this._$AD=e,this._$AM=t}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(e){const{el:{content:t},parts:i}=this._$AD,s=((e==null?void 0:e.creationScope)??N).importNode(t,!0);D.currentNode=s;let o=D.nextNode(),r=0,l=0,a=i[0];for(;a!==void 0;){if(r===a.index){let c;a.type===2?c=new re(o,o.nextSibling,this,e):a.type===1?c=new a.ctor(o,a.name,a.strings,this,e):a.type===6&&(c=new Yt(o,this,e)),this._$AV.push(c),a=i[++l]}r!==(a==null?void 0:a.index)&&(o=D.nextNode(),r++)}return D.currentNode=N,s}p(e){let t=0;for(const i of this._$AV)i!==void 0&&(i.strings!==void 0?(i._$AI(e,i,t),t+=i.strings.length-2):i._$AI(e[t])),t++}}class re{get _$AU(){var e;return((e=this._$AM)==null?void 0:e._$AU)??this._$Cv}constructor(e,t,i,s){this.type=2,this._$AH=m,this._$AN=void 0,this._$AA=e,this._$AB=t,this._$AM=i,this.options=s,this._$Cv=(s==null?void 0:s.isConnected)??!0}get parentNode(){let e=this._$AA.parentNode;const t=this._$AM;return t!==void 0&&(e==null?void 0:e.nodeType)===11&&(e=t.parentNode),e}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(e,t=this){e=V(this,e,t),te(e)?e===m||e==null||e===""?(this._$AH!==m&&this._$AR(),this._$AH=m):e!==this._$AH&&e!==B&&this._(e):e._$litType$!==void 0?this.$(e):e.nodeType!==void 0?this.T(e):Nt(e)?this.k(e):this._(e)}O(e){return this._$AA.parentNode.insertBefore(e,this._$AB)}T(e){this._$AH!==e&&(this._$AR(),this._$AH=this.O(e))}_(e){this._$AH!==m&&te(this._$AH)?this._$AA.nextSibling.data=e:this.T(N.createTextNode(e)),this._$AH=e}$(e){var o;const{values:t,_$litType$:i}=e,s=typeof i=="number"?this._$AC(e):(i.el===void 0&&(i.el=ie.createElement(vt(i.h,i.h[0]),this.options)),i);if(((o=this._$AH)==null?void 0:o._$AD)===s)this._$AH.p(t);else{const r=new Wt(s,this),l=r.u(this.options);r.p(t),this.T(l),this._$AH=r}}_$AC(e){let t=Ze.get(e.strings);return t===void 0&&Ze.set(e.strings,t=new ie(e)),t}k(e){Oe(this._$AH)||(this._$AH=[],this._$AR());const t=this._$AH;let i,s=0;for(const o of e)s===t.length?t.push(i=new re(this.O(ee()),this.O(ee()),this,this.options)):i=t[s],i._$AI(o),s++;s<t.length&&(this._$AR(i&&i._$AB.nextSibling,s),t.length=s)}_$AR(e=this._$AA.nextSibling,t){var i;for((i=this._$AP)==null?void 0:i.call(this,!1,!0,t);e!==this._$AB;){const s=Ve(e).nextSibling;Ve(e).remove(),e=s}}setConnected(e){var t;this._$AM===void 0&&(this._$Cv=e,(t=this._$AP)==null||t.call(this,e))}}class be{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(e,t,i,s,o){this.type=1,this._$AH=m,this._$AN=void 0,this.element=e,this.name=t,this._$AM=s,this.options=o,i.length>2||i[0]!==""||i[1]!==""?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=m}_$AI(e,t=this,i,s){const o=this.strings;let r=!1;if(o===void 0)e=V(this,e,t,0),r=!te(e)||e!==this._$AH&&e!==B,r&&(this._$AH=e);else{const l=e;let a,c;for(e=o[0],a=0;a<o.length-1;a++)c=V(this,l[i+a],t,a),c===B&&(c=this._$AH[a]),r||(r=!te(c)||c!==this._$AH[a]),c===m?e=m:e!==m&&(e+=(c??"")+o[a+1]),this._$AH[a]=c}r&&!s&&this.j(e)}j(e){e===m?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,e??"")}}class Vt extends be{constructor(){super(...arguments),this.type=3}j(e){this.element[this.name]=e===m?void 0:e}}class qt extends be{constructor(){super(...arguments),this.type=4}j(e){this.element.toggleAttribute(this.name,!!e&&e!==m)}}class Xt extends be{constructor(e,t,i,s,o){super(e,t,i,s,o),this.type=5}_$AI(e,t=this){if((e=V(this,e,t,0)??m)===B)return;const i=this._$AH,s=e===m&&i!==m||e.capture!==i.capture||e.once!==i.once||e.passive!==i.passive,o=e!==m&&(i===m||s);s&&this.element.removeEventListener(this.name,this,i),o&&this.element.addEventListener(this.name,this,e),this._$AH=e}handleEvent(e){var t;typeof this._$AH=="function"?this._$AH.call(((t=this.options)==null?void 0:t.host)??this.element,e):this._$AH.handleEvent(e)}}class Yt{constructor(e,t,i){this.element=e,this.type=6,this._$AN=void 0,this._$AM=t,this.options=i}get _$AU(){return this._$AM._$AU}_$AI(e){V(this,e)}}const $e=J.litHtmlPolyfillSupport;$e==null||$e(ie,re),(J.litHtmlVersions??(J.litHtmlVersions=[])).push("3.3.2");const Kt=(n,e,t)=>{const i=(t==null?void 0:t.renderBefore)??e;let s=i._$litPart$;if(s===void 0){const o=(t==null?void 0:t.renderBefore)??null;i._$litPart$=s=new re(e.insertBefore(ee(),o),o,void 0,t??{})}return s._$AI(n),s};/**
|
|
44
44
|
* @license
|
|
45
45
|
* Copyright 2017 Google LLC
|
|
46
46
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
47
|
-
*/const
|
|
47
|
+
*/const H=globalThis;let _=class extends W{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){var t;const e=super.createRenderRoot();return(t=this.renderOptions).renderBefore??(t.renderBefore=e.firstChild),e}update(e){const t=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(e),this._$Do=Kt(t,this.renderRoot,this.renderOptions)}connectedCallback(){var e;super.connectedCallback(),(e=this._$Do)==null||e.setConnected(!0)}disconnectedCallback(){var e;super.disconnectedCallback(),(e=this._$Do)==null||e.setConnected(!1)}render(){return B}};var dt;_._$litElement$=!0,_.finalized=!0,(dt=H.litElementHydrateSupport)==null||dt.call(H,{LitElement:_});const ke=H.litElementPolyfillSupport;ke==null||ke({LitElement:_});(H.litElementVersions??(H.litElementVersions=[])).push("4.2.2");/**
|
|
48
48
|
* @license
|
|
49
49
|
* Copyright 2017 Google LLC
|
|
50
50
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -52,11 +52,11 @@
|
|
|
52
52
|
* @license
|
|
53
53
|
* Copyright 2017 Google LLC
|
|
54
54
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
55
|
-
*/const Gt={attribute:!0,type:String,converter:fe,reflect:!1,hasChanged:Me},Zt=(n=Gt,e,t)=>{const{kind:i,metadata:s}=t;let o=globalThis.litPropertyMetadata.get(s);if(o===void 0&&globalThis.litPropertyMetadata.set(s,o=new Map),i==="setter"&&((n=Object.create(n)).wrapped=!0),o.set(t.name,n),i==="accessor"){const{name:r}=t;return{set(l){const a=e.get.call(this);e.set.call(this,l),this.requestUpdate(r,a,n,!0,l)},init(l){return l!==void 0&&this.C(r,void 0,n,l),l}}}if(i==="setter"){const{name:r}=t;return function(l){const a=this[r];e.call(this,l),this.requestUpdate(r,a,n,!0,l)}}throw Error("Unsupported decorator location: "+i)};function
|
|
55
|
+
*/const Gt={attribute:!0,type:String,converter:fe,reflect:!1,hasChanged:Me},Zt=(n=Gt,e,t)=>{const{kind:i,metadata:s}=t;let o=globalThis.litPropertyMetadata.get(s);if(o===void 0&&globalThis.litPropertyMetadata.set(s,o=new Map),i==="setter"&&((n=Object.create(n)).wrapped=!0),o.set(t.name,n),i==="accessor"){const{name:r}=t;return{set(l){const a=e.get.call(this);e.set.call(this,l),this.requestUpdate(r,a,n,!0,l)},init(l){return l!==void 0&&this.C(r,void 0,n,l),l}}}if(i==="setter"){const{name:r}=t;return function(l){const a=this[r];e.call(this,l),this.requestUpdate(r,a,n,!0,l)}}throw Error("Unsupported decorator location: "+i)};function b(n){return(e,t)=>typeof t=="object"?Zt(n,e,t):((i,s,o)=>{const r=s.hasOwnProperty(o);return s.constructor.createProperty(o,i),r?Object.getOwnPropertyDescriptor(s,o):void 0})(n,e,t)}/**
|
|
56
56
|
* @license
|
|
57
57
|
* Copyright 2017 Google LLC
|
|
58
58
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
59
|
-
*/function
|
|
59
|
+
*/function x(n){return b({...n,state:!0,attribute:!1})}const q="pulse-client";var Jt=Object.defineProperty,Qt=Object.getOwnPropertyDescriptor,X=(n,e,t,i)=>{for(var s=i>1?void 0:i?Qt(e,t):e,o=n.length-1,r;o>=0;o--)(r=n[o])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&Jt(e,t,s),s};exports.PulseProvider=class extends _{constructor(){super(...arguments),this.apiKey="",this.token="",this.room=""}connectedCallback(){super.connectedCallback();const e={apiKey:this.apiKey,token:this.token,room:this.room,endpoint:this.endpoint};this.client=new pt(e),this.client.connect()}disconnectedCallback(){var e;super.disconnectedCallback(),(e=this.client)==null||e.disconnect()}render(){return h`<slot></slot>`}};X([b({attribute:"api-key"})],exports.PulseProvider.prototype,"apiKey",2);X([b()],exports.PulseProvider.prototype,"token",2);X([b()],exports.PulseProvider.prototype,"room",2);X([b()],exports.PulseProvider.prototype,"endpoint",2);X([Et({context:q})],exports.PulseProvider.prototype,"client",2);exports.PulseProvider=X([O("pulse-provider")],exports.PulseProvider);var ei=Object.defineProperty,ti=Object.getOwnPropertyDescriptor,ve=(n,e,t,i)=>{for(var s=i>1?void 0:i?ti(e,t):e,o=n.length-1,r;o>=0;o--)(r=n[o])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&ei(e,t,s),s};exports.PulsePresence=class extends _{constructor(){super(...arguments),this.maxVisible=5,this.users=[]}connectedCallback(){super.connectedCallback(),this.setupListener()}disconnectedCallback(){var e;super.disconnectedCallback(),(e=this.unsub)==null||e.call(this)}updated(e){var t;e.has("client")&&this.client&&((t=this.unsub)==null||t.call(this),this.setupListener())}setupListener(){this.client&&(this.users=this.client.state.presence,this.unsub=this.client.state.on("presence",e=>{this.users=e}))}getInitials(e){return e.split(" ").map(t=>t[0]).join("").toUpperCase().slice(0,2)}render(){const e=this.users.slice(0,this.maxVisible),t=this.users.length-this.maxVisible;return h`
|
|
60
60
|
<div class="avatars">
|
|
61
61
|
${t>0?h`<div class="overflow">+${t}</div>`:null}
|
|
62
62
|
${e.map(i=>h`
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
</div>
|
|
71
71
|
`)}
|
|
72
72
|
</div>
|
|
73
|
-
`}};exports.PulsePresence.styles=
|
|
73
|
+
`}};exports.PulsePresence.styles=A`
|
|
74
74
|
:host {
|
|
75
75
|
display: inline-flex;
|
|
76
76
|
align-items: center;
|
|
@@ -173,7 +173,7 @@
|
|
|
173
173
|
.avatar:hover .tooltip {
|
|
174
174
|
opacity: 1;
|
|
175
175
|
}
|
|
176
|
-
`;ve([oe({context:q,subscribe:!0}),
|
|
176
|
+
`;ve([oe({context:q,subscribe:!0}),b({attribute:!1})],exports.PulsePresence.prototype,"client",2);ve([b({type:Number,attribute:"max-visible"})],exports.PulsePresence.prototype,"maxVisible",2);ve([x()],exports.PulsePresence.prototype,"users",2);exports.PulsePresence=ve([O("pulse-presence")],exports.PulsePresence);var ii=Object.defineProperty,si=Object.getOwnPropertyDescriptor,Re=(n,e,t,i)=>{for(var s=i>1?void 0:i?si(e,t):e,o=n.length-1,r;o>=0;o--)(r=n[o])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&ii(e,t,s),s};exports.PulseCursors=class extends _{constructor(){super(...arguments),this.cursors=new Map,this.unsubs=[],this.handleLocalCursor=e=>{var t;(t=this.client)==null||t.moveCursor({x:e.clientX,y:e.clientY,pageX:e.pageX,pageY:e.pageY})}}connectedCallback(){super.connectedCallback(),this.setupListeners()}disconnectedCallback(){super.disconnectedCallback(),this.unsubs.forEach(e=>e()),this.unsubs=[],document.removeEventListener("mousemove",this.handleLocalCursor)}updated(e){e.has("client")&&this.client&&(this.unsubs.forEach(t=>t()),this.unsubs=[],this.setupListeners())}setupListeners(){this.client&&(this.unsubs.push(this.client.state.on("cursor",({userId:e,position:t})=>{const i=this.cursors.get(e);if(i)i.position=t;else{const s=this.client.state.presence.find(o=>o.user.id===e);s&&this.cursors.set(e,{userId:e,name:s.user.name,color:s.user.color,position:t})}this.requestUpdate()})),this.unsubs.push(this.client.state.on("presence",e=>{const t=new Set(e.map(i=>i.user.id));for(const i of this.cursors.keys())t.has(i)||this.cursors.delete(i);this.requestUpdate()})),document.addEventListener("mousemove",this.handleLocalCursor))}render(){const e=[...this.cursors.values()];return h`
|
|
177
177
|
${e.map(t=>h`
|
|
178
178
|
<div
|
|
179
179
|
class="cursor"
|
|
@@ -191,7 +191,7 @@
|
|
|
191
191
|
</span>
|
|
192
192
|
</div>
|
|
193
193
|
`)}
|
|
194
|
-
`}};exports.PulseCursors.styles=
|
|
194
|
+
`}};exports.PulseCursors.styles=A`
|
|
195
195
|
:host {
|
|
196
196
|
position: fixed;
|
|
197
197
|
top: 0;
|
|
@@ -227,7 +227,7 @@
|
|
|
227
227
|
letter-spacing: 0.01em;
|
|
228
228
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
|
|
229
229
|
}
|
|
230
|
-
`;Re([oe({context:q,subscribe:!0}),
|
|
230
|
+
`;Re([oe({context:q,subscribe:!0}),b({attribute:!1})],exports.PulseCursors.prototype,"client",2);Re([x()],exports.PulseCursors.prototype,"cursors",2);exports.PulseCursors=Re([O("pulse-cursors")],exports.PulseCursors);var ni=Object.defineProperty,oi=Object.getOwnPropertyDescriptor,ae=(n,e,t,i)=>{for(var s=i>1?void 0:i?oi(e,t):e,o=n.length-1,r;o>=0;o--)(r=n[o])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&ni(e,t,s),s};exports.PulseComments=class extends _{constructor(){super(...arguments),this.showResolved=!1,this.threads=[],this.replyingTo=null}connectedCallback(){super.connectedCallback(),this.setupListener()}disconnectedCallback(){var e;super.disconnectedCallback(),(e=this.unsub)==null||e.call(this)}updated(e){var t;e.has("client")&&this.client&&((t=this.unsub)==null||t.call(this),this.setupListener())}setupListener(){this.client&&(this.threads=this.client.state.threads,this.unsub=this.client.state.on("threads",e=>{this.threads=[...e]}))}parseMentions(e){return e.split(/(@\w+)/g).map(i=>i.startsWith("@")?h`<span class="mention">${i}</span>`:i)}getInitials(e){return e.split(" ").map(t=>t[0]).join("").toUpperCase().slice(0,2)}getUserForComment(e){var t;return(t=this.client.state.presence.find(i=>i.user.id===e))==null?void 0:t.user}handleNewThread(e){e.preventDefault();const i=e.target.querySelector("textarea"),s=i.value.trim();if(!s)return;const o=[...s.matchAll(/@(\w+)/g)].map(r=>r[1]);this.client.createThread(s,{mentions:o}),i.value=""}handleReply(e,t){t.preventDefault();const s=t.target.querySelector("input"),o=s.value.trim();if(!o)return;const r=[...o.matchAll(/@(\w+)/g)].map(l=>l[1]);this.client.reply(e,o,r),s.value="",this.replyingTo=null}render(){const e=this.showResolved?this.threads:this.threads.filter(t=>!t.resolved);return h`
|
|
231
231
|
<div class="threads">
|
|
232
232
|
${e.length===0?h`<div class="empty">
|
|
233
233
|
<div class="empty-icon">💬</div>
|
|
@@ -243,7 +243,7 @@
|
|
|
243
243
|
`}renderThread(e){return h`
|
|
244
244
|
<div class="thread ${e.resolved?"resolved":""}">
|
|
245
245
|
${e.comments.map((t,i)=>{const s=this.getUserForComment(t.userId);return h`
|
|
246
|
-
${i>0?h`<div class="divider"></div>`:
|
|
246
|
+
${i>0?h`<div class="divider"></div>`:m}
|
|
247
247
|
<div class="comment">
|
|
248
248
|
<div class="comment-header">
|
|
249
249
|
<div
|
|
@@ -279,9 +279,9 @@
|
|
|
279
279
|
<input type="text" placeholder="Write a reply..." />
|
|
280
280
|
<button type="submit">Send</button>
|
|
281
281
|
</form>
|
|
282
|
-
`:
|
|
282
|
+
`:m}
|
|
283
283
|
</div>
|
|
284
|
-
`}formatTime(e){const t=new Date(e),s=new Date().getTime()-t.getTime(),o=Math.floor(s/6e4);if(o<1)return"just now";if(o<60)return`${o}m ago`;const r=Math.floor(o/60);return r<24?`${r}h ago`:t.toLocaleDateString()}};exports.PulseComments.styles=
|
|
284
|
+
`}formatTime(e){const t=new Date(e),s=new Date().getTime()-t.getTime(),o=Math.floor(s/6e4);if(o<1)return"just now";if(o<60)return`${o}m ago`;const r=Math.floor(o/60);return r<24?`${r}h ago`:t.toLocaleDateString()}};exports.PulseComments.styles=A`
|
|
285
285
|
:host {
|
|
286
286
|
display: block;
|
|
287
287
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
|
|
@@ -492,15 +492,15 @@
|
|
|
492
492
|
margin-bottom: 8px;
|
|
493
493
|
opacity: 0.4;
|
|
494
494
|
}
|
|
495
|
-
`;ae([oe({context:q,subscribe:!0}),
|
|
495
|
+
`;ae([oe({context:q,subscribe:!0}),b({attribute:!1})],exports.PulseComments.prototype,"client",2);ae([b({type:Boolean,attribute:"show-resolved"})],exports.PulseComments.prototype,"showResolved",2);ae([x()],exports.PulseComments.prototype,"threads",2);ae([x()],exports.PulseComments.prototype,"replyingTo",2);exports.PulseComments=ae([O("pulse-comments")],exports.PulseComments);var ri=Object.defineProperty,ai=Object.getOwnPropertyDescriptor,Le=(n,e,t,i)=>{for(var s=i>1?void 0:i?ai(e,t):e,o=n.length-1,r;o>=0;o--)(r=n[o])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&ri(e,t,s),s};const li={"comment:created":"left a comment","comment:mention":"mentioned you","comment:reply":"replied to your comment","thread:resolved":"resolved a thread","reaction:added":"reacted to your comment"},ci={"comment:created":"💬","comment:mention":"📣","comment:reply":"↩️","thread:resolved":"✅","reaction:added":"🎉"};exports.PulseNotifications=class extends _{constructor(){super(...arguments),this.notifications=[]}connectedCallback(){super.connectedCallback(),this.setupListener()}disconnectedCallback(){var e;super.disconnectedCallback(),(e=this.unsub)==null||e.call(this)}updated(e){var t;e.has("client")&&this.client&&((t=this.unsub)==null||t.call(this),this.setupListener())}setupListener(){this.client&&(this.notifications=this.client.state.notifications,this.unsub=this.client.state.on("notifications",e=>{this.notifications=[...e]}))}handleClick(e){e.read||this.client.markRead(e.id),this.dispatchEvent(new CustomEvent("pulse-notification-click",{detail:e,bubbles:!0,composed:!0}))}getActorName(e){const t=this.client.state.presence.find(i=>i.user.id===e);return(t==null?void 0:t.user.name)??"Someone"}formatTime(e){const t=new Date(e),s=new Date().getTime()-t.getTime(),o=Math.floor(s/6e4);if(o<1)return"just now";if(o<60)return`${o}m ago`;const r=Math.floor(o/60);return r<24?`${r}h ago`:t.toLocaleDateString()}render(){const e=this.notifications.filter(t=>!t.read).length;return h`
|
|
496
496
|
<div class="header">
|
|
497
497
|
<span class="title">
|
|
498
498
|
Notifications
|
|
499
|
-
${e>0?h`<span class="badge">${e}</span>`:
|
|
499
|
+
${e>0?h`<span class="badge">${e}</span>`:m}
|
|
500
500
|
</span>
|
|
501
501
|
${e>0?h`<button class="mark-all" @click=${()=>this.client.markAllRead()}>
|
|
502
502
|
Mark all read
|
|
503
|
-
</button>`:
|
|
503
|
+
</button>`:m}
|
|
504
504
|
</div>
|
|
505
505
|
<div class="list">
|
|
506
506
|
${this.notifications.length===0?h`<div class="empty">
|
|
@@ -523,7 +523,7 @@
|
|
|
523
523
|
</div>
|
|
524
524
|
`)}
|
|
525
525
|
</div>
|
|
526
|
-
`}};exports.PulseNotifications.styles=
|
|
526
|
+
`}};exports.PulseNotifications.styles=A`
|
|
527
527
|
:host {
|
|
528
528
|
display: block;
|
|
529
529
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
|
|
@@ -663,7 +663,7 @@
|
|
|
663
663
|
margin-bottom: 8px;
|
|
664
664
|
opacity: 0.4;
|
|
665
665
|
}
|
|
666
|
-
`;Le([oe({context:q,subscribe:!0}),
|
|
666
|
+
`;Le([oe({context:q,subscribe:!0}),b({attribute:!1})],exports.PulseNotifications.prototype,"client",2);Le([x()],exports.PulseNotifications.prototype,"notifications",2);exports.PulseNotifications=Le([O("pulse-notifications")],exports.PulseNotifications);var di=Object.defineProperty,hi=Object.getOwnPropertyDescriptor,Y=(n,e,t,i)=>{for(var s=i>1?void 0:i?hi(e,t):e,o=n.length-1,r;o>=0;o--)(r=n[o])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&di(e,t,s),s};const pi=["👍","👎","❤️","🎉","👀","🚀"];exports.PulseReactions=class extends _{constructor(){super(...arguments),this.targetId="",this.targetType="comment",this.reactions=[],this.showPicker=!1}connectedCallback(){super.connectedCallback(),this.setupListener()}disconnectedCallback(){var e;super.disconnectedCallback(),(e=this.unsub)==null||e.call(this)}updated(e){var t;e.has("client")&&this.client&&((t=this.unsub)==null||t.call(this),this.setupListener())}setupListener(){this.client&&(this.reactions=this.client.state.getReactions(this.targetId),this.unsub=this.client.state.on("reactions",e=>{e.targetId===this.targetId&&(this.reactions=[...e.reactions])}))}groupReactions(){var i,s;const e=new Map,t=(s=(i=this.client)==null?void 0:i.state.user)==null?void 0:s.id;for(const o of this.reactions){const r=e.get(o.emoji)??{count:0,userReactionId:null};r.count++,o.userId===t&&(r.userReactionId=o.id),e.set(o.emoji,r)}return[...e.entries()].map(([o,r])=>({emoji:o,...r}))}toggleReaction(e){e.userReactionId?this.client.removeReaction(e.userReactionId):this.client.addReaction(this.targetId,this.targetType,e.emoji)}addEmoji(e){this.client.addReaction(this.targetId,this.targetType,e),this.showPicker=!1}render(){const e=this.groupReactions();return h`
|
|
667
667
|
${e.map(t=>h`
|
|
668
668
|
<button
|
|
669
669
|
class="reaction ${t.userReactionId?"active":""}"
|
|
@@ -688,9 +688,9 @@
|
|
|
688
688
|
</button>
|
|
689
689
|
`)}
|
|
690
690
|
</div>
|
|
691
|
-
`:
|
|
691
|
+
`:m}
|
|
692
692
|
</div>
|
|
693
|
-
`}};exports.PulseReactions.styles=
|
|
693
|
+
`}};exports.PulseReactions.styles=A`
|
|
694
694
|
:host {
|
|
695
695
|
display: inline-flex;
|
|
696
696
|
align-items: center;
|
|
@@ -801,7 +801,7 @@
|
|
|
801
801
|
background: #f1f5f9;
|
|
802
802
|
transform: scale(1.2);
|
|
803
803
|
}
|
|
804
|
-
`;Y([oe({context:q,subscribe:!0}),
|
|
804
|
+
`;Y([oe({context:q,subscribe:!0}),b({attribute:!1})],exports.PulseReactions.prototype,"client",2);Y([b({attribute:"target-id"})],exports.PulseReactions.prototype,"targetId",2);Y([b({attribute:"target-type"})],exports.PulseReactions.prototype,"targetType",2);Y([x()],exports.PulseReactions.prototype,"reactions",2);Y([x()],exports.PulseReactions.prototype,"showPicker",2);exports.PulseReactions=Y([O("pulse-reactions")],exports.PulseReactions);/**
|
|
805
805
|
* @license
|
|
806
806
|
* Copyright 2017 Google LLC
|
|
807
807
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -809,7 +809,7 @@
|
|
|
809
809
|
* @license
|
|
810
810
|
* Copyright 2017 Google LLC
|
|
811
811
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
812
|
-
*/class Ce extends mi{constructor(e){if(super(e),this.it=
|
|
812
|
+
*/class Ce extends mi{constructor(e){if(super(e),this.it=m,e.type!==ui.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(e){if(e===m||e==null)return this._t=void 0,this.it=e;if(e===B)return e;if(typeof e!="string")throw Error(this.constructor.directiveName+"() called with a non-string value");if(e===this.it)return this._t;this.it=e;const t=[e];return t.raw=t,this._t={_$litType$:this.constructor.resultType,strings:t,values:[]}}}Ce.directiveName="unsafeHTML",Ce.resultType=1;/**
|
|
813
813
|
* @license
|
|
814
814
|
* Copyright 2017 Google LLC
|
|
815
815
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -878,7 +878,7 @@
|
|
|
878
878
|
*
|
|
879
879
|
* This source code is licensed under the ISC license.
|
|
880
880
|
* See the LICENSE file in the root directory of this source tree.
|
|
881
|
-
*/const _i=[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z"}]];function Ti(n){return n.map(([e,t])=>{const i=Object.entries(t).filter(([,s])=>s!=null).map(([s,o])=>`${s}="${o}"`).join(" ");return`<${e} ${i}/>`}).join("")}function
|
|
881
|
+
*/const _i=[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z"}]];function Ti(n){return n.map(([e,t])=>{const i=Object.entries(t).filter(([,s])=>s!=null).map(([s,o])=>`${s}="${o}"`).join(" ");return`<${e} ${i}/>`}).join("")}function E(n,e=18){return Bt`<svg
|
|
882
882
|
xmlns="http://www.w3.org/2000/svg"
|
|
883
883
|
width="${e}"
|
|
884
884
|
height="${e}"
|
|
@@ -888,7 +888,7 @@
|
|
|
888
888
|
stroke-width="2"
|
|
889
889
|
stroke-linecap="round"
|
|
890
890
|
stroke-linejoin="round"
|
|
891
|
-
>${gi(Ti(n))}</svg>`}const K=
|
|
891
|
+
>${gi(Ti(n))}</svg>`}const K=A`
|
|
892
892
|
* {
|
|
893
893
|
box-sizing: border-box;
|
|
894
894
|
margin: 0;
|
|
@@ -931,7 +931,7 @@
|
|
|
931
931
|
--pw-shadow: var(--pulse-shadow);
|
|
932
932
|
--pw-shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.16), 0 2px 8px rgba(0, 0, 0, 0.08);
|
|
933
933
|
}
|
|
934
|
-
`,ce=
|
|
934
|
+
`,ce=A`
|
|
935
935
|
.pw-btn {
|
|
936
936
|
display: inline-flex;
|
|
937
937
|
align-items: center;
|
|
@@ -975,7 +975,7 @@
|
|
|
975
975
|
width: 18px;
|
|
976
976
|
height: 18px;
|
|
977
977
|
}
|
|
978
|
-
`,xe=
|
|
978
|
+
`,xe=A`
|
|
979
979
|
.pw-scrollable::-webkit-scrollbar {
|
|
980
980
|
width: 4px;
|
|
981
981
|
}
|
|
@@ -986,12 +986,12 @@
|
|
|
986
986
|
.pw-scrollable::-webkit-scrollbar-track {
|
|
987
987
|
background: transparent;
|
|
988
988
|
}
|
|
989
|
-
`;var Si=Object.defineProperty,Ai=Object.getOwnPropertyDescriptor,je=(n,e,t,i)=>{for(var s=i>1?void 0:i?Ai(e,t):e,o=n.length-1,r;o>=0;o--)(r=n[o])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&Si(e,t,s),s};let F=class extends
|
|
989
|
+
`;var Si=Object.defineProperty,Ai=Object.getOwnPropertyDescriptor,je=(n,e,t,i)=>{for(var s=i>1?void 0:i?Ai(e,t):e,o=n.length-1,r;o>=0;o--)(r=n[o])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&Si(e,t,s),s};let F=class extends _{constructor(){super(...arguments),this.items=[],this.unsubs=[],this.counter=0}connectedCallback(){super.connectedCallback(),this.setupListeners()}disconnectedCallback(){super.disconnectedCallback(),this.unsubs.forEach(n=>n()),this.unsubs=[]}updated(n){n.has("client")&&this.client&&(this.unsubs.forEach(e=>e()),this.unsubs=[],this.setupListeners())}setupListeners(){if(!this.client)return;const n=this.client.state.activityLogs;n.length>0&&(this.items=n.map(e=>this.logToItem(e)),this.counter=this.items.length),this.unsubs.push(this.client.state.on("activity-logs",e=>{this.items=e.map(t=>this.logToItem(t))}))}logToItem(n){return{id:n.id,type:n.type,userId:n.userId,description:n.description,timestamp:new Date(n.createdAt).getTime(),color:F.TYPE_COLORS[n.type]??"#94a3b8"}}getUserName(n){var e;return((e=this.client.state.getUser(n))==null?void 0:e.name)??"Someone"}formatRelativeTime(n){const e=Math.floor((Date.now()-n)/1e3);return e<5?"just now":e<60?`${e}s ago`:e<3600?`${Math.floor(e/60)}m ago`:`${Math.floor(e/3600)}h ago`}fireClose(){this.dispatchEvent(new CustomEvent("panel-close",{bubbles:!0,composed:!0}))}render(){return h`
|
|
990
990
|
<div class="panel">
|
|
991
991
|
<div class="panel-header">
|
|
992
992
|
<span class="panel-title">Activity</span>
|
|
993
993
|
<button class="close-btn" @click=${this.fireClose} title="Close">
|
|
994
|
-
${
|
|
994
|
+
${E(le,16)}
|
|
995
995
|
</button>
|
|
996
996
|
</div>
|
|
997
997
|
|
|
@@ -1017,7 +1017,7 @@
|
|
|
1017
1017
|
`)}
|
|
1018
1018
|
</div>
|
|
1019
1019
|
</div>
|
|
1020
|
-
`}};F.styles=[K,ce,xe,
|
|
1020
|
+
`}};F.styles=[K,ce,xe,A`
|
|
1021
1021
|
:host {
|
|
1022
1022
|
display: block;
|
|
1023
1023
|
}
|
|
@@ -1133,12 +1133,12 @@
|
|
|
1133
1133
|
border-radius: 16px 16px 0 0;
|
|
1134
1134
|
}
|
|
1135
1135
|
}
|
|
1136
|
-
`];F.TYPE_COLORS={join:"#22c55e",leave:"#94a3b8",thread:"var(--pw-accent, #6366f1)",comment:"#3b82f6",resolve:"#22c55e"};je([
|
|
1136
|
+
`];F.TYPE_COLORS={join:"#22c55e",leave:"#94a3b8",thread:"var(--pw-accent, #6366f1)",comment:"#3b82f6",resolve:"#22c55e"};je([b({attribute:!1})],F.prototype,"client",2);je([x()],F.prototype,"items",2);F=je([O("pulse-widget-activity-panel")],F);const Ii="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",Je="#6366f1",Qe="#e2e8f0",Mi="#f8fafc",Oi="#e2e8f0",et="#64748b",pe=28,Ri=Array.from({length:pe},(n,e)=>.2+Math.abs(Math.sin(e*12.9898+78.233)*43758.5453)%1*.8);function tt(n){const e=Math.max(0,Math.floor(n)),t=Math.floor(e/60),i=e%60;return`${t}:${i.toString().padStart(2,"0")}`}class Pe{static render(e,t){let i=!1,s=t!=null?t/1e3:0,o=0;const r=document.createElement("audio");r.preload="metadata",r.src=e;const l=document.createElement("div");Object.assign(l.style,{display:"inline-flex",alignItems:"center",gap:"10px",width:"220px",height:"44px",padding:"0 10px",background:Mi,borderRadius:"12px",border:`1px solid ${Oi}`,fontFamily:Ii,fontSize:"11px",color:et,userSelect:"none",boxSizing:"border-box"});const a=document.createElement("button");Object.assign(a.style,{width:"28px",height:"28px",minWidth:"28px",borderRadius:"50%",border:"none",background:Je,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",padding:"0",outline:"none",flexShrink:"0"});const c=document.createElement("span");Object.assign(c.style,{display:"block",width:"10px",height:"12px",lineHeight:"0"});function p(){c.innerHTML=`<svg width="10" height="12" viewBox="0 0 10 12" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
1137
1137
|
<path d="M1 1L9 6L1 11V1Z" fill="white" stroke="white" stroke-width="1" stroke-linejoin="round"/>
|
|
1138
1138
|
</svg>`}function d(){c.innerHTML=`<svg width="10" height="12" viewBox="0 0 10 12" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
1139
1139
|
<rect x="1" y="1" width="2.5" height="10" rx="0.5" fill="white"/>
|
|
1140
1140
|
<rect x="6.5" y="1" width="2.5" height="10" rx="0.5" fill="white"/>
|
|
1141
|
-
</svg>`}p(),a.appendChild(c);const
|
|
1141
|
+
</svg>`}p(),a.appendChild(c);const f=document.createElement("div");Object.assign(f.style,{flex:"1",display:"flex",flexDirection:"column",gap:"3px",overflow:"hidden",minWidth:"0"});const u=document.createElement("div");Object.assign(u.style,{display:"flex",alignItems:"center",gap:"1.5px",height:"22px",cursor:"pointer"});const g=[];for(let C=0;C<pe;C++){const S=document.createElement("div"),y=Math.round(Ri[C]*20);Object.assign(S.style,{flex:"1",height:`${Math.max(3,y)}px`,borderRadius:"1px",background:Qe,transition:"background 0.1s ease",minWidth:"0"}),g.push(S),u.appendChild(S)}const v=document.createElement("div");Object.assign(v.style,{fontSize:"10px",color:et,whiteSpace:"nowrap",lineHeight:"1"});function k(){const C=tt(o),S=tt(s);v.textContent=`${C} / ${S}`}k(),f.appendChild(u),f.appendChild(v),l.appendChild(a),l.appendChild(f);function w(){const C=s>0?o/s:0,S=Math.floor(C*pe);for(let y=0;y<pe;y++)g[y].style.background=y<=S?Je:Qe}return u.addEventListener("click",C=>{if(s<=0)return;const S=u.getBoundingClientRect(),y=Math.min(1,Math.max(0,(C.clientX-S.left)/S.width));r.currentTime=y*s,o=r.currentTime,w(),k()}),a.addEventListener("click",()=>{i?r.pause():r.play().catch(()=>{})}),r.addEventListener("play",()=>{i=!0,d()}),r.addEventListener("pause",()=>{i=!1,p()}),r.addEventListener("ended",()=>{i=!1,p(),o=0,w(),k()}),r.addEventListener("timeupdate",()=>{o=r.currentTime,w(),k()}),r.addEventListener("loadedmetadata",()=>{r.duration&&isFinite(r.duration)&&(s=r.duration,k())}),r.addEventListener("durationchange",()=>{r.duration&&isFinite(r.duration)&&(s=r.duration,k())}),l}}class _e{constructor(){this.container=null,this.stream=null,this.recorder=null,this.analyser=null,this.audioCtx=null,this.recording=!1,this.animFrame=null,this.startTime=0,this.maxDuration=12e4,this.maxTimer=null,this.canvas=null,this.timerEl=null,this.resolve=null,this.animate=()=>{this.recording&&(this.drawWaveform(),this.updateTimer(),this.animFrame=requestAnimationFrame(this.animate))}}async startRecording(e){this.destroy(),this.stream=await navigator.mediaDevices.getUserMedia({audio:!0}),this.audioCtx=new AudioContext;const t=this.audioCtx.createMediaStreamSource(this.stream);this.analyser=this.audioCtx.createAnalyser(),this.analyser.fftSize=64,t.connect(this.analyser);const i=this.detectMimeType(),s={};i&&(s.mimeType=i),this.recorder=new MediaRecorder(this.stream,s);const o=[];this.recorder.ondataavailable=l=>{l.data.size>0&&o.push(l.data)},this.buildUI(e);const r=new Promise(l=>{this.resolve=l});return this.recorder.onstop=()=>{var c,p;const l=((c=this.recorder)==null?void 0:c.mimeType)||i||"audio/webm",a=new Blob(o,{type:l});(p=this.resolve)==null||p.call(this,a),this.resolve=null,this.cleanupResources()},this.recorder.start(),this.recording=!0,this.startTime=Date.now(),this.maxTimer=setTimeout(()=>{this.stopRecording()},this.maxDuration),this.animate(),r}stopRecording(){!this.recording||!this.recorder||(this.recording=!1,this.recorder.state==="recording"&&this.recorder.stop())}cancelRecording(){var e;this.recorder&&(this.recording=!1,this.recorder.ondataavailable=null,this.recorder.onstop=null,this.recorder.state==="recording"&&this.recorder.stop(),(e=this.resolve)==null||e.call(this,null),this.resolve=null,this.cleanupResources())}destroy(){this.cancelRecording(),this.cleanupResources()}detectMimeType(){if(typeof MediaRecorder.isTypeSupported=="function"){if(MediaRecorder.isTypeSupported("audio/webm;codecs=opus"))return"audio/webm;codecs=opus";if(MediaRecorder.isTypeSupported("audio/webm"))return"audio/webm";if(MediaRecorder.isTypeSupported("audio/mp4;codecs=mp4a.40.2"))return"audio/mp4;codecs=mp4a.40.2";if(MediaRecorder.isTypeSupported("audio/mp4"))return"audio/mp4"}}buildUI(e){this.container=document.createElement("div"),this.container.className="pulse-audio-recorder",Object.assign(this.container.style,{display:"flex",alignItems:"center",gap:"10px",padding:"8px 12px",background:"#ffffff",borderRadius:"12px",boxShadow:"0 2px 12px rgba(0,0,0,0.10), 0 1px 3px rgba(0,0,0,0.06)",border:"1px solid #e2e8f0",fontFamily:"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",fontSize:"13px",width:"fit-content"});const t=document.createElement("button");t.title="Cancel",t.innerHTML='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',Object.assign(t.style,{display:"flex",alignItems:"center",justifyContent:"center",width:"28px",height:"28px",border:"none",background:"none",cursor:"pointer",color:"#64748b",borderRadius:"6px",padding:"0",transition:"background 0.15s, color 0.15s",flexShrink:"0"}),t.addEventListener("mouseenter",()=>{t.style.background="#f1f5f9",t.style.color="#0f172a"}),t.addEventListener("mouseleave",()=>{t.style.background="none",t.style.color="#64748b"}),t.addEventListener("click",()=>this.cancelRecording()),this.container.appendChild(t),this.canvas=document.createElement("canvas"),this.canvas.width=200,this.canvas.height=40,Object.assign(this.canvas.style,{display:"block",borderRadius:"4px",flexShrink:"0"}),this.container.appendChild(this.canvas),this.timerEl=document.createElement("span"),this.timerEl.textContent="00:00",Object.assign(this.timerEl.style,{color:"#ef4444",fontWeight:"600",fontSize:"13px",fontVariantNumeric:"tabular-nums",minWidth:"40px",flexShrink:"0"}),this.container.appendChild(this.timerEl);const i=document.createElement("button");i.title="Stop recording",i.innerHTML='<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><rect x="6" y="6" width="12" height="12" rx="2"/></svg>',Object.assign(i.style,{display:"flex",alignItems:"center",justifyContent:"center",width:"32px",height:"32px",border:"none",background:"#ef4444",cursor:"pointer",color:"#ffffff",borderRadius:"50%",padding:"0",transition:"background 0.15s, transform 0.15s",flexShrink:"0"}),i.addEventListener("mouseenter",()=>{i.style.background="#dc2626",i.style.transform="scale(1.08)"}),i.addEventListener("mouseleave",()=>{i.style.background="#ef4444",i.style.transform="scale(1)"}),i.addEventListener("click",()=>this.stopRecording()),this.container.appendChild(i),e.appendChild(this.container)}drawWaveform(){if(!this.canvas||!this.analyser)return;const e=this.canvas.getContext("2d");if(!e)return;const t=this.canvas.width,i=this.canvas.height,s=this.analyser.frequencyBinCount,o=new Uint8Array(s);this.analyser.getByteFrequencyData(o),e.clearRect(0,0,t,i);const r=s,l=Math.max(2,t/r*.7),a=(t-l*r)/(r-1||1);for(let c=0;c<r;c++){const p=o[c]/255,d=Math.max(2,p*i*.85),f=c*(l+a),u=(i-d)/2,g=.4+p*.6;e.fillStyle=`rgba(99, 102, 241, ${g})`,e.beginPath(),e.roundRect(f,u,l,d,1),e.fill()}}updateTimer(){if(!this.timerEl)return;const e=Date.now()-this.startTime,t=Math.floor(e/1e3),i=Math.floor(t/60),s=t%60;this.timerEl.textContent=`${String(i).padStart(2,"0")}:${String(s).padStart(2,"0")}`}cleanupResources(){if(this.animFrame!==null&&(cancelAnimationFrame(this.animFrame),this.animFrame=null),this.maxTimer!==null&&(clearTimeout(this.maxTimer),this.maxTimer=null),this.audioCtx&&(this.audioCtx.close().catch(()=>{}),this.audioCtx=null),this.analyser=null,this.stream){for(const e of this.stream.getTracks())e.stop();this.stream=null}this.recorder=null,this.container&&(this.container.remove(),this.container=null),this.canvas=null,this.timerEl=null}}const it=80,Li="#e2e8f0",ji=`
|
|
1142
1142
|
<svg width="28" height="28" viewBox="0 0 28 28" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
1143
1143
|
<circle cx="14" cy="14" r="14" fill="rgba(0,0,0,0.35)"/>
|
|
1144
1144
|
<polygon points="11,8 22,14 11,20" fill="rgba(255,255,255,0.9)"/>
|
|
@@ -1258,7 +1258,7 @@
|
|
|
1258
1258
|
background: #e2e8f0;
|
|
1259
1259
|
color: #0f172a;
|
|
1260
1260
|
}
|
|
1261
|
-
`;function ot(n){return n.toString().padStart(2,"0")}function Di(n){const e=Math.floor(n/60),t=n%60;return`${ot(e)}:${ot(t)}`}function
|
|
1261
|
+
`;function ot(n){return n.toString().padStart(2,"0")}function Di(n){const e=Math.floor(n/60),t=n%60;return`${ot(e)}:${ot(t)}`}function Hi(){const n=["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm","video/mp4"];for(const e of n)if(MediaRecorder.isTypeSupported(e))return e;return""}function Ni(n){return new Promise((e,t)=>{const i=URL.createObjectURL(n),s=document.createElement("video");s.muted=!0,s.playsInline=!0,s.preload="auto",s.src=i,s.addEventListener("loadeddata",()=>{s.currentTime=.01}),s.addEventListener("seeked",()=>{const o=document.createElement("canvas");o.width=s.videoWidth||240,o.height=s.videoHeight||240,o.getContext("2d").drawImage(s,0,0,o.width,o.height),URL.revokeObjectURL(i),o.toBlob(l=>{l?e(l):t(new Error("Failed to generate poster frame"))},"image/jpeg",.85)}),s.addEventListener("error",()=>{URL.revokeObjectURL(i),t(new Error("Failed to load video for poster generation"))}),s.load()})}class Te{constructor(){this.recording=!1,this.container=null,this.stream=null,this.mediaRecorder=null,this.chunks=[],this.timerInterval=null,this.elapsed=0,this.resolvePromise=null,this.root=null,this.styleEl=null,this.videoEl=null,this.timerEl=null}async startRecording(e){if(this.recording)return null;let t;try{t=await navigator.mediaDevices.getUserMedia({video:!0,audio:!0})}catch{return null}this.stream=t,this.container=e,this.recording=!0,this.elapsed=0,this.chunks=[],this.buildUI(e),this.videoEl&&(this.videoEl.srcObject=t,this.videoEl.play().catch(()=>{}));const i=Hi(),s={};i&&(s.mimeType=i);const o=new MediaRecorder(t,s);return this.mediaRecorder=o,o.ondataavailable=r=>{r.data.size>0&&this.chunks.push(r.data)},o.onstop=()=>{this.handleRecordingComplete()},o.start(),this.timerInterval=setInterval(()=>{this.elapsed++,this.updateTimer(),this.elapsed>=nt&&this.stopRecording()},1e3),new Promise(r=>{this.resolvePromise=r})}stopRecording(){!this.recording||!this.mediaRecorder||this.mediaRecorder.state==="recording"&&this.mediaRecorder.stop()}cancelRecording(){var e;this.cleanup(),(e=this.resolvePromise)==null||e.call(this,null),this.resolvePromise=null}destroy(){this.cancelRecording()}buildUI(e){this.styleEl=document.createElement("style"),this.styleEl.textContent=Ui,document.head.appendChild(this.styleEl),this.root=document.createElement("div"),this.root.className="vr-overlay";const t=document.createElement("div");t.className="vr-circle-wrapper";const i=document.createElement("div");i.className="vr-ring",t.appendChild(i);const s=document.createElement("div");s.className="vr-video-circle",this.videoEl=document.createElement("video"),this.videoEl.muted=!0,this.videoEl.playsInline=!0,this.videoEl.setAttribute("playsinline",""),s.appendChild(this.videoEl),t.appendChild(s),this.root.appendChild(t),this.timerEl=document.createElement("span"),this.timerEl.className="vr-timer",this.timerEl.textContent="00:00",this.root.appendChild(this.timerEl);const o=document.createElement("div");o.className="vr-actions";const r=document.createElement("button");r.className="vr-btn vr-btn-stop",r.textContent="Stop",r.addEventListener("click",()=>this.stopRecording()),o.appendChild(r);const l=document.createElement("button");l.className="vr-btn vr-btn-cancel",l.textContent="Cancel",l.addEventListener("click",()=>this.cancelRecording()),o.appendChild(l),this.root.appendChild(o),e.appendChild(this.root)}updateTimer(){if(!this.timerEl)return;const e=nt-this.elapsed;this.timerEl.textContent=Di(this.elapsed),e<=10?this.timerEl.classList.add("vr-countdown"):this.timerEl.classList.remove("vr-countdown")}async handleRecordingComplete(){var s,o;const e=((s=this.mediaRecorder)==null?void 0:s.mimeType)||"video/webm",t=new Blob(this.chunks,{type:e});let i;try{i=await Ni(t)}catch{const r=document.createElement("canvas");r.width=1,r.height=1,i=await new Promise(l=>{r.toBlob(a=>l(a),"image/png")})}this.cleanup(),(o=this.resolvePromise)==null||o.call(this,{blob:t,posterBlob:i}),this.resolvePromise=null}cleanup(){if(this.recording=!1,this.timerInterval&&(clearInterval(this.timerInterval),this.timerInterval=null),this.mediaRecorder&&this.mediaRecorder.state!=="inactive")try{this.mediaRecorder.stop()}catch{}if(this.mediaRecorder=null,this.stream){for(const e of this.stream.getTracks())e.stop();this.stream=null}this.videoEl&&(this.videoEl.srcObject=null,this.videoEl=null),this.root&&this.root.parentElement&&this.root.parentElement.removeChild(this.root),this.root=null,this.styleEl&&this.styleEl.parentElement&&this.styleEl.parentElement.removeChild(this.styleEl),this.styleEl=null,this.chunks=[],this.elapsed=0}}const P=class P{static open(e){P.close();const t=document.createElement("div");t.id="pulse-widget-lightbox",Object.assign(t.style,{position:"fixed",top:"0",left:"0",width:"100%",height:"100%",zIndex:"100000",background:"rgba(0,0,0,0.85)",display:"flex",alignItems:"center",justifyContent:"center",opacity:"0",transition:"opacity 200ms ease",cursor:"pointer",fontFamily:"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif"});const i=document.createElement("button");i.textContent="×",Object.assign(i.style,{position:"absolute",top:"16px",right:"16px",width:"40px",height:"40px",border:"none",borderRadius:"50%",background:"rgba(255,255,255,0.15)",color:"#fff",fontSize:"24px",lineHeight:"40px",textAlign:"center",cursor:"pointer",padding:"0",fontFamily:"inherit",display:"flex",alignItems:"center",justifyContent:"center",transition:"background 150ms ease"}),i.addEventListener("mouseenter",()=>{i.style.background="rgba(255,255,255,0.3)"}),i.addEventListener("mouseleave",()=>{i.style.background="rgba(255,255,255,0.15)"}),i.addEventListener("click",r=>{r.stopPropagation(),P.close()});const s=document.createElement("img");s.src=e,s.alt="Lightbox image",Object.assign(s.style,{maxWidth:"90vw",maxHeight:"90vh",borderRadius:"8px",objectFit:"contain",cursor:"default",userSelect:"none"}),s.addEventListener("click",r=>{r.stopPropagation()}),t.appendChild(i),t.appendChild(s),t.addEventListener("click",()=>{P.close()});const o=r=>{r.key==="Escape"&&P.close()};document.addEventListener("keydown",o),P.overlay=t,P.onKeyDown=o,document.body.appendChild(t),requestAnimationFrame(()=>{t.style.opacity="1"})}static close(){if(!P.overlay)return;const e=P.overlay;P.onKeyDown&&(document.removeEventListener("keydown",P.onKeyDown),P.onKeyDown=null),e.style.opacity="0",e.addEventListener("transitionend",()=>{e.remove()}),P.overlay=null}};P.overlay=null,P.onKeyDown=null;let ge=P;class Q{constructor(e){this.uploading=!1,this.client=e,this.input=document.createElement("input"),this.input.type="file",this.input.style.display="none",document.body.appendChild(this.input)}pickFile(e){return new Promise(t=>{this.input.accept=e,this.input.value="";const i=()=>{o(),t(null)},s=async()=>{var l;o();const r=(l=this.input.files)==null?void 0:l[0];if(!r){t(null);return}this.uploading=!0;try{const a=await this.client.uploadFile(r);t(a)}catch(a){console.error("[Pulse] File upload failed:",a),t(null)}finally{this.uploading=!1}},o=()=>{this.input.removeEventListener("change",s),this.input.removeEventListener("cancel",i)};this.input.addEventListener("change",s,{once:!0}),this.input.addEventListener("cancel",i,{once:!0}),this.input.click()})}async uploadBlob(e,t){this.uploading=!0;try{const i=new File([e],t,{type:e.type});return await this.client.uploadFile(i)}catch(i){return console.error("[Pulse] Blob upload failed:",i),null}finally{this.uploading=!1}}destroy(){this.input.remove()}}const Bi=["👍","👎","❤️","🎉","👀","🚀"],de="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",Fi='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z"/><path d="m15 5 4 4"/></svg>',Wi='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/><line x1="10" y1="11" x2="10" y2="17"/><line x1="14" y1="11" x2="14" y2="17"/></svg>',rt=`<button class="pulse-close-btn" style="
|
|
1262
1262
|
border:none;background:none;cursor:pointer;color:#94a3b8;padding:4px;
|
|
1263
1263
|
border-radius:6px;display:flex;align-items:center;justify-content:center;
|
|
1264
1264
|
transition:all 0.15s;flex-shrink:0;
|
|
@@ -1298,15 +1298,15 @@
|
|
|
1298
1298
|
">Pin Comment</button>
|
|
1299
1299
|
</div>
|
|
1300
1300
|
</div>
|
|
1301
|
-
<div class="pin-attachments-preview" style="margin-top:6px;"></div>
|
|
1302
|
-
`;const a=this.form.querySelector("textarea"),c=this.form.querySelector(".pulse-close-btn"),p=this.form.querySelector(".pin-submit");c.addEventListener("click",()=>this.exitPinMode()),this.pendingAttachmentIds=[],this.upload||(this.upload=new Q(this.client));const d=this.form.querySelector(".pin-attachments-preview");this.form.querySelector(".attach-img").addEventListener("click",async()=>{const u=await this.upload.pickFile("image/*");if(u){this.pendingAttachmentIds.push(u.id);const
|
|
1301
|
+
<div class="pin-attachments-preview" style="margin-top:6px;display:flex;flex-wrap:wrap;gap:6px;"></div>
|
|
1302
|
+
`;const a=this.form.querySelector("textarea"),c=this.form.querySelector(".pulse-close-btn"),p=this.form.querySelector(".pin-submit");c.addEventListener("click",()=>this.exitPinMode()),this.pendingAttachmentIds=[],this.upload||(this.upload=new Q(this.client));const d=this.form.querySelector(".pin-attachments-preview"),f=(u,g)=>{const v=document.createElement("div");Object.assign(v.style,{position:"relative",display:"inline-block"}),v.appendChild(g);const k=document.createElement("button");k.innerHTML="×",Object.assign(k.style,{position:"absolute",top:"-4px",right:"-4px",width:"16px",height:"16px",borderRadius:"50%",background:"#ef4444",color:"#fff",border:"none",fontSize:"11px",lineHeight:"1",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",padding:"0",fontWeight:"700"}),k.addEventListener("click",()=>{const w=this.pendingAttachmentIds.indexOf(u);w!==-1&&this.pendingAttachmentIds.splice(w,1),v.remove()}),v.appendChild(k),d.appendChild(v)};this.form.querySelector(".attach-img").addEventListener("click",async()=>{const u=await this.upload.pickFile("image/*");if(u){this.pendingAttachmentIds.push(u.id);const g=document.createElement("img");g.src=u.thumbnailUrl||u.url,Object.assign(g.style,{width:"48px",height:"48px",borderRadius:"6px",objectFit:"cover",border:"1px solid #e2e8f0",display:"block"}),f(u.id,g)}}),this.form.querySelector(".attach-mic").addEventListener("click",async()=>{this.audioRecorder||(this.audioRecorder=new _e);const u=await this.audioRecorder.startRecording(d);if(u){const g=await this.upload.uploadBlob(u,"audio.webm");if(g){this.pendingAttachmentIds.push(g.id);const v=document.createElement("span");Object.assign(v.style,{display:"flex",alignItems:"center",padding:"4px 10px",borderRadius:"6px",background:"#f1f5f9",fontSize:"11px",color:"#64748b",height:"48px",boxSizing:"border-box"}),v.textContent="🎤 Audio",f(g.id,v)}}}),this.form.querySelector(".attach-video").addEventListener("click",async()=>{this.videoRecorder||(this.videoRecorder=new Te);const u=await this.videoRecorder.startRecording(d);if(u){const g=await this.upload.uploadBlob(u.blob,"video.webm");if(g){this.pendingAttachmentIds.push(g.id);const v=document.createElement("span");Object.assign(v.style,{display:"flex",alignItems:"center",padding:"4px 10px",borderRadius:"6px",background:"#f1f5f9",fontSize:"11px",color:"#64748b",height:"48px",boxSizing:"border-box"}),v.textContent="🎥 Video",f(g.id,v)}}}),p.addEventListener("click",()=>{const u=a.value.trim();if(!u&&this.pendingAttachmentIds.length===0)return;const g=[...(u||"").matchAll(/@(\w+)/g)].map(v=>v[1]);this.client.createThread(u,{position:i,mentions:g,attachmentIds:this.pendingAttachmentIds.length>0?[...this.pendingAttachmentIds]:void 0}),this.pendingAttachmentIds=[],this.exitPinMode()}),a.addEventListener("keydown",u=>{u.key==="Escape"&&this.exitPinMode(),u.stopPropagation()}),document.body.appendChild(this.form),requestAnimationFrame(()=>a.focus())}showThreadPopover(e,t){this.closePopover(),this.popover=document.createElement("div"),this.popover.dataset.threadId=e.id;const i=window.innerWidth<=480,s=i?window.innerWidth:300,o=t.getBoundingClientRect();let r,l;i?(r=0,l=window.innerHeight*.4):(r=o.right+10,l=o.top-8,r+s>window.innerWidth-16&&(r=o.left-s-10),l<16&&(l=16)),Object.assign(this.popover.style,{position:"fixed",left:`${r}px`,top:`${l}px`,width:i?"100vw":`${s}px`,maxHeight:i?"60vh":"360px",zIndex:"10001",background:"#fff",borderRadius:i?"16px 16px 0 0":"12px",boxShadow:"0 8px 40px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.08)",border:"1px solid #e2e8f0",fontFamily:de,display:"flex",flexDirection:"column",overflow:"hidden",pointerEvents:"auto",...i?{bottom:"0",top:"auto"}:{}});const a=document.createElement("div");Object.assign(a.style,{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",borderBottom:"1px solid #f1f5f9",flexShrink:"0"}),a.innerHTML=`
|
|
1303
1303
|
<span style="font-size:13px;font-weight:700;color:#0f172a;">Thread</span>
|
|
1304
1304
|
${rt}
|
|
1305
|
-
`,a.querySelector(".pulse-close-btn").addEventListener("click",()=>{this.closePopover()}),this.popover.appendChild(a),this.refreshPopoverComments(e),this.addPopoverReplyForm(e),document.body.appendChild(this.popover);const c=this.popover.getBoundingClientRect();c.bottom>window.innerHeight-16&&(this.popover.style.top=`${Math.max(16,window.innerHeight-c.height-16)}px`),requestAnimationFrame(()=>{document.addEventListener("pointerdown",this.handlePopoverOutsideClick),document.addEventListener("keydown",this.handlePopoverEscape)})}refreshPopoverComments(e){var l;if(!this.popover)return;this.removePickerEl(),this.editingPopoverCommentId&&!e.comments.find(a=>a.id===this.editingPopoverCommentId)&&(this.editingPopoverCommentId=null);let t=this.popover.querySelector(".popover-comments");if(!t){t=document.createElement("div"),t.className="popover-comments",Object.assign(t.style,{flex:"1",overflowY:"auto",padding:"12px 14px",minHeight:"0"});const a=this.popover.firstElementChild;a&&a.nextSibling?this.popover.insertBefore(t,a.nextSibling):this.popover.appendChild(t)}const i=(l=this.client.state.user)==null?void 0:l.id;t.innerHTML=e.comments.map(a=>{const c=this.client.state.getUser(a.userId),p=c?c.name.split(" ").map(
|
|
1305
|
+
`,a.querySelector(".pulse-close-btn").addEventListener("click",()=>{this.closePopover()}),this.popover.appendChild(a),this.refreshPopoverComments(e),this.addPopoverReplyForm(e),document.body.appendChild(this.popover);const c=this.popover.getBoundingClientRect();c.bottom>window.innerHeight-16&&(this.popover.style.top=`${Math.max(16,window.innerHeight-c.height-16)}px`),requestAnimationFrame(()=>{document.addEventListener("pointerdown",this.handlePopoverOutsideClick),document.addEventListener("keydown",this.handlePopoverEscape)})}refreshPopoverComments(e){var l;if(!this.popover)return;this.removePickerEl(),this.editingPopoverCommentId&&!e.comments.find(a=>a.id===this.editingPopoverCommentId)&&(this.editingPopoverCommentId=null);let t=this.popover.querySelector(".popover-comments");if(!t){t=document.createElement("div"),t.className="popover-comments",Object.assign(t.style,{flex:"1",overflowY:"auto",padding:"12px 14px",minHeight:"0"});const a=this.popover.firstElementChild;a&&a.nextSibling?this.popover.insertBefore(t,a.nextSibling):this.popover.appendChild(t)}const i=(l=this.client.state.user)==null?void 0:l.id;t.innerHTML=e.comments.map(a=>{const c=this.client.state.getUser(a.userId),p=c?c.name.split(" ").map(y=>y[0]).join("").toUpperCase().slice(0,2):"?",d=(c==null?void 0:c.color)??"#94a3b8",f=this.escapeHtml((c==null?void 0:c.name)??"Unknown"),u=this.formatTime(a.createdAt),g=i===a.userId,v=a.editedAt?'<span style="font-size:10px;color:#94a3b8;font-style:italic;">(edited)</span>':"";if(this.editingPopoverCommentId===a.id)return`
|
|
1306
1306
|
<div style="margin-bottom:10px;" data-comment-id="${a.id}">
|
|
1307
1307
|
<div style="display:flex;align-items:center;gap:7px;margin-bottom:4px;">
|
|
1308
1308
|
<div style="width:22px;height:22px;border-radius:50%;background:${d};color:#fff;display:flex;align-items:center;justify-content:center;font-size:9px;font-weight:700;flex-shrink:0;">${p}</div>
|
|
1309
|
-
<span style="font-size:12px;font-weight:600;color:#0f172a;">${
|
|
1309
|
+
<span style="font-size:12px;font-weight:600;color:#0f172a;">${f}</span>
|
|
1310
1310
|
</div>
|
|
1311
1311
|
<div style="margin-left:29px;">
|
|
1312
1312
|
<textarea class="edit-textarea" style="width:100%;padding:6px 10px;border:1.5px solid #e2e8f0;border-radius:6px;font-size:12px;font-family:inherit;outline:none;resize:vertical;min-height:48px;color:#0f172a;box-sizing:border-box;">${this.escapeHtml(a.body)}</textarea>
|
|
@@ -1316,29 +1316,29 @@
|
|
|
1316
1316
|
</div>
|
|
1317
1317
|
</div>
|
|
1318
1318
|
</div>
|
|
1319
|
-
`;const
|
|
1320
|
-
<img src="${this.escapeHtml($t)}" alt="${this.escapeHtml(
|
|
1321
|
-
</div>`}return
|
|
1319
|
+
`;const k=a.body&&a.body!=="(attachment)"?a.body.replace(/@(\w+)/g,'<span style="color:#6366f1;font-weight:600;background:#eef2ff;padding:0 3px;border-radius:3px;">@$1</span>'):"",w=(a.attachments??[]).map(y=>{if(y.type==="image"){const $t=y.thumbnailUrl||y.url;return`<div class="popover-attachment-img" data-full-url="${this.escapeHtml(y.url)}" style="margin:4px 0 4px 29px;cursor:pointer;">
|
|
1320
|
+
<img src="${this.escapeHtml($t)}" alt="${this.escapeHtml(y.filename)}" style="max-width:180px;max-height:120px;border-radius:8px;border:1px solid #e2e8f0;display:block;" />
|
|
1321
|
+
</div>`}return y.type==="audio"?`<div class="popover-attachment-audio" data-url="${this.escapeHtml(y.url)}" data-duration="${y.durationMs??""}" style="margin:4px 0 4px 29px;"></div>`:y.type==="video"?`<div class="popover-attachment-video" data-url="${this.escapeHtml(y.url)}" data-poster="${this.escapeHtml(y.thumbnailUrl??"")}" style="margin:4px 0 4px 29px;"></div>`:""}).join(""),C=g?`<div class="popover-comment-actions" style="display:flex;gap:2px;margin-top:2px;margin-left:29px;">
|
|
1322
1322
|
<button class="edit-btn" data-comment-id="${a.id}" style="border:none;background:none;cursor:pointer;color:#94a3b8;padding:3px;border-radius:4px;display:flex;align-items:center;transition:all 0.15s;" title="Edit"
|
|
1323
1323
|
onmouseover="this.style.color='#6366f1';this.style.background='#eef2ff'"
|
|
1324
1324
|
onmouseout="this.style.color='#94a3b8';this.style.background='none'">${Fi}</button>
|
|
1325
1325
|
<button class="delete-btn" data-comment-id="${a.id}" style="border:none;background:none;cursor:pointer;color:#94a3b8;padding:3px;border-radius:4px;display:flex;align-items:center;transition:all 0.15s;" title="Delete"
|
|
1326
1326
|
onmouseover="this.style.color='#ef4444';this.style.background='#fef2f2'"
|
|
1327
1327
|
onmouseout="this.style.color='#94a3b8';this.style.background='none'">${Wi}</button>
|
|
1328
|
-
</div>`:"",
|
|
1328
|
+
</div>`:"",S=this.buildReactionPillsHtml(a.id);return`
|
|
1329
1329
|
<div class="popover-comment" style="margin-bottom:10px;" data-comment-id="${a.id}">
|
|
1330
1330
|
<div style="display:flex;align-items:center;gap:7px;margin-bottom:2px;">
|
|
1331
1331
|
<div style="width:22px;height:22px;border-radius:50%;background:${d};color:#fff;display:flex;align-items:center;justify-content:center;font-size:9px;font-weight:700;flex-shrink:0;">${p}</div>
|
|
1332
|
-
<span style="font-size:12px;font-weight:600;color:#0f172a;">${
|
|
1333
|
-
<span style="font-size:10px;color:#94a3b8;">${
|
|
1334
|
-
${
|
|
1332
|
+
<span style="font-size:12px;font-weight:600;color:#0f172a;">${f}</span>
|
|
1333
|
+
<span style="font-size:10px;color:#94a3b8;">${u}</span>
|
|
1334
|
+
${v}
|
|
1335
1335
|
</div>
|
|
1336
|
-
${
|
|
1337
|
-
${$}
|
|
1336
|
+
${k?`<div style="font-size:13px;color:#334155;line-height:1.45;margin-left:29px;word-wrap:break-word;">${k}</div>`:""}
|
|
1338
1337
|
${w}
|
|
1339
|
-
${
|
|
1338
|
+
${C}
|
|
1339
|
+
${S}
|
|
1340
1340
|
</div>
|
|
1341
|
-
`}).join(""),t.querySelectorAll(".edit-btn").forEach(a=>{a.addEventListener("click",()=>{this.editingPopoverCommentId=a.dataset.commentId,this.refreshPopoverComments(e)})}),t.querySelectorAll(".delete-btn").forEach(a=>{a.addEventListener("click",()=>{this.client.deleteComment(a.dataset.commentId)})});const s=t.querySelector(".edit-save"),o=t.querySelector(".edit-cancel"),r=t.querySelector(".edit-textarea");s&&r&&s.addEventListener("click",()=>{const a=r.value.trim();if(!a)return;const c=[...a.matchAll(/@(\w+)/g)].map(p=>p[1]);this.client.editComment(this.editingPopoverCommentId,a,c),this.editingPopoverCommentId=null}),o&&o.addEventListener("click",()=>{this.editingPopoverCommentId=null,this.refreshPopoverComments(e)}),t.querySelectorAll("[data-reaction-emoji]").forEach(a=>{a.addEventListener("click",c=>{c.stopPropagation();const p=a.dataset.reactionEmoji,d=a.dataset.reactionTarget,
|
|
1341
|
+
`}).join(""),t.querySelectorAll(".edit-btn").forEach(a=>{a.addEventListener("click",()=>{this.editingPopoverCommentId=a.dataset.commentId,this.refreshPopoverComments(e)})}),t.querySelectorAll(".delete-btn").forEach(a=>{a.addEventListener("click",()=>{this.client.deleteComment(a.dataset.commentId)})});const s=t.querySelector(".edit-save"),o=t.querySelector(".edit-cancel"),r=t.querySelector(".edit-textarea");s&&r&&s.addEventListener("click",()=>{const a=r.value.trim();if(!a)return;const c=[...a.matchAll(/@(\w+)/g)].map(p=>p[1]);this.client.editComment(this.editingPopoverCommentId,a,c),this.editingPopoverCommentId=null}),o&&o.addEventListener("click",()=>{this.editingPopoverCommentId=null,this.refreshPopoverComments(e)}),t.querySelectorAll("[data-reaction-emoji]").forEach(a=>{a.addEventListener("click",c=>{c.stopPropagation();const p=a.dataset.reactionEmoji,d=a.dataset.reactionTarget,f=a.dataset.reactionId;f?this.client.removeReaction(f):this.client.addReaction(d,"comment",p)})}),t.querySelectorAll(".popover-reaction-add").forEach(a=>{a.addEventListener("click",c=>{c.stopPropagation();const p=a.dataset.commentId;this.popoverPickerOpen===p?(this.popoverPickerOpen=null,this.removePickerEl()):(this.popoverPickerOpen=p,this.showPickerForButton(a,p))})}),t.querySelectorAll(".popover-attachment-img").forEach(a=>{a.addEventListener("click",()=>{const c=a.dataset.fullUrl;c&&ge.open(c)})}),t.querySelectorAll(".popover-attachment-audio").forEach(a=>{const c=a.dataset.url;if(c){const p=a.dataset.duration?parseInt(a.dataset.duration):void 0,d=Pe.render(c,p);a.appendChild(d)}}),t.querySelectorAll(".popover-attachment-video").forEach(a=>{const c=a.dataset.url;if(c){const p=a.dataset.poster||void 0,d=yt.render(c,p);a.appendChild(d)}}),t.scrollTop=t.scrollHeight}addPopoverReplyForm(e){if(!this.popover)return;const t=document.createElement("div");Object.assign(t.style,{padding:"8px 14px 12px",borderTop:"1px solid #f1f5f9"});const i="border:none;background:none;cursor:pointer;color:#94a3b8;padding:6px;border-radius:6px;display:flex;align-items:center;justify-content:center;min-width:32px;min-height:32px;transition:all 0.15s;",s='width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"';t.innerHTML=`
|
|
1342
1342
|
<div style="display:flex;align-items:center;gap:4px;margin-bottom:6px;">
|
|
1343
1343
|
<input type="text" placeholder="Reply..."
|
|
1344
1344
|
style="flex:1;padding:8px 12px;border:1.5px solid #e2e8f0;border-radius:8px;font-size:13px;font-family:inherit;outline:none;color:#0f172a;min-width:0;min-height:36px;transition:border-color 0.15s;" />
|
|
@@ -1356,9 +1356,9 @@
|
|
|
1356
1356
|
</button>
|
|
1357
1357
|
<div class="reply-attachments-preview" style="flex:1;display:flex;gap:4px;flex-wrap:wrap;margin-left:4px;"></div>
|
|
1358
1358
|
</div>
|
|
1359
|
-
`;const o=t.querySelector("input"),r=t.querySelector(".reply-send"),l=t.querySelector(".reply-attachments-preview");this.upload||(this.upload=new Q(this.client));const a=[],c=d=>{const u=document.createElement("span");Object.assign(u.style,{display:"inline-
|
|
1359
|
+
`;const o=t.querySelector("input"),r=t.querySelector(".reply-send"),l=t.querySelector(".reply-attachments-preview");this.upload||(this.upload=new Q(this.client));const a=[],c=(d,f)=>{const u=document.createElement("span");Object.assign(u.style,{position:"relative",display:"inline-flex",alignItems:"center",padding:"2px 18px 2px 8px",borderRadius:"4px",background:"#f1f5f9",fontSize:"10px",color:"#64748b"}),u.textContent=f;const g=document.createElement("button");g.innerHTML="×",Object.assign(g.style,{position:"absolute",top:"-3px",right:"-3px",width:"14px",height:"14px",borderRadius:"50%",background:"#ef4444",color:"#fff",border:"none",fontSize:"10px",lineHeight:"1",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",padding:"0",fontWeight:"700"}),g.addEventListener("click",()=>{const v=a.indexOf(d);v!==-1&&a.splice(v,1),u.remove()}),u.appendChild(g),l.appendChild(u)};t.querySelector(".reply-attach-img").addEventListener("click",async()=>{const d=await this.upload.pickFile("image/*");d&&(a.push(d.id),c(d.id,"📎 Image"))}),t.querySelector(".reply-attach-mic").addEventListener("click",async()=>{this.audioRecorder||(this.audioRecorder=new _e);const d=await this.audioRecorder.startRecording(t);if(d){const f=await this.upload.uploadBlob(d,"audio.webm");f&&(a.push(f.id),c(f.id,"🎤 Audio"))}}),t.querySelector(".reply-attach-video").addEventListener("click",async()=>{this.videoRecorder||(this.videoRecorder=new Te);const d=await this.videoRecorder.startRecording(t);if(d){const f=await this.upload.uploadBlob(d.blob,"video.webm");f&&(a.push(f.id),c(f.id,"🎥 Video"))}});const p=()=>{const d=o.value.trim();if(!d&&a.length===0)return;const f=[...(d||"").matchAll(/@(\w+)/g)].map(u=>u[1]);this.client.reply(e.id,d,f,a.length>0?[...a]:void 0),o.value="",a.length=0,l.innerHTML=""};r.addEventListener("click",p),o.addEventListener("input",()=>{const d=Date.now(),f=this.lastTypingSendPins.get(e.id)??0;d-f>=2e3&&(this.client.sendTyping(e.id),this.lastTypingSendPins.set(e.id,d))}),o.addEventListener("keydown",d=>{d.key==="Enter"&&(d.preventDefault(),p()),d.key==="Escape"&&this.closePopover(),d.stopPropagation()}),this.popover.appendChild(t)}removePickerEl(){var e;(e=this.pickerEl)==null||e.remove(),this.pickerEl=null}showPickerForButton(e,t){this.removePickerEl();const i=e.getBoundingClientRect();this.pickerEl=document.createElement("div"),Object.assign(this.pickerEl.style,{position:"fixed",left:`${i.left}px`,top:`${i.top-4}px`,transform:"translateY(-100%)",display:"flex",gap:"2px",padding:"4px 6px",background:"#fff",border:"1px solid #e2e8f0",borderRadius:"8px",boxShadow:"0 4px 24px rgba(0,0,0,0.12)",zIndex:"10002",fontFamily:de});for(const s of Bi){const o=document.createElement("button");Object.assign(o.style,{border:"none",background:"none",cursor:"pointer",fontSize:"16px",padding:"4px",borderRadius:"4px",lineHeight:"1"}),o.textContent=s,o.addEventListener("click",r=>{r.stopPropagation();const a=this.client.state.getReactions(t).find(c=>{var p;return c.emoji===s&&c.userId===((p=this.client.state.user)==null?void 0:p.id)});a?this.client.removeReaction(a.id):this.client.addReaction(t,"comment",s),this.popoverPickerOpen=null,this.removePickerEl()}),this.pickerEl.appendChild(o)}document.body.appendChild(this.pickerEl)}buildReactionPillsHtml(e){var a;const t=this.client.state.getReactions(e),i=(a=this.client.state.user)==null?void 0:a.id,s=new Map;for(const c of t){const p=s.get(c.emoji)??{count:0,ownId:null};p.count++,c.userId===i&&(p.ownId=c.id),s.set(c.emoji,p)}const o="display:inline-flex;align-items:center;gap:3px;padding:2px 8px;border-radius:12px;border:1px solid #e2e8f0;background:#fff;font-size:12px;cursor:pointer;transition:all 0.15s;line-height:1.4;",r=o+"background:#eef2ff;border-color:#6366f1;";let l='<div style="margin-left:29px;display:flex;gap:4px;flex-wrap:wrap;margin-top:4px;">';for(const[c,{count:p,ownId:d}]of s){const f=d?r:o;l+=`<button data-reaction-emoji="${c}" data-reaction-target="${e}" ${d?`data-reaction-id="${d}"`:""} style="${f}">
|
|
1360
1360
|
<span>${c}</span><span style="font-size:11px;font-weight:600;color:#64748b;">${p}</span>
|
|
1361
|
-
</button>`}return l+=`<button class="popover-reaction-add" data-comment-id="${e}" style="display:inline-flex;align-items:center;justify-content:center;width:26px;height:26px;border-radius:50%;border:1px dashed #e2e8f0;background:none;cursor:pointer;color:#94a3b8;font-size:14px;">+</button>`,l+="</div>",l}updatePopoverTyping(e){if(!this.popover)return;let t=this.popover.querySelector(".popover-typing");if(!t){t=document.createElement("div"),t.className="popover-typing",Object.assign(t.style,{padding:"0 14px 4px",fontSize:"11px",color:"#94a3b8",fontStyle:"italic",minHeight:"16px"});const s=this.popover.lastElementChild;s&&this.popover.insertBefore(t,s)}const i=this.client.state.getTypingUsers(e).filter(s=>{var o;return s!==((o=this.client.state.user)==null?void 0:o.id)}).map(s=>{const o=this.client.state.presence.find(r=>r.user.id===s);return(o==null?void 0:o.user.name)??"Someone"});i.length===0?t.textContent="":i.length===1?t.textContent=`${i[0]} is typing...`:t.textContent=`${i.join(", ")} are typing...`}formatTime(e){const t=new Date(e),s=new Date().getTime()-t.getTime(),o=Math.floor(s/6e4);if(o<1)return"now";if(o<60)return`${o}m`;const r=Math.floor(o/60);return r<24?`${r}h`:t.toLocaleDateString()}resolvePosition(e){if(e.selector&&e.elementOffsetX!=null&&e.elementOffsetY!=null)try{const t=document.querySelector(e.selector);if(t){const i=t.getBoundingClientRect();return{x:i.left+e.elementOffsetX*i.width,y:i.top+e.elementOffsetY*i.height}}}catch{}return{x:e.x*window.innerWidth,y:e.y*window.innerHeight}}renderPins(){if(!this.container)return;const e=this.threads.filter(i=>i.position&&!i.resolved),t=new Set(e.map(i=>i.id));for(const[i,s]of this.pinEls)t.has(i)||(s.remove(),this.pinEls.delete(i));e.forEach((i,s)=>{const o=i.position;let r=this.pinEls.get(i.id);r||(r=document.createElement("div"),Object.assign(r.style,{position:"fixed",width:"24px",height:"24px",borderRadius:"50%",background:"#6366f1",color:"#fff",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"11px",fontWeight:"700",fontFamily:de,cursor:"pointer",pointerEvents:"auto",boxShadow:"0 2px 8px rgba(99,102,241,0.4)",border:"2px solid #fff",transition:"left 0.15s ease, top 0.15s ease, transform 0.15s ease",zIndex:"9997",transform:"translate(-50%, -50%)"}),r.addEventListener("mouseenter",()=>{r.style.transform="translate(-50%, -50%) scale(1.15)"}),r.addEventListener("mouseleave",()=>{r.style.transform="translate(-50%, -50%)"}),r.addEventListener("click",()=>{if(this.popover&&this.popover.dataset.threadId===i.id){this.closePopover();return}const a=this.threads.find(c=>c.id===i.id);a&&this.showThreadPopover(a,r)}),this.container.appendChild(r),this.pinEls.set(i.id,r)),r.textContent=`${s+1}`;const l=this.resolvePosition(o);r.style.left=`${l.x}px`,r.style.top=`${l.y}px`})}}var qi=Object.defineProperty,Xi=Object.getOwnPropertyDescriptor,L=(n,e,t,i)=>{for(var s=i>1?void 0:i?Xi(e,t):e,o=n.length-1,r;o>=0;o--)(r=n[o])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&qi(e,t,s),s};const Yi=["👍","👎","❤️","🎉","👀","🚀"];let M=class extends
|
|
1361
|
+
</button>`}return l+=`<button class="popover-reaction-add" data-comment-id="${e}" style="display:inline-flex;align-items:center;justify-content:center;width:26px;height:26px;border-radius:50%;border:1px dashed #e2e8f0;background:none;cursor:pointer;color:#94a3b8;font-size:14px;">+</button>`,l+="</div>",l}updatePopoverTyping(e){if(!this.popover)return;let t=this.popover.querySelector(".popover-typing");if(!t){t=document.createElement("div"),t.className="popover-typing",Object.assign(t.style,{padding:"0 14px 4px",fontSize:"11px",color:"#94a3b8",fontStyle:"italic",minHeight:"16px"});const s=this.popover.lastElementChild;s&&this.popover.insertBefore(t,s)}const i=this.client.state.getTypingUsers(e).filter(s=>{var o;return s!==((o=this.client.state.user)==null?void 0:o.id)}).map(s=>{const o=this.client.state.presence.find(r=>r.user.id===s);return(o==null?void 0:o.user.name)??"Someone"});i.length===0?t.textContent="":i.length===1?t.textContent=`${i[0]} is typing...`:t.textContent=`${i.join(", ")} are typing...`}formatTime(e){const t=new Date(e),s=new Date().getTime()-t.getTime(),o=Math.floor(s/6e4);if(o<1)return"now";if(o<60)return`${o}m`;const r=Math.floor(o/60);return r<24?`${r}h`:t.toLocaleDateString()}resolvePosition(e){if(e.selector&&e.elementOffsetX!=null&&e.elementOffsetY!=null)try{const t=document.querySelector(e.selector);if(t){const i=t.getBoundingClientRect();return{x:i.left+e.elementOffsetX*i.width,y:i.top+e.elementOffsetY*i.height}}}catch{}return{x:e.x*window.innerWidth,y:e.y*window.innerHeight}}renderPins(){if(!this.container)return;const e=this.threads.filter(i=>i.position&&!i.resolved),t=new Set(e.map(i=>i.id));for(const[i,s]of this.pinEls)t.has(i)||(s.remove(),this.pinEls.delete(i));e.forEach((i,s)=>{const o=i.position;let r=this.pinEls.get(i.id);r||(r=document.createElement("div"),Object.assign(r.style,{position:"fixed",width:"24px",height:"24px",borderRadius:"50%",background:"#6366f1",color:"#fff",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"11px",fontWeight:"700",fontFamily:de,cursor:"pointer",pointerEvents:"auto",boxShadow:"0 2px 8px rgba(99,102,241,0.4)",border:"2px solid #fff",transition:"left 0.15s ease, top 0.15s ease, transform 0.15s ease",zIndex:"9997",transform:"translate(-50%, -50%)"}),r.addEventListener("mouseenter",()=>{r.style.transform="translate(-50%, -50%) scale(1.15)"}),r.addEventListener("mouseleave",()=>{r.style.transform="translate(-50%, -50%)"}),r.addEventListener("click",()=>{if(this.popover&&this.popover.dataset.threadId===i.id){this.closePopover();return}const a=this.threads.find(c=>c.id===i.id);a&&this.showThreadPopover(a,r)}),this.container.appendChild(r),this.pinEls.set(i.id,r)),r.textContent=`${s+1}`;const l=this.resolvePosition(o);r.style.left=`${l.x}px`,r.style.top=`${l.y}px`})}}var qi=Object.defineProperty,Xi=Object.getOwnPropertyDescriptor,L=(n,e,t,i)=>{for(var s=i>1?void 0:i?Xi(e,t):e,o=n.length-1,r;o>=0;o--)(r=n[o])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&qi(e,t,s),s};const Yi=["👍","👎","❤️","🎉","👀","🚀"];let M=class extends _{constructor(){super(...arguments),this.highlightThreadId=null,this.threadsVersion=0,this.replyingTo=null,this.editingCommentId=null,this.editBody="",this.pickerOpenForComment=null,this.typingByThread=new Map,this.reactionsVersion=0,this.typingTimers=new Map,this.lastTypingSend=new Map,this.replyAttachmentIds=[]}get threads(){return this.threadsVersion,this.client?[...this.client.state.threads]:[]}connectedCallback(){super.connectedCallback(),this.ensureListener()}disconnectedCallback(){super.disconnectedCallback(),this.teardownListeners()}willUpdate(n){this.client&&!this.unsub&&this.ensureListener()}updated(n){var e,t;(e=this.shadowRoot)==null||e.querySelectorAll(".audio-player-host").forEach(i=>{if(i.children.length>0)return;const s=i.dataset.url;if(s){const o=i.dataset.duration?parseInt(i.dataset.duration):void 0;i.appendChild(Pe.render(s,o))}}),(t=this.shadowRoot)==null||t.querySelectorAll(".video-player-host").forEach(i=>{if(i.children.length>0)return;const s=i.dataset.url;s&&i.appendChild(yt.render(s,i.dataset.poster||void 0))})}teardownListeners(){var n,e,t,i;(n=this.unsub)==null||n.call(this),this.unsub=void 0,(e=this.authUnsub)==null||e.call(this),this.authUnsub=void 0,(t=this.reactionUnsub)==null||t.call(this),this.reactionUnsub=void 0,(i=this.typingUnsub)==null||i.call(this),this.typingUnsub=void 0;for(const s of this.typingTimers.values())clearTimeout(s);this.typingTimers.clear()}ensureListener(){this.client&&(this.teardownListeners(),this.threadsVersion++,this.setupListener())}setupListener(){this.client&&(this.unsub=this.client.state.on("threads",()=>{this.threadsVersion++}),this.authUnsub=this.client.state.on("auth",()=>{this.threadsVersion++}),this.reactionUnsub=this.client.state.on("reactions",()=>{this.reactionsVersion++}),this.typingUnsub=this.client.state.on("typing",({threadId:n})=>{this.refreshTyping(n)}))}refreshTyping(n){const t=this.client.state.getTypingUsers(n).filter(s=>{var o;return s!==((o=this.client.state.user)==null?void 0:o.id)}).map(s=>{const o=this.client.state.presence.find(r=>r.user.id===s);return(o==null?void 0:o.user.name)??"Someone"}),i=new Map(this.typingByThread);i.set(n,t),this.typingByThread=i,this.typingTimers.has(n)&&clearTimeout(this.typingTimers.get(n)),this.typingTimers.set(n,setTimeout(()=>{this.refreshTyping(n)},3500))}handleTypingInput(n){const e=Date.now(),t=this.lastTypingSend.get(n)??0;e-t>=2e3&&(this.client.sendTyping(n),this.lastTypingSend.set(n,e))}toggleReaction(n,e){var o;const t=this.client.state.getReactions(n),i=(o=this.client.state.user)==null?void 0:o.id,s=t.find(r=>r.emoji===e&&r.userId===i);s?this.client.removeReaction(s.id):this.client.addReaction(n,"comment",e),this.pickerOpenForComment=null}fireClose(){this.dispatchEvent(new CustomEvent("panel-close",{bubbles:!0,composed:!0}))}scrollToThread(n){this.updateComplete.then(()=>{var t;const e=(t=this.shadowRoot)==null?void 0:t.querySelector(`[data-thread-id="${n}"]`);e==null||e.scrollIntoView({behavior:"smooth",block:"center"})})}parseMentions(n){return n.split(/(@\w+)/g).map(t=>t.startsWith("@")?h`<span class="mention">${t}</span>`:t)}getInitials(n){return n.split(" ").map(e=>e[0]).join("").toUpperCase().slice(0,2)}getUserForComment(n){return this.client.state.getUser(n)}formatTime(n){const e=new Date(n),i=new Date().getTime()-e.getTime(),s=Math.floor(i/6e4);if(s<1)return"now";if(s<60)return`${s}m`;const o=Math.floor(s/60);return o<24?`${o}h`:e.toLocaleDateString()}async handleAttachImage(){this.upload||(this.upload=new Q(this.client));const n=await this.upload.pickFile("image/*");n&&(this.replyAttachmentIds.push(n.id),this.requestUpdate())}async handleRecordAudio(n){var i;this.upload||(this.upload=new Q(this.client)),this.audioRecorder||(this.audioRecorder=new _e);const e=(i=this.shadowRoot)==null?void 0:i.querySelector(`[data-thread-id="${n}"]`),t=await this.audioRecorder.startRecording(e??document.body);if(t){const s=await this.upload.uploadBlob(t,"audio.webm");s&&(this.replyAttachmentIds.push(s.id),this.requestUpdate())}}async handleRecordVideo(n){var i;this.upload||(this.upload=new Q(this.client)),this.videoRecorder||(this.videoRecorder=new Te);const e=(i=this.shadowRoot)==null?void 0:i.querySelector(`[data-thread-id="${n}"]`),t=await this.videoRecorder.startRecording(e??document.body);if(t){const s=await this.upload.uploadBlob(t.blob,"video.webm");s&&(this.replyAttachmentIds.push(s.id),this.requestUpdate())}}removeReplyAttachment(n){this.replyAttachmentIds=this.replyAttachmentIds.filter(e=>e!==n),this.requestUpdate()}handleReply(n,e){e.preventDefault();const i=e.target.querySelector("input"),s=i.value.trim();if(!s&&this.replyAttachmentIds.length===0)return;const o=[...(s||"").matchAll(/@(\w+)/g)].map(r=>r[1]);this.client.reply(n,s,o,this.replyAttachmentIds.length>0?[...this.replyAttachmentIds]:void 0),i.value="",this.replyAttachmentIds=[],this.replyingTo=null}isOwnComment(n){var e,t;return((t=(e=this.client)==null?void 0:e.state.user)==null?void 0:t.id)===n.userId}startEdit(n){this.editingCommentId=n.id,this.editBody=n.body}cancelEdit(){this.editingCommentId=null,this.editBody=""}saveEdit(n){const e=this.editBody.trim();if(!e)return;const t=[...e.matchAll(/@(\w+)/g)].map(i=>i[1]);this.client.editComment(n,e,t),this.editingCommentId=null,this.editBody=""}deleteComment(n){this.client.deleteComment(n)}renderEditForm(n){return h`
|
|
1362
1362
|
<div class="edit-form">
|
|
1363
1363
|
<textarea
|
|
1364
1364
|
.value=${this.editBody}
|
|
@@ -1392,10 +1392,10 @@
|
|
|
1392
1392
|
<button @click=${r=>{r.stopPropagation(),this.toggleReaction(n.id,o)}}>${o}</button>
|
|
1393
1393
|
`)}
|
|
1394
1394
|
</div>
|
|
1395
|
-
`:
|
|
1395
|
+
`:m}
|
|
1396
1396
|
</button>
|
|
1397
1397
|
</div>
|
|
1398
|
-
`}renderTypingIndicator(n){const e=this.typingByThread.get(n)??[];if(e.length===0)return
|
|
1398
|
+
`}renderTypingIndicator(n){const e=this.typingByThread.get(n)??[];if(e.length===0)return m;const t=e.length===1?`${e[0]} is typing...`:`${e.join(", ")} are typing...`;return h`<div class="typing-indicator">${t}</div>`}sortedThreads(){return[...this.threads].sort((n,e)=>{if(n.resolved!==e.resolved)return n.resolved?1:-1;const t=n.comments.length?new Date(n.comments[n.comments.length-1].createdAt).getTime():0;return(e.comments.length?new Date(e.comments[e.comments.length-1].createdAt).getTime():0)-t})}render(){const n=this.sortedThreads();return h`
|
|
1399
1399
|
<div class="panel">
|
|
1400
1400
|
<div class="panel-header">
|
|
1401
1401
|
<span class="panel-title">
|
|
@@ -1403,7 +1403,7 @@
|
|
|
1403
1403
|
<span class="thread-count">${this.threads.length}</span>
|
|
1404
1404
|
</span>
|
|
1405
1405
|
<button class="close-btn" @click=${this.fireClose} title="Close">
|
|
1406
|
-
${
|
|
1406
|
+
${E(le,16)}
|
|
1407
1407
|
</button>
|
|
1408
1408
|
</div>
|
|
1409
1409
|
|
|
@@ -1418,7 +1418,7 @@
|
|
|
1418
1418
|
Use the pin button to comment anywhere on the page
|
|
1419
1419
|
</div>
|
|
1420
1420
|
</div>
|
|
1421
|
-
`}renderAttachments(n){return!n||n.length===0?
|
|
1421
|
+
`}renderAttachments(n){return!n||n.length===0?m:h`
|
|
1422
1422
|
${n.map(e=>{if(e.type==="image"){const t=e.thumbnailUrl||e.url;return h`
|
|
1423
1423
|
<div class="comment-attachment-media">
|
|
1424
1424
|
<img
|
|
@@ -1436,18 +1436,18 @@
|
|
|
1436
1436
|
<div class="comment-attachment-media" id="video-${e.id}">
|
|
1437
1437
|
${this.renderVideoPlayer(e)}
|
|
1438
1438
|
</div>
|
|
1439
|
-
`:
|
|
1439
|
+
`:m})}
|
|
1440
1440
|
`}renderAudioPlayer(n){const e=document.createElement("div"),t=Pe.render(n.url,n.durationMs);return e.appendChild(t),h`<div class="audio-player-host" data-url=${n.url} data-duration=${n.durationMs??""}></div>`}renderVideoPlayer(n){return h`<div class="video-player-host" data-url=${n.url} data-poster=${n.thumbnailUrl??""}></div>`}renderThread(n){const e=this.highlightThreadId===n.id;return h`
|
|
1441
1441
|
<div
|
|
1442
1442
|
class="thread ${n.resolved?"resolved":""} ${e?"highlighted":""}"
|
|
1443
1443
|
data-thread-id=${n.id}
|
|
1444
1444
|
>
|
|
1445
1445
|
${n.position?h`<div class="pin-badge">
|
|
1446
|
-
${
|
|
1446
|
+
${E(xt,12)}
|
|
1447
1447
|
Pinned
|
|
1448
|
-
</div>`:
|
|
1448
|
+
</div>`:m}
|
|
1449
1449
|
${n.comments.map((t,i)=>{const s=this.getUserForComment(t.userId),o=this.isOwnComment(t),r=this.editingCommentId===t.id;return h`
|
|
1450
|
-
${i>0?h`<div class="comment-divider"></div>`:
|
|
1450
|
+
${i>0?h`<div class="comment-divider"></div>`:m}
|
|
1451
1451
|
<div class="comment">
|
|
1452
1452
|
<div class="comment-header">
|
|
1453
1453
|
<div
|
|
@@ -1458,16 +1458,16 @@
|
|
|
1458
1458
|
</div>
|
|
1459
1459
|
<span class="comment-author">${(s==null?void 0:s.name)??"Unknown"}</span>
|
|
1460
1460
|
<span class="comment-time">${this.formatTime(t.createdAt)}</span>
|
|
1461
|
-
${t.editedAt?h`<span class="edited-badge">(edited)</span>`:
|
|
1461
|
+
${t.editedAt?h`<span class="edited-badge">(edited)</span>`:m}
|
|
1462
1462
|
</div>
|
|
1463
1463
|
${r?this.renderEditForm(t):h`
|
|
1464
|
-
${t.body&&t.body!=="(attachment)"?h`<div class="comment-body">${this.parseMentions(t.body)}</div>`:
|
|
1464
|
+
${t.body&&t.body!=="(attachment)"?h`<div class="comment-body">${this.parseMentions(t.body)}</div>`:m}
|
|
1465
1465
|
${this.renderAttachments(t.attachments??[])}
|
|
1466
1466
|
`}
|
|
1467
1467
|
${o&&!r?h`<div class="comment-actions">
|
|
1468
|
-
<button @click=${()=>this.startEdit(t)} title="Edit">${
|
|
1469
|
-
<button class="danger" @click=${()=>this.deleteComment(t.id)} title="Delete">${
|
|
1470
|
-
</div>`:
|
|
1468
|
+
<button @click=${()=>this.startEdit(t)} title="Edit">${E(ki,14)}</button>
|
|
1469
|
+
<button class="danger" @click=${()=>this.deleteComment(t.id)} title="Delete">${E(Ei,14)}</button>
|
|
1470
|
+
</div>`:m}
|
|
1471
1471
|
${this.renderReactions(t)}
|
|
1472
1472
|
</div>
|
|
1473
1473
|
`})}
|
|
@@ -1506,27 +1506,34 @@
|
|
|
1506
1506
|
class="reply-media-btn"
|
|
1507
1507
|
title="Attach image"
|
|
1508
1508
|
@click=${()=>this.handleAttachImage()}
|
|
1509
|
-
>${
|
|
1509
|
+
>${E(wi,16)}</button>
|
|
1510
1510
|
<button
|
|
1511
1511
|
type="button"
|
|
1512
1512
|
class="reply-media-btn"
|
|
1513
1513
|
title="Record audio"
|
|
1514
1514
|
@click=${()=>this.handleRecordAudio(n.id)}
|
|
1515
|
-
>${
|
|
1515
|
+
>${E(yi,16)}</button>
|
|
1516
1516
|
<button
|
|
1517
1517
|
type="button"
|
|
1518
1518
|
class="reply-media-btn"
|
|
1519
1519
|
title="Record video"
|
|
1520
1520
|
@click=${()=>this.handleRecordVideo(n.id)}
|
|
1521
|
-
>${
|
|
1521
|
+
>${E(Pi,16)}</button>
|
|
1522
1522
|
<div class="reply-preview">
|
|
1523
|
-
${this.replyAttachmentIds.map((t,i)=>h`<span class="reply-preview-badge">
|
|
1523
|
+
${this.replyAttachmentIds.map((t,i)=>h`<span class="reply-preview-badge">
|
|
1524
|
+
Attached #${i+1}
|
|
1525
|
+
<button
|
|
1526
|
+
type="button"
|
|
1527
|
+
class="reply-preview-remove"
|
|
1528
|
+
@click=${()=>this.removeReplyAttachment(t)}
|
|
1529
|
+
>×</button>
|
|
1530
|
+
</span>`)}
|
|
1524
1531
|
</div>
|
|
1525
1532
|
</div>
|
|
1526
1533
|
</form>
|
|
1527
|
-
`:
|
|
1534
|
+
`:m}
|
|
1528
1535
|
</div>
|
|
1529
|
-
`}};M.styles=[K,ce,xe,
|
|
1536
|
+
`}};M.styles=[K,ce,xe,A`
|
|
1530
1537
|
:host {
|
|
1531
1538
|
display: block;
|
|
1532
1539
|
}
|
|
@@ -1767,7 +1774,10 @@
|
|
|
1767
1774
|
}
|
|
1768
1775
|
|
|
1769
1776
|
.reply-preview-badge {
|
|
1770
|
-
|
|
1777
|
+
position: relative;
|
|
1778
|
+
display: inline-flex;
|
|
1779
|
+
align-items: center;
|
|
1780
|
+
gap: 4px;
|
|
1771
1781
|
padding: 2px 8px;
|
|
1772
1782
|
border-radius: 4px;
|
|
1773
1783
|
background: var(--pw-surface-hover);
|
|
@@ -1775,6 +1785,24 @@
|
|
|
1775
1785
|
color: var(--pw-text-muted);
|
|
1776
1786
|
}
|
|
1777
1787
|
|
|
1788
|
+
.reply-preview-remove {
|
|
1789
|
+
border: none;
|
|
1790
|
+
background: var(--pw-danger, #ef4444);
|
|
1791
|
+
color: #fff;
|
|
1792
|
+
width: 14px;
|
|
1793
|
+
height: 14px;
|
|
1794
|
+
border-radius: 50%;
|
|
1795
|
+
font-size: 10px;
|
|
1796
|
+
line-height: 1;
|
|
1797
|
+
cursor: pointer;
|
|
1798
|
+
display: inline-flex;
|
|
1799
|
+
align-items: center;
|
|
1800
|
+
justify-content: center;
|
|
1801
|
+
padding: 0;
|
|
1802
|
+
font-weight: 700;
|
|
1803
|
+
flex-shrink: 0;
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1778
1806
|
.reply-form .pw-btn-primary {
|
|
1779
1807
|
padding: 8px 14px;
|
|
1780
1808
|
font-size: 12px;
|
|
@@ -2043,19 +2071,19 @@
|
|
|
2043
2071
|
background: var(--pw-surface-hover);
|
|
2044
2072
|
color: var(--pw-text);
|
|
2045
2073
|
}
|
|
2046
|
-
`];L([
|
|
2074
|
+
`];L([b({attribute:!1})],M.prototype,"client",2);L([b()],M.prototype,"highlightThreadId",2);L([x()],M.prototype,"threadsVersion",2);L([x()],M.prototype,"replyingTo",2);L([x()],M.prototype,"editingCommentId",2);L([x()],M.prototype,"editBody",2);L([x()],M.prototype,"pickerOpenForComment",2);L([x()],M.prototype,"typingByThread",2);L([x()],M.prototype,"reactionsVersion",2);M=L([O("pulse-widget-comments-panel")],M);var Ki=Object.defineProperty,Gi=Object.getOwnPropertyDescriptor,ze=(n,e,t,i)=>{for(var s=i>1?void 0:i?Gi(e,t):e,o=n.length-1,r;o>=0;o--)(r=n[o])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&Ki(e,t,s),s};const Zi={"comment:created":"left a comment","comment:mention":"mentioned you","comment:reply":"replied to your comment","thread:resolved":"resolved a thread","reaction:added":"reacted to your comment"},Ji={"comment:created":"💬","comment:mention":"📣","comment:reply":"↩️","thread:resolved":"✅","reaction:added":"🎉"};let se=class extends _{constructor(){super(...arguments),this.notifications=[]}connectedCallback(){super.connectedCallback(),this.setupListener()}disconnectedCallback(){var n;super.disconnectedCallback(),(n=this.unsub)==null||n.call(this)}updated(n){var e;n.has("client")&&this.client&&((e=this.unsub)==null||e.call(this),this.setupListener())}setupListener(){this.client&&(this.notifications=this.client.state.notifications,this.unsub=this.client.state.on("notifications",n=>{this.notifications=[...n]}))}fireClose(){this.dispatchEvent(new CustomEvent("panel-close",{bubbles:!0,composed:!0}))}handleClick(n){n.read||this.client.markRead(n.id)}getActorName(n){var e;return((e=this.client.state.getUser(n))==null?void 0:e.name)??"Someone"}formatTime(n){const e=new Date(n),i=new Date().getTime()-e.getTime(),s=Math.floor(i/6e4);if(s<1)return"now";if(s<60)return`${s}m`;const o=Math.floor(s/60);return o<24?`${o}h`:e.toLocaleDateString()}render(){const n=this.notifications.filter(e=>!e.read).length;return h`
|
|
2047
2075
|
<div class="panel">
|
|
2048
2076
|
<div class="panel-header">
|
|
2049
2077
|
<span class="panel-title">
|
|
2050
2078
|
Notifications
|
|
2051
|
-
${n>0?h`<span class="unread-badge">${n}</span>`:
|
|
2079
|
+
${n>0?h`<span class="unread-badge">${n}</span>`:m}
|
|
2052
2080
|
</span>
|
|
2053
2081
|
<div style="display:flex;align-items:center;gap:4px;">
|
|
2054
2082
|
${n>0?h`<button class="mark-all" @click=${()=>this.client.markAllRead()}>
|
|
2055
2083
|
Mark all read
|
|
2056
|
-
</button>`:
|
|
2084
|
+
</button>`:m}
|
|
2057
2085
|
<button class="close-btn" @click=${this.fireClose} title="Close">
|
|
2058
|
-
${
|
|
2086
|
+
${E(le,16)}
|
|
2059
2087
|
</button>
|
|
2060
2088
|
</div>
|
|
2061
2089
|
</div>
|
|
@@ -2082,7 +2110,7 @@
|
|
|
2082
2110
|
`)}
|
|
2083
2111
|
</div>
|
|
2084
2112
|
</div>
|
|
2085
|
-
`}};se.styles=[K,ce,xe,
|
|
2113
|
+
`}};se.styles=[K,ce,xe,A`
|
|
2086
2114
|
:host {
|
|
2087
2115
|
display: block;
|
|
2088
2116
|
}
|
|
@@ -2273,7 +2301,7 @@
|
|
|
2273
2301
|
min-height: 44px;
|
|
2274
2302
|
}
|
|
2275
2303
|
}
|
|
2276
|
-
`];ze([
|
|
2304
|
+
`];ze([b({attribute:!1})],se.prototype,"client",2);ze([x()],se.prototype,"notifications",2);se=ze([O("pulse-widget-notifications-panel")],se);const Qi=3e3;class es{constructor(e){this.container=null,this.cursors=new Map,this.cursorEls=new Map,this.cursorLastSeen=new Map,this.unsubs=[],this.enabled=!1,this.sending=!1,this.staleTimer=null,this.handleLocalCursor=t=>{t.pointerType!=="touch"&&this.client.moveCursor({x:t.clientX,y:t.clientY,pageX:t.pageX,pageY:t.pageY})},this.client=e}enable(){this.enabled||(this.enabled=!0,this.container=document.createElement("div"),this.container.id="pulse-widget-cursors",Object.assign(this.container.style,{position:"fixed",top:"0",left:"0",width:"100%",height:"100%",pointerEvents:"none",zIndex:"9998",overflow:"hidden"}),document.body.appendChild(this.container),this.unsubs.push(this.client.state.on("cursor",({userId:e,position:t})=>{const i=this.cursors.get(e);if(i)i.position=t;else{const s=this.client.state.presence.find(o=>o.user.id===e);s&&this.cursors.set(e,{userId:e,name:s.user.name,color:s.user.color,position:t})}this.cursorLastSeen.set(e,Date.now()),this.renderCursor(e)})),this.unsubs.push(this.client.state.on("presence",e=>{var i;const t=new Set(e.map(s=>s.user.id));for(const s of this.cursors.keys())t.has(s)||(this.cursors.delete(s),(i=this.cursorEls.get(s))==null||i.remove(),this.cursorEls.delete(s),this.cursorLastSeen.delete(s))})),this.setSending(!0),this.staleTimer=setInterval(()=>{const e=Date.now();for(const[t,i]of this.cursorLastSeen)if(e-i>Qi){this.cursors.delete(t);const s=this.cursorEls.get(t);s&&s.remove(),this.cursorEls.delete(t),this.cursorLastSeen.delete(t)}},1e3))}disable(){var e;this.enabled&&(this.enabled=!1,this.setSending(!1),this.unsubs.forEach(t=>t()),this.unsubs=[],this.staleTimer&&(clearInterval(this.staleTimer),this.staleTimer=null),(e=this.container)==null||e.remove(),this.container=null,this.cursors.clear(),this.cursorEls.clear(),this.cursorLastSeen.clear())}get isEnabled(){return this.enabled}get isSending(){return this.sending}setSending(e){e!==this.sending&&(this.sending=e,e?document.addEventListener("pointermove",this.handleLocalCursor):document.removeEventListener("pointermove",this.handleLocalCursor))}setReceiving(e){this.container&&(this.container.style.display=e?"":"none")}showClickRipple(e,t){if(!this.container)return;const i=this.client.state.presence.find(r=>r.user.id===e),s=(i==null?void 0:i.user.color)??"#6366f1",o=document.createElement("div");Object.assign(o.style,{position:"absolute",left:`${t.x}px`,top:`${t.y}px`,width:"0px",height:"0px",borderRadius:"50%",border:`3px solid ${s}`,transform:"translate(-50%, -50%)",pointerEvents:"none",opacity:"1",transition:"width 0.6s ease-out, height 0.6s ease-out, opacity 0.6s ease-out"}),this.container.appendChild(o),requestAnimationFrame(()=>{o.style.width="60px",o.style.height="60px",o.style.opacity="0"}),setTimeout(()=>o.remove(),600)}showEmojiDrop(e,t,i){if(!this.container)return;const s=document.createElement("div");Object.assign(s.style,{position:"absolute",left:`${i.x}px`,top:`${i.y}px`,fontSize:"32px",pointerEvents:"none",transition:"transform 2s ease-out, opacity 2s ease-out",transform:"translate(-50%, 0)",zIndex:"10",lineHeight:"1"}),s.textContent=t,this.container.appendChild(s),requestAnimationFrame(()=>{s.style.transform="translate(-50%, -80px)",s.style.opacity="0"}),setTimeout(()=>s.remove(),2e3)}destroy(){this.disable()}renderCursor(e){if(!this.container)return;const t=this.cursors.get(e);if(!t)return;let i=this.cursorEls.get(e);if(!i){i=document.createElement("div"),Object.assign(i.style,{position:"absolute",transition:"transform 60ms cubic-bezier(0.22,1,0.36,1)",willChange:"transform",pointerEvents:"none"});const s=t.color||"#e74c3c";i.innerHTML=`
|
|
2277
2305
|
<svg width="24" height="24" viewBox="0 0 16 16" fill="${s}" style="filter:drop-shadow(0 2px 4px rgba(0,0,0,0.4))">
|
|
2278
2306
|
<path d="M0 0l6.5 16L8 9l7-2.5z" stroke="#fff" stroke-width="1"/>
|
|
2279
2307
|
</svg>
|
|
@@ -2287,7 +2315,7 @@
|
|
|
2287
2315
|
box-shadow:0 2px 10px rgba(0,0,0,0.25);
|
|
2288
2316
|
letter-spacing:0.01em;
|
|
2289
2317
|
">${t.name}</span>
|
|
2290
|
-
`,this.container.appendChild(i),this.cursorEls.set(e,i)}i.style.transform=`translate(${t.position.x}px, ${t.position.y}px)`}}class ts{constructor(e){this.container=null,this.unsubs=[],this.enabled=!1,this.drawMode=!1,this.currentPoints=[],this.currentPath=null,this.lastPoint=null,this.fadeTimers=new Map,this.handlePointerDown=t=>{var l,a,c;t.preventDefault(),(a=(l=t.target)==null?void 0:l.setPointerCapture)==null||a.call(l,t.pointerId),this.currentPoints=[{x:t.clientX,y:t.clientY}],this.lastPoint={x:t.clientX,y:t.clientY};const i=this.client.state.user,s=(i==null?void 0:i.color)??"#6366f1",r=2+(t.pressure>0?t.pressure:.5)*4;this.currentPath=document.createElementNS("http://www.w3.org/2000/svg","polyline"),this.currentPath.setAttribute("fill","none"),this.currentPath.setAttribute("stroke",s),this.currentPath.setAttribute("stroke-width",String(r)),this.currentPath.setAttribute("stroke-linecap","round"),this.currentPath.setAttribute("stroke-linejoin","round"),this.currentPath.setAttribute("points",`${t.clientX},${t.clientY}`),(c=this.container)==null||c.appendChild(this.currentPath),document.addEventListener("pointermove",this.handlePointerMove),document.addEventListener("pointerup",this.handlePointerUp)},this.handlePointerMove=t=>{if(!this.currentPath||!this.lastPoint)return;const i=t.clientX-this.lastPoint.x,s=t.clientY-this.lastPoint.y;if(i*i+s*s<4)return;this.currentPoints.push({x:t.clientX,y:t.clientY}),this.lastPoint={x:t.clientX,y:t.clientY};const o=this.currentPoints.map(r=>`${r.x},${r.y}`).join(" ");this.currentPath.setAttribute("points",o)},this.handlePointerUp=()=>{var t;if(document.removeEventListener("pointermove",this.handlePointerMove),document.removeEventListener("pointerup",this.handlePointerUp),this.currentPoints.length>1){const i=this.client.state.user,s=(i==null?void 0:i.color)??"#6366f1";this.client.drawStroke(this.currentPoints,s,3),this.currentPath&&this.scheduleFade(this.currentPath)}else(t=this.currentPath)==null||t.remove();this.currentPoints=[],this.currentPath=null,this.lastPoint=null},this.client=e}enable(){this.enabled||(this.enabled=!0,this.container=document.createElementNS("http://www.w3.org/2000/svg","svg"),this.container.id="pulse-widget-drawing",this.container.setAttribute("style","position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:9989;"),document.body.appendChild(this.container),this.unsubs.push(this.client.state.on("draw-stroke",({userId:e,points:t,color:i,width:s})=>{this.renderStroke(t,i,s)})),this.unsubs.push(this.client.state.on("draw-clear",({userId:e})=>{})))}disable(){var e;if(this.enabled){this.enabled=!1,this.disableDrawMode(),this.unsubs.forEach(t=>t()),this.unsubs=[];for(const t of this.fadeTimers.values())clearTimeout(t);this.fadeTimers.clear(),(e=this.container)==null||e.remove(),this.container=null}}destroy(){this.disable()}enableDrawMode(){!this.container||this.drawMode||(this.drawMode=!0,this.container.style.pointerEvents="auto",this.container.style.cursor="crosshair",this.container.style.touchAction="none",this.container.addEventListener("pointerdown",this.handlePointerDown))}disableDrawMode(){this.drawMode&&(this.drawMode=!1,this.container&&(this.container.style.pointerEvents="none",this.container.style.cursor="",this.container.style.touchAction="",this.container.removeEventListener("pointerdown",this.handlePointerDown)),document.removeEventListener("pointermove",this.handlePointerMove),document.removeEventListener("pointerup",this.handlePointerUp),this.currentPoints=[],this.currentPath=null,this.lastPoint=null)}renderStroke(e,t,i){if(!this.container||e.length<2)return;const s=document.createElementNS("http://www.w3.org/2000/svg","polyline");s.setAttribute("fill","none"),s.setAttribute("stroke",t),s.setAttribute("stroke-width",String(i)),s.setAttribute("stroke-linecap","round"),s.setAttribute("stroke-linejoin","round"),s.setAttribute("points",e.map(o=>`${o.x},${o.y}`).join(" ")),s.style.willChange="opacity",this.container.appendChild(s),this.scheduleFade(s)}scheduleFade(e){const t=setTimeout(()=>{e.style.transition="opacity 1s ease-out",e.style.opacity="0",setTimeout(()=>{e.remove(),this.fadeTimers.delete(e)},1e3)},1e4);this.fadeTimers.set(e,t)}}function is(n){if(!n.rangeCount||n.isCollapsed)return null;const e=n.getRangeAt(0),t=e.startContainer,i=e.endContainer,s=at(t),o=at(i);return!s||!o?null:{startSelector:s,startOffset:e.startOffset,endSelector:o,endOffset:e.endOffset}}function ss(n){var e,t;try{const i=ct(n.startSelector),s=ct(n.endSelector);if(!i||!s)return null;const o=document.createRange(),r=i.nodeType===Node.TEXT_NODE?((e=i.textContent)==null?void 0:e.length)??0:i.childNodes.length,l=s.nodeType===Node.TEXT_NODE?((t=s.textContent)==null?void 0:t.length)??0:s.childNodes.length;return o.setStart(i,Math.min(n.startOffset,r)),o.setEnd(s,Math.min(n.endOffset,l)),o}catch{return null}}function at(n){if(n.nodeType===Node.TEXT_NODE){const e=n.parentElement;if(!e)return null;const t=lt(e);if(!t)return null;const i=Array.from(e.childNodes).indexOf(n);return`${t}::text(${i})`}return n.nodeType===Node.ELEMENT_NODE?lt(n):null}function lt(n){if(!n||n===document.documentElement)return"html";if(n===document.body)return"body";if(n.id)return`#${CSS.escape(n.id)}`;const e=[];let t=n,i=0;for(;t&&t!==document.body&&i<10;){const s=t.parentElement;if(!s)break;const o=t.tagName.toLowerCase(),r=t.tagName,l=Array.from(s.children).filter(a=>a.tagName===r);if(l.length===1)e.unshift(o);else{const a=l.indexOf(t)+1;e.unshift(`${o}:nth-of-type(${a})`)}if(s.id){e.unshift(`#${CSS.escape(s.id)}`);break}t=s,i++}return e.length>0?e.join(" > "):null}function ct(n){const e=n.match(/^(.+)::text\((\d+)\)$/);if(e){const t=e[1],i=parseInt(e[2],10);try{const s=document.querySelector(t);return s?s.childNodes[i]??null:null}catch{return null}}try{return document.querySelector(n)}catch{return null}}class ns{constructor(e){this.container=null,this.unsubs=[],this.enabled=!1,this.selectionEls=new Map,this.clearTimers=new Map,this.client=e}enable(){this.enabled||(this.enabled=!0,this.container=document.createElement("div"),this.container.id="pulse-widget-selections",Object.assign(this.container.style,{position:"fixed",top:"0",left:"0",width:"100%",height:"100%",pointerEvents:"none",zIndex:"9995"}),document.body.appendChild(this.container),this.unsubs.push(this.client.state.on("selection",({userId:e,selection:t})=>{this.renderSelection(e,t)})),this.unsubs.push(this.client.state.on("presence",e=>{const t=new Set(e.map(i=>i.user.id));for(const i of this.selectionEls.keys())t.has(i)||this.clearSelection(i)})))}disable(){var e;if(this.enabled){this.enabled=!1,this.unsubs.forEach(t=>t()),this.unsubs=[];for(const t of this.clearTimers.values())clearTimeout(t);this.clearTimers.clear(),(e=this.container)==null||e.remove(),this.container=null,this.selectionEls.clear()}}destroy(){this.disable()}renderSelection(e,t){var l;if(!this.container)return;const i=(l=this.client.state.user)==null?void 0:l.id;if(e===i||(this.clearSelection(e),!t))return;const s=ss(t);if(!s)return;const o=this.client.state.presence.find(a=>a.user.id===e),r=(o==null?void 0:o.user.color)??"#6366f1";try{const a=s.getClientRects(),c=[];for(let p=0;p<a.length;p++){const d=a[p],
|
|
2318
|
+
`,this.container.appendChild(i),this.cursorEls.set(e,i)}i.style.transform=`translate(${t.position.x}px, ${t.position.y}px)`}}class ts{constructor(e){this.container=null,this.unsubs=[],this.enabled=!1,this.drawMode=!1,this.currentPoints=[],this.currentPath=null,this.lastPoint=null,this.fadeTimers=new Map,this.handlePointerDown=t=>{var l,a,c;t.preventDefault(),(a=(l=t.target)==null?void 0:l.setPointerCapture)==null||a.call(l,t.pointerId),this.currentPoints=[{x:t.clientX,y:t.clientY}],this.lastPoint={x:t.clientX,y:t.clientY};const i=this.client.state.user,s=(i==null?void 0:i.color)??"#6366f1",r=2+(t.pressure>0?t.pressure:.5)*4;this.currentPath=document.createElementNS("http://www.w3.org/2000/svg","polyline"),this.currentPath.setAttribute("fill","none"),this.currentPath.setAttribute("stroke",s),this.currentPath.setAttribute("stroke-width",String(r)),this.currentPath.setAttribute("stroke-linecap","round"),this.currentPath.setAttribute("stroke-linejoin","round"),this.currentPath.setAttribute("points",`${t.clientX},${t.clientY}`),(c=this.container)==null||c.appendChild(this.currentPath),document.addEventListener("pointermove",this.handlePointerMove),document.addEventListener("pointerup",this.handlePointerUp)},this.handlePointerMove=t=>{if(!this.currentPath||!this.lastPoint)return;const i=t.clientX-this.lastPoint.x,s=t.clientY-this.lastPoint.y;if(i*i+s*s<4)return;this.currentPoints.push({x:t.clientX,y:t.clientY}),this.lastPoint={x:t.clientX,y:t.clientY};const o=this.currentPoints.map(r=>`${r.x},${r.y}`).join(" ");this.currentPath.setAttribute("points",o)},this.handlePointerUp=()=>{var t;if(document.removeEventListener("pointermove",this.handlePointerMove),document.removeEventListener("pointerup",this.handlePointerUp),this.currentPoints.length>1){const i=this.client.state.user,s=(i==null?void 0:i.color)??"#6366f1";this.client.drawStroke(this.currentPoints,s,3),this.currentPath&&this.scheduleFade(this.currentPath)}else(t=this.currentPath)==null||t.remove();this.currentPoints=[],this.currentPath=null,this.lastPoint=null},this.client=e}enable(){this.enabled||(this.enabled=!0,this.container=document.createElementNS("http://www.w3.org/2000/svg","svg"),this.container.id="pulse-widget-drawing",this.container.setAttribute("style","position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:9989;"),document.body.appendChild(this.container),this.unsubs.push(this.client.state.on("draw-stroke",({userId:e,points:t,color:i,width:s})=>{this.renderStroke(t,i,s)})),this.unsubs.push(this.client.state.on("draw-clear",({userId:e})=>{})))}disable(){var e;if(this.enabled){this.enabled=!1,this.disableDrawMode(),this.unsubs.forEach(t=>t()),this.unsubs=[];for(const t of this.fadeTimers.values())clearTimeout(t);this.fadeTimers.clear(),(e=this.container)==null||e.remove(),this.container=null}}destroy(){this.disable()}enableDrawMode(){!this.container||this.drawMode||(this.drawMode=!0,this.container.style.pointerEvents="auto",this.container.style.cursor="crosshair",this.container.style.touchAction="none",this.container.addEventListener("pointerdown",this.handlePointerDown))}disableDrawMode(){this.drawMode&&(this.drawMode=!1,this.container&&(this.container.style.pointerEvents="none",this.container.style.cursor="",this.container.style.touchAction="",this.container.removeEventListener("pointerdown",this.handlePointerDown)),document.removeEventListener("pointermove",this.handlePointerMove),document.removeEventListener("pointerup",this.handlePointerUp),this.currentPoints=[],this.currentPath=null,this.lastPoint=null)}renderStroke(e,t,i){if(!this.container||e.length<2)return;const s=document.createElementNS("http://www.w3.org/2000/svg","polyline");s.setAttribute("fill","none"),s.setAttribute("stroke",t),s.setAttribute("stroke-width",String(i)),s.setAttribute("stroke-linecap","round"),s.setAttribute("stroke-linejoin","round"),s.setAttribute("points",e.map(o=>`${o.x},${o.y}`).join(" ")),s.style.willChange="opacity",this.container.appendChild(s),this.scheduleFade(s)}scheduleFade(e){const t=setTimeout(()=>{e.style.transition="opacity 1s ease-out",e.style.opacity="0",setTimeout(()=>{e.remove(),this.fadeTimers.delete(e)},1e3)},1e4);this.fadeTimers.set(e,t)}}function is(n){if(!n.rangeCount||n.isCollapsed)return null;const e=n.getRangeAt(0),t=e.startContainer,i=e.endContainer,s=at(t),o=at(i);return!s||!o?null:{startSelector:s,startOffset:e.startOffset,endSelector:o,endOffset:e.endOffset}}function ss(n){var e,t;try{const i=ct(n.startSelector),s=ct(n.endSelector);if(!i||!s)return null;const o=document.createRange(),r=i.nodeType===Node.TEXT_NODE?((e=i.textContent)==null?void 0:e.length)??0:i.childNodes.length,l=s.nodeType===Node.TEXT_NODE?((t=s.textContent)==null?void 0:t.length)??0:s.childNodes.length;return o.setStart(i,Math.min(n.startOffset,r)),o.setEnd(s,Math.min(n.endOffset,l)),o}catch{return null}}function at(n){if(n.nodeType===Node.TEXT_NODE){const e=n.parentElement;if(!e)return null;const t=lt(e);if(!t)return null;const i=Array.from(e.childNodes).indexOf(n);return`${t}::text(${i})`}return n.nodeType===Node.ELEMENT_NODE?lt(n):null}function lt(n){if(!n||n===document.documentElement)return"html";if(n===document.body)return"body";if(n.id)return`#${CSS.escape(n.id)}`;const e=[];let t=n,i=0;for(;t&&t!==document.body&&i<10;){const s=t.parentElement;if(!s)break;const o=t.tagName.toLowerCase(),r=t.tagName,l=Array.from(s.children).filter(a=>a.tagName===r);if(l.length===1)e.unshift(o);else{const a=l.indexOf(t)+1;e.unshift(`${o}:nth-of-type(${a})`)}if(s.id){e.unshift(`#${CSS.escape(s.id)}`);break}t=s,i++}return e.length>0?e.join(" > "):null}function ct(n){const e=n.match(/^(.+)::text\((\d+)\)$/);if(e){const t=e[1],i=parseInt(e[2],10);try{const s=document.querySelector(t);return s?s.childNodes[i]??null:null}catch{return null}}try{return document.querySelector(n)}catch{return null}}class ns{constructor(e){this.container=null,this.unsubs=[],this.enabled=!1,this.selectionEls=new Map,this.clearTimers=new Map,this.client=e}enable(){this.enabled||(this.enabled=!0,this.container=document.createElement("div"),this.container.id="pulse-widget-selections",Object.assign(this.container.style,{position:"fixed",top:"0",left:"0",width:"100%",height:"100%",pointerEvents:"none",zIndex:"9995"}),document.body.appendChild(this.container),this.unsubs.push(this.client.state.on("selection",({userId:e,selection:t})=>{this.renderSelection(e,t)})),this.unsubs.push(this.client.state.on("presence",e=>{const t=new Set(e.map(i=>i.user.id));for(const i of this.selectionEls.keys())t.has(i)||this.clearSelection(i)})))}disable(){var e;if(this.enabled){this.enabled=!1,this.unsubs.forEach(t=>t()),this.unsubs=[];for(const t of this.clearTimers.values())clearTimeout(t);this.clearTimers.clear(),(e=this.container)==null||e.remove(),this.container=null,this.selectionEls.clear()}}destroy(){this.disable()}renderSelection(e,t){var l;if(!this.container)return;const i=(l=this.client.state.user)==null?void 0:l.id;if(e===i||(this.clearSelection(e),!t))return;const s=ss(t);if(!s)return;const o=this.client.state.presence.find(a=>a.user.id===e),r=(o==null?void 0:o.user.color)??"#6366f1";try{const a=s.getClientRects(),c=[];for(let p=0;p<a.length;p++){const d=a[p],f=document.createElement("div");Object.assign(f.style,{position:"absolute",left:`${d.left}px`,top:`${d.top}px`,width:`${d.width}px`,height:`${d.height}px`,background:r,opacity:"0.2",borderRadius:"2px",pointerEvents:"none"}),this.container.appendChild(f),c.push(f)}this.selectionEls.set(e,c)}catch{}this.clearTimers.has(e)&&clearTimeout(this.clearTimers.get(e)),this.clearTimers.set(e,setTimeout(()=>{this.clearSelection(e),this.clearTimers.delete(e)},5e3))}clearSelection(e){const t=this.selectionEls.get(e);if(t){for(const i of t)i.remove();this.selectionEls.delete(e)}}}var os=Object.defineProperty,rs=Object.getOwnPropertyDescriptor,Ue=(n,e,t,i)=>{for(var s=i>1?void 0:i?rs(e,t):e,o=n.length-1,r;o>=0;o--)(r=n[o])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&os(e,t,s),s};let ne=class extends _{constructor(){super(...arguments),this.roomId=""}fireClose(){this.dispatchEvent(new CustomEvent("panel-close",{bubbles:!0,composed:!0}))}toggle(n){const e={...this.settings,[n]:!this.settings[n]};this.dispatchEvent(new CustomEvent("settings-change",{detail:e,bubbles:!0,composed:!0}))}renderToggle(n,e){return h`
|
|
2291
2319
|
<div class="setting-row">
|
|
2292
2320
|
<span class="setting-label">${n}</span>
|
|
2293
2321
|
<label class="toggle">
|
|
@@ -2304,7 +2332,7 @@
|
|
|
2304
2332
|
<div class="panel-header">
|
|
2305
2333
|
<span class="panel-title">Settings</span>
|
|
2306
2334
|
<button class="close-btn" @click=${this.fireClose} title="Close">
|
|
2307
|
-
${
|
|
2335
|
+
${E(le,16)}
|
|
2308
2336
|
</button>
|
|
2309
2337
|
</div>
|
|
2310
2338
|
|
|
@@ -2346,7 +2374,7 @@
|
|
|
2346
2374
|
${this.renderToggle("Show drawings","showDrawings")}
|
|
2347
2375
|
</div>
|
|
2348
2376
|
</div>
|
|
2349
|
-
`}};ne.styles=[K,ce,xe,
|
|
2377
|
+
`}};ne.styles=[K,ce,xe,A`
|
|
2350
2378
|
:host {
|
|
2351
2379
|
display: block;
|
|
2352
2380
|
}
|
|
@@ -2515,16 +2543,16 @@
|
|
|
2515
2543
|
min-height: 44px;
|
|
2516
2544
|
}
|
|
2517
2545
|
}
|
|
2518
|
-
`];Ue([
|
|
2546
|
+
`];Ue([b({attribute:!1})],ne.prototype,"settings",2);Ue([b()],ne.prototype,"roomId",2);ne=Ue([O("pulse-widget-settings-panel")],ne);const ue={enabled:!0,showMyCursor:!0,showOthersCursors:!0,showMyClicks:!0,showOthersClicks:!0,appearOffline:!1,showCommentPins:!0,showViewportIndicators:!0,showSelections:!0,showDrawings:!0},wt="pulse:settings:";function as(n){try{const e=localStorage.getItem(`${wt}${n}`);return e?{...ue,...JSON.parse(e)}:{...ue}}catch{return{...ue}}}function ls(n,e){localStorage.setItem(`${wt}${n}`,JSON.stringify(e))}var cs=Object.defineProperty,ds=Object.getOwnPropertyDescriptor,R=(n,e,t,i)=>{for(var s=i>1?void 0:i?ds(e,t):e,o=n.length-1,r;o>=0;o--)(r=n[o])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&cs(e,t,s),s};let I=class extends _{constructor(){super(...arguments),this.collapsed=!1,this.activePanel=null,this.pinModeActive=!1,this.featuresDisabled=!1,this.drawModeActive=!1,this.followingUserId=null,this.display="floating",this.users=[],this.unreadCount=0}connectedCallback(){super.connectedCallback(),this.setupPresence()}disconnectedCallback(){var n,e;super.disconnectedCallback(),(n=this.unsub)==null||n.call(this),(e=this.notifUnsub)==null||e.call(this)}updated(n){var e,t;n.has("client")&&this.client&&((e=this.unsub)==null||e.call(this),(t=this.notifUnsub)==null||t.call(this),this.setupPresence())}setupPresence(){this.client&&(this.users=this.client.state.presence,this.unreadCount=this.client.state.unreadCount,this.unsub=this.client.state.on("presence",n=>{this.users=n}),this.notifUnsub=this.client.state.on("notifications",()=>{this.unreadCount=this.client.state.unreadCount}))}getInitials(n){return n.split(" ").map(e=>e[0]).join("").toUpperCase().slice(0,2)}fire(n){this.dispatchEvent(new CustomEvent("toolbar-action",{detail:n,bubbles:!0,composed:!0}))}fireFollow(n){this.dispatchEvent(new CustomEvent("toolbar-follow",{detail:n,bubbles:!0,composed:!0}))}fireToggle(){this.dispatchEvent(new CustomEvent("toolbar-toggle",{bubbles:!0,composed:!0}))}render(){const n=this.display==="inline";if(this.collapsed)return h`
|
|
2519
2547
|
<div class="toolbar collapsed ${n?"inline":""}" @click=${this.fireToggle}>
|
|
2520
|
-
<span class="fab-icon">${
|
|
2548
|
+
<span class="fab-icon">${E(_i,n?18:24)}</span>
|
|
2521
2549
|
</div>
|
|
2522
2550
|
`;const e=this.users.slice(0,3),t=this.users.length-3;return h`
|
|
2523
2551
|
<div class="toolbar ${n?"inline":""}"
|
|
2524
2552
|
<!-- Presence avatars -->
|
|
2525
2553
|
${this.users.length>0?h`
|
|
2526
2554
|
<div class="presence">
|
|
2527
|
-
${t>0?h`<div class="presence-overflow">+${t}</div>`:
|
|
2555
|
+
${t>0?h`<div class="presence-overflow">+${t}</div>`:m}
|
|
2528
2556
|
${e.map(i=>h`
|
|
2529
2557
|
<div
|
|
2530
2558
|
class="presence-avatar clickable ${this.followingUserId===i.user.id?"following":""}"
|
|
@@ -2534,12 +2562,12 @@
|
|
|
2534
2562
|
>
|
|
2535
2563
|
${i.user.avatar?h`<img src="${i.user.avatar}" alt="${i.user.name}" />`:this.getInitials(i.user.name)}
|
|
2536
2564
|
<span class="presence-tooltip">${i.user.name}</span>
|
|
2537
|
-
${i.deviceType&&i.deviceType!=="desktop"?h`<span class="device-icon">${i.deviceType==="mobile"?"📱":"📲"}</span>`:
|
|
2565
|
+
${i.deviceType&&i.deviceType!=="desktop"?h`<span class="device-icon">${i.deviceType==="mobile"?"📱":"📲"}</span>`:m}
|
|
2538
2566
|
</div>
|
|
2539
2567
|
`)}
|
|
2540
2568
|
</div>
|
|
2541
2569
|
<div class="separator"></div>
|
|
2542
|
-
`:
|
|
2570
|
+
`:m}
|
|
2543
2571
|
|
|
2544
2572
|
<!-- Pin comment (primary) -->
|
|
2545
2573
|
<button
|
|
@@ -2549,7 +2577,7 @@
|
|
|
2549
2577
|
?disabled=${this.featuresDisabled}
|
|
2550
2578
|
style="${this.featuresDisabled?"opacity:0.35;pointer-events:none":""}"
|
|
2551
2579
|
>
|
|
2552
|
-
${
|
|
2580
|
+
${E(xt)}
|
|
2553
2581
|
</button>
|
|
2554
2582
|
|
|
2555
2583
|
<!-- View comments -->
|
|
@@ -2560,7 +2588,7 @@
|
|
|
2560
2588
|
?disabled=${this.featuresDisabled}
|
|
2561
2589
|
style="${this.featuresDisabled?"opacity:0.35;pointer-events:none":""}"
|
|
2562
2590
|
>
|
|
2563
|
-
${
|
|
2591
|
+
${E(xi)}
|
|
2564
2592
|
</button>
|
|
2565
2593
|
|
|
2566
2594
|
<!-- Activity feed -->
|
|
@@ -2571,7 +2599,7 @@
|
|
|
2571
2599
|
?disabled=${this.featuresDisabled}
|
|
2572
2600
|
style="${this.featuresDisabled?"opacity:0.35;pointer-events:none":""}"
|
|
2573
2601
|
>
|
|
2574
|
-
${
|
|
2602
|
+
${E(vi)}
|
|
2575
2603
|
</button>
|
|
2576
2604
|
|
|
2577
2605
|
<!-- Draw mode -->
|
|
@@ -2582,7 +2610,7 @@
|
|
|
2582
2610
|
?disabled=${this.featuresDisabled}
|
|
2583
2611
|
style="${this.featuresDisabled?"opacity:0.35;pointer-events:none":""}"
|
|
2584
2612
|
>
|
|
2585
|
-
${
|
|
2613
|
+
${E($i)}
|
|
2586
2614
|
</button>
|
|
2587
2615
|
|
|
2588
2616
|
<!-- Notifications -->
|
|
@@ -2593,8 +2621,8 @@
|
|
|
2593
2621
|
?disabled=${this.featuresDisabled}
|
|
2594
2622
|
style="${this.featuresDisabled?"opacity:0.35;pointer-events:none":"position:relative"}"
|
|
2595
2623
|
>
|
|
2596
|
-
${
|
|
2597
|
-
${this.unreadCount>0?h`<span class="badge">${this.unreadCount>9?"9+":this.unreadCount}</span>`:
|
|
2624
|
+
${E(bi)}
|
|
2625
|
+
${this.unreadCount>0?h`<span class="badge">${this.unreadCount>9?"9+":this.unreadCount}</span>`:m}
|
|
2598
2626
|
</button>
|
|
2599
2627
|
|
|
2600
2628
|
<!-- Settings -->
|
|
@@ -2603,7 +2631,7 @@
|
|
|
2603
2631
|
@click=${()=>this.fire("settings")}
|
|
2604
2632
|
title="Settings"
|
|
2605
2633
|
>
|
|
2606
|
-
${
|
|
2634
|
+
${E(Ci)}
|
|
2607
2635
|
</button>
|
|
2608
2636
|
|
|
2609
2637
|
<div class="separator"></div>
|
|
@@ -2614,10 +2642,10 @@
|
|
|
2614
2642
|
@click=${this.fireToggle}
|
|
2615
2643
|
title="Collapse"
|
|
2616
2644
|
>
|
|
2617
|
-
${
|
|
2645
|
+
${E(le,14)}
|
|
2618
2646
|
</button>
|
|
2619
2647
|
</div>
|
|
2620
|
-
`}};I.styles=[K,ce,
|
|
2648
|
+
`}};I.styles=[K,ce,A`
|
|
2621
2649
|
:host {
|
|
2622
2650
|
display: block;
|
|
2623
2651
|
}
|
|
@@ -2827,13 +2855,13 @@
|
|
|
2827
2855
|
height: 32px;
|
|
2828
2856
|
}
|
|
2829
2857
|
}
|
|
2830
|
-
`];R([g({attribute:!1})],I.prototype,"client",2);R([g({type:Boolean})],I.prototype,"collapsed",2);R([g()],I.prototype,"activePanel",2);R([g({type:Boolean})],I.prototype,"pinModeActive",2);R([g({type:Boolean})],I.prototype,"featuresDisabled",2);R([g({type:Boolean})],I.prototype,"drawModeActive",2);R([g()],I.prototype,"followingUserId",2);R([g()],I.prototype,"display",2);R([v()],I.prototype,"users",2);R([v()],I.prototype,"unreadCount",2);I=R([O("pulse-widget-toolbar")],I);class hs{constructor(e){this.container=null,this.unsubs=[],this.enabled=!1,this.pillEls=new Map,this.client=e}enable(){this.enabled||(this.enabled=!0,this.container=document.createElement("div"),this.container.id="pulse-widget-viewports",Object.assign(this.container.style,{position:"fixed",top:"0",left:"0",width:"100%",height:"100%",pointerEvents:"none",zIndex:"9996"}),document.body.appendChild(this.container),this.unsubs.push(this.client.state.on("viewport",()=>{this.render()})),this.unsubs.push(this.client.state.on("presence",()=>{this.render()})),this.render())}disable(){var e;this.enabled&&(this.enabled=!1,this.unsubs.forEach(t=>t()),this.unsubs=[],(e=this.container)==null||e.remove(),this.container=null,this.pillEls.clear())}destroy(){this.disable()}render(){var r;if(!this.container)return;if(document.documentElement.scrollHeight<=window.innerHeight){for(const l of this.pillEls.values())l.remove();this.pillEls.clear();return}const e=window.scrollY,t=window.innerHeight,i=document.documentElement.scrollHeight,s=(r=this.client.state.user)==null?void 0:r.id,o=new Set;for(const[l,a]of this.client.state.viewports){if(l===s)continue;const c=a.scrollY,p=a.scrollY+a.viewportHeight,d=e,u=e+t;if(c>=d&&p<=u){const w=this.pillEls.get(l);w&&(w.style.display="none");continue}o.add(l);const m=this.client.state.presence.find(w=>w.user.id===l);if(!m)continue;const b=a.scrollY+a.viewportHeight/2,A=i>0?b/i:0,C=Math.max(8,Math.min(t-28,A*t));let $=this.pillEls.get(l);$||($=document.createElement("div"),Object.assign($.style,{position:"absolute",right:"8px",padding:"2px 6px",borderRadius:"10px",fontSize:"10px",fontWeight:"700",color:"#fff",fontFamily:"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",whiteSpace:"nowrap",pointerEvents:"none",transition:"top 0.3s ease"}),this.container.appendChild($),this.pillEls.set(l,$)),$.style.display="",$.style.background=m.user.color,$.style.top=`${C}px`,$.textContent=this.getInitials(m.user.name)}for(const[l,a]of this.pillEls)!o.has(l)&&!this.client.state.viewports.has(l)&&(a.remove(),this.pillEls.delete(l))}getInitials(e){return e.split(" ").map(t=>t[0]).join("").toUpperCase().slice(0,2)}}var ps=Object.defineProperty,us=Object.getOwnPropertyDescriptor,_=(n,e,t,i)=>{for(var s=i>1?void 0:i?us(e,t):e,o=n.length-1,r;o>=0;o--)(r=n[o])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&ps(e,t,s),s};exports.PulseWidget=class extends P{constructor(){super(...arguments),this.apiKey="",this.token="",this.room="",this.position="bottom-right",this.display="floating",this.collapsed=!0,this.activePanel=null,this.pinModeActive=!1,this.highlightThreadId=null,this.settings={...ue},this.followingUserId=null,this.drawModeActive=!1,this.connectionState="disconnected",this.showConnectedFlash=!1,this.unsubs=[],this.clientConfigKey="",this._isFollowScrolling=!1,this._viewportThrottleTimer=null,this._selectionThrottleTimer=null,this._connectedFlashTimer=null,this._wasDisconnected=!1,this.handleScroll=()=>{!this.settings.enabled||!this.client||this._isFollowScrolling||(this.followingUserId&&(this.followingUserId=null),!this._viewportThrottleTimer&&(this._viewportThrottleTimer=setTimeout(()=>{var e;this._viewportThrottleTimer=null,(e=this.client)==null||e.updateViewport({scrollX:window.scrollX,scrollY:window.scrollY,viewportWidth:window.innerWidth,viewportHeight:window.innerHeight,pageWidth:document.documentElement.scrollWidth,pageHeight:document.documentElement.scrollHeight})},200)))},this.handleSelectionChange=()=>{!this.settings.enabled||!this.settings.showSelections||!this.client||this._selectionThrottleTimer||(this._selectionThrottleTimer=setTimeout(()=>{var i,s;this._selectionThrottleTimer=null;const e=window.getSelection();if(!e||e.isCollapsed){(i=this.client)==null||i.updateSelection(null);return}const t=is(e);(s=this.client)==null||s.updateSelection(t)},500))},this.handleDocumentClick=e=>{var t;this.settings.enabled&&this.settings.showMyClicks&&(this.contains(e.target)||(t=this.client)==null||t.performClick({x:e.clientX,y:e.clientY,pageX:e.pageX,pageY:e.pageY}))},this.handleKeydown=e=>{var t,i;e.key==="Escape"&&(this.drawModeActive?((t=this.drawingOverlay)==null||t.disableDrawMode(),this.drawModeActive=!1):this.followingUserId?this.followingUserId=null:this.pinModeActive?((i=this.commentPins)==null||i.exitPinMode(),this.pinModeActive=!1):this.activePanel&&(this.activePanel=null,this.highlightThreadId=null))}}connectedCallback(){super.connectedCallback(),document.addEventListener("keydown",this.handleKeydown),document.addEventListener("pointerup",this.handleDocumentClick),this.apiKey&&this.token&&this.room&&this.initClient()}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener("keydown",this.handleKeydown),document.removeEventListener("pointerup",this.handleDocumentClick),this.teardownClient()}getConfigKey(){return`${this.apiKey}\0${this.token}\0${this.room}\0${this.endpoint??""}`}initClient(){const e={apiKey:this.apiKey,token:this.token,room:this.room,endpoint:this.endpoint};this.client=new pt(e),this.clientConfigKey=this.getConfigKey(),this.cursorOverlay=new es(this.client),this.commentPins=new Vi(this.client,{onPinModeExit:()=>{this.pinModeActive=!1}}),this.viewportOverlay=new hs(this.client),this.selectionOverlay=new ns(this.client),this.drawingOverlay=new ts(this.client),this.settings=as(this.room),this.applySettings(this.settings),this.unsubs.push(this.client.on("connection",t=>{this.connectionState=t,t==="connected"&&this._wasDisconnected?(this.showConnectedFlash=!0,this._connectedFlashTimer&&clearTimeout(this._connectedFlashTimer),this._connectedFlashTimer=setTimeout(()=>{this.showConnectedFlash=!1,this._connectedFlashTimer=null},2e3),this._wasDisconnected=!1):(t==="connecting"||t==="disconnected")&&(this._wasDisconnected=!0,this.showConnectedFlash=!1,this._connectedFlashTimer&&(clearTimeout(this._connectedFlashTimer),this._connectedFlashTimer=null))})),this.unsubs.push(this.client.state.on("click",({userId:t,position:i})=>{var s;this.settings.showOthersClicks&&((s=this.cursorOverlay)!=null&&s.isEnabled)&&this.cursorOverlay.showClickRipple(t,i)})),this.unsubs.push(this.client.state.on("viewport",({userId:t})=>{if(this.followingUserId===t){const i=this.client.state.getViewport(t);i&&(this._isFollowScrolling=!0,window.scrollTo({top:i.scrollY,left:i.scrollX,behavior:"smooth"}),setTimeout(()=>{this._isFollowScrolling=!1},500))}})),window.addEventListener("scroll",this.handleScroll),document.addEventListener("selectionchange",this.handleSelectionChange),this.client.connect()}teardownClient(){var e,t,i,s,o,r;this.unsubs.forEach(l=>l()),this.unsubs=[],window.removeEventListener("scroll",this.handleScroll),document.removeEventListener("selectionchange",this.handleSelectionChange),this._viewportThrottleTimer&&(clearTimeout(this._viewportThrottleTimer),this._viewportThrottleTimer=null),this._selectionThrottleTimer&&(clearTimeout(this._selectionThrottleTimer),this._selectionThrottleTimer=null),(e=this.cursorOverlay)==null||e.destroy(),(t=this.commentPins)==null||t.destroy(),(i=this.viewportOverlay)==null||i.destroy(),(s=this.selectionOverlay)==null||s.destroy(),(o=this.drawingOverlay)==null||o.destroy(),(r=this.client)==null||r.disconnect(),this.client=void 0,this.cursorOverlay=void 0,this.commentPins=void 0,this.viewportOverlay=void 0,this.selectionOverlay=void 0,this.drawingOverlay=void 0,this.clientConfigKey="",this.followingUserId=null,this.drawModeActive=!1,this.connectionState="disconnected",this.showConnectedFlash=!1,this._wasDisconnected=!1,this._connectedFlashTimer&&(clearTimeout(this._connectedFlashTimer),this._connectedFlashTimer=null)}handlePanelClose(){this.activePanel=null,this.highlightThreadId=null}handleToolbarAction(e){var i,s,o,r;const t=e.detail;if(!(!this.settings.enabled&&t!=="settings"))switch(t){case"comments":this.activePanel=this.activePanel==="comments"?null:"comments",this.highlightThreadId=null;break;case"settings":this.activePanel=this.activePanel==="settings"?null:"settings";break;case"notifications":this.activePanel=this.activePanel==="notifications"?null:"notifications";break;case"activity":this.activePanel=this.activePanel==="activity"?null:"activity";break;case"pin-mode":this.pinModeActive=!this.pinModeActive,this.pinModeActive?(i=this.commentPins)==null||i.enterPinMode():(s=this.commentPins)==null||s.exitPinMode();break;case"draw-mode":this.drawModeActive=!this.drawModeActive,this.drawModeActive?(o=this.drawingOverlay)==null||o.enableDrawMode():(r=this.drawingOverlay)==null||r.disableDrawMode();break}}handleFollow(e){const t=e.detail;this.followingUserId===t?this.followingUserId=null:this.followingUserId=t}handleSettingsChange(e){const t=e.detail;this.settings=t,ls(this.room,t),this.applySettings(t)}applySettings(e){var t,i,s,o,r,l,a,c,p,d,u,m,b,A,C,$,w;if(!e.enabled){(t=this.cursorOverlay)==null||t.disable(),(i=this.viewportOverlay)==null||i.disable(),(s=this.selectionOverlay)==null||s.disable(),(o=this.drawingOverlay)==null||o.disable(),this.drawModeActive&&((r=this.drawingOverlay)==null||r.disableDrawMode(),this.drawModeActive=!1),(l=this.client)==null||l.setAppearOffline(!0),(a=this.commentPins)==null||a.setVisible(!1),this.followingUserId=null,this.pinModeActive&&((c=this.commentPins)==null||c.exitPinMode(),this.pinModeActive=!1),this.activePanel=this.activePanel==="settings"?"settings":null,this.highlightThreadId=null;return}this.applyCursorSettings(e),(p=this.client)==null||p.setAppearOffline(e.appearOffline),(d=this.commentPins)==null||d.setVisible(e.showCommentPins),e.showViewportIndicators?(u=this.viewportOverlay)==null||u.enable():(m=this.viewportOverlay)==null||m.disable(),e.showSelections?(b=this.selectionOverlay)==null||b.enable():(A=this.selectionOverlay)==null||A.disable(),e.showDrawings?(C=this.drawingOverlay)==null||C.enable():(($=this.drawingOverlay)==null||$.disable(),this.drawModeActive&&((w=this.drawingOverlay)==null||w.disableDrawMode(),this.drawModeActive=!1))}applyCursorSettings(e){if(!this.cursorOverlay)return;e.showMyCursor||e.showOthersCursors?(this.cursorOverlay.enable(),this.cursorOverlay.setSending(e.showMyCursor),this.cursorOverlay.setReceiving(e.showOthersCursors)):this.cursorOverlay.disable()}updated(e){(e.has("room")||e.has("token")||e.has("apiKey")||e.has("endpoint"))&&this.apiKey&&this.token&&this.room&&this.getConfigKey()!==this.clientConfigKey&&(this.teardownClient(),this.initClient(),this.activePanel=null,this.highlightThreadId=null,this.pinModeActive=!1),(e.has("activePanel")||e.has("collapsed"))&&requestAnimationFrame(()=>this.positionPopups())}positionPopups(){var A,C,$,w;const e=this.display==="inline",t=(A=this.shadowRoot)==null?void 0:A.querySelector(".inline-trigger"),i=(C=this.shadowRoot)==null?void 0:C.querySelector("pulse-widget-toolbar"),s=e?t:i;if(!s)return;const o=s.getBoundingClientRect(),r=window.innerWidth,l=window.innerHeight,a=8,c=($=this.shadowRoot)==null?void 0:$.querySelector(".toolbar-popover");if(c){Object.assign(c.style,{top:"auto",left:"auto"});const T=c.getBoundingClientRect(),x=this.computePosition(o,T,r,l,a);c.style.top=`${x.top}px`,c.style.left=`${x.left}px`}const p=(w=this.shadowRoot)==null?void 0:w.querySelector(".panel-container");if(!p)return;Object.assign(p.style,{top:"auto",left:"auto"});const d=c??i;if(!d)return;const u=d.getBoundingClientRect(),m=p.getBoundingClientRect(),b=this.computePosition(u,m,r,l,a);p.style.top=`${b.top}px`,p.style.left=`${b.left}px`}computePosition(e,t,i,s,o){const r=e.top,l=s-e.bottom;let a;r>=t.height+o?a=e.top-t.height-o:l>=t.height+o?a=e.bottom+o:a=r>=l?Math.max(o,e.top-t.height-o):e.bottom+o;let c;const p=e.right-t.width;return p>=o?c=p:e.left+t.width+o<=i?c=e.left:c=Math.max(o,Math.min(i-t.width-o,e.left)),a=Math.max(o,Math.min(s-t.height-o,a)),c=Math.max(o,Math.min(i-t.width-o,c)),{top:a,left:c}}getFollowUserName(){var t;if(!this.followingUserId)return"";const e=(t=this.client)==null?void 0:t.state.presence.find(i=>i.user.id===this.followingUserId);return(e==null?void 0:e.user.name)??"user"}renderConnectionBanner(){return this.showConnectedFlash?h`<div class="connection-banner connected">
|
|
2858
|
+
`];R([b({attribute:!1})],I.prototype,"client",2);R([b({type:Boolean})],I.prototype,"collapsed",2);R([b()],I.prototype,"activePanel",2);R([b({type:Boolean})],I.prototype,"pinModeActive",2);R([b({type:Boolean})],I.prototype,"featuresDisabled",2);R([b({type:Boolean})],I.prototype,"drawModeActive",2);R([b()],I.prototype,"followingUserId",2);R([b()],I.prototype,"display",2);R([x()],I.prototype,"users",2);R([x()],I.prototype,"unreadCount",2);I=R([O("pulse-widget-toolbar")],I);class hs{constructor(e){this.container=null,this.unsubs=[],this.enabled=!1,this.pillEls=new Map,this.client=e}enable(){this.enabled||(this.enabled=!0,this.container=document.createElement("div"),this.container.id="pulse-widget-viewports",Object.assign(this.container.style,{position:"fixed",top:"0",left:"0",width:"100%",height:"100%",pointerEvents:"none",zIndex:"9996"}),document.body.appendChild(this.container),this.unsubs.push(this.client.state.on("viewport",()=>{this.render()})),this.unsubs.push(this.client.state.on("presence",()=>{this.render()})),this.render())}disable(){var e;this.enabled&&(this.enabled=!1,this.unsubs.forEach(t=>t()),this.unsubs=[],(e=this.container)==null||e.remove(),this.container=null,this.pillEls.clear())}destroy(){this.disable()}render(){var r;if(!this.container)return;if(document.documentElement.scrollHeight<=window.innerHeight){for(const l of this.pillEls.values())l.remove();this.pillEls.clear();return}const e=window.scrollY,t=window.innerHeight,i=document.documentElement.scrollHeight,s=(r=this.client.state.user)==null?void 0:r.id,o=new Set;for(const[l,a]of this.client.state.viewports){if(l===s)continue;const c=a.scrollY,p=a.scrollY+a.viewportHeight,d=e,f=e+t;if(c>=d&&p<=f){const C=this.pillEls.get(l);C&&(C.style.display="none");continue}o.add(l);const u=this.client.state.presence.find(C=>C.user.id===l);if(!u)continue;const g=a.scrollY+a.viewportHeight/2,v=i>0?g/i:0,k=Math.max(8,Math.min(t-28,v*t));let w=this.pillEls.get(l);w||(w=document.createElement("div"),Object.assign(w.style,{position:"absolute",right:"8px",padding:"2px 6px",borderRadius:"10px",fontSize:"10px",fontWeight:"700",color:"#fff",fontFamily:"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",whiteSpace:"nowrap",pointerEvents:"none",transition:"top 0.3s ease"}),this.container.appendChild(w),this.pillEls.set(l,w)),w.style.display="",w.style.background=u.user.color,w.style.top=`${k}px`,w.textContent=this.getInitials(u.user.name)}for(const[l,a]of this.pillEls)!o.has(l)&&!this.client.state.viewports.has(l)&&(a.remove(),this.pillEls.delete(l))}getInitials(e){return e.split(" ").map(t=>t[0]).join("").toUpperCase().slice(0,2)}}var ps=Object.defineProperty,us=Object.getOwnPropertyDescriptor,T=(n,e,t,i)=>{for(var s=i>1?void 0:i?us(e,t):e,o=n.length-1,r;o>=0;o--)(r=n[o])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&ps(e,t,s),s};exports.PulseWidget=class extends _{constructor(){super(...arguments),this.apiKey="",this.token="",this.room="",this.position="bottom-right",this.display="floating",this.collapsed=!0,this.activePanel=null,this.pinModeActive=!1,this.highlightThreadId=null,this.settings={...ue},this.followingUserId=null,this.drawModeActive=!1,this.connectionState="disconnected",this.showConnectedFlash=!1,this.unsubs=[],this.clientConfigKey="",this._isFollowScrolling=!1,this._viewportThrottleTimer=null,this._selectionThrottleTimer=null,this._connectedFlashTimer=null,this._wasDisconnected=!1,this.handleScroll=()=>{!this.settings.enabled||!this.client||this._isFollowScrolling||(this.followingUserId&&(this.followingUserId=null),!this._viewportThrottleTimer&&(this._viewportThrottleTimer=setTimeout(()=>{var e;this._viewportThrottleTimer=null,(e=this.client)==null||e.updateViewport({scrollX:window.scrollX,scrollY:window.scrollY,viewportWidth:window.innerWidth,viewportHeight:window.innerHeight,pageWidth:document.documentElement.scrollWidth,pageHeight:document.documentElement.scrollHeight})},200)))},this.handleSelectionChange=()=>{!this.settings.enabled||!this.settings.showSelections||!this.client||this._selectionThrottleTimer||(this._selectionThrottleTimer=setTimeout(()=>{var i,s;this._selectionThrottleTimer=null;const e=window.getSelection();if(!e||e.isCollapsed){(i=this.client)==null||i.updateSelection(null);return}const t=is(e);(s=this.client)==null||s.updateSelection(t)},500))},this.handleDocumentClick=e=>{var t;this.settings.enabled&&this.settings.showMyClicks&&(this.contains(e.target)||(t=this.client)==null||t.performClick({x:e.clientX,y:e.clientY,pageX:e.pageX,pageY:e.pageY}))},this.handleKeydown=e=>{var t,i;e.key==="Escape"&&(this.drawModeActive?((t=this.drawingOverlay)==null||t.disableDrawMode(),this.drawModeActive=!1):this.followingUserId?this.followingUserId=null:this.pinModeActive?((i=this.commentPins)==null||i.exitPinMode(),this.pinModeActive=!1):this.activePanel&&(this.activePanel=null,this.highlightThreadId=null))}}connectedCallback(){super.connectedCallback(),document.addEventListener("keydown",this.handleKeydown),document.addEventListener("pointerup",this.handleDocumentClick),this.apiKey&&this.token&&this.room&&this.initClient()}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener("keydown",this.handleKeydown),document.removeEventListener("pointerup",this.handleDocumentClick),this.teardownClient()}getConfigKey(){return`${this.apiKey}\0${this.token}\0${this.room}\0${this.endpoint??""}`}initClient(){const e={apiKey:this.apiKey,token:this.token,room:this.room,endpoint:this.endpoint};this.client=new pt(e),this.clientConfigKey=this.getConfigKey(),this.cursorOverlay=new es(this.client),this.commentPins=new Vi(this.client,{onPinModeExit:()=>{this.pinModeActive=!1}}),this.viewportOverlay=new hs(this.client),this.selectionOverlay=new ns(this.client),this.drawingOverlay=new ts(this.client),this.settings=as(this.room),this.applySettings(this.settings),this.unsubs.push(this.client.on("connection",t=>{this.connectionState=t,t==="connected"&&this._wasDisconnected?(this.showConnectedFlash=!0,this._connectedFlashTimer&&clearTimeout(this._connectedFlashTimer),this._connectedFlashTimer=setTimeout(()=>{this.showConnectedFlash=!1,this._connectedFlashTimer=null},2e3),this._wasDisconnected=!1):(t==="connecting"||t==="disconnected")&&(this._wasDisconnected=!0,this.showConnectedFlash=!1,this._connectedFlashTimer&&(clearTimeout(this._connectedFlashTimer),this._connectedFlashTimer=null))})),this.unsubs.push(this.client.state.on("click",({userId:t,position:i})=>{var s;this.settings.showOthersClicks&&((s=this.cursorOverlay)!=null&&s.isEnabled)&&this.cursorOverlay.showClickRipple(t,i)})),this.unsubs.push(this.client.state.on("viewport",({userId:t})=>{if(this.followingUserId===t){const i=this.client.state.getViewport(t);i&&(this._isFollowScrolling=!0,window.scrollTo({top:i.scrollY,left:i.scrollX,behavior:"smooth"}),setTimeout(()=>{this._isFollowScrolling=!1},500))}})),window.addEventListener("scroll",this.handleScroll),document.addEventListener("selectionchange",this.handleSelectionChange),this.client.connect()}teardownClient(){var e,t,i,s,o,r;this.unsubs.forEach(l=>l()),this.unsubs=[],window.removeEventListener("scroll",this.handleScroll),document.removeEventListener("selectionchange",this.handleSelectionChange),this._viewportThrottleTimer&&(clearTimeout(this._viewportThrottleTimer),this._viewportThrottleTimer=null),this._selectionThrottleTimer&&(clearTimeout(this._selectionThrottleTimer),this._selectionThrottleTimer=null),(e=this.cursorOverlay)==null||e.destroy(),(t=this.commentPins)==null||t.destroy(),(i=this.viewportOverlay)==null||i.destroy(),(s=this.selectionOverlay)==null||s.destroy(),(o=this.drawingOverlay)==null||o.destroy(),(r=this.client)==null||r.disconnect(),this.client=void 0,this.cursorOverlay=void 0,this.commentPins=void 0,this.viewportOverlay=void 0,this.selectionOverlay=void 0,this.drawingOverlay=void 0,this.clientConfigKey="",this.followingUserId=null,this.drawModeActive=!1,this.connectionState="disconnected",this.showConnectedFlash=!1,this._wasDisconnected=!1,this._connectedFlashTimer&&(clearTimeout(this._connectedFlashTimer),this._connectedFlashTimer=null)}handlePanelClose(){this.activePanel=null,this.highlightThreadId=null}handleToolbarAction(e){var i,s,o,r;const t=e.detail;if(!(!this.settings.enabled&&t!=="settings"))switch(t){case"comments":this.activePanel=this.activePanel==="comments"?null:"comments",this.highlightThreadId=null;break;case"settings":this.activePanel=this.activePanel==="settings"?null:"settings";break;case"notifications":this.activePanel=this.activePanel==="notifications"?null:"notifications";break;case"activity":this.activePanel=this.activePanel==="activity"?null:"activity";break;case"pin-mode":this.pinModeActive=!this.pinModeActive,this.pinModeActive?(i=this.commentPins)==null||i.enterPinMode():(s=this.commentPins)==null||s.exitPinMode();break;case"draw-mode":this.drawModeActive=!this.drawModeActive,this.drawModeActive?(o=this.drawingOverlay)==null||o.enableDrawMode():(r=this.drawingOverlay)==null||r.disableDrawMode();break}}handleFollow(e){const t=e.detail;this.followingUserId===t?this.followingUserId=null:this.followingUserId=t}handleSettingsChange(e){const t=e.detail;this.settings=t,ls(this.room,t),this.applySettings(t)}applySettings(e){var t,i,s,o,r,l,a,c,p,d,f,u,g,v,k,w,C;if(!e.enabled){(t=this.cursorOverlay)==null||t.disable(),(i=this.viewportOverlay)==null||i.disable(),(s=this.selectionOverlay)==null||s.disable(),(o=this.drawingOverlay)==null||o.disable(),this.drawModeActive&&((r=this.drawingOverlay)==null||r.disableDrawMode(),this.drawModeActive=!1),(l=this.client)==null||l.setAppearOffline(!0),(a=this.commentPins)==null||a.setVisible(!1),this.followingUserId=null,this.pinModeActive&&((c=this.commentPins)==null||c.exitPinMode(),this.pinModeActive=!1),this.activePanel=this.activePanel==="settings"?"settings":null,this.highlightThreadId=null;return}this.applyCursorSettings(e),(p=this.client)==null||p.setAppearOffline(e.appearOffline),(d=this.commentPins)==null||d.setVisible(e.showCommentPins),e.showViewportIndicators?(f=this.viewportOverlay)==null||f.enable():(u=this.viewportOverlay)==null||u.disable(),e.showSelections?(g=this.selectionOverlay)==null||g.enable():(v=this.selectionOverlay)==null||v.disable(),e.showDrawings?(k=this.drawingOverlay)==null||k.enable():((w=this.drawingOverlay)==null||w.disable(),this.drawModeActive&&((C=this.drawingOverlay)==null||C.disableDrawMode(),this.drawModeActive=!1))}applyCursorSettings(e){if(!this.cursorOverlay)return;e.showMyCursor||e.showOthersCursors?(this.cursorOverlay.enable(),this.cursorOverlay.setSending(e.showMyCursor),this.cursorOverlay.setReceiving(e.showOthersCursors)):this.cursorOverlay.disable()}updated(e){(e.has("room")||e.has("token")||e.has("apiKey")||e.has("endpoint"))&&this.apiKey&&this.token&&this.room&&this.getConfigKey()!==this.clientConfigKey&&(this.teardownClient(),this.initClient(),this.activePanel=null,this.highlightThreadId=null,this.pinModeActive=!1),(e.has("activePanel")||e.has("collapsed"))&&requestAnimationFrame(()=>this.positionPopups())}positionPopups(){var v,k,w,C;const e=this.display==="inline",t=(v=this.shadowRoot)==null?void 0:v.querySelector(".inline-trigger"),i=(k=this.shadowRoot)==null?void 0:k.querySelector("pulse-widget-toolbar"),s=e?t:i;if(!s)return;const o=s.getBoundingClientRect(),r=window.innerWidth,l=window.innerHeight,a=8,c=(w=this.shadowRoot)==null?void 0:w.querySelector(".toolbar-popover");if(c){Object.assign(c.style,{top:"auto",left:"auto"});const S=c.getBoundingClientRect(),y=this.computePosition(o,S,r,l,a);c.style.top=`${y.top}px`,c.style.left=`${y.left}px`}const p=(C=this.shadowRoot)==null?void 0:C.querySelector(".panel-container");if(!p)return;Object.assign(p.style,{top:"auto",left:"auto"});const d=c??i;if(!d)return;const f=d.getBoundingClientRect(),u=p.getBoundingClientRect(),g=this.computePosition(f,u,r,l,a);p.style.top=`${g.top}px`,p.style.left=`${g.left}px`}computePosition(e,t,i,s,o){const r=e.top,l=s-e.bottom;let a;r>=t.height+o?a=e.top-t.height-o:l>=t.height+o?a=e.bottom+o:a=r>=l?Math.max(o,e.top-t.height-o):e.bottom+o;let c;const p=e.right-t.width;return p>=o?c=p:e.left+t.width+o<=i?c=e.left:c=Math.max(o,Math.min(i-t.width-o,e.left)),a=Math.max(o,Math.min(s-t.height-o,a)),c=Math.max(o,Math.min(i-t.width-o,c)),{top:a,left:c}}getFollowUserName(){var t;if(!this.followingUserId)return"";const e=(t=this.client)==null?void 0:t.state.presence.find(i=>i.user.id===this.followingUserId);return(e==null?void 0:e.user.name)??"user"}renderConnectionBanner(){return this.showConnectedFlash?h`<div class="connection-banner connected">
|
|
2831
2859
|
<span class="connection-dot"></span>Connected
|
|
2832
2860
|
</div>`:this.connectionState==="connecting"?h`<div class="connection-banner connecting">
|
|
2833
2861
|
<span class="connection-dot"></span>Reconnecting...
|
|
2834
2862
|
</div>`:this.connectionState==="disconnected"&&this.client?h`<div class="connection-banner disconnected">
|
|
2835
2863
|
<span class="connection-dot"></span>Disconnected
|
|
2836
|
-
</div>`:
|
|
2864
|
+
</div>`:m}handleToolbarToggle(){this.collapsed=!this.collapsed,this.collapsed&&(this.activePanel=null,this.highlightThreadId=null)}render(){const e=this.display==="inline";if(e&&this.collapsed)return h`
|
|
2837
2865
|
<div class="widget-root">
|
|
2838
2866
|
<div class="inline-trigger" @click=${this.handleToolbarToggle}>
|
|
2839
2867
|
<slot>Collaborate</slot>
|
|
@@ -2844,23 +2872,23 @@
|
|
|
2844
2872
|
${this.activePanel==="comments"?h`<pulse-widget-comments-panel
|
|
2845
2873
|
.client=${this.client}
|
|
2846
2874
|
.highlightThreadId=${this.highlightThreadId}
|
|
2847
|
-
></pulse-widget-comments-panel>`:
|
|
2875
|
+
></pulse-widget-comments-panel>`:m}
|
|
2848
2876
|
${this.activePanel==="settings"?h`<pulse-widget-settings-panel
|
|
2849
2877
|
.settings=${this.settings}
|
|
2850
2878
|
.roomId=${this.room}
|
|
2851
2879
|
@settings-change=${this.handleSettingsChange}
|
|
2852
|
-
></pulse-widget-settings-panel>`:
|
|
2880
|
+
></pulse-widget-settings-panel>`:m}
|
|
2853
2881
|
${this.activePanel==="notifications"?h`<pulse-widget-notifications-panel
|
|
2854
2882
|
.client=${this.client}
|
|
2855
|
-
></pulse-widget-notifications-panel>`:
|
|
2883
|
+
></pulse-widget-notifications-panel>`:m}
|
|
2856
2884
|
${this.activePanel==="activity"?h`<pulse-widget-activity-panel
|
|
2857
2885
|
.client=${this.client}
|
|
2858
|
-
></pulse-widget-activity-panel>`:
|
|
2886
|
+
></pulse-widget-activity-panel>`:m}
|
|
2859
2887
|
</div>
|
|
2860
|
-
`:
|
|
2888
|
+
`:m,i=this.followingUserId?h`<div class="follow-banner">
|
|
2861
2889
|
Following ${this.getFollowUserName()}
|
|
2862
2890
|
<button @click=${()=>{this.followingUserId=null}}>Stop</button>
|
|
2863
|
-
</div>`:
|
|
2891
|
+
</div>`:m;return e?h`
|
|
2864
2892
|
${i}
|
|
2865
2893
|
<div class="widget-root">
|
|
2866
2894
|
<div class="inline-trigger" @click=${this.handleToolbarToggle}>
|
|
@@ -2903,7 +2931,7 @@
|
|
|
2903
2931
|
@toolbar-follow=${this.handleFollow}
|
|
2904
2932
|
></pulse-widget-toolbar>
|
|
2905
2933
|
</div>
|
|
2906
|
-
`}};exports.PulseWidget.styles=[K,
|
|
2934
|
+
`}};exports.PulseWidget.styles=[K,A`
|
|
2907
2935
|
:host {
|
|
2908
2936
|
display: block;
|
|
2909
2937
|
}
|
|
@@ -3077,4 +3105,4 @@
|
|
|
3077
3105
|
from { opacity: 1; }
|
|
3078
3106
|
to { opacity: 0; }
|
|
3079
3107
|
}
|
|
3080
|
-
`];
|
|
3108
|
+
`];T([b({attribute:"api-key"})],exports.PulseWidget.prototype,"apiKey",2);T([b()],exports.PulseWidget.prototype,"token",2);T([b()],exports.PulseWidget.prototype,"room",2);T([b()],exports.PulseWidget.prototype,"endpoint",2);T([b({reflect:!0})],exports.PulseWidget.prototype,"position",2);T([b({reflect:!0})],exports.PulseWidget.prototype,"display",2);T([x()],exports.PulseWidget.prototype,"collapsed",2);T([x()],exports.PulseWidget.prototype,"activePanel",2);T([x()],exports.PulseWidget.prototype,"pinModeActive",2);T([x()],exports.PulseWidget.prototype,"highlightThreadId",2);T([x()],exports.PulseWidget.prototype,"settings",2);T([x()],exports.PulseWidget.prototype,"followingUserId",2);T([x()],exports.PulseWidget.prototype,"drawModeActive",2);T([x()],exports.PulseWidget.prototype,"connectionState",2);T([x()],exports.PulseWidget.prototype,"showConnectedFlash",2);exports.PulseWidget=T([O("pulse-widget")],exports.PulseWidget);
|