f1ow 0.1.0

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.
Files changed (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +210 -0
  3. package/dist/assets/elbowWorker-CUBh1uET.js +1 -0
  4. package/dist/assets/exportWorker-hU9uNZXJ.js +8 -0
  5. package/dist/assets/syncWorker.worker-CnlpNZ3k.js +6 -0
  6. package/dist/components/Canvas/CanvasElement.d.ts +42 -0
  7. package/dist/components/Canvas/ConnectionPoints.d.ts +13 -0
  8. package/dist/components/Canvas/GridLayer.d.ts +13 -0
  9. package/dist/components/Canvas/LinearElementHandles.d.ts +17 -0
  10. package/dist/components/Canvas/SelectionBox.d.ts +12 -0
  11. package/dist/components/Canvas/SelectionTransformer.d.ts +7 -0
  12. package/dist/components/ContextMenu/ContextMenu.d.ts +23 -0
  13. package/dist/components/StylePanel/StylePanel.d.ts +7 -0
  14. package/dist/components/Toolbar/Toolbar.d.ts +9 -0
  15. package/dist/components/shapes/ArrowShape.d.ts +18 -0
  16. package/dist/components/shapes/DiamondShape.d.ts +24 -0
  17. package/dist/components/shapes/EllipseShape.d.ts +24 -0
  18. package/dist/components/shapes/FreeDrawShape.d.ts +24 -0
  19. package/dist/components/shapes/ImageShape.d.ts +24 -0
  20. package/dist/components/shapes/LineShape.d.ts +18 -0
  21. package/dist/components/shapes/RectangleShape.d.ts +24 -0
  22. package/dist/components/shapes/TextShape.d.ts +23 -0
  23. package/dist/constants/index.d.ts +44 -0
  24. package/dist/f1ow-canvas.js +37725 -0
  25. package/dist/f1ow-canvas.umd.cjs +371 -0
  26. package/dist/hooks/useEfficientZoom.d.ts +14 -0
  27. package/dist/hooks/useElbowShapeFingerprint.d.ts +21 -0
  28. package/dist/hooks/useElbowWorker.d.ts +23 -0
  29. package/dist/hooks/useKeyboardShortcuts.d.ts +7 -0
  30. package/dist/hooks/useProgressiveRender.d.ts +52 -0
  31. package/dist/hooks/useSpatialIndex.d.ts +9 -0
  32. package/dist/hooks/useViewportCulling.d.ts +13 -0
  33. package/dist/lib/FlowCanvas.d.ts +4 -0
  34. package/dist/lib/FlowCanvasProps.d.ts +154 -0
  35. package/dist/lib/index.d.ts +57 -0
  36. package/dist/store/useCanvasStore.d.ts +127 -0
  37. package/dist/store/useLinearEditStore.d.ts +25 -0
  38. package/dist/types/index.d.ts +257 -0
  39. package/dist/utils/alignment.d.ts +34 -0
  40. package/dist/utils/arrowheads.d.ts +20 -0
  41. package/dist/utils/camera.d.ts +63 -0
  42. package/dist/utils/clipboard.d.ts +4 -0
  43. package/dist/utils/clone.d.ts +29 -0
  44. package/dist/utils/connection.d.ts +122 -0
  45. package/dist/utils/crdtPrep.d.ts +97 -0
  46. package/dist/utils/curve.d.ts +51 -0
  47. package/dist/utils/elbow.d.ts +110 -0
  48. package/dist/utils/elbowWorkerManager.d.ts +53 -0
  49. package/dist/utils/export.d.ts +17 -0
  50. package/dist/utils/exportWorkerManager.d.ts +25 -0
  51. package/dist/utils/fractionalIndex.d.ts +51 -0
  52. package/dist/utils/geometry.d.ts +49 -0
  53. package/dist/utils/id.d.ts +1 -0
  54. package/dist/utils/image.d.ts +52 -0
  55. package/dist/utils/performance.d.ts +65 -0
  56. package/dist/utils/roughness.d.ts +104 -0
  57. package/dist/utils/spatialIndex.d.ts +109 -0
  58. package/dist/utils/spatialSoA.d.ts +82 -0
  59. package/dist/workers/elbowWorker.d.ts +18 -0
  60. package/dist/workers/exportWorker.d.ts +18 -0
  61. package/package.json +80 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 KhUmBaL!
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,210 @@
1
+ <p align="center">
2
+ <h1 align="center">f1ow-canvas</h1>
3
+ <p align="center">
4
+ Interactive canvas drawing toolkit built on <strong>KonvaJS</strong> — drop-in React component for any project.
5
+ </p>
6
+ </p>
7
+
8
+ <p align="center">
9
+ <a href="https://www.npmjs.com/package/f1ow-canvas"><img src="https://img.shields.io/npm/v/f1ow-canvas.svg" alt="npm version"></a>
10
+ <a href="https://www.npmjs.com/package/f1ow-canvas"><img src="https://img.shields.io/npm/dm/f1ow-canvas.svg" alt="npm downloads"></a>
11
+ <a href="https://github.com/nuumz/f1ow-canvas/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/f1ow-canvas.svg" alt="license"></a>
12
+ <a href="https://github.com/nuumz/f1ow-canvas"><img src="https://img.shields.io/badge/TypeScript-strict-blue.svg" alt="TypeScript"></a>
13
+ </p>
14
+
15
+ ---
16
+
17
+ ## Features
18
+
19
+ - **10 Drawing Tools** — Rectangle, Ellipse, Diamond, Line, Arrow, Free Draw, Text, Image, Eraser
20
+ - **Selection & Transform** — Click, drag, resize, rotate, multi-select
21
+ - **Smart Connectors** — Arrows/lines snap to shapes with auto-routing (sharp, curved, elbow)
22
+ - **11 Arrowhead Variants** — Triangle, circle, diamond, bar, crow's foot (ERD), and more
23
+ - **Pan & Zoom** — Hand tool, scroll-wheel, trackpad pinch, zoom-to-fit
24
+ - **Undo / Redo** — 100-step history
25
+ - **Rich Styling** — Stroke, fill, width, dash, opacity, roughness, fonts
26
+ - **Export** — PNG, SVG, JSON
27
+ - **Context Menu** — Built-in + extensible
28
+ - **Grouping & Locking** — Group/ungroup, lock/unlock
29
+ - **Real-Time Collaboration** — Optional CRDT via Yjs (experimental)
30
+ - **Fully Themeable** — Dark mode, custom colors, all via props
31
+ - **Zero CSS** — No external stylesheets required
32
+ - **TypeScript** — Full type safety with strict mode
33
+
34
+ ## Installation
35
+
36
+ ```bash
37
+ npm install f1ow-canvas
38
+ ```
39
+
40
+ > **Peer dependencies:** `react` and `react-dom` ≥ 17
41
+
42
+ ## Quick Start
43
+
44
+ ```tsx
45
+ import { FlowCanvas } from "f1ow-canvas";
46
+
47
+ function App() {
48
+ return (
49
+ <div style={{ width: "100vw", height: "100vh" }}>
50
+ <FlowCanvas onChange={(elements) => console.log(elements)} />
51
+ </div>
52
+ );
53
+ }
54
+ ```
55
+
56
+ That's it — you get a full-featured canvas editor with toolbar, style panel, keyboard shortcuts, and grid out of the box.
57
+
58
+ ## Props
59
+
60
+ | Prop | Type | Default | Description |
61
+ | --- | --- | --- | --- |
62
+ | `initialElements` | `CanvasElement[]` | `[]` | Preloaded elements (uncontrolled) |
63
+ | `elements` | `CanvasElement[]` | — | Controlled elements |
64
+ | `onChange` | `(elements) => void` | — | Elements changed |
65
+ | `onSelectionChange` | `(ids) => void` | — | Selection changed |
66
+ | `onElementCreate` | `(element) => void` | — | Element created |
67
+ | `onElementDelete` | `(ids) => void` | — | Elements deleted |
68
+ | `onElementDoubleClick` | `(id, element) => boolean` | — | Return `true` to prevent default |
69
+ | `width` / `height` | `number \| string` | `'100%'` | Canvas dimensions |
70
+ | `tools` | `ToolType[]` | all | Visible tools in toolbar |
71
+ | `defaultStyle` | `Partial<ElementStyle>` | — | Default style for new elements |
72
+ | `showToolbar` | `boolean` | `true` | Show toolbar |
73
+ | `showStylePanel` | `boolean` | `true` | Show style panel |
74
+ | `showStatusBar` | `boolean` | `true` | Show status bar |
75
+ | `showGrid` | `boolean` | `true` | Show grid |
76
+ | `enableShortcuts` | `boolean` | `true` | Enable keyboard shortcuts |
77
+ | `theme` | `Partial<FlowCanvasTheme>` | — | [Theme customization](#theming) |
78
+ | `readOnly` | `boolean` | `false` | Disable editing |
79
+ | `className` | `string` | — | Root container CSS class |
80
+ | `contextMenuItems` | `ContextMenuItem[]` or `(ctx) => ContextMenuItem[]` | — | Extra context menu items |
81
+ | `renderContextMenu` | `(ctx) => ReactNode` | — | Replace built-in context menu |
82
+ | `collaboration` | `CollaborationConfig` | — | Enable real-time collaboration |
83
+
84
+ ## Ref API
85
+
86
+ Control the canvas programmatically via `ref`:
87
+
88
+ ```tsx
89
+ import { useRef } from "react";
90
+ import type { FlowCanvasRef } from "f1ow-canvas";
91
+
92
+ const ref = useRef<FlowCanvasRef>(null);
93
+
94
+ <FlowCanvas ref={ref} />;
95
+ ```
96
+
97
+ | Method | Returns | Description |
98
+ | --- | --- | --- |
99
+ | `getElements()` | `CanvasElement[]` | Get all elements |
100
+ | `setElements(elements)` | — | Replace all elements |
101
+ | `addElement(element)` | — | Add one element |
102
+ | `deleteElements(ids)` | — | Delete by IDs |
103
+ | `getSelectedIds()` | `string[]` | Get selected IDs |
104
+ | `setSelectedIds(ids)` | — | Set selection |
105
+ | `clearSelection()` | — | Deselect all |
106
+ | `setActiveTool(tool)` | — | Switch tool |
107
+ | `undo()` / `redo()` | — | History navigation |
108
+ | `zoomTo(scale)` | — | Set zoom level |
109
+ | `resetView()` | — | Reset pan & zoom |
110
+ | `scrollToElement(id, opts?)` | — | Center on element |
111
+ | `zoomToFit(ids?, opts?)` | — | Fit elements in view |
112
+ | `exportPNG()` | `string \| null` | Export as data URL |
113
+ | `exportSVG()` | `string` | Export as SVG string |
114
+ | `exportJSON()` | `string` | Export as JSON string |
115
+ | `importJSON(json)` | — | Load from JSON |
116
+ | `getStage()` | `Konva.Stage` | Raw Konva stage access |
117
+
118
+ ## Keyboard Shortcuts
119
+
120
+ `⌘` = Cmd (Mac) / Ctrl (Windows/Linux)
121
+
122
+ | Tool Shortcuts | | Action Shortcuts | |
123
+ | --- | --- | --- | --- |
124
+ | `V` Select | `A` Arrow | `⌘Z` Undo | `⌘⇧1` Zoom to fit |
125
+ | `H` Hand | `P` Pencil | `⌘⇧Z` Redo | `⌘⇧2` Zoom to selection |
126
+ | `R` Rectangle | `T` Text | `⌘D` Duplicate | `⌘G` Group |
127
+ | `O` Ellipse | `I` Image | `⌘A` Select all | `⌘⇧G` Ungroup |
128
+ | `D` Diamond | `E` Eraser | `Del` Delete | `⌘⇧L` Lock toggle |
129
+ | `L` Line | `G` Grid | `⌘+/-/0` Zoom | `⌘]/[` Layer order |
130
+
131
+ ## Theming
132
+
133
+ ```tsx
134
+ <FlowCanvas
135
+ theme={{
136
+ canvasBackground: "#1a1a2e",
137
+ gridColor: "#2a2a4a",
138
+ selectionColor: "#7c3aed",
139
+ toolbarBg: "rgba(26, 26, 46, 0.95)",
140
+ toolbarBorder: "#2a2a4a",
141
+ panelBg: "rgba(26, 26, 46, 0.95)",
142
+ activeToolColor: "#7c3aed",
143
+ textColor: "#e5e7eb",
144
+ mutedTextColor: "#6b7280",
145
+ }}
146
+ />
147
+ ```
148
+
149
+ All properties are optional — only override what you need.
150
+
151
+ ## Context Menu
152
+
153
+ Append custom items or fully replace the built-in menu:
154
+
155
+ ```tsx
156
+ // Add items
157
+ <FlowCanvas
158
+ contextMenuItems={[
159
+ { label: "My Action", action: (ctx) => console.log(ctx.selectedIds) },
160
+ ]}
161
+ />
162
+
163
+ // Full replacement
164
+ <FlowCanvas
165
+ renderContextMenu={(ctx) => <MyCustomMenu {...ctx} />}
166
+ />
167
+ ```
168
+
169
+ ## Collaboration (Experimental)
170
+
171
+ ```tsx
172
+ <FlowCanvas
173
+ collaboration={{
174
+ roomId: "my-room",
175
+ wsUrl: "wss://my-yjs-server.example.com",
176
+ user: { id: "user-1", name: "Alice", color: "#e03131" },
177
+ }}
178
+ />
179
+ ```
180
+
181
+ Provides CRDT-based real-time sync with cursor presence overlay. Requires a [Yjs WebSocket server](https://github.com/yjs/y-websocket).
182
+
183
+ ## Element Types
184
+
185
+ `CanvasElement` is a discriminated union of 8 types:
186
+
187
+ **Shapes** — `rectangle`, `ellipse`, `diamond`
188
+ **Connectors** — `line`, `arrow` (with bindings, routing, arrowheads)
189
+ **Content** — `text`, `image`, `freedraw`
190
+
191
+ All elements share: `id`, `x`, `y`, `width`, `height`, `rotation`, `style`, `isLocked`, `isVisible`, `boundElements`, `groupIds`.
192
+
193
+ > Full type definitions are bundled in the package `.d.ts` files.
194
+
195
+ ## Development
196
+
197
+ ```bash
198
+ pnpm install # Install dependencies
199
+ pnpm dev # Dev server (demo app)
200
+ pnpm build:lib # Build library → dist/
201
+ pnpm typecheck # Type check (strict)
202
+ ```
203
+
204
+ ## Browser Support
205
+
206
+ Chrome/Edge ≥ 80 · Firefox ≥ 78 · Safari ≥ 14
207
+
208
+ ## License
209
+
210
+ [MIT](LICENSE) © [KhUmBaL!](https://github.com/nuumz)
@@ -0,0 +1 @@
1
+ var bt=Object.defineProperty;var St=(_,A,R)=>A in _?bt(_,A,{enumerable:!0,configurable:!0,writable:!0,value:R}):_[A]=R;var $=(_,A,R)=>St(_,typeof A!="symbol"?A+"":A,R);(function(){"use strict";function T(t){switch(t){case"up":return{x:0,y:-1};case"down":return{x:0,y:1};case"left":return{x:-1,y:0};case"right":return{x:1,y:0}}}function X(t){return t==="up"||t==="down"}function F(t,n){const e=t.x+t.width/2,o=t.y+t.height/2,s=n.x-e,c=n.y-o,i=(t.width||1)/2,h=(t.height||1)/2,u=Math.abs(s)/i,r=Math.abs(c)/h;return u>r*3?s>=0?"right":"left":(r>u*3,c>=0?"down":"up")}function L(t){const[n,e]=t,o=e,s=1-e,c=n,i=1-n,h=Math.min(o,s,c,i);return h===o?"up":h===s?"down":h===c?"left":"right"}function Y(t,n){const e=n.x-t.x,o=n.y-t.y;return Math.abs(e)>=Math.abs(o)?e>=0?"right":"left":o>=0?"down":"up"}function j(t,n){const e=t.x+t.width/2,o=t.y+t.height/2,s=n.x-e,c=n.y-o,i=t.width/2||1,h=t.height/2||1,u=s/i,r=c/h;return Math.abs(u)>=Math.abs(r)?s>=0?"right":"left":c>=0?"down":"up"}function S(t){return t.left+t.width}function I(t){return t.top+t.height}function Z(t,n){return n.x>t.left&&n.x<S(t)&&n.y>t.top&&n.y<I(t)}function P(t,n,e){return{left:t.left-n,top:t.top-e,width:t.width+n*2,height:t.height+e*2}}function H(t,n,e){const o=Math.min(n,25),s=e==="left"?o:n,c=e==="right"?o:n,i=e==="up"?o:n,h=e==="down"?o:n;return{left:t.left-s,top:t.top-i,width:t.width+s+c,height:t.height+i+h}}function K(t,n,e){const o=new Set(e),s=Math.min(n,25),c=o.has("left")?s:n,i=o.has("right")?s:n,h=o.has("up")?s:n,u=o.has("down")?s:n;return{left:t.left-c,top:t.top-h,width:t.width+c+i,height:t.height+h+u}}function B(t,n){const e=Math.min(t.left,n.left),o=Math.min(t.top,n.top),s=Math.max(S(t),S(n)),c=Math.max(I(t),I(n));return{left:e,top:o,width:s-e,height:c-o}}function v(t){return{left:t.x,top:t.y,width:t.width,height:t.height}}function O(t){const n=t.rotation||0;if(n===0)return{x:t.x,y:t.y,width:t.width,height:t.height};const e=t.x+t.width/2,o=t.y+t.height/2,s=t.width/2,c=t.height/2,i=n*Math.PI/180,h=Math.cos(i),u=Math.sin(i),r=[{x:-s,y:-c},{x:s,y:-c},{x:s,y:c},{x:-s,y:c}].map(a=>({x:e+a.x*h-a.y*u,y:o+a.x*u+a.y*h}));let l=1/0,y=1/0,f=-1/0,p=-1/0;for(const a of r)a.x<l&&(l=a.x),a.y<y&&(y=a.y),a.x>f&&(f=a.x),a.y>p&&(p=a.y);return{x:l,y,width:f-l,height:p-y}}function W(t){switch(t){case"left":return"right";case"right":return"left";case"up":return"down";case"down":return"up"}}function tt(t,n){return n.x<t.x?"left":n.x>t.x?"right":n.y<t.y?"up":n.y>t.y?"down":null}function nt(t,n){return t===null||n===null?!1:(t==="left"||t==="right"?"h":"v")!==(n==="left"||n==="right"?"h":"v")}class et{constructor(n){$(this,"adjacent",new Map);this.pt=n}}class ot{constructor(){$(this,"idx",{})}add(n){const e=String(n.x),o=String(n.y);e in this.idx||(this.idx[e]={}),o in this.idx[e]||(this.idx[e][o]=new et(n))}get(n){var s;const e=String(n.x),o=String(n.y);return((s=this.idx[e])==null?void 0:s[o])??null}has(n){return this.get(n)!==null}connect(n,e){const o=this.get(n),s=this.get(e);if(!o||!s)return;const c=Math.abs(e.x-n.x)+Math.abs(e.y-n.y);o.adjacent.set(s,c),s.adjacent.set(o,c)}}class st{constructor(){$(this,"data",[])}get size(){return this.data.length}push(n,e){this.data.push({item:n,priority:e}),this.bubbleUp(this.data.length-1)}pop(){if(this.data.length===0)return;const n=this.data[0],e=this.data.pop();return this.data.length>0&&(this.data[0]=e,this.sinkDown(0)),n.item}bubbleUp(n){for(;n>0;){const e=n-1>>1;if(this.data[e].priority<=this.data[n].priority)break;[this.data[e],this.data[n]]=[this.data[n],this.data[e]],n=e}}sinkDown(n){const e=this.data.length;for(;;){let o=n;const s=2*n+1,c=2*n+2;if(s<e&&this.data[s].priority<this.data[o].priority&&(o=s),c<e&&this.data[c].priority<this.data[o].priority&&(o=c),o===n)break;[this.data[o],this.data[n]]=[this.data[n],this.data[o]],n=o}}}function ct(t,n,e){const o=t.get(n),s=t.get(e);if(!o||!s)return null;const c=f=>Math.abs(f.x-e.x)+Math.abs(f.y-e.y),i=(f,p)=>`${f.pt.x},${f.pt.y},${p??"n"}`,h=new Map,u=new Map,r=new st,l={node:o,dir:null,g:0},y=i(o,null);for(h.set(y,0),u.set(y,null),r.push(l,c(o.pt));r.size>0;){const f=r.pop(),p=i(f.node,f.dir);if(!(f.g>(h.get(p)??1/0))){if(f.node===s){const a=[];let d=f;for(;d;){a.push(d.node.pt);const w=i(d.node,d.dir);if(d=u.get(w),d==null)break}return a[a.length-1]!==o.pt&&a.push(o.pt),a.reverse(),a}for(const[a,d]of f.node.adjacent){const w=tt(f.node.pt,a.pt);if(w===null)continue;const g=f.dir!==null&&w===W(f.dir),E=nt(f.dir,w),G=g?1e4*3:E?1e4:0,m=f.g+d+G,N=i(a,w);m<(h.get(N)??1/0)&&(h.set(N,m),u.set(N,f),r.push({node:a,dir:w,g:m},m+c(a.pt)))}}}return null}function it(t){const n=new Map,e=[];for(const o of t){let s=n.get(o.x);s||(s=new Set,n.set(o.x,s)),s.has(o.y)||(s.add(o.y),e.push(o))}return e}function ht(t,n,e,o){const s=e.left,c=S(e),i=e.top,h=I(e),u=[...new Set([s,...t.filter(f=>f>=s&&f<=c),c])].sort((f,p)=>f-p),r=[...new Set([i,...n.filter(f=>f>=i&&f<=h),h])].sort((f,p)=>f-p),l=f=>o.some(p=>Z(p,f)),y=[];for(const f of r)for(const p of u){const a={x:p,y:f};l(a)||y.push(a)}return y}function z(t,n,e){if(t.y===n.y){const o=t.y,s=Math.min(t.x,n.x),c=Math.max(t.x,n.x);for(const i of e)if(i.top<o&&o<I(i)&&i.left<c&&S(i)>s)return!0}else if(t.x===n.x){const o=t.x,s=Math.min(t.y,n.y),c=Math.max(t.y,n.y);for(const i of e)if(i.left<o&&o<S(i)&&i.top<c&&I(i)>s)return!0}return!1}function ut(t,n){const e=new ot,o=new Set,s=new Set;for(const h of t)e.add(h),o.add(h.x),s.add(h.y);const c=[...o].sort((h,u)=>h-u),i=[...s].sort((h,u)=>h-u);for(let h=0;h<i.length;h++)for(let u=0;u<c.length;u++){const r={x:c[u],y:i[h]};if(e.has(r)){for(let l=u-1;l>=0;l--){const y={x:c[l],y:i[h]};if(e.has(y)){z(y,r,n)||e.connect(y,r);break}}for(let l=h-1;l>=0;l--){const y={x:c[u],y:i[l]};if(e.has(y)){z(y,r,n)||e.connect(y,r);break}}}}return e}function V(t){if(t.length<=2)return t;const n=[t[0]];for(let e=1;e<t.length-1;e++){const o=t[e-1],s=t[e],c=t[e+1],i=o.x===s.x&&s.x===c.x,h=o.y===s.y&&s.y===c.y;i||h||o.x===s.x&&o.y===s.y||n.push(s)}return n.push(t[t.length-1]),n}function D(t){if(t.length<=2)return 0;let n=0;for(let e=1;e<t.length-1;e++){const o=t[e-1],s=t[e],c=t[e+1],i=o.x===s.x&&s.x===c.x,h=o.y===s.y&&s.y===c.y;!i&&!h&&n++}return n}function q(t){let n=0;for(let e=1;e<t.length;e++)n+=Math.abs(t[e].x-t[e-1].x)+Math.abs(t[e].y-t[e-1].y);return n}function ft(t){let n=t[0],e=D(n),o=q(n);for(let s=1;s<t.length;s++){const c=D(t[s]),i=q(t[s]);(c<e||c===e&&i<o)&&(n=t[s],e=c,o=i)}return n}function C(t,n,e,o,s,c){let i={left:Math.min(t.x,n.x),top:Math.min(t.y,n.y),width:Math.abs(n.x-t.x)||1,height:Math.abs(n.y-t.y)||1};for(const g of s)i=B(i,g);i=P(i,40,40);const h=[],u=[];for(const g of s)h.push(g.left,S(g)),u.push(g.top,I(g)),h.push(g.left+g.width/2),u.push(g.top+g.height/2);h.push(t.x,n.x),u.push(t.y,n.y);const r=T(e),l=T(o);let y={x:t.x+r.x*c,y:t.y+r.y*c},f={x:n.x+l.x*c,y:n.y+l.y*c};y=J(y,e,s),f=J(f,o,s),h.push(y.x,f.x),u.push(y.y,f.y),h.push((t.x+n.x)/2),u.push((t.y+n.y)/2);const p=ht(h,u,i,s),a=it([y,f,...p]),d=ut(a,s),w=ct(d,y,f);if(w){const g=[t,...w,n];return V(g)}return null}function rt(t,n,e,o,s,c,i,h){if(t.x===n.x&&t.y===n.y)return[t,n];const u=s?v(s):{left:t.x,top:t.y,width:0,height:0},r=c?v(c):{left:n.x,top:n.y,width:0,height:0},l=20,y=Math.max(36,i??0),f=(h??[]).map(M=>P(v(M),l,l)),p=s?H(u,l,e):P(u,l,l),a=c?H(r,l,o):P(r,l,l),d=[e],w=[o];let g=!1;if(s){const M=j(s,n);M!==e&&(d.push(M),g=!0)}if(c){const M=j(c,t);M!==o&&(w.push(M),g=!0)}const E=s?K(u,l,d):P(u,l,l),G=c?K(r,l,w):P(r,l,l),m=[],N=C(t,n,e,o,[p,a,...f],y);if(N&&m.push(N),g){const M=C(t,n,e,o,[E,G,...f],y);M&&m.push(M)}if(m.length>0)return ft(m);if(f.length>0){const M=C(t,n,e,o,[p,a],y);if(M)return M}return V(lt(t,n,e,o,y))}function J(t,n,e){let{x:o,y:s}=t;for(let c=0;c<e.length;c++){let i=!0;for(const h of e)if(!(o<=h.left||o>=S(h)||s<=h.top||s>=I(h)))switch(i=!1,n){case"left":o=h.left-1;break;case"right":o=S(h)+1;break;case"up":s=h.top-1;break;case"down":s=I(h)+1;break}if(i)break}return{x:o,y:s}}function lt(t,n,e,o,s){const c=Math.max(s,20),i=T(e),h=T(o),u={x:t.x+i.x*c,y:t.y+i.y*c},r={x:n.x+h.x*c,y:n.y+h.y*c};if(X(e)===X(o))if(X(e)){const l=(u.y+r.y)/2;return[t,u,{x:u.x,y:l},{x:r.x,y:l},r,n]}else{const l=(u.x+r.x)/2;return[t,u,{x:l,y:u.y},{x:l,y:r.y},r,n]}else return X(e)?[t,u,{x:u.x,y:r.y},r,n]:[t,u,{x:r.x,y:u.y},r,n]}const at=new Set(["rectangle","ellipse","diamond","text","image"]),yt=256,k=new Map;function xt(t,n,e,o,s,c,i,h){const u=r=>Math.round(r*2)/2;return[u(t.x),u(t.y),u(n.x),u(n.y),e,o,s?`${u(s.x)},${u(s.y)},${u(s.width)},${u(s.height)}`:"n",c?`${u(c.x)},${u(c.y)},${u(c.width)},${u(c.height)}`:"n",i,h??0].join("|")}function pt(t,n,e,o,s,c){const i=new Map(s.map(x=>[x.id,x])),h=x=>!x.isPrecise||x.fixedPoint[0]===.5&&x.fixedPoint[1]===.5;let u;if(e)if(h(e)){const x=i.get(e.elementId);u=x?F(x,n):Y(t,n)}else u=L(e.fixedPoint);else u=Y(t,n);let r;if(o)if(h(o)){const x=i.get(o.elementId);r=x?F(x,t):Y(n,t)}else r=L(o.fixedPoint);else r=Y(n,t);const l=e?i.get(e.elementId)??null:null,y=o?i.get(o.elementId)??null:null,f=l?O(l):null,p=y?O(y):null,a=e==null?void 0:e.elementId,d=o==null?void 0:o.elementId,w=[],g=[],E=x=>Math.round(x*2)/2;for(const x of s){if(!at.has(x.type)||x.id===a||x.id===d||!x.isVisible)continue;const b=O(x),dt=Math.min(t.x,n.x)-120,wt=Math.max(t.x,n.x)+120,Mt=Math.min(t.y,n.y)-120,mt=Math.max(t.y,n.y)+120;b.x+b.width<dt||b.x>wt||b.y+b.height<Mt||b.y>mt||(w.push(b),g.push(`${x.id}:${E(b.x)},${E(b.y)},${E(b.width)},${E(b.height)}`))}g.sort();const G=g.join(";"),m=xt(t,n,u,r,f,p,G,c),N=k.get(m);if(N)return N;const M=rt(t,n,u,r,f,p,c,w),U=[];for(const x of M)U.push(x.x-t.x,x.y-t.y);if(k.size>=yt){const x=k.keys().next().value;x!==void 0&&k.delete(x)}return k.set(m,U),U}function gt(t){if(t.length<=4)return t;const n=[t[0],t[1]];for(let e=2;e<t.length-2;e+=2){const o=n[n.length-2],s=n[n.length-1],c=t[e],i=t[e+1],h=t[e+2],u=t[e+3];s===i&&i===u||o===c&&c===h||o===c&&s===i||n.push(c,i)}return n.push(t[t.length-2],t[t.length-1]),n}let Q=[];function At(t){return t}self.onmessage=t=>{const n=t.data;if(n.type==="updateElements"){Q=n.elements;return}if(n.type==="computeRoute"){const{requestId:e,params:o}=n;try{const s=pt(o.startWorld,o.endWorld,o.startBinding,o.endBinding,Q,o.minStubLength),c=gt(s);self.postMessage({type:"routeResult",requestId:e,points:c})}catch{self.postMessage({type:"routeResult",requestId:e,points:[0,0,o.endWorld.x-o.startWorld.x,o.endWorld.y-o.startWorld.y]})}}}})();
@@ -0,0 +1,8 @@
1
+ (function(){"use strict";function S(t,n){return[t/2,0,t,n/2,t/2,n,0,n/2]}function b(t,n){switch(t){case"dashed":return[n*4,n*4];case"dotted":return[n,n*2];case"solid":default:return[]}}const w=.2;function v(t,n,y=w){const s=(t.x+n.x)/2,e=(t.y+n.y)/2,i=n.x-t.x,x=n.y-t.y,o=Math.sqrt(i*i+x*x);if(o===0)return{x:s,y:e};const $=-x/o,r=i/o,c=o*y;return{x:s+$*c,y:e+r*c}}function j(t){return Math.max(10,t*4)}const l=20;function h(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function u(t,n){const y=b(t,n);return y.length>0?y.join(","):"none"}function m(t){const{strokeColor:n,fillColor:y,strokeWidth:s,opacity:e,strokeStyle:i}=t.style,x=u(i,s),o=[`fill="${h(y==="transparent"?"none":y)}"`,`stroke="${h(n)}"`,`stroke-width="${s}"`,`opacity="${e}"`];return x!=="none"&&o.push(`stroke-dasharray="${x}"`),o.join(" ")}function g(t,n,y,s){return n.rotation?`<g transform="rotate(${n.rotation} ${y} ${s})">${t}</g>`:t}function C(t){const{x:n,y,width:s,height:e,cornerRadius:i}=t,x=i?` rx="${i}" ry="${i}"`:"",o=`<rect x="${n}" y="${y}" width="${s}" height="${e}"${x} ${m(t)} />`;return g(o,t,n+s/2,y+e/2)}function M(t){const n=t.x+t.width/2,y=t.y+t.height/2,s=`<ellipse cx="${n}" cy="${y}" rx="${t.width/2}" ry="${t.height/2}" ${m(t)} />`;return g(s,t,n,y)}function I(t){const n=S(t.width,t.height),y=[];for(let e=0;e<n.length;e+=2)y.push(`${t.x+n[e]},${t.y+n[e+1]}`);const s=`<polygon points="${y.join(" ")}" ${m(t)} />`;return g(s,t,t.x+t.width/2,t.y+t.height/2)}function W(t){const y=t.points.map((e,i)=>`${i%2===0?t.x+e:t.y+e}`),s=[];for(let e=0;e<y.length;e+=2)s.push(`${y[e]},${y[e+1]}`);return`<polyline points="${s.join(" ")}" fill="none" stroke="${h(t.style.strokeColor)}" stroke-width="${t.style.strokeWidth}" opacity="${t.style.opacity}" stroke-linecap="round" stroke-linejoin="round"${u(t.style.strokeStyle,t.style.strokeWidth)!=="none"?` stroke-dasharray="${u(t.style.strokeStyle,t.style.strokeWidth)}"`:""} />`}function A(t){const n=t.points,y={x:n[0],y:n[1]},s={x:n[n.length-2],y:n[n.length-1]},e=v(y,s,t.curvature??w),i=t.x+y.x,x=t.y+y.y,o=t.x+e.x,$=t.y+e.y,r=t.x+s.x,c=t.y+s.y;return`<path d="M ${i} ${x} Q ${o} ${$} ${r} ${c}" fill="none" stroke="${h(t.style.strokeColor)}" stroke-width="${t.style.strokeWidth}" opacity="${t.style.opacity}" stroke-linecap="round"${u(t.style.strokeStyle,t.style.strokeWidth)!=="none"?` stroke-dasharray="${u(t.style.strokeStyle,t.style.strokeWidth)}"`:""} />`}function _(t,n){const y=t.x-n.x,s=t.y-n.y,e=Math.sqrt(y*y+s*s)||1;return{x:y/e,y:s/e}}function R(t){return{x:-t.y,y:t.x}}function p(t,n,y,s,e,i){const x=_(n,y),o=R(x),$=s*.45;switch(t){case"arrow":{const r={x:n.x-x.x*s+o.x*$,y:n.y-x.y*s+o.y*$},c={x:n.x-x.x*s-o.x*$,y:n.y-x.y*s-o.y*$};return`<polyline points="${r.x},${r.y} ${n.x},${n.y} ${c.x},${c.y}" fill="none" stroke="${h(e)}" stroke-width="${i}" stroke-linecap="round" stroke-linejoin="round" />`}case"triangle":{const r={x:n.x-x.x*s+o.x*$,y:n.y-x.y*s+o.y*$},c={x:n.x-x.x*s-o.x*$,y:n.y-x.y*s-o.y*$};return`<polygon points="${n.x},${n.y} ${r.x},${r.y} ${c.x},${c.y}" fill="${h(e)}" stroke="${h(e)}" stroke-width="${i}" />`}case"triangle_outline":{const r={x:n.x-x.x*s+o.x*$,y:n.y-x.y*s+o.y*$},c={x:n.x-x.x*s-o.x*$,y:n.y-x.y*s-o.y*$};return`<polygon points="${n.x},${n.y} ${r.x},${r.y} ${c.x},${c.y}" fill="#ffffff" stroke="${h(e)}" stroke-width="${i}" />`}case"circle":{const r=s*.35,c=n.x-x.x*r,a=n.y-x.y*r;return`<circle cx="${c}" cy="${a}" r="${r}" fill="${h(e)}" stroke="${h(e)}" stroke-width="${i}" />`}case"circle_outline":{const r=s*.35,c=n.x-x.x*r,a=n.y-x.y*r;return`<circle cx="${c}" cy="${a}" r="${r}" fill="#ffffff" stroke="${h(e)}" stroke-width="${i}" />`}case"bar":{const r=$*1.2;return`<line x1="${n.x+o.x*r}" y1="${n.y+o.y*r}" x2="${n.x-o.x*r}" y2="${n.y-o.y*r}" stroke="${h(e)}" stroke-width="${i}" />`}case"diamond":case"diamond_outline":{const r=$*.7,c=s*.55,a={x:n.x-x.x*c,y:n.y-x.y*c},f=t==="diamond"?h(e):"#ffffff";return`<polygon points="${n.x},${n.y} ${a.x+o.x*r},${a.y+o.y*r} ${a.x-x.x*c},${a.y-x.y*c} ${a.x-o.x*r},${a.y-o.y*r}" fill="${f}" stroke="${h(e)}" stroke-width="${i}" />`}case"crowfoot_one":{const r=$*1,c=s*.25,a={x:n.x-x.x*c,y:n.y-x.y*c};return[`<line x1="${n.x+o.x*r}" y1="${n.y+o.y*r}" x2="${n.x-o.x*r}" y2="${n.y-o.y*r}" stroke="${h(e)}" stroke-width="${i}" />`,`<line x1="${a.x+o.x*r}" y1="${a.y+o.y*r}" x2="${a.x-o.x*r}" y2="${a.y-o.y*r}" stroke="${h(e)}" stroke-width="${i}" />`].join(`
2
+ `)}case"crowfoot_many":{const r=$*1,c=s*.6,a={x:n.x-x.x*c,y:n.y-x.y*c};return[`<line x1="${n.x+o.x*r}" y1="${n.y+o.y*r}" x2="${n.x-o.x*r}" y2="${n.y-o.y*r}" stroke="${h(e)}" stroke-width="${i}" />`,`<polyline points="${n.x+o.x*r},${n.y+o.y*r} ${a.x},${a.y} ${n.x-o.x*r},${n.y-o.y*r}" fill="none" stroke="${h(e)}" stroke-width="${i}" />`].join(`
3
+ `)}case"crowfoot_one_or_many":{const r=$*1,c=s*.6,a=s*.25,f={x:n.x-x.x*a,y:n.y-x.y*a},d={x:n.x-x.x*c,y:n.y-x.y*c};return[`<line x1="${n.x+o.x*r}" y1="${n.y+o.y*r}" x2="${n.x-o.x*r}" y2="${n.y-o.y*r}" stroke="${h(e)}" stroke-width="${i}" />`,`<line x1="${f.x+o.x*r}" y1="${f.y+o.y*r}" x2="${f.x-o.x*r}" y2="${f.y-o.y*r}" stroke="${h(e)}" stroke-width="${i}" />`,`<polyline points="${n.x+o.x*r},${n.y+o.y*r} ${d.x},${d.y} ${n.x-o.x*r},${n.y-o.y*r}" fill="none" stroke="${h(e)}" stroke-width="${i}" />`].join(`
4
+ `)}default:return""}}function q(t){const n=[],y=t.lineType==="curved";if(n.push(y?A(t):W(t)),t.type==="arrow"){const s=t,e=s.startArrowhead??(s.startArrow?"arrow":null),i=s.endArrowhead??(s.endArrow?"arrow":null),x=j(t.style.strokeWidth),o=t.points;if(y){const $={x:o[0],y:o[1]},r={x:o[o.length-2],y:o[o.length-1]},c=v($,r,s.curvature??w),a={x:t.x+$.x,y:t.y+$.y},f={x:t.x+r.x,y:t.y+r.y},d={x:t.x+c.x*.1+$.x*.9,y:t.y+c.y*.1+$.y*.9},k={x:t.x+c.x*.1+r.x*.9,y:t.y+c.y*.1+r.y*.9};e&&n.push(p(e,a,d,x,t.style.strokeColor,t.style.strokeWidth)),i&&n.push(p(i,f,k,x,t.style.strokeColor,t.style.strokeWidth))}else{if(e&&o.length>=4){const $={x:t.x+o[0],y:t.y+o[1]},r={x:t.x+o[2],y:t.y+o[3]};n.push(p(e,$,r,x,t.style.strokeColor,t.style.strokeWidth))}if(i&&o.length>=4){const $={x:t.x+o[o.length-2],y:t.y+o[o.length-1]},r={x:t.x+o[o.length-4],y:t.y+o[o.length-3]};n.push(p(i,$,r,x,t.style.strokeColor,t.style.strokeWidth))}}}return n.join(`
5
+ `)}function D(t){if(t.points.length<4)return"";const n=[];for(let y=0;y<t.points.length;y+=2)n.push(`${t.x+t.points[y]},${t.y+t.points[y+1]}`);return`<polyline points="${n.join(" ")}" fill="none" stroke="${h(t.style.strokeColor)}" stroke-width="${t.style.strokeWidth}" opacity="${t.style.opacity}" stroke-linecap="round" stroke-linejoin="round" />`}function H(t){if(!t.text)return"";const{style:n,x:y,y:s,text:e,textAlign:i}=t,x=e.split(`
6
+ `),o=n.fontSize*1.18;let $="start",r=0;i==="center"?($="middle",r=t.width/2):i==="right"&&($="end",r=t.width);const c=x.map((f,d)=>`<tspan x="${y+r}" dy="${d===0?0:o}">${h(f)}</tspan>`).join(""),a=[`font-family="${h(n.fontFamily)}"`,`font-size="${n.fontSize}"`,`fill="${h(n.strokeColor)}"`,`opacity="${n.opacity}"`,`text-anchor="${$}"`];return`<text x="${y+r}" y="${s+n.fontSize}" ${a.join(" ")}>${c}</text>`}function E(t){const{x:n,y,width:s,height:e,src:i,cornerRadius:x,style:o}=t,$=[],r=x>0?`clip-${t.id}`:"";r&&$.push(`<defs><clipPath id="${r}"><rect x="${n}" y="${y}" width="${s}" height="${e}" rx="${x}" ry="${x}" /></clipPath></defs>`);const c=`<image href="${h(i)}" x="${n}" y="${y}" width="${s}" height="${e}" opacity="${o.opacity}" preserveAspectRatio="none"${r?` clip-path="url(#${r})"`:""} />`;let a="";if(o.strokeWidth>0&&o.strokeColor!=="transparent"){const d=x?` rx="${x}" ry="${x}"`:"";a=`<rect x="${n}" y="${y}" width="${s}" height="${e}"${d} fill="none" stroke="${h(o.strokeColor)}" stroke-width="${o.strokeWidth}" opacity="${o.opacity}" />`}const f=$.join("")+c+a;return g(f,t,n+s/2,y+e/2)}function P(t){switch(t.type){case"rectangle":return C(t);case"ellipse":return M(t);case"diamond":return I(t);case"line":case"arrow":return q(t);case"freedraw":return D(t);case"text":return H(t);case"image":return E(t);default:return""}}function T(t){if(t.length===0)return'<svg xmlns="http://www.w3.org/2000/svg" width="0" height="0"></svg>';let n=1/0,y=1/0,s=-1/0,e=-1/0;for(const c of t)if(c.isVisible)if(c.type==="line"||c.type==="arrow"||c.type==="freedraw"){const a=c.points;for(let f=0;f<a.length;f+=2){const d=c.x+a[f],k=c.y+a[f+1];n=Math.min(n,d),y=Math.min(y,k),s=Math.max(s,d),e=Math.max(e,k)}}else n=Math.min(n,c.x),y=Math.min(y,c.y),s=Math.max(s,c.x+c.width),e=Math.max(e,c.y+c.height);const i=s-n+l*2,x=e-y+l*2,o=-n+l,$=-y+l,r=t.filter(c=>c.isVisible).map(c=>P(c)).filter(Boolean).join(`
7
+ `);return[`<svg xmlns="http://www.w3.org/2000/svg" width="${i}" height="${x}" viewBox="0 0 ${i} ${x}">`,` <g transform="translate(${o} ${$})">`,` ${r}`," </g>","</svg>"].join(`
8
+ `)}self.onmessage=t=>{const n=t.data;switch(n.type){case"exportSVG":{try{const y=T(n.elements),s={type:"svgResult",requestId:n.requestId,svg:y};self.postMessage(s)}catch(y){const s={type:"error",requestId:n.requestId,message:y instanceof Error?y.message:String(y)};self.postMessage(s)}break}}}})();
@@ -0,0 +1,6 @@
1
+ var El=Object.defineProperty;var Cl=(S,j,N)=>j in S?El(S,j,{enumerable:!0,configurable:!0,writable:!0,value:N}):S[j]=N;var Je=(S,j,N)=>Cl(S,typeof j!="symbol"?j+"":j,N);(function(){"use strict";const S=()=>new Map,j=e=>{const t=S();return e.forEach((n,s)=>{t.set(s,n)}),t},N=(e,t,n)=>{let s=e.get(t);return s===void 0&&e.set(t,s=n()),s},Yr=(e,t)=>{const n=[];for(const[s,r]of e)n.push(t(r,s));return n},Wr=(e,t)=>{for(const[n,s]of e)if(t(s,n))return!0;return!1},et=()=>new Set,He=e=>e[e.length-1],zr=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},X=Array.from,Ye=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},Wn=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},Gr=(e,t)=>{const n=new Array(e);for(let s=0;s<e;s++)n[s]=t(s,n);return n},ce=Array.isArray;class zn{constructor(){this._observers=S()}on(t,n){return N(this._observers,t,et).add(n),n}once(t,n){const s=(...r)=>{this.off(t,s),n(...r)};this.on(t,s)}off(t,n){const s=this._observers.get(t);s!==void 0&&(s.delete(n),s.size===0&&this._observers.delete(t))}emit(t,n){return X((this._observers.get(t)||S()).values()).forEach(s=>s(...n))}destroy(){this._observers=S()}}class Kr{constructor(){this._observers=S()}on(t,n){N(this._observers,t,et).add(n)}once(t,n){const s=(...r)=>{this.off(t,s),n(...r)};this.on(t,s)}off(t,n){const s=this._observers.get(t);s!==void 0&&(s.delete(n),s.size===0&&this._observers.delete(t))}emit(t,n){return X((this._observers.get(t)||S()).values()).forEach(s=>s(...n))}destroy(){this._observers=S()}}const M=Math.floor,oe=Math.abs,We=(e,t)=>e<t?e:t,ht=(e,t)=>e>t?e:t,Xr=Math.pow,Gn=e=>e!==0?e<0:1/e<0,Kn=1,Xn=2,ze=4,Ge=8,Mt=32,q=64,$=128,le=31,Ke=63,at=127,qr=2147483647,he=Number.MAX_SAFE_INTEGER,qn=Number.MIN_SAFE_INTEGER,Qr=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&M(e)===e),Qn=String.fromCharCode,Zr=e=>e.toLowerCase(),Pr=/^\s*/g,ti=e=>e.replace(Pr,""),ei=/([A-Z])/g,Zn=(e,t)=>ti(e.replace(ei,n=>`${t}${Zr(n)}`)),ni=e=>{const t=unescape(encodeURIComponent(e)),n=t.length,s=new Uint8Array(n);for(let r=0;r<n;r++)s[r]=t.codePointAt(r);return s},Jt=typeof TextEncoder<"u"?new TextEncoder:null,si=Jt?e=>Jt.encode(e):ni;let Ht=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Ht&&Ht.decode(new Uint8Array).length===1&&(Ht=null);const ri=(e,t)=>Gr(t,()=>e).join("");class Yt{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const L=()=>new Yt,Xe=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},b=e=>{const t=new Uint8Array(Xe(e));let n=0;for(let s=0;s<e.bufs.length;s++){const r=e.bufs[s];t.set(r,n),n+=r.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},ii=(e,t)=>{const n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(ht(n,t)*2),e.cpos=0)},A=(e,t)=>{const n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},qe=A,p=(e,t)=>{for(;t>at;)A(e,$|at&t),t=M(t/128);A(e,at&t)},Qe=(e,t)=>{const n=Gn(t);for(n&&(t=-t),A(e,(t>Ke?$:0)|(n?q:0)|Ke&t),t=M(t/64);t>0;)A(e,(t>at?$:0)|at&t),t=M(t/128)},Ze=new Uint8Array(3e4),ci=Ze.length/3,oi=(e,t)=>{if(t.length<ci){const n=Jt.encodeInto(t,Ze).written||0;p(e,n);for(let s=0;s<n;s++)A(e,Ze[s])}else _(e,si(t))},li=(e,t)=>{const n=unescape(encodeURIComponent(t)),s=n.length;p(e,s);for(let r=0;r<s;r++)A(e,n.codePointAt(r))},ut=Jt&&Jt.encodeInto?oi:li,ae=(e,t)=>{const n=e.cbuf.length,s=e.cpos,r=We(n-s,t.length),i=t.length-r;e.cbuf.set(t.subarray(0,r),s),e.cpos+=r,i>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(ht(n*2,i)),e.cbuf.set(t.subarray(r)),e.cpos=i)},_=(e,t)=>{p(e,t.byteLength),ae(e,t)},Pe=(e,t)=>{ii(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},hi=(e,t)=>Pe(e,4).setFloat32(0,t,!1),ai=(e,t)=>Pe(e,8).setFloat64(0,t,!1),ui=(e,t)=>Pe(e,8).setBigInt64(0,t,!1),Pn=new DataView(new ArrayBuffer(4)),di=e=>(Pn.setFloat32(0,e),Pn.getFloat32(0)===e),Wt=(e,t)=>{switch(typeof t){case"string":A(e,119),ut(e,t);break;case"number":Qr(t)&&oe(t)<=qr?(A(e,125),Qe(e,t)):di(t)?(A(e,124),hi(e,t)):(A(e,123),ai(e,t));break;case"bigint":A(e,122),ui(e,t);break;case"object":if(t===null)A(e,126);else if(ce(t)){A(e,117),p(e,t.length);for(let n=0;n<t.length;n++)Wt(e,t[n])}else if(t instanceof Uint8Array)A(e,116),_(e,t);else{A(e,118);const n=Object.keys(t);p(e,n.length);for(let s=0;s<n.length;s++){const r=n[s];ut(e,r),Wt(e,t[r])}}break;case"boolean":A(e,t?120:121);break;default:A(e,127)}};class ts extends Yt{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 es=e=>{e.count>0&&(Qe(e.encoder,e.count===1?e.s:-e.s),e.count>1&&p(e.encoder,e.count-2))};class ue{constructor(){this.encoder=new Yt,this.s=0,this.count=0}write(t){this.s===t?this.count++:(es(this),this.count=1,this.s=t)}toUint8Array(){return es(this),b(this.encoder)}}const ns=e=>{if(e.count>0){const t=e.diff*2+(e.count===1?0:1);Qe(e.encoder,t),e.count>1&&p(e.encoder,e.count-2)}};class tn{constructor(){this.encoder=new Yt,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(ns(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return ns(this),b(this.encoder)}}class fi{constructor(){this.sarr=[],this.s="",this.lensE=new ue}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 Yt;return this.sarr.push(this.s),this.s="",ut(t,this.sarr.join("")),ae(t,this.lensE.toUint8Array()),b(t)}}const Y=e=>new Error(e),J=()=>{throw Y("Method unimplemented")},B=()=>{throw Y("Unexpected case")},ss=Y("Unexpected end of array"),rs=Y("Integer out of Range");class de{constructor(t){this.arr=t,this.pos=0}}const nt=e=>new de(e),gi=e=>e.pos!==e.arr.length,pi=(e,t)=>{const n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},T=e=>pi(e,w(e)),bt=e=>e.arr[e.pos++],w=e=>{let t=0,n=1;const s=e.arr.length;for(;e.pos<s;){const r=e.arr[e.pos++];if(t=t+(r&at)*n,n*=128,r<$)return t;if(t>he)throw rs}throw ss},en=e=>{let t=e.arr[e.pos++],n=t&Ke,s=64;const r=(t&q)>0?-1:1;if((t&$)===0)return r*n;const i=e.arr.length;for(;e.pos<i;){if(t=e.arr[e.pos++],n=n+(t&at)*s,s*=128,t<$)return r*n;if(n>he)throw rs}throw ss},st=Ht?e=>Ht.decode(T(e)):e=>{let t=w(e);if(t===0)return"";{let n=String.fromCodePoint(bt(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(bt(e));else for(;t>0;){const s=t<1e4?t:1e4,r=e.arr.subarray(e.pos,e.pos+s);e.pos+=s,n+=String.fromCodePoint.apply(null,r),t-=s}return decodeURIComponent(escape(n))}},nn=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},wi=[e=>{},e=>null,en,e=>nn(e,4).getFloat32(0,!1),e=>nn(e,8).getFloat64(0,!1),e=>nn(e,8).getBigInt64(0,!1),e=>!1,e=>!0,st,e=>{const t=w(e),n={};for(let s=0;s<t;s++){const r=st(e);n[r]=zt(e)}return n},e=>{const t=w(e),n=[];for(let s=0;s<t;s++)n.push(zt(e));return n},T],zt=e=>wi[127-bt(e)](e);class is extends de{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),gi(this)?this.count=w(this)+1:this.count=-1),this.count--,this.s}}class fe extends de{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=en(this);const t=Gn(this.s);this.count=1,t&&(this.s=-this.s,this.count=w(this)+2)}return this.count--,this.s}}class sn extends de{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){const t=en(this),n=t&1;this.diff=M(t/2),this.count=1,n&&(this.count=w(this)+2)}return this.s+=this.diff,this.count--,this.s}}class mi{constructor(t){this.decoder=new fe(t),this.str=st(this.decoder),this.spos=0}read(){const t=this.spos+this.decoder.read(),n=this.str.slice(this.spos,t);return this.spos=t,n}}const ki=crypto.getRandomValues.bind(crypto),cs=()=>ki(new Uint32Array(1))[0],yi="10000000-1000-4000-8000"+-1e11,bi=()=>yi.replace(/[018]/g,e=>(e^cs()&15>>e/4).toString(16)),dt=Date.now,os=e=>new Promise(e);Promise.all.bind(Promise);const ls=e=>e===void 0?null:e;class _i{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}}let hs=new _i,rn=!0;try{typeof localStorage<"u"&&localStorage&&(hs=localStorage,rn=!1)}catch{}const as=hs,Si=e=>rn||addEventListener("storage",e),Ei=e=>rn||removeEventListener("storage",e),Gt=Symbol("Equality"),us=(e,t)=>{var n;return e===t||!!((n=e==null?void 0:e[Gt])!=null&&n.call(e,t))||!1},Ci=e=>typeof e=="object",Di=Object.assign,Ai=Object.keys,Ii=(e,t)=>{for(const n in e)t(e[n],n)},xi=(e,t)=>{const n=[];for(const s in e)n.push(t(e[s],s));return n},ge=e=>Ai(e).length,Oi=e=>{for(const t in e)return!1;return!0},Kt=(e,t)=>{for(const n in e)if(!t(e[n],n))return!1;return!0},cn=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Li=(e,t)=>e===t||ge(e)===ge(t)&&Kt(e,(n,s)=>(n!==void 0||cn(t,s))&&us(t[s],n)),Ti=Object.freeze,ds=e=>{for(const t in e){const n=e[t];(typeof n=="object"||typeof n=="function")&&ds(e[t])}return Ti(e)},on=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&on(e,t,n+1)}},Ui=e=>e,_t=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[Gt]!=null)return e[Gt](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:{if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;break}case Set:{if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;break}case Map:{if(e.size!==t.size)return!1;for(const n of e.keys())if(!t.has(n)||!_t(e.get(n),t.get(n)))return!1;break}case void 0:case Object:if(ge(e)!==ge(t))return!1;for(const n in e)if(!cn(e,n)||!_t(e[n],t[n]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!_t(e[n],t[n]))return!1;break;default:return!1}return!0},Ri=(e,t)=>t.includes(e),rt=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]",fs=typeof window<"u"&&typeof document<"u"&&!rt;let W;const Ni=()=>{if(W===void 0)if(rt){W=S();const e=process.argv;let t=null;for(let n=0;n<e.length;n++){const s=e[n];s[0]==="-"?(t!==null&&W.set(t,""),t=s):t!==null&&(W.set(t,s),t=null)}t!==null&&W.set(t,"")}else typeof location=="object"?(W=S(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){const[t,n]=e.split("=");W.set(`--${Zn(t,"-")}`,n),W.set(`-${Zn(t,"-")}`,n)}})):W=S();return W},ln=e=>Ni().has(e),pe=e=>ls(rt?process.env[e.toUpperCase().replaceAll("-","_")]:as.getItem(e)),gs=e=>ln("--"+e)||pe(e)!==null,vi=gs("production"),$i=rt&&Ri(process.env.FORCE_COLOR,["true","1","2"])||!ln("--no-colors")&&!gs("no-color")&&(!rt||process.stdout.isTTY)&&(!rt||ln("--color")||pe("COLORTERM")!==null||(pe("TERM")||"").includes("color")),ps=e=>new Uint8Array(e),Bi=(e,t,n)=>new Uint8Array(e,t,n),Vi=e=>new Uint8Array(e),Fi=e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=Qn(e[n]);return btoa(t)},ji=e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),Mi=e=>{const t=atob(e),n=ps(t.length);for(let s=0;s<t.length;s++)n[s]=t.charCodeAt(s);return n},Ji=e=>{const t=Buffer.from(e,"base64");return Bi(t.buffer,t.byteOffset,t.byteLength)},Hi=fs?Fi:ji,Yi=fs?Mi:Ji,Wi=e=>{const t=ps(e.byteLength);return t.set(e),t};class zi{constructor(t,n){this.left=t,this.right=n}}const Q=(e,t)=>new zi(e,t),ws=e=>e.next()>=.5,hn=(e,t,n)=>M(e.next()*(n+1-t)+t),ms=(e,t,n)=>M(e.next()*(n+1-t)+t),an=(e,t,n)=>ms(e,t,n),Gi=e=>Qn(an(e,97,122)),Ki=(e,t=0,n=20)=>{const s=an(e,t,n);let r="";for(let i=0;i<s;i++)r+=Gi(e);return r},un=(e,t)=>t[an(e,0,t.length-1)],Xi=Symbol("0schema");class qi{constructor(){this._rerrs=[]}extend(t,n,s,r=null){this._rerrs.push({path:t,expected:n,has:s,message:r})}toString(){const t=[];for(let n=this._rerrs.length-1;n>0;n--){const s=this._rerrs[n];t.push(ri(" ",(this._rerrs.length-n)*2)+`${s.path!=null?`[${s.path}] `:""}${s.has} doesn't match ${s.expected}. ${s.message}`)}return t.join(`
2
+ `)}}const dn=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[Gt]?us(e,t):ce(e)?Ye(e,n=>Wn(t,s=>dn(n,s))):Ci(e)?Kt(e,(n,s)=>dn(n,t[s])):!1;class U{extends(t){let[n,s]=[this.shape,t.shape];return this.constructor._dilutes&&([s,n]=[n,s]),dn(n,s)}equals(t){return this.constructor===t.constructor&&_t(this.shape,t.shape)}[Xi](){return!0}[Gt](t){return this.equals(t)}validate(t){return this.check(t)}check(t,n){J()}get nullable(){return St(this,Ee)}get optional(){return new bs(this)}cast(t){return Us(t,this),t}expect(t){return Us(t,this),t}}Je(U,"_dilutes",!1);class fn extends U{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n=void 0){const s=(t==null?void 0:t.constructor)===this.shape&&(this._c==null||this._c(t));return!s&&(n==null||n.extend(null,this.shape.name,t==null?void 0:t.constructor.name,(t==null?void 0:t.constructor)!==this.shape?"Constructor match failed":"Check failed")),s}}const E=(e,t=null)=>new fn(e,t);E(fn);class gn extends U{constructor(t){super(),this.shape=t}check(t,n){const s=this.shape(t);return!s&&(n==null||n.extend(null,"custom prop",t==null?void 0:t.constructor.name,"failed to check custom prop")),s}}const I=e=>new gn(e);E(gn);class we extends U{constructor(t){super(),this.shape=t}check(t,n){const s=this.shape.some(r=>r===t);return!s&&(n==null||n.extend(null,this.shape.join(" | "),t.toString())),s}}const me=(...e)=>new we(e),ks=E(we),Qi=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,t=>"\\"+t)),ys=e=>{if(Ct.check(e))return[Qi(e)];if(ks.check(e))return e.shape.map(t=>t+"");if(Os.check(e))return["[+-]?\\d+.?\\d*"];if(Ls.check(e))return[".*"];if(be.check(e))return e.shape.map(ys).flat(1);B()};class Zi extends U{constructor(t){super(),this.shape=t,this._r=new RegExp("^"+t.map(ys).map(n=>`(${n.join("|")})`).join("")+"$")}check(t,n){const s=this._r.exec(t)!=null;return!s&&(n==null||n.extend(null,this._r.toString(),t.toString(),"String doesn't match string template.")),s}}E(Zi);const Pi=Symbol("optional");class bs extends U{constructor(t){super(),this.shape=t}check(t,n){const s=t===void 0||this.shape.check(t);return!s&&(n==null||n.extend(null,"undefined (optional)","()")),s}get[Pi](){return!0}}const tc=E(bs);class ec extends U{check(t,n){return n==null||n.extend(null,"never",typeof t),!1}}E(ec);const Me=class Me extends U{constructor(t,n=!1){super(),this.shape=t,this._isPartial=n}get partial(){return new Me(this.shape,!0)}check(t,n){return t==null?(n==null||n.extend(null,"object","null"),!1):Kt(this.shape,(s,r)=>{const i=this._isPartial&&!cn(t,r)||s.check(t[r],n);return!i&&(n==null||n.extend(r.toString(),s.toString(),typeof t[r],"Object property does not match")),i})}};Je(Me,"_dilutes",!0);let ke=Me;const nc=e=>new ke(e),sc=E(ke),rc=I(e=>e!=null&&(e.constructor===Object||e.constructor==null));class _s extends U{constructor(t,n){super(),this.shape={keys:t,values:n}}check(t,n){return t!=null&&Kt(t,(s,r)=>{const i=this.shape.keys.check(r,n);return!i&&(n==null||n.extend(r+"","Record",typeof t,i?"Key doesn't match schema":"Value doesn't match value")),i&&this.shape.values.check(s,n)})}}const Ss=(e,t)=>new _s(e,t),ic=E(_s);class Es extends U{constructor(t){super(),this.shape=t}check(t,n){return t!=null&&Kt(this.shape,(s,r)=>{const i=s.check(t[r],n);return!i&&(n==null||n.extend(r.toString(),"Tuple",typeof s)),i})}}const cc=(...e)=>new Es(e);E(Es);class Cs extends U{constructor(t){super(),this.shape=t.length===1?t[0]:new ye(t)}check(t,n){const s=ce(t)&&Ye(t,r=>this.shape.check(r));return!s&&(n==null||n.extend(null,"Array","")),s}}const Ds=(...e)=>new Cs(e),oc=E(Cs),lc=I(e=>ce(e));class As extends U{constructor(t,n){super(),this.shape=t,this._c=n}check(t,n){const s=t instanceof this.shape&&(this._c==null||this._c(t));return!s&&(n==null||n.extend(null,this.shape.name,t==null?void 0:t.constructor.name)),s}}const hc=(e,t=null)=>new As(e,t);E(As);const ac=hc(U);class uc extends U{constructor(t){super(),this.len=t.length-1,this.args=cc(...t.slice(-1)),this.res=t[this.len]}check(t,n){const s=t.constructor===Function&&t.length<=this.len;return!s&&(n==null||n.extend(null,"function",typeof t)),s}}const dc=E(uc),fc=I(e=>typeof e=="function");class gc extends U{constructor(t){super(),this.shape=t}check(t,n){const s=Ye(this.shape,r=>r.check(t,n));return!s&&(n==null||n.extend(null,"Intersectinon",typeof t)),s}}E(gc,e=>e.shape.length>0);class ye extends U{constructor(t){super(),this.shape=t}check(t,n){const s=Wn(this.shape,r=>r.check(t,n));return n==null||n.extend(null,"Union",typeof t),s}}Je(ye,"_dilutes",!0);const St=(...e)=>e.findIndex(t=>be.check(t))>=0?St(...e.map(t=>Xt(t)).map(t=>be.check(t)?t.shape:[t]).flat(1)):e.length===1?e[0]:new ye(e),be=E(ye),Is=()=>!0,_e=I(Is),pc=E(gn,e=>e.shape===Is),pn=I(e=>typeof e=="bigint"),wc=I(e=>e===pn),xs=I(e=>typeof e=="symbol");I(e=>e===xs);const Et=I(e=>typeof e=="number"),Os=I(e=>e===Et),Ct=I(e=>typeof e=="string"),Ls=I(e=>e===Ct),Se=I(e=>typeof e=="boolean"),mc=I(e=>e===Se),Ts=me(void 0);E(we,e=>e.shape.length===1&&e.shape[0]===void 0),me(void 0);const Ee=me(null),kc=E(we,e=>e.shape.length===1&&e.shape[0]===null);E(Uint8Array),E(fn,e=>e.shape===Uint8Array);const yc=St(Et,Ct,Ee,Ts,pn,Se,xs);(()=>{const e=Ds(_e),t=Ss(Ct,_e),n=St(Et,Ct,Ee,Se,e,t);return e.shape=n,t.shape.values=n,n})();const Xt=e=>{if(ac.check(e))return e;if(rc.check(e)){const t={};for(const n in e)t[n]=Xt(e[n]);return nc(t)}else{if(lc.check(e))return St(...e.map(Xt));if(yc.check(e))return me(e);if(fc.check(e))return E(e)}B()},Us=vi?()=>{}:(e,t)=>{const n=new qi;if(!t.check(e,n))throw Y(`Expected value to be of type ${t.constructor.name}.
3
+ ${n.toString()}`)};class bc{constructor(t){this.patterns=[],this.$state=t}if(t,n){return this.patterns.push({if:Xt(t),h:n}),this}else(t){return this.if(_e,t)}done(){return(t,n)=>{for(let s=0;s<this.patterns.length;s++){const r=this.patterns[s];if(r.if.check(t))return r.h(t,n)}throw Y("Unhandled pattern")}}}const Rs=(e=>new bc(e))(_e).if(Os,(e,t)=>hn(t,qn,he)).if(Ls,(e,t)=>Ki(t)).if(mc,(e,t)=>ws(t)).if(wc,(e,t)=>BigInt(hn(t,qn,he))).if(be,(e,t)=>Dt(t,un(t,e.shape))).if(sc,(e,t)=>{const n={};for(const s in e.shape){let r=e.shape[s];if(tc.check(r)){if(ws(t))continue;r=r.shape}n[s]=Rs(r,t)}return n}).if(oc,(e,t)=>{const n=[],s=ms(t,0,42);for(let r=0;r<s;r++)n.push(Dt(t,e.shape));return n}).if(ks,(e,t)=>un(t,e.shape)).if(kc,(e,t)=>null).if(dc,(e,t)=>{const n=Dt(t,e.res);return()=>n}).if(pc,(e,t)=>Dt(t,un(t,[Et,Ct,Ee,Ts,pn,Se,Ds(Et),Ss(St("a","b","c"),Et)]))).if(ic,(e,t)=>{const n={},s=hn(t,0,3);for(let r=0;r<s;r++){const i=Dt(t,e.shape.keys),c=Dt(t,e.shape.values);n[i]=c}return n}).done(),Dt=(e,t)=>Rs(Xt(t),e),Ce=typeof document<"u"?document:{};I(e=>e.nodeType===Dc),typeof DOMParser<"u"&&new DOMParser,I(e=>e.nodeType===Sc),I(e=>e.nodeType===Ec);const _c=e=>Yr(e,(t,n)=>`${n}:${t};`).join(""),Sc=Ce.ELEMENT_NODE,Ec=Ce.TEXT_NODE,Cc=Ce.DOCUMENT_NODE,Dc=Ce.DOCUMENT_FRAGMENT_NODE;I(e=>e.nodeType===Cc);const Z=Symbol,Ns=Z(),vs=Z(),Ac=Z(),Ic=Z(),xc=Z(),$s=Z(),Oc=Z(),wn=Z(),Lc=Z(),Tc=e=>{var r;e.length===1&&((r=e[0])==null?void 0:r.constructor)===Function&&(e=e[0]());const t=[],n=[];let s=0;for(;s<e.length;s++){const i=e[s];if(i===void 0)break;if(i.constructor===String||i.constructor===Number)t.push(i);else if(i.constructor===Object)break}for(s>0&&n.push(t.join(""));s<e.length;s++){const i=e[s];i instanceof Symbol||n.push(i)}return n},Uc={[Ns]:Q("font-weight","bold"),[vs]:Q("font-weight","normal"),[Ac]:Q("color","blue"),[xc]:Q("color","green"),[Ic]:Q("color","grey"),[$s]:Q("color","red"),[Oc]:Q("color","purple"),[wn]:Q("color","orange"),[Lc]:Q("color","black")},Bs=$i?e=>{var c;e.length===1&&((c=e[0])==null?void 0:c.constructor)===Function&&(e=e[0]());const t=[],n=[],s=S();let r=[],i=0;for(;i<e.length;i++){const o=e[i],l=Uc[o];if(l!==void 0)s.set(l.left,l.right);else{if(o===void 0)break;if(o.constructor===String||o.constructor===Number){const h=_c(s);i>0||h.length>0?(t.push("%c"+o),n.push(h)):t.push(o)}else break}}for(i>0&&(r=n,r.unshift(t.join("")));i<e.length;i++){const o=e[i];o instanceof Symbol||r.push(o)}return r}:Tc,Rc=(...e)=>{console.log(...Bs(e)),Vs.forEach(t=>t.print(e))},Nc=(...e)=>{console.warn(...Bs(e)),e.unshift(wn),Vs.forEach(t=>t.print(e))},Vs=et(),Fs=e=>({[Symbol.iterator](){return this},next:e}),vc=(e,t)=>Fs(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),mn=(e,t)=>Fs(()=>{const{done:n,value:s}=e.next();return{done:n,value:n?void 0:t(s)}});class kn{constructor(t,n){this.clock=t,this.len=n}}class qt{constructor(){this.clients=new Map}}const js=(e,t,n)=>t.clients.forEach((s,r)=>{const i=e.doc.store.clients.get(r);if(i!=null){const c=i[i.length-1],o=c.id.clock+c.length;for(let l=0,h=s[l];l<s.length&&h.clock<o;h=s[++l])rr(e,i,h.clock,h.len,n)}}),$c=(e,t)=>{let n=0,s=e.length-1;for(;n<=s;){const r=M((n+s)/2),i=e[r],c=i.clock;if(c<=t){if(t<c+i.len)return r;n=r+1}else s=r-1}return null},Ms=(e,t)=>{const n=e.clients.get(t.client);return n!==void 0&&$c(n,t.clock)!==null},yn=e=>{e.clients.forEach(t=>{t.sort((r,i)=>r.clock-i.clock);let n,s;for(n=1,s=1;n<t.length;n++){const r=t[s-1],i=t[n];r.clock+r.len>=i.clock?r.len=ht(r.len,i.clock+i.len-r.clock):(s<n&&(t[s]=i),s++)}t.length=s})},Bc=e=>{const t=new qt;for(let n=0;n<e.length;n++)e[n].clients.forEach((s,r)=>{if(!t.clients.has(r)){const i=s.slice();for(let c=n+1;c<e.length;c++)zr(i,e[c].clients.get(r)||[]);t.clients.set(r,i)}});return yn(t),t},De=(e,t,n,s)=>{N(e.clients,t,()=>[]).push(new kn(n,s))},Vc=()=>new qt,Fc=e=>{const t=Vc();return e.clients.forEach((n,s)=>{const r=[];for(let i=0;i<n.length;i++){const c=n[i];if(c.deleted){const o=c.id.clock;let l=c.length;if(i+1<n.length)for(let h=n[i+1];i+1<n.length&&h.deleted;h=n[++i+1])l+=h.length;r.push(new kn(o,l))}}r.length>0&&t.clients.set(s,r)}),t},At=(e,t)=>{p(e.restEncoder,t.clients.size),X(t.clients.entries()).sort((n,s)=>s[0]-n[0]).forEach(([n,s])=>{e.resetDsCurVal(),p(e.restEncoder,n);const r=s.length;p(e.restEncoder,r);for(let i=0;i<r;i++){const c=s[i];e.writeDsClock(c.clock),e.writeDsLen(c.len)}})},bn=e=>{const t=new qt,n=w(e.restDecoder);for(let s=0;s<n;s++){e.resetDsCurVal();const r=w(e.restDecoder),i=w(e.restDecoder);if(i>0){const c=N(t.clients,r,()=>[]);for(let o=0;o<i;o++)c.push(new kn(e.readDsClock(),e.readDsLen()))}}return t},Js=(e,t,n)=>{const s=new qt,r=w(e.restDecoder);for(let i=0;i<r;i++){e.resetDsCurVal();const c=w(e.restDecoder),o=w(e.restDecoder),l=n.clients.get(c)||[],h=x(n,c);for(let a=0;a<o;a++){const u=e.readDsClock(),d=u+e.readDsLen();if(u<h){h<d&&De(s,c,h,d-h);let f=z(l,u),g=l[f];for(!g.deleted&&g.id.clock<u&&(l.splice(f+1,0,je(t,g,u-g.id.clock)),f++);f<l.length&&(g=l[f++],g.id.clock<d);)g.deleted||(d<g.id.clock+g.length&&l.splice(f,0,je(t,g,d-g.id.clock)),g.delete(t))}else De(s,c,u,d-u)}}if(s.clients.size>0){const i=new ft;return p(i.restEncoder,0),At(i,s),i.toUint8Array()}return null},Hs=cs;class It extends zn{constructor({guid:t=bi(),collectionid:n=null,gc:s=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:c=!1,shouldLoad:o=!0}={}){super(),this.gc=s,this.gcFilter=r,this.clientID=Hs(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new er,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=c,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=os(h=>{this.on("load",()=>{this.isLoaded=!0,h(this)})});const l=()=>os(h=>{const a=u=>{(u===void 0||u===!0)&&(this.off("sync",a),h())};this.on("sync",a)});this.on("sync",h=>{h===!1&&this.isSynced&&(this.whenSynced=l()),this.isSynced=h===void 0||h===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=l()}load(){const t=this._item;t!==null&&!this.shouldLoad&&y(t.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(X(this.subdocs).map(t=>t.guid))}transact(t,n=null){return y(this,t,n)}get(t,n=O){const s=N(this.share,t,()=>{const i=new n;return i._integrate(this,null),i}),r=s.constructor;if(n!==O&&r!==n)if(r===O){const i=new n;i._map=s._map,s._map.forEach(c=>{for(;c!==null;c=c.left)c.parent=i}),i._start=s._start;for(let c=i._start;c!==null;c=c.right)c.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,Tt)}getText(t=""){return this.get(t,Rt)}getMap(t=""){return this.get(t,P)}getXmlElement(t=""){return this.get(t,Nt)}getXmlFragment(t=""){return this.get(t,gt)}toJSON(){const t={};return this.share.forEach((n,s)=>{t[s]=n.toJSON()}),t}destroy(){this.isDestroyed=!0,X(this.subdocs).forEach(n=>n.destroy());const t=this._item;if(t!==null){this._item=null;const n=t.content;n.doc=new It({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,y(t.parent.doc,s=>{const r=n.doc;t.deleted||s.subdocsAdded.add(r),s.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class Ys{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return w(this.restDecoder)}readDsLen(){return w(this.restDecoder)}}class Ws extends Ys{readLeftID(){return m(w(this.restDecoder),w(this.restDecoder))}readRightID(){return m(w(this.restDecoder),w(this.restDecoder))}readClient(){return w(this.restDecoder)}readInfo(){return bt(this.restDecoder)}readString(){return st(this.restDecoder)}readParentInfo(){return w(this.restDecoder)===1}readTypeRef(){return w(this.restDecoder)}readLen(){return w(this.restDecoder)}readAny(){return zt(this.restDecoder)}readBuf(){return Wi(T(this.restDecoder))}readJSON(){return JSON.parse(st(this.restDecoder))}readKey(){return st(this.restDecoder)}}class jc{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 xt extends jc{constructor(t){super(t),this.keys=[],w(t),this.keyClockDecoder=new sn(T(t)),this.clientDecoder=new fe(T(t)),this.leftClockDecoder=new sn(T(t)),this.rightClockDecoder=new sn(T(t)),this.infoDecoder=new is(T(t),bt),this.stringDecoder=new mi(T(t)),this.parentInfoDecoder=new is(T(t),bt),this.typeRefDecoder=new fe(T(t)),this.lenDecoder=new fe(T(t))}readLeftID(){return new Ot(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Ot(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 zt(this.restDecoder)}readBuf(){return T(this.restDecoder)}readJSON(){return zt(this.restDecoder)}readKey(){const t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{const n=this.stringDecoder.read();return this.keys.push(n),n}}}class zs{constructor(){this.restEncoder=L()}toUint8Array(){return b(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){p(this.restEncoder,t)}writeDsLen(t){p(this.restEncoder,t)}}class Qt extends zs{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){qe(this.restEncoder,t)}writeString(t){ut(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){Wt(this.restEncoder,t)}writeBuf(t){_(this.restEncoder,t)}writeJSON(t){ut(this.restEncoder,JSON.stringify(t))}writeKey(t){ut(this.restEncoder,t)}}class Gs{constructor(){this.restEncoder=L(),this.dsCurrVal=0}toUint8Array(){return b(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const n=t-this.dsCurrVal;this.dsCurrVal=t,p(this.restEncoder,n)}writeDsLen(t){t===0&&B(),p(this.restEncoder,t-1),this.dsCurrVal+=t}}class ft extends Gs{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new tn,this.clientEncoder=new ue,this.leftClockEncoder=new tn,this.rightClockEncoder=new tn,this.infoEncoder=new ts(qe),this.stringEncoder=new fi,this.parentInfoEncoder=new ts(qe),this.typeRefEncoder=new ue,this.lenEncoder=new ue}toUint8Array(){const t=L();return p(t,0),_(t,this.keyClockEncoder.toUint8Array()),_(t,this.clientEncoder.toUint8Array()),_(t,this.leftClockEncoder.toUint8Array()),_(t,this.rightClockEncoder.toUint8Array()),_(t,b(this.infoEncoder)),_(t,this.stringEncoder.toUint8Array()),_(t,b(this.parentInfoEncoder)),_(t,this.typeRefEncoder.toUint8Array()),_(t,this.lenEncoder.toUint8Array()),ae(t,b(this.restEncoder)),b(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){Wt(this.restEncoder,t)}writeBuf(t){_(this.restEncoder,t)}writeJSON(t){Wt(this.restEncoder,t)}writeKey(t){const n=this.keyMap.get(t);n===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(n)}}const Mc=(e,t,n,s)=>{s=ht(s,t[0].id.clock);const r=z(t,s);p(e.restEncoder,t.length-r),e.writeClient(n),p(e.restEncoder,s);const i=t[r];i.write(e,s-i.id.clock);for(let c=r+1;c<t.length;c++)t[c].write(e,0)},_n=(e,t,n)=>{const s=new Map;n.forEach((r,i)=>{x(t,i)>r&&s.set(i,r)}),Ie(t).forEach((r,i)=>{n.has(i)||s.set(i,0)}),p(e.restEncoder,s.size),X(s.entries()).sort((r,i)=>i[0]-r[0]).forEach(([r,i])=>{Mc(e,t.clients.get(r),r,i)})},Jc=(e,t)=>{const n=S(),s=w(e.restDecoder);for(let r=0;r<s;r++){const i=w(e.restDecoder),c=new Array(i),o=e.readClient();let l=w(e.restDecoder);n.set(o,{i:0,refs:c});for(let h=0;h<i;h++){const a=e.readInfo();switch(le&a){case 0:{const u=e.readLen();c[h]=new V(m(o,l),u),l+=u;break}case 10:{const u=w(e.restDecoder);c[h]=new F(m(o,l),u),l+=u;break}default:{const u=(a&(q|$))===0,d=new D(m(o,l),null,(a&$)===$?e.readLeftID():null,null,(a&q)===q?e.readRightID():null,u?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,u&&(a&Mt)===Mt?e.readString():null,Or(e,a));c[h]=d,l+=d.length}}}}return n},Hc=(e,t,n)=>{const s=[];let r=X(n.keys()).sort((f,g)=>f-g);if(r.length===0)return null;const i=()=>{if(r.length===0)return null;let f=n.get(r[r.length-1]);for(;f.refs.length===f.i;)if(r.pop(),r.length>0)f=n.get(r[r.length-1]);else return null;return f};let c=i();if(c===null)return null;const o=new er,l=new Map,h=(f,g)=>{const k=l.get(f);(k==null||k>g)&&l.set(f,g)};let a=c.refs[c.i++];const u=new Map,d=()=>{for(const f of s){const g=f.id.client,k=n.get(g);k?(k.i--,o.clients.set(g,k.refs.slice(k.i)),n.delete(g),k.i=0,k.refs=[]):o.clients.set(g,[f]),r=r.filter(H=>H!==g)}s.length=0};for(;;){if(a.constructor!==F){const g=N(u,a.id.client,()=>x(t,a.id.client))-a.id.clock;if(g<0)s.push(a),h(a.id.client,a.id.clock-1),d();else{const k=a.getMissing(e,t);if(k!==null){s.push(a);const H=n.get(k)||{refs:[],i:0};if(H.refs.length===H.i)h(k,x(t,k)),d();else{a=H.refs[H.i++];continue}}else(g===0||g<a.length)&&(a.integrate(e,g),u.set(a.id.client,a.id.clock+a.length))}}if(s.length>0)a=s.pop();else if(c!==null&&c.i<c.refs.length)a=c.refs[c.i++];else{if(c=i(),c===null)break;a=c.refs[c.i++]}}if(o.clients.size>0){const f=new ft;return _n(f,o,new Map),p(f.restEncoder,0),{missing:l,update:f.toUint8Array()}}return null},Yc=(e,t)=>_n(e,t.doc.store,t.beforeState),Wc=(e,t,n,s=new xt(e))=>y(t,r=>{r.local=!1;let i=!1;const c=r.doc,o=c.store,l=Jc(s,c),h=Hc(r,o,l),a=o.pendingStructs;if(a){for(const[d,f]of a.missing)if(f<x(o,d)){i=!0;break}if(h){for(const[d,f]of h.missing){const g=a.missing.get(d);(g==null||g>f)&&a.missing.set(d,f)}a.update=Oe([a.update,h.update])}}else o.pendingStructs=h;const u=Js(s,r,o);if(o.pendingDs){const d=new xt(nt(o.pendingDs));w(d.restDecoder);const f=Js(d,r,o);u&&f?o.pendingDs=Oe([u,f]):o.pendingDs=u||f}else o.pendingDs=u;if(i){const d=o.pendingStructs.update;o.pendingStructs=null,Ks(r.doc,d)}},n,!1),Ks=(e,t,n,s=xt)=>{const r=nt(t);Wc(r,e,n,new s(r))},zc=(e,t,n)=>Ks(e,t,n,Ws),Gc=(e,t,n=new Map)=>{_n(e,t.store,n),At(e,Fc(t.store))},Kc=(e,t=new Uint8Array([0]),n=new ft)=>{const s=Xs(t);Gc(n,e,s);const r=[n.toUint8Array()];if(e.store.pendingDs&&r.push(e.store.pendingDs),e.store.pendingStructs&&r.push(ho(e.store.pendingStructs.update,t)),r.length>1){if(n.constructor===Qt)return oo(r.map((i,c)=>c===0?i:uo(i)));if(n.constructor===ft)return Oe(r)}return r[0]},Xc=(e,t)=>Kc(e,t,new Qt),qc=e=>{const t=new Map,n=w(e.restDecoder);for(let s=0;s<n;s++){const r=w(e.restDecoder),i=w(e.restDecoder);t.set(r,i)}return t},Xs=e=>qc(new Ys(nt(e))),qs=(e,t)=>(p(e.restEncoder,t.size),X(t.entries()).sort((n,s)=>s[0]-n[0]).forEach(([n,s])=>{p(e.restEncoder,n),p(e.restEncoder,s)}),e),Qc=(e,t)=>qs(e,Ie(t.store)),Zc=(e,t=new Gs)=>(e instanceof Map?qs(t,e):Qc(t,e),t.toUint8Array()),Pc=e=>Zc(e,new zs);class to{constructor(){this.l=[]}}const Qs=()=>new to,Zs=(e,t)=>e.l.push(t),Ps=(e,t)=>{const n=e.l,s=n.length;e.l=n.filter(r=>t!==r),s===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},tr=(e,t,n)=>on(e.l,[t,n]);class Ot{constructor(t,n){this.client=t,this.clock=n}}const Ae=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,m=(e,t)=>new Ot(e,t),eo=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw B()},Lt=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!Ms(t.ds,e.id),Sn=(e,t)=>{const n=N(e.meta,Sn,et),s=e.doc.store;n.has(t)||(t.sv.forEach((r,i)=>{r<x(s,i)&&it(e,m(i,r))}),js(e,t.ds,r=>{}),n.add(t))};class er{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const Ie=e=>{const t=new Map;return e.clients.forEach((n,s)=>{const r=n[n.length-1];t.set(s,r.id.clock+r.length)}),t},x=(e,t)=>{const n=e.clients.get(t);if(n===void 0)return 0;const s=n[n.length-1];return s.id.clock+s.length},nr=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{const s=n[n.length-1];if(s.id.clock+s.length!==t.id.clock)throw B()}n.push(t)},z=(e,t)=>{let n=0,s=e.length-1,r=e[s],i=r.id.clock;if(i===t)return s;let c=M(t/(i+r.length-1)*s);for(;n<=s;){if(r=e[c],i=r.id.clock,i<=t){if(t<i+r.length)return c;n=c+1}else s=c-1;c=M((n+s)/2)}throw B()},En=(e,t)=>{const n=e.clients.get(t.client);return n[z(n,t.clock)]},Cn=(e,t,n)=>{const s=z(t,n),r=t[s];return r.id.clock<n&&r instanceof D?(t.splice(s+1,0,je(e,r,n-r.id.clock)),s+1):s},it=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[Cn(e,n,t.clock)]},sr=(e,t,n)=>{const s=t.clients.get(n.client),r=z(s,n.clock),i=s[r];return n.clock!==i.id.clock+i.length-1&&i.constructor!==V&&s.splice(r+1,0,je(e,i,n.clock-i.id.clock+1)),i},no=(e,t,n)=>{const s=e.clients.get(t.id.client);s[z(s,t.id.clock)]=n},rr=(e,t,n,s,r)=>{if(s===0)return;const i=n+s;let c=Cn(e,t,n),o;do o=t[c++],i<o.id.clock+o.length&&Cn(e,t,i),r(o);while(c<t.length&&t[c].id.clock<i)};class so{constructor(t,n,s){this.doc=t,this.deleteSet=new qt,this.beforeState=Ie(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=n,this.meta=new Map,this.local=s,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const ir=(e,t)=>t.deleteSet.clients.size===0&&!Wr(t.afterState,(n,s)=>t.beforeState.get(s)!==n)?!1:(yn(t.deleteSet),Yc(e,t),At(e,t.deleteSet),!0),cr=(e,t,n)=>{const s=t._item;(s===null||s.id.clock<(e.beforeState.get(s.id.client)||0)&&!s.deleted)&&N(e.changed,t,et).add(n)},xe=(e,t)=>{let n=e[t],s=e[t-1],r=t;for(;r>0;n=s,s=e[--r-1]){if(s.deleted===n.deleted&&s.constructor===n.constructor&&s.mergeWith(n)){n instanceof D&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,s);continue}break}const i=t-r;return i&&e.splice(t+1-i,i),i},ro=(e,t,n)=>{for(const[s,r]of e.clients.entries()){const i=t.clients.get(s);for(let c=r.length-1;c>=0;c--){const o=r[c],l=o.clock+o.len;for(let h=z(i,o.clock),a=i[h];h<i.length&&a.id.clock<l;a=i[++h]){const u=i[h];if(o.clock+o.len<=u.id.clock)break;u instanceof D&&u.deleted&&!u.keep&&n(u)&&u.gc(t,!1)}}}},io=(e,t)=>{e.clients.forEach((n,s)=>{const r=t.clients.get(s);for(let i=n.length-1;i>=0;i--){const c=n[i],o=We(r.length-1,1+z(r,c.clock+c.len-1));for(let l=o,h=r[l];l>0&&h.id.clock>=c.clock;h=r[l])l-=1+xe(r,l)}})},or=(e,t)=>{if(t<e.length){const n=e[t],s=n.doc,r=s.store,i=n.deleteSet,c=n._mergeStructs;try{yn(i),n.afterState=Ie(n.doc.store),s.emit("beforeObserverCalls",[n,s]);const o=[];n.changed.forEach((l,h)=>o.push(()=>{(h._item===null||!h._item.deleted)&&h._callObserver(n,l)})),o.push(()=>{n.changedParentTypes.forEach((l,h)=>{h._dEH.l.length>0&&(h._item===null||!h._item.deleted)&&(l=l.filter(a=>a.target._item===null||!a.target._item.deleted),l.forEach(a=>{a.currentTarget=h,a._path=null}),l.sort((a,u)=>a.path.length-u.path.length),o.push(()=>{tr(h._dEH,l,n)}))}),o.push(()=>s.emit("afterTransaction",[n,s])),o.push(()=>{n._needFormattingCleanup&&Ao(n)})}),on(o,[])}finally{s.gc&&ro(i,r,s.gcFilter),io(i,r),n.afterState.forEach((a,u)=>{const d=n.beforeState.get(u)||0;if(d!==a){const f=r.clients.get(u),g=ht(z(f,d),1);for(let k=f.length-1;k>=g;)k-=1+xe(f,k)}});for(let a=c.length-1;a>=0;a--){const{client:u,clock:d}=c[a].id,f=r.clients.get(u),g=z(f,d);g+1<f.length&&xe(f,g+1)>1||g>0&&xe(f,g)}if(!n.local&&n.afterState.get(s.clientID)!==n.beforeState.get(s.clientID)&&(Rc(wn,Ns,"[yjs] ",vs,$s,"Changed the client-id because another client seems to be using it."),s.clientID=Hs()),s.emit("afterTransactionCleanup",[n,s]),s._observers.has("update")){const a=new Qt;ir(a,n)&&s.emit("update",[a.toUint8Array(),n.origin,s,n])}if(s._observers.has("updateV2")){const a=new ft;ir(a,n)&&s.emit("updateV2",[a.toUint8Array(),n.origin,s,n])}const{subdocsAdded:o,subdocsLoaded:l,subdocsRemoved:h}=n;(o.size>0||h.size>0||l.size>0)&&(o.forEach(a=>{a.clientID=s.clientID,a.collectionid==null&&(a.collectionid=s.collectionid),s.subdocs.add(a)}),h.forEach(a=>s.subdocs.delete(a)),s.emit("subdocs",[{loaded:l,added:o,removed:h},s,n]),h.forEach(a=>a.destroy())),e.length<=t+1?(s._transactionCleanups=[],s.emit("afterAllTransactions",[s,e])):or(e,t+1)}}},y=(e,t,n=null,s=!0)=>{const r=e._transactionCleanups;let i=!1,c=null;e._transaction===null&&(i=!0,e._transaction=new so(e,n,s),r.push(e._transaction),r.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{c=t(e._transaction)}finally{if(i){const o=e._transaction===r[0];e._transaction=null,o&&or(r,0)}}return c};function*co(e){const t=w(e.restDecoder);for(let n=0;n<t;n++){const s=w(e.restDecoder),r=e.readClient();let i=w(e.restDecoder);for(let c=0;c<s;c++){const o=e.readInfo();if(o===10){const l=w(e.restDecoder);yield new F(m(r,i),l),i+=l}else if((le&o)!==0){const l=(o&(q|$))===0,h=new D(m(r,i),null,(o&$)===$?e.readLeftID():null,null,(o&q)===q?e.readRightID():null,l?e.readParentInfo()?e.readString():e.readLeftID():null,l&&(o&Mt)===Mt?e.readString():null,Or(e,o));yield h,i+=h.length}else{const l=e.readLen();yield new V(m(r,i),l),i+=l}}}}class Dn{constructor(t,n){this.gen=co(t),this.curr=null,this.done=!1,this.filterSkips=n,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===F);return this.curr}}class An{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}}const oo=e=>Oe(e,Ws,Qt),lo=(e,t)=>{if(e.constructor===V){const{client:n,clock:s}=e.id;return new V(m(n,s+t),e.length-t)}else if(e.constructor===F){const{client:n,clock:s}=e.id;return new F(m(n,s+t),e.length-t)}else{const n=e,{client:s,clock:r}=n.id;return new D(m(s,r+t),null,m(s,r+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Oe=(e,t=xt,n=ft)=>{if(e.length===1)return e[0];const s=e.map(a=>new t(nt(a)));let r=s.map(a=>new Dn(a,!0)),i=null;const c=new n,o=new An(c);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===F?1:-1:g}else return f.curr.id.client-d.curr.id.client}),r.length!==0;){const a=r[0],u=a.curr.id.client;if(i!==null){let d=a.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=a.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)ct(o,i.struct,i.offset),i={struct:d,offset:0},a.next();else if(i.struct.id.clock+i.struct.length<d.id.clock)if(i.struct.constructor===F)i.struct.length=d.id.clock+d.length-i.struct.id.clock;else{ct(o,i.struct,i.offset);const g=d.id.clock-i.struct.id.clock-i.struct.length;i={struct:new F(m(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===F?i.struct.length-=g:d=lo(d,g)),i.struct.mergeWith(d)||(ct(o,i.struct,i.offset),i={struct:d,offset:0},a.next())}}else i={struct:a.curr,offset:0},a.next();for(let d=a.curr;d!==null&&d.id.client===u&&d.id.clock===i.struct.id.clock+i.struct.length&&d.constructor!==F;d=a.next())ct(o,i.struct,i.offset),i={struct:d,offset:0}}i!==null&&(ct(o,i.struct,i.offset),i=null),In(o);const l=s.map(a=>bn(a)),h=Bc(l);return At(c,h),c.toUint8Array()},ho=(e,t,n=xt,s=ft)=>{const r=Xs(t),i=new s,c=new An(i),o=new n(nt(e)),l=new Dn(o,!1);for(;l.curr;){const a=l.curr,u=a.id.client,d=r.get(u)||0;if(l.curr.constructor===F){l.next();continue}if(a.id.clock+a.length>d)for(ct(c,a,ht(d-a.id.clock,0)),l.next();l.curr&&l.curr.id.client===u;)ct(c,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===u&&l.curr.id.clock+l.curr.length<=d;)l.next()}In(c);const h=bn(o);return At(i,h),i.toUint8Array()},lr=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:b(e.encoder.restEncoder)}),e.encoder.restEncoder=L(),e.written=0)},ct=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&lr(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),p(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},In=e=>{lr(e);const t=e.encoder.restEncoder;p(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){const s=e.clientStructs[n];p(t,s.written),ae(t,s.restEncoder)}},ao=(e,t,n,s)=>{const r=new n(nt(e)),i=new Dn(r,!1),c=new s,o=new An(c);for(let h=i.curr;h!==null;h=i.next())ct(o,t(h),0);In(o);const l=bn(r);return At(c,l),c.toUint8Array()},uo=e=>ao(e,Ui,xt,Qt),hr="You must not compute changes after the event-handler fired.";class Le{constructor(t,n){this.target=t,this.currentTarget=t,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=fo(this.currentTarget,this.target))}deletes(t){return Ms(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw Y(hr);const t=new Map,n=this.target;this.transaction.changed.get(n).forEach(r=>{if(r!==null){const i=n._map.get(r);let c,o;if(this.adds(i)){let l=i.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(i))if(l!==null&&this.deletes(l))c="delete",o=He(l.content.getContent());else return;else l!==null&&this.deletes(l)?(c="update",o=He(l.content.getContent())):(c="add",o=void 0)}else if(this.deletes(i))c="delete",o=He(i.content.getContent());else return;t.set(r,{action:c,oldValue:o})}}),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 Y(hr);const n=this.target,s=et(),r=et(),i=[];if(t={added:s,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(n).has(null)){let o=null;const l=()=>{o&&i.push(o)};for(let h=n._start;h!==null;h=h.right)h.deleted?this.deletes(h)&&!this.adds(h)&&((o===null||o.delete===void 0)&&(l(),o={delete:0}),o.delete+=h.length,r.add(h)):this.adds(h)?((o===null||o.insert===void 0)&&(l(),o={insert:[]}),o.insert=o.insert.concat(h.content.getContent()),s.add(h)):((o===null||o.retain===void 0)&&(l(),o={retain:0}),o.retain+=h.length);o!==null&&o.retain===void 0&&l()}this._changes=t}return t}}const fo=(e,t)=>{const n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let s=0,r=t._item.parent._start;for(;r!==t._item&&r!==null;)!r.deleted&&r.countable&&(s+=r.length),r=r.right;n.unshift(s)}t=t._item.parent}return n},R=()=>{Nc("Invalid access: Add Yjs type to a document before reading data.")},ar=80;let xn=0;class go{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=xn++}}const po=e=>{e.timestamp=xn++},ur=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=xn++},wo=(e,t,n)=>{if(e.length>=ar){const s=e.reduce((r,i)=>r.timestamp<i.timestamp?r:i);return ur(s,t,n),s}else{const s=new go(t,n);return e.push(s),s}},Te=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;const n=e._searchMarker.length===0?null:e._searchMarker.reduce((i,c)=>oe(t-i.index)<oe(t-c.index)?i:c);let s=e._start,r=0;for(n!==null&&(s=n.p,r=n.index,po(n));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 n!==null&&oe(n.index-r)<s.parent.length/ar?(ur(n,s,r),n):wo(e._searchMarker,s,r)},Zt=(e,t,n)=>{for(let s=e.length-1;s>=0;s--){const r=e[s];if(n>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){e.splice(s,1);continue}r.p=i,i.marker=!0}(t<r.index||n>0&&t===r.index)&&(r.index=ht(t,r.index+n))}},Ue=(e,t,n)=>{const s=e,r=t.changedParentTypes;for(;N(r,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;tr(s._eH,n,t)};class O{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Qs(),this._dEH=Qs(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw J()}clone(){throw J()}_write(t){}get _first(){let t=this._start;for(;t!==null&&t.deleted;)t=t.right;return t}_callObserver(t,n){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){Zs(this._eH,t)}observeDeep(t){Zs(this._dEH,t)}unobserve(t){Ps(this._eH,t)}unobserveDeep(t){Ps(this._dEH,t)}toJSON(){}}const dr=(e,t,n)=>{e.doc??R(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let s=n-t;const r=[];let i=e._start;for(;i!==null&&s>0;){if(i.countable&&!i.deleted){const c=i.content.getContent();if(c.length<=t)t-=c.length;else{for(let o=t;o<c.length&&s>0;o++)r.push(c[o]),s--;t=0}}i=i.right}return r},fr=e=>{e.doc??R();const t=[];let n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){const s=n.content.getContent();for(let r=0;r<s.length;r++)t.push(s[r])}n=n.right}return t},Pt=(e,t)=>{let n=0,s=e._start;for(e.doc??R();s!==null;){if(s.countable&&!s.deleted){const r=s.content.getContent();for(let i=0;i<r.length;i++)t(r[i],n++,e)}s=s.right}},gr=(e,t)=>{const n=[];return Pt(e,(s,r)=>{n.push(t(s,r,e))}),n},mo=e=>{let t=e._start,n=null,s=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),s=0,t=t.right}const r=n[s++];return n.length<=s&&(n=null),{done:!1,value:r}}}},pr=(e,t)=>{e.doc??R();const n=Te(e,t);let s=e._start;for(n!==null&&(s=n.p,t-=n.index);s!==null;s=s.right)if(!s.deleted&&s.countable){if(t<s.length)return s.content.getContent()[t];t-=s.length}},Re=(e,t,n,s)=>{let r=n;const i=e.doc,c=i.clientID,o=i.store,l=n===null?t._start:n.right;let h=[];const a=()=>{h.length>0&&(r=new D(m(c,x(o,c)),r,r&&r.lastId,l,l&&l.id,t,null,new wt(h)),r.integrate(e,0),h=[])};s.forEach(u=>{if(u===null)h.push(u);else switch(u.constructor){case Number:case Object:case Boolean:case Array:case String:h.push(u);break;default:switch(a(),u.constructor){case Uint8Array:case ArrayBuffer:r=new D(m(c,x(o,c)),r,r&&r.lastId,l,l&&l.id,t,null,new te(new Uint8Array(u))),r.integrate(e,0);break;case It:r=new D(m(c,x(o,c)),r,r&&r.lastId,l,l&&l.id,t,null,new ne(u)),r.integrate(e,0);break;default:if(u instanceof O)r=new D(m(c,x(o,c)),r,r&&r.lastId,l,l&&l.id,t,null,new tt(u)),r.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),a()},wr=()=>Y("Length exceeded!"),mr=(e,t,n,s)=>{if(n>t._length)throw wr();if(n===0)return t._searchMarker&&Zt(t._searchMarker,n,s.length),Re(e,t,null,s);const r=n,i=Te(t,n);let c=t._start;for(i!==null&&(c=i.p,n-=i.index,n===0&&(c=c.prev,n+=c&&c.countable&&!c.deleted?c.length:0));c!==null;c=c.right)if(!c.deleted&&c.countable){if(n<=c.length){n<c.length&&it(e,m(c.id.client,c.id.clock+n));break}n-=c.length}return t._searchMarker&&Zt(t._searchMarker,r,s.length),Re(e,t,c,s)},ko=(e,t,n)=>{let r=(t._searchMarker||[]).reduce((i,c)=>c.index>i.index?c:i,{index:0,p:t._start}).p;if(r)for(;r.right;)r=r.right;return Re(e,t,r,n)},kr=(e,t,n,s)=>{if(s===0)return;const r=n,i=s,c=Te(t,n);let o=t._start;for(c!==null&&(o=c.p,n-=c.index);o!==null&&n>0;o=o.right)!o.deleted&&o.countable&&(n<o.length&&it(e,m(o.id.client,o.id.clock+n)),n-=o.length);for(;s>0&&o!==null;)o.deleted||(s<o.length&&it(e,m(o.id.client,o.id.clock+s)),o.delete(e),s-=o.length),o=o.right;if(s>0)throw wr();t._searchMarker&&Zt(t._searchMarker,r,-i+s)},Ne=(e,t,n)=>{const s=t._map.get(n);s!==void 0&&s.delete(e)},On=(e,t,n,s)=>{const r=t._map.get(n)||null,i=e.doc,c=i.clientID;let o;if(s==null)o=new wt([s]);else switch(s.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:o=new wt([s]);break;case Uint8Array:o=new te(s);break;case It:o=new ne(s);break;default:if(s instanceof O)o=new tt(s);else throw new Error("Unexpected content type")}new D(m(c,x(i.store,c)),r,r&&r.lastId,null,null,t,n,o).integrate(e,0)},Ln=(e,t)=>{e.doc??R();const n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},yr=e=>{const t={};return e.doc??R(),e._map.forEach((n,s)=>{n.deleted||(t[s]=n.content.getContent()[n.length-1])}),t},br=(e,t)=>{e.doc??R();const n=e._map.get(t);return n!==void 0&&!n.deleted},yo=(e,t)=>{const n={};return e._map.forEach((s,r)=>{let i=s;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&Lt(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},ve=e=>(e.doc??R(),vc(e._map.entries(),t=>!t[1].deleted));class bo extends Le{}class Tt extends O{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const n=new Tt;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Tt}clone(){const t=new Tt;return t.insert(0,this.toArray().map(n=>n instanceof O?n.clone():n)),t}get length(){return this.doc??R(),this._length}_callObserver(t,n){super._callObserver(t,n),Ue(this,t,new bo(this,t))}insert(t,n){this.doc!==null?y(this.doc,s=>{mr(s,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?y(this.doc,n=>{ko(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?y(this.doc,s=>{kr(s,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return pr(this,t)}toArray(){return fr(this)}slice(t=0,n=this.length){return dr(this,t,n)}toJSON(){return this.map(t=>t instanceof O?t.toJSON():t)}map(t){return gr(this,t)}forEach(t){Pt(this,t)}[Symbol.iterator](){return mo(this)}_write(t){t.writeTypeRef(Wo)}}const _o=e=>new Tt;class So extends Le{constructor(t,n,s){super(t,n),this.keysChanged=s}}class P extends O{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,n){super._integrate(t,n),this._prelimContent.forEach((s,r)=>{this.set(r,s)}),this._prelimContent=null}_copy(){return new P}clone(){const t=new P;return this.forEach((n,s)=>{t.set(s,n instanceof O?n.clone():n)}),t}_callObserver(t,n){Ue(this,t,new So(this,t,n))}toJSON(){this.doc??R();const t={};return this._map.forEach((n,s)=>{if(!n.deleted){const r=n.content.getContent()[n.length-1];t[s]=r instanceof O?r.toJSON():r}}),t}get size(){return[...ve(this)].length}keys(){return mn(ve(this),t=>t[0])}values(){return mn(ve(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return mn(ve(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this.doc??R(),this._map.forEach((n,s)=>{n.deleted||t(n.content.getContent()[n.length-1],s,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?y(this.doc,n=>{Ne(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?y(this.doc,s=>{On(s,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return Ln(this,t)}has(t){return br(this,t)}clear(){this.doc!==null?y(this.doc,t=>{this.forEach(function(n,s,r){Ne(t,r,s)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(zo)}}const Eo=e=>new P,ot=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&Li(e,t);class Tn{constructor(t,n,s,r){this.left=t,this.right=n,this.index=s,this.currentAttributes=r}forward(){switch(this.right===null&&B(),this.right.content.constructor){case C:this.right.deleted||Ut(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 _r=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case C:t.right.deleted||Ut(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&it(e,m(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length);break}t.left=t.right,t.right=t.right.right}return t},$e=(e,t,n,s)=>{const r=new Map,i=s?Te(t,n):null;if(i){const c=new Tn(i.p.left,i.p,i.index,r);return _r(e,c,n-i.index)}else{const c=new Tn(null,t._start,0,r);return _r(e,c,n)}},Sr=(e,t,n,s)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===C&&ot(s.get(n.right.content.key),n.right.content.value));)n.right.deleted||s.delete(n.right.content.key),n.forward();const r=e.doc,i=r.clientID;s.forEach((c,o)=>{const l=n.left,h=n.right,a=new D(m(i,x(r.store,i)),l,l&&l.lastId,h,h&&h.id,t,null,new C(o,c));a.integrate(e,0),n.right=a,n.forward()})},Ut=(e,t)=>{const{key:n,value:s}=t;s===null?e.delete(n):e.set(n,s)},Er=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===C&&ot(t[e.right.content.key]??null,e.right.content.value)))break;e.forward()}},Cr=(e,t,n,s)=>{const r=e.doc,i=r.clientID,c=new Map;for(const o in s){const l=s[o],h=n.currentAttributes.get(o)??null;if(!ot(h,l)){c.set(o,h);const{left:a,right:u}=n;n.right=new D(m(i,x(r.store,i)),a,a&&a.lastId,u,u&&u.id,t,null,new C(o,l)),n.right.integrate(e,0),n.forward()}}return c},Un=(e,t,n,s,r)=>{n.currentAttributes.forEach((d,f)=>{r[f]===void 0&&(r[f]=null)});const i=e.doc,c=i.clientID;Er(n,r);const o=Cr(e,t,n,r),l=s.constructor===String?new G(s):s instanceof O?new tt(s):new pt(s);let{left:h,right:a,index:u}=n;t._searchMarker&&Zt(t._searchMarker,n.index,l.getLength()),a=new D(m(c,x(i.store,c)),h,h&&h.lastId,a,a&&a.id,t,null,l),a.integrate(e,0),n.right=a,n.index=u,n.forward(),Sr(e,t,n,o)},Dr=(e,t,n,s,r)=>{const i=e.doc,c=i.clientID;Er(n,r);const o=Cr(e,t,n,r);t:for(;n.right!==null&&(s>0||o.size>0&&(n.right.deleted||n.right.content.constructor===C));){if(!n.right.deleted)switch(n.right.content.constructor){case C:{const{key:l,value:h}=n.right.content,a=r[l];if(a!==void 0){if(ot(a,h))o.delete(l);else{if(s===0)break t;o.set(l,h)}n.right.delete(e)}else n.currentAttributes.set(l,h);break}default:s<n.right.length&&it(e,m(n.right.id.client,n.right.id.clock+s)),s-=n.right.length;break}n.forward()}if(s>0){let l="";for(;s>0;s--)l+=`
4
+ `;n.right=new D(m(c,x(i.store,c)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new G(l)),n.right.integrate(e,0),n.forward()}Sr(e,t,n,o)},Ar=(e,t,n,s,r)=>{let i=t;const c=S();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===C){const h=i.content;c.set(h.key,h)}i=i.right}let o=0,l=!1;for(;t!==i;){if(n===t&&(l=!0),!t.deleted){const h=t.content;switch(h.constructor){case C:{const{key:a,value:u}=h,d=s.get(a)??null;(c.get(a)!==h||d===u)&&(t.delete(e),o++,!l&&(r.get(a)??null)===u&&d!==u&&(d===null?r.delete(a):r.set(a,d))),!l&&!t.deleted&&Ut(r,h);break}}}t=t.right}return o},Co=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===C){const s=t.content.key;n.has(s)?t.delete(e):n.add(s)}t=t.left}},Do=e=>{let t=0;return y(e.doc,n=>{let s=e._start,r=e._start,i=S();const c=j(i);for(;r;){if(r.deleted===!1)switch(r.content.constructor){case C:Ut(c,r.content);break;default:t+=Ar(n,s,r,i,c),i=j(c),s=r;break}r=r.right}}),t},Ao=e=>{const t=new Set,n=e.doc;for(const[s,r]of e.afterState.entries()){const i=e.beforeState.get(s)||0;r!==i&&rr(e,n.store.clients.get(s),i,r,c=>{!c.deleted&&c.content.constructor===C&&c.constructor!==V&&t.add(c.parent)})}y(n,s=>{js(e,e.deleteSet,r=>{if(r instanceof V||!r.parent._hasFormatting||t.has(r.parent))return;const i=r.parent;r.content.constructor===C?t.add(i):Co(s,r)});for(const r of t)Do(r)})},Ir=(e,t,n)=>{const s=n,r=j(t.currentAttributes),i=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case tt:case pt:case G:n<t.right.length&&it(e,m(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}i&&Ar(e,i,t.right,r,t.currentAttributes);const c=(t.left||t.right).parent;return c._searchMarker&&Zt(c._searchMarker,t.index,-s+n),t};class Io extends Le{constructor(t,n,s){super(t,n),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,n=[];y(t,s=>{const r=new Map,i=new Map;let c=this.target._start,o=null;const l={};let h="",a=0,u=0;const d=()=>{if(o!==null){let f=null;switch(o){case"delete":u>0&&(f={delete:u}),u=0;break;case"insert":(typeof h=="object"||h.length>0)&&(f={insert:h},r.size>0&&(f.attributes={},r.forEach((g,k)=>{g!==null&&(f.attributes[k]=g)}))),h="";break;case"retain":a>0&&(f={retain:a},Oi(l)||(f.attributes=Di({},l))),a=0;break}f&&n.push(f),o=null}};for(;c!==null;){switch(c.content.constructor){case tt:case pt:this.adds(c)?this.deletes(c)||(d(),o="insert",h=c.content.getContent()[0],d()):this.deletes(c)?(o!=="delete"&&(d(),o="delete"),u+=1):c.deleted||(o!=="retain"&&(d(),o="retain"),a+=1);break;case G:this.adds(c)?this.deletes(c)||(o!=="insert"&&(d(),o="insert"),h+=c.content.str):this.deletes(c)?(o!=="delete"&&(d(),o="delete"),u+=c.length):c.deleted||(o!=="retain"&&(d(),o="retain"),a+=c.length);break;case C:{const{key:f,value:g}=c.content;if(this.adds(c)){if(!this.deletes(c)){const k=r.get(f)??null;ot(k,g)?g!==null&&c.delete(s):(o==="retain"&&d(),ot(g,i.get(f)??null)?delete l[f]:l[f]=g)}}else if(this.deletes(c)){i.set(f,g);const k=r.get(f)??null;ot(k,g)||(o==="retain"&&d(),l[f]=k)}else if(!c.deleted){i.set(f,g);const k=l[f];k!==void 0&&(ot(k,g)?k!==null&&c.delete(s):(o==="retain"&&d(),g===null?delete l[f]:l[f]=g))}c.deleted||(o==="insert"&&d(),Ut(r,c.content));break}}c=c.right}for(d();n.length>0;){const f=n[n.length-1];if(f.retain!==void 0&&f.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}}class Rt extends O{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??R(),this._length}_integrate(t,n){super._integrate(t,n);try{this._pending.forEach(s=>s())}catch(s){console.error(s)}this._pending=null}_copy(){return new Rt}clone(){const t=new Rt;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);const s=new Io(this,t,n);Ue(this,t,s),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??R();let t="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===G&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){this.doc!==null?y(this.doc,s=>{const r=new Tn(null,this._start,0,new Map);for(let i=0;i<t.length;i++){const c=t[i];if(c.insert!==void 0){const o=!n&&typeof c.insert=="string"&&i===t.length-1&&r.right===null&&c.insert.slice(-1)===`
5
+ `?c.insert.slice(0,-1):c.insert;(typeof o!="string"||o.length>0)&&Un(s,this,r,o,c.attributes||{})}else c.retain!==void 0?Dr(s,this,r,c.retain,c.attributes||{}):c.delete!==void 0&&Ir(s,r,c.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,s){this.doc??R();const r=[],i=new Map,c=this.doc;let o="",l=this._start;function h(){if(o.length>0){const u={};let d=!1;i.forEach((g,k)=>{d=!0,u[k]=g});const f={insert:o};d&&(f.attributes=u),r.push(f),o=""}}const a=()=>{for(;l!==null;){if(Lt(l,t)||n!==void 0&&Lt(l,n))switch(l.content.constructor){case G:{const u=i.get("ychange");t!==void 0&&!Lt(l,t)?(u===void 0||u.user!==l.id.client||u.type!=="removed")&&(h(),i.set("ychange",s?s("removed",l.id):{type:"removed"})):n!==void 0&&!Lt(l,n)?(u===void 0||u.user!==l.id.client||u.type!=="added")&&(h(),i.set("ychange",s?s("added",l.id):{type:"added"})):u!==void 0&&(h(),i.delete("ychange")),o+=l.content.str;break}case tt:case pt:{h();const u={insert:l.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:Lt(l,t)&&(h(),Ut(i,l.content));break}l=l.right}h()};return t||n?y(c,u=>{t&&Sn(u,t),n&&Sn(u,n),a()},"cleanup"):a(),r}insert(t,n,s){if(n.length<=0)return;const r=this.doc;r!==null?y(r,i=>{const c=$e(i,this,t,!s);s||(s={},c.currentAttributes.forEach((o,l)=>{s[l]=o})),Un(i,this,c,n,s)}):this._pending.push(()=>this.insert(t,n,s))}insertEmbed(t,n,s){const r=this.doc;r!==null?y(r,i=>{const c=$e(i,this,t,!s);Un(i,this,c,n,s||{})}):this._pending.push(()=>this.insertEmbed(t,n,s||{}))}delete(t,n){if(n===0)return;const s=this.doc;s!==null?y(s,r=>{Ir(r,$e(r,this,t,!0),n)}):this._pending.push(()=>this.delete(t,n))}format(t,n,s){if(n===0)return;const r=this.doc;r!==null?y(r,i=>{const c=$e(i,this,t,!1);c.right!==null&&Dr(i,this,c,n,s)}):this._pending.push(()=>this.format(t,n,s))}removeAttribute(t){this.doc!==null?y(this.doc,n=>{Ne(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?y(this.doc,s=>{On(s,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return Ln(this,t)}getAttributes(){return yr(this)}_write(t){t.writeTypeRef(Go)}}const xo=e=>new Rt;class Rn{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??R()}[Symbol.iterator](){return this}next(){let t=this._currentNode,n=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(n)))do if(n=t.content.type,!t.deleted&&(n.constructor===Nt||n.constructor===gt)&&n._start!==null)t=n._start;else for(;t!==null;){const s=t.next;if(s!==null){t=s;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 gt extends O{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new gt}clone(){const t=new gt;return t.insert(0,this.toArray().map(n=>n instanceof O?n.clone():n)),t}get length(){return this.doc??R(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new Rn(this,t)}querySelector(t){t=t.toUpperCase();const s=new Rn(this,r=>r.nodeName&&r.nodeName.toUpperCase()===t).next();return s.done?null:s.value}querySelectorAll(t){return t=t.toUpperCase(),X(new Rn(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){Ue(this,t,new To(this,n,t))}toString(){return gr(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,n={},s){const r=t.createDocumentFragment();return s!==void 0&&s._createAssociation(r,this),Pt(this,i=>{r.insertBefore(i.toDOM(t,n,s),null)}),r}insert(t,n){this.doc!==null?y(this.doc,s=>{mr(s,this,t,n)}):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(this.doc!==null)y(this.doc,s=>{const r=t&&t instanceof O?t._item:t;Re(s,this,r,n)});else{const s=this._prelimContent,r=t===null?0:s.findIndex(i=>i===t)+1;if(r===0&&t!==null)throw Y("Reference item not found");s.splice(r,0,...n)}}delete(t,n=1){this.doc!==null?y(this.doc,s=>{kr(s,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return fr(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return pr(this,t)}slice(t=0,n=this.length){return dr(this,t,n)}forEach(t){Pt(this,t)}_write(t){t.writeTypeRef(Xo)}}const Oo=e=>new gt;class Nt extends gt{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,n){super._integrate(t,n),this._prelimAttrs.forEach((s,r)=>{this.setAttribute(r,s)}),this._prelimAttrs=null}_copy(){return new Nt(this.nodeName)}clone(){const t=new Nt(this.nodeName),n=this.getAttributes();return Ii(n,(s,r)=>{t.setAttribute(r,s)}),t.insert(0,this.toArray().map(s=>s instanceof O?s.clone():s)),t}toString(){const t=this.getAttributes(),n=[],s=[];for(const o in t)s.push(o);s.sort();const r=s.length;for(let o=0;o<r;o++){const l=s[o];n.push(l+'="'+t[l]+'"')}const i=this.nodeName.toLocaleLowerCase(),c=n.length>0?" "+n.join(" "):"";return`<${i}${c}>${super.toString()}</${i}>`}removeAttribute(t){this.doc!==null?y(this.doc,n=>{Ne(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?y(this.doc,s=>{On(s,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return Ln(this,t)}hasAttribute(t){return br(this,t)}getAttributes(t){return t?yo(this,t):yr(this)}toDOM(t=document,n={},s){const r=t.createElement(this.nodeName),i=this.getAttributes();for(const c in i){const o=i[c];typeof o=="string"&&r.setAttribute(c,o)}return Pt(this,c=>{r.appendChild(c.toDOM(t,n,s))}),s!==void 0&&s._createAssociation(r,this),r}_write(t){t.writeTypeRef(Ko),t.writeKey(this.nodeName)}}const Lo=e=>new Nt(e.readKey());class To extends Le{constructor(t,n,s){super(t,s),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(r=>{r===null?this.childListChanged=!0:this.attributesChanged.add(r)})}}class Be extends P{constructor(t){super(),this.hookName=t}_copy(){return new Be(this.hookName)}clone(){const t=new Be(this.hookName);return this.forEach((n,s)=>{t.set(s,n)}),t}toDOM(t=document,n={},s){const r=n[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(qo),t.writeKey(this.hookName)}}const Uo=e=>new Be(e.readKey());class Ve extends Rt{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 Ve}clone(){const t=new Ve;return t.applyDelta(this.toDelta()),t}toDOM(t=document,n,s){const r=t.createTextNode(this.toString());return s!==void 0&&s._createAssociation(r,this),r}toString(){return this.toDelta().map(t=>{const n=[];for(const r in t.attributes){const i=[];for(const c in t.attributes[r])i.push({key:c,value:t.attributes[r][c]});i.sort((c,o)=>c.key<o.key?-1:1),n.push({nodeName:r,attrs:i})}n.sort((r,i)=>r.nodeName<i.nodeName?-1:1);let s="";for(let r=0;r<n.length;r++){const i=n[r];s+=`<${i.nodeName}`;for(let c=0;c<i.attrs.length;c++){const o=i.attrs[c];s+=` ${o.key}="${o.value}"`}s+=">"}s+=t.insert;for(let r=n.length-1;r>=0;r--)s+=`</${n[r].nodeName}>`;return s}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(Qo)}}const Ro=e=>new Ve;class Nn{constructor(t,n){this.id=t,this.length=n}get deleted(){throw J()}mergeWith(t){return!1}write(t,n,s){throw J()}integrate(t,n){throw J()}}const No=0;class V extends Nn{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){n>0&&(this.id.clock+=n,this.length-=n),nr(t.doc.store,this)}write(t,n){t.writeInfo(No),t.writeLen(this.length-n)}getMissing(t,n){return null}}class te{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new te(this.content)}splice(t){throw J()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}}const vo=e=>new te(e.readBuf());class ee{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new ee(this.len)}splice(t){const n=new ee(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){De(t.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(t){}gc(t){}write(t,n){t.writeLen(this.len-n)}getRef(){return 1}}const $o=e=>new ee(e.readLen()),xr=(e,t)=>new It({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class ne{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 n={};this.opts=n,t.gc||(n.gc=!1),t.autoLoad&&(n.autoLoad=!0),t.meta!==null&&(n.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new ne(xr(this.doc.guid,this.opts))}splice(t){throw J()}mergeWith(t){return!1}integrate(t,n){this.doc._item=n,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,n){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}}const Bo=e=>new ne(xr(e.readString(),e.readAny()));class pt{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new pt(this.embed)}splice(t){throw J()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}}const Vo=e=>new pt(e.readJSON());class C{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new C(this.key,this.value)}splice(t){throw J()}mergeWith(t){return!1}integrate(t,n){const s=n.parent;s._searchMarker=null,s._hasFormatting=!0}delete(t){}gc(t){}write(t,n){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}}const Fo=e=>new C(e.readKey(),e.readJSON());class Fe{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new Fe(this.arr)}splice(t){const n=new Fe(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const s=this.arr.length;t.writeLen(s-n);for(let r=n;r<s;r++){const i=this.arr[r];t.writeString(i===void 0?"undefined":JSON.stringify(i))}}getRef(){return 2}}const jo=e=>{const t=e.readLen(),n=[];for(let s=0;s<t;s++){const r=e.readString();r==="undefined"?n.push(void 0):n.push(JSON.parse(r))}return new Fe(n)},Mo=pe("node_env")==="development";class wt{constructor(t){this.arr=t,Mo&&ds(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new wt(this.arr)}splice(t){const n=new wt(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const s=this.arr.length;t.writeLen(s-n);for(let r=n;r<s;r++){const i=this.arr[r];t.writeAny(i)}}getRef(){return 8}}const Jo=e=>{const t=e.readLen(),n=[];for(let s=0;s<t;s++)n.push(e.readAny());return new wt(n)};class G{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new G(this.str)}splice(t){const n=new G(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)+"�",n.str="�"+n.str.slice(1)),n}mergeWith(t){return this.str+=t.str,!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeString(n===0?this.str:this.str.slice(n))}getRef(){return 4}}const Ho=e=>new G(e.readString()),Yo=[_o,Eo,xo,Lo,Oo,Uo,Ro],Wo=0,zo=1,Go=2,Ko=3,Xo=4,qo=5,Qo=6;class tt{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new tt(this.type._copy())}splice(t){throw J()}mergeWith(t){return!1}integrate(t,n){this.type._integrate(t.doc,n)}delete(t){let n=this.type._start;for(;n!==null;)n.deleted?n.id.clock<(t.beforeState.get(n.id.client)||0)&&t._mergeStructs.push(n):n.delete(t),n=n.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 n=this.type._start;for(;n!==null;)n.gc(t,!0),n=n.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,n){this.type._write(t)}getRef(){return 7}}const Zo=e=>new tt(Yo[e.readTypeRef()](e)),je=(e,t,n)=>{const{client:s,clock:r}=t.id,i=new D(m(s,r+n),t,m(s,r+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&i.markDeleted(),t.keep&&(i.keep=!0),t.redone!==null&&(i.redone=m(t.redone.client,t.redone.clock+n)),t.right=i,i.right!==null&&(i.right.left=i),e._mergeStructs.push(i),i.parentSub!==null&&i.right===null&&i.parent._map.set(i.parentSub,i),t.length=n,i};class D extends Nn{constructor(t,n,s,r,i,c,o,l){super(t,l.getLength()),this.origin=s,this.left=n,this.right=r,this.rightOrigin=i,this.parent=c,this.parentSub=o,this.redone=null,this.content=l,this.info=this.content.isCountable()?Xn:0}set marker(t){(this.info&Ge)>0!==t&&(this.info^=Ge)}get marker(){return(this.info&Ge)>0}get keep(){return(this.info&Kn)>0}set keep(t){this.keep!==t&&(this.info^=Kn)}get countable(){return(this.info&Xn)>0}get deleted(){return(this.info&ze)>0}set deleted(t){this.deleted!==t&&(this.info^=ze)}markDeleted(){this.info|=ze}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=x(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=x(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Ot&&this.id.client!==this.parent.client&&this.parent.clock>=x(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=sr(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=it(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===V||this.right&&this.right.constructor===V)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===D?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===D&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Ot){const s=En(n,this.parent);s.constructor===V?this.parent=null:this.parent=s.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=sr(t,t.doc.store,m(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),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,c=new Set;for(;r!==null&&r!==this.right;){if(c.add(r),i.add(r),Ae(this.origin,r.origin)){if(r.id.client<this.id.client)s=r,i.clear();else if(Ae(this.rightOrigin,r.rightOrigin))break}else if(r.origin!==null&&c.has(En(t.doc.store,r.origin)))i.has(En(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),nr(t.doc.store,this),this.content.integrate(t,this),cr(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new V(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:m(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Ae(t.origin,this.lastId)&&this.right===t&&Ae(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 n=this.parent._searchMarker;return n&&n.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 n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),De(t.deleteSet,this.id.client,this.id.clock,this.length),cr(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw B();this.content.gc(t),n?no(t,this,new V(this.id,this.length)):this.content=new ee(this.length)}write(t,n){const s=n>0?m(this.id.client,this.id.clock+n-1):this.origin,r=this.rightOrigin,i=this.parentSub,c=this.content.getRef()&le|(s===null?0:$)|(r===null?0:q)|(i===null?0:Mt);if(t.writeInfo(c),s!==null&&t.writeLeftID(s),r!==null&&t.writeRightID(r),s===null&&r===null){const o=this.parent;if(o._item!==void 0){const l=o._item;if(l===null){const h=eo(o);t.writeParentInfo(!0),t.writeString(h)}else t.writeParentInfo(!1),t.writeLeftID(l.id)}else o.constructor===String?(t.writeParentInfo(!0),t.writeString(o)):o.constructor===Ot?(t.writeParentInfo(!1),t.writeLeftID(o)):B();i!==null&&t.writeString(i)}this.content.write(t,n)}}const Or=(e,t)=>Po[t&le](e),Po=[()=>{B()},$o,jo,vo,Ho,Vo,Fo,Zo,Jo,Bo,()=>{B()}],tl=10;class F extends Nn{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){B()}write(t,n){t.writeInfo(tl),p(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const Lr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Tr="__ $YJS$ __";Lr[Tr]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),Lr[Tr]=!0;const Ur=new Map;class el{constructor(t){this.room=t,this.onmessage=null,this._onChange=n=>n.key===t&&this.onmessage!==null&&this.onmessage({data:Yi(n.newValue||"")}),Si(this._onChange)}postMessage(t){as.setItem(this.room,Hi(Vi(t)))}close(){Ei(this._onChange)}}const nl=typeof BroadcastChannel>"u"?el:BroadcastChannel,vn=e=>N(Ur,e,()=>{const t=et(),n=new nl(e);return n.onmessage=s=>t.forEach(r=>r(s.data,"broadcastchannel")),{bc:n,subs:t}}),sl=(e,t)=>(vn(e).subs.add(t),t),rl=(e,t)=>{const n=vn(e),s=n.subs.delete(t);return s&&n.subs.size===0&&(n.bc.close(),Ur.delete(e)),s},vt=(e,t,n=null)=>{const s=vn(e);s.bc.postMessage(t),s.subs.forEach(r=>r(t,n))},Rr=0,$n=1,Nr=2,Bn=(e,t)=>{p(e,Rr);const n=Pc(t);_(e,n)},vr=(e,t,n)=>{p(e,$n),_(e,Xc(t,n))},il=(e,t,n)=>vr(t,n,T(e)),$r=(e,t,n,s)=>{try{zc(t,T(e),n)}catch(r){s!=null&&s(r),console.error("Caught error while handling a Yjs update",r)}},cl=(e,t)=>{p(e,Nr),_(e,t)},ol=$r,ll=(e,t,n,s,r)=>{const i=w(e);switch(i){case Rr:il(e,t,n);break;case $n:$r(e,n,s,r);break;case Nr:ol(e,n,s,r);break;default:throw new Error("Unknown message type")}return i},hl=0,al=(e,t,n)=>{switch(w(e)){case hl:n(t,st(e))}},Vn=3e4;class ul extends Kr{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{const n=dt();this.getLocalState()!==null&&Vn/2<=n-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const s=[];this.meta.forEach((r,i)=>{i!==this.clientID&&Vn<=n-r.lastUpdated&&this.states.has(i)&&s.push(i)}),s.length>0&&Fn(this,s,"timeout")},M(Vn/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 n=this.clientID,s=this.meta.get(n),r=s===void 0?0:s.clock+1,i=this.states.get(n);t===null?this.states.delete(n):this.states.set(n,t),this.meta.set(n,{clock:r,lastUpdated:dt()});const c=[],o=[],l=[],h=[];t===null?h.push(n):i==null?t!=null&&c.push(n):(o.push(n),_t(i,t)||l.push(n)),(c.length>0||l.length>0||h.length>0)&&this.emit("change",[{added:c,updated:l,removed:h},"local"]),this.emit("update",[{added:c,updated:o,removed:h},"local"])}setLocalStateField(t,n){const s=this.getLocalState();s!==null&&this.setLocalState({...s,[t]:n})}getStates(){return this.states}}const Fn=(e,t,n)=>{const s=[];for(let r=0;r<t.length;r++){const i=t[r];if(e.states.has(i)){if(e.states.delete(i),i===e.clientID){const c=e.meta.get(i);e.meta.set(i,{clock:c.clock+1,lastUpdated:dt()})}s.push(i)}}s.length>0&&(e.emit("change",[{added:[],updated:[],removed:s},n]),e.emit("update",[{added:[],updated:[],removed:s},n]))},se=(e,t,n=e.states)=>{const s=t.length,r=L();p(r,s);for(let i=0;i<s;i++){const c=t[i],o=n.get(c)||null,l=e.meta.get(c).clock;p(r,c),p(r,l),ut(r,JSON.stringify(o))}return b(r)},dl=(e,t,n)=>{const s=nt(t),r=dt(),i=[],c=[],o=[],l=[],h=w(s);for(let a=0;a<h;a++){const u=w(s);let d=w(s);const f=JSON.parse(st(s)),g=e.meta.get(u),k=e.states.get(u),H=g===void 0?0:g.clock;(H<d||H===d&&f===null&&e.states.has(u))&&(f===null?u===e.clientID&&e.getLocalState()!=null?d++:e.states.delete(u):e.states.set(u,f),e.meta.set(u,{clock:d,lastUpdated:r}),g===void 0&&f!==null?i.push(u):g!==void 0&&f===null?l.push(u):f!==null&&(_t(f,k)||o.push(u),c.push(u)))}(i.length>0||o.length>0||l.length>0)&&e.emit("change",[{added:i,updated:o,removed:l},n]),(i.length>0||c.length>0||l.length>0)&&e.emit("update",[{added:i,updated:c,removed:l},n])},fl=e=>xi(e,(t,n)=>`${encodeURIComponent(n)}=${encodeURIComponent(t)}`).join("&"),mt=0,Br=3,$t=1,gl=2,re=[];re[mt]=(e,t,n,s,r)=>{p(e,mt);const i=ll(t,e,n.doc,n);s&&i===$n&&!n.synced&&(n.synced=!0)},re[Br]=(e,t,n,s,r)=>{p(e,$t),_(e,se(n.awareness,Array.from(n.awareness.getStates().keys())))},re[$t]=(e,t,n,s,r)=>{dl(n.awareness,T(t),n)},re[gl]=(e,t,n,s,r)=>{al(t,n.doc,(i,c)=>pl(n,c))};const Vr=3e4,pl=(e,t)=>console.warn(`Permission denied to access ${e.url}.
6
+ ${t}`),Fr=(e,t,n)=>{const s=nt(t),r=L(),i=w(s),c=e.messageHandlers[i];return c?c(r,s,e,n,i):console.error("Unable to compute message"),r},jn=(e,t,n)=>{t===e.ws&&(e.emit("connection-close",[n,e]),e.ws=null,t.close(),e.wsconnecting=!1,e.wsconnected?(e.wsconnected=!1,e.synced=!1,Fn(e.awareness,Array.from(e.awareness.getStates().keys()).filter(s=>s!==e.doc.clientID),e),e.emit("status",[{status:"disconnected"}])):e.wsUnsuccessfulReconnects++,setTimeout(jr,We(Xr(2,e.wsUnsuccessfulReconnects)*100,e.maxBackoffTime),e))},jr=e=>{if(e.shouldConnect&&e.ws===null){const t=new e._WS(e.url,e.protocols);t.binaryType="arraybuffer",e.ws=t,e.wsconnecting=!0,e.wsconnected=!1,e.synced=!1,t.onmessage=n=>{e.wsLastMessageReceived=dt();const s=Fr(e,new Uint8Array(n.data),!0);Xe(s)>1&&t.send(b(s))},t.onerror=n=>{e.emit("connection-error",[n,e])},t.onclose=n=>{jn(e,t,n)},t.onopen=()=>{e.wsLastMessageReceived=dt(),e.wsconnecting=!1,e.wsconnected=!0,e.wsUnsuccessfulReconnects=0,e.emit("status",[{status:"connected"}]);const n=L();if(p(n,mt),Bn(n,e.doc),t.send(b(n)),e.awareness.getLocalState()!==null){const s=L();p(s,$t),_(s,se(e.awareness,[e.doc.clientID])),t.send(b(s))}},e.emit("status",[{status:"connecting"}])}},Mn=(e,t)=>{const n=e.ws;e.wsconnected&&n&&n.readyState===n.OPEN&&n.send(t),e.bcconnected&&vt(e.bcChannel,t,e)};class wl extends zn{constructor(t,n,s,{connect:r=!0,awareness:i=new ul(s),params:c={},protocols:o=[],WebSocketPolyfill:l=WebSocket,resyncInterval:h=-1,maxBackoffTime:a=2500,disableBc:u=!1}={}){for(super();t[t.length-1]==="/";)t=t.slice(0,t.length-1);this.serverUrl=t,this.bcChannel=t+"/"+n,this.maxBackoffTime=a,this.params=c,this.protocols=o,this.roomname=n,this.doc=s,this._WS=l,this.awareness=i,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=u,this.wsUnsuccessfulReconnects=0,this.messageHandlers=re.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=r,this._resyncInterval=0,h>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const d=L();p(d,mt),Bn(d,s),this.ws.send(b(d))}},h)),this._bcSubscriber=(d,f)=>{if(f!==this){const g=Fr(this,new Uint8Array(d),!1);Xe(g)>1&&vt(this.bcChannel,b(g),this)}},this._updateHandler=(d,f)=>{if(f!==this){const g=L();p(g,mt),cl(g,d),Mn(this,b(g))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:d,updated:f,removed:g},k)=>{const H=d.concat(f).concat(g),Yn=L();p(Yn,$t),_(Yn,se(i,H)),Mn(this,b(Yn))},this._exitHandler=()=>{Fn(this.awareness,[s.clientID],"app closed")},rt&&typeof process<"u"&&process.on("exit",this._exitHandler),i.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&Vr<dt()-this.wsLastMessageReceived&&jn(this,this.ws,null)},Vr/10),r&&this.connect()}get url(){const t=fl(this.params);return this.serverUrl+"/"+this.roomname+(t.length===0?"":"?"+t)}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(),rt&&typeof process<"u"&&process.off("exit",this._exitHandler),this.awareness.off("update",this._awarenessUpdateHandler),this.doc.off("update",this._updateHandler),super.destroy()}connectBc(){if(this.disableBc)return;this.bcconnected||(sl(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const t=L();p(t,mt),Bn(t,this.doc),vt(this.bcChannel,b(t),this);const n=L();p(n,mt),vr(n,this.doc),vt(this.bcChannel,b(n),this);const s=L();p(s,Br),vt(this.bcChannel,b(s),this);const r=L();p(r,$t),_(r,se(this.awareness,[this.doc.clientID])),vt(this.bcChannel,b(r),this)}disconnectBc(){const t=L();p(t,$t),_(t,se(this.awareness,[this.doc.clientID],new Map)),Mn(this,b(t)),this.bcconnected&&(rl(this.bcChannel,this._bcSubscriber),this.bcconnected=!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&jn(this,this.ws,null)}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(jr(this),this.connectBc())}}const Mr=["id","type","x","y","width","height","rotation","isLocked","isVisible","sortOrder"],Jn=["strokeColor","fillColor","strokeWidth","opacity","strokeStyle","roughness","fontSize","fontFamily"];function ml(e,t){const n=e;for(const s of Mr){const r=n[s];r!==void 0&&t.set(s,r)}if(e.style)for(const s of Jn)t.set(`style.${s}`,e.style[s]);switch(e.boundElements?t.set("boundElements",JSON.stringify(e.boundElements)):t.set("boundElements",null),e.groupIds&&t.set("groupIds",JSON.stringify(e.groupIds)),e.type){case"rectangle":t.set("cornerRadius",e.cornerRadius);break;case"line":case"arrow":t.set("points",JSON.stringify(e.points)),t.set("lineType",e.lineType),e.curvature!==void 0&&t.set("curvature",e.curvature),t.set("startBinding",e.startBinding?JSON.stringify(e.startBinding):null),t.set("endBinding",e.endBinding?JSON.stringify(e.endBinding):null),e.type==="arrow"&&(t.set("startArrowhead",e.startArrowhead),t.set("endArrowhead",e.endArrowhead));break;case"freedraw":t.set("points",JSON.stringify(e.points));break;case"text":t.set("text",e.text),t.set("containerId",e.containerId),t.set("textAlign",e.textAlign),t.set("verticalAlign",e.verticalAlign);break;case"image":t.set("src",e.src),t.set("naturalWidth",e.naturalWidth),t.set("naturalHeight",e.naturalHeight),t.set("scaleMode",e.scaleMode),t.set("crop",e.crop?JSON.stringify(e.crop):null),t.set("cornerRadius",e.cornerRadius),t.set("alt",e.alt);break}}function Hn(e){const t=e.get("type"),n=e.get("id");if(!t||!n)return null;const s={};for(const i of Jn){const c=e.get(`style.${i}`);c!==void 0&&(s[i]=c)}const r={id:n,type:t,x:e.get("x")??0,y:e.get("y")??0,width:e.get("width")??100,height:e.get("height")??100,rotation:e.get("rotation")??0,isLocked:e.get("isLocked")??!1,isVisible:e.get("isVisible")??!0,style:s,boundElements:kt(e.get("boundElements"))??null,groupIds:kt(e.get("groupIds"))??void 0,sortOrder:e.get("sortOrder")??void 0};switch(t){case"rectangle":r.cornerRadius=e.get("cornerRadius")??0;break;case"line":case"arrow":r.points=kt(e.get("points"))??[0,0,100,0],r.lineType=e.get("lineType")??"sharp",r.curvature=e.get("curvature")??void 0,r.startBinding=kt(e.get("startBinding")),r.endBinding=kt(e.get("endBinding")),t==="arrow"&&(r.startArrowhead=e.get("startArrowhead")??null,r.endArrowhead=e.get("endArrowhead")??"arrow");break;case"freedraw":r.points=kt(e.get("points"))??[];break;case"text":r.text=e.get("text")??"",r.containerId=e.get("containerId")??null,r.textAlign=e.get("textAlign")??"center",r.verticalAlign=e.get("verticalAlign")??"middle";break;case"image":r.src=e.get("src")??"",r.naturalWidth=e.get("naturalWidth")??0,r.naturalHeight=e.get("naturalHeight")??0,r.scaleMode=e.get("scaleMode")??"fit",r.crop=kt(e.get("crop"))??null,r.cornerRadius=e.get("cornerRadius")??0,r.alt=e.get("alt")??"";break}return r}function kt(e){if(e==null)return null;try{return JSON.parse(e)}catch{return null}}let K=null,v=null,Bt=!1,Vt=!1,lt=[],Ft=null,jt=null;const ie=new Set;let Jr=50;function yt(e){self.postMessage(e)}function kl(e){const t=[];for(const[,n]of e.entries()){const s=Hn(n);s&&t.push(s)}return t.sort((n,s)=>n.sortOrder&&s.sortOrder?n.sortOrder<s.sortOrder?-1:n.sortOrder>s.sortOrder?1:0:0),t}function yl(e,t){const n=e;for(const r of Mr){const i=n[r];i!==t.get(r)&&t.set(r,i)}if(e.style)for(const r of Jn){const i=e.style[r];i!==t.get(`style.${r}`)&&t.set(`style.${r}`,i)}const s=e.boundElements?JSON.stringify(e.boundElements):null;switch(s!==t.get("boundElements")&&t.set("boundElements",s),e.type){case"rectangle":e.cornerRadius!==t.get("cornerRadius")&&t.set("cornerRadius",e.cornerRadius);break;case"line":case"arrow":{const i=JSON.stringify(e.points);i!==t.get("points")&&t.set("points",i),e.lineType!==t.get("lineType")&&t.set("lineType",e.lineType),e.curvature!==t.get("curvature")&&t.set("curvature",e.curvature);const c=e.startBinding?JSON.stringify(e.startBinding):null;c!==t.get("startBinding")&&t.set("startBinding",c);const o=e.endBinding?JSON.stringify(e.endBinding):null;o!==t.get("endBinding")&&t.set("endBinding",o),e.type==="arrow"&&(e.startArrowhead!==t.get("startArrowhead")&&t.set("startArrowhead",e.startArrowhead),e.endArrowhead!==t.get("endArrowhead")&&t.set("endArrowhead",e.endArrowhead));break}case"freedraw":{const i=JSON.stringify(e.points);i!==t.get("points")&&t.set("points",i);break}case"text":e.text!==t.get("text")&&t.set("text",e.text),e.containerId!==t.get("containerId")&&t.set("containerId",e.containerId),e.textAlign!==t.get("textAlign")&&t.set("textAlign",e.textAlign),e.verticalAlign!==t.get("verticalAlign")&&t.set("verticalAlign",e.verticalAlign);break;case"image":e.src!==t.get("src")&&t.set("src",e.src),e.naturalWidth!==t.get("naturalWidth")&&t.set("naturalWidth",e.naturalWidth),e.naturalHeight!==t.get("naturalHeight")&&t.set("naturalHeight",e.naturalHeight),e.scaleMode!==t.get("scaleMode")&&t.set("scaleMode",e.scaleMode);const r=e.crop?JSON.stringify(e.crop):null;r!==t.get("crop")&&t.set("crop",r),e.cornerRadius!==t.get("cornerRadius")&&t.set("cornerRadius",e.cornerRadius),e.alt!==t.get("alt")&&t.set("alt",e.alt);break}}function bl(e,t){Hr(),Jr=t,K=new It,v=new wl(e.serverUrl,e.roomName,K,{connect:!0,params:e.authToken?{token:e.authToken}:void 0}),v.awareness.setLocalState({user:e.user,cursor:null,selectedIds:[]}),v.on("status",s=>{yt({type:"status",status:s.status})}),v.awareness.on("change",()=>{if(!v)return;const s=v.awareness.getStates(),r=v.awareness.clientID,i=[];for(const[c,o]of s)c!==r&&o&&o.user&&i.push(o);yt({type:"peers",peers:i})});const n=K.getMap("elements");if(n.size>0){const s=kl(n);lt=s,yt({type:"remote-update",elements:s})}n.observe((s,r)=>{if(r.origin==="local-sync"||r.origin==="local-init"||Vt)return;Bt=!0;let i=[...lt],c=!1;for(const[o,l]of s.keys)if(l.action==="add"||l.action==="update"){const h=n.get(o);if(h){const a=Hn(h);if(a){const u=i.findIndex(d=>d.id===o);u>=0?i[u]=a:i.push(a),c=!0}}}else l.action==="delete"&&(i=i.filter(h=>h.id!==o),c=!0);c&&(i.sort((o,l)=>o.sortOrder&&l.sortOrder?o.sortOrder<l.sortOrder?-1:o.sortOrder>l.sortOrder?1:0:0),lt=i,yt({type:"remote-update",elements:i})),Bt=!1}),n.observeDeep(s=>{if(!Vt){for(const r of s){let i=r.target;for(;i&&!(i instanceof P&&i.parent===n);)i=i.parent;if(i instanceof P){const c=i.get("id");c&&ie.add(c)}}jt&&clearTimeout(jt),jt=setTimeout(()=>{if(ie.size===0||Vt)return;Bt=!0;let r=[...lt],i=!1;for(const c of ie){const o=n.get(c);if(!o)continue;const l=Hn(o);if(!l)continue;const h=r.findIndex(a=>a.id===c);h>=0&&(r[h]=l,i=!0)}ie.clear(),i&&(lt=r,yt({type:"remote-update",elements:r})),Bt=!1},16)}})}function Hr(){Ft&&(clearTimeout(Ft),Ft=null),jt&&(clearTimeout(jt),jt=null),ie.clear(),v&&(v.awareness.setLocalState(null),v.disconnect(),v.destroy(),v=null),K&&(K.destroy(),K=null),lt=[],Bt=!1,Vt=!1,yt({type:"status",status:"disconnected"})}function _l(e){!K||Bt||e!==lt&&(Ft&&clearTimeout(Ft),Ft=setTimeout(()=>{if(!K)return;const t=K.getMap("elements");Vt=!0,lt=e;const n=new Map;for(const s of e)n.set(s.id,s);K.transact(()=>{for(const[s]of t.entries())n.has(s)||t.delete(s);for(const s of e){let r=t.get(s.id);r?yl(s,r):(r=new P,ml(s,r),t.set(s.id,r))}},"local-sync"),Vt=!1},Jr))}function Sl(e){if(!v)return;const t=v.awareness.getLocalState(),n={cursor:e.cursor};e.selectedIds&&(n.selectedIds=e.selectedIds),e.activeTool&&(n.activeTool=e.activeTool),v.awareness.setLocalState({...t,...n})}self.onmessage=e=>{const t=e.data;try{switch(t.type){case"connect":bl(t.config,t.syncDebounceMs);break;case"disconnect":Hr();break;case"local-update":_l(t.elements);break;case"awareness":Sl(t);break}}catch(n){yt({type:"error",message:n instanceof Error?n.message:String(n)})}}})();
@@ -0,0 +1,42 @@
1
+ import { default as React } from 'react';
2
+ import { CanvasElement } from '../../types';
3
+ interface Props {
4
+ element: CanvasElement;
5
+ isSelected: boolean;
6
+ isEditing?: boolean;
7
+ /** When true, individual drag is disabled — the parent KonvaGroup handles dragging */
8
+ isGrouped?: boolean;
9
+ onSelect: (id: string) => void;
10
+ onChange: (id: string, updates: Partial<CanvasElement>) => void;
11
+ onDragMove?: (id: string, updates: Partial<CanvasElement>) => void;
12
+ onDoubleClick?: (id: string) => void;
13
+ /** Text-specific: auto-open editor on mount */
14
+ autoEditText?: boolean;
15
+ /** Text-specific: editing started */
16
+ onTextEditStart?: (id: string) => void;
17
+ /** Text-specific: editing ended */
18
+ onTextEditEnd?: (id: string, isEmpty: boolean) => void;
19
+ /** All elements for resolving containerId position */
20
+ allElements?: CanvasElement[];
21
+ /** Grid snap size (0 or undefined = no snap) */
22
+ gridSnap?: number;
23
+ /** Alignment snap: returns snapped {x,y} given current bounds */
24
+ onDragSnap?: (id: string, bounds: {
25
+ x: number;
26
+ y: number;
27
+ width: number;
28
+ height: number;
29
+ }) => {
30
+ x: number;
31
+ y: number;
32
+ } | null;
33
+ /**
34
+ * Current viewport scale (efficient/discretized zoom).
35
+ * When provided, enables LOD optimisation for non-selected elements:
36
+ * - < LOD_SKIP_THRESHOLD screen px → skip rendering entirely
37
+ * - < LOD_SIMPLIFY_THRESHOLD screen px → render simplified rect
38
+ */
39
+ viewportScale?: number;
40
+ }
41
+ declare const _default: React.NamedExoticComponent<Props>;
42
+ export default _default;
@@ -0,0 +1,13 @@
1
+ import { default as React } from 'react';
2
+ import { CanvasElement, SnapTarget } from '../../types';
3
+ interface Props {
4
+ elements: CanvasElement[];
5
+ /** Currently hovered snap target */
6
+ snapTarget: SnapTarget | null;
7
+ /** Whether to render at all (only during line/arrow tool) */
8
+ visible: boolean;
9
+ /** Accent color */
10
+ color?: string;
11
+ }
12
+ declare const _default: React.NamedExoticComponent<Props>;
13
+ export default _default;
@@ -0,0 +1,13 @@
1
+ import { default as React } from 'react';
2
+ interface Props {
3
+ width: number;
4
+ height: number;
5
+ viewport: {
6
+ x: number;
7
+ y: number;
8
+ scale: number;
9
+ };
10
+ gridColor?: string;
11
+ }
12
+ declare const _default: React.NamedExoticComponent<Props>;
13
+ export default _default;