playhtml 1.3.0 → 1.3.1
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/README.md +14 -33
- package/dist/elements.d.ts +1 -46
- package/dist/playhtml-candles.png +0 -0
- package/dist/playhtml.es.js +12 -11
- package/dist/playhtml.umd.js +3 -3
- package/dist/types.d.ts +48 -0
- package/package.json +1 -1
- package/dist/tags.d.ts +0 -0
package/README.md
CHANGED
|
@@ -66,8 +66,15 @@ https://github.com/spencerc99/playhtml/assets/14796580/fae669b1-b3e2-404e-bd7a-3
|
|
|
66
66
|
<img can-play id="customCandle" src="/candle-gif.gif" />
|
|
67
67
|
<!-- IMPORTANT: this data must be set _before_ importing the playhtml library. -->
|
|
68
68
|
<script>
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
let candle = document.getElementById("customCandle");
|
|
70
|
+
candle.defaultData = true;
|
|
71
|
+
candle.onClick = (_e, { data, setData }) => {
|
|
72
|
+
setData(!data);
|
|
73
|
+
};
|
|
74
|
+
candle.updateElement = ({ data }) => {
|
|
75
|
+
candle.src = data ? "/candle-gif.gif" : "/candle-off.png";
|
|
76
|
+
};
|
|
77
|
+
candle.resetShortcut = "shiftKey";
|
|
71
78
|
customCandle.defaultData = true;
|
|
72
79
|
customCandle.onClick = (_e, { data, setData }) => {
|
|
73
80
|
setData(!data);
|
|
@@ -80,20 +87,6 @@ https://github.com/spencerc99/playhtml/assets/14796580/fae669b1-b3e2-404e-bd7a-3
|
|
|
80
87
|
// setData(!data);
|
|
81
88
|
// });
|
|
82
89
|
// };
|
|
83
|
-
customCandle.updateElement = ({ data }) => {
|
|
84
|
-
customCandle.src = data ? "/candle-gif.gif" : "/candle-off.png";
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
// Alternatively
|
|
88
|
-
// let candle = document.getElementById('customCandle');
|
|
89
|
-
// candle.defaultData = true;
|
|
90
|
-
// candle.onClick = (_e, { data, setData }) => {
|
|
91
|
-
// setData(!data);
|
|
92
|
-
// };
|
|
93
|
-
// candle.updateElement = ({ data }) => {
|
|
94
|
-
// candle.src = data ? "/candle-gif.gif" : "/candle-off.png";
|
|
95
|
-
// };
|
|
96
|
-
// candle.resetShortcut = "shiftKey";
|
|
97
90
|
</script>
|
|
98
91
|
|
|
99
92
|
<!-- Import playhtml -->
|
|
@@ -101,16 +94,16 @@ https://github.com/spencerc99/playhtml/assets/14796580/fae669b1-b3e2-404e-bd7a-3
|
|
|
101
94
|
<link rel="stylesheet" href="https://unpkg.com/playhtml/dist/style.css" />
|
|
102
95
|
```
|
|
103
96
|
|
|
104
|
-
|
|
97
|
+
See all supported properties in the `ElementInitializer` [object in `types.ts`](https://github.com/spencerc99/playhtml/blob/main/src/types.ts#L13).
|
|
98
|
+
|
|
99
|
+
The only required properties are `defaultData`, `updateElement` and some kind of setup to trigger those functions (in this case, `onClick`, but you can add custom event listeners and logic using the `additionalSetup` property). See more examples based on the definitions for the included capabilities in [`elements.ts`](https://github.com/spencerc99/playhtml/blob/main/src/elements.ts#L72).
|
|
105
100
|
|
|
106
|
-
If you make something fun, please show me! This is designed as an open library for anyone to add on new interactions and capabilities, so
|
|
101
|
+
If you make something fun, please show me! This is designed as an open library for anyone to add on new interactions and capabilities, so we [welcome contributions](https://github.com/spencerc99/playhtml/blob/main/CONTRIBUTING.md) for new built-in capabilities.
|
|
107
102
|
|
|
108
103
|
## Plug-and-play Capabilities
|
|
109
104
|
|
|
110
105
|
These capabilities are common ones that have been designed and created by the community. You should expect that they are relatively well-tested, and they simply build on top of the same API and constructs that `can-play` uses.
|
|
111
106
|
|
|
112
|
-
We welcome any contributions if you have custom `can-play` elements that you would like to add to the library! Please make a PR.
|
|
113
|
-
|
|
114
107
|
### `can-move`
|
|
115
108
|
|
|
116
109
|
https://github.com/spencerc99/playhtml/assets/14796580/9c2b9bf6-142c-41e2-8c8f-93a3b121a73e
|
|
@@ -146,21 +139,9 @@ Creates a rotatable element using a `rotate` `transform` on the element. Draggin
|
|
|
146
139
|
|
|
147
140
|
Creates a communal forum from a `form` element. The form will sync any new submissions including all the `input` elements in the form, using their `name` property as the key and their value as the value. New messages will be currently prepended to the element with the `guestbookMessages` ID. TODO: make this generic and take user input
|
|
148
141
|
|
|
149
|
-
---
|
|
150
|
-
|
|
151
|
-
To add new ones, please find contributor guidelines in [New Capabilities](#new-capabilities).
|
|
152
|
-
|
|
153
142
|
## Contributing
|
|
154
143
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
`playhtml` is designed to be a collective library of magical capabilities that anyone can attach to arbitrary HTML elements. If you have an idea for a new capability, please first ensure that there is not a duplicate existing one in the current library (see `TagType` in `types.ts`). Please make a proposal for the capability you would like to add by opening an issue with the `new-capability` label.
|
|
158
|
-
|
|
159
|
-
To contribute your capability, see sample PR (TODO: LINK).
|
|
160
|
-
|
|
161
|
-
---
|
|
162
|
-
|
|
163
|
-
Outside of contributing new capabilities, feel free to submit any issues or PRs for bugs or improvements to the core of the library.
|
|
144
|
+
See [CONTRIBUTING.md](https://github.com/spencerc99/playhtml/blob/main/CONTRIBUTING.md).
|
|
164
145
|
|
|
165
146
|
## Support & Maintenance
|
|
166
147
|
|
package/dist/elements.d.ts
CHANGED
|
@@ -1,49 +1,5 @@
|
|
|
1
1
|
/// <reference lib="dom" />
|
|
2
|
-
import { TagType } from "./types";
|
|
3
|
-
type ModifierKey = "ctrlKey" | "altKey" | "shiftKey" | "metaKey";
|
|
4
|
-
export interface ElementInitializer<T = any, U = any, V = any> {
|
|
5
|
-
defaultData: T | ((element: HTMLElement) => T);
|
|
6
|
-
defaultLocalData?: U | ((element: HTMLElement) => U);
|
|
7
|
-
myDefaultAwareness?: V | ((element: HTMLElement) => V);
|
|
8
|
-
updateElement: (data: ElementEventHandlerData<T, U, V>) => void;
|
|
9
|
-
updateElementAwareness?: (data: ElementAwarenessEventHandlerData<T, U, V>) => void;
|
|
10
|
-
onDrag?: (e: MouseEvent | TouchEvent, eventData: ElementEventHandlerData<T, U, V>) => void;
|
|
11
|
-
onClick?: (e: MouseEvent, eventData: ElementEventHandlerData<T, U, V>) => void;
|
|
12
|
-
onDragStart?: (e: MouseEvent | TouchEvent, eventData: ElementEventHandlerData<T, U, V>) => void;
|
|
13
|
-
additionalSetup?: (eventData: ElementSetupData<T, U, V>) => void;
|
|
14
|
-
resetShortcut?: ModifierKey;
|
|
15
|
-
debounceMs?: number;
|
|
16
|
-
}
|
|
17
|
-
export interface ElementData<T = any, U = any, V = any> extends ElementInitializer<T> {
|
|
18
|
-
data?: T;
|
|
19
|
-
localData?: U;
|
|
20
|
-
awareness?: V;
|
|
21
|
-
element: HTMLElement;
|
|
22
|
-
onChange: (data: T) => void;
|
|
23
|
-
onAwarenessChange: (data: V) => void;
|
|
24
|
-
triggerAwarenessUpdate: () => void;
|
|
25
|
-
}
|
|
26
|
-
interface ElementEventHandlerData<T = any, U = any, V = any> {
|
|
27
|
-
data: T;
|
|
28
|
-
localData: U;
|
|
29
|
-
awareness: V[];
|
|
30
|
-
element: HTMLElement;
|
|
31
|
-
setData: (data: T) => void;
|
|
32
|
-
setLocalData: (data: U) => void;
|
|
33
|
-
setLocalAwareness: (data: V) => void;
|
|
34
|
-
}
|
|
35
|
-
interface ElementAwarenessEventHandlerData<T = any, U = any, V = any> extends ElementEventHandlerData<T, U, V> {
|
|
36
|
-
myAwareness?: V;
|
|
37
|
-
}
|
|
38
|
-
interface ElementSetupData<T = any, U = any, V = any> {
|
|
39
|
-
getData: () => T;
|
|
40
|
-
getLocalData: () => U;
|
|
41
|
-
getAwareness: () => V[];
|
|
42
|
-
getElement: () => HTMLElement;
|
|
43
|
-
setData: (data: T) => void;
|
|
44
|
-
setLocalData: (data: U) => void;
|
|
45
|
-
setLocalAwareness: (data: V) => void;
|
|
46
|
-
}
|
|
2
|
+
import { ElementAwarenessEventHandlerData, ElementData, ElementEventHandlerData, ElementInitializer, ElementSetupData, ModifierKey, TagType } from "./types";
|
|
47
3
|
export declare const TagTypeToElement: Record<Exclude<TagType, "can-play">, ElementInitializer>;
|
|
48
4
|
export declare class ElementHandler<T = any, U = any, V = any> {
|
|
49
5
|
defaultData: T;
|
|
@@ -85,4 +41,3 @@ export declare class ElementHandler<T = any, U = any, V = any> {
|
|
|
85
41
|
*/
|
|
86
42
|
reset(): void;
|
|
87
43
|
}
|
|
88
|
-
export {};
|
|
Binary file
|
package/dist/playhtml.es.js
CHANGED
|
@@ -6024,18 +6024,18 @@ class Ac extends me {
|
|
|
6024
6024
|
});
|
|
6025
6025
|
}
|
|
6026
6026
|
}
|
|
6027
|
-
const Ic =
|
|
6027
|
+
const Ic = {
|
|
6028
|
+
ctrlKey: "Control",
|
|
6029
|
+
altKey: "Alt",
|
|
6030
|
+
shiftKey: "Shift",
|
|
6031
|
+
metaKey: "Meta"
|
|
6032
|
+
}, Lc = "can-duplicate-to";
|
|
6028
6033
|
var D = /* @__PURE__ */ ((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.CanPost = "can-post", n))(D || {});
|
|
6029
|
-
const
|
|
6034
|
+
const Mc = (n, t = 300) => {
|
|
6030
6035
|
let e;
|
|
6031
6036
|
return function(...s) {
|
|
6032
6037
|
clearTimeout(e), e = setTimeout(() => n.apply(this, s), t);
|
|
6033
6038
|
};
|
|
6034
|
-
}, Mc = {
|
|
6035
|
-
ctrlKey: "Control",
|
|
6036
|
-
altKey: "Alt",
|
|
6037
|
-
shiftKey: "Shift",
|
|
6038
|
-
metaKey: "Meta"
|
|
6039
6039
|
}, sr = `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>")
|
|
6040
6040
|
16 0,
|
|
6041
6041
|
auto`, xc = `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`;
|
|
@@ -6194,7 +6194,7 @@ const rr = {
|
|
|
6194
6194
|
);
|
|
6195
6195
|
return;
|
|
6196
6196
|
}
|
|
6197
|
-
const c = s.getAttribute(
|
|
6197
|
+
const c = s.getAttribute(Lc);
|
|
6198
6198
|
function l(u) {
|
|
6199
6199
|
if (c) {
|
|
6200
6200
|
const d = document.getElementById(c) || document.querySelector(c);
|
|
@@ -6258,7 +6258,7 @@ class vc {
|
|
|
6258
6258
|
y(this, "updateElement");
|
|
6259
6259
|
y(this, "updateElementAwareness");
|
|
6260
6260
|
y(this, "triggerAwarenessUpdate");
|
|
6261
|
-
this.element = t, this.defaultData = r instanceof Function ? r(t) : r, this.localData = i instanceof Function ? i(t) : i, this.triggerAwarenessUpdate = Mt, this.onChange = e, this.resetShortcut = m, this.debouncedOnChange =
|
|
6261
|
+
this.element = t, this.defaultData = r instanceof Function ? r(t) : r, this.localData = i instanceof Function ? i(t) : i, this.triggerAwarenessUpdate = Mt, this.onChange = e, this.resetShortcut = m, this.debouncedOnChange = Mc(this.onChange, v), this.onAwarenessChange = s, this.updateElement = a, this.updateElementAwareness = h;
|
|
6262
6262
|
const bn = c === void 0 ? this.defaultData : c;
|
|
6263
6263
|
l !== void 0 && (this.__awareness = l);
|
|
6264
6264
|
const _n = o instanceof Function ? o(t) : o;
|
|
@@ -6280,7 +6280,7 @@ class vc {
|
|
|
6280
6280
|
document.removeEventListener("mousemove", xt), document.removeEventListener("mouseup", vt);
|
|
6281
6281
|
};
|
|
6282
6282
|
document.addEventListener("mousemove", xt), document.addEventListener("mouseup", vt);
|
|
6283
|
-
})), g && g(this.getSetupData()), m && (t.title || (t.title = `Hold down the ${
|
|
6283
|
+
})), g && g(this.getSetupData()), m && (t.title || (t.title = `Hold down the ${Ic[m]} key while clicking to reset.`), t.reset = this.reset, t.addEventListener("click", (U) => {
|
|
6284
6284
|
switch (m) {
|
|
6285
6285
|
case "ctrlKey":
|
|
6286
6286
|
if (!U.ctrlKey)
|
|
@@ -6552,7 +6552,8 @@ function yn(n, t) {
|
|
|
6552
6552
|
if (l) {
|
|
6553
6553
|
const a = Xn.get(l) ?? 0;
|
|
6554
6554
|
n.id = btoa(`${t}-${l}-${a}`), Xn.set(l, a + 1);
|
|
6555
|
-
}
|
|
6555
|
+
} else
|
|
6556
|
+
n.id = btoa(`${t}-${n.innerHTML}}`);
|
|
6556
6557
|
}
|
|
6557
6558
|
const e = Tc(n);
|
|
6558
6559
|
if (!e) {
|
package/dist/playhtml.umd.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
(function(v,k){typeof exports=="object"&&typeof module<"u"?k(exports):typeof define=="function"&&define.amd?define(["exports"],k):(v=typeof globalThis<"u"?globalThis:v||self,k(v.playhtml={}))})(this,function(v){"use strict";var xl=Object.defineProperty;var Ul=(v,k,K)=>k in v?xl(v,k,{enumerable:!0,configurable:!0,writable:!0,value:K}):v[k]=K;var y=(v,k,K)=>(Ul(v,typeof k!="symbol"?k+"":k,K),K);const k=()=>new Map,K=n=>{const t=k();return n.forEach((e,s)=>{t.set(s,e)}),t},Y=(n,t,e)=>{let s=n.get(t);return s===void 0&&n.set(t,s=e()),s},dr=(n,t)=>{const e=[];for(const[s,r]of n)e.push(t(r,s));return e},fr=(n,t)=>{for(const[e,s]of n)if(t(s,e))return!0;return!1},rt=()=>new Set,Ce=n=>n[n.length-1],gr=(n,t)=>{for(let e=0;e<t.length;e++)n.push(t[e])},Q=Array.from,pr=Array.isArray,wr=String.fromCharCode,mr=n=>n.toLowerCase(),yr=/^\s*/g,br=n=>n.replace(yr,""),_r=/([A-Z])/g,Dn=(n,t)=>br(n.replace(_r,e=>`${t}${mr(e)}`)),kr=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},xt=typeof TextEncoder<"u"?new TextEncoder:null,Sr=xt?n=>xt.encode(n):kr;let Ut=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Ut&&Ut.decode(new Uint8Array).length===1&&(Ut=null);const En=n=>n===void 0?null:n;class Dr{constructor(){this.map=new Map}setItem(t,e){this.map.set(t,e)}getItem(t){return this.map.get(t)}}let Cn=new Dr,Ae=!0;try{typeof localStorage<"u"&&(Cn=localStorage,Ae=!1)}catch{}const An=Cn,Er=n=>Ae||addEventListener("storage",n),Cr=n=>Ae||removeEventListener("storage",n),Ar=Object.assign,Ir=Object.keys,Lr=(n,t)=>{for(const e in n)t(n[e],e)},Mr=(n,t)=>{const e=[];for(const s in n)e.push(t(n[s],s));return e},Zt=n=>Ir(n).length,vr=n=>{for(const t in n)return!1;return!0},xr=(n,t)=>{for(const e in n)if(!t(n[e],e))return!1;return!0},In=(n,t)=>Object.prototype.hasOwnProperty.call(n,t),Ur=(n,t)=>n===t||Zt(n)===Zt(t)&&xr(n,(e,s)=>(e!==void 0||In(t,s))&&t[s]===e),Ie=(n,t,e=0)=>{try{for(;e<n.length;e++)n[e](...t)}finally{e<n.length&&Ie(n,t,e+1)}},Tr=n=>n,Or=(n,t)=>n===t,Tt=(n,t)=>{if(n==null||t==null)return Or(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)||!Tt(n.get(e),t.get(e)))return!1;break}case Object:if(Zt(n)!==Zt(t))return!1;for(const e in n)if(!In(n,e)||!Tt(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(!Tt(n[e],t[e]))return!1;break;default:return!1}return!0},Rr=(n,t)=>t.includes(n),yt=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name),Ln=typeof window<"u"&&typeof document<"u"&&!yt;let F;const Nr=()=>{if(F===void 0)if(yt){F=k();const n=process.argv;let t=null;for(let e=0;e<n.length;e++){const s=n[e];s[0]==="-"?(t!==null&&F.set(t,""),t=s):t!==null&&(F.set(t,s),t=null)}t!==null&&F.set(t,"")}else typeof location=="object"?(F=k(),(location.search||"?").slice(1).split("&").forEach(n=>{if(n.length!==0){const[t,e]=n.split("=");F.set(`--${Dn(t,"-")}`,e),F.set(`-${Dn(t,"-")}`,e)}})):F=k();return F},Le=n=>Nr().has(n),Me=n=>En(yt?process.env[n.toUpperCase()]:An.getItem(n));(n=>Le("--"+n)||Me(n)!==null)("production");const Mn=yt&&Rr(process.env.FORCE_COLOR,["true","1","2"]),Br=!Le("no-colors")&&(!yt||process.stdout.isTTY||Mn)&&(!yt||Le("color")||Mn||Me("COLORTERM")!==null||(Me("TERM")||"").includes("color")),X=Math.floor,te=Math.abs,ve=(n,t)=>n<t?n:t,it=(n,t)=>n>t?n:t,Fr=Math.pow,vn=n=>n!==0?n<0:1/n<0,xn=1,Un=2,xe=4,Ue=8,Ot=32,z=64,T=128,ee=31,Te=63,ot=127,Vr=2147483647,Tn=Number.MAX_SAFE_INTEGER,Hr=Number.isInteger||(n=>typeof n=="number"&&isFinite(n)&&X(n)===n);class Rt{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const x=()=>new Rt,Oe=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(Oe(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(Ke(n.cbuf.buffer,0,n.cpos),e),t},$r=(n,t)=>{const e=n.cbuf.length;e-n.cpos<t&&(n.bufs.push(Ke(n.cbuf.buffer,0,n.cpos)),n.cbuf=new Uint8Array(it(e,t)*2),n.cpos=0)},I=(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},Re=I,p=(n,t)=>{for(;t>ot;)I(n,T|ot&t),t=X(t/128);I(n,ot&t)},Ne=(n,t)=>{const e=vn(t);for(e&&(t=-t),I(n,(t>Te?T:0)|(e?z:0)|Te&t),t=X(t/64);t>0;)I(n,(t>ot?T:0)|ot&t),t=X(t/128)},Be=new Uint8Array(3e4),jr=Be.length/3,Kr=(n,t)=>{if(t.length<jr){const e=xt.encodeInto(t,Be).written||0;p(n,e);for(let s=0;s<e;s++)I(n,Be[s])}else D(n,Sr(t))},Yr=(n,t)=>{const e=unescape(encodeURIComponent(t)),s=e.length;p(n,s);for(let r=0;r<s;r++)I(n,e.codePointAt(r))},lt=xt&&xt.encodeInto?Kr:Yr,ne=(n,t)=>{const e=n.cbuf.length,s=n.cpos,r=ve(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(it(e*2,i)),n.cbuf.set(t.subarray(r)),n.cpos=i)},D=(n,t)=>{p(n,t.byteLength),ne(n,t)},Fe=(n,t)=>{$r(n,t);const e=new DataView(n.cbuf.buffer,n.cpos,t);return n.cpos+=t,e},Xr=(n,t)=>Fe(n,4).setFloat32(0,t,!1),zr=(n,t)=>Fe(n,8).setFloat64(0,t,!1),Jr=(n,t)=>Fe(n,8).setBigInt64(0,t,!1),On=new DataView(new ArrayBuffer(4)),Gr=n=>(On.setFloat32(0,n),On.getFloat32(0)===n),Nt=(n,t)=>{switch(typeof t){case"string":I(n,119),lt(n,t);break;case"number":Hr(t)&&te(t)<=Vr?(I(n,125),Ne(n,t)):Gr(t)?(I(n,124),Xr(n,t)):(I(n,123),zr(n,t));break;case"bigint":I(n,122),Jr(n,t);break;case"object":if(t===null)I(n,126);else if(pr(t)){I(n,117),p(n,t.length);for(let e=0;e<t.length;e++)Nt(n,t[e])}else if(t instanceof Uint8Array)I(n,116),D(n,t);else{I(n,118);const e=Object.keys(t);p(n,e.length);for(let s=0;s<e.length;s++){const r=e[s];lt(n,r),Nt(n,t[r])}}break;case"boolean":I(n,t?120:121);break;default:I(n,127)}};class Rn extends Rt{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 Nn=n=>{n.count>0&&(Ne(n.encoder,n.count===1?n.s:-n.s),n.count>1&&p(n.encoder,n.count-2))};class se{constructor(){this.encoder=new Rt,this.s=0,this.count=0}write(t){this.s===t?this.count++:(Nn(this),this.count=1,this.s=t)}toUint8Array(){return Nn(this),S(this.encoder)}}const Bn=n=>{if(n.count>0){const t=n.diff*2+(n.count===1?0:1);Ne(n.encoder,t),n.count>1&&p(n.encoder,n.count-2)}};class Ve{constructor(){this.encoder=new Rt,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(Bn(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return Bn(this),S(this.encoder)}}class Wr{constructor(){this.sarr=[],this.s="",this.lensE=new se}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 Rt;return this.sarr.push(this.s),this.s="",lt(t,this.sarr.join("")),ne(t,this.lensE.toUint8Array()),S(t)}}const J=n=>new Error(n),V=()=>{throw J("Method unimplemented")},H=()=>{throw J("Unexpected case")},Fn=J("Unexpected end of array"),Vn=J("Integer out of Range");class re{constructor(t){this.arr=t,this.pos=0}}const Z=n=>new re(n),qr=n=>n.pos!==n.arr.length,Pr=(n,t)=>{const e=Ke(n.arr.buffer,n.pos+n.arr.byteOffset,t);return n.pos+=t,e},U=n=>Pr(n,w(n)),bt=n=>n.arr[n.pos++],w=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&ot)*e,e*=128,r<T)return t;if(t>Tn)throw Vn}throw Fn},He=n=>{let t=n.arr[n.pos++],e=t&Te,s=64;const r=(t&z)>0?-1:1;if(!(t&T))return r*e;const i=n.arr.length;for(;n.pos<i;){if(t=n.arr[n.pos++],e=e+(t&ot)*s,s*=128,t<T)return r*e;if(e>Tn)throw Vn}throw Fn},tt=Ut?n=>Ut.decode(U(n)):n=>{let t=w(n);if(t===0)return"";{let e=String.fromCodePoint(bt(n));if(--t<100)for(;t--;)e+=String.fromCodePoint(bt(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))}},$e=(n,t)=>{const e=new DataView(n.arr.buffer,n.arr.byteOffset+n.pos,t);return n.pos+=t,e},Qr=[n=>{},n=>null,He,n=>$e(n,4).getFloat32(0,!1),n=>$e(n,8).getFloat64(0,!1),n=>$e(n,8).getBigInt64(0,!1),n=>!1,n=>!0,tt,n=>{const t=w(n),e={};for(let s=0;s<t;s++){const r=tt(n);e[r]=Bt(n)}return e},n=>{const t=w(n),e=[];for(let s=0;s<t;s++)e.push(Bt(n));return e},U],Bt=n=>Qr[127-bt(n)](n);class Hn extends re{constructor(t,e){super(t),this.reader=e,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),qr(this)?this.count=w(this)+1:this.count=-1),this.count--,this.s}}class ie extends re{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=He(this);const t=vn(this.s);this.count=1,t&&(this.s=-this.s,this.count=w(this)+2)}return this.count--,this.s}}class je extends re{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=He(this),e=t&1;this.diff=X(t/2),this.count=1,e&&(this.count=w(this)+2)}return this.s+=this.diff,this.count--,this.s}}class Zr{constructor(t){this.decoder=new ie(t),this.str=tt(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 $n=n=>new Uint8Array(n),Ke=(n,t,e)=>new Uint8Array(n,t,e),ti=n=>new Uint8Array(n),ei=n=>{let t="";for(let e=0;e<n.byteLength;e++)t+=wr(n[e]);return btoa(t)},ni=n=>Buffer.from(n.buffer,n.byteOffset,n.byteLength).toString("base64"),si=n=>{const t=atob(n),e=$n(t.length);for(let s=0;s<t.length;s++)e[s]=t.charCodeAt(s);return e},ri=n=>{const t=Buffer.from(n,"base64");return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)},ii=Ln?ei:ni,oi=Ln?si:ri,li=n=>{const t=$n(n.byteLength);return t.set(n),t},jn=new Map;class ci{constructor(t){this.room=t,this.onmessage=null,this._onChange=e=>e.key===t&&this.onmessage!==null&&this.onmessage({data:oi(e.newValue||"")}),Er(this._onChange)}postMessage(t){An.setItem(this.room,ii(ti(t)))}close(){Cr(this._onChange)}}const ai=typeof BroadcastChannel>"u"?ci:BroadcastChannel,Ye=n=>Y(jn,n,()=>{const t=rt(),e=new ai(n);return e.onmessage=s=>t.forEach(r=>r(s.data,"broadcastchannel")),{bc:e,subs:t}}),hi=(n,t)=>(Ye(n).subs.add(t),t),ui=(n,t)=>{const e=Ye(n),s=e.subs.delete(t);return s&&e.subs.size===0&&(e.bc.close(),jn.delete(n)),s},_t=(n,t,e=null)=>{const s=Ye(n);s.bc.postMessage(t),s.subs.forEach(r=>r(t,e))},ct=Date.now;class oe{constructor(){this._observers=k()}on(t,e){Y(this._observers,t,rt).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 Q((this._observers.get(t)||k()).values()).forEach(s=>s(...e))}destroy(){this._observers=k()}}const di=crypto.getRandomValues.bind(crypto),Kn=()=>di(new Uint32Array(1))[0],fi=[1e7]+-1e3+-4e3+-8e3+-1e11,gi=()=>fi.replace(/[018]/g,n=>(n^Kn()&15>>n/4).toString(16)),kt=n=>new Promise(n);Promise.all.bind(Promise);class pi{constructor(t,e){this.left=t,this.right=e}}const G=(n,t)=>new pi(n,t);typeof DOMParser<"u"&&new DOMParser;const wi=n=>dr(n,(t,e)=>`${e}:${t};`).join(""),W=Symbol,Yn=W(),Xn=W(),mi=W(),yi=W(),bi=W(),zn=W(),_i=W(),Jn=W(),ki=W(),Si=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},Di={[Yn]:G("font-weight","bold"),[Xn]:G("font-weight","normal"),[mi]:G("color","blue"),[bi]:G("color","green"),[yi]:G("color","grey"),[zn]:G("color","red"),[_i]:G("color","purple"),[Jn]:G("color","orange"),[ki]:G("color","black")},Ei=Br?n=>{const t=[],e=[],s=k();let r=[],i=0;for(;i<n.length;i++){const o=n[i],l=Di[o];if(l!==void 0)s.set(l.left,l.right);else if(o.constructor===String||o.constructor===Number){const c=wi(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}:Si,Ci=(...n)=>{console.log(...Ei(n)),Ai.forEach(t=>t.print(n))},Ai=rt(),Gn=n=>({[Symbol.iterator](){return this},next:n}),Ii=(n,t)=>Gn(()=>{let e;do e=n.next();while(!e.done&&!t(e.value));return e}),Xe=(n,t)=>Gn(()=>{const{done:e,value:s}=n.next();return{done:e,value:e?void 0:t(s)}});class ze{constructor(t,e){this.clock=t,this.len=e}}class Ft{constructor(){this.clients=new Map}}const Wn=(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];gs(n,i,l.clock,l.len,e)}}),Li=(n,t)=>{let e=0,s=n.length-1;for(;e<=s;){const r=X((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},qn=(n,t)=>{const e=n.clients.get(t.client);return e!==void 0&&Li(e,t.clock)!==null},Je=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=it(r.len,i.clock+i.len-r.clock):(s<e&&(t[s]=i),s++)}t.length=s})},Mi=n=>{const t=new Ft;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++)gr(i,n[o].clients.get(r)||[]);t.clients.set(r,i)}});return Je(t),t},le=(n,t,e,s)=>{Y(n.clients,t,()=>[]).push(new ze(e,s))},vi=()=>new Ft,xi=n=>{const t=vi();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 ze(l,c))}}r.length>0&&t.clients.set(s,r)}),t},St=(n,t)=>{p(n.restEncoder,t.clients.size),Q(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)}})},Ge=n=>{const t=new Ft,e=w(n.restDecoder);for(let s=0;s<e;s++){n.resetDsCurVal();const r=w(n.restDecoder),i=w(n.restDecoder);if(i>0){const o=Y(t.clients,r,()=>[]);for(let l=0;l<i;l++)o.push(new ze(n.readDsClock(),n.readDsLen()))}}return t},Pn=(n,t,e)=>{const s=new Ft,r=w(n.restDecoder);for(let i=0;i<r;i++){n.resetDsCurVal();const o=w(n.restDecoder),l=w(n.restDecoder),c=e.clients.get(o)||[],a=L(e,o);for(let h=0;h<l;h++){const u=n.readDsClock(),d=u+n.readDsLen();if(u<a){a<d&&le(s,o,a,d-a);let f=$(c,u),g=c[f];for(!g.deleted&&g.id.clock<u&&(c.splice(f+1,0,Se(t,g,u-g.id.clock)),f++);f<c.length&&(g=c[f++],g.id.clock<d);)g.deleted||(d<g.id.clock+g.length&&c.splice(f,0,Se(t,g,d-g.id.clock)),g.delete(t))}else le(s,o,u,d-u)}}if(s.clients.size>0){const i=new at;return p(i.restEncoder,0),St(i,s),i.toUint8Array()}return null},Qn=Kn;class Dt extends oe{constructor({guid:t=gi(),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=Qn(),this.guid=t,this.collectionid=e,this.share=new Map,this.store=new us,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=kt(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})});const c=()=>kt(a=>{const h=u=>{(u===void 0||u===!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&&_(t.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Q(this.subdocs).map(t=>t.guid))}transact(t,e=null){return _(this,t,e)}get(t,e=M){const s=Y(this.share,t,()=>{const i=new e;return i._integrate(this,null),i}),r=s.constructor;if(e!==M&&r!==e)if(r===M){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,At)}getText(t=""){return this.get(t,Lt)}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(){Q(this.subdocs).forEach(e=>e.destroy());const t=this._item;if(t!==null){this._item=null;const e=t.content;e.doc=new Dt({guid:this.guid,...e.opts,shouldLoad:!1}),e.doc._item=t,_(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 Zn{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return w(this.restDecoder)}readDsLen(){return w(this.restDecoder)}}class ts extends Zn{readLeftID(){return b(w(this.restDecoder),w(this.restDecoder))}readRightID(){return b(w(this.restDecoder),w(this.restDecoder))}readClient(){return w(this.restDecoder)}readInfo(){return bt(this.restDecoder)}readString(){return tt(this.restDecoder)}readParentInfo(){return w(this.restDecoder)===1}readTypeRef(){return w(this.restDecoder)}readLen(){return w(this.restDecoder)}readAny(){return Bt(this.restDecoder)}readBuf(){return li(U(this.restDecoder))}readJSON(){return JSON.parse(tt(this.restDecoder))}readKey(){return tt(this.restDecoder)}}class Ui{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=w(this.restDecoder),this.dsCurrVal}readDsLen(){const t=w(this.restDecoder)+1;return this.dsCurrVal+=t,t}}class Et extends Ui{constructor(t){super(t),this.keys=[],w(t),this.keyClockDecoder=new je(U(t)),this.clientDecoder=new ie(U(t)),this.leftClockDecoder=new je(U(t)),this.rightClockDecoder=new je(U(t)),this.infoDecoder=new Hn(U(t),bt),this.stringDecoder=new Zr(U(t)),this.parentInfoDecoder=new Hn(U(t),bt),this.typeRefDecoder=new ie(U(t)),this.lenDecoder=new ie(U(t))}readLeftID(){return new Ct(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Ct(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 Bt(this.restDecoder)}readBuf(){return U(this.restDecoder)}readJSON(){return Bt(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 es{constructor(){this.restEncoder=x()}toUint8Array(){return S(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){p(this.restEncoder,t)}writeDsLen(t){p(this.restEncoder,t)}}class Vt extends es{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){Re(this.restEncoder,t)}writeString(t){lt(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){Nt(this.restEncoder,t)}writeBuf(t){D(this.restEncoder,t)}writeJSON(t){lt(this.restEncoder,JSON.stringify(t))}writeKey(t){lt(this.restEncoder,t)}}class ns{constructor(){this.restEncoder=x(),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&&H(),p(this.restEncoder,t-1),this.dsCurrVal+=t}}class at extends ns{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Ve,this.clientEncoder=new se,this.leftClockEncoder=new Ve,this.rightClockEncoder=new Ve,this.infoEncoder=new Rn(Re),this.stringEncoder=new Wr,this.parentInfoEncoder=new Rn(Re),this.typeRefEncoder=new se,this.lenEncoder=new se}toUint8Array(){const t=x();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()),ne(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){Nt(this.restEncoder,t)}writeBuf(t){D(this.restEncoder,t)}writeJSON(t){Nt(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 Ti=(n,t,e,s)=>{s=it(s,t[0].id.clock);const r=$(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)},We=(n,t,e)=>{const s=new Map;e.forEach((r,i)=>{L(t,i)>r&&s.set(i,r)}),ae(t).forEach((r,i)=>{e.has(i)||s.set(i,0)}),p(n.restEncoder,s.size),Q(s.entries()).sort((r,i)=>i[0]-r[0]).forEach(([r,i])=>{Ti(n,t.clients.get(r),r,i)})},Oi=(n,t)=>{const e=k(),s=w(n.restDecoder);for(let r=0;r<s;r++){const i=w(n.restDecoder),o=new Array(i),l=n.readClient();let c=w(n.restDecoder);e.set(l,{i:0,refs:o});for(let a=0;a<i;a++){const h=n.readInfo();switch(ee&h){case 0:{const u=n.readLen();o[a]=new N(b(l,c),u),c+=u;break}case 10:{const u=w(n.restDecoder);o[a]=new B(b(l,c),u),c+=u;break}default:{const u=(h&(z|T))===0,d=new A(b(l,c),null,(h&T)===T?n.readLeftID():null,null,(h&z)===z?n.readRightID():null,u?n.readParentInfo()?t.get(n.readString()):n.readLeftID():null,u&&(h&Ot)===Ot?n.readString():null,Vs(n,h));o[a]=d,c+=d.length}}}}return e},Ri=(n,t,e)=>{const s=[];let r=Q(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 us,c=new Map,a=(f,g)=>{const m=c.get(f);(m==null||m>g)&&c.set(f,g)};let h=o.refs[o.i++];const u=new Map,d=()=>{for(const f of s){const g=f.id.client,m=e.get(g);m?(m.i--,l.clients.set(g,m.refs.slice(m.i)),e.delete(g),m.i=0,m.refs=[]):l.clients.set(g,[f]),r=r.filter(O=>O!==g)}s.length=0};for(;;){if(h.constructor!==B){const g=Y(u,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),d();else{const m=h.getMissing(n,t);if(m!==null){s.push(h);const O=e.get(m)||{refs:[],i:0};if(O.refs.length===O.i)a(m,L(t,m)),d();else{h=O.refs[O.i++];continue}}else(g===0||g<h.length)&&(h.integrate(n,g),u.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 We(f,l,new Map),p(f.restEncoder,0),{missing:c,update:f.toUint8Array()}}return null},Ni=(n,t)=>We(n,t.doc.store,t.beforeState),Bi=(n,t,e,s=new Et(n))=>_(t,r=>{r.local=!1;let i=!1;const o=r.doc,l=o.store,c=Oi(s,o),a=Ri(r,l,c),h=l.pendingStructs;if(h){for(const[d,f]of h.missing)if(f<L(l,d)){i=!0;break}if(a){for(const[d,f]of a.missing){const g=h.missing.get(d);(g==null||g>f)&&h.missing.set(d,f)}h.update=ue([h.update,a.update])}}else l.pendingStructs=a;const u=Pn(s,r,l);if(l.pendingDs){const d=new Et(Z(l.pendingDs));w(d.restDecoder);const f=Pn(d,r,l);u&&f?l.pendingDs=ue([u,f]):l.pendingDs=u||f}else l.pendingDs=u;if(i){const d=l.pendingStructs.update;l.pendingStructs=null,ss(r.doc,d)}},e,!1),ss=(n,t,e,s=Et)=>{const r=Z(t);Bi(r,n,e,new s(r))},rs=(n,t,e)=>ss(n,t,e,ts),Fi=(n,t,e=new Map)=>{We(n,t.store,e),St(n,xi(t.store))},Vi=(n,t=new Uint8Array([0]),e=new at)=>{const s=is(t);Fi(e,n,s);const r=[e.toUint8Array()];if(n.store.pendingDs&&r.push(n.store.pendingDs),n.store.pendingStructs&&r.push(Zi(n.store.pendingStructs.update,t)),r.length>1){if(e.constructor===Vt)return Pi(r.map((i,o)=>o===0?i:eo(i)));if(e.constructor===at)return ue(r)}return r[0]},qe=(n,t)=>Vi(n,t,new Vt),Hi=n=>{const t=new Map,e=w(n.restDecoder);for(let s=0;s<e;s++){const r=w(n.restDecoder),i=w(n.restDecoder);t.set(r,i)}return t},is=n=>Hi(new Zn(Z(n))),os=(n,t)=>(p(n.restEncoder,t.size),Q(t.entries()).sort((e,s)=>s[0]-e[0]).forEach(([e,s])=>{p(n.restEncoder,e),p(n.restEncoder,s)}),n),$i=(n,t)=>os(n,ae(t.store)),ji=(n,t=new ns)=>(n instanceof Map?os(t,n):$i(t,n),t.toUint8Array()),Ki=n=>ji(n,new es);class Yi{constructor(){this.l=[]}}const ls=()=>new Yi,cs=(n,t)=>n.l.push(t),as=(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.")},hs=(n,t,e)=>Ie(n.l,[t,e]);class Ct{constructor(t,e){this.client=t,this.clock=e}}const ce=(n,t)=>n===t||n!==null&&t!==null&&n.client===t.client&&n.clock===t.clock,b=(n,t)=>new Ct(n,t),Xi=n=>{for(const[t,e]of n.doc.share.entries())if(e===n)return t;throw H()},Ht=(n,t)=>t===void 0?!n.deleted:t.sv.has(n.id.client)&&(t.sv.get(n.id.client)||0)>n.id.clock&&!qn(t.ds,n.id),Pe=(n,t)=>{const e=Y(n.meta,Pe,rt),s=n.doc.store;e.has(t)||(t.sv.forEach((r,i)=>{r<L(s,i)&&et(n,b(i,r))}),Wn(n,t.ds,r=>{}),e.add(t))};class us{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const ae=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},ds=(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 H()}e.push(t)},$=(n,t)=>{let e=0,s=n.length-1,r=n[s],i=r.id.clock;if(i===t)return s;let o=X(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=X((e+s)/2)}throw H()},Qe=(n,t)=>{const e=n.clients.get(t.client);return e[$(e,t.clock)]},Ze=(n,t,e)=>{const s=$(t,e),r=t[s];return r.id.clock<e&&r instanceof A?(t.splice(s+1,0,Se(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)]},fs=(n,t,e)=>{const s=t.clients.get(e.client),r=$(s,e.clock),i=s[r];return e.clock!==i.id.clock+i.length-1&&i.constructor!==N&&s.splice(r+1,0,Se(n,i,e.clock-i.id.clock+1)),i},zi=(n,t,e)=>{const s=n.clients.get(t.id.client);s[$(s,t.id.clock)]=e},gs=(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 Ji{constructor(t,e,s){this.doc=t,this.deleteSet=new Ft,this.beforeState=ae(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 ps=(n,t)=>t.deleteSet.clients.size===0&&!fr(t.afterState,(e,s)=>t.beforeState.get(s)!==e)?!1:(Je(t.deleteSet),Ni(n,t),St(n,t.deleteSet),!0),ws=(n,t,e)=>{const s=t._item;(s===null||s.id.clock<(n.beforeState.get(s.id.client)||0)&&!s.deleted)&&Y(n.changed,t,rt).add(e)},he=(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 A&&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},Gi=(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=$(i,l.clock),h=i[a];a<i.length&&h.id.clock<c;h=i[++a]){const u=i[a];if(l.clock+l.len<=u.id.clock)break;u instanceof A&&u.deleted&&!u.keep&&e(u)&&u.gc(t,!1)}}}},Wi=(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=ve(r.length-1,1+$(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+he(r,c)}})},ms=(n,t)=>{if(t<n.length){const e=n[t],s=e.doc,r=s.store,i=e.deleteSet,o=e._mergeStructs;try{Je(i),e.afterState=ae(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,u)=>h.path.length-u.path.length),hs(a._dEH,c,e))})}),l.push(()=>s.emit("afterTransaction",[e,s])),Ie(l,[]),e._needFormattingCleanup&&po(e)}finally{s.gc&&Gi(i,r,s.gcFilter),Wi(i,r),e.afterState.forEach((h,u)=>{const d=e.beforeState.get(u)||0;if(d!==h){const f=r.clients.get(u),g=it($(f,d),1);for(let m=f.length-1;m>=g;)m-=1+he(f,m)}});for(let h=o.length-1;h>=0;h--){const{client:u,clock:d}=o[h].id,f=r.clients.get(u),g=$(f,d);g+1<f.length&&he(f,g+1)>1||g>0&&he(f,g)}if(!e.local&&e.afterState.get(s.clientID)!==e.beforeState.get(s.clientID)&&(Ci(Jn,Yn,"[yjs] ",Xn,zn,"Changed the client-id because another client seems to be using it."),s.clientID=Qn()),s.emit("afterTransactionCleanup",[e,s]),s._observers.has("update")){const h=new Vt;ps(h,e)&&s.emit("update",[h.toUint8Array(),e.origin,s,e])}if(s._observers.has("updateV2")){const h=new at;ps(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])):ms(n,t+1)}}},_=(n,t,e=null,s=!0)=>{const r=n._transactionCleanups;let i=!1,o=null;n._transaction===null&&(i=!0,n._transaction=new Ji(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&&ms(r,0)}}return o};function*qi(n){const t=w(n.restDecoder);for(let e=0;e<t;e++){const s=w(n.restDecoder),r=n.readClient();let i=w(n.restDecoder);for(let o=0;o<s;o++){const l=n.readInfo();if(l===10){const c=w(n.restDecoder);yield new B(b(r,i),c),i+=c}else if(ee&l){const c=(l&(z|T))===0,a=new A(b(r,i),null,(l&T)===T?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,Vs(n,l));yield a,i+=a.length}else{const c=n.readLen();yield new N(b(r,i),c),i+=c}}}}class tn{constructor(t,e){this.gen=qi(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===B);return this.curr}}class en{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const Pi=n=>ue(n,ts,Vt),Qi=(n,t)=>{if(n.constructor===N){const{client:e,clock:s}=n.id;return new N(b(e,s+t),n.length-t)}else if(n.constructor===B){const{client:e,clock:s}=n.id;return new B(b(e,s+t),n.length-t)}else{const e=n,{client:s,clock:r}=e.id;return new A(b(s,r+t),null,b(s,r+t-1),null,e.rightOrigin,e.parent,e.parentSub,e.content.splice(t))}},ue=(n,t=Et,e=at)=>{if(n.length===1)return n[0];const s=n.map(h=>new t(Z(h)));let r=s.map(h=>new tn(h,!0)),i=null;const o=new e,l=new en(o);for(;r=r.filter(d=>d.curr!==null),r.sort((d,f)=>{if(d.curr.id.client===f.curr.id.client){const g=d.curr.id.clock-f.curr.id.clock;return g===0?d.curr.constructor===f.curr.constructor?0:d.curr.constructor===B?1:-1:g}else return f.curr.id.client-d.curr.id.client}),r.length!==0;){const h=r[0],u=h.curr.id.client;if(i!==null){let d=h.curr,f=!1;for(;d!==null&&d.id.clock+d.length<=i.struct.id.clock+i.struct.length&&d.id.client>=i.struct.id.client;)d=h.next(),f=!0;if(d===null||d.id.client!==u||f&&d.id.clock>i.struct.id.clock+i.struct.length)continue;if(u!==i.struct.id.client)nt(l,i.struct,i.offset),i={struct:d,offset:0},h.next();else if(i.struct.id.clock+i.struct.length<d.id.clock)if(i.struct.constructor===B)i.struct.length=d.id.clock+d.length-i.struct.id.clock;else{nt(l,i.struct,i.offset);const g=d.id.clock-i.struct.id.clock-i.struct.length;i={struct:new B(b(u,i.struct.id.clock+i.struct.length),g),offset:0}}else{const g=i.struct.id.clock+i.struct.length-d.id.clock;g>0&&(i.struct.constructor===B?i.struct.length-=g:d=Qi(d,g)),i.struct.mergeWith(d)||(nt(l,i.struct,i.offset),i={struct:d,offset:0},h.next())}}else i={struct:h.curr,offset:0},h.next();for(let d=h.curr;d!==null&&d.id.client===u&&d.id.clock===i.struct.id.clock+i.struct.length&&d.constructor!==B;d=h.next())nt(l,i.struct,i.offset),i={struct:d,offset:0}}i!==null&&(nt(l,i.struct,i.offset),i=null),nn(l);const c=s.map(h=>Ge(h)),a=Mi(c);return St(o,a),o.toUint8Array()},Zi=(n,t,e=Et,s=at)=>{const r=is(t),i=new s,o=new en(i),l=new e(Z(n)),c=new tn(l,!1);for(;c.curr;){const h=c.curr,u=h.id.client,d=r.get(u)||0;if(c.curr.constructor===B){c.next();continue}if(h.id.clock+h.length>d)for(nt(o,h,it(d-h.id.clock,0)),c.next();c.curr&&c.curr.id.client===u;)nt(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===u&&c.curr.id.clock+c.curr.length<=d;)c.next()}nn(o);const a=Ge(l);return St(i,a),i.toUint8Array()},ys=n=>{n.written>0&&(n.clientStructs.push({written:n.written,restEncoder:S(n.encoder.restEncoder)}),n.encoder.restEncoder=x(),n.written=0)},nt=(n,t,e)=>{n.written>0&&n.currClient!==t.id.client&&ys(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++},nn=n=>{ys(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),ne(t,s.restEncoder)}},to=(n,t,e,s)=>{const r=new e(Z(n)),i=new tn(r,!1),o=new s,l=new en(o);for(let a=i.curr;a!==null;a=i.next())nt(l,t(a),0);nn(l);const c=Ge(r);return St(o,c),o.toUint8Array()},eo=n=>to(n,Tr,Et,Vt),bs="You must not compute changes after the event-handler fired.";class de{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=no(this.currentTarget,this.target))}deletes(t){return qn(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw J(bs);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=Ce(c.content.getContent());else return;else c!==null&&this.deletes(c)?(o="update",l=Ce(c.content.getContent())):(o="add",l=void 0)}else if(this.deletes(i))o="delete",l=Ce(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 J(bs);const e=this.target,s=rt(),r=rt(),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 no=(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},_s=80;let sn=0;class so{constructor(t,e){t.marker=!0,this.p=t,this.index=e,this.timestamp=sn++}}const ro=n=>{n.timestamp=sn++},ks=(n,t,e)=>{n.p.marker=!1,n.p=t,t.marker=!0,n.index=e,n.timestamp=sn++},io=(n,t,e)=>{if(n.length>=_s){const s=n.reduce((r,i)=>r.timestamp<i.timestamp?r:i);return ks(s,t,e),s}else{const s=new so(t,e);return n.push(s),s}},fe=(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,ro(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/_s?(ks(e,s,r),e):io(n._searchMarker,s,r)},$t=(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=it(t,r.index+e))}},ge=(n,t,e)=>{const s=n,r=t.changedParentTypes;for(;Y(r,n,()=>[]).push(e),n._item!==null;)n=n._item.parent;hs(s._eH,e,t)};class M{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=ls(),this._dEH=ls(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,e){this.doc=t,this._item=e}_copy(){throw V()}clone(){throw V()}_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){cs(this._eH,t)}observeDeep(t){cs(this._dEH,t)}unobserve(t){as(this._eH,t)}unobserveDeep(t){as(this._dEH,t)}toJSON(){}}const Ss=(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},Ds=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},jt=(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}},Es=(n,t)=>{const e=[];return jt(n,(s,r)=>{e.push(t(s,r,n))}),e},oo=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}}}},Cs=(n,t)=>{const e=fe(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}},pe=(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 A(b(o,L(l,o)),r,r&&r.lastId,c,c&&c.id,t,null,new ft(a)),r.integrate(n,0),a=[])};s.forEach(u=>{if(u===null)a.push(u);else switch(u.constructor){case Number:case Object:case Boolean:case Array:case String:a.push(u);break;default:switch(h(),u.constructor){case Uint8Array:case ArrayBuffer:r=new A(b(o,L(l,o)),r,r&&r.lastId,c,c&&c.id,t,null,new Yt(new Uint8Array(u))),r.integrate(n,0);break;case Dt:r=new A(b(o,L(l,o)),r,r&&r.lastId,c,c&&c.id,t,null,new zt(u)),r.integrate(n,0);break;default:if(u instanceof M)r=new A(b(o,L(l,o)),r,r&&r.lastId,c,c&&c.id,t,null,new q(u)),r.integrate(n,0);else throw new Error("Unexpected content type in insert operation")}}}),h()},As=J("Length exceeded!"),Is=(n,t,e,s)=>{if(e>t._length)throw As;if(e===0)return t._searchMarker&&$t(t._searchMarker,e,s.length),pe(n,t,null,s);const r=e,i=fe(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&&$t(t._searchMarker,r,s.length),pe(n,t,o,s)},lo=(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 pe(n,t,r,e)},Ls=(n,t,e,s)=>{if(s===0)return;const r=e,i=s,o=fe(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 As;t._searchMarker&&$t(t._searchMarker,r,-i+s)},we=(n,t,e)=>{const s=t._map.get(e);s!==void 0&&s.delete(n)},rn=(n,t,e,s)=>{const r=t._map.get(e)||null,i=n.doc,o=i.clientID;let l;if(s==null)l=new ft([s]);else switch(s.constructor){case Number:case Object:case Boolean:case Array:case String:l=new ft([s]);break;case Uint8Array:l=new Yt(s);break;case Dt:l=new zt(s);break;default:if(s instanceof M)l=new q(s);else throw new Error("Unexpected content type")}new A(b(o,L(i.store,o)),r,r&&r.lastId,null,null,t,e,l).integrate(n,0)},on=(n,t)=>{const e=n._map.get(t);return e!==void 0&&!e.deleted?e.content.getContent()[e.length-1]:void 0},Ms=n=>{const t={};return n._map.forEach((e,s)=>{e.deleted||(t[s]=e.content.getContent()[e.length-1])}),t},vs=(n,t)=>{const e=n._map.get(t);return e!==void 0&&!e.deleted},me=n=>Ii(n.entries(),t=>!t[1].deleted);class co extends de{constructor(t,e){super(t,e),this._transaction=e}}class At extends M{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const e=new At;return e.push(t),e}_integrate(t,e){super._integrate(t,e),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new At}clone(){const t=new At;return t.insert(0,this.toArray().map(e=>e instanceof M?e.clone():e)),t}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}_callObserver(t,e){super._callObserver(t,e),ge(this,t,new co(this,t))}insert(t,e){this.doc!==null?_(this.doc,s=>{Is(s,this,t,e)}):this._prelimContent.splice(t,0,...e)}push(t){this.doc!==null?_(this.doc,e=>{lo(e,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,e=1){this.doc!==null?_(this.doc,s=>{Ls(s,this,t,e)}):this._prelimContent.splice(t,e)}get(t){return Cs(this,t)}toArray(){return Ds(this)}slice(t=0,e=this.length){return Ss(this,t,e)}toJSON(){return this.map(t=>t instanceof M?t.toJSON():t)}map(t){return Es(this,t)}forEach(t){jt(this,t)}[Symbol.iterator](){return oo(this)}_write(t){t.writeTypeRef(To)}}const ao=n=>new At;class ho extends de{constructor(t,e,s){super(t,e),this.keysChanged=s}}class ht extends M{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 M?e.clone():e)}),t}_callObserver(t,e){ge(this,t,new ho(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 M?r.toJSON():r}}),t}get size(){return[...me(this._map)].length}keys(){return Xe(me(this._map),t=>t[0])}values(){return Xe(me(this._map),t=>t[1].content.getContent()[t[1].length-1])}entries(){return Xe(me(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?_(this.doc,e=>{we(e,this,t)}):this._prelimContent.delete(t)}set(t,e){return this.doc!==null?_(this.doc,s=>{rn(s,this,t,e)}):this._prelimContent.set(t,e),e}get(t){return on(this,t)}has(t){return vs(this,t)}clear(){this.doc!==null?_(this.doc,t=>{this.forEach(function(e,s,r){we(t,r,s)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(Oo)}}const uo=n=>new ht,st=(n,t)=>n===t||typeof n=="object"&&typeof t=="object"&&n&&t&&Ur(n,t);class ln{constructor(t,e,s,r){this.left=t,this.right=e,this.index=s,this.currentAttributes=r}forward(){switch(this.right===null&&H(),this.right.content.constructor){case C:this.right.deleted||It(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 xs=(n,t,e)=>{for(;t.right!==null&&e>0;){switch(t.right.content.constructor){case C:t.right.deleted||It(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},ye=(n,t,e)=>{const s=new Map,r=fe(t,e);if(r){const i=new ln(r.p.left,r.p,r.index,s);return xs(n,i,e-r.index)}else{const i=new ln(null,t._start,0,s);return xs(n,i,e)}},Us=(n,t,e,s)=>{for(;e.right!==null&&(e.right.deleted===!0||e.right.content.constructor===C&&st(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 A(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()})},It=(n,t)=>{const{key:e,value:s}=t;s===null?n.delete(e):n.set(e,s)},Ts=(n,t)=>{for(;n.right!==null;){if(!(n.right.deleted||n.right.content.constructor===C&&st(t[n.right.content.key]||null,n.right.content.value)))break;n.forward()}},Os=(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(!st(a,c)){o.set(l,a);const{left:h,right:u}=e;e.right=new A(b(i,L(r.store,i)),h,h&&h.lastId,u,u&&u.id,t,null,new C(l,c)),e.right.integrate(n,0),e.forward()}}return o},cn=(n,t,e,s,r)=>{e.currentAttributes.forEach((d,f)=>{r[f]===void 0&&(r[f]=null)});const i=n.doc,o=i.clientID;Ts(e,r);const l=Os(n,t,e,r),c=s.constructor===String?new j(s):s instanceof M?new q(s):new dt(s);let{left:a,right:h,index:u}=e;t._searchMarker&&$t(t._searchMarker,e.index,c.getLength()),h=new A(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=u,e.forward(),Us(n,t,e,l)},Rs=(n,t,e,s,r)=>{const i=n.doc,o=i.clientID;Ts(e,r);const l=Os(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(st(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
2
|
`;e.right=new A(b(o,L(i.store,o)),e.left,e.left&&e.left.lastId,e.right,e.right&&e.right.id,t,null,new j(c)),e.right.integrate(n,0),e.forward()}Us(n,t,e,l)},Ns=(n,t,e,s,r)=>{let i=t;const o=k();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:u}=a,d=s.get(h)||null;(o.get(h)!==a||d===u)&&(t.delete(n),l++,!c&&(r.get(h)||null)===u&&d!==u&&(d===null?r.delete(h):r.set(h,d))),!c&&!t.deleted&&It(r,a);break}}}t=t.right}return l},fo=(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}},go=n=>{let t=0;return _(n.doc,e=>{let s=n._start,r=n._start,i=k();const o=K(i);for(;r;){if(r.deleted===!1)switch(r.content.constructor){case C:It(o,r.content);break;default:t+=Ns(e,s,r,i,o),i=K(o),s=r;break}r=r.right}}),t},po=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&&gs(n,e.store.clients.get(s),i,r,o=>{!o.deleted&&o.content.constructor===C&&o.constructor!==N&&t.add(o.parent)})}_(e,s=>{Wn(n,n.deleteSet,r=>{if(r instanceof N||!r.parent._hasFormatting||t.has(r.parent))return;const i=r.parent;r.content.constructor===C?t.add(i):fo(s,r)});for(const r of t)go(r)})},Bs=(n,t,e)=>{const s=e,r=K(t.currentAttributes),i=t.right;for(;e>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case q:case dt:case j: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&&Ns(n,i,t.right,r,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&$t(o._searchMarker,t.index,-s+e),t};class wo extends de{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=[];_(t,s=>{const r=new Map,i=new Map;let o=this.target._start,l=null;const c={};let a="",h=0,u=0;const d=()=>{if(l!==null){let f=null;switch(l){case"delete":u>0&&(f={delete:u}),u=0;break;case"insert":(typeof a=="object"||a.length>0)&&(f={insert:a},r.size>0&&(f.attributes={},r.forEach((g,m)=>{g!==null&&(f.attributes[m]=g)}))),a="";break;case"retain":h>0&&(f={retain:h},vr(c)||(f.attributes=Ar({},c))),h=0;break}f&&e.push(f),l=null}};for(;o!==null;){switch(o.content.constructor){case q:case dt:this.adds(o)?this.deletes(o)||(d(),l="insert",a=o.content.getContent()[0],d()):this.deletes(o)?(l!=="delete"&&(d(),l="delete"),u+=1):o.deleted||(l!=="retain"&&(d(),l="retain"),h+=1);break;case j:this.adds(o)?this.deletes(o)||(l!=="insert"&&(d(),l="insert"),a+=o.content.str):this.deletes(o)?(l!=="delete"&&(d(),l="delete"),u+=o.length):o.deleted||(l!=="retain"&&(d(),l="retain"),h+=o.length);break;case C:{const{key:f,value:g}=o.content;if(this.adds(o)){if(!this.deletes(o)){const m=r.get(f)||null;st(m,g)?g!==null&&o.delete(s):(l==="retain"&&d(),st(g,i.get(f)||null)?delete c[f]:c[f]=g)}}else if(this.deletes(o)){i.set(f,g);const m=r.get(f)||null;st(m,g)||(l==="retain"&&d(),c[f]=m)}else if(!o.deleted){i.set(f,g);const m=c[f];m!==void 0&&(st(m,g)?m!==null&&o.delete(s):(l==="retain"&&d(),g===null?delete c[f]:c[f]=g))}o.deleted||(l==="insert"&&d(),It(r,o.content));break}}o=o.right}for(d();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 Lt extends M{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 Lt}clone(){const t=new Lt;return t.applyDelta(this.toDelta()),t}_callObserver(t,e){super._callObserver(t,e);const s=new wo(this,t,e);ge(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===j&&(t+=e.content.str),e=e.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:e=!0}={}){this.doc!==null?_(this.doc,s=>{const r=new ln(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
3
|
`?o.insert.slice(0,-1):o.insert;(typeof l!="string"||l.length>0)&&cn(s,this,r,l,o.attributes||{})}else o.retain!==void 0?Rs(s,this,r,o.retain,o.attributes||{}):o.delete!==void 0&&Bs(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 u={};let d=!1;i.forEach((g,m)=>{d=!0,u[m]=g});const f={insert:l};d&&(f.attributes=u),r.push(f),l=""}}const h=()=>{for(;c!==null;){if(Ht(c,t)||e!==void 0&&Ht(c,e))switch(c.content.constructor){case j:{const u=i.get("ychange");t!==void 0&&!Ht(c,t)?(u===void 0||u.user!==c.id.client||u.type!=="removed")&&(a(),i.set("ychange",s?s("removed",c.id):{type:"removed"})):e!==void 0&&!Ht(c,e)?(u===void 0||u.user!==c.id.client||u.type!=="added")&&(a(),i.set("ychange",s?s("added",c.id):{type:"added"})):u!==void 0&&(a(),i.delete("ychange")),l+=c.content.str;break}case q:case dt:{a();const u={insert:c.content.getContent()[0]};if(i.size>0){const d={};u.attributes=d,i.forEach((f,g)=>{d[g]=f})}r.push(u);break}case C:Ht(c,t)&&(a(),It(i,c.content));break}c=c.right}a()};return t||e?_(o,u=>{t&&Pe(u,t),e&&Pe(u,e),h()},"cleanup"):h(),r}insert(t,e,s){if(e.length<=0)return;const r=this.doc;r!==null?_(r,i=>{const o=ye(i,this,t);s||(s={},o.currentAttributes.forEach((l,c)=>{s[c]=l})),cn(i,this,o,e,s)}):this._pending.push(()=>this.insert(t,e,s))}insertEmbed(t,e,s={}){const r=this.doc;r!==null?_(r,i=>{const o=ye(i,this,t);cn(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?_(s,r=>{Bs(r,ye(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?_(r,i=>{const o=ye(i,this,t);o.right!==null&&Rs(i,this,o,e,s)}):this._pending.push(()=>this.format(t,e,s))}removeAttribute(t){this.doc!==null?_(this.doc,e=>{we(e,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,e){this.doc!==null?_(this.doc,s=>{rn(s,this,t,e)}):this._pending.push(()=>this.setAttribute(t,e))}getAttribute(t){return on(this,t)}getAttributes(){return Ms(this)}_write(t){t.writeTypeRef(Ro)}}const mo=n=>new Lt;class an{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===Kt||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 M{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 M?e.clone():e)),t}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new an(this,t)}querySelector(t){t=t.toUpperCase();const s=new an(this,r=>r.nodeName&&r.nodeName.toUpperCase()===t).next();return s.done?null:s.value}querySelectorAll(t){return t=t.toUpperCase(),Q(new an(this,e=>e.nodeName&&e.nodeName.toUpperCase()===t))}_callObserver(t,e){ge(this,t,new _o(this,e,t))}toString(){return Es(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),jt(this,i=>{r.insertBefore(i.toDOM(t,e,s),null)}),r}insert(t,e){this.doc!==null?_(this.doc,s=>{Is(s,this,t,e)}):this._prelimContent.splice(t,0,...e)}insertAfter(t,e){if(this.doc!==null)_(this.doc,s=>{const r=t&&t instanceof M?t._item:t;pe(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 J("Reference item not found");s.splice(r,0,...e)}}delete(t,e=1){this.doc!==null?_(this.doc,s=>{Ls(s,this,t,e)}):this._prelimContent.splice(t,e)}toArray(){return Ds(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return Cs(this,t)}slice(t=0,e=this.length){return Ss(this,t,e)}forEach(t){jt(this,t)}_write(t){t.writeTypeRef(Bo)}}const yo=n=>new ut;class Kt 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 Kt(this.nodeName)}clone(){const t=new Kt(this.nodeName),e=this.getAttributes();return Lr(e,(s,r)=>{typeof s=="string"&&t.setAttribute(r,s)}),t.insert(0,this.toArray().map(s=>s instanceof M?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?_(this.doc,e=>{we(e,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,e){this.doc!==null?_(this.doc,s=>{rn(s,this,t,e)}):this._prelimAttrs.set(t,e)}getAttribute(t){return on(this,t)}hasAttribute(t){return vs(this,t)}getAttributes(){return Ms(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 jt(this,o=>{r.appendChild(o.toDOM(t,e,s))}),s!==void 0&&s._createAssociation(r,this),r}_write(t){t.writeTypeRef(No),t.writeKey(this.nodeName)}}const bo=n=>new Kt(n.readKey());class _o extends de{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 be extends ht{constructor(t){super(),this.hookName=t}_copy(){return new be(this.hookName)}clone(){const t=new be(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(Fo),t.writeKey(this.hookName)}}const ko=n=>new be(n.readKey());class _e extends Lt{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 _e}clone(){const t=new _e;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(Vo)}}const So=n=>new _e;class hn{constructor(t,e){this.id=t,this.length=e}get deleted(){throw V()}mergeWith(t){return!1}write(t,e,s){throw V()}integrate(t,e){throw V()}}const Do=0;class N extends hn{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),ds(t.doc.store,this)}write(t,e){t.writeInfo(Do),t.writeLen(this.length-e)}getMissing(t,e){return null}}class Yt{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Yt(this.content)}splice(t){throw V()}mergeWith(t){return!1}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeBuf(this.content)}getRef(){return 3}}const Eo=n=>new Yt(n.readBuf());class Xt{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new Xt(this.len)}splice(t){const e=new Xt(this.len-t);return this.len=t,e}mergeWith(t){return this.len+=t.len,!0}integrate(t,e){le(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 Co=n=>new Xt(n.readLen()),Fs=(n,t)=>new Dt({guid:n,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class zt{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 zt(Fs(this.doc.guid,this.opts))}splice(t){throw V()}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 Ao=n=>new zt(Fs(n.readString(),n.readAny()));class dt{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new dt(this.embed)}splice(t){throw V()}mergeWith(t){return!1}integrate(t,e){}delete(t){}gc(t){}write(t,e){t.writeJSON(this.embed)}getRef(){return 5}}const Io=n=>new dt(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 V()}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 Lo=n=>new C(n.readKey(),n.readJSON());class ke{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new ke(this.arr)}splice(t){const e=new ke(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 Mo=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 ke(e)};class ft{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new ft(this.arr)}splice(t){const e=new ft(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 vo=n=>{const t=n.readLen(),e=[];for(let s=0;s<t;s++)e.push(n.readAny());return new ft(e)};class j{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new j(this.str)}splice(t){const e=new j(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 xo=n=>new j(n.readString()),Uo=[ao,uo,mo,bo,yo,ko,So],To=0,Oo=1,Ro=2,No=3,Bo=4,Fo=5,Vo=6;class q{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new q(this.type._copy())}splice(t){throw V()}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 Ho=n=>new q(Uo[n.readTypeRef()](n)),Se=(n,t,e)=>{const{client:s,clock:r}=t.id,i=new A(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 A extends hn{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&Ue)>0!==t&&(this.info^=Ue)}get marker(){return(this.info&Ue)>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&xe)>0}set deleted(t){this.deleted!==t&&(this.info^=xe)}markDeleted(){this.info|=xe}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===Ct&&this.id.client!==this.parent.client&&this.parent.clock>=L(e,this.parent.client))return this.parent.client;if(this.origin&&(this.left=fs(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===N||this.right&&this.right.constructor===N)&&(this.parent=null),!this.parent)this.left&&this.left.constructor===A&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===A&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Ct){const s=Qe(e,this.parent);s.constructor===N?this.parent=null:this.parent=s.content.type}return null}integrate(t,e){if(e>0&&(this.id.clock+=e,this.left=fs(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),ce(this.origin,r.origin)){if(r.id.client<this.id.client)s=r,i.clear();else if(ce(this.rightOrigin,r.rightOrigin))break}else if(r.origin!==null&&o.has(Qe(t.doc.store,r.origin)))i.has(Qe(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),ds(t.doc.store,this),this.content.integrate(t,this),ws(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new N(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&&ce(t.origin,this.lastId)&&this.right===t&&ce(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(),le(t.deleteSet,this.id.client,this.id.clock,this.length),ws(t,e,this.parentSub),this.content.delete(t)}}gc(t,e){if(!this.deleted)throw H();this.content.gc(t),e?zi(t,this,new N(this.id,this.length)):this.content=new Xt(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()&ee|(s===null?0:T)|(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=Xi(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===Ct?(t.writeParentInfo(!1),t.writeLeftID(l)):H();i!==null&&t.writeString(i)}this.content.write(t,e)}}const Vs=(n,t)=>$o[t&ee](n),$o=[()=>{H()},Co,Mo,Eo,xo,Io,Lo,Ho,vo,Ao,()=>{H()}],jo=10;class B extends hn{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,e){H()}write(t,e){t.writeInfo(jo),p(t.restEncoder,this.length-e)}getMissing(t,e){return null}}const Hs=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},$s="__ $YJS$ __";Hs[$s]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),Hs[$s]=!0;const js=0,un=1,Ks=2,dn=(n,t)=>{p(n,js);const e=Ki(t);D(n,e)},Ys=(n,t,e)=>{p(n,un),D(n,qe(t,e))},Ko=(n,t,e)=>Ys(t,e,U(n)),Xs=(n,t,e)=>{try{rs(t,U(n),e)}catch(s){console.error("Caught error while handling a Yjs update",s)}},Yo=(n,t)=>{p(n,Ks),D(n,t)},Xo=Xs,zo=(n,t,e,s)=>{const r=w(n);switch(r){case js:Ko(n,t,e);break;case un:Xs(n,e,s);break;case Ks:Xo(n,e,s);break;default:throw new Error("Unknown message type")}return r},Jo=0,Go=(n,t,e)=>{switch(w(n)){case Jo:e(t,tt(n))}},fn=3e4;class Wo extends oe{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&&fn/2<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const s=[];this.meta.forEach((r,i)=>{i!==this.clientID&&fn<=e-r.lastUpdated&&this.states.has(i)&&s.push(i)}),s.length>0&&gn(this,s,"timeout")},X(fn/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),Tt(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 gn=(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]))},Jt=(n,t,e=n.states)=>{const s=t.length,r=x();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),lt(r,JSON.stringify(l))}return S(r)},qo=(n,t,e)=>{const s=Z(t),r=ct(),i=[],o=[],l=[],c=[],a=w(s);for(let h=0;h<a;h++){const u=w(s);let d=w(s);const f=JSON.parse(tt(s)),g=n.meta.get(u),m=n.states.get(u),O=g===void 0?0:g.clock;(O<d||O===d&&f===null&&n.states.has(u))&&(f===null?u===n.clientID&&n.getLocalState()!=null?d++:n.states.delete(u):n.states.set(u,f),n.meta.set(u,{clock:d,lastUpdated:r}),g===void 0&&f!==null?i.push(u):g!==void 0&&f===null?c.push(u):f!==null&&(Tt(f,m)||l.push(u),o.push(u)))}(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])},Po=n=>Mr(n,(t,e)=>`${encodeURIComponent(e)}=${encodeURIComponent(t)}`).join("&");var gt=0,zs=3,Mt=1,Qo=2;function Zo(n,t){if(!n)throw new Error(t)}var Gt=[];Gt[gt]=(n,t,e,s,r)=>{p(n,gt);const i=zo(t,n,e.doc,e);s&&i===un&&!e.synced&&(e.synced=!0)},Gt[zs]=(n,t,e,s,r)=>{p(n,Mt),D(n,Jt(e.awareness,Array.from(e.awareness.getStates().keys())))},Gt[Mt]=(n,t,e,s,r)=>{qo(e.awareness,U(t),e)},Gt[Qo]=(n,t,e,s,r)=>{Go(t,e.doc,(i,o)=>tl(e,o))};var Js=3e4;function tl(n,t){console.warn(`Permission denied to access ${n.url}.
|
|
4
|
-
${t}`)}function Gs(n,t,e){const s=Z(t),r=x(),i=w(s),o=n.messageHandlers[i];return o?o(r,s,n,e,i):console.error("Unable to compute message"),r}function Ws(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(e.data==="ping"){t.send("pong");return}n.wsLastMessageReceived=ct();const s=Gs(n,new Uint8Array(e.data),!0);Oe(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,gn(n.awareness,Array.from(n.awareness.getStates().keys()).filter(s=>s!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(Ws,ve(Fr(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=x();if(p(e,gt),dn(e,n.doc),t.send(S(e)),n.awareness.getLocalState()!==null){const s=x();p(s,Mt),D(s,Jt(n.awareness,[n.doc.clientID])),t.send(S(s))}},n.emit("status",[{status:"connecting"}])}}function pn(n,t){const e=n.ws;n.wsconnected&&e&&e.readyState===e.OPEN&&e.send(t),n.bcconnected&&_t(n.bcChannel,t,n)}var el=class extends oe{constructor(t,e,s,{connect:r=!0,awareness:i=new Wo(s),params:o={},WebSocketPolyfill:l=WebSocket,resyncInterval:c=-1,maxBackoffTime:a=2500,disableBc:h=!1}={}){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 u=Po(o);this.maxBackoffTime=a,this.bcChannel=t+"/"+e,this.url=t+"/"+e+(u.length===0?"":"?"+u),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=Gt.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 d=x();p(d,gt),dn(d,s),this.ws.send(S(d))}},c)),this._bcSubscriber=(d,f)=>{if(f!==this){const g=Gs(this,new Uint8Array(d),!1);Oe(g)>1&&_t(this.bcChannel,S(g),this)}},this._updateHandler=(d,f)=>{if(f!==this){const g=x();p(g,gt),Yo(g,d),pn(this,S(g))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:d,updated:f,removed:g},m)=>{const O=d.concat(f).concat(g),qt=x();p(qt,Mt),D(qt,Jt(i,O)),pn(this,S(qt))},this._unloadHandler=()=>{gn(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&&Js<ct()-this.wsLastMessageReceived&&(Zo(this.ws!==null,"ws must not be null"),this.ws.close())},Js/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||(hi(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const t=x();p(t,gt),dn(t,this.doc),_t(this.bcChannel,S(t),this);const e=x();p(e,gt),Ys(e,this.doc),_t(this.bcChannel,S(e),this);const s=x();p(s,zs),_t(this.bcChannel,S(s),this);const r=x();p(r,Mt),D(r,Jt(this.awareness,[this.doc.clientID])),_t(this.bcChannel,S(r),this)}disconnectBc(){const t=x();p(t,Mt),D(t,Jt(this.awareness,[this.doc.clientID],new Map)),pn(this,S(t)),this.bcconnected&&(ui(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&&(Ws(this),this.connectBc())}};function qs(){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)})}var nl=class extends el{constructor(n,t,e,s={}){const r=`${n.startsWith("localhost:")||n.startsWith("127.0.0.1:")?"ws":"wss"}://${n}/party`;s.params===void 0?s.params={_pk:qs()}:s.params._pk=qs(),super(r,t,e,s)}};const pt=n=>kt((t,e)=>{n.onerror=s=>e(new Error(s.target.error)),n.onsuccess=s=>t(s.target.result)}),sl=(n,t)=>kt((e,s)=>{const r=indexedDB.open(n);r.onupgradeneeded=i=>t(i.target.result),r.onerror=i=>s(J(i.target.error)),r.onsuccess=i=>{const o=i.target.result;o.onversionchange=()=>{o.close()},typeof addEventListener<"u"&&addEventListener("unload",()=>o.close()),e(o)}}),rl=n=>pt(indexedDB.deleteDatabase(n)),il=(n,t)=>t.forEach(e=>n.createObjectStore.apply(n,e)),Wt=(n,t,e="readwrite")=>{const s=n.transaction(t,e);return t.map(r=>fl(s,r))},Ps=(n,t)=>pt(n.count(t)),ol=(n,t)=>pt(n.get(t)),Qs=(n,t)=>pt(n.delete(t)),ll=(n,t,e)=>pt(n.put(t,e)),wn=(n,t)=>pt(n.add(t)),cl=(n,t,e)=>pt(n.getAll(t,e)),al=(n,t,e)=>{let s=null;return dl(n,t,r=>(s=r,!1),e).then(()=>s)},hl=(n,t=null)=>al(n,t,"prev"),ul=(n,t)=>kt((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()}}),dl=(n,t,e,s="next")=>ul(n.openKeyCursor(t,s),r=>e(r.key)),fl=(n,t)=>n.objectStore(t),gl=(n,t)=>IDBKeyRange.upperBound(n,t),pl=(n,t)=>IDBKeyRange.lowerBound(n,t),mn="custom",Zs="updates",tr=500,er=(n,t=()=>{},e=()=>{})=>{const[s]=Wt(n.db,[Zs]);return cl(s,pl(n._dbref,!1)).then(r=>{n._destroyed||(t(s),_(n.doc,()=>{r.forEach(i=>rs(n.doc,i))},n,!1),e(s))}).then(()=>hl(s).then(r=>{n._dbref=r+1})).then(()=>Ps(s).then(r=>{n._dbsize=r})).then(()=>s)},wl=(n,t=!0)=>er(n).then(e=>{(t||n._dbsize>=tr)&&wn(e,qe(n.doc)).then(()=>Qs(e,gl(n._dbref,!0))).then(()=>Ps(e).then(s=>{n._dbsize=s}))});class ml extends oe{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=>il(s,[["updates",{autoIncrement:!0}],["custom"]])),this.whenSynced=kt(s=>this.on("synced",()=>s(this))),this._db.then(s=>{this.db=s,er(this,o=>wn(o,qe(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]=Wt(this.db,[Zs]);wn(i,s),++this._dbsize>=tr&&(this._storeTimeoutId!==null&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout(()=>{wl(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(()=>{rl(this.name)})}get(t){return this._db.then(e=>{const[s]=Wt(e,[mn],"readonly");return ol(s,t)})}set(t,e){return this._db.then(s=>{const[r]=Wt(s,[mn]);return ll(r,e,t)})}del(t){return this._db.then(e=>{const[s]=Wt(e,[mn]);return Qs(s,t)})}}const jl="",yl="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.CanPost="can-post",n))(E||{});const
|
|
4
|
+
${t}`)}function Gs(n,t,e){const s=Z(t),r=x(),i=w(s),o=n.messageHandlers[i];return o?o(r,s,n,e,i):console.error("Unable to compute message"),r}function Ws(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(e.data==="ping"){t.send("pong");return}n.wsLastMessageReceived=ct();const s=Gs(n,new Uint8Array(e.data),!0);Oe(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,gn(n.awareness,Array.from(n.awareness.getStates().keys()).filter(s=>s!==n.doc.clientID),n),n.emit("status",[{status:"disconnected"}])):n.wsUnsuccessfulReconnects++,setTimeout(Ws,ve(Fr(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=x();if(p(e,gt),dn(e,n.doc),t.send(S(e)),n.awareness.getLocalState()!==null){const s=x();p(s,Mt),D(s,Jt(n.awareness,[n.doc.clientID])),t.send(S(s))}},n.emit("status",[{status:"connecting"}])}}function pn(n,t){const e=n.ws;n.wsconnected&&e&&e.readyState===e.OPEN&&e.send(t),n.bcconnected&&_t(n.bcChannel,t,n)}var el=class extends oe{constructor(t,e,s,{connect:r=!0,awareness:i=new Wo(s),params:o={},WebSocketPolyfill:l=WebSocket,resyncInterval:c=-1,maxBackoffTime:a=2500,disableBc:h=!1}={}){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 u=Po(o);this.maxBackoffTime=a,this.bcChannel=t+"/"+e,this.url=t+"/"+e+(u.length===0?"":"?"+u),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=Gt.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 d=x();p(d,gt),dn(d,s),this.ws.send(S(d))}},c)),this._bcSubscriber=(d,f)=>{if(f!==this){const g=Gs(this,new Uint8Array(d),!1);Oe(g)>1&&_t(this.bcChannel,S(g),this)}},this._updateHandler=(d,f)=>{if(f!==this){const g=x();p(g,gt),Yo(g,d),pn(this,S(g))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:d,updated:f,removed:g},m)=>{const O=d.concat(f).concat(g),qt=x();p(qt,Mt),D(qt,Jt(i,O)),pn(this,S(qt))},this._unloadHandler=()=>{gn(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&&Js<ct()-this.wsLastMessageReceived&&(Zo(this.ws!==null,"ws must not be null"),this.ws.close())},Js/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||(hi(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const t=x();p(t,gt),dn(t,this.doc),_t(this.bcChannel,S(t),this);const e=x();p(e,gt),Ys(e,this.doc),_t(this.bcChannel,S(e),this);const s=x();p(s,zs),_t(this.bcChannel,S(s),this);const r=x();p(r,Mt),D(r,Jt(this.awareness,[this.doc.clientID])),_t(this.bcChannel,S(r),this)}disconnectBc(){const t=x();p(t,Mt),D(t,Jt(this.awareness,[this.doc.clientID],new Map)),pn(this,S(t)),this.bcconnected&&(ui(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&&(Ws(this),this.connectBc())}};function qs(){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)})}var nl=class extends el{constructor(n,t,e,s={}){const r=`${n.startsWith("localhost:")||n.startsWith("127.0.0.1:")?"ws":"wss"}://${n}/party`;s.params===void 0?s.params={_pk:qs()}:s.params._pk=qs(),super(r,t,e,s)}};const pt=n=>kt((t,e)=>{n.onerror=s=>e(new Error(s.target.error)),n.onsuccess=s=>t(s.target.result)}),sl=(n,t)=>kt((e,s)=>{const r=indexedDB.open(n);r.onupgradeneeded=i=>t(i.target.result),r.onerror=i=>s(J(i.target.error)),r.onsuccess=i=>{const o=i.target.result;o.onversionchange=()=>{o.close()},typeof addEventListener<"u"&&addEventListener("unload",()=>o.close()),e(o)}}),rl=n=>pt(indexedDB.deleteDatabase(n)),il=(n,t)=>t.forEach(e=>n.createObjectStore.apply(n,e)),Wt=(n,t,e="readwrite")=>{const s=n.transaction(t,e);return t.map(r=>fl(s,r))},Ps=(n,t)=>pt(n.count(t)),ol=(n,t)=>pt(n.get(t)),Qs=(n,t)=>pt(n.delete(t)),ll=(n,t,e)=>pt(n.put(t,e)),wn=(n,t)=>pt(n.add(t)),cl=(n,t,e)=>pt(n.getAll(t,e)),al=(n,t,e)=>{let s=null;return dl(n,t,r=>(s=r,!1),e).then(()=>s)},hl=(n,t=null)=>al(n,t,"prev"),ul=(n,t)=>kt((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()}}),dl=(n,t,e,s="next")=>ul(n.openKeyCursor(t,s),r=>e(r.key)),fl=(n,t)=>n.objectStore(t),gl=(n,t)=>IDBKeyRange.upperBound(n,t),pl=(n,t)=>IDBKeyRange.lowerBound(n,t),mn="custom",Zs="updates",tr=500,er=(n,t=()=>{},e=()=>{})=>{const[s]=Wt(n.db,[Zs]);return cl(s,pl(n._dbref,!1)).then(r=>{n._destroyed||(t(s),_(n.doc,()=>{r.forEach(i=>rs(n.doc,i))},n,!1),e(s))}).then(()=>hl(s).then(r=>{n._dbref=r+1})).then(()=>Ps(s).then(r=>{n._dbsize=r})).then(()=>s)},wl=(n,t=!0)=>er(n).then(e=>{(t||n._dbsize>=tr)&&wn(e,qe(n.doc)).then(()=>Qs(e,gl(n._dbref,!0))).then(()=>Ps(e).then(s=>{n._dbsize=s}))});class ml extends oe{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=>il(s,[["updates",{autoIncrement:!0}],["custom"]])),this.whenSynced=kt(s=>this.on("synced",()=>s(this))),this._db.then(s=>{this.db=s,er(this,o=>wn(o,qe(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]=Wt(this.db,[Zs]);wn(i,s),++this._dbsize>=tr&&(this._storeTimeoutId!==null&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout(()=>{wl(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(()=>{rl(this.name)})}get(t){return this._db.then(e=>{const[s]=Wt(e,[mn],"readonly");return ol(s,t)})}set(t,e){return this._db.then(s=>{const[r]=Wt(s,[mn]);return ll(r,e,t)})}del(t){return this._db.then(e=>{const[s]=Wt(e,[mn]);return Qs(s,t)})}}const jl="",yl={ctrlKey:"Control",altKey:"Alt",shiftKey:"Shift",metaKey:"Meta"},bl="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.CanPost="can-post",n))(E||{});const _l=(n,t=300)=>{let e;return function(...s){clearTimeout(e),e=setTimeout(()=>n.apply(this,s),t)}},nr=`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
5
|
16 0,
|
|
6
6
|
auto`,kl=`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 sr(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=kl}else{if(i.scale>=i.maxScale){l.style.cursor="not-allowed";return}l.style.cursor=nr}r(o)}function De(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 rr={[E.CanMove]:{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}=De(n);t({startMouseX:e,startMouseY:s})},onDrag:(n,{data:t,localData:e,setData:s,setLocalData:r,element:i})=>{const{clientX:o,clientY:l}=De(n),{top:c,left:a,bottom:h,right:u}=i.getBoundingClientRect();u>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"},[E.CanSpin]:{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}=De(n);t({startMouseX:e})},onDrag:(n,{data:t,localData:e,setData:s,setLocalData:r})=>{const{clientX:i}=De(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"},[E.CanToggle]:{defaultData:!1,updateElement:({element:n,data:t})=>{n.classList.toggle("clicked",t)},onClick:(n,{data:t,setData:e})=>{e(!t)},resetShortcut:"shiftKey"},[E.CanGrow]:{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=nr,t.scale>=r.maxScale)return;i+=.1}s({...t,scale:i})},additionalSetup:n=>{n.getElement().addEventListener("mouseenter",t=>{sr(t,n);const e=s=>sr(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"},[E.CanPost]:{defaultData:[],defaultLocalData:{addedEntries:new Set},updateElement:({data:n,localData:{addedEntries:t},setLocalData:e})=>{const s=n.filter(i=>!t.has(i.id)),r=bn("guestbookMessages");s.forEach(i=>{const o=document.createElement("div");o.classList.add("guestbook-entry");const l=new Date(i.timestamp),c=l.toTimeString().split(" ")[0],a=l.toDateString()===new Date().toDateString(),h=(()=>a?"Today ":new Date().getDate()-l.getDate()===1?"Yesterday ":new Date().getDate()-l.getDate()<7?"This week ":"Sometime before ")();o.innerHTML=`
|
|
7
|
-
<span class="guestbook-entry-timestamp">${h}${c}</span><span class="guestbook-entry-name">${i.name}</span> <span class="guestbook-entry-message">${i.message}</span>`,r.prepend(o),t.add(i.id)}),e({addedEntries:t})},additionalSetup:({getElement:n,getData:t,setData:e})=>{n().addEventListener("submit",r=>{r.preventDefault(),r.stopImmediatePropagation();const i=t(),o=new FormData(r.target),l=Object.fromEntries(o.entries()),c=Date.now(),a={name:"someone",message:"something",...l,timestamp:c,id:`${c}-${l.name}`};return e([...i,a]),!1})}},[E.CanDuplicate]:{defaultData:[],defaultLocalData:[],updateElement:({data:n,localData:t,setLocalData:e,element:s})=>{var h;const r=s.getAttribute(E.CanDuplicate),i=document.getElementById(r);let o=document.getElementById((h=t.slice(-1))==null?void 0:h[0])??null;if(!i){console.error(`Element with id ${r} not found. Cannot duplicate.`);return}const l=s.getAttribute(
|
|
7
|
+
<span class="guestbook-entry-timestamp">${h}${c}</span><span class="guestbook-entry-name">${i.name}</span> <span class="guestbook-entry-message">${i.message}</span>`,r.prepend(o),t.add(i.id)}),e({addedEntries:t})},additionalSetup:({getElement:n,getData:t,setData:e})=>{n().addEventListener("submit",r=>{r.preventDefault(),r.stopImmediatePropagation();const i=t(),o=new FormData(r.target),l=Object.fromEntries(o.entries()),c=Date.now(),a={name:"someone",message:"something",...l,timestamp:c,id:`${c}-${l.name}`};return e([...i,a]),!1})}},[E.CanDuplicate]:{defaultData:[],defaultLocalData:[],updateElement:({data:n,localData:t,setLocalData:e,element:s})=>{var h;const r=s.getAttribute(E.CanDuplicate),i=document.getElementById(r);let o=document.getElementById((h=t.slice(-1))==null?void 0:h[0])??null;if(!i){console.error(`Element with id ${r} not found. Cannot duplicate.`);return}const l=s.getAttribute(bl);function c(u){if(l){const d=document.getElementById(l)||document.querySelector(l);if(d){d.appendChild(u);return}}i.parentNode.insertBefore(u,(o||i).nextSibling)}const a=new Set(t);for(const u of n){if(a.has(u))continue;const d=i.cloneNode(!0);Object.assign(d,{...i}),d.id=u,c(d),t.push(u),Sn.setupPlayElement(d),o=d}e(t)},onClick:(n,{data:t,element:e,setData:s})=>{const i=e.getAttribute(E.CanDuplicate)+"-"+Math.random().toString(36).substr(2,9);s([...t,i])}}};class Sl{constructor({element:t,onChange:e,onAwarenessChange:s,defaultData:r,defaultLocalData:i,myDefaultAwareness:o,data:l,awareness:c,updateElement:a,updateElementAwareness:h,onClick:u,onDrag:d,onDragStart:f,additionalSetup:g,resetShortcut:m,debounceMs:O,triggerAwarenessUpdate:qt}){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");this.element=t,this.defaultData=r instanceof Function?r(t):r,this.localData=i instanceof Function?i(t):i,this.triggerAwarenessUpdate=qt,this.onChange=e,this.resetShortcut=m,this.debouncedOnChange=_l(this.onChange,O),this.onAwarenessChange=s,this.updateElement=a,this.updateElementAwareness=h;const hr=l===void 0?this.defaultData:l;c!==void 0&&(this.__awareness=c);const ur=o instanceof Function?o(t):o;ur!==void 0&&this.setLocalAwareness(ur),this._data=hr,this.__data=hr,u&&t.addEventListener("click",R=>{u(R,this.getEventHandlerData())}),d&&(t.addEventListener("touchstart",R=>{R.preventDefault(),f&&f(R,this.getEventHandlerData());const Pt=mt=>{mt.preventDefault(),d(mt,this.getEventHandlerData())},Qt=mt=>{document.removeEventListener("touchmove",Pt),document.removeEventListener("touchend",Qt)};document.addEventListener("touchmove",Pt),document.addEventListener("touchend",Qt)}),t.addEventListener("mousedown",R=>{f&&f(R,this.getEventHandlerData());const Pt=mt=>{mt.preventDefault(),d(mt,this.getEventHandlerData())},Qt=mt=>{document.removeEventListener("mousemove",Pt),document.removeEventListener("mouseup",Qt)};document.addEventListener("mousemove",Pt),document.addEventListener("mouseup",Qt)})),g&&g(this.getSetupData()),m&&(t.title||(t.title=`Hold down the ${yl[m]} key while clicking to reset.`),t.reset=this.reset,t.addEventListener("click",R=>{switch(m){case"ctrlKey":if(!R.ctrlKey)return;break;case"altKey":if(!R.altKey)return;break;case"shiftKey":if(!R.shiftKey)return;break;case"metaKey":if(!R.metaKey)return;break;default:return}this.reset(),R.preventDefault(),R.stopPropagation()}))}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 Dl="playhtml.spencerc99.partykit.dev",yn=new Dt,ir=window.location.href,vt=new nl(Dl,ir,yn);new ml(ir,yn);const P=yn.getMap("playhtml-global"),wt=new Map,or=new Map;let lr=!0;function El(n){return n.id}function bn(n){return document.getElementById(n)}function Cl(n,t){const e=vt.awareness.getLocalState();return((e==null?void 0:e[n])??{})[t]}vt.on("sync",n=>{n||console.error("Issue connecting to yjs..."),kn()});function _n(n){return n instanceof HTMLElement}function Al(n,t,e,s){const r=P.get(t),i={...e,data:r.get(s)??e.defaultData,awareness:Cl(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=vt.awareness.getLocalState())==null?void 0:c[t])||{};l[s]!==o&&(l[s]=o,vt.awareness.setLocalStateField(t,l))},triggerAwarenessUpdate:()=>{cr()}};return new Sl(i)}function Il(n){return n.defaultData!==void 0&&n.updateElement!==void 0}function Ll(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}}return rr[n]}function cr(){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)}vt.awareness.getStates().forEach((e,s)=>{var r;for(const[i,o]of Object.entries(e)){const l=wt.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=wt.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 u=Array.from(h);a.__awareness=u}}})}function kn(){console.log(`࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂
|
|
8
8
|
࿂࿂࿂࿂ ࿂ ࿂ ࿂ ࿂ ࿂ ࿂࿂࿂࿂
|
|
9
9
|
࿂࿂࿂࿂ booting up playhtml... ࿂࿂࿂࿂
|
|
10
10
|
࿂࿂࿂࿂ https://playhtml.fun ࿂࿂࿂࿂
|
|
11
11
|
࿂࿂࿂࿂ ࿂ ࿂ ࿂ ࿂ ࿂࿂࿂࿂
|
|
12
|
-
࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂`);for(const n of Object.values(E)){const t=Array.from(document.querySelectorAll(`[${n}]`)).filter(_n);if(t.length)for(let e=0;e<t.length;e++){const s=t[e];Ee(s,n)}}lr&&(P.observe(n=>{n.changes.keys.forEach((t,e)=>{t.action==="add"&&P.set(e,P.get(e))})}),vt.awareness.on("change",()=>cr()),lr=!1)}const Sn={setupElements:kn,globalData:P,elementHandlers:wt,setupPlayElement:ar};window.playhtml=Sn;function Ml(n){if(wt.has(n))return;wt.set(n,new Map),n!==E.CanPlay&&rr[n],P.get(n)||P.set(n,new ht);const t=P.get(n);t.observe(e=>{e.changes.keys.forEach((s,r)=>{const i=wt.get(n);if(s.action==="add"){const o=bn(r);if(!_n(o)){console.log(`Element ${r} not an HTML element. Ignoring.`);return}Ee(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 vl(n,t){const e=n.getAttribute(t);switch(t){case E.CanPlay:case E.CanMove:case E.CanSpin:case E.CanGrow:case E.CanToggle:case E.CanPost:return!0;case E.CanDuplicate:return e?(document.getElementById(e)||console.warn(`${E.CanDuplicate} element (${n.id}) duplicate element ("${e}") not found.`),!0):!1;default:return console.error(`Unhandled tag found in validation: ${t}`),!1}}function Ee(n,t){var l;if(!vl(n,t))return;if(!n.id){const c=n.getAttribute("selector-id");if(c){const a=or.get(c)??0;n.id=btoa(`${t}-${c}-${a}`),or.set(c,a+1)}}const e=El(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}Ml(t);const s=wt.get(t);if(s.has(e))return;const r=Ll(t,n);if(!Il(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=P.get(t),o=Al(n,t,r,e);s.set(e,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 ar(n){if(!_n(n)){console.log(`Element ${n.id} not an HTML element. Ignoring.`);return}for(const t of Object.values(E))n.hasAttribute(t)&&Ee(n,t)}v.getElementFromId=bn,v.playhtml=Sn,v.setupElements=kn,v.setupPlayElement=ar,v.setupPlayElementForTag=Ee,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
|
|
12
|
+
࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂`);for(const n of Object.values(E)){const t=Array.from(document.querySelectorAll(`[${n}]`)).filter(_n);if(t.length)for(let e=0;e<t.length;e++){const s=t[e];Ee(s,n)}}lr&&(P.observe(n=>{n.changes.keys.forEach((t,e)=>{t.action==="add"&&P.set(e,P.get(e))})}),vt.awareness.on("change",()=>cr()),lr=!1)}const Sn={setupElements:kn,globalData:P,elementHandlers:wt,setupPlayElement:ar};window.playhtml=Sn;function Ml(n){if(wt.has(n))return;wt.set(n,new Map),n!==E.CanPlay&&rr[n],P.get(n)||P.set(n,new ht);const t=P.get(n);t.observe(e=>{e.changes.keys.forEach((s,r)=>{const i=wt.get(n);if(s.action==="add"){const o=bn(r);if(!_n(o)){console.log(`Element ${r} not an HTML element. Ignoring.`);return}Ee(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 vl(n,t){const e=n.getAttribute(t);switch(t){case E.CanPlay:case E.CanMove:case E.CanSpin:case E.CanGrow:case E.CanToggle:case E.CanPost:return!0;case E.CanDuplicate:return e?(document.getElementById(e)||console.warn(`${E.CanDuplicate} element (${n.id}) duplicate element ("${e}") not found.`),!0):!1;default:return console.error(`Unhandled tag found in validation: ${t}`),!1}}function Ee(n,t){var l;if(!vl(n,t))return;if(!n.id){const c=n.getAttribute("selector-id");if(c){const a=or.get(c)??0;n.id=btoa(`${t}-${c}-${a}`),or.set(c,a+1)}else n.id=btoa(`${t}-${n.innerHTML}}`)}const e=El(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}Ml(t);const s=wt.get(t);if(s.has(e))return;const r=Ll(t,n);if(!Il(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=P.get(t),o=Al(n,t,r,e);s.set(e,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 ar(n){if(!_n(n)){console.log(`Element ${n.id} not an HTML element. Ignoring.`);return}for(const t of Object.values(E))n.hasAttribute(t)&&Ee(n,t)}v.getElementFromId=bn,v.playhtml=Sn,v.setupElements=kn,v.setupPlayElement=ar,v.setupPlayElementForTag=Ee,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,51 @@
|
|
|
1
|
+
export type ModifierKey = "ctrlKey" | "altKey" | "shiftKey" | "metaKey";
|
|
2
|
+
export declare const ModifierKeyToName: Record<ModifierKey, string>;
|
|
3
|
+
export interface ElementInitializer<T = any, U = any, V = any> {
|
|
4
|
+
defaultData: T | ((element: HTMLElement) => T);
|
|
5
|
+
defaultLocalData?: U | ((element: HTMLElement) => U);
|
|
6
|
+
myDefaultAwareness?: V | ((element: HTMLElement) => V);
|
|
7
|
+
updateElement: (data: ElementEventHandlerData<T, U, V>) => void;
|
|
8
|
+
updateElementAwareness?: (data: ElementAwarenessEventHandlerData<T, U, V>) => void;
|
|
9
|
+
onDrag?: (e: MouseEvent | TouchEvent, eventData: ElementEventHandlerData<T, U, V>) => void;
|
|
10
|
+
onClick?: (e: MouseEvent, eventData: ElementEventHandlerData<T, U, V>) => void;
|
|
11
|
+
onDragStart?: (e: MouseEvent | TouchEvent, eventData: ElementEventHandlerData<T, U, V>) => void;
|
|
12
|
+
additionalSetup?: (eventData: ElementSetupData<T, U, V>) => void;
|
|
13
|
+
resetShortcut?: ModifierKey;
|
|
14
|
+
debounceMs?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface ElementData<T = any, U = any, V = any> extends ElementInitializer<T> {
|
|
17
|
+
data?: T;
|
|
18
|
+
localData?: U;
|
|
19
|
+
awareness?: V;
|
|
20
|
+
element: HTMLElement;
|
|
21
|
+
onChange: (data: T) => void;
|
|
22
|
+
onAwarenessChange: (data: V) => void;
|
|
23
|
+
triggerAwarenessUpdate: () => void;
|
|
24
|
+
}
|
|
25
|
+
export interface ElementEventHandlerData<T = any, U = any, V = any> {
|
|
26
|
+
data: T;
|
|
27
|
+
localData: U;
|
|
28
|
+
awareness: V[];
|
|
29
|
+
element: HTMLElement;
|
|
30
|
+
setData: (data: T) => void;
|
|
31
|
+
setLocalData: (data: U) => void;
|
|
32
|
+
setLocalAwareness: (data: V) => void;
|
|
33
|
+
}
|
|
34
|
+
export interface ElementAwarenessEventHandlerData<T = any, U = any, V = any> extends ElementEventHandlerData<T, U, V> {
|
|
35
|
+
myAwareness?: V;
|
|
36
|
+
}
|
|
37
|
+
export interface ElementSetupData<T = any, U = any, V = any> {
|
|
38
|
+
getData: () => T;
|
|
39
|
+
getLocalData: () => U;
|
|
40
|
+
getAwareness: () => V[];
|
|
41
|
+
getElement: () => HTMLElement;
|
|
42
|
+
setData: (data: T) => void;
|
|
43
|
+
setLocalData: (data: U) => void;
|
|
44
|
+
setLocalAwareness: (data: V) => void;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Custom Capabilities data types
|
|
48
|
+
*/
|
|
1
49
|
export type MoveData = {
|
|
2
50
|
x: number;
|
|
3
51
|
y: number;
|
package/package.json
CHANGED
package/dist/tags.d.ts
DELETED
|
File without changes
|