@gamention/pulse-elements 0.1.22 → 0.1.23
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 +11 -11
- package/dist/pulse-elements.js +15 -13
- package/package.json +1 -1
package/dist/pulse-elements.cjs
CHANGED
|
@@ -26,11 +26,11 @@
|
|
|
26
26
|
* @license
|
|
27
27
|
* Copyright 2022 Google LLC
|
|
28
28
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
29
|
-
*/function ae({context:o,subscribe:e}){return(t,i)=>{typeof i=="object"?i.addInitializer((function(){new We(this,{context:o,callback:s=>{t.set.call(this,s)},subscribe:e})})):t.constructor.addInitializer((s=>{new We(s,{context:o,callback:n=>{s[i]=n},subscribe:e})}))}}var Ot=Object.defineProperty,Rt=(o,e,t)=>e in o?Ot(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,E=(o,e,t)=>Rt(o,typeof e!="symbol"?e+"":e,t);const ke={allowImages:!0,allowAudio:!0,allowVideo:!0,maxFileSizeMb:10,maxAttachmentsPerComment:5,allowReactions:!0,allowDrawing:!0,allowMentions:!0,showCursors:!0,showPresence:!0,showTypingIndicators:!0},Lt="ws://localhost:4567",Ve=50,jt=3e4,Ut=1e3,zt=3e4;let Re=class{constructor(){E(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()}},Dt=class extends Re{constructor(e){super(),E(this,"ws",null),E(this,"endpoint"),E(this,"reconnectAttempt",0),E(this,"reconnectTimer",null),E(this,"_state","disconnected"),this.endpoint=e??Lt}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(Ut*2**this.reconnectAttempt,zt);this.reconnectAttempt++,this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.connect()},e)}},Nt=class extends Re{constructor(){super(...arguments),E(this,"baseUrl",""),E(this,"_user",null),E(this,"_config",{...ke}),E(this,"_users",new Map),E(this,"_presence",new Map),E(this,"_threads",new Map),E(this,"_reactions",new Map),E(this,"_notifications",[]),E(this,"_activityLogs",[]),E(this,"_typing",new Map),E(this,"_viewports",new Map),E(this,"_selections",new Map)}get user(){return this._user}get config(){return this._config}removeComment(e){for(const[t,i]of this._threads){const s=i.comments.findIndex(n=>n.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}markNotificationRead(e){const t=this._notifications.find(i=>i.id===e);t&&!t.read&&(t.read=!0,this.emit("notifications",this._notifications))}markAllNotificationsRead(){let e=!1;for(const t of this._notifications)t.read||(t.read=!0,e=!0);e&&this.emit("notifications",this._notifications)}get activityLogs(){return this._activityLogs}getUser(e){return this._users.get(e)}get users(){return[...this._users.values()]}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[n,r]of t)i-r<3e3&&s.push(n);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._config=e.config??{...ke},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._config={...ke},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()}},bt=class extends Re{constructor(e){var t;super(),E(this,"state"),E(this,"connection"),E(this,"config"),E(this,"heartbeatTimer",null),E(this,"lastCursorSend",0),E(this,"pendingCursor",null),E(this,"cursorTimer",null),this.config=e,this.state=new Nt,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 Dt(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>=Ve?this.flushCursor():this.cursorTimer||(this.cursorTimer=setTimeout(()=>{this.cursorTimer=null,this.flushCursor()},Ve))}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"})},jt)}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 n=crypto.randomUUID();return this.send({type:"comment:create",threadId:e,id:n,body:t,mentions:i,attachmentIds:s}),n}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.state.markNotificationRead(e),this.send({type:"notification:read",notificationId:e})}markAllRead(){this.state.markAllNotificationsRead(),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 n=await s.json();return n.url&&!n.url.startsWith("http")&&(n.url=`${t}${n.url}`),n.thumbnailUrl&&!n.thumbnailUrl.startsWith("http")&&(n.thumbnailUrl=`${t}${n.thumbnailUrl}`),n}setAppearOffline(e){e?(this.stopHeartbeat(),this.send({type:"presence:update",status:"idle"})):(this.startHeartbeat(),this.send({type:"presence:update",status:"online"}))}};/**
|
|
29
|
+
*/function ae({context:o,subscribe:e}){return(t,i)=>{typeof i=="object"?i.addInitializer((function(){new We(this,{context:o,callback:s=>{t.set.call(this,s)},subscribe:e})})):t.constructor.addInitializer((s=>{new We(s,{context:o,callback:n=>{s[i]=n},subscribe:e})}))}}var Ot=Object.defineProperty,Rt=(o,e,t)=>e in o?Ot(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,E=(o,e,t)=>Rt(o,typeof e!="symbol"?e+"":e,t);const ke={allowImages:!0,allowAudio:!0,allowVideo:!0,maxFileSizeMb:10,maxAttachmentsPerComment:5,allowReactions:!0,allowDrawing:!0,allowMentions:!0,showCursors:!0,showPresence:!0,showTypingIndicators:!0},Lt="ws://localhost:4567",Ve=50,jt=3e4,Ut=1e3,zt=3e4;let Re=class{constructor(){E(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()}},Dt=class extends Re{constructor(e){super(),E(this,"ws",null),E(this,"endpoint"),E(this,"reconnectAttempt",0),E(this,"reconnectTimer",null),E(this,"_state","disconnected"),this.endpoint=e??Lt}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(Ut*2**this.reconnectAttempt,zt);this.reconnectAttempt++,this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.connect()},e)}},Ht=class extends Re{constructor(){super(...arguments),E(this,"baseUrl",""),E(this,"_user",null),E(this,"_config",{...ke}),E(this,"_users",new Map),E(this,"_presence",new Map),E(this,"_threads",new Map),E(this,"_reactions",new Map),E(this,"_notifications",[]),E(this,"_activityLogs",[]),E(this,"_typing",new Map),E(this,"_viewports",new Map),E(this,"_selections",new Map)}get user(){return this._user}get config(){return this._config}removeComment(e){for(const[t,i]of this._threads){const s=i.comments.findIndex(n=>n.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}markNotificationRead(e){const t=this._notifications.find(i=>i.id===e);t&&!t.read&&(t.read=!0,this.emit("notifications",this._notifications))}markAllNotificationsRead(){let e=!1;for(const t of this._notifications)t.read||(t.read=!0,e=!0);e&&this.emit("notifications",this._notifications)}get activityLogs(){return this._activityLogs}getUser(e){return this._users.get(e)}get users(){return[...this._users.values()]}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[n,r]of t)i-r<3e3&&s.push(n);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._config=e.config??{...ke},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._config={...ke},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()}},bt=class extends Re{constructor(e){var t;super(),E(this,"state"),E(this,"connection"),E(this,"config"),E(this,"heartbeatTimer",null),E(this,"lastCursorSend",0),E(this,"pendingCursor",null),E(this,"cursorTimer",null),this.config=e,this.state=new Ht,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 Dt(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>=Ve?this.flushCursor():this.cursorTimer||(this.cursorTimer=setTimeout(()=>{this.cursorTimer=null,this.flushCursor()},Ve))}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"})},jt)}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 n=crypto.randomUUID();return this.send({type:"comment:create",threadId:e,id:n,body:t,mentions:i,attachmentIds:s}),n}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.state.markNotificationRead(e),this.send({type:"notification:read",notificationId:e})}markAllRead(){this.state.markAllNotificationsRead(),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 n=await s.json();return n.url&&!n.url.startsWith("http")&&(n.url=`${t}${n.url}`),n.thumbnailUrl&&!n.thumbnailUrl.startsWith("http")&&(n.thumbnailUrl=`${t}${n.thumbnailUrl}`),n}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 ue=globalThis,Le=ue.ShadowRoot&&(ue.ShadyCSS===void 0||ue.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,je=Symbol(),Xe=new WeakMap;let xt=class{constructor(e,t,i){if(this._$cssResult$=!0,i!==je)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(Le&&e===void 0){const i=t!==void 0&&t.length===1;i&&(e=Xe.get(t)),e===void 0&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),i&&Xe.set(t,e))}return e}toString(){return this.cssText}};const
|
|
33
|
+
*/const ue=globalThis,Le=ue.ShadowRoot&&(ue.ShadyCSS===void 0||ue.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,je=Symbol(),Xe=new WeakMap;let xt=class{constructor(e,t,i){if(this._$cssResult$=!0,i!==je)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(Le&&e===void 0){const i=t!==void 0&&t.length===1;i&&(e=Xe.get(t)),e===void 0&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),i&&Xe.set(t,e))}return e}toString(){return this.cssText}};const Nt=o=>new xt(typeof o=="string"?o:o+"",void 0,je),M=(o,...e)=>{const t=o.length===1?o[0]:e.reduce((i,s,n)=>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)+o[n+1],o[0]);return new xt(t,o,je)},Bt=(o,e)=>{if(Le)o.adoptedStyleSheets=e.map(t=>t instanceof CSSStyleSheet?t:t.styleSheet);else for(const t of e){const i=document.createElement("style"),s=ue.litNonce;s!==void 0&&i.setAttribute("nonce",s),i.textContent=t.cssText,o.appendChild(i)}},Ye=Le?o=>o:o=>o instanceof CSSStyleSheet?(e=>{let t="";for(const i of e.cssRules)t+=i.cssText;return Nt(t)})(o):o;/**
|
|
34
34
|
* @license
|
|
35
35
|
* Copyright 2017 Google LLC
|
|
36
36
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
* Copyright 2017 Google LLC
|
|
40
40
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
41
41
|
*/const ee=globalThis,Je=o=>o,ve=ee.trustedTypes,Ze=ve?ve.createPolicy("lit-html",{createHTML:o=>o}):void 0,yt="$lit$",z=`lit$${Math.random().toFixed(9).slice(2)}$`,wt="?"+z,Gt=`<${wt}>`,F=document,ie=()=>F.createComment(""),se=o=>o===null||typeof o!="object"&&typeof o!="function",ze=Array.isArray,Jt=o=>ze(o)||typeof(o==null?void 0:o[Symbol.iterator])=="function",Ce=`[
|
|
42
|
-
\f\r]`,Z=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,Qe=/-->/g,et=/>/g,
|
|
43
|
-
\f\r"'\`<>=]|("|')|))|$)`,"g"),tt=/'/g,it=/"/g,$t=/^(?:script|style|textarea|title)$/i,kt=o=>(e,...t)=>({_$litType$:o,strings:e,values:t}),p=kt(1),Zt=kt(2),W=Symbol.for("lit-noChange"),g=Symbol.for("lit-nothing"),st=new WeakMap,
|
|
42
|
+
\f\r]`,Z=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,Qe=/-->/g,et=/>/g,H=RegExp(`>|${Ce}(?:([^\\s"'>=/]+)(${Ce}*=${Ce}*(?:[^
|
|
43
|
+
\f\r"'\`<>=]|("|')|))|$)`,"g"),tt=/'/g,it=/"/g,$t=/^(?:script|style|textarea|title)$/i,kt=o=>(e,...t)=>({_$litType$:o,strings:e,values:t}),p=kt(1),Zt=kt(2),W=Symbol.for("lit-noChange"),g=Symbol.for("lit-nothing"),st=new WeakMap,N=F.createTreeWalker(F,129);function Et(o,e){if(!ze(o)||!o.hasOwnProperty("raw"))throw Error("invalid template strings array");return Ze!==void 0?Ze.createHTML(e):e}const Qt=(o,e)=>{const t=o.length-1,i=[];let s,n=e===2?"<svg>":e===3?"<math>":"",r=Z;for(let a=0;a<t;a++){const l=o[a];let d,c,h=-1,u=0;for(;u<l.length&&(r.lastIndex=u,c=r.exec(l),c!==null);)u=r.lastIndex,r===Z?c[1]==="!--"?r=Qe:c[1]!==void 0?r=et:c[2]!==void 0?($t.test(c[2])&&(s=RegExp("</"+c[2],"g")),r=H):c[3]!==void 0&&(r=H):r===H?c[0]===">"?(r=s??Z,h=-1):c[1]===void 0?h=-2:(h=r.lastIndex-c[2].length,d=c[1],r=c[3]===void 0?H:c[3]==='"'?it:tt):r===it||r===tt?r=H:r===Qe||r===et?r=Z:(r=H,s=void 0);const f=r===H&&o[a+1].startsWith("/>")?" ":"";n+=r===Z?l+Gt:h>=0?(i.push(d),l.slice(0,h)+yt+l.slice(h)+z+f):l+z+(h===-2?a:f)}return[Et(o,n+(o[t]||"<?>")+(e===2?"</svg>":e===3?"</math>":"")),i]};class ne{constructor({strings:e,_$litType$:t},i){let s;this.parts=[];let n=0,r=0;const a=e.length-1,l=this.parts,[d,c]=Qt(e,t);if(this.el=ne.createElement(d,i),N.currentNode=this.el.content,t===2||t===3){const h=this.el.content.firstChild;h.replaceWith(...h.childNodes)}for(;(s=N.nextNode())!==null&&l.length<a;){if(s.nodeType===1){if(s.hasAttributes())for(const h of s.getAttributeNames())if(h.endsWith(yt)){const u=c[r++],f=s.getAttribute(h).split(z),b=/([.?@])?(.*)/.exec(u);l.push({type:1,index:n,name:b[2],strings:f,ctor:b[1]==="."?ti:b[1]==="?"?ii:b[1]==="@"?si:ye}),s.removeAttribute(h)}else h.startsWith(z)&&(l.push({type:6,index:n}),s.removeAttribute(h));if($t.test(s.tagName)){const h=s.textContent.split(z),u=h.length-1;if(u>0){s.textContent=ve?ve.emptyScript:"";for(let f=0;f<u;f++)s.append(h[f],ie()),N.nextNode(),l.push({type:2,index:++n});s.append(h[u],ie())}}}else if(s.nodeType===8)if(s.data===wt)l.push({type:2,index:n});else{let h=-1;for(;(h=s.data.indexOf(z,h+1))!==-1;)l.push({type:7,index:n}),h+=z.length-1}n++}}static createElement(e,t){const i=F.createElement("template");return i.innerHTML=e,i}}function X(o,e,t=o,i){var r,a;if(e===W)return e;let s=i!==void 0?(r=t._$Co)==null?void 0:r[i]:t._$Cl;const n=se(e)?void 0:e._$litDirective$;return(s==null?void 0:s.constructor)!==n&&((a=s==null?void 0:s._$AO)==null||a.call(s,!1),n===void 0?s=void 0:(s=new n(o),s._$AT(o,t,i)),i!==void 0?(t._$Co??(t._$Co=[]))[i]=s:t._$Cl=s),s!==void 0&&(e=X(o,s._$AS(o,e.values),s,i)),e}class ei{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)??F).importNode(t,!0);N.currentNode=s;let n=N.nextNode(),r=0,a=0,l=i[0];for(;l!==void 0;){if(r===l.index){let d;l.type===2?d=new le(n,n.nextSibling,this,e):l.type===1?d=new l.ctor(n,l.name,l.strings,this,e):l.type===6&&(d=new ni(n,this,e)),this._$AV.push(d),l=i[++a]}r!==(l==null?void 0:l.index)&&(n=N.nextNode(),r++)}return N.currentNode=F,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 le{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=g,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=X(this,e,t),se(e)?e===g||e==null||e===""?(this._$AH!==g&&this._$AR(),this._$AH=g):e!==this._$AH&&e!==W&&this._(e):e._$litType$!==void 0?this.$(e):e.nodeType!==void 0?this.T(e):Jt(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!==g&&se(this._$AH)?this._$AA.nextSibling.data=e:this.T(F.createTextNode(e)),this._$AH=e}$(e){var n;const{values:t,_$litType$:i}=e,s=typeof i=="number"?this._$AC(e):(i.el===void 0&&(i.el=ne.createElement(Et(i.h,i.h[0]),this.options)),i);if(((n=this._$AH)==null?void 0:n._$AD)===s)this._$AH.p(t);else{const r=new ei(s,this),a=r.u(this.options);r.p(t),this.T(a),this._$AH=r}}_$AC(e){let t=st.get(e.strings);return t===void 0&&st.set(e.strings,t=new ne(e)),t}k(e){ze(this._$AH)||(this._$AH=[],this._$AR());const t=this._$AH;let i,s=0;for(const n of e)s===t.length?t.push(i=new le(this.O(ie()),this.O(ie()),this,this.options)):i=t[s],i._$AI(n),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=Je(e).nextSibling;Je(e).remove(),e=s}}setConnected(e){var t;this._$AM===void 0&&(this._$Cv=e,(t=this._$AP)==null||t.call(this,e))}}class ye{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(e,t,i,s,n){this.type=1,this._$AH=g,this._$AN=void 0,this.element=e,this.name=t,this._$AM=s,this.options=n,i.length>2||i[0]!==""||i[1]!==""?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=g}_$AI(e,t=this,i,s){const n=this.strings;let r=!1;if(n===void 0)e=X(this,e,t,0),r=!se(e)||e!==this._$AH&&e!==W,r&&(this._$AH=e);else{const a=e;let l,d;for(e=n[0],l=0;l<n.length-1;l++)d=X(this,a[i+l],t,l),d===W&&(d=this._$AH[l]),r||(r=!se(d)||d!==this._$AH[l]),d===g?e=g:e!==g&&(e+=(d??"")+n[l+1]),this._$AH[l]=d}r&&!s&&this.j(e)}j(e){e===g?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,e??"")}}class ti extends ye{constructor(){super(...arguments),this.type=3}j(e){this.element[this.name]=e===g?void 0:e}}class ii extends ye{constructor(){super(...arguments),this.type=4}j(e){this.element.toggleAttribute(this.name,!!e&&e!==g)}}class si extends ye{constructor(e,t,i,s,n){super(e,t,i,s,n),this.type=5}_$AI(e,t=this){if((e=X(this,e,t,0)??g)===W)return;const i=this._$AH,s=e===g&&i!==g||e.capture!==i.capture||e.once!==i.once||e.passive!==i.passive,n=e!==g&&(i===g||s);s&&this.element.removeEventListener(this.name,this,i),n&&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 ni{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){X(this,e)}}const Pe=ee.litHtmlPolyfillSupport;Pe==null||Pe(ne,le),(ee.litHtmlVersions??(ee.litHtmlVersions=[])).push("3.3.2");const oi=(o,e,t)=>{const i=(t==null?void 0:t.renderBefore)??e;let s=i._$litPart$;if(s===void 0){const n=(t==null?void 0:t.renderBefore)??null;i._$litPart$=s=new le(e.insertBefore(ie(),n),n,void 0,t??{})}return s._$AI(o),s};/**
|
|
44
44
|
* @license
|
|
45
45
|
* Copyright 2017 Google LLC
|
|
46
46
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
@@ -492,7 +492,7 @@
|
|
|
492
492
|
margin-bottom: 8px;
|
|
493
493
|
opacity: 0.4;
|
|
494
494
|
}
|
|
495
|
-
`;ce([ae({context:Y,subscribe:!0}),w({attribute:!1})],exports.PulseComments.prototype,"client",2);ce([w({type:Boolean,attribute:"show-resolved"})],exports.PulseComments.prototype,"showResolved",2);ce([k()],exports.PulseComments.prototype,"threads",2);ce([k()],exports.PulseComments.prototype,"replyingTo",2);exports.PulseComments=ce([L("pulse-comments")],exports.PulseComments);var gi=Object.defineProperty,vi=Object.getOwnPropertyDescriptor,
|
|
495
|
+
`;ce([ae({context:Y,subscribe:!0}),w({attribute:!1})],exports.PulseComments.prototype,"client",2);ce([w({type:Boolean,attribute:"show-resolved"})],exports.PulseComments.prototype,"showResolved",2);ce([k()],exports.PulseComments.prototype,"threads",2);ce([k()],exports.PulseComments.prototype,"replyingTo",2);exports.PulseComments=ce([L("pulse-comments")],exports.PulseComments);var gi=Object.defineProperty,vi=Object.getOwnPropertyDescriptor,He=(o,e,t,i)=>{for(var s=i>1?void 0:i?vi(e,t):e,n=o.length-1,r;n>=0;n--)(r=o[n])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&gi(e,t,s),s};const bi={"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"},xi={"comment:created":"💬","comment:mention":"📣","comment:reply":"↩️","thread:resolved":"✅","reaction:added":"🎉"};exports.PulseNotifications=class extends A{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(),n=Math.floor(s/6e4);if(n<1)return"just now";if(n<60)return`${n}m ago`;const r=Math.floor(n/60);return r<24?`${r}h ago`:t.toLocaleDateString()}render(){const e=this.notifications.filter(t=>!t.read).length;return p`
|
|
496
496
|
<div class="header">
|
|
497
497
|
<span class="title">
|
|
498
498
|
Notifications
|
|
@@ -663,7 +663,7 @@
|
|
|
663
663
|
margin-bottom: 8px;
|
|
664
664
|
opacity: 0.4;
|
|
665
665
|
}
|
|
666
|
-
`;
|
|
666
|
+
`;He([ae({context:Y,subscribe:!0}),w({attribute:!1})],exports.PulseNotifications.prototype,"client",2);He([k()],exports.PulseNotifications.prototype,"notifications",2);exports.PulseNotifications=He([L("pulse-notifications")],exports.PulseNotifications);var yi=Object.defineProperty,wi=Object.getOwnPropertyDescriptor,G=(o,e,t,i)=>{for(var s=i>1?void 0:i?wi(e,t):e,n=o.length-1,r;n>=0;n--)(r=o[n])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&yi(e,t,s),s};const $i=["👍","👎","❤️","🎉","👀","🚀"];exports.PulseReactions=class extends A{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 n of this.reactions){const r=e.get(n.emoji)??{count:0,userReactionId:null};r.count++,n.userId===t&&(r.userReactionId=n.id),e.set(n.emoji,r)}return[...e.entries()].map(([n,r])=>({emoji:n,...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 p`
|
|
667
667
|
${e.map(t=>p`
|
|
668
668
|
<button
|
|
669
669
|
class="reaction ${t.userReactionId?"active":""}"
|
|
@@ -986,7 +986,7 @@
|
|
|
986
986
|
.pw-scrollable::-webkit-scrollbar-track {
|
|
987
987
|
background: transparent;
|
|
988
988
|
}
|
|
989
|
-
`;var Di=Object.defineProperty,
|
|
989
|
+
`;var Di=Object.defineProperty,Hi=Object.getOwnPropertyDescriptor,Ne=(o,e,t,i)=>{for(var s=i>1?void 0:i?Hi(e,t):e,n=o.length-1,r;n>=0;n--)(r=o[n])&&(s=(i?r(e,t,s):r(s))||s);return i&&s&&Di(e,t,s),s};let q=class extends A{constructor(){super(...arguments),this.items=[],this.unsubs=[],this.counter=0}connectedCallback(){super.connectedCallback(),this.setupListeners()}disconnectedCallback(){super.disconnectedCallback(),this.unsubs.forEach(o=>o()),this.unsubs=[]}updated(o){o.has("client")&&this.client&&(this.unsubs.forEach(e=>e()),this.unsubs=[],this.setupListeners())}setupListeners(){if(!this.client)return;const o=this.client.state.activityLogs;o.length>0&&(this.items=o.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(o){return{id:o.id,type:o.type,userId:o.userId,description:o.description,timestamp:new Date(o.createdAt).getTime(),color:q.TYPE_COLORS[o.type]??"#94a3b8"}}getUserName(o){var e;return((e=this.client.state.getUser(o))==null?void 0:e.name)??"Someone"}formatRelativeTime(o){const e=Math.floor((Date.now()-o)/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 p`
|
|
990
990
|
<div class="panel">
|
|
991
991
|
<div class="panel-header">
|
|
992
992
|
<span class="panel-title">Activity</span>
|
|
@@ -1133,7 +1133,7 @@
|
|
|
1133
1133
|
border-radius: 16px 16px 0 0;
|
|
1134
1134
|
}
|
|
1135
1135
|
}
|
|
1136
|
-
`];q.TYPE_COLORS={join:"#22c55e",leave:"#94a3b8",thread:"var(--pw-accent, #6366f1)",comment:"#3b82f6",resolve:"#22c55e"};
|
|
1136
|
+
`];q.TYPE_COLORS={join:"#22c55e",leave:"#94a3b8",thread:"var(--pw-accent, #6366f1)",comment:"#3b82f6",resolve:"#22c55e"};Ne([w({attribute:!1})],q.prototype,"client",2);Ne([k()],q.prototype,"items",2);q=Ne([L("pulse-widget-activity-panel")],q);const Ni="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",nt="#6366f1",ot="#e2e8f0",Bi="#f8fafc",Fi="#e2e8f0",rt="#64748b",fe=28,Wi=Array.from({length:fe},(o,e)=>.2+Math.abs(Math.sin(e*12.9898+78.233)*43758.5453)%1*.8);function at(o){const e=Math.max(0,Math.floor(o)),t=Math.floor(e/60),i=e%60;return`${t}:${i.toString().padStart(2,"0")}`}class _e{static render(e,t){let i=!1,s=t!=null?t/1e3:0,n=0;const r=document.createElement("audio");r.preload="metadata",r.src=e;const a=document.createElement("div");Object.assign(a.style,{display:"inline-flex",alignItems:"center",gap:"10px",width:"220px",height:"44px",padding:"0 10px",background:Bi,borderRadius:"12px",border:`1px solid ${Fi}`,fontFamily:Ni,fontSize:"11px",color:rt,userSelect:"none",boxSizing:"border-box"});const l=document.createElement("button");Object.assign(l.style,{width:"28px",height:"28px",minWidth:"28px",borderRadius:"50%",border:"none",background:nt,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",padding:"0",outline:"none",flexShrink:"0"});const d=document.createElement("span");Object.assign(d.style,{display:"block",width:"10px",height:"12px",lineHeight:"0"});function c(){d.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 h(){d.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"/>
|
|
@@ -1262,9 +1262,9 @@
|
|
|
1262
1262
|
background: #e2e8f0;
|
|
1263
1263
|
color: #0f172a;
|
|
1264
1264
|
}
|
|
1265
|
-
`;function dt(o){return o.toString().padStart(2,"0")}function Zi(o){const e=Math.floor(o/60),t=o%60;return`${dt(e)}:${dt(t)}`}function Qi(){const o=["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm","video/mp4"];for(const e of o)if(MediaRecorder.isTypeSupported(e))return e;return""}function es(o){return new Promise((e,t)=>{const i=URL.createObjectURL(o),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 n=document.createElement("canvas");n.width=s.videoWidth||240,n.height=s.videoHeight||240,n.getContext("2d").drawImage(s,0,0,n.width,n.height),URL.revokeObjectURL(i),n.toBlob(a=>{a?e(a):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 Me{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=Qi(),s={};i&&(s.mimeType=i);const n=new MediaRecorder(t,s);return this.mediaRecorder=n,n.ondataavailable=r=>{r.data.size>0&&this.chunks.push(r.data)},n.onstop=()=>{this.handleRecordingComplete()},n.start(),this.timerInterval=setInterval(()=>{this.elapsed++,this.updateTimer(),this.elapsed>=ct&&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=Ji,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 n=document.createElement("div");n.className="vr-actions";const r=document.createElement("button");r.className="vr-btn vr-btn-stop",r.textContent="Stop",r.addEventListener("click",()=>this.stopRecording()),n.appendChild(r);const a=document.createElement("button");a.className="vr-btn vr-btn-cancel",a.textContent="Cancel",a.addEventListener("click",()=>this.cancelRecording()),n.appendChild(a),this.root.appendChild(n),e.appendChild(this.root)}updateTimer(){if(!this.timerEl)return;const e=ct-this.elapsed;this.timerEl.textContent=Zi(this.elapsed),e<=10?this.timerEl.classList.add("vr-countdown"):this.timerEl.classList.remove("vr-countdown")}async handleRecordingComplete(){var s,n;const e=((s=this.mediaRecorder)==null?void 0:s.mimeType)||"video/webm",t=new Blob(this.chunks,{type:e});let i;try{i=await es(t)}catch{const r=document.createElement("canvas");r.width=1,r.height=1,i=await new Promise(a=>{r.toBlob(l=>a(l),"image/png")})}this.cleanup(),(n=this.resolvePromise)==null||n.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 ht={position:"absolute",top:"50%",transform:"translateY(-50%)",width:"44px",height:"44px",border:"none",borderRadius:"50%",background:"rgba(255,255,255,0.15)",color:"#fff",fontSize:"22px",cursor:"pointer",padding:"0",display:"flex",alignItems:"center",justifyContent:"center",transition:"background 150ms ease",zIndex:"1"},m=class m{static open(e,t,i){m.close(),m.urls=t&&t.length>1?t:[e],m.currentIndex=i??0;const s=m.urls.length>1,n=document.createElement("div");n.id="pulse-widget-lightbox",Object.assign(n.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 r=document.createElement("button");r.textContent="×",Object.assign(r.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",cursor:"pointer",padding:"0",display:"flex",alignItems:"center",justifyContent:"center",transition:"background 150ms ease",zIndex:"1"}),r.addEventListener("mouseenter",()=>{r.style.background="rgba(255,255,255,0.3)"}),r.addEventListener("mouseleave",()=>{r.style.background="rgba(255,255,255,0.15)"}),r.addEventListener("click",d=>{d.stopPropagation(),m.close()}),n.appendChild(r);const a=document.createElement("img");if(a.src=m.urls[m.currentIndex],a.alt="Lightbox image",Object.assign(a.style,{maxWidth:"90vw",maxHeight:"85vh",borderRadius:"8px",objectFit:"contain",cursor:"default",userSelect:"none",transition:"opacity 150ms ease"}),a.addEventListener("click",d=>d.stopPropagation()),n.appendChild(a),m.imgEl=a,s){const d=document.createElement("button");d.innerHTML='<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="15,18 9,12 15,6"/></svg>',Object.assign(d.style,{...ht,left:"16px"}),d.addEventListener("mouseenter",()=>{d.style.background="rgba(255,255,255,0.3)"}),d.addEventListener("mouseleave",()=>{d.style.background="rgba(255,255,255,0.15)"}),d.addEventListener("click",u=>{u.stopPropagation(),m.navigate(-1)}),n.appendChild(d),m.prevBtn=d;const c=document.createElement("button");c.innerHTML='<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="9,18 15,12 9,6"/></svg>',Object.assign(c.style,{...ht,right:"16px"}),c.addEventListener("mouseenter",()=>{c.style.background="rgba(255,255,255,0.3)"}),c.addEventListener("mouseleave",()=>{c.style.background="rgba(255,255,255,0.15)"}),c.addEventListener("click",u=>{u.stopPropagation(),m.navigate(1)}),n.appendChild(c),m.nextBtn=c;const h=document.createElement("span");Object.assign(h.style,{position:"absolute",bottom:"20px",left:"50%",transform:"translateX(-50%)",color:"rgba(255,255,255,0.7)",fontSize:"13px",fontWeight:"500",pointerEvents:"none"}),n.appendChild(h),m.counterEl=h,m.updateNav()}n.addEventListener("click",()=>m.close());const l=d=>{d.key==="Escape"&&m.close(),s&&d.key==="ArrowLeft"&&m.navigate(-1),s&&d.key==="ArrowRight"&&m.navigate(1)};document.addEventListener("keydown",l),m.overlay=n,m.onKeyDown=l,document.body.appendChild(n),requestAnimationFrame(()=>{n.style.opacity="1"})}static navigate(e){const t=m.urls.length;m.currentIndex=(m.currentIndex+e+t)%t,m.imgEl&&(m.imgEl.style.opacity="0",setTimeout(()=>{m.imgEl&&(m.imgEl.src=m.urls[m.currentIndex],m.imgEl.style.opacity="1")},100)),m.updateNav()}static updateNav(){const e=m.currentIndex,t=m.urls.length;m.counterEl&&(m.counterEl.textContent=`${e+1} / ${t}`)}static close(){if(!m.overlay)return;const e=m.overlay;m.onKeyDown&&(document.removeEventListener("keydown",m.onKeyDown),m.onKeyDown=null),e.style.opacity="0",e.addEventListener("transitionend",()=>e.remove()),m.overlay=null,m.imgEl=null,m.prevBtn=null,m.nextBtn=null,m.counterEl=null,m.urls=[],m.currentIndex=0}};m.overlay=null,m.onKeyDown=null,m.urls=[],m.currentIndex=0,m.imgEl=null,m.prevBtn=null,m.nextBtn=null,m.counterEl=null;let xe=m;class te{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=()=>{n(),t(null)},s=async()=>{var a;n();const r=(a=this.input.files)==null?void 0:a[0];if(!r){t(null);return}this.uploading=!0;try{const l=await this.client.uploadFile(r);t(l)}catch(l){console.error("[Pulse] File upload failed:",l),t(null)}finally{this.uploading=!1}},n=()=>{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()})}pickFiles(e,t){return new Promise(i=>{this.input.accept=e,this.input.multiple=!0,this.input.value="";const s=()=>{r(),i([])},n=async()=>{r();const a=this.input.files;if(!a||a.length===0){i([]);return}const l=Array.from(a).slice(0,t);this.uploading=!0;try{const d=await Promise.all(l.map(async c=>{try{return await this.client.uploadFile(c)}catch(h){return console.error("[Pulse] File upload failed:",h),null}}));i(d.filter(c=>c!==null))}finally{this.uploading=!1,this.input.multiple=!1}},r=()=>{this.input.removeEventListener("change",n),this.input.removeEventListener("cancel",s)};this.input.addEventListener("change",n,{once:!0}),this.input.addEventListener("cancel",s,{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 ts="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif";class Oe{constructor(e){this.dropdown=null,this.target=null,this.mentionStart=-1,this.selectedIndex=0,this.filteredUsers=[],this.handleInput=()=>{var d;if(!this.target)return;const t=this.target.value,i=this.target.selectionStart??t.length,s=t.slice(0,i),n=s.lastIndexOf("@");if(n===-1||n>0&&/\w/.test(s[n-1])){this.close();return}const r=s.slice(n+1).toLowerCase();if(r.includes(" ")){this.close();return}this.mentionStart=n;const a=(d=this.client.state.user)==null?void 0:d.id,l=new Set(this.client.state.presence.map(c=>c.user.id));if(this.filteredUsers=this.client.state.users.filter(c=>c.id!==a&&c.name.toLowerCase().includes(r)).sort((c,h)=>{const u=l.has(c.id)?0:1,f=l.has(h.id)?0:1;return u-f||c.name.localeCompare(h.name)}).slice(0,5),this.filteredUsers.length===0){this.close();return}this.selectedIndex=0,this.showDropdown()},this.handleKeydown=t=>{this.dropdown&&(t.key==="ArrowDown"?(t.preventDefault(),this.selectedIndex=Math.min(this.selectedIndex+1,this.filteredUsers.length-1),this.renderItems()):t.key==="ArrowUp"?(t.preventDefault(),this.selectedIndex=Math.max(this.selectedIndex-1,0),this.renderItems()):t.key==="Enter"&&this.dropdown?(t.preventDefault(),t.stopPropagation(),this.selectUser(this.filteredUsers[this.selectedIndex])):t.key==="Escape"&&this.close())},this.handleBlur=()=>{setTimeout(()=>this.close(),150)},this.client=e}attach(e){this.target=e,e.addEventListener("input",this.handleInput),e.addEventListener("keydown",this.handleKeydown),e.addEventListener("blur",this.handleBlur)}detach(){this.target&&(this.target.removeEventListener("input",this.handleInput),this.target.removeEventListener("keydown",this.handleKeydown),this.target.removeEventListener("blur",this.handleBlur),this.target=null),this.close()}selectUser(e){if(!this.target)return;const t=this.target.value,i=this.target.selectionStart??t.length,s=e.name.split(" ")[0],n=t.slice(0,this.mentionStart),r=t.slice(i);this.target.value=`${n}@${s} ${r}`;const a=this.mentionStart+s.length+2;this.target.setSelectionRange(a,a),this.target.focus(),this.target.dispatchEvent(new Event("input",{bubbles:!0})),this.close()}showDropdown(){if(!this.target)return;this.dropdown||(this.dropdown=document.createElement("div"),Object.assign(this.dropdown.style,{position:"absolute",zIndex:"100002",background:"#fff",border:"1px solid #e2e8f0",borderRadius:"8px",boxShadow:"0 4px 16px rgba(0,0,0,0.12)",overflow:"hidden",fontFamily:ts,minWidth:"160px",maxWidth:"220px"}),document.body.appendChild(this.dropdown));const e=this.target.getBoundingClientRect();this.dropdown.style.left=`${e.left}px`,this.dropdown.style.top=`${e.bottom+4}px`,this.renderItems()}renderItems(){if(!this.dropdown)return;const e=new Set(this.client.state.presence.map(t=>t.user.id));this.dropdown.innerHTML=this.filteredUsers.map((t,i)=>{const s=t.name.split(" ").map(a=>a[0]).join("").toUpperCase().slice(0,2),n=i===this.selectedIndex,r=e.has(t.id);return`
|
|
1265
|
+
`;function dt(o){return o.toString().padStart(2,"0")}function Zi(o){const e=Math.floor(o/60),t=o%60;return`${dt(e)}:${dt(t)}`}function Qi(){const o=["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm","video/mp4"];for(const e of o)if(MediaRecorder.isTypeSupported(e))return e;return""}function es(o){return new Promise((e,t)=>{const i=URL.createObjectURL(o),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 n=document.createElement("canvas");n.width=s.videoWidth||240,n.height=s.videoHeight||240,n.getContext("2d").drawImage(s,0,0,n.width,n.height),URL.revokeObjectURL(i),n.toBlob(a=>{a?e(a):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 Me{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=Qi(),s={};i&&(s.mimeType=i);const n=new MediaRecorder(t,s);return this.mediaRecorder=n,n.ondataavailable=r=>{r.data.size>0&&this.chunks.push(r.data)},n.onstop=()=>{this.handleRecordingComplete()},n.start(),this.timerInterval=setInterval(()=>{this.elapsed++,this.updateTimer(),this.elapsed>=ct&&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=Ji,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 n=document.createElement("div");n.className="vr-actions";const r=document.createElement("button");r.className="vr-btn vr-btn-stop",r.textContent="Stop",r.addEventListener("click",()=>this.stopRecording()),n.appendChild(r);const a=document.createElement("button");a.className="vr-btn vr-btn-cancel",a.textContent="Cancel",a.addEventListener("click",()=>this.cancelRecording()),n.appendChild(a),this.root.appendChild(n),e.appendChild(this.root)}updateTimer(){if(!this.timerEl)return;const e=ct-this.elapsed;this.timerEl.textContent=Zi(this.elapsed),e<=10?this.timerEl.classList.add("vr-countdown"):this.timerEl.classList.remove("vr-countdown")}async handleRecordingComplete(){var s,n;const e=((s=this.mediaRecorder)==null?void 0:s.mimeType)||"video/webm",t=new Blob(this.chunks,{type:e});let i;try{i=await es(t)}catch{const r=document.createElement("canvas");r.width=1,r.height=1,i=await new Promise(a=>{r.toBlob(l=>a(l),"image/png")})}this.cleanup(),(n=this.resolvePromise)==null||n.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 ht={position:"absolute",top:"50%",transform:"translateY(-50%)",width:"44px",height:"44px",border:"none",borderRadius:"50%",background:"rgba(255,255,255,0.15)",color:"#fff",fontSize:"22px",cursor:"pointer",padding:"0",display:"flex",alignItems:"center",justifyContent:"center",transition:"background 150ms ease",zIndex:"1"},m=class m{static open(e,t,i){m.close(),m.urls=t&&t.length>1?t:[e],m.currentIndex=i??0;const s=m.urls.length>1,n=document.createElement("div");n.id="pulse-widget-lightbox",Object.assign(n.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 r=document.createElement("button");r.textContent="×",Object.assign(r.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",cursor:"pointer",padding:"0",display:"flex",alignItems:"center",justifyContent:"center",transition:"background 150ms ease",zIndex:"1"}),r.addEventListener("mouseenter",()=>{r.style.background="rgba(255,255,255,0.3)"}),r.addEventListener("mouseleave",()=>{r.style.background="rgba(255,255,255,0.15)"}),r.addEventListener("click",d=>{d.stopPropagation(),m.close()}),n.appendChild(r);const a=document.createElement("img");if(a.src=m.urls[m.currentIndex],a.alt="Lightbox image",Object.assign(a.style,{maxWidth:"90vw",maxHeight:"85vh",borderRadius:"8px",objectFit:"contain",cursor:"default",userSelect:"none",transition:"opacity 150ms ease"}),a.addEventListener("click",d=>d.stopPropagation()),n.appendChild(a),m.imgEl=a,s){const d=document.createElement("button");d.innerHTML='<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="15,18 9,12 15,6"/></svg>',Object.assign(d.style,{...ht,left:"16px"}),d.addEventListener("mouseenter",()=>{d.style.background="rgba(255,255,255,0.3)"}),d.addEventListener("mouseleave",()=>{d.style.background="rgba(255,255,255,0.15)"}),d.addEventListener("click",u=>{u.stopPropagation(),m.navigate(-1)}),n.appendChild(d),m.prevBtn=d;const c=document.createElement("button");c.innerHTML='<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="9,18 15,12 9,6"/></svg>',Object.assign(c.style,{...ht,right:"16px"}),c.addEventListener("mouseenter",()=>{c.style.background="rgba(255,255,255,0.3)"}),c.addEventListener("mouseleave",()=>{c.style.background="rgba(255,255,255,0.15)"}),c.addEventListener("click",u=>{u.stopPropagation(),m.navigate(1)}),n.appendChild(c),m.nextBtn=c;const h=document.createElement("span");Object.assign(h.style,{position:"absolute",bottom:"20px",left:"50%",transform:"translateX(-50%)",color:"rgba(255,255,255,0.7)",fontSize:"13px",fontWeight:"500",pointerEvents:"none"}),n.appendChild(h),m.counterEl=h,m.updateNav()}n.addEventListener("click",()=>m.close());const l=d=>{d.key==="Escape"&&m.close(),s&&d.key==="ArrowLeft"&&m.navigate(-1),s&&d.key==="ArrowRight"&&m.navigate(1)};document.addEventListener("keydown",l),m.overlay=n,m.onKeyDown=l,document.body.appendChild(n),requestAnimationFrame(()=>{n.style.opacity="1"})}static navigate(e){const t=m.urls.length;m.currentIndex=(m.currentIndex+e+t)%t,m.imgEl&&(m.imgEl.style.opacity="0",setTimeout(()=>{m.imgEl&&(m.imgEl.src=m.urls[m.currentIndex],m.imgEl.style.opacity="1")},100)),m.updateNav()}static updateNav(){const e=m.currentIndex,t=m.urls.length;m.counterEl&&(m.counterEl.textContent=`${e+1} / ${t}`)}static close(){if(!m.overlay)return;const e=m.overlay;m.onKeyDown&&(document.removeEventListener("keydown",m.onKeyDown),m.onKeyDown=null),e.style.opacity="0",e.addEventListener("transitionend",()=>e.remove()),m.overlay=null,m.imgEl=null,m.prevBtn=null,m.nextBtn=null,m.counterEl=null,m.urls=[],m.currentIndex=0}};m.overlay=null,m.onKeyDown=null,m.urls=[],m.currentIndex=0,m.imgEl=null,m.prevBtn=null,m.nextBtn=null,m.counterEl=null;let xe=m;class te{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=()=>{n(),t(null)},s=async()=>{var a;n();const r=(a=this.input.files)==null?void 0:a[0];if(!r){t(null);return}this.uploading=!0;try{const l=await this.client.uploadFile(r);t(l)}catch(l){console.error("[Pulse] File upload failed:",l),t(null)}finally{this.uploading=!1}},n=()=>{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()})}pickFiles(e,t){return new Promise(i=>{this.input.accept=e,this.input.multiple=!0,this.input.value="";const s=()=>{r(),i([])},n=async()=>{r();const a=this.input.files;if(!a||a.length===0){i([]);return}const l=Array.from(a).slice(0,t);this.uploading=!0;try{const d=await Promise.all(l.map(async c=>{try{return await this.client.uploadFile(c)}catch(h){return console.error("[Pulse] File upload failed:",h),null}}));i(d.filter(c=>c!==null))}finally{this.uploading=!1,this.input.multiple=!1}},r=()=>{this.input.removeEventListener("change",n),this.input.removeEventListener("cancel",s)};this.input.addEventListener("change",n,{once:!0}),this.input.addEventListener("cancel",s,{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 ts="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif";class Oe{constructor(e){this.dropdown=null,this.target=null,this.mentionStart=-1,this.selectedIndex=0,this.filteredUsers=[],this.isSelecting=!1,this.handleInput=()=>{var d;if(!this.target)return;const t=this.target.value,i=this.target.selectionStart??t.length,s=t.slice(0,i),n=s.lastIndexOf("@");if(n===-1||n>0&&/\w/.test(s[n-1])){this.close();return}const r=s.slice(n+1).toLowerCase();if(r.length>30){this.close();return}this.mentionStart=n;const a=(d=this.client.state.user)==null?void 0:d.id,l=new Set(this.client.state.presence.map(c=>c.user.id));if(this.filteredUsers=this.client.state.users.filter(c=>c.id!==a&&c.name.toLowerCase().includes(r)).sort((c,h)=>{const u=l.has(c.id)?0:1,f=l.has(h.id)?0:1;return u-f||c.name.localeCompare(h.name)}).slice(0,5),this.filteredUsers.length===0){this.close();return}this.selectedIndex=0,this.showDropdown()},this.handleKeydown=t=>{this.dropdown&&(t.key==="ArrowDown"?(t.preventDefault(),this.selectedIndex=Math.min(this.selectedIndex+1,this.filteredUsers.length-1),this.renderItems()):t.key==="ArrowUp"?(t.preventDefault(),this.selectedIndex=Math.max(this.selectedIndex-1,0),this.renderItems()):(t.key==="Enter"||t.key==="Tab")&&this.filteredUsers.length>0?(t.preventDefault(),t.stopPropagation(),this.selectUser(this.filteredUsers[this.selectedIndex])):t.key==="Escape"&&(t.preventDefault(),this.close()))},this.handleBlur=()=>{this.isSelecting||setTimeout(()=>{this.isSelecting||this.close()},200)},this.client=e}attach(e){this.target=e,e.addEventListener("input",this.handleInput),e.addEventListener("keydown",this.handleKeydown),e.addEventListener("blur",this.handleBlur)}detach(){this.target&&(this.target.removeEventListener("input",this.handleInput),this.target.removeEventListener("keydown",this.handleKeydown),this.target.removeEventListener("blur",this.handleBlur),this.target=null),this.close()}selectUser(e){if(!this.target)return;const t=this.target.value,i=this.target.selectionStart??t.length,s=e.name.replace(/\s+/g,"_"),n=t.slice(0,this.mentionStart),r=t.slice(i);this.target.value=`${n}@${s} ${r}`;const a=this.mentionStart+s.length+2;this.target.setSelectionRange(a,a),this.target.focus(),this.target.dispatchEvent(new Event("input",{bubbles:!0})),this.isSelecting=!1,this.close()}showDropdown(){if(!this.target)return;this.dropdown||(this.dropdown=document.createElement("div"),Object.assign(this.dropdown.style,{position:"fixed",zIndex:"100002",background:"#fff",border:"1px solid #e2e8f0",borderRadius:"8px",boxShadow:"0 4px 16px rgba(0,0,0,0.12)",overflow:"hidden",fontFamily:ts,minWidth:"180px",maxWidth:"240px"}),document.body.appendChild(this.dropdown));const e=this.target.getBoundingClientRect(),t=this.filteredUsers.length*36+4,i=e.top,s=window.innerHeight-e.bottom;s>=t+4||s>i?(this.dropdown.style.top=`${e.bottom+4}px`,this.dropdown.style.bottom=""):(this.dropdown.style.bottom=`${window.innerHeight-e.top+4}px`,this.dropdown.style.top=""),this.dropdown.style.left=`${e.left}px`,this.renderItems()}renderItems(){if(!this.dropdown)return;const e=new Set(this.client.state.presence.map(t=>t.user.id));this.dropdown.innerHTML=this.filteredUsers.map((t,i)=>{const s=t.name.split(" ").map(a=>a[0]).join("").toUpperCase().slice(0,2),n=i===this.selectedIndex,r=e.has(t.id);return`
|
|
1266
1266
|
<div class="mention-item" data-index="${i}" style="
|
|
1267
|
-
display:flex;align-items:center;gap:8px;padding:
|
|
1267
|
+
display:flex;align-items:center;gap:8px;padding:8px 12px;
|
|
1268
1268
|
cursor:pointer;font-size:13px;
|
|
1269
1269
|
background:${n?"#f1f5f9":"#fff"};
|
|
1270
1270
|
transition:background 0.1s;
|
|
@@ -1280,7 +1280,7 @@
|
|
|
1280
1280
|
</div>
|
|
1281
1281
|
<span style="color:#0f172a;font-weight:500;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;">${this.escapeHtml(t.name)}</span>
|
|
1282
1282
|
</div>
|
|
1283
|
-
`}).join(""),this.dropdown.querySelectorAll(".mention-item").forEach(t=>{t.addEventListener("mousedown",i=>{i.preventDefault();const s=parseInt(t.dataset.index,10);this.selectUser(this.filteredUsers[s])}),t.addEventListener("mouseenter",()=>{this.selectedIndex=parseInt(t.dataset.index,10),this.renderItems()})})}close(){var e;(e=this.dropdown)==null||e.remove(),this.dropdown=null,this.mentionStart=-1,this.filteredUsers=[]}escapeHtml(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}}const is=["👍","👎","❤️","🎉","👀","🚀"],pe="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",ss='<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>',ns='<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>',pt=`<button class="pulse-close-btn" style="
|
|
1283
|
+
`}).join(""),this.dropdown.querySelectorAll(".mention-item").forEach(t=>{t.addEventListener("mousedown",i=>{i.preventDefault(),i.stopPropagation(),this.isSelecting=!0;const s=parseInt(t.dataset.index,10);this.selectUser(this.filteredUsers[s])}),t.addEventListener("mouseenter",()=>{this.selectedIndex=parseInt(t.dataset.index,10),this.renderItems()})})}close(){var e;(e=this.dropdown)==null||e.remove(),this.dropdown=null,this.mentionStart=-1,this.filteredUsers=[]}escapeHtml(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}}const is=["👍","👎","❤️","🎉","👀","🚀"],pe="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",ss='<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>',ns='<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>',pt=`<button class="pulse-close-btn" style="
|
|
1284
1284
|
border:none;background:none;cursor:pointer;color:#94a3b8;padding:4px;
|
|
1285
1285
|
border-radius:6px;display:flex;align-items:center;justify-content:center;
|
|
1286
1286
|
transition:all 0.15s;flex-shrink:0;
|
package/dist/pulse-elements.js
CHANGED
|
@@ -3884,7 +3884,7 @@ class re {
|
|
|
3884
3884
|
const ls = "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif";
|
|
3885
3885
|
class He {
|
|
3886
3886
|
constructor(e) {
|
|
3887
|
-
this.dropdown = null, this.target = null, this.mentionStart = -1, this.selectedIndex = 0, this.filteredUsers = [], this.handleInput = () => {
|
|
3887
|
+
this.dropdown = null, this.target = null, this.mentionStart = -1, this.selectedIndex = 0, this.filteredUsers = [], this.isSelecting = !1, this.handleInput = () => {
|
|
3888
3888
|
var d;
|
|
3889
3889
|
if (!this.target) return;
|
|
3890
3890
|
const t = this.target.value, i = this.target.selectionStart ?? t.length, s = t.slice(0, i), o = s.lastIndexOf("@");
|
|
@@ -3893,7 +3893,7 @@ class He {
|
|
|
3893
3893
|
return;
|
|
3894
3894
|
}
|
|
3895
3895
|
const r = s.slice(o + 1).toLowerCase();
|
|
3896
|
-
if (r.
|
|
3896
|
+
if (r.length > 30) {
|
|
3897
3897
|
this.close();
|
|
3898
3898
|
return;
|
|
3899
3899
|
}
|
|
@@ -3908,9 +3908,11 @@ class He {
|
|
|
3908
3908
|
}
|
|
3909
3909
|
this.selectedIndex = 0, this.showDropdown();
|
|
3910
3910
|
}, this.handleKeydown = (t) => {
|
|
3911
|
-
this.dropdown && (t.key === "ArrowDown" ? (t.preventDefault(), this.selectedIndex = Math.min(this.selectedIndex + 1, this.filteredUsers.length - 1), this.renderItems()) : t.key === "ArrowUp" ? (t.preventDefault(), this.selectedIndex = Math.max(this.selectedIndex - 1, 0), this.renderItems()) : t.key === "Enter" && this.
|
|
3911
|
+
this.dropdown && (t.key === "ArrowDown" ? (t.preventDefault(), this.selectedIndex = Math.min(this.selectedIndex + 1, this.filteredUsers.length - 1), this.renderItems()) : t.key === "ArrowUp" ? (t.preventDefault(), this.selectedIndex = Math.max(this.selectedIndex - 1, 0), this.renderItems()) : (t.key === "Enter" || t.key === "Tab") && this.filteredUsers.length > 0 ? (t.preventDefault(), t.stopPropagation(), this.selectUser(this.filteredUsers[this.selectedIndex])) : t.key === "Escape" && (t.preventDefault(), this.close()));
|
|
3912
3912
|
}, this.handleBlur = () => {
|
|
3913
|
-
setTimeout(() =>
|
|
3913
|
+
this.isSelecting || setTimeout(() => {
|
|
3914
|
+
this.isSelecting || this.close();
|
|
3915
|
+
}, 200);
|
|
3914
3916
|
}, this.client = e;
|
|
3915
3917
|
}
|
|
3916
3918
|
/** Attach the mention picker to a text input or textarea. */
|
|
@@ -3923,15 +3925,15 @@ class He {
|
|
|
3923
3925
|
}
|
|
3924
3926
|
selectUser(e) {
|
|
3925
3927
|
if (!this.target) return;
|
|
3926
|
-
const t = this.target.value, i = this.target.selectionStart ?? t.length, s = e.name.
|
|
3928
|
+
const t = this.target.value, i = this.target.selectionStart ?? t.length, s = e.name.replace(/\s+/g, "_"), o = t.slice(0, this.mentionStart), r = t.slice(i);
|
|
3927
3929
|
this.target.value = `${o}@${s} ${r}`;
|
|
3928
3930
|
const a = this.mentionStart + s.length + 2;
|
|
3929
|
-
this.target.setSelectionRange(a, a), this.target.focus(), this.target.dispatchEvent(new Event("input", { bubbles: !0 })), this.close();
|
|
3931
|
+
this.target.setSelectionRange(a, a), this.target.focus(), this.target.dispatchEvent(new Event("input", { bubbles: !0 })), this.isSelecting = !1, this.close();
|
|
3930
3932
|
}
|
|
3931
3933
|
showDropdown() {
|
|
3932
3934
|
if (!this.target) return;
|
|
3933
3935
|
this.dropdown || (this.dropdown = document.createElement("div"), Object.assign(this.dropdown.style, {
|
|
3934
|
-
position: "
|
|
3936
|
+
position: "fixed",
|
|
3935
3937
|
zIndex: "100002",
|
|
3936
3938
|
background: "#fff",
|
|
3937
3939
|
border: "1px solid #e2e8f0",
|
|
@@ -3939,11 +3941,11 @@ class He {
|
|
|
3939
3941
|
boxShadow: "0 4px 16px rgba(0,0,0,0.12)",
|
|
3940
3942
|
overflow: "hidden",
|
|
3941
3943
|
fontFamily: ls,
|
|
3942
|
-
minWidth: "
|
|
3943
|
-
maxWidth: "
|
|
3944
|
+
minWidth: "180px",
|
|
3945
|
+
maxWidth: "240px"
|
|
3944
3946
|
}), document.body.appendChild(this.dropdown));
|
|
3945
|
-
const e = this.target.getBoundingClientRect();
|
|
3946
|
-
this.dropdown.style.
|
|
3947
|
+
const e = this.target.getBoundingClientRect(), t = this.filteredUsers.length * 36 + 4, i = e.top, s = window.innerHeight - e.bottom;
|
|
3948
|
+
s >= t + 4 || s > i ? (this.dropdown.style.top = `${e.bottom + 4}px`, this.dropdown.style.bottom = "") : (this.dropdown.style.bottom = `${window.innerHeight - e.top + 4}px`, this.dropdown.style.top = ""), this.dropdown.style.left = `${e.left}px`, this.renderItems();
|
|
3947
3949
|
}
|
|
3948
3950
|
renderItems() {
|
|
3949
3951
|
if (!this.dropdown) return;
|
|
@@ -3952,7 +3954,7 @@ class He {
|
|
|
3952
3954
|
const s = t.name.split(" ").map((a) => a[0]).join("").toUpperCase().slice(0, 2), o = i === this.selectedIndex, r = e.has(t.id);
|
|
3953
3955
|
return `
|
|
3954
3956
|
<div class="mention-item" data-index="${i}" style="
|
|
3955
|
-
display:flex;align-items:center;gap:8px;padding:
|
|
3957
|
+
display:flex;align-items:center;gap:8px;padding:8px 12px;
|
|
3956
3958
|
cursor:pointer;font-size:13px;
|
|
3957
3959
|
background:${o ? "#f1f5f9" : "#fff"};
|
|
3958
3960
|
transition:background 0.1s;
|
|
@@ -3971,7 +3973,7 @@ class He {
|
|
|
3971
3973
|
`;
|
|
3972
3974
|
}).join(""), this.dropdown.querySelectorAll(".mention-item").forEach((t) => {
|
|
3973
3975
|
t.addEventListener("mousedown", (i) => {
|
|
3974
|
-
i.preventDefault();
|
|
3976
|
+
i.preventDefault(), i.stopPropagation(), this.isSelecting = !0;
|
|
3975
3977
|
const s = parseInt(t.dataset.index, 10);
|
|
3976
3978
|
this.selectUser(this.filteredUsers[s]);
|
|
3977
3979
|
}), t.addEventListener("mouseenter", () => {
|
package/package.json
CHANGED