playhtml 2.0.11 → 2.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
4
4
 
5
+ ## [Unreleased]
6
+
7
+ **BREAKING CHANGES**
8
+
9
+ - deprecated using non-object values as `defaultData` for elements. If you were using a single value before, instead, use an object with a `value` key. e.g. `defaultData: { value: "my value" }`. This allows for easier extension of the data in the future.
10
+ - deprecated `playhtml.init()` automatically being called to avoid side-effects upon import. This has been replaced with a new `init` file that you can directly import if you'd like to auto-initialize without any settings.
11
+
5
12
  ## 2.0.7 - 2023-10-02
6
13
 
7
14
  - upgrading y-partykit and yjs to latest for improved performance
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # <a href="https://playhtml.fun">playhtml</a> 🛝🌐 [![npm release](https://img.shields.io/npm/v/playhtml?color=%23ff980c)](https://www.npmjs.com/package/playhtml) [![Downloads](https://img.shields.io/npm/dm/playhtml)](https://www.npmjs.com/package/spencerc99/playhtml) [![Size](https://img.shields.io/bundlephobia/min/playhtml?color=%23c6e1ea)](https://www.npmjs.com/package/spencerc99/playhtml)
1
+ # <a href="https://playhtml.fun">playhtml</a> 🛝🌐 [![npm release](https://img.shields.io/npm/v/playhtml?color=%23ff980c)](https://www.npmjs.com/package/playhtml) [![Downloads](https://img.shields.io/npm/dm/playhtml)](https://www.npmjs.com/package/playhtml) [![Size](https://img.shields.io/bundlephobia/min/playhtml?color=%23c6e1ea)](https://www.npmjs.com/package/playhtml)
2
2
 
3
3
  _interactive, collaborative html elements with a single data attribute_
4
4
 
