liveroom-client-element 0.0.9 → 0.0.11

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/main.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";const i=t=>Object.freeze(Object.defineProperty({__proto__:null,default:t},Symbol.toStringTag,{value:"Module"}));let c,e;l();m();const a="liveroom-client-element";async function l(){const o=new URLSearchParams(window.location.search).get("_liveroom"),n=document.querySelector("script[src*='liveroom-client-element.js']")||document.querySelector("script[src*='client/dist/main.js']"),s=n==null?void 0:n.getAttribute("data-roomid"),r=o||s;r&&r!=c&&(c=r,e&&(e.remove(),e=void 0),await u(c))}function m(){window.addEventListener("popstate",l)}async function u(t){if(!t)return!1;await Promise.resolve().then(()=>i(require("./liveroom-client-element.cjs"))),console.log("[Liveroom] Installed successfully");const o=document.getElementsByTagName("body")[0];return e=document.createElement(a),e.setAttribute("url","ws://localhost:4000/client_socket"),e.setAttribute("room_id",t),o.appendChild(e),console.log("[Liveroom] Injected successfully"),!0}
package/dist/main.js ADDED
@@ -0,0 +1,22 @@
1
+ let c, e;
2
+ s();
3
+ a();
4
+ const l = "liveroom-client-element";
5
+ async function s() {
6
+ const o = new URLSearchParams(window.location.search).get("_liveroom"), n = (
7
+ // prod
8
+ document.querySelector("script[src*='liveroom-client-element.js']") || // local dev
9
+ document.querySelector("script[src*='client/dist/main.js']")
10
+ ), i = n == null ? void 0 : n.getAttribute("data-roomid"), r = o || i;
11
+ r && r != c && (c = r, e && (e.remove(), e = void 0), await m(c));
12
+ }
13
+ function a() {
14
+ window.addEventListener("popstate", s);
15
+ }
16
+ async function m(t) {
17
+ if (!t)
18
+ return !1;
19
+ await import("./liveroom-client-element.js"), console.log("[Liveroom] Installed successfully");
20
+ const o = document.getElementsByTagName("body")[0];
21
+ return e = document.createElement(l), e.setAttribute("url", "ws://localhost:4000/client_socket"), e.setAttribute("room_id", t), o.appendChild(e), console.log("[Liveroom] Injected successfully"), !0;
22
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "liveroom-client-element",
3
3
  "private": false,
4
- "version": "0.0.9",
4
+ "version": "0.0.11",
5
5
  "type": "module",
6
6
  "main": "./dist/liveroom-client-element.umd.cjs",
7
7
  "module": "./dist/liveroom-client-element.js",
@@ -10,6 +10,10 @@
10
10
  ],
11
11
  "exports": {
12
12
  ".": {
13
+ "import": "./dist/main.js",
14
+ "require": "./dist/main.umd.cjs"
15
+ },
16
+ "./liveroom-client-element": {
13
17
  "import": "./dist/liveroom-client-element.js",
14
18
  "require": "./dist/liveroom-client-element.umd.cjs"
15
19
  }
@@ -19,11 +23,12 @@
19
23
  "build": "vite build",
20
24
  "preview": "vite preview",
21
25
  "format": "prettier --write .",
22
- "lint": "prettier . --check",
23
- "check": "svelte-check --tsconfig ./tsconfig.json"
26
+ "check-format": "prettier . --check",
27
+ "check": "svelte-check --tsconfig ./tsconfig.json",
28
+ "lint": "npm run check-format && npm run check"
24
29
  },
25
30
  "dependencies": {
26
- "phx-live-state": "^0.9.2"
31
+ "phx-live-state": "^0.9.4"
27
32
  },
28
33
  "devDependencies": {
29
34
  "@sveltejs/vite-plugin-svelte": "^2.4.2",
@@ -1,14 +0,0 @@
1
- (function(P,U){typeof exports=="object"&&typeof module<"u"?module.exports=U():typeof define=="function"&&define.amd?define(U):(P=typeof globalThis<"u"?globalThis:P||self,P.LiveroomClientElement=U())})(this,function(){"use strict";var nn=Object.defineProperty;var rn=(P,U,q)=>U in P?nn(P,U,{enumerable:!0,configurable:!0,writable:!0,value:q}):P[U]=q;var f=(P,U,q)=>(rn(P,typeof U!="symbol"?U+"":U,q),q);function P(){}function U(s){return s()}function q(){return Object.create(null)}function ct(s){s.forEach(U)}function Vt(s){return typeof s=="function"}function ve(s,n){return s!=s?n==n:s!==n||s&&typeof s=="object"||typeof s=="function"}function ye(s){return Object.keys(s).length===0}function W(s,n){s.appendChild(n)}function me(s,n,t){const e=we(s);if(!e.getElementById(n)){const r=K("style");r.id=n,r.textContent=t,_e(e,r)}}function we(s){if(!s)return document;const n=s.getRootNode?s.getRootNode():s.ownerDocument;return n&&n.host?n:s.ownerDocument}function _e(s,n){return W(s.head||s,n),n.sheet}function _t(s,n,t){s.insertBefore(n,t||null)}function lt(s){s.parentNode&&s.parentNode.removeChild(s)}function K(s){return document.createElement(s)}function Bt(s){return document.createElementNS("http://www.w3.org/2000/svg",s)}function zt(s){return document.createTextNode(s)}function Ot(){return zt(" ")}function x(s,n,t){t==null?s.removeAttribute(n):s.getAttribute(n)!==t&&s.setAttribute(n,t)}function be(s){return Array.from(s.childNodes)}function Ee(s,n){n=""+n,s.data!==n&&(s.data=n)}function et(s,n,t,e){t==null?s.style.removeProperty(n):s.style.setProperty(n,t,e?"important":"")}function $e(s){const n={};return s.childNodes.forEach(t=>{n[t.slot||"default"]=!0}),n}let ut;function pt(s){ut=s}function Ft(){if(!ut)throw new Error("Function called outside component initialization");return ut}function Ce(s){Ft().$$.on_mount.push(s)}function ke(s){Ft().$$.on_destroy.push(s)}const st=[],jt=[];let nt=[];const Wt=[],Ae=Promise.resolve();let xt=!1;function Te(){xt||(xt=!0,Ae.then(ft))}function St(s){nt.push(s)}const Mt=new Set;let rt=0;function ft(){if(rt!==0)return;const s=ut;do{try{for(;rt<st.length;){const n=st[rt];rt++,pt(n),Oe(n.$$)}}catch(n){throw st.length=0,rt=0,n}for(pt(null),st.length=0,rt=0;jt.length;)jt.pop()();for(let n=0;n<nt.length;n+=1){const t=nt[n];Mt.has(t)||(Mt.add(t),t())}nt.length=0}while(st.length);for(;Wt.length;)Wt.pop()();xt=!1,Mt.clear(),pt(s)}function Oe(s){if(s.fragment!==null){s.update(),ct(s.before_update);const n=s.dirty;s.dirty=[-1],s.fragment&&s.fragment.p(s.ctx,n),s.after_update.forEach(St)}}function je(s){const n=[],t=[];nt.forEach(e=>s.indexOf(e)===-1?n.push(e):t.push(e)),t.forEach(e=>e()),nt=n}const xe=new Set;function Gt(s,n){s&&s.i&&(xe.delete(s),s.i(n))}function Xt(s){return(s==null?void 0:s.length)!==void 0?s:Array.from(s)}function Se(s,n){s.d(1),n.delete(s.key)}function Me(s,n,t,e,r,i,a,h,l,d,_,b){let O=s.length,j=i.length,S=O;const R={};for(;S--;)R[s[S].key]=S;const M=[],Y=new Map,Z=new Map,tt=[];for(S=j;S--;){const A=b(r,i,S),D=t(A);let B=a.get(D);B?e&&tt.push(()=>B.p(A,n)):(B=d(D,A),B.c()),Y.set(D,M[S]=B),D in R&&Z.set(D,Math.abs(S-R[D]))}const it=new Set,k=new Set;function F(A){Gt(A,1),A.m(h,_),a.set(A.key,A),_=A.first,j--}for(;O&&j;){const A=M[j-1],D=s[O-1],B=A.key,ot=D.key;A===D?(_=A.first,O--,j--):Y.has(ot)?!a.has(B)||it.has(B)?F(A):k.has(ot)?O--:Z.get(B)>Z.get(ot)?(k.add(B),F(A)):(it.add(ot),O--):(l(D,a),O--)}for(;O--;){const A=s[O];Y.has(A.key)||l(A,a)}for(;j;)F(M[j-1]);return ct(tt),M}function Le(s,n,t){const{fragment:e,after_update:r}=s.$$;e&&e.m(n,t),St(()=>{const i=s.$$.on_mount.map(U).filter(Vt);s.$$.on_destroy?s.$$.on_destroy.push(...i):ct(i),s.$$.on_mount=[]}),r.forEach(St)}function Ne(s,n){const t=s.$$;t.fragment!==null&&(je(t.after_update),ct(t.on_destroy),t.fragment&&t.fragment.d(n),t.on_destroy=t.fragment=null,t.ctx=[])}function Re(s,n){s.$$.dirty[0]===-1&&(st.push(s),Te(),s.$$.dirty.fill(0)),s.$$.dirty[n/31|0]|=1<<n%31}function He(s,n,t,e,r,i,a,h=[-1]){const l=ut;pt(s);const d=s.$$={fragment:null,ctx:[],props:i,update:P,not_equal:r,bound:q(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(n.context||(l?l.$$.context:[])),callbacks:q(),dirty:h,skip_bound:!1,root:n.target||l.$$.root};a&&a(d.root);let _=!1;if(d.ctx=t?t(s,n.props||{},(b,O,...j)=>{const S=j.length?j[0]:O;return d.ctx&&r(d.ctx[b],d.ctx[b]=S)&&(!d.skip_bound&&d.bound[b]&&d.bound[b](S),_&&Re(s,b)),O}):[],d.update(),_=!0,ct(d.before_update),d.fragment=e?e(d.ctx):!1,n.target){if(n.hydrate){const b=be(n.target);d.fragment&&d.fragment.l(b),b.forEach(lt)}else d.fragment&&d.fragment.c();n.intro&&Gt(s.$$.fragment),Le(s,n.target,n.anchor),ft()}pt(l)}let qt;typeof HTMLElement=="function"&&(qt=class extends HTMLElement{constructor(n,t,e){super();f(this,"$$ctor");f(this,"$$s");f(this,"$$c");f(this,"$$cn",!1);f(this,"$$d",{});f(this,"$$r",!1);f(this,"$$p_d",{});f(this,"$$l",{});f(this,"$$l_u",new Map);this.$$ctor=n,this.$$s=t,e&&this.attachShadow({mode:"open"})}addEventListener(n,t,e){if(this.$$l[n]=this.$$l[n]||[],this.$$l[n].push(t),this.$$c){const r=this.$$c.$on(n,t);this.$$l_u.set(t,r)}super.addEventListener(n,t,e)}removeEventListener(n,t,e){if(super.removeEventListener(n,t,e),this.$$c){const r=this.$$l_u.get(t);r&&(r(),this.$$l_u.delete(t))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let n=function(i){return()=>{let a;return{c:function(){a=K("slot"),i!=="default"&&x(a,"name",i)},m:function(d,_){_t(d,a,_)},d:function(d){d&&lt(a)}}}};if(await Promise.resolve(),!this.$$cn)return;const t={},e=$e(this);for(const i of this.$$s)i in e&&(t[i]=[n(i)]);for(const i of this.attributes){const a=this.$$g_p(i.name);a in this.$$d||(this.$$d[a]=bt(a,i.value,this.$$p_d,"toProp"))}this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:t,$$scope:{ctx:[]}}});const r=()=>{this.$$r=!0;for(const i in this.$$p_d)if(this.$$d[i]=this.$$c.$$.ctx[this.$$c.$$.props[i]],this.$$p_d[i].reflect){const a=bt(i,this.$$d[i],this.$$p_d,"toAttribute");a==null?this.removeAttribute(i):this.setAttribute(this.$$p_d[i].attribute||i,a)}this.$$r=!1};this.$$c.$$.after_update.push(r),r();for(const i in this.$$l)for(const a of this.$$l[i]){const h=this.$$c.$on(i,a);this.$$l_u.set(a,h)}this.$$l={}}}attributeChangedCallback(n,t,e){var r;this.$$r||(n=this.$$g_p(n),this.$$d[n]=bt(n,e,this.$$p_d,"toProp"),(r=this.$$c)==null||r.$set({[n]:this.$$d[n]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{this.$$cn||(this.$$c.$destroy(),this.$$c=void 0)})}$$g_p(n){return Object.keys(this.$$p_d).find(t=>this.$$p_d[t].attribute===n||!this.$$p_d[t].attribute&&t.toLowerCase()===n)||n}});function bt(s,n,t,e){var i;const r=(i=t[s])==null?void 0:i.type;if(n=r==="Boolean"&&typeof n!="boolean"?n!=null:n,!e||!t[s])return n;if(e==="toAttribute")switch(r){case"Object":case"Array":return n==null?null:JSON.stringify(n);case"Boolean":return n?"":null;case"Number":return n??null;default:return n}else switch(r){case"Object":case"Array":return n&&JSON.parse(n);case"Boolean":return n;case"Number":return n!=null?+n:n;default:return n}}function Pe(s,n,t,e,r,i){let a=class extends qt{constructor(){super(s,t,r),this.$$p_d=n}static get observedAttributes(){return Object.keys(n).map(h=>(n[h].attribute||h).toLowerCase())}};return Object.keys(n).forEach(h=>{Object.defineProperty(a.prototype,h,{get(){return this.$$c&&h in this.$$c?this.$$c[h]:this.$$d[h]},set(l){var d;l=bt(h,l,n),this.$$d[h]=l,(d=this.$$c)==null||d.$set({[h]:l})}})}),e.forEach(h=>{Object.defineProperty(a.prototype,h,{get(){var l;return(l=this.$$c)==null?void 0:l[h]}})}),i&&(a=i(a)),s.element=a,a}class Ie{constructor(){f(this,"$$");f(this,"$$set")}$destroy(){Ne(this,1),this.$destroy=P}$on(n,t){if(!Vt(t))return P;const e=this.$$.callbacks[n]||(this.$$.callbacks[n]=[]);return e.push(t),()=>{const r=e.indexOf(t);r!==-1&&e.splice(r,1)}}$set(n){this.$$set&&!ye(n)&&(this.$$.skip_bound=!0,this.$$set(n),this.$$.skip_bound=!1)}}const De="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(De);const{isArray:Ue}=Array,Je=Object.keys,dt=s=>{if(!s)return s;if(Ue(s)){const n=[],t=s.length;for(let e=0;e<t;e++)n.push(dt(s[e]));return n}else if(typeof s=="object"){const n=Je(s),t=n.length,e={};for(let r=0;r<t;r++){const i=n[r];e[i]=dt(s[i])}return e}return s};class J{constructor(n){f(this,"path");f(this,"from");this.path=n}}const Ve=/~1/g,Be=/~0/g,ze=/~/g,Fe=/\//g;function We(s){return s.indexOf("~")===-1?s:s.replace(Ve,"/").replace(Be,"~")}function Ge(s){return s.indexOf("/")===-1&&s.indexOf("~")===-1?s:s.replace(ze,"~0").replace(Fe,"~1")}function Xe(s){return s?s.slice(1).split("/").map(We):[]}function E(s){return qe(s)?"":"/"+s.map(n=>Ge(String(n))).join("/")}const w=s=>typeof s=="string"?Xe(s):s,qe=s=>!s.length,Ye=Object.prototype.hasOwnProperty;function Ze(s,n){return Ye.call(s,n)}const{isArray:Yt}=Array,T=(s,n)=>{const t=n.length;if(!t)return{val:s};let e,r;for(let a=0;a<t;a++)if(e=s,r=n[a],Yt(e)){const h=e.length;if(r==="-")r=h;else if(typeof r=="string"){const l=~~r;if(""+l!==r)throw new Error("INVALID_INDEX");if(r=l,r<0)throw new Error("INVALID_INDEX")}s=e[r]}else if(typeof e=="object"&&e)s=Ze(e,r)?e[r]:void 0;else throw new Error("NOT_FOUND");return{val:s,obj:e,key:r}},gt=s=>Yt(s.obj)&&typeof s.key=="number",Et=s=>typeof s.obj=="object"&&typeof s.key=="string";class Lt extends J{constructor(t,e){super(t);f(this,"value");this.value=e}op(){return"add"}code(){return 0}apply(t){const{val:e,key:r,obj:i}=T(t,this.path),a=dt(this.value);if(!i)t=a;else if(typeof r=="string")i[r]=a;else{const h=i.length;if(r<h)i.splice(r,0,a);else{if(r>h)throw new Error("INVALID_INDEX");i.push(a)}}return{doc:t,old:e}}toJson(t){return{op:"add",path:E(this.path),value:this.value}}toCompact(t,e){return[e?"add":0,this.path,this.value]}encode(t){t.encodeArrayHeader(3),t.writer.u8(0),t.encodeArray(this.path),t.encodeAny(this.value)}}class Zt extends J{constructor(t,e){super(t);f(this,"oldValue");this.oldValue=e}op(){return"remove"}code(){return 1}apply(t){const e=T(t,this.path);if(e.val===void 0)throw new Error("NOT_FOUND");return Et(e)?delete e.obj[e.key]:gt(e)?e.val!==void 0&&e.obj.splice(e.key,1):t=null,{doc:t,old:e.val}}toJson(t){const e={op:"remove",path:E(this.path)};return this.oldValue!==void 0&&(e.oldValue=this.oldValue),e}toCompact(t,e){const r=e?"remove":1;return this.oldValue===void 0?[r,this.path]:[r,this.path,this.oldValue]}encode(t,e){const r=this.oldValue!==void 0;t.encodeArrayHeader(r?3:2),t.writer.u8(1),t.encodeArray(this.path),r&&t.encodeAny(this.oldValue)}}class Qe extends J{constructor(t,e,r){super(t);f(this,"value");f(this,"oldValue");this.value=e,this.oldValue=r}op(){return"replace"}code(){return 2}apply(t){const e=T(t,this.path);if(e.val===void 0)throw new Error("NOT_FOUND");return Et(e)?e.obj[e.key]=this.value:gt(e)?e.obj[e.key]=this.value:t=this.value,{doc:t,old:e.val}}toJson(t){const e={op:"replace",path:E(this.path),value:this.value};return this.oldValue!==void 0&&(e.oldValue=this.oldValue),e}toCompact(t,e){const r=e?"replace":2;return this.oldValue===void 0?[r,this.path,this.value]:[r,this.path,this.value,this.oldValue]}encode(t,e){const r=this.oldValue!==void 0;t.encodeArrayHeader(r?4:3),t.writer.u8(2),t.encodeArray(this.path),t.encodeAny(this.value),r&&t.encodeAny(this.oldValue)}}class Ke extends J{constructor(t,e){super(t);f(this,"from");this.from=e}op(){return"move"}code(){return 4}apply(t){const e=new Zt(w(this.from),void 0).apply(t);return new Lt(this.path,e.old).apply(e.doc)}toJson(t){return{op:"move",path:E(this.path),from:E(this.from)}}toCompact(t,e){return[e?"move":4,this.path,this.from]}encode(t,e){t.encodeArrayHeader(3),t.writer.u8(4),t.encodeArray(this.path),t.encodeArray(this.from)}}class ts extends J{constructor(t,e){super(t);f(this,"from");this.from=e}op(){return"copy"}code(){return 3}apply(t){const{val:e}=T(t,this.from);if(e===void 0)throw new Error("NOT_FOUND");return new Lt(this.path,dt(e)).apply(t)}toJson(t){return{op:"copy",path:E(this.path),from:E(this.from)}}toCompact(t,e){return[e?"copy":3,this.path,this.from]}encode(t,e){t.encodeArrayHeader(3),t.writer.u8(3),t.encodeArray(this.path),t.encodeArray(this.from)}}class I extends J{apply(n){if(!this.test(n))throw new Error("TEST");return{doc:n}}}const $t=(s,n)=>{if(s===n)return!0;if(s&&n&&typeof s=="object"&&typeof n=="object"){if(s.constructor!==n.constructor)return!1;let t,e,r;if(Array.isArray(s)){if(t=s.length,t!==n.length)return!1;for(e=t;e--!==0;)if(!$t(s[e],n[e]))return!1;return!0}if(r=Object.keys(s),t=r.length,t!==Object.keys(n).length)return!1;for(e=t;e--!==0;){const i=r[e];if(!$t(s[i],n[i]))return!1}return!0}return!1};class es extends I{constructor(t,e,r){super(t);f(this,"value");f(this,"not");this.value=e,this.not=r}op(){return"test"}code(){return 5}test(t){const{val:e}=T(t,this.path);if(e===void 0)return!!this.not;const r=$t(e,this.value);return this.not?!r:r}toJson(t){const e={op:"test",path:E(t?this.path.slice(t.path.length):this.path),value:this.value};return this.not&&(e.not=this.not),e}toCompact(t,e){const r=t?this.path.slice(t.path.length):this.path,i=e?"test":5;return this.not?[i,r,this.value,1]:[i,r,this.value]}encode(t,e){t.encodeArrayHeader(this.not?4:3),t.writer.u8(5),t.encodeArray(e?this.path.slice(e.path.length):this.path),t.encodeAny(this.value),this.not&&t.writer.u8(1)}}class ss extends J{constructor(n){super(n)}op(){return"flip"}code(){return 8}apply(n){const t=T(n,this.path);return t.obj?t.obj[t.key]=!t.val:n=!t.val,{doc:n,old:t.val}}toJson(n){return{op:"flip",path:E(this.path)}}toCompact(n,t){return[t?"flip":8,this.path]}encode(n,t){n.encodeArrayHeader(2),n.writer.u8(8),n.encodeArray(this.path)}}class ns extends J{constructor(t,e){super(t);f(this,"inc");this.inc=e}op(){return"inc"}code(){return 9}apply(t){const e=T(t,this.path),r=this.inc+Number(e.val);return e.obj?e.obj[e.key]=r:t=r,{doc:t,old:e.val}}toJson(t){return{op:"inc",path:E(this.path),inc:this.inc}}toCompact(t,e){return[e?"inc":9,this.path,this.inc]}encode(t,e){t.encodeArrayHeader(3),t.writer.u8(9),t.encodeArray(this.path),t.encodeNumber(this.inc)}}class rs extends J{constructor(t,e,r){super(t);f(this,"pos");f(this,"str");this.pos=e,this.str=r}op(){return"str_ins"}code(){return 6}apply(t){const{val:e,key:r,obj:i}=T(t,this.path);if(typeof e!="string"){if(e!==void 0)throw new Error("NOT_A_STRING");if(this.pos!==0)throw new Error("POS")}const a=typeof e=="string"?e:"",h=Math.min(this.pos,a.length),l=a.slice(0,h),d=a.slice(h),_=l+this.str+d;return i?i[r]=_:t=_,{doc:t,old:e}}toJson(t){return{op:"str_ins",path:E(this.path),pos:this.pos,str:this.str}}toCompact(t,e){return[e?"str_ins":6,this.path,this.pos,this.str]}encode(t,e){t.encodeArrayHeader(4),t.writer.u8(6),t.encodeArray(this.path),t.encodeNumber(this.pos),t.encodeString(this.str)}}class is extends J{constructor(t,e,r,i){super(t);f(this,"pos");f(this,"str");f(this,"len");this.pos=e,this.str=r,this.len=i}op(){return"str_del"}code(){return 7}deleteLength(){return typeof this.str=="string"?this.str.length:this.len}apply(t){const{val:e,key:r,obj:i}=T(t,this.path);if(typeof e!="string")throw new Error("NOT_A_STRING");const a=e.length,h=Math.min(this.pos,e.length),l=Math.min(h,a),d=this.str!==void 0?this.str.length:this.len,_=Math.min(h+d,a),b=e.slice(0,l),O=e.substr(_),j=b+O;return i?i[r]=j:t=j,{doc:t,old:e}}toJson(t){return typeof this.str=="string"?{op:"str_del",path:E(this.path),pos:this.pos,str:this.str}:{op:"str_del",path:E(this.path),pos:this.pos,len:this.len}}toCompact(t,e){const r=e?"str_del":7;return typeof this.str=="string"?[r,this.path,this.pos,this.str]:[r,this.path,this.pos,0,this.len]}encode(t,e){const r=typeof this.str=="string";t.encodeArrayHeader(r?4:5),t.writer.u8(7),t.encodeArray(this.path),t.encodeNumber(this.pos),r?t.encodeString(this.str):(t.writer.u8(0),t.encodeNumber(this.len))}}const{isArray:os}=Array,Nt=s=>!!s&&typeof s=="object"&&typeof s.text=="string",Rt=s=>!!s&&typeof s=="object"&&os(s.children),as=(s,n)=>{const t=new RegExp(s,n?"i":void 0);return e=>t.test(e)};class hs extends J{constructor(t,e,r){super(t);f(this,"pos");f(this,"props");this.pos=e,this.props=r}op(){return"split"}code(){return 10}apply(t){const e=T(t,this.path);if(e.val===void 0)throw new Error("NOT_FOUND");const r=this.split(e.val);return Et(e)?e.obj[e.key]=r:gt(e)?(e.obj[e.key]=r[0],e.obj.splice(e.key+1,0,r[1])):t=r,{doc:t,old:e.val}}split(t){if(typeof t=="string"){const{pos:e,props:r}=this,i=t.slice(0,e),a=t.slice(e);return r?[{...r,text:i},{...r,text:a}]:[i,a]}else if(Nt(t)){const{pos:e,props:r}=this,i=t.text.slice(0,e),a=t.text.slice(e);return[{...t,...r,text:i},{...t,...r,text:a}]}else if(Rt(t)){const{pos:e,props:r}=this,i=t.children.slice(0,e),a=t.children.slice(e);return[{...t,...r,children:i},{...t,...r,children:a}]}else if(typeof t=="number"){const{pos:e}=this;return[e,t-e]}else return[t,t]}toJson(t){const e={op:"split",path:E(this.path),pos:this.pos};return this.props&&(e.props=this.props),e}toCompact(t,e){const r=e?"split":10;return this.props?[r,this.path,this.pos,this.props]:[r,this.path,this.pos]}encode(t,e){t.encodeArrayHeader(this.props?4:3),t.writer.u8(10),t.encodeArray(this.path),t.encodeNumber(this.pos),this.props&&t.encodeObject(this.props)}}class cs extends J{constructor(t,e,r){super(t);f(this,"pos");f(this,"props");this.pos=e,this.props=r}op(){return"merge"}code(){return 11}apply(t){const e=T(t,this.path);if(!gt(e))throw new Error("INVALID_TARGET");if(e.key<=0)throw new Error("INVALID_KEY");const r=e.obj[e.key-1],i=e.obj[e.key],a=this.merge(r,i);return e.obj[e.key-1]=a,e.obj.splice(e.key,1),{doc:t,old:[r,i]}}merge(t,e){return typeof t=="string"&&typeof e=="string"||typeof t=="number"&&typeof e=="number"?t+e:Nt(t)&&Nt(e)?{...t,...e,text:t.text+e.text}:Rt(t)&&Rt(e)?{...t,...e,children:[...t.children,...e.children]}:[t,e]}toJson(t){const e={op:"merge",path:E(this.path),pos:this.pos};return this.props&&(e.props=this.props),e}toCompact(t,e){const r=e?"merge":11;return this.props?[r,this.path,this.pos,this.props]:[r,this.path,this.pos]}encode(t,e){t.encodeArrayHeader(this.props?4:3),t.writer.u8(11),t.encodeArray(this.path),t.encodeNumber(this.pos),this.props&&t.encodeAny(this.props)}}const{isArray:ls}=Array;class us extends J{constructor(t,e,r){super(t);f(this,"props");f(this,"deleteNull");this.props=e,this.deleteNull=r}op(){return"extend"}code(){return 12}apply(t){const e=T(t,this.path);return gt(e)?e.val!==void 0&&(e.obj[e.key]=this.extend(e.val)):Et(e)?e.obj[e.key]=this.extend(e.val):t=this.extend(t),{doc:t}}extend(t){if(ls(t)||typeof t!="object"||!t)return t;for(const[e,r]of Object.entries(this.props)){if(e==="__proto__")throw new Error("NO_PROTO");if(r===null&&this.deleteNull){delete t[e];continue}t[e]=r}return t}toJson(t){const e={op:"extend",path:E(this.path),props:this.props};return this.deleteNull&&(e.deleteNull=this.deleteNull),e}toCompact(t,e){const r=e?"extend":12;return this.deleteNull?[r,this.path,this.props,1]:[r,this.path,this.props]}encode(t,e){const{deleteNull:r}=this;t.encodeArrayHeader(r?4:3),t.writer.u8(12),t.encodeArray(this.path),t.encodeObject(this.props),r&&t.writer.u8(1)}}class ps extends I{constructor(n){super(n)}op(){return"defined"}code(){return 31}test(n){const{val:t}=T(n,this.path);return t!==void 0}toJson(n){return{op:"defined",path:E(n?this.path.slice(n.path.length):this.path)}}toCompact(n,t){return[t?"defined":31,n?this.path.slice(n.path.length):this.path]}encode(n,t){n.encodeArrayHeader(2),n.writer.u8(31),n.encodeArray(t?this.path.slice(t.path.length):this.path)}}class fs extends I{constructor(n){super(n)}op(){return"undefined"}code(){return 38}test(n){try{const{val:t}=T(n,this.path);return t===void 0}catch(t){if(t.message==="NOT_FOUND")return!0;throw t}}toJson(n){return{op:"undefined",path:E(n?this.path.slice(n.path.length):this.path)}}toCompact(n,t){return[t?"undefined":38,n?this.path.slice(n.path.length):this.path]}encode(n,t){n.encodeArrayHeader(2),n.writer.u8(38),n.encodeArray(t?this.path.slice(t.path.length):this.path)}}const{isArray:ds}=Array;class gs extends I{constructor(t,e){super(t);f(this,"type");this.type=e}op(){return"test_type"}code(){return 39}test(t){const{val:e}=T(t,this.path);return e===null?this.type.indexOf("null")>-1:ds(e)?this.type.indexOf("array")>-1:this.type.indexOf(typeof e)>-1||typeof e=="number"&&e===Math.round(e)&&this.type.indexOf("integer")>-1}toJson(t){return{op:"test_type",path:E(t?this.path.slice(t.path.length):this.path),type:this.type}}toCompact(t,e){return[e?"test_type":39,t?this.path.slice(t.path.length):this.path,this.type]}encode(t,e){t.encodeArrayHeader(3),t.writer.u8(39),t.encodeArray(e?this.path.slice(e.path.length):this.path),t.encodeArray(this.type)}}class vs extends I{constructor(t,e,r,i){super(t);f(this,"pos");f(this,"str");f(this,"not");this.pos=e,this.str=r,this.not=i}op(){return"test_string"}code(){return 40}test(t){const{val:e}=T(t,this.path);if(typeof e!="string")return!1;const r=e.length,i=Math.min(this.pos,r),a=Math.min(this.pos+this.str.length,r),h=e.substring(i,a)===this.str;return this.not?!h:h}toJson(t){const e={op:"test_string",path:E(t?this.path.slice(t.path.length):this.path),pos:this.pos,str:this.str};return this.not&&(e.not=this.not),e}toCompact(t,e){const r=e?"test_string":40,i=t?this.path.slice(t.path.length):this.path;return this.not?[r,i,this.pos,this.str,1]:[r,i,this.pos,this.str]}encode(t,e){t.encodeArrayHeader(this.not?5:4),t.writer.u8(40),t.encodeArray(e?this.path.slice(e.path.length):this.path),t.encodeNumber(this.pos),t.encodeString(this.str),this.not&&t.writer.u8(1)}}class ys extends I{constructor(t,e,r){super(t);f(this,"len");f(this,"not");this.len=e,this.not=r}op(){return"test_string_len"}code(){return 41}test(t){const{val:e}=T(t,this.path);if(typeof e!="string")return!1;const i=e.length>=this.len;return this.not?!i:i}toJson(t){const e={op:"test_string_len",path:E(t?this.path.slice(t.path.length):this.path),len:this.len};return this.not&&(e.not=this.not),e}toCompact(t,e){const r=e?"test_string_len":41,i=t?this.path.slice(t.path.length):this.path;return this.not?[r,i,this.len,1]:[r,i,this.len]}encode(t,e){t.encodeArrayHeader(this.not?4:3),t.writer.u8(41),t.encodeArray(e?this.path.slice(e.path.length):this.path),t.encodeNumber(this.len),this.not&&t.writer.u8(1)}}class ms extends I{constructor(t,e,r){super(t);f(this,"value");f(this,"ignore_case");this.value=e,this.ignore_case=r}op(){return"contains"}code(){return 30}test(t){const{val:e}=T(t,this.path);if(typeof e!="string")return!1;const r=this.ignore_case?e.toLowerCase():e,i=this.ignore_case?this.value.toLowerCase():this.value;return r.indexOf(i)>-1}toJson(t){const e={op:"contains",path:E(t?this.path.slice(t.path.length):this.path),value:this.value};return this.ignore_case&&(e.ignore_case=this.ignore_case),e}toCompact(t,e){const r=e?"contains":30;return this.ignore_case?[r,t?this.path.slice(t.path.length):this.path,this.value,1]:[r,t?this.path.slice(t.path.length):this.path,this.value]}encode(t,e){const r=this.ignore_case;t.encodeArrayHeader(r?4:3),t.writer.u8(30),t.encodeArray(e?this.path.slice(e.path.length):this.path),t.encodeString(this.value),r&&t.writer.u8(1)}}class ws extends I{constructor(t,e,r){super(t);f(this,"value");f(this,"ignore_case");this.value=e,this.ignore_case=r}op(){return"ends"}code(){return 32}test(t){const{val:e}=T(t,this.path);if(typeof e!="string")return!1;const r=this.ignore_case?e.toLowerCase():e,i=this.ignore_case?this.value.toLowerCase():this.value;return r.endsWith(i)}toJson(t){const e={op:"ends",path:E(t?this.path.slice(t.path.length):this.path),value:this.value};return this.ignore_case&&(e.ignore_case=this.ignore_case),e}toCompact(t,e){const r=e?"ends":32;return this.ignore_case?[r,t?this.path.slice(t.path.length):this.path,this.value,1]:[r,t?this.path.slice(t.path.length):this.path,this.value]}encode(t,e){const r=this.ignore_case;t.encodeArrayHeader(r?4:3),t.writer.u8(32),t.encodeArray(e?this.path.slice(e.path.length):this.path),t.encodeString(this.value),r&&t.writer.u8(1)}}class _s extends I{constructor(t,e,r){super(t);f(this,"value");f(this,"ignore_case");this.value=e,this.ignore_case=r}op(){return"starts"}code(){return 37}test(t){const{val:e}=T(t,this.path);if(typeof e!="string")return!1;const r=this.ignore_case?e.toLowerCase():e,i=this.ignore_case?this.value.toLowerCase():this.value;return r.startsWith(i)}toJson(t){const e={op:"starts",path:E(t?this.path.slice(t.path.length):this.path),value:this.value};return this.ignore_case&&(e.ignore_case=this.ignore_case),e}toCompact(t,e){const r=e?"starts":37;return this.ignore_case?[r,t?this.path.slice(t.path.length):this.path,this.value,1]:[r,t?this.path.slice(t.path.length):this.path,this.value]}encode(t,e){const r=this.ignore_case;t.encodeArrayHeader(r?4:3),t.writer.u8(37),t.encodeArray(e?this.path.slice(e.path.length):this.path),t.encodeString(this.value),r&&t.writer.u8(1)}}class bs extends I{constructor(t,e){super(t);f(this,"value");this.value=e}op(){return"in"}code(){return 33}test(t){const{val:e}=T(t,this.path);for(const r of this.value)if($t(e,r))return!0;return!1}toJson(t){return{op:"in",path:E(t?this.path.slice(t.path.length):this.path),value:this.value}}toCompact(t,e){return[e?"in":33,t?this.path.slice(t.path.length):this.path,this.value]}encode(t,e){t.encodeArrayHeader(3),t.writer.u8(33),t.encodeArray(e?this.path.slice(e.path.length):this.path),t.encodeArray(this.value)}}class Es extends I{constructor(t,e){super(t);f(this,"value");this.value=e}op(){return"less"}code(){return 34}test(t){const{val:e}=T(t,this.path);return typeof e!="number"?!1:e<this.value}toJson(t){return{op:"less",path:E(t?this.path.slice(t.path.length):this.path),value:this.value}}toCompact(t,e){return[e?"less":34,t?this.path.slice(t.path.length):this.path,this.value]}encode(t,e){t.encodeArrayHeader(3),t.writer.u8(34),t.encodeArray(e?this.path.slice(e.path.length):this.path),t.encodeNumber(this.value)}}class $s extends I{constructor(t,e){super(t);f(this,"value");this.value=e}op(){return"more"}code(){return 36}test(t){const{val:e}=T(t,this.path);return typeof e!="number"?!1:e>this.value}toJson(t){return{op:"more",path:E(t?this.path.slice(t.path.length):this.path),value:this.value}}toCompact(t,e){return[e?"more":36,t?this.path.slice(t.path.length):this.path,this.value]}encode(t,e){t.encodeArrayHeader(3),t.writer.u8(36),t.encodeArray(e?this.path.slice(e.path.length):this.path),t.encodeNumber(this.value)}}class Ht extends I{constructor(t,e){super(t);f(this,"ops");this.ops=e}}class Cs extends Ht{constructor(t,e){super(t,e);f(this,"ops");this.ops=e}op(){return"and"}code(){return 43}test(t){for(const e of this.ops)if(!e.test(t))return!1;return!0}toJson(t){return{op:"and",path:E(t?this.path.slice(t.path.length):this.path),apply:this.ops.map(r=>r.toJson(this))}}toCompact(t,e){return[e?"and":43,t?this.path.slice(t.path.length):this.path,this.ops.map(i=>i.toCompact(this,e))]}encode(t,e){const r=e?this.path.slice(e.path.length):this.path;t.encodeArrayHeader(3),t.writer.u8(43),t.encodeArray(r);const i=this.ops.length;t.encodeArrayHeader(i);for(let a=0;a<i;a++)this.ops[a].encode(t,this)}}class ks extends Ht{constructor(t,e){super(t,e);f(this,"ops");this.ops=e}op(){return"or"}code(){return 45}test(t){for(const e of this.ops)if(e.test(t))return!0;return!1}toJson(t){return{op:"or",path:E(t?this.path.slice(t.path.length):this.path),apply:this.ops.map(r=>r.toJson(this))}}toCompact(t,e){return[e?"or":45,t?this.path.slice(t.path.length):this.path,this.ops.map(i=>i.toCompact(this,e))]}encode(t,e){t.encodeArrayHeader(3),t.writer.u8(45),t.encodeArray(e?this.path.slice(e.path.length):this.path);const r=this.ops.length;t.encodeArrayHeader(r);for(let i=0;i<r;i++)this.ops[i].encode(t,this)}}class As extends Ht{constructor(t,e){super(t,e);f(this,"ops");this.ops=e}op(){return"not"}code(){return 44}test(t){for(const e of this.ops)if(e.test(t))return!1;return!0}toJson(t){return{op:"not",path:E(t?this.path.slice(t.path.length):this.path),apply:this.ops.map(r=>r.toJson(this))}}toCompact(t,e){return[e?"not":44,t?this.path.slice(t.path.length):this.path,this.ops.map(i=>i.toCompact(this,e))]}encode(t,e){t.encodeArrayHeader(3),t.writer.u8(44),t.encodeArray(e?this.path.slice(e.path.length):this.path);const r=this.ops.length;t.encodeArrayHeader(r);for(let i=0;i<r;i++)this.ops[i].encode(t,this)}}class Ts extends I{constructor(t,e,r,i){super(t);f(this,"value");f(this,"ignore_case");f(this,"matcher");this.value=e,this.ignore_case=r,this.matcher=i(e,r)}op(){return"matches"}code(){return 35}test(t){const{val:e}=T(t,this.path);return typeof e!="string"?!1:this.matcher(e)}toJson(t){const e={op:"matches",path:E(t?this.path.slice(t.path.length):this.path),value:this.value};return this.ignore_case&&(e.ignore_case=this.ignore_case),e}toCompact(t,e){const r=e?"matches":35;return this.ignore_case?[r,t?this.path.slice(t.path.length):this.path,this.value,1]:[r,t?this.path.slice(t.path.length):this.path,this.value]}encode(t,e){const r=this.ignore_case;t.encodeArrayHeader(r?4:3),t.writer.u8(35),t.encodeArray(e?this.path.slice(e.path.length):this.path),t.encodeString(this.value),r&&t.writer.u8(1)}}const{isArray:Os}=Array;class js extends I{constructor(t,e){super(t);f(this,"value");this.value=e}op(){return"type"}code(){return 42}test(t){const{val:e}=T(t,this.path);return e===null?this.value==="null":Os(e)?this.value==="array":typeof e===this.value||typeof e=="number"&&e===Math.round(e)&&this.value==="integer"}toJson(t){return{op:"type",path:E(t?this.path.slice(t.path.length):this.path),value:this.value}}toCompact(t,e){return[e?"type":42,t?this.path.slice(t.path.length):this.path,this.value]}encode(t,e){t.encodeArrayHeader(3),t.writer.u8(42),t.encodeArray(e?this.path.slice(e.path.length):this.path),t.encodeString(this.value)}}const xs=(s,n)=>{switch(s.op){case"add":return new Lt(w(s.path),s.value);case"remove":return new Zt(w(s.path),s.oldValue);case"replace":return new Qe(w(s.path),s.value,s.oldValue);case"move":return new Ke(w(s.path),w(s.from));case"copy":return new ts(w(s.path),w(s.from));case"flip":return new ss(w(s.path));case"inc":return new ns(w(s.path),s.inc);case"str_ins":return new rs(w(s.path),s.pos,s.str);case"str_del":return new is(w(s.path),s.pos,s.str,s.len);case"split":return new hs(w(s.path),s.pos,s.props||null);case"merge":return new cs(w(s.path),s.pos,s.props||null);case"extend":return new us(w(s.path),s.props,!!s.deleteNull);default:return Ct(s,n)}},Ct=(s,n)=>{switch(s.op){case"test":return new es(w(s.path),s.value,!!s.not);case"defined":return new ps(w(s.path));case"undefined":return new fs(w(s.path));case"type":return new js(w(s.path),s.value);case"test_type":return new gs(w(s.path),s.type);case"test_string":return new vs(w(s.path),s.pos,s.str,!!s.not);case"test_string_len":return new ys(w(s.path),s.len,!!s.not);case"contains":return new ms(w(s.path),s.value,!!s.ignore_case);case"ends":return new ws(w(s.path),s.value,!!s.ignore_case);case"starts":return new _s(w(s.path),s.value,!!s.ignore_case);case"matches":return new Ts(w(s.path),s.value,!!s.ignore_case,n.createMatcher||as);case"in":return new bs(w(s.path),s.value);case"less":return new Es(w(s.path),s.value);case"more":return new $s(w(s.path),s.value);case"and":{const t=w(s.path);return new Cs(t,s.apply.map(e=>Ct({...e,path:[...t,...w(e.path)]},n)))}case"or":{const t=w(s.path);return new ks(t,s.apply.map(e=>Ct({...e,path:[...t,...w(e.path)]},n)))}case"not":{const t=w(s.path);return new As(t,s.apply.map(e=>Ct({...e,path:[...t,...w(e.path)]},n)))}default:throw new Error("OP_UNKNOWN")}};function Ss(s,n,t){t.mutate||(s=dt(s));const e=[],r=n.length;for(let i=0;i<r;i++){const h=xs(n[i],t).apply(s);s=h.doc,e.push(h)}return{doc:s,res:e}}var vt=s=>typeof s=="function"?s:function(){return s},Ms=typeof self<"u"?self:null,yt=typeof window<"u"?window:null,mt=Ms||yt||mt,Ls="2.0.0",z={connecting:0,open:1,closing:2,closed:3},Ns=1e4,Rs=1e3,V={closed:"closed",errored:"errored",joined:"joined",joining:"joining",leaving:"leaving"},G={close:"phx_close",error:"phx_error",join:"phx_join",reply:"phx_reply",leave:"phx_leave"},Pt={longpoll:"longpoll",websocket:"websocket"},Hs={complete:4},kt=class{constructor(s,n,t,e){this.channel=s,this.event=n,this.payload=t||function(){return{}},this.receivedResp=null,this.timeout=e,this.timeoutTimer=null,this.recHooks=[],this.sent=!1}resend(s){this.timeout=s,this.reset(),this.send()}send(){this.hasReceived("timeout")||(this.startTimeout(),this.sent=!0,this.channel.socket.push({topic:this.channel.topic,event:this.event,payload:this.payload(),ref:this.ref,join_ref:this.channel.joinRef()}))}receive(s,n){return this.hasReceived(s)&&n(this.receivedResp.response),this.recHooks.push({status:s,callback:n}),this}reset(){this.cancelRefEvent(),this.ref=null,this.refEvent=null,this.receivedResp=null,this.sent=!1}matchReceive({status:s,response:n,_ref:t}){this.recHooks.filter(e=>e.status===s).forEach(e=>e.callback(n))}cancelRefEvent(){this.refEvent&&this.channel.off(this.refEvent)}cancelTimeout(){clearTimeout(this.timeoutTimer),this.timeoutTimer=null}startTimeout(){this.timeoutTimer&&this.cancelTimeout(),this.ref=this.channel.socket.makeRef(),this.refEvent=this.channel.replyEventName(this.ref),this.channel.on(this.refEvent,s=>{this.cancelRefEvent(),this.cancelTimeout(),this.receivedResp=s,this.matchReceive(s)}),this.timeoutTimer=setTimeout(()=>{this.trigger("timeout",{})},this.timeout)}hasReceived(s){return this.receivedResp&&this.receivedResp.status===s}trigger(s,n){this.channel.trigger(this.refEvent,{status:s,response:n})}},Qt=class{constructor(s,n){this.callback=s,this.timerCalc=n,this.timer=null,this.tries=0}reset(){this.tries=0,clearTimeout(this.timer)}scheduleTimeout(){clearTimeout(this.timer),this.timer=setTimeout(()=>{this.tries=this.tries+1,this.callback()},this.timerCalc(this.tries+1))}},Ps=class{constructor(s,n,t){this.state=V.closed,this.topic=s,this.params=vt(n||{}),this.socket=t,this.bindings=[],this.bindingRef=0,this.timeout=this.socket.timeout,this.joinedOnce=!1,this.joinPush=new kt(this,G.join,this.params,this.timeout),this.pushBuffer=[],this.stateChangeRefs=[],this.rejoinTimer=new Qt(()=>{this.socket.isConnected()&&this.rejoin()},this.socket.rejoinAfterMs),this.stateChangeRefs.push(this.socket.onError(()=>this.rejoinTimer.reset())),this.stateChangeRefs.push(this.socket.onOpen(()=>{this.rejoinTimer.reset(),this.isErrored()&&this.rejoin()})),this.joinPush.receive("ok",()=>{this.state=V.joined,this.rejoinTimer.reset(),this.pushBuffer.forEach(e=>e.send()),this.pushBuffer=[]}),this.joinPush.receive("error",()=>{this.state=V.errored,this.socket.isConnected()&&this.rejoinTimer.scheduleTimeout()}),this.onClose(()=>{this.rejoinTimer.reset(),this.socket.hasLogger()&&this.socket.log("channel",`close ${this.topic} ${this.joinRef()}`),this.state=V.closed,this.socket.remove(this)}),this.onError(e=>{this.socket.hasLogger()&&this.socket.log("channel",`error ${this.topic}`,e),this.isJoining()&&this.joinPush.reset(),this.state=V.errored,this.socket.isConnected()&&this.rejoinTimer.scheduleTimeout()}),this.joinPush.receive("timeout",()=>{this.socket.hasLogger()&&this.socket.log("channel",`timeout ${this.topic} (${this.joinRef()})`,this.joinPush.timeout),new kt(this,G.leave,vt({}),this.timeout).send(),this.state=V.errored,this.joinPush.reset(),this.socket.isConnected()&&this.rejoinTimer.scheduleTimeout()}),this.on(G.reply,(e,r)=>{this.trigger(this.replyEventName(r),e)})}join(s=this.timeout){if(this.joinedOnce)throw new Error("tried to join multiple times. 'join' can only be called a single time per channel instance");return this.timeout=s,this.joinedOnce=!0,this.rejoin(),this.joinPush}onClose(s){this.on(G.close,s)}onError(s){return this.on(G.error,n=>s(n))}on(s,n){let t=this.bindingRef++;return this.bindings.push({event:s,ref:t,callback:n}),t}off(s,n){this.bindings=this.bindings.filter(t=>!(t.event===s&&(typeof n>"u"||n===t.ref)))}canPush(){return this.socket.isConnected()&&this.isJoined()}push(s,n,t=this.timeout){if(n=n||{},!this.joinedOnce)throw new Error(`tried to push '${s}' to '${this.topic}' before joining. Use channel.join() before pushing events`);let e=new kt(this,s,function(){return n},t);return this.canPush()?e.send():(e.startTimeout(),this.pushBuffer.push(e)),e}leave(s=this.timeout){this.rejoinTimer.reset(),this.joinPush.cancelTimeout(),this.state=V.leaving;let n=()=>{this.socket.hasLogger()&&this.socket.log("channel",`leave ${this.topic}`),this.trigger(G.close,"leave")},t=new kt(this,G.leave,vt({}),s);return t.receive("ok",()=>n()).receive("timeout",()=>n()),t.send(),this.canPush()||t.trigger("ok",{}),t}onMessage(s,n,t){return n}isMember(s,n,t,e){return this.topic!==s?!1:e&&e!==this.joinRef()?(this.socket.hasLogger()&&this.socket.log("channel","dropping outdated message",{topic:s,event:n,payload:t,joinRef:e}),!1):!0}joinRef(){return this.joinPush.ref}rejoin(s=this.timeout){this.isLeaving()||(this.socket.leaveOpenTopic(this.topic),this.state=V.joining,this.joinPush.resend(s))}trigger(s,n,t,e){let r=this.onMessage(s,n,t,e);if(n&&!r)throw new Error("channel onMessage callbacks must return the payload, modified or unmodified");let i=this.bindings.filter(a=>a.event===s);for(let a=0;a<i.length;a++)i[a].callback(r,t,e||this.joinRef())}replyEventName(s){return`chan_reply_${s}`}isClosed(){return this.state===V.closed}isErrored(){return this.state===V.errored}isJoined(){return this.state===V.joined}isJoining(){return this.state===V.joining}isLeaving(){return this.state===V.leaving}},At=class{static request(s,n,t,e,r,i,a){if(mt.XDomainRequest){let h=new mt.XDomainRequest;return this.xdomainRequest(h,s,n,e,r,i,a)}else{let h=new mt.XMLHttpRequest;return this.xhrRequest(h,s,n,t,e,r,i,a)}}static xdomainRequest(s,n,t,e,r,i,a){return s.timeout=r,s.open(n,t),s.onload=()=>{let h=this.parseJSON(s.responseText);a&&a(h)},i&&(s.ontimeout=i),s.onprogress=()=>{},s.send(e),s}static xhrRequest(s,n,t,e,r,i,a,h){return s.open(n,t,!0),s.timeout=i,s.setRequestHeader("Content-Type",e),s.onerror=()=>h&&h(null),s.onreadystatechange=()=>{if(s.readyState===Hs.complete&&h){let l=this.parseJSON(s.responseText);h(l)}},a&&(s.ontimeout=a),s.send(r),s}static parseJSON(s){if(!s||s==="")return null;try{return JSON.parse(s)}catch{return console&&console.log("failed to parse JSON response",s),null}}static serialize(s,n){let t=[];for(var e in s){if(!Object.prototype.hasOwnProperty.call(s,e))continue;let r=n?`${n}[${e}]`:e,i=s[e];typeof i=="object"?t.push(this.serialize(i,r)):t.push(encodeURIComponent(r)+"="+encodeURIComponent(i))}return t.join("&")}static appendParams(s,n){if(Object.keys(n).length===0)return s;let t=s.match(/\?/)?"&":"?";return`${s}${t}${this.serialize(n)}`}},It=class{constructor(s){this.endPoint=null,this.token=null,this.skipHeartbeat=!0,this.reqs=new Set,this.onopen=function(){},this.onerror=function(){},this.onmessage=function(){},this.onclose=function(){},this.pollEndpoint=this.normalizeEndpoint(s),this.readyState=z.connecting,this.poll()}normalizeEndpoint(s){return s.replace("ws://","http://").replace("wss://","https://").replace(new RegExp("(.*)/"+Pt.websocket),"$1/"+Pt.longpoll)}endpointURL(){return At.appendParams(this.pollEndpoint,{token:this.token})}closeAndRetry(s,n,t){this.close(s,n,t),this.readyState=z.connecting}ontimeout(){this.onerror("timeout"),this.closeAndRetry(1005,"timeout",!1)}isActive(){return this.readyState===z.open||this.readyState===z.connecting}poll(){this.ajax("GET",null,()=>this.ontimeout(),s=>{if(s){var{status:n,token:t,messages:e}=s;this.token=t}else n=0;switch(n){case 200:e.forEach(r=>{setTimeout(()=>this.onmessage({data:r}),0)}),this.poll();break;case 204:this.poll();break;case 410:this.readyState=z.open,this.onopen({}),this.poll();break;case 403:this.onerror(403),this.close(1008,"forbidden",!1);break;case 0:case 500:this.onerror(500),this.closeAndRetry(1011,"internal server error",500);break;default:throw new Error(`unhandled poll status ${n}`)}})}send(s){this.ajax("POST",s,()=>this.onerror("timeout"),n=>{(!n||n.status!==200)&&(this.onerror(n&&n.status),this.closeAndRetry(1011,"internal server error",!1))})}close(s,n,t){for(let r of this.reqs)r.abort();this.readyState=z.closed;let e=Object.assign({code:1e3,reason:void 0,wasClean:!0},{code:s,reason:n,wasClean:t});typeof CloseEvent<"u"?this.onclose(new CloseEvent("close",e)):this.onclose(e)}ajax(s,n,t,e){let r,i=()=>{this.reqs.delete(r),t()};r=At.request(s,this.endpointURL(),"application/json",n,this.timeout,i,a=>{this.reqs.delete(r),this.isActive()&&e(a)}),this.reqs.add(r)}},Tt={HEADER_LENGTH:1,META_LENGTH:4,KINDS:{push:0,reply:1,broadcast:2},encode(s,n){if(s.payload.constructor===ArrayBuffer)return n(this.binaryEncode(s));{let t=[s.join_ref,s.ref,s.topic,s.event,s.payload];return n(JSON.stringify(t))}},decode(s,n){if(s.constructor===ArrayBuffer)return n(this.binaryDecode(s));{let[t,e,r,i,a]=JSON.parse(s);return n({join_ref:t,ref:e,topic:r,event:i,payload:a})}},binaryEncode(s){let{join_ref:n,ref:t,event:e,topic:r,payload:i}=s,a=this.META_LENGTH+n.length+t.length+r.length+e.length,h=new ArrayBuffer(this.HEADER_LENGTH+a),l=new DataView(h),d=0;l.setUint8(d++,this.KINDS.push),l.setUint8(d++,n.length),l.setUint8(d++,t.length),l.setUint8(d++,r.length),l.setUint8(d++,e.length),Array.from(n,b=>l.setUint8(d++,b.charCodeAt(0))),Array.from(t,b=>l.setUint8(d++,b.charCodeAt(0))),Array.from(r,b=>l.setUint8(d++,b.charCodeAt(0))),Array.from(e,b=>l.setUint8(d++,b.charCodeAt(0)));var _=new Uint8Array(h.byteLength+i.byteLength);return _.set(new Uint8Array(h),0),_.set(new Uint8Array(i),h.byteLength),_.buffer},binaryDecode(s){let n=new DataView(s),t=n.getUint8(0),e=new TextDecoder;switch(t){case this.KINDS.push:return this.decodePush(s,n,e);case this.KINDS.reply:return this.decodeReply(s,n,e);case this.KINDS.broadcast:return this.decodeBroadcast(s,n,e)}},decodePush(s,n,t){let e=n.getUint8(1),r=n.getUint8(2),i=n.getUint8(3),a=this.HEADER_LENGTH+this.META_LENGTH-1,h=t.decode(s.slice(a,a+e));a=a+e;let l=t.decode(s.slice(a,a+r));a=a+r;let d=t.decode(s.slice(a,a+i));a=a+i;let _=s.slice(a,s.byteLength);return{join_ref:h,ref:null,topic:l,event:d,payload:_}},decodeReply(s,n,t){let e=n.getUint8(1),r=n.getUint8(2),i=n.getUint8(3),a=n.getUint8(4),h=this.HEADER_LENGTH+this.META_LENGTH,l=t.decode(s.slice(h,h+e));h=h+e;let d=t.decode(s.slice(h,h+r));h=h+r;let _=t.decode(s.slice(h,h+i));h=h+i;let b=t.decode(s.slice(h,h+a));h=h+a;let O=s.slice(h,s.byteLength),j={status:b,response:O};return{join_ref:l,ref:d,topic:_,event:G.reply,payload:j}},decodeBroadcast(s,n,t){let e=n.getUint8(1),r=n.getUint8(2),i=this.HEADER_LENGTH+2,a=t.decode(s.slice(i,i+e));i=i+e;let h=t.decode(s.slice(i,i+r));i=i+r;let l=s.slice(i,s.byteLength);return{join_ref:null,ref:null,topic:a,event:h,payload:l}}},Is=class{constructor(s,n={}){this.stateChangeCallbacks={open:[],close:[],error:[],message:[]},this.channels=[],this.sendBuffer=[],this.ref=0,this.timeout=n.timeout||Ns,this.transport=n.transport||mt.WebSocket||It,this.establishedConnections=0,this.defaultEncoder=Tt.encode.bind(Tt),this.defaultDecoder=Tt.decode.bind(Tt),this.closeWasClean=!1,this.binaryType=n.binaryType||"arraybuffer",this.connectClock=1,this.transport!==It?(this.encode=n.encode||this.defaultEncoder,this.decode=n.decode||this.defaultDecoder):(this.encode=this.defaultEncoder,this.decode=this.defaultDecoder);let t=null;yt&&yt.addEventListener&&(yt.addEventListener("pagehide",e=>{this.conn&&(this.disconnect(),t=this.connectClock)}),yt.addEventListener("pageshow",e=>{t===this.connectClock&&(t=null,this.connect())})),this.heartbeatIntervalMs=n.heartbeatIntervalMs||3e4,this.rejoinAfterMs=e=>n.rejoinAfterMs?n.rejoinAfterMs(e):[1e3,2e3,5e3][e-1]||1e4,this.reconnectAfterMs=e=>n.reconnectAfterMs?n.reconnectAfterMs(e):[10,50,100,150,200,250,500,1e3,2e3][e-1]||5e3,this.logger=n.logger||null,this.longpollerTimeout=n.longpollerTimeout||2e4,this.params=vt(n.params||{}),this.endPoint=`${s}/${Pt.websocket}`,this.vsn=n.vsn||Ls,this.heartbeatTimeoutTimer=null,this.heartbeatTimer=null,this.pendingHeartbeatRef=null,this.reconnectTimer=new Qt(()=>{this.teardown(()=>this.connect())},this.reconnectAfterMs)}getLongPollTransport(){return It}replaceTransport(s){this.connectClock++,this.closeWasClean=!0,this.reconnectTimer.reset(),this.sendBuffer=[],this.conn&&(this.conn.close(),this.conn=null),this.transport=s}protocol(){return location.protocol.match(/^https/)?"wss":"ws"}endPointURL(){let s=At.appendParams(At.appendParams(this.endPoint,this.params()),{vsn:this.vsn});return s.charAt(0)!=="/"?s:s.charAt(1)==="/"?`${this.protocol()}:${s}`:`${this.protocol()}://${location.host}${s}`}disconnect(s,n,t){this.connectClock++,this.closeWasClean=!0,this.reconnectTimer.reset(),this.teardown(s,n,t)}connect(s){s&&(console&&console.log("passing params to connect is deprecated. Instead pass :params to the Socket constructor"),this.params=vt(s)),!this.conn&&(this.connectClock++,this.closeWasClean=!1,this.conn=new this.transport(this.endPointURL()),this.conn.binaryType=this.binaryType,this.conn.timeout=this.longpollerTimeout,this.conn.onopen=()=>this.onConnOpen(),this.conn.onerror=n=>this.onConnError(n),this.conn.onmessage=n=>this.onConnMessage(n),this.conn.onclose=n=>this.onConnClose(n))}log(s,n,t){this.logger(s,n,t)}hasLogger(){return this.logger!==null}onOpen(s){let n=this.makeRef();return this.stateChangeCallbacks.open.push([n,s]),n}onClose(s){let n=this.makeRef();return this.stateChangeCallbacks.close.push([n,s]),n}onError(s){let n=this.makeRef();return this.stateChangeCallbacks.error.push([n,s]),n}onMessage(s){let n=this.makeRef();return this.stateChangeCallbacks.message.push([n,s]),n}ping(s){if(!this.isConnected())return!1;let n=this.makeRef(),t=Date.now();this.push({topic:"phoenix",event:"heartbeat",payload:{},ref:n});let e=this.onMessage(r=>{r.ref===n&&(this.off([e]),s(Date.now()-t))});return!0}clearHeartbeats(){clearTimeout(this.heartbeatTimer),clearTimeout(this.heartbeatTimeoutTimer)}onConnOpen(){this.hasLogger()&&this.log("transport",`connected to ${this.endPointURL()}`),this.closeWasClean=!1,this.establishedConnections++,this.flushSendBuffer(),this.reconnectTimer.reset(),this.resetHeartbeat(),this.stateChangeCallbacks.open.forEach(([,s])=>s())}heartbeatTimeout(){this.pendingHeartbeatRef&&(this.pendingHeartbeatRef=null,this.hasLogger()&&this.log("transport","heartbeat timeout. Attempting to re-establish connection"),this.triggerChanError(),this.closeWasClean=!1,this.teardown(()=>this.reconnectTimer.scheduleTimeout(),Rs,"heartbeat timeout"))}resetHeartbeat(){this.conn&&this.conn.skipHeartbeat||(this.pendingHeartbeatRef=null,this.clearHeartbeats(),this.heartbeatTimer=setTimeout(()=>this.sendHeartbeat(),this.heartbeatIntervalMs))}teardown(s,n,t){if(!this.conn)return s&&s();this.waitForBufferDone(()=>{this.conn&&(n?this.conn.close(n,t||""):this.conn.close()),this.waitForSocketClosed(()=>{this.conn&&(this.conn.onopen=function(){},this.conn.onerror=function(){},this.conn.onmessage=function(){},this.conn.onclose=function(){},this.conn=null),s&&s()})})}waitForBufferDone(s,n=1){if(n===5||!this.conn||!this.conn.bufferedAmount){s();return}setTimeout(()=>{this.waitForBufferDone(s,n+1)},150*n)}waitForSocketClosed(s,n=1){if(n===5||!this.conn||this.conn.readyState===z.closed){s();return}setTimeout(()=>{this.waitForSocketClosed(s,n+1)},150*n)}onConnClose(s){let n=s&&s.code;this.hasLogger()&&this.log("transport","close",s),this.triggerChanError(),this.clearHeartbeats(),!this.closeWasClean&&n!==1e3&&this.reconnectTimer.scheduleTimeout(),this.stateChangeCallbacks.close.forEach(([,t])=>t(s))}onConnError(s){this.hasLogger()&&this.log("transport",s);let n=this.transport,t=this.establishedConnections;this.stateChangeCallbacks.error.forEach(([,e])=>{e(s,n,t)}),(n===this.transport||t>0)&&this.triggerChanError()}triggerChanError(){this.channels.forEach(s=>{s.isErrored()||s.isLeaving()||s.isClosed()||s.trigger(G.error)})}connectionState(){switch(this.conn&&this.conn.readyState){case z.connecting:return"connecting";case z.open:return"open";case z.closing:return"closing";default:return"closed"}}isConnected(){return this.connectionState()==="open"}remove(s){this.off(s.stateChangeRefs),this.channels=this.channels.filter(n=>n.joinRef()!==s.joinRef())}off(s){for(let n in this.stateChangeCallbacks)this.stateChangeCallbacks[n]=this.stateChangeCallbacks[n].filter(([t])=>s.indexOf(t)===-1)}channel(s,n={}){let t=new Ps(s,n,this);return this.channels.push(t),t}push(s){if(this.hasLogger()){let{topic:n,event:t,payload:e,ref:r,join_ref:i}=s;this.log("push",`${n} ${t} (${i}, ${r})`,e)}this.isConnected()?this.encode(s,n=>this.conn.send(n)):this.sendBuffer.push(()=>this.encode(s,n=>this.conn.send(n)))}makeRef(){let s=this.ref+1;return s===this.ref?this.ref=0:this.ref=s,this.ref.toString()}sendHeartbeat(){this.pendingHeartbeatRef&&!this.isConnected()||(this.pendingHeartbeatRef=this.makeRef(),this.push({topic:"phoenix",event:"heartbeat",payload:{},ref:this.pendingHeartbeatRef}),this.heartbeatTimeoutTimer=setTimeout(()=>this.heartbeatTimeout(),this.heartbeatIntervalMs))}flushSendBuffer(){this.isConnected()&&this.sendBuffer.length>0&&(this.sendBuffer.forEach(s=>s()),this.sendBuffer=[])}onConnMessage(s){this.decode(s.data,n=>{let{topic:t,event:e,payload:r,ref:i,join_ref:a}=n;i&&i===this.pendingHeartbeatRef&&(this.clearHeartbeats(),this.pendingHeartbeatRef=null,this.heartbeatTimer=setTimeout(()=>this.sendHeartbeat(),this.heartbeatIntervalMs)),this.hasLogger()&&this.log("receive",`${r.status||""} ${t} ${e} ${i&&"("+i+")"||""}`,r);for(let h=0;h<this.channels.length;h++){const l=this.channels[h];l.isMember(t,e,r,a)&&l.trigger(e,r,i,a)}for(let h=0;h<this.stateChangeCallbacks.message.length;h++){let[,l]=this.stateChangeCallbacks.message[h];l(n)}})}leaveOpenTopic(s){let n=this.channels.find(t=>t.topic===s&&(t.isJoined()||t.isJoining()));n&&(this.hasLogger()&&this.log("transport",`leaving duplicate topic "${s}"`),n.leave())}};class Ds{constructor(n){this.connected=!1,this.config=n,this.socket=new Is(this.config.url,{logger:(t,e,r)=>{console.log(`${t}: ${e}`,r)}}),this.channel=this.socket.channel(this.config.topic,this.config.params),this.eventTarget=new EventTarget}connect(){this.connected||(this.socket.onError(n=>this.emitError("socket error",n)),this.socket.connect(),this.channel.onError(n=>console.log("channel error",n)),this.channel.join().receive("ok",()=>{console.log("joined")}).receive("error",n=>{this.emitError("channel join error",n)}),this.channel.on("state:change",n=>this.handleChange(n)),this.channel.on("state:patch",n=>this.handlePatch(n)),this.connected=!0)}disconnect(){this.channel&&this.channel.leave(),this.socket.disconnect(),this.connected=!1}addEventListener(n,t,e){var r;this.eventTarget.addEventListener(n,t,e),n.startsWith("livestate-")||(r=this.channel)==null||r.on(n,i=>{this.eventTarget.dispatchEvent(new CustomEvent(n,{detail:i}))})}removeEventListener(n,t,e){return this.eventTarget.removeEventListener(n,t,e)}subscribe(n){this.addEventListener("livestate-change",n)}unsubscribe(n){this.removeEventListener("livestate-change",n)}emitError(n,t){this.eventTarget.dispatchEvent(new CustomEvent("livestate-error",{detail:{kind:n,error:t}}))}handleChange({state:n,version:t}){this.state=n,this.stateVersion=t,this.eventTarget.dispatchEvent(new CustomEvent("livestate-change",{detail:{state:this.state,version:this.stateVersion}}))}handlePatch({patch:n,version:t}){if(this.eventTarget.dispatchEvent(new CustomEvent("livestate-patch",{detail:{patch:n,version:t}})),t===this.stateVersion+1){const{doc:e,res:r}=Ss(this.state,n,{mutate:!1});this.state=e,this.stateVersion=t,this.eventTarget.dispatchEvent(new CustomEvent("livestate-change",{detail:{state:this.state,version:this.stateVersion}}))}else this.channel.push("lvs_refresh")}pushEvent(n,t){this.dispatchEvent(new CustomEvent(n,{detail:t}))}dispatchEvent(n){return this.channel.push(`lvs_evt:${n.type}`,n.detail),!0}pushCustomEvent(n){this.dispatchEvent(n)}}Promise.resolve();var Kt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};/*! *****************************************************************************
2
- Copyright (C) Microsoft. All rights reserved.
3
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4
- this file except in compliance with the License. You may obtain a copy of the
5
- License at http://www.apache.org/licenses/LICENSE-2.0
6
-
7
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10
- MERCHANTABLITY OR NON-INFRINGEMENT.
11
-
12
- See the Apache Version 2.0 License for specific language governing permissions
13
- and limitations under the License.
14
- ***************************************************************************** */var te;(function(s){(function(n){var t=typeof Kt=="object"?Kt:typeof self=="object"?self:typeof this=="object"?this:Function("return this;")(),e=r(s);typeof t.Reflect>"u"?t.Reflect=s:e=r(t.Reflect,e),n(e);function r(i,a){return function(h,l){typeof i[h]!="function"&&Object.defineProperty(i,h,{configurable:!0,writable:!0,value:l}),a&&a(h,l)}}})(function(n){var t=Object.prototype.hasOwnProperty,e=typeof Symbol=="function",r=e&&typeof Symbol.toPrimitive<"u"?Symbol.toPrimitive:"@@toPrimitive",i=e&&typeof Symbol.iterator<"u"?Symbol.iterator:"@@iterator",a=typeof Object.create=="function",h={__proto__:[]}instanceof Array,l=!a&&!h,d={create:a?function(){return Jt(Object.create(null))}:h?function(){return Jt({__proto__:null})}:function(){return Jt({})},has:l?function(o,c){return t.call(o,c)}:function(o,c){return c in o},get:l?function(o,c){return t.call(o,c)?o[c]:void 0}:function(o,c){return o[c]}},_=Object.getPrototypeOf(Function),b=typeof process=="object"&&process.env&&process.env.REFLECT_METADATA_USE_MAP_POLYFILL==="true",O=!b&&typeof Map=="function"&&typeof Map.prototype.entries=="function"?Map:tn(),j=!b&&typeof Set=="function"&&typeof Set.prototype.entries=="function"?Set:en(),S=!b&&typeof WeakMap=="function"?WeakMap:sn(),R=new S;function M(o,c,u,p){if(L(u)){if(!pe(o))throw new TypeError;if(!fe(c))throw new TypeError;return ot(o,c)}else{if(!pe(o))throw new TypeError;if(!N(c))throw new TypeError;if(!N(p)&&!L(p)&&!at(p))throw new TypeError;return at(p)&&(p=void 0),u=X(u),Bs(o,c,u,p)}}n("decorate",M);function Y(o,c){function u(p,g){if(!N(p))throw new TypeError;if(!L(g)&&!qs(g))throw new TypeError;he(o,c,p,g)}return u}n("metadata",Y);function Z(o,c,u,p){if(!N(u))throw new TypeError;return L(p)||(p=X(p)),he(o,c,u,p)}n("defineMetadata",Z);function tt(o,c,u){if(!N(c))throw new TypeError;return L(u)||(u=X(u)),ie(o,c,u)}n("hasMetadata",tt);function it(o,c,u){if(!N(c))throw new TypeError;return L(u)||(u=X(u)),Dt(o,c,u)}n("hasOwnMetadata",it);function k(o,c,u){if(!N(c))throw new TypeError;return L(u)||(u=X(u)),oe(o,c,u)}n("getMetadata",k);function F(o,c,u){if(!N(c))throw new TypeError;return L(u)||(u=X(u)),ae(o,c,u)}n("getOwnMetadata",F);function A(o,c){if(!N(o))throw new TypeError;return L(c)||(c=X(c)),ce(o,c)}n("getMetadataKeys",A);function D(o,c){if(!N(o))throw new TypeError;return L(c)||(c=X(c)),le(o,c)}n("getOwnMetadataKeys",D);function B(o,c,u){if(!N(c))throw new TypeError;L(u)||(u=X(u));var p=wt(c,u,!1);if(L(p)||!p.delete(o))return!1;if(p.size>0)return!0;var g=R.get(c);return g.delete(u),g.size>0||R.delete(c),!0}n("deleteMetadata",B);function ot(o,c){for(var u=o.length-1;u>=0;--u){var p=o[u],g=p(c);if(!L(g)&&!at(g)){if(!fe(g))throw new TypeError;c=g}}return c}function Bs(o,c,u,p){for(var g=o.length-1;g>=0;--g){var H=o[g],y=H(c,u,p);if(!L(y)&&!at(y)){if(!N(y))throw new TypeError;p=y}}return p}function wt(o,c,u){var p=R.get(o);if(L(p)){if(!u)return;p=new O,R.set(o,p)}var g=p.get(c);if(L(g)){if(!u)return;g=new O,p.set(c,g)}return g}function ie(o,c,u){var p=Dt(o,c,u);if(p)return!0;var g=Ut(c);return at(g)?!1:ie(o,g,u)}function Dt(o,c,u){var p=wt(c,u,!1);return L(p)?!1:Gs(p.has(o))}function oe(o,c,u){var p=Dt(o,c,u);if(p)return ae(o,c,u);var g=Ut(c);if(!at(g))return oe(o,g,u)}function ae(o,c,u){var p=wt(c,u,!1);if(!L(p))return p.get(o)}function he(o,c,u,p){var g=wt(u,p,!0);g.set(o,c)}function ce(o,c){var u=le(o,c),p=Ut(o);if(p===null)return u;var g=ce(p,c);if(g.length<=0)return u;if(u.length<=0)return g;for(var H=new j,y=[],m=0,v=u;m<v.length;m++){var $=v[m],C=H.has($);C||(H.add($),y.push($))}for(var Q=0,ge=g;Q<ge.length;Q++){var $=ge[Q],C=H.has($);C||(H.add($),y.push($))}return y}function le(o,c){var u=[],p=wt(o,c,!1);if(L(p))return u;for(var g=p.keys(),H=Ys(g),y=0;;){var m=Qs(H);if(!m)return u.length=y,u;var v=Zs(m);try{u[y]=v}catch($){try{Ks(H)}finally{throw $}}y++}}function ue(o){if(o===null)return 1;switch(typeof o){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return o===null?1:6;default:return 6}}function L(o){return o===void 0}function at(o){return o===null}function zs(o){return typeof o=="symbol"}function N(o){return typeof o=="object"?o!==null:typeof o=="function"}function Fs(o,c){switch(ue(o)){case 0:return o;case 1:return o;case 2:return o;case 3:return o;case 4:return o;case 5:return o}var u=c===3?"string":c===5?"number":"default",p=de(o,r);if(p!==void 0){var g=p.call(o,u);if(N(g))throw new TypeError;return g}return Ws(o,u==="default"?"number":u)}function Ws(o,c){if(c==="string"){var u=o.toString;if(ht(u)){var p=u.call(o);if(!N(p))return p}var g=o.valueOf;if(ht(g)){var p=g.call(o);if(!N(p))return p}}else{var g=o.valueOf;if(ht(g)){var p=g.call(o);if(!N(p))return p}var H=o.toString;if(ht(H)){var p=H.call(o);if(!N(p))return p}}throw new TypeError}function Gs(o){return!!o}function Xs(o){return""+o}function X(o){var c=Fs(o,3);return zs(c)?c:Xs(c)}function pe(o){return Array.isArray?Array.isArray(o):o instanceof Object?o instanceof Array:Object.prototype.toString.call(o)==="[object Array]"}function ht(o){return typeof o=="function"}function fe(o){return typeof o=="function"}function qs(o){switch(ue(o)){case 3:return!0;case 4:return!0;default:return!1}}function de(o,c){var u=o[c];if(u!=null){if(!ht(u))throw new TypeError;return u}}function Ys(o){var c=de(o,i);if(!ht(c))throw new TypeError;var u=c.call(o);if(!N(u))throw new TypeError;return u}function Zs(o){return o.value}function Qs(o){var c=o.next();return c.done?!1:c}function Ks(o){var c=o.return;c&&c.call(o)}function Ut(o){var c=Object.getPrototypeOf(o);if(typeof o!="function"||o===_||c!==_)return c;var u=o.prototype,p=u&&Object.getPrototypeOf(u);if(p==null||p===Object.prototype)return c;var g=p.constructor;return typeof g!="function"||g===o?c:g}function tn(){var o={},c=[],u=function(){function y(m,v,$){this._index=0,this._keys=m,this._values=v,this._selector=$}return y.prototype["@@iterator"]=function(){return this},y.prototype[i]=function(){return this},y.prototype.next=function(){var m=this._index;if(m>=0&&m<this._keys.length){var v=this._selector(this._keys[m],this._values[m]);return m+1>=this._keys.length?(this._index=-1,this._keys=c,this._values=c):this._index++,{value:v,done:!1}}return{value:void 0,done:!0}},y.prototype.throw=function(m){throw this._index>=0&&(this._index=-1,this._keys=c,this._values=c),m},y.prototype.return=function(m){return this._index>=0&&(this._index=-1,this._keys=c,this._values=c),{value:m,done:!0}},y}();return function(){function y(){this._keys=[],this._values=[],this._cacheKey=o,this._cacheIndex=-2}return Object.defineProperty(y.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),y.prototype.has=function(m){return this._find(m,!1)>=0},y.prototype.get=function(m){var v=this._find(m,!1);return v>=0?this._values[v]:void 0},y.prototype.set=function(m,v){var $=this._find(m,!0);return this._values[$]=v,this},y.prototype.delete=function(m){var v=this._find(m,!1);if(v>=0){for(var $=this._keys.length,C=v+1;C<$;C++)this._keys[C-1]=this._keys[C],this._values[C-1]=this._values[C];return this._keys.length--,this._values.length--,m===this._cacheKey&&(this._cacheKey=o,this._cacheIndex=-2),!0}return!1},y.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=o,this._cacheIndex=-2},y.prototype.keys=function(){return new u(this._keys,this._values,p)},y.prototype.values=function(){return new u(this._keys,this._values,g)},y.prototype.entries=function(){return new u(this._keys,this._values,H)},y.prototype["@@iterator"]=function(){return this.entries()},y.prototype[i]=function(){return this.entries()},y.prototype._find=function(m,v){return this._cacheKey!==m&&(this._cacheIndex=this._keys.indexOf(this._cacheKey=m)),this._cacheIndex<0&&v&&(this._cacheIndex=this._keys.length,this._keys.push(m),this._values.push(void 0)),this._cacheIndex},y}();function p(y,m){return y}function g(y,m){return m}function H(y,m){return[y,m]}}function en(){return function(){function o(){this._map=new O}return Object.defineProperty(o.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),o.prototype.has=function(c){return this._map.has(c)},o.prototype.add=function(c){return this._map.set(c,c),this},o.prototype.delete=function(c){return this._map.delete(c)},o.prototype.clear=function(){this._map.clear()},o.prototype.keys=function(){return this._map.keys()},o.prototype.values=function(){return this._map.values()},o.prototype.entries=function(){return this._map.entries()},o.prototype["@@iterator"]=function(){return this.keys()},o.prototype[i]=function(){return this.keys()},o}()}function sn(){var o=16,c=d.create(),u=p();return function(){function v(){this._key=p()}return v.prototype.has=function($){var C=g($,!1);return C!==void 0?d.has(C,this._key):!1},v.prototype.get=function($){var C=g($,!1);return C!==void 0?d.get(C,this._key):void 0},v.prototype.set=function($,C){var Q=g($,!0);return Q[this._key]=C,this},v.prototype.delete=function($){var C=g($,!1);return C!==void 0?delete C[this._key]:!1},v.prototype.clear=function(){this._key=p()},v}();function p(){var v;do v="@@WeakMap@@"+m();while(d.has(c,v));return c[v]=!0,v}function g(v,$){if(!t.call(v,u)){if(!$)return;Object.defineProperty(v,u,{value:d.create()})}return v[u]}function H(v,$){for(var C=0;C<$;++C)v[C]=Math.random()*255|0;return v}function y(v){return typeof Uint8Array=="function"?typeof crypto<"u"?crypto.getRandomValues(new Uint8Array(v)):typeof msCrypto<"u"?msCrypto.getRandomValues(new Uint8Array(v)):H(new Uint8Array(v),v):H(new Array(v),v)}function m(){var v=y(o);v[6]=v[6]&79|64,v[8]=v[8]&191|128;for(var $="",C=0;C<o;++C){var Q=v[C];(C===4||C===6||C===8)&&($+="-"),Q<16&&($+="0"),$+=Q.toString(16).toLowerCase()}return $}}function Jt(o){return o.__=void 0,delete o.__,o}})})(te||(te={}));function Us(s){me(s,"svelte-1tmn7wo",'#liveroom-client-element.svelte-1tmn7wo.svelte-1tmn7wo{font-family:Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;line-height:1.5;font-weight:400;font-synthesis:none;text-rendering:optimizeLegibility;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;-webkit-text-size-adjust:100%}#users-container.svelte-1tmn7wo.svelte-1tmn7wo{z-index:99999;position:fixed;inset:0;overflow:hidden;pointer-events:none}.user.svelte-1tmn7wo.svelte-1tmn7wo{z-index:10;position:absolute;top:0;left:0;user-select:none;transform:translate(var(--x), var(--y))}.user.svelte-1tmn7wo .cursor.svelte-1tmn7wo{position:absolute;top:0;left:0;color:var(--color);transform-origin:top left;transform:rotate(6deg)}.user[data-isself="true"].svelte-1tmn7wo .cursor.svelte-1tmn7wo{display:none}.user-name.svelte-1tmn7wo.svelte-1tmn7wo{padding:4px 10px;font-size:14px;line-height:20px;font-weight:600;color:black;background-color:var(--color);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;border-radius:9999px;box-shadow:0 1px 2px 0 rgb(0 0 0 / 0.05)}.user.svelte-1tmn7wo .user-name.svelte-1tmn7wo{position:absolute;top:20px;left:16px}.user[data-isself="true"].svelte-1tmn7wo .user-name.svelte-1tmn7wo{display:none}.user.svelte-1tmn7wo .halo.svelte-1tmn7wo{transform:scale(0);z-index:-1;position:absolute;top:-60px;left:-60px;width:120px;height:120px;border-radius:9999px;background-color:var(--color);opacity:0.25;transition:transform 100ms ease-out;box-shadow:0 1px 2px 0 rgb(0 0 0 / 0.05)}.user.svelte-1tmn7wo .halo[data-show="true"].svelte-1tmn7wo{transform:scale(1)}')}function ee(s,n,t){const e=s.slice();return e[18]=n[t],e}function se(s){let n,t=[],e=new Map,r=Xt(Object.values(s[0]));const i=a=>a[18].id;for(let a=0;a<r.length;a+=1){let h=ee(s,r,a),l=i(h);e.set(l,t[a]=ne(l,h))}return{c(){n=K("div");for(let a=0;a<t.length;a+=1)t[a].c();x(n,"id","users-container"),x(n,"class","svelte-1tmn7wo")},m(a,h){_t(a,n,h);for(let l=0;l<t.length;l+=1)t[l]&&t[l].m(n,null)},p(a,h){h&13&&(r=Xt(Object.values(a[0])),t=Me(t,h,i,1,a,r,e,n,Se,ne,null,ee))},d(a){a&&lt(n);for(let h=0;h<t.length;h+=1)t[h].d()}}}function ne(s,n){let t,e,r,i,a,h=n[18].name+"",l,d,_,b,O,j,S;return{key:s,first:null,c(){t=K("div"),e=Bt("svg"),r=Bt("path"),i=Ot(),a=K("span"),l=zt(h),d=Ot(),_=K("div"),O=Ot(),x(r,"d","M2.2706 0.0593359L25.4277 8.05957H25.45926C25.65896 8.13153 25.83096 8.25952 25.95221 8.42653C26.07357 8.59354 26.13851 8.79166 26.13851 8.99459C26.13851 9.19751 26.07357 9.39564 25.95221 9.56265C25.83096 9.72966 25.65896 9.85765 25.45926 9.92962L15.3543 13.7698L11.3124 23.37C11.2344 23.5561 11.0994 23.7156 10.9248 23.828C10.7503 23.9402 10.5443 24.0002 10.3335 24C10.1172 24 9.9061 23.9365 9.7291 23.8184C9.552 23.7004 9.4176 23.5332 9.344 23.34L0.9233 1.33937C0.8555 1.16076 0.8426 0.967504 0.8861 0.782189C0.9297 0.596873 1.0278 0.427163 1.1691 0.292901C1.3105 0.158639 1.4891 0.0653762 1.6841 0.0240151C1.8792 -0.0173461 2.0826 -0.00509504 2.2706 0.0593359Z"),x(e,"width","23"),x(e,"viewBox","0 0 27 24"),x(e,"fill","currentColor"),x(e,"aria-hidden","true"),x(e,"xmlns","http://www.w3.org/2000/svg"),x(e,"class","cursor svelte-1tmn7wo"),x(a,"class","user-name svelte-1tmn7wo"),x(_,"class","halo svelte-1tmn7wo"),x(_,"data-show",b=(n[18].id==n[2].id&&n[18].is_shift_key_down||n[18].id!=n[2].id&&(n[18].is_shift_key_down||n[18].is_mouse_down))&&n[3]>1),x(t,"id",j="user-"+n[18].id),x(t,"class","user svelte-1tmn7wo"),x(t,"data-isself",S=n[18].id==n[2].id),et(t,"--color",n[18].color),et(t,"--x",parseFloat(n[18].x)+"vw"),et(t,"--y",parseFloat(n[18].y)+"vh"),this.first=t},m(R,M){_t(R,t,M),W(t,e),W(e,r),W(t,i),W(t,a),W(a,l),W(t,d),W(t,_),W(t,O)},p(R,M){n=R,M&1&&h!==(h=n[18].name+"")&&Ee(l,h),M&13&&b!==(b=(n[18].id==n[2].id&&n[18].is_shift_key_down||n[18].id!=n[2].id&&(n[18].is_shift_key_down||n[18].is_mouse_down))&&n[3]>1)&&x(_,"data-show",b),M&1&&j!==(j="user-"+n[18].id)&&x(t,"id",j),M&5&&S!==(S=n[18].id==n[2].id)&&x(t,"data-isself",S),M&1&&et(t,"--color",n[18].color),M&1&&et(t,"--x",parseFloat(n[18].x)+"vw"),M&1&&et(t,"--y",parseFloat(n[18].y)+"vh")},d(R){R&&lt(t)}}}function Js(s){let n,t=s[2]&&s[0]&&se(s);return{c(){n=K("div"),t&&t.c(),x(n,"id","liveroom-client-element"),x(n,"class","svelte-1tmn7wo")},m(e,r){_t(e,n,r),t&&t.m(n,null),s[7](n)},p(e,[r]){e[2]&&e[0]?t?t.p(e,r):(t=se(e),t.c(),t.m(n,null)):t&&(t.d(1),t=null)},i:P,o:P,d(e){e&&lt(n),t&&t.d(),s[7](null)}}}function Vs(s,n,t){let{url:e}=n,{room_id:r}=n,{user_name:i}=n,a,h,l,d,_;Ce(async()=>{const k=new URLSearchParams(window.location.search),F=k.get("_liveroom"),A=F==null?void 0:F.split("https://meet.google.com/");let D=A==null?void 0:A[0];!!(A!=null&&A[1])&&(D=A[1].split("?")[0]),t(4,r=D||r),t(5,i=k.get("_liveroom_user_name")),b()}),ke(()=>{O()});function b(){h=new Ds({url:e,topic:`liveroom-livestate:${r}`,params:{room_id:r,user_name:i,current_url:window.origin,inner_width:window.innerWidth,inner_height:window.innerHeight}}),h.connect(),h.addEventListener("livestate-change",({detail:{state:k}})=>{t(4,r=k.room_id),t(2,l=k.me),t(0,d=k.users)}),window.addEventListener("mousemove",j),window.addEventListener("mousedown",S),window.addEventListener("mouseup",R),window.addEventListener("keydown",Y),window.addEventListener("keyup",Z),window.addEventListener("resize",tt)}function O(){window.removeEventListener("resize",tt),window.removeEventListener("keyup",Z),window.removeEventListener("keydown",Y),window.removeEventListener("mouseup",R),window.removeEventListener("mousedown",S),window.removeEventListener("mousemove",j),h==null||h.disconnect()}function j(k){h&&(l!=null&&l.id)&&h.dispatchEvent(new CustomEvent("mouse_move",{detail:{user_id:l.id,x:Number(k.clientX/window.innerWidth*100).toFixed(2),y:Number(k.clientY/window.innerHeight*100).toFixed(2)}}))}function S(){h&&(l!=null&&l.id)&&h.dispatchEvent(new CustomEvent("mouse_down",{detail:{user_id:l.id}}))}function R(){h&&(l!=null&&l.id)&&h.dispatchEvent(new CustomEvent("mouse_up",{detail:{user_id:l.id}}))}const M=["Shift"];function Y(k){!k.repeat&&M.includes(k.key)&&h&&(l!=null&&l.id)&&h.dispatchEvent(new CustomEvent("key_down",{detail:{key:k.key,user_id:l.id}}))}function Z(k){M.includes(k.key)&&h&&(l!=null&&l.id)&&h.dispatchEvent(new CustomEvent("key_up",{detail:{key:k.key,user_id:l.id}}))}function tt(){h&&(l!=null&&l.id)&&h.dispatchEvent(new CustomEvent("window_resize",{detail:{inner_width:window.innerWidth,inner_height:window.innerHeight,user_id:l.id}}))}function it(k){jt[k?"unshift":"push"](()=>{a=k,t(1,a)})}return s.$$set=k=>{"url"in k&&t(6,e=k.url),"room_id"in k&&t(4,r=k.room_id),"user_name"in k&&t(5,i=k.user_name)},s.$$.update=()=>{s.$$.dirty&1&&t(3,_=Object.keys(d||{}).length)},[d,a,l,_,r,i,e,it]}class re extends Ie{constructor(n){super(),He(this,n,Vs,Js,ve,{url:6,room_id:4,user_name:5},Us)}get url(){return this.$$.ctx[6]}set url(n){this.$$set({url:n}),ft()}get room_id(){return this.$$.ctx[4]}set room_id(n){this.$$set({room_id:n}),ft()}get user_name(){return this.$$.ctx[5]}set user_name(n){this.$$set({user_name:n}),ft()}}return customElements.define("liveroom-client-element",Pe(re,{url:{},room_id:{},user_name:{}},[],[],!0)),re});