@realsee/live 0.7.7 → 0.7.8
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/index.cjs.js +3 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +729 -729
- package/dist/index.es.js.map +1 -1
- package/docs/classes/Live.html +13 -13
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var pn=Object.defineProperty;var _n=(i,e,t)=>e in i?pn(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var a=(i,e,t)=>_n(i,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ht=require("trtc-js-sdk"),Q=require("amazon-chime-sdk-js"),mn=require("@realsee/jsbridge-x"),y=require("react"),de=Symbol("$$REALSEE_LIVE_EVENT$$");function Be(i){return i[de]||(i[de]={}),i[de]}function Pt(i){const e=i[de];if(!e)return;Object.keys(e).some(n=>Array.isArray(e[n])&&e[n].length>0)||delete i[de]}class ge{hasListener(e){const t=Be(this);return t&&t[e]&&t[e].length>0}on(e,t,n){const s=Be(this);return s[e]||(s[e]=[]),s[e].push([t,n||!1]),()=>this.off(e,t)}once(e,t){return this.on(e,t,!0)}off(e,t){const n=Be(this);if(!e){delete this[de];return}if(n[e]||(n[e]=[]),t===void 0){n[e].length=0,Pt(this);return}const s=n[e].findIndex(r=>r[0]===t);s!==-1&&n[e].splice(s,1),Pt(this)}emit(e,...t){let n=!1;const r=Be(this)[e]||[];for(let o of r.slice()){const[c,l=!1]=o,h=c(...t);l&&this.off(e,c),h===!1&&(n=!0)}return n}}class tt extends ge{}var se=(i=>(i.RealseeBrowserRTC="RealseeBrowserRTC",i.RealseeVRWebViewRTC="RealseeVRWebViewRTC",i.RealseeBrowserChimeRTC="RealseeBrowserChimeRTC",i))(se||{}),Tt=(i=>(i.RealseeXTRTC="trtc",i.RealseeXChimeRTC="chime",i))(Tt||{});const wn=()=>{const i=new Date,e=i.getFullYear(),t=(i.getMonth()+1).toString().padStart(2,"0"),n=i.getDate().toString().padStart(2,"0"),s=i.getHours().toString().padStart(2,"0"),r=i.getMinutes().toString().padStart(2,"0"),o=i.getSeconds().toString().padStart(2,"0"),c=i.getMilliseconds().toString().padStart(3,"0");return`[${e}-${t}-${n} ${s}:${r}:${o}.${c}]`},Ie=(i,e=[])=>{const t=`Realsee Live ${wn()} <${i}> `;switch(i){case"INFO":console.info(t,...e);break;case"ERROR":console.error(t,...e);break;case"WARN":console.warn(t,...e);break;case"DEBUG":console.debug(t,...e);break;default:console.log(t,...e)}},m={log:(...i)=>Ie("LOG",i),info:(...i)=>Ie("INFO",i),error:(...i)=>Ie("ERROR",i),warn:(...i)=>Ie("WARN",i),debug:(...i)=>Ie("DEBUG",i)};function ee(){return((1+Math.random())*65536|0).toString(16).substring(1)}function Te(){return[ee(),ee(),"4"+ee().substring(0,3),ee(),ee(),ee()+ee()+ee()].join("-").toLowerCase()}class fi extends tt{constructor(t){super();a(this,"type",se.RealseeBrowserRTC);a(this,"joined",!1);a(this,"micro",!1);a(this,"voiceId","");a(this,"_getVoiceSign",()=>{throw new Error("方法 getVoiceSign 未实现")});a(this,"_autoPlayConfirm");a(this,"checkRequirement",()=>ht.checkSystemRequirements());a(this,"$dom",document.createElement("div"));a(this,"_trtc",{client:null,stream:null});a(this,"join",async t=>{var r;this.emit("joinWillStart");const n=await this._getVoiceSign({voiceId:t.voiceId,roomId:t.roomId,userId:t.userId});this._trtc.client=ht.createClient({mode:"rtc",...n,enableAutoPlayDialog:typeof this._autoPlayConfirm!="function"}),(r=this._trtc.client)==null||r.enableAudioVolumeEvaluation(),this._registerRtcEvent();let s=await new Promise(o=>{var c;(c=this._trtc.client)==null||c.join({roomId:Number(t.voiceId)}).then(()=>o(!0)).catch(()=>o(!1))});return this.joined=s,s?(this._trtc.stream=ht.createStream({userId:n.userId,audio:!0,video:!1}),s=await new Promise(o=>{var c;(c=this._trtc.stream)==null||c.initialize().then(()=>o(!0)).catch(()=>o(!1))}),s=await new Promise(o=>{var c;(c=this._trtc.client)==null||c.publish(this._trtc.stream).then(()=>o(!0)).catch(()=>o(!1))}),this.joined=s,this.joined&&this.emit("joined"),s):!1});a(this,"_handleStreamAdded",t=>{var s;const n=t.stream;m.info("远端流增加:",n.getId()),(s=this._trtc.client)==null||s.subscribe(n)});a(this,"_handleStreamSubscribed",t=>{const n=t.stream;m.info("远端流订阅成功:",n.getId());const r=`rs-rtc-remote_stream-${n.getId()}`,o=document.createElement("div");o.id=r,this.$dom.appendChild(o),typeof this._autoPlayConfirm=="function"?(n.play(r).catch(c=>{m.warn("远端流播放失败(将尝试用户确认恢复)")}),n.on("error",c=>{if(c.getCode()===16451){const h=()=>n.resume();this._autoPlayConfirm({onConfirm:h})}})):n.play(r)});this._getVoiceSign=t.getVoiceSign,this._autoPlayConfirm=t.autoPlayConfirm,this._initParentDom()}_initParentDom(){this.$dom.id=`rs-rtc-${Te()}`,this.$dom.style.display="none",document.body.appendChild(this.$dom)}quit(){return new Promise(async t=>{var n,s;this.joined=!1,this._trtc.stream&&(await((n=this._trtc.client)==null?void 0:n.unpublish(this._trtc.stream)),this._trtc.stream.stop(),this._trtc.stream.close(),this._trtc.stream=null),(s=this._trtc.client)==null||s.leave().then(()=>this._trtc.client=null).then(()=>t(!0)).catch(()=>t(!1)),t(!0)})}detectMicro(){return new Promise(t=>{const n={audio:!0,video:!1};try{navigator.mediaDevices.getUserMedia(n).then(()=>t(!0)).catch(s=>{m.error(s.message),t(!1)})}catch(s){console.error(s),t(!1)}})}toggleMicro(t){return new Promise(n=>{var s,r,o,c;try{t?((r=(s=this._trtc)==null?void 0:s.stream)==null||r.unmuteAudio(),this.micro=!0):((c=(o=this._trtc)==null?void 0:o.stream)==null||c.muteAudio(),this.micro=!1),n(!0)}catch(l){n(!1)}})}shock(){throw new Error("Method not implemented.")}_registerRtcEvent(){var t,n,s,r;(t=this._trtc.client)==null||t.on("stream-added",this._handleStreamAdded),(n=this._trtc.client)==null||n.on("stream-subscribed",this._handleStreamSubscribed),(s=this._trtc.client)==null||s.on("audio-volume",o=>this.emit("userVolumes",o.result.map(({userId:c,audioVolume:l})=>({userId:c,audioVolume:l})))),(r=this._trtc.client)==null||r.on("error",o=>this.emit("error",o))}}class Ct extends tt{constructor(t){super();a(this,"type",se.RealseeBrowserChimeRTC);a(this,"joined",!1);a(this,"micro",!1);a(this,"voiceId","");a(this,"userId","");a(this,"logger");a(this,"deviceController");a(this,"meetingSession");a(this,"audioInput");a(this,"audioOutput");a(this,"deviceChangeObserver",{});a(this,"audioVideoObserver",{});a(this,"audioMixObserver");a(this,"_getVoiceSign",()=>{throw new Error("方法 getVoiceSign 未实现")});a(this,"_autoPlayConfirm");a(this,"$dom",document.createElement("div"));a(this,"$audio",document.createElement("audio"));a(this,"_initDom",()=>{this.$audio.id=`rs-rtc-${Te()}`,this.$dom.id=`rs-rtc-${Te()}`,this.$dom.appendChild(this.$audio),document.body.appendChild(this.$dom)});a(this,"initObservers",()=>{this.deviceChangeObserver={audioInputsChanged:t=>{this.logger.info(`audioInputsChanged ${typeof t}`),t==null||t.forEach(n=>{this.logger.info(`Device ID: ${n.deviceId} Microphone: ${n.label}`)})},audioOutputsChanged:t=>{this.logger.info(`audioOutputsChanged ${typeof t}`),t==null||t.forEach(n=>{this.logger.info(`Device ID: ${n.deviceId} Speaker: ${n.label}`)})},audioInputMuteStateChanged:(t,n)=>{this.logger.info(`Device ${t.toString()} ${n?"is muted in hardware":"is not muted"}`)}},this.audioVideoObserver={audioVideoDidStart:()=>{this.logger.info("Started")},audioVideoDidStop:t=>{this.logger.info(`Stopped with a session status code: ${t.statusCode()}`)},audioVideoDidStartConnecting:t=>{t&&this.logger.info("Attempting to reconnect")}},this.audioMixObserver={meetingAudioStreamBecameActive:t=>{if(this.$audio.paused){const n=()=>this.$audio.play().then(()=>{}).catch(s=>{if(m.error("播放远端流失败!",s),typeof this._autoPlayConfirm=="function"){const r=()=>n();this._autoPlayConfirm({onConfirm:r})}});n()}},meetingAudioStreamBecameInactive:t=>{}}});a(this,"_registerRtcEvent",()=>{var n,s,r,o,c,l;const t=((r=(s=(n=this.meetingSession)==null?void 0:n.configuration)==null?void 0:s.credentials)==null?void 0:r.attendeeId)||"";if(t){const h=new Map,u=()=>{const d=[];return h.forEach((g,w)=>{d.push({userId:g.userId,volume:g.muted||g.signalStrength===0||!g.volume?0:g.volume})}),d};(o=this.meetingSession)==null||o.audioVideo.realtimeSubscribeToAttendeeIdPresence((d,g,w)=>{var b;if(!g){h.delete(d),this.emit("userVolumes",u());return}(b=this.meetingSession)==null||b.audioVideo.realtimeSubscribeToVolumeIndicator(d,(p,_,I,N)=>{new Q.DefaultModality(p).base()===p&&(h.set(p,{userId:w||p,volume:_,muted:I,signalStrength:N}),this.emit("userVolumes",u()))})}),(c=this.meetingSession)==null||c.audioVideo.realtimeSubscribeToVolumeIndicator(t,(d,g,w,b)=>{new Q.DefaultModality(d).base()===d&&b!==null&&b!==1&&this.emit("weakNetwork")}),(l=this.meetingSession)==null||l.audioVideo.realtimeSubscribeToFatalError(d=>this.emit("error",d))}});this._getVoiceSign=t.getVoiceSign,this._autoPlayConfirm=t.autoPlayConfirm,this._initDom(),this.logger=new Q.ConsoleLogger("WebRTCLogger",t.logLevel||Q.LogLevel.INFO),this.deviceController=new Q.DefaultDeviceController(this.logger),this.initObservers()}async join(t){return new Promise(async(n,s)=>{var r,o;this.emit("joinWillStart");try{const{sdkAppId:c,userId:l,roomId:h,userSig:u}=await this._getVoiceSign({...t,roomId:t.roomId||0});this.userId=l;const{attendence:d,vendor_wrapper:g}=JSON.parse(decodeURIComponent(u)),w=new Q.MeetingSessionConfiguration({Meeting:g},{Attendee:{ExternalUserId:d.external_user_id,AttendeeId:d.attendee_id,JoinToken:d.join_token}});this.meetingSession=new Q.DefaultMeetingSession(w,this.logger,this.deviceController),this._registerRtcEvent(),this.meetingSession.audioVideo.addDeviceChangeObserver(this.deviceChangeObserver),this.meetingSession.audioVideo.addObserver(this.audioVideoObserver),this.meetingSession.audioVideo.bindAudioElement(this.$audio);const b={audioVideoDidStart:()=>{var p;(p=this.meetingSession)==null||p.audioVideo.realtimeMuteLocalAudio(),this.joined=!0,this.emit("joined"),n(!0)},audioVideoDidStop:()=>{this.joined=!1,n(!1)}};this.meetingSession.audioVideo.addObserver(b),this.audioMixObserver&&this.meetingSession.audioVideo.addAudioMixObserver(this.audioMixObserver),this.meetingSession.audioVideo.setDeviceLabelTrigger(async()=>await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}));try{const p=await this.meetingSession.audioVideo.listAudioInputDevices();m.info("audioInputDevices ===>",p);const _=((r=p[0])==null?void 0:r.deviceId)||"default";await this.meetingSession.audioVideo.startAudioInput(_)}catch(p){m.error(`设置语音输入设备失败:${p.message}`)}try{const p=await this.meetingSession.audioVideo.listAudioOutputDevices();m.info("audioOutputDevices ===>",p);const _=((o=p[0])==null?void 0:o.deviceId)||"default";await this.meetingSession.audioVideo.chooseAudioOutput(_)}catch(p){m.error(`设置语音输出设备失败:${p.message}`)}this.meetingSession.audioVideo.start()}catch(c){this.emit("error",c),this.logger.error(c.message),n(!1)}})}quit(){return this.joined?new Promise((t,n)=>{var r,o;this.joined=!1;const s={audioVideoDidStop:async c=>{var h;const l=c.statusCode();(h=this.meetingSession)==null||h.deviceController.destroy(),l===Q.MeetingSessionStatusCode.Left?(this.logger.info("You left the session"),t(!0)):(this.logger.info(`Stopped with a session status code: ${l}`),t(!0))}};(r=this.meetingSession)==null||r.audioVideo.addObserver(s),(o=this.meetingSession)==null||o.audioVideo.stop()}):Promise.resolve(!0)}async detectMicro(){return new Promise(t=>{const n={audio:!0,video:!1};try{navigator.mediaDevices.getUserMedia(n).then(()=>t(!0)).catch(()=>t(!1))}catch(s){this.logger.error(s.message),t(!1)}})}async toggleMicro(t){var s,r,o;t?(s=this.meetingSession)==null||s.audioVideo.realtimeUnmuteLocalAudio():(r=this.meetingSession)==null||r.audioVideo.realtimeMuteLocalAudio();const n=(o=this.meetingSession)==null?void 0:o.audioVideo.realtimeIsLocalAudioMuted();return n!==void 0?t!==n:!1}shock(){throw new Error("Method not implemented.")}}var le=(i=>(i[i.Success=0]="Success",i[i.Failure=1]="Failure",i[i.ReJoin=2]="ReJoin",i[i.NoMicroPermission=3]="NoMicroPermission",i[i.Unknown=500]="Unknown",i))(le||{});class gi extends tt{constructor({jsBridge:t,getVoiceSign:n}){super();a(this,"type",se.RealseeVRWebViewRTC);a(this,"joined",!1);a(this,"micro",!1);a(this,"voiceId","");a(this,"_joinOptions",null);a(this,"options");a(this,"handleUserVolumes",t=>{this.emit("userVolumes",t)});a(this,"handleWeakNetwork",t=>{t&&this.emit("weakNetwork")});a(this,"join",async t=>{this._joinOptions=t,this.emit("joinWillStart");const{sdkAppId:n,userId:s,userSig:r}=await this.getVoiceSignOrEmitError(t);return!n||!s||!r?!1:(this.type=t.type,this.jsBridge.webViewType==="WxMiniProgramWebView"?this.handleWxMiniProgramWebViewJoin({sdkAppId:n,userId:s,userSig:r,voiceId:t.voiceId}):this.handleAppWebViewJoin({sdkAppId:n,userId:s,userSig:r,voiceId:t.voiceId}))});a(this,"reJoin",async()=>this._joinOptions?this.join({voiceId:this._joinOptions.voiceId,userId:this._joinOptions.userId,roomId:this._joinOptions.roomId,type:this._joinOptions.type}):(this.emitErrorAndSetJoinedFalse("重连失败:未找到加入房间参数。"),!1));a(this,"getVoiceSignOrEmitError",async t=>{try{return await this.options.getVoiceSign(t)}catch(n){return this.emitErrorAndSetJoinedFalse("加入房间失败:rtc 签名请求异常"),{}}});a(this,"handleWxMiniProgramWebViewJoin",async t=>{const[n,s]=await this.joinRoomOrEmitError(t);return s?!1:this.handleJoinResult(n)});a(this,"handleAppWebViewJoin",t=>new Promise(n=>{this.off("inner.rtc.success");const s=r=>{this.off("inner.rtc.fail",s),this.off("inner.rtc.success",s),n(this.handleJoinResult(r))};this.once("inner.rtc.fail",s),this.once("inner.rtc.success",s);try{const{sdkAppId:r,userId:o,userSig:c,voiceId:l}=t;this.jsBridge.callAndListen(`live/join?sdkAppID=${r}&userID=${o}&roomID=${l}&userSig=${c}`,h=>{h===!0?this.emit("inner.rtc.success",h):typeof h=="object"?h.code===le.Success||h.code===le.ReJoin?this.emit("inner.rtc.success",h):this.emit("inner.rtc.fail",h):this.emit("inner.rtc.fail",h)})}catch(r){n(this.handleJoinResult({message:r.message,code:le.Unknown}))}}));a(this,"joinRoomOrEmitError",async({sdkAppId:t,userId:n,voiceId:s,userSig:r})=>{try{return await this.jsBridge.callAndBackfeed(`live/join?sdkAppID=${t}&userID=${n}&roomID=${Number(s)}&userSig=${r}`)}catch(o){return this.emitErrorAndSetJoinedFalse("加入房间失败:"+o.message),[null,o]}});a(this,"handleJoinResult",t=>{switch(!0){case t===!0:case(typeof t=="object"&&t.code===le.Success):case(typeof t=="object"&&t.code===le.ReJoin):{this.emit("joined"),this.joined=!0;break}default:{this.joined=!1;const n=typeof t=="object"?t.message:"加入房间失败:未知异常。";this.emit("error",new Error(n,{cause:t}))}}return this.joined});a(this,"emitErrorAndSetJoinedFalse",t=>{this.emit("error",new Error(t)),this.joined=!1});a(this,"quit",async()=>{const[t,n]=await this.jsBridge.callAndBackfeed("live/quit");return t===null&&this.emit("error",n||new Error("退出房间失败:未知异常。")),this.joined=!1,!!t});a(this,"detectMicro",async()=>{const[t,n]=await this.jsBridge.detectMicro();return t===null?(this.emit("error",n||new Error("麦克风监测异常!")),!1):t});a(this,"toggleMicro",async t=>{const[n,s]=await this.jsBridge.callAndBackfeed(`live/toggleMicro?flag=${t?1:0}`);return n===null?(this.emit("error",s||new Error("麦克风监测异常!")),!1):(this.micro=n,n)});a(this,"shock",()=>{this.jsBridge.shock(1)});this.options={jsBridge:t,getVoiceSign:n},this.jsBridge.webViewType!=="WxMiniProgramWebView"&&this.jsBridge.callAndListen("live/userVolumes",this.handleUserVolumes),this.jsBridge.callAndListen("live/weakNetwork",this.handleWeakNetwork),this.on("inner.rtc.fail",this.handleJoinResult)}get jsBridge(){return this.options.jsBridge}}var $=(i=>(i.SelfUserInfo="SELF_USER_INFO",i.RoomInfo="ROOM_INFO",i.RTCInfo="RTC_INFO",i.UserList="USER_LIST",i.BuiltinMsg="BUILTIN_MSG",i.CustomEvent="CUSTOM_EVENT",i.KeyframeSync="KEYFRAME_SYNC",i.UserKickOut="USER_KICK_OUT",i))($||{}),F=(i=>(i.UserChange="user_change",i.RoomChange="room_change",i))(F||{}),K=(i=>(i.UserMicroStatus="change_micro_status",i.UserMicroStatusSync="sync_micro_status",i.UserPermission="change_permission",i.UserStatus="change_status",i.UserInfo="change_info",i.RoomClose="close",i))(K||{}),te=(i=>(i.OPEN="OPEN",i.CLOSE="CLOSE",i))(te||{});function bn(i){try{const e=JSON.parse(i),t={code:e.code,message:e.message,command:e.command,roomCode:e.room_code,appID:e.app_id,requestId:e.request_id,frontRequestId:e.front_request_id,triggerUserID:e.trigger_user_id,data:e.data||{}},n=Object.keys(t).filter(s=>t[s]===void 0);return n.length>0&&console.warn(`推送数据格式异常:${n.join(" ")} 值不存在!`),t}catch(e){return!1}}var V=(i=>(i[i.NOTINITIALIZED=-1]="NOTINITIALIZED",i[i.CONNECTING=0]="CONNECTING",i[i.OPEN=1]="OPEN",i[i.CLOSED=3]="CLOSED",i))(V||{}),pi=(i=>(i[i.Normal=0]="Normal",i[i.Removed=1]="Removed",i[i.Replaced=2]="Replaced",i))(pi||{}),_i=(i=>(i.WAIT_ENTER="WAIT_ENTER",i.ONLINE="ONLINE",i.LEAVE="LEAVE",i.KICK_OUT="KICK_OUT",i.BE_REPLACE="BE_REPLACE",i.EXCEPTION="EXCEPTION",i))(_i||{}),Ge=(i=>(i[i.NOTINITIALIZED=-1]="NOTINITIALIZED",i[i.CONNECTING=0]="CONNECTING",i[i.OPEN=1]="OPEN",i[i.CLOSING=2]="CLOSING",i[i.CLOSED=3]="CLOSED",i))(Ge||{}),mi=(i=>(i.Error="Error",i.Close="Close",i.MicroAuth="MicroAuth",i.DuplicateConnect="DuplicateConnect",i.IllegalURL="IllegalURL",i.Unknown="Unknown",i.IllegalArgs="IllegalArgs",i))(mi||{}),wi=(i=>(i.Err_1000="CLOSE_NORMAL",i.Err_1001="CLOSE_GOING_AWAY",i.Err_1002="CLOSE_PROTOCOL_ERROR",i.Err_1003="CLOSE_UNSUPPORTED",i.Err_1006="CLOSE_ABNORMAL",i.Err_1007="Unsupported Data",i.Err_1008="Policy Violation",i.Err_1009="CLOSE_TOO_LARGE",i.Err_unknown="unknown",i))(wi||{});function bi(i){switch(i){case 1e3:return"CLOSE_NORMAL";case 1001:return"CLOSE_GOING_AWAY";case 1002:return"CLOSE_PROTOCOL_ERROR";case 1003:return"CLOSE_UNSUPPORTED";case 1006:return"CLOSE_ABNORMAL";case 1007:return"Unsupported Data";case 1008:return"Policy Violation";case 1009:return"CLOSE_TOO_LARGE"}return"unknown"}function yn(i,e={}){var c;const t=new URL(i,"http://localhost"),n=new URLSearchParams(t.search);for(const[l,h]of Object.entries(e))n.set(l,String(h));const s=n.toString(),r=i.split("#")[0].split("?")[0],o=(c=t.hash)!=null?c:"";return`${r}${s?`?${s}`:""}${o}`}const yi=(()=>{var t;const i=typeof process!="undefined"&&((t=process.versions)==null?void 0:t.node)!=null;return typeof window!="undefined"&&"Deno"in window||i||typeof window=="undefined"})(),pe=yi?"":navigator.userAgent,Sn=/android/i.test(pe),Cn=/iPhone|iPad|iPod|iPadOS/i.test(pe)||!yi&&/Macintosh/.test(pe)&&"ontouchend"in globalThis,Kt=/MicroMessenger/i.test(pe)&&/miniProgram/i.test(pe),Jt=/realsee/i.test(pe);function qe(i){return Object.prototype.toString.call(i)==="[object Object]"}function it(i,e){return i===e?!0:i==null||e==null||typeof i!=typeof e?!1:Number.isNaN(i)&&Number.isNaN(e)}function En(i,e){if(i===e)return!0;if(i==null||e==null)return!1;const t=Object.keys(i),n=Object.keys(e);return t.length!==n.length?!1:t.every(s=>it(i[s],e[s]))}function kn(i,e){return i===e?!0:i==null||e==null||i.length!==e.length?!1:i.every((t,n)=>it(t,e[n]))}function vn(i,e){return it(i,e)?!0:qe(i)&&qe(e)?En(i,e):Array.isArray(i)&&Array.isArray(e)?kn(i,e):!1}function Lt(i,e){return it(i,e)?!0:qe(i)&&qe(e)?On(i,e):Array.isArray(i)&&Array.isArray(e)?In(i,e):!1}function In(i,e){if(i.length!==e.length)return!1;for(let t=0,n=i.length;t<n;t++)if(!Lt(i[t],e[t]))return!1;return!0}function On(i,e){if(i===e)return!0;if(i==null||e==null)return!1;const t=Object.keys(i),n=Object.keys(e);return t.length!==n.length?!1:t.every(s=>Lt(i[s],e[s]))}function Rn(i,e,t={deep:!1}){return t.deep?Lt(i,e):vn(i,e)}class An extends ge{constructor(t){super();a(this,"_realWebSocket");a(this,"_url");a(this,"_protocols");a(this,"_readyState",Ge.NOTINITIALIZED);a(this,"_options",{timeout:1e4,shouldReconnect:(t,n)=>{if(!(t.code===1008||t.code===1011))return[0,1e3,2e3][n.attempts%3]},should1000Reconnect:!1,ignoreConnectivityEvents:!1,automaticOpen:!1});a(this,"_connectTimeout");a(this,"_attempts",0);a(this,"_reconnects",-1);a(this,"_reconnectWhenOnlineAgain",!1);a(this,"_explicitlyClosed",!1);a(this,"_pendingReconnect");a(this,"_connectivityEventsAttached",!1);a(this,"_heathCheckTimer");a(this,"_healthCheck",async()=>{if(this._realWebSocket){const t=this._realWebSocket.readyState;t!==this._readyState&&(this._readyState=t,this._readyState===Ge.CLOSING&&this.emit("closing"))}await new Promise(t=>setTimeout(t,2e3)),this._heathCheckTimer=requestAnimationFrame(this._healthCheck)});a(this,"_clearConnectTimeoutIfNeed",()=>{this._connectTimeout&&(clearTimeout(this._connectTimeout),this._connectTimeout=void 0)});a(this,"_clearHeathCheckIfNeed",()=>{this._heathCheckTimer&&(cancelAnimationFrame(this._heathCheckTimer),this._heathCheckTimer=void 0)});a(this,"_startHealthCheck",()=>{this._clearHeathCheckIfNeed(),this._heathCheckTimer=requestAnimationFrame(this._healthCheck)});a(this,"_stopHealthCheck",()=>{this._clearHeathCheckIfNeed()});a(this,"_clearPendingReconnectIfNeeded",()=>{this._pendingReconnect&&(clearTimeout(this._pendingReconnect),this._pendingReconnect=void 0)});a(this,"_online",t=>{this._reconnectWhenOnlineAgain&&(this._clearPendingReconnectIfNeeded(),this._reconnect(t))});a(this,"_offline",()=>{var t;this._reconnectWhenOnlineAgain=!0,(t=this._realWebSocket)==null||t.close(1e3,"offline")});a(this,"_detachConnectivityEvents",()=>{this._connectivityEventsAttached&&(globalThis==null||globalThis.removeEventListener("online",this._online),globalThis==null||globalThis.removeEventListener("offline",this._offline),this._connectivityEventsAttached=!1)});a(this,"_attachConnectivityEvents",()=>{this._connectivityEventsAttached||(globalThis==null||globalThis.addEventListener("online",this._online),globalThis==null||globalThis.addEventListener("offline",this._offline),this._connectivityEventsAttached=!0)});a(this,"send",t=>{var n,s,r;((n=this._realWebSocket)==null?void 0:n.readyState)===((s=this._realWebSocket)==null?void 0:s.OPEN)&&((r=this._realWebSocket)==null||r.send(t))});a(this,"close",(t,n)=>{var s;return typeof t!="number"&&(n=t,t=1e3),this._clearPendingReconnectIfNeeded(),this._reconnectWhenOnlineAgain=!1,this._explicitlyClosed=!0,this._detachConnectivityEvents(),(s=this._realWebSocket)==null?void 0:s.close(t,n)});a(this,"open",t=>{var n,s;t&&(this._url=t),((n=this._realWebSocket)==null?void 0:n.readyState)!==WebSocket.OPEN&&((s=this._realWebSocket)==null?void 0:s.readyState)!==WebSocket.CONNECTING&&(this._clearPendingReconnectIfNeeded(),this._reconnectWhenOnlineAgain=!1,this._explicitlyClosed=!1,this._createWebSocket())});a(this,"_createWebSocket",()=>{var s;const t=typeof this._url=="string"?this._url:(s=this._url)==null?void 0:s.call(this,this);if(!t)return;this._clearConnectTimeoutIfNeed(),this._clearPendingReconnectIfNeeded(),this._removeWebSocketEvent(),this._realWebSocket=new WebSocket(t,this._protocols||void 0),this._attempts++,this.emit("connecting",new CustomEvent("connecting",{detail:{attempts:this._attempts,reconnects:this._reconnects}}));const n=()=>{this._connectTimeout=void 0,this._detachConnectivityEvents(),this.emit("timeout",new CustomEvent("timeout",{detail:{attempts:this._attempts,reconnects:this._reconnects}}))};this._connectTimeout=setTimeout(n,this._options.timeout),this._dispatchWebSocketEvent(),this._options.ignoreConnectivityEvents||this._attachConnectivityEvents()});a(this,"_removeWebSocketEvent",()=>{var t,n,s,r;(t=this._realWebSocket)==null||t.removeEventListener("open",this._webSocketOpenHandler),(n=this._realWebSocket)==null||n.removeEventListener("close",this._webSocketCloseHandler),(s=this._realWebSocket)==null||s.removeEventListener("error",this._webSocketErrorHandler),(r=this._realWebSocket)==null||r.removeEventListener("message",this._webSocketMessageHandler)});a(this,"_dispatchWebSocketEvent",()=>{var t,n,s,r;(t=this._realWebSocket)==null||t.addEventListener("open",this._webSocketOpenHandler),(n=this._realWebSocket)==null||n.addEventListener("close",this._webSocketCloseHandler),(s=this._realWebSocket)==null||s.addEventListener("error",this._webSocketErrorHandler),(r=this._realWebSocket)==null||r.addEventListener("message",this._webSocketMessageHandler)});a(this,"_webSocketOpenHandler",t=>{this._connectTimeout&&(clearTimeout(this._connectTimeout),this._connectTimeout=void 0);const n=++this._reconnects,s=this._attempts;return this._attempts=0,this._reconnectWhenOnlineAgain=!1,this._startHealthCheck(),this.emit("open",Object.assign(t,{detail:{reconnects:n,attempts:s}}))});a(this,"_webSocketCloseHandler",t=>(this._reconnect(t),this._stopHealthCheck(),this.emit("close",t)));a(this,"_webSocketErrorHandler",t=>this.emit("error",new CustomEvent("error",{detail:{error:t}})));a(this,"_webSocketMessageHandler",t=>this.emit("message",t));t&&this.setOptions(t),this._startHealthCheck()}get attempts(){return this._attempts}setOptions(t){if(!t)return;this._url=t.url,this._protocols=t.protocols;const n=Object.assign(this._options,t.robustOptions||{});if(typeof(n==null?void 0:n.timeout)!="number")throw new Error("timeout must be the number of milliseconds to timeout a connection attempt");if(typeof(n==null?void 0:n.shouldReconnect)!="function")throw new Error("shouldReconnect must be a function that returns the number of milliseconds to wait for a reconnect attempt, or null or undefined to not reconnect.");this._options=n,this._options.automaticOpen&&this._createWebSocket()}_reconnect(t){var o,c,l;if(!this._options.should1000Reconnect&&t.code===1e3||this._explicitlyClosed){this._attempts=0;return}if(this._connectivityEventsAttached&&((o=globalThis==null?void 0:globalThis.navigator)==null?void 0:o.onLine)===!1){this._reconnectWhenOnlineAgain=!0;return}const r=(l=(c=this._options).shouldReconnect)==null?void 0:l.call(c,t,this);typeof r=="number"?(m.debug(`RobustWebSocket: Reconnecting in ${r}ms...`),this._pendingReconnect=setTimeout(this._createWebSocket,r)):m.debug("RobustWebSocket: No reconnection will be attempted.")}}class Tn extends ge{constructor(){super();a(this,"_ws",new An({url:"",robustOptions:{should1000Reconnect:!0,ignoreConnectivityEvents:!0}}));a(this,"_state",V.NOTINITIALIZED);a(this,"_addWebSocketEventListeners",()=>{this._ws.on("close",this._handleCloseEvent),this._ws.on("closing",this._handleClosingEvent),this._ws.on("connecting",this._handleConnectingEvent),this._ws.on("error",this._handleErrorEvent),this._ws.on("message",this._handleMessageEvent),this._ws.on("open",this._handleOpenEvent),this._ws.on("timeout",this._handleTimeoutEvent)});a(this,"_removeWebSocketEventListeners",()=>{this._ws.off("close",this._handleCloseEvent),this._ws.off("closing",this._handleClosingEvent),this._ws.off("connecting",this._handleConnectingEvent),this._ws.off("error",this._handleErrorEvent),this._ws.off("message",this._handleMessageEvent),this._ws.off("open",this._handleOpenEvent),this._ws.off("timeout",this._handleTimeoutEvent)});a(this,"_handleCloseEvent",t=>{m.info(`live room closed bacause of ${t.code}-${t.reason||bi(t.code)}`),this.state=V.CLOSED});a(this,"_handleClosingEvent",()=>{var t;m.info("live room is closing, onLine:",(t=globalThis==null?void 0:globalThis.navigator)==null?void 0:t.onLine),this.state=V.CLOSED});a(this,"_handleConnectingEvent",t=>{m.info("live room is connecting"),this.state=V.CONNECTING,t.detail.reconnects>0&&this.emit("reconnecting",t.detail)});a(this,"_handleErrorEvent",t=>{m.error("live room error",t),this.state=V.CLOSED});a(this,"_handleMessageEvent",t=>{let n=(()=>{try{return JSON.parse(t.data)}catch(s){return t.data}})();this.emit("message",n)});a(this,"_handleOpenEvent",t=>{m.info("live room open",t.detail),this.state=V.OPEN,t.detail.reconnects>0&&this.emit("reconnected",t.detail)});a(this,"_handleTimeoutEvent",t=>{m.error("live room connect timeout!",t.detail),this.state=V.CLOSED});a(this,"dispose",async()=>(this._removeWebSocketEventListeners(),await this.close("live room close by controller disposed!")));a(this,"open",t=>this._ws.open(t));a(this,"close",(t,n)=>new Promise(s=>{this._ws.once("close",()=>s(!0)),this._ws.close(t,n)}));a(this,"sendMessage",(t="")=>{if(t==null)throw new Error("live message is empty!");if(this.state!==V.OPEN)throw new Error("live has not yet been initialized!");return this._ws.send(JSON.stringify(t))});a(this,"readyClose",()=>{this._ws&&(this._ws._explicitlyClosed=!0)});this._addWebSocketEventListeners()}set state(t){const n=JSON.parse(JSON.stringify(this._state));this._state=t,this.emit("stateChange",this.state,n)}get state(){return this._state}}const J=()=>new Map,Et=i=>{const e=J();return i.forEach((t,n)=>{e.set(n,t)}),e},Se=(i,e,t)=>{let n=i.get(e);return n===void 0&&i.set(e,n=t()),n},Ln=(i,e)=>{const t=[];for(const[n,s]of i)t.push(e(s,n));return t},Mn=(i,e)=>{for(const[t,n]of i)if(e(n,t))return!0;return!1},_e=()=>new Set,ut=i=>i[i.length-1],me=Array.from,Dn=Array.isArray;class Nn{constructor(){this._observers=J()}on(e,t){return Se(this._observers,e,_e).add(t),t}once(e,t){const n=(...s)=>{this.off(e,n),t(...s)};this.on(e,n)}off(e,t){const n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return me((this._observers.get(e)||J()).values()).forEach(n=>n(...t))}destroy(){this._observers=J()}}const ae=Math.floor,We=Math.abs,Si=(i,e)=>i<e?i:e,Ce=(i,e)=>i>e?i:e,Vn=i=>i!==0?i<0:1/i<0,Gt=1,qt=2,dt=4,ft=8,Un=32,Ci=64,He=128,jn=31,Ht=63,Re=127,Bn=2147483647,$n=Number.isInteger||(i=>typeof i=="number"&&isFinite(i)&&ae(i)===i),xn=i=>i.toLowerCase(),Fn=/^\s*/g,Wn=i=>i.replace(Fn,""),Pn=/([A-Z])/g,zt=(i,e)=>Wn(i.replace(Pn,t=>`${e}${xn(t)}`)),Kn=i=>{const e=unescape(encodeURIComponent(i)),t=e.length,n=new Uint8Array(t);for(let s=0;s<t;s++)n[s]=e.codePointAt(s);return n},Le=typeof TextEncoder!="undefined"?new TextEncoder:null,Jn=i=>Le.encode(i),Gn=Le?Jn:Kn;let gt=typeof TextDecoder=="undefined"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});gt&>.decode(new Uint8Array).length===1&&(gt=null);class je{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Mt=()=>new je,qn=i=>{let e=i.cpos;for(let t=0;t<i.bufs.length;t++)e+=i.bufs[t].length;return e},z=i=>{const e=new Uint8Array(qn(i));let t=0;for(let n=0;n<i.bufs.length;n++){const s=i.bufs[n];e.set(s,t),t+=s.length}return e.set(new Uint8Array(i.cbuf.buffer,0,i.cpos),t),e},Hn=(i,e)=>{const t=i.cbuf.length;t-i.cpos<e&&(i.bufs.push(new Uint8Array(i.cbuf.buffer,0,i.cpos)),i.cbuf=new Uint8Array(Ce(t,e)*2),i.cpos=0)},T=(i,e)=>{const t=i.cbuf.length;i.cpos===t&&(i.bufs.push(i.cbuf),i.cbuf=new Uint8Array(t*2),i.cpos=0),i.cbuf[i.cpos++]=e},kt=T,C=(i,e)=>{for(;e>Re;)T(i,He|Re&e),e=ae(e/128);T(i,Re&e)},Dt=(i,e)=>{const t=Vn(e);for(t&&(e=-e),T(i,(e>Ht?He:0)|(t?Ci:0)|Ht&e),e=ae(e/64);e>0;)T(i,(e>Re?He:0)|Re&e),e=ae(e/128)},vt=new Uint8Array(3e4),zn=vt.length/3,Yn=(i,e)=>{if(e.length<zn){const t=Le.encodeInto(e,vt).written||0;C(i,t);for(let n=0;n<t;n++)T(i,vt[n])}else x(i,Gn(e))},Xn=(i,e)=>{const t=unescape(encodeURIComponent(e)),n=t.length;C(i,n);for(let s=0;s<n;s++)T(i,t.codePointAt(s))},fe=Le&&Le.encodeInto?Yn:Xn,Nt=(i,e)=>{const t=i.cbuf.length,n=i.cpos,s=Si(t-n,e.length),r=e.length-s;i.cbuf.set(e.subarray(0,s),n),i.cpos+=s,r>0&&(i.bufs.push(i.cbuf),i.cbuf=new Uint8Array(Ce(t*2,r)),i.cbuf.set(e.subarray(s)),i.cpos=r)},x=(i,e)=>{C(i,e.byteLength),Nt(i,e)},Vt=(i,e)=>{Hn(i,e);const t=new DataView(i.cbuf.buffer,i.cpos,e);return i.cpos+=e,t},Zn=(i,e)=>Vt(i,4).setFloat32(0,e,!1),Qn=(i,e)=>Vt(i,8).setFloat64(0,e,!1),es=(i,e)=>Vt(i,8).setBigInt64(0,e,!1),Yt=new DataView(new ArrayBuffer(4)),ts=i=>(Yt.setFloat32(0,i),Yt.getFloat32(0)===i),Me=(i,e)=>{switch(typeof e){case"string":T(i,119),fe(i,e);break;case"number":$n(e)&&We(e)<=Bn?(T(i,125),Dt(i,e)):ts(e)?(T(i,124),Zn(i,e)):(T(i,123),Qn(i,e));break;case"bigint":T(i,122),es(i,e);break;case"object":if(e===null)T(i,126);else if(Dn(e)){T(i,117),C(i,e.length);for(let t=0;t<e.length;t++)Me(i,e[t])}else if(e instanceof Uint8Array)T(i,116),x(i,e);else{T(i,118);const t=Object.keys(e);C(i,t.length);for(let n=0;n<t.length;n++){const s=t[n];fe(i,s),Me(i,e[s])}}break;case"boolean":T(i,e?120:121);break;default:T(i,127)}};class Xt extends je{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&C(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}}const Zt=i=>{i.count>0&&(Dt(i.encoder,i.count===1?i.s:-i.s),i.count>1&&C(i.encoder,i.count-2))};class Pe{constructor(){this.encoder=new je,this.s=0,this.count=0}write(e){this.s===e?this.count++:(Zt(this),this.count=1,this.s=e)}toUint8Array(){return Zt(this),z(this.encoder)}}const Qt=i=>{if(i.count>0){const e=i.diff*2+(i.count===1?0:1);Dt(i.encoder,e),i.count>1&&C(i.encoder,i.count-2)}};class pt{constructor(){this.encoder=new je,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Qt(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Qt(this),z(this.encoder)}}class is{constructor(){this.sarr=[],this.s="",this.lensE=new Pe}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){const e=new je;return this.sarr.push(this.s),this.s="",fe(e,this.sarr.join("")),Nt(e,this.lensE.toUint8Array()),z(e)}}const we=i=>new Error(i),G=()=>{throw we("Method unimplemented")},he=()=>{throw we("Unexpected case")},ns=crypto.getRandomValues.bind(crypto),Ei=()=>ns(new Uint32Array(1))[0],ss="10000000-1000-4000-8000"+-1e11,rs=()=>ss.replace(/[018]/g,i=>(i^Ei()&15>>i/4).toString(16)),ei=i=>new Promise(i);Promise.all.bind(Promise);const ti=i=>i===void 0?null:i;class os{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}}let ki=new os,cs=!0;try{typeof localStorage!="undefined"&&localStorage&&(ki=localStorage,cs=!1)}catch(i){}const ls=ki,as=Object.assign,hs=Object.keys,us=(i,e)=>{for(const t in i)e(i[t],t)},ii=i=>hs(i).length,ds=i=>{for(const e in i)return!1;return!0},fs=(i,e)=>{for(const t in i)if(!e(i[t],t))return!1;return!0},gs=(i,e)=>Object.prototype.hasOwnProperty.call(i,e),ps=(i,e)=>i===e||ii(i)===ii(e)&&fs(i,(t,n)=>(t!==void 0||gs(e,n))&&e[n]===t),_s=Object.freeze,vi=i=>{for(const e in i){const t=i[e];(typeof t=="object"||typeof t=="function")&&vi(i[e])}return _s(i)},Ut=(i,e,t=0)=>{try{for(;t<i.length;t++)i[t](...e)}finally{t<i.length&&Ut(i,e,t+1)}},ms=(i,e)=>e.includes(i),De=typeof process!="undefined"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process!="undefined"?process:0)==="[object process]";let P;const ws=()=>{if(P===void 0)if(De){P=J();const i=process.argv;let e=null;for(let t=0;t<i.length;t++){const n=i[t];n[0]==="-"?(e!==null&&P.set(e,""),e=n):e!==null&&(P.set(e,n),e=null)}e!==null&&P.set(e,"")}else typeof location=="object"?(P=J(),(location.search||"?").slice(1).split("&").forEach(i=>{if(i.length!==0){const[e,t]=i.split("=");P.set(`--${zt(e,"-")}`,t),P.set(`-${zt(e,"-")}`,t)}})):P=J();return P},It=i=>ws().has(i),ze=i=>ti(De?process.env[i.toUpperCase().replaceAll("-","_")]:ls.getItem(i)),Ii=i=>It("--"+i)||ze(i)!==null;Ii("production");const bs=De&&ms(process.env.FORCE_COLOR,["true","1","2"]),ys=bs||!It("--no-colors")&&!Ii("no-color")&&(!De||process.stdout.isTTY)&&(!De||It("--color")||ze("COLORTERM")!==null||(ze("TERM")||"").includes("color"));class Ss{constructor(e,t){this.left=e,this.right=t}}const H=(i,e)=>new Ss(i,e);typeof DOMParser!="undefined"&&new DOMParser;const Cs=i=>Ln(i,(e,t)=>`${t}:${e};`).join(""),Z=Symbol,Oi=Z(),Ri=Z(),Es=Z(),ks=Z(),vs=Z(),Ai=Z(),Is=Z(),jt=Z(),Os=Z(),Rs=i=>{var s;i.length===1&&((s=i[0])==null?void 0:s.constructor)===Function&&(i=i[0]());const e=[],t=[];let n=0;for(;n<i.length;n++){const r=i[n];if(r===void 0)break;if(r.constructor===String||r.constructor===Number)e.push(r);else if(r.constructor===Object)break}for(n>0&&t.push(e.join(""));n<i.length;n++){const r=i[n];r instanceof Symbol||t.push(r)}return t},As={[Oi]:H("font-weight","bold"),[Ri]:H("font-weight","normal"),[Es]:H("color","blue"),[vs]:H("color","green"),[ks]:H("color","grey"),[Ai]:H("color","red"),[Is]:H("color","purple"),[jt]:H("color","orange"),[Os]:H("color","black")},Ts=i=>{var o;i.length===1&&((o=i[0])==null?void 0:o.constructor)===Function&&(i=i[0]());const e=[],t=[],n=J();let s=[],r=0;for(;r<i.length;r++){const c=i[r],l=As[c];if(l!==void 0)n.set(l.left,l.right);else{if(c===void 0)break;if(c.constructor===String||c.constructor===Number){const h=Cs(n);r>0||h.length>0?(e.push("%c"+c),t.push(h)):e.push(c)}else break}}for(r>0&&(s=t,s.unshift(e.join("")));r<i.length;r++){const c=i[r];c instanceof Symbol||s.push(c)}return s},Ti=ys?Ts:Rs,Ls=(...i)=>{console.log(...Ti(i)),Li.forEach(e=>e.print(i))},Ms=(...i)=>{console.warn(...Ti(i)),i.unshift(jt),Li.forEach(e=>e.print(i))},Li=_e(),Mi=i=>({[Symbol.iterator](){return this},next:i}),Ds=(i,e)=>Mi(()=>{let t;do t=i.next();while(!t.done&&!e(t.value));return t}),_t=(i,e)=>Mi(()=>{const{done:t,value:n}=i.next();return{done:t,value:t?void 0:e(n)}});class Ns{constructor(e,t){this.clock=e,this.len=t}}class Vs{constructor(){this.clients=new Map}}const Di=(i,e,t)=>e.clients.forEach((n,s)=>{const r=i.doc.store.clients.get(s);for(let o=0;o<n.length;o++){const c=n[o];xi(i,r,c.clock,c.len,t)}}),Us=(i,e)=>{let t=0,n=i.length-1;for(;t<=n;){const s=ae((t+n)/2),r=i[s],o=r.clock;if(o<=e){if(e<o+r.len)return s;t=s+1}else n=s-1}return null},Ni=(i,e)=>{const t=i.clients.get(e.client);return t!==void 0&&Us(t,e.clock)!==null},Vi=i=>{i.clients.forEach(e=>{e.sort((s,r)=>s.clock-r.clock);let t,n;for(t=1,n=1;t<e.length;t++){const s=e[n-1],r=e[t];s.clock+s.len>=r.clock?s.len=Ce(s.len,r.clock+r.len-s.clock):(n<t&&(e[n]=r),n++)}e.length=n})},Ui=(i,e,t,n)=>{Se(i.clients,e,()=>[]).push(new Ns(t,n))},js=(i,e)=>{C(i.restEncoder,e.clients.size),me(e.clients.entries()).sort((t,n)=>n[0]-t[0]).forEach(([t,n])=>{i.resetDsCurVal(),C(i.restEncoder,t);const s=n.length;C(i.restEncoder,s);for(let r=0;r<s;r++){const o=n[r];i.writeDsClock(o.clock),i.writeDsLen(o.len)}})},ji=Ei;class Ee extends Nn{constructor({guid:e=rs(),collectionid:t=null,gc:n=!0,gcFilter:s=()=>!0,meta:r=null,autoLoad:o=!1,shouldLoad:c=!0}={}){super(),this.gc=n,this.gcFilter=s,this.clientID=ji(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new qs,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=c,this.autoLoad=o,this.meta=r,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=ei(h=>{this.on("load",()=>{this.isLoaded=!0,h(this)})});const l=()=>ei(h=>{const u=d=>{(d===void 0||d===!0)&&(this.off("sync",u),h())};this.on("sync",u)});this.on("sync",h=>{h===!1&&this.isSynced&&(this.whenSynced=l()),this.isSynced=h===void 0||h===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=l()}load(){const e=this._item;e!==null&&!this.shouldLoad&&k(e.parent.doc,t=>{t.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(me(this.subdocs).map(e=>e.guid))}transact(e,t=null){return k(this,e,t)}get(e,t=D){const n=Se(this.share,e,()=>{const r=new t;return r._integrate(this,null),r}),s=n.constructor;if(t!==D&&s!==t)if(s===D){const r=new t;r._map=n._map,n._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=r}),r._start=n._start;for(let o=r._start;o!==null;o=o.right)o.parent=r;return r._length=n._length,this.share.set(e,r),r._integrate(this,null),r}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return n}getArray(e=""){return this.get(e,Ae)}getText(e=""){return this.get(e,Qe)}getMap(e=""){return this.get(e,Ze)}getXmlElement(e=""){return this.get(e,Ue)}getXmlFragment(e=""){return this.get(e,be)}toJSON(){const e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,me(this.subdocs).forEach(t=>t.destroy());const e=this._item;if(e!==null){this._item=null;const t=e.content;t.doc=new Ee({guid:this.guid,...t.opts,shouldLoad:!1}),t.doc._item=e,k(e.parent.doc,n=>{const s=t.doc;e.deleted||n.subdocsAdded.add(s),n.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class Bs{constructor(){this.restEncoder=Mt()}toUint8Array(){return z(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){C(this.restEncoder,e)}writeDsLen(e){C(this.restEncoder,e)}}class $s extends Bs{writeLeftID(e){C(this.restEncoder,e.client),C(this.restEncoder,e.clock)}writeRightID(e){C(this.restEncoder,e.client),C(this.restEncoder,e.clock)}writeClient(e){C(this.restEncoder,e)}writeInfo(e){kt(this.restEncoder,e)}writeString(e){fe(this.restEncoder,e)}writeParentInfo(e){C(this.restEncoder,e?1:0)}writeTypeRef(e){C(this.restEncoder,e)}writeLen(e){C(this.restEncoder,e)}writeAny(e){Me(this.restEncoder,e)}writeBuf(e){x(this.restEncoder,e)}writeJSON(e){fe(this.restEncoder,JSON.stringify(e))}writeKey(e){fe(this.restEncoder,e)}}class xs{constructor(){this.restEncoder=Mt(),this.dsCurrVal=0}toUint8Array(){return z(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const t=e-this.dsCurrVal;this.dsCurrVal=e,C(this.restEncoder,t)}writeDsLen(e){e===0&&he(),C(this.restEncoder,e-1),this.dsCurrVal+=e}}class Fs extends xs{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new pt,this.clientEncoder=new Pe,this.leftClockEncoder=new pt,this.rightClockEncoder=new pt,this.infoEncoder=new Xt(kt),this.stringEncoder=new is,this.parentInfoEncoder=new Xt(kt),this.typeRefEncoder=new Pe,this.lenEncoder=new Pe}toUint8Array(){const e=Mt();return C(e,0),x(e,this.keyClockEncoder.toUint8Array()),x(e,this.clientEncoder.toUint8Array()),x(e,this.leftClockEncoder.toUint8Array()),x(e,this.rightClockEncoder.toUint8Array()),x(e,z(this.infoEncoder)),x(e,this.stringEncoder.toUint8Array()),x(e,z(this.parentInfoEncoder)),x(e,this.typeRefEncoder.toUint8Array()),x(e,this.lenEncoder.toUint8Array()),Nt(e,z(this.restEncoder)),z(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(e?1:0)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){Me(this.restEncoder,e)}writeBuf(e){x(this.restEncoder,e)}writeJSON(e){Me(this.restEncoder,e)}writeKey(e){const t=this.keyMap.get(e);t===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}}const Ws=(i,e,t,n)=>{n=Ce(n,e[0].id.clock);const s=Y(e,n);C(i.restEncoder,e.length-s),i.writeClient(t),C(i.restEncoder,n);const r=e[s];r.write(i,n-r.id.clock);for(let o=s+1;o<e.length;o++)e[o].write(i,0)},Ps=(i,e,t)=>{const n=new Map;t.forEach((s,r)=>{B(e,r)>s&&n.set(r,s)}),Bt(e).forEach((s,r)=>{t.has(r)||n.set(r,0)}),C(i.restEncoder,n.size),me(n.entries()).sort((s,r)=>r[0]-s[0]).forEach(([s,r])=>{Ws(i,e.clients.get(s),s,r)})},Ks=(i,e)=>Ps(i,e.doc.store,e.beforeState);class Js{constructor(){this.l=[]}}const ni=()=>new Js,si=(i,e)=>i.l.push(e),ri=(i,e)=>{const t=i.l,n=t.length;i.l=t.filter(s=>e!==s),n===i.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Bi=(i,e,t)=>Ut(i.l,[e,t]);class Ke{constructor(e,t){this.client=e,this.clock=t}}const $e=(i,e)=>i===e||i!==null&&e!==null&&i.client===e.client&&i.clock===e.clock,v=(i,e)=>new Ke(i,e),Gs=i=>{for(const[e,t]of i.doc.share.entries())if(t===i)return e;throw he()},ue=(i,e)=>e===void 0?!i.deleted:e.sv.has(i.id.client)&&(e.sv.get(i.id.client)||0)>i.id.clock&&!Ni(e.ds,i.id),Ot=(i,e)=>{const t=Se(i.meta,Ot,_e),n=i.doc.store;t.has(e)||(e.sv.forEach((s,r)=>{s<B(n,r)&&re(i,v(r,s))}),Di(i,e.ds,s=>{}),t.add(e))};class qs{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const Bt=i=>{const e=new Map;return i.clients.forEach((t,n)=>{const s=t[t.length-1];e.set(n,s.id.clock+s.length)}),e},B=(i,e)=>{const t=i.clients.get(e);if(t===void 0)return 0;const n=t[t.length-1];return n.id.clock+n.length},$i=(i,e)=>{let t=i.clients.get(e.id.client);if(t===void 0)t=[],i.clients.set(e.id.client,t);else{const n=t[t.length-1];if(n.id.clock+n.length!==e.id.clock)throw he()}t.push(e)},Y=(i,e)=>{let t=0,n=i.length-1,s=i[n],r=s.id.clock;if(r===e)return n;let o=ae(e/(r+s.length-1)*n);for(;t<=n;){if(s=i[o],r=s.id.clock,r<=e){if(e<r+s.length)return o;t=o+1}else n=o-1;o=ae((t+n)/2)}throw he()},Hs=(i,e)=>{const t=i.clients.get(e.client);return t[Y(t,e.clock)]},mt=Hs,Rt=(i,e,t)=>{const n=Y(e,t),s=e[n];return s.id.clock<t&&s instanceof U?(e.splice(n+1,0,rn(i,s,t-s.id.clock)),n+1):n},re=(i,e)=>{const t=i.doc.store.clients.get(e.client);return t[Rt(i,t,e.clock)]},oi=(i,e,t)=>{const n=e.clients.get(t.client),s=Y(n,t.clock),r=n[s];return t.clock!==r.id.clock+r.length-1&&r.constructor!==ie&&n.splice(s+1,0,rn(i,r,t.clock-r.id.clock+1)),r},zs=(i,e,t)=>{const n=i.clients.get(e.id.client);n[Y(n,e.id.clock)]=t},xi=(i,e,t,n,s)=>{if(n===0)return;const r=t+n;let o=Rt(i,e,t),c;do c=e[o++],r<c.id.clock+c.length&&Rt(i,e,r),s(c);while(o<e.length&&e[o].id.clock<r)};class Ys{constructor(e,t,n){this.doc=e,this.deleteSet=new Vs,this.beforeState=Bt(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=n,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const ci=(i,e)=>e.deleteSet.clients.size===0&&!Mn(e.afterState,(t,n)=>e.beforeState.get(n)!==t)?!1:(Vi(e.deleteSet),Ks(i,e),js(i,e.deleteSet),!0),li=(i,e,t)=>{const n=e._item;(n===null||n.id.clock<(i.beforeState.get(n.id.client)||0)&&!n.deleted)&&Se(i.changed,e,_e).add(t)},Je=(i,e)=>{let t=i[e],n=i[e-1],s=e;for(;s>0;t=n,n=i[--s-1]){if(n.deleted===t.deleted&&n.constructor===t.constructor&&n.mergeWith(t)){t instanceof U&&t.parentSub!==null&&t.parent._map.get(t.parentSub)===t&&t.parent._map.set(t.parentSub,n);continue}break}const r=e-s;return r&&i.splice(e+1-r,r),r},Xs=(i,e,t)=>{for(const[n,s]of i.clients.entries()){const r=e.clients.get(n);for(let o=s.length-1;o>=0;o--){const c=s[o],l=c.clock+c.len;for(let h=Y(r,c.clock),u=r[h];h<r.length&&u.id.clock<l;u=r[++h]){const d=r[h];if(c.clock+c.len<=d.id.clock)break;d instanceof U&&d.deleted&&!d.keep&&t(d)&&d.gc(e,!1)}}}},Zs=(i,e)=>{i.clients.forEach((t,n)=>{const s=e.clients.get(n);for(let r=t.length-1;r>=0;r--){const o=t[r],c=Si(s.length-1,1+Y(s,o.clock+o.len-1));for(let l=c,h=s[l];l>0&&h.id.clock>=o.clock;h=s[l])l-=1+Je(s,l)}})},Fi=(i,e)=>{if(e<i.length){const t=i[e],n=t.doc,s=n.store,r=t.deleteSet,o=t._mergeStructs;try{Vi(r),t.afterState=Bt(t.doc.store),n.emit("beforeObserverCalls",[t,n]);const c=[];t.changed.forEach((l,h)=>c.push(()=>{(h._item===null||!h._item.deleted)&&h._callObserver(t,l)})),c.push(()=>{t.changedParentTypes.forEach((l,h)=>{h._dEH.l.length>0&&(h._item===null||!h._item.deleted)&&(l=l.filter(u=>u.target._item===null||!u.target._item.deleted),l.forEach(u=>{u.currentTarget=h,u._path=null}),l.sort((u,d)=>u.path.length-d.path.length),Bi(h._dEH,l,t))})}),c.push(()=>n.emit("afterTransaction",[t,n])),Ut(c,[]),t._needFormattingCleanup&&hr(t)}finally{n.gc&&Xs(r,s,n.gcFilter),Zs(r,s),t.afterState.forEach((u,d)=>{const g=t.beforeState.get(d)||0;if(g!==u){const w=s.clients.get(d),b=Ce(Y(w,g),1);for(let p=w.length-1;p>=b;)p-=1+Je(w,p)}});for(let u=o.length-1;u>=0;u--){const{client:d,clock:g}=o[u].id,w=s.clients.get(d),b=Y(w,g);b+1<w.length&&Je(w,b+1)>1||b>0&&Je(w,b)}if(!t.local&&t.afterState.get(n.clientID)!==t.beforeState.get(n.clientID)&&(Ls(jt,Oi,"[yjs] ",Ri,Ai,"Changed the client-id because another client seems to be using it."),n.clientID=ji()),n.emit("afterTransactionCleanup",[t,n]),n._observers.has("update")){const u=new $s;ci(u,t)&&n.emit("update",[u.toUint8Array(),t.origin,n,t])}if(n._observers.has("updateV2")){const u=new Fs;ci(u,t)&&n.emit("updateV2",[u.toUint8Array(),t.origin,n,t])}const{subdocsAdded:c,subdocsLoaded:l,subdocsRemoved:h}=t;(c.size>0||h.size>0||l.size>0)&&(c.forEach(u=>{u.clientID=n.clientID,u.collectionid==null&&(u.collectionid=n.collectionid),n.subdocs.add(u)}),h.forEach(u=>n.subdocs.delete(u)),n.emit("subdocs",[{loaded:l,added:c,removed:h},n,t]),h.forEach(u=>u.destroy())),i.length<=e+1?(n._transactionCleanups=[],n.emit("afterAllTransactions",[n,i])):Fi(i,e+1)}}},k=(i,e,t=null,n=!0)=>{const s=i._transactionCleanups;let r=!1,o=null;i._transaction===null&&(r=!0,i._transaction=new Ys(i,t,n),s.push(i._transaction),s.length===1&&i.emit("beforeAllTransactions",[i]),i.emit("beforeTransaction",[i._transaction,i]));try{o=e(i._transaction)}finally{if(r){const c=i._transaction===s[0];i._transaction=null,c&&Fi(s,0)}}return o},ai="You must not compute changes after the event-handler fired.";class nt{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Qs(this.currentTarget,this.target))}deletes(e){return Ni(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw we(ai);const e=new Map,t=this.target;this.transaction.changed.get(t).forEach(s=>{if(s!==null){const r=t._map.get(s);let o,c;if(this.adds(r)){let l=r.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(r))if(l!==null&&this.deletes(l))o="delete",c=ut(l.content.getContent());else return;else l!==null&&this.deletes(l)?(o="update",c=ut(l.content.getContent())):(o="add",c=void 0)}else if(this.deletes(r))o="delete",c=ut(r.content.getContent());else return;e.set(s,{action:o,oldValue:c})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw we(ai);const t=this.target,n=_e(),s=_e(),r=[];if(e={added:n,deleted:s,delta:r,keys:this.keys},this.transaction.changed.get(t).has(null)){let c=null;const l=()=>{c&&r.push(c)};for(let h=t._start;h!==null;h=h.right)h.deleted?this.deletes(h)&&!this.adds(h)&&((c===null||c.delete===void 0)&&(l(),c={delete:0}),c.delete+=h.length,s.add(h)):this.adds(h)?((c===null||c.insert===void 0)&&(l(),c={insert:[]}),c.insert=c.insert.concat(h.content.getContent()),n.add(h)):((c===null||c.retain===void 0)&&(l(),c={retain:0}),c.retain+=h.length);c!==null&&c.retain===void 0&&l()}this._changes=e}return e}}const Qs=(i,e)=>{const t=[];for(;e._item!==null&&e!==i;){if(e._item.parentSub!==null)t.unshift(e._item.parentSub);else{let n=0,s=e._item.parent._start;for(;s!==e._item&&s!==null;)!s.deleted&&s.countable&&(n+=s.length),s=s.right;t.unshift(n)}e=e._item.parent}return t},j=()=>{Ms("Invalid access: Add Yjs type to a document before reading data.")},Wi=80;let $t=0;class er{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=$t++}}const tr=i=>{i.timestamp=$t++},Pi=(i,e,t)=>{i.p.marker=!1,i.p=e,e.marker=!0,i.index=t,i.timestamp=$t++},ir=(i,e,t)=>{if(i.length>=Wi){const n=i.reduce((s,r)=>s.timestamp<r.timestamp?s:r);return Pi(n,e,t),n}else{const n=new er(e,t);return i.push(n),n}},st=(i,e)=>{if(i._start===null||e===0||i._searchMarker===null)return null;const t=i._searchMarker.length===0?null:i._searchMarker.reduce((r,o)=>We(e-r.index)<We(e-o.index)?r:o);let n=i._start,s=0;for(t!==null&&(n=t.p,s=t.index,tr(t));n.right!==null&&s<e;){if(!n.deleted&&n.countable){if(e<s+n.length)break;s+=n.length}n=n.right}for(;n.left!==null&&s>e;)n=n.left,!n.deleted&&n.countable&&(s-=n.length);for(;n.left!==null&&n.left.id.client===n.id.client&&n.left.id.clock+n.left.length===n.id.clock;)n=n.left,!n.deleted&&n.countable&&(s-=n.length);return t!==null&&We(t.index-s)<n.parent.length/Wi?(Pi(t,n,s),t):ir(i._searchMarker,n,s)},Ne=(i,e,t)=>{for(let n=i.length-1;n>=0;n--){const s=i[n];if(t>0){let r=s.p;for(r.marker=!1;r&&(r.deleted||!r.countable);)r=r.left,r&&!r.deleted&&r.countable&&(s.index-=r.length);if(r===null||r.marker===!0){i.splice(n,1);continue}s.p=r,r.marker=!0}(e<s.index||t>0&&e===s.index)&&(s.index=Ce(e,s.index+t))}},rt=(i,e,t)=>{const n=i,s=e.changedParentTypes;for(;Se(s,i,()=>[]).push(t),i._item!==null;)i=i._item.parent;Bi(n._eH,t,e)};class D{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=ni(),this._dEH=ni(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw G()}clone(){throw G()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){si(this._eH,e)}observeDeep(e){si(this._dEH,e)}unobserve(e){ri(this._eH,e)}unobserveDeep(e){ri(this._dEH,e)}toJSON(){}}const Ki=(i,e,t)=>{var o;(o=i.doc)!=null||j(),e<0&&(e=i._length+e),t<0&&(t=i._length+t);let n=t-e;const s=[];let r=i._start;for(;r!==null&&n>0;){if(r.countable&&!r.deleted){const c=r.content.getContent();if(c.length<=e)e-=c.length;else{for(let l=e;l<c.length&&n>0;l++)s.push(c[l]),n--;e=0}}r=r.right}return s},Ji=i=>{var n;(n=i.doc)!=null||j();const e=[];let t=i._start;for(;t!==null;){if(t.countable&&!t.deleted){const s=t.content.getContent();for(let r=0;r<s.length;r++)e.push(s[r])}t=t.right}return e},Ve=(i,e)=>{var s;let t=0,n=i._start;for((s=i.doc)!=null||j();n!==null;){if(n.countable&&!n.deleted){const r=n.content.getContent();for(let o=0;o<r.length;o++)e(r[o],t++,i)}n=n.right}},Gi=(i,e)=>{const t=[];return Ve(i,(n,s)=>{t.push(e(n,s,i))}),t},nr=i=>{let e=i._start,t=null,n=0;return{[Symbol.iterator](){return this},next:()=>{if(t===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};t=e.content.getContent(),n=0,e=e.right}const s=t[n++];return t.length<=n&&(t=null),{done:!1,value:s}}}},qi=(i,e)=>{var s;(s=i.doc)!=null||j();const t=st(i,e);let n=i._start;for(t!==null&&(n=t.p,e-=t.index);n!==null;n=n.right)if(!n.deleted&&n.countable){if(e<n.length)return n.content.getContent()[e];e-=n.length}},Ye=(i,e,t,n)=>{let s=t;const r=i.doc,o=r.clientID,c=r.store,l=t===null?e._start:t.right;let h=[];const u=()=>{h.length>0&&(s=new U(v(o,B(c,o)),s,s&&s.lastId,l,l&&l.id,e,null,new ye(h)),s.integrate(i,0),h=[])};n.forEach(d=>{if(d===null)h.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:h.push(d);break;default:switch(u(),d.constructor){case Uint8Array:case ArrayBuffer:s=new U(v(o,B(c,o)),s,s&&s.lastId,l,l&&l.id,e,null,new ot(new Uint8Array(d))),s.integrate(i,0);break;case Ee:s=new U(v(o,B(c,o)),s,s&&s.lastId,l,l&&l.id,e,null,new ct(d)),s.integrate(i,0);break;default:if(d instanceof D)s=new U(v(o,B(c,o)),s,s&&s.lastId,l,l&&l.id,e,null,new oe(d)),s.integrate(i,0);else throw new Error("Unexpected content type in insert operation")}}}),u()},Hi=()=>we("Length exceeded!"),zi=(i,e,t,n)=>{if(t>e._length)throw Hi();if(t===0)return e._searchMarker&&Ne(e._searchMarker,t,n.length),Ye(i,e,null,n);const s=t,r=st(e,t);let o=e._start;for(r!==null&&(o=r.p,t-=r.index,t===0&&(o=o.prev,t+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(t<=o.length){t<o.length&&re(i,v(o.id.client,o.id.clock+t));break}t-=o.length}return e._searchMarker&&Ne(e._searchMarker,s,n.length),Ye(i,e,o,n)},sr=(i,e,t)=>{let s=(e._searchMarker||[]).reduce((r,o)=>o.index>r.index?o:r,{index:0,p:e._start}).p;if(s)for(;s.right;)s=s.right;return Ye(i,e,s,t)},Yi=(i,e,t,n)=>{if(n===0)return;const s=t,r=n,o=st(e,t);let c=e._start;for(o!==null&&(c=o.p,t-=o.index);c!==null&&t>0;c=c.right)!c.deleted&&c.countable&&(t<c.length&&re(i,v(c.id.client,c.id.clock+t)),t-=c.length);for(;n>0&&c!==null;)c.deleted||(n<c.length&&re(i,v(c.id.client,c.id.clock+n)),c.delete(i),n-=c.length),c=c.right;if(n>0)throw Hi();e._searchMarker&&Ne(e._searchMarker,s,-r+n)},Xe=(i,e,t)=>{const n=e._map.get(t);n!==void 0&&n.delete(i)},xt=(i,e,t,n)=>{const s=e._map.get(t)||null,r=i.doc,o=r.clientID;let c;if(n==null)c=new ye([n]);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:c=new ye([n]);break;case Uint8Array:c=new ot(n);break;case Ee:c=new ct(n);break;default:if(n instanceof D)c=new oe(n);else throw new Error("Unexpected content type")}new U(v(o,B(r.store,o)),s,s&&s.lastId,null,null,e,t,c).integrate(i,0)},Ft=(i,e)=>{var n;(n=i.doc)!=null||j();const t=i._map.get(e);return t!==void 0&&!t.deleted?t.content.getContent()[t.length-1]:void 0},Xi=i=>{var t;const e={};return(t=i.doc)!=null||j(),i._map.forEach((n,s)=>{n.deleted||(e[s]=n.content.getContent()[n.length-1])}),e},Zi=(i,e)=>{var n;(n=i.doc)!=null||j();const t=i._map.get(e);return t!==void 0&&!t.deleted},rr=(i,e)=>{const t={};return i._map.forEach((n,s)=>{let r=n;for(;r!==null&&(!e.sv.has(r.id.client)||r.id.clock>=(e.sv.get(r.id.client)||0));)r=r.left;r!==null&&ue(r,e)&&(t[s]=r.content.getContent()[r.length-1])}),t},xe=i=>{var e;return(e=i.doc)!=null||j(),Ds(i._map.entries(),t=>!t[1].deleted)};class or extends nt{}class Ae extends D{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){const t=new Ae;return t.push(e),t}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Ae}clone(){const e=new Ae;return e.insert(0,this.toArray().map(t=>t instanceof D?t.clone():t)),e}get length(){var e;return(e=this.doc)!=null||j(),this._length}_callObserver(e,t){super._callObserver(e,t),rt(this,e,new or(this,e))}insert(e,t){this.doc!==null?k(this.doc,n=>{zi(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){this.doc!==null?k(this.doc,t=>{sr(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc!==null?k(this.doc,n=>{Yi(n,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return qi(this,e)}toArray(){return Ji(this)}slice(e=0,t=this.length){return Ki(this,e,t)}toJSON(){return this.map(e=>e instanceof D?e.toJSON():e)}map(e){return Gi(this,e)}forEach(e){Ve(this,e)}[Symbol.iterator](){return nr(this)}_write(e){e.writeTypeRef(_r)}}class cr extends nt{constructor(e,t,n){super(e,t),this.keysChanged=n}}class Ze extends D{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((n,s)=>{this.set(s,n)}),this._prelimContent=null}_copy(){return new Ze}clone(){const e=new Ze;return this.forEach((t,n)=>{e.set(n,t instanceof D?t.clone():t)}),e}_callObserver(e,t){rt(this,e,new cr(this,e,t))}toJSON(){var t;(t=this.doc)!=null||j();const e={};return this._map.forEach((n,s)=>{if(!n.deleted){const r=n.content.getContent()[n.length-1];e[s]=r instanceof D?r.toJSON():r}}),e}get size(){return[...xe(this)].length}keys(){return _t(xe(this),e=>e[0])}values(){return _t(xe(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return _t(xe(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){var t;(t=this.doc)!=null||j(),this._map.forEach((n,s)=>{n.deleted||e(n.content.getContent()[n.length-1],s,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?k(this.doc,t=>{Xe(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return this.doc!==null?k(this.doc,n=>{xt(n,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return Ft(this,e)}has(e){return Zi(this,e)}clear(){this.doc!==null?k(this.doc,e=>{this.forEach(function(t,n,s){Xe(e,s,n)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(mr)}}const ne=(i,e)=>i===e||typeof i=="object"&&typeof e=="object"&&i&&e&&ps(i,e);class At{constructor(e,t,n,s){this.left=e,this.right=t,this.index=n,this.currentAttributes=s}forward(){switch(this.right===null&&he(),this.right.content.constructor){case L:this.right.deleted||ke(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}}const hi=(i,e,t)=>{for(;e.right!==null&&t>0;){switch(e.right.content.constructor){case L:e.right.deleted||ke(e.currentAttributes,e.right.content);break;default:e.right.deleted||(t<e.right.length&&re(i,v(e.right.id.client,e.right.id.clock+t)),e.index+=e.right.length,t-=e.right.length);break}e.left=e.right,e.right=e.right.right}return e},Fe=(i,e,t,n)=>{const s=new Map,r=n?st(e,t):null;if(r){const o=new At(r.p.left,r.p,r.index,s);return hi(i,o,t-r.index)}else{const o=new At(null,e._start,0,s);return hi(i,o,t)}},Qi=(i,e,t,n)=>{for(;t.right!==null&&(t.right.deleted===!0||t.right.content.constructor===L&&ne(n.get(t.right.content.key),t.right.content.value));)t.right.deleted||n.delete(t.right.content.key),t.forward();const s=i.doc,r=s.clientID;n.forEach((o,c)=>{const l=t.left,h=t.right,u=new U(v(r,B(s.store,r)),l,l&&l.lastId,h,h&&h.id,e,null,new L(c,o));u.integrate(i,0),t.right=u,t.forward()})},ke=(i,e)=>{const{key:t,value:n}=e;n===null?i.delete(t):i.set(t,n)},en=(i,e)=>{var t;for(;i.right!==null;){if(!(i.right.deleted||i.right.content.constructor===L&&ne((t=e[i.right.content.key])!=null?t:null,i.right.content.value)))break;i.forward()}},tn=(i,e,t,n)=>{var c;const s=i.doc,r=s.clientID,o=new Map;for(const l in n){const h=n[l],u=(c=t.currentAttributes.get(l))!=null?c:null;if(!ne(u,h)){o.set(l,u);const{left:d,right:g}=t;t.right=new U(v(r,B(s.store,r)),d,d&&d.lastId,g,g&&g.id,e,null,new L(l,h)),t.right.integrate(i,0),t.forward()}}return o},wt=(i,e,t,n,s)=>{t.currentAttributes.forEach((g,w)=>{s[w]===void 0&&(s[w]=null)});const r=i.doc,o=r.clientID;en(t,s);const c=tn(i,e,t,s),l=n.constructor===String?new X(n):n instanceof D?new oe(n):new ve(n);let{left:h,right:u,index:d}=t;e._searchMarker&&Ne(e._searchMarker,t.index,l.getLength()),u=new U(v(o,B(r.store,o)),h,h&&h.lastId,u,u&&u.id,e,null,l),u.integrate(i,0),t.right=u,t.index=d,t.forward(),Qi(i,e,t,c)},ui=(i,e,t,n,s)=>{const r=i.doc,o=r.clientID;en(t,s);const c=tn(i,e,t,s);e:for(;t.right!==null&&(n>0||c.size>0&&(t.right.deleted||t.right.content.constructor===L));){if(!t.right.deleted)switch(t.right.content.constructor){case L:{const{key:l,value:h}=t.right.content,u=s[l];if(u!==void 0){if(ne(u,h))c.delete(l);else{if(n===0)break e;c.set(l,h)}t.right.delete(i)}else t.currentAttributes.set(l,h);break}default:n<t.right.length&&re(i,v(t.right.id.client,t.right.id.clock+n)),n-=t.right.length;break}t.forward()}if(n>0){let l="";for(;n>0;n--)l+=`
|
|
2
|
-
`;t.right=new U(
|
|
3
|
-
`?o.insert.slice(0,-1):o.insert;(typeof c!="string"||c.length>0)&&wt(n,this,s,c,o.attributes||{})}else o.retain!==void 0?ui(n,this,s,o.retain,o.attributes||{}):o.delete!==void 0&&di(n,s,o.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,n){var d;(d=this.doc)!=null||j();const s=[],r=new Map,o=this.doc;let c="",l=this._start;function h(){if(c.length>0){const g={};let w=!1;r.forEach((p,_)=>{w=!0,g[_]=p});const b={insert:c};w&&(b.attributes=g),s.push(b),c=""}}const u=()=>{for(;l!==null;){if(ue(l,e)||t!==void 0&&ue(l,t))switch(l.content.constructor){case X:{const g=r.get("ychange");e!==void 0&&!ue(l,e)?(g===void 0||g.user!==l.id.client||g.type!=="removed")&&(h(),r.set("ychange",n?n("removed",l.id):{type:"removed"})):t!==void 0&&!ue(l,t)?(g===void 0||g.user!==l.id.client||g.type!=="added")&&(h(),r.set("ychange",n?n("added",l.id):{type:"added"})):g!==void 0&&(h(),r.delete("ychange")),c+=l.content.str;break}case oe:case ve:{h();const g={insert:l.content.getContent()[0]};if(r.size>0){const w={};g.attributes=w,r.forEach((b,p)=>{w[p]=b})}s.push(g);break}case L:ue(l,e)&&(h(),ke(r,l.content));break}l=l.right}h()};return e||t?k(o,g=>{e&&Ot(g,e),t&&Ot(g,t),u()},"cleanup"):u(),s}insert(e,t,n){if(t.length<=0)return;const s=this.doc;s!==null?k(s,r=>{const o=Fe(r,this,e,!n);n||(n={},o.currentAttributes.forEach((c,l)=>{n[l]=c})),wt(r,this,o,t,n)}):this._pending.push(()=>this.insert(e,t,n))}insertEmbed(e,t,n){const s=this.doc;s!==null?k(s,r=>{const o=Fe(r,this,e,!n);wt(r,this,o,t,n||{})}):this._pending.push(()=>this.insertEmbed(e,t,n||{}))}delete(e,t){if(t===0)return;const n=this.doc;n!==null?k(n,s=>{di(s,Fe(s,this,e,!0),t)}):this._pending.push(()=>this.delete(e,t))}format(e,t,n){if(t===0)return;const s=this.doc;s!==null?k(s,r=>{const o=Fe(r,this,e,!1);o.right!==null&&ui(r,this,o,t,n)}):this._pending.push(()=>this.format(e,t,n))}removeAttribute(e){this.doc!==null?k(this.doc,t=>{Xe(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){this.doc!==null?k(this.doc,n=>{xt(n,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return Ft(this,e)}getAttributes(){return Xi(this)}_write(e){e.writeTypeRef(wr)}}class bt{constructor(e,t=()=>!0){var n;this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,(n=e.doc)!=null||j()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===Ue||t.constructor===be)&&t._start!==null)e=t._start;else for(;e!==null;)if(e.right!==null){e=e.right;break}else e.parent===this._root?e=null:e=e.parent._item;while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}}class be extends D{constructor(){super(),this._prelimContent=[]}get firstChild(){const e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new be}clone(){const e=new be;return e.insert(0,this.toArray().map(t=>t instanceof D?t.clone():t)),e}get length(){var e;return(e=this.doc)!=null||j(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new bt(this,e)}querySelector(e){e=e.toUpperCase();const n=new bt(this,s=>s.nodeName&&s.nodeName.toUpperCase()===e).next();return n.done?null:n.value}querySelectorAll(e){return e=e.toUpperCase(),me(new bt(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){rt(this,e,new dr(this,t,e))}toString(){return Gi(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},n){const s=e.createDocumentFragment();return n!==void 0&&n._createAssociation(s,this),Ve(this,r=>{s.insertBefore(r.toDOM(e,t,n),null)}),s}insert(e,t){this.doc!==null?k(this.doc,n=>{zi(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(this.doc!==null)k(this.doc,n=>{const s=e&&e instanceof D?e._item:e;Ye(n,this,s,t)});else{const n=this._prelimContent,s=e===null?0:n.findIndex(r=>r===e)+1;if(s===0&&e!==null)throw we("Reference item not found");n.splice(s,0,...t)}}delete(e,t=1){this.doc!==null?k(this.doc,n=>{Yi(n,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return Ji(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return qi(this,e)}slice(e=0,t=this.length){return Ki(this,e,t)}forEach(e){Ve(this,e)}_write(e){e.writeTypeRef(yr)}}class Ue extends be{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((n,s)=>{this.setAttribute(s,n)}),this._prelimAttrs=null}_copy(){return new Ue(this.nodeName)}clone(){const e=new Ue(this.nodeName),t=this.getAttributes();return us(t,(n,s)=>{typeof n=="string"&&e.setAttribute(s,n)}),e.insert(0,this.toArray().map(n=>n instanceof D?n.clone():n)),e}toString(){const e=this.getAttributes(),t=[],n=[];for(const c in e)n.push(c);n.sort();const s=n.length;for(let c=0;c<s;c++){const l=n[c];t.push(l+'="'+e[l]+'"')}const r=this.nodeName.toLocaleLowerCase(),o=t.length>0?" "+t.join(" "):"";return`<${r}${o}>${super.toString()}</${r}>`}removeAttribute(e){this.doc!==null?k(this.doc,t=>{Xe(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){this.doc!==null?k(this.doc,n=>{xt(n,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return Ft(this,e)}hasAttribute(e){return Zi(this,e)}getAttributes(e){return e?rr(this,e):Xi(this)}toDOM(e=document,t={},n){const s=e.createElement(this.nodeName),r=this.getAttributes();for(const o in r){const c=r[o];typeof c=="string"&&s.setAttribute(o,c)}return Ve(this,o=>{s.appendChild(o.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(s,this),s}_write(e){e.writeTypeRef(br),e.writeKey(this.nodeName)}}class dr extends nt{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}}class sn{constructor(e,t){this.id=e,this.length=t}get deleted(){throw G()}mergeWith(e){return!1}write(e,t,n){throw G()}integrate(e,t){throw G()}}const fr=0;class ie extends sn{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),$i(e.doc.store,this)}write(e,t){e.writeInfo(fr),e.writeLen(this.length-t)}getMissing(e,t){return null}}class ot{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new ot(this.content)}splice(e){throw G()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}}class et{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new et(this.len)}splice(e){const t=new et(this.len-e);return this.len=e,t}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){Ui(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}}const gr=(i,e)=>new Ee({guid:i,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1});class ct{constructor(e){e._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=e;const t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new ct(gr(this.doc.guid,this.opts))}splice(e){throw G()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}}class ve{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new ve(this.embed)}splice(e){throw G()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}}class L{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new L(this.key,this.value)}splice(e){throw G()}mergeWith(e){return!1}integrate(e,t){const n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}}const pr=ze("node_env")==="development";class ye{constructor(e){this.arr=e,pr&&vi(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new ye(this.arr)}splice(e){const t=new ye(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){const n=this.arr.length;e.writeLen(n-t);for(let s=t;s<n;s++){const r=this.arr[s];e.writeAny(r)}}getRef(){return 8}}class X{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new X(this.str)}splice(e){const t=new X(this.str.slice(e));this.str=this.str.slice(0,e);const n=this.str.charCodeAt(e-1);return n>=55296&&n<=56319&&(this.str=this.str.slice(0,e-1)+"�",t.str="�"+t.str.slice(1)),t}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}}const _r=0,mr=1,wr=2,br=3,yr=4;class oe{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new oe(this.type._copy())}splice(e){throw G()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(n=>{n.deleted?n.id.clock<(e.beforeState.get(n.id.client)||0)&&e._mergeStructs.push(n):n.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(n=>{for(;n!==null;)n.gc(e,!0),n=n.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}}const rn=(i,e,t)=>{const{client:n,clock:s}=e.id,r=new U(v(n,s+t),e,v(n,s+t-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t));return e.deleted&&r.markDeleted(),e.keep&&(r.keep=!0),e.redone!==null&&(r.redone=v(e.redone.client,e.redone.clock+t)),e.right=r,r.right!==null&&(r.right.left=r),i._mergeStructs.push(r),r.parentSub!==null&&r.right===null&&r.parent._map.set(r.parentSub,r),e.length=t,r};class U extends sn{constructor(e,t,n,s,r,o,c,l){super(e,l.getLength()),this.origin=n,this.left=t,this.right=s,this.rightOrigin=r,this.parent=o,this.parentSub=c,this.redone=null,this.content=l,this.info=this.content.isCountable()?qt:0}set marker(e){(this.info&ft)>0!==e&&(this.info^=ft)}get marker(){return(this.info&ft)>0}get keep(){return(this.info&Gt)>0}set keep(e){this.keep!==e&&(this.info^=Gt)}get countable(){return(this.info&qt)>0}get deleted(){return(this.info&dt)>0}set deleted(e){this.deleted!==e&&(this.info^=dt)}markDeleted(){this.info|=dt}getMissing(e,t){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=B(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=B(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Ke&&this.id.client!==this.parent.client&&this.parent.clock>=B(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=oi(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=re(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===ie||this.right&&this.right.constructor===ie)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===U&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===U&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Ke){const n=mt(t,this.parent);n.constructor===ie?this.parent=null:this.parent=n.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=oi(e,e.doc.store,v(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let n=this.left,s;if(n!==null)s=n.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;const r=new Set,o=new Set;for(;s!==null&&s!==this.right;){if(o.add(s),r.add(s),$e(this.origin,s.origin)){if(s.id.client<this.id.client)n=s,r.clear();else if($e(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&o.has(mt(e.doc.store,s.origin)))r.has(mt(e.doc.store,s.origin))||(n=s,r.clear());else break;s=s.right}this.left=n}if(this.left!==null){const n=this.left.right;this.right=n,this.left.right=this}else{let n;if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start,this.parent._start=this;this.right=n}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(e)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),$i(e.doc.store,this),this.content.integrate(e,this),li(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new ie(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;e!==null&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;e!==null&&e.deleted;)e=e.left;return e}get lastId(){return this.length===1?this.id:v(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&$e(e.origin,this.lastId)&&this.right===e&&$e(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&this.redone===null&&e.redone===null&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){const t=this.parent._searchMarker;return t&&t.forEach(n=>{n.p===e&&(n.p=this,!this.deleted&&this.countable&&(n.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){const t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),Ui(e.deleteSet,this.id.client,this.id.clock,this.length),li(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw he();this.content.gc(e),t?zs(e,this,new ie(this.id,this.length)):this.content=new et(this.length)}write(e,t){const n=t>0?v(this.id.client,this.id.clock+t-1):this.origin,s=this.rightOrigin,r=this.parentSub,o=this.content.getRef()&jn|(n===null?0:He)|(s===null?0:Ci)|(r===null?0:Un);if(e.writeInfo(o),n!==null&&e.writeLeftID(n),s!==null&&e.writeRightID(s),n===null&&s===null){const c=this.parent;if(c._item!==void 0){const l=c._item;if(l===null){const h=Gs(c);e.writeParentInfo(!0),e.writeString(h)}else e.writeParentInfo(!1),e.writeLeftID(l.id)}else c.constructor===String?(e.writeParentInfo(!0),e.writeString(c)):c.constructor===Ke?(e.writeParentInfo(!1),e.writeLeftID(c)):he();r!==null&&e.writeString(r)}this.content.write(e,t)}}const on=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:{},cn="__ $YJS$ __";on[cn]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");on[cn]=!0;const Oe=i=>Promise.reject(new Error("unimplemented method GetVoiceSign")),yt=(i,e={},t=[])=>({command:i,front_request_id:Te(),data:{...e,to_user_ids:Array.isArray(t)?t:[t]}}),ln=()=>{var i,e;window!=null&&window.__Realsee_Live__&&((e=(i=window==null?void 0:window.__Realsee_Live__)==null?void 0:i.dispose)==null||e.call(i),window.__Realsee_Live__=null)};class an extends ge{constructor(t){super();a(this,"_options",{});a(this,"keyframes",new ge);a(this,"_yDoc");a(this,"_buildInData");a(this,"_initializeKeyframesObservers",()=>{this._yDoc.getMap("keyframes").observe(this._handleKeyframesChange)});a(this,"_handleKeyframesChange",t=>{var o;const{transaction:n,target:s,changes:r}=t;if(s===this._buildInData.keyframes)if(n.origin.triggerUserId===((o=this.selfInfo)==null?void 0:o.id)){const c=yt($.KeyframeSync,this.snapshot,void 0);try{this._controller.sendMessage(c)}catch(l){m.error("Failed to send keyframe sync message:",l)}}else r.keys.forEach((c,l)=>{const h=c.oldValue,u=this.getFramesByKey(l),d=n.origin.frontRequestId;this.keyframes.emit(l,u,h,d)}),r.keys.size!==0&&this.emit("keyframes",this.snapshot,n.origin.frontRequestId)});a(this,"getFramesByKey",t=>this.snapshot[t]);a(this,"sendKeyframe",(t,n)=>{var s;return this.state!==V.OPEN?(m.warn("Attempted to send keyframe while connection is not open"),!1):(this._yDoc.transact(()=>{this._buildInData.keyframes.set(t,n)},{triggerUserId:(s=this.selfInfo)==null?void 0:s.id,frontRequestId:""}),!0)});a(this,"_controller",new Tn);a(this,"_initializeOptions",t=>{var n;this._options=Object.assign({initialMicroStatus:te.OPEN},t),this._options.jsBridge=this._initializeJsBridge(t),this._options.getVoiceSign=(n=t.getVoiceSign)!=null?n:Oe,this._options.autoPlayConfirm=t.autoPlayConfirm,this._options.rtc=this._initializeRTC(t)});a(this,"_initializeJsBridge",t=>{if(t.jsBridge)return t.jsBridge;if(t.useBuiltInJsBridge)return new mn});a(this,"_initializeRTC",t=>{if(t.rtc)return t.rtc;if(t.rtcType)return this._createBuiltInRTC(t);if(t.useBuiltInRTC)return this._createDefaultRTC(t)});a(this,"_createBuiltInRTC",t=>{var n;if(!t.getVoiceSign){m.error("GetVoiceSign method must be passed when using built-in RTC instances");return}switch(t.rtcType){case se.RealseeVRWebViewRTC:return this._createVRWebViewRTC();case se.RealseeBrowserChimeRTC:return new Ct({getVoiceSign:(n=this._options.getVoiceSign)!=null?n:Oe,logLevel:t.__debug__?0:1});case se.RealseeBrowserRTC:return this._createBrowserRTC();default:m.error("unknown built-in RTC type");return}});a(this,"_createVRWebViewRTC",()=>{var t;if(this._options.jsBridge)return new gi({jsBridge:this._options.jsBridge,getVoiceSign:(t=this._options.getVoiceSign)!=null?t:Oe});m.error("JsBridge instance must be passed when using built-in VRWebViewRTC instances")});a(this,"_createBrowserRTC",()=>{var t;if(!this._options.autoPlayConfirm){m.error("autoPlayConfirm method must be passed when using built-in RealseeBrowserRTC instances");return}return new fi({getVoiceSign:(t=this._options.getVoiceSign)!=null?t:Oe,autoPlayConfirm:this._options.autoPlayConfirm})});a(this,"_createDefaultRTC",t=>{var s;const n=(s=this._options.getVoiceSign)!=null?s:Oe;return!this._options.jsBridge||!Jt&&!Kt?t.builtInRTCType===Tt.RealseeXChimeRTC?new Ct({getVoiceSign:n}):this._createBrowserRTC():Jt&&(Sn||Cn)||Kt?this._createVRWebViewRTC():this._createBrowserRTC()});a(this,"_autoConnect",()=>{this._options.url&&this._options.getTicket&&this.connect()});a(this,"_debugSetup",()=>{this._options.__debug__&&Object.assign(window,{$liveController:this._controller,$live:this})});a(this,"_addLiveControllerEventListeners",()=>{this._controller.on("stateChange",this._handleStateChange),this._controller.on("message",this._handleMessage)});a(this,"_removeLiveControllerEventListeners",()=>{this._controller.off("stateChange",this._handleStateChange),this._controller.off("message",this._handleMessage)});a(this,"_handleStateChange",(t,n)=>{m.info(`State changed from ${n} to ${t}`),this.emit("stateChange",t,n)});a(this,"_handleMessage",async t=>{var n,s,r,o,c,l;if(m.debug("Received message:",t),typeof t=="object"){const{command:h,data:u={},frontRequestId:d,code:g,message:w,triggerUserId:b}=t;if(g==="SUCCESS")switch(h){case $.SelfUserInfo:{const p=u;Rn(this.selfInfo,p,{deep:!0})||(this._buildInData.selfInfo=p,this.emit("selfInfoUpdate",this._buildInData.selfInfo,d));break}case $.RoomInfo:{const p=u;this._buildInData.roomInfo=Object.assign({},p);const _=p.last_frame||{};this._yDoc.transact(()=>{for(const I in _)this._buildInData.keyframes.set(I,_[I])},{triggerUserId:"readyKeyframeSync",frontRequestId:d}),this.emit("readyKeyframeSync",p.last_frame||{});break}case $.RTCInfo:{m.info("RTC info updated:",u);const{voice_id:p,type:_}=u;if(this._buildInData.rtcInfo={voiceId:p,type:_},(n=this.$RTC)!=null&&n.joined)m.warn("已加入语音房间,无需重复加入!");else if(await((o=this.$RTC)==null?void 0:o.join({voiceId:p,userId:((s=this.selfInfo)==null?void 0:s.id)||"",roomId:(r=this.roomInfo)==null?void 0:r.info.room_code,type:_}))){const N=(c=this._options.initialMicroStatus)!=null?c:te.OPEN;await this.toggleMicro(N===te.OPEN)}else m.error("加入语音房间失败");break}case $.UserList:{const p=u;this._buildInData.userList=p,this.emit("userListUpdate",this.userList,d);break}case $.CustomEvent:{const p=u;this.emit("broadcast",p,d);break}case $.KeyframeSync:{const p=u;if(b===((l=this.selfInfo)==null?void 0:l.id))return;this._yDoc.transact(()=>{for(const _ in p)this._buildInData.keyframes.set(_,p[_])},{triggerUserId:b,frontRequestId:d});break}case $.BuiltinMsg:{const p=u;this.emit("builtinEvent",p),p.event_type===F.UserChange&&this.emit("userChange",p),p.event_type===F.RoomChange&&this.emit("roomChange",p),p.event_type===F.UserChange&&p.action===K.UserMicroStatus&&await this.toggleMicro(p.data.status===te.OPEN),p.event_type===F.RoomChange&&p.action===K.RoomClose&&await this._exit();break}case $.UserKickOut:{this.emit("kickOut");break}default:m.warn("Unknown command received:",h)}else m.error("Error in message:",w),this.emit("error",t)}});a(this,"_clearLiveData",()=>{this._buildInData.keyframes.clear(),this._buildInData={keyframes:this._yDoc.getMap("keyframes")}});a(this,"connect",async(t={})=>{var s,r,o,c;if(m.info("Attempting to connect with options:",t),this._options.url=(r=(s=t.url)!=null?s:this._options.url)!=null?r:"",this._options.getTicket=(o=t.getTicket)!=null?o:this._options.getTicket,this._options.initialMicroStatus=(c=t.rtcMicStatus)!=null?c:this._options.initialMicroStatus,!/^wss?:\/\//.test(this._options.url)||typeof this._options.getTicket!="function")return new Error("Invalid connection parameters");if(this._options.rtc&&!await this._options.rtc.detectMicro())return new Error("Failed to obtain microphone authorization");const n=this.state;if(n===V.CONNECTING||n===V.OPEN)if(t.force)await this._controller.close("force close by connect").catch(console.warn);else return new Error("已有Live实例正在连接中,请勿重复连接!");this._clearLiveData();try{const l=await this._options.getTicket(),h=yn(this._options.url,{ticket:l,force:+!!t.force});return this._controller.open(h),m.info("Connection established successfully"),!0}catch(l){return m.error("Failed to connect:",l),new Error("Failed to connect")}});a(this,"_exit",async()=>{var t;this._clearLiveData();try{await((t=this.$RTC)==null?void 0:t.quit())}catch(n){m.warn(n)}return this.state!==V.OPEN?!0:await this._controller.close()});a(this,"exit",async()=>this.close());a(this,"close",async()=>{var t;await this._controller.readyClose();try{await((t=this.$RTC)==null?void 0:t.quit())}catch(n){m.warn(n)}await this.updateStatus(F.RoomChange,K.RoomClose,{})});a(this,"dispose",async()=>{this._removeLiveControllerEventListeners();try{this._yDoc.getMap("keyframes").unobserve(this._handleKeyframesChange),this._yDoc.destroy()}catch(t){m.warn(t)}return this._clearLiveData(),await this._controller.dispose()});a(this,"setSelfInfo",async t=>await this.updateStatus(F.UserChange,K.UserInfo,t));a(this,"broadcast",(t,n,s)=>this.state!==V.OPEN?!1:new Promise((r,o)=>{const c=yt($.CustomEvent,t,n),l=c.front_request_id,h=s?setTimeout(()=>{o(new Error("RESPONSE TIMEOUT")),this.off("broadcast",u)},s):void 0,u=(d,g)=>{g===l&&(h&&clearTimeout(h),this.off("broadcast",u),r(d))};this.on("broadcast",u);try{this._controller.sendMessage(c)}catch(d){o(d)}}));a(this,"toggleMicro",async t=>{var s,r,o;if(!((r=(s=this.selfInfo)==null?void 0:s.permission)!=null&&r.control_own_micro))return!1;const n=await((o=this.$RTC)==null?void 0:o.toggleMicro(t));return n&&await this.updateStatus(F.UserChange,K.UserMicroStatusSync,{status:t?te.OPEN:te.CLOSE},[]),n});a(this,"forbidMicro",async(t,n)=>{var s,r;return typeof this._options.canForbidUserMicro=="function"&&!this._options.canForbidUserMicro(n)||!((r=(s=this.selfInfo)==null?void 0:s.permission)!=null&&r.control_other_micro)?!1:await this.updateStatus(F.UserChange,K.UserMicroStatus,{status:t},n)});a(this,"forbidSync",async(t,n)=>{var s,r;return typeof this._options.canForbidUserSync=="function"&&!this._options.canForbidUserSync(n)||!((r=(s=this.selfInfo)==null?void 0:s.permission)!=null&&r.control_other_sync)?!1:await this.updateStatus(F.UserChange,K.UserPermission,{sync_frame:t},n)});a(this,"kick",async t=>{var n,s;return typeof this._options.canForbidUserKick=="function"&&!this._options.canForbidUserKick(t)||!((s=(n=this.selfInfo)==null?void 0:n.permission)!=null&&s.change_other_status)?!1:await this.updateStatus(F.UserChange,K.UserStatus,{status:"KICK_OUT"},t)});a(this,"getSnapshotForKey",t=>this.snapshot[t]);m.info("Initializing Live instance with options:",t),this._addLiveControllerEventListeners(),this._yDoc=new Ee({guid:Te()}),this._buildInData={keyframes:this._yDoc.getMap("keyframes")},this._initializeKeyframesObservers(),this._initializeOptions(t),this._autoConnect(),this._debugSetup()}get options(){return Object.freeze(this._options||{})}get state(){return this._controller.state}get readyState(){return this._controller.state}get url(){return this.options.url}get $RTC(){return this._options.rtc}get jsBridge(){return this._options.jsBridge}get snapshot(){return this._buildInData.keyframes.toJSON()}get selfInfo(){return this._buildInData.selfInfo}get userList(){return this._buildInData.userList||[]}get roomInfo(){return this._buildInData.roomInfo}async updateStatus(t,n,s,r){if(this.state!==V.OPEN)return!1;const o=Object.assign({event_type:t,action:n},{data:s}),c=yt($.BuiltinMsg,o,r);try{return this._controller.sendMessage(c),!0}catch(l){return m.error(l),!1}}}const hn=i=>(ln(),new an(i));function Sr(i){const e=y.createContext(null),t=hn(i),n=t.jsBridge,s=f=>y.createElement(e.Provider,{value:t},f.children),r=()=>{const f=y.useContext(e);if(!f)throw new Error("LiveProvider never found.");return f},o=()=>t,c=()=>t.$RTC,l=()=>c(),h=()=>async f=>await t.connect(f);function u(f,E,A=[]){const S=r(),O=[S,f,...A],M=()=>S.keyframes.off(f,E);return y.useEffect(()=>(S.keyframes.on(f,E),M),O),M}function d(){const f=r(),E=y.useCallback(async R=>{await f.connect(R)},[f]),A=y.useCallback(R=>{f.toggleMicro(R)},[f]),S=y.useCallback(async(R,q,at=0)=>{await f.broadcast(R,q,at)},[f]),O=y.useCallback(async()=>{await f.exit()},[f]),M=y.useCallback(async R=>{await f.kick(R)},[f]),W=y.useCallback(async(R,q=[])=>{await f.forbidMicro(R,q)},[f]),ce=y.useCallback((R,q=[])=>{f.forbidSync(R,q)},[f]),lt=y.useCallback(R=>f.getFramesByKey(R),[f]),un=y.useCallback((R,q)=>{f.sendKeyframe(R,q)},[f]),dn=y.useCallback(R=>{f.setSelfInfo(R)},[f]),fn=y.useCallback((R,q,at,gn)=>{f.updateStatus(R,q,at,gn)},[f]);return{connect:E,broadcast:S,exit:O,kick:M,toggleMicro:A,forbidMicro:W,forbidSync:ce,sendKeyframe:un,getFramesByKey:lt,setSelfInfo:dn,updateStatus:fn}}function g(f){const E=r(),[A,S]=y.useState(E.getFramesByKey(f));y.useEffect(()=>{const M=lt=>S(lt),W=f,ce=M;return E.keyframes.on(W,ce),()=>E.keyframes.off(W,ce)},[E]);const O=y.useCallback(M=>E.sendKeyframe(f,M),[E]);return[A,O]}function w(f,E,A=[]){const S=r(),O=()=>S.off(f,E),M=[S,f,...A];return y.useEffect(()=>(S.on(f,E),O),M),O}function b(){const f=r(),[E,A]=y.useState(f.state);return y.useEffect(()=>{const S=O=>A(O);return f.on("stateChange",S),()=>f.off("stateChange",S)},[f]),E}function p(){const f=r();return{join:W=>f.$RTC.join(W),quit:()=>f.$RTC.quit(),shock:()=>{var W,ce;return(ce=(W=f.$RTC).shock)==null?void 0:ce.call(W)},toggleMicro:W=>f.$RTC.toggleMicro(W),detectMicro:()=>f.$RTC.detectMicro()}}function _(f,E,A=[]){const S=r(),O=()=>S.$RTC.off(f,E),M=[S,f,...A];return y.useEffect(()=>(S.$RTC.on(f,E),O),M),O}function I(){const f=r(),[E,A]=y.useState(f.selfInfo||{}),S=M=>A(M);y.useEffect(()=>(f.on("selfInfoUpdate",S),()=>f.off("selfInfoUpdate",S)),[f]);const O=y.useCallback(async M=>await f.setSelfInfo(M),[f]);return[E,O]}function N(){const f=r(),[E,A]=y.useState(f.snapshot);return y.useEffect(()=>{const S=O=>A(O);return f.on("keyframes",S),()=>f.off("keyframes",S)},[f]),E}function Wt(){const f=r(),[E,A]=y.useState(f.userList),S=O=>A(O);return y.useEffect(()=>(f.on("userListUpdate",S),()=>f.off("userListUpdate",S)),[f]),E}return{live:t,jsBridge:n,LiveProvider:s,unsafe__useLiveInstance:o,unsafe__useRTCInstance:l,useConnect:h,useKeyframe:g,useKeyframeUpdateCallback:u,useLiveAction:d,useLiveEventCallback:w,useLiveState:b,useRTCAction:p,useRTCEventCallback:_,useSelfInfo:I,useKeyframesSnapshot:N,useUserList:Wt}}const St=globalThis.__REALSEE_LIVE_BADGE_LOG__;(St==null||St)&&console.log("%c@realsee/live@0.7.7 (8/10/2026, 3:08:21 PM)","background: linear-gradient(to right, #1890ff, #52c41a); color: white; padding: 3px 6px; border-radius: 4px; font-weight: bold; text-shadow: 0 1px 0 rgba(0,0,0,0.2);");exports.BrowserRTC=fi;exports.BrowserRTC4Chime=Ct;exports.BuiltInRTCType=Tt;exports.BuiltinActionType=K;exports.BuiltinEventType=F;exports.Command=$;exports.CoreRTC=tt;exports.Live=an;exports.LiveState=V;exports.MemUserStatus=_i;exports.MicroStatus=te;exports.RTCJoinedInfoCodeEnum=le;exports.RTCType=se;exports.Subscribe=ge;exports.UserStatus=pi;exports.VRWebViewRTC=gi;exports.WebSocketCloseError=wi;exports.WebSocketErrorType=mi;exports.WebSocketState=Ge;exports._clearLiveInstanceIfNeed=ln;exports.createLive=hn;exports.createLiveReact=Sr;exports.parseLiveMsg=bn;exports.parseWSClsErr=bi;
|
|
1
|
+
"use strict";var pn=Object.defineProperty;var _n=(i,e,t)=>e in i?pn(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var a=(i,e,t)=>_n(i,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ut=require("trtc-js-sdk"),ee=require("amazon-chime-sdk-js"),mn=require("@realsee/jsbridge-x"),S=require("react"),fe=Symbol("$$REALSEE_LIVE_EVENT$$");function $e(i){return i[fe]||(i[fe]={}),i[fe]}function Pt(i){const e=i[fe];if(!e)return;Object.keys(e).some(n=>Array.isArray(e[n])&&e[n].length>0)||delete i[fe]}class pe{hasListener(e){const t=$e(this);return t&&t[e]&&t[e].length>0}on(e,t,n){const s=$e(this);return s[e]||(s[e]=[]),s[e].push([t,n||!1]),()=>this.off(e,t)}once(e,t){return this.on(e,t,!0)}off(e,t){const n=$e(this);if(!e){delete this[fe];return}if(n[e]||(n[e]=[]),t===void 0){n[e].length=0,Pt(this);return}const s=n[e].findIndex(r=>r[0]===t);s!==-1&&n[e].splice(s,1),Pt(this)}emit(e,...t){let n=!1;const r=$e(this)[e]||[];for(let o of r.slice()){const[c,l=!1]=o,h=c(...t);l&&this.off(e,c),h===!1&&(n=!0)}return n}}class it extends pe{}var re=(i=>(i.RealseeBrowserRTC="RealseeBrowserRTC",i.RealseeVRWebViewRTC="RealseeVRWebViewRTC",i.RealseeBrowserChimeRTC="RealseeBrowserChimeRTC",i))(re||{}),Lt=(i=>(i.RealseeXTRTC="trtc",i.RealseeXChimeRTC="chime",i))(Lt||{});const wn=()=>{const i=new Date,e=i.getFullYear(),t=(i.getMonth()+1).toString().padStart(2,"0"),n=i.getDate().toString().padStart(2,"0"),s=i.getHours().toString().padStart(2,"0"),r=i.getMinutes().toString().padStart(2,"0"),o=i.getSeconds().toString().padStart(2,"0"),c=i.getMilliseconds().toString().padStart(3,"0");return`[${e}-${t}-${n} ${s}:${r}:${o}.${c}]`},Oe=(i,e=[])=>{const t=`Realsee Live ${wn()} <${i}> `;switch(i){case"INFO":console.info(t,...e);break;case"ERROR":console.error(t,...e);break;case"WARN":console.warn(t,...e);break;case"DEBUG":console.debug(t,...e);break;default:console.log(t,...e)}},m={log:(...i)=>Oe("LOG",i),info:(...i)=>Oe("INFO",i),error:(...i)=>Oe("ERROR",i),warn:(...i)=>Oe("WARN",i),debug:(...i)=>Oe("DEBUG",i)};function te(){return((1+Math.random())*65536|0).toString(16).substring(1)}function Le(){return[te(),te(),"4"+te().substring(0,3),te(),te(),te()+te()+te()].join("-").toLowerCase()}class fi extends it{constructor(t){super();a(this,"type",re.RealseeBrowserRTC);a(this,"joined",!1);a(this,"micro",!1);a(this,"voiceId","");a(this,"_getVoiceSign",()=>{throw new Error("方法 getVoiceSign 未实现")});a(this,"_autoPlayConfirm");a(this,"checkRequirement",()=>ut.checkSystemRequirements());a(this,"$dom",document.createElement("div"));a(this,"_trtc",{client:null,stream:null});a(this,"join",async t=>{var r;this.emit("joinWillStart");const n=await this._getVoiceSign({voiceId:t.voiceId,roomId:t.roomId,userId:t.userId});this._trtc.client=ut.createClient({mode:"rtc",...n,enableAutoPlayDialog:typeof this._autoPlayConfirm!="function"}),(r=this._trtc.client)==null||r.enableAudioVolumeEvaluation(),this._registerRtcEvent();let s=await new Promise(o=>{var c;(c=this._trtc.client)==null||c.join({roomId:Number(t.voiceId)}).then(()=>o(!0)).catch(()=>o(!1))});return this.joined=s,s?(this._trtc.stream=ut.createStream({userId:n.userId,audio:!0,video:!1}),s=await new Promise(o=>{var c;(c=this._trtc.stream)==null||c.initialize().then(()=>o(!0)).catch(()=>o(!1))}),s=await new Promise(o=>{var c;(c=this._trtc.client)==null||c.publish(this._trtc.stream).then(()=>o(!0)).catch(()=>o(!1))}),this.joined=s,this.joined&&this.emit("joined"),s):!1});a(this,"_handleStreamAdded",t=>{var s;const n=t.stream;m.info("远端流增加:",n.getId()),(s=this._trtc.client)==null||s.subscribe(n)});a(this,"_handleStreamSubscribed",t=>{const n=t.stream;m.info("远端流订阅成功:",n.getId());const r=`rs-rtc-remote_stream-${n.getId()}`,o=document.createElement("div");o.id=r,this.$dom.appendChild(o),typeof this._autoPlayConfirm=="function"?(n.play(r).catch(c=>{m.warn("远端流播放失败(将尝试用户确认恢复)")}),n.on("error",c=>{if(c.getCode()===16451){const h=()=>n.resume();this._autoPlayConfirm({onConfirm:h})}})):n.play(r)});this._getVoiceSign=t.getVoiceSign,this._autoPlayConfirm=t.autoPlayConfirm,this._initParentDom()}_initParentDom(){this.$dom.id=`rs-rtc-${Le()}`,this.$dom.style.display="none",document.body.appendChild(this.$dom)}quit(){return new Promise(async t=>{var n,s;this.joined=!1,this._trtc.stream&&(await((n=this._trtc.client)==null?void 0:n.unpublish(this._trtc.stream)),this._trtc.stream.stop(),this._trtc.stream.close(),this._trtc.stream=null),(s=this._trtc.client)==null||s.leave().then(()=>this._trtc.client=null).then(()=>t(!0)).catch(()=>t(!1)),t(!0)})}detectMicro(){return new Promise(t=>{const n={audio:!0,video:!1};try{navigator.mediaDevices.getUserMedia(n).then(()=>t(!0)).catch(s=>{m.error(s.message),t(!1)})}catch(s){console.error(s),t(!1)}})}toggleMicro(t){return new Promise(n=>{var s,r,o,c;try{t?((r=(s=this._trtc)==null?void 0:s.stream)==null||r.unmuteAudio(),this.micro=!0):((c=(o=this._trtc)==null?void 0:o.stream)==null||c.muteAudio(),this.micro=!1),n(!0)}catch(l){n(!1)}})}shock(){throw new Error("Method not implemented.")}_registerRtcEvent(){var t,n,s,r;(t=this._trtc.client)==null||t.on("stream-added",this._handleStreamAdded),(n=this._trtc.client)==null||n.on("stream-subscribed",this._handleStreamSubscribed),(s=this._trtc.client)==null||s.on("audio-volume",o=>this.emit("userVolumes",o.result.map(({userId:c,audioVolume:l})=>({userId:c,audioVolume:l})))),(r=this._trtc.client)==null||r.on("error",o=>this.emit("error",o))}}class Et extends it{constructor(t){super();a(this,"type",re.RealseeBrowserChimeRTC);a(this,"joined",!1);a(this,"micro",!1);a(this,"voiceId","");a(this,"userId","");a(this,"logger");a(this,"deviceController");a(this,"meetingSession");a(this,"audioInput");a(this,"audioOutput");a(this,"deviceChangeObserver",{});a(this,"audioVideoObserver",{});a(this,"audioMixObserver");a(this,"_getVoiceSign",()=>{throw new Error("方法 getVoiceSign 未实现")});a(this,"_autoPlayConfirm");a(this,"$dom",document.createElement("div"));a(this,"$audio",document.createElement("audio"));a(this,"_initDom",()=>{this.$audio.id=`rs-rtc-${Le()}`,this.$dom.id=`rs-rtc-${Le()}`,this.$dom.appendChild(this.$audio),document.body.appendChild(this.$dom)});a(this,"initObservers",()=>{this.deviceChangeObserver={audioInputsChanged:t=>{this.logger.info(`audioInputsChanged ${typeof t}`),t==null||t.forEach(n=>{this.logger.info(`Device ID: ${n.deviceId} Microphone: ${n.label}`)})},audioOutputsChanged:t=>{this.logger.info(`audioOutputsChanged ${typeof t}`),t==null||t.forEach(n=>{this.logger.info(`Device ID: ${n.deviceId} Speaker: ${n.label}`)})},audioInputMuteStateChanged:(t,n)=>{this.logger.info(`Device ${t.toString()} ${n?"is muted in hardware":"is not muted"}`)}},this.audioVideoObserver={audioVideoDidStart:()=>{this.logger.info("Started")},audioVideoDidStop:t=>{this.logger.info(`Stopped with a session status code: ${t.statusCode()}`)},audioVideoDidStartConnecting:t=>{t&&this.logger.info("Attempting to reconnect")}},this.audioMixObserver={meetingAudioStreamBecameActive:t=>{if(this.$audio.paused){const n=()=>this.$audio.play().then(()=>{}).catch(s=>{if(m.error("播放远端流失败!",s),typeof this._autoPlayConfirm=="function"){const r=()=>n();this._autoPlayConfirm({onConfirm:r})}});n()}},meetingAudioStreamBecameInactive:t=>{}}});a(this,"_registerRtcEvent",()=>{var n,s,r,o,c,l;const t=((r=(s=(n=this.meetingSession)==null?void 0:n.configuration)==null?void 0:s.credentials)==null?void 0:r.attendeeId)||"";if(t){const h=new Map,u=()=>{const d=[];return h.forEach((g,_)=>{d.push({userId:g.userId,volume:g.muted||g.signalStrength===0||!g.volume?0:g.volume})}),d};(o=this.meetingSession)==null||o.audioVideo.realtimeSubscribeToAttendeeIdPresence((d,g,_)=>{var w;if(!g){h.delete(d),this.emit("userVolumes",u());return}(w=this.meetingSession)==null||w.audioVideo.realtimeSubscribeToVolumeIndicator(d,(y,b,O,p)=>{new ee.DefaultModality(y).base()===y&&(h.set(y,{userId:_||y,volume:b,muted:O,signalStrength:p}),this.emit("userVolumes",u()))})}),(c=this.meetingSession)==null||c.audioVideo.realtimeSubscribeToVolumeIndicator(t,(d,g,_,w)=>{new ee.DefaultModality(d).base()===d&&w!==null&&w!==1&&this.emit("weakNetwork")}),(l=this.meetingSession)==null||l.audioVideo.realtimeSubscribeToFatalError(d=>this.emit("error",d))}});this._getVoiceSign=t.getVoiceSign,this._autoPlayConfirm=t.autoPlayConfirm,this._initDom(),this.logger=new ee.ConsoleLogger("WebRTCLogger",t.logLevel||ee.LogLevel.INFO),this.deviceController=new ee.DefaultDeviceController(this.logger),this.initObservers()}async join(t){return new Promise(async(n,s)=>{var r,o;this.emit("joinWillStart");try{const{sdkAppId:c,userId:l,roomId:h,userSig:u}=await this._getVoiceSign({...t,roomId:t.roomId||0});this.userId=l;const{attendence:d,vendor_wrapper:g}=JSON.parse(decodeURIComponent(u)),_=new ee.MeetingSessionConfiguration({Meeting:g},{Attendee:{ExternalUserId:d.external_user_id,AttendeeId:d.attendee_id,JoinToken:d.join_token}});this.meetingSession=new ee.DefaultMeetingSession(_,this.logger,this.deviceController),this._registerRtcEvent(),this.meetingSession.audioVideo.addDeviceChangeObserver(this.deviceChangeObserver),this.meetingSession.audioVideo.addObserver(this.audioVideoObserver),this.meetingSession.audioVideo.bindAudioElement(this.$audio);const w={audioVideoDidStart:()=>{var y;(y=this.meetingSession)==null||y.audioVideo.realtimeMuteLocalAudio(),this.joined=!0,this.emit("joined"),n(!0)},audioVideoDidStop:()=>{this.joined=!1,n(!1)}};this.meetingSession.audioVideo.addObserver(w),this.audioMixObserver&&this.meetingSession.audioVideo.addAudioMixObserver(this.audioMixObserver),this.meetingSession.audioVideo.setDeviceLabelTrigger(async()=>await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}));try{const y=await this.meetingSession.audioVideo.listAudioInputDevices();m.info("audioInputDevices ===>",y);const b=((r=y[0])==null?void 0:r.deviceId)||"default";await this.meetingSession.audioVideo.startAudioInput(b)}catch(y){m.error(`设置语音输入设备失败:${y.message}`)}try{const y=await this.meetingSession.audioVideo.listAudioOutputDevices();m.info("audioOutputDevices ===>",y);const b=((o=y[0])==null?void 0:o.deviceId)||"default";await this.meetingSession.audioVideo.chooseAudioOutput(b)}catch(y){m.error(`设置语音输出设备失败:${y.message}`)}this.meetingSession.audioVideo.start()}catch(c){this.emit("error",c),this.logger.error(c.message),n(!1)}})}quit(){return this.joined?new Promise((t,n)=>{var r,o;this.joined=!1;const s={audioVideoDidStop:async c=>{var h;const l=c.statusCode();(h=this.meetingSession)==null||h.deviceController.destroy(),l===ee.MeetingSessionStatusCode.Left?(this.logger.info("You left the session"),t(!0)):(this.logger.info(`Stopped with a session status code: ${l}`),t(!0))}};(r=this.meetingSession)==null||r.audioVideo.addObserver(s),(o=this.meetingSession)==null||o.audioVideo.stop()}):Promise.resolve(!0)}async detectMicro(){return new Promise(t=>{const n={audio:!0,video:!1};try{navigator.mediaDevices.getUserMedia(n).then(()=>t(!0)).catch(()=>t(!1))}catch(s){this.logger.error(s.message),t(!1)}})}async toggleMicro(t){var s,r,o;t?(s=this.meetingSession)==null||s.audioVideo.realtimeUnmuteLocalAudio():(r=this.meetingSession)==null||r.audioVideo.realtimeMuteLocalAudio();const n=(o=this.meetingSession)==null?void 0:o.audioVideo.realtimeIsLocalAudioMuted();return n!==void 0?t!==n:!1}shock(){throw new Error("Method not implemented.")}}var ae=(i=>(i[i.Success=0]="Success",i[i.Failure=1]="Failure",i[i.ReJoin=2]="ReJoin",i[i.NoMicroPermission=3]="NoMicroPermission",i[i.Unknown=500]="Unknown",i))(ae||{});class gi extends it{constructor({jsBridge:t,getVoiceSign:n}){super();a(this,"type",re.RealseeVRWebViewRTC);a(this,"joined",!1);a(this,"micro",!1);a(this,"voiceId","");a(this,"_joinOptions",null);a(this,"options");a(this,"handleUserVolumes",t=>{this.emit("userVolumes",t)});a(this,"handleWeakNetwork",t=>{t&&this.emit("weakNetwork")});a(this,"join",async t=>{this._joinOptions=t,this.emit("joinWillStart");const{sdkAppId:n,userId:s,userSig:r}=await this.getVoiceSignOrEmitError(t);return!n||!s||!r?!1:(this.type=t.type,this.jsBridge.webViewType==="WxMiniProgramWebView"?this.handleWxMiniProgramWebViewJoin({sdkAppId:n,userId:s,userSig:r,voiceId:t.voiceId}):this.handleAppWebViewJoin({sdkAppId:n,userId:s,userSig:r,voiceId:t.voiceId}))});a(this,"reJoin",async()=>this._joinOptions?this.join({voiceId:this._joinOptions.voiceId,userId:this._joinOptions.userId,roomId:this._joinOptions.roomId,type:this._joinOptions.type}):(this.emitErrorAndSetJoinedFalse("重连失败:未找到加入房间参数。"),!1));a(this,"getVoiceSignOrEmitError",async t=>{try{return await this.options.getVoiceSign(t)}catch(n){return this.emitErrorAndSetJoinedFalse("加入房间失败:rtc 签名请求异常"),{}}});a(this,"handleWxMiniProgramWebViewJoin",async t=>{const[n,s]=await this.joinRoomOrEmitError(t);return s?!1:this.handleJoinResult(n)});a(this,"handleAppWebViewJoin",t=>new Promise(n=>{this.off("inner.rtc.success");const s=r=>{this.off("inner.rtc.fail",s),this.off("inner.rtc.success",s),n(this.handleJoinResult(r))};this.once("inner.rtc.fail",s),this.once("inner.rtc.success",s);try{const{sdkAppId:r,userId:o,userSig:c,voiceId:l}=t;this.jsBridge.callAndListen(`live/join?sdkAppID=${r}&userID=${o}&roomID=${l}&userSig=${c}`,h=>{h===!0?this.emit("inner.rtc.success",h):typeof h=="object"?h.code===ae.Success||h.code===ae.ReJoin?this.emit("inner.rtc.success",h):this.emit("inner.rtc.fail",h):this.emit("inner.rtc.fail",h)})}catch(r){n(this.handleJoinResult({message:r.message,code:ae.Unknown}))}}));a(this,"joinRoomOrEmitError",async({sdkAppId:t,userId:n,voiceId:s,userSig:r})=>{try{return await this.jsBridge.callAndBackfeed(`live/join?sdkAppID=${t}&userID=${n}&roomID=${Number(s)}&userSig=${r}`)}catch(o){return this.emitErrorAndSetJoinedFalse("加入房间失败:"+o.message),[null,o]}});a(this,"handleJoinResult",t=>{switch(!0){case t===!0:case(typeof t=="object"&&t.code===ae.Success):case(typeof t=="object"&&t.code===ae.ReJoin):{this.emit("joined"),this.joined=!0;break}default:{this.joined=!1;const n=typeof t=="object"?t.message:"加入房间失败:未知异常。";this.emit("error",new Error(n,{cause:t}))}}return this.joined});a(this,"emitErrorAndSetJoinedFalse",t=>{this.emit("error",new Error(t)),this.joined=!1});a(this,"quit",async()=>{const[t,n]=await this.jsBridge.callAndBackfeed("live/quit");return t===null&&this.emit("error",n||new Error("退出房间失败:未知异常。")),this.joined=!1,!!t});a(this,"detectMicro",async()=>{const[t,n]=await this.jsBridge.detectMicro();return t===null?(this.emit("error",n||new Error("麦克风监测异常!")),!1):t});a(this,"toggleMicro",async t=>{const[n,s]=await this.jsBridge.callAndBackfeed(`live/toggleMicro?flag=${t?1:0}`);return n===null?(this.emit("error",s||new Error("麦克风监测异常!")),!1):(this.micro=n,n)});a(this,"shock",()=>{this.jsBridge.shock(1)});this.options={jsBridge:t,getVoiceSign:n},this.jsBridge.webViewType!=="WxMiniProgramWebView"&&this.jsBridge.callAndListen("live/userVolumes",this.handleUserVolumes),this.jsBridge.callAndListen("live/weakNetwork",this.handleWeakNetwork),this.on("inner.rtc.fail",this.handleJoinResult)}get jsBridge(){return this.options.jsBridge}}var $=(i=>(i.SelfUserInfo="SELF_USER_INFO",i.RoomInfo="ROOM_INFO",i.RTCInfo="RTC_INFO",i.UserList="USER_LIST",i.BuiltinMsg="BUILTIN_MSG",i.CustomEvent="CUSTOM_EVENT",i.KeyframeSync="KEYFRAME_SYNC",i.UserKickOut="USER_KICK_OUT",i))($||{}),F=(i=>(i.UserChange="user_change",i.RoomChange="room_change",i))(F||{}),J=(i=>(i.UserMicroStatus="change_micro_status",i.UserMicroStatusSync="sync_micro_status",i.UserPermission="change_permission",i.UserStatus="change_status",i.UserInfo="change_info",i.RoomClose="close",i))(J||{}),ie=(i=>(i.OPEN="OPEN",i.CLOSE="CLOSE",i))(ie||{});function bn(i){try{const e=JSON.parse(i),t={code:e.code,message:e.message,command:e.command,roomCode:e.room_code,appID:e.app_id,requestId:e.request_id,frontRequestId:e.front_request_id,triggerUserID:e.trigger_user_id,data:e.data||{}},n=Object.keys(t).filter(s=>t[s]===void 0);return n.length>0&&console.warn(`推送数据格式异常:${n.join(" ")} 值不存在!`),t}catch(e){return!1}}var V=(i=>(i[i.NOTINITIALIZED=-1]="NOTINITIALIZED",i[i.CONNECTING=0]="CONNECTING",i[i.OPEN=1]="OPEN",i[i.CLOSED=3]="CLOSED",i))(V||{}),pi=(i=>(i[i.Normal=0]="Normal",i[i.Removed=1]="Removed",i[i.Replaced=2]="Replaced",i))(pi||{}),_i=(i=>(i.WAIT_ENTER="WAIT_ENTER",i.ONLINE="ONLINE",i.LEAVE="LEAVE",i.KICK_OUT="KICK_OUT",i.BE_REPLACE="BE_REPLACE",i.EXCEPTION="EXCEPTION",i))(_i||{}),qe=(i=>(i[i.NOTINITIALIZED=-1]="NOTINITIALIZED",i[i.CONNECTING=0]="CONNECTING",i[i.OPEN=1]="OPEN",i[i.CLOSING=2]="CLOSING",i[i.CLOSED=3]="CLOSED",i))(qe||{}),mi=(i=>(i.Error="Error",i.Close="Close",i.MicroAuth="MicroAuth",i.DuplicateConnect="DuplicateConnect",i.IllegalURL="IllegalURL",i.Unknown="Unknown",i.IllegalArgs="IllegalArgs",i))(mi||{}),wi=(i=>(i.Err_1000="CLOSE_NORMAL",i.Err_1001="CLOSE_GOING_AWAY",i.Err_1002="CLOSE_PROTOCOL_ERROR",i.Err_1003="CLOSE_UNSUPPORTED",i.Err_1006="CLOSE_ABNORMAL",i.Err_1007="Unsupported Data",i.Err_1008="Policy Violation",i.Err_1009="CLOSE_TOO_LARGE",i.Err_unknown="unknown",i))(wi||{});function bi(i){switch(i){case 1e3:return"CLOSE_NORMAL";case 1001:return"CLOSE_GOING_AWAY";case 1002:return"CLOSE_PROTOCOL_ERROR";case 1003:return"CLOSE_UNSUPPORTED";case 1006:return"CLOSE_ABNORMAL";case 1007:return"Unsupported Data";case 1008:return"Policy Violation";case 1009:return"CLOSE_TOO_LARGE"}return"unknown"}function yn(i,e={}){var c;const t=new URL(i,"http://localhost"),n=new URLSearchParams(t.search);for(const[l,h]of Object.entries(e))n.set(l,String(h));const s=n.toString(),r=i.split("#")[0].split("?")[0],o=(c=t.hash)!=null?c:"";return`${r}${s?`?${s}`:""}${o}`}const yi=(()=>{var t;const i=typeof process!="undefined"&&((t=process.versions)==null?void 0:t.node)!=null;return typeof window!="undefined"&&"Deno"in window||i||typeof window=="undefined"})(),_e=yi?"":navigator.userAgent,Sn=/android/i.test(_e),Cn=/iPhone|iPad|iPod|iPadOS/i.test(_e)||!yi&&/Macintosh/.test(_e)&&"ontouchend"in globalThis,Kt=/MicroMessenger/i.test(_e)&&/miniProgram/i.test(_e),Jt=/realsee/i.test(_e);function He(i){return Object.prototype.toString.call(i)==="[object Object]"}function nt(i,e){return i===e?!0:i==null||e==null||typeof i!=typeof e?!1:Number.isNaN(i)&&Number.isNaN(e)}function En(i,e){if(i===e)return!0;if(i==null||e==null)return!1;const t=Object.keys(i),n=Object.keys(e);return t.length!==n.length?!1:t.every(s=>nt(i[s],e[s]))}function kn(i,e){return i===e?!0:i==null||e==null||i.length!==e.length?!1:i.every((t,n)=>nt(t,e[n]))}function vn(i,e){return nt(i,e)?!0:He(i)&&He(e)?En(i,e):Array.isArray(i)&&Array.isArray(e)?kn(i,e):!1}function Mt(i,e){return nt(i,e)?!0:He(i)&&He(e)?On(i,e):Array.isArray(i)&&Array.isArray(e)?In(i,e):!1}function In(i,e){if(i.length!==e.length)return!1;for(let t=0,n=i.length;t<n;t++)if(!Mt(i[t],e[t]))return!1;return!0}function On(i,e){if(i===e)return!0;if(i==null||e==null)return!1;const t=Object.keys(i),n=Object.keys(e);return t.length!==n.length?!1:t.every(s=>Mt(i[s],e[s]))}function Rn(i,e,t={deep:!1}){return t.deep?Mt(i,e):vn(i,e)}class Tn extends pe{constructor(t){super();a(this,"_realWebSocket");a(this,"_url");a(this,"_protocols");a(this,"_readyState",qe.NOTINITIALIZED);a(this,"_options",{timeout:1e4,shouldReconnect:(t,n)=>{if(!(t.code===1008||t.code===1011))return[0,1e3,2e3][n.attempts%3]},should1000Reconnect:!1,ignoreConnectivityEvents:!1,automaticOpen:!1});a(this,"_connectTimeout");a(this,"_attempts",0);a(this,"_reconnects",-1);a(this,"_reconnectWhenOnlineAgain",!1);a(this,"_explicitlyClosed",!1);a(this,"_pendingReconnect");a(this,"_connectivityEventsAttached",!1);a(this,"_heathCheckTimer");a(this,"_healthCheck",async()=>{if(this._realWebSocket){const t=this._realWebSocket.readyState;t!==this._readyState&&(this._readyState=t,this._readyState===qe.CLOSING&&this.emit("closing"))}await new Promise(t=>setTimeout(t,2e3)),this._heathCheckTimer=requestAnimationFrame(this._healthCheck)});a(this,"_clearConnectTimeoutIfNeed",()=>{this._connectTimeout&&(clearTimeout(this._connectTimeout),this._connectTimeout=void 0)});a(this,"_clearHeathCheckIfNeed",()=>{this._heathCheckTimer&&(cancelAnimationFrame(this._heathCheckTimer),this._heathCheckTimer=void 0)});a(this,"_startHealthCheck",()=>{this._clearHeathCheckIfNeed(),this._heathCheckTimer=requestAnimationFrame(this._healthCheck)});a(this,"_stopHealthCheck",()=>{this._clearHeathCheckIfNeed()});a(this,"_clearPendingReconnectIfNeeded",()=>{this._pendingReconnect&&(clearTimeout(this._pendingReconnect),this._pendingReconnect=void 0)});a(this,"_online",t=>{this._reconnectWhenOnlineAgain&&(this._clearPendingReconnectIfNeeded(),this._reconnect(t))});a(this,"_offline",()=>{var t;this._reconnectWhenOnlineAgain=!0,(t=this._realWebSocket)==null||t.close(1e3,"offline")});a(this,"_detachConnectivityEvents",()=>{this._connectivityEventsAttached&&(globalThis==null||globalThis.removeEventListener("online",this._online),globalThis==null||globalThis.removeEventListener("offline",this._offline),this._connectivityEventsAttached=!1)});a(this,"_attachConnectivityEvents",()=>{this._connectivityEventsAttached||(globalThis==null||globalThis.addEventListener("online",this._online),globalThis==null||globalThis.addEventListener("offline",this._offline),this._connectivityEventsAttached=!0)});a(this,"send",t=>{var n,s,r;((n=this._realWebSocket)==null?void 0:n.readyState)===((s=this._realWebSocket)==null?void 0:s.OPEN)&&((r=this._realWebSocket)==null||r.send(t))});a(this,"close",(t,n)=>{var s;return typeof t!="number"&&(n=t,t=1e3),this._clearPendingReconnectIfNeeded(),this._reconnectWhenOnlineAgain=!1,this._explicitlyClosed=!0,this._detachConnectivityEvents(),(s=this._realWebSocket)==null?void 0:s.close(t,n)});a(this,"open",t=>{var n,s;t&&(this._url=t),((n=this._realWebSocket)==null?void 0:n.readyState)!==WebSocket.OPEN&&((s=this._realWebSocket)==null?void 0:s.readyState)!==WebSocket.CONNECTING&&(this._clearPendingReconnectIfNeeded(),this._reconnectWhenOnlineAgain=!1,this._explicitlyClosed=!1,this._createWebSocket())});a(this,"_createWebSocket",()=>{var s;const t=typeof this._url=="string"?this._url:(s=this._url)==null?void 0:s.call(this,this);if(!t)return;this._clearConnectTimeoutIfNeed(),this._clearPendingReconnectIfNeeded(),this._removeWebSocketEvent(),this._realWebSocket=new WebSocket(t,this._protocols||void 0),this._attempts++,this.emit("connecting",new CustomEvent("connecting",{detail:{attempts:this._attempts,reconnects:this._reconnects}}));const n=()=>{this._connectTimeout=void 0,this._detachConnectivityEvents(),this.emit("timeout",new CustomEvent("timeout",{detail:{attempts:this._attempts,reconnects:this._reconnects}}))};this._connectTimeout=setTimeout(n,this._options.timeout),this._dispatchWebSocketEvent(),this._options.ignoreConnectivityEvents||this._attachConnectivityEvents()});a(this,"_removeWebSocketEvent",()=>{var t,n,s,r;(t=this._realWebSocket)==null||t.removeEventListener("open",this._webSocketOpenHandler),(n=this._realWebSocket)==null||n.removeEventListener("close",this._webSocketCloseHandler),(s=this._realWebSocket)==null||s.removeEventListener("error",this._webSocketErrorHandler),(r=this._realWebSocket)==null||r.removeEventListener("message",this._webSocketMessageHandler)});a(this,"_dispatchWebSocketEvent",()=>{var t,n,s,r;(t=this._realWebSocket)==null||t.addEventListener("open",this._webSocketOpenHandler),(n=this._realWebSocket)==null||n.addEventListener("close",this._webSocketCloseHandler),(s=this._realWebSocket)==null||s.addEventListener("error",this._webSocketErrorHandler),(r=this._realWebSocket)==null||r.addEventListener("message",this._webSocketMessageHandler)});a(this,"_webSocketOpenHandler",t=>{this._connectTimeout&&(clearTimeout(this._connectTimeout),this._connectTimeout=void 0);const n=++this._reconnects,s=this._attempts;return this._attempts=0,this._reconnectWhenOnlineAgain=!1,this._startHealthCheck(),this.emit("open",Object.assign(t,{detail:{reconnects:n,attempts:s}}))});a(this,"_webSocketCloseHandler",t=>(this._reconnect(t),this._stopHealthCheck(),this.emit("close",t)));a(this,"_webSocketErrorHandler",t=>this.emit("error",new CustomEvent("error",{detail:{error:t}})));a(this,"_webSocketMessageHandler",t=>this.emit("message",t));t&&this.setOptions(t),this._startHealthCheck()}get attempts(){return this._attempts}setOptions(t){if(!t)return;this._url=t.url,this._protocols=t.protocols;const n=Object.assign(this._options,t.robustOptions||{});if(typeof(n==null?void 0:n.timeout)!="number")throw new Error("timeout must be the number of milliseconds to timeout a connection attempt");if(typeof(n==null?void 0:n.shouldReconnect)!="function")throw new Error("shouldReconnect must be a function that returns the number of milliseconds to wait for a reconnect attempt, or null or undefined to not reconnect.");this._options=n,this._options.automaticOpen&&this._createWebSocket()}_reconnect(t){var o,c,l;if(!this._options.should1000Reconnect&&t.code===1e3||this._explicitlyClosed){this._attempts=0;return}if(this._connectivityEventsAttached&&((o=globalThis==null?void 0:globalThis.navigator)==null?void 0:o.onLine)===!1){this._reconnectWhenOnlineAgain=!0;return}const r=(l=(c=this._options).shouldReconnect)==null?void 0:l.call(c,t,this);typeof r=="number"?(m.debug(`RobustWebSocket: Reconnecting in ${r}ms...`),this._pendingReconnect=setTimeout(this._createWebSocket,r)):m.debug("RobustWebSocket: No reconnection will be attempted.")}}class An extends pe{constructor(){super();a(this,"_ws",new Tn({url:"",robustOptions:{should1000Reconnect:!0,ignoreConnectivityEvents:!0}}));a(this,"_state",V.NOTINITIALIZED);a(this,"_addWebSocketEventListeners",()=>{this._ws.on("close",this._handleCloseEvent),this._ws.on("closing",this._handleClosingEvent),this._ws.on("connecting",this._handleConnectingEvent),this._ws.on("error",this._handleErrorEvent),this._ws.on("message",this._handleMessageEvent),this._ws.on("open",this._handleOpenEvent),this._ws.on("timeout",this._handleTimeoutEvent)});a(this,"_removeWebSocketEventListeners",()=>{this._ws.off("close",this._handleCloseEvent),this._ws.off("closing",this._handleClosingEvent),this._ws.off("connecting",this._handleConnectingEvent),this._ws.off("error",this._handleErrorEvent),this._ws.off("message",this._handleMessageEvent),this._ws.off("open",this._handleOpenEvent),this._ws.off("timeout",this._handleTimeoutEvent)});a(this,"_handleCloseEvent",t=>{m.info(`live room closed bacause of ${t.code}-${t.reason||bi(t.code)}`),this.state=V.CLOSED});a(this,"_handleClosingEvent",()=>{var t;m.info("live room is closing, onLine:",(t=globalThis==null?void 0:globalThis.navigator)==null?void 0:t.onLine),this.state=V.CLOSED});a(this,"_handleConnectingEvent",t=>{m.info("live room is connecting"),this.state=V.CONNECTING,t.detail.reconnects>0&&this.emit("reconnecting",t.detail)});a(this,"_handleErrorEvent",t=>{m.error("live room error",t),this.state=V.CLOSED});a(this,"_handleMessageEvent",t=>{let n=(()=>{try{return JSON.parse(t.data)}catch(s){return t.data}})();this.emit("message",n)});a(this,"_handleOpenEvent",t=>{m.info("live room open",t.detail),this.state=V.OPEN,t.detail.reconnects>0&&this.emit("reconnected",t.detail)});a(this,"_handleTimeoutEvent",t=>{m.error("live room connect timeout!",t.detail),this.state=V.CLOSED});a(this,"dispose",async()=>(this._removeWebSocketEventListeners(),await this.close("live room close by controller disposed!")));a(this,"open",t=>this._ws.open(t));a(this,"close",(t,n)=>new Promise(s=>{this._ws.once("close",()=>s(!0)),this._ws.close(t,n)}));a(this,"sendMessage",(t="")=>{if(t==null)throw new Error("live message is empty!");if(this.state!==V.OPEN)throw new Error("live has not yet been initialized!");return this._ws.send(JSON.stringify(t))});a(this,"readyClose",()=>{this._ws&&(this._ws._explicitlyClosed=!0)});this._addWebSocketEventListeners()}set state(t){const n=JSON.parse(JSON.stringify(this._state));this._state=t,this.emit("stateChange",this.state,n)}get state(){return this._state}}const G=()=>new Map,kt=i=>{const e=G();return i.forEach((t,n)=>{e.set(n,t)}),e},Ce=(i,e,t)=>{let n=i.get(e);return n===void 0&&i.set(e,n=t()),n},Ln=(i,e)=>{const t=[];for(const[n,s]of i)t.push(e(s,n));return t},Mn=(i,e)=>{for(const[t,n]of i)if(e(n,t))return!0;return!1},me=()=>new Set,dt=i=>i[i.length-1],we=Array.from,Dn=Array.isArray;class Nn{constructor(){this._observers=G()}on(e,t){return Ce(this._observers,e,me).add(t),t}once(e,t){const n=(...s)=>{this.off(e,n),t(...s)};this.on(e,n)}off(e,t){const n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,t){return we((this._observers.get(e)||G()).values()).forEach(n=>n(...t))}destroy(){this._observers=G()}}const he=Math.floor,Pe=Math.abs,Si=(i,e)=>i<e?i:e,Ee=(i,e)=>i>e?i:e,Vn=i=>i!==0?i<0:1/i<0,Gt=1,qt=2,ft=4,gt=8,Un=32,Ci=64,ze=128,jn=31,Ht=63,Te=127,Bn=2147483647,$n=Number.isInteger||(i=>typeof i=="number"&&isFinite(i)&&he(i)===i),xn=i=>i.toLowerCase(),Fn=/^\s*/g,Wn=i=>i.replace(Fn,""),Pn=/([A-Z])/g,zt=(i,e)=>Wn(i.replace(Pn,t=>`${e}${xn(t)}`)),Kn=i=>{const e=unescape(encodeURIComponent(i)),t=e.length,n=new Uint8Array(t);for(let s=0;s<t;s++)n[s]=e.codePointAt(s);return n},Me=typeof TextEncoder!="undefined"?new TextEncoder:null,Jn=i=>Me.encode(i),Gn=Me?Jn:Kn;let pt=typeof TextDecoder=="undefined"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});pt&&pt.decode(new Uint8Array).length===1&&(pt=null);class Be{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Dt=()=>new Be,qn=i=>{let e=i.cpos;for(let t=0;t<i.bufs.length;t++)e+=i.bufs[t].length;return e},Y=i=>{const e=new Uint8Array(qn(i));let t=0;for(let n=0;n<i.bufs.length;n++){const s=i.bufs[n];e.set(s,t),t+=s.length}return e.set(new Uint8Array(i.cbuf.buffer,0,i.cpos),t),e},Hn=(i,e)=>{const t=i.cbuf.length;t-i.cpos<e&&(i.bufs.push(new Uint8Array(i.cbuf.buffer,0,i.cpos)),i.cbuf=new Uint8Array(Ee(t,e)*2),i.cpos=0)},L=(i,e)=>{const t=i.cbuf.length;i.cpos===t&&(i.bufs.push(i.cbuf),i.cbuf=new Uint8Array(t*2),i.cpos=0),i.cbuf[i.cpos++]=e},vt=L,k=(i,e)=>{for(;e>Te;)L(i,ze|Te&e),e=he(e/128);L(i,Te&e)},Nt=(i,e)=>{const t=Vn(e);for(t&&(e=-e),L(i,(e>Ht?ze:0)|(t?Ci:0)|Ht&e),e=he(e/64);e>0;)L(i,(e>Te?ze:0)|Te&e),e=he(e/128)},It=new Uint8Array(3e4),zn=It.length/3,Yn=(i,e)=>{if(e.length<zn){const t=Me.encodeInto(e,It).written||0;k(i,t);for(let n=0;n<t;n++)L(i,It[n])}else x(i,Gn(e))},Xn=(i,e)=>{const t=unescape(encodeURIComponent(e)),n=t.length;k(i,n);for(let s=0;s<n;s++)L(i,t.codePointAt(s))},ge=Me&&Me.encodeInto?Yn:Xn,Vt=(i,e)=>{const t=i.cbuf.length,n=i.cpos,s=Si(t-n,e.length),r=e.length-s;i.cbuf.set(e.subarray(0,s),n),i.cpos+=s,r>0&&(i.bufs.push(i.cbuf),i.cbuf=new Uint8Array(Ee(t*2,r)),i.cbuf.set(e.subarray(s)),i.cpos=r)},x=(i,e)=>{k(i,e.byteLength),Vt(i,e)},Ut=(i,e)=>{Hn(i,e);const t=new DataView(i.cbuf.buffer,i.cpos,e);return i.cpos+=e,t},Zn=(i,e)=>Ut(i,4).setFloat32(0,e,!1),Qn=(i,e)=>Ut(i,8).setFloat64(0,e,!1),es=(i,e)=>Ut(i,8).setBigInt64(0,e,!1),Yt=new DataView(new ArrayBuffer(4)),ts=i=>(Yt.setFloat32(0,i),Yt.getFloat32(0)===i),De=(i,e)=>{switch(typeof e){case"string":L(i,119),ge(i,e);break;case"number":$n(e)&&Pe(e)<=Bn?(L(i,125),Nt(i,e)):ts(e)?(L(i,124),Zn(i,e)):(L(i,123),Qn(i,e));break;case"bigint":L(i,122),es(i,e);break;case"object":if(e===null)L(i,126);else if(Dn(e)){L(i,117),k(i,e.length);for(let t=0;t<e.length;t++)De(i,e[t])}else if(e instanceof Uint8Array)L(i,116),x(i,e);else{L(i,118);const t=Object.keys(e);k(i,t.length);for(let n=0;n<t.length;n++){const s=t[n];ge(i,s),De(i,e[s])}}break;case"boolean":L(i,e?120:121);break;default:L(i,127)}};class Xt extends Be{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&k(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}}const Zt=i=>{i.count>0&&(Nt(i.encoder,i.count===1?i.s:-i.s),i.count>1&&k(i.encoder,i.count-2))};class Ke{constructor(){this.encoder=new Be,this.s=0,this.count=0}write(e){this.s===e?this.count++:(Zt(this),this.count=1,this.s=e)}toUint8Array(){return Zt(this),Y(this.encoder)}}const Qt=i=>{if(i.count>0){const e=i.diff*2+(i.count===1?0:1);Nt(i.encoder,e),i.count>1&&k(i.encoder,i.count-2)}};class _t{constructor(){this.encoder=new Be,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Qt(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return Qt(this),Y(this.encoder)}}class is{constructor(){this.sarr=[],this.s="",this.lensE=new Ke}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){const e=new Be;return this.sarr.push(this.s),this.s="",ge(e,this.sarr.join("")),Vt(e,this.lensE.toUint8Array()),Y(e)}}const be=i=>new Error(i),q=()=>{throw be("Method unimplemented")},ue=()=>{throw be("Unexpected case")},ns=crypto.getRandomValues.bind(crypto),Ei=()=>ns(new Uint32Array(1))[0],ss="10000000-1000-4000-8000"+-1e11,rs=()=>ss.replace(/[018]/g,i=>(i^Ei()&15>>i/4).toString(16)),ei=i=>new Promise(i);Promise.all.bind(Promise);const ti=i=>i===void 0?null:i;class os{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}}let ki=new os,cs=!0;try{typeof localStorage!="undefined"&&localStorage&&(ki=localStorage,cs=!1)}catch(i){}const ls=ki,as=Object.assign,hs=Object.keys,us=(i,e)=>{for(const t in i)e(i[t],t)},ii=i=>hs(i).length,ds=i=>{for(const e in i)return!1;return!0},fs=(i,e)=>{for(const t in i)if(!e(i[t],t))return!1;return!0},gs=(i,e)=>Object.prototype.hasOwnProperty.call(i,e),ps=(i,e)=>i===e||ii(i)===ii(e)&&fs(i,(t,n)=>(t!==void 0||gs(e,n))&&e[n]===t),_s=Object.freeze,vi=i=>{for(const e in i){const t=i[e];(typeof t=="object"||typeof t=="function")&&vi(i[e])}return _s(i)},jt=(i,e,t=0)=>{try{for(;t<i.length;t++)i[t](...e)}finally{t<i.length&&jt(i,e,t+1)}},ms=(i,e)=>e.includes(i),Ne=typeof process!="undefined"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process!="undefined"?process:0)==="[object process]";let K;const ws=()=>{if(K===void 0)if(Ne){K=G();const i=process.argv;let e=null;for(let t=0;t<i.length;t++){const n=i[t];n[0]==="-"?(e!==null&&K.set(e,""),e=n):e!==null&&(K.set(e,n),e=null)}e!==null&&K.set(e,"")}else typeof location=="object"?(K=G(),(location.search||"?").slice(1).split("&").forEach(i=>{if(i.length!==0){const[e,t]=i.split("=");K.set(`--${zt(e,"-")}`,t),K.set(`-${zt(e,"-")}`,t)}})):K=G();return K},Ot=i=>ws().has(i),Ye=i=>ti(Ne?process.env[i.toUpperCase().replaceAll("-","_")]:ls.getItem(i)),Ii=i=>Ot("--"+i)||Ye(i)!==null;Ii("production");const bs=Ne&&ms(process.env.FORCE_COLOR,["true","1","2"]),ys=bs||!Ot("--no-colors")&&!Ii("no-color")&&(!Ne||process.stdout.isTTY)&&(!Ne||Ot("--color")||Ye("COLORTERM")!==null||(Ye("TERM")||"").includes("color"));class Ss{constructor(e,t){this.left=e,this.right=t}}const z=(i,e)=>new Ss(i,e);typeof DOMParser!="undefined"&&new DOMParser;const Cs=i=>Ln(i,(e,t)=>`${t}:${e};`).join(""),Q=Symbol,Oi=Q(),Ri=Q(),Es=Q(),ks=Q(),vs=Q(),Ti=Q(),Is=Q(),Bt=Q(),Os=Q(),Rs=i=>{var s;i.length===1&&((s=i[0])==null?void 0:s.constructor)===Function&&(i=i[0]());const e=[],t=[];let n=0;for(;n<i.length;n++){const r=i[n];if(r===void 0)break;if(r.constructor===String||r.constructor===Number)e.push(r);else if(r.constructor===Object)break}for(n>0&&t.push(e.join(""));n<i.length;n++){const r=i[n];r instanceof Symbol||t.push(r)}return t},Ts={[Oi]:z("font-weight","bold"),[Ri]:z("font-weight","normal"),[Es]:z("color","blue"),[vs]:z("color","green"),[ks]:z("color","grey"),[Ti]:z("color","red"),[Is]:z("color","purple"),[Bt]:z("color","orange"),[Os]:z("color","black")},As=i=>{var o;i.length===1&&((o=i[0])==null?void 0:o.constructor)===Function&&(i=i[0]());const e=[],t=[],n=G();let s=[],r=0;for(;r<i.length;r++){const c=i[r],l=Ts[c];if(l!==void 0)n.set(l.left,l.right);else{if(c===void 0)break;if(c.constructor===String||c.constructor===Number){const h=Cs(n);r>0||h.length>0?(e.push("%c"+c),t.push(h)):e.push(c)}else break}}for(r>0&&(s=t,s.unshift(e.join("")));r<i.length;r++){const c=i[r];c instanceof Symbol||s.push(c)}return s},Ai=ys?As:Rs,Ls=(...i)=>{console.log(...Ai(i)),Li.forEach(e=>e.print(i))},Ms=(...i)=>{console.warn(...Ai(i)),i.unshift(Bt),Li.forEach(e=>e.print(i))},Li=me(),Mi=i=>({[Symbol.iterator](){return this},next:i}),Ds=(i,e)=>Mi(()=>{let t;do t=i.next();while(!t.done&&!e(t.value));return t}),mt=(i,e)=>Mi(()=>{const{done:t,value:n}=i.next();return{done:t,value:t?void 0:e(n)}});class Ns{constructor(e,t){this.clock=e,this.len=t}}class Vs{constructor(){this.clients=new Map}}const Di=(i,e,t)=>e.clients.forEach((n,s)=>{const r=i.doc.store.clients.get(s);for(let o=0;o<n.length;o++){const c=n[o];xi(i,r,c.clock,c.len,t)}}),Us=(i,e)=>{let t=0,n=i.length-1;for(;t<=n;){const s=he((t+n)/2),r=i[s],o=r.clock;if(o<=e){if(e<o+r.len)return s;t=s+1}else n=s-1}return null},Ni=(i,e)=>{const t=i.clients.get(e.client);return t!==void 0&&Us(t,e.clock)!==null},Vi=i=>{i.clients.forEach(e=>{e.sort((s,r)=>s.clock-r.clock);let t,n;for(t=1,n=1;t<e.length;t++){const s=e[n-1],r=e[t];s.clock+s.len>=r.clock?s.len=Ee(s.len,r.clock+r.len-s.clock):(n<t&&(e[n]=r),n++)}e.length=n})},Ui=(i,e,t,n)=>{Ce(i.clients,e,()=>[]).push(new Ns(t,n))},js=(i,e)=>{k(i.restEncoder,e.clients.size),we(e.clients.entries()).sort((t,n)=>n[0]-t[0]).forEach(([t,n])=>{i.resetDsCurVal(),k(i.restEncoder,t);const s=n.length;k(i.restEncoder,s);for(let r=0;r<s;r++){const o=n[r];i.writeDsClock(o.clock),i.writeDsLen(o.len)}})},ji=Ei;class ke extends Nn{constructor({guid:e=rs(),collectionid:t=null,gc:n=!0,gcFilter:s=()=>!0,meta:r=null,autoLoad:o=!1,shouldLoad:c=!0}={}){super(),this.gc=n,this.gcFilter=s,this.clientID=ji(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new qs,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=c,this.autoLoad=o,this.meta=r,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=ei(h=>{this.on("load",()=>{this.isLoaded=!0,h(this)})});const l=()=>ei(h=>{const u=d=>{(d===void 0||d===!0)&&(this.off("sync",u),h())};this.on("sync",u)});this.on("sync",h=>{h===!1&&this.isSynced&&(this.whenSynced=l()),this.isSynced=h===void 0||h===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=l()}load(){const e=this._item;e!==null&&!this.shouldLoad&&v(e.parent.doc,t=>{t.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(we(this.subdocs).map(e=>e.guid))}transact(e,t=null){return v(this,e,t)}get(e,t=N){const n=Ce(this.share,e,()=>{const r=new t;return r._integrate(this,null),r}),s=n.constructor;if(t!==N&&s!==t)if(s===N){const r=new t;r._map=n._map,n._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=r}),r._start=n._start;for(let o=r._start;o!==null;o=o.right)o.parent=r;return r._length=n._length,this.share.set(e,r),r._integrate(this,null),r}else throw new Error(`Type with the name ${e} has already been defined with a different constructor`);return n}getArray(e=""){return this.get(e,Ae)}getText(e=""){return this.get(e,et)}getMap(e=""){return this.get(e,Qe)}getXmlElement(e=""){return this.get(e,je)}getXmlFragment(e=""){return this.get(e,ye)}toJSON(){const e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,we(this.subdocs).forEach(t=>t.destroy());const e=this._item;if(e!==null){this._item=null;const t=e.content;t.doc=new ke({guid:this.guid,...t.opts,shouldLoad:!1}),t.doc._item=e,v(e.parent.doc,n=>{const s=t.doc;e.deleted||n.subdocsAdded.add(s),n.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class Bs{constructor(){this.restEncoder=Dt()}toUint8Array(){return Y(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){k(this.restEncoder,e)}writeDsLen(e){k(this.restEncoder,e)}}class $s extends Bs{writeLeftID(e){k(this.restEncoder,e.client),k(this.restEncoder,e.clock)}writeRightID(e){k(this.restEncoder,e.client),k(this.restEncoder,e.clock)}writeClient(e){k(this.restEncoder,e)}writeInfo(e){vt(this.restEncoder,e)}writeString(e){ge(this.restEncoder,e)}writeParentInfo(e){k(this.restEncoder,e?1:0)}writeTypeRef(e){k(this.restEncoder,e)}writeLen(e){k(this.restEncoder,e)}writeAny(e){De(this.restEncoder,e)}writeBuf(e){x(this.restEncoder,e)}writeJSON(e){ge(this.restEncoder,JSON.stringify(e))}writeKey(e){ge(this.restEncoder,e)}}class xs{constructor(){this.restEncoder=Dt(),this.dsCurrVal=0}toUint8Array(){return Y(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const t=e-this.dsCurrVal;this.dsCurrVal=e,k(this.restEncoder,t)}writeDsLen(e){e===0&&ue(),k(this.restEncoder,e-1),this.dsCurrVal+=e}}class Fs extends xs{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new _t,this.clientEncoder=new Ke,this.leftClockEncoder=new _t,this.rightClockEncoder=new _t,this.infoEncoder=new Xt(vt),this.stringEncoder=new is,this.parentInfoEncoder=new Xt(vt),this.typeRefEncoder=new Ke,this.lenEncoder=new Ke}toUint8Array(){const e=Dt();return k(e,0),x(e,this.keyClockEncoder.toUint8Array()),x(e,this.clientEncoder.toUint8Array()),x(e,this.leftClockEncoder.toUint8Array()),x(e,this.rightClockEncoder.toUint8Array()),x(e,Y(this.infoEncoder)),x(e,this.stringEncoder.toUint8Array()),x(e,Y(this.parentInfoEncoder)),x(e,this.typeRefEncoder.toUint8Array()),x(e,this.lenEncoder.toUint8Array()),Vt(e,Y(this.restEncoder)),Y(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(e?1:0)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){De(this.restEncoder,e)}writeBuf(e){x(this.restEncoder,e)}writeJSON(e){De(this.restEncoder,e)}writeKey(e){const t=this.keyMap.get(e);t===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}}const Ws=(i,e,t,n)=>{n=Ee(n,e[0].id.clock);const s=X(e,n);k(i.restEncoder,e.length-s),i.writeClient(t),k(i.restEncoder,n);const r=e[s];r.write(i,n-r.id.clock);for(let o=s+1;o<e.length;o++)e[o].write(i,0)},Ps=(i,e,t)=>{const n=new Map;t.forEach((s,r)=>{B(e,r)>s&&n.set(r,s)}),$t(e).forEach((s,r)=>{t.has(r)||n.set(r,0)}),k(i.restEncoder,n.size),we(n.entries()).sort((s,r)=>r[0]-s[0]).forEach(([s,r])=>{Ws(i,e.clients.get(s),s,r)})},Ks=(i,e)=>Ps(i,e.doc.store,e.beforeState);class Js{constructor(){this.l=[]}}const ni=()=>new Js,si=(i,e)=>i.l.push(e),ri=(i,e)=>{const t=i.l,n=t.length;i.l=t.filter(s=>e!==s),n===i.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Bi=(i,e,t)=>jt(i.l,[e,t]);class Je{constructor(e,t){this.client=e,this.clock=t}}const xe=(i,e)=>i===e||i!==null&&e!==null&&i.client===e.client&&i.clock===e.clock,I=(i,e)=>new Je(i,e),Gs=i=>{for(const[e,t]of i.doc.share.entries())if(t===i)return e;throw ue()},de=(i,e)=>e===void 0?!i.deleted:e.sv.has(i.id.client)&&(e.sv.get(i.id.client)||0)>i.id.clock&&!Ni(e.ds,i.id),Rt=(i,e)=>{const t=Ce(i.meta,Rt,me),n=i.doc.store;t.has(e)||(e.sv.forEach((s,r)=>{s<B(n,r)&&oe(i,I(r,s))}),Di(i,e.ds,s=>{}),t.add(e))};class qs{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const $t=i=>{const e=new Map;return i.clients.forEach((t,n)=>{const s=t[t.length-1];e.set(n,s.id.clock+s.length)}),e},B=(i,e)=>{const t=i.clients.get(e);if(t===void 0)return 0;const n=t[t.length-1];return n.id.clock+n.length},$i=(i,e)=>{let t=i.clients.get(e.id.client);if(t===void 0)t=[],i.clients.set(e.id.client,t);else{const n=t[t.length-1];if(n.id.clock+n.length!==e.id.clock)throw ue()}t.push(e)},X=(i,e)=>{let t=0,n=i.length-1,s=i[n],r=s.id.clock;if(r===e)return n;let o=he(e/(r+s.length-1)*n);for(;t<=n;){if(s=i[o],r=s.id.clock,r<=e){if(e<r+s.length)return o;t=o+1}else n=o-1;o=he((t+n)/2)}throw ue()},Hs=(i,e)=>{const t=i.clients.get(e.client);return t[X(t,e.clock)]},wt=Hs,Tt=(i,e,t)=>{const n=X(e,t),s=e[n];return s.id.clock<t&&s instanceof U?(e.splice(n+1,0,rn(i,s,t-s.id.clock)),n+1):n},oe=(i,e)=>{const t=i.doc.store.clients.get(e.client);return t[Tt(i,t,e.clock)]},oi=(i,e,t)=>{const n=e.clients.get(t.client),s=X(n,t.clock),r=n[s];return t.clock!==r.id.clock+r.length-1&&r.constructor!==ne&&n.splice(s+1,0,rn(i,r,t.clock-r.id.clock+1)),r},zs=(i,e,t)=>{const n=i.clients.get(e.id.client);n[X(n,e.id.clock)]=t},xi=(i,e,t,n,s)=>{if(n===0)return;const r=t+n;let o=Tt(i,e,t),c;do c=e[o++],r<c.id.clock+c.length&&Tt(i,e,r),s(c);while(o<e.length&&e[o].id.clock<r)};class Ys{constructor(e,t,n){this.doc=e,this.deleteSet=new Vs,this.beforeState=$t(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=n,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const ci=(i,e)=>e.deleteSet.clients.size===0&&!Mn(e.afterState,(t,n)=>e.beforeState.get(n)!==t)?!1:(Vi(e.deleteSet),Ks(i,e),js(i,e.deleteSet),!0),li=(i,e,t)=>{const n=e._item;(n===null||n.id.clock<(i.beforeState.get(n.id.client)||0)&&!n.deleted)&&Ce(i.changed,e,me).add(t)},Ge=(i,e)=>{let t=i[e],n=i[e-1],s=e;for(;s>0;t=n,n=i[--s-1]){if(n.deleted===t.deleted&&n.constructor===t.constructor&&n.mergeWith(t)){t instanceof U&&t.parentSub!==null&&t.parent._map.get(t.parentSub)===t&&t.parent._map.set(t.parentSub,n);continue}break}const r=e-s;return r&&i.splice(e+1-r,r),r},Xs=(i,e,t)=>{for(const[n,s]of i.clients.entries()){const r=e.clients.get(n);for(let o=s.length-1;o>=0;o--){const c=s[o],l=c.clock+c.len;for(let h=X(r,c.clock),u=r[h];h<r.length&&u.id.clock<l;u=r[++h]){const d=r[h];if(c.clock+c.len<=d.id.clock)break;d instanceof U&&d.deleted&&!d.keep&&t(d)&&d.gc(e,!1)}}}},Zs=(i,e)=>{i.clients.forEach((t,n)=>{const s=e.clients.get(n);for(let r=t.length-1;r>=0;r--){const o=t[r],c=Si(s.length-1,1+X(s,o.clock+o.len-1));for(let l=c,h=s[l];l>0&&h.id.clock>=o.clock;h=s[l])l-=1+Ge(s,l)}})},Fi=(i,e)=>{if(e<i.length){const t=i[e],n=t.doc,s=n.store,r=t.deleteSet,o=t._mergeStructs;try{Vi(r),t.afterState=$t(t.doc.store),n.emit("beforeObserverCalls",[t,n]);const c=[];t.changed.forEach((l,h)=>c.push(()=>{(h._item===null||!h._item.deleted)&&h._callObserver(t,l)})),c.push(()=>{t.changedParentTypes.forEach((l,h)=>{h._dEH.l.length>0&&(h._item===null||!h._item.deleted)&&(l=l.filter(u=>u.target._item===null||!u.target._item.deleted),l.forEach(u=>{u.currentTarget=h,u._path=null}),l.sort((u,d)=>u.path.length-d.path.length),Bi(h._dEH,l,t))})}),c.push(()=>n.emit("afterTransaction",[t,n])),jt(c,[]),t._needFormattingCleanup&&hr(t)}finally{n.gc&&Xs(r,s,n.gcFilter),Zs(r,s),t.afterState.forEach((u,d)=>{const g=t.beforeState.get(d)||0;if(g!==u){const _=s.clients.get(d),w=Ee(X(_,g),1);for(let y=_.length-1;y>=w;)y-=1+Ge(_,y)}});for(let u=o.length-1;u>=0;u--){const{client:d,clock:g}=o[u].id,_=s.clients.get(d),w=X(_,g);w+1<_.length&&Ge(_,w+1)>1||w>0&&Ge(_,w)}if(!t.local&&t.afterState.get(n.clientID)!==t.beforeState.get(n.clientID)&&(Ls(Bt,Oi,"[yjs] ",Ri,Ti,"Changed the client-id because another client seems to be using it."),n.clientID=ji()),n.emit("afterTransactionCleanup",[t,n]),n._observers.has("update")){const u=new $s;ci(u,t)&&n.emit("update",[u.toUint8Array(),t.origin,n,t])}if(n._observers.has("updateV2")){const u=new Fs;ci(u,t)&&n.emit("updateV2",[u.toUint8Array(),t.origin,n,t])}const{subdocsAdded:c,subdocsLoaded:l,subdocsRemoved:h}=t;(c.size>0||h.size>0||l.size>0)&&(c.forEach(u=>{u.clientID=n.clientID,u.collectionid==null&&(u.collectionid=n.collectionid),n.subdocs.add(u)}),h.forEach(u=>n.subdocs.delete(u)),n.emit("subdocs",[{loaded:l,added:c,removed:h},n,t]),h.forEach(u=>u.destroy())),i.length<=e+1?(n._transactionCleanups=[],n.emit("afterAllTransactions",[n,i])):Fi(i,e+1)}}},v=(i,e,t=null,n=!0)=>{const s=i._transactionCleanups;let r=!1,o=null;i._transaction===null&&(r=!0,i._transaction=new Ys(i,t,n),s.push(i._transaction),s.length===1&&i.emit("beforeAllTransactions",[i]),i.emit("beforeTransaction",[i._transaction,i]));try{o=e(i._transaction)}finally{if(r){const c=i._transaction===s[0];i._transaction=null,c&&Fi(s,0)}}return o},ai="You must not compute changes after the event-handler fired.";class st{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=Qs(this.currentTarget,this.target))}deletes(e){return Ni(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw be(ai);const e=new Map,t=this.target;this.transaction.changed.get(t).forEach(s=>{if(s!==null){const r=t._map.get(s);let o,c;if(this.adds(r)){let l=r.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(r))if(l!==null&&this.deletes(l))o="delete",c=dt(l.content.getContent());else return;else l!==null&&this.deletes(l)?(o="update",c=dt(l.content.getContent())):(o="add",c=void 0)}else if(this.deletes(r))o="delete",c=dt(r.content.getContent());else return;e.set(s,{action:o,oldValue:c})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw be(ai);const t=this.target,n=me(),s=me(),r=[];if(e={added:n,deleted:s,delta:r,keys:this.keys},this.transaction.changed.get(t).has(null)){let c=null;const l=()=>{c&&r.push(c)};for(let h=t._start;h!==null;h=h.right)h.deleted?this.deletes(h)&&!this.adds(h)&&((c===null||c.delete===void 0)&&(l(),c={delete:0}),c.delete+=h.length,s.add(h)):this.adds(h)?((c===null||c.insert===void 0)&&(l(),c={insert:[]}),c.insert=c.insert.concat(h.content.getContent()),n.add(h)):((c===null||c.retain===void 0)&&(l(),c={retain:0}),c.retain+=h.length);c!==null&&c.retain===void 0&&l()}this._changes=e}return e}}const Qs=(i,e)=>{const t=[];for(;e._item!==null&&e!==i;){if(e._item.parentSub!==null)t.unshift(e._item.parentSub);else{let n=0,s=e._item.parent._start;for(;s!==e._item&&s!==null;)!s.deleted&&s.countable&&(n+=s.length),s=s.right;t.unshift(n)}e=e._item.parent}return t},j=()=>{Ms("Invalid access: Add Yjs type to a document before reading data.")},Wi=80;let xt=0;class er{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=xt++}}const tr=i=>{i.timestamp=xt++},Pi=(i,e,t)=>{i.p.marker=!1,i.p=e,e.marker=!0,i.index=t,i.timestamp=xt++},ir=(i,e,t)=>{if(i.length>=Wi){const n=i.reduce((s,r)=>s.timestamp<r.timestamp?s:r);return Pi(n,e,t),n}else{const n=new er(e,t);return i.push(n),n}},rt=(i,e)=>{if(i._start===null||e===0||i._searchMarker===null)return null;const t=i._searchMarker.length===0?null:i._searchMarker.reduce((r,o)=>Pe(e-r.index)<Pe(e-o.index)?r:o);let n=i._start,s=0;for(t!==null&&(n=t.p,s=t.index,tr(t));n.right!==null&&s<e;){if(!n.deleted&&n.countable){if(e<s+n.length)break;s+=n.length}n=n.right}for(;n.left!==null&&s>e;)n=n.left,!n.deleted&&n.countable&&(s-=n.length);for(;n.left!==null&&n.left.id.client===n.id.client&&n.left.id.clock+n.left.length===n.id.clock;)n=n.left,!n.deleted&&n.countable&&(s-=n.length);return t!==null&&Pe(t.index-s)<n.parent.length/Wi?(Pi(t,n,s),t):ir(i._searchMarker,n,s)},Ve=(i,e,t)=>{for(let n=i.length-1;n>=0;n--){const s=i[n];if(t>0){let r=s.p;for(r.marker=!1;r&&(r.deleted||!r.countable);)r=r.left,r&&!r.deleted&&r.countable&&(s.index-=r.length);if(r===null||r.marker===!0){i.splice(n,1);continue}s.p=r,r.marker=!0}(e<s.index||t>0&&e===s.index)&&(s.index=Ee(e,s.index+t))}},ot=(i,e,t)=>{const n=i,s=e.changedParentTypes;for(;Ce(s,i,()=>[]).push(t),i._item!==null;)i=i._item.parent;Bi(n._eH,t,e)};class N{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=ni(),this._dEH=ni(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw q()}clone(){throw q()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){si(this._eH,e)}observeDeep(e){si(this._dEH,e)}unobserve(e){ri(this._eH,e)}unobserveDeep(e){ri(this._dEH,e)}toJSON(){}}const Ki=(i,e,t)=>{var o;(o=i.doc)!=null||j(),e<0&&(e=i._length+e),t<0&&(t=i._length+t);let n=t-e;const s=[];let r=i._start;for(;r!==null&&n>0;){if(r.countable&&!r.deleted){const c=r.content.getContent();if(c.length<=e)e-=c.length;else{for(let l=e;l<c.length&&n>0;l++)s.push(c[l]),n--;e=0}}r=r.right}return s},Ji=i=>{var n;(n=i.doc)!=null||j();const e=[];let t=i._start;for(;t!==null;){if(t.countable&&!t.deleted){const s=t.content.getContent();for(let r=0;r<s.length;r++)e.push(s[r])}t=t.right}return e},Ue=(i,e)=>{var s;let t=0,n=i._start;for((s=i.doc)!=null||j();n!==null;){if(n.countable&&!n.deleted){const r=n.content.getContent();for(let o=0;o<r.length;o++)e(r[o],t++,i)}n=n.right}},Gi=(i,e)=>{const t=[];return Ue(i,(n,s)=>{t.push(e(n,s,i))}),t},nr=i=>{let e=i._start,t=null,n=0;return{[Symbol.iterator](){return this},next:()=>{if(t===null){for(;e!==null&&e.deleted;)e=e.right;if(e===null)return{done:!0,value:void 0};t=e.content.getContent(),n=0,e=e.right}const s=t[n++];return t.length<=n&&(t=null),{done:!1,value:s}}}},qi=(i,e)=>{var s;(s=i.doc)!=null||j();const t=rt(i,e);let n=i._start;for(t!==null&&(n=t.p,e-=t.index);n!==null;n=n.right)if(!n.deleted&&n.countable){if(e<n.length)return n.content.getContent()[e];e-=n.length}},Xe=(i,e,t,n)=>{let s=t;const r=i.doc,o=r.clientID,c=r.store,l=t===null?e._start:t.right;let h=[];const u=()=>{h.length>0&&(s=new U(I(o,B(c,o)),s,s&&s.lastId,l,l&&l.id,e,null,new Se(h)),s.integrate(i,0),h=[])};n.forEach(d=>{if(d===null)h.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:h.push(d);break;default:switch(u(),d.constructor){case Uint8Array:case ArrayBuffer:s=new U(I(o,B(c,o)),s,s&&s.lastId,l,l&&l.id,e,null,new ct(new Uint8Array(d))),s.integrate(i,0);break;case ke:s=new U(I(o,B(c,o)),s,s&&s.lastId,l,l&&l.id,e,null,new lt(d)),s.integrate(i,0);break;default:if(d instanceof N)s=new U(I(o,B(c,o)),s,s&&s.lastId,l,l&&l.id,e,null,new ce(d)),s.integrate(i,0);else throw new Error("Unexpected content type in insert operation")}}}),u()},Hi=()=>be("Length exceeded!"),zi=(i,e,t,n)=>{if(t>e._length)throw Hi();if(t===0)return e._searchMarker&&Ve(e._searchMarker,t,n.length),Xe(i,e,null,n);const s=t,r=rt(e,t);let o=e._start;for(r!==null&&(o=r.p,t-=r.index,t===0&&(o=o.prev,t+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(t<=o.length){t<o.length&&oe(i,I(o.id.client,o.id.clock+t));break}t-=o.length}return e._searchMarker&&Ve(e._searchMarker,s,n.length),Xe(i,e,o,n)},sr=(i,e,t)=>{let s=(e._searchMarker||[]).reduce((r,o)=>o.index>r.index?o:r,{index:0,p:e._start}).p;if(s)for(;s.right;)s=s.right;return Xe(i,e,s,t)},Yi=(i,e,t,n)=>{if(n===0)return;const s=t,r=n,o=rt(e,t);let c=e._start;for(o!==null&&(c=o.p,t-=o.index);c!==null&&t>0;c=c.right)!c.deleted&&c.countable&&(t<c.length&&oe(i,I(c.id.client,c.id.clock+t)),t-=c.length);for(;n>0&&c!==null;)c.deleted||(n<c.length&&oe(i,I(c.id.client,c.id.clock+n)),c.delete(i),n-=c.length),c=c.right;if(n>0)throw Hi();e._searchMarker&&Ve(e._searchMarker,s,-r+n)},Ze=(i,e,t)=>{const n=e._map.get(t);n!==void 0&&n.delete(i)},Ft=(i,e,t,n)=>{const s=e._map.get(t)||null,r=i.doc,o=r.clientID;let c;if(n==null)c=new Se([n]);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:c=new Se([n]);break;case Uint8Array:c=new ct(n);break;case ke:c=new lt(n);break;default:if(n instanceof N)c=new ce(n);else throw new Error("Unexpected content type")}new U(I(o,B(r.store,o)),s,s&&s.lastId,null,null,e,t,c).integrate(i,0)},Wt=(i,e)=>{var n;(n=i.doc)!=null||j();const t=i._map.get(e);return t!==void 0&&!t.deleted?t.content.getContent()[t.length-1]:void 0},Xi=i=>{var t;const e={};return(t=i.doc)!=null||j(),i._map.forEach((n,s)=>{n.deleted||(e[s]=n.content.getContent()[n.length-1])}),e},Zi=(i,e)=>{var n;(n=i.doc)!=null||j();const t=i._map.get(e);return t!==void 0&&!t.deleted},rr=(i,e)=>{const t={};return i._map.forEach((n,s)=>{let r=n;for(;r!==null&&(!e.sv.has(r.id.client)||r.id.clock>=(e.sv.get(r.id.client)||0));)r=r.left;r!==null&&de(r,e)&&(t[s]=r.content.getContent()[r.length-1])}),t},Fe=i=>{var e;return(e=i.doc)!=null||j(),Ds(i._map.entries(),t=>!t[1].deleted)};class or extends st{}class Ae extends N{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(e){const t=new Ae;return t.push(e),t}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Ae}clone(){const e=new Ae;return e.insert(0,this.toArray().map(t=>t instanceof N?t.clone():t)),e}get length(){var e;return(e=this.doc)!=null||j(),this._length}_callObserver(e,t){super._callObserver(e,t),ot(this,e,new or(this,e))}insert(e,t){this.doc!==null?v(this.doc,n=>{zi(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){this.doc!==null?v(this.doc,t=>{sr(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc!==null?v(this.doc,n=>{Yi(n,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return qi(this,e)}toArray(){return Ji(this)}slice(e=0,t=this.length){return Ki(this,e,t)}toJSON(){return this.map(e=>e instanceof N?e.toJSON():e)}map(e){return Gi(this,e)}forEach(e){Ue(this,e)}[Symbol.iterator](){return nr(this)}_write(e){e.writeTypeRef(_r)}}class cr extends st{constructor(e,t,n){super(e,t),this.keysChanged=n}}class Qe extends N{constructor(e){super(),this._prelimContent=null,e===void 0?this._prelimContent=new Map:this._prelimContent=new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((n,s)=>{this.set(s,n)}),this._prelimContent=null}_copy(){return new Qe}clone(){const e=new Qe;return this.forEach((t,n)=>{e.set(n,t instanceof N?t.clone():t)}),e}_callObserver(e,t){ot(this,e,new cr(this,e,t))}toJSON(){var t;(t=this.doc)!=null||j();const e={};return this._map.forEach((n,s)=>{if(!n.deleted){const r=n.content.getContent()[n.length-1];e[s]=r instanceof N?r.toJSON():r}}),e}get size(){return[...Fe(this)].length}keys(){return mt(Fe(this),e=>e[0])}values(){return mt(Fe(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return mt(Fe(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){var t;(t=this.doc)!=null||j(),this._map.forEach((n,s)=>{n.deleted||e(n.content.getContent()[n.length-1],s,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc!==null?v(this.doc,t=>{Ze(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return this.doc!==null?v(this.doc,n=>{Ft(n,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return Wt(this,e)}has(e){return Zi(this,e)}clear(){this.doc!==null?v(this.doc,e=>{this.forEach(function(t,n,s){Ze(e,s,n)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(mr)}}const se=(i,e)=>i===e||typeof i=="object"&&typeof e=="object"&&i&&e&&ps(i,e);class At{constructor(e,t,n,s){this.left=e,this.right=t,this.index=n,this.currentAttributes=s}forward(){switch(this.right===null&&ue(),this.right.content.constructor){case M:this.right.deleted||ve(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}}const hi=(i,e,t)=>{for(;e.right!==null&&t>0;){switch(e.right.content.constructor){case M:e.right.deleted||ve(e.currentAttributes,e.right.content);break;default:e.right.deleted||(t<e.right.length&&oe(i,I(e.right.id.client,e.right.id.clock+t)),e.index+=e.right.length,t-=e.right.length);break}e.left=e.right,e.right=e.right.right}return e},We=(i,e,t,n)=>{const s=new Map,r=n?rt(e,t):null;if(r){const o=new At(r.p.left,r.p,r.index,s);return hi(i,o,t-r.index)}else{const o=new At(null,e._start,0,s);return hi(i,o,t)}},Qi=(i,e,t,n)=>{for(;t.right!==null&&(t.right.deleted===!0||t.right.content.constructor===M&&se(n.get(t.right.content.key),t.right.content.value));)t.right.deleted||n.delete(t.right.content.key),t.forward();const s=i.doc,r=s.clientID;n.forEach((o,c)=>{const l=t.left,h=t.right,u=new U(I(r,B(s.store,r)),l,l&&l.lastId,h,h&&h.id,e,null,new M(c,o));u.integrate(i,0),t.right=u,t.forward()})},ve=(i,e)=>{const{key:t,value:n}=e;n===null?i.delete(t):i.set(t,n)},en=(i,e)=>{var t;for(;i.right!==null;){if(!(i.right.deleted||i.right.content.constructor===M&&se((t=e[i.right.content.key])!=null?t:null,i.right.content.value)))break;i.forward()}},tn=(i,e,t,n)=>{var c;const s=i.doc,r=s.clientID,o=new Map;for(const l in n){const h=n[l],u=(c=t.currentAttributes.get(l))!=null?c:null;if(!se(u,h)){o.set(l,u);const{left:d,right:g}=t;t.right=new U(I(r,B(s.store,r)),d,d&&d.lastId,g,g&&g.id,e,null,new M(l,h)),t.right.integrate(i,0),t.forward()}}return o},bt=(i,e,t,n,s)=>{t.currentAttributes.forEach((g,_)=>{s[_]===void 0&&(s[_]=null)});const r=i.doc,o=r.clientID;en(t,s);const c=tn(i,e,t,s),l=n.constructor===String?new Z(n):n instanceof N?new ce(n):new Ie(n);let{left:h,right:u,index:d}=t;e._searchMarker&&Ve(e._searchMarker,t.index,l.getLength()),u=new U(I(o,B(r.store,o)),h,h&&h.lastId,u,u&&u.id,e,null,l),u.integrate(i,0),t.right=u,t.index=d,t.forward(),Qi(i,e,t,c)},ui=(i,e,t,n,s)=>{const r=i.doc,o=r.clientID;en(t,s);const c=tn(i,e,t,s);e:for(;t.right!==null&&(n>0||c.size>0&&(t.right.deleted||t.right.content.constructor===M));){if(!t.right.deleted)switch(t.right.content.constructor){case M:{const{key:l,value:h}=t.right.content,u=s[l];if(u!==void 0){if(se(u,h))c.delete(l);else{if(n===0)break e;c.set(l,h)}t.right.delete(i)}else t.currentAttributes.set(l,h);break}default:n<t.right.length&&oe(i,I(t.right.id.client,t.right.id.clock+n)),n-=t.right.length;break}t.forward()}if(n>0){let l="";for(;n>0;n--)l+=`
|
|
2
|
+
`;t.right=new U(I(o,B(r.store,o)),t.left,t.left&&t.left.lastId,t.right,t.right&&t.right.id,e,null,new Z(l)),t.right.integrate(i,0),t.forward()}Qi(i,e,t,c)},nn=(i,e,t,n,s)=>{var h,u;let r=e;const o=G();for(;r&&(!r.countable||r.deleted);){if(!r.deleted&&r.content.constructor===M){const d=r.content;o.set(d.key,d)}r=r.right}let c=0,l=!1;for(;e!==r;){if(t===e&&(l=!0),!e.deleted){const d=e.content;switch(d.constructor){case M:{const{key:g,value:_}=d,w=(h=n.get(g))!=null?h:null;(o.get(g)!==d||w===_)&&(e.delete(i),c++,!l&&((u=s.get(g))!=null?u:null)===_&&w!==_&&(w===null?s.delete(g):s.set(g,w))),!l&&!e.deleted&&ve(s,d);break}}}e=e.right}return c},lr=(i,e)=>{for(;e&&e.right&&(e.right.deleted||!e.right.countable);)e=e.right;const t=new Set;for(;e&&(e.deleted||!e.countable);){if(!e.deleted&&e.content.constructor===M){const n=e.content.key;t.has(n)?e.delete(i):t.add(n)}e=e.left}},ar=i=>{let e=0;return v(i.doc,t=>{let n=i._start,s=i._start,r=G();const o=kt(r);for(;s;){if(s.deleted===!1)switch(s.content.constructor){case M:ve(o,s.content);break;default:e+=nn(t,n,s,r,o),r=kt(o),n=s;break}s=s.right}}),e},hr=i=>{const e=new Set,t=i.doc;for(const[n,s]of i.afterState.entries()){const r=i.beforeState.get(n)||0;s!==r&&xi(i,t.store.clients.get(n),r,s,o=>{!o.deleted&&o.content.constructor===M&&o.constructor!==ne&&e.add(o.parent)})}v(t,n=>{Di(i,i.deleteSet,s=>{if(s instanceof ne||!s.parent._hasFormatting||e.has(s.parent))return;const r=s.parent;s.content.constructor===M?e.add(r):lr(n,s)});for(const s of e)ar(s)})},di=(i,e,t)=>{const n=t,s=kt(e.currentAttributes),r=e.right;for(;t>0&&e.right!==null;){if(e.right.deleted===!1)switch(e.right.content.constructor){case ce:case Ie:case Z:t<e.right.length&&oe(i,I(e.right.id.client,e.right.id.clock+t)),t-=e.right.length,e.right.delete(i);break}e.forward()}r&&nn(i,r,e.right,s,e.currentAttributes);const o=(e.left||e.right).parent;return o._searchMarker&&Ve(o._searchMarker,e.index,-n+t),e};class ur extends st{constructor(e,t,n){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,n.forEach(s=>{s===null?this.childListChanged=!0:this.keysChanged.add(s)})}get changes(){if(this._changes===null){const e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){const e=this.target.doc,t=[];v(e,n=>{var _,w,y;const s=new Map,r=new Map;let o=this.target._start,c=null;const l={};let h="",u=0,d=0;const g=()=>{if(c!==null){let b=null;switch(c){case"delete":d>0&&(b={delete:d}),d=0;break;case"insert":(typeof h=="object"||h.length>0)&&(b={insert:h},s.size>0&&(b.attributes={},s.forEach((O,p)=>{O!==null&&(b.attributes[p]=O)}))),h="";break;case"retain":u>0&&(b={retain:u},ds(l)||(b.attributes=as({},l))),u=0;break}b&&t.push(b),c=null}};for(;o!==null;){switch(o.content.constructor){case ce:case Ie:this.adds(o)?this.deletes(o)||(g(),c="insert",h=o.content.getContent()[0],g()):this.deletes(o)?(c!=="delete"&&(g(),c="delete"),d+=1):o.deleted||(c!=="retain"&&(g(),c="retain"),u+=1);break;case Z:this.adds(o)?this.deletes(o)||(c!=="insert"&&(g(),c="insert"),h+=o.content.str):this.deletes(o)?(c!=="delete"&&(g(),c="delete"),d+=o.length):o.deleted||(c!=="retain"&&(g(),c="retain"),u+=o.length);break;case M:{const{key:b,value:O}=o.content;if(this.adds(o)){if(!this.deletes(o)){const p=(_=s.get(b))!=null?_:null;se(p,O)?O!==null&&o.delete(n):(c==="retain"&&g(),se(O,(w=r.get(b))!=null?w:null)?delete l[b]:l[b]=O)}}else if(this.deletes(o)){r.set(b,O);const p=(y=s.get(b))!=null?y:null;se(p,O)||(c==="retain"&&g(),l[b]=p)}else if(!o.deleted){r.set(b,O);const p=l[b];p!==void 0&&(se(p,O)?p!==null&&o.delete(n):(c==="retain"&&g(),O===null?delete l[b]:l[b]=O))}o.deleted||(c==="insert"&&g(),ve(s,o.content));break}}o=o.right}for(g();t.length>0;){const b=t[t.length-1];if(b.retain!==void 0&&b.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}}class et extends N{constructor(e){super(),this._pending=e!==void 0?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){var e;return(e=this.doc)!=null||j(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(n=>n())}catch(n){console.error(n)}this._pending=null}_copy(){return new et}clone(){const e=new et;return e.applyDelta(this.toDelta()),e}_callObserver(e,t){super._callObserver(e,t);const n=new ur(this,e,t);ot(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){var n;(n=this.doc)!=null||j();let e="",t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===Z&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc!==null?v(this.doc,n=>{const s=new At(null,this._start,0,new Map);for(let r=0;r<e.length;r++){const o=e[r];if(o.insert!==void 0){const c=!t&&typeof o.insert=="string"&&r===e.length-1&&s.right===null&&o.insert.slice(-1)===`
|
|
3
|
+
`?o.insert.slice(0,-1):o.insert;(typeof c!="string"||c.length>0)&&bt(n,this,s,c,o.attributes||{})}else o.retain!==void 0?ui(n,this,s,o.retain,o.attributes||{}):o.delete!==void 0&&di(n,s,o.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,n){var d;(d=this.doc)!=null||j();const s=[],r=new Map,o=this.doc;let c="",l=this._start;function h(){if(c.length>0){const g={};let _=!1;r.forEach((y,b)=>{_=!0,g[b]=y});const w={insert:c};_&&(w.attributes=g),s.push(w),c=""}}const u=()=>{for(;l!==null;){if(de(l,e)||t!==void 0&&de(l,t))switch(l.content.constructor){case Z:{const g=r.get("ychange");e!==void 0&&!de(l,e)?(g===void 0||g.user!==l.id.client||g.type!=="removed")&&(h(),r.set("ychange",n?n("removed",l.id):{type:"removed"})):t!==void 0&&!de(l,t)?(g===void 0||g.user!==l.id.client||g.type!=="added")&&(h(),r.set("ychange",n?n("added",l.id):{type:"added"})):g!==void 0&&(h(),r.delete("ychange")),c+=l.content.str;break}case ce:case Ie:{h();const g={insert:l.content.getContent()[0]};if(r.size>0){const _={};g.attributes=_,r.forEach((w,y)=>{_[y]=w})}s.push(g);break}case M:de(l,e)&&(h(),ve(r,l.content));break}l=l.right}h()};return e||t?v(o,g=>{e&&Rt(g,e),t&&Rt(g,t),u()},"cleanup"):u(),s}insert(e,t,n){if(t.length<=0)return;const s=this.doc;s!==null?v(s,r=>{const o=We(r,this,e,!n);n||(n={},o.currentAttributes.forEach((c,l)=>{n[l]=c})),bt(r,this,o,t,n)}):this._pending.push(()=>this.insert(e,t,n))}insertEmbed(e,t,n){const s=this.doc;s!==null?v(s,r=>{const o=We(r,this,e,!n);bt(r,this,o,t,n||{})}):this._pending.push(()=>this.insertEmbed(e,t,n||{}))}delete(e,t){if(t===0)return;const n=this.doc;n!==null?v(n,s=>{di(s,We(s,this,e,!0),t)}):this._pending.push(()=>this.delete(e,t))}format(e,t,n){if(t===0)return;const s=this.doc;s!==null?v(s,r=>{const o=We(r,this,e,!1);o.right!==null&&ui(r,this,o,t,n)}):this._pending.push(()=>this.format(e,t,n))}removeAttribute(e){this.doc!==null?v(this.doc,t=>{Ze(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){this.doc!==null?v(this.doc,n=>{Ft(n,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return Wt(this,e)}getAttributes(){return Xi(this)}_write(e){e.writeTypeRef(wr)}}class yt{constructor(e,t=()=>!0){var n;this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,(n=e.doc)!=null||j()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===je||t.constructor===ye)&&t._start!==null)e=t._start;else for(;e!==null;)if(e.right!==null){e=e.right;break}else e.parent===this._root?e=null:e=e.parent._item;while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}}class ye extends N{constructor(){super(),this._prelimContent=[]}get firstChild(){const e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new ye}clone(){const e=new ye;return e.insert(0,this.toArray().map(t=>t instanceof N?t.clone():t)),e}get length(){var e;return(e=this.doc)!=null||j(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new yt(this,e)}querySelector(e){e=e.toUpperCase();const n=new yt(this,s=>s.nodeName&&s.nodeName.toUpperCase()===e).next();return n.done?null:n.value}querySelectorAll(e){return e=e.toUpperCase(),we(new yt(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){ot(this,e,new dr(this,t,e))}toString(){return Gi(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},n){const s=e.createDocumentFragment();return n!==void 0&&n._createAssociation(s,this),Ue(this,r=>{s.insertBefore(r.toDOM(e,t,n),null)}),s}insert(e,t){this.doc!==null?v(this.doc,n=>{zi(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(this.doc!==null)v(this.doc,n=>{const s=e&&e instanceof N?e._item:e;Xe(n,this,s,t)});else{const n=this._prelimContent,s=e===null?0:n.findIndex(r=>r===e)+1;if(s===0&&e!==null)throw be("Reference item not found");n.splice(s,0,...t)}}delete(e,t=1){this.doc!==null?v(this.doc,n=>{Yi(n,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return Ji(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return qi(this,e)}slice(e=0,t=this.length){return Ki(this,e,t)}forEach(e){Ue(this,e)}_write(e){e.writeTypeRef(yr)}}class je extends ye{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((n,s)=>{this.setAttribute(s,n)}),this._prelimAttrs=null}_copy(){return new je(this.nodeName)}clone(){const e=new je(this.nodeName),t=this.getAttributes();return us(t,(n,s)=>{typeof n=="string"&&e.setAttribute(s,n)}),e.insert(0,this.toArray().map(n=>n instanceof N?n.clone():n)),e}toString(){const e=this.getAttributes(),t=[],n=[];for(const c in e)n.push(c);n.sort();const s=n.length;for(let c=0;c<s;c++){const l=n[c];t.push(l+'="'+e[l]+'"')}const r=this.nodeName.toLocaleLowerCase(),o=t.length>0?" "+t.join(" "):"";return`<${r}${o}>${super.toString()}</${r}>`}removeAttribute(e){this.doc!==null?v(this.doc,t=>{Ze(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){this.doc!==null?v(this.doc,n=>{Ft(n,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return Wt(this,e)}hasAttribute(e){return Zi(this,e)}getAttributes(e){return e?rr(this,e):Xi(this)}toDOM(e=document,t={},n){const s=e.createElement(this.nodeName),r=this.getAttributes();for(const o in r){const c=r[o];typeof c=="string"&&s.setAttribute(o,c)}return Ue(this,o=>{s.appendChild(o.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(s,this),s}_write(e){e.writeTypeRef(br),e.writeKey(this.nodeName)}}class dr extends st{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}}class sn{constructor(e,t){this.id=e,this.length=t}get deleted(){throw q()}mergeWith(e){return!1}write(e,t,n){throw q()}integrate(e,t){throw q()}}const fr=0;class ne extends sn{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor!==e.constructor?!1:(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),$i(e.doc.store,this)}write(e,t){e.writeInfo(fr),e.writeLen(this.length-t)}getMissing(e,t){return null}}class ct{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new ct(this.content)}splice(e){throw q()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}}class tt{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new tt(this.len)}splice(e){const t=new tt(this.len-e);return this.len=e,t}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){Ui(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}}const gr=(i,e)=>new ke({guid:i,...e,shouldLoad:e.shouldLoad||e.autoLoad||!1});class lt{constructor(e){e._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=e;const t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new lt(gr(this.doc.guid,this.opts))}splice(e){throw q()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}}class Ie{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new Ie(this.embed)}splice(e){throw q()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}}class M{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new M(this.key,this.value)}splice(e){throw q()}mergeWith(e){return!1}integrate(e,t){const n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}}const pr=Ye("node_env")==="development";class Se{constructor(e){this.arr=e,pr&&vi(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Se(this.arr)}splice(e){const t=new Se(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){const n=this.arr.length;e.writeLen(n-t);for(let s=t;s<n;s++){const r=this.arr[s];e.writeAny(r)}}getRef(){return 8}}class Z{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new Z(this.str)}splice(e){const t=new Z(this.str.slice(e));this.str=this.str.slice(0,e);const n=this.str.charCodeAt(e-1);return n>=55296&&n<=56319&&(this.str=this.str.slice(0,e-1)+"�",t.str="�"+t.str.slice(1)),t}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}}const _r=0,mr=1,wr=2,br=3,yr=4;class ce{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new ce(this.type._copy())}splice(e){throw q()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(n=>{n.deleted?n.id.clock<(e.beforeState.get(n.id.client)||0)&&e._mergeStructs.push(n):n.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(n=>{for(;n!==null;)n.gc(e,!0),n=n.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}}const rn=(i,e,t)=>{const{client:n,clock:s}=e.id,r=new U(I(n,s+t),e,I(n,s+t-1),e.right,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t));return e.deleted&&r.markDeleted(),e.keep&&(r.keep=!0),e.redone!==null&&(r.redone=I(e.redone.client,e.redone.clock+t)),e.right=r,r.right!==null&&(r.right.left=r),i._mergeStructs.push(r),r.parentSub!==null&&r.right===null&&r.parent._map.set(r.parentSub,r),e.length=t,r};class U extends sn{constructor(e,t,n,s,r,o,c,l){super(e,l.getLength()),this.origin=n,this.left=t,this.right=s,this.rightOrigin=r,this.parent=o,this.parentSub=c,this.redone=null,this.content=l,this.info=this.content.isCountable()?qt:0}set marker(e){(this.info>)>0!==e&&(this.info^=gt)}get marker(){return(this.info>)>0}get keep(){return(this.info&Gt)>0}set keep(e){this.keep!==e&&(this.info^=Gt)}get countable(){return(this.info&qt)>0}get deleted(){return(this.info&ft)>0}set deleted(e){this.deleted!==e&&(this.info^=ft)}markDeleted(){this.info|=ft}getMissing(e,t){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=B(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=B(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Je&&this.id.client!==this.parent.client&&this.parent.clock>=B(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=oi(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=oe(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===ne||this.right&&this.right.constructor===ne)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===U&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===U&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Je){const n=wt(t,this.parent);n.constructor===ne?this.parent=null:this.parent=n.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=oi(e,e.doc.store,I(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let n=this.left,s;if(n!==null)s=n.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;const r=new Set,o=new Set;for(;s!==null&&s!==this.right;){if(o.add(s),r.add(s),xe(this.origin,s.origin)){if(s.id.client<this.id.client)n=s,r.clear();else if(xe(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&o.has(wt(e.doc.store,s.origin)))r.has(wt(e.doc.store,s.origin))||(n=s,r.clear());else break;s=s.right}this.left=n}if(this.left!==null){const n=this.left.right;this.right=n,this.left.right=this}else{let n;if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start,this.parent._start=this;this.right=n}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(e)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),$i(e.doc.store,this),this.content.integrate(e,this),li(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new ne(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;e!==null&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;e!==null&&e.deleted;)e=e.left;return e}get lastId(){return this.length===1?this.id:I(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&xe(e.origin,this.lastId)&&this.right===e&&xe(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&this.redone===null&&e.redone===null&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){const t=this.parent._searchMarker;return t&&t.forEach(n=>{n.p===e&&(n.p=this,!this.deleted&&this.countable&&(n.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){const t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),Ui(e.deleteSet,this.id.client,this.id.clock,this.length),li(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw ue();this.content.gc(e),t?zs(e,this,new ne(this.id,this.length)):this.content=new tt(this.length)}write(e,t){const n=t>0?I(this.id.client,this.id.clock+t-1):this.origin,s=this.rightOrigin,r=this.parentSub,o=this.content.getRef()&jn|(n===null?0:ze)|(s===null?0:Ci)|(r===null?0:Un);if(e.writeInfo(o),n!==null&&e.writeLeftID(n),s!==null&&e.writeRightID(s),n===null&&s===null){const c=this.parent;if(c._item!==void 0){const l=c._item;if(l===null){const h=Gs(c);e.writeParentInfo(!0),e.writeString(h)}else e.writeParentInfo(!1),e.writeLeftID(l.id)}else c.constructor===String?(e.writeParentInfo(!0),e.writeString(c)):c.constructor===Je?(e.writeParentInfo(!1),e.writeLeftID(c)):ue();r!==null&&e.writeString(r)}this.content.write(e,t)}}const on=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:{},cn="__ $YJS$ __";on[cn]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");on[cn]=!0;const Re=i=>Promise.reject(new Error("unimplemented method GetVoiceSign")),St=(i,e={},t=[])=>({command:i,front_request_id:Le(),data:{...e,to_user_ids:Array.isArray(t)?t:[t]}}),ln=()=>{var i,e;window!=null&&window.__Realsee_Live__&&((e=(i=window==null?void 0:window.__Realsee_Live__)==null?void 0:i.dispose)==null||e.call(i),window.__Realsee_Live__=null)};class an extends pe{constructor(t){super();a(this,"_options",{});a(this,"keyframes",new pe);a(this,"_yDoc");a(this,"_buildInData");a(this,"_initializeKeyframesObservers",()=>{this._yDoc.getMap("keyframes").observe(this._handleKeyframesChange)});a(this,"_handleKeyframesChange",t=>{var o;const{transaction:n,target:s,changes:r}=t;if(s===this._buildInData.keyframes)if(n.origin.triggerUserId===((o=this.selfInfo)==null?void 0:o.id)){const c=St($.KeyframeSync,this.snapshot,void 0);try{this._controller.sendMessage(c)}catch(l){m.error("Failed to send keyframe sync message:",l)}}else r.keys.forEach((c,l)=>{const h=c.oldValue,u=this.getFramesByKey(l),d=n.origin.frontRequestId;this.keyframes.emit(l,u,h,d)}),r.keys.size!==0&&this.emit("keyframes",this.snapshot,n.origin.frontRequestId)});a(this,"getFramesByKey",t=>this.snapshot[t]);a(this,"sendKeyframe",(t,n)=>{var s;return this.state!==V.OPEN?(m.warn("Attempted to send keyframe while connection is not open"),!1):(this._yDoc.transact(()=>{this._buildInData.keyframes.set(t,n)},{triggerUserId:(s=this.selfInfo)==null?void 0:s.id,frontRequestId:""}),!0)});a(this,"_controller",new An);a(this,"_initializeOptions",t=>{var n;this._options=Object.assign({initialMicroStatus:ie.OPEN},t),this._options.jsBridge=this._initializeJsBridge(t),this._options.getVoiceSign=(n=t.getVoiceSign)!=null?n:Re,this._options.autoPlayConfirm=t.autoPlayConfirm,this._options.rtc=this._initializeRTC(t)});a(this,"_initializeJsBridge",t=>{if(t.jsBridge)return t.jsBridge;if(t.useBuiltInJsBridge)return new mn});a(this,"_initializeRTC",t=>{if(t.rtc)return t.rtc;if(t.rtcType)return this._createBuiltInRTC(t);if(t.useBuiltInRTC)return this._createDefaultRTC(t)});a(this,"_createBuiltInRTC",t=>{var n;if(!t.getVoiceSign){m.error("GetVoiceSign method must be passed when using built-in RTC instances");return}switch(t.rtcType){case re.RealseeVRWebViewRTC:return this._createVRWebViewRTC();case re.RealseeBrowserChimeRTC:return new Et({getVoiceSign:(n=this._options.getVoiceSign)!=null?n:Re,logLevel:t.__debug__?0:1});case re.RealseeBrowserRTC:return this._createBrowserRTC();default:m.error("unknown built-in RTC type");return}});a(this,"_createVRWebViewRTC",()=>{var t;if(this._options.jsBridge)return new gi({jsBridge:this._options.jsBridge,getVoiceSign:(t=this._options.getVoiceSign)!=null?t:Re});m.error("JsBridge instance must be passed when using built-in VRWebViewRTC instances")});a(this,"_createBrowserRTC",()=>{var t;if(!this._options.autoPlayConfirm){m.error("autoPlayConfirm method must be passed when using built-in RealseeBrowserRTC instances");return}return new fi({getVoiceSign:(t=this._options.getVoiceSign)!=null?t:Re,autoPlayConfirm:this._options.autoPlayConfirm})});a(this,"_createDefaultRTC",t=>{var s;const n=(s=this._options.getVoiceSign)!=null?s:Re;return!this._options.jsBridge||!Jt&&!Kt?t.builtInRTCType===Lt.RealseeXChimeRTC?new Et({getVoiceSign:n}):this._createBrowserRTC():Jt&&(Sn||Cn)||Kt?this._createVRWebViewRTC():this._createBrowserRTC()});a(this,"_autoConnect",()=>{this._options.url&&this._options.getTicket&&this.connect()});a(this,"_debugSetup",()=>{this._options.__debug__&&Object.assign(window,{$liveController:this._controller,$live:this})});a(this,"_addLiveControllerEventListeners",()=>{this._controller.on("stateChange",this._handleStateChange),this._controller.on("message",this._handleMessage)});a(this,"_removeLiveControllerEventListeners",()=>{this._controller.off("stateChange",this._handleStateChange),this._controller.off("message",this._handleMessage)});a(this,"_handleStateChange",(t,n)=>{m.info(`State changed from ${n} to ${t}`),this.emit("stateChange",t,n)});a(this,"_handleMessage",async t=>{var n,s,r,o,c,l,h,u,d;if(m.debug("Received message:",t),typeof t=="object"){const{command:g,data:_={},frontRequestId:w,code:y,message:b,triggerUserId:O}=t;if(y==="SUCCESS")switch(g){case $.SelfUserInfo:{const p=_;Rn(this.selfInfo,p,{deep:!0})||(this._buildInData.selfInfo=p,this.emit("selfInfoUpdate",this._buildInData.selfInfo,w));break}case $.RoomInfo:{const p=_;this._buildInData.roomInfo=Object.assign({},p);const W=p.last_frame||{};this._yDoc.transact(()=>{for(const f in W)this._buildInData.keyframes.set(f,W[f])},{triggerUserId:"readyKeyframeSync",frontRequestId:w}),this.emit("readyKeyframeSync",p.last_frame||{});break}case $.RTCInfo:{m.info("RTC info updated:",_);const{voice_id:p,type:W}=_;if(this._buildInData.rtcInfo={voiceId:p,type:W},(n=this.$RTC)!=null&&n.joined)m.warn("已加入语音房间,无需重复加入!");else if(await((o=this.$RTC)==null?void 0:o.join({voiceId:p,userId:((s=this.selfInfo)==null?void 0:s.id)||"",roomId:(r=this.roomInfo)==null?void 0:r.info.room_code,type:W}))){const C=(c=this._options.initialMicroStatus)!=null?c:ie.OPEN;await this.toggleMicro(C===ie.OPEN)}else m.error("加入语音房间失败");break}case $.UserList:{const p=_;this._buildInData.userList=p,this.emit("userListUpdate",this.userList,w);break}case $.CustomEvent:{const p=_;this.emit("broadcast",p,w);break}case $.KeyframeSync:{const p=_;if(O===((l=this.selfInfo)==null?void 0:l.id))return;this._yDoc.transact(()=>{for(const W in p)this._buildInData.keyframes.set(W,p[W])},{triggerUserId:O,frontRequestId:w});break}case $.BuiltinMsg:{const p=_;this.emit("builtinEvent",p),p.event_type===F.UserChange&&this.emit("userChange",p),p.event_type===F.RoomChange&&this.emit("roomChange",p),p.event_type===F.UserChange&&p.action===J.UserMicroStatus&&p.to_user_ids.includes((u=(h=this.selfInfo)==null?void 0:h.id)!=null?u:"")&&await((d=this.$RTC)==null?void 0:d.toggleMicro(p.data.status===ie.OPEN)),p.event_type===F.RoomChange&&p.action===J.RoomClose&&await this._exit();break}case $.UserKickOut:{this.emit("kickOut");break}default:m.warn("Unknown command received:",g)}else m.error("Error in message:",b),this.emit("error",t)}});a(this,"_clearLiveData",()=>{this._buildInData.keyframes.clear(),this._buildInData={keyframes:this._yDoc.getMap("keyframes")}});a(this,"connect",async(t={})=>{var s,r,o,c;if(m.info("Attempting to connect with options:",t),this._options.url=(r=(s=t.url)!=null?s:this._options.url)!=null?r:"",this._options.getTicket=(o=t.getTicket)!=null?o:this._options.getTicket,this._options.initialMicroStatus=(c=t.rtcMicStatus)!=null?c:this._options.initialMicroStatus,!/^wss?:\/\//.test(this._options.url)||typeof this._options.getTicket!="function")return new Error("Invalid connection parameters");if(this._options.rtc&&!await this._options.rtc.detectMicro())return new Error("Failed to obtain microphone authorization");const n=this.state;if(n===V.CONNECTING||n===V.OPEN)if(t.force)await this._controller.close("force close by connect").catch(console.warn);else return new Error("已有Live实例正在连接中,请勿重复连接!");this._clearLiveData();try{const l=await this._options.getTicket(),h=yn(this._options.url,{ticket:l,force:+!!t.force});return this._controller.open(h),m.info("Connection established successfully"),!0}catch(l){return m.error("Failed to connect:",l),new Error("Failed to connect")}});a(this,"_exit",async()=>{var t;this._clearLiveData();try{await((t=this.$RTC)==null?void 0:t.quit())}catch(n){m.warn(n)}return this.state!==V.OPEN?!0:await this._controller.close()});a(this,"exit",async()=>this.close());a(this,"close",async()=>{var t;await this._controller.readyClose();try{await((t=this.$RTC)==null?void 0:t.quit())}catch(n){m.warn(n)}await this.updateStatus(F.RoomChange,J.RoomClose,{})});a(this,"dispose",async()=>{this._removeLiveControllerEventListeners();try{this._yDoc.getMap("keyframes").unobserve(this._handleKeyframesChange),this._yDoc.destroy()}catch(t){m.warn(t)}return this._clearLiveData(),await this._controller.dispose()});a(this,"setSelfInfo",async t=>await this.updateStatus(F.UserChange,J.UserInfo,t));a(this,"broadcast",(t,n,s)=>this.state!==V.OPEN?!1:new Promise((r,o)=>{const c=St($.CustomEvent,t,n),l=c.front_request_id,h=s?setTimeout(()=>{o(new Error("RESPONSE TIMEOUT")),this.off("broadcast",u)},s):void 0,u=(d,g)=>{g===l&&(h&&clearTimeout(h),this.off("broadcast",u),r(d))};this.on("broadcast",u);try{this._controller.sendMessage(c)}catch(d){o(d)}}));a(this,"toggleMicro",async t=>{var s,r,o;if(!((r=(s=this.selfInfo)==null?void 0:s.permission)!=null&&r.control_own_micro))return!1;const n=await((o=this.$RTC)==null?void 0:o.toggleMicro(t));return n&&await this.updateStatus(F.UserChange,J.UserMicroStatus,{status:t?ie.OPEN:ie.CLOSE},[]),n});a(this,"forbidMicro",async(t,n)=>{var s,r;return typeof this._options.canForbidUserMicro=="function"&&!this._options.canForbidUserMicro(n)||!((r=(s=this.selfInfo)==null?void 0:s.permission)!=null&&r.control_other_micro)?!1:await this.updateStatus(F.UserChange,J.UserMicroStatus,{status:t},n)});a(this,"forbidSync",async(t,n)=>{var s,r;return typeof this._options.canForbidUserSync=="function"&&!this._options.canForbidUserSync(n)||!((r=(s=this.selfInfo)==null?void 0:s.permission)!=null&&r.control_other_sync)?!1:await this.updateStatus(F.UserChange,J.UserPermission,{sync_frame:t},n)});a(this,"kick",async t=>{var n,s;return typeof this._options.canForbidUserKick=="function"&&!this._options.canForbidUserKick(t)||!((s=(n=this.selfInfo)==null?void 0:n.permission)!=null&&s.change_other_status)?!1:await this.updateStatus(F.UserChange,J.UserStatus,{status:"KICK_OUT"},t)});a(this,"getSnapshotForKey",t=>this.snapshot[t]);m.info("Initializing Live instance with options:",t),this._addLiveControllerEventListeners(),this._yDoc=new ke({guid:Le()}),this._buildInData={keyframes:this._yDoc.getMap("keyframes")},this._initializeKeyframesObservers(),this._initializeOptions(t),this._autoConnect(),this._debugSetup()}get options(){return Object.freeze(this._options||{})}get state(){return this._controller.state}get readyState(){return this._controller.state}get url(){return this.options.url}get $RTC(){return this._options.rtc}get jsBridge(){return this._options.jsBridge}get snapshot(){return this._buildInData.keyframes.toJSON()}get selfInfo(){return this._buildInData.selfInfo}get userList(){return this._buildInData.userList||[]}get roomInfo(){return this._buildInData.roomInfo}async updateStatus(t,n,s,r){if(this.state!==V.OPEN)return!1;const o=Object.assign({event_type:t,action:n},{data:s}),c=St($.BuiltinMsg,o,r);try{return this._controller.sendMessage(c),!0}catch(l){return m.error(l),!1}}}const hn=i=>(ln(),new an(i));function Sr(i){const e=S.createContext(null),t=hn(i),n=t.jsBridge,s=f=>S.createElement(e.Provider,{value:t},f.children),r=()=>{const f=S.useContext(e);if(!f)throw new Error("LiveProvider never found.");return f},o=()=>t,c=()=>t.$RTC,l=()=>c(),h=()=>async f=>await t.connect(f);function u(f,C,A=[]){const E=r(),R=[E,f,...A],D=()=>E.keyframes.off(f,C);return S.useEffect(()=>(E.keyframes.on(f,C),D),R),D}function d(){const f=r(),C=S.useCallback(async T=>{await f.connect(T)},[f]),A=S.useCallback(T=>{f.toggleMicro(T)},[f]),E=S.useCallback(async(T,H,ht=0)=>{await f.broadcast(T,H,ht)},[f]),R=S.useCallback(async()=>{await f.exit()},[f]),D=S.useCallback(async T=>{await f.kick(T)},[f]),P=S.useCallback(async(T,H=[])=>{await f.forbidMicro(T,H)},[f]),le=S.useCallback((T,H=[])=>{f.forbidSync(T,H)},[f]),at=S.useCallback(T=>f.getFramesByKey(T),[f]),un=S.useCallback((T,H)=>{f.sendKeyframe(T,H)},[f]),dn=S.useCallback(T=>{f.setSelfInfo(T)},[f]),fn=S.useCallback((T,H,ht,gn)=>{f.updateStatus(T,H,ht,gn)},[f]);return{connect:C,broadcast:E,exit:R,kick:D,toggleMicro:A,forbidMicro:P,forbidSync:le,sendKeyframe:un,getFramesByKey:at,setSelfInfo:dn,updateStatus:fn}}function g(f){const C=r(),[A,E]=S.useState(C.getFramesByKey(f));S.useEffect(()=>{const D=at=>E(at),P=f,le=D;return C.keyframes.on(P,le),()=>C.keyframes.off(P,le)},[C]);const R=S.useCallback(D=>C.sendKeyframe(f,D),[C]);return[A,R]}function _(f,C,A=[]){const E=r(),R=()=>E.off(f,C),D=[E,f,...A];return S.useEffect(()=>(E.on(f,C),R),D),R}function w(){const f=r(),[C,A]=S.useState(f.state);return S.useEffect(()=>{const E=R=>A(R);return f.on("stateChange",E),()=>f.off("stateChange",E)},[f]),C}function y(){const f=r();return{join:P=>f.$RTC.join(P),quit:()=>f.$RTC.quit(),shock:()=>{var P,le;return(le=(P=f.$RTC).shock)==null?void 0:le.call(P)},toggleMicro:P=>f.$RTC.toggleMicro(P),detectMicro:()=>f.$RTC.detectMicro()}}function b(f,C,A=[]){const E=r(),R=()=>E.$RTC.off(f,C),D=[E,f,...A];return S.useEffect(()=>(E.$RTC.on(f,C),R),D),R}function O(){const f=r(),[C,A]=S.useState(f.selfInfo||{}),E=D=>A(D);S.useEffect(()=>(f.on("selfInfoUpdate",E),()=>f.off("selfInfoUpdate",E)),[f]);const R=S.useCallback(async D=>await f.setSelfInfo(D),[f]);return[C,R]}function p(){const f=r(),[C,A]=S.useState(f.snapshot);return S.useEffect(()=>{const E=R=>A(R);return f.on("keyframes",E),()=>f.off("keyframes",E)},[f]),C}function W(){const f=r(),[C,A]=S.useState(f.userList),E=R=>A(R);return S.useEffect(()=>(f.on("userListUpdate",E),()=>f.off("userListUpdate",E)),[f]),C}return{live:t,jsBridge:n,LiveProvider:s,unsafe__useLiveInstance:o,unsafe__useRTCInstance:l,useConnect:h,useKeyframe:g,useKeyframeUpdateCallback:u,useLiveAction:d,useLiveEventCallback:_,useLiveState:w,useRTCAction:y,useRTCEventCallback:b,useSelfInfo:O,useKeyframesSnapshot:p,useUserList:W}}const Ct=globalThis.__REALSEE_LIVE_BADGE_LOG__;(Ct==null||Ct)&&console.log("%c@realsee/live@0.7.8 (8/10/2026, 3:54:22 PM)","background: linear-gradient(to right, #1890ff, #52c41a); color: white; padding: 3px 6px; border-radius: 4px; font-weight: bold; text-shadow: 0 1px 0 rgba(0,0,0,0.2);");exports.BrowserRTC=fi;exports.BrowserRTC4Chime=Et;exports.BuiltInRTCType=Lt;exports.BuiltinActionType=J;exports.BuiltinEventType=F;exports.Command=$;exports.CoreRTC=it;exports.Live=an;exports.LiveState=V;exports.MemUserStatus=_i;exports.MicroStatus=ie;exports.RTCJoinedInfoCodeEnum=ae;exports.RTCType=re;exports.Subscribe=pe;exports.UserStatus=pi;exports.VRWebViewRTC=gi;exports.WebSocketCloseError=wi;exports.WebSocketErrorType=mi;exports.WebSocketState=qe;exports._clearLiveInstanceIfNeed=ln;exports.createLive=hn;exports.createLiveReact=Sr;exports.parseLiveMsg=bn;exports.parseWSClsErr=bi;
|