@@ -14,6 +14,11 @@ If you enjoy this, please consider [sponsoring the project or sending a small do
14
14
 
15
15
  ## Usage
16
16
 
17
+ Head to the proper section depending on your technology preference:
18
+
19
+ - [vanilla html / simple browser usage](#vanilla-html--simple-browser-usage)
20
+ - [react / next.js / other frameworks](#react--nextjs--other-frameworks)
21
+
17
22
  ### vanilla html / simple browser usage
18
23
 
19
24
  To use this library, you can import the library and the associated styles from a CDN (in this case we will use [unpkg.com](https://unpkg.com)). Please make sure to do this after all the HTML elements on the page and ensure that the HTML elements you are "magic-ifying" have an `id` set.
@@ -30,7 +35,7 @@ To use this library, you can import the library and the associated styles from a
30
35
  <!-- INVALID EXAMPLE <img src="https://media2.giphy.com/media/lL7A3Li0YtFHq/giphy.gif?cid=ecf05e47ah89o71gzz7ke7inrgb1ai1xcbrjnqdf7o890118&ep=v1_stickers_search&rid=giphy.gif" can-move /> -->
31
36
  <!-- import the script -->
32
37
  <script type="module">
33
- import "https://unpkg.com/playhtml";
38
+ import "https://unpkg.com/playhtml@latest";
34
39
  playhtml.init();
35
40
  // Optionally you could customize the room and host, like so:
36
41
  // playhtml.init({
@@ -38,7 +43,10 @@ To use this library, you can import the library and the associated styles from a
38
43
  // host: "mypartykit.user.partykit.dev"
39
44
  // })
40
45
  </script>
41
- <link rel="stylesheet" href="https://unpkg.com/playhtml/dist/style.css" />
46
+ <link
47
+ rel="stylesheet"
48
+ href="https://unpkg.com/playhtml@latest/dist/style.css"
49
+ />
42
50
  </body>
43
51
  ```
44
52
 
@@ -46,7 +54,7 @@ If you have dynamic elements that are hydrated after the initial load, you can c
46
54
 
47
55
  ```html
48
56
  <script type="module">
49
- import { playhtml } from "https://unpkg.com/playhtml";
57
+ import { playhtml } from "https://unpkg.com/playhtml@latest";
50
58
  const newPlayElement = document.createElement("div");
51
59
  newPlayElement.id = "newPlayElement";
52
60
  playhtml.setupPlayElement(newPlayElement);
@@ -175,10 +183,13 @@ https://github.com/spencerc99/playhtml/assets/14796580/fae669b1-b3e2-404e-bd7a-3
175
183
 
176
184
  <!-- Import playhtml -->
177
185
  <script type="module">
178
- import "https://unpkg.com/playhtml";
186
+ import "https://unpkg.com/playhtml@latest";
179
187
  playhtml.init();
180
188
  </script>
181
- <link rel="stylesheet" href="https://unpkg.com/playhtml/dist/style.css" />
189
+ <link
190
+ rel="stylesheet"
191
+ href="https://unpkg.com/playhtml@latest/dist/style.css"
192
+ />
182
193
  ```
183
194
 
184
195
  See all supported properties in the `ElementInitializer` [object in `types.ts`](https://github.com/spencerc99/playhtml/blob/main/src/types.ts#L13).
@@ -229,6 +240,10 @@ Creates an element that can be resized using a `scale` `transform`. Clicking the
229
240
 
230
241
  Creates a rotatable element using a `rotate` `transform` on the element. Dragging the element to the left or right will rotate it counter-clockwise and clockwise respectively.
231
242
 
243
+ ## Data Policy
244
+
245
+ Currently all data is stored by a [Partykit](https://partykit.dev) instance under my account and is not encrypted. This means that anyone with the room name can access the data. In the future, I'd like to enable providing your own custom persistence options via object storage providers (or any generic service that can accept a POST endpoint with a dump of the data).
246
+
232
247
  ## Contributing
233
248
 
234
249
  See [CONTRIBUTING.md](https://github.com/spencerc99/playhtml/blob/main/CONTRIBUTING.md).
@@ -0,0 +1 @@
1
+ "use strict";const e=require("./playhtml.cjs.js");e.playhtml.init({});const t=document.createElement("link");t.rel="stylesheet";t.href="https://unpkg.com/playhtml@latest/dist/style.css";document.head.appendChild(t);
package/dist/init.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { }
@@ -0,0 +1,6 @@
1
+ import { playhtml as e } from "./playhtml.es.js";
2
+ e.init({});
3
+ const t = document.createElement("link");
4
+ t.rel = "stylesheet";
5
+ t.href = "https://unpkg.com/playhtml@latest/dist/style.css";
6
+ document.head.appendChild(t);
package/dist/main.d.ts CHANGED
@@ -55,7 +55,7 @@ declare class ElementHandler<T = any, U = any, V = any> {
55
55
  reset(): void;
56
56
  }
57
57
 
58
- declare interface InitOptions {
58
+ export declare interface InitOptions {
59
59
  room?: string;
60
60
  host?: string;
61
61
  extraCapabilities?: Record<string, ElementInitializer>;
@@ -67,6 +67,7 @@ export declare const playhtml: PlayHTMLComponents;
67
67
 
68
68
  declare interface PlayHTMLComponents {
69
69
  init: typeof initPlayHTML;
70
+ setupPlayElements: typeof setupElements;
70
71
  setupPlayElement: typeof setupPlayElement;
71
72
  removePlayElement: typeof removePlayElement;
72
73
  setupPlayElementForTag: typeof setupPlayElementForTag;
@@ -76,6 +77,14 @@ declare interface PlayHTMLComponents {
76
77
 
77
78
  declare function removePlayElement(element: Element | null): void;
78
79
 
80
+ /**
81
+ * Sets up any playhtml elements that are currently on the page.
82
+ *
83
+ * Should be called only once. If you'd like to set up new elements, use `setupPlayElement`, which is exposed
84
+ * on the `playhtml` object on `window`.
85
+ */
86
+ declare function setupElements(): void;
87
+
79
88
  declare function setupPlayElement(element: Element): void;
80
89
 
81
90
  /**
@@ -0,0 +1,11 @@
1
+ "use strict";var gr=Object.defineProperty;var pr=(n,t,e)=>t in n?gr(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var y=(n,t,e)=>(pr(n,typeof t!="symbol"?t+"":t,e),e),Dn=(n,t,e)=>{if(!t.has(n))throw TypeError("Cannot "+e)};var Wt=(n,t,e)=>(Dn(n,t,"read from private field"),e?e.call(n):t.get(n)),En=(n,t,e)=>{if(t.has(n))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(n):t.set(n,e)},Cn=(n,t,e,s)=>(Dn(n,t,"write to private field"),s?s.call(n,e):t.set(n,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Gt=1e6,wr="y-pk-batch",An=!1,mr=(n,t)=>{if(n.byteLength<=Gt){t(n);return}An||(console.warn("[y-partykit]","The Y.js update size exceeds 1MB, which is the maximum size for an individual update. The update will be split into chunks. This is an experimental feature.",`Message size: ${(n.byteLength/1e3/1e3).toFixed(1)}MB`),An=!0);const e=(Date.now()+Math.random()).toString(36).substring(10),s=Math.ceil(n.byteLength/Gt);t(Ln({id:e,type:"start",size:n.byteLength,count:s}));let r=0,i=0;for(let o=0;o<s;o++){const l=n.slice(Gt*o,Gt*(o+1));t(l),i+=1,r+=l.byteLength}t(Ln({id:e,type:"end",size:r,count:i}))};function Ln(n){return`${wr}#${JSON.stringify(n)}`}const O=()=>new Map,Ne=n=>{const t=O();return n.forEach((e,s)=>{t.set(s,e)}),t},J=(n,t,e)=>{let s=n.get(t);return s===void 0&&n.set(t,s=e()),s},yr=(n,t)=>{const e=[];for(const[s,r]of n)e.push(t(r,s));return e},br=(n,t)=>{for(const[e,s]of n)if(t(s,e))return!0;return!1},lt=()=>new Set,Ee=n=>n[n.length-1],kr=(n,t)=>{for(let e=0;e<t.length;e++)n.push(t[e])},tt=Array.from,Sr=Array.isArray;class ge{constructor(){this._observers=O()}on(t,e){J(this._observers,t,lt).add(e)}once(t,e){const s=(...r)=>{this.off(t,s),e(...r)};this.on(t,s)}off(t,e){const s=this._observers.get(t);s!==void 0&&(s.delete(e),s.size===0&&this._observers.delete(t))}emit(t,e){return tt((this._observers.get(t)||O()).values()).forEach(s=>s(...e))}destroy(){this._observers=O()}}const Y=Math.floor,te=Math.abs,Pe=(n,t)=>n<t?n:t,ft=(n,t)=>n>t?n:t,_r=Math.pow,es=n=>n!==0?n<0:1/n<0,Dr=String.fromCharCode,Er=n=>n.toLowerCase(),Cr=/^\s*/g,Ar=n=>n.replace(Cr,""),Lr=/([A-Z])/g,In=(n,t)=>Ar(n.replace(Lr,e=>`${t}${Er(e)}`)),Ir=n=>{const t=unescape(encodeURIComponent(n)),e=t.length,s=new Uint8Array(e);for(let r=0;r<e;r++)s[r]=t.codePointAt(r);return s},Tt=typeof TextEncoder<"u"?new TextEncoder:null,Mr=n=>Tt.encode(n),vr=Tt?Mr:Ir;let vt=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});vt&&vt.decode(new Uint8Array).length===1&&(vt=null);const Mn=n=>n===void 0?null:n;class xr{constructor(){this.map=new Map}setItem(t,e){this.map.set(t,e)}getItem(t){return this.map.get(t)}}let ns=new xr,qe=!0;try{typeof localStorage<"u"&&(ns=localStorage,qe=!1)}catch{}const ss=ns,Ur=n=>qe||addEventListener("storage",n),Tr=n=>qe||removeEventListener("storage",n),Or=Object.assign,Rr=Object.keys,Br=(n,t)=>{for(const e in n)t(n[e],e)},Nr=(n,t)=>{const e=[];for(const s in n)e.push(t(n[s],s));return e},re=n=>Rr(n).length,Fr=n=>{for(const t in n)return!1;return!0},Vr=(n,t)=>{for(const e in n)if(!t(n[e],e))return!1;return!0},rs=(n,t)=>Object.prototype.hasOwnProperty.call(n,t),Hr=(n,t)=>n===t||re(n)===re(t)&&Vr(n,(e,s)=>(e!==void 0||rs(t,s))&&t[s]===e),Ze=(n,t,e=0)=>{try{for(;e<n.length;e++)n[e](...t)}finally{e<n.length&&Ze(n,t,e+1)}},$r=n=>n,jr=(n,t)=>n===t,xt=(n,t)=>{if(n==null||t==null)return jr(n,t);if(n.constructor!==t.constructor)return!1;if(n===t)return!0;switch(n.constructor){case ArrayBuffer:n=new Uint8Array(n),t=new Uint8Array(t);case Uint8Array:{if(n.byteLength!==t.byteLength)return!1;for(let e=0;e<n.length;e++)if(n[e]!==t[e])return!1;break}case Set:{if(n.size!==t.size)return!1;for(const e of n)if(!t.has(e))return!1;break}case Map:{if(n.size!==t.size)return!1;for(const e of n.keys())if(!t.has(e)||!xt(n.get(e),t.get(e)))return!1;break}case Object:if(re(n)!==re(t))return!1;for(const e in n)if(!rs(n,e)||!xt(n[e],t[e]))return!1;break;case Array:if(n.length!==t.length)return!1;for(let e=0;e<n.length;e++)if(!xt(n[e],t[e]))return!1;break;default:return!1}return!0},Kr=(n,t)=>t.includes(n),St=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name),is=typeof window<"u"&&typeof document<"u"&&!St;let R;const zr=()=>{if(R===void 0)if(St){R=O();const n=process.argv;let t=null;for(let e=0;e<n.length;e++){const s=n[e];s[0]==="-"?(t!==null&&R.set(t,""),t=s):t!==null&&(R.set(t,s),t=null)}t!==null&&R.set(t,"")}else typeof location=="object"?(R=O(),(location.search||"?").slice(1).split("&").forEach(n=>{if(n.length!==0){const[t,e]=n.split("=");R.set(`--${In(t,"-")}`,e),R.set(`-${In(t,"-")}`,e)}})):R=O();return R},Fe=n=>zr().has(n),Ve=n=>Mn(St?process.env[n.toUpperCase()]:ss.getItem(n)),Yr=n=>Fe("--"+n)||Ve(n)!==null;Yr("production");const vn=St&&Kr(process.env.FORCE_COLOR,["true","1","2"]),Xr=!Fe("no-colors")&&(!St||process.stdout.isTTY||vn)&&(!St||Fe("color")||vn||Ve("COLORTERM")!==null||(Ve("TERM")||"").includes("color")),xn=1,Un=2,Ce=4,Ae=8,Ot=32,z=64,x=128,pe=31,He=63,it=127,Jr=2147483647,os=Number.MAX_SAFE_INTEGER,Wr=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&Y(n)===n),X=n=>new Error(n),B=()=>{throw X("Method unimplemented")},V=()=>{throw X("Unexpected case")},ls=X("Unexpected end of array"),cs=X("Integer out of Range");class we{constructor(t){this.arr=t,this.pos=0}}const nt=n=>new we(n),Gr=n=>n.pos!==n.arr.length,Pr=(n,t)=>{const e=en(n.arr.buffer,n.pos+n.arr.byteOffset,t);return n.pos+=t,e},M=n=>Pr(n,m(n)),_t=n=>n.arr[n.pos++],m=n=>{let t=0,e=1;const s=n.arr.length;for(;n.pos<s;){const r=n.arr[n.pos++];if(t=t+(r&it)*e,e*=128,r<x)return t;if(t>os)throw cs}throw ls},Qe=n=>{let t=n.arr[n.pos++],e=t&He,s=64;const r=(t&z)>0?-1:1;if(!(t&x))return r*e;const i=n.arr.length;for(;n.pos<i;){if(t=n.arr[n.pos++],e=e+(t&it)*s,s*=128,t<x)return r*e;if(e>os)throw cs}throw ls},qr=n=>{let t=m(n);if(t===0)return"";{let e=String.fromCodePoint(_t(n));if(--t<100)for(;t--;)e+=String.fromCodePoint(_t(n));else for(;t>0;){const s=t<1e4?t:1e4,r=n.arr.subarray(n.pos,n.pos+s);n.pos+=s,e+=String.fromCodePoint.apply(null,r),t-=s}return decodeURIComponent(escape(e))}},Zr=n=>vt.decode(M(n)),Z=vt?Zr:qr,tn=(n,t)=>{const e=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,t);return n.pos+=t,e},Qr=n=>tn(n,4).getFloat32(0,!1),ti=n=>tn(n,8).getFloat64(0,!1),ei=n=>tn(n,8).getBigInt64(0,!1),ni=[n=>{},n=>null,Qe,Qr,ti,ei,n=>!1,n=>!0,Z,n=>{const t=m(n),e={};for(let s=0;s<t;s++){const r=Z(n);e[r]=Rt(n)}return e},n=>{const t=m(n),e=[];for(let s=0;s<t;s++)e.push(Rt(n));return e},M],Rt=n=>ni[127-_t(n)](n);class Tn extends we{constructor(t,e){super(t),this.reader=e,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),Gr(this)?this.count=m(this)+1:this.count=-1),this.count--,this.s}}class ee extends we{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=Qe(this);const t=es(this.s);this.count=1,t&&(this.s=-this.s,this.count=m(this)+2)}return this.count--,this.s}}class Le extends we{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=Qe(this),e=t&1;this.diff=Y(t/2),this.count=1,e&&(this.count=m(this)+2)}return this.s+=this.diff,this.count--,this.s}}class si{constructor(t){this.decoder=new ee(t),this.str=Z(this.decoder),this.spos=0}read(){const t=this.spos+this.decoder.read(),e=this.str.slice(this.spos,t);return this.spos=t,e}}const as=n=>new Uint8Array(n),en=(n,t,e)=>new Uint8Array(n,t,e),ri=n=>new Uint8Array(n),ii=n=>{let t="";for(let e=0;e<n.byteLength;e++)t+=Dr(n[e]);return btoa(t)},oi=n=>Buffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),li=n=>{const t=atob(n),e=as(t.length);for(let s=0;s<t.length;s++)e[s]=t.charCodeAt(s);return e},ci=n=>{const t=Buffer.from(n,"base64");return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)},ai=is?ii:oi,hi=is?li:ci,ui=n=>{const t=as(n.byteLength);return t.set(n),t};class $t{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const v=()=>new $t,nn=n=>{let t=n.cpos;for(let e=0;e<n.bufs.length;e++)t+=n.bufs[e].length;return t},S=n=>{const t=new Uint8Array(nn(n));let e=0;for(let s=0;s<n.bufs.length;s++){const r=n.bufs[s];t.set(r,e),e+=r.length}return t.set(en(n.cbuf.buffer,0,n.cpos),e),t},di=(n,t)=>{const e=n.cbuf.length;e-n.cpos<t&&(n.bufs.push(en(n.cbuf.buffer,0,n.cpos)),n.cbuf=new Uint8Array(ft(e,t)*2),n.cpos=0)},A=(n,t)=>{const e=n.cbuf.length;n.cpos===e&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(e*2),n.cpos=0),n.cbuf[n.cpos++]=t},$e=A,p=(n,t)=>{for(;t>it;)A(n,x|it&t),t=Y(t/128);A(n,it&t)},sn=(n,t)=>{const e=es(t);for(e&&(t=-t),A(n,(t>He?x:0)|(e?z:0)|He&t),t=Y(t/64);t>0;)A(n,(t>it?x:0)|it&t),t=Y(t/128)},je=new Uint8Array(3e4),fi=je.length/3,gi=(n,t)=>{if(t.length<fi){const e=Tt.encodeInto(t,je).written||0;p(n,e);for(let s=0;s<e;s++)A(n,je[s])}else D(n,vr(t))},pi=(n,t)=>{const e=unescape(encodeURIComponent(t)),s=e.length;p(n,s);for(let r=0;r<s;r++)A(n,e.codePointAt(r))},ot=Tt&&Tt.encodeInto?gi:pi,me=(n,t)=>{const e=n.cbuf.length,s=n.cpos,r=Pe(e-s,t.length),i=t.length-r;n.cbuf.set(t.subarray(0,r),s),n.cpos+=r,i>0&&(n.bufs.push(n.cbuf),n.cbuf=new Uint8Array(ft(e*2,i)),n.cbuf.set(t.subarray(r)),n.cpos=i)},D=(n,t)=>{p(n,t.byteLength),me(n,t)},rn=(n,t)=>{di(n,t);const e=new DataView(n.cbuf.buffer,n.cpos,t);return n.cpos+=t,e},wi=(n,t)=>rn(n,4).setFloat32(0,t,!1),mi=(n,t)=>rn(n,8).setFloat64(0,t,!1),yi=(n,t)=>rn(n,8).setBigInt64(0,t,!1),On=new DataView(new ArrayBuffer(4)),bi=n=>(On.setFloat32(0,n),On.getFloat32(0)===n),Bt=(n,t)=>{switch(typeof t){case"string":A(n,119),ot(n,t);break;case"number":Wr(t)&&te(t)<=Jr?(A(n,125),sn(n,t)):bi(t)?(A(n,124),wi(n,t)):(A(n,123),mi(n,t));break;case"bigint":A(n,122),yi(n,t);break;case"object":if(t===null)A(n,126);else if(Sr(t)){A(n,117),p(n,t.length);for(let e=0;e<t.length;e++)Bt(n,t[e])}else if(t instanceof Uint8Array)A(n,116),D(n,t);else{A(n,118);const e=Object.keys(t);p(n,e.length);for(let s=0;s<e.length;s++){const r=e[s];ot(n,r),Bt(n,t[r])}}break;case"boolean":A(n,t?120:121);break;default:A(n,127)}};class Rn extends $t{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&p(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const Bn=n=>{n.count>0&&(sn(n.encoder,n.count===1?n.s:-n.s),n.count>1&&p(n.encoder,n.count-2))};class ne{constructor(){this.encoder=new $t,this.s=0,this.count=0}write(t){this.s===t?this.count++:(Bn(this),this.count=1,this.s=t)}toUint8Array(){return Bn(this),S(this.encoder)}}const Nn=n=>{if(n.count>0){const t=n.diff*2+(n.count===1?0:1);sn(n.encoder,t),n.count>1&&p(n.encoder,n.count-2)}};class Ie{constructor(){this.encoder=new $t,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(Nn(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return Nn(this),S(this.encoder)}}class ki{constructor(){this.sarr=[],this.s="",this.lensE=new ne}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){const t=new $t;return this.sarr.push(this.s),this.s="",ot(t,this.sarr.join("")),me(t,this.lensE.toUint8Array()),S(t)}}const Si=crypto.getRandomValues.bind(crypto),hs=()=>Si(new Uint32Array(1))[0],_i=[1e7]+-1e3+-4e3+-8e3+-1e11,Di=()=>_i.replace(/[018]/g,n=>(n^hs()&15>>n/4).toString(16)),ct=Date.now,Dt=n=>new Promise(n);Promise.all.bind(Promise);class Ei{constructor(t,e){this.left=t,this.right=e}}const K=(n,t)=>new Ei(n,t);typeof DOMParser<"u"&&new DOMParser;const Ci=n=>yr(n,(t,e)=>`${e}:${t};`).join(""),W=Symbol,us=W(),ds=W(),Ai=W(),Li=W(),Ii=W(),fs=W(),Mi=W(),gs=W(),vi=W(),xi=n=>{const t=[];let e=0;for(;e<n.length;e++){const s=n[e];s.constructor===String||s.constructor===Number||s.constructor===Object&&t.push(JSON.stringify(s))}return t},Ui={[us]:K("font-weight","bold"),[ds]:K("font-weight","normal"),[Ai]:K("color","blue"),[Ii]:K("color","green"),[Li]:K("color","grey"),[fs]:K("color","red"),[Mi]:K("color","purple"),[gs]:K("color","orange"),[vi]:K("color","black")},Ti=n=>{const t=[],e=[],s=O();let r=[],i=0;for(;i<n.length;i++){const o=n[i],l=Ui[o];if(l!==void 0)s.set(l.left,l.right);else if(o.constructor===String||o.constructor===Number){const c=Ci(s);i>0||c.length>0?(t.push("%c"+o),e.push(c)):t.push(o)}else break}for(i>0&&(r=e,r.unshift(t.join("")));i<n.length;i++){const o=n[i];o instanceof Symbol||r.push(o)}return r},Oi=Xr?Ti:xi,Ri=(...n)=>{console.log(...Oi(n)),Bi.forEach(t=>t.print(n))},Bi=lt(),ps=n=>({[Symbol.iterator](){return this},next:n}),Ni=(n,t)=>ps(()=>{let e;do e=n.next();while(!e.done&&!t(e.value));return e}),Me=(n,t)=>ps(()=>{const{done:e,value:s}=n.next();return{done:e,value:e?void 0:t(s)}});class on{constructor(t,e){this.clock=t,this.len=e}}class jt{constructor(){this.clients=new Map}}const ws=(n,t,e)=>t.clients.forEach((s,r)=>{const i=n.doc.store.clients.get(r);for(let o=0;o<s.length;o++){const l=s[o];vs(n,i,l.clock,l.len,e)}}),Fi=(n,t)=>{let e=0,s=n.length-1;for(;e<=s;){const r=Y((e+s)/2),i=n[r],o=i.clock;if(o<=t){if(t<o+i.len)return r;e=r+1}else s=r-1}return null},ms=(n,t)=>{const e=n.clients.get(t.client);return e!==void 0&&Fi(e,t.clock)!==null},ln=n=>{n.clients.forEach(t=>{t.sort((r,i)=>r.clock-i.clock);let e,s;for(e=1,s=1;e<t.length;e++){const r=t[s-1],i=t[e];r.clock+r.len>=i.clock?r.len=ft(r.len,i.clock+i.len-r.clock):(s<e&&(t[s]=i),s++)}t.length=s})},Vi=n=>{const t=new jt;for(let e=0;e<n.length;e++)n[e].clients.forEach((s,r)=>{if(!t.clients.has(r)){const i=s.slice();for(let o=e+1;o<n.length;o++)kr(i,n[o].clients.get(r)||[]);t.clients.set(r,i)}});return ln(t),t},ie=(n,t,e,s)=>{J(n.clients,t,()=>[]).push(new on(e,s))},Hi=()=>new jt,$i=n=>{const t=Hi();return n.clients.forEach((e,s)=>{const r=[];for(let i=0;i<e.length;i++){const o=e[i];if(o.deleted){const l=o.id.clock;let c=o.length;if(i+1<e.length)for(let a=e[i+1];i+1<e.length&&a.deleted;a=e[++i+1])c+=a.length;r.push(new on(l,c))}}r.length>0&&t.clients.set(s,r)}),t},At=(n,t)=>{p(n.restEncoder,t.clients.size),tt(t.clients.entries()).sort((e,s)=>s[0]-e[0]).forEach(([e,s])=>{n.resetDsCurVal(),p(n.restEncoder,e);const r=s.length;p(n.restEncoder,r);for(let i=0;i<r;i++){const o=s[i];n.writeDsClock(o.clock),n.writeDsLen(o.len)}})},cn=n=>{const t=new jt,e=m(n.restDecoder);for(let s=0;s<e;s++){n.resetDsCurVal();const r=m(n.restDecoder),i=m(n.restDecoder);if(i>0){const o=J(t.clients,r,()=>[]);for(let l=0;l<i;l++)o.push(new on(n.readDsClock(),n.readDsLen()))}}return t},Fn=(n,t,e)=>{const s=new jt,r=m(n.restDecoder);for(let i=0;i<r;i++){n.resetDsCurVal();const o=m(n.restDecoder),l=m(n.restDecoder),c=e.clients.get(o)||[],a=L(e,o);for(let h=0;h<l;h++){const d=n.readDsClock(),u=d+n.readDsLen();if(d<a){a<u&&ie(s,o,a,u-a);let f=H(c,d),g=c[f];for(!g.deleted&&g.id.clock<d&&(c.splice(f+1,0,de(t,g,d-g.id.clock)),f++);f<c.length&&(g=c[f++],g.id.clock<u);)g.deleted||(u<g.id.clock+g.length&&c.splice(f,0,de(t,g,u-g.id.clock)),g.delete(t))}else ie(s,o,d,u-d)}}if(s.clients.size>0){const i=new at;return p(i.restEncoder,0),At(i,s),i.toUint8Array()}return null},ys=hs;class gt extends ge{constructor({guid:t=Di(),collectionid:e=null,gc:s=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:o=!1,shouldLoad:l=!0}={}){super(),this.gc=s,this.gcFilter=r,this.clientID=ys(),this.guid=t,this.collectionid=e,this.share=new Map,this.store=new Is,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=l,this.autoLoad=o,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.whenLoaded=Dt(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const c=()=>Dt(a=>{const h=d=>{(d===void 0||d===!0)&&(this.off("sync",h),a())};this.on("sync",h)});this.on("sync",a=>{a===!1&&this.isSynced&&(this.whenSynced=c()),this.isSynced=a===void 0||a===!0,this.isLoaded||this.emit("load",[])}),this.whenSynced=c()}load(){const t=this._item;t!==null&&!this.shouldLoad&&k(t.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(tt(this.subdocs).map(t=>t.guid))}transact(t,e=null){return k(this,t,e)}get(t,e=I){const s=J(this.share,t,()=>{const i=new e;return i._integrate(this,null),i}),r=s.constructor;if(e!==I&&r!==e)if(r===I){const i=new e;i._map=s._map,s._map.forEach(o=>{for(;o!==null;o=o.left)o.parent=i}),i._start=s._start;for(let o=i._start;o!==null;o=o.right)o.parent=i;return i._length=s._length,this.share.set(t,i),i._integrate(this,null),i}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return s}getArray(t=""){return this.get(t,bt)}getText(t=""){return this.get(t,Ct)}getMap(t=""){return this.get(t,ht)}getXmlFragment(t=""){return this.get(t,ut)}toJSON(){const t={};return this.share.forEach((e,s)=>{t[s]=e.toJSON()}),t}destroy(){tt(this.subdocs).forEach(e=>e.destroy());const t=this._item;if(t!==null){this._item=null;const e=t.content;e.doc=new gt({guid:this.guid,...e.opts,shouldLoad:!1}),e.doc._item=t,k(t.parent.doc,s=>{const r=e.doc;t.deleted||s.subdocsAdded.add(r),s.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}on(t,e){super.on(t,e)}off(t,e){super.off(t,e)}}class bs{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return m(this.restDecoder)}readDsLen(){return m(this.restDecoder)}}class ks extends bs{readLeftID(){return b(m(this.restDecoder),m(this.restDecoder))}readRightID(){return b(m(this.restDecoder),m(this.restDecoder))}readClient(){return m(this.restDecoder)}readInfo(){return _t(this.restDecoder)}readString(){return Z(this.restDecoder)}readParentInfo(){return m(this.restDecoder)===1}readTypeRef(){return m(this.restDecoder)}readLen(){return m(this.restDecoder)}readAny(){return Rt(this.restDecoder)}readBuf(){return ui(M(this.restDecoder))}readJSON(){return JSON.parse(Z(this.restDecoder))}readKey(){return Z(this.restDecoder)}}class ji{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=m(this.restDecoder),this.dsCurrVal}readDsLen(){const t=m(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class Et extends ji{constructor(t){super(t),this.keys=[],m(t),this.keyClockDecoder=new Le(M(t)),this.clientDecoder=new ee(M(t)),this.leftClockDecoder=new Le(M(t)),this.rightClockDecoder=new Le(M(t)),this.infoDecoder=new Tn(M(t),_t),this.stringDecoder=new si(M(t)),this.parentInfoDecoder=new Tn(M(t),_t),this.typeRefDecoder=new ee(M(t)),this.lenDecoder=new ee(M(t))}readLeftID(){return new yt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new yt(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return Rt(this.restDecoder)}readBuf(){return M(this.restDecoder)}readJSON(){return Rt(this.restDecoder)}readKey(){const t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{const e=this.stringDecoder.read();return this.keys.push(e),e}}}class Ss{constructor(){this.restEncoder=v()}toUint8Array(){return S(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){p(this.restEncoder,t)}writeDsLen(t){p(this.restEncoder,t)}}class Kt extends Ss{writeLeftID(t){p(this.restEncoder,t.client),p(this.restEncoder,t.clock)}writeRightID(t){p(this.restEncoder,t.client),p(this.restEncoder,t.clock)}writeClient(t){p(this.restEncoder,t)}writeInfo(t){$e(this.restEncoder,t)}writeString(t){ot(this.restEncoder,t)}writeParentInfo(t){p(this.restEncoder,t?1:0)}writeTypeRef(t){p(this.restEncoder,t)}writeLen(t){p(this.restEncoder,t)}writeAny(t){Bt(this.restEncoder,t)}writeBuf(t){D(this.restEncoder,t)}writeJSON(t){ot(this.restEncoder,JSON.stringify(t))}writeKey(t){ot(this.restEncoder,t)}}class _s{constructor(){this.restEncoder=v(),this.dsCurrVal=0}toUint8Array(){return S(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const e=t-this.dsCurrVal;this.dsCurrVal=t,p(this.restEncoder,e)}writeDsLen(t){t===0&&V(),p(this.restEncoder,t-1),this.dsCurrVal+=t}}class at extends _s{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Ie,this.clientEncoder=new ne,this.leftClockEncoder=new Ie,this.rightClockEncoder=new Ie,this.infoEncoder=new Rn($e),this.stringEncoder=new ki,this.parentInfoEncoder=new Rn($e),this.typeRefEncoder=new ne,this.lenEncoder=new ne}toUint8Array(){const t=v();return p(t,0),D(t,this.keyClockEncoder.toUint8Array()),D(t,this.clientEncoder.toUint8Array()),D(t,this.leftClockEncoder.toUint8Array()),D(t,this.rightClockEncoder.toUint8Array()),D(t,S(this.infoEncoder)),D(t,this.stringEncoder.toUint8Array()),D(t,S(this.parentInfoEncoder)),D(t,this.typeRefEncoder.toUint8Array()),D(t,this.lenEncoder.toUint8Array()),me(t,S(this.restEncoder)),S(t)}writeLeftID(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}writeRightID(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}writeClient(t){this.clientEncoder.write(t)}writeInfo(t){this.infoEncoder.write(t)}writeString(t){this.stringEncoder.write(t)}writeParentInfo(t){this.parentInfoEncoder.write(t?1:0)}writeTypeRef(t){this.typeRefEncoder.write(t)}writeLen(t){this.lenEncoder.write(t)}writeAny(t){Bt(this.restEncoder,t)}writeBuf(t){D(this.restEncoder,t)}writeJSON(t){Bt(this.restEncoder,t)}writeKey(t){const e=this.keyMap.get(t);e===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(e)}}const Ki=(n,t,e,s)=>{s=ft(s,t[0].id.clock);const r=H(t,s);p(n.restEncoder,t.length-r),n.writeClient(e),p(n.restEncoder,s);const i=t[r];i.write(n,s-i.id.clock);for(let o=r+1;o<t.length;o++)t[o].write(n,0)},an=(n,t,e)=>{const s=new Map;e.forEach((r,i)=>{L(t,i)>r&&s.set(i,r)}),ye(t).forEach((r,i)=>{e.has(i)||s.set(i,0)}),p(n.restEncoder,s.size),tt(s.entries()).sort((r,i)=>i[0]-r[0]).forEach(([r,i])=>{Ki(n,t.clients.get(r),r,i)})},zi=(n,t)=>{const e=O(),s=m(n.restDecoder);for(let r=0;r<s;r++){const i=m(n.restDecoder),o=new Array(i),l=n.readClient();let c=m(n.restDecoder);e.set(l,{i:0,refs:o});for(let a=0;a<i;a++){const h=n.readInfo();switch(pe&h){case 0:{const d=n.readLen();o[a]=new U(b(l,c),d),c+=d;break}case 10:{const d=m(n.restDecoder);o[a]=new T(b(l,c),d),c+=d;break}default:{const d=(h&(z|x))===0,u=new E(b(l,c),null,(h&x)===x?n.readLeftID():null,null,(h&z)===z?n.readRightID():null,d?n.readParentInfo()?t.get(n.readString()):n.readLeftID():null,d&&(h&Ot)===Ot?n.readString():null,Gs(n,h));o[a]=u,c+=u.length}}}}return e},Yi=(n,t,e)=>{const s=[];let r=tt(e.keys()).sort((f,g)=>f-g);if(r.length===0)return null;const i=()=>{if(r.length===0)return null;let f=e.get(r[r.length-1]);for(;f.refs.length===f.i;)if(r.pop(),r.length>0)f=e.get(r[r.length-1]);else return null;return f};let o=i();if(o===null&&s.length===0)return null;const l=new Is,c=new Map,a=(f,g)=>{const w=c.get(f);(w==null||w>g)&&c.set(f,g)};let h=o.refs[o.i++];const d=new Map,u=()=>{for(const f of s){const g=f.id.client,w=e.get(g);w?(w.i--,l.clients.set(g,w.refs.slice(w.i)),e.delete(g),w.i=0,w.refs=[]):l.clients.set(g,[f]),r=r.filter(_=>_!==g)}s.length=0};for(;;){if(h.constructor!==T){const g=J(d,h.id.client,()=>L(t,h.id.client))-h.id.clock;if(g<0)s.push(h),a(h.id.client,h.id.clock-1),u();else{const w=h.getMissing(n,t);if(w!==null){s.push(h);const _=e.get(w)||{refs:[],i:0};if(_.refs.length===_.i)a(w,L(t,w)),u();else{h=_.refs[_.i++];continue}}else(g===0||g<h.length)&&(h.integrate(n,g),d.set(h.id.client,h.id.clock+h.length))}}if(s.length>0)h=s.pop();else if(o!==null&&o.i<o.refs.length)h=o.refs[o.i++];else{if(o=i(),o===null)break;h=o.refs[o.i++]}}if(l.clients.size>0){const f=new at;return an(f,l,new Map),p(f.restEncoder,0),{missing:c,update:f.toUint8Array()}}return null},Xi=(n,t)=>an(n,t.doc.store,t.beforeState),Ji=(n,t,e,s=new Et(n))=>k(t,r=>{r.local=!1;let i=!1;const o=r.doc,l=o.store,c=zi(s,o),a=Yi(r,l,c),h=l.pendingStructs;if(h){for(const[u,f]of h.missing)if(f<L(l,u)){i=!0;break}if(a){for(const[u,f]of a.missing){const g=h.missing.get(u);(g==null||g>f)&&h.missing.set(u,f)}h.update=oe([h.update,a.update])}}else l.pendingStructs=a;const d=Fn(s,r,l);if(l.pendingDs){const u=new Et(nt(l.pendingDs));m(u.restDecoder);const f=Fn(u,r,l);d&&f?l.pendingDs=oe([d,f]):l.pendingDs=d||f}else l.pendingDs=d;if(i){const u=l.pendingStructs.update;l.pendingStructs=null,Ds(r.doc,u)}},e,!1),Ds=(n,t,e,s=Et)=>{const r=nt(t);Ji(r,n,e,new s(r))},Es=(n,t,e)=>Ds(n,t,e,ks),Wi=(n,t,e=new Map)=>{an(n,t.store,e),At(n,$i(t.store))},Gi=(n,t=new Uint8Array([0]),e=new at)=>{const s=Cs(t);Wi(e,n,s);const r=[e.toUint8Array()];if(n.store.pendingDs&&r.push(n.store.pendingDs),n.store.pendingStructs&&r.push(ho(n.store.pendingStructs.update,t)),r.length>1){if(e.constructor===Kt)return co(r.map((i,o)=>o===0?i:fo(i)));if(e.constructor===at)return oe(r)}return r[0]},hn=(n,t)=>Gi(n,t,new Kt),Pi=n=>{const t=new Map,e=m(n.restDecoder);for(let s=0;s<e;s++){const r=m(n.restDecoder),i=m(n.restDecoder);t.set(r,i)}return t},Cs=n=>Pi(new bs(nt(n))),As=(n,t)=>(p(n.restEncoder,t.size),tt(t.entries()).sort((e,s)=>s[0]-e[0]).forEach(([e,s])=>{p(n.restEncoder,e),p(n.restEncoder,s)}),n),qi=(n,t)=>As(n,ye(t.store)),Zi=(n,t=new _s)=>(n instanceof Map?As(t,n):qi(t,n),t.toUint8Array()),Qi=n=>Zi(n,new Ss);class to{constructor(){this.l=[]}}const Vn=()=>new to,Hn=(n,t)=>n.l.push(t),$n=(n,t)=>{const e=n.l,s=e.length;n.l=e.filter(r=>t!==r),s===n.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},Ls=(n,t,e)=>Ze(n.l,[t,e]);class yt{constructor(t,e){this.client=t,this.clock=e}}const Pt=(n,t)=>n===t||n!==null&&t!==null&&n.client===t.client&&n.clock===t.clock,b=(n,t)=>new yt(n,t),eo=n=>{for(const[t,e]of n.doc.share.entries())if(e===n)return t;throw V()},It=(n,t)=>t===void 0?!n.deleted:t.sv.has(n.id.client)&&(t.sv.get(n.id.client)||0)>n.id.clock&&!ms(t.ds,n.id),Ke=(n,t)=>{const e=J(n.meta,Ke,lt),s=n.doc.store;e.has(t)||(t.sv.forEach((r,i)=>{r<L(s,i)&&et(n,b(i,r))}),ws(n,t.ds,r=>{}),e.add(t))};class Is{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const ye=n=>{const t=new Map;return n.clients.forEach((e,s)=>{const r=e[e.length-1];t.set(s,r.id.clock+r.length)}),t},L=(n,t)=>{const e=n.clients.get(t);if(e===void 0)return 0;const s=e[e.length-1];return s.id.clock+s.length},Ms=(n,t)=>{let e=n.clients.get(t.id.client);if(e===void 0)e=[],n.clients.set(t.id.client,e);else{const s=e[e.length-1];if(s.id.clock+s.length!==t.id.clock)throw V()}e.push(t)},H=(n,t)=>{let e=0,s=n.length-1,r=n[s],i=r.id.clock;if(i===t)return s;let o=Y(t/(i+r.length-1)*s);for(;e<=s;){if(r=n[o],i=r.id.clock,i<=t){if(t<i+r.length)return o;e=o+1}else s=o-1;o=Y((e+s)/2)}throw V()},no=(n,t)=>{const e=n.clients.get(t.client);return e[H(e,t.clock)]},ve=no,ze=(n,t,e)=>{const s=H(t,e),r=t[s];return r.id.clock<e&&r instanceof E?(t.splice(s+1,0,de(n,r,e-r.id.clock)),s+1):s},et=(n,t)=>{const e=n.doc.store.clients.get(t.client);return e[ze(n,e,t.clock)]},jn=(n,t,e)=>{const s=t.clients.get(e.client),r=H(s,e.clock),i=s[r];return e.clock!==i.id.clock+i.length-1&&i.constructor!==U&&s.splice(r+1,0,de(n,i,e.clock-i.id.clock+1)),i},so=(n,t,e)=>{const s=n.clients.get(t.id.client);s[H(s,t.id.clock)]=e},vs=(n,t,e,s,r)=>{if(s===0)return;const i=e+s;let o=ze(n,t,e),l;do l=t[o++],i<l.id.clock+l.length&&ze(n,t,i),r(l);while(o<t.length&&t[o].id.clock<i)};class ro{constructor(t,e,s){this.doc=t,this.deleteSet=new jt,this.beforeState=ye(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=e,this.meta=new Map,this.local=s,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const Kn=(n,t)=>t.deleteSet.clients.size===0&&!br(t.afterState,(e,s)=>t.beforeState.get(s)!==e)?!1:(ln(t.deleteSet),Xi(n,t),At(n,t.deleteSet),!0),zn=(n,t,e)=>{const s=t._item;(s===null||s.id.clock<(n.beforeState.get(s.id.client)||0)&&!s.deleted)&&J(n.changed,t,lt).add(e)},se=(n,t)=>{let e=n[t],s=n[t-1],r=t;for(;r>0;e=s,s=n[--r-1]){if(s.deleted===e.deleted&&s.constructor===e.constructor&&s.mergeWith(e)){e instanceof E&&e.parentSub!==null&&e.parent._map.get(e.parentSub)===e&&e.parent._map.set(e.parentSub,s);continue}break}const i=t-r;return i&&n.splice(t+1-i,i),i},io=(n,t,e)=>{for(const[s,r]of n.clients.entries()){const i=t.clients.get(s);for(let o=r.length-1;o>=0;o--){const l=r[o],c=l.clock+l.len;for(let a=H(i,l.clock),h=i[a];a<i.length&&h.id.clock<c;h=i[++a]){const d=i[a];if(l.clock+l.len<=d.id.clock)break;d instanceof E&&d.deleted&&!d.keep&&e(d)&&d.gc(t,!1)}}}},oo=(n,t)=>{n.clients.forEach((e,s)=>{const r=t.clients.get(s);for(let i=e.length-1;i>=0;i--){const o=e[i],l=Pe(r.length-1,1+H(r,o.clock+o.len-1));for(let c=l,a=r[c];c>0&&a.id.clock>=o.clock;a=r[c])c-=1+se(r,c)}})},xs=(n,t)=>{if(t<n.length){const e=n[t],s=e.doc,r=s.store,i=e.deleteSet,o=e._mergeStructs;try{ln(i),e.afterState=ye(e.doc.store),s.emit("beforeObserverCalls",[e,s]);const l=[];e.changed.forEach((c,a)=>l.push(()=>{(a._item===null||!a._item.deleted)&&a._callObserver(e,c)})),l.push(()=>{e.changedParentTypes.forEach((c,a)=>{a._dEH.l.length>0&&(a._item===null||!a._item.deleted)&&(c=c.filter(h=>h.target._item===null||!h.target._item.deleted),c.forEach(h=>{h.currentTarget=a,h._path=null}),c.sort((h,d)=>h.path.length-d.path.length),Ls(a._dEH,c,e))})}),l.push(()=>s.emit("afterTransaction",[e,s])),Ze(l,[]),e._needFormattingCleanup&&Ao(e)}finally{s.gc&&io(i,r,s.gcFilter),oo(i,r),e.afterState.forEach((h,d)=>{const u=e.beforeState.get(d)||0;if(u!==h){const f=r.clients.get(d),g=ft(H(f,u),1);for(let w=f.length-1;w>=g;)w-=1+se(f,w)}});for(let h=o.length-1;h>=0;h--){const{client:d,clock:u}=o[h].id,f=r.clients.get(d),g=H(f,u);g+1<f.length&&se(f,g+1)>1||g>0&&se(f,g)}if(!e.local&&e.afterState.get(s.clientID)!==e.beforeState.get(s.clientID)&&(Ri(gs,us,"[yjs] ",ds,fs,"Changed the client-id because another client seems to be using it."),s.clientID=ys()),s.emit("afterTransactionCleanup",[e,s]),s._observers.has("update")){const h=new Kt;Kn(h,e)&&s.emit("update",[h.toUint8Array(),e.origin,s,e])}if(s._observers.has("updateV2")){const h=new at;Kn(h,e)&&s.emit("updateV2",[h.toUint8Array(),e.origin,s,e])}const{subdocsAdded:l,subdocsLoaded:c,subdocsRemoved:a}=e;(l.size>0||a.size>0||c.size>0)&&(l.forEach(h=>{h.clientID=s.clientID,h.collectionid==null&&(h.collectionid=s.collectionid),s.subdocs.add(h)}),a.forEach(h=>s.subdocs.delete(h)),s.emit("subdocs",[{loaded:c,added:l,removed:a},s,e]),a.forEach(h=>h.destroy())),n.length<=t+1?(s._transactionCleanups=[],s.emit("afterAllTransactions",[s,n])):xs(n,t+1)}}},k=(n,t,e=null,s=!0)=>{const r=n._transactionCleanups;let i=!1,o=null;n._transaction===null&&(i=!0,n._transaction=new ro(n,e,s),r.push(n._transaction),r.length===1&&n.emit("beforeAllTransactions",[n]),n.emit("beforeTransaction",[n._transaction,n]));try{o=t(n._transaction)}finally{if(i){const l=n._transaction===r[0];n._transaction=null,l&&xs(r,0)}}return o};function*lo(n){const t=m(n.restDecoder);for(let e=0;e<t;e++){const s=m(n.restDecoder),r=n.readClient();let i=m(n.restDecoder);for(let o=0;o<s;o++){const l=n.readInfo();if(l===10){const c=m(n.restDecoder);yield new T(b(r,i),c),i+=c}else if(pe&l){const c=(l&(z|x))===0,a=new E(b(r,i),null,(l&x)===x?n.readLeftID():null,null,(l&z)===z?n.readRightID():null,c?n.readParentInfo()?n.readString():n.readLeftID():null,c&&(l&Ot)===Ot?n.readString():null,Gs(n,l));yield a,i+=a.length}else{const c=n.readLen();yield new U(b(r,i),c),i+=c}}}}class un{constructor(t,e){this.gen=lo(t),this.curr=null,this.done=!1,this.filterSkips=e,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===T);return this.curr}}class dn{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const co=n=>oe(n,ks,Kt),ao=(n,t)=>{if(n.constructor===U){const{client:e,clock:s}=n.id;return new U(b(e,s+t),n.length-t)}else if(n.constructor===T){const{client:e,clock:s}=n.id;return new T(b(e,s+t),n.length-t)}else{const e=n,{client:s,clock:r}=e.id;return new E(b(s,r+t),null,b(s,r+t-1),null,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t))}},oe=(n,t=Et,e=at)=>{if(n.length===1)return n[0];const s=n.map(h=>new t(nt(h)));let r=s.map(h=>new un(h,!0)),i=null;const o=new e,l=new dn(o);for(;r=r.filter(u=>u.curr!==null),r.sort((u,f)=>{if(u.curr.id.client===f.curr.id.client){const g=u.curr.id.clock-f.curr.id.clock;return g===0?u.curr.constructor===f.curr.constructor?0:u.curr.constructor===T?1:-1:g}else return f.curr.id.client-u.curr.id.client}),r.length!==0;){const h=r[0],d=h.curr.id.client;if(i!==null){let u=h.curr,f=!1;for(;u!==null&&u.id.clock+u.length<=i.struct.id.clock+i.struct.length&&u.id.client>=i.struct.id.client;)u=h.next(),f=!0;if(u===null||u.id.client!==d||f&&u.id.clock>i.struct.id.clock+i.struct.length)continue;if(d!==i.struct.id.client)P(l,i.struct,i.offset),i={struct:u,offset:0},h.next();else if(i.struct.id.clock+i.struct.length<u.id.clock)if(i.struct.constructor===T)i.struct.length=u.id.clock+u.length-i.struct.id.clock;else{P(l,i.struct,i.offset);const g=u.id.clock-i.struct.id.clock-i.struct.length;i={struct:new T(b(d,i.struct.id.clock+i.struct.length),g),offset:0}}else{const g=i.struct.id.clock+i.struct.length-u.id.clock;g>0&&(i.struct.constructor===T?i.struct.length-=g:u=ao(u,g)),i.struct.mergeWith(u)||(P(l,i.struct,i.offset),i={struct:u,offset:0},h.next())}}else i={struct:h.curr,offset:0},h.next();for(let u=h.curr;u!==null&&u.id.client===d&&u.id.clock===i.struct.id.clock+i.struct.length&&u.constructor!==T;u=h.next())P(l,i.struct,i.offset),i={struct:u,offset:0}}i!==null&&(P(l,i.struct,i.offset),i=null),fn(l);const c=s.map(h=>cn(h)),a=Vi(c);return At(o,a),o.toUint8Array()},ho=(n,t,e=Et,s=at)=>{const r=Cs(t),i=new s,o=new dn(i),l=new e(nt(n)),c=new un(l,!1);for(;c.curr;){const h=c.curr,d=h.id.client,u=r.get(d)||0;if(c.curr.constructor===T){c.next();continue}if(h.id.clock+h.length>u)for(P(o,h,ft(u-h.id.clock,0)),c.next();c.curr&&c.curr.id.client===d;)P(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===d&&c.curr.id.clock+c.curr.length<=u;)c.next()}fn(o);const a=cn(l);return At(i,a),i.toUint8Array()},Us=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:S(n.encoder.restEncoder)}),n.encoder.restEncoder=v(),n.written=0)},P=(n,t,e)=>{n.written>0&&n.currClient!==t.id.client&&Us(n),n.written===0&&(n.currClient=t.id.client,n.encoder.writeClient(t.id.client),p(n.encoder.restEncoder,t.id.clock+e)),t.write(n.encoder,e),n.written++},fn=n=>{Us(n);const t=n.encoder.restEncoder;p(t,n.clientStructs.length);for(let e=0;e<n.clientStructs.length;e++){const s=n.clientStructs[e];p(t,s.written),me(t,s.restEncoder)}},uo=(n,t,e,s)=>{const r=new e(nt(n)),i=new un(r,!1),o=new s,l=new dn(o);for(let a=i.curr;a!==null;a=i.next())P(l,t(a),0);fn(l);const c=cn(r);return At(o,c),o.toUint8Array()},fo=n=>uo(n,$r,Et,Kt),Yn="You must not compute changes after the event-handler fired.";class be{constructor(t,e){this.target=t,this.currentTarget=t,this.transaction=e,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=go(this.currentTarget,this.target))}deletes(t){return ms(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw X(Yn);const t=new Map,e=this.target;this.transaction.changed.get(e).forEach(r=>{if(r!==null){const i=e._map.get(r);let o,l;if(this.adds(i)){let c=i.left;for(;c!==null&&this.adds(c);)c=c.left;if(this.deletes(i))if(c!==null&&this.deletes(c))o="delete",l=Ee(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",l=Ee(c.content.getContent())):(o="add",l=void 0)}else if(this.deletes(i))o="delete",l=Ee(i.content.getContent());else return;t.set(r,{action:o,oldValue:l})}}),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(t===null){if(this.transaction.doc._transactionCleanups.length===0)throw X(Yn);const e=this.target,s=lt(),r=lt(),i=[];if(t={added:s,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(e).has(null)){let l=null;const c=()=>{l&&i.push(l)};for(let a=e._start;a!==null;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&((l===null||l.delete===void 0)&&(c(),l={delete:0}),l.delete+=a.length,r.add(a)):this.adds(a)?((l===null||l.insert===void 0)&&(c(),l={insert:[]}),l.insert=l.insert.concat(a.content.getContent()),s.add(a)):((l===null||l.retain===void 0)&&(c(),l={retain:0}),l.retain+=a.length);l!==null&&l.retain===void 0&&c()}this._changes=t}return t}}const go=(n,t)=>{const e=[];for(;t._item!==null&&t!==n;){if(t._item.parentSub!==null)e.unshift(t._item.parentSub);else{let s=0,r=t._item.parent._start;for(;r!==t._item&&r!==null;)r.deleted||s++,r=r.right;e.unshift(s)}t=t._item.parent}return e},Ts=80;let gn=0;class po{constructor(t,e){t.marker=!0,this.p=t,this.index=e,this.timestamp=gn++}}const wo=n=>{n.timestamp=gn++},Os=(n,t,e)=>{n.p.marker=!1,n.p=t,t.marker=!0,n.index=e,n.timestamp=gn++},mo=(n,t,e)=>{if(n.length>=Ts){const s=n.reduce((r,i)=>r.timestamp<i.timestamp?r:i);return Os(s,t,e),s}else{const s=new po(t,e);return n.push(s),s}},ke=(n,t)=>{if(n._start===null||t===0||n._searchMarker===null)return null;const e=n._searchMarker.length===0?null:n._searchMarker.reduce((i,o)=>te(t-i.index)<te(t-o.index)?i:o);let s=n._start,r=0;for(e!==null&&(s=e.p,r=e.index,wo(e));s.right!==null&&r<t;){if(!s.deleted&&s.countable){if(t<r+s.length)break;r+=s.length}s=s.right}for(;s.left!==null&&r>t;)s=s.left,!s.deleted&&s.countable&&(r-=s.length);for(;s.left!==null&&s.left.id.client===s.id.client&&s.left.id.clock+s.left.length===s.id.clock;)s=s.left,!s.deleted&&s.countable&&(r-=s.length);return e!==null&&te(e.index-r)<s.parent.length/Ts?(Os(e,s,r),e):mo(n._searchMarker,s,r)},Nt=(n,t,e)=>{for(let s=n.length-1;s>=0;s--){const r=n[s];if(e>0){let i=r.p;for(i.marker=!1;i&&(i.deleted||!i.countable);)i=i.left,i&&!i.deleted&&i.countable&&(r.index-=i.length);if(i===null||i.marker===!0){n.splice(s,1);continue}r.p=i,i.marker=!0}(t<r.index||e>0&&t===r.index)&&(r.index=ft(t,r.index+e))}},Se=(n,t,e)=>{const s=n,r=t.changedParentTypes;for(;J(r,n,()=>[]).push(e),n._item!==null;)n=n._item.parent;Ls(s._eH,e,t)};class I{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Vn(),this._dEH=Vn(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,e){this.doc=t,this._item=e}_copy(){throw B()}clone(){throw B()}_write(t){}get _first(){let t=this._start;for(;t!==null&&t.deleted;)t=t.right;return t}_callObserver(t,e){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){Hn(this._eH,t)}observeDeep(t){Hn(this._dEH,t)}unobserve(t){$n(this._eH,t)}unobserveDeep(t){$n(this._dEH,t)}toJSON(){}}const Rs=(n,t,e)=>{t<0&&(t=n._length+t),e<0&&(e=n._length+e);let s=e-t;const r=[];let i=n._start;for(;i!==null&&s>0;){if(i.countable&&!i.deleted){const o=i.content.getContent();if(o.length<=t)t-=o.length;else{for(let l=t;l<o.length&&s>0;l++)r.push(o[l]),s--;t=0}}i=i.right}return r},Bs=n=>{const t=[];let e=n._start;for(;e!==null;){if(e.countable&&!e.deleted){const s=e.content.getContent();for(let r=0;r<s.length;r++)t.push(s[r])}e=e.right}return t},Ft=(n,t)=>{let e=0,s=n._start;for(;s!==null;){if(s.countable&&!s.deleted){const r=s.content.getContent();for(let i=0;i<r.length;i++)t(r[i],e++,n)}s=s.right}},Ns=(n,t)=>{const e=[];return Ft(n,(s,r)=>{e.push(t(s,r,n))}),e},yo=n=>{let t=n._start,e=null,s=0;return{[Symbol.iterator](){return this},next:()=>{if(e===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};e=t.content.getContent(),s=0,t=t.right}const r=e[s++];return e.length<=s&&(e=null),{done:!1,value:r}}}},Fs=(n,t)=>{const e=ke(n,t);let s=n._start;for(e!==null&&(s=e.p,t-=e.index);s!==null;s=s.right)if(!s.deleted&&s.countable){if(t<s.length)return s.content.getContent()[t];t-=s.length}},le=(n,t,e,s)=>{let r=e;const i=n.doc,o=i.clientID,l=i.store,c=e===null?t._start:e.right;let a=[];const h=()=>{a.length>0&&(r=new E(b(o,L(l,o)),r,r&&r.lastId,c,c&&c.id,t,null,new dt(a)),r.integrate(n,0),a=[])};s.forEach(d=>{if(d===null)a.push(d);else switch(d.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(d);break;default:switch(h(),d.constructor){case Uint8Array:case ArrayBuffer:r=new E(b(o,L(l,o)),r,r&&r.lastId,c,c&&c.id,t,null,new zt(new Uint8Array(d))),r.integrate(n,0);break;case gt:r=new E(b(o,L(l,o)),r,r&&r.lastId,c,c&&c.id,t,null,new Yt(d)),r.integrate(n,0);break;default:if(d instanceof I)r=new E(b(o,L(l,o)),r,r&&r.lastId,c,c&&c.id,t,null,new G(d)),r.integrate(n,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},Vs=()=>X("Length exceeded!"),Hs=(n,t,e,s)=>{if(e>t._length)throw Vs();if(e===0)return t._searchMarker&&Nt(t._searchMarker,e,s.length),le(n,t,null,s);const r=e,i=ke(t,e);let o=t._start;for(i!==null&&(o=i.p,e-=i.index,e===0&&(o=o.prev,e+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(e<=o.length){e<o.length&&et(n,b(o.id.client,o.id.clock+e));break}e-=o.length}return t._searchMarker&&Nt(t._searchMarker,r,s.length),le(n,t,o,s)},bo=(n,t,e)=>{let r=(t._searchMarker||[]).reduce((i,o)=>o.index>i.index?o:i,{index:0,p:t._start}).p;if(r)for(;r.right;)r=r.right;return le(n,t,r,e)},$s=(n,t,e,s)=>{if(s===0)return;const r=e,i=s,o=ke(t,e);let l=t._start;for(o!==null&&(l=o.p,e-=o.index);l!==null&&e>0;l=l.right)!l.deleted&&l.countable&&(e<l.length&&et(n,b(l.id.client,l.id.clock+e)),e-=l.length);for(;s>0&&l!==null;)l.deleted||(s<l.length&&et(n,b(l.id.client,l.id.clock+s)),l.delete(n),s-=l.length),l=l.right;if(s>0)throw Vs();t._searchMarker&&Nt(t._searchMarker,r,-i+s)},ce=(n,t,e)=>{const s=t._map.get(e);s!==void 0&&s.delete(n)},pn=(n,t,e,s)=>{const r=t._map.get(e)||null,i=n.doc,o=i.clientID;let l;if(s==null)l=new dt([s]);else switch(s.constructor){case Number:case Object:case Boolean:case Array:case String:l=new dt([s]);break;case Uint8Array:l=new zt(s);break;case gt:l=new Yt(s);break;default:if(s instanceof I)l=new G(s);else throw new Error("Unexpected content type")}new E(b(o,L(i.store,o)),r,r&&r.lastId,null,null,t,e,l).integrate(n,0)},wn=(n,t)=>{const e=n._map.get(t);return e!==void 0&&!e.deleted?e.content.getContent()[e.length-1]:void 0},js=n=>{const t={};return n._map.forEach((e,s)=>{e.deleted||(t[s]=e.content.getContent()[e.length-1])}),t},Ks=(n,t)=>{const e=n._map.get(t);return e!==void 0&&!e.deleted},qt=n=>Ni(n.entries(),t=>!t[1].deleted);class ko extends be{constructor(t,e){super(t,e),this._transaction=e}}class bt extends I{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const e=new bt;return e.push(t),e}_integrate(t,e){super._integrate(t,e),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new bt}clone(){const t=new bt;return t.insert(0,this.toArray().map(e=>e instanceof I?e.clone():e)),t}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}_callObserver(t,e){super._callObserver(t,e),Se(this,t,new ko(this,t))}insert(t,e){this.doc!==null?k(this.doc,s=>{Hs(s,this,t,e)}):this._prelimContent.splice(t,0,...e)}push(t){this.doc!==null?k(this.doc,e=>{bo(e,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,e=1){this.doc!==null?k(this.doc,s=>{$s(s,this,t,e)}):this._prelimContent.splice(t,e)}get(t){return Fs(this,t)}toArray(){return Bs(this)}slice(t=0,e=this.length){return Rs(this,t,e)}toJSON(){return this.map(t=>t instanceof I?t.toJSON():t)}map(t){return Ns(this,t)}forEach(t){Ft(this,t)}[Symbol.iterator](){return yo(this)}_write(t){t.writeTypeRef(zo)}}const So=n=>new bt;class _o extends be{constructor(t,e,s){super(t,e),this.keysChanged=s}}class ht extends I{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,e){super._integrate(t,e),this._prelimContent.forEach((s,r)=>{this.set(r,s)}),this._prelimContent=null}_copy(){return new ht}clone(){const t=new ht;return this.forEach((e,s)=>{t.set(s,e instanceof I?e.clone():e)}),t}_callObserver(t,e){Se(this,t,new _o(this,t,e))}toJSON(){const t={};return this._map.forEach((e,s)=>{if(!e.deleted){const r=e.content.getContent()[e.length-1];t[s]=r instanceof I?r.toJSON():r}}),t}get size(){return[...qt(this._map)].length}keys(){return Me(qt(this._map),t=>t[0])}values(){return Me(qt(this._map),t=>t[1].content.getContent()[t[1].length-1])}entries(){return Me(qt(this._map),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this._map.forEach((e,s)=>{e.deleted||t(e.content.getContent()[e.length-1],s,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?k(this.doc,e=>{ce(e,this,t)}):this._prelimContent.delete(t)}set(t,e){return this.doc!==null?k(this.doc,s=>{pn(s,this,t,e)}):this._prelimContent.set(t,e),e}get(t){return wn(this,t)}has(t){return Ks(this,t)}clear(){this.doc!==null?k(this.doc,t=>{this.forEach(function(e,s,r){ce(t,r,s)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Yo)}}const Do=n=>new ht,q=(n,t)=>n===t||typeof n=="object"&&typeof t=="object"&&n&&t&&Hr(n,t);class Ye{constructor(t,e,s,r){this.left=t,this.right=e,this.index=s,this.currentAttributes=r}forward(){switch(this.right===null&&V(),this.right.content.constructor){case C:this.right.deleted||Lt(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 Xn=(n,t,e)=>{for(;t.right!==null&&e>0;){switch(t.right.content.constructor){case C:t.right.deleted||Lt(t.currentAttributes,t.right.content);break;default:t.right.deleted||(e<t.right.length&&et(n,b(t.right.id.client,t.right.id.clock+e)),t.index+=t.right.length,e-=t.right.length);break}t.left=t.right,t.right=t.right.right}return t},Zt=(n,t,e)=>{const s=new Map,r=ke(t,e);if(r){const i=new Ye(r.p.left,r.p,r.index,s);return Xn(n,i,e-r.index)}else{const i=new Ye(null,t._start,0,s);return Xn(n,i,e)}},zs=(n,t,e,s)=>{for(;e.right!==null&&(e.right.deleted===!0||e.right.content.constructor===C&&q(s.get(e.right.content.key),e.right.content.value));)e.right.deleted||s.delete(e.right.content.key),e.forward();const r=n.doc,i=r.clientID;s.forEach((o,l)=>{const c=e.left,a=e.right,h=new E(b(i,L(r.store,i)),c,c&&c.lastId,a,a&&a.id,t,null,new C(l,o));h.integrate(n,0),e.right=h,e.forward()})},Lt=(n,t)=>{const{key:e,value:s}=t;s===null?n.delete(e):n.set(e,s)},Ys=(n,t)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===C&&q(t[n.right.content.key]||null,n.right.content.value)))break;n.forward()}},Xs=(n,t,e,s)=>{const r=n.doc,i=r.clientID,o=new Map;for(const l in s){const c=s[l],a=e.currentAttributes.get(l)||null;if(!q(a,c)){o.set(l,a);const{left:h,right:d}=e;e.right=new E(b(i,L(r.store,i)),h,h&&h.lastId,d,d&&d.id,t,null,new C(l,c)),e.right.integrate(n,0),e.forward()}}return o},xe=(n,t,e,s,r)=>{e.currentAttributes.forEach((u,f)=>{r[f]===void 0&&(r[f]=null)});const i=n.doc,o=i.clientID;Ys(e,r);const l=Xs(n,t,e,r),c=s.constructor===String?new $(s):s instanceof I?new G(s):new pt(s);let{left:a,right:h,index:d}=e;t._searchMarker&&Nt(t._searchMarker,e.index,c.getLength()),h=new E(b(o,L(i.store,o)),a,a&&a.lastId,h,h&&h.id,t,null,c),h.integrate(n,0),e.right=h,e.index=d,e.forward(),zs(n,t,e,l)},Jn=(n,t,e,s,r)=>{const i=n.doc,o=i.clientID;Ys(e,r);const l=Xs(n,t,e,r);t:for(;e.right!==null&&(s>0||l.size>0&&(e.right.deleted||e.right.content.constructor===C));){if(!e.right.deleted)switch(e.right.content.constructor){case C:{const{key:c,value:a}=e.right.content,h=r[c];if(h!==void 0){if(q(h,a))l.delete(c);else{if(s===0)break t;l.set(c,a)}e.right.delete(n)}else e.currentAttributes.set(c,a);break}default:s<e.right.length&&et(n,b(e.right.id.client,e.right.id.clock+s)),s-=e.right.length;break}e.forward()}if(s>0){let c="";for(;s>0;s--)c+=`
2
+ `;e.right=new E(b(o,L(i.store,o)),e.left,e.left&&e.left.lastId,e.right,e.right&&e.right.id,t,null,new $(c)),e.right.integrate(n,0),e.forward()}zs(n,t,e,l)},Js=(n,t,e,s,r)=>{let i=t;const o=O();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===C){const a=i.content;o.set(a.key,a)}i=i.right}let l=0,c=!1;for(;t!==i;){if(e===t&&(c=!0),!t.deleted){const a=t.content;switch(a.constructor){case C:{const{key:h,value:d}=a,u=s.get(h)||null;(o.get(h)!==a||u===d)&&(t.delete(n),l++,!c&&(r.get(h)||null)===d&&u!==d&&(u===null?r.delete(h):r.set(h,u))),!c&&!t.deleted&&Lt(r,a);break}}}t=t.right}return l},Eo=(n,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const e=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===C){const s=t.content.key;e.has(s)?t.delete(n):e.add(s)}t=t.left}},Co=n=>{let t=0;return k(n.doc,e=>{let s=n._start,r=n._start,i=O();const o=Ne(i);for(;r;){if(r.deleted===!1)switch(r.content.constructor){case C:Lt(o,r.content);break;default:t+=Js(e,s,r,i,o),i=Ne(o),s=r;break}r=r.right}}),t},Ao=n=>{const t=new Set,e=n.doc;for(const[s,r]of n.afterState.entries()){const i=n.beforeState.get(s)||0;r!==i&&vs(n,e.store.clients.get(s),i,r,o=>{!o.deleted&&o.content.constructor===C&&o.constructor!==U&&t.add(o.parent)})}k(e,s=>{ws(n,n.deleteSet,r=>{if(r instanceof U||!r.parent._hasFormatting||t.has(r.parent))return;const i=r.parent;r.content.constructor===C?t.add(i):Eo(s,r)});for(const r of t)Co(r)})},Wn=(n,t,e)=>{const s=e,r=Ne(t.currentAttributes),i=t.right;for(;e>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case G:case pt:case $:e<t.right.length&&et(n,b(t.right.id.client,t.right.id.clock+e)),e-=t.right.length,t.right.delete(n);break}t.forward()}i&&Js(n,i,t.right,r,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&Nt(o._searchMarker,t.index,-s+e),t};class Lo extends be{constructor(t,e,s){super(t,e),this.childListChanged=!1,this.keysChanged=new Set,s.forEach(r=>{r===null?this.childListChanged=!0:this.keysChanged.add(r)})}get changes(){if(this._changes===null){const t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(this._delta===null){const t=this.target.doc,e=[];k(t,s=>{const r=new Map,i=new Map;let o=this.target._start,l=null;const c={};let a="",h=0,d=0;const u=()=>{if(l!==null){let f=null;switch(l){case"delete":d>0&&(f={delete:d}),d=0;break;case"insert":(typeof a=="object"||a.length>0)&&(f={insert:a},r.size>0&&(f.attributes={},r.forEach((g,w)=>{g!==null&&(f.attributes[w]=g)}))),a="";break;case"retain":h>0&&(f={retain:h},Fr(c)||(f.attributes=Or({},c))),h=0;break}f&&e.push(f),l=null}};for(;o!==null;){switch(o.content.constructor){case G:case pt:this.adds(o)?this.deletes(o)||(u(),l="insert",a=o.content.getContent()[0],u()):this.deletes(o)?(l!=="delete"&&(u(),l="delete"),d+=1):o.deleted||(l!=="retain"&&(u(),l="retain"),h+=1);break;case $:this.adds(o)?this.deletes(o)||(l!=="insert"&&(u(),l="insert"),a+=o.content.str):this.deletes(o)?(l!=="delete"&&(u(),l="delete"),d+=o.length):o.deleted||(l!=="retain"&&(u(),l="retain"),h+=o.length);break;case C:{const{key:f,value:g}=o.content;if(this.adds(o)){if(!this.deletes(o)){const w=r.get(f)||null;q(w,g)?g!==null&&o.delete(s):(l==="retain"&&u(),q(g,i.get(f)||null)?delete c[f]:c[f]=g)}}else if(this.deletes(o)){i.set(f,g);const w=r.get(f)||null;q(w,g)||(l==="retain"&&u(),c[f]=w)}else if(!o.deleted){i.set(f,g);const w=c[f];w!==void 0&&(q(w,g)?w!==null&&o.delete(s):(l==="retain"&&u(),g===null?delete c[f]:c[f]=g))}o.deleted||(l==="insert"&&u(),Lt(r,o.content));break}}o=o.right}for(u();e.length>0;){const f=e[e.length-1];if(f.retain!==void 0&&f.attributes===void 0)e.pop();else break}}),this._delta=e}return this._delta}}class Ct extends I{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this._length}_integrate(t,e){super._integrate(t,e);try{this._pending.forEach(s=>s())}catch(s){console.error(s)}this._pending=null}_copy(){return new Ct}clone(){const t=new Ct;return t.applyDelta(this.toDelta()),t}_callObserver(t,e){super._callObserver(t,e);const s=new Lo(this,t,e);Se(this,t,s),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){let t="",e=this._start;for(;e!==null;)!e.deleted&&e.countable&&e.content.constructor===$&&(t+=e.content.str),e=e.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:e=!0}={}){this.doc!==null?k(this.doc,s=>{const r=new Ye(null,this._start,0,new Map);for(let i=0;i<t.length;i++){const o=t[i];if(o.insert!==void 0){const l=!e&&typeof o.insert=="string"&&i===t.length-1&&r.right===null&&o.insert.slice(-1)===`
3
+ `?o.insert.slice(0,-1):o.insert;(typeof l!="string"||l.length>0)&&xe(s,this,r,l,o.attributes||{})}else o.retain!==void 0?Jn(s,this,r,o.retain,o.attributes||{}):o.delete!==void 0&&Wn(s,r,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,e,s){const r=[],i=new Map,o=this.doc;let l="",c=this._start;function a(){if(l.length>0){const d={};let u=!1;i.forEach((g,w)=>{u=!0,d[w]=g});const f={insert:l};u&&(f.attributes=d),r.push(f),l=""}}const h=()=>{for(;c!==null;){if(It(c,t)||e!==void 0&&It(c,e))switch(c.content.constructor){case $:{const d=i.get("ychange");t!==void 0&&!It(c,t)?(d===void 0||d.user!==c.id.client||d.type!=="removed")&&(a(),i.set("ychange",s?s("removed",c.id):{type:"removed"})):e!==void 0&&!It(c,e)?(d===void 0||d.user!==c.id.client||d.type!=="added")&&(a(),i.set("ychange",s?s("added",c.id):{type:"added"})):d!==void 0&&(a(),i.delete("ychange")),l+=c.content.str;break}case G:case pt:{a();const d={insert:c.content.getContent()[0]};if(i.size>0){const u={};d.attributes=u,i.forEach((f,g)=>{u[g]=f})}r.push(d);break}case C:It(c,t)&&(a(),Lt(i,c.content));break}c=c.right}a()};return t||e?k(o,d=>{t&&Ke(d,t),e&&Ke(d,e),h()},"cleanup"):h(),r}insert(t,e,s){if(e.length<=0)return;const r=this.doc;r!==null?k(r,i=>{const o=Zt(i,this,t);s||(s={},o.currentAttributes.forEach((l,c)=>{s[c]=l})),xe(i,this,o,e,s)}):this._pending.push(()=>this.insert(t,e,s))}insertEmbed(t,e,s={}){const r=this.doc;r!==null?k(r,i=>{const o=Zt(i,this,t);xe(i,this,o,e,s)}):this._pending.push(()=>this.insertEmbed(t,e,s))}delete(t,e){if(e===0)return;const s=this.doc;s!==null?k(s,r=>{Wn(r,Zt(r,this,t),e)}):this._pending.push(()=>this.delete(t,e))}format(t,e,s){if(e===0)return;const r=this.doc;r!==null?k(r,i=>{const o=Zt(i,this,t);o.right!==null&&Jn(i,this,o,e,s)}):this._pending.push(()=>this.format(t,e,s))}removeAttribute(t){this.doc!==null?k(this.doc,e=>{ce(e,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,e){this.doc!==null?k(this.doc,s=>{pn(s,this,t,e)}):this._pending.push(()=>this.setAttribute(t,e))}getAttribute(t){return wn(this,t)}getAttributes(){return js(this)}_write(t){t.writeTypeRef(Xo)}}const Io=n=>new Ct;class Ue{constructor(t,e=()=>!0){this._filter=e,this._root=t,this._currentNode=t._start,this._firstCall=!0}[Symbol.iterator](){return this}next(){let t=this._currentNode,e=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(e)))do if(e=t.content.type,!t.deleted&&(e.constructor===Vt||e.constructor===ut)&&e._start!==null)t=e._start;else for(;t!==null;)if(t.right!==null){t=t.right;break}else t.parent===this._root?t=null:t=t.parent._item;while(t!==null&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,t===null?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}}class ut extends I{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,e){super._integrate(t,e),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new ut}clone(){const t=new ut;return t.insert(0,this.toArray().map(e=>e instanceof I?e.clone():e)),t}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new Ue(this,t)}querySelector(t){t=t.toUpperCase();const s=new Ue(this,r=>r.nodeName&&r.nodeName.toUpperCase()===t).next();return s.done?null:s.value}querySelectorAll(t){return t=t.toUpperCase(),tt(new Ue(this,e=>e.nodeName&&e.nodeName.toUpperCase()===t))}_callObserver(t,e){Se(this,t,new xo(this,e,t))}toString(){return Ns(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,e={},s){const r=t.createDocumentFragment();return s!==void 0&&s._createAssociation(r,this),Ft(this,i=>{r.insertBefore(i.toDOM(t,e,s),null)}),r}insert(t,e){this.doc!==null?k(this.doc,s=>{Hs(s,this,t,e)}):this._prelimContent.splice(t,0,...e)}insertAfter(t,e){if(this.doc!==null)k(this.doc,s=>{const r=t&&t instanceof I?t._item:t;le(s,this,r,e)});else{const s=this._prelimContent,r=t===null?0:s.findIndex(i=>i===t)+1;if(r===0&&t!==null)throw X("Reference item not found");s.splice(r,0,...e)}}delete(t,e=1){this.doc!==null?k(this.doc,s=>{$s(s,this,t,e)}):this._prelimContent.splice(t,e)}toArray(){return Bs(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Fs(this,t)}slice(t=0,e=this.length){return Rs(this,t,e)}forEach(t){Ft(this,t)}_write(t){t.writeTypeRef(Wo)}}const Mo=n=>new ut;class Vt extends ut{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,e){super._integrate(t,e),this._prelimAttrs.forEach((s,r)=>{this.setAttribute(r,s)}),this._prelimAttrs=null}_copy(){return new Vt(this.nodeName)}clone(){const t=new Vt(this.nodeName),e=this.getAttributes();return Br(e,(s,r)=>{typeof s=="string"&&t.setAttribute(r,s)}),t.insert(0,this.toArray().map(s=>s instanceof I?s.clone():s)),t}toString(){const t=this.getAttributes(),e=[],s=[];for(const l in t)s.push(l);s.sort();const r=s.length;for(let l=0;l<r;l++){const c=s[l];e.push(c+'="'+t[c]+'"')}const i=this.nodeName.toLocaleLowerCase(),o=e.length>0?" "+e.join(" "):"";return`<${i}${o}>${super.toString()}</${i}>`}removeAttribute(t){this.doc!==null?k(this.doc,e=>{ce(e,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,e){this.doc!==null?k(this.doc,s=>{pn(s,this,t,e)}):this._prelimAttrs.set(t,e)}getAttribute(t){return wn(this,t)}hasAttribute(t){return Ks(this,t)}getAttributes(){return js(this)}toDOM(t=document,e={},s){const r=t.createElement(this.nodeName),i=this.getAttributes();for(const o in i){const l=i[o];typeof l=="string"&&r.setAttribute(o,l)}return Ft(this,o=>{r.appendChild(o.toDOM(t,e,s))}),s!==void 0&&s._createAssociation(r,this),r}_write(t){t.writeTypeRef(Jo),t.writeKey(this.nodeName)}}const vo=n=>new Vt(n.readKey());class xo extends be{constructor(t,e,s){super(t,s),this.childListChanged=!1,this.attributesChanged=new Set,e.forEach(r=>{r===null?this.childListChanged=!0:this.attributesChanged.add(r)})}}class ae extends ht{constructor(t){super(),this.hookName=t}_copy(){return new ae(this.hookName)}clone(){const t=new ae(this.hookName);return this.forEach((e,s)=>{t.set(s,e)}),t}toDOM(t=document,e={},s){const r=e[this.hookName];let i;return r!==void 0?i=r.createDom(this):i=document.createElement(this.hookName),i.setAttribute("data-yjs-hook",this.hookName),s!==void 0&&s._createAssociation(i,this),i}_write(t){t.writeTypeRef(Go),t.writeKey(this.hookName)}}const Uo=n=>new ae(n.readKey());class he extends Ct{get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new he}clone(){const t=new he;return t.applyDelta(this.toDelta()),t}toDOM(t=document,e,s){const r=t.createTextNode(this.toString());return s!==void 0&&s._createAssociation(r,this),r}toString(){return this.toDelta().map(t=>{const e=[];for(const r in t.attributes){const i=[];for(const o in t.attributes[r])i.push({key:o,value:t.attributes[r][o]});i.sort((o,l)=>o.key<l.key?-1:1),e.push({nodeName:r,attrs:i})}e.sort((r,i)=>r.nodeName<i.nodeName?-1:1);let s="";for(let r=0;r<e.length;r++){const i=e[r];s+=`<${i.nodeName}`;for(let o=0;o<i.attrs.length;o++){const l=i.attrs[o];s+=` ${l.key}="${l.value}"`}s+=">"}s+=t.insert;for(let r=e.length-1;r>=0;r--)s+=`</${e[r].nodeName}>`;return s}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(Po)}}const To=n=>new he;class mn{constructor(t,e){this.id=t,this.length=e}get deleted(){throw B()}mergeWith(t){return!1}write(t,e,s){throw B()}integrate(t,e){throw B()}}const Oo=0;class U extends mn{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,e){e>0&&(this.id.clock+=e,this.length-=e),Ms(t.doc.store,this)}write(t,e){t.writeInfo(Oo),t.writeLen(this.length-e)}getMissing(t,e){return null}}class zt{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new zt(this.content)}splice(t){throw B()}mergeWith(t){return!1}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeBuf(this.content)}getRef(){return 3}}const Ro=n=>new zt(n.readBuf());class Ht{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Ht(this.len)}splice(t){const e=new Ht(this.len-t);return this.len=t,e}mergeWith(t){return this.len+=t.len,!0}integrate(t,e){ie(t.deleteSet,e.id.client,e.id.clock,this.len),e.markDeleted()}delete(t){}gc(t){}write(t,e){t.writeLen(this.len-e)}getRef(){return 1}}const Bo=n=>new Ht(n.readLen()),Ws=(n,t)=>new gt({guid:n,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class Yt{constructor(t){t._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=t;const e={};this.opts=e,t.gc||(e.gc=!1),t.autoLoad&&(e.autoLoad=!0),t.meta!==null&&(e.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new Yt(Ws(this.doc.guid,this.opts))}splice(t){throw B()}mergeWith(t){return!1}integrate(t,e){this.doc._item=e,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,e){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}}const No=n=>new Yt(Ws(n.readString(),n.readAny()));class pt{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new pt(this.embed)}splice(t){throw B()}mergeWith(t){return!1}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeJSON(this.embed)}getRef(){return 5}}const Fo=n=>new pt(n.readJSON());class C{constructor(t,e){this.key=t,this.value=e}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new C(this.key,this.value)}splice(t){throw B()}mergeWith(t){return!1}integrate(t,e){const s=e.parent;s._searchMarker=null,s._hasFormatting=!0}delete(t){}gc(t){}write(t,e){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}}const Vo=n=>new C(n.readKey(),n.readJSON());class ue{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new ue(this.arr)}splice(t){const e=new ue(this.arr.slice(t));return this.arr=this.arr.slice(0,t),e}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){const s=this.arr.length;t.writeLen(s-e);for(let r=e;r<s;r++){const i=this.arr[r];t.writeString(i===void 0?"undefined":JSON.stringify(i))}}getRef(){return 2}}const Ho=n=>{const t=n.readLen(),e=[];for(let s=0;s<t;s++){const r=n.readString();r==="undefined"?e.push(void 0):e.push(JSON.parse(r))}return new ue(e)};class dt{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new dt(this.arr)}splice(t){const e=new dt(this.arr.slice(t));return this.arr=this.arr.slice(0,t),e}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){const s=this.arr.length;t.writeLen(s-e);for(let r=e;r<s;r++){const i=this.arr[r];t.writeAny(i)}}getRef(){return 8}}const $o=n=>{const t=n.readLen(),e=[];for(let s=0;s<t;s++)e.push(n.readAny());return new dt(e)};class ${constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new $(this.str)}splice(t){const e=new $(this.str.slice(t));this.str=this.str.slice(0,t);const s=this.str.charCodeAt(t-1);return s>=55296&&s<=56319&&(this.str=this.str.slice(0,t-1)+"�",e.str="�"+e.str.slice(1)),e}mergeWith(t){return this.str+=t.str,!0}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeString(e===0?this.str:this.str.slice(e))}getRef(){return 4}}const jo=n=>new $(n.readString()),Ko=[So,Do,Io,vo,Mo,Uo,To],zo=0,Yo=1,Xo=2,Jo=3,Wo=4,Go=5,Po=6;class G{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new G(this.type._copy())}splice(t){throw B()}mergeWith(t){return!1}integrate(t,e){this.type._integrate(t.doc,e)}delete(t){let e=this.type._start;for(;e!==null;)e.deleted?e.id.clock<(t.beforeState.get(e.id.client)||0)&&t._mergeStructs.push(e):e.delete(t),e=e.right;this.type._map.forEach(s=>{s.deleted?s.id.clock<(t.beforeState.get(s.id.client)||0)&&t._mergeStructs.push(s):s.delete(t)}),t.changed.delete(this.type)}gc(t){let e=this.type._start;for(;e!==null;)e.gc(t,!0),e=e.right;this.type._start=null,this.type._map.forEach(s=>{for(;s!==null;)s.gc(t,!0),s=s.left}),this.type._map=new Map}write(t,e){this.type._write(t)}getRef(){return 7}}const qo=n=>new G(Ko[n.readTypeRef()](n)),de=(n,t,e)=>{const{client:s,clock:r}=t.id,i=new E(b(s,r+e),t,b(s,r+e-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(e));return t.deleted&&i.markDeleted(),t.keep&&(i.keep=!0),t.redone!==null&&(i.redone=b(t.redone.client,t.redone.clock+e)),t.right=i,i.right!==null&&(i.right.left=i),n._mergeStructs.push(i),i.parentSub!==null&&i.right===null&&i.parent._map.set(i.parentSub,i),t.length=e,i};class E extends mn{constructor(t,e,s,r,i,o,l,c){super(t,c.getLength()),this.origin=s,this.left=e,this.right=r,this.rightOrigin=i,this.parent=o,this.parentSub=l,this.redone=null,this.content=c,this.info=this.content.isCountable()?Un:0}set marker(t){(this.info&Ae)>0!==t&&(this.info^=Ae)}get marker(){return(this.info&Ae)>0}get keep(){return(this.info&xn)>0}set keep(t){this.keep!==t&&(this.info^=xn)}get countable(){return(this.info&Un)>0}get deleted(){return(this.info&Ce)>0}set deleted(t){this.deleted!==t&&(this.info^=Ce)}markDeleted(){this.info|=Ce}getMissing(t,e){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=L(e,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=L(e,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===yt&&this.id.client!==this.parent.client&&this.parent.clock>=L(e,this.parent.client))return this.parent.client;if(this.origin&&(this.left=jn(t,e,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=et(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===U||this.right&&this.right.constructor===U)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===E&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===E&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===yt){const s=ve(e,this.parent);s.constructor===U?this.parent=null:this.parent=s.content.type}return null}integrate(t,e){if(e>0&&(this.id.clock+=e,this.left=jn(t,t.doc.store,b(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(e),this.length-=e),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let s=this.left,r;if(s!==null)r=s.right;else if(this.parentSub!==null)for(r=this.parent._map.get(this.parentSub)||null;r!==null&&r.left!==null;)r=r.left;else r=this.parent._start;const i=new Set,o=new Set;for(;r!==null&&r!==this.right;){if(o.add(r),i.add(r),Pt(this.origin,r.origin)){if(r.id.client<this.id.client)s=r,i.clear();else if(Pt(this.rightOrigin,r.rightOrigin))break}else if(r.origin!==null&&o.has(ve(t.doc.store,r.origin)))i.has(ve(t.doc.store,r.origin))||(s=r,i.clear());else break;r=r.right}this.left=s}if(this.left!==null){const s=this.left.right;this.right=s,this.left.right=this}else{let s;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,this.parent._start=this;this.right=s}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(t)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),Ms(t.doc.store,this),this.content.integrate(t,this),zn(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new U(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;t!==null&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;t!==null&&t.deleted;)t=t.left;return t}get lastId(){return this.length===1?this.id:b(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Pt(t.origin,this.lastId)&&this.right===t&&Pt(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const e=this.parent._searchMarker;return e&&e.forEach(s=>{s.p===t&&(s.p=this,!this.deleted&&this.countable&&(s.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const e=this.parent;this.countable&&this.parentSub===null&&(e._length-=this.length),this.markDeleted(),ie(t.deleteSet,this.id.client,this.id.clock,this.length),zn(t,e,this.parentSub),this.content.delete(t)}}gc(t,e){if(!this.deleted)throw V();this.content.gc(t),e?so(t,this,new U(this.id,this.length)):this.content=new Ht(this.length)}write(t,e){const s=e>0?b(this.id.client,this.id.clock+e-1):this.origin,r=this.rightOrigin,i=this.parentSub,o=this.content.getRef()&pe|(s===null?0:x)|(r===null?0:z)|(i===null?0:Ot);if(t.writeInfo(o),s!==null&&t.writeLeftID(s),r!==null&&t.writeRightID(r),s===null&&r===null){const l=this.parent;if(l._item!==void 0){const c=l._item;if(c===null){const a=eo(l);t.writeParentInfo(!0),t.writeString(a)}else t.writeParentInfo(!1),t.writeLeftID(c.id)}else l.constructor===String?(t.writeParentInfo(!0),t.writeString(l)):l.constructor===yt?(t.writeParentInfo(!1),t.writeLeftID(l)):V();i!==null&&t.writeString(i)}this.content.write(t,e)}}const Gs=(n,t)=>Zo[t&pe](n),Zo=[()=>{V()},Bo,Ho,Ro,jo,Fo,Vo,qo,$o,No,()=>{V()}],Qo=10;class T extends mn{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,e){V()}write(t,e){t.writeInfo(Qo),p(t.restEncoder,this.length-e)}getMissing(t,e){return null}}const Ps=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},qs="__ $YJS$ __";Ps[qs]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");Ps[qs]=!0;const Zs=new Map;class tl{constructor(t){this.room=t,this.onmessage=null,this._onChange=e=>e.key===t&&this.onmessage!==null&&this.onmessage({data:hi(e.newValue||"")}),Ur(this._onChange)}postMessage(t){ss.setItem(this.room,ai(ri(t)))}close(){Tr(this._onChange)}}const el=typeof BroadcastChannel>"u"?tl:BroadcastChannel,yn=n=>J(Zs,n,()=>{const t=lt(),e=new el(n);return e.onmessage=s=>t.forEach(r=>r(s.data,"broadcastchannel")),{bc:e,subs:t}}),nl=(n,t)=>(yn(n).subs.add(t),t),sl=(n,t)=>{const e=yn(n),s=e.subs.delete(t);return s&&e.subs.size===0&&(e.bc.close(),Zs.delete(n)),s},mt=(n,t,e=null)=>{const s=yn(n);s.bc.postMessage(t),s.subs.forEach(r=>r(t,e))},Qs=0,bn=1,tr=2,Xe=(n,t)=>{p(n,Qs);const e=Qi(t);D(n,e)},er=(n,t,e)=>{p(n,bn),D(n,hn(t,e))},rl=(n,t,e)=>er(t,e,M(n)),nr=(n,t,e)=>{try{Es(t,M(n),e)}catch(s){console.error("Caught error while handling a Yjs update",s)}},il=(n,t)=>{p(n,tr),D(n,t)},ol=nr,ll=(n,t,e,s)=>{const r=m(n);switch(r){case Qs:rl(n,t,e);break;case bn:nr(n,e,s);break;case tr:ol(n,e,s);break;default:throw new Error("Unknown message type")}return r},cl=0,al=(n,t,e)=>{switch(m(n)){case cl:e(t,Z(n))}},Te=3e4;class hl extends ge{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{const e=ct();this.getLocalState()!==null&&Te/2<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const s=[];this.meta.forEach((r,i)=>{i!==this.clientID&&Te<=e-r.lastUpdated&&this.states.has(i)&&s.push(i)}),s.length>0&&kn(this,s,"timeout")},Y(Te/10)),t.on("destroy",()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(t){const e=this.clientID,s=this.meta.get(e),r=s===void 0?0:s.clock+1,i=this.states.get(e);t===null?this.states.delete(e):this.states.set(e,t),this.meta.set(e,{clock:r,lastUpdated:ct()});const o=[],l=[],c=[],a=[];t===null?a.push(e):i==null?t!=null&&o.push(e):(l.push(e),xt(i,t)||c.push(e)),(o.length>0||c.length>0||a.length>0)&&this.emit("change",[{added:o,updated:c,removed:a},"local"]),this.emit("update",[{added:o,updated:l,removed:a},"local"])}setLocalStateField(t,e){const s=this.getLocalState();s!==null&&this.setLocalState({...s,[t]:e})}getStates(){return this.states}}const kn=(n,t,e)=>{const s=[];for(let r=0;r<t.length;r++){const i=t[r];if(n.states.has(i)){if(n.states.delete(i),i===n.clientID){const o=n.meta.get(i);n.meta.set(i,{clock:o.clock+1,lastUpdated:ct()})}s.push(i)}}s.length>0&&(n.emit("change",[{added:[],updated:[],removed:s},e]),n.emit("update",[{added:[],updated:[],removed:s},e]))},Ut=(n,t,e=n.states)=>{const s=t.length,r=v();p(r,s);for(let i=0;i<s;i++){const o=t[i],l=e.get(o)||null,c=n.meta.get(o).clock;p(r,o),p(r,c),ot(r,JSON.stringify(l))}return S(r)},ul=(n,t,e)=>{const s=nt(t),r=ct(),i=[],o=[],l=[],c=[],a=m(s);for(let h=0;h<a;h++){const d=m(s);let u=m(s);const f=JSON.parse(Z(s)),g=n.meta.get(d),w=n.states.get(d),_=g===void 0?0:g.clock;(_<u||_===u&&f===null&&n.states.has(d))&&(f===null?d===n.clientID&&n.getLocalState()!=null?u++:n.states.delete(d):n.states.set(d,f),n.meta.set(d,{clock:u,lastUpdated:r}),g===void 0&&f!==null?i.push(d):g!==void 0&&f===null?c.push(d):f!==null&&(xt(f,w)||l.push(d),o.push(d)))}(i.length>0||l.length>0||c.length>0)&&n.emit("change",[{added:i,updated:l,removed:c},e]),(i.length>0||o.length>0||c.length>0)&&n.emit("update",[{added:i,updated:o,removed:c},e])},dl=n=>Nr(n,(t,e)=>`${encodeURIComponent(e)}=${encodeURIComponent(t)}`).join("&");var st=0,sr=3,kt=1,fl=2,gl=typeof window>"u";function pl(n,t){if(!n)throw new Error(t)}var Xt=[];Xt[st]=(n,t,e,s,r)=>{p(n,st);const i=ll(t,n,e.doc,e);s&&i===bn&&!e.synced&&(e.synced=!0)};Xt[sr]=(n,t,e,s,r)=>{p(n,kt),D(n,Ut(e.awareness,Array.from(e.awareness.getStates().keys())))};Xt[kt]=(n,t,e,s,r)=>{ul(e.awareness,M(t),e)};Xt[fl]=(n,t,e,s,r)=>{al(t,e.doc,(i,o)=>wl(e,o))};var Gn=3e4;function wl(n,t){console.warn(`Permission denied to access ${n.url}.
4
+ ${t}`)}function rr(n,t,e){const s=nt(t),r=v(),i=m(s),o=n.messageHandlers[i];return o?o(r,s,n,e,i):console.error("Unable to compute message"),r}function ir(n){if(n.shouldConnect&&n.ws===null){const t=new n._WS(n.url);t.binaryType="arraybuffer",n.ws=t,n.wsconnecting=!0,n.wsconnected=!1,n.synced=!1,t.onmessage=e=>{if(typeof e.data=="string")return;n.wsLastMessageReceived=ct();const s=rr(n,new Uint8Array(e.data),!0);nn(s)>1&&t.send(S(s))},t.onerror=e=>{n.emit("connection-error",[e,n])},t.onclose=e=>{n.emit("connection-close",[e,n]),n.ws=null,n.wsconnecting=!1,n.wsconnected?(n.wsconnected=!1,n.synced=!1,kn(n.awareness,Array.from(n.awareness.getStates().keys()).filter(s=>s!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(ir,Pe(_r(2,n.wsUnsuccessfulReconnects)*100,n.maxBackoffTime),n)},t.onopen=()=>{n.wsLastMessageReceived=ct(),n.wsconnecting=!1,n.wsconnected=!0,n.wsUnsuccessfulReconnects=0,n.emit("status",[{status:"connected"}]);const e=v();if(p(e,st),Xe(e,n.doc),t.send(S(e)),n.awareness.getLocalState()!==null){const s=v();p(s,kt),D(s,Ut(n.awareness,[n.doc.clientID])),t.send(S(s))}},n.emit("status",[{status:"connecting"}])}}function Oe(n,t){const e=n.ws;n.wsconnected&&e&&e.readyState===e.OPEN&&e.send(t),n.bcconnected&&mt(n.bcChannel,t,n)}var ml=class extends ge{constructor(t,e,s,{connect:r=!0,awareness:i=new hl(s),params:o={},WebSocketPolyfill:l=WebSocket,resyncInterval:c=-1,maxBackoffTime:a=2500,disableBc:h=gl}={}){super();y(this,"maxBackoffTime");y(this,"bcChannel");y(this,"url");y(this,"roomname");y(this,"doc");y(this,"_WS");y(this,"awareness");y(this,"wsconnected");y(this,"wsconnecting");y(this,"bcconnected");y(this,"disableBc");y(this,"wsUnsuccessfulReconnects");y(this,"messageHandlers");y(this,"_synced");y(this,"ws");y(this,"wsLastMessageReceived");y(this,"shouldConnect");y(this,"_resyncInterval");y(this,"_bcSubscriber");y(this,"_updateHandler");y(this,"_awarenessUpdateHandler");y(this,"_unloadHandler");y(this,"_checkInterval");for(;t[t.length-1]==="/";)t=t.slice(0,t.length-1);const d=dl(o);this.maxBackoffTime=a,this.bcChannel=t+"/"+e,this.url=t+"/"+e+(d.length===0?"":"?"+d),this.roomname=e,this.doc=s,this._WS=l,this.awareness=i,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=h,this.wsUnsuccessfulReconnects=0,this.messageHandlers=Xt.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=r,this._resyncInterval=0,c>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const u=v();p(u,st),Xe(u,s),this.ws.send(S(u))}},c)),this._bcSubscriber=(u,f)=>{if(f!==this){const g=rr(this,new Uint8Array(u),!1);nn(g)>1&&mt(this.bcChannel,S(g),this)}},this._updateHandler=(u,f)=>{if(f!==this){const g=v();p(g,st),il(g,u),Oe(this,S(g))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:u,updated:f,removed:g},w)=>{const _=u.concat(f).concat(g),j=v();p(j,kt),D(j,Ut(i,_)),Oe(this,S(j))},this._unloadHandler=()=>{kn(this.awareness,[s.clientID],"window unload")},typeof window<"u"?window.addEventListener("unload",this._unloadHandler):typeof process<"u"&&process.on("exit",this._unloadHandler),i.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&Gn<ct()-this.wsLastMessageReceived&&(pl(this.ws!==null,"ws must not be null"),this.ws.close())},Gn/10),r&&this.connect()}get synced(){return this._synced}set synced(t){this._synced!==t&&(this._synced=t,this.emit("synced",[t]),this.emit("sync",[t]))}destroy(){this._resyncInterval!==0&&clearInterval(this._resyncInterval),clearInterval(this._checkInterval),this.disconnect(),typeof window<"u"?window.removeEventListener("unload",this._unloadHandler):typeof process<"u"&&process.off("exit",this._unloadHandler),this.awareness.off("update",this._awarenessUpdateHandler),this.doc.off("update",this._updateHandler),super.destroy()}connectBc(){if(this.disableBc)return;this.bcconnected||(nl(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const t=v();p(t,st),Xe(t,this.doc),mt(this.bcChannel,S(t),this);const e=v();p(e,st),er(e,this.doc),mt(this.bcChannel,S(e),this);const s=v();p(s,sr),mt(this.bcChannel,S(s),this);const r=v();p(r,kt),D(r,Ut(this.awareness,[this.doc.clientID])),mt(this.bcChannel,S(r),this)}disconnectBc(){const t=v();p(t,kt),D(t,Ut(this.awareness,[this.doc.clientID],new Map)),Oe(this,S(t)),this.bcconnected&&(sl(this.bcChannel,this._bcSubscriber),this.bcconnected=!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&this.ws.close()}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(ir(this),this.connectBc())}};function yl(){if(crypto.randomUUID)return crypto.randomUUID();let n=new Date().getTime(),t=typeof performance<"u"&&performance.now&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){let s=Math.random()*16;return n>0?(s=(n+s)%16|0,n=Math.floor(n/16)):(s=(t+s)%16|0,t=Math.floor(t/16)),(e==="x"?s:s&3|8).toString(16)})}function Pn(n,t,e){if(typeof n!==e)throw new Error(`Invalid "${t}" parameter provided to YPartyKitProvider. Expected: ${e}, received: ${n}`)}var bl=class extends WebSocket{send(n){typeof n!="string"&&mr(n,t=>super.send(t))}},rt,ts,kl=(ts=class extends ml{constructor(t,e,s,r={}){Pn(t,"host","string"),Pn(e,"room","string"),t=t.replace(/^(http|https|ws|wss):\/\//,""),t.endsWith("/")&&t.slice(0,-1);const i=`${t.startsWith("localhost:")||t.startsWith("127.0.0.1:")?"ws":"wss"}://${t}${r.party?`/parties/${r.party}`:"/party"}`,o=r.connectionId??yl(),{params:l,connect:c=!0,...a}=r,h={...a,connect:!1,WebSocketPolyfill:bl};super(i,e,s??new gt,h);y(this,"id");En(this,rt,void 0);this.id=o,Cn(this,rt,l),c&&this.connect()}connect(){Promise.resolve(typeof Wt(this,rt)=="function"?Wt(this,rt).call(this):Wt(this,rt)).then(t=>{const e=new URLSearchParams([["_pk",this.id]]);if(t)for(const[r,i]of Object.entries(t))i!=null&&e.append(r,i);const s=new URL(this.url);s.search=e.toString(),this.url=s.toString(),super.connect()}).catch(t=>{throw console.error("Failed to open connecton to PartyKit",t),new Error(t)})}},rt=new WeakMap,ts);const wt=n=>Dt((t,e)=>{n.onerror=s=>e(new Error(s.target.error)),n.onsuccess=s=>t(s.target.result)}),Sl=(n,t)=>Dt((e,s)=>{const r=indexedDB.open(n);r.onupgradeneeded=i=>t(i.target.result),r.onerror=i=>s(X(i.target.error)),r.onsuccess=i=>{const o=i.target.result;o.onversionchange=()=>{o.close()},typeof addEventListener<"u"&&addEventListener("unload",()=>o.close()),e(o)}}),_l=n=>wt(indexedDB.deleteDatabase(n)),Dl=(n,t)=>t.forEach(e=>n.createObjectStore.apply(n,e)),Mt=(n,t,e="readwrite")=>{const s=n.transaction(t,e);return t.map(r=>xl(s,r))},or=(n,t)=>wt(n.count(t)),El=(n,t)=>wt(n.get(t)),lr=(n,t)=>wt(n.delete(t)),Cl=(n,t,e)=>wt(n.put(t,e)),Je=(n,t)=>wt(n.add(t)),Al=(n,t,e)=>wt(n.getAll(t,e)),Ll=(n,t,e)=>{let s=null;return vl(n,t,r=>(s=r,!1),e).then(()=>s)},Il=(n,t=null)=>Ll(n,t,"prev"),Ml=(n,t)=>Dt((e,s)=>{n.onerror=s,n.onsuccess=async r=>{const i=r.target.result;if(i===null||await t(i)===!1)return e();i.continue()}}),vl=(n,t,e,s="next")=>Ml(n.openKeyCursor(t,s),r=>e(r.key)),xl=(n,t)=>n.objectStore(t),Ul=(n,t)=>IDBKeyRange.upperBound(n,t),Tl=(n,t)=>IDBKeyRange.lowerBound(n,t),Re="custom",cr="updates",ar=500,hr=(n,t=()=>{},e=()=>{})=>{const[s]=Mt(n.db,[cr]);return Al(s,Tl(n._dbref,!1)).then(r=>{n._destroyed||(t(s),k(n.doc,()=>{r.forEach(i=>Es(n.doc,i))},n,!1),e(s))}).then(()=>Il(s).then(r=>{n._dbref=r+1})).then(()=>or(s).then(r=>{n._dbsize=r})).then(()=>s)},Ol=(n,t=!0)=>hr(n).then(e=>{(t||n._dbsize>=ar)&&Je(e,hn(n.doc)).then(()=>lr(e,Ul(n._dbref,!0))).then(()=>or(e).then(s=>{n._dbsize=s}))});class Rl extends ge{constructor(t,e){super(),this.doc=e,this.name=t,this._dbref=0,this._dbsize=0,this._destroyed=!1,this.db=null,this.synced=!1,this._db=Sl(t,s=>Dl(s,[["updates",{autoIncrement:!0}],["custom"]])),this.whenSynced=Dt(s=>this.on("synced",()=>s(this))),this._db.then(s=>{this.db=s,hr(this,o=>Je(o,hn(e)),()=>{if(this._destroyed)return this;this.synced=!0,this.emit("synced",[this])})}),this._storeTimeout=1e3,this._storeTimeoutId=null,this._storeUpdate=(s,r)=>{if(this.db&&r!==this){const[i]=Mt(this.db,[cr]);Je(i,s),++this._dbsize>=ar&&(this._storeTimeoutId!==null&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout(()=>{Ol(this,!1),this._storeTimeoutId=null},this._storeTimeout))}},e.on("update",this._storeUpdate),this.destroy=this.destroy.bind(this),e.on("destroy",this.destroy)}destroy(){return this._storeTimeoutId&&clearTimeout(this._storeTimeoutId),this.doc.off("update",this._storeUpdate),this.doc.off("destroy",this.destroy),this._destroyed=!0,this._db.then(t=>{t.close()})}clearData(){return this.destroy().then(()=>{_l(this.name)})}get(t){return this._db.then(e=>{const[s]=Mt(e,[Re],"readonly");return El(s,t)})}set(t,e){return this._db.then(s=>{const[r]=Mt(s,[Re]);return Cl(r,e,t)})}del(t){return this._db.then(e=>{const[s]=Mt(e,[Re]);return lr(s,t)})}}const Bl={ctrlKey:"Control",altKey:"Alt",shiftKey:"Shift",metaKey:"Meta"},Nl="can-duplicate-to";var _e=(n=>(n.CanPlay="can-play",n.CanMove="can-move",n.CanSpin="can-spin",n.CanGrow="can-grow",n.CanToggle="can-toggle",n.CanDuplicate="can-duplicate",n))(_e||{});function Fl(n){return n.id}const ur=`url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='44' height='53' viewport='0 0 100 100' style='fill:black;font-size:26px;'><text y='40%'>🚿</text></svg>")
5
+ 16 0,
6
+ auto`,Vl=`url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='40' height='48' viewport='0 0 100 100' style='fill:black;font-size:24px;'><text y='50%'>✂️</text></svg>") 16 0,auto`;function qn(n,{getData:t,getElement:e,getLocalData:s,setLocalData:r}){const i=t(),o=s(),l=e();if(o.isHovering=!0,n.altKey){if(i.scale<=.5){l.style.cursor="not-allowed";return}l.style.cursor=Vl}else{if(i.scale>=i.maxScale){l.style.cursor="not-allowed";return}l.style.cursor=ur}r(o)}function Qt(n){if("touches"in n){const{clientX:t,clientY:e}=n.touches[0];return{clientX:t,clientY:e}}return{clientX:n.clientX,clientY:n.clientY}}const Hl={["can-move"]:{defaultData:{x:0,y:0},defaultLocalData:{startMouseX:0,startMouseY:0},updateElement:({element:n,data:t})=>{n.style.transform=`translate(${t.x}px, ${t.y}px)`},onDragStart:(n,{setLocalData:t})=>{const{clientX:e,clientY:s}=Qt(n);t({startMouseX:e,startMouseY:s})},onDrag:(n,{data:t,localData:e,setData:s,setLocalData:r,element:i})=>{const{clientX:o,clientY:l}=Qt(n),{top:c,left:a,bottom:h,right:d}=i.getBoundingClientRect();d>window.outerWidth&&o>e.startMouseX||h>window.innerHeight&&l>e.startMouseY||a<0&&o<e.startMouseX||c<0&&l<e.startMouseY||(s({x:t.x+o-e.startMouseX,y:t.y+l-e.startMouseY}),r({startMouseX:o,startMouseY:l}))},resetShortcut:"shiftKey"},["can-spin"]:{defaultData:{rotation:0},defaultLocalData:{startMouseX:0},updateElement:({element:n,data:t})=>{n.style.transform=`rotate(${t.rotation}deg)`},onDragStart:(n,{setLocalData:t})=>{const{clientX:e}=Qt(n);t({startMouseX:e})},onDrag:(n,{data:t,localData:e,setData:s,setLocalData:r})=>{const{clientX:i}=Qt(n);let o=Math.abs(i-e.startMouseX)*2,l=t.rotation;i>e.startMouseX?l+=o:i<e.startMouseX&&(l-=o),s({rotation:l}),r({startMouseX:i})},resetShortcut:"shiftKey"},["can-toggle"]:{defaultData:!1,updateElement:({element:n,data:t})=>{n.classList.toggle("clicked",t)},onClick:(n,{data:t,setData:e})=>{e(!t)},resetShortcut:"shiftKey"},["can-grow"]:{defaultData:{scale:1},defaultLocalData:{maxScale:2,isHovering:!1},updateElement:({element:n,data:t})=>{n.style.transform=`scale(${t.scale})`},onClick:(n,{data:t,element:e,setData:s,localData:r})=>{let{scale:i}=t;if(n.altKey){if(t.scale<=.5)return;i-=.1}else{if(e.style.cursor=ur,t.scale>=r.maxScale)return;i+=.1}s({...t,scale:i})},additionalSetup:n=>{n.getElement().addEventListener("mouseenter",t=>{qn(t,n);const e=s=>qn(s,n);document.addEventListener("keydown",e),document.addEventListener("keyup",e),n.getElement().addEventListener("mouseleave",s=>{document.removeEventListener("keydown",e),document.removeEventListener("keyup",e)})})},resetShortcut:"shiftKey"},["can-duplicate"]:{defaultData:[],defaultLocalData:[],updateElement:({data:n,localData:t,setLocalData:e,element:s})=>{var r;const i=s.getAttribute("can-duplicate"),o=document.getElementById(i);let l=document.getElementById((r=t.slice(-1))==null?void 0:r[0])??null;if(!o){console.error(`Element with id ${i} not found. Cannot duplicate.`);return}const c=s.getAttribute(Nl);function a(d){if(c){const u=document.getElementById(c)||document.querySelector(c);if(u){u.appendChild(d);return}}o.parentNode.insertBefore(d,(l||o).nextSibling)}const h=new Set(t);for(const d of n){if(h.has(d))continue;const u=o.cloneNode(!0);Object.assign(u,{...o}),u.id=d,a(u),t.push(d),window.playhtml.setupPlayElement(u),l=u}e(t)},onClick:(n,{data:t,element:e,setData:s})=>{const r=e.getAttribute("can-duplicate")+"-"+Math.random().toString(36).substr(2,9);s([...t,r])},isValidElementForTag:n=>{const t=n.getAttribute("can-duplicate");return t?(document.getElementById(t)||console.warn(`can-duplicate element (${n.id}) duplicate element ("${t}") not found.`),!0):!1}}},Zn=(n,t=300)=>{let e;return function(...s){clearTimeout(e),e=setTimeout(()=>n.apply(this,s),t)}};class $l{constructor(t){y(this,"defaultData");y(this,"localData");y(this,"awareness",[]);y(this,"selfAwareness");y(this,"element");y(this,"_data");y(this,"onChange");y(this,"onAwarenessChange");y(this,"debouncedOnChange");y(this,"resetShortcut");y(this,"updateElement");y(this,"updateElementAwareness");y(this,"triggerAwarenessUpdate");y(this,"onClick");y(this,"onDrag");y(this,"onDragStart");const{element:e,onChange:s,onAwarenessChange:r,defaultData:i,defaultLocalData:o,myDefaultAwareness:l,data:c,awareness:a,updateElement:h,updateElementAwareness:d,additionalSetup:u,debounceMs:f,triggerAwarenessUpdate:g}=t;this.element=e,this.defaultData=i instanceof Function?i(e):i,this.localData=o instanceof Function?o(e):o,this.triggerAwarenessUpdate=g,this.onChange=s,this.debouncedOnChange=Zn(this.onChange,f),this.onAwarenessChange=r,this.updateElement=h,this.updateElementAwareness=d;const w=c===void 0?this.defaultData:c;a!==void 0&&(this.__awareness=a);const _=l instanceof Function?l(e):l;_!==void 0&&this.setLocalAwareness(_),this._data=w,this.__data=w,this.reinitializeElementData(t),u&&u(this.getSetupData())}reinitializeElementData({element:t,onChange:e,onAwarenessChange:s,updateElement:r,updateElementAwareness:i,onClick:o,onDrag:l,onDragStart:c,resetShortcut:a,debounceMs:h,triggerAwarenessUpdate:d}){this.triggerAwarenessUpdate=d,this.onChange=e,this.debouncedOnChange=Zn(this.onChange,h),this.onAwarenessChange=s,this.updateElement=r,this.updateElementAwareness=i,o&&!this.onClick&&t.addEventListener("click",u=>{var f;(f=this.onClick)==null||f.call(this,u,this.getEventHandlerData())}),this.onClick=o,l&&!this.onDrag&&(t.addEventListener("touchstart",u=>{var w;u.preventDefault(),(w=this.onDragStart)==null||w.call(this,u,this.getEventHandlerData());const f=_=>{var j;_.preventDefault(),(j=this.onDrag)==null||j.call(this,_,this.getEventHandlerData())},g=_=>{document.removeEventListener("touchmove",f),document.removeEventListener("touchend",g)};document.addEventListener("touchmove",f),document.addEventListener("touchend",g)}),t.addEventListener("mousedown",u=>{var w;(w=this.onDragStart)==null||w.call(this,u,this.getEventHandlerData());const f=_=>{var j;_.preventDefault(),(j=this.onDrag)==null||j.call(this,_,this.getEventHandlerData())},g=_=>{document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",g)};document.addEventListener("mousemove",f),document.addEventListener("mouseup",g)})),this.onDrag=l,this.onDragStart=c,a&&!this.resetShortcut&&(t.title||(t.title=`Hold down the ${Bl[a]} key while clicking to reset.`),t.reset=this.reset,t.addEventListener("click",u=>{switch(this.resetShortcut){case"ctrlKey":if(!u.ctrlKey)return;break;case"altKey":if(!u.altKey)return;break;case"shiftKey":if(!u.shiftKey)return;break;case"metaKey":if(!u.metaKey)return;break;default:return}this.reset(),u.preventDefault(),u.stopPropagation()})),this.resetShortcut=a}get data(){return this._data}setLocalData(t){this.localData=t}set __data(t){this._data=t,this.updateElement(this.getEventHandlerData())}set __awareness(t){this.updateElementAwareness&&(this.awareness=t,this.updateElementAwareness(this.getAwarenessEventHandlerData()))}getEventHandlerData(){return{element:this.element,data:this.data,localData:this.localData,awareness:this.awareness,setData:t=>this.setData(t),setLocalData:t=>this.setLocalData(t),setLocalAwareness:t=>this.setLocalAwareness(t)}}getAwarenessEventHandlerData(){return{...this.getEventHandlerData(),myAwareness:this.selfAwareness}}getSetupData(){return{getElement:()=>this.element,getData:()=>this.data,getLocalData:()=>this.localData,getAwareness:()=>this.awareness,setData:t=>this.setData(t),setLocalData:t=>this.setLocalData(t),setLocalAwareness:t=>this.setLocalAwareness(t)}}setData(t){this.onChange(t)}setLocalAwareness(t){var e;t!==this.selfAwareness&&(this.selfAwareness=t,this.onAwarenessChange(t),(e=this.triggerAwarenessUpdate)==null||e.call(this))}setDataDebounced(t){this.debouncedOnChange(t)}reset(){this.setData(this.defaultData)}}const jl="playhtml.spencerc99.partykit.dev",Be=new gt;function Kl(){return window.location.pathname+window.location.search}let Q,N,F;const Qn=new Map;let Jt=Hl;function We(){return[_e.CanPlay,...Object.keys(Jt)]}let Sn=!1,Ge=!0;function zl({room:n=Kl(),host:t=jl,extraCapabilities:e}={}){if(!Ge){console.error("playhtml already set up!");return}const s=encodeURIComponent(window.location.hostname+"-"+n),r=t;if(console.log(`࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂
7
+ ࿂࿂࿂࿂ ࿂ ࿂ ࿂ ࿂ ࿂ ࿂࿂࿂࿂
8
+ ࿂࿂࿂࿂ booting up playhtml... ࿂࿂࿂࿂
9
+ ࿂࿂࿂࿂ https://playhtml.fun ࿂࿂࿂࿂
10
+ ࿂࿂࿂࿂ ࿂ ࿂ ࿂ ࿂ ࿂࿂࿂࿂
11
+ ࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂`),Q=new kl(r,s,Be),N=Be.getMap("playhtml-global"),F=new Map,new Rl(s,Be),fe.globalData=N,fe.elementHandlers=F,e)for(const[i,o]of Object.entries(e))Jt[i]=o;return Q.on("sync",i=>{i||console.error("Issue connecting to yjs..."),Sn=!0,fr()}),Q}function Yl(n,t){const e=Q.awareness.getLocalState();return((e==null?void 0:e[n])??{})[t]}function _n(n){return n instanceof HTMLElement}function Xl(n,t,e,s){const r=N.get(t);return{...e,data:r.get(s)??e.defaultData,awareness:Yl(t,s)??e.myDefaultAwareness!==void 0?[e.myDefaultAwareness]:void 0,element:n,onChange:o=>{r.get(s)!==o&&r.set(s,o)},onAwarenessChange:o=>{var c;const l=((c=Q.awareness.getLocalState())==null?void 0:c[t])||{};l[s]!==o&&(l[s]=o,Q.awareness.setLocalStateField(t,l))},triggerAwarenessUpdate:()=>{dr()}}}function Jl(n){return n.defaultData!==void 0&&typeof n.defaultData=="object"&&n.updateElement!==void 0}function Wl(n,t){if(n===_e.CanPlay){const e=t;return{defaultData:e.defaultData,defaultLocalData:e.defaultLocalData,myDefaultAwareness:e.myDefaultAwareness,updateElement:e.updateElement,updateElementAwareness:e.updateElementAwareness,onDrag:e.onDrag,onDragStart:e.onDragStart,onClick:e.onClick,additionalSetup:e.additionalSetup,resetShortcut:e.resetShortcut,debounceMs:e.debounceMs,isValidElementForTag:e.isValidElementForTag}}return Jt[n]}function dr(){const n=new Map;function t(e,s,r,i){n.has(e)||n.set(e,new Map);const o=n.get(e);o.has(s)||o.set(s,new Map),o.get(s).set(r,i)}Q.awareness.getStates().forEach((e,s)=>{var r;for(const[i,o]of Object.entries(e)){const l=F.get(i);if(l)for(const[c,a]of l){if(!(c in o))continue;const h=o[c];t(i,c,s,h)}}for(const[i,o]of n){const l=F.get(i);if(l)for(const[c,a]of l){const h=(r=o.get(c))==null?void 0:r.values();if(!h)continue;let d=Array.from(h);a.__awareness=d}}})}function fr(){console.log("[PLAYHTML]: Setting up elements... Time to have some fun 🛝"),console.log(We());for(const n of We()){const t=Array.from(document.querySelectorAll(`[${n}]`)).filter(_n);if(t.length)for(let e=0;e<t.length;e++){const s=t[e];De(s,n)}}Ge&&(N.observe(n=>{n.changes.keys.forEach((t,e)=>{t.action==="add"&&N.set(e,N.get(e))})}),Q.awareness.on("change",()=>dr()),Ge=!1)}const fe={init:zl,setupPlayElements:fr,setupPlayElement:ql,removePlayElement:Zl,setupPlayElementForTag:De,globalData:void 0,elementHandlers:void 0};window.playhtml=fe;function Gl(n){if(F.has(n)||!Sn)return;F.set(n,new Map),n!==_e.CanPlay&&Jt[n],N.get(n)||N.set(n,new ht);const t=N.get(n);t.observe(e=>{e.changes.keys.forEach((s,r)=>{const i=F.get(n);if(s.action==="add"){const o=document.getElementById(r);if(!_n(o)){console.log(`Element ${r} not an HTML element. Ignoring.`);return}De(o,n)}else if(s.action==="update"){const o=i.get(r);o.__data=t.get(r)}else s.action==="delete"?i.delete(r):console.log(`Unhandled action: ${s.action}`)})})}function Pl(n,t){var e,s;return((s=(e=Jt[t])==null?void 0:e.isValidElementForTag)==null?void 0:s.call(e,n))??!0}function De(n,t){var l;if(!Pl(n,t)||!Sn)return;if(!n.id){const c=n.getAttribute("selector-id");if(c){const a=Qn.get(c)??0;n.id=btoa(`${t}-${c}-${a}`),Qn.set(c,a+1)}else n.id=btoa(`${t}-${n.innerHTML}}`)}const e=Fl(n);if(!e){console.error(`Element ${n} does not have an acceptable ID. Please add an ID to the element to register it as a playhtml element.`);return}Gl(t);const s=F.get(t),r=Wl(t,n);if(!Jl(r)){console.error(`Element ${e} does not have proper info to initial a playhtml element. Please refer to https://github.com/spencerc99/playhtml#can-play for troubleshooting help.`);return}const i=N.get(t),o=Xl(n,t,r,e);if(s.has(e)){s.get(e).reinitializeElementData(o);return}else s.set(e,new $l(o));i.get(e)===void 0&&r.defaultData!==void 0&&i.set(e,r.defaultData),(l=o.triggerAwarenessUpdate)==null||l.call(o),n.classList.add("__playhtml-element"),n.classList.add(`__playhtml-${t}`),n.style.setProperty("--jiggle-delay",`${Math.random()*1}s;}`)}function ql(n){if(!_n(n)){console.log(`Element ${n.id} not an HTML element. Ignoring.`);return}for(const t of We())n.hasAttribute(t)&&De(n,t)}function Zl(n){if(!(!n||!n.id))for(const t of Object.keys(F)){const e=F.get(t);e.has(n.id)&&e.delete(n.id)}}exports.playhtml=fe;