@eventcatalog/core 5.4.0 → 5.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analytics/analytics.cjs +1 -1
- package/dist/analytics/analytics.js +2 -2
- package/dist/analytics/log-build.cjs +1 -1
- package/dist/analytics/log-build.js +3 -3
- package/dist/{chunk-PAS36QHK.js → chunk-GAKU752C.js} +1 -1
- package/dist/{chunk-EPDVXHC7.js → chunk-GQQFHJSY.js} +3 -3
- package/dist/{chunk-OT2U5OES.js → chunk-NSVRGATQ.js} +1 -1
- package/dist/{chunk-OX6TSVHY.js → chunk-QJ7KKN2D.js} +1 -1
- package/dist/{chunk-O2K4VPDO.js → chunk-VZNPE26F.js} +1 -1
- package/dist/{chunk-TERJXCLK.js → chunk-WG276AIE.js} +1 -1
- package/dist/constants.cjs +1 -1
- package/dist/constants.js +1 -1
- package/dist/eventcatalog.cjs +1 -1
- package/dist/eventcatalog.js +12 -12
- package/dist/federation/federate.js +3 -3
- package/dist/federation/source-provider.js +2 -2
- package/dist/generate.cjs +1 -1
- package/dist/generate.js +3 -3
- package/dist/utils/cli-logger.cjs +1 -1
- package/dist/utils/cli-logger.js +2 -2
- package/eventcatalog/src/features/mcp/apps/generated/canvas.html +1 -1
- package/eventcatalog/src/features/studio/hooks/use-canvas-webmcp.ts +4 -3
- package/package.json +4 -4
- package/dist/{chunk-6K7XZAYI.js → chunk-A2RZR3U4.js} +3 -3
|
@@ -169,7 +169,7 @@ var verifyRequiredFieldsAreInCatalogConfigFile = async (projectDirectory) => {
|
|
|
169
169
|
var import_os = __toESM(require("os"), 1);
|
|
170
170
|
|
|
171
171
|
// package.json
|
|
172
|
-
var version = "5.4.
|
|
172
|
+
var version = "5.4.1";
|
|
173
173
|
|
|
174
174
|
// src/constants.ts
|
|
175
175
|
var VERSION = version;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
log_build_default
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-GQQFHJSY.js";
|
|
4
4
|
import "../chunk-AD7CL772.js";
|
|
5
|
+
import "../chunk-GAKU752C.js";
|
|
5
6
|
import "../chunk-YRZK7HKX.js";
|
|
6
7
|
import "../chunk-CA6WCQ2T.js";
|
|
7
|
-
import "../chunk-PAS36QHK.js";
|
|
8
8
|
import "../chunk-CPW6G62V.js";
|
|
9
|
-
import "../chunk-
|
|
9
|
+
import "../chunk-NSVRGATQ.js";
|
|
10
10
|
import "../chunk-4G7FSRPN.js";
|
|
11
11
|
export {
|
|
12
12
|
log_build_default as default
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getLicenseAnalytics
|
|
3
3
|
} from "./chunk-AD7CL772.js";
|
|
4
|
+
import {
|
|
5
|
+
raiseEvent
|
|
6
|
+
} from "./chunk-GAKU752C.js";
|
|
4
7
|
import {
|
|
5
8
|
countResources,
|
|
6
9
|
hashCatalogContent,
|
|
@@ -11,9 +14,6 @@ import {
|
|
|
11
14
|
getStudioMode,
|
|
12
15
|
serializeStudioUsage
|
|
13
16
|
} from "./chunk-CA6WCQ2T.js";
|
|
14
|
-
import {
|
|
15
|
-
raiseEvent
|
|
16
|
-
} from "./chunk-PAS36QHK.js";
|
|
17
17
|
import {
|
|
18
18
|
TELEMETRY_REQUEST_TIMEOUT_MS,
|
|
19
19
|
isTelemetryDisabled
|
package/dist/constants.cjs
CHANGED
package/dist/constants.js
CHANGED
package/dist/eventcatalog.cjs
CHANGED
|
@@ -174,7 +174,7 @@ var verifyRequiredFieldsAreInCatalogConfigFile = async (projectDirectory) => {
|
|
|
174
174
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
175
175
|
|
|
176
176
|
// package.json
|
|
177
|
-
var version = "5.4.
|
|
177
|
+
var version = "5.4.1";
|
|
178
178
|
|
|
179
179
|
// src/constants.ts
|
|
180
180
|
var VERSION = version;
|
package/dist/eventcatalog.js
CHANGED
|
@@ -1,34 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
stopChildWithParent
|
|
3
|
+
} from "./chunk-S5GWAUG5.js";
|
|
1
4
|
import {
|
|
2
5
|
runMigrations
|
|
3
6
|
} from "./chunk-XUAF2H54.js";
|
|
4
7
|
import "./chunk-CA4U2JP7.js";
|
|
5
|
-
import {
|
|
6
|
-
stopChildWithParent
|
|
7
|
-
} from "./chunk-S5GWAUG5.js";
|
|
8
8
|
import {
|
|
9
9
|
log_build_default
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-GQQFHJSY.js";
|
|
11
11
|
import {
|
|
12
12
|
getLicenseStatus,
|
|
13
13
|
printLicenseStatus
|
|
14
14
|
} from "./chunk-AD7CL772.js";
|
|
15
|
+
import "./chunk-GAKU752C.js";
|
|
15
16
|
import "./chunk-YRZK7HKX.js";
|
|
16
17
|
import "./chunk-CA6WCQ2T.js";
|
|
18
|
+
import "./chunk-CPW6G62V.js";
|
|
17
19
|
import {
|
|
18
20
|
FederationConflictError,
|
|
19
21
|
FederationDiagnosticError,
|
|
20
22
|
federateCatalog
|
|
21
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-QJ7KKN2D.js";
|
|
22
24
|
import "./chunk-WRNH5C3U.js";
|
|
23
25
|
import "./chunk-5EPNFDT5.js";
|
|
24
|
-
import "./chunk-
|
|
26
|
+
import "./chunk-A2RZR3U4.js";
|
|
27
|
+
import "./chunk-SDZQJTJW.js";
|
|
25
28
|
import "./chunk-352FGP6W.js";
|
|
26
29
|
import "./chunk-R7Z5ALYI.js";
|
|
27
30
|
import {
|
|
28
31
|
getFederationDiagnosticCounts,
|
|
29
32
|
getVisibleFederationDiagnostics
|
|
30
33
|
} from "./chunk-JJPB6EOZ.js";
|
|
31
|
-
import "./chunk-SDZQJTJW.js";
|
|
32
34
|
import {
|
|
33
35
|
getProjectOutDir,
|
|
34
36
|
isAuthEnabled,
|
|
@@ -37,10 +39,10 @@ import {
|
|
|
37
39
|
} from "./chunk-NKNOXQ62.js";
|
|
38
40
|
import {
|
|
39
41
|
generate
|
|
40
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-WG276AIE.js";
|
|
41
43
|
import {
|
|
42
44
|
logger
|
|
43
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-VZNPE26F.js";
|
|
44
46
|
import {
|
|
45
47
|
resolve_catalog_dependencies_default
|
|
46
48
|
} from "./chunk-PD7KTSYN.js";
|
|
@@ -54,8 +56,6 @@ import {
|
|
|
54
56
|
import {
|
|
55
57
|
watch
|
|
56
58
|
} from "./chunk-U63GDPPY.js";
|
|
57
|
-
import "./chunk-PAS36QHK.js";
|
|
58
|
-
import "./chunk-CPW6G62V.js";
|
|
59
59
|
import {
|
|
60
60
|
hasCustomExports,
|
|
61
61
|
isCatalogAuthEnabled,
|
|
@@ -79,7 +79,7 @@ import {
|
|
|
79
79
|
} from "./chunk-LFQJXLHG.js";
|
|
80
80
|
import {
|
|
81
81
|
VERSION
|
|
82
|
-
} from "./chunk-
|
|
82
|
+
} from "./chunk-NSVRGATQ.js";
|
|
83
83
|
import {
|
|
84
84
|
getEventCatalogConfigFile,
|
|
85
85
|
verifyRequiredFieldsAreInCatalogConfigFile
|
|
@@ -2,14 +2,14 @@ import {
|
|
|
2
2
|
FederationConflictError,
|
|
3
3
|
FederationDiagnosticError,
|
|
4
4
|
federateCatalog
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-QJ7KKN2D.js";
|
|
6
6
|
import "../chunk-WRNH5C3U.js";
|
|
7
7
|
import "../chunk-5EPNFDT5.js";
|
|
8
|
-
import "../chunk-
|
|
8
|
+
import "../chunk-A2RZR3U4.js";
|
|
9
|
+
import "../chunk-SDZQJTJW.js";
|
|
9
10
|
import "../chunk-352FGP6W.js";
|
|
10
11
|
import "../chunk-R7Z5ALYI.js";
|
|
11
12
|
import "../chunk-JJPB6EOZ.js";
|
|
12
|
-
import "../chunk-SDZQJTJW.js";
|
|
13
13
|
import "../chunk-4G7FSRPN.js";
|
|
14
14
|
export {
|
|
15
15
|
FederationConflictError,
|
package/dist/generate.cjs
CHANGED
|
@@ -105,7 +105,7 @@ var getEventCatalogConfigFile = async (projectDirectory) => {
|
|
|
105
105
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
106
106
|
|
|
107
107
|
// package.json
|
|
108
|
-
var version = "5.4.
|
|
108
|
+
var version = "5.4.1";
|
|
109
109
|
|
|
110
110
|
// src/constants.ts
|
|
111
111
|
var VERSION = version;
|
package/dist/generate.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
generate
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-WG276AIE.js";
|
|
4
|
+
import "./chunk-VZNPE26F.js";
|
|
5
|
+
import "./chunk-NSVRGATQ.js";
|
|
6
6
|
import "./chunk-4G7FSRPN.js";
|
|
7
7
|
export {
|
|
8
8
|
generate
|
package/dist/utils/cli-logger.js
CHANGED
|
@@ -152,7 +152,7 @@ event`,queries:`requests`},$Le={commands:`accepts`,events:`subscribed by`,querie
|
|
|
152
152
|
<path fill-rule="evenodd" d="M 445 55 c -174.6 0.5 -188.1 0.7 -196.5 2.3 -20.7 4.1 -35.3 8.5 -51 15.3 -66.7 28.8 -114.7 86.9 -130.3 157.9 l -2.6 12 -0.4 371 c -0.2 261 0 373.8 0.8 380.5 4.6 40.7 21.8 79.6 49.8 113 36.8 43.9 89.5 72.4 144.2 77.9 5.9 0.6 148.2 1.1 372.5 1.3 345.2 0.3 363.5 0.2 373 -1.5 32.1 -5.7 58.7 -16.4 85.5 -34.2 53.2 -35.3 89.1 -93.6 96 -156 0.8 -7.2 1 -114.8 0.8 -381.5 l -0.3 -371.5 -2.2 -10.4 c -7.7 -35.9 -18.8 -61.1 -38.9 -88.2 -9.5 -12.8 -30.7 -34.1 -43.4 -43.5 -34.4 -25.6 -73.7 -40.9 -113.5 -44.3 -12.5 -1.1 -182.7 -1.1 -543.5 -0.1 z m -26.3 152.5 c 30.7 11.6 86.7 67 122.9 121.6 l 8.4 12.6 9.7 -2.3 c 13.3 -3.3 30.3 -6.1 44.8 -7.5 15.1 -1.5 51.8 -0.6 67.5 1.6 10.1 1.4 37.1 6.8 40.5 8.1 0.7 0.3 3.6 -3.4 7.1 -8.8 18.3 -29.1 37.9 -53.5 64.7 -80.7 31.8 -32.2 53.3 -47 68.5 -47.1 10.5 -0 16.2 4.1 22.3 16.1 11.6 23 17.3 80.8 15 153.1 l -1 33.7 6 14.7 c 3.2 8 7.8 20.4 10 27.5 2.3 7.1 4.5 12.9 4.9 12.9 0.4 -0 5 -1.5 10.1 -3.4 29.8 -10.8 61.4 -20.5 89.6 -27.5 20 -5.1 21.5 -5.1 25.9 -0.7 2.9 2.9 3.4 4.1 3.4 7.9 0 3.4 -0.6 5.3 -2.5 7.5 -2.9 3.5 -4.7 4.3 -18 7.7 -23.9 6.3 -83.7 25.2 -103 32.5 -2 0.8 -2 1.2 -1 10.6 0.5 5.3 1.5 9.9 2 10 0.6 0.2 16.8 2.4 36 4.9 69.6 9.1 85.9 11.5 89.4 13.3 10.1 5.1 7.6 20.4 -3.6 21.9 -3.7 0.5 -26.4 -2.1 -63.3 -7.2 -18.4 -2.6 -56.7 -7.5 -58 -7.5 -0.4 -0 -1 0.8 -1.2 1.8 -0.4 1.4 -2.9 2.3 -11.4 4.1 -50.2 10.3 -130.1 33.1 -167.9 47.8 -35.1 13.6 -69.4 33.4 -96.1 55.6 -6.6 5.4 -10.1 7.7 -10.9 7.1 -0.7 -0.5 -5.8 -4.6 -11.5 -9.2 -25 -20.2 -55.1 -37.5 -88.5 -50.7 -39.3 -15.6 -111.9 -36.5 -170.7 -49.1 -15.1 -3.2 -17.8 -4.1 -17.8 -5.6 0 -2.4 0.4 -2.4 -35 2.2 -16.8 2.2 -42.6 5.7 -57.5 7.6 -14.8 2 -28.8 3.3 -31 3 -5.9 -0.7 -9.5 -5.1 -9.5 -11.5 0 -5.7 2.4 -9.4 7.3 -11 3.2 -1.1 62.2 -9.4 103.2 -14.6 11.6 -1.5 21.3 -3 21.7 -3.3 0.3 -0.4 0.9 -5 1.3 -10.3 l 0.7 -9.6 -30.3 -10.1 c -24.9 -8.3 -73.2 -22.8 -85.2 -25.6 -1.5 -0.4 -4.1 -1.9 -5.8 -3.4 -2.6 -2.3 -3.3 -3.8 -3.7 -8 -0.4 -4.7 -0.2 -5.4 2.5 -8.1 1.7 -1.6 4.3 -3.3 5.8 -3.7 5.8 -1.4 46 9.3 88.5 23.7 16.2 5.5 30.3 10.3 31.2 10.6 1 0.3 2 -0.1 2.2 -0.8 4.6 -14.9 9 -27.2 14 -39.4 l 6.2 -15 -1 -32.5 c -1.5 -48.5 0.9 -93.8 6.4 -122.4 5 -25.8 12 -40.4 21.9 -45.6 5.4 -2.9 15.3 -2.6 23.8 0.5 z m -67.6 364.4 c 81.9 16.7 161.5 40.4 199.3 59.3 11.7 5.9 29.8 16.7 34.1 20.3 l 3 2.6 -9.5 -0.4 c -8.7 -0.4 -15.5 -2.1 -78.5 -19.7 -37.9 -10.6 -76 -21.2 -84.5 -23.5 -56.6 -15.7 -123.4 -34.6 -123.8 -35 -0.6 -0.6 13.5 -2.8 37.3 -5.8 6.4 -0.8 8.6 -0.6 22.6 2.2 z m 589.5 -0.4 c 10.4 1.4 20.4 2.8 22.3 3.2 3.4 0.6 -40.5 13.5 -170.9 50.2 -20.1 5.7 -42.6 12 -50 14.1 -50.1 14.2 -53.5 15 -60.8 15 -4 -0 -7.2 -0.3 -7.2 -0.8 0 -2.1 28.9 -19.2 45.8 -27.1 36.1 -16.7 110.6 -38.3 193.2 -55.9 6.6 -1.4 7.1 -1.4 27.6 1.3 z m -672.2 33.1 c 13.2 3.6 31.1 8.5 39.6 10.9 8.5 2.4 35.3 9.8 59.5 16.4 52.5 14.3 120.5 33 167.5 46.1 22.9 6.3 23.5 6.6 24.9 9.6 0.8 1.8 1.1 45.6 1.1 162.2 0 175.7 0.4 164.2 -5.9 164.2 -1.5 -0 -12.4 -2.7 -24.2 -6.1 -20.6 -5.8 -66.3 -18.6 -188.9 -52.7 -31.6 -8.8 -63.1 -17.5 -70 -19.2 -13 -3.3 -16.3 -4.8 -17.9 -7.8 -1.1 -2.1 -7.2 -104.7 -15.6 -262.7 -1.3 -25.9 -2.7 -50.5 -3.1 -54.7 -0.6 -7.3 -0.5 -7.8 2 -10.2 1.4 -1.5 3.5 -2.6 4.7 -2.6 1.2 -0 13 3 26.3 6.6 z m 748.1 -5.6 c 3.9 1.5 4.4 4.2 3.4 19.5 -0.8 12.4 -4.2 70.9 -15 256 -2.6 46 -3.3 53.3 -4.8 55.5 -1.9 2.6 1.3 1.6 -78.6 23.9 -9.9 2.8 -34.2 9.6 -54 15.1 -19.8 5.6 -50.4 14.1 -68 19 -17.6 4.9 -45.7 12.8 -62.5 17.5 -16.7 4.7 -31.7 8.5 -33.2 8.5 -6.3 -0 -5.9 11.3 -5.6 -165.1 0.2 -88.2 0.7 -161.2 1.2 -162.1 0.9 -1.9 4.6 -3.1 32.6 -10.7 10.2 -2.8 25.9 -7.1 35 -9.6 9.1 -2.5 32 -8.9 51 -14.1 47.4 -13.1 124.2 -34.5 168.5 -46.9 14.3 -4 26.3 -7.4 26.7 -7.4 0.4 -0.1 1.8 0.3 3.3 0.9 z m -351.7 95.3 c 0.9 0.7 1.2 35.1 1.2 166.7 l 0 165.9 -2.2 1.3 c -1.8 1 -10.2 1.3 -35.1 1.3 -31.4 -0 -32.9 -0.1 -34.3 -1.9 -2.1 -2.9 -2.1 -330.7 0 -332.8 1.1 -1.2 7.6 -1.4 35.2 -1.4 18.7 0.1 34.5 0.5 35.2 0.9 z"/>
|
|
153
153
|
</svg>
|
|
154
154
|
`,Jz=2,Mze=e=>{let t=new DOMMatrix(getComputedStyle(e).transform);return{x:t.e,y:t.f}};function Yz(e){let t=[];if(e.querySelectorAll(`.react-flow__node`).forEach(e=>{let{x:n,y:r}=Mze(e);t.push({x:n,y:r,width:e.offsetWidth,height:e.offsetHeight})}),e.querySelectorAll(`.studio-note`).forEach(e=>{t.push({x:e.offsetLeft,y:e.offsetTop,width:e.offsetWidth,height:e.offsetHeight})}),!t.length)return;let n=Math.min(...t.map(e=>e.x)),r=Math.min(...t.map(e=>e.y));return{x:n,y:r,width:Math.max(...t.map(e=>e.x+e.width))-n,height:Math.max(...t.map(e=>e.y+e.height))-r}}var Xz=e=>new Promise((t,n)=>{let r=new Image;r.onload=()=>t(r),r.onerror=n,r.src=e}),Zz=(e,t=1)=>{let n=getComputedStyle(document.documentElement).getPropertyValue(e).trim()||getComputedStyle(document.body).getPropertyValue(e).trim();return n?`rgb(${n} / ${t})`:t===1?`#0f172a`:`rgb(15 23 42 / ${t})`};async function Qz(e){let t=await Xz(e),n=document.createElement(`canvas`);n.width=t.width,n.height=t.height;let r=n.getContext(`2d`);if(!r)return e;r.drawImage(t,0,0),await document.fonts?.ready;let i=Math.max(Jz,Math.min(n.width/1200,n.height/500)),a=Zz(`--ec-page-text`),o=Zz(`--ec-page-text-muted`),s=e=>`${e} ${12*i}px Inter, ui-sans-serif, system-ui, sans-serif`,c=[{label:`Made with `,weight:400,color:o},{label:`EventCatalog`,weight:600,color:a},{label:` · eventcatalog.dev`,weight:400,color:o}],l=c.map(e=>(r.font=s(e.weight),r.measureText(e.label).width)),u=16*i,d=12*i,f=7*i,p=30*i,m=d*2+u+f+l.reduce((e,t)=>e+t,0),h=20*i,g=n.width-m-h,_=n.height-p-h;r.fillStyle=Zz(`--ec-card-bg`,.96),r.strokeStyle=Zz(`--ec-page-border`),r.lineWidth=i,r.beginPath(),r.roundRect(g,_,m,p,p/2),r.fill(),r.stroke();let v=await Xz(`data:image/svg+xml;charset=utf-8,${encodeURIComponent(qz.replace(/currentColor/g,a))}`);r.drawImage(v,g+d,_+(p-u)/2,u,u);let y=g+d+u+f;return r.textBaseline=`middle`,c.forEach((e,t)=>{r.font=s(e.weight),r.fillStyle=e.color,r.fillText(e.label,y,_+p/2+i),y+=l[t]}),n.toDataURL(`image/png`)}async function $z(e){let t=e.querySelector(`.react-flow__viewport`),n=t&&Yz(t);if(!t||!n)return;let{width:r,height:i,viewport:a}=aOe(n),o=dOe(t);e.classList.add(`ec-exporting`);let s;try{s=await lv(t,{backgroundColor:getComputedStyle(document.body).backgroundColor,width:r,height:i,pixelRatio:Jz,style:{width:`${r}px`,height:`${i}px`,transform:`translate(${a.x}px, ${a.y}px) scale(${a.zoom})`}})}finally{o(),e.classList.remove(`ec-exporting`)}try{return await Qz(s)}catch{return s}}var Nze=(0,h.memo)(function({data:e,selected:t}){let{mode:n=`full`,team:r={}}=e,i=r.name||`Team`;return(0,D.jsxs)(`div`,{className:`relative min-w-44 max-w-60 rounded-xl border-2 border-emerald-500 ${t?`ring-2 ring-emerald-400/60 ring-offset-2`:``}`,style:{background:`rgb(var(--ec-card-bg))`,boxShadow:`0 2px 12px rgba(16, 185, 129, 0.15)`},children:[(0,D.jsx)(Zl,{type:`target`,position:co.Left}),(0,D.jsx)(Zl,{type:`source`,position:co.Right}),(0,D.jsx)(`div`,{className:`absolute -top-2.5 left-2.5 z-10 flex items-center`,children:(0,D.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-emerald-500 px-1.5 py-0.5 text-[7px] font-bold uppercase tracking-widest text-white shadow-sm`,children:[(0,D.jsx)(Ip,{className:`h-2.5 w-2.5`,strokeWidth:2.5}),`Team`]})}),(0,D.jsxs)(`div`,{className:`flex items-start gap-2 px-3 pb-2.5 pt-3.5`,children:[(0,D.jsx)(`span`,{className:`mt-0.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-emerald-500/10 text-emerald-600`,children:(0,D.jsx)(Ip,{className:`h-3.5 w-3.5`})}),(0,D.jsxs)(`div`,{className:`min-w-0`,children:[(0,D.jsx)(`div`,{className:`truncate text-[13px] font-semibold leading-snug text-[rgb(var(--ec-page-text))]`,title:i,children:i}),n===`full`&&r.summary&&(0,D.jsx)(`div`,{className:`mt-1 line-clamp-2 text-[9px] leading-relaxed text-[rgb(var(--ec-page-text-muted))]`,title:r.summary,children:r.summary})]})]})]})}),eB=(0,h.createContext)(()=>{}),tB=(0,h.createContext)(()=>{}),nB=(0,h.createContext)(null),rB=(0,h.createContext)(null),iB=(0,h.createContext)(!1),Pze=lEe;function Fze(){return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)($d,{position:`left`,variant:oc.Line,resizeDirection:`horizontal`,minWidth:80,className:`studio-width-handle`}),(0,D.jsx)($d,{position:`right`,variant:oc.Line,resizeDirection:`horizontal`,minWidth:80,className:`studio-width-handle`})]})}function Ize({id:e,text:t,editing:n,onDone:r,placeholder:i,className:a,style:o,growWidth:s=!1}){let c=(0,h.useContext)(eB),l=(0,h.useContext)(tB),u=(0,h.useRef)(null);(0,h.useEffect)(()=>{if(!n)return;let e=0,t=0,r=()=>{let n=u.current;!n||document.activeElement===n||(n.focus({preventScroll:!0}),document.activeElement!==n&&++t<30&&(e=requestAnimationFrame(r)))};return r(),()=>cancelAnimationFrame(e)},[n]);let d=e=>{s&&(e.style.width=`0`,e.style.width=`${e.scrollWidth+2}px`),e.style.height=`auto`,e.style.height=`${e.scrollHeight}px`};return n?(0,D.jsx)(`textarea`,{ref:e=>{u.current=e,e&&d(e)},defaultValue:t,placeholder:i,wrap:s?`off`:void 0,onFocus:e=>e.currentTarget.select(),onInput:t=>{d(t.currentTarget),l({id:e,text:t.currentTarget.value})},onBlur:n=>{let i=n.currentTarget.value;r(i),i!==t&&c(e,e=>({...e,text:i})),l(null)},onKeyDown:e=>{(e.key===`Escape`||e.key===`Enter`&&(e.metaKey||e.ctrlKey))&&e.currentTarget.blur()},className:`nodrag nopan nowheel block w-full resize-none overflow-hidden bg-transparent outline-none ${a}`,style:o}):(0,D.jsx)(`p`,{className:a,style:o,children:t||i&&(0,D.jsx)(`span`,{className:`opacity-50`,children:i})})}var Lze={yellow:{fill:`#fef9c3`,border:`#fde047`},blue:{fill:`#dbeafe`,border:`#93c5fd`},green:{fill:`#dcfce7`,border:`#86efac`},pink:{fill:`#fce7f3`,border:`#f9a8d4`},purple:{fill:`#ede9fe`,border:`#c4b5fd`},gray:{fill:`#f3f4f6`,border:`#d1d5db`}},aB=(0,h.memo)(function({id:e,data:t,selected:n}){let r=(0,h.useContext)(eB),[i,a]=(0,h.useState)((0,h.useContext)(rB)===e),o=(0,h.useContext)(iB),s=typeof t.color==`string`&&Lze[t.color]?t.color:`yellow`,c=Lze[s];return(0,D.jsxs)(`div`,{className:`studio-note`,style:{background:c.fill,borderColor:c.border},onDoubleClick:()=>!o&&a(!0),children:[n&&!i&&!o&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(Fze,{}),(0,D.jsx)(`div`,{className:`nodrag nopan studio-note-colors`,role:`radiogroup`,"aria-label":`Note colour`,children:Object.entries(Lze).map(([t,{fill:n,border:i}])=>(0,D.jsx)(`button`,{role:`radio`,"aria-checked":t===s,title:t.charAt(0).toUpperCase()+t.slice(1),onClick:()=>r(e,e=>({...e,color:t})),className:`studio-note-color`,style:{background:n,borderColor:t===s?`rgb(var(--ec-page-text))`:i}},t))})]}),(0,D.jsx)(Ize,{id:e,text:String(t.text??``),editing:i,onDone:()=>a(!1),placeholder:``,className:`studio-note-body`}),(0,D.jsxs)(`span`,{className:`studio-note-level`,children:[`L`,XL({type:`note`,data:t}),` note`]}),typeof t.createdAt==`number`&&(0,D.jsx)(`span`,{className:`studio-note-date`,children:new Date(t.createdAt).toLocaleDateString(void 0,{day:`numeric`,month:`short`})})]})}),Rze=e=>Math.round(Math.min(160,Math.max(10,e))),zze=e=>Math.round(((e+180)%360+360)%360-180),Bze=[`top-left`,`top-right`,`bottom-left`,`bottom-right`],Vze=(e,t)=>{let n=()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`pointerup`,n),window.removeEventListener(`pointercancel`,n),t()};window.addEventListener(`pointermove`,e),window.addEventListener(`pointerup`,n),window.addEventListener(`pointercancel`,n)},Hze=(0,h.memo)(function({id:e,data:t,selected:n}){let[r,i]=(0,h.useState)((0,h.useContext)(rB)===e),{deleteElements:a}=Dl(),o=(0,h.useContext)(eB),s=(0,h.useContext)(tB),c=(0,h.useRef)(null),l=typeof t.fontSize==`number`?t.fontSize:22,u=typeof t.angle==`number`?t.angle:0,[d,f]=(0,h.useState)(null),[p,m]=(0,h.useState)(null),g=d??l,_=p??u,v=t=>n=>{n.stopPropagation(),n.preventDefault();let r=c.current.getBoundingClientRect(),i={x:t.endsWith(`left`)?r.right:r.left,y:t.startsWith(`top`)?r.bottom:r.top},a=Math.max(Math.hypot(n.clientX-i.x,n.clientY-i.y),1),u=l;Vze(t=>{let n=Rze(l*Math.hypot(t.clientX-i.x,t.clientY-i.y)/a);n!==u&&(f(u=n),s({id:e,fontSize:n}))},()=>{f(null),u!==l&&o(e,e=>({...e,fontSize:u})),s(null)})},y=t=>{t.stopPropagation(),t.preventDefault();let n=c.current.getBoundingClientRect(),r={x:n.left+n.width/2,y:n.top+n.height/2},i=u;Vze(t=>{let n=Math.atan2(t.clientY-r.y,t.clientX-r.x)*180/Math.PI+90,a=zze(t.shiftKey?Math.round(n/15)*15:n);a!==i&&(m(i=a),s({id:e,angle:a}))},()=>{m(null),i!==u&&o(e,e=>({...e,angle:i})),s(null)})},b=t=>{i(!1),t.trim()||a({nodes:[{id:e}]})},x=(0,h.useContext)(iB),S=(n||d!==null||p!==null)&&!r&&!x;return(0,D.jsxs)(`div`,{ref:c,className:`studio-text ${S?`is-framed`:``}`,style:_?{transform:`rotate(${_}deg)`}:void 0,onDoubleClick:()=>!x&&i(!0),children:[S&&(0,D.jsxs)(D.Fragment,{children:[Bze.map(e=>(0,D.jsx)(`span`,{className:`nodrag nopan studio-text-corner is-${e}`,onPointerDown:v(e)},e)),(0,D.jsx)(`span`,{className:`nodrag nopan studio-text-turn`,title:`Rotate (Shift: 15° steps)`,onPointerDown:y})]}),(0,D.jsx)(Ize,{id:e,text:String(t.text??``),editing:r,onDone:b,placeholder:r?``:`Double-click to write`,className:`studio-text-body`,style:{fontSize:g},growWidth:!0})]})}),oB=({type:e,data:t,parentId:n})=>(0,h.useMemo)(()=>(e===LL.domain||e===`context-domain`)&&n&&t.subdomain===void 0?{...t,subdomain:!0}:t,[e,t,n]),Uze=(0,h.memo)(function(e){let t=(0,h.useMemo)(()=>({...e.data,entity:{data:e.data.entity??{}}}),[e.data]);return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(uO,{...e,data:t}),(0,D.jsx)(Zl,{type:`source`,position:co.Right,id:ZR,className:`studio-entity-source`})]})}),Wze=(0,h.memo)(function(e){return(0,D.jsx)(dEe,{...e,data:oB(e)})}),sB=(0,h.memo)(function(e){let t=(0,h.useContext)(nB)===e.id,n=(0,h.useContext)(iB),r=oB(e),i=Pc(),a=(0,h.useRef)(null),o=(0,h.useCallback)(()=>{let{nodeLookup:t}=i.getState(),n=t.get(e.id),r=[...t.values()].filter(t=>t.parentId===e.id);if(!n||r.length===0){a.current=null;return}let{x:o,y:s}=n.position,c=e=>({width:e.measured.width??e.width??0,height:e.measured.height??e.height??0}),l=c(n);a.current={left:Math.max(o+Math.min(...r.map(e=>e.position.x))-rR.left,o),top:Math.max(s+Math.min(...r.map(e=>e.position.y))-rR.top,s),right:Math.min(o+Math.max(...r.map(e=>e.position.x+c(e).width))+rR.right,o+l.width),bottom:Math.min(s+Math.max(...r.map(e=>e.position.y+c(e).height))+rR.bottom,s+l.height)}},[i,e.id]),s=(0,h.useCallback)((e,{x:t,y:n,width:r,height:i})=>{let o=a.current;return!o||t<=o.left&&n<=o.top&&t+r>=o.right&&n+i>=o.bottom},[]);return(0,D.jsxs)(`div`,{style:{width:`100%`,height:`100%`,position:`relative`},children:[(0,D.jsx)(ef,{isVisible:e.selected&&!n,onResizeStart:o,shouldResize:s,minWidth:240,minHeight:160,lineClassName:`!border-[rgb(var(--ec-accent))]`,handleClassName:`!h-2.5 !w-2.5 !rounded-sm !border-2 !bg-[rgb(var(--ec-card-bg))] !border-[rgb(var(--ec-accent))]`}),(0,D.jsx)(Pze,{...e,data:r}),(0,D.jsx)(`div`,{className:`ec-group-grip absolute inset-x-0 -top-3 h-[60px] cursor-grab`}),t?(0,D.jsx)(`div`,{className:`ec-drop-target`,children:(0,D.jsxs)(`span`,{className:`ec-drop-target-label`,children:[`Drop to add to`,` `,nR(e.type,e.data,`this container`)]})}):e.selected&&(0,D.jsx)(`div`,{className:`ec-group-selected`})]})}),Gze={...YEe,note:aB,text:Hze,actor:YEe[`context-actor`],"context-domain":Wze,entity:Uze,team:Nze,[LL.domain]:sB,[LL.system]:sB},Kze=Object.fromEntries(Object.entries(Gze).map(([e,t])=>[e,tOe(t)])),cB={success:{text:`text-[rgb(var(--ec-badge-color-green-text))]`,dot:`bg-[rgb(var(--ec-badge-color-green-text))]`},warning:{text:`text-[rgb(var(--ec-badge-color-yellow-text))]`,dot:`bg-[rgb(var(--ec-badge-color-yellow-text))]`},danger:{text:`text-[rgb(var(--ec-badge-color-red-text))]`,dot:`bg-[rgb(var(--ec-badge-color-red-text))]`,hover:`hover:bg-[rgb(var(--ec-badge-color-red-background))]`,button:`bg-[rgb(var(--ec-badge-color-red-text))] text-white hover:bg-[rgb(var(--ec-badge-color-red-text)/0.85)]`}},lB={draft:{label:`Draft`,description:`Being worked on`,pill:`bg-[rgb(var(--ec-badge-color-gray-background))] text-[rgb(var(--ec-badge-color-gray-text))] border-[rgb(var(--ec-badge-color-gray-text)/0.25)]`,dot:`bg-[rgb(var(--ec-badge-color-gray-text))]`},proposed:{label:`Proposed`,description:`Ready for review`,pill:`bg-[rgb(var(--ec-badge-color-yellow-background))] text-[rgb(var(--ec-badge-color-yellow-text))] border-[rgb(var(--ec-badge-color-yellow-text)/0.3)]`,dot:`bg-[rgb(var(--ec-badge-color-yellow-text))]`},accepted:{label:`Accepted`,description:`The agreed design`,pill:`bg-[rgb(var(--ec-badge-color-green-background))] text-[rgb(var(--ec-badge-color-green-text))] border-[rgb(var(--ec-badge-color-green-text)/0.3)]`,dot:`bg-[rgb(var(--ec-badge-color-green-text))]`},rejected:{label:`Rejected`,description:`Decided against, kept for the record`,pill:`bg-[rgb(var(--ec-badge-color-red-background))] text-[rgb(var(--ec-badge-color-red-text))] border-[rgb(var(--ec-badge-color-red-text)/0.3)]`,dot:`bg-[rgb(var(--ec-badge-color-red-text))]`}};function uB({src:e,className:t=`absolute inset-0 h-full w-full`}){let[n,r]=(0,h.useState)();return!e||n===e?null:(0,D.jsx)(`img`,{src:e,alt:``,draggable:!1,referrerPolicy:`no-referrer`,onError:()=>r(e),className:`rounded-full object-cover ${t}`})}var dB=e=>(0,D.jsx)(`svg`,{viewBox:`0 0 24 24`,"aria-hidden":!0,...e,children:(0,D.jsx)(`path`,{fill:`#D97757`,d:`M4.709 15.955l4.72-2.647.08-.23-.08-.128H9.2l-.79-.048-2.698-.073-2.339-.097-2.266-.122-.571-.121L0 11.784l.055-.352.48-.321.686.06 1.52.103 2.278.158 1.652.097 2.449.255h.389l.055-.157-.134-.098-.103-.097-2.358-1.596-2.552-1.688-1.336-.972-.724-.491-.364-.462-.158-1.008.656-.722.881.06.225.061.893.686 1.908 1.476 2.491 1.833.365.304.145-.103.019-.073-.164-.274-1.355-2.446-1.446-2.49-.644-1.032-.17-.619a2.97 2.97 0 01-.104-.729L6.283.134 6.696 0l.996.134.42.364.62 1.414 1.002 2.229 1.555 3.03.456.898.243.832.091.255h.158V9.01l.128-1.706.237-2.095.23-2.695.08-.76.376-.91.747-.492.584.28.48.685-.067.444-.286 1.851-.559 2.903-.364 1.942h.212l.243-.242.985-1.306 1.652-2.064.73-.82.85-.904.547-.431h1.033l.76 1.129-.34 1.166-1.064 1.347-.881 1.142-1.264 1.7-.79 1.36.073.11.188-.02 2.856-.606 1.543-.28 1.841-.315.833.388.091.395-.328.807-1.969.486-2.309.462-3.439.813-.042.03.049.061 1.549.146.662.036h1.622l3.02.225.79.522.474.638-.079.485-1.215.62-1.64-.389-3.829-.91-1.312-.329h-.182v.11l1.093 1.068 2.006 1.81 2.509 2.33.127.578-.322.455-.34-.049-2.205-1.657-.851-.747-1.926-1.62h-.128v.17l.444.649 2.345 3.521.122 1.08-.17.353-.608.213-.668-.122-1.374-1.925-1.415-2.167-1.143-1.943-.14.08-.674 7.254-.316.37-.729.28-.607-.461-.322-.747.322-1.476.389-1.924.315-1.53.286-1.9.17-.632-.012-.042-.14.018-1.434 1.967-2.18 2.945-1.726 1.845-.414.164-.717-.37.067-.662.401-.589 2.388-3.036 1.44-1.882.93-1.086-.006-.158h-.055L4.132 18.56l-1.13.146-.487-.456.061-.746.231-.243 1.908-1.312-.006.006z`})}),qze=e=>(0,D.jsx)(`svg`,{viewBox:`0 0 24 24`,"aria-hidden":!0,...e,children:(0,D.jsx)(`path`,{fill:`#D97757`,fillRule:`evenodd`,clipRule:`evenodd`,d:`M20.998 10.949H24v3.102h-3v3.028h-1.487V20H18v-2.921h-1.487V20H15v-2.921H9V20H7.488v-2.921H6V20H4.487v-2.921H3V14.05H0V10.95h3V5h17.998v5.949zM6 10.949h1.488V8.102H6v2.847zm10.51 0H18V8.102h-1.49v2.847z`})}),Jze=e=>(0,D.jsx)(`svg`,{viewBox:`0 0 24 24`,"aria-hidden":!0,...e,children:(0,D.jsx)(`path`,{fill:`currentColor`,d:`M9.205 8.658v-2.26c0-.19.072-.333.238-.428l4.543-2.616c.619-.357 1.356-.523 2.117-.523 2.854 0 4.662 2.212 4.662 4.566 0 .167 0 .357-.024.547l-4.71-2.759a.797.797 0 00-.856 0l-5.97 3.473zm10.609 8.8V12.06c0-.333-.143-.57-.429-.737l-5.97-3.473 1.95-1.118a.433.433 0 01.476 0l4.543 2.617c1.309.76 2.189 2.378 2.189 3.948 0 1.808-1.07 3.473-2.76 4.163zM7.802 12.703l-1.95-1.142c-.167-.095-.239-.238-.239-.428V5.899c0-2.545 1.95-4.472 4.591-4.472 1 0 1.927.333 2.712.928L8.23 5.067c-.285.166-.428.404-.428.737v6.898zM12 15.128l-2.795-1.57v-3.33L12 8.658l2.795 1.57v3.33L12 15.128zm1.796 7.23c-1 0-1.927-.332-2.712-.927l4.686-2.712c.285-.166.428-.404.428-.737v-6.898l1.974 1.142c.167.095.238.238.238.428v5.233c0 2.545-1.974 4.472-4.614 4.472zm-5.637-5.303l-4.544-2.617c-1.308-.761-2.188-2.378-2.188-3.948A4.482 4.482 0 014.21 6.327v5.423c0 .333.143.571.428.738l5.947 3.449-1.95 1.118a.432.432 0 01-.476 0zm-.262 3.9c-2.688 0-4.662-2.021-4.662-4.519 0-.19.024-.38.047-.57l4.686 2.71c.286.167.571.167.856 0l5.97-3.448v2.26c0 .19-.07.333-.237.428l-4.543 2.616c-.619.357-1.356.523-2.117.523zm5.899 2.83a5.947 5.947 0 005.827-4.756C22.287 18.339 24 15.84 24 13.296c0-1.665-.713-3.282-1.998-4.448.119-.5.19-.999.19-1.498 0-3.401-2.759-5.947-5.946-5.947-.642 0-1.26.095-1.88.31A5.962 5.962 0 0010.205 0a5.947 5.947 0 00-5.827 4.757C1.713 5.447 0 7.945 0 10.49c0 1.666.713 3.283 1.998 4.448-.119.5-.19 1-.19 1.499 0 3.401 2.759 5.946 5.946 5.946.642 0 1.26-.095 1.88-.309a5.96 5.96 0 004.162 1.713z`})}),Yze=e=>(0,D.jsx)(`svg`,{viewBox:`0 0 24 24`,"aria-hidden":!0,...e,children:(0,D.jsx)(`path`,{fill:`currentColor`,d:`M22.106 5.68L12.5.135a.998.998 0 00-.998 0L1.893 5.68a.84.84 0 00-.419.726v11.186c0 .3.16.577.42.727l9.607 5.547a.999.999 0 00.998 0l9.608-5.547a.84.84 0 00.42-.727V6.407a.84.84 0 00-.42-.726zm-.603 1.176L12.228 22.92c-.063.108-.228.064-.228-.061V12.34a.59.59 0 00-.295-.51l-9.11-5.26c-.107-.062-.063-.228.062-.228h18.55c.264 0 .428.286.296.514z`})}),Xze=e=>{let t=(e??``).toLowerCase();if(t.includes(`claude code`))return qze;if(/\b(claude|anthropic)\b/.test(t))return dB;if(/\b(codex|chatgpt|openai|gpt)/.test(t))return Jze;if(/\bcursor\b/.test(t))return Yze};function fB({name:e,size:t=14}){let n=Xze(e);return n?(0,D.jsx)(`span`,{className:`flex flex-none items-center justify-center rounded-full bg-white`,style:{width:t+4,height:t+4,color:`#111827`},children:(0,D.jsx)(n,{width:t-2,height:t-2})}):(0,D.jsx)(Lf,{size:t})}var pB=e=>{let t=e.trim().split(/\s+/).filter(Boolean);return(t.length>1?t.map(e=>e[0]).join(``):e.trim()).slice(0,2).toUpperCase()},mB=e=>{let t=Math.round((Date.now()-e)/1e3);if(t<60)return`just now`;let n=Math.round(t/60);if(n<60)return`${n}m ago`;let r=Math.round(n/60);return r<24?`${r}h ago`:new Date(e).toLocaleDateString()},Zze=(e,t)=>{let n=e.nodeId?t.get(e.nodeId):void 0;if(!n||!e.offset)return e.position;let r=oR(n,t);return{x:r.x+e.offset.x,y:r.y+e.offset.y}},hB=(e,t,n)=>{if(!t)return{position:e};let r=oR(t,n??new Map([[t.id,t]]));return{position:e,nodeId:t.id,offset:{x:e.x-r.x,y:e.y-r.y}}},Qze=4,$ze=`nowheel nodrag nopan absolute z-40 w-72 rounded-xl border shadow-xl bg-[rgb(var(--ec-card-bg))] border-[rgb(var(--ec-page-border))] text-[rgb(var(--ec-page-text))]`,gB=e=>{let t=new Map([[e.author.name,e.author]]);for(let n of e.messages)t.has(n.author.name)||t.set(n.author.name,n.author);return[...t.values()]},_B=3,eBe=500,vB=e=>e===1?`1 reply`:`${e} replies`;function tBe({author:e,muted:t,size:n=`h-6 w-6`}){return(0,D.jsxs)(`span`,{title:e.name,className:`relative flex ${n} shrink-0 items-center justify-center rounded-full text-[10px] font-semibold text-white ring-2 ring-[rgb(var(--ec-card-bg))]`,style:{backgroundColor:t?`rgb(var(--ec-page-text-muted))`:e.color},children:[e.agent?(0,D.jsx)(fB,{name:e.name,size:13}):pB(e.name),(0,D.jsx)(uB,{src:e.picture,className:`absolute inset-0 h-full w-full ${t?`opacity-50 grayscale`:``}`})]})}function nBe({author:e,thread:t,active:n,selected:r,resolved:i,onClick:a,onDrag:o}){let s=(0,h.useRef)(null),[c,l]=(0,h.useState)(!1),u=(0,h.useRef)(void 0);(0,h.useEffect)(()=>()=>clearTimeout(u.current),[]);let[d,f]=(0,h.useState)(!1),p=e=>({x:e.clientX-s.current.grab.x,y:e.clientY-s.current.grab.y}),m=t?gB(t):[e],[g,..._]=t?.messages??[],v=!!t&&!!g&&c&&!n&&!d;return(0,D.jsx)(`button`,{onPointerEnter:()=>{clearTimeout(u.current),u.current=setTimeout(()=>l(!0),eBe)},onPointerLeave:()=>{clearTimeout(u.current),l(!1)},onPointerDown:e=>{if(e.button!==0)return;try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}f(!0);let t=e.currentTarget.getBoundingClientRect();s.current={start:{x:e.clientX,y:e.clientY},grab:{x:e.clientX-t.left,y:e.clientY-t.bottom},moved:!1}},onPointerMove:e=>{let t=s.current;if(!t||!o)return;let n=Math.hypot(e.clientX-t.start.x,e.clientY-t.start.y);!t.moved&&n<Qze||(t.moved=!0,o(p(e),`move`))},onPointerUp:e=>{let t=s.current;f(!1),t&&(t.moved?o?.(p(e),`end`):a?.(),s.current=null)},onPointerCancel:()=>{s.current=null,f(!1)},onClick:e=>e.detail===0&&a?.(),"aria-label":t?`Comment by ${t.author.name}${_.length?`, ${vB(_.length)}`:``}`:`New comment`,className:`block cursor-grab rounded-[18px] rounded-bl-none border p-1 text-left shadow-lg transition-[box-shadow,transform] active:cursor-grabbing bg-[rgb(var(--ec-card-bg))] border-[rgb(var(--ec-page-border))] text-[rgb(var(--ec-page-text))] ${n?`ring-2 ring-[rgb(var(--ec-accent))]`:``} ${v?`w-64`:``}`,style:r?{boxShadow:`0 0 0 2px rgb(var(--ec-card-bg)), 0 0 0 4px rgb(var(--ec-button-bg))`}:void 0,children:v?(0,D.jsxs)(`span`,{className:`block space-y-1 px-1.5 py-1`,children:[(0,D.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`flex -space-x-0.5`,children:m.slice(0,_B).map(e=>(0,D.jsx)(tBe,{author:e,muted:i,size:`h-5 w-5`},e.name))}),(0,D.jsx)(`span`,{className:`min-w-0 truncate text-xs font-semibold`,children:t.author.name}),(0,D.jsx)(`span`,{className:`shrink-0 text-[11px] text-[rgb(var(--ec-page-text-muted))]`,children:mB(g.createdAt)})]}),(0,D.jsx)(`span`,{className:`line-clamp-3 block whitespace-pre-wrap break-words text-xs`,children:g.text}),(_.length>0||i)&&(0,D.jsxs)(`span`,{className:`flex items-center gap-2 text-[11px] font-medium text-[rgb(var(--ec-page-text-muted))]`,children:[_.length>0&&(0,D.jsx)(`span`,{children:vB(_.length)}),i&&(0,D.jsxs)(`span`,{className:`flex items-center gap-0.5 ${cB.success.text}`,children:[(0,D.jsx)(Bf,{size:11}),` Resolved`]})]})]}):(0,D.jsxs)(`span`,{className:`flex -space-x-1`,children:[m.slice(0,_B).map(e=>(0,D.jsx)(tBe,{author:e,muted:i},e.name)),m.length>_B&&(0,D.jsxs)(`span`,{className:`flex h-6 w-6 items-center justify-center rounded-full text-[10px] font-semibold ring-2 ring-[rgb(var(--ec-card-bg))] bg-[rgb(var(--ec-page-border))]`,children:[`+`,m.length-_B]})]})})}function rBe({placeholder:e,onSubmit:t,onCancel:n}){let[r,i]=(0,h.useState)(``),a=()=>{r.trim()&&(t(r.trim()),i(``))};return(0,D.jsxs)(`div`,{className:`flex items-end gap-2 p-2`,children:[(0,D.jsx)(`textarea`,{autoFocus:!0,rows:1,value:r,placeholder:e,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),a()),e.key===`Escape`&&n?.()},className:`max-h-32 min-h-[34px] flex-1 resize-none rounded-md border px-2 py-1.5 text-sm bg-[rgb(var(--ec-input-bg))] border-[rgb(var(--ec-input-border))] text-[rgb(var(--ec-input-text))]`}),(0,D.jsx)(`button`,{onClick:a,disabled:!r.trim(),className:`rounded-md px-2.5 py-1.5 text-xs font-medium disabled:opacity-40 bg-[rgb(var(--ec-button-bg))] text-[rgb(var(--ec-button-text))]`,children:`Post`})]})}function yB({title:e,onClick:t,children:n}){return(0,D.jsx)(`button`,{title:e,onClick:t,className:`rounded p-1 text-[rgb(var(--ec-icon-color))] hover:bg-[rgb(var(--ec-page-border)/0.5)] hover:text-[rgb(var(--ec-icon-hover))]`,children:n})}var bB=12,iBe=360,xB=(0,h.createContext)(null);function aBe({children:e,onClickOutside:t}){let n=(0,h.useRef)(null),[r,i]=(0,h.useState)({x:0,y:0}),a=(0,h.useRef)(r);a.current=r;let o=(0,h.useRef)(t);o.current=t;let s=!!t;(0,h.useEffect)(()=>{if(!s)return;let e=e=>{let t=n.current,r=t?.parentElement;!t||e.button!==0||r?.contains(e.target)||t.querySelector(`textarea`)?.value.trim()||o.current?.()};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[s]),(0,h.useEffect)(()=>{let e=n.current;if(!e)return;let t=new ResizeObserver(()=>{let t=e.getBoundingClientRect(),n=e.closest(`.react-flow`)?.getBoundingClientRect()??{top:0,bottom:window.innerHeight},r=Math.min(t.bottom-(n.bottom-bB),t.top-(n.top+bB));r>0&&i(e=>({x:e.x,y:e.y-r}))});return t.observe(e),()=>t.disconnect()},[]);let c=(0,h.useCallback)(e=>{if(e.button!==0||e.target.closest(`button`))return;e.preventDefault();let t=e.currentTarget;t.setPointerCapture(e.pointerId);let n={x:e.clientX,y:e.clientY},r=a.current,o=e=>i({x:r.x+e.clientX-n.x,y:r.y+e.clientY-n.y}),s=()=>{t.removeEventListener(`pointermove`,o),t.removeEventListener(`pointerup`,s),t.removeEventListener(`pointercancel`,s)};t.addEventListener(`pointermove`,o),t.addEventListener(`pointerup`,s),t.addEventListener(`pointercancel`,s)},[]);return(0,D.jsx)(`div`,{ref:n,className:`${$ze} flex flex-col`,style:{left:`calc(100% + 8px + ${r.x}px)`,top:r.y,maxHeight:iBe},children:(0,D.jsx)(xB.Provider,{value:c,children:e})})}function SB({thread:e,onReply:t,onResolve:n,onDelete:r,onClose:i,onExpand:a}){let o=(0,h.useRef)(null),s=(0,h.useContext)(xB);return(0,h.useEffect)(()=>{o.current?.scrollTo({top:o.current.scrollHeight})},[e.messages.length]),(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{onPointerDown:s??void 0,title:s?`Drag to move`:void 0,className:`flex shrink-0 select-none items-center justify-between border-b px-3 py-2 border-[rgb(var(--ec-page-border))] ${s?`cursor-move`:``}`,children:[(0,D.jsxs)(`span`,{className:`flex items-center gap-1 text-xs font-semibold`,children:[s&&(0,D.jsx)(Zf,{size:14,"aria-hidden":!0,className:`-ml-1 text-[rgb(var(--ec-page-text-muted))]`}),e.resolved?`Resolved thread`:`Thread`]}),(0,D.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,D.jsx)(yB,{title:e.resolved?`Reopen`:`Resolve`,onClick:()=>n(!e.resolved),children:e.resolved?(0,D.jsx)(Sp,{size:14}):(0,D.jsx)(Bf,{size:14})}),(0,D.jsx)(yB,{title:`Delete thread`,onClick:r,children:(0,D.jsx)(jp,{size:14})}),a&&(0,D.jsx)(yB,{title:`Open bigger`,onClick:a,children:(0,D.jsx)(sp,{size:14})}),(0,D.jsx)(yB,{title:`Close`,onClick:i,children:(0,D.jsx)(zp,{size:14})})]})]}),(0,D.jsx)(`div`,{ref:o,className:`min-h-0 flex-1 space-y-3 overflow-y-auto px-3 py-3`,children:e.messages.map(e=>(0,D.jsxs)(`div`,{className:`flex gap-2`,children:[(0,D.jsxs)(`span`,{className:`relative flex h-6 w-6 shrink-0 items-center justify-center rounded-full text-[10px] font-semibold text-white`,style:{backgroundColor:e.author.color},children:[e.author.agent?(0,D.jsx)(fB,{name:e.author.name,size:13}):pB(e.author.name),(0,D.jsx)(uB,{src:e.author.picture})]}),(0,D.jsxs)(`div`,{className:`min-w-0`,children:[(0,D.jsxs)(`p`,{className:`text-xs`,children:[(0,D.jsx)(`span`,{className:`font-semibold`,children:e.author.name}),` `,(0,D.jsx)(`span`,{className:`text-[rgb(var(--ec-page-text-muted))]`,children:mB(e.createdAt)})]}),(0,D.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-sm`,children:e.text})]})]},e.id))}),(0,D.jsx)(`div`,{className:`shrink-0 border-t border-[rgb(var(--ec-page-border))]`,children:(0,D.jsx)(rBe,{placeholder:`Reply`,onSubmit:t,onCancel:i})})]})}function oBe({thread:e,onReply:t,onResolve:n,onDelete:r,onShrink:i,onClose:a}){return(0,h.useEffect)(()=>{let e=e=>e.key===`Escape`&&i();return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i]),(0,D.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,onClick:e=>{e.stopPropagation(),i()},onPointerDown:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation(),onContextMenu:e=>e.stopPropagation(),onWheel:e=>e.stopPropagation(),children:(0,D.jsx)(`div`,{role:`dialog`,"aria-label":`Comment thread`,onClick:e=>e.stopPropagation(),className:`flex max-h-[80vh] w-full max-w-xl flex-col rounded-xl border shadow-2xl bg-[rgb(var(--ec-card-bg))] border-[rgb(var(--ec-page-border))] text-[rgb(var(--ec-page-text))]`,children:(0,D.jsx)(SB,{thread:e,onReply:t,onResolve:n,onDelete:r,onClose:a})})})}function CB({anchor:e,zIndex:t,children:n}){let r=Od(e.nodeId??``),i=e.nodeId&&e.offset?r?.internals.positionAbsolute:void 0,{x:a,y:o}=i&&e.offset?{x:i.x+e.offset.x,y:i.y+e.offset.y}:e.position;return(0,D.jsx)(`div`,{className:`absolute`,style:{left:a,top:o,transform:`scale(var(${jz}, 1))`,transformOrigin:`0 0`,zIndex:t},children:(0,D.jsx)(`div`,{className:`nopan nodrag nowheel pointer-events-auto absolute bottom-0 left-0`,children:n})})}var wB=(0,h.memo)(function({threads:e,author:t,openThreadId:n,draft:r,showResolved:i,onOpen:a,onCreate:o,onCancelDraft:s,onReply:c,onResolve:l,onDelete:u,onMove:d,onMoveDraft:f,selectedIds:p,selectionOffset:m,live:g}){let _=(0,h.useRef)(null);hze(_);let{screenToFlowPosition:v,getInternalNode:y}=Dl(),[b,x]=(0,h.useState)(null),S=Az(g,`comment`),[C,w]=(0,h.useState)(null),T=C&&C===n?e.find(e=>e.id===C):void 0,E=e=>{for(let t of document.elementsFromPoint(e.x,e.y)){let e=t.closest(`.react-flow__node`)?.getAttribute(`data-id`),n=e?y(e):void 0;if(n&&!RL(n.type)&&!eR(n.type))return n}},ee=(e,t)=>{let n=v(e),r=t===`end`?E(e):void 0;if(!r)return{position:n};let i=r.internals.positionAbsolute;return{position:n,nodeId:r.id,offset:{x:n.x-i.x,y:n.y-i.y}}};return(0,D.jsx)(IO,{children:(0,D.jsxs)(`div`,{ref:_,className:`absolute left-0 top-0`,style:{zIndex:2001},children:[e.filter(e=>i||!e.resolved||e.id===n).map(e=>{let t=e.id===n;return(0,D.jsxs)(CB,{anchor:b?.threadId===e.id?b.anchor:S.has(e.id)?{position:S.get(e.id)}:m&&!e.nodeId&&p.has(e.id)?{position:{x:e.position.x+m.x,y:e.position.y+m.y}}:e,zIndex:t?2:1,children:[(0,D.jsx)(nBe,{author:e.author,thread:e,active:t,selected:p.has(e.id),resolved:e.resolved,onClick:()=>a(t?null:e.id),onDrag:(t,n)=>{let r=ee(t,n);if(n===`move`)return Oz(g,`comment`,e.id,r.position),x({threadId:e.id,anchor:r});d(e.id,r),Oz(g,`comment`,e.id,null),x(null)}}),t&&T?.id!==e.id&&(0,D.jsx)(aBe,{onClickOutside:()=>a(null),children:(0,D.jsx)(SB,{thread:e,onReply:t=>c(e.id,t),onResolve:t=>l(e.id,t),onDelete:()=>u(e.id),onClose:()=>a(null),onExpand:()=>w(e.id)})})]},e.id)}),T&&(0,kc.createPortal)((0,D.jsx)(oBe,{thread:T,onReply:e=>c(T.id,e),onResolve:e=>l(T.id,e),onDelete:()=>{w(null),u(T.id)},onShrink:()=>w(null),onClose:()=>{w(null),a(null)}}),document.body),r&&(0,D.jsxs)(CB,{anchor:r,zIndex:3,children:[(0,D.jsx)(nBe,{author:t,active:!0,onDrag:(e,t)=>f(ee(e,t))}),(0,D.jsx)(aBe,{children:(0,D.jsx)(rBe,{placeholder:`Add a comment`,onSubmit:o,onCancel:s})})]})]})})});function sBe({threads:e,showResolved:t,onToggleResolved:n,onOpen:r}){let i=e.filter(e=>t||!e.resolved).reverse();return(0,D.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,D.jsxs)(`label`,{className:`mx-3 mb-2 flex items-center gap-2 text-xs text-[rgb(var(--ec-page-text-muted))]`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:t,onChange:n}),`Show resolved`]}),(0,D.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-1.5 overflow-y-auto px-3 pb-3`,children:[i.length===0&&(0,D.jsx)(`p`,{className:`py-6 text-center text-xs text-[rgb(var(--ec-page-text-muted))]`,children:`No comments yet. Right click the canvas, or press C, to add one.`}),i.map(e=>{let[t,...n]=e.messages;return(0,D.jsxs)(`button`,{onClick:()=>r(e),className:`w-full space-y-1 rounded-md border px-2.5 py-2 text-left bg-[rgb(var(--ec-page-bg))] border-[rgb(var(--ec-page-border))] hover:border-[rgb(var(--ec-accent))] ${e.resolved?`opacity-60`:``}`,children:[(0,D.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs`,children:[(0,D.jsx)(`span`,{className:`h-2 w-2 shrink-0 rounded-full`,style:{backgroundColor:e.author.color}}),(0,D.jsx)(`span`,{className:`font-semibold`,children:e.author.name}),(0,D.jsx)(`span`,{className:`text-[rgb(var(--ec-page-text-muted))]`,children:mB(e.createdAt)}),e.resolved&&(0,D.jsx)(Bf,{size:12,className:`ml-auto ${cB.success.text}`})]}),(0,D.jsx)(`p`,{className:`line-clamp-2 text-xs`,children:t?.text}),n.length>0&&(0,D.jsxs)(`p`,{className:`text-[11px] text-[rgb(var(--ec-page-text-muted))]`,children:[n.length,` `,n.length===1?`reply`:`replies`]})]},e.id)})]})]})}var TB=8,cBe=(0,h.memo)(function({menu:e,questions:t,onCopy:n,onDuplicate:r,onPaste:i,onAddNote:a,onAddComment:o,onAddHotspot:s,onEditDetails:c,onReorder:l,onDeleteNode:u,onClose:d}){(0,h.useEffect)(()=>{if(!e)return;let t=e=>{e instanceof KeyboardEvent&&e.key!==`Escape`||d()};return window.addEventListener(`pointerdown`,t),window.addEventListener(`keydown`,t),window.addEventListener(`wheel`,t),()=>{window.removeEventListener(`pointerdown`,t),window.removeEventListener(`keydown`,t),window.removeEventListener(`wheel`,t)}},[e,d]);let f=(0,h.useRef)(null),[p,m]=(0,h.useState)(null);if((0,h.useLayoutEffect)(()=>{let t=f.current;if(!e||!t)return m(null);let{width:n,height:r}=t.getBoundingClientRect(),i=(e,t,n)=>e+t<=n-TB?e:Math.max(TB,Math.min(e-t,n-TB-t));m({left:i(e.x,n,window.innerWidth),top:i(e.y,r,window.innerHeight)})},[e]),!e)return null;let g=`flex w-full items-center gap-2 rounded px-2.5 py-1.5 text-left text-xs hover:bg-[rgb(var(--ec-page-border)/0.5)]`,_=(e,t,n,r,i=``)=>(0,D.jsxs)(`button`,{className:`${g} ${i}`,onClick:n,children:[e,t,r&&(0,D.jsx)(`span`,{className:`ml-auto text-[rgb(var(--ec-page-text-muted))]`,children:r})]}),v=(0,D.jsx)(`div`,{className:`my-1 h-px bg-[rgb(var(--ec-page-border))]`});return(0,D.jsxs)(`div`,{onPointerDown:e=>e.stopPropagation(),onContextMenu:e=>e.preventDefault(),ref:f,className:`fixed z-50 w-56 overflow-y-auto rounded-lg border p-1 shadow-xl bg-[rgb(var(--ec-card-bg))] border-[rgb(var(--ec-page-border))] text-[rgb(var(--ec-page-text))]`,style:{left:p?.left??e.x,top:p?.top??e.y,maxHeight:`calc(100vh - ${TB*2}px)`,visibility:p?`visible`:`hidden`},children:[e.node&&t?.length?(0,D.jsxs)(D.Fragment,{children:[t.map(e=>(0,D.jsxs)(`button`,{className:g,onClick:e.onSelect,children:[(0,D.jsx)(lp,{size:14}),e.label]},e.label)),v]}):null,e.node&&(0,D.jsxs)(D.Fragment,{children:[o&&_((0,D.jsx)(up,{size:14}),`Add comment`,o,`C`),s&&!eR(e.node.type)&&_((0,D.jsx)(Pf,{size:14}),`Add hotspot`,s,`A`),!eR(e.node.type)&&_((0,D.jsx)(Op,{size:14}),`Add a note`,a),c&&!eR(e.node.type)&&_((0,D.jsx)(vp,{size:14}),`Edit details`,c),_((0,D.jsx)(kte,{size:14}),`Copy`,n,`⌘C`),_((0,D.jsx)(Ote,{size:14}),`Duplicate`,r,`⌘D`),v,_((0,D.jsx)(jp,{size:14}),`Delete`,u,`⌫`,cB.danger.text)]}),!e.node&&(0,D.jsxs)(D.Fragment,{children:[o&&_((0,D.jsx)(up,{size:14}),`Add comment`,o,`C`),s&&_((0,D.jsx)(Pf,{size:14}),`Add hotspot`,s,`A`),_((0,D.jsx)(Op,{size:14}),`Add a sticky note`,a,`N`),i&&_((0,D.jsx)(Dte,{size:14}),`Paste here`,i,`⌘V`),l&&(0,D.jsxs)(D.Fragment,{children:[v,_((0,D.jsx)(Tp,{size:14}),`Reorder diagram`,l)]})]})]})}),lBe=typeof Image>`u`?void 0:Object.assign(new Image,{src:`data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7`}),EB=16,uBe={hideAttribution:!0};function dBe(){let e=Pc(),[t,n]=(0,h.useState)(null);return{startDrag:(0,h.useCallback)((t,r,i)=>a=>{a.dataTransfer.setData(t,r),a.dataTransfer.effectAllowed=`move`,lBe&&a.dataTransfer.setDragImage(lBe,0,0),n({preview:i,zoom:e.getState().transform[2],at:{x:a.clientX,y:a.clientY}})},[e]),ghost:t&&(0,D.jsx)(DB,{ghost:t,onEnd:()=>n(null)})}}function DB({ghost:e,onEnd:t}){let n=(0,h.useRef)(null),{preview:r,zoom:i}=e,a=RL(r.type),o=GL(r.type),s={x:o.width/2*i+EB,y:o.height/2*i+EB};(0,h.useEffect)(()=>{let r=(e,t)=>{n.current&&(n.current.style.transform=`translate(${e-s.x}px, ${t-s.y}px)`)};r(e.at.x,e.at.y);let i=e=>{(e.clientX||e.clientY)&&r(e.clientX,e.clientY)};return document.addEventListener(`dragover`,i),document.addEventListener(`drop`,t),document.addEventListener(`dragend`,t),()=>{document.removeEventListener(`dragover`,i),document.removeEventListener(`drop`,t),document.removeEventListener(`dragend`,t)}},[e]);let c=(0,h.useMemo)(()=>[{id:`drag-ghost`,type:r.type,position:{x:0,y:0},data:r.data,...a&&o}],[r,a,o]),l=(0,h.useMemo)(()=>({x:EB,y:EB,zoom:i}),[i]);return(0,D.jsx)(`div`,{ref:n,"aria-hidden":!0,className:`studio-drag-preview eventcatalog-visualizer pointer-events-none fixed left-0 top-0 z-[100] opacity-70`,style:{width:o.width*i+EB*2,height:o.height*i+EB*2},children:(0,D.jsx)(Sd,{children:(0,D.jsx)(Td,{nodes:c,nodeTypes:Kze,defaultViewport:l,proOptions:uBe,nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!1,panOnDrag:!1,zoomOnScroll:!1,zoomOnPinch:!1,preventScrolling:!1})})})}var OB={critical:{label:`Critical`,color:`#dc2626`,icon:Cte,rank:0},warning:{label:`Warning`,color:`#d97706`,icon:Pf,rank:1},info:{label:`Info`,color:`#2563eb`,icon:ep,rank:2}},kB=[`critical`,`warning`,`info`],AB=(e,t)=>OB[e.severity].rank-OB[t.severity].rank||e.createdAt-t.createdAt,fBe=e=>[...e].sort(AB)[0]?.severity,pBe=`--studio-hotspot-scale`,mBe=`--studio-hotspot-panel-scale`,hBe=.5,jB=.6;function MB(e){let t=Pc();(0,h.useLayoutEffect)(()=>{let n=t=>{let n=e.current;if(!n)return;let r=t>=1?1/t:Math.max(1,hBe/t);n.style.setProperty(pBe,String(r)),n.style.setProperty(mBe,String(1/t/r)),n.classList.toggle(`is-icons-only`,t<jB)};return n(t.getState().transform[2]),t.subscribe((e,t)=>{e.transform[2]!==t.transform[2]&&n(e.transform[2])})},[t,e])}function gBe({nodeId:e,position:t,zIndex:n,children:r}){let i=Od(e??``),a=t;if(e){if(!i)return null;let{x:e,y:t}=i.internals.positionAbsolute;a={x:e+(i.measured.width??i.width??0),y:t}}return a?(0,D.jsx)(`div`,{className:`absolute`,style:{left:a.x,top:a.y,transform:`scale(var(${pBe}, 1))`,transformOrigin:`0 0`,zIndex:n},children:(0,D.jsx)(`div`,{className:`nopan nodrag nowheel pointer-events-auto absolute left-[-14px] top-[-14px]`,children:r})}):null}function NB({severity:e,size:t=13}){let{icon:n}=OB[e];return(0,D.jsx)(n,{size:t,strokeWidth:2.5,"aria-hidden":!0})}var PB=4,_Be=14;function vBe({spot:e,open:t,selected:n,onClick:r,onDrag:i}){let a=(0,h.useRef)(null),o=e=>({x:e.clientX-a.current.grab.x,y:e.clientY-a.current.grab.y}),s=[...e.hotspots].sort(AB),c=s[0].severity,l=s.length,u=e.inside?`${l} hotspot${l===1?``:`s`}`:l>1?`${s[0].title} +${l-1}`:s[0].title;return(0,D.jsxs)(`button`,{type:`button`,"aria-expanded":t,title:s.map(e=>`${OB[e.severity].label}: ${e.title}`).join(`
|
|
155
|
-
`),onKeyDown:e=>(e.key===`Enter`||e.key===` `)&&r(),onPointerDown:e=>{if(e.button!==0)return;try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}let t=e.currentTarget.getBoundingClientRect();a.current={start:{x:e.clientX,y:e.clientY},grab:{x:e.clientX-t.left-_Be*(t.height/28),y:e.clientY-t.top-t.height/2},moved:!1}},onPointerMove:e=>{let t=a.current;!t||!i||!t.moved&&Math.hypot(e.clientX-t.start.x,e.clientY-t.start.y)<PB||(t.moved=!0,i(o(e),`move`))},onPointerUp:e=>{let t=a.current;a.current=null,t&&(t.moved?i?.({x:e.clientX-t.grab.x,y:e.clientY-t.grab.y},`end`):r())},onPointerCancel:()=>a.current=null,className:`studio-hotspot-marker flex h-7 max-w-[240px] items-center gap-1.5 rounded-full pl-1 pr-2.5 text-[11px] font-semibold text-white ${i?`cursor-grab active:cursor-grabbing`:``}`,style:{background:OB[c].color,touchAction:`none`,...n&&{boxShadow:`0 0 0 2px rgb(var(--ec-card-bg)), 0 0 0 4px rgb(var(--ec-button-bg))`}},children:[(0,D.jsx)(`span`,{className:`flex h-5 w-5 flex-none items-center justify-center rounded-full bg-white/20`,children:(0,D.jsx)(NB,{severity:c})}),(0,D.jsx)(`span`,{className:`studio-hotspot-label truncate`,children:u})]})}var yBe=`studio-hotspot-panel absolute left-0 top-[34px] w-80 rounded-xl border border-[rgb(var(--ec-page-border))] bg-[rgb(var(--ec-card-bg))] text-[rgb(var(--ec-page-text))] shadow-xl`,bBe=`block w-full rounded-md border border-[rgb(var(--ec-input-border))] bg-[rgb(var(--ec-input-bg))] px-2.5 py-1.5 text-sm text-[rgb(var(--ec-input-text))] outline-none focus:border-[rgb(var(--ec-accent))]`;function xBe({initial:e,submitLabel:t,onSubmit:n,onCancel:r}){let[i,a]=(0,h.useState)(e?.severity??`warning`),[o,s]=(0,h.useState)(e?.title??``),[c,l]=(0,h.useState)(e?.description??``),u=e=>{e?.preventDefault(),o.trim()&&n({severity:i,title:o.trim(),...c.trim()&&{description:c.trim()}})};return(0,D.jsxs)(`form`,{onSubmit:u,onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),r())},className:`space-y-2.5 p-3`,children:[(0,D.jsx)(`div`,{role:`radiogroup`,"aria-label":`How important`,className:`flex gap-1`,children:kB.map(e=>{let t=e===i;return(0,D.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":t,onClick:()=>a(e),className:`flex flex-1 items-center justify-center gap-1 rounded-md border px-2 py-1.5 text-xs font-semibold transition-colors`,style:t?{background:OB[e].color,borderColor:OB[e].color,color:`#fff`}:{borderColor:`rgb(var(--ec-page-border))`,color:OB[e].color},children:[(0,D.jsx)(NB,{severity:e,size:12}),OB[e].label]},e)})}),(0,D.jsx)(`input`,{autoFocus:!0,value:o,maxLength:120,onChange:e=>s(e.target.value),placeholder:`What should people know? e.g. Single point of failure`,className:bBe}),(0,D.jsx)(`textarea`,{value:c,maxLength:1e3,rows:3,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&u()},placeholder:`Why it matters, and what to do about it (optional)`,className:`${bBe} resize-none`}),(0,D.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,D.jsx)(`button`,{type:`button`,onClick:r,className:`rounded-md px-3 py-1.5 text-xs font-medium text-[rgb(var(--ec-page-text-muted))] hover:bg-[rgb(var(--ec-content-hover))]!`,children:`Cancel`}),(0,D.jsx)(`button`,{type:`submit`,disabled:!o.trim(),className:`rounded-md bg-[rgb(var(--ec-primary-bg))] px-3 py-1.5 text-xs font-semibold text-[rgb(var(--ec-primary-text))] disabled:opacity-40`,children:t})]})]})}function FB({severity:e}){return(0,D.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-bold uppercase tracking-wide text-white`,style:{background:OB[e].color},children:[(0,D.jsx)(NB,{severity:e,size:10}),OB[e].label]})}function IB({hotspot:e,actions:t}){return(0,D.jsxs)(`div`,{className:`border-l-[3px] pl-2.5`,style:{borderColor:OB[e.severity].color},children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(FB,{severity:e.severity}),(0,D.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1 truncate text-[11px] text-[rgb(var(--ec-page-text-muted))]`,children:[e.author.agent&&(0,D.jsx)(fB,{name:e.author.name,size:11}),e.author.name,` · `,mB(e.createdAt)]}),t&&(0,D.jsx)(`span`,{className:`ml-auto flex flex-none items-center gap-0.5`,children:t})]}),(0,D.jsx)(`p`,{className:`mt-1.5 text-sm font-semibold leading-snug`,children:e.title}),e.description&&(0,D.jsx)(`p`,{className:`mt-1 whitespace-pre-wrap text-xs leading-relaxed text-[rgb(var(--ec-page-text-muted))]`,children:e.description})]})}function SBe({label:e,onClick:t,children:n}){return(0,D.jsx)(`button`,{type:`button`,title:e,"aria-label":e,onClick:t,className:`rounded p-1 text-[rgb(var(--ec-icon-color))] hover:bg-[rgb(var(--ec-page-border)/0.5)] hover:text-[rgb(var(--ec-icon-hover))]`,children:n})}function LB({spot:e,locked:t,onClose:n,onUpdate:r,onDelete:i,onGo:a}){let[o,s]=(0,h.useState)(null),c=[...e.hotspots].sort(AB);return(0,D.jsxs)(`div`,{className:yBe,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between border-b border-[rgb(var(--ec-page-border))] px-3 py-2`,children:[(0,D.jsx)(`span`,{className:`text-xs font-semibold`,children:c.length===1?`Hotspot`:`${c.length} hotspots`}),(0,D.jsx)(SBe,{label:`Close`,onClick:n,children:(0,D.jsx)(zp,{size:14})})]}),(0,D.jsx)(`div`,{className:`max-h-80 space-y-3 overflow-y-auto p-3`,children:c.map(n=>o===n.id?(0,D.jsx)(`div`,{className:`-m-3`,children:(0,D.jsx)(xBe,{initial:n,submitLabel:`Save`,onCancel:()=>s(null),onSubmit:e=>{r(n.id,e),s(null)}})},n.id):e.inside?(0,D.jsx)(`button`,{type:`button`,onClick:()=>a(n),className:`block w-full rounded-md text-left hover:bg-[rgb(var(--ec-content-hover))]!`,children:(0,D.jsx)(IB,{hotspot:n})},n.id):(0,D.jsx)(IB,{hotspot:n,actions:!t&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(SBe,{label:`Edit`,onClick:()=>s(n.id),children:(0,D.jsx)(vp,{size:13})}),(0,D.jsx)(SBe,{label:`Remove`,onClick:()=>i(n.id),children:(0,D.jsx)(jp,{size:13})})]})},n.id))}),e.inside&&(0,D.jsx)(`p`,{className:`border-t border-[rgb(var(--ec-page-border))] px-3 py-2 text-[11px] text-[rgb(var(--ec-page-text-muted))]`,children:`Inside this: click one to go to it.`})]})}var RB=(0,h.memo)(function({spots:e,openKey:t,draft:n,locked:r,movable:i,selectedIds:a,onMove:o,onDropTarget:s,onOpen:c,onCreate:l,onCancelDraft:u,onUpdate:d,onDelete:f,onGo:p,live:m}){let g=(0,h.useRef)(null);MB(g);let{screenToFlowPosition:_}=Dl(),[v,y]=(0,h.useState)(null),b=Az(m,`hotspot`),x=e=>{for(let t of e.hotspots)if(b.has(t.id))return b.get(t.id)},S=e=>{let t=document.elementsFromPoint(e.x,e.y).find(e=>e.closest(`.react-flow__node`))?.closest(`.react-flow__node`),n=[...t?.classList??[]].find(e=>e.startsWith(`react-flow__node-`))?.slice(17);return t&&!eR(n)?t.getAttribute(`data-id`)??void 0:void 0},C=e=>i&&!r&&!e.inside?(t,n)=>{let r=_(t),i=S(t);if(n===`move`)return i!==v?.over&&s(i?{nodeId:i,severity:fBe(e.hotspots)}:null),Oz(m,`hotspot`,e.hotspots[0].id,r),y({key:e.key,position:r,over:i});y(null),s(null),o(e.hotspots.map(e=>e.id),i?{nodeId:i,position:r}:{position:r}),Oz(m,`hotspot`,e.hotspots[0].id,null)}:void 0;return(0,D.jsx)(IO,{children:(0,D.jsxs)(`div`,{ref:g,className:`absolute left-0 top-0`,style:{zIndex:2e3},children:[e.map(e=>{let n=e.key===t,i=x(e),o=v?.key===e.key?v:i?{position:i}:void 0;return(0,D.jsxs)(gBe,{nodeId:o?void 0:e.nodeId,position:o?o.position:e.position,zIndex:o?5:n?3:1,children:[(0,D.jsx)(vBe,{spot:e,open:n,selected:!!a&&e.hotspots.some(e=>a.has(e.id)),onClick:()=>c(n?null:e.key),onDrag:C(e)}),n&&!o&&(0,D.jsx)(LB,{spot:e,locked:r,onClose:()=>c(null),onUpdate:d,onDelete:f,onGo:p})]},e.key)}),n&&(0,D.jsxs)(gBe,{nodeId:n.nodeId,position:n.nodeId?void 0:n.position,zIndex:4,children:[(0,D.jsx)(`span`,{className:`studio-hotspot-marker flex h-7 w-7 items-center justify-center rounded-full text-white`,style:{background:OB.warning.color},children:(0,D.jsx)(NB,{severity:`warning`})}),(0,D.jsx)(`div`,{className:yBe,children:(0,D.jsx)(xBe,{submitLabel:`Add hotspot`,onSubmit:l,onCancel:u})})]})]})})});function zB({hotspots:e,nameOf:t,onOpen:n}){let r=[...e].sort(AB);return r.length?(0,D.jsx)(`div`,{className:`space-y-1.5 p-3`,children:r.map(e=>{let r=e.nodeId&&t(e.nodeId);return(0,D.jsxs)(`button`,{type:`button`,onClick:()=>n(e),className:`w-full rounded-md border border-[rgb(var(--ec-page-border))] bg-[rgb(var(--ec-page-bg))] px-2.5 py-2 text-left hover:border-[rgb(var(--ec-accent))]!`,children:[(0,D.jsx)(IB,{hotspot:e}),r&&(0,D.jsxs)(`p`,{className:`mt-1.5 pl-[13px] text-[11px] text-[rgb(var(--ec-page-text-muted))]`,children:[`On `,r]})]},e.id)})}):(0,D.jsx)(`p`,{className:`px-4 py-6 text-center text-xs leading-relaxed text-[rgb(var(--ec-page-text-muted))]`,children:`No hotspots yet. Press A, or right-click a node, to flag what people should know: a risk, a problem, or the key part.`})}var BB={[LL.domain]:{icon:zf,className:`text-yellow-500`},[LL.system]:{icon:Qf,className:`text-violet-600`},"context-domain":{icon:zf,className:`text-yellow-500`},system:{icon:Qf,className:`text-violet-600`},service:{icon:Ep,className:`text-pink-600`},event:{icon:Vp,className:`text-orange-600`},command:{icon:ap,className:`text-blue-600`},query:{icon:wp,className:`text-green-600`},channel:{icon:If,className:`text-gray-600`},data:{icon:Gf,className:`text-blue-600`},"data:cache":{icon:Ate,className:`text-blue-600`},"data:searchIndex":{icon:Mte,className:`text-blue-600`},"data:objectStore":{icon:wte,className:`text-blue-600`},view:{icon:pp,className:`text-sky-600`},externalSystem:{icon:Xf,className:`text-purple-600`},agent:{icon:Lf,className:`text-violet-600`},actor:{icon:Fp,className:`text-yellow-500`},team:{icon:Ip,className:`text-emerald-600`},entity:{icon:kp,className:`text-blue-600`},note:{icon:Op,className:`text-yellow-500`},text:{icon:Mp,className:`text-[rgb(var(--ec-icon-color))]`}},CBe=[{collection:`domains`,label:`Domains`,...BB[LL.domain]},{collection:`systems`,label:`Systems`,...BB[LL.system]},{collection:`services`,label:`Services`,...BB.service},{collection:`events`,label:`Events`,...BB.event},{collection:`commands`,label:`Commands`,...BB.command},{collection:`queries`,label:`Queries`,...BB.query},{collection:`channels`,label:`Channels`,...BB.channel},{collection:`containers`,label:`Data Stores`,...BB.data}],VB=QO;function HB({shortcut:e,children:t}){return(0,D.jsxs)(`span`,{className:`relative flex h-8 w-8 items-center justify-center`,children:[(0,D.jsx)(`span`,{className:`-translate-x-[3px] -translate-y-[2px]`,children:t}),(0,D.jsx)(`span`,{"aria-hidden":!0,className:`absolute bottom-[2px] right-[4px] text-[9px] font-medium leading-none text-[rgb(var(--ec-page-text-muted))] opacity-60`,children:e})]})}var wBe={note:`Click anywhere to put a sticky note there`,text:`Click anywhere to start typing`,comment:`Click anywhere, or on a node, to comment there`,hotspot:`Click a node, or anywhere, to flag a hotspot there`};function TBe({level:e,onChange:t,unavailable:n}){return(0,D.jsx)(`div`,{role:`group`,"aria-label":`Level of detail`,className:`flex items-center gap-0.5`,children:pz.map(({level:r,description:i})=>(0,D.jsx)(JO,{label:`Level ${r}: ${i} (${r})`,hint:n?.[r],active:r===e,disabled:!!n?.[r],onClick:()=>t(r),children:(0,D.jsx)(HB,{shortcut:String(r),children:(0,D.jsxs)(`span`,{className:`text-xs font-semibold`,children:[`L`,r]})})},r))})}var EBe=(0,h.memo)(function({level:e,onLevelChange:t,unavailableLevels:n,editable:r,locked:i,onToggleLock:a,lockedBy:o,selectMode:s,onSelectMode:c,handMode:l,onHandMode:u,noteMode:d,onToggleNoteMode:f,textMode:p,onToggleTextMode:m,commentMode:h,onToggleCommentMode:g,hotspotMode:_,onToggleHotspotMode:v,extras:y}){return(0,D.jsxs)(`div`,{className:`absolute left-1/2 top-3 z-10 -translate-x-1/2`,children:[(0,D.jsxs)(YO,{children:[(0,D.jsx)(JO,{label:i?`Locked${o?` by ${o}`:``}: unlock it to change it (for everyone on it)`:`Lock the canvas (it can be looked at, not changed, by everyone on it)`,active:i,onClick:a,children:i?(0,D.jsx)(ip,{className:`h-4 w-4`}):(0,D.jsx)(Ste,{className:`h-4 w-4`})}),(0,D.jsx)(FDe,{}),(0,D.jsx)(JO,{label:`Select (V)`,active:s,onClick:c,children:(0,D.jsx)(HB,{shortcut:`V`,children:(0,D.jsx)(hp,{className:`h-4 w-4`})})}),(0,D.jsx)(JO,{label:`Hand (H): drag to move around`,active:l,onClick:u,children:(0,D.jsx)(HB,{shortcut:`H`,children:(0,D.jsx)($f,{className:`h-4 w-4`})})}),(0,D.jsx)(FDe,{}),(0,D.jsx)(TBe,{level:e,onChange:t,unavailable:n}),(0,D.jsx)(FDe,{}),(0,D.jsx)(JO,{label:r?`Sticky note (N): click where it goes`:`Sticky note (N): on L${e}, where it's clicked`,active:d,disabled:i,hint:i?`The canvas is locked`:void 0,onClick:f,children:(0,D.jsx)(HB,{shortcut:`N`,children:(0,D.jsx)(Op,{className:`h-4 w-4 text-yellow-500`})})}),(0,D.jsx)(JO,{label:r?`Text (T): click anywhere and type`:`Text (T): on L${e}, where it's clicked`,active:p,disabled:i,hint:i?`The canvas is locked`:void 0,onClick:m,children:(0,D.jsx)(HB,{shortcut:`T`,children:(0,D.jsx)(Mp,{className:`h-4 w-4`})})}),(0,D.jsx)(JO,{label:`Comment (C): click where it goes, or on a node`,active:h,onClick:g,children:(0,D.jsx)(HB,{shortcut:`C`,children:(0,D.jsx)(up,{className:`h-4 w-4`})})}),(0,D.jsx)(JO,{label:`Hotspot (A): click a node, or anywhere, to flag it`,active:_,disabled:i,hint:i?`The canvas is locked`:void 0,onClick:v,children:(0,D.jsx)(HB,{shortcut:`A`,children:(0,D.jsx)(Pf,{className:`h-4 w-4 text-amber-600`})})}),y]}),(d||p||h||_)&&(0,D.jsxs)(`p`,{className:`pointer-events-none mt-2 text-center text-xs text-[rgb(var(--ec-page-text-muted))]`,children:[wBe[d?`note`:h?`comment`:_?`hotspot`:`text`],` `,`·`,` `,(0,D.jsx)(`kbd`,{className:`rounded border border-[rgb(var(--ec-page-border))] px-1 font-sans text-[11px]`,children:`Esc`}),` `,`to cancel`]})]})}),DBe=(0,h.memo)(function({canUndo:e,canRedo:t,onUndo:n,onRedo:r,onReorder:i,reorderLabel:a,locked:o,fitOptions:s=VB,comments:c,hotspots:l}){let{zoomIn:u,zoomOut:d,fitView:f}=Dl();return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(YO,{children:[(0,D.jsx)(JO,{label:`Zoom out`,onClick:()=>void d({duration:200}),children:(0,D.jsx)(Up,{className:`h-4 w-4`})}),(0,D.jsx)(PDe,{}),(0,D.jsx)(JO,{label:`Zoom in`,onClick:()=>void u({duration:200}),children:(0,D.jsx)(Hp,{className:`h-4 w-4`})})]}),(0,D.jsxs)(YO,{children:[(0,D.jsx)(JO,{label:`Undo (⌘Z)`,hint:e?void 0:`Nothing to undo`,disabled:!e,onClick:n,children:(0,D.jsx)(Np,{className:`h-4 w-4`})}),(0,D.jsx)(JO,{label:`Redo (⇧⌘Z)`,hint:t?void 0:`Nothing to redo`,disabled:!t,onClick:r,children:(0,D.jsx)(jte,{className:`h-4 w-4`})})]}),(0,D.jsxs)(YO,{children:[(0,D.jsx)(JO,{label:`Fit view (⇧1)`,onClick:()=>void f({...s,duration:500}),children:(0,D.jsx)(cp,{className:`h-4 w-4`})}),(0,D.jsx)(JO,{label:a,hint:o?`The canvas is locked`:void 0,disabled:o,onClick:i,children:(0,D.jsx)(Tp,{className:`h-4 w-4`})})]}),c&&(0,D.jsxs)(YO,{children:[(0,D.jsx)(JO,{label:c.open?`Comments (${c.open} open)`:`Comments`,active:c.active,onClick:c.onToggle,children:(0,D.jsxs)(`span`,{className:`relative`,children:[(0,D.jsx)(dp,{className:`h-4 w-4`}),c.open>0&&(0,D.jsx)(`span`,{className:`absolute -right-2 -top-2 min-w-4 rounded-full bg-[rgb(var(--ec-accent))] px-1 text-center text-[9px] font-semibold leading-4 text-white`,children:c.open})]})}),l&&(0,D.jsx)(JO,{label:l.count?`Hotspots (${l.count})`:`Hotspots`,active:l.active,onClick:l.onToggle,children:(0,D.jsxs)(`span`,{className:`relative`,children:[(0,D.jsx)(Pf,{className:`h-4 w-4`}),l.count>0&&(0,D.jsx)(`span`,{className:`absolute -right-2 -top-2 min-w-4 rounded-full px-1 text-center text-[9px] font-semibold leading-4 text-white`,style:{background:OB[l.severity??`warning`].color},children:l.count})]})})]})]})}),UB=(e,t)=>`${e} ${t}${e===1?``:`s`}`,WB=()=>(0,D.jsxs)(`svg`,{viewBox:`0 0 64 36`,className:`h-9 w-16`,"aria-hidden":!0,children:[(0,D.jsx)(`rect`,{x:`18`,y:`8`,width:`28`,height:`20`,rx:`4`,fill:`currentColor`,fillOpacity:`0.1`,stroke:`currentColor`,strokeOpacity:`0.5`,strokeWidth:`1.5`}),(0,D.jsx)(`rect`,{x:`23`,y:`13`,width:`14`,height:`3`,rx:`1.5`,fill:`currentColor`,fillOpacity:`0.6`}),(0,D.jsx)(`rect`,{x:`23`,y:`19`,width:`18`,height:`2`,rx:`1`,fill:`currentColor`,fillOpacity:`0.35`}),(0,D.jsx)(`path`,{d:`M46 18h12`,stroke:`currentColor`,strokeOpacity:`0.5`,strokeWidth:`1.5`,strokeDasharray:`2 2`}),(0,D.jsx)(`rect`,{x:`57`,y:`14`,width:`6`,height:`8`,rx:`1.5`,fill:`currentColor`,fillOpacity:`0.4`})]}),OBe=[{as:`card`,label:`Card`,hint:`Connected to what it contains`,Preview:WB},{as:`container`,label:`Container`,hint:`What it contains sits inside it`,Preview:()=>(0,D.jsxs)(`svg`,{viewBox:`0 0 64 36`,className:`h-9 w-16`,"aria-hidden":!0,children:[(0,D.jsx)(`rect`,{x:`4`,y:`2`,width:`56`,height:`32`,rx:`4`,fill:`currentColor`,fillOpacity:`0.08`,stroke:`currentColor`,strokeOpacity:`0.5`,strokeWidth:`1.5`}),(0,D.jsx)(`path`,{d:`M4 10h56`,stroke:`currentColor`,strokeOpacity:`0.35`,strokeWidth:`1`}),(0,D.jsx)(`rect`,{x:`8`,y:`4.5`,width:`14`,height:`3`,rx:`1.5`,fill:`currentColor`,fillOpacity:`0.6`}),(0,D.jsx)(`rect`,{x:`10`,y:`15`,width:`18`,height:`12`,rx:`2`,fill:`currentColor`,fillOpacity:`0.5`}),(0,D.jsx)(`rect`,{x:`36`,y:`15`,width:`18`,height:`12`,rx:`2`,fill:`currentColor`,fillOpacity:`0.5`})]})}];function kBe({kind:e,name:t,contents:n,position:r,onChoose:i,onCancel:a}){let[o,s]=(0,h.useState)(!0),c=n?[n.systems>0&&UB(n.systems,`system`),n.services>0&&UB(n.services,`service`)].filter(Boolean).join(` and `):``;(0,h.useEffect)(()=>{let e=e=>e.key===`Escape`&&a();return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[a]);let l=Math.min(Math.max(r.x-160,12),window.innerWidth-332),u=Math.min(Math.max(r.y-20,12),window.innerHeight-(c?260:200));return(0,D.jsx)(`div`,{className:`fixed inset-0 z-50`,onPointerDown:a,children:(0,D.jsxs)(`div`,{role:`dialog`,"aria-label":t?`Add ${t} as`:`Add the ${e} as`,onPointerDown:e=>e.stopPropagation(),className:`absolute w-80 rounded-lg border p-1.5 shadow-xl bg-[rgb(var(--ec-card-bg))] border-[rgb(var(--ec-page-border))] text-[rgb(var(--ec-page-text))]`,style:{left:l,top:u},children:[(0,D.jsxs)(`div`,{className:`flex items-start justify-between gap-2 px-2 pb-1.5 pt-1`,children:[(0,D.jsxs)(`div`,{className:`min-w-0`,children:[(0,D.jsxs)(`p`,{className:`text-[10px] font-semibold uppercase tracking-wider text-[rgb(var(--ec-page-text-muted))]`,children:[`Add this `,e,` as`]}),t&&(0,D.jsx)(`p`,{className:`truncate text-xs font-semibold`,children:t})]}),(0,D.jsx)(`button`,{onClick:a,"aria-label":`Cancel`,className:`rounded p-0.5 text-[rgb(var(--ec-icon-color))] hover:bg-[rgb(var(--ec-page-border)/0.5)]`,children:(0,D.jsx)(zp,{size:14})})]}),(0,D.jsx)(`div`,{className:`grid grid-cols-2 gap-1.5 px-0.5 pb-0.5`,children:OBe.map(({as:e,label:t,hint:n,Preview:r})=>(0,D.jsxs)(`button`,{autoFocus:e===`container`,onClick:()=>i(e===`card`?{as:e}:{as:e,withContents:o&&!!c}),className:`flex flex-col items-center gap-1 rounded-md border px-2 pb-1.5 pt-2 text-xs outline-none transition-colors border-[rgb(var(--ec-page-border))] text-[rgb(var(--ec-page-text-muted))] hover:border-[rgb(var(--ec-accent))] hover:bg-[color-mix(in_srgb,rgb(var(--ec-accent))_8%,transparent)] hover:text-[rgb(var(--ec-accent))] focus-visible:border-[rgb(var(--ec-accent))] focus-visible:text-[rgb(var(--ec-accent))]`,children:[(0,D.jsx)(r,{}),(0,D.jsx)(`span`,{className:`font-semibold`,children:t}),(0,D.jsx)(`span`,{className:`text-center text-[10px] leading-tight text-[rgb(var(--ec-page-text-muted))]`,children:n})]},e))}),c&&(0,D.jsxs)(`label`,{className:`mt-1 flex items-center gap-2 rounded-md px-2 py-1.5 text-[11px] text-[rgb(var(--ec-page-text-muted))]`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked)}),`As a container, bring its `,c,` inside, with their messages and data stores`]})]})})}var ABe=.4,jBe=1.6,GB=8,KB=(0,h.memo)(function({nodeId:e,locked:t,onClick:n}){let r=Nc(e=>e.transform[2]),i=Math.min(jBe,Math.max(ABe,r));return(0,D.jsx)(sf,{nodeId:e,isVisible:!0,position:co.Top,align:`end`,offset:GB*i,children:(0,D.jsx)(`button`,{type:`button`,className:`studio-edit-button`,style:{transform:`scale(${i})`,transformOrigin:`bottom right`},onClick:n,children:t?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(ep,{"aria-hidden":!0}),` Details`]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(vp,{"aria-hidden":!0}),` Edit`]})})})}),qB=`application/eventcatalog-studio`,JB=nRe.map(e=>({...e,definitions:iRe.filter(t=>t.category===e.id&&!t.unlisted)})),YB=e=>({type:e===`domain`?`context-domain`:`system`,data:{mode:`full`,navigable:!1,[e]:{name:e===`domain`?`New Domain`:`New System`,version:`0.0.1`}}}),MBe=new Map(iRe.map(e=>[BL(e),e.type===LL.domain?YB(`domain`):e.type===LL.system?YB(`system`):{type:e.type,data:e.createData()}])),NBe=`eventcatalog-studio-palette-collapsed`,PBe=()=>{try{return localStorage.getItem(NBe)===`true`}catch{return!1}};function FBe({icon:e,iconClassName:t,label:n,description:r,usable:i=!0,onDragStart:a,onClick:o,title:s,trailing:c}){return(0,D.jsxs)(`button`,{type:`button`,draggable:i&&!!a,"aria-disabled":!i,onDragStart:i?a:void 0,onClick:i?o:void 0,"aria-label":n,title:s,className:`group flex w-full items-center gap-2.5 rounded-lg border border-[rgb(var(--ec-page-border))] bg-[rgb(var(--ec-card-bg))] py-1 pl-1 pr-2 text-left text-[rgb(var(--ec-page-text))] shadow-[0_1px_2px_rgb(0_0_0/0.05)] transition-[transform,box-shadow,border-color] duration-150 ${i?`cursor-grab hover:-translate-y-px hover:border-[color-mix(in_srgb,rgb(var(--ec-accent))_45%,transparent)]! hover:shadow-[0_4px_12px_rgb(0_0_0/0.08)] active:translate-y-0 active:cursor-grabbing`:`cursor-not-allowed opacity-40 grayscale`}`,children:[(0,D.jsx)(`span`,{className:`flex h-8 w-8 flex-none items-center justify-center rounded-md bg-[rgb(var(--ec-content-hover))]`,children:(0,D.jsx)(e,{size:16,className:t})}),(0,D.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,D.jsx)(`span`,{className:`block truncate text-[13px] font-medium leading-tight`,children:n}),r&&(0,D.jsx)(`span`,{className:`block truncate text-[11px] leading-snug text-[rgb(var(--ec-page-text-muted))]`,children:r})]}),c??(i&&a&&(0,D.jsx)(Zf,{"aria-hidden":!0,size:14,className:`flex-none text-[rgb(var(--ec-page-text-muted))] opacity-40 transition-opacity group-hover:opacity-80`}))]})}function XB({title:e,divided:t=!1,children:n}){return(0,D.jsxs)(`section`,{className:t?`border-t border-[rgb(var(--ec-page-border))] pt-3`:``,children:[(0,D.jsx)(`h3`,{className:`mb-1.5 text-[11px] font-medium text-[rgb(var(--ec-page-text-muted))]`,children:e}),(0,D.jsx)(`div`,{className:`space-y-1.5`,children:n})]})}var IBe=`components`,LBe=(0,h.memo)(function({level:e,onAddComponent:t,footer:n,tabs:r,tab:i,onTabChange:a,startCollapsed:o}){let{startDrag:s,ghost:c}=dBe(),[l,u]=(0,h.useState)(()=>o??PBe()),d=e=>{if(o===void 0)try{localStorage.setItem(NBe,String(e))}catch{}},f=(0,h.useCallback)(()=>{u(e=>(d(!e),!e))},[]),[p,m]=(0,h.useState)(IBe),g=i??(r?.some(e=>e.id===p)?p:IBe),_=e=>{m(e),a?.(e),l&&(u(!1),d(!1))},v=(0,h.useRef)(i);(0,h.useEffect)(()=>{i!==v.current&&(v.current=i,!(i===void 0||!l)&&(u(!1),d(!1)))},[i]);let y=JB.flatMap(t=>t.definitions.filter(t=>!QL(t.type,e))),b=(e,n=!0)=>{let{label:r,summary:i,firstLevel:a}=e,o=BL(e),{icon:c,className:l}=BB[o]??BB[e.type];return(0,D.jsx)(FBe,{icon:c,iconClassName:l,label:n?r:`${r}: shown from Level ${a}`,description:n?i:`Shown from Level ${a}`,usable:n,onDragStart:s(qB,o,MBe.get(o)),onClick:()=>t(o),title:n?`${r}: drag onto the canvas, or click to add`:void 0},o)},x=(0,D.jsxs)(D.Fragment,{children:[JB.map(t=>{let n=t.definitions.filter(t=>QL(t.type,e));return n.length?(0,D.jsx)(XB,{title:t.label,children:n.map(e=>b(e))},t.id):null}),y.length>0&&(0,D.jsx)(XB,{title:`Not on Level ${e}`,divided:!0,children:y.map(e=>b(e,!1))})]}),S=r?.find(e=>e.id===g),C=(e,t,n)=>(0,D.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":g===e,onClick:()=>_(e),className:`flex flex-1 items-center justify-center gap-1 whitespace-nowrap rounded-md px-1.5 py-1 text-xs font-medium ${g===e&&!l?`bg-[rgb(var(--ec-card-bg))] text-[rgb(var(--ec-page-text))] shadow-sm`:`text-[rgb(var(--ec-page-text-muted))] hover:text-[rgb(var(--ec-page-text))]`}`,children:[t,!!n&&(0,D.jsx)(`span`,{className:`rounded-full bg-[rgb(var(--ec-accent))] px-1.5 text-[10px] leading-4 text-white`,children:n})]},e);return(0,D.jsxs)(`div`,{className:`absolute left-3 top-[62px] z-10 flex w-[264px] flex-col ${l?``:`bottom-[68px]`} rounded-xl border border-[rgb(var(--ec-page-border))] bg-[rgb(var(--ec-card-bg))] text-[rgb(var(--ec-page-text))] shadow-[0_8px_24px_rgb(0_0_0/0.08),0_1px_3px_rgb(0_0_0/0.05)]`,children:[r?.length?(0,D.jsxs)(`div`,{className:`flex flex-none items-center gap-1 p-2`,children:[(0,D.jsxs)(`div`,{role:`tablist`,className:`flex flex-1 gap-0.5 rounded-lg bg-[rgb(var(--ec-page-border)/0.5)] p-0.5`,children:[C(IBe,`Components`),r.map(({id:e,label:t,badge:n})=>C(e,t,n))]}),(0,D.jsx)(`button`,{type:`button`,onClick:f,"aria-expanded":!l,"aria-label":l?`Show the palette`:`Fold the palette away`,className:`flex-none rounded-md p-1 text-[rgb(var(--ec-page-text-muted))] hover:bg-[rgb(var(--ec-page-border)/0.5)]`,children:(0,D.jsx)(Vf,{"aria-hidden":!0,className:`h-4 w-4 transition-transform ${l?`-rotate-90`:``}`})})]}):(0,D.jsxs)(`button`,{type:`button`,onClick:f,"aria-expanded":!l,className:`flex flex-none items-center justify-between rounded-xl px-3.5 py-2.5 text-left text-[13px] font-semibold hover:bg-[rgb(var(--ec-content-hover))]!`,children:[(0,D.jsx)(`span`,{children:`Resources`}),(0,D.jsx)(Vf,{"aria-hidden":!0,className:`h-4 w-4 text-[rgb(var(--ec-page-text-muted))] transition-transform ${l?`-rotate-90`:``}`})]}),!l&&(0,D.jsx)(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto px-3 pb-3`,children:S?S.render(s):x}),!l&&n&&(0,D.jsx)(`div`,{className:`flex-none border-t border-[rgb(var(--ec-page-border))] px-3 py-2.5`,children:n}),c]})}),ZB=typeof navigator<`u`&&/Mac|iPhone|iPad/.test(navigator.platform)?`⌘`:`Ctrl`,RBe=[{group:`Tools`,items:[[`Select`,[`V`]],[`Hand (move around)`,[`H`]],[`Sticky note`,[`N`]],[`Text`,[`T`]],[`Comment`,[`C`]],[`Hotspot`,[`A`]],[`Level 1 / 2 / 3`,[`1`,`2`,`3`]],[`Back to selecting`,[`Esc`]]]},{group:`Canvas`,items:[[`Select everything`,[ZB,`A`]],[`Select several`,[`⇧`,`Click`]],[`Delete what's selected`,[`Delete`]],[`Duplicate`,[ZB,`D`]],[`Copy / paste`,[ZB,`C / V`]],[`Undo / redo`,[ZB,`Z / ⇧Z`]],[`Move around`,[`Scroll`]],[`Zoom`,[ZB,`Scroll`]],[`Fit view`,[`⇧`,`1`]]]},{group:`Notes and text`,items:[[`Write on one`,[`Double-click`]],[`Finish writing`,[`Esc`]]]},{group:`Diagram`,items:[[`Command palette`,[ZB,`K`]],[`Find on canvas`,[ZB,`F`]],[`Open a diagram file`,[ZB,`O`]],[`Save to file`,[ZB,`S`]],[`Export image`,[ZB,`⇧`,`E`]],[`Help`,[`?`]]]}];function zBe({omit:e=[]}){return(0,D.jsx)(`div`,{className:`grid min-h-0 gap-x-8 gap-y-5 overflow-y-auto px-5 py-4 md:grid-cols-2!`,children:RBe.map(({group:t,items:n})=>({group:t,items:n.filter(([t])=>!e.includes(t))})).map(({group:e,items:t})=>(0,D.jsxs)(`section`,{children:[(0,D.jsx)(`h3`,{className:`mb-2 text-[11px] font-semibold uppercase tracking-wide text-[rgb(var(--ec-page-text-muted))]`,children:e}),(0,D.jsx)(`ul`,{className:`divide-y divide-[rgb(var(--ec-page-border))]`,children:t.map(([e,t])=>(0,D.jsxs)(`li`,{className:`flex items-center justify-between gap-3 py-1.5 text-sm`,children:[(0,D.jsx)(`span`,{children:e}),(0,D.jsx)(`span`,{className:`flex gap-1`,children:t.map(e=>(0,D.jsx)(`kbd`,{className:`min-w-6 rounded-md border border-[rgb(var(--ec-page-border))] bg-[rgb(var(--ec-content-hover))] px-1.5 py-0.5 text-center font-sans text-xs text-[rgb(var(--ec-page-text-muted))]`,children:e},e))})]},e))})]},e))})}var BBe=`font-[Excalifont,Inter,sans-serif] text-[14px] leading-snug text-[color-mix(in_srgb,rgb(var(--ec-page-text))_22%,transparent)]`,QB={fill:`none`,stroke:`currentColor`,strokeWidth:1.6,strokeLinecap:`round`,strokeLinejoin:`round`};function VBe({palette:e,live:t}){return(0,D.jsxs)(`div`,{"aria-hidden":!0,className:`hidden md:block! ${BBe}`,children:[e&&(0,D.jsxs)(`div`,{className:`absolute bottom-[120px] left-[290px] flex items-start gap-1`,children:[(0,D.jsxs)(`svg`,{width:`56`,height:`32`,viewBox:`0 0 70 40`,...QB,children:[(0,D.jsx)(`path`,{d:`M66 8 C 45 4, 22 10, 6 26`}),(0,D.jsx)(`path`,{d:`M6 26 L15.7 23.4 M6 26 L8.6 16.3`})]}),(0,D.jsx)(`p`,{className:`-mt-0.5 max-w-[160px]`,children:`Drag resources onto the canvas, then connect them`})]}),(0,D.jsxs)(`div`,{className:`absolute left-[calc(50%+6px)] top-[66px] flex -translate-x-1/2 flex-col items-center`,children:[(0,D.jsxs)(`svg`,{width:`32`,height:`45`,viewBox:`0 0 40 56`,...QB,children:[(0,D.jsx)(`path`,{d:`M14 54 C 6 38, 10 18, 20 4`}),(0,D.jsx)(`path`,{d:`M20 4 L11.8 7.7 M20 4 L19.1 13`})]}),(0,D.jsx)(`p`,{className:`mt-1 whitespace-nowrap`,children:`Switch between levels of detail`})]}),t&&(0,D.jsxs)(`div`,{className:`absolute right-[52px] top-[66px] flex items-end gap-1`,children:[(0,D.jsx)(`p`,{className:`mb-[-5px] max-w-[200px] text-right`,children:`Start live collaboration with your team or agents`}),(0,D.jsxs)(`svg`,{width:`40`,height:`48`,viewBox:`0 0 50 60`,className:`flex-none`,...QB,children:[(0,D.jsx)(`path`,{d:`M6 56 C 30 52, 42 30, 40 4`}),(0,D.jsx)(`path`,{d:`M40 4 L36.1 12.1 M40 4 L45.1 11.4`})]})]})]})}var HBe=typeof navigator<`u`&&/Mac|iPhone|iPad/.test(navigator.platform)?`Cmd`:`Ctrl`;function $B({welcome:e=!0,onOpen:t,onHelp:n,onConnect:r,palette:i,live:a}){let[o,s]=(0,h.useState)(!1),[c,l]=(0,h.useState)(!1);if((0,h.useEffect)(()=>{let e=()=>s(!0),t=()=>s(!1),n=()=>{l(!0),s(!1)};return document.addEventListener(`dragstart`,e),document.addEventListener(`dragend`,t),document.addEventListener(`drop`,n),()=>{document.removeEventListener(`dragstart`,e),document.removeEventListener(`dragend`,t),document.removeEventListener(`drop`,n)}},[]),o||c)return null;let u=(e,t,n,r)=>(0,D.jsxs)(`button`,{type:`button`,onClick:n,className:`group flex h-11 w-full items-center gap-3.5 rounded-lg px-3 text-left text-[15px] text-[rgb(var(--ec-page-text-muted))] transition-colors hover:bg-[rgb(var(--ec-content-hover))]! hover:text-[rgb(var(--ec-page-text))]! [&_svg]:h-[18px] [&_svg]:w-[18px] [&_svg]:stroke-[1.75]`,children:[(0,D.jsx)(`span`,{className:`flex flex-none`,children:e}),(0,D.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:t}),r&&(0,D.jsx)(`span`,{className:`flex-none text-[13px] opacity-80`,children:r})]});return(0,D.jsxs)(`div`,{className:`pointer-events-none absolute inset-0 z-[5] flex items-center justify-center px-4 pb-16 pt-40`,children:[(0,D.jsx)(VBe,{palette:i,live:a}),e&&(0,D.jsxs)(`div`,{className:`pointer-events-auto flex w-full max-w-[440px] flex-col items-center`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-3 text-[rgb(var(--ec-page-text))]`,children:[(0,D.jsx)(`span`,{className:`h-11 w-11 [&_svg]:h-full [&_svg]:w-full`,dangerouslySetInnerHTML:{__html:qz}}),(0,D.jsxs)(`span`,{className:`text-[34px] font-bold tracking-tight`,children:[`EventCatalog`,` `,(0,D.jsx)(`span`,{className:`font-light text-[rgb(var(--ec-page-text-muted))]`,children:`Studio`})]})]}),(0,D.jsx)(`p`,{className:`mt-5 text-center font-[Excalifont,Inter,sans-serif] text-[22px] leading-snug text-[color-mix(in_srgb,rgb(var(--ec-page-text))_38%,transparent)]`,children:`Sketch, design and share architecture with your team and AI agents.`}),(0,D.jsxs)(`div`,{className:`mt-10 w-full`,children:[t&&u((0,D.jsx)(Yf,{"aria-hidden":!0}),`Open`,t,`${HBe}+O`),r&&u((0,D.jsx)(bp,{"aria-hidden":!0}),`Connect to MCP Server`,r),u((0,D.jsx)(kf,{"aria-hidden":!0}),`Help`,n,`?`)]})]})]})}var eV=300,tV=12,nV=8,UBe=32;function WBe(e,t,n,r=nV){let[i,a]=(0,h.useState)(null);return(0,h.useEffect)(()=>{let i=0,o=()=>{let s=t.current,c=s?.querySelector(`.react-flow__node[data-id="${CSS.escape(e)}"]`);if(s&&c){let e=s.getBoundingClientRect(),t=c.getBoundingClientRect(),i=n.current?.offsetHeight??200,o=n.current?.offsetWidth||eV,l=t.right+tV+o<=e.right-nV?`right`:`left`,u=l===`right`?t.right-e.left+tV:t.left-e.left-tV-o,d=(e,t)=>Math.min(Math.max(e,nV),Math.max(t,nV)),f=d(Math.min(t.top,t.top+t.height/2-UBe)-e.top,e.height-i-r),p=d(u,e.width-o-nV),m=t.top+t.height/2-e.top-f,h={side:l,left:p,top:f,pointsAt:p===u&&m>=14&&m<=i-14?Math.round(m):void 0};a(e=>e?.left===h.left&&e?.top===h.top&&e?.side===h.side&&e?.pointsAt===h.pointsAt?e:h)}i=requestAnimationFrame(o)};return o(),()=>cancelAnimationFrame(i)},[e,t,n,r]),i}function GBe(){let[e,t]=(0,h.useState)(!1),n=(0,h.useRef)(void 0),r=(0,h.useCallback)(()=>{t(!0),clearTimeout(n.current),n.current=setTimeout(()=>t(!1),1600)},[]);return(0,h.useEffect)(()=>()=>clearTimeout(n.current),[]),{saved:e,showSaved:r}}function KBe({saved:e}){return(0,D.jsx)(`p`,{className:`ec-edit-status ${e?`is-saved`:``}`,"aria-live":`polite`,children:e?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(Bf,{"aria-hidden":!0}),` Saved`]}):`Changes save as you type`})}function rV({nodeId:e,containerRef:t,label:n,kicker:r,header:i,children:a,width:o=340,bottomInset:s=76,onClose:c}){let l=(0,h.useRef)(null),u=WBe(e,t,l,s),d=(0,h.useRef)(c);d.current=c,(0,h.useEffect)(()=>{let e=()=>{let e=document.activeElement;e instanceof HTMLElement&&l.current?.contains(e)&&e.blur(),d.current()},t=t=>{l.current?.contains(t.target)||e()},n=t=>t.key===`Escape`&&e();return document.addEventListener(`pointerdown`,t,!0),document.addEventListener(`keydown`,n),()=>{document.removeEventListener(`pointerdown`,t,!0),document.removeEventListener(`keydown`,n)}},[]);let f=!!u,p=(0,h.useRef)(!1);return(0,h.useEffect)(()=>{if(!f||p.current)return;p.current=!0;let e=l.current?.querySelector(`input:not([readonly]):not([disabled]), textarea:not([readonly]):not([disabled])`);if(e){e.focus({preventScroll:!0});try{e.setSelectionRange(e.value.length,e.value.length)}catch{}}},[f]),(0,D.jsxs)(D.Fragment,{children:[u?.pointsAt!==void 0&&(0,D.jsx)(`span`,{"aria-hidden":!0,className:`ec-doc-card-arrow is-${u.side}`,style:{top:u.top+u.pointsAt-7,left:u.side===`right`?u.left-6:u.left+o-8}}),(0,D.jsxs)(`div`,{ref:l,className:`ec-doc-card`,role:`dialog`,"aria-label":n,style:{width:o,top:u?.top??8,left:u?.left??8,visibility:u?`visible`:`hidden`},children:[(0,D.jsxs)(`header`,{className:`ec-doc-card-header`,children:[(0,D.jsxs)(`div`,{className:`ec-doc-card-kicker`,children:[r,(0,D.jsx)(`button`,{type:`button`,className:`ec-icon-button ec-doc-card-close`,"aria-label":`Close`,onClick:c,children:(0,D.jsx)(zp,{"aria-hidden":!0})})]}),i]}),a]})]})}var iV=250;function qBe({value:e,onSave:t,multiline:n=!1,placeholder:r,className:i=``,label:a,required:o=!1,onSaved:s}){let[c,l]=(0,h.useState)(e),u=(0,h.useRef)(!1),d=(0,h.useRef)(e),f=(0,h.useRef)(null),p=(0,h.useRef)(void 0),m=(0,h.useRef)({value:e,onSave:t,onSaved:s,required:o});m.current={value:e,onSave:t,onSaved:s,required:o},(0,h.useEffect)(()=>{u.current||l(e)},[e]);let g=()=>{clearTimeout(p.current);let e=f.current;if(f.current=null,e===null)return;let{value:t,onSave:n,onSaved:r,required:i}=m.current;i&&!e.trim()||e===t||(n(e),r?.())};(0,h.useEffect)(()=>g,[]);let _=e=>{l(e),f.current=e,clearTimeout(p.current),p.current=setTimeout(g,iV)},v=(0,h.useRef)(!1),y=()=>{if(u.current=!1,v.current){v.current=!1;return}let e=c.trim();o&&!e?(l(d.current),f.current=d.current):(e!==c&&l(e),f.current=e),g()},b=e=>{e.key===`Escape`?(e.stopPropagation(),l(d.current),f.current=d.current,g(),v.current=!0,e.target.blur()):e.key===`Enter`&&(!n||e.metaKey||e.ctrlKey)&&(e.preventDefault(),e.target.blur())},x=()=>{u.current=!0,d.current=e},S=e=>{e&&(e.style.height=`auto`,e.style.height=`${e.scrollHeight+2}px`)};return n?(0,D.jsx)(`textarea`,{ref:S,"aria-label":a,value:c,rows:2,placeholder:r,onChange:e=>{_(e.target.value),S(e.target)},onFocus:x,onBlur:y,onKeyDown:b,className:`ec-editable ${i}`}):(0,D.jsx)(`input`,{"aria-label":a,value:c,placeholder:r,onChange:e=>_(e.target.value),onFocus:x,onBlur:y,onKeyDown:b,className:`ec-editable ${i}`})}function JBe({label:e,children:t,className:n=``}){return(0,D.jsxs)(`label`,{className:`ec-field ${n}`,children:[(0,D.jsx)(`span`,{className:`ec-field-label`,children:e}),t]})}var aV=e=>({...e.node.data,catalog:{key:e.key,url:e.url,version:e.version}}),oV=e=>e.data?.catalog,YBe=e=>{let t=new Map;for(let n of e)for(let e of[n.source,n.target])t.set(e,[...t.get(e)??[],n]);return t},sV=(e,t,n,r,i=e.node.type)=>{let a=[];for(let o of r.get(e.key)??[]){let r=o.source===e.key,s=r?o.target:o.source;for(let e of n.filter(e=>oV(e)?.key===s)){if(o.label===`contains`&&(RL(i)||RL(e.type)))continue;let[n,s]=r?[{id:t,type:i},e]:[e,{id:t,type:i}],c=IL({source:n.id,target:s.id,sourceHandle:null,targetHandle:null},n.type,s.type);a.push(o.label?{...c,label:o.label}:c)}}return a},cV=e=>e.collection===`domains`||e.collection===`systems`,lV=e=>e.collection===`domains`?LL.domain:LL.system,XBe=e=>{let t=e.collection===`domains`?`domain`:`system`,{scope:n}=e.node.data[t]??{};return{[t]:{id:e.id,name:e.name,version:e.version,summary:e.summary,...n&&{scope:n}},catalog:{key:e.key,url:e.url,version:e.version}}},uV=(e,t)=>(t.relationsByKey.get(e.key)??[]).filter(t=>t.source===e.key&&t.label===`contains`).map(e=>t.resourcesByKey.get(e.target)).filter(e=>!!e),dV=(e,t)=>wR(lV(e),XBe(e),t),ZBe=async(e,t,n,r)=>{let i=new Set(r.map(e=>oV(e)?.key).filter(Boolean)),a=dV(e,{x:0,y:0}),o=[a],s=e=>i.has(e)||o.some(t=>oV(t)?.key===e),c=[],l=(e,t)=>{for(let r of uV(e,n))if(!s(r.key))if(cV(r)){let e={...dV(r,{x:0,y:0}),parentId:t};o.push(e),l(r,e.id)}else o.push({...wR(r.node.type,aV(r),{x:0,y:0}),parentId:t}),r.collection===`services`&&c.push({resource:r,parentId:t})};l(e,a.id);for(let e of c)for(let t of n.relationsByKey.get(e.resource.key)??[]){if(t.label===`contains`)continue;let r=n.resourcesByKey.get(t.source===e.resource.key?t.target:t.source);if(!r||s(r.key)||cV(r)||r.collection===`services`)continue;let i=r.collection===`containers`?e.parentId:a.id;o.push({...wR(r.node.type,aV(r),{x:0,y:0}),parentId:i})}if(o.length===1)return{nodes:[dV(e,t)],edges:[]};let u=[],d=[],f=[...r];for(let e of o){let t=oV(e),i=t&&n.resourcesByKey.get(t.key);if(i)for(let t of sV(i,e.id,f,n.relationsByKey,e.type))(r.some(e=>e.id===t.source||e.id===t.target)?d:u).push(t);f.push(e)}let p=rz((await nz(o,u)).nodes),m=p.find(e=>e.id===a.id),h={x:t.x-(m.width??0)/2-m.position.x,y:t.y-(m.height??0)/2-m.position.y};return{nodes:p.map(e=>({...o.find(t=>t.id===e.id),position:e.parentId?e.position:{x:e.position.x+h.x,y:e.position.y+h.y},...RL(e.type)&&{width:e.width,height:e.height}})),edges:[...u,...d]}},QBe=GM(U({ref:H().optional().describe(`Your name for this node, to use in edges`),resource:U({collection:$M(rRe),id:H()}).optional().describe(`A catalog resource to add (latest version)`),type:$M(aRe).optional().describe(`For a new component: what it is`),name:H().optional().describe(`For a new component: its name`),summary:H().optional().describe(`For a new component: what it does. For a note or text: its text`),version:H().optional().describe(`For a new component: its version, e.g. 1.0.0 (defaults to 0.0.1)`),container:RM().optional().describe(`For a domain or system from the catalog: add it as a container that other nodes sit inside, rather than a card`),inside:H().optional().describe(`A ref (or node id) of a container (a domain or system added as one) to put this node inside`),x:LM().optional(),y:LM().optional(),width:LM().positive().optional().describe(`For a container: its width to start with (it grows to fit what is put in it)`),height:LM().positive().optional().describe(`For a container: its height to start with (it grows to fit what is put in it)`)})).min(1),$Be=GM(U({from:H().describe(`A ref from nodes, or the id of a node already on the canvas`),to:H().describe(`A ref from nodes, or the id of a node already on the canvas`),label:H().optional().describe(`Defaults to EventCatalog wording, e.g. "publishes event"`)})),eVe=U({x:LM(),y:LM()}),tVe=U({points:GM(eVe).min(2).max(200),label:eVe.optional()});$Be.element.extend({route:tVe.optional()});var nVe=1e3,rVe=U({nodes:GM(U({ref:H().describe(`The ref of the node it is on the canvas (or its own id, if it's only on this level)`),type:H(),data:QM(H(),HM()),parent:H().optional().describe(`The ref of the node it is shown in on this level`),x:LM().describe(`Its top-left corner (relative to its parent)`),y:LM(),width:LM().positive().optional().describe(`For a container: its size`),height:LM().positive().optional()})).max(nVe),edges:GM(U({from:H(),to:H(),label:H().optional(),type:H().optional(),style:QM(H(),HM()).optional(),markerEnd:HM().optional(),data:QM(H(),HM()).optional().describe(`The edge's data, e.g. its route`)})).max(nVe*2)}),iVe=H().max(300).optional();U({1:rVe.optional(),2:rVe.optional(),unavailable:U({1:iVe,2:iVe}).optional().describe(`Levels the diagram doesn't have, and why`)});var aVe=[`Adds nodes (and connections between them) to the canvas, live for everyone on it.`,`A node is either a catalog resource (resource: { collection, id }), shown with its real name and summary and automatically connected to the related resources already on the canvas (e.g. a service to the events it publishes), or a new component (type, name, summary) for things that are not in the catalog yet, like a proposed service.`,`Give each node a ref to connect new nodes to each other in edges.`,`Domains and systems can be containers (container: true for catalog ones, or type domain-group / system-group for new ones): put services, messages and data stores inside one with inside (its ref or node id), e.g. a domain container with its system containers inside, and their services inside those.`,`Leave out x/y and each node is placed like an architect would: next to what it connects to (in edges, or as a related catalog resource), following the flow left to right (producers on the left of their messages, consumers on the right), lined up with it, and stacked when several connect to the same node. Nothing already on the canvas moves, and nodes connected to nothing go below what is there.`,`Give x/y (a node's centre, like the positions from reading the canvas) only to put a node somewhere specific. Nodes are about 240 wide and 110 tall: leave about 200 between connected nodes for the labels on their connections.`].join(` `),oVe=(e,t)=>({resourcesByKey:new Map(e.map(e=>[e.key,e])),relationsByKey:YBe(t)}),fV=(e,t)=>t??new Map([[e.id,e]]),sVe=(e,t)=>{let n=qL(e.type,e.data),r=oV(e),i=r?.version??(typeof n.version==`string`?n.version:void 0);return{id:e.id,type:UL(e.type),...!eR(e.type)&&{name:n.name},...n.summary?{summary:n.summary}:{},...eR(e.type)?{text:e.data.text}:{},...XL(e)!==void 0&&XL(e)!==3&&{onLevel:`L${XL(e)}`},...r&&{catalogResource:r.key.replace(`:`,`/`)},...i&&{version:i},position:(({x:e,y:t})=>({x:Math.round(e),y:Math.round(t)}))(cVe(e,t)),size:aR(e),...RL(e.type)&&{container:!0},...e.parentId&&{inside:e.parentId}}},cVe=(e,t)=>{let{width:n,height:r}=aR(e),i=oR(e,fV(e,t));return{x:i.x+n/2,y:i.y+r/2}},lVe=(e,t,n)=>{let{width:r,height:i}=aR(e),a=e.parentId?n?.get(e.parentId):void 0,o=a?oR(a,fV(a,n)):{x:0,y:0};return{x:t.x-r/2-o.x,y:t.y-i/2-o.y}},uVe=e=>{let t=RRe(e),n=new Map(t.nodes.map(e=>[e.id,e])),r=new Map(t.nodes.map(e=>[e.id,nR(e.type,e.data,e.id)])),i=t.meta.statusHistory?.at(-1);return{title:t.meta.title,status:DR(t.meta),...i&&{statusChanged:{by:i.by.name,at:new Date(i.at).toISOString(),...i.note&&{note:i.note}}},nodes:t.nodes.map(e=>sVe(e,n)),connections:t.edges.map(e=>({id:e.id,from:e.source,to:e.target,description:`${r.get(e.source)} ${String(e.label||`→`).replace(/\s+/g,` `)} ${r.get(e.target)}`})),comments:t.threads.map(e=>({threadId:e.id,...e.nodeId?{onNode:e.nodeId}:{position:e.position},resolved:e.resolved,messages:e.messages.map(e=>({from:e.author.name,text:e.text}))}))}},dVe=(e,t,n,r=[])=>{let i=new Map(e.map(e=>[e.id,e])),a=new Map,o=[],s=[],c=[],l=e=>e.x!==void 0&&e.y!==void 0,u=e=>l(e)?{x:e.x,y:e.y}:{x:0,y:0},d=(e,t)=>{if(!RL(e.type)||!t.width||!t.height)return e;let n=u(t),{width:r,height:i}=t;return{...e,width:r,height:i,position:{x:n.x-r/2,y:n.y-i/2}}},f=(e,t,n)=>{if(!l(n))return{...e,parentId:t.id};let{width:r,height:a}=aR(e),o=oR(t,i);return{...e,parentId:t.id,position:{x:n.x-r/2-o.x,y:n.y-a/2-o.y}}};for(let e of t){let t;if(e.resource){let r=n.resourcesByKey.get(`${e.resource.collection}:${e.resource.id}`);if(!r){c.push(`No ${e.resource.collection} resource "${e.resource.id}" in the catalog`);continue}t={node:e.container&&cV(r)?d(dV(r,u(e)),e):wR(r.node.type,aV(r),u(e)),name:r.name,resource:r}}else{let n=HL(e.type);if(!n){c.push(`Give each node a resource, or a type (one of ${aRe.join(`, `)})`);continue}let r=eR(n.type)?{...n.createData(),text:e.summary??e.name??``}:tR(n.type,n.createData(),{...e.name&&{name:e.name},...e.summary&&{summary:e.summary},...e.version&&$L(n.type)&&{version:e.version}}),i=d(wR(n.type,r,u(e)),e);t={node:i,name:String(qL(i.type,i.data).name??n.label)}}if(e.inside&&!JL(t.node.type))c.push(`Notes aren't put in containers: "${e.ref??t.name}" was put on the canvas instead`);else if(e.inside){let n=a.get(e.inside)??i.get(e.inside);n&&RL(n.type)?t.node=f(t.node,n,e):c.push(`"${e.inside}" is not a container on the canvas (a domain or system added as a container)`)}l(e)||s.push(t.node.id),i.set(t.node.id,t.node),e.ref&&a.set(e.ref,t.node),o.push({ref:e.ref,...t,canvasPosition:oR(t.node,i)})}let p=new Map,m=(e,t)=>p.set(`${e}>${t}`,{source:e,target:t}),h=e=>a.get(e)?.id??e;r.forEach(e=>m(h(e.from),h(e.to)));let g=new Map;for(let e of i.values()){let t=oV(e)?.key;t&&g.set(t,[...g.get(t)??[],e])}for(let{node:e,resource:t}of o)for(let r of t?n.relationsByKey.get(t.key)??[]:[]){let n=r.source===t?.key;for(let t of g.get(n?r.target:r.source)??[])r.label===`contains`&&(RL(e.type)||RL(t.type))||(n?m(e.id,t.id):m(t.id,e.id))}let _=lz([...i.values()].filter(e=>ZL(e,3)),s,[...p.values()]),v=new Map(o.map(e=>[e.node.id,_.get(e.node.id)??e.canvasPosition]));for(let e of o){let t=_.get(e.node.id);if(!t)continue;let{parentId:n}=e.node,r=n?i.get(n):void 0,a=n?v.get(n)??(r?oR(r,i):{x:0,y:0}):{x:0,y:0};e.canvasPosition=t,e.node={...e.node,position:{x:t.x-a.x,y:t.y-a.y}}}return{planned:o,errors:c}},fVe=e=>new Map(e.flatMap(e=>e.ref?[[e.ref,e.node.id]]:[])),pVe=(e,t)=>{let n=fVe(t);return e.map(e=>({...e,from:n.get(e.from)??e.from,to:n.get(e.to)??e.to}))},mVe=(e,{nodeId:t,name:n,summary:r,version:i})=>e.transact(()=>{let a=SR(e).nodes.get(t);return a?(oV(a)||PR(e,t,e=>eR(a.type)?{...e,text:r??n??e.text}:tR(a.type,e,{...n!==void 0&&{name:n},...r!==void 0&&{summary:r},...i!==void 0&&$L(a.type)&&{version:i}})),{updated:t}):{error:`No node "${t}" on the canvas`}}),hVe=new Set([`events`,`commands`,`queries`]),gVe={receives:`Messages it receives`,sends:`Messages it sends`,dataStores:`Data stores it reads or writes`,senders:`Services that send it`,receivers:`Services that receive it`},_Ve=(e,t,n)=>{if(e.collection===`services`){if(t.collection===`containers`)return`dataStores`;if(hVe.has(t.collection))return n?`sends`:`receives`}if(hVe.has(e.collection)&&t.collection===`services`)return n?`receivers`:`senders`},vVe=(e,t,n)=>{let r=new Map,i=new Set;for(let a of t.relationsByKey.get(e.key)??[]){let o=a.source===e.key,s=t.resourcesByKey.get(o?a.target:a.source);if(!s||i.has(s.key)||n.has(s.key))continue;let c=_Ve(e,s,o);c&&(r.set(c,[...r.get(c)??[],s]),i.add(s.key))}return[`receives`,`senders`,`sends`,`receivers`,`dataStores`].flatMap(e=>{let t=r.get(e);return t?[{id:e,label:gVe[e],resources:t}]:[]})},yVe=(e,t,n,r,i,a)=>{let o=pR(n,e,a),s=e=>({resource:{collection:e.collection,id:e.id}}),{planned:c}=dVe(e,[{...s(t),x:n.x,y:n.y,...o&&{inside:o.id}},...r.map(e=>({...s(e),...o&&e.collection===`containers`&&{inside:o.id}}))],i),l=[...e],u=[];for(let{node:e,resource:t}of c)t&&u.push(...sV(t,e.id,l,i.relationsByKey,e.type)),l.push(e);return{nodes:c.map(e=>e.node),edges:u}},bVe=`Failed to parse input arguments`,xVe=`Tool was executed but the invocation failed. For example, the script function threw an error`,SVe=/^[A-Za-z0-9_.-]{1,128}$/u;function pV(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function CVe(e){if(typeof e==`symbol`)throw TypeError(`Symbol values cannot be converted to a DOMString`);return String(e)}function mV(e){let t=Reflect.get(e,`name`),n=Reflect.get(e,`description`),r=Reflect.get(e,`title`);if(t===void 0)throw TypeError(`Tool "name" is required`);if(n===void 0)throw TypeError(`Tool "description" is required`);let i=Reflect.get(e,`annotations`),a=pV(i)?i:{},o=Reflect.get(e,`inputSchema`),s=Reflect.get(e,`outputSchema`),c=Reflect.get(e,`execute`);return{name:CVe(t),...r===void 0?{}:{title:CVe(r).toWellFormed()},description:CVe(n),...o===void 0?{}:{inputSchema:o},...s===void 0?{}:{outputSchema:s},execute:c,...i===void 0?{}:{annotations:{...a.title===void 0?{}:{title:CVe(a.title).toWellFormed()},readOnlyHint:!!a.readOnlyHint,...a.destructiveHint===void 0?{}:{destructiveHint:!!a.destructiveHint},...a.idempotentHint===void 0?{}:{idempotentHint:!!a.idempotentHint},...a.openWorldHint===void 0?{}:{openWorldHint:!!a.openWorldHint},untrustedContentHint:!!a.untrustedContentHint}}}}function hV(e){return new DOMException(e,`UnknownError`)}function wVe(e){return hV(e instanceof Error?`${xVe}: ${e.message}`:xVe)}function gV(e){return new DOMException(e,`InvalidStateError`)}function TVe(e){if(e.name===``)throw gV(`Tool "name" must be a non-empty string`);if(typeof e.name!=`string`||!SVe.test(e.name))throw gV(`Tool "name" must be 1–128 characters and contain only ASCII alphanumeric, underscore, hyphen, or period`);if(typeof e.description!=`string`||e.description.length===0)throw gV(`Tool "description" must be a non-empty string`);if(typeof e.execute!=`function`)throw TypeError(`Tool "execute" must be a function`)}function _V(e){return{readOnlyHint:e.readOnlyHint??!1,untrustedContentHint:e.untrustedContentHint??!1}}function EVe(e){try{let t=JSON.parse(e);if(Array.isArray(t)||pV(t))return t}catch{}throw hV(bVe)}function DVe(e){if(typeof e==`object`&&e||typeof e==`function`)try{let t=JSON.stringify(e);if(t)return t}catch{}return String(e)||`Operation succeeded`}function OVe(e,t,n=()=>t?.reason){return t?t.aborted?Promise.reject(n()):new Promise((r,i)=>{let a=()=>{o(),i(n())},o=()=>t.removeEventListener(`abort`,a);t.addEventListener(`abort`,a,{once:!0}),e.then(e=>{o(),r(e)},e=>{o(),i(e)})}):e}function vV(e){let t=e.origin===`null`?e:new URL(e.origin),n=t.protocol;if([`https:`,`wss:`,`file:`,`chrome-extension:`,`moz-extension:`].includes(n))return!0;let r=t.hostname.toLowerCase(),i=r.split(`.`),a=i.length===4&&i.every(e=>/^\d{1,3}$/u.test(e)&&Number(e)<=255)&&Number(i[0])===127;return r===`::1`||r===`[::1]`||r===`localhost`||r===`localhost.`||r.endsWith(`.localhost`)||r.endsWith(`.localhost.`)||a}function kVe(e){for(let t of e??[]){let e;try{e=new URL(t)}catch{throw new DOMException(`Invalid or untrustworthy origin: ${String(t)}`,`SecurityError`)}if(!vV(e))throw new DOMException(`Invalid or untrustworthy origin: ${t}`,`SecurityError`)}}function yV(e){if(AVe(),!e)return;let t=e.defaultView?.DOMException??DOMException,n=!1;try{let t=e.defaultView;n=!!(t&&t.document===e)}catch{}if(!n)throw new t(`The associated document is not fully active`,`InvalidStateError`);let r=Reflect.get(e,`permissionsPolicy`)??Reflect.get(e,`featurePolicy`);if(r&&typeof r==`object`){let e=Reflect.get(r,`features`),n=Reflect.get(r,`allowsFeature`);if(typeof e==`function`&&typeof n==`function`){let i=Reflect.apply(e,r,[]);if(Array.isArray(i)&&i.includes(`tools`)){if(Reflect.apply(n,r,[`tools`])===!0)return;throw new t(`WebMCP is disabled by Permissions Policy`,`NotAllowedError`)}}}let i=e.defaultView;if(!(!i||i.parent===i)){try{i.parent.document;return}catch{}throw new t(`WebMCP in cross-origin frames requires native Permissions Policy support`,`NotAllowedError`)}}function AVe(){if(globalThis.originAgentCluster===!1&&globalThis.location?.protocol!==`file:`)throw new DOMException(``,`SecurityError`)}function bV(e){try{if(new URL(String(e)).origin!==`null`)return}catch{}throw new DOMException(`Unsupported tool origin: ${String(e)}`,`NotSupportedError`)}function jVe(e){if(e===null||typeof e!=`object`&&typeof e!=`function`)throw TypeError(`inputSchema must be an object`);let t=JSON.stringify(e);if(t===void 0)throw TypeError(`inputSchema must be JSON-serializable`);return t}var xV=new WeakSet,SV=new WeakMap,CV=new WeakMap;function wV(e){return e.isTrusted&&(xV.has(e)||e.eventPhase!==Event.NONE&&e.target instanceof HTMLFormElement&&CV.has(e.target))}function TV(e,t){if(!wV(e))throw new DOMException(`respondWith() is only available during an agent-invoked submit event`,`InvalidStateError`);if(!e.defaultPrevented)throw new DOMException(`respondWith() requires preventDefault() during an agent-invoked submit event`,`InvalidStateError`);if(e.eventPhase===Event.NONE)throw new DOMException(`respondWith() is only available while the submit event is being dispatched`,`InvalidStateError`);xV.add(e);let n=Promise.resolve(t);SV.set(e,n),e.target instanceof HTMLFormElement&&CV.get(e.target)?.respond(e)}var MVe=new Set([`email`,`password`,`search`,`tel`,`text`,`url`]),EV=new Set([...MVe,`date`,`datetime-local`,`month`,`number`,`time`,`week`]);function NVe(e){return e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement}function PVe(e){return Reflect.get(HTMLFormElement.prototype,`elements`,e)}function FVe(e,t){return Reflect.apply(Element.prototype.getAttribute,e,[t])}function IVe(e,t){return Reflect.apply(Element.prototype.hasAttribute,e,[t])}function LVe(e){return Reflect.get(Node.prototype,`isConnected`,e)}function RVe(e){return Reflect.get(Element.prototype,`shadowRoot`,e)}function zVe(e){return Reflect.apply(HTMLFormElement.prototype.checkValidity,e,[])}function BVe(e,t){Reflect.apply(HTMLFormElement.prototype.requestSubmit,e,t?[t]:[])}function DV(e){return[...PVe(e)].filter(e=>NVe(e)&&!e.matches(`:disabled`)&&!(`readOnly`in e&&e.readOnly&&(e instanceof HTMLTextAreaElement||EV.has(e.type))))}function VVe(e){let t=new Map;for(let n of DV(e)){let e=n.name.trim(),r=t.get(e);r?r.push(n):t.set(e,[n])}return t}function OV(e){return[...e.labels??[]].map(e=>{let t=e.cloneNode(!0);return t instanceof HTMLElement?(t.querySelectorAll(`button, input, meter, output, progress, select, textarea`).forEach(e=>e.remove()),t.textContent?.trim()??``):``}).filter(Boolean).join(`; `)}function HVe(e,t){for(let n=t[0]?.parentElement;n&&n!==e;n=n.parentElement)if(n instanceof HTMLFieldSetElement&&t.every(e=>n.contains(e)))return n}function kV(e,t){if(t.length===1){let e=t[0];return e&&(e.getAttribute(`toolparamdescription`)||OV(e)||e.getAttribute(`aria-description`))||void 0}return HVe(e,t)?.getAttribute(`toolparamdescription`)||void 0}function AV(e,t,n,r){let i=kV(t,n),a=i&&r?`${i} (${r})`:i||r;return a?{...e,description:a}:e}function UVe(e,t){let n=e.getAttribute(t);if(n===null||n.trim()===``)return;let r=Number(n);return Number.isFinite(r)?r:void 0}function WVe(e,t){let n=e/t;return Math.abs(n-Math.round(n))<2**-52*16}function GVe(e){let t=e.getAttribute(`pattern`);if(t!==null)try{return new RegExp(t,`v`),t}catch{return}}function KVe(e,t=!0){let n={type:`number`},r=UVe(e,`min`),i=UVe(e,`max`);r!==void 0&&(n.minimum=r),i!==void 0&&(n.maximum=i);let a=e.getAttribute(`step`);if(a!==`any`){let t=a===null||a===``?1:Number(a),i=Number.isFinite(t)&&t>0?t:1,o=Number(e.getAttribute(`value`));WVe(r??(Number.isFinite(o)?o:0),i)&&(n.multipleOf=i)}let o=t?GVe(e):void 0;return o!==void 0&&(n.pattern=o),n}function jV(e,t){let n=e.getAttribute(`step`),r=n===null||n===``?60:Number(n),i=Number.isFinite(r)&&r>0?r:60;return i<1?`${t}(:[0-5][0-9](\\.[0-9]{1,3})?)?$`:i<60?`${t}(:[0-5][0-9])?$`:`${t}$`}function qVe(e){return{anyOf:e.map(e=>({type:`string`,const:e.value,title:e.textContent??``})),enum:e.map(e=>e.value)}}function JVe(e){return{anyOf:e.map(e=>{let t=OV(e);return{type:`string`,const:e.value,...t?{title:t}:{}}}),enum:e.map(e=>e.value)}}function YVe(e,t){let n=t[0];if(n){if(t.length>1)return t.every(e=>e instanceof HTMLInputElement)?t.every(e=>e.type===`checkbox`)?AV({type:`array`,items:{type:`string`,...JVe(t)},uniqueItems:!0},e,t):t.every(e=>e.type===`radio`)?AV({type:`string`,...JVe(t)},e,t):void 0:void 0;if(n instanceof HTMLTextAreaElement)return AV({type:`string`},e,t);if(n instanceof HTMLSelectElement){let r=qVe([...n.options]);return AV(n.multiple?{type:`array`,items:{type:`string`,...r},uniqueItems:!0}:{type:`string`,...r},e,t)}if(MVe.has(n.type)){let r={type:`string`},i=GVe(n);return i!==void 0&&(r.pattern=i),AV(r,e,t)}if(n.type===`hidden`)return n.getAttribute(`toolparamdescription`)?AV({type:`string`},e,t):void 0;if(n.type===`number`)return AV(KVe(n),e,t);if(n.type===`range`){let r=KVe(n,!1);return r.minimum??=0,r.maximum??=100,AV(r,e,t)}if(n.type===`checkbox`)return AV({type:`boolean`},e,t);if(n.type===`radio`)return AV({type:`string`,...JVe([n])},e,t);if(n.type===`date`)return AV({type:`string`,format:`date`},e,t,`Dates MUST be provided in 'YYYY-MM-DD' format.`);if(n.type===`month`)return AV({type:`string`,format:`^[0-9]{4}-(0[1-9]|1[0-2])$`},e,t);if(n.type===`week`)return AV({type:`string`,format:`^[0-9]{4}-W(0[1-9]|[1-4][0-9]|5[0-3])$`},e,t);if(n.type===`time`)return AV({type:`string`,format:jV(n,`^([01][0-9]|2[0-3]):[0-5][0-9]`)},e,t);if(n.type===`datetime-local`)return AV({type:`string`,format:jV(n,`^[0-9]{4}-(0[1-9]|1[0-2])-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]`)},e,t);if(n.type===`color`)return AV({type:`string`,format:`^#[0-9a-zA-Z]{6}$`},e,t)}}function XVe(e){let t={},n=[];for(let[r,i]of VVe(e)){if(!r)continue;let a=YVe(e,i);a&&(Object.defineProperty(t,r,{configurable:!0,enumerable:!0,value:a,writable:!0}),i.some(e=>e.required)&&n.push(r))}return{type:`object`,properties:t,required:n}}function ZVe(e){return{name:FVe(e,`toolname`)??``,title:FVe(e,`tooltitle`)??``,description:FVe(e,`tooldescription`)??``,inputSchema:XVe(e),autosubmit:IVe(e,`toolautosubmit`)}}function MV(e){if(typeof e==`string`||typeof e==`boolean`||typeof e==`number`&&Number.isFinite(e))return String(e)}function QVe(e){if(typeof e==`boolean`)return e;if(typeof e==`number`&&Number.isInteger(e))return e!==0;if(typeof e==`string`){if(e===`1`||e.toLowerCase()===`true`)return!0;if(e===`0`||e.toLowerCase()===`false`)return!1}}function $Ve(e,t){if(!Array.isArray(e))return!1;let n=new Set(t);for(let t of e){let e=MV(t);if(e===void 0||!n.delete(e))return!1}return!0}function eHe(e,t){if(t===``)return e.type!==`number`&&e.type!==`range`;let n=e.ownerDocument.createElement(`input`);return n.type=e.type,n.value=t,n.value!==``}function NV(e,t,n){let r=t[0];if(!r||!YVe(e,t))return!1;if(t.length>1){if(!t.every(e=>e instanceof HTMLInputElement))return!1;if(t.every(e=>e.type===`checkbox`))return $Ve(n,new Set(t.map(e=>e.value)));if(t.every(e=>e.type===`radio`)){let e=MV(n);return e!==void 0&&t.some(t=>t.value===e)}return!1}if(r instanceof HTMLSelectElement){let e=new Set([...r.options].map(e=>e.value));if(r.multiple)return $Ve(n,e);let t=MV(n);return t!==void 0&&e.has(t)}if(r instanceof HTMLTextAreaElement)return MV(n)!==void 0;if(r.type===`checkbox`)return QVe(n)!==void 0;if(r.type===`radio`){let e=MV(n);return e!==void 0&&r.value===e}let i=MV(n);return i!==void 0&&eHe(r,i)}function PV(e){e.dispatchEvent(new Event(`input`,{bubbles:!0,composed:!0})),e.dispatchEvent(new Event(`change`,{bubbles:!0}))}function tHe(e,t){let n=e instanceof HTMLInputElement?HTMLInputElement.prototype:HTMLTextAreaElement.prototype;Object.getOwnPropertyDescriptor(n,`value`)?.set?.call(e,t)}function FV(e,t){Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,`checked`)?.set?.call(e,t)}function IV(e,t){let n=e[0];if(!n)return;if(e.length>1&&e.every(e=>e instanceof HTMLInputElement)){if(e.every(e=>e.type===`checkbox`)&&Array.isArray(t)){let n=new Set(t.map(MV));for(let t of e){let e=n.has(t.value);t.checked!==e&&(FV(t,e),PV(t))}return}let n=MV(t),r=e.find(e=>e.value===n);r&&!r.checked&&(FV(r,!0),PV(r));return}if(n instanceof HTMLSelectElement){if(n.multiple&&Array.isArray(t)){let e=new Set(t.map(MV)),r=!1;for(let t of n.options){let n=e.has(t.value);t.selected!==n&&(t.selected=n,r=!0)}r&&PV(n);return}let e=MV(t);e!==void 0&&n.value!==e&&(n.value=e,PV(n));return}if(n instanceof HTMLInputElement&&n.type===`checkbox`){let e=QVe(t);e!==void 0&&n.checked!==e&&(FV(n,e),PV(n));return}if(n instanceof HTMLInputElement&&n.type===`radio`){MV(t)===n.value&&!n.checked&&(FV(n,!0),PV(n));return}let r=MV(t);r!==void 0&&n.value!==r&&(tHe(n,r),PV(n))}function nHe(e,t){if(Array.isArray(t))throw TypeError(`Declarative tool input must be an object`);let n=VVe(e);for(let[r,i]of Object.entries(t)){let t=n.get(r);if(!t||!NV(e,t,i))throw TypeError(`Invalid value for declarative form parameter "${r}"`)}for(let[e,r]of Object.entries(t))IV(n.get(e)??[],r)}function rHe(e){return[...PVe(e)].find(e=>!e.matches(`:disabled`)&&(e instanceof HTMLButtonElement&&e.type===`submit`||e instanceof HTMLInputElement&&[`image`,`submit`].includes(e.type)))}function iHe(e){let t=[...PVe(e)].filter(e=>NVe(e)&&e.willValidate&&!e.validity.valid).map(e=>`${e.name.trim()||`{unknown}`}: ${e.validationMessage}`).join(`. `);return new DOMException(`Form validation failed: ${t}`,`UnknownError`)}function aHe(e){let t=new Event(`toolactivated`);return Object.defineProperty(t,"toolName",{enumerable:!0,value:e}),t}function oHe(e,t,n,r){let{form:i}=e;return e.cancelPending?.(new DOMException(`Tool execution cancelled`,`UnknownError`)),new Promise((a,o)=>{let s=!1,c=()=>{Reflect.apply(EventTarget.prototype.removeEventListener,i,[`invalid`,f,!0]),CV.delete(i),e.cancelPending===u&&delete e.cancelPending},l=e=>{s||(s=!0,c(),e())},u=e=>l(()=>o(e)),d=e=>{e.then(e=>l(()=>a(e)),e=>l(()=>o(e)))},f=e=>{e.isTrusted&&queueMicrotask(()=>{zVe(i)||u(iHe(i))})};if(CV.set(i,{complete(e){queueMicrotask(()=>{let t=SV.get(e);t?d(t):e.defaultPrevented?u(new DOMException(`preventDefault() requires respondWith()`,`UnknownError`)):l(()=>a(void 0))})},direct(){l(()=>a(void 0))},respond(e){queueMicrotask(()=>{let t=SV.get(e);t&&d(t)})}}),e.cancelPending=u,Reflect.apply(EventTarget.prototype.addEventListener,i,[`invalid`,f,!0]),!n){r?.focus(),window.dispatchEvent(aHe(t));return}try{BVe(i,r),window.dispatchEvent(aHe(t))}catch(e){u(e)}})}function sHe(e,t){let n=!0,r=new Map,i=new Map,a=new Map,o=e=>{if(!(e instanceof SubmitEvent)||!e.isTrusted||!(e.target instanceof HTMLFormElement))return;let t=CV.get(e.target);t&&(xV.add(e),t.complete(e))},s=e=>{if(!e.isTrusted||!(e.target instanceof HTMLFormElement))return;let t=e.target;queueMicrotask(()=>{e.defaultPrevented||r.get(t)?.cancelPending?.(new DOMException(`Tool execution cancelled by form reset`,`UnknownError`))})};function c(e){a.get(e)?.disconnect(),a.delete(e),e.removeEventListener(`reset`,s,!0),e.removeEventListener(`submit`,o,!0)}function l(e){if(a.has(e))return;let t=new MutationObserver(u);a.set(e,t),t.observe(e,{attributes:!0,characterData:!0,childList:!0,subtree:!0}),e.addEventListener(`reset`,s,!0),e.addEventListener(`submit`,o,!0)}function u(){l(e);for(let e of a.keys())e instanceof ShadowRoot&&!Reflect.get(Node.prototype,`isConnected`,e.host)&&c(e);let n=new Set,o=new Map,s=new Map;for(let e of a.keys())for(let t of e.querySelectorAll(`*`)){let e=RVe(t);if(e&&l(e),!(t instanceof HTMLFormElement)||!IVe(t,`toolname`)||!IVe(t,`tooldescription`)||!LVe(t))continue;let r=t;n.add(r);let a=ZVe(r),c=JSON.stringify(a),u=i.get(r);if(u===c)continue;let d=u!==void 0;i.delete(r);let f=s.get(a.name);if(f&&!d){i.set(r,c);continue}if(f){let e=o.get(f);e&&(i.set(f,e.fingerprint),o.delete(f))}s.set(a.name,r),o.set(r,{definition:a,fingerprint:c})}for(let e of i.keys())n.has(e)||i.delete(e);for(let[e,t]of r)o.get(e)?.fingerprint!==t.fingerprint&&(t.cancelPending?.(new DOMException(`Tool execution cancelled because its form changed`,`UnknownError`)),t.controller.abort(),r.delete(e));for(let[e,{definition:n,fingerprint:i}]of o){if(r.has(e))continue;let a=new AbortController,o={controller:a,fingerprint:i,form:e};r.set(e,o),t.registerTool({name:n.name,title:n.title,description:n.description,inputSchema:n.inputSchema,execute(t){let r=rHe(e);if(!n.autosubmit&&!r)throw new DOMException(`A declarative form without toolautosubmit requires a submit button`,`UnknownError`);return nHe(e,t),oHe(o,n.name,n.autosubmit,r)}},{signal:a.signal}).catch(e=>{a.abort(),e?.name!==`AbortError`&&console.error(`[webmcp] declarative form tool "${n.name}" was not registered:`,e)})}}let d=()=>{},f=e.defaultView?.Element.prototype,p=f?Object.getOwnPropertyDescriptor(f,`attachShadow`):void 0;if(f&&p?.configurable){let t=f.attachShadow,r=function(r){let i=t.call(this,r);return n&&i.mode===`open`&&Reflect.get(Node.prototype,`ownerDocument`,this)===e&&Reflect.get(Node.prototype,`isConnected`,this)&&l(i),i};Object.defineProperty(f,"attachShadow",{...p,value:r}),d=()=>{f.attachShadow===r&&Object.defineProperty(f,"attachShadow",p)}}let m=()=>{},h=e.defaultView?.HTMLFormElement.prototype,g=h?Object.getOwnPropertyDescriptor(h,`submit`):void 0;if(h&&g?.configurable){let e=h.submit,t=function(){e.call(this),n&&CV.get(this)?.direct()};Object.defineProperty(h,"submit",{...g,value:t}),m=()=>{h.submit===t&&Object.defineProperty(h,"submit",g)}}return u(),()=>{n=!1,m(),d();for(let e of a.keys())c(e);i.clear();for(let e of r.values())e.cancelPending?.(new DOMException(`Tool execution cancelled`,`UnknownError`)),e.controller.abort();r.clear()}}var cHe=`__isWebMCPPolyfill`,lHe=Symbol(`registeredInputSchema`),LV=Symbol(`registrationSignal`),uHe=Symbol(`registrationAbort`),RV=[],dHe=null,zV=null;function fHe(){return typeof globalThis.origin==`string`?globalThis.origin:globalThis.location?.origin??``}function BV(e,t,n){let r=Object.getOwnPropertyDescriptor(e,t);try{Object.defineProperty(e,t,n)}catch(e){throw gHe(),e}RV.push({target:e,key:t,previous:r})}var VV=class extends EventTarget{#e=new Map;#t=null;#n=null;#r=e=>{this.#n?.call(this,e)};#i;#a;constructor(e){super(),this.#a=e,this.#i=e?.defaultView?.DOMException??DOMException,Object.defineProperty(this,cHe,{value:!0,enumerable:!1,writable:!1,configurable:!1})}get ontoolchange(){return this.#n}set ontoolchange(e){let t=typeof e==`function`?e:null;if(t===null){this.#n=null,super.removeEventListener(`toolchange`,this.#r);return}this.#n===null&&super.addEventListener(`toolchange`,this.#r),this.#n=t}async registerTool(e,t={}){yV(this.#a);let n=t?.signal,r=pHe(e,this.#e);if(n?.throwIfAborted(),kVe(t?.exposedTo),n?.throwIfAborted(),t?.exposedTo?.length)throw new this.#i(`Cross-document tool exposure requires native WebMCP`,`NotSupportedError`);if(this.#e.set(r.name,r),n){let e=()=>{this.#o(r.name,r)&&this.#c()};r[LV]=n,r[uHe]=e,n.addEventListener(`abort`,e,{once:!0})}if(await this.#c(),n?.aborted)throw n.reason}async getTools(e={}){if(yV(this.#a),kVe(e?.fromOrigins),e?.fromOrigins?.length)throw new this.#i(`Cross-document tool discovery requires native WebMCP`,`NotSupportedError`);let t=[...this.#e.values()].map(e=>{let t=e[lHe],n=t===void 0?void 0:JSON.parse(t);return{name:e.name,title:e.title??``,description:e.description,...pV(n)?{inputSchema:n}:{},origin:fHe(),window:globalThis.window,...e.annotations?{annotations:_V(e.annotations)}:{}}}).sort((e,t)=>e.name<t.name?-1:+(e.name>t.name));return await new Promise(e=>setTimeout(e,0)),t}async executeTool(e,t,n={}){if(yV(this.#a),typeof e!=`object`||!e)throw TypeError(`RegisteredTool must be an object`);for(let t of[`name`,`description`,`window`,`origin`])if(!(t in e))throw TypeError(`RegisteredTool.${t} is required`);if(bV(e.origin),e.window!==globalThis.window||e.origin!==fHe())throw hV(`Tool not found: ${e.name}`);return this.#s(e.name,t,n)}static getTestingShim(e){return e.#t??=new UV(e),e.#t}static getToolInfos(e){return[...e.#e.values()].map(e=>({name:e.name,description:e.description,...e[lHe]===void 0?{}:{inputSchema:e[lHe]}}))}static executeToolForTesting(e,t,n,r){return yV(e.#a),e.#s(t,n,r)}static dispose(e){for(let t of e.#e.keys())e.#o(t);e.ontoolchange=null,e.#t?.dispose()}#o(e,t){let n=this.#e.get(e);if(!n||t&&n!==t)return!1;let r=n[LV],i=n[uHe];return r&&i&&r.removeEventListener(`abort`,i),this.#e.delete(e)}async#s(e,t,n){n?.signal?.throwIfAborted();let r=this.#e.get(e);if(!r)throw hV(`Tool not found: ${e}`);let i=EVe(t);if(n?.signal?.throwIfAborted(),r[LV]?.aborted)throw hV(`Tool unregistered`);let a;try{let e=r[LV];a=await OVe(OVe(Promise.resolve(r.execute(i)),e,()=>hV(`Tool unregistered`)),n?.signal)}catch(e){throw n?.signal?.aborted&&e===n.signal.reason||r[LV]?.aborted?e:wVe(e)}return DVe(a)}async#c(){await new Promise(e=>setTimeout(e,0)),this.dispatchEvent(new Event(`toolchange`)),this.#t?.dispatchToolChange()}},HV=function(){throw TypeError(`Illegal constructor`)};Object.defineProperty(HV,"name",{value:`ModelContext`}),Object.defineProperty(HV,"prototype",{value:VV.prototype,writable:!1}),Object.setPrototypeOf(HV,EventTarget),Object.defineProperty(VV.prototype,"constructor",{configurable:!0,writable:!0,value:HV}),Object.defineProperty(VV.prototype,Symbol.toStringTag,{configurable:!0,value:`ModelContext`});for(let e of[`registerTool`,`getTools`,`executeTool`,`ontoolchange`]){let t=Object.getOwnPropertyDescriptor(VV.prototype,e);t&&Object.defineProperty(VV.prototype,e,{...t,enumerable:!0})}var UV=class extends EventTarget{_ontoolchange=null;ontoolchangeListener=e=>{this._ontoolchange?.call(this,e)};#e;constructor(e){super(),this.#e=e}listTools(){return VV.getToolInfos(this.#e)}executeTool(e,t,n){return VV.executeToolForTesting(this.#e,e,t,n)}get ontoolchange(){return this._ontoolchange}set ontoolchange(e){let t=typeof e==`function`?e:null;if(t===null){this._ontoolchange=null,super.removeEventListener(`toolchange`,this.ontoolchangeListener);return}this._ontoolchange===null&&super.addEventListener(`toolchange`,this.ontoolchangeListener),this._ontoolchange=t}dispatchToolChange(){this.dispatchEvent(new Event(`toolchange`))}dispose(){this.ontoolchange=null}};function pHe(e,t){if(!e||typeof e!=`object`)throw TypeError(`registerTool(tool) requires a tool object`);let n=mV(e);if(TVe(n),t.has(n.name))throw gV(`Tool already registered: ${n.name}`);let r=n.inputSchema===void 0?void 0:jVe(n.inputSchema);return{name:n.name,...n.title===void 0?{}:{title:n.title},description:n.description,...n.inputSchema===void 0?{}:{inputSchema:n.inputSchema},...n.annotations===void 0?{}:{annotations:n.annotations},execute:e=>Reflect.apply(n.execute,void 0,[e]),...r===void 0?{}:{[lHe]:r}}}var WV=!1,GV=new WeakMap,{modelContext:mHe}={modelContext(){if(!(this instanceof Document))throw TypeError(`Illegal invocation`);return GV.get(this)}};Object.defineProperty(mHe,"name",{value:`get modelContext`});function KV(e,t){GV.set(e,t),!Object.hasOwn(Document.prototype,`modelContext`)&&BV(Document.prototype,`modelContext`,{configurable:!0,enumerable:!0,get:mHe})}function qV(e,t){BV(e,`modelContext`,{configurable:!0,enumerable:!0,get(){return WV||(WV=!0,console.warn(`[WebMCPPolyfill] navigator.modelContext is deprecated. The May 27, 2026 WebMCP draft moved the modelContext getter from Navigator to Document — use document.modelContext instead. See https://github.com/webmachinelearning/webmcp/pull/184.`)),t}})}function JV(){let e=SubmitEvent.prototype;`agentInvoked`in e||BV(e,`agentInvoked`,{configurable:!0,enumerable:!0,get(){return wV(this)}}),`respondWith`in e||BV(e,`respondWith`,{configurable:!0,enumerable:!0,writable:!0,value(e){TV(this,e)}})}function hHe(e){if(globalThis.isSecureContext===!1)return;let t=typeof navigator>`u`?null:navigator,n=typeof document>`u`?null:document;if(!t||!n||typeof window>`u`||n.modelContext)return;let r=t.modelContext;if(RV.length>0&&gHe(),r){KV(n,r);return}let i=Object.getOwnPropertyDescriptor(window,`ModelContext`);if(i&&!i.configurable){if(!Object.is(Reflect.get(window,`ModelContext`),HV))throw TypeError(`Cannot install ModelContext over a non-configurable global`)}else BV(window,`ModelContext`,{configurable:!0,enumerable:!1,writable:!0,value:HV});let a=new VV(n);dHe=a,KV(n,a),WV=!1,qV(t,a),JV(),e?.installTestingShim&&!t.modelContextTesting&&BV(t,`modelContextTesting`,{configurable:!0,enumerable:!0,writable:!1,value:VV.getTestingShim(a)}),zV=sHe(n,a)}function gHe(){zV?.(),zV=null,dHe&&VV.dispose(dHe),dHe=null;for(let{target:e,key:t,previous:n}of[...RV].reverse())n?Object.defineProperty(e,t,n):Reflect.deleteProperty(e,t);RV.length=0,WV=!1}var _He=40,YV=e=>new Promise(t=>setTimeout(t,e)),vHe=e=>e<.5?4*e*e*e:1-(-2*e+2)**3/2,XV=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y),yHe=(e,t)=>oR(e,t),ZV=(e,t)=>{let n=yHe(e,t);return{x:n.x+aR(e).width,y:n.y+aR(e).height/2}},bHe=(e,t)=>{let n=yHe(e,t);return{x:n.x,y:n.y+aR(e).height/2}},xHe=e=>nR(e.type,e.data);function QV(e,{pace:t=1}={}){let n={pointer:e.lastPointer??null,selection:[]},r=()=>e.present({...n});return{get pointer(){return n.pointer},async pause(e){await YV(e*t)},say(e){n.activity=e,r()},select(e){n.selection=e,r()},async moveTo(e,{connecting:i,carry:a}={}){let o=n.pointer??{x:e.x-160,y:e.y-120},s=Math.min(900,Math.max(250,200+XV(o,e)*.6))*t,c=Math.max(1,Math.round(s/_He));n.connecting=i??null;for(let t=1;t<=c;t++){let i=vHe(t/c);n.pointer={x:o.x+(e.x-o.x)*i,y:o.y+(e.y-o.y)*i},a&&(n.moving={[a.nodeId]:{x:n.pointer.x-a.grab.x,y:n.pointer.y-a.grab.y}}),r(),await YV(_He)}},release(){n.connecting=null,n.moving=null,r()}}}var SHe=e=>Math.max(.25,Math.min(1,10/Math.max(e,1))),$V=e=>new Map(SR(e).nodes.entries());async function eH(e,t,n,r,i){let a=await e.change($V),o=a.get(r),s=a.get(i);if(!o||!s)return e.change(n);t.say(`Connecting ${xHe(o)} to ${xHe(s)}`);let c=ZV(o,a);await t.moveTo(c),await t.pause(120),await t.moveTo(bHe(s,a),{connecting:c});let l=await e.change(n);return t.release(),await t.pause(180),l}async function tH(e,{nodes:t,edges:n=[]},r){let{planned:i,errors:a}=dVe(await e.change(e=>[...$V(e).values()]),t,r,n),o=pVe(n,i),s=QV(e,{pace:SHe(i.length*2+o.length)}),c=[];for(let{node:t,canvasPosition:n,name:l,resource:u}of i){s.say(`Adding ${l}`);let{width:i,height:d}=aR(t);await s.moveTo({x:n.x+i/2,y:n.y+d/2}),await s.pause(150);let{node:f,related:p}=await e.change(e=>{let i=$V(e),a=t.parentId?i.get(t.parentId):void 0,o=a?oR(a,i):{x:0,y:0},s={...t,position:{x:n.x-o.x,y:n.y-o.y}};return kR(e,[s]),MR(e,s.id),{node:s,related:u?sV(u,s.id,[...i.values()],r.relationsByKey,s.type):[]}});s.select([f.id]),await s.pause(300);for(let t of p)await eH(e,s,e=>(kR(e,[],[t]),t),t.source,t.target),c.push(t.id);let m=await e.change(e=>new Set($V(e).keys()));for(let t of o.filter(e=>m.has(e.from)&&m.has(e.to))){o.splice(o.indexOf(t),1);let n=await eH(e,s,e=>RR(e,{source:t.from,target:t.to},t.label),t.from,t.to);`error`in n?a.push(n.error):c.push(n.id)}}for(let t of o){let n=await e.change(e=>RR(e,{source:t.from,target:t.to},t.label));`error`in n&&a.push(n.error)}return s.say(`Done`),{created:i.map(({ref:e,node:t,name:n})=>({ref:e,nodeId:t.id,name:n})),connections:c,errors:a}}async function nH(e,t){let n=QV(e,{pace:SHe(t.length)}),r=[],i=[];for(let a of t){let t=await eH(e,n,e=>RR(e,{source:a.from,target:a.to},a.label),a.from,a.to);`error`in t?i.push(t.error):r.push(t.id)}return{connections:r,errors:i}}async function CHe(e,t,n,r=QV(e)){let i=await e.change($V),a=i.get(t);if(!a)return!1;let o=a.parentId?i.get(a.parentId):void 0,s=o?yHe(o,i):{x:0,y:0},c={x:s.x+aR(a).width/2,y:s.y+24};if(r.say(`Moving ${xHe(a)}`),await r.moveTo({x:a.position.x+c.x,y:a.position.y+c.y}),r.select([t]),await r.pause(120),e.sharesMoves)return await r.moveTo({x:n.x+c.x,y:n.y+c.y},{carry:{nodeId:t,grab:c}}),await e.change(e=>wRe(e,t,n)),r.release(),!0;let l=a.position;for(let i=1;i<=12;i++){let a=vHe(i/12),o={x:l.x+(n.x-l.x)*a,y:l.y+(n.y-l.y)*a};await e.change(e=>wRe(e,t,o)),await r.moveTo({x:o.x+c.x,y:o.y+c.y})}return!0}var rH=(e,t)=>e.transact(()=>{t.nodes.forEach(({position:t,size:n},r)=>CRe(e,r,t,n)),DRe(e,t.routes),ER(e,{layoutAt:Date.now()})});async function iH(e,t,n){let r=QV(e,{pace:SHe(t.length)});n.length&&await e.change(e=>zR(e,n));for(let n of t){let t=await e.change($V),i=t.get(n);i&&(r.say(`Removing ${xHe(i)}`),await r.moveTo(cVe(i,t)),r.select([n]),await r.pause(250),await e.change(e=>BR(e,[n])),r.select([]))}}async function wHe(e,{text:t,nodeId:n,x:r,y:i},a){let o=await e.change($V),s=n?o.get(n):void 0;if(n&&!s)return{error:`No node "${n}" on the canvas`};let c=s?{x:aR(s).width-8,y:8}:void 0,l=s&&yHe(s,o),u=s&&c&&l?{position:{x:l.x+c.x,y:l.y+c.y},nodeId:s.id,offset:c}:{position:{x:r??0,y:i??0}},d=QV(e);return d.say(`Commenting`),await d.moveTo(u.position),await d.pause(400),{threadId:await e.change(e=>HR(e,u,t,a))}}async function THe(e,t,n,r){let i=await e.change($V),a=i.get(t),o=QV(e);return a&&(o.say(n),await o.moveTo(cVe(a,i)),o.select([t]),await o.pause(250)),e.change(r)}async function EHe(e,{nodeId:t,name:n,summary:r,version:i,x:a,y:o}){let s={error:`No node "${t}" on the canvas`};if(n!==void 0||r!==void 0||i!==void 0){let a=await THe(e,t,`Editing`,e=>mVe(e,{nodeId:t,name:n,summary:r,version:i}));if(`error`in a)return a}if(a!==void 0||o!==void 0){let n=await e.change($V),r=n.get(t);if(!r)return s;let i=cVe(r,n);await CHe(e,t,lVe(r,{x:a??i.x,y:o??i.y},n))}let c=await e.change($V),l=c.get(t);return l?sVe(l,c):s}var aH=function(e){return e[e.Token=0]=`Token`,e[e.PermissionDenied=1]=`PermissionDenied`,e[e.Authenticated=2]=`Authenticated`,e}({}),DHe=(e,t)=>{YN(e,aH.Token),QN(e,t)},OHe=(e,t,n,r)=>{switch(gP(e)){case aH.Token:t();break;case aH.PermissionDenied:n(vP(e));break;case aH.Authenticated:r(vP(e));break;default:}},kHe=e=>Array.from(e.entries()).map(([e,t])=>({clientId:e,...t})),AHe=`\0`;function jHe(e,t){return e+AHe+t}function MHe(e){let t=e.indexOf(AHe);return t===-1?{documentName:e,sessionId:null}:{documentName:e.substring(0,t),sessionId:e.substring(t+1)}}var NHe=function(e){return e[e.Connecting=0]=`Connecting`,e[e.Open=1]=`Open`,e[e.Closing=2]=`Closing`,e[e.Closed=3]=`Closed`,e}({}),PHe=3e4,oH=class extends PN{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let e=DP();this.getLocalState()!==null&&3e4/2<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let t=[];this.meta.forEach((n,r)=>{r!==this.clientID&&3e4<=e-n.lastUpdated&&this.states.has(r)&&t.push(r)}),t.length>0&&sH(this,t,`timeout`)},FN(PHe/10)),e.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(e){let t=this.clientID,n=this.meta.get(t),r=n===void 0?0:n.clock+1,i=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:r,lastUpdated:DP()});let a=[],o=[],s=[],c=[];e===null?c.push(t):i==null?e!=null&&a.push(t):(o.push(t),IP(i,e)||s.push(t)),(a.length>0||s.length>0||c.length>0)&&this.emit(`change`,[{added:a,updated:s,removed:c},`local`]),this.emit(`update`,[{added:a,updated:o,removed:c},`local`])}setLocalStateField(e,t){let n=this.getLocalState();n!==null&&this.setLocalState({...n,[e]:t})}getStates(){return this.states}},sH=(e,t,n)=>{let r=[];for(let n=0;n<t.length;n++){let i=t[n];if(e.states.has(i)){if(e.states.delete(i),i===e.clientID){let t=e.meta.get(i);e.meta.set(i,{clock:t.clock+1,lastUpdated:DP()})}r.push(i)}}r.length>0&&(e.emit(`change`,[{added:[],updated:[],removed:r},n]),e.emit(`update`,[{added:[],updated:[],removed:r},n]))},cH=(e,t,n=e.states)=>{let r=t.length,i=UN();YN(i,r);for(let a=0;a<r;a++){let r=t[a],o=n.get(r)||null,s=e.meta.get(r).clock;YN(i,r),YN(i,s),QN(i,JSON.stringify(o))}return GN(i)},FHe=(e,t,n)=>{let r=pP(t),i=DP(),a=[],o=[],s=[],c=[],l=gP(r);for(let t=0;t<l;t++){let t=gP(r),n=gP(r),l=JSON.parse(vP(r)),u=e.meta.get(t),d=e.states.get(t),f=u===void 0?0:u.clock;(f<n||f===n&&l===null&&e.states.has(t))&&(l===null?t===e.clientID&&e.getLocalState()!=null?n++:e.states.delete(t):e.states.set(t,l),e.meta.set(t,{clock:n,lastUpdated:i}),u===void 0&&l!==null?a.push(t):u!==void 0&&l===null?c.push(t):l!==null&&(IP(l,d)||s.push(t),o.push(t)))}(a.length>0||s.length>0||c.length>0)&&e.emit(`change`,[{added:a,updated:s,removed:c},n]),(a.length>0||o.length>0||c.length>0)&&e.emit(`update`,[{added:a,updated:o,removed:c},n])};function IHe(e){return e||={},{delay:e.delay===void 0?200:e.delay,initialDelay:e.initialDelay===void 0?0:e.initialDelay,minDelay:e.minDelay===void 0?0:e.minDelay,maxDelay:e.maxDelay===void 0?0:e.maxDelay,factor:e.factor===void 0?0:e.factor,maxAttempts:e.maxAttempts===void 0?3:e.maxAttempts,timeout:e.timeout===void 0?0:e.timeout,jitter:e.jitter===!0,initialJitter:e.initialJitter===!0,handleError:e.handleError===void 0?null:e.handleError,handleTimeout:e.handleTimeout===void 0?null:e.handleTimeout,beforeAttempt:e.beforeAttempt===void 0?null:e.beforeAttempt,calculateDelay:e.calculateDelay===void 0?null:e.calculateDelay}}async function lH(e){return new Promise(t=>setTimeout(t,e))}function LHe(e,t){let n=t.delay;if(n===0)return 0;if(t.factor&&(n*=t.factor**(e.attemptNum-1),t.maxDelay!==0&&(n=Math.min(n,t.maxDelay))),t.jitter){let e=Math.ceil(t.minDelay);n=Math.floor(Math.random()*(Math.floor(n)-e+1))+e}return Math.round(n)}async function RHe(e,t){let n=IHe(t);for(let e of[`delay`,`initialDelay`,`minDelay`,`maxDelay`,`maxAttempts`,`timeout`]){let t=n[e];if(!Number.isInteger(t)||t<0)throw Error(`Value for ${e} must be an integer greater than or equal to 0`)}if(n.factor.constructor!==Number||n.factor<0)throw Error(`Value for factor must be a number greater than or equal to 0`);if(n.delay<n.minDelay)throw Error(`delay cannot be less than minDelay (delay: ${n.delay}, minDelay: ${n.minDelay}`);let r={attemptNum:0,attemptsRemaining:n.maxAttempts?n.maxAttempts:-1,aborted:!1,abort(){r.aborted=!0}},i=n.calculateDelay||LHe;async function a(){if(n.beforeAttempt&&n.beforeAttempt(r,n),r.aborted){let e=Error(`Attempt aborted`);throw e.code=`ATTEMPT_ABORTED`,e}let t=async e=>{if(n.handleError&&await n.handleError(e,r,n),r.aborted||r.attemptsRemaining===0)throw e;r.attemptNum++;let t=i(r,n);return t&&await lH(t),a()};return r.attemptsRemaining>0&&r.attemptsRemaining--,n.timeout?new Promise((i,a)=>{let o=setTimeout(()=>{if(n.handleTimeout)try{i(n.handleTimeout(r,n))}catch(e){a(e)}else{let e=Error(`Retry timeout (attemptNum: ${r.attemptNum}, timeout: ${n.timeout})`);e.code=`ATTEMPT_TIMEOUT`,a(e)}},n.timeout);e(r,n).then(e=>{clearTimeout(o),i(e)}).catch(e=>{clearTimeout(o),t(e).then(i).catch(a)})}):e(r,n).catch(t)}let o=n.calculateDelay?n.calculateDelay(r,n):n.initialDelay;if(o&&await lH(o),r.attemptNum<1&&n.initialJitter){let e=i(r,n);e&&await lH(e)}return a()}var zHe=(e,t)=>{YN(e,0),eP(e,kIe(t))},BHe=(e,t,n)=>{YN(e,1),eP(e,OIe(t,n))},VHe=(e,t,n)=>BHe(t,n,mP(e)),HHe=(e,t,n,r)=>{try{tI(t,mP(e),n)}catch(e){r?.(e),console.error(`Caught error while handling a Yjs update`,e)}},UHe=(e,t)=>{YN(e,2),eP(e,t)},WHe=HHe,GHe=(e,t,n,r,i)=>{let a=gP(e);switch(a){case 0:VHe(e,t,n);break;case 1:HHe(e,n,r,i);break;case 2:WHe(e,n,r,i);break;default:throw Error(`Unknown message type`)}return a},KHe=class{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){let n=this.callbacks[e];return n&&n.forEach(e=>e.apply(this,t)),this}off(e,t){let n=this.callbacks[e];return n&&(t?this.callbacks[e]=n.filter(e=>e!==t):delete this.callbacks[e]),this}removeAllListeners(){this.callbacks={}}},uH=class{constructor(e){this.data=e,this.encoder=UN(),this.decoder=pP(new Uint8Array(this.data))}peekVarString(){return yP(this.decoder)}readVarUint(){return gP(this.decoder)}readVarString(){return vP(this.decoder)}readVarUint8Array(){return mP(this.decoder)}writeVarUint(e){return YN(this.encoder,e)}writeVarString(e){return QN(this.encoder,e)}writeVarUint8Array(e){return eP(this.encoder,e)}length(){return WN(this.encoder)}},dH=function(e){return e[e.Sync=0]=`Sync`,e[e.Awareness=1]=`Awareness`,e[e.Auth=2]=`Auth`,e[e.QueryAwareness=3]=`QueryAwareness`,e[e.Stateless=5]=`Stateless`,e[e.CLOSE=7]=`CLOSE`,e[e.SyncStatus=8]=`SyncStatus`,e[e.Ping=9]=`Ping`,e[e.Pong=10]=`Pong`,e}({}),fH=function(e){return e.Connecting=`connecting`,e.Connected=`connected`,e.Disconnected=`disconnected`,e}({}),pH=class{constructor(){this.encoder=UN()}get(e){return e.encoder}toUint8Array(){return GN(this.encoder)}},qHe=class extends pH{constructor(...e){super(...e),this.type=dH.CLOSE,this.description=`Ask the server to close the connection`}get(e){return QN(this.encoder,e.documentName),YN(this.encoder,this.type),this.encoder}},JHe=class e extends KHe{static{this.DEDUPLICATABLE_TYPES=new Set([dH.Awareness,dH.QueryAwareness])}constructor(e){super(),this.messageQueue=[],this.configuration={url:``,autoConnect:!0,preserveTrailingSlash:!1,document:void 0,WebSocketPolyfill:void 0,messageReconnectTimeout:3e4,delay:1e3,initialDelay:0,factor:2,maxAttempts:0,minDelay:1e3,maxDelay:3e4,jitter:!0,timeout:0,onOpen:()=>null,onConnect:()=>null,onMessage:()=>null,onOutgoingMessage:()=>null,onStatus:()=>null,onDisconnect:()=>null,onClose:()=>null,onMaxAttemptsFailed:()=>null,onDestroy:()=>null,onAwarenessUpdate:()=>null,onAwarenessChange:()=>null,handleTimeout:null,providerMap:new Map},this.webSocket=null,this.webSocketHandlers={},this.shouldConnect=!0,this.status=fH.Disconnected,this.lastMessageReceived=0,this.identifier=0,this.intervals={connectionChecker:null},this.connectionAttempt=null,this.receivedOnOpenPayload=void 0,this.closeTries=0,this.setConfiguration(e),this.configuration.WebSocketPolyfill=e.WebSocketPolyfill?e.WebSocketPolyfill:WebSocket,this.on(`open`,this.configuration.onOpen),this.on(`open`,this.onOpen.bind(this)),this.on(`connect`,this.configuration.onConnect),this.on(`message`,this.configuration.onMessage),this.on(`outgoingMessage`,this.configuration.onOutgoingMessage),this.on(`status`,this.configuration.onStatus),this.on(`disconnect`,this.configuration.onDisconnect),this.on(`close`,this.configuration.onClose),this.on(`maxAttemptsFailed`,this.configuration.onMaxAttemptsFailed),this.on(`destroy`,this.configuration.onDestroy),this.on(`awarenessUpdate`,this.configuration.onAwarenessUpdate),this.on(`awarenessChange`,this.configuration.onAwarenessChange),this.on(`close`,this.onClose.bind(this)),this.on(`message`,this.onMessage.bind(this)),this.intervals.connectionChecker=setInterval(this.checkConnection.bind(this),this.configuration.messageReconnectTimeout/10),this.shouldConnect&&this.connect()}async onOpen(e){this.status=fH.Connected,this.emit(`status`,{status:fH.Connected}),this.cancelWebsocketRetry=void 0,this.receivedOnOpenPayload=e}attach(e){let t=e.effectiveName,n=this.configuration.providerMap.get(t);if(n&&n!==e&&n.isAuthenticated)throw Error(`Cannot attach two providers with the same effective name "${t}". Use sessionAwareness: true to multiplex providers with the same document name.`);this.configuration.providerMap.set(t,e),this.status===fH.Disconnected&&this.shouldConnect&&this.connect(),this.receivedOnOpenPayload&&this.status===fH.Connected&&e.onOpen(this.receivedOnOpenPayload)}detach(e){let t=e.effectiveName;this.configuration.providerMap.has(t)&&(e.send(qHe,{documentName:t}),this.configuration.providerMap.delete(t))}setConfiguration(e={}){this.configuration={...this.configuration,...e},this.configuration.autoConnect||(this.shouldConnect=!1)}async connect(){if(this.status===fH.Connected)return;this.cancelWebsocketRetry&&=(this.cancelWebsocketRetry(),void 0),this.receivedOnOpenPayload=void 0,this.shouldConnect=!0;let{retryPromise:e,cancelFunc:t}=(()=>{let e=!1;return{retryPromise:RHe(this.createWebSocketConnection.bind(this),{delay:this.configuration.delay,initialDelay:this.configuration.initialDelay,factor:this.configuration.factor,maxAttempts:this.configuration.maxAttempts,minDelay:this.configuration.minDelay,maxDelay:this.configuration.maxDelay,jitter:this.configuration.jitter,timeout:this.configuration.timeout,handleTimeout:this.configuration.handleTimeout,beforeAttempt:t=>{(!this.shouldConnect||e)&&t.abort()}}).catch(e=>{e?.code!==`ATTEMPT_ABORTED`&&this.emit(`maxAttemptsFailed`,{error:e})}),cancelFunc:()=>{e=!0}}})();return this.cancelWebsocketRetry=t,e}attachWebSocketListeners(e,t){let{identifier:n}=e,r=e=>this.emit(`message`,e),i=e=>this.emit(`close`,{event:e}),a=e=>this.emit(`open`,e),o=e=>{t(e)};this.webSocketHandlers[n]={message:r,close:i,open:a,error:o};let s=this.webSocketHandlers[e.identifier];Object.keys(s).forEach(t=>{e.addEventListener(t,s[t])})}cleanupWebSocket(){if(!this.webSocket)return;let{identifier:e}=this.webSocket,t=this.webSocketHandlers[e];Object.keys(t).forEach(n=>{this.webSocket?.removeEventListener(n,t[n]),delete this.webSocketHandlers[e]}),this.webSocket.close(),this.webSocket=null}createWebSocketConnection(){return new Promise((e,t)=>{this.webSocket&&(this.messageQueue=[],this.cleanupWebSocket()),this.lastMessageReceived=0,this.identifier+=1;let n=new this.configuration.WebSocketPolyfill(this.url);n.binaryType=`arraybuffer`,n.identifier=this.identifier,this.attachWebSocketListeners(n,t),this.webSocket=n,this.status=fH.Connecting,this.emit(`status`,{status:fH.Connecting}),this.connectionAttempt={resolve:e,reject:t}})}onMessage(e){this.resolveConnectionAttempt(),this.lastMessageReceived=DP();let t=new Uint8Array(e.data);if(t.length===1&&t[0]===dH.Ping){this.sendPong();return}let n=new uH(t).peekVarString();this.configuration.providerMap.get(n)?.onMessage(e)}sendPong(){let e=UN();YN(e,dH.Pong),this.send(GN(e))}resolveConnectionAttempt(){this.connectionAttempt&&(this.connectionAttempt.resolve(),this.connectionAttempt=null,this.status=fH.Connected,this.emit(`status`,{status:fH.Connected}),this.emit(`connect`),this.messageQueue.forEach(e=>this.send(e)),this.messageQueue=[])}stopConnectionAttempt(){this.connectionAttempt=null}rejectConnectionAttempt(e){this.connectionAttempt?.reject(e),this.connectionAttempt=null}checkConnection(){this.status===fH.Connected&&this.lastMessageReceived&&(this.configuration.messageReconnectTimeout>=DP()-this.lastMessageReceived||(this.closeTries+=1,this.closeTries>2?(this.onClose({event:{code:4408,reason:`forced`}}),this.closeTries=0):(this.webSocket?.close(),this.messageQueue=[])))}get serverUrl(){if(this.configuration.preserveTrailingSlash)return this.configuration.url;let e=this.configuration.url;for(;e[e.length-1]===`/`;)e=e.slice(0,e.length-1);return e}get url(){return this.serverUrl}disconnect(){if(this.shouldConnect=!1,this.webSocket!==null)try{this.webSocket.close(),this.messageQueue=[]}catch(e){console.error(e)}}parseQueuedMessage(e){try{let t=pP(e);return{documentName:vP(t),messageType:gP(t)}}catch{return null}}addToQueue(t){if(t instanceof Uint8Array){let n=this.parseQueuedMessage(t);n&&e.DEDUPLICATABLE_TYPES.has(n.messageType)&&(this.messageQueue=this.messageQueue.filter(e=>{if(!(e instanceof Uint8Array))return!0;let t=this.parseQueuedMessage(e);return t?!(t.documentName===n.documentName&&t.messageType===n.messageType):!0}))}this.messageQueue.push(t)}send(e){this.webSocket?.readyState===NHe.Open?this.webSocket.send(e):this.addToQueue(e)}onClose({event:e}){this.closeTries=0,this.cleanupWebSocket(),this.connectionAttempt&&this.rejectConnectionAttempt(Error(`WebSocket closed before the connection was established (code: ${e?.code}, reason: ${e?.reason||`none`})`)),this.status=fH.Disconnected,this.emit(`status`,{status:fH.Disconnected}),this.emit(`disconnect`,{event:e}),!this.cancelWebsocketRetry&&this.shouldConnect&&setTimeout(()=>{this.connect()},this.configuration.delay)}destroy(){this.emit(`destroy`),clearInterval(this.intervals.connectionChecker),this.stopConnectionAttempt(),this.disconnect(),this.removeAllListeners(),this.cleanupWebSocket()}},YHe=class{constructor(e){this.message=e}apply(e,t){let{message:n}=this,r=n.readVarUint(),i=n.length();switch(r){case dH.Sync:this.applySyncMessage(e,t);break;case dH.Awareness:this.applyAwarenessMessage(e);break;case dH.Auth:this.applyAuthMessage(e);break;case dH.QueryAwareness:this.applyQueryAwarenessMessage(e);break;case dH.Stateless:e.receiveStateless(vP(n.decoder));break;case dH.SyncStatus:this.applySyncStatusMessage(e,_P(n.decoder)===1);break;case dH.CLOSE:{let t={code:1e3,reason:vP(n.decoder)};e.onClose(),e.configuration.onClose({event:t}),e.forwardClose({event:t});break}default:console.error(`Can’t apply message of unknown type: ${r}`)}n.length()>i+1&&e.send(pH,{encoder:n.encoder})}applySyncMessage(e,t){let{message:n}=this;n.writeVarUint(dH.Sync);let r=GHe(n.decoder,n.encoder,e.document,e);t&&r===1&&(e.synced=!0)}applySyncStatusMessage(e,t){t&&e.decrementUnsyncedChanges()}applyAwarenessMessage(e){if(!e.awareness)return;let{message:t}=this;FHe(e.awareness,t.readVarUint8Array(),e)}applyAuthMessage(e){let{message:t}=this;OHe(t.decoder,e.sendToken.bind(e),e.permissionDeniedHandler.bind(e),e.authenticatedHandler.bind(e))}applyQueryAwarenessMessage(e){if(!e.awareness)return;let{message:t}=this;t.writeVarUint(dH.Awareness),t.writeVarUint8Array(cH(e.awareness,Array.from(e.awareness.getStates().keys())))}},XHe=class{constructor(e,t={}){this.message=new e,this.encoder=this.message.get(t)}create(){return GN(this.encoder)}send(e){e?.send(this.create())}},ZHe=`4.7.0`,QHe=class extends pH{constructor(...e){super(...e),this.type=dH.Auth,this.description=`Authentication`}get(e){if(e.token===void 0)throw Error("The authentication message requires `token` as an argument.");return QN(this.encoder,e.documentName),YN(this.encoder,this.type),DHe(this.encoder,e.token),QN(this.encoder,ZHe),this.encoder}},mH=class extends pH{constructor(...e){super(...e),this.type=dH.Awareness,this.description=`Awareness states update`}get(e){if(e.awareness===void 0)throw Error(`The awareness message requires awareness as an argument`);if(e.clients===void 0)throw Error(`The awareness message requires clients as an argument`);QN(this.encoder,e.documentName),YN(this.encoder,this.type);let t;return t=e.states===void 0?cH(e.awareness,e.clients):cH(e.awareness,e.clients,e.states),eP(this.encoder,t),this.encoder}},$He=class extends pH{constructor(...e){super(...e),this.type=dH.Stateless,this.description=`A stateless message`}get(e){return QN(this.encoder,e.documentName),YN(this.encoder,this.type),QN(this.encoder,e.payload??``),this.encoder}},hH=class extends pH{constructor(...e){super(...e),this.type=dH.Sync,this.description=`First sync step`}get(e){if(e.document===void 0)throw Error(`The sync step one message requires document as an argument`);return QN(this.encoder,e.documentName),YN(this.encoder,this.type),zHe(this.encoder,e.document),this.encoder}},eUe=class extends pH{constructor(...e){super(...e),this.type=dH.Sync,this.description=`A document update`}get(e){return QN(this.encoder,e.documentName),YN(this.encoder,this.type),UHe(this.encoder,e.update),this.encoder}},tUe=class extends Error{constructor(...e){super(...e),this.code=1001}},nUe=class extends KHe{get effectiveName(){return this.configuration.sessionAwareness?jHe(this.configuration.name,this.sessionId):this.configuration.name}constructor(e){super(),this.configuration={name:``,document:void 0,awareness:void 0,token:null,sessionAwareness:!1,forceSyncInterval:!1,flushDelay:!1,onAuthenticated:()=>null,onAuthenticationFailed:()=>null,onOpen:()=>null,onConnect:()=>null,onMessage:()=>null,onOutgoingMessage:()=>null,onSynced:()=>null,onStatus:()=>null,onDisconnect:()=>null,onClose:()=>null,onDestroy:()=>null,onAwarenessUpdate:()=>null,onAwarenessChange:()=>null,onStateless:()=>null,onUnsyncedChanges:()=>null},this.isSynced=!1,this.unsyncedChanges=0,this.isAuthenticated=!1,this.authorizedScope=void 0,this.manageSocket=!1,this._isAttached=!1,this.pendingUpdates=[],this.pendingAwarenessClients=new Set,this.flushTimeout=null,this.sessionId=Math.random().toString(36).slice(2),this.intervals={forceSync:null},this.boundDocumentUpdateHandler=this.documentUpdateHandler.bind(this),this.boundAwarenessUpdateHandler=this.awarenessUpdateHandler.bind(this),this.boundPageHide=this.pageHide.bind(this),this.boundOnOpen=this.onOpen.bind(this),this.boundOnClose=this.onClose.bind(this),this.forwardConnect=()=>this.emit(`connect`),this.forwardStatus=e=>this.emit(`status`,e),this.forwardClose=e=>this.emit(`close`,e),this.forwardDisconnect=e=>this.emit(`disconnect`,e),this.forwardDestroy=()=>this.emit(`destroy`),this.setConfiguration(e),this.configuration.document=e.document?e.document:new GF,this.configuration.awareness=e.awareness===void 0?new oH(this.document):e.awareness,this.on(`open`,this.configuration.onOpen),this.on(`message`,this.configuration.onMessage),this.on(`outgoingMessage`,this.configuration.onOutgoingMessage),this.on(`synced`,this.configuration.onSynced),this.on(`destroy`,this.configuration.onDestroy),this.on(`awarenessUpdate`,this.configuration.onAwarenessUpdate),this.on(`awarenessChange`,this.configuration.onAwarenessChange),this.on(`stateless`,this.configuration.onStateless),this.on(`unsyncedChanges`,this.configuration.onUnsyncedChanges),this.on(`authenticated`,this.configuration.onAuthenticated),this.on(`authenticationFailed`,this.configuration.onAuthenticationFailed),this.awareness?.on(`update`,()=>{this.emit(`awarenessUpdate`,{states:kHe(this.awareness.getStates())})}),this.awareness?.on(`change`,()=>{this.emit(`awarenessChange`,{states:kHe(this.awareness.getStates())})}),this.document.on(`update`,this.boundDocumentUpdateHandler),this.awareness?.on(`update`,this.boundAwarenessUpdateHandler),this.registerEventListeners(),this.configuration.forceSyncInterval&&typeof this.configuration.forceSyncInterval==`number`&&(this.intervals.forceSync=setInterval(this.forceSync.bind(this),this.configuration.forceSyncInterval)),this.manageSocket&&this.attach()}setConfiguration(e={}){e.websocketProvider||(this.manageSocket=!0,this.configuration.websocketProvider=new JHe(e)),this.configuration={...this.configuration,...e}}get document(){return this.configuration.document}get isAttached(){return this._isAttached}get awareness(){return this.configuration.awareness}get hasUnsyncedChanges(){return this.unsyncedChanges>0}resetUnsyncedChanges(){this.unsyncedChanges=1,this.emit(`unsyncedChanges`,{number:this.unsyncedChanges})}incrementUnsyncedChanges(){this.unsyncedChanges+=1,this.emit(`unsyncedChanges`,{number:this.unsyncedChanges})}decrementUnsyncedChanges(){this.unsyncedChanges>0&&--this.unsyncedChanges,this.unsyncedChanges===0&&(this.synced=!0),this.emit(`unsyncedChanges`,{number:this.unsyncedChanges})}forceSync(){this.resetUnsyncedChanges(),this.send(hH,{document:this.document,documentName:this.effectiveName})}pageHide(){this.awareness&&sH(this.awareness,[this.document.clientID],`page hide`)}registerEventListeners(){typeof window>`u`||!(`addEventListener`in window)||window.addEventListener(`pagehide`,this.boundPageHide)}sendStateless(e){this.send($He,{documentName:this.effectiveName,payload:e})}async sendToken(){let e;try{e=await this.getToken()}catch(e){this.permissionDeniedHandler(`Failed to get token during sendToken(): ${e}`);return}this.send(QHe,{token:e??``,documentName:this.effectiveName})}get batchingEnabled(){return!!this.configuration.flushDelay&&typeof this.configuration.flushDelay==`number`}documentUpdateHandler(e,t){if(t!==this){if(!this.batchingEnabled){this.incrementUnsyncedChanges(),this.send(eUe,{update:e,documentName:this.effectiveName});return}this.pendingUpdates.length===0&&this.incrementUnsyncedChanges(),this.pendingUpdates.push(e),this.scheduleFlush()}}awarenessUpdateHandler({added:e,updated:t,removed:n},r){if(r===this)return;let i=e.concat(t).concat(n);if(!this.batchingEnabled){this.send(mH,{awareness:this.awareness,clients:i,documentName:this.effectiveName});return}for(let e of i)this.pendingAwarenessClients.add(e);this.scheduleFlush()}scheduleFlush(){this.flushTimeout===null&&(this.flushTimeout=setTimeout(()=>{this.flushTimeout=null,this.flushPendingUpdates()},this.configuration.flushDelay))}flushPendingUpdates(){if(this.flushTimeout!==null&&(clearTimeout(this.flushTimeout),this.flushTimeout=null),this.pendingUpdates.length>0){let e=this.pendingUpdates.length===1?this.pendingUpdates[0]:KIe(this.pendingUpdates);this.pendingUpdates=[],this.send(eUe,{update:e,documentName:this.effectiveName})}if(this.pendingAwarenessClients.size>0){let e=Array.from(this.pendingAwarenessClients);this.pendingAwarenessClients.clear(),this.send(mH,{awareness:this.awareness,clients:e,documentName:this.effectiveName})}}get synced(){return this.isSynced}set synced(e){this.isSynced!==e&&(this.isSynced=e,e&&this.emit(`synced`,{state:e}))}receiveStateless(e){this.emit(`stateless`,{payload:e})}async connect(){if(this.manageSocket)return this.configuration.websocketProvider.connect();console.warn(`HocuspocusProvider::connect() is deprecated and does not do anything. Please connect/disconnect on the websocketProvider, or attach/deattach providers.`)}disconnect(){if(this.manageSocket)return this.configuration.websocketProvider.disconnect();console.warn(`HocuspocusProvider::disconnect() is deprecated and does not do anything. Please connect/disconnect on the websocketProvider, or attach/deattach providers.`)}async onOpen(e){this.isAuthenticated=!1,this.emit(`open`,{event:e}),await this.sendToken(),this.startSync()}async getToken(){return typeof this.configuration.token==`function`?await this.configuration.token():this.configuration.token}startSync(){this.resetUnsyncedChanges(),this.send(hH,{document:this.document,documentName:this.effectiveName}),this.awareness&&this.awareness.getLocalState()!==null&&this.send(mH,{awareness:this.awareness,clients:[this.document.clientID],documentName:this.effectiveName})}send(e,t){if(!this._isAttached)return;let n=new XHe(e,t);this.emit(`outgoingMessage`,{message:n.message}),n.send(this.configuration.websocketProvider)}onMessage(e){let t=new uH(e.data),{documentName:n}=MHe(t.readVarString());t.writeVarString(this.effectiveName),this.emit(`message`,{event:e,message:new uH(e.data)}),new YHe(t).apply(this,!0)}onClose(){this.isAuthenticated=!1,this.synced=!1,this.flushTimeout!==null&&(clearTimeout(this.flushTimeout),this.flushTimeout=null),this.pendingUpdates=[],this.pendingAwarenessClients.clear(),this.awareness&&sH(this.awareness,Array.from(this.awareness.getStates().keys()).filter(e=>e!==this.document.clientID),this)}destroy(){this.emit(`destroy`),this.intervals.forceSync&&clearInterval(this.intervals.forceSync),this.awareness&&(sH(this.awareness,[this.document.clientID],`provider destroy`),this.awareness.off(`update`,this.boundAwarenessUpdateHandler),this.awareness.destroy()),this.flushPendingUpdates(),this.document.off(`update`,this.boundDocumentUpdateHandler),this.removeAllListeners(),this.detach(),this.manageSocket&&this.configuration.websocketProvider.destroy(),!(typeof window>`u`||!(`removeEventListener`in window))&&window.removeEventListener(`pagehide`,this.boundPageHide)}detach(){this.configuration.websocketProvider.off(`connect`,this.configuration.onConnect),this.configuration.websocketProvider.off(`connect`,this.forwardConnect),this.configuration.websocketProvider.off(`status`,this.forwardStatus),this.configuration.websocketProvider.off(`status`,this.configuration.onStatus),this.configuration.websocketProvider.off(`open`,this.boundOnOpen),this.configuration.websocketProvider.off(`close`,this.boundOnClose),this.configuration.websocketProvider.off(`close`,this.configuration.onClose),this.configuration.websocketProvider.off(`close`,this.forwardClose),this.configuration.websocketProvider.off(`disconnect`,this.configuration.onDisconnect),this.configuration.websocketProvider.off(`disconnect`,this.forwardDisconnect),this.configuration.websocketProvider.off(`destroy`,this.configuration.onDestroy),this.configuration.websocketProvider.off(`destroy`,this.forwardDestroy),this.configuration.websocketProvider.detach(this),this._isAttached=!1}attach(){this._isAttached||=(this.configuration.websocketProvider.on(`connect`,this.configuration.onConnect),this.configuration.websocketProvider.on(`connect`,this.forwardConnect),this.configuration.websocketProvider.on(`status`,this.configuration.onStatus),this.configuration.websocketProvider.on(`status`,this.forwardStatus),this.configuration.websocketProvider.on(`open`,this.boundOnOpen),this.configuration.websocketProvider.on(`close`,this.boundOnClose),this.configuration.websocketProvider.on(`close`,this.configuration.onClose),this.configuration.websocketProvider.on(`close`,this.forwardClose),this.configuration.websocketProvider.on(`disconnect`,this.configuration.onDisconnect),this.configuration.websocketProvider.on(`disconnect`,this.forwardDisconnect),this.configuration.websocketProvider.on(`destroy`,this.configuration.onDestroy),this.configuration.websocketProvider.on(`destroy`,this.forwardDestroy),this.configuration.websocketProvider.attach(this),!0)}permissionDeniedHandler(e){this.emit(`authenticationFailed`,{reason:e}),this.isAuthenticated=!1}authenticatedHandler(e){this.isAuthenticated=!0,this.authorizedScope=e,this.emit(`authenticated`,{scope:e})}setAwarenessField(e,t){if(!this.awareness)throw new tUe(`Cannot set awareness field "${e}" to ${JSON.stringify(t)}. You have disabled Awareness for this provider by explicitly passing awareness: null in the provider configuration.`);this.awareness.setLocalStateField(e,t)}},gH=`design:`,rUe=e=>`${gH}${e}`,iUe=e=>{let t=``;for(let n=0;n<e.length;n+=32768)t+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(t)},_H=e=>Uint8Array.from(atob(e),e=>e.charCodeAt(0)),aUe=Symbol(`tool-sync`);function oUe(e,t,{canvasId:n,sync:r,onStatus:i,intervalMs:a=1e3}){let o,s=!1,c,l=async()=>{try{let a=await r({canvasId:n,clientId:e.clientID,stateVector:iUe(kIe(e)),update:iUe(OIe(e,o)),awareness:iUe(cH(t,[e.clientID]))});if(s)return;tI(e,_H(a.update),aUe),o=_H(a.stateVector),a.awareness&&FHe(t,_H(a.awareness),aUe),i(`connected`)}catch{s||i(`disconnected`)}s||(c=setTimeout(l,a))};return l(),()=>{s=!0,clearTimeout(c)}}var sUe=1e3;function cUe(e,t=33,n=sUe){let r,i,a=-1/0,o=()=>e.getStates().size<=1,s=()=>{if(clearTimeout(i),i=void 0,!r)return;let t=r;r=void 0,a=performance.now(),e.setLocalState({...e.getLocalState(),...t})},c=({added:t})=>{r&&t.some(t=>t!==e.clientID)&&s()};return e.on(`change`,c),{send:e=>{if(r={...r,...e},i)return;let c=o()?n:t;i=setTimeout(s,Math.max(0,c-(performance.now()-a)))},flush:s,destroy:()=>{clearTimeout(i),r=void 0,e.off(`change`,c)}}}var vH=[],lUe=e=>{let t=[];return e.getStates().forEach((e,n)=>{e.user&&t.push({clientId:n,...e.user,activity:e.activity,pointer:e.pointer??null,selection:e.selection??[],viewport:e.viewport,connecting:e.connecting})}),t},uUe=e=>[e.clientId,e.name,e.color,e.picture??``,+!!e.agent,e.activity??``,+!!e.pointer].join(`|`);function dUe(e){let t=new Set,n=lUe(e),r=null,i=n,a=n,o=JSON.stringify(e.getLocalState()?.user??null),s=()=>{i=r?[...n,r]:n;let e=i.length?i:vH;e.map(uUe).join()!==a.map(uUe).join()&&(a=e),t.forEach(e=>e())},c=({added:t,updated:r,removed:i})=>{let a=[...t,...r,...i].some(t=>t!==e.clientID),c=JSON.stringify(e.getLocalState()?.user??null);!a&&c===o||(o=c,n=lUe(e),s())};return e.on(`change`,c),{subscribe:e=>(t.add(e),()=>t.delete(e)),getPeers:()=>i,getPeople:()=>a,setLocalAgent:e=>{r=e,s()},destroy:()=>{e.off(`change`,c),t.clear()}}}var fUe={subscribe:()=>()=>{},getPeers:()=>vH,getPeople:()=>vH},yH=e=>{let t=e??fUe;return(0,h.useSyncExternalStore)(t.subscribe,t.getPeople)},pUe=4e3,bH=500,xH=Symbol(`studio-local`),mUe=Symbol(`studio-browser-agent`),SH=Symbol(`studio-status`),hUe=Symbol(`studio-open`),gUe=Symbol(`studio-level-placement`),_Ue={1:new Map,2:new Map},vUe=[`text`,`fontSize`,`angle`],yUe={status:`draft`,history:[]};function bUe({canvasId:e,socketUrl:t,name:n,color:r,picture:i,agent:a,syncViaTools:o,onLayout:s,onContainerResize:c}){let l=(0,h.useRef)(null),[u,d]=(0,h.useState)([]),[f,p]=(0,h.useState)([]),[m,g]=(0,h.useState)(`connecting`),[_,v]=(0,h.useState)(null),[y,b]=(0,h.useState)(null),[x,S]=(0,h.useState)(null),[C,w]=(0,h.useState)({canUndo:!1,canRedo:!1}),[T,E]=(0,h.useState)(),[ee,te]=(0,h.useState)(),[ne,re]=(0,h.useState)(``),[ie,ae]=(0,h.useState)(_Ue),[oe,se]=(0,h.useState)(yUe),[ce,le]=(0,h.useState)(`websocket`),[ue,de]=(0,h.useState)(!1),[fe,pe]=(0,h.useState)([]),[me,he]=(0,h.useState)(null),[ge,_e]=(0,h.useState)(!1),ve=(0,h.useRef)({name:n,color:r});ve.current={name:n,color:r,...i&&{picture:i},...a&&{agent:a}};let ye=(0,h.useRef)(s);ye.current=s;let be=(0,h.useRef)(c);be.current=c,(0,h.useEffect)(()=>{d([]),p([]);let n=new GF,{nodes:r,edges:i,threads:a,meta:s,levelLayouts:c,hotspots:u}=SR(n),f=e=>{let t=new Set([...e.keysChanged].map(e=>Number(e.split(`:`)[0])));ae(e=>{let r={...e};return t.forEach(e=>r[e]=gRe(n,e)),r})};c.observe(f),ae(_Ue);let m=e=>{let t=TR(n);E(t.title),e.keysChanged.has(`diagramLevels`)&&te(t.diagramLevels),(e.keysChanged.has(`status`)||e.keysChanged.has(`statusHistory`))&&se({status:DR(t),history:t.statusHistory??[]}),e.keysChanged.has(`layoutAt`)&&ye.current?.(),e.keysChanged.has(`lockedBy`)&&he(mRe(n))};s.observe(m),he(null);let h=()=>pe(KR(n));u.observe(h),pe([]),E(void 0),re(``),te(void 0),se(yUe);let _=e=>{if(!e.local||e.origin===SH||!SRe(e))return;let t=e.origin===mUe?{name:`${ve.current.name}'s agent`,color:ve.current.color,agent:!0}:ve.current;queueMicrotask(()=>n.transact(()=>{xRe(n,t),TR(n).createdAt||ER(n,{createdAt:Date.now(),createdBy:t.name})},SH))};n.on(`afterTransaction`,_);let y=e=>{e.origin!==xH&&SRe(e)&&re(ORe(Array.from(r.values()),Array.from(i.values())))};n.on(`afterTransaction`,y);let x=new oH(n);x.setLocalStateField(`user`,ve.current);let C=dUe(x);v(C);let T=cUe(x),ee=!1,ne=!1,ie,oe,ce=`connecting`,ue=!1,fe=()=>{ue=!0,clearTimeout(oe),ie?.(),ge.disconnect(),de(!0),g(`disconnected`)},me=()=>{!o||ie||(clearTimeout(oe),le(`tools`),ie=oUe(n,x,{canvasId:e,sync:o,onStatus:g}),ge.disconnect())},ge=new nUe({url:t,name:rUe(e),document:n,awareness:x,onStatus:({status:e})=>{ce=e,e!==`connected`&&(ne=!1),ie||g(e===`connected`&&!ne?`connecting`:e)},onSynced:({state:e})=>_e(e),onAuthenticated:()=>{ee=ne=!0,ie||g(`connected`)},onClose:({event:e})=>{e.reason===`canvas-deleted`&&fe()},onAuthenticationFailed:({reason:e})=>{if(e===`canvas-deleted`)return fe();if(o)return me();ge.disconnect(),g(`disconnected`)}});le(`websocket`),de(!1),_e(!1);let xe=()=>{!ie&&!ue&&ce===`disconnected`&&ge.connect()},Se=()=>{if(document.visibilityState===`visible`)return xe();T.send({pointer:null}),T.flush()};window.addEventListener(`online`,xe),document.addEventListener(`visibilitychange`,Se),o&&(oe=setTimeout(()=>!ee&&me(),pUe));let Ce=new UIe([r,i,a,c,u],{captureTimeout:500,trackedOrigins:new Set([null,xH])}),we=()=>w({canUndo:Ce.undoStack.length>0,canRedo:Ce.redoStack.length>0});Ce.on(`stack-item-added`,we),Ce.on(`stack-item-popped`,we),Ce.on(`stack-cleared`,we),w({canUndo:!1,canRedo:!1}),l.current={doc:n,awareness:x,undoManager:Ce,sender:T},b(n.clientID),S(n);let Te=new Map,D=new Set,Ee=Dz(e=>{let t=new Map([...e].filter(([e])=>Te.has(e)));t.size&&d(e=>tz(e,t))}),De=(e,t)=>{if(t===`local`)return;let i=new Map;x.getStates().forEach((e,t)=>{t===n.clientID||!e.moving||Object.entries(e.moving).forEach(([e,t])=>i.set(e,t))});let a=[...i].some(([e,{x:t,y:n}])=>Te.get(e)?.x!==t||Te.get(e)?.y!==n),o=[...Te.keys()].filter(e=>!i.has(e));if(Te=i,(a||o.length)&&Ee.set(i),o.length===0)return;let s=setTimeout(()=>{D.delete(s);let e=o.flatMap(e=>{let t=Te.has(e)?void 0:r.get(e);return t?[[e,t.position]]:[]});d(t=>tz(t,new Map(e)))},bH);D.add(s)};x.on(`change`,De);let Oe=``,ke=new Set,Ae=(e,t)=>{if(t===`local`)return;let i=new Map;x.getStates().forEach((e,t)=>{let r=e.editing;if(t===n.clientID||!r?.id)return;let{id:a,...o}=r;i.set(a,o)});let a=JSON.stringify([...i]);if(a===Oe)return;Oe=a;let o=ke;ke=new Set(i.keys()),d(e=>{let t;return e.forEach((n,a)=>{let s=i.get(n.id),c=o.has(n.id)?r.get(n.id)?.data:void 0,l=s??(c&&Object.fromEntries(vUe.map(e=>[e,c[e]])));!l||Object.entries(l).every(([e,t])=>n.data[e]===t)||(t??=[...e],t[a]={...n,data:{...n.data,...l}})}),t??e})};x.on(`change`,Ae);let je=e=>{e.transaction.origin!==xH&&(e.keysChanged.forEach(e=>Te.delete(e)),[...e.changes.keys].some(([e,t])=>{let n=r.get(e),i=t.oldValue;return t.action===`update`&&RL(n?.type)&&(n?.width!==i?.width||n?.height!==i?.height)})&&be.current?.(),d(t=>qRe(GRe(t,e.keysChanged,e=>r.get(e),URe),t)))},Me=e=>{e.transaction.origin!==xH&&p(t=>GRe(t,e.keysChanged,e=>i.get(e),WRe))};return r.observe(je),i.observe(Me),()=>{clearTimeout(oe),D.forEach(clearTimeout),window.removeEventListener(`online`,xe),document.removeEventListener(`visibilitychange`,Se),x.off(`change`,De),x.off(`change`,Ae),Ee.stop(),T.destroy(),ie?.(),r.unobserve(je),c.unobserve(f),i.unobserve(Me),s.unobserve(m),u.unobserve(h),n.off(`afterTransaction`,_),n.off(`afterTransaction`,y),C.destroy(),Ce.destroy(),ge.destroy(),n.destroy(),l.current=null,S(null),v(null)}},[e,t,o]),(0,h.useEffect)(()=>{l.current?.awareness.setLocalStateField(`user`,ve.current)},[n,r,i]);let xe=(0,h.useMemo)(()=>u.filter(e=>e.selected).map(e=>e.id).join(`,`),[u]);(0,h.useEffect)(()=>{l.current?.sender.send({selection:xe?xe.split(`,`):[]})},[xe]);let Se=(0,h.useRef)(u);Se.current=u;let Ce=()=>new Map(Se.current.flatMap(e=>e.measured?.width&&e.measured.height?[[e.id,{width:e.measured.width,height:e.measured.height}]]:[])),we=(e,t=null)=>{let n=l.current?.doc;return n?n.transact(()=>e(n),t):void 0},Te=(0,h.useRef)(new Map),D=(0,h.useRef)(new Map),Ee=e=>{Te.current.forEach((t,n)=>wRe(e,n,t)),D.current.forEach(({position:t,width:n,height:r},i)=>CRe(e,i,t,n!==void 0&&r!==void 0?{width:n,height:r}:void 0)),D.current=new Map,Te.current.clear();let t=l.current;t?.sender.send({moving:null}),queueMicrotask(()=>t?.sender.flush())},De=(0,h.useCallback)(e=>{d(t=>fl(e,t));let t=!1,n=[],r=[];for(let i of e)i.type===`position`&&i.position&&(Te.current.set(i.id,i.position),i.dragging||(t=!0)),i.type===`dimensions`&&i.setAttributes&&i.dimensions&&n.push({id:i.id,dimensions:i.dimensions,attributes:i.setAttributes}),i.type===`dimensions`&&i.resizing===!1&&r.push(i.id);t?(l.current?.undoManager.stopCapturing(),we(Ee,xH)):Te.current.size&&l.current?.sender.send({moving:Object.fromEntries(Te.current)}),n.length&&we(e=>n.forEach(({id:t,dimensions:n,attributes:r})=>TRe(e,t,n,r)),xH),r.length&&we(e=>r.forEach(t=>MR(e,t,Ce())));let i=e.filter(e=>e.type===`remove`).map(e=>e.id);i.length&&we(e=>BR(e,i))},[]),Oe=(0,h.useCallback)(e=>{p(t=>pl(e,t));let t=e.filter(e=>e.type===`remove`).map(e=>e.id);t.length&&we(e=>zR(e,t))},[]),ke=(0,h.useCallback)(e=>{we(t=>RR(t,e))},[]),Ae=(0,h.useCallback)((e,t)=>{we(n=>kRe(n,e.id,t))},[]),je=(0,h.useCallback)(e=>{D.current=e,d(t=>{let n;return t.forEach((r,i)=>{let a=e.get(r.id);!a||r.position.x===a.position.x&&r.position.y===a.position.y&&(a.width===void 0||r.width===a.width&&r.height===a.height)||(n??=[...t],n[i]={...r,...a})}),n??t})},[]),Me=(0,h.useCallback)((e,t,n,r,i)=>{let a=wR(e,t,n);return we(t=>{let o=Array.from(SR(t).nodes.values()),s=JL(e)?pR(n,o,i):void 0,c=s?{...a,parentId:s.id,position:fRe(a.position,s.id,o)}:a;kR(t,[c],r?.(c.id,o)??[]),s&&jR(t,s.id,Ce())}),a.id},[]),Ne=(0,h.useCallback)((e,t,n)=>{let r=HL(e);return r?Me(r.type,r.createData(),t,void 0,n):void 0},[Me]),Pe=(0,h.useCallback)((e,t)=>we(n=>PR(n,e,t)),[]),Fe=(0,h.useCallback)(e=>we(t=>BR(t,e)),[]),Ie=(0,h.useCallback)(e=>we(t=>rH(t,e)),[]),Le=(0,h.useCallback)((e,t,n=`person`)=>we(n=>vRe(n,e,t),n===`level`?gUe:null),[]),Re=(0,h.useCallback)((e,t=[])=>we(n=>{kR(n,e,t);let r=new Set(e.map(e=>e.id));new Set(e.flatMap(e=>e.parentId&&!r.has(e.parentId)?[e.parentId]:[])).forEach(e=>jR(n,e,Ce()))}),[]),ze=(0,h.useCallback)(e=>we(t=>(Te.current.size&&Ee(t),NR(t,e,Ce()))),[]),Be=(0,h.useCallback)((e,t)=>we(n=>OR(n,e,ve.current,t),SH),[]),Ve=(0,h.useCallback)(e=>we(t=>ER(t,{title:e||void 0})),[]),He=(0,h.useCallback)(()=>l.current?.undoManager.undo(),[]),Ue=(0,h.useCallback)(()=>l.current?.undoManager.redo(),[]),We=(0,h.useCallback)(e=>{l.current?.sender.send({pointer:e})},[]),Ge=(0,h.useCallback)(e=>{l.current?.sender.send({viewport:e})},[]),Ke=(0,h.useCallback)(e=>{let t=l.current?.sender;t&&(t.send({editing:e&&{...e,...e.text!==void 0&&{text:e.text.slice(0,2e3)}}}),e||t.flush())},[]),qe=(0,h.useCallback)(e=>we(t=>{kR(t,e.nodes,e.edges),e.threads?.length&&jRe(t,e.threads),e.hotspots?.length&&IRe(t,e.hotspots),vRe(t,1,e.levelLayouts[1]),vRe(t,2,e.levelLayouts[2])},hUe),[]);return{nodes:u,edges:f,status:m,presence:_,clientId:y,doc:x,onNodesChange:De,onEdgesChange:Oe,onConnect:ke,onReconnect:Ae,showDragPreview:je,addNode:Ne,insertNode:Me,updateNodeData:Pe,deleteNodes:Fe,applyPositions:Ie,levelLayouts:ie,setLevelLayout:Le,insertNodes:Re,setParents:ze,title:T,diagramLevels:ee,structureKey:ne,rename:Ve,canvasStatus:oe,changeStatus:Be,transport:ce,deleted:ue,hotspots:fe,createHotspot:(0,h.useCallback)(e=>we(t=>qR(t,e)),[]),updateHotspot:(0,h.useCallback)((e,t)=>we(n=>JR(n,e,t)),[]),deleteHotspot:(0,h.useCallback)(e=>we(t=>LRe(t,e)),[]),lockedBy:me,setLocked:(0,h.useCallback)(e=>we(t=>hRe(t,e),SH),[]),sendEditing:Ke,synced:ge,addContent:qe,undo:He,redo:Ue,...C,setPointer:We,setViewport:Ge}}var xUe=3e4,SUe=()=>document.modelContext??navigator.modelContext,CUe=!1,CH=e=>e,wUe=(e,t=!1)=>({content:[{type:`text`,text:JSON.stringify(e,null,2)}],...t&&{isError:t}});function TUe(e){let[t,n]=(0,h.useState)({state:`off`}),r=(0,h.useRef)(null),i=(0,h.useRef)(void 0),a=()=>{let{doc:e}=s.current;if(e)return{change:t=>e.transact(()=>t(e),mUe),present:e=>{let{agent:t,presence:n}=s.current;r.current=e.pointer,n?.setLocalAgent({clientId:-1,name:t.name,color:t.color,agent:!0,...e}),clearTimeout(i.current),i.current=setTimeout(()=>s.current.presence?.setLocalAgent(null),xUe)},lastPointer:r.current}},o=(0,h.useRef)(a);o.current=a;let s=(0,h.useRef)(e);return s.current=e,(0,h.useEffect)(()=>{if(!e.doc)return;if(!SUe()){if(!e.allowPolyfill)return;hHe(),CUe=!0}let t=SUe();if(!t)return;let r=new AbortController,i=TH(()=>s.current,()=>o.current()),a=e=>n(t=>t.state===`on`?{...t,lastCall:e}:t);return Promise.allSettled(i.map(e=>t.registerTool({name:e.name,title:e.title,description:e.description,inputSchema:_M(e.input,{io:`input`,unrepresentable:`any`}),annotations:e.annotations,execute:async t=>{let n=e.input.safeParse(t??{});if(!n.success)return wUe({error:Eke(n.error)},!0);a(e.name);try{let t=await e.execute(n.data);return wUe(t,!!t&&typeof t==`object`&&`error`in t)}catch(e){return wUe({error:String(e?.message??e)},!0)}}},{signal:r.signal}))).then(e=>{r.signal.aborted||n({state:`on`,source:CUe?`polyfill`:`native`,tools:e.length})}),()=>{r.abort(),n({state:`off`})}},[e.doc,e.allowPolyfill]),(0,h.useEffect)(()=>()=>clearTimeout(i.current),[]),t}var wH={error:`The canvas is not connected yet`},TH=(e,t)=>{let n=t=>{let{doc:n}=e();return n?n.transact(()=>t(n),mUe):wH},r=t=>{t.length&&(e().select(t),e().fitView(t))};return[CH({name:`get_canvas`,title:`Read the canvas`,description:`Reads the collaborative canvas open on this page: its nodes (ids, names, positions, the catalog resource they stand for), connections, comment threads, and who is on it. Call it first, and again to see what people changed.`,input:U({}),annotations:{readOnlyHint:!0},execute:()=>n(t=>({...uVe(t),people:e().getPeers().map(e=>`${e.name}${e.agent?` (agent)`:``}`)}))}),CH({name:`search_catalog`,title:`Search the catalog`,description:`Finds EventCatalog resources (domains, systems, services, events, commands, queries, channels, data stores) to add to the canvas with add_to_canvas.`,input:U({query:H().optional().describe(`Matches names and ids`),collection:$M(rRe).optional()}),annotations:{readOnlyHint:!0},execute:({query:t,collection:n})=>{let r=t?.toLowerCase();return e().resources.filter(e=>!n||e.collection===n).filter(e=>!r||`${e.name} ${e.id}`.toLowerCase().includes(r)).slice(0,50).map(({collection:e,id:t,name:n,version:r,summary:i})=>({collection:e,id:t,name:n,version:r,summary:i}))}}),CH({name:`add_to_canvas`,title:`Add to the canvas`,description:`${aVe} Use search_catalog to find catalog resources first.`,input:U({nodes:QBe,edges:$Be.optional()}),execute:async n=>{let i=t();if(!i)return wH;let a=await tH(i,n,e().catalog);return r(a.created.map(e=>e.nodeId)),a}}),CH({name:`update_node`,title:`Update a node`,description:`Renames, re-describes, re-versions or moves a node (x/y: its new centre). Catalog resources keep their catalog name, summary and version. For notes, summary is the note text.`,input:U({nodeId:H(),name:H().optional(),summary:H().optional(),version:H().optional().describe(`e.g. 1.0.0`),x:LM().optional(),y:LM().optional()}),execute:async e=>{let n=t();return n?EHe(n,e):wH}}),CH({name:`connect_nodes`,title:`Connect nodes`,description:`Draws connections between nodes (by id). Labels default to EventCatalog wording, e.g. "publishes event".`,input:U({edges:$Be.min(1)}),execute:async({edges:e})=>{let n=t();return n?nH(n,e):wH}}),CH({name:`remove_from_canvas`,title:`Remove from the canvas`,description:`Removes nodes (and their connections) or connections. Only remove what the user asked for.`,input:U({nodeIds:GM(H()).optional(),connectionIds:GM(H()).optional()}),annotations:{consequentialHint:!0},execute:async({nodeIds:e=[],connectionIds:n=[]})=>{let r=t();return r?(await iH(r,e,n),{removedNodes:e,removedConnections:n}):wH}}),CH({name:`layout_canvas`,title:`Tidy the canvas`,description:`Lays the whole canvas out again with EventCatalog's visualiser layout (left to right, connections routed around nodes), for everyone on it. Call it once when you finish a round of changes, before you hand back to the user, so the canvas is tidy for everyone, and whenever the user asks to tidy up. Don't call it after every change (add_to_canvas already places what you add next to what it connects to while you work), and skip it if the user asked to keep the layout as it is: it moves everything, including what people placed themselves.`,input:U({}),execute:async()=>(await e().reorder(),{laidOut:!0})}),CH({name:`set_canvas_status`,title:`Set the canvas status`,description:`Changes the canvas's status: draft (being worked on, where every canvas starts), proposed (ready for review), accepted (the agreed design) or rejected (decided against). Only change it when the user asks you to. Changing the nodes or connections on an accepted or rejected canvas makes it a draft again.`,input:U({status:$M(pRe),note:H().optional()}),execute:({status:t,note:r})=>n(n=>({status:t,changed:OR(n,t,e().agent,r)}))}),CH({name:`add_comment`,title:`Comment on the canvas`,description:`Starts a comment thread pinned to a node (nodeId) or a spot (x, y). Only use it when the user asks you to comment (e.g. to review the canvas). Don't use comments to greet people or ask the user questions: talk to them in the conversation.`,input:U({text:H(),nodeId:H().optional(),x:LM().optional(),y:LM().optional()}),execute:async n=>{let r=t();return r?wHe(r,n,e().agent):wH}}),CH({name:`reply_to_comment`,title:`Reply to a comment`,description:`Replies to a comment thread (threadId from get_canvas).`,input:U({threadId:H(),text:H()}),execute:({threadId:t,text:r})=>n(n=>NRe(n,t,r,e().agent)?{threadId:t}:{error:`No comment thread "${t}"`})}),CH({name:`resolve_comment`,title:`Resolve a comment`,description:`Resolves (or reopens) a comment thread.`,input:U({threadId:H(),resolved:RM().default(!0)}),execute:({threadId:e,resolved:t})=>n(n=>UR(n,e,t)?{threadId:e,resolved:t}:{error:`No comment thread "${e}"`})}),CH({name:`show_nodes`,title:`Show nodes to the user`,description:`Selects nodes and moves the view to them, to point the user at something. Leave out nodeIds to show the whole canvas.`,input:U({nodeIds:GM(H()).optional()}),annotations:{readOnlyHint:!0},execute:({nodeIds:t})=>(t?.length&&e().select(t),e().fitView(t),{shown:t??`everything`})})]};function EUe(e,t){let[n,r]=(0,h.useState)([]);(0,h.useEffect)(()=>{if(!e)return r([]);let{threads:t}=SR(e),n=()=>r(ARe(e));return n(),t.observeDeep(n),()=>t.unobserveDeep(n)},[e]);let i=(0,h.useCallback)((n,r)=>e?HR(e,n,r,t):void 0,[e,t]),a=(0,h.useCallback)((n,r)=>e&&NRe(e,n,r,t),[e,t]),o=(0,h.useCallback)((t,n)=>e&&UR(e,t,n),[e]),s=(0,h.useCallback)((t,n)=>e&&WR(e,t,n),[e]),c=(0,h.useCallback)(t=>e&&GR(e,t),[e]),l=(0,h.useCallback)(t=>e&&PRe(e,t),[e]);return{threads:n,createThread:i,reply:a,setResolved:o,moveThread:s,moveThreads:(0,h.useCallback)(t=>e&&FRe(e,t),[e]),deleteThread:c,deleteThreads:l}}var EH=[`#ef4444`,`#f97316`,`#eab308`,`#22c55e`,`#06b6d4`,`#3b82f6`,`#8b5cf6`,`#ec4899`],DH=EH,DUe=`eventcatalog-studio-name`,OUe=`eventcatalog-studio-color`,kUe=()=>{try{return localStorage.getItem(DUe)}catch{return null}},AUe=e=>{try{return localStorage.setItem(DUe,e),!0}catch{return!1}},OH=e=>{let t=t=>t.key===DUe&&e(t.newValue);return window.addEventListener(`storage`,t),()=>window.removeEventListener(`storage`,t)},kH=e=>{let t=0;for(let n of e)t=t*31+n.charCodeAt(0)|0;return DH[Math.abs(t)%DH.length]},jUe=()=>{try{let e=localStorage.getItem(OUe);return e&&EH.includes(e)?e:null}catch{return null}},MUe=e=>{try{return localStorage.setItem(OUe,e),!0}catch{return!1}},NUe=(0,h.memo)(function({status:e,history:t,onChange:n}){let[r,i]=(0,h.useState)(!1),[a,o]=(0,h.useState)(``),s=(0,h.useRef)(null),c=lB[e];(0,h.useEffect)(()=>{if(!r)return;let e=e=>{s.current?.contains(e.target)||i(!1)},t=e=>e.key===`Escape`&&i(!1);return window.addEventListener(`pointerdown`,e),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`pointerdown`,e),window.removeEventListener(`keydown`,t)}},[r]);let l=t=>{t!==e&&n(t,a),o(``),i(!1)},u=t.slice(-8).reverse();return(0,D.jsxs)(`div`,{ref:s,className:`relative`,children:[(0,D.jsxs)(`button`,{onClick:()=>i(e=>!e),"aria-label":`Status: ${c.label}`,"aria-expanded":r,className:`flex items-center gap-1 rounded-full border px-2 py-0.5 text-[11px] font-semibold ${c.pill}`,children:[c.label,(0,D.jsx)(S,{size:12})]}),r&&(0,D.jsxs)(`div`,{className:`absolute left-0 top-full mt-2 w-72 min-w-56 bg-[rgb(var(--ec-page-bg))] border border-[rgb(var(--ec-page-border))] rounded-lg shadow-xl z-50 py-1.5`,children:[(0,D.jsx)(`p`,{className:`px-3 pb-1 pt-1.5 text-[11px] font-semibold uppercase tracking-wide text-[rgb(var(--ec-page-text-muted))]`,children:`Status`}),pRe.map(t=>{let n=lB[t];return(0,D.jsxs)(`button`,{onClick:()=>l(t),className:`flex items-center px-3 py-2 text-xs text-[rgb(var(--ec-page-text))] hover:bg-[rgb(var(--ec-accent-subtle)/0.3)] cursor-pointer transition-colors gap-2 w-full text-left`,children:[(0,D.jsx)(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${n.dot}`}),(0,D.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,D.jsx)(`span`,{className:`block text-xs font-medium`,children:n.label}),(0,D.jsx)(`span`,{className:`block text-[11px] text-[rgb(var(--ec-page-text-muted))]`,children:n.description})]}),t===e&&(0,D.jsx)(x,{size:14,className:`shrink-0 text-[rgb(var(--ec-accent))]`})]},t)}),(0,D.jsx)(`div`,{className:`px-3 py-2`,children:(0,D.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),placeholder:`Add a note (optional), then pick a status`,"aria-label":`Note for the status change`,className:`w-full rounded-md border px-2 py-1.5 text-xs bg-[rgb(var(--ec-input-bg))] border-[rgb(var(--ec-input-border))] text-[rgb(var(--ec-input-text))] placeholder:text-[rgb(var(--ec-page-text-muted))] focus:outline-none focus:border-[rgb(var(--ec-accent))]`})}),u.length>0&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`div`,{className:`my-1 h-px bg-[rgb(var(--ec-page-border))]`}),(0,D.jsx)(`p`,{className:`px-3 pb-1 pt-1.5 text-[11px] font-semibold uppercase tracking-wide text-[rgb(var(--ec-page-text-muted))]`,children:`History`}),(0,D.jsx)(`ul`,{className:`max-h-48 space-y-1.5 overflow-y-auto px-3 pb-2`,children:u.map(e=>(0,D.jsxs)(`li`,{className:`text-[11px]`,children:[(0,D.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,D.jsx)(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${lB[e.status].dot}`}),(0,D.jsx)(`span`,{className:`font-medium`,children:lB[e.status].label}),(0,D.jsxs)(`span`,{className:`text-[rgb(var(--ec-page-text-muted))]`,children:[`by `,e.by.name,` · `,mB(e.at)]})]}),e.note&&(0,D.jsx)(`span`,{className:`block pl-3 text-[rgb(var(--ec-page-text-muted))]`,children:e.note})]},`${e.at}-${e.status}`))})]})]})]})}),PUe={connected:cB.success.dot,connecting:cB.warning.dot,disconnected:cB.danger.dot},AH=`pointer-events-auto flex h-[38px] items-center rounded-[9px] border border-[rgb(var(--ec-page-border))] bg-[rgb(var(--ec-card-bg))] shadow-sm`,jH=`pointer-events-auto absolute top-full mt-2`,MH=`${jH} ${ZDe}`,FUe=`${$O} w-full text-left`,IUe=4,LUe=typeof navigator<`u`&&/Mac|iPhone|iPad/.test(navigator.platform)?`Cmd`:`Ctrl`,NH=`flex h-[34px] w-full cursor-pointer items-center gap-3 rounded-[7px] px-2 text-left text-sm outline-none hover:bg-[rgb(var(--ec-content-hover))]`,RUe=`flex flex-none [&_svg]:h-[17px] [&_svg]:w-[17px] [&_svg]:stroke-[1.75]`;function zUe(){let[e,t]=(0,h.useState)(!1),n=(0,h.useRef)(null);return(0,h.useEffect)(()=>{if(!e)return;let r=e=>{n.current?.contains(e.target)||t(!1)},i=e=>e.key===`Escape`&&t(!1);return window.addEventListener(`pointerdown`,r),window.addEventListener(`keydown`,i),()=>{window.removeEventListener(`pointerdown`,r),window.removeEventListener(`keydown`,i)}},[e]),{open:e,setOpen:t,ref:n}}function PH({peer:e,size:t=28,children:n}){return(0,D.jsxs)(`span`,{className:`relative flex items-center justify-center rounded-full text-[11px] font-semibold text-white ring-2 ring-[rgb(var(--ec-card-bg))]`,style:{backgroundColor:e.color,width:t,height:t},children:[n??(e.agent?(0,D.jsx)(fB,{name:e.name,size:14}):e.name.slice(0,2).toUpperCase()),!n&&(0,D.jsx)(uB,{src:e.picture})]})}function FH({title:e,status:t,transport:n,onRetitle:r,shareUrl:i,newCanvasUrl:a,onConnectAgent:o,webMcp:s,agentsHere:c,onDelete:l,onOpenFile:u,onSaveToFile:d,onExportImage:f,onLiveCollaboration:p,onHelp:m,children:g}){let _=zUe(),v=(0,h.useRef)(null),[y,b]=(0,h.useState)(null),x={connected:n===`tools`?`Connected through the chat`:`Connected`,connecting:`Connecting…`,disconnected:`Offline, reconnecting…`}[t],S=PUe[t],C=(e,t,n,r,i=``)=>(0,D.jsxs)(`button`,{type:`button`,className:`${NH} ${i}`,onClick:()=>{_.setOpen(!1),n()},children:[(0,D.jsx)(`span`,{className:RUe,children:e}),(0,D.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:t}),typeof r==`string`?(0,D.jsx)(`span`,{className:`flex-none text-xs font-normal text-[rgb(var(--ec-page-text-muted))]`,children:r}):r]});return(0,D.jsxs)(`div`,{ref:_.ref,className:`relative`,children:[(0,D.jsxs)(`div`,{className:`${AH} gap-1.5 pl-3 pr-1`,children:[(0,D.jsx)(`span`,{title:x,className:`h-2 w-2 shrink-0 rounded-full ${S}`}),(0,D.jsx)(`input`,{ref:v,"aria-label":`Canvas title`,value:y??e??``,placeholder:`Untitled canvas`,onChange:e=>b(e.target.value),onBlur:()=>{y!==null&&y.trim()!==(e??``)&&r(y.trim()),b(null)},onKeyDown:e=>e.key===`Enter`&&e.currentTarget.blur(),size:Math.max(12,(y??e??`Untitled canvas`).length),className:`${YDe} max-w-64 truncate rounded-md bg-transparent px-1.5 py-1 placeholder:text-[rgb(var(--ec-page-text-muted))] hover:bg-[rgb(var(--ec-page-border)/0.4)] focus:bg-[rgb(var(--ec-input-bg))] focus:outline-none`}),g,(0,D.jsx)(`button`,{"aria-label":`Canvas menu`,onClick:()=>_.setOpen(e=>!e),className:`group rounded-md p-1 hover:bg-[rgb(var(--ec-accent-subtle))]`,children:(0,D.jsx)(xe,{className:XDe})})]}),_.open&&(0,D.jsxs)(`div`,{className:`${jH} left-0 z-50 w-72 rounded-xl border border-[rgb(var(--ec-page-border))] bg-[rgb(var(--ec-card-bg))] p-1.5 text-[rgb(var(--ec-page-text))] shadow-xl`,children:[u&&C((0,D.jsx)(te,{}),`Open…`,u,`${LUe}+O`),C((0,D.jsx)(w,{}),`Save to file…`,d,`${LUe}+S`),C((0,D.jsx)(re,{}),`Export image…`,f,`${LUe}+Shift+E`),C((0,D.jsx)(_e,{}),`Live collaboration…`,p),C((0,D.jsx)(de,{}),c?`AI agent connected`:`Connect your AI agent…`,o,s.state===`on`||c?(0,D.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full ${cB.success.dot}`}):void 0),C((0,D.jsx)(ye,{}),`Help`,m,`?`),(0,D.jsx)(`div`,{className:`my-1.5 h-px bg-[rgb(var(--ec-page-border))]`}),C((0,D.jsx)(ue,{}),`Rename canvas`,()=>{v.current?.focus(),v.current?.select()}),C((0,D.jsx)(ae,{}),`Copy link`,()=>void navigator.clipboard.writeText(i??window.location.href)),a&&(0,D.jsxs)(`a`,{className:NH,href:a,children:[(0,D.jsx)(`span`,{className:RUe,children:(0,D.jsx)(fe,{})}),(0,D.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:`New canvas`})]}),l&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`div`,{className:`my-1.5 h-px bg-[rgb(var(--ec-page-border))]`}),C((0,D.jsx)(he,{}),`Delete canvas`,l,void 0,`${cB.danger.text} ${cB.danger.hover}`)]}),(0,D.jsx)(`div`,{className:`my-1.5 h-px bg-[rgb(var(--ec-page-border))]`}),(0,D.jsxs)(`p`,{className:`flex items-center gap-2 px-2 py-1.5 text-[11px] text-[rgb(var(--ec-page-text-muted))]`,children:[(0,D.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full ${S}`}),x]})]})]})}var BUe=e=>{let t=e.trim().split(/\s+/).filter(Boolean);return(t.length>1?t.map(e=>e[0]).join(``):e.trim()).slice(0,2).toUpperCase()};function VUe({me:e,onRename:t,onRecolor:n}){let r=zUe(),[i,a]=(0,h.useState)(e.name);(0,h.useEffect)(()=>a(e.name),[e.name]);let o=()=>{let n=i.trim();if(!n)return a(e.name);n!==e.name&&t?.(n)},s=(t,n)=>(0,D.jsxs)(`span`,{className:`relative flex ${t} flex-none items-center justify-center rounded-full text-[10px] font-semibold text-white`,style:{background:e.color},children:[BUe(n),(0,D.jsx)(uB,{src:e.picture})]});return e.agent?(0,D.jsx)(`span`,{title:`You're here as ${e.name} (AI agent)`,className:`${AH} pointer-events-auto w-[38px] justify-center`,children:(0,D.jsx)(`span`,{className:`flex h-6 w-6 items-center justify-center rounded-full text-white`,style:{background:e.color},children:(0,D.jsx)(fB,{name:e.name,size:14})})}):(0,D.jsxs)(`div`,{ref:r.ref,className:`pointer-events-auto relative`,children:[(0,D.jsx)(`button`,{type:`button`,title:t?`${e.name}: change your name and colour`:`${e.name}: change your colour`,onClick:()=>r.setOpen(e=>!e),className:`${AH} w-[38px] justify-center hover:bg-[rgb(var(--ec-content-hover))]`,children:s(`h-6 w-6`,e.name)}),r.open&&(0,D.jsxs)(`div`,{className:`${jH} right-0 z-[70] w-72 rounded-xl border border-[rgb(var(--ec-page-border))] bg-[rgb(var(--ec-card-bg))] p-4 text-[rgb(var(--ec-page-text))] shadow-xl`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-3`,children:[s(`h-9 w-9 text-xs`,i||e.name),(0,D.jsxs)(`div`,{className:`min-w-0`,children:[(0,D.jsx)(`p`,{className:`truncate text-sm font-semibold`,children:i||e.name}),(0,D.jsx)(`p`,{className:`text-xs text-[rgb(var(--ec-page-text-muted))]`,children:`On your pointer and comments`})]})]}),t&&(0,D.jsxs)(`label`,{className:`mt-4 block text-xs font-medium text-[rgb(var(--ec-page-text-muted))]`,children:[`Your name`,(0,D.jsx)(`input`,{value:i,maxLength:60,onChange:e=>a(e.target.value),onBlur:o,onKeyDown:e=>e.key===`Enter`&&e.currentTarget.blur(),className:`mt-1.5 block h-9 w-full rounded-md border border-[rgb(var(--ec-page-border))] bg-[rgb(var(--ec-page-bg))] px-3 text-sm text-[rgb(var(--ec-page-text))] outline-none focus:border-[rgb(var(--ec-accent))]`})]}),(0,D.jsxs)(`div`,{className:`mt-3 text-xs font-medium text-[rgb(var(--ec-page-text-muted))]`,children:[`Your colour`,(0,D.jsx)(`div`,{role:`radiogroup`,"aria-label":`Your colour`,className:`mt-2 flex gap-2`,children:EH.map(t=>(0,D.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":t===e.color,"aria-label":t,onClick:()=>n(t),className:`h-6 w-6 rounded-full transition-transform hover:scale-110 ${t===e.color?`ring-2 ring-[rgb(var(--ec-page-text))] ring-offset-2 ring-offset-[rgb(var(--ec-card-bg))]`:``}`,style:{background:t}},t))})]})]})]})}var HUe=(e,t,n)=>{let r=new Set(n.agent?[n.name]:[]);return e.filter(e=>e.clientId===t?!1:e.agent?r.has(e.name)?!1:(r.add(e.name),!0):!0)};function UUe({peers:e,clientId:t,me:n,onJumpTo:r}){let i=zUe(),a=HUe(e,t,n),o=a.slice(0,IUe),s=a.slice(IUe),c=e=>`${e.name}${e.agent?` (AI agent)${e.activity?`: ${e.activity}`:``}`:``}`;return(0,D.jsx)(`div`,{className:`flex items-center gap-1.5`,children:(0,D.jsxs)(`div`,{className:`flex -space-x-1.5`,children:[o.map(e=>(0,D.jsx)(`button`,{title:`${c(e)}. Click to jump to them`,onClick:()=>r(e),className:`block rounded-full transition-transform hover:z-10 hover:scale-110`,children:(0,D.jsx)(PH,{peer:e})},e.clientId)),s.length>0&&(0,D.jsxs)(`div`,{ref:i.ref,className:`relative`,children:[(0,D.jsxs)(`button`,{title:`${s.length} more`,onClick:()=>i.setOpen(e=>!e),className:`flex h-7 w-7 items-center justify-center rounded-full text-[11px] font-semibold ring-2 ring-[rgb(var(--ec-card-bg))] bg-[rgb(var(--ec-page-border))] text-[rgb(var(--ec-page-text))]`,children:[`+`,s.length]}),i.open&&(0,D.jsx)(`div`,{className:`${MH} right-0`,children:s.map(e=>(0,D.jsxs)(`button`,{className:FUe,onClick:()=>{r(e),i.setOpen(!1)},children:[(0,D.jsx)(PH,{peer:e,size:20}),c(e)]},e.clientId))})]})]})})}var WUe=(0,h.memo)(function({title:e,onRetitle:t,status:n,transport:r,presence:i,clientId:a,onJumpTo:o,me:s,onRename:c,onRecolor:l,onConnectAgent:u,webMcp:d,shareUrl:f,newCanvasUrl:p,onShare:m,onOpenFile:h,onSaveToFile:g,onExportImage:_,onLiveCollaboration:v,onHelp:y,canvasStatus:b,statusHistory:x,onStatusChange:S,onDelete:C}){let w=yH(i),T=w.some(e=>e.agent),E=HUe(w,a,s).length>0;return(0,D.jsxs)(`div`,{className:`pointer-events-none absolute left-3 right-3 top-3 z-10 flex items-start justify-between gap-3`,children:[(0,D.jsx)(FH,{title:e,status:n,transport:r,onRetitle:t,shareUrl:f,newCanvasUrl:p,onConnectAgent:u,webMcp:d,agentsHere:T,onDelete:C,onOpenFile:h,onSaveToFile:g,onExportImage:_,onLiveCollaboration:v,onHelp:y,children:(0,D.jsx)(NUe,{status:b,history:x,onChange:S})}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[E&&(0,D.jsx)(`div`,{className:`${AH} px-1.5`,children:(0,D.jsx)(UUe,{peers:w,clientId:a,me:s,onJumpTo:o})}),(0,D.jsx)(VUe,{me:s,onRename:c,onRecolor:l}),(0,D.jsxs)(`button`,{onClick:m,className:`pointer-events-auto inline-flex h-[38px] items-center gap-2 rounded-[9px] bg-[rgb(var(--ec-page-text))] px-4 text-sm font-semibold text-[rgb(var(--ec-page-bg))] shadow-sm transition-colors hover:bg-[rgb(var(--ec-page-text)/0.85)]`,children:[(0,D.jsx)(me,{size:16,"aria-hidden":!0}),`Share`]})]})]})}),GUe=`npx -y @mcp-b/webmcp-local-relay@5.1.0`,IH=`eventcatalog-webmcp-relay`,KUe=`eventcatalog-webmcp`,LH=e=>{try{return localStorage.getItem(e)===`true`}catch{return!1}},RH=e=>{try{localStorage.setItem(e,`true`)}catch{}},qUe=()=>LH(KUe)||LH(IH),JUe=()=>RH(KUe),zH=()=>LH(IH),YUe=e=>{if(document.querySelector(`script[data-webmcp-relay-embed]`))return;let t=document.createElement(`script`);t.src=e,t.dataset.webmcpRelayEmbed=``,t.dataset.relayPort=`9333`,document.body.appendChild(t)},XUe=e=>{RH(IH),YUe(e)},BH=({canvasId:e,title:t,canvasUrl:n,mcpUrl:r})=>`Join me on an EventCatalog canvas so we can design this together, live.
|
|
155
|
+
`),onKeyDown:e=>(e.key===`Enter`||e.key===` `)&&r(),onPointerDown:e=>{if(e.button!==0)return;try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}let t=e.currentTarget.getBoundingClientRect();a.current={start:{x:e.clientX,y:e.clientY},grab:{x:e.clientX-t.left-_Be*(t.height/28),y:e.clientY-t.top-t.height/2},moved:!1}},onPointerMove:e=>{let t=a.current;!t||!i||!t.moved&&Math.hypot(e.clientX-t.start.x,e.clientY-t.start.y)<PB||(t.moved=!0,i(o(e),`move`))},onPointerUp:e=>{let t=a.current;a.current=null,t&&(t.moved?i?.({x:e.clientX-t.grab.x,y:e.clientY-t.grab.y},`end`):r())},onPointerCancel:()=>a.current=null,className:`studio-hotspot-marker flex h-7 max-w-[240px] items-center gap-1.5 rounded-full pl-1 pr-2.5 text-[11px] font-semibold text-white ${i?`cursor-grab active:cursor-grabbing`:``}`,style:{background:OB[c].color,touchAction:`none`,...n&&{boxShadow:`0 0 0 2px rgb(var(--ec-card-bg)), 0 0 0 4px rgb(var(--ec-button-bg))`}},children:[(0,D.jsx)(`span`,{className:`flex h-5 w-5 flex-none items-center justify-center rounded-full bg-white/20`,children:(0,D.jsx)(NB,{severity:c})}),(0,D.jsx)(`span`,{className:`studio-hotspot-label truncate`,children:u})]})}var yBe=`studio-hotspot-panel absolute left-0 top-[34px] w-80 rounded-xl border border-[rgb(var(--ec-page-border))] bg-[rgb(var(--ec-card-bg))] text-[rgb(var(--ec-page-text))] shadow-xl`,bBe=`block w-full rounded-md border border-[rgb(var(--ec-input-border))] bg-[rgb(var(--ec-input-bg))] px-2.5 py-1.5 text-sm text-[rgb(var(--ec-input-text))] outline-none focus:border-[rgb(var(--ec-accent))]`;function xBe({initial:e,submitLabel:t,onSubmit:n,onCancel:r}){let[i,a]=(0,h.useState)(e?.severity??`warning`),[o,s]=(0,h.useState)(e?.title??``),[c,l]=(0,h.useState)(e?.description??``),u=e=>{e?.preventDefault(),o.trim()&&n({severity:i,title:o.trim(),...c.trim()&&{description:c.trim()}})};return(0,D.jsxs)(`form`,{onSubmit:u,onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),r())},className:`space-y-2.5 p-3`,children:[(0,D.jsx)(`div`,{role:`radiogroup`,"aria-label":`How important`,className:`flex gap-1`,children:kB.map(e=>{let t=e===i;return(0,D.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":t,onClick:()=>a(e),className:`flex flex-1 items-center justify-center gap-1 rounded-md border px-2 py-1.5 text-xs font-semibold transition-colors`,style:t?{background:OB[e].color,borderColor:OB[e].color,color:`#fff`}:{borderColor:`rgb(var(--ec-page-border))`,color:OB[e].color},children:[(0,D.jsx)(NB,{severity:e,size:12}),OB[e].label]},e)})}),(0,D.jsx)(`input`,{autoFocus:!0,value:o,maxLength:120,onChange:e=>s(e.target.value),placeholder:`What should people know? e.g. Single point of failure`,className:bBe}),(0,D.jsx)(`textarea`,{value:c,maxLength:1e3,rows:3,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&u()},placeholder:`Why it matters, and what to do about it (optional)`,className:`${bBe} resize-none`}),(0,D.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,D.jsx)(`button`,{type:`button`,onClick:r,className:`rounded-md px-3 py-1.5 text-xs font-medium text-[rgb(var(--ec-page-text-muted))] hover:bg-[rgb(var(--ec-content-hover))]!`,children:`Cancel`}),(0,D.jsx)(`button`,{type:`submit`,disabled:!o.trim(),className:`rounded-md bg-[rgb(var(--ec-primary-bg))] px-3 py-1.5 text-xs font-semibold text-[rgb(var(--ec-primary-text))] disabled:opacity-40`,children:t})]})]})}function FB({severity:e}){return(0,D.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-bold uppercase tracking-wide text-white`,style:{background:OB[e].color},children:[(0,D.jsx)(NB,{severity:e,size:10}),OB[e].label]})}function IB({hotspot:e,actions:t}){return(0,D.jsxs)(`div`,{className:`border-l-[3px] pl-2.5`,style:{borderColor:OB[e.severity].color},children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(FB,{severity:e.severity}),(0,D.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1 truncate text-[11px] text-[rgb(var(--ec-page-text-muted))]`,children:[e.author.agent&&(0,D.jsx)(fB,{name:e.author.name,size:11}),e.author.name,` · `,mB(e.createdAt)]}),t&&(0,D.jsx)(`span`,{className:`ml-auto flex flex-none items-center gap-0.5`,children:t})]}),(0,D.jsx)(`p`,{className:`mt-1.5 text-sm font-semibold leading-snug`,children:e.title}),e.description&&(0,D.jsx)(`p`,{className:`mt-1 whitespace-pre-wrap text-xs leading-relaxed text-[rgb(var(--ec-page-text-muted))]`,children:e.description})]})}function SBe({label:e,onClick:t,children:n}){return(0,D.jsx)(`button`,{type:`button`,title:e,"aria-label":e,onClick:t,className:`rounded p-1 text-[rgb(var(--ec-icon-color))] hover:bg-[rgb(var(--ec-page-border)/0.5)] hover:text-[rgb(var(--ec-icon-hover))]`,children:n})}function LB({spot:e,locked:t,onClose:n,onUpdate:r,onDelete:i,onGo:a}){let[o,s]=(0,h.useState)(null),c=[...e.hotspots].sort(AB);return(0,D.jsxs)(`div`,{className:yBe,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between border-b border-[rgb(var(--ec-page-border))] px-3 py-2`,children:[(0,D.jsx)(`span`,{className:`text-xs font-semibold`,children:c.length===1?`Hotspot`:`${c.length} hotspots`}),(0,D.jsx)(SBe,{label:`Close`,onClick:n,children:(0,D.jsx)(zp,{size:14})})]}),(0,D.jsx)(`div`,{className:`max-h-80 space-y-3 overflow-y-auto p-3`,children:c.map(n=>o===n.id?(0,D.jsx)(`div`,{className:`-m-3`,children:(0,D.jsx)(xBe,{initial:n,submitLabel:`Save`,onCancel:()=>s(null),onSubmit:e=>{r(n.id,e),s(null)}})},n.id):e.inside?(0,D.jsx)(`button`,{type:`button`,onClick:()=>a(n),className:`block w-full rounded-md text-left hover:bg-[rgb(var(--ec-content-hover))]!`,children:(0,D.jsx)(IB,{hotspot:n})},n.id):(0,D.jsx)(IB,{hotspot:n,actions:!t&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(SBe,{label:`Edit`,onClick:()=>s(n.id),children:(0,D.jsx)(vp,{size:13})}),(0,D.jsx)(SBe,{label:`Remove`,onClick:()=>i(n.id),children:(0,D.jsx)(jp,{size:13})})]})},n.id))}),e.inside&&(0,D.jsx)(`p`,{className:`border-t border-[rgb(var(--ec-page-border))] px-3 py-2 text-[11px] text-[rgb(var(--ec-page-text-muted))]`,children:`Inside this: click one to go to it.`})]})}var RB=(0,h.memo)(function({spots:e,openKey:t,draft:n,locked:r,movable:i,selectedIds:a,onMove:o,onDropTarget:s,onOpen:c,onCreate:l,onCancelDraft:u,onUpdate:d,onDelete:f,onGo:p,live:m}){let g=(0,h.useRef)(null);MB(g);let{screenToFlowPosition:_}=Dl(),[v,y]=(0,h.useState)(null),b=Az(m,`hotspot`),x=e=>{for(let t of e.hotspots)if(b.has(t.id))return b.get(t.id)},S=e=>{let t=document.elementsFromPoint(e.x,e.y).find(e=>e.closest(`.react-flow__node`))?.closest(`.react-flow__node`),n=[...t?.classList??[]].find(e=>e.startsWith(`react-flow__node-`))?.slice(17);return t&&!eR(n)?t.getAttribute(`data-id`)??void 0:void 0},C=e=>i&&!r&&!e.inside?(t,n)=>{let r=_(t),i=S(t);if(n===`move`)return i!==v?.over&&s(i?{nodeId:i,severity:fBe(e.hotspots)}:null),Oz(m,`hotspot`,e.hotspots[0].id,r),y({key:e.key,position:r,over:i});y(null),s(null),o(e.hotspots.map(e=>e.id),i?{nodeId:i,position:r}:{position:r}),Oz(m,`hotspot`,e.hotspots[0].id,null)}:void 0;return(0,D.jsx)(IO,{children:(0,D.jsxs)(`div`,{ref:g,className:`absolute left-0 top-0`,style:{zIndex:2e3},children:[e.map(e=>{let n=e.key===t,i=x(e),o=v?.key===e.key?v:i?{position:i}:void 0;return(0,D.jsxs)(gBe,{nodeId:o?void 0:e.nodeId,position:o?o.position:e.position,zIndex:o?5:n?3:1,children:[(0,D.jsx)(vBe,{spot:e,open:n,selected:!!a&&e.hotspots.some(e=>a.has(e.id)),onClick:()=>c(n?null:e.key),onDrag:C(e)}),n&&!o&&(0,D.jsx)(LB,{spot:e,locked:r,onClose:()=>c(null),onUpdate:d,onDelete:f,onGo:p})]},e.key)}),n&&(0,D.jsxs)(gBe,{nodeId:n.nodeId,position:n.nodeId?void 0:n.position,zIndex:4,children:[(0,D.jsx)(`span`,{className:`studio-hotspot-marker flex h-7 w-7 items-center justify-center rounded-full text-white`,style:{background:OB.warning.color},children:(0,D.jsx)(NB,{severity:`warning`})}),(0,D.jsx)(`div`,{className:yBe,children:(0,D.jsx)(xBe,{submitLabel:`Add hotspot`,onSubmit:l,onCancel:u})})]})]})})});function zB({hotspots:e,nameOf:t,onOpen:n}){let r=[...e].sort(AB);return r.length?(0,D.jsx)(`div`,{className:`space-y-1.5 p-3`,children:r.map(e=>{let r=e.nodeId&&t(e.nodeId);return(0,D.jsxs)(`button`,{type:`button`,onClick:()=>n(e),className:`w-full rounded-md border border-[rgb(var(--ec-page-border))] bg-[rgb(var(--ec-page-bg))] px-2.5 py-2 text-left hover:border-[rgb(var(--ec-accent))]!`,children:[(0,D.jsx)(IB,{hotspot:e}),r&&(0,D.jsxs)(`p`,{className:`mt-1.5 pl-[13px] text-[11px] text-[rgb(var(--ec-page-text-muted))]`,children:[`On `,r]})]},e.id)})}):(0,D.jsx)(`p`,{className:`px-4 py-6 text-center text-xs leading-relaxed text-[rgb(var(--ec-page-text-muted))]`,children:`No hotspots yet. Press A, or right-click a node, to flag what people should know: a risk, a problem, or the key part.`})}var BB={[LL.domain]:{icon:zf,className:`text-yellow-500`},[LL.system]:{icon:Qf,className:`text-violet-600`},"context-domain":{icon:zf,className:`text-yellow-500`},system:{icon:Qf,className:`text-violet-600`},service:{icon:Ep,className:`text-pink-600`},event:{icon:Vp,className:`text-orange-600`},command:{icon:ap,className:`text-blue-600`},query:{icon:wp,className:`text-green-600`},channel:{icon:If,className:`text-gray-600`},data:{icon:Gf,className:`text-blue-600`},"data:cache":{icon:Ate,className:`text-blue-600`},"data:searchIndex":{icon:Mte,className:`text-blue-600`},"data:objectStore":{icon:wte,className:`text-blue-600`},view:{icon:pp,className:`text-sky-600`},externalSystem:{icon:Xf,className:`text-purple-600`},agent:{icon:Lf,className:`text-violet-600`},actor:{icon:Fp,className:`text-yellow-500`},team:{icon:Ip,className:`text-emerald-600`},entity:{icon:kp,className:`text-blue-600`},note:{icon:Op,className:`text-yellow-500`},text:{icon:Mp,className:`text-[rgb(var(--ec-icon-color))]`}},CBe=[{collection:`domains`,label:`Domains`,...BB[LL.domain]},{collection:`systems`,label:`Systems`,...BB[LL.system]},{collection:`services`,label:`Services`,...BB.service},{collection:`events`,label:`Events`,...BB.event},{collection:`commands`,label:`Commands`,...BB.command},{collection:`queries`,label:`Queries`,...BB.query},{collection:`channels`,label:`Channels`,...BB.channel},{collection:`containers`,label:`Data Stores`,...BB.data}],VB=QO;function HB({shortcut:e,children:t}){return(0,D.jsxs)(`span`,{className:`relative flex h-8 w-8 items-center justify-center`,children:[(0,D.jsx)(`span`,{className:`-translate-x-[3px] -translate-y-[2px]`,children:t}),(0,D.jsx)(`span`,{"aria-hidden":!0,className:`absolute bottom-[2px] right-[4px] text-[9px] font-medium leading-none text-[rgb(var(--ec-page-text-muted))] opacity-60`,children:e})]})}var wBe={note:`Click anywhere to put a sticky note there`,text:`Click anywhere to start typing`,comment:`Click anywhere, or on a node, to comment there`,hotspot:`Click a node, or anywhere, to flag a hotspot there`};function TBe({level:e,onChange:t,unavailable:n}){return(0,D.jsx)(`div`,{role:`group`,"aria-label":`Level of detail`,className:`flex items-center gap-0.5`,children:pz.map(({level:r,description:i})=>(0,D.jsx)(JO,{label:`Level ${r}: ${i} (${r})`,hint:n?.[r],active:r===e,disabled:!!n?.[r],onClick:()=>t(r),children:(0,D.jsx)(HB,{shortcut:String(r),children:(0,D.jsxs)(`span`,{className:`text-xs font-semibold`,children:[`L`,r]})})},r))})}var EBe=(0,h.memo)(function({level:e,onLevelChange:t,unavailableLevels:n,editable:r,locked:i,onToggleLock:a,lockedBy:o,selectMode:s,onSelectMode:c,handMode:l,onHandMode:u,noteMode:d,onToggleNoteMode:f,textMode:p,onToggleTextMode:m,commentMode:h,onToggleCommentMode:g,hotspotMode:_,onToggleHotspotMode:v,extras:y}){return(0,D.jsxs)(`div`,{className:`absolute left-1/2 top-3 z-10 -translate-x-1/2`,children:[(0,D.jsxs)(YO,{children:[(0,D.jsx)(JO,{label:i?`Locked${o?` by ${o}`:``}: unlock it to change it (for everyone on it)`:`Lock the canvas (it can be looked at, not changed, by everyone on it)`,active:i,onClick:a,children:i?(0,D.jsx)(ip,{className:`h-4 w-4`}):(0,D.jsx)(Ste,{className:`h-4 w-4`})}),(0,D.jsx)(FDe,{}),(0,D.jsx)(JO,{label:`Select (V)`,active:s,onClick:c,children:(0,D.jsx)(HB,{shortcut:`V`,children:(0,D.jsx)(hp,{className:`h-4 w-4`})})}),(0,D.jsx)(JO,{label:`Hand (H): drag to move around`,active:l,onClick:u,children:(0,D.jsx)(HB,{shortcut:`H`,children:(0,D.jsx)($f,{className:`h-4 w-4`})})}),(0,D.jsx)(FDe,{}),(0,D.jsx)(TBe,{level:e,onChange:t,unavailable:n}),(0,D.jsx)(FDe,{}),(0,D.jsx)(JO,{label:r?`Sticky note (N): click where it goes`:`Sticky note (N): on L${e}, where it's clicked`,active:d,disabled:i,hint:i?`The canvas is locked`:void 0,onClick:f,children:(0,D.jsx)(HB,{shortcut:`N`,children:(0,D.jsx)(Op,{className:`h-4 w-4 text-yellow-500`})})}),(0,D.jsx)(JO,{label:r?`Text (T): click anywhere and type`:`Text (T): on L${e}, where it's clicked`,active:p,disabled:i,hint:i?`The canvas is locked`:void 0,onClick:m,children:(0,D.jsx)(HB,{shortcut:`T`,children:(0,D.jsx)(Mp,{className:`h-4 w-4`})})}),(0,D.jsx)(JO,{label:`Comment (C): click where it goes, or on a node`,active:h,onClick:g,children:(0,D.jsx)(HB,{shortcut:`C`,children:(0,D.jsx)(up,{className:`h-4 w-4`})})}),(0,D.jsx)(JO,{label:`Hotspot (A): click a node, or anywhere, to flag it`,active:_,disabled:i,hint:i?`The canvas is locked`:void 0,onClick:v,children:(0,D.jsx)(HB,{shortcut:`A`,children:(0,D.jsx)(Pf,{className:`h-4 w-4 text-amber-600`})})}),y]}),(d||p||h||_)&&(0,D.jsxs)(`p`,{className:`pointer-events-none mt-2 text-center text-xs text-[rgb(var(--ec-page-text-muted))]`,children:[wBe[d?`note`:h?`comment`:_?`hotspot`:`text`],` `,`·`,` `,(0,D.jsx)(`kbd`,{className:`rounded border border-[rgb(var(--ec-page-border))] px-1 font-sans text-[11px]`,children:`Esc`}),` `,`to cancel`]})]})}),DBe=(0,h.memo)(function({canUndo:e,canRedo:t,onUndo:n,onRedo:r,onReorder:i,reorderLabel:a,locked:o,fitOptions:s=VB,comments:c,hotspots:l}){let{zoomIn:u,zoomOut:d,fitView:f}=Dl();return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(YO,{children:[(0,D.jsx)(JO,{label:`Zoom out`,onClick:()=>void d({duration:200}),children:(0,D.jsx)(Up,{className:`h-4 w-4`})}),(0,D.jsx)(PDe,{}),(0,D.jsx)(JO,{label:`Zoom in`,onClick:()=>void u({duration:200}),children:(0,D.jsx)(Hp,{className:`h-4 w-4`})})]}),(0,D.jsxs)(YO,{children:[(0,D.jsx)(JO,{label:`Undo (⌘Z)`,hint:e?void 0:`Nothing to undo`,disabled:!e,onClick:n,children:(0,D.jsx)(Np,{className:`h-4 w-4`})}),(0,D.jsx)(JO,{label:`Redo (⇧⌘Z)`,hint:t?void 0:`Nothing to redo`,disabled:!t,onClick:r,children:(0,D.jsx)(jte,{className:`h-4 w-4`})})]}),(0,D.jsxs)(YO,{children:[(0,D.jsx)(JO,{label:`Fit view (⇧1)`,onClick:()=>void f({...s,duration:500}),children:(0,D.jsx)(cp,{className:`h-4 w-4`})}),(0,D.jsx)(JO,{label:a,hint:o?`The canvas is locked`:void 0,disabled:o,onClick:i,children:(0,D.jsx)(Tp,{className:`h-4 w-4`})})]}),c&&(0,D.jsxs)(YO,{children:[(0,D.jsx)(JO,{label:c.open?`Comments (${c.open} open)`:`Comments`,active:c.active,onClick:c.onToggle,children:(0,D.jsxs)(`span`,{className:`relative`,children:[(0,D.jsx)(dp,{className:`h-4 w-4`}),c.open>0&&(0,D.jsx)(`span`,{className:`absolute -right-2 -top-2 min-w-4 rounded-full bg-[rgb(var(--ec-accent))] px-1 text-center text-[9px] font-semibold leading-4 text-white`,children:c.open})]})}),l&&(0,D.jsx)(JO,{label:l.count?`Hotspots (${l.count})`:`Hotspots`,active:l.active,onClick:l.onToggle,children:(0,D.jsxs)(`span`,{className:`relative`,children:[(0,D.jsx)(Pf,{className:`h-4 w-4`}),l.count>0&&(0,D.jsx)(`span`,{className:`absolute -right-2 -top-2 min-w-4 rounded-full px-1 text-center text-[9px] font-semibold leading-4 text-white`,style:{background:OB[l.severity??`warning`].color},children:l.count})]})})]})]})}),UB=(e,t)=>`${e} ${t}${e===1?``:`s`}`,WB=()=>(0,D.jsxs)(`svg`,{viewBox:`0 0 64 36`,className:`h-9 w-16`,"aria-hidden":!0,children:[(0,D.jsx)(`rect`,{x:`18`,y:`8`,width:`28`,height:`20`,rx:`4`,fill:`currentColor`,fillOpacity:`0.1`,stroke:`currentColor`,strokeOpacity:`0.5`,strokeWidth:`1.5`}),(0,D.jsx)(`rect`,{x:`23`,y:`13`,width:`14`,height:`3`,rx:`1.5`,fill:`currentColor`,fillOpacity:`0.6`}),(0,D.jsx)(`rect`,{x:`23`,y:`19`,width:`18`,height:`2`,rx:`1`,fill:`currentColor`,fillOpacity:`0.35`}),(0,D.jsx)(`path`,{d:`M46 18h12`,stroke:`currentColor`,strokeOpacity:`0.5`,strokeWidth:`1.5`,strokeDasharray:`2 2`}),(0,D.jsx)(`rect`,{x:`57`,y:`14`,width:`6`,height:`8`,rx:`1.5`,fill:`currentColor`,fillOpacity:`0.4`})]}),OBe=[{as:`card`,label:`Card`,hint:`Connected to what it contains`,Preview:WB},{as:`container`,label:`Container`,hint:`What it contains sits inside it`,Preview:()=>(0,D.jsxs)(`svg`,{viewBox:`0 0 64 36`,className:`h-9 w-16`,"aria-hidden":!0,children:[(0,D.jsx)(`rect`,{x:`4`,y:`2`,width:`56`,height:`32`,rx:`4`,fill:`currentColor`,fillOpacity:`0.08`,stroke:`currentColor`,strokeOpacity:`0.5`,strokeWidth:`1.5`}),(0,D.jsx)(`path`,{d:`M4 10h56`,stroke:`currentColor`,strokeOpacity:`0.35`,strokeWidth:`1`}),(0,D.jsx)(`rect`,{x:`8`,y:`4.5`,width:`14`,height:`3`,rx:`1.5`,fill:`currentColor`,fillOpacity:`0.6`}),(0,D.jsx)(`rect`,{x:`10`,y:`15`,width:`18`,height:`12`,rx:`2`,fill:`currentColor`,fillOpacity:`0.5`}),(0,D.jsx)(`rect`,{x:`36`,y:`15`,width:`18`,height:`12`,rx:`2`,fill:`currentColor`,fillOpacity:`0.5`})]})}];function kBe({kind:e,name:t,contents:n,position:r,onChoose:i,onCancel:a}){let[o,s]=(0,h.useState)(!0),c=n?[n.systems>0&&UB(n.systems,`system`),n.services>0&&UB(n.services,`service`)].filter(Boolean).join(` and `):``;(0,h.useEffect)(()=>{let e=e=>e.key===`Escape`&&a();return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[a]);let l=Math.min(Math.max(r.x-160,12),window.innerWidth-332),u=Math.min(Math.max(r.y-20,12),window.innerHeight-(c?260:200));return(0,D.jsx)(`div`,{className:`fixed inset-0 z-50`,onPointerDown:a,children:(0,D.jsxs)(`div`,{role:`dialog`,"aria-label":t?`Add ${t} as`:`Add the ${e} as`,onPointerDown:e=>e.stopPropagation(),className:`absolute w-80 rounded-lg border p-1.5 shadow-xl bg-[rgb(var(--ec-card-bg))] border-[rgb(var(--ec-page-border))] text-[rgb(var(--ec-page-text))]`,style:{left:l,top:u},children:[(0,D.jsxs)(`div`,{className:`flex items-start justify-between gap-2 px-2 pb-1.5 pt-1`,children:[(0,D.jsxs)(`div`,{className:`min-w-0`,children:[(0,D.jsxs)(`p`,{className:`text-[10px] font-semibold uppercase tracking-wider text-[rgb(var(--ec-page-text-muted))]`,children:[`Add this `,e,` as`]}),t&&(0,D.jsx)(`p`,{className:`truncate text-xs font-semibold`,children:t})]}),(0,D.jsx)(`button`,{onClick:a,"aria-label":`Cancel`,className:`rounded p-0.5 text-[rgb(var(--ec-icon-color))] hover:bg-[rgb(var(--ec-page-border)/0.5)]`,children:(0,D.jsx)(zp,{size:14})})]}),(0,D.jsx)(`div`,{className:`grid grid-cols-2 gap-1.5 px-0.5 pb-0.5`,children:OBe.map(({as:e,label:t,hint:n,Preview:r})=>(0,D.jsxs)(`button`,{autoFocus:e===`container`,onClick:()=>i(e===`card`?{as:e}:{as:e,withContents:o&&!!c}),className:`flex flex-col items-center gap-1 rounded-md border px-2 pb-1.5 pt-2 text-xs outline-none transition-colors border-[rgb(var(--ec-page-border))] text-[rgb(var(--ec-page-text-muted))] hover:border-[rgb(var(--ec-accent))] hover:bg-[color-mix(in_srgb,rgb(var(--ec-accent))_8%,transparent)] hover:text-[rgb(var(--ec-accent))] focus-visible:border-[rgb(var(--ec-accent))] focus-visible:text-[rgb(var(--ec-accent))]`,children:[(0,D.jsx)(r,{}),(0,D.jsx)(`span`,{className:`font-semibold`,children:t}),(0,D.jsx)(`span`,{className:`text-center text-[10px] leading-tight text-[rgb(var(--ec-page-text-muted))]`,children:n})]},e))}),c&&(0,D.jsxs)(`label`,{className:`mt-1 flex items-center gap-2 rounded-md px-2 py-1.5 text-[11px] text-[rgb(var(--ec-page-text-muted))]`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked)}),`As a container, bring its `,c,` inside, with their messages and data stores`]})]})})}var ABe=.4,jBe=1.6,GB=8,KB=(0,h.memo)(function({nodeId:e,locked:t,onClick:n}){let r=Nc(e=>e.transform[2]),i=Math.min(jBe,Math.max(ABe,r));return(0,D.jsx)(sf,{nodeId:e,isVisible:!0,position:co.Top,align:`end`,offset:GB*i,children:(0,D.jsx)(`button`,{type:`button`,className:`studio-edit-button`,style:{transform:`scale(${i})`,transformOrigin:`bottom right`},onClick:n,children:t?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(ep,{"aria-hidden":!0}),` Details`]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(vp,{"aria-hidden":!0}),` Edit`]})})})}),qB=`application/eventcatalog-studio`,JB=nRe.map(e=>({...e,definitions:iRe.filter(t=>t.category===e.id&&!t.unlisted)})),YB=e=>({type:e===`domain`?`context-domain`:`system`,data:{mode:`full`,navigable:!1,[e]:{name:e===`domain`?`New Domain`:`New System`,version:`0.0.1`}}}),MBe=new Map(iRe.map(e=>[BL(e),e.type===LL.domain?YB(`domain`):e.type===LL.system?YB(`system`):{type:e.type,data:e.createData()}])),NBe=`eventcatalog-studio-palette-collapsed`,PBe=()=>{try{return localStorage.getItem(NBe)===`true`}catch{return!1}};function FBe({icon:e,iconClassName:t,label:n,description:r,usable:i=!0,onDragStart:a,onClick:o,title:s,trailing:c}){return(0,D.jsxs)(`button`,{type:`button`,draggable:i&&!!a,"aria-disabled":!i,onDragStart:i?a:void 0,onClick:i?o:void 0,"aria-label":n,title:s,className:`group flex w-full items-center gap-2.5 rounded-lg border border-[rgb(var(--ec-page-border))] bg-[rgb(var(--ec-card-bg))] py-1 pl-1 pr-2 text-left text-[rgb(var(--ec-page-text))] shadow-[0_1px_2px_rgb(0_0_0/0.05)] transition-[transform,box-shadow,border-color] duration-150 ${i?`cursor-grab hover:-translate-y-px hover:border-[color-mix(in_srgb,rgb(var(--ec-accent))_45%,transparent)]! hover:shadow-[0_4px_12px_rgb(0_0_0/0.08)] active:translate-y-0 active:cursor-grabbing`:`cursor-not-allowed opacity-40 grayscale`}`,children:[(0,D.jsx)(`span`,{className:`flex h-8 w-8 flex-none items-center justify-center rounded-md bg-[rgb(var(--ec-content-hover))]`,children:(0,D.jsx)(e,{size:16,className:t})}),(0,D.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,D.jsx)(`span`,{className:`block truncate text-[13px] font-medium leading-tight`,children:n}),r&&(0,D.jsx)(`span`,{className:`block truncate text-[11px] leading-snug text-[rgb(var(--ec-page-text-muted))]`,children:r})]}),c??(i&&a&&(0,D.jsx)(Zf,{"aria-hidden":!0,size:14,className:`flex-none text-[rgb(var(--ec-page-text-muted))] opacity-40 transition-opacity group-hover:opacity-80`}))]})}function XB({title:e,divided:t=!1,children:n}){return(0,D.jsxs)(`section`,{className:t?`border-t border-[rgb(var(--ec-page-border))] pt-3`:``,children:[(0,D.jsx)(`h3`,{className:`mb-1.5 text-[11px] font-medium text-[rgb(var(--ec-page-text-muted))]`,children:e}),(0,D.jsx)(`div`,{className:`space-y-1.5`,children:n})]})}var IBe=`components`,LBe=(0,h.memo)(function({level:e,onAddComponent:t,footer:n,tabs:r,tab:i,onTabChange:a,startCollapsed:o}){let{startDrag:s,ghost:c}=dBe(),[l,u]=(0,h.useState)(()=>o??PBe()),d=e=>{if(o===void 0)try{localStorage.setItem(NBe,String(e))}catch{}},f=(0,h.useCallback)(()=>{u(e=>(d(!e),!e))},[]),[p,m]=(0,h.useState)(IBe),g=i??(r?.some(e=>e.id===p)?p:IBe),_=e=>{m(e),a?.(e),l&&(u(!1),d(!1))},v=(0,h.useRef)(i);(0,h.useEffect)(()=>{i!==v.current&&(v.current=i,!(i===void 0||!l)&&(u(!1),d(!1)))},[i]);let y=JB.flatMap(t=>t.definitions.filter(t=>!QL(t.type,e))),b=(e,n=!0)=>{let{label:r,summary:i,firstLevel:a}=e,o=BL(e),{icon:c,className:l}=BB[o]??BB[e.type];return(0,D.jsx)(FBe,{icon:c,iconClassName:l,label:n?r:`${r}: shown from Level ${a}`,description:n?i:`Shown from Level ${a}`,usable:n,onDragStart:s(qB,o,MBe.get(o)),onClick:()=>t(o),title:n?`${r}: drag onto the canvas, or click to add`:void 0},o)},x=(0,D.jsxs)(D.Fragment,{children:[JB.map(t=>{let n=t.definitions.filter(t=>QL(t.type,e));return n.length?(0,D.jsx)(XB,{title:t.label,children:n.map(e=>b(e))},t.id):null}),y.length>0&&(0,D.jsx)(XB,{title:`Not on Level ${e}`,divided:!0,children:y.map(e=>b(e,!1))})]}),S=r?.find(e=>e.id===g),C=(e,t,n)=>(0,D.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":g===e,onClick:()=>_(e),className:`flex flex-1 items-center justify-center gap-1 whitespace-nowrap rounded-md px-1.5 py-1 text-xs font-medium ${g===e&&!l?`bg-[rgb(var(--ec-card-bg))] text-[rgb(var(--ec-page-text))] shadow-sm`:`text-[rgb(var(--ec-page-text-muted))] hover:text-[rgb(var(--ec-page-text))]`}`,children:[t,!!n&&(0,D.jsx)(`span`,{className:`rounded-full bg-[rgb(var(--ec-accent))] px-1.5 text-[10px] leading-4 text-white`,children:n})]},e);return(0,D.jsxs)(`div`,{className:`absolute left-3 top-[62px] z-10 flex w-[264px] flex-col ${l?``:`bottom-[68px]`} rounded-xl border border-[rgb(var(--ec-page-border))] bg-[rgb(var(--ec-card-bg))] text-[rgb(var(--ec-page-text))] shadow-[0_8px_24px_rgb(0_0_0/0.08),0_1px_3px_rgb(0_0_0/0.05)]`,children:[r?.length?(0,D.jsxs)(`div`,{className:`flex flex-none items-center gap-1 p-2`,children:[(0,D.jsxs)(`div`,{role:`tablist`,className:`flex flex-1 gap-0.5 rounded-lg bg-[rgb(var(--ec-page-border)/0.5)] p-0.5`,children:[C(IBe,`Components`),r.map(({id:e,label:t,badge:n})=>C(e,t,n))]}),(0,D.jsx)(`button`,{type:`button`,onClick:f,"aria-expanded":!l,"aria-label":l?`Show the palette`:`Fold the palette away`,className:`flex-none rounded-md p-1 text-[rgb(var(--ec-page-text-muted))] hover:bg-[rgb(var(--ec-page-border)/0.5)]`,children:(0,D.jsx)(Vf,{"aria-hidden":!0,className:`h-4 w-4 transition-transform ${l?`-rotate-90`:``}`})})]}):(0,D.jsxs)(`button`,{type:`button`,onClick:f,"aria-expanded":!l,className:`flex flex-none items-center justify-between rounded-xl px-3.5 py-2.5 text-left text-[13px] font-semibold hover:bg-[rgb(var(--ec-content-hover))]!`,children:[(0,D.jsx)(`span`,{children:`Resources`}),(0,D.jsx)(Vf,{"aria-hidden":!0,className:`h-4 w-4 text-[rgb(var(--ec-page-text-muted))] transition-transform ${l?`-rotate-90`:``}`})]}),!l&&(0,D.jsx)(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto px-3 pb-3`,children:S?S.render(s):x}),!l&&n&&(0,D.jsx)(`div`,{className:`flex-none border-t border-[rgb(var(--ec-page-border))] px-3 py-2.5`,children:n}),c]})}),ZB=typeof navigator<`u`&&/Mac|iPhone|iPad/.test(navigator.platform)?`⌘`:`Ctrl`,RBe=[{group:`Tools`,items:[[`Select`,[`V`]],[`Hand (move around)`,[`H`]],[`Sticky note`,[`N`]],[`Text`,[`T`]],[`Comment`,[`C`]],[`Hotspot`,[`A`]],[`Level 1 / 2 / 3`,[`1`,`2`,`3`]],[`Back to selecting`,[`Esc`]]]},{group:`Canvas`,items:[[`Select everything`,[ZB,`A`]],[`Select several`,[`⇧`,`Click`]],[`Delete what's selected`,[`Delete`]],[`Duplicate`,[ZB,`D`]],[`Copy / paste`,[ZB,`C / V`]],[`Undo / redo`,[ZB,`Z / ⇧Z`]],[`Move around`,[`Scroll`]],[`Zoom`,[ZB,`Scroll`]],[`Fit view`,[`⇧`,`1`]]]},{group:`Notes and text`,items:[[`Write on one`,[`Double-click`]],[`Finish writing`,[`Esc`]]]},{group:`Diagram`,items:[[`Command palette`,[ZB,`K`]],[`Find on canvas`,[ZB,`F`]],[`Open a diagram file`,[ZB,`O`]],[`Save to file`,[ZB,`S`]],[`Export image`,[ZB,`⇧`,`E`]],[`Help`,[`?`]]]}];function zBe({omit:e=[]}){return(0,D.jsx)(`div`,{className:`grid min-h-0 gap-x-8 gap-y-5 overflow-y-auto px-5 py-4 md:grid-cols-2!`,children:RBe.map(({group:t,items:n})=>({group:t,items:n.filter(([t])=>!e.includes(t))})).map(({group:e,items:t})=>(0,D.jsxs)(`section`,{children:[(0,D.jsx)(`h3`,{className:`mb-2 text-[11px] font-semibold uppercase tracking-wide text-[rgb(var(--ec-page-text-muted))]`,children:e}),(0,D.jsx)(`ul`,{className:`divide-y divide-[rgb(var(--ec-page-border))]`,children:t.map(([e,t])=>(0,D.jsxs)(`li`,{className:`flex items-center justify-between gap-3 py-1.5 text-sm`,children:[(0,D.jsx)(`span`,{children:e}),(0,D.jsx)(`span`,{className:`flex gap-1`,children:t.map(e=>(0,D.jsx)(`kbd`,{className:`min-w-6 rounded-md border border-[rgb(var(--ec-page-border))] bg-[rgb(var(--ec-content-hover))] px-1.5 py-0.5 text-center font-sans text-xs text-[rgb(var(--ec-page-text-muted))]`,children:e},e))})]},e))})]},e))})}var BBe=`font-[Excalifont,Inter,sans-serif] text-[14px] leading-snug text-[color-mix(in_srgb,rgb(var(--ec-page-text))_22%,transparent)]`,QB={fill:`none`,stroke:`currentColor`,strokeWidth:1.6,strokeLinecap:`round`,strokeLinejoin:`round`};function VBe({palette:e,live:t}){return(0,D.jsxs)(`div`,{"aria-hidden":!0,className:`hidden md:block! ${BBe}`,children:[e&&(0,D.jsxs)(`div`,{className:`absolute bottom-[120px] left-[290px] flex items-start gap-1`,children:[(0,D.jsxs)(`svg`,{width:`56`,height:`32`,viewBox:`0 0 70 40`,...QB,children:[(0,D.jsx)(`path`,{d:`M66 8 C 45 4, 22 10, 6 26`}),(0,D.jsx)(`path`,{d:`M6 26 L15.7 23.4 M6 26 L8.6 16.3`})]}),(0,D.jsx)(`p`,{className:`-mt-0.5 max-w-[160px]`,children:`Drag resources onto the canvas, then connect them`})]}),(0,D.jsxs)(`div`,{className:`absolute left-[calc(50%+6px)] top-[66px] flex -translate-x-1/2 flex-col items-center`,children:[(0,D.jsxs)(`svg`,{width:`32`,height:`45`,viewBox:`0 0 40 56`,...QB,children:[(0,D.jsx)(`path`,{d:`M14 54 C 6 38, 10 18, 20 4`}),(0,D.jsx)(`path`,{d:`M20 4 L11.8 7.7 M20 4 L19.1 13`})]}),(0,D.jsx)(`p`,{className:`mt-1 whitespace-nowrap`,children:`Switch between levels of detail`})]}),t&&(0,D.jsxs)(`div`,{className:`absolute right-[52px] top-[66px] flex items-end gap-1`,children:[(0,D.jsx)(`p`,{className:`mb-[-5px] max-w-[200px] text-right`,children:`Start live collaboration with your team or agents`}),(0,D.jsxs)(`svg`,{width:`40`,height:`48`,viewBox:`0 0 50 60`,className:`flex-none`,...QB,children:[(0,D.jsx)(`path`,{d:`M6 56 C 30 52, 42 30, 40 4`}),(0,D.jsx)(`path`,{d:`M40 4 L36.1 12.1 M40 4 L45.1 11.4`})]})]})]})}var HBe=typeof navigator<`u`&&/Mac|iPhone|iPad/.test(navigator.platform)?`Cmd`:`Ctrl`;function $B({welcome:e=!0,onOpen:t,onHelp:n,onConnect:r,palette:i,live:a}){let[o,s]=(0,h.useState)(!1),[c,l]=(0,h.useState)(!1);if((0,h.useEffect)(()=>{let e=()=>s(!0),t=()=>s(!1),n=()=>{l(!0),s(!1)};return document.addEventListener(`dragstart`,e),document.addEventListener(`dragend`,t),document.addEventListener(`drop`,n),()=>{document.removeEventListener(`dragstart`,e),document.removeEventListener(`dragend`,t),document.removeEventListener(`drop`,n)}},[]),o||c)return null;let u=(e,t,n,r)=>(0,D.jsxs)(`button`,{type:`button`,onClick:n,className:`group flex h-11 w-full items-center gap-3.5 rounded-lg px-3 text-left text-[15px] text-[rgb(var(--ec-page-text-muted))] transition-colors hover:bg-[rgb(var(--ec-content-hover))]! hover:text-[rgb(var(--ec-page-text))]! [&_svg]:h-[18px] [&_svg]:w-[18px] [&_svg]:stroke-[1.75]`,children:[(0,D.jsx)(`span`,{className:`flex flex-none`,children:e}),(0,D.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:t}),r&&(0,D.jsx)(`span`,{className:`flex-none text-[13px] opacity-80`,children:r})]});return(0,D.jsxs)(`div`,{className:`pointer-events-none absolute inset-0 z-[5] flex items-center justify-center px-4 pb-16 pt-40`,children:[(0,D.jsx)(VBe,{palette:i,live:a}),e&&(0,D.jsxs)(`div`,{className:`pointer-events-auto flex w-full max-w-[440px] flex-col items-center`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-3 text-[rgb(var(--ec-page-text))]`,children:[(0,D.jsx)(`span`,{className:`h-11 w-11 [&_svg]:h-full [&_svg]:w-full`,dangerouslySetInnerHTML:{__html:qz}}),(0,D.jsxs)(`span`,{className:`text-[34px] font-bold tracking-tight`,children:[`EventCatalog`,` `,(0,D.jsx)(`span`,{className:`font-light text-[rgb(var(--ec-page-text-muted))]`,children:`Studio`})]})]}),(0,D.jsx)(`p`,{className:`mt-5 text-center font-[Excalifont,Inter,sans-serif] text-[22px] leading-snug text-[color-mix(in_srgb,rgb(var(--ec-page-text))_38%,transparent)]`,children:`Sketch, design and share architecture with your team and AI agents.`}),(0,D.jsxs)(`div`,{className:`mt-10 w-full`,children:[t&&u((0,D.jsx)(Yf,{"aria-hidden":!0}),`Open`,t,`${HBe}+O`),r&&u((0,D.jsx)(bp,{"aria-hidden":!0}),`Connect to MCP Server`,r),u((0,D.jsx)(kf,{"aria-hidden":!0}),`Help`,n,`?`)]})]})]})}var eV=300,tV=12,nV=8,UBe=32;function WBe(e,t,n,r=nV){let[i,a]=(0,h.useState)(null);return(0,h.useEffect)(()=>{let i=0,o=()=>{let s=t.current,c=s?.querySelector(`.react-flow__node[data-id="${CSS.escape(e)}"]`);if(s&&c){let e=s.getBoundingClientRect(),t=c.getBoundingClientRect(),i=n.current?.offsetHeight??200,o=n.current?.offsetWidth||eV,l=t.right+tV+o<=e.right-nV?`right`:`left`,u=l===`right`?t.right-e.left+tV:t.left-e.left-tV-o,d=(e,t)=>Math.min(Math.max(e,nV),Math.max(t,nV)),f=d(Math.min(t.top,t.top+t.height/2-UBe)-e.top,e.height-i-r),p=d(u,e.width-o-nV),m=t.top+t.height/2-e.top-f,h={side:l,left:p,top:f,pointsAt:p===u&&m>=14&&m<=i-14?Math.round(m):void 0};a(e=>e?.left===h.left&&e?.top===h.top&&e?.side===h.side&&e?.pointsAt===h.pointsAt?e:h)}i=requestAnimationFrame(o)};return o(),()=>cancelAnimationFrame(i)},[e,t,n,r]),i}function GBe(){let[e,t]=(0,h.useState)(!1),n=(0,h.useRef)(void 0),r=(0,h.useCallback)(()=>{t(!0),clearTimeout(n.current),n.current=setTimeout(()=>t(!1),1600)},[]);return(0,h.useEffect)(()=>()=>clearTimeout(n.current),[]),{saved:e,showSaved:r}}function KBe({saved:e}){return(0,D.jsx)(`p`,{className:`ec-edit-status ${e?`is-saved`:``}`,"aria-live":`polite`,children:e?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(Bf,{"aria-hidden":!0}),` Saved`]}):`Changes save as you type`})}function rV({nodeId:e,containerRef:t,label:n,kicker:r,header:i,children:a,width:o=340,bottomInset:s=76,onClose:c}){let l=(0,h.useRef)(null),u=WBe(e,t,l,s),d=(0,h.useRef)(c);d.current=c,(0,h.useEffect)(()=>{let e=()=>{let e=document.activeElement;e instanceof HTMLElement&&l.current?.contains(e)&&e.blur(),d.current()},t=t=>{l.current?.contains(t.target)||e()},n=t=>t.key===`Escape`&&e();return document.addEventListener(`pointerdown`,t,!0),document.addEventListener(`keydown`,n),()=>{document.removeEventListener(`pointerdown`,t,!0),document.removeEventListener(`keydown`,n)}},[]);let f=!!u,p=(0,h.useRef)(!1);return(0,h.useEffect)(()=>{if(!f||p.current)return;p.current=!0;let e=l.current?.querySelector(`input:not([readonly]):not([disabled]), textarea:not([readonly]):not([disabled])`);if(e){e.focus({preventScroll:!0});try{e.setSelectionRange(e.value.length,e.value.length)}catch{}}},[f]),(0,D.jsxs)(D.Fragment,{children:[u?.pointsAt!==void 0&&(0,D.jsx)(`span`,{"aria-hidden":!0,className:`ec-doc-card-arrow is-${u.side}`,style:{top:u.top+u.pointsAt-7,left:u.side===`right`?u.left-6:u.left+o-8}}),(0,D.jsxs)(`div`,{ref:l,className:`ec-doc-card`,role:`dialog`,"aria-label":n,style:{width:o,top:u?.top??8,left:u?.left??8,visibility:u?`visible`:`hidden`},children:[(0,D.jsxs)(`header`,{className:`ec-doc-card-header`,children:[(0,D.jsxs)(`div`,{className:`ec-doc-card-kicker`,children:[r,(0,D.jsx)(`button`,{type:`button`,className:`ec-icon-button ec-doc-card-close`,"aria-label":`Close`,onClick:c,children:(0,D.jsx)(zp,{"aria-hidden":!0})})]}),i]}),a]})]})}var iV=250;function qBe({value:e,onSave:t,multiline:n=!1,placeholder:r,className:i=``,label:a,required:o=!1,onSaved:s}){let[c,l]=(0,h.useState)(e),u=(0,h.useRef)(!1),d=(0,h.useRef)(e),f=(0,h.useRef)(null),p=(0,h.useRef)(void 0),m=(0,h.useRef)({value:e,onSave:t,onSaved:s,required:o});m.current={value:e,onSave:t,onSaved:s,required:o},(0,h.useEffect)(()=>{u.current||l(e)},[e]);let g=()=>{clearTimeout(p.current);let e=f.current;if(f.current=null,e===null)return;let{value:t,onSave:n,onSaved:r,required:i}=m.current;i&&!e.trim()||e===t||(n(e),r?.())};(0,h.useEffect)(()=>g,[]);let _=e=>{l(e),f.current=e,clearTimeout(p.current),p.current=setTimeout(g,iV)},v=(0,h.useRef)(!1),y=()=>{if(u.current=!1,v.current){v.current=!1;return}let e=c.trim();o&&!e?(l(d.current),f.current=d.current):(e!==c&&l(e),f.current=e),g()},b=e=>{e.key===`Escape`?(e.stopPropagation(),l(d.current),f.current=d.current,g(),v.current=!0,e.target.blur()):e.key===`Enter`&&(!n||e.metaKey||e.ctrlKey)&&(e.preventDefault(),e.target.blur())},x=()=>{u.current=!0,d.current=e},S=e=>{e&&(e.style.height=`auto`,e.style.height=`${e.scrollHeight+2}px`)};return n?(0,D.jsx)(`textarea`,{ref:S,"aria-label":a,value:c,rows:2,placeholder:r,onChange:e=>{_(e.target.value),S(e.target)},onFocus:x,onBlur:y,onKeyDown:b,className:`ec-editable ${i}`}):(0,D.jsx)(`input`,{"aria-label":a,value:c,placeholder:r,onChange:e=>_(e.target.value),onFocus:x,onBlur:y,onKeyDown:b,className:`ec-editable ${i}`})}function JBe({label:e,children:t,className:n=``}){return(0,D.jsxs)(`label`,{className:`ec-field ${n}`,children:[(0,D.jsx)(`span`,{className:`ec-field-label`,children:e}),t]})}var aV=e=>({...e.node.data,catalog:{key:e.key,url:e.url,version:e.version}}),oV=e=>e.data?.catalog,YBe=e=>{let t=new Map;for(let n of e)for(let e of[n.source,n.target])t.set(e,[...t.get(e)??[],n]);return t},sV=(e,t,n,r,i=e.node.type)=>{let a=[];for(let o of r.get(e.key)??[]){let r=o.source===e.key,s=r?o.target:o.source;for(let e of n.filter(e=>oV(e)?.key===s)){if(o.label===`contains`&&(RL(i)||RL(e.type)))continue;let[n,s]=r?[{id:t,type:i},e]:[e,{id:t,type:i}],c=IL({source:n.id,target:s.id,sourceHandle:null,targetHandle:null},n.type,s.type);a.push(o.label?{...c,label:o.label}:c)}}return a},cV=e=>e.collection===`domains`||e.collection===`systems`,lV=e=>e.collection===`domains`?LL.domain:LL.system,XBe=e=>{let t=e.collection===`domains`?`domain`:`system`,{scope:n}=e.node.data[t]??{};return{[t]:{id:e.id,name:e.name,version:e.version,summary:e.summary,...n&&{scope:n}},catalog:{key:e.key,url:e.url,version:e.version}}},uV=(e,t)=>(t.relationsByKey.get(e.key)??[]).filter(t=>t.source===e.key&&t.label===`contains`).map(e=>t.resourcesByKey.get(e.target)).filter(e=>!!e),dV=(e,t)=>wR(lV(e),XBe(e),t),ZBe=async(e,t,n,r)=>{let i=new Set(r.map(e=>oV(e)?.key).filter(Boolean)),a=dV(e,{x:0,y:0}),o=[a],s=e=>i.has(e)||o.some(t=>oV(t)?.key===e),c=[],l=(e,t)=>{for(let r of uV(e,n))if(!s(r.key))if(cV(r)){let e={...dV(r,{x:0,y:0}),parentId:t};o.push(e),l(r,e.id)}else o.push({...wR(r.node.type,aV(r),{x:0,y:0}),parentId:t}),r.collection===`services`&&c.push({resource:r,parentId:t})};l(e,a.id);for(let e of c)for(let t of n.relationsByKey.get(e.resource.key)??[]){if(t.label===`contains`)continue;let r=n.resourcesByKey.get(t.source===e.resource.key?t.target:t.source);if(!r||s(r.key)||cV(r)||r.collection===`services`)continue;let i=r.collection===`containers`?e.parentId:a.id;o.push({...wR(r.node.type,aV(r),{x:0,y:0}),parentId:i})}if(o.length===1)return{nodes:[dV(e,t)],edges:[]};let u=[],d=[],f=[...r];for(let e of o){let t=oV(e),i=t&&n.resourcesByKey.get(t.key);if(i)for(let t of sV(i,e.id,f,n.relationsByKey,e.type))(r.some(e=>e.id===t.source||e.id===t.target)?d:u).push(t);f.push(e)}let p=rz((await nz(o,u)).nodes),m=p.find(e=>e.id===a.id),h={x:t.x-(m.width??0)/2-m.position.x,y:t.y-(m.height??0)/2-m.position.y};return{nodes:p.map(e=>({...o.find(t=>t.id===e.id),position:e.parentId?e.position:{x:e.position.x+h.x,y:e.position.y+h.y},...RL(e.type)&&{width:e.width,height:e.height}})),edges:[...u,...d]}},QBe=GM(U({ref:H().optional().describe(`Your name for this node, to use in edges`),resource:U({collection:$M(rRe),id:H()}).optional().describe(`A catalog resource to add (latest version)`),type:$M(aRe).optional().describe(`For a new component: what it is`),name:H().optional().describe(`For a new component: its name`),summary:H().optional().describe(`For a new component: what it does. For a note or text: its text`),version:H().optional().describe(`For a new component: its version, e.g. 1.0.0 (defaults to 0.0.1)`),container:RM().optional().describe(`For a domain or system from the catalog: add it as a container that other nodes sit inside, rather than a card`),inside:H().optional().describe(`A ref (or node id) of a container (a domain or system added as one) to put this node inside`),x:LM().optional(),y:LM().optional(),width:LM().positive().optional().describe(`For a container: its width to start with (it grows to fit what is put in it)`),height:LM().positive().optional().describe(`For a container: its height to start with (it grows to fit what is put in it)`)})).min(1),$Be=GM(U({from:H().describe(`A ref from nodes, or the id of a node already on the canvas`),to:H().describe(`A ref from nodes, or the id of a node already on the canvas`),label:H().optional().describe(`Defaults to EventCatalog wording, e.g. "publishes event"`)})),eVe=U({x:LM(),y:LM()}),tVe=U({points:GM(eVe).min(2).max(200),label:eVe.optional()});$Be.element.extend({route:tVe.optional()});var nVe=1e3,rVe=U({nodes:GM(U({ref:H().describe(`The ref of the node it is on the canvas (or its own id, if it's only on this level)`),type:H(),data:QM(H(),HM()),parent:H().optional().describe(`The ref of the node it is shown in on this level`),x:LM().describe(`Its top-left corner (relative to its parent)`),y:LM(),width:LM().positive().optional().describe(`For a container: its size`),height:LM().positive().optional()})).max(nVe),edges:GM(U({from:H(),to:H(),label:H().optional(),type:H().optional(),style:QM(H(),HM()).optional(),markerEnd:HM().optional(),data:QM(H(),HM()).optional().describe(`The edge's data, e.g. its route`)})).max(nVe*2)}),iVe=H().max(300).optional();U({1:rVe.optional(),2:rVe.optional(),unavailable:U({1:iVe,2:iVe}).optional().describe(`Levels the diagram doesn't have, and why`)});var aVe=[`Adds nodes (and connections between them) to the canvas, live for everyone on it.`,`A node is either a catalog resource (resource: { collection, id }), shown with its real name and summary and automatically connected to the related resources already on the canvas (e.g. a service to the events it publishes), or a new component (type, name, summary) for things that are not in the catalog yet, like a proposed service.`,`Give each node a ref to connect new nodes to each other in edges.`,`Domains and systems can be containers (container: true for catalog ones, or type domain-group / system-group for new ones): put services, messages and data stores inside one with inside (its ref or node id), e.g. a domain container with its system containers inside, and their services inside those.`,`Leave out x/y and each node is placed like an architect would: next to what it connects to (in edges, or as a related catalog resource), following the flow left to right (producers on the left of their messages, consumers on the right), lined up with it, and stacked when several connect to the same node. Nothing already on the canvas moves, and nodes connected to nothing go below what is there.`,`Give x/y (a node's centre, like the positions from reading the canvas) only to put a node somewhere specific. Nodes are about 240 wide and 110 tall: leave about 200 between connected nodes for the labels on their connections.`].join(` `),oVe=(e,t)=>({resourcesByKey:new Map(e.map(e=>[e.key,e])),relationsByKey:YBe(t)}),fV=(e,t)=>t??new Map([[e.id,e]]),sVe=(e,t)=>{let n=qL(e.type,e.data),r=oV(e),i=r?.version??(typeof n.version==`string`?n.version:void 0);return{id:e.id,type:UL(e.type),...!eR(e.type)&&{name:n.name},...n.summary?{summary:n.summary}:{},...eR(e.type)?{text:e.data.text}:{},...XL(e)!==void 0&&XL(e)!==3&&{onLevel:`L${XL(e)}`},...r&&{catalogResource:r.key.replace(`:`,`/`)},...i&&{version:i},position:(({x:e,y:t})=>({x:Math.round(e),y:Math.round(t)}))(cVe(e,t)),size:aR(e),...RL(e.type)&&{container:!0},...e.parentId&&{inside:e.parentId}}},cVe=(e,t)=>{let{width:n,height:r}=aR(e),i=oR(e,fV(e,t));return{x:i.x+n/2,y:i.y+r/2}},lVe=(e,t,n)=>{let{width:r,height:i}=aR(e),a=e.parentId?n?.get(e.parentId):void 0,o=a?oR(a,fV(a,n)):{x:0,y:0};return{x:t.x-r/2-o.x,y:t.y-i/2-o.y}},uVe=e=>{let t=RRe(e),n=new Map(t.nodes.map(e=>[e.id,e])),r=new Map(t.nodes.map(e=>[e.id,nR(e.type,e.data,e.id)])),i=t.meta.statusHistory?.at(-1);return{title:t.meta.title,status:DR(t.meta),...i&&{statusChanged:{by:i.by.name,at:new Date(i.at).toISOString(),...i.note&&{note:i.note}}},nodes:t.nodes.map(e=>sVe(e,n)),connections:t.edges.map(e=>({id:e.id,from:e.source,to:e.target,description:`${r.get(e.source)} ${String(e.label||`→`).replace(/\s+/g,` `)} ${r.get(e.target)}`})),comments:t.threads.map(e=>({threadId:e.id,...e.nodeId?{onNode:e.nodeId}:{position:e.position},resolved:e.resolved,messages:e.messages.map(e=>({from:e.author.name,text:e.text}))}))}},dVe=(e,t,n,r=[])=>{let i=new Map(e.map(e=>[e.id,e])),a=new Map,o=[],s=[],c=[],l=e=>e.x!==void 0&&e.y!==void 0,u=e=>l(e)?{x:e.x,y:e.y}:{x:0,y:0},d=(e,t)=>{if(!RL(e.type)||!t.width||!t.height)return e;let n=u(t),{width:r,height:i}=t;return{...e,width:r,height:i,position:{x:n.x-r/2,y:n.y-i/2}}},f=(e,t,n)=>{if(!l(n))return{...e,parentId:t.id};let{width:r,height:a}=aR(e),o=oR(t,i);return{...e,parentId:t.id,position:{x:n.x-r/2-o.x,y:n.y-a/2-o.y}}};for(let e of t){let t;if(e.resource){let r=n.resourcesByKey.get(`${e.resource.collection}:${e.resource.id}`);if(!r){c.push(`No ${e.resource.collection} resource "${e.resource.id}" in the catalog`);continue}t={node:e.container&&cV(r)?d(dV(r,u(e)),e):wR(r.node.type,aV(r),u(e)),name:r.name,resource:r}}else{let n=HL(e.type);if(!n){c.push(`Give each node a resource, or a type (one of ${aRe.join(`, `)})`);continue}let r=eR(n.type)?{...n.createData(),text:e.summary??e.name??``}:tR(n.type,n.createData(),{...e.name&&{name:e.name},...e.summary&&{summary:e.summary},...e.version&&$L(n.type)&&{version:e.version}}),i=d(wR(n.type,r,u(e)),e);t={node:i,name:String(qL(i.type,i.data).name??n.label)}}if(e.inside&&!JL(t.node.type))c.push(`Notes aren't put in containers: "${e.ref??t.name}" was put on the canvas instead`);else if(e.inside){let n=a.get(e.inside)??i.get(e.inside);n&&RL(n.type)?t.node=f(t.node,n,e):c.push(`"${e.inside}" is not a container on the canvas (a domain or system added as a container)`)}l(e)||s.push(t.node.id),i.set(t.node.id,t.node),e.ref&&a.set(e.ref,t.node),o.push({ref:e.ref,...t,canvasPosition:oR(t.node,i)})}let p=new Map,m=(e,t)=>p.set(`${e}>${t}`,{source:e,target:t}),h=e=>a.get(e)?.id??e;r.forEach(e=>m(h(e.from),h(e.to)));let g=new Map;for(let e of i.values()){let t=oV(e)?.key;t&&g.set(t,[...g.get(t)??[],e])}for(let{node:e,resource:t}of o)for(let r of t?n.relationsByKey.get(t.key)??[]:[]){let n=r.source===t?.key;for(let t of g.get(n?r.target:r.source)??[])r.label===`contains`&&(RL(e.type)||RL(t.type))||(n?m(e.id,t.id):m(t.id,e.id))}let _=lz([...i.values()].filter(e=>ZL(e,3)),s,[...p.values()]),v=new Map(o.map(e=>[e.node.id,_.get(e.node.id)??e.canvasPosition]));for(let e of o){let t=_.get(e.node.id);if(!t)continue;let{parentId:n}=e.node,r=n?i.get(n):void 0,a=n?v.get(n)??(r?oR(r,i):{x:0,y:0}):{x:0,y:0};e.canvasPosition=t,e.node={...e.node,position:{x:t.x-a.x,y:t.y-a.y}}}return{planned:o,errors:c}},fVe=e=>new Map(e.flatMap(e=>e.ref?[[e.ref,e.node.id]]:[])),pVe=(e,t)=>{let n=fVe(t);return e.map(e=>({...e,from:n.get(e.from)??e.from,to:n.get(e.to)??e.to}))},mVe=(e,{nodeId:t,name:n,summary:r,version:i})=>e.transact(()=>{let a=SR(e).nodes.get(t);return a?(oV(a)||PR(e,t,e=>eR(a.type)?{...e,text:r??n??e.text}:tR(a.type,e,{...n!==void 0&&{name:n},...r!==void 0&&{summary:r},...i!==void 0&&$L(a.type)&&{version:i}})),{updated:t}):{error:`No node "${t}" on the canvas`}}),hVe=new Set([`events`,`commands`,`queries`]),gVe={receives:`Messages it receives`,sends:`Messages it sends`,dataStores:`Data stores it reads or writes`,senders:`Services that send it`,receivers:`Services that receive it`},_Ve=(e,t,n)=>{if(e.collection===`services`){if(t.collection===`containers`)return`dataStores`;if(hVe.has(t.collection))return n?`sends`:`receives`}if(hVe.has(e.collection)&&t.collection===`services`)return n?`receivers`:`senders`},vVe=(e,t,n)=>{let r=new Map,i=new Set;for(let a of t.relationsByKey.get(e.key)??[]){let o=a.source===e.key,s=t.resourcesByKey.get(o?a.target:a.source);if(!s||i.has(s.key)||n.has(s.key))continue;let c=_Ve(e,s,o);c&&(r.set(c,[...r.get(c)??[],s]),i.add(s.key))}return[`receives`,`senders`,`sends`,`receivers`,`dataStores`].flatMap(e=>{let t=r.get(e);return t?[{id:e,label:gVe[e],resources:t}]:[]})},yVe=(e,t,n,r,i,a)=>{let o=pR(n,e,a),s=e=>({resource:{collection:e.collection,id:e.id}}),{planned:c}=dVe(e,[{...s(t),x:n.x,y:n.y,...o&&{inside:o.id}},...r.map(e=>({...s(e),...o&&e.collection===`containers`&&{inside:o.id}}))],i),l=[...e],u=[];for(let{node:e,resource:t}of c)t&&u.push(...sV(t,e.id,l,i.relationsByKey,e.type)),l.push(e);return{nodes:c.map(e=>e.node),edges:u}},bVe=`Failed to parse input arguments`,xVe=`Tool was executed but the invocation failed. For example, the script function threw an error`,SVe=/^[A-Za-z0-9_.-]{1,128}$/u;function pV(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function CVe(e){if(typeof e==`symbol`)throw TypeError(`Symbol values cannot be converted to a DOMString`);return String(e)}function mV(e){let t=Reflect.get(e,`name`),n=Reflect.get(e,`description`),r=Reflect.get(e,`title`);if(t===void 0)throw TypeError(`Tool "name" is required`);if(n===void 0)throw TypeError(`Tool "description" is required`);let i=Reflect.get(e,`annotations`),a=pV(i)?i:{},o=Reflect.get(e,`inputSchema`),s=Reflect.get(e,`outputSchema`),c=Reflect.get(e,`execute`);return{name:CVe(t),...r===void 0?{}:{title:CVe(r).toWellFormed()},description:CVe(n),...o===void 0?{}:{inputSchema:o},...s===void 0?{}:{outputSchema:s},execute:c,...i===void 0?{}:{annotations:{...a.title===void 0?{}:{title:CVe(a.title).toWellFormed()},readOnlyHint:!!a.readOnlyHint,...a.destructiveHint===void 0?{}:{destructiveHint:!!a.destructiveHint},...a.idempotentHint===void 0?{}:{idempotentHint:!!a.idempotentHint},...a.openWorldHint===void 0?{}:{openWorldHint:!!a.openWorldHint},untrustedContentHint:!!a.untrustedContentHint}}}}function hV(e){return new DOMException(e,`UnknownError`)}function wVe(e){return hV(e instanceof Error?`${xVe}: ${e.message}`:xVe)}function gV(e){return new DOMException(e,`InvalidStateError`)}function TVe(e){if(e.name===``)throw gV(`Tool "name" must be a non-empty string`);if(typeof e.name!=`string`||!SVe.test(e.name))throw gV(`Tool "name" must be 1–128 characters and contain only ASCII alphanumeric, underscore, hyphen, or period`);if(typeof e.description!=`string`||e.description.length===0)throw gV(`Tool "description" must be a non-empty string`);if(typeof e.execute!=`function`)throw TypeError(`Tool "execute" must be a function`)}function _V(e){return{readOnlyHint:e.readOnlyHint??!1,untrustedContentHint:e.untrustedContentHint??!1}}function EVe(e){try{let t=JSON.parse(e);if(Array.isArray(t)||pV(t))return t}catch{}throw hV(bVe)}function DVe(e){if(typeof e==`object`&&e||typeof e==`function`)try{let t=JSON.stringify(e);if(t)return t}catch{}return String(e)||`Operation succeeded`}function OVe(e,t,n=()=>t?.reason){return t?t.aborted?Promise.reject(n()):new Promise((r,i)=>{let a=()=>{o(),i(n())},o=()=>t.removeEventListener(`abort`,a);t.addEventListener(`abort`,a,{once:!0}),e.then(e=>{o(),r(e)},e=>{o(),i(e)})}):e}function vV(e){let t=e.origin===`null`?e:new URL(e.origin),n=t.protocol;if([`https:`,`wss:`,`file:`,`chrome-extension:`,`moz-extension:`].includes(n))return!0;let r=t.hostname.toLowerCase(),i=r.split(`.`),a=i.length===4&&i.every(e=>/^\d{1,3}$/u.test(e)&&Number(e)<=255)&&Number(i[0])===127;return r===`::1`||r===`[::1]`||r===`localhost`||r===`localhost.`||r.endsWith(`.localhost`)||r.endsWith(`.localhost.`)||a}function kVe(e){for(let t of e??[]){let e;try{e=new URL(t)}catch{throw new DOMException(`Invalid or untrustworthy origin: ${String(t)}`,`SecurityError`)}if(!vV(e))throw new DOMException(`Invalid or untrustworthy origin: ${t}`,`SecurityError`)}}function yV(e){if(AVe(),!e)return;let t=e.defaultView?.DOMException??DOMException,n=!1;try{let t=e.defaultView;n=!!(t&&t.document===e)}catch{}if(!n)throw new t(`The associated document is not fully active`,`InvalidStateError`);let r=Reflect.get(e,`permissionsPolicy`)??Reflect.get(e,`featurePolicy`);if(r&&typeof r==`object`){let e=Reflect.get(r,`features`),n=Reflect.get(r,`allowsFeature`);if(typeof e==`function`&&typeof n==`function`){let i=Reflect.apply(e,r,[]);if(Array.isArray(i)&&i.includes(`tools`)){if(Reflect.apply(n,r,[`tools`])===!0)return;throw new t(`WebMCP is disabled by Permissions Policy`,`NotAllowedError`)}}}let i=e.defaultView;if(!(!i||i.parent===i)){try{i.parent.document;return}catch{}throw new t(`WebMCP in cross-origin frames requires native Permissions Policy support`,`NotAllowedError`)}}function AVe(){if(globalThis.originAgentCluster===!1&&globalThis.location?.protocol!==`file:`)throw new DOMException(``,`SecurityError`)}function bV(e){try{if(new URL(String(e)).origin!==`null`)return}catch{}throw new DOMException(`Unsupported tool origin: ${String(e)}`,`NotSupportedError`)}function jVe(e){if(e===null||typeof e!=`object`&&typeof e!=`function`)throw TypeError(`inputSchema must be an object`);let t=JSON.stringify(e);if(t===void 0)throw TypeError(`inputSchema must be JSON-serializable`);return t}var xV=new WeakSet,SV=new WeakMap,CV=new WeakMap;function wV(e){return e.isTrusted&&(xV.has(e)||e.eventPhase!==Event.NONE&&e.target instanceof HTMLFormElement&&CV.has(e.target))}function TV(e,t){if(!wV(e))throw new DOMException(`respondWith() is only available during an agent-invoked submit event`,`InvalidStateError`);if(!e.defaultPrevented)throw new DOMException(`respondWith() requires preventDefault() during an agent-invoked submit event`,`InvalidStateError`);if(e.eventPhase===Event.NONE)throw new DOMException(`respondWith() is only available while the submit event is being dispatched`,`InvalidStateError`);xV.add(e);let n=Promise.resolve(t);SV.set(e,n),e.target instanceof HTMLFormElement&&CV.get(e.target)?.respond(e)}var MVe=new Set([`email`,`password`,`search`,`tel`,`text`,`url`]),EV=new Set([...MVe,`date`,`datetime-local`,`month`,`number`,`time`,`week`]);function NVe(e){return e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement}function PVe(e){return Reflect.get(HTMLFormElement.prototype,`elements`,e)}function FVe(e,t){return Reflect.apply(Element.prototype.getAttribute,e,[t])}function IVe(e,t){return Reflect.apply(Element.prototype.hasAttribute,e,[t])}function LVe(e){return Reflect.get(Node.prototype,`isConnected`,e)}function RVe(e){return Reflect.get(Element.prototype,`shadowRoot`,e)}function zVe(e){return Reflect.apply(HTMLFormElement.prototype.checkValidity,e,[])}function BVe(e,t){Reflect.apply(HTMLFormElement.prototype.requestSubmit,e,t?[t]:[])}function DV(e){return[...PVe(e)].filter(e=>NVe(e)&&!e.matches(`:disabled`)&&!(`readOnly`in e&&e.readOnly&&(e instanceof HTMLTextAreaElement||EV.has(e.type))))}function VVe(e){let t=new Map;for(let n of DV(e)){let e=n.name.trim(),r=t.get(e);r?r.push(n):t.set(e,[n])}return t}function OV(e){return[...e.labels??[]].map(e=>{let t=e.cloneNode(!0);return t instanceof HTMLElement?(t.querySelectorAll(`button, input, meter, output, progress, select, textarea`).forEach(e=>e.remove()),t.textContent?.trim()??``):``}).filter(Boolean).join(`; `)}function HVe(e,t){for(let n=t[0]?.parentElement;n&&n!==e;n=n.parentElement)if(n instanceof HTMLFieldSetElement&&t.every(e=>n.contains(e)))return n}function kV(e,t){if(t.length===1){let e=t[0];return e&&(e.getAttribute(`toolparamdescription`)||OV(e)||e.getAttribute(`aria-description`))||void 0}return HVe(e,t)?.getAttribute(`toolparamdescription`)||void 0}function AV(e,t,n,r){let i=kV(t,n),a=i&&r?`${i} (${r})`:i||r;return a?{...e,description:a}:e}function UVe(e,t){let n=e.getAttribute(t);if(n===null||n.trim()===``)return;let r=Number(n);return Number.isFinite(r)?r:void 0}function WVe(e,t){let n=e/t;return Math.abs(n-Math.round(n))<2**-52*16}function GVe(e){let t=e.getAttribute(`pattern`);if(t!==null)try{return new RegExp(t,`v`),t}catch{return}}function KVe(e,t=!0){let n={type:`number`},r=UVe(e,`min`),i=UVe(e,`max`);r!==void 0&&(n.minimum=r),i!==void 0&&(n.maximum=i);let a=e.getAttribute(`step`);if(a!==`any`){let t=a===null||a===``?1:Number(a),i=Number.isFinite(t)&&t>0?t:1,o=Number(e.getAttribute(`value`));WVe(r??(Number.isFinite(o)?o:0),i)&&(n.multipleOf=i)}let o=t?GVe(e):void 0;return o!==void 0&&(n.pattern=o),n}function jV(e,t){let n=e.getAttribute(`step`),r=n===null||n===``?60:Number(n),i=Number.isFinite(r)&&r>0?r:60;return i<1?`${t}(:[0-5][0-9](\\.[0-9]{1,3})?)?$`:i<60?`${t}(:[0-5][0-9])?$`:`${t}$`}function qVe(e){return{anyOf:e.map(e=>({type:`string`,const:e.value,title:e.textContent??``})),enum:e.map(e=>e.value)}}function JVe(e){return{anyOf:e.map(e=>{let t=OV(e);return{type:`string`,const:e.value,...t?{title:t}:{}}}),enum:e.map(e=>e.value)}}function YVe(e,t){let n=t[0];if(n){if(t.length>1)return t.every(e=>e instanceof HTMLInputElement)?t.every(e=>e.type===`checkbox`)?AV({type:`array`,items:{type:`string`,...JVe(t)},uniqueItems:!0},e,t):t.every(e=>e.type===`radio`)?AV({type:`string`,...JVe(t)},e,t):void 0:void 0;if(n instanceof HTMLTextAreaElement)return AV({type:`string`},e,t);if(n instanceof HTMLSelectElement){let r=qVe([...n.options]);return AV(n.multiple?{type:`array`,items:{type:`string`,...r},uniqueItems:!0}:{type:`string`,...r},e,t)}if(MVe.has(n.type)){let r={type:`string`},i=GVe(n);return i!==void 0&&(r.pattern=i),AV(r,e,t)}if(n.type===`hidden`)return n.getAttribute(`toolparamdescription`)?AV({type:`string`},e,t):void 0;if(n.type===`number`)return AV(KVe(n),e,t);if(n.type===`range`){let r=KVe(n,!1);return r.minimum??=0,r.maximum??=100,AV(r,e,t)}if(n.type===`checkbox`)return AV({type:`boolean`},e,t);if(n.type===`radio`)return AV({type:`string`,...JVe([n])},e,t);if(n.type===`date`)return AV({type:`string`,format:`date`},e,t,`Dates MUST be provided in 'YYYY-MM-DD' format.`);if(n.type===`month`)return AV({type:`string`,format:`^[0-9]{4}-(0[1-9]|1[0-2])$`},e,t);if(n.type===`week`)return AV({type:`string`,format:`^[0-9]{4}-W(0[1-9]|[1-4][0-9]|5[0-3])$`},e,t);if(n.type===`time`)return AV({type:`string`,format:jV(n,`^([01][0-9]|2[0-3]):[0-5][0-9]`)},e,t);if(n.type===`datetime-local`)return AV({type:`string`,format:jV(n,`^[0-9]{4}-(0[1-9]|1[0-2])-[0-9]{2}T([01][0-9]|2[0-3]):[0-5][0-9]`)},e,t);if(n.type===`color`)return AV({type:`string`,format:`^#[0-9a-zA-Z]{6}$`},e,t)}}function XVe(e){let t={},n=[];for(let[r,i]of VVe(e)){if(!r)continue;let a=YVe(e,i);a&&(Object.defineProperty(t,r,{configurable:!0,enumerable:!0,value:a,writable:!0}),i.some(e=>e.required)&&n.push(r))}return{type:`object`,properties:t,required:n}}function ZVe(e){return{name:FVe(e,`toolname`)??``,title:FVe(e,`tooltitle`)??``,description:FVe(e,`tooldescription`)??``,inputSchema:XVe(e),autosubmit:IVe(e,`toolautosubmit`)}}function MV(e){if(typeof e==`string`||typeof e==`boolean`||typeof e==`number`&&Number.isFinite(e))return String(e)}function QVe(e){if(typeof e==`boolean`)return e;if(typeof e==`number`&&Number.isInteger(e))return e!==0;if(typeof e==`string`){if(e===`1`||e.toLowerCase()===`true`)return!0;if(e===`0`||e.toLowerCase()===`false`)return!1}}function $Ve(e,t){if(!Array.isArray(e))return!1;let n=new Set(t);for(let t of e){let e=MV(t);if(e===void 0||!n.delete(e))return!1}return!0}function eHe(e,t){if(t===``)return e.type!==`number`&&e.type!==`range`;let n=e.ownerDocument.createElement(`input`);return n.type=e.type,n.value=t,n.value!==``}function NV(e,t,n){let r=t[0];if(!r||!YVe(e,t))return!1;if(t.length>1){if(!t.every(e=>e instanceof HTMLInputElement))return!1;if(t.every(e=>e.type===`checkbox`))return $Ve(n,new Set(t.map(e=>e.value)));if(t.every(e=>e.type===`radio`)){let e=MV(n);return e!==void 0&&t.some(t=>t.value===e)}return!1}if(r instanceof HTMLSelectElement){let e=new Set([...r.options].map(e=>e.value));if(r.multiple)return $Ve(n,e);let t=MV(n);return t!==void 0&&e.has(t)}if(r instanceof HTMLTextAreaElement)return MV(n)!==void 0;if(r.type===`checkbox`)return QVe(n)!==void 0;if(r.type===`radio`){let e=MV(n);return e!==void 0&&r.value===e}let i=MV(n);return i!==void 0&&eHe(r,i)}function PV(e){e.dispatchEvent(new Event(`input`,{bubbles:!0,composed:!0})),e.dispatchEvent(new Event(`change`,{bubbles:!0}))}function tHe(e,t){let n=e instanceof HTMLInputElement?HTMLInputElement.prototype:HTMLTextAreaElement.prototype;Object.getOwnPropertyDescriptor(n,`value`)?.set?.call(e,t)}function FV(e,t){Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,`checked`)?.set?.call(e,t)}function IV(e,t){let n=e[0];if(!n)return;if(e.length>1&&e.every(e=>e instanceof HTMLInputElement)){if(e.every(e=>e.type===`checkbox`)&&Array.isArray(t)){let n=new Set(t.map(MV));for(let t of e){let e=n.has(t.value);t.checked!==e&&(FV(t,e),PV(t))}return}let n=MV(t),r=e.find(e=>e.value===n);r&&!r.checked&&(FV(r,!0),PV(r));return}if(n instanceof HTMLSelectElement){if(n.multiple&&Array.isArray(t)){let e=new Set(t.map(MV)),r=!1;for(let t of n.options){let n=e.has(t.value);t.selected!==n&&(t.selected=n,r=!0)}r&&PV(n);return}let e=MV(t);e!==void 0&&n.value!==e&&(n.value=e,PV(n));return}if(n instanceof HTMLInputElement&&n.type===`checkbox`){let e=QVe(t);e!==void 0&&n.checked!==e&&(FV(n,e),PV(n));return}if(n instanceof HTMLInputElement&&n.type===`radio`){MV(t)===n.value&&!n.checked&&(FV(n,!0),PV(n));return}let r=MV(t);r!==void 0&&n.value!==r&&(tHe(n,r),PV(n))}function nHe(e,t){if(Array.isArray(t))throw TypeError(`Declarative tool input must be an object`);let n=VVe(e);for(let[r,i]of Object.entries(t)){let t=n.get(r);if(!t||!NV(e,t,i))throw TypeError(`Invalid value for declarative form parameter "${r}"`)}for(let[e,r]of Object.entries(t))IV(n.get(e)??[],r)}function rHe(e){return[...PVe(e)].find(e=>!e.matches(`:disabled`)&&(e instanceof HTMLButtonElement&&e.type===`submit`||e instanceof HTMLInputElement&&[`image`,`submit`].includes(e.type)))}function iHe(e){let t=[...PVe(e)].filter(e=>NVe(e)&&e.willValidate&&!e.validity.valid).map(e=>`${e.name.trim()||`{unknown}`}: ${e.validationMessage}`).join(`. `);return new DOMException(`Form validation failed: ${t}`,`UnknownError`)}function aHe(e){let t=new Event(`toolactivated`);return Object.defineProperty(t,"toolName",{enumerable:!0,value:e}),t}function oHe(e,t,n,r){let{form:i}=e;return e.cancelPending?.(new DOMException(`Tool execution cancelled`,`UnknownError`)),new Promise((a,o)=>{let s=!1,c=()=>{Reflect.apply(EventTarget.prototype.removeEventListener,i,[`invalid`,f,!0]),CV.delete(i),e.cancelPending===u&&delete e.cancelPending},l=e=>{s||(s=!0,c(),e())},u=e=>l(()=>o(e)),d=e=>{e.then(e=>l(()=>a(e)),e=>l(()=>o(e)))},f=e=>{e.isTrusted&&queueMicrotask(()=>{zVe(i)||u(iHe(i))})};if(CV.set(i,{complete(e){queueMicrotask(()=>{let t=SV.get(e);t?d(t):e.defaultPrevented?u(new DOMException(`preventDefault() requires respondWith()`,`UnknownError`)):l(()=>a(void 0))})},direct(){l(()=>a(void 0))},respond(e){queueMicrotask(()=>{let t=SV.get(e);t&&d(t)})}}),e.cancelPending=u,Reflect.apply(EventTarget.prototype.addEventListener,i,[`invalid`,f,!0]),!n){r?.focus(),window.dispatchEvent(aHe(t));return}try{BVe(i,r),window.dispatchEvent(aHe(t))}catch(e){u(e)}})}function sHe(e,t){let n=!0,r=new Map,i=new Map,a=new Map,o=e=>{if(!(e instanceof SubmitEvent)||!e.isTrusted||!(e.target instanceof HTMLFormElement))return;let t=CV.get(e.target);t&&(xV.add(e),t.complete(e))},s=e=>{if(!e.isTrusted||!(e.target instanceof HTMLFormElement))return;let t=e.target;queueMicrotask(()=>{e.defaultPrevented||r.get(t)?.cancelPending?.(new DOMException(`Tool execution cancelled by form reset`,`UnknownError`))})};function c(e){a.get(e)?.disconnect(),a.delete(e),e.removeEventListener(`reset`,s,!0),e.removeEventListener(`submit`,o,!0)}function l(e){if(a.has(e))return;let t=new MutationObserver(u);a.set(e,t),t.observe(e,{attributes:!0,characterData:!0,childList:!0,subtree:!0}),e.addEventListener(`reset`,s,!0),e.addEventListener(`submit`,o,!0)}function u(){l(e);for(let e of a.keys())e instanceof ShadowRoot&&!Reflect.get(Node.prototype,`isConnected`,e.host)&&c(e);let n=new Set,o=new Map,s=new Map;for(let e of a.keys())for(let t of e.querySelectorAll(`*`)){let e=RVe(t);if(e&&l(e),!(t instanceof HTMLFormElement)||!IVe(t,`toolname`)||!IVe(t,`tooldescription`)||!LVe(t))continue;let r=t;n.add(r);let a=ZVe(r),c=JSON.stringify(a),u=i.get(r);if(u===c)continue;let d=u!==void 0;i.delete(r);let f=s.get(a.name);if(f&&!d){i.set(r,c);continue}if(f){let e=o.get(f);e&&(i.set(f,e.fingerprint),o.delete(f))}s.set(a.name,r),o.set(r,{definition:a,fingerprint:c})}for(let e of i.keys())n.has(e)||i.delete(e);for(let[e,t]of r)o.get(e)?.fingerprint!==t.fingerprint&&(t.cancelPending?.(new DOMException(`Tool execution cancelled because its form changed`,`UnknownError`)),t.controller.abort(),r.delete(e));for(let[e,{definition:n,fingerprint:i}]of o){if(r.has(e))continue;let a=new AbortController,o={controller:a,fingerprint:i,form:e};r.set(e,o),t.registerTool({name:n.name,title:n.title,description:n.description,inputSchema:n.inputSchema,execute(t){let r=rHe(e);if(!n.autosubmit&&!r)throw new DOMException(`A declarative form without toolautosubmit requires a submit button`,`UnknownError`);return nHe(e,t),oHe(o,n.name,n.autosubmit,r)}},{signal:a.signal}).catch(e=>{a.abort(),e?.name!==`AbortError`&&console.error(`[webmcp] declarative form tool "${n.name}" was not registered:`,e)})}}let d=()=>{},f=e.defaultView?.Element.prototype,p=f?Object.getOwnPropertyDescriptor(f,`attachShadow`):void 0;if(f&&p?.configurable){let t=f.attachShadow,r=function(r){let i=t.call(this,r);return n&&i.mode===`open`&&Reflect.get(Node.prototype,`ownerDocument`,this)===e&&Reflect.get(Node.prototype,`isConnected`,this)&&l(i),i};Object.defineProperty(f,"attachShadow",{...p,value:r}),d=()=>{f.attachShadow===r&&Object.defineProperty(f,"attachShadow",p)}}let m=()=>{},h=e.defaultView?.HTMLFormElement.prototype,g=h?Object.getOwnPropertyDescriptor(h,`submit`):void 0;if(h&&g?.configurable){let e=h.submit,t=function(){e.call(this),n&&CV.get(this)?.direct()};Object.defineProperty(h,"submit",{...g,value:t}),m=()=>{h.submit===t&&Object.defineProperty(h,"submit",g)}}return u(),()=>{n=!1,m(),d();for(let e of a.keys())c(e);i.clear();for(let e of r.values())e.cancelPending?.(new DOMException(`Tool execution cancelled`,`UnknownError`)),e.controller.abort();r.clear()}}var cHe=`__isWebMCPPolyfill`,lHe=Symbol(`registeredInputSchema`),LV=Symbol(`registrationSignal`),uHe=Symbol(`registrationAbort`),RV=[],dHe=null,zV=null;function fHe(){return typeof globalThis.origin==`string`?globalThis.origin:globalThis.location?.origin??``}function BV(e,t,n){let r=Object.getOwnPropertyDescriptor(e,t);try{Object.defineProperty(e,t,n)}catch(e){throw gHe(),e}RV.push({target:e,key:t,previous:r})}var VV=class extends EventTarget{#e=new Map;#t=null;#n=null;#r=e=>{this.#n?.call(this,e)};#i;#a;constructor(e){super(),this.#a=e,this.#i=e?.defaultView?.DOMException??DOMException,Object.defineProperty(this,cHe,{value:!0,enumerable:!1,writable:!1,configurable:!1})}get ontoolchange(){return this.#n}set ontoolchange(e){let t=typeof e==`function`?e:null;if(t===null){this.#n=null,super.removeEventListener(`toolchange`,this.#r);return}this.#n===null&&super.addEventListener(`toolchange`,this.#r),this.#n=t}async registerTool(e,t={}){yV(this.#a);let n=t?.signal,r=pHe(e,this.#e);if(n?.throwIfAborted(),kVe(t?.exposedTo),n?.throwIfAborted(),t?.exposedTo?.length)throw new this.#i(`Cross-document tool exposure requires native WebMCP`,`NotSupportedError`);if(this.#e.set(r.name,r),n){let e=()=>{this.#o(r.name,r)&&this.#c()};r[LV]=n,r[uHe]=e,n.addEventListener(`abort`,e,{once:!0})}if(await this.#c(),n?.aborted)throw n.reason}async getTools(e={}){if(yV(this.#a),kVe(e?.fromOrigins),e?.fromOrigins?.length)throw new this.#i(`Cross-document tool discovery requires native WebMCP`,`NotSupportedError`);let t=[...this.#e.values()].map(e=>{let t=e[lHe],n=t===void 0?void 0:JSON.parse(t);return{name:e.name,title:e.title??``,description:e.description,...pV(n)?{inputSchema:n}:{},origin:fHe(),window:globalThis.window,...e.annotations?{annotations:_V(e.annotations)}:{}}}).sort((e,t)=>e.name<t.name?-1:+(e.name>t.name));return await new Promise(e=>setTimeout(e,0)),t}async executeTool(e,t,n={}){if(yV(this.#a),typeof e!=`object`||!e)throw TypeError(`RegisteredTool must be an object`);for(let t of[`name`,`description`,`window`,`origin`])if(!(t in e))throw TypeError(`RegisteredTool.${t} is required`);if(bV(e.origin),e.window!==globalThis.window||e.origin!==fHe())throw hV(`Tool not found: ${e.name}`);return this.#s(e.name,t,n)}static getTestingShim(e){return e.#t??=new UV(e),e.#t}static getToolInfos(e){return[...e.#e.values()].map(e=>({name:e.name,description:e.description,...e[lHe]===void 0?{}:{inputSchema:e[lHe]}}))}static executeToolForTesting(e,t,n,r){return yV(e.#a),e.#s(t,n,r)}static dispose(e){for(let t of e.#e.keys())e.#o(t);e.ontoolchange=null,e.#t?.dispose()}#o(e,t){let n=this.#e.get(e);if(!n||t&&n!==t)return!1;let r=n[LV],i=n[uHe];return r&&i&&r.removeEventListener(`abort`,i),this.#e.delete(e)}async#s(e,t,n){n?.signal?.throwIfAborted();let r=this.#e.get(e);if(!r)throw hV(`Tool not found: ${e}`);let i=EVe(t);if(n?.signal?.throwIfAborted(),r[LV]?.aborted)throw hV(`Tool unregistered`);let a;try{let e=r[LV];a=await OVe(OVe(Promise.resolve(r.execute(i)),e,()=>hV(`Tool unregistered`)),n?.signal)}catch(e){throw n?.signal?.aborted&&e===n.signal.reason||r[LV]?.aborted?e:wVe(e)}return DVe(a)}async#c(){await new Promise(e=>setTimeout(e,0)),this.dispatchEvent(new Event(`toolchange`)),this.#t?.dispatchToolChange()}},HV=function(){throw TypeError(`Illegal constructor`)};Object.defineProperty(HV,"name",{value:`ModelContext`}),Object.defineProperty(HV,"prototype",{value:VV.prototype,writable:!1}),Object.setPrototypeOf(HV,EventTarget),Object.defineProperty(VV.prototype,"constructor",{configurable:!0,writable:!0,value:HV}),Object.defineProperty(VV.prototype,Symbol.toStringTag,{configurable:!0,value:`ModelContext`});for(let e of[`registerTool`,`getTools`,`executeTool`,`ontoolchange`]){let t=Object.getOwnPropertyDescriptor(VV.prototype,e);t&&Object.defineProperty(VV.prototype,e,{...t,enumerable:!0})}var UV=class extends EventTarget{_ontoolchange=null;ontoolchangeListener=e=>{this._ontoolchange?.call(this,e)};#e;constructor(e){super(),this.#e=e}listTools(){return VV.getToolInfos(this.#e)}executeTool(e,t,n){return VV.executeToolForTesting(this.#e,e,t,n)}get ontoolchange(){return this._ontoolchange}set ontoolchange(e){let t=typeof e==`function`?e:null;if(t===null){this._ontoolchange=null,super.removeEventListener(`toolchange`,this.ontoolchangeListener);return}this._ontoolchange===null&&super.addEventListener(`toolchange`,this.ontoolchangeListener),this._ontoolchange=t}dispatchToolChange(){this.dispatchEvent(new Event(`toolchange`))}dispose(){this.ontoolchange=null}};function pHe(e,t){if(!e||typeof e!=`object`)throw TypeError(`registerTool(tool) requires a tool object`);let n=mV(e);if(TVe(n),t.has(n.name))throw gV(`Tool already registered: ${n.name}`);let r=n.inputSchema===void 0?void 0:jVe(n.inputSchema);return{name:n.name,...n.title===void 0?{}:{title:n.title},description:n.description,...n.inputSchema===void 0?{}:{inputSchema:n.inputSchema},...n.annotations===void 0?{}:{annotations:n.annotations},execute:e=>Reflect.apply(n.execute,void 0,[e]),...r===void 0?{}:{[lHe]:r}}}var WV=!1,GV=new WeakMap,{modelContext:mHe}={modelContext(){if(!(this instanceof Document))throw TypeError(`Illegal invocation`);return GV.get(this)}};Object.defineProperty(mHe,"name",{value:`get modelContext`});function KV(e,t){GV.set(e,t),!Object.hasOwn(Document.prototype,`modelContext`)&&BV(Document.prototype,`modelContext`,{configurable:!0,enumerable:!0,get:mHe})}function qV(e,t){BV(e,`modelContext`,{configurable:!0,enumerable:!0,get(){return WV||(WV=!0,console.warn(`[WebMCPPolyfill] navigator.modelContext is deprecated. The May 27, 2026 WebMCP draft moved the modelContext getter from Navigator to Document — use document.modelContext instead. See https://github.com/webmachinelearning/webmcp/pull/184.`)),t}})}function JV(){let e=SubmitEvent.prototype;`agentInvoked`in e||BV(e,`agentInvoked`,{configurable:!0,enumerable:!0,get(){return wV(this)}}),`respondWith`in e||BV(e,`respondWith`,{configurable:!0,enumerable:!0,writable:!0,value(e){TV(this,e)}})}function hHe(e){if(globalThis.isSecureContext===!1)return;let t=typeof navigator>`u`?null:navigator,n=typeof document>`u`?null:document;if(!t||!n||typeof window>`u`||n.modelContext)return;let r=t.modelContext;if(RV.length>0&&gHe(),r){KV(n,r);return}let i=Object.getOwnPropertyDescriptor(window,`ModelContext`);if(i&&!i.configurable){if(!Object.is(Reflect.get(window,`ModelContext`),HV))throw TypeError(`Cannot install ModelContext over a non-configurable global`)}else BV(window,`ModelContext`,{configurable:!0,enumerable:!1,writable:!0,value:HV});let a=new VV(n);dHe=a,KV(n,a),WV=!1,qV(t,a),JV(),e?.installTestingShim&&!t.modelContextTesting&&BV(t,`modelContextTesting`,{configurable:!0,enumerable:!0,writable:!1,value:VV.getTestingShim(a)}),zV=sHe(n,a)}function gHe(){zV?.(),zV=null,dHe&&VV.dispose(dHe),dHe=null;for(let{target:e,key:t,previous:n}of[...RV].reverse())n?Object.defineProperty(e,t,n):Reflect.deleteProperty(e,t);RV.length=0,WV=!1}var _He=40,YV=e=>new Promise(t=>setTimeout(t,e)),vHe=e=>e<.5?4*e*e*e:1-(-2*e+2)**3/2,XV=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y),yHe=(e,t)=>oR(e,t),ZV=(e,t)=>{let n=yHe(e,t);return{x:n.x+aR(e).width,y:n.y+aR(e).height/2}},bHe=(e,t)=>{let n=yHe(e,t);return{x:n.x,y:n.y+aR(e).height/2}},xHe=e=>nR(e.type,e.data);function QV(e,{pace:t=1}={}){let n={pointer:e.lastPointer??null,selection:[]},r=()=>e.present({...n});return{get pointer(){return n.pointer},async pause(e){await YV(e*t)},say(e){n.activity=e,r()},select(e){n.selection=e,r()},async moveTo(e,{connecting:i,carry:a}={}){let o=n.pointer??{x:e.x-160,y:e.y-120},s=Math.min(900,Math.max(250,200+XV(o,e)*.6))*t,c=Math.max(1,Math.round(s/_He));n.connecting=i??null;for(let t=1;t<=c;t++){let i=vHe(t/c);n.pointer={x:o.x+(e.x-o.x)*i,y:o.y+(e.y-o.y)*i},a&&(n.moving={[a.nodeId]:{x:n.pointer.x-a.grab.x,y:n.pointer.y-a.grab.y}}),r(),await YV(_He)}},release(){n.connecting=null,n.moving=null,r()}}}var SHe=e=>Math.max(.25,Math.min(1,10/Math.max(e,1))),$V=e=>new Map(SR(e).nodes.entries());async function eH(e,t,n,r,i){let a=await e.change($V),o=a.get(r),s=a.get(i);if(!o||!s)return e.change(n);t.say(`Connecting ${xHe(o)} to ${xHe(s)}`);let c=ZV(o,a);await t.moveTo(c),await t.pause(120),await t.moveTo(bHe(s,a),{connecting:c});let l=await e.change(n);return t.release(),await t.pause(180),l}async function tH(e,{nodes:t,edges:n=[]},r){let{planned:i,errors:a}=dVe(await e.change(e=>[...$V(e).values()]),t,r,n),o=pVe(n,i),s=QV(e,{pace:SHe(i.length*2+o.length)}),c=[];for(let{node:t,canvasPosition:n,name:l,resource:u}of i){s.say(`Adding ${l}`);let{width:i,height:d}=aR(t);await s.moveTo({x:n.x+i/2,y:n.y+d/2}),await s.pause(150);let{node:f,related:p}=await e.change(e=>{let i=$V(e),a=t.parentId?i.get(t.parentId):void 0,o=a?oR(a,i):{x:0,y:0},s={...t,position:{x:n.x-o.x,y:n.y-o.y}};return kR(e,[s]),MR(e,s.id),{node:s,related:u?sV(u,s.id,[...i.values()],r.relationsByKey,s.type):[]}});s.select([f.id]),await s.pause(300);for(let t of p)await eH(e,s,e=>(kR(e,[],[t]),t),t.source,t.target),c.push(t.id);let m=await e.change(e=>new Set($V(e).keys()));for(let t of o.filter(e=>m.has(e.from)&&m.has(e.to))){o.splice(o.indexOf(t),1);let n=await eH(e,s,e=>RR(e,{source:t.from,target:t.to},t.label),t.from,t.to);`error`in n?a.push(n.error):c.push(n.id)}}for(let t of o){let n=await e.change(e=>RR(e,{source:t.from,target:t.to},t.label));`error`in n&&a.push(n.error)}return s.say(`Done`),{created:i.map(({ref:e,node:t,name:n})=>({ref:e,nodeId:t.id,name:n})),connections:c,errors:a}}async function nH(e,t){let n=QV(e,{pace:SHe(t.length)}),r=[],i=[];for(let a of t){let t=await eH(e,n,e=>RR(e,{source:a.from,target:a.to},a.label),a.from,a.to);`error`in t?i.push(t.error):r.push(t.id)}return{connections:r,errors:i}}async function CHe(e,t,n,r=QV(e)){let i=await e.change($V),a=i.get(t);if(!a)return!1;let o=a.parentId?i.get(a.parentId):void 0,s=o?yHe(o,i):{x:0,y:0},c={x:s.x+aR(a).width/2,y:s.y+24};if(r.say(`Moving ${xHe(a)}`),await r.moveTo({x:a.position.x+c.x,y:a.position.y+c.y}),r.select([t]),await r.pause(120),e.sharesMoves)return await r.moveTo({x:n.x+c.x,y:n.y+c.y},{carry:{nodeId:t,grab:c}}),await e.change(e=>wRe(e,t,n)),r.release(),!0;let l=a.position;for(let i=1;i<=12;i++){let a=vHe(i/12),o={x:l.x+(n.x-l.x)*a,y:l.y+(n.y-l.y)*a};await e.change(e=>wRe(e,t,o)),await r.moveTo({x:o.x+c.x,y:o.y+c.y})}return!0}var rH=(e,t)=>e.transact(()=>{t.nodes.forEach(({position:t,size:n},r)=>CRe(e,r,t,n)),DRe(e,t.routes),ER(e,{layoutAt:Date.now()})});async function iH(e,t,n){let r=QV(e,{pace:SHe(t.length)});n.length&&await e.change(e=>zR(e,n));for(let n of t){let t=await e.change($V),i=t.get(n);i&&(r.say(`Removing ${xHe(i)}`),await r.moveTo(cVe(i,t)),r.select([n]),await r.pause(250),await e.change(e=>BR(e,[n])),r.select([]))}}async function wHe(e,{text:t,nodeId:n,x:r,y:i},a){let o=await e.change($V),s=n?o.get(n):void 0;if(n&&!s)return{error:`No node "${n}" on the canvas`};let c=s?{x:aR(s).width-8,y:8}:void 0,l=s&&yHe(s,o),u=s&&c&&l?{position:{x:l.x+c.x,y:l.y+c.y},nodeId:s.id,offset:c}:{position:{x:r??0,y:i??0}},d=QV(e);return d.say(`Commenting`),await d.moveTo(u.position),await d.pause(400),{threadId:await e.change(e=>HR(e,u,t,a))}}async function THe(e,t,n,r){let i=await e.change($V),a=i.get(t),o=QV(e);return a&&(o.say(n),await o.moveTo(cVe(a,i)),o.select([t]),await o.pause(250)),e.change(r)}async function EHe(e,{nodeId:t,name:n,summary:r,version:i,x:a,y:o}){let s={error:`No node "${t}" on the canvas`};if(n!==void 0||r!==void 0||i!==void 0){let a=await THe(e,t,`Editing`,e=>mVe(e,{nodeId:t,name:n,summary:r,version:i}));if(`error`in a)return a}if(a!==void 0||o!==void 0){let n=await e.change($V),r=n.get(t);if(!r)return s;let i=cVe(r,n);await CHe(e,t,lVe(r,{x:a??i.x,y:o??i.y},n))}let c=await e.change($V),l=c.get(t);return l?sVe(l,c):s}var aH=function(e){return e[e.Token=0]=`Token`,e[e.PermissionDenied=1]=`PermissionDenied`,e[e.Authenticated=2]=`Authenticated`,e}({}),DHe=(e,t)=>{YN(e,aH.Token),QN(e,t)},OHe=(e,t,n,r)=>{switch(gP(e)){case aH.Token:t();break;case aH.PermissionDenied:n(vP(e));break;case aH.Authenticated:r(vP(e));break;default:}},kHe=e=>Array.from(e.entries()).map(([e,t])=>({clientId:e,...t})),AHe=`\0`;function jHe(e,t){return e+AHe+t}function MHe(e){let t=e.indexOf(AHe);return t===-1?{documentName:e,sessionId:null}:{documentName:e.substring(0,t),sessionId:e.substring(t+1)}}var NHe=function(e){return e[e.Connecting=0]=`Connecting`,e[e.Open=1]=`Open`,e[e.Closing=2]=`Closing`,e[e.Closed=3]=`Closed`,e}({}),PHe=3e4,oH=class extends PN{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let e=DP();this.getLocalState()!==null&&3e4/2<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let t=[];this.meta.forEach((n,r)=>{r!==this.clientID&&3e4<=e-n.lastUpdated&&this.states.has(r)&&t.push(r)}),t.length>0&&sH(this,t,`timeout`)},FN(PHe/10)),e.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(e){let t=this.clientID,n=this.meta.get(t),r=n===void 0?0:n.clock+1,i=this.states.get(t);e===null?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:r,lastUpdated:DP()});let a=[],o=[],s=[],c=[];e===null?c.push(t):i==null?e!=null&&a.push(t):(o.push(t),IP(i,e)||s.push(t)),(a.length>0||s.length>0||c.length>0)&&this.emit(`change`,[{added:a,updated:s,removed:c},`local`]),this.emit(`update`,[{added:a,updated:o,removed:c},`local`])}setLocalStateField(e,t){let n=this.getLocalState();n!==null&&this.setLocalState({...n,[e]:t})}getStates(){return this.states}},sH=(e,t,n)=>{let r=[];for(let n=0;n<t.length;n++){let i=t[n];if(e.states.has(i)){if(e.states.delete(i),i===e.clientID){let t=e.meta.get(i);e.meta.set(i,{clock:t.clock+1,lastUpdated:DP()})}r.push(i)}}r.length>0&&(e.emit(`change`,[{added:[],updated:[],removed:r},n]),e.emit(`update`,[{added:[],updated:[],removed:r},n]))},cH=(e,t,n=e.states)=>{let r=t.length,i=UN();YN(i,r);for(let a=0;a<r;a++){let r=t[a],o=n.get(r)||null,s=e.meta.get(r).clock;YN(i,r),YN(i,s),QN(i,JSON.stringify(o))}return GN(i)},FHe=(e,t,n)=>{let r=pP(t),i=DP(),a=[],o=[],s=[],c=[],l=gP(r);for(let t=0;t<l;t++){let t=gP(r),n=gP(r),l=JSON.parse(vP(r)),u=e.meta.get(t),d=e.states.get(t),f=u===void 0?0:u.clock;(f<n||f===n&&l===null&&e.states.has(t))&&(l===null?t===e.clientID&&e.getLocalState()!=null?n++:e.states.delete(t):e.states.set(t,l),e.meta.set(t,{clock:n,lastUpdated:i}),u===void 0&&l!==null?a.push(t):u!==void 0&&l===null?c.push(t):l!==null&&(IP(l,d)||s.push(t),o.push(t)))}(a.length>0||s.length>0||c.length>0)&&e.emit(`change`,[{added:a,updated:s,removed:c},n]),(a.length>0||o.length>0||c.length>0)&&e.emit(`update`,[{added:a,updated:o,removed:c},n])};function IHe(e){return e||={},{delay:e.delay===void 0?200:e.delay,initialDelay:e.initialDelay===void 0?0:e.initialDelay,minDelay:e.minDelay===void 0?0:e.minDelay,maxDelay:e.maxDelay===void 0?0:e.maxDelay,factor:e.factor===void 0?0:e.factor,maxAttempts:e.maxAttempts===void 0?3:e.maxAttempts,timeout:e.timeout===void 0?0:e.timeout,jitter:e.jitter===!0,initialJitter:e.initialJitter===!0,handleError:e.handleError===void 0?null:e.handleError,handleTimeout:e.handleTimeout===void 0?null:e.handleTimeout,beforeAttempt:e.beforeAttempt===void 0?null:e.beforeAttempt,calculateDelay:e.calculateDelay===void 0?null:e.calculateDelay}}async function lH(e){return new Promise(t=>setTimeout(t,e))}function LHe(e,t){let n=t.delay;if(n===0)return 0;if(t.factor&&(n*=t.factor**(e.attemptNum-1),t.maxDelay!==0&&(n=Math.min(n,t.maxDelay))),t.jitter){let e=Math.ceil(t.minDelay);n=Math.floor(Math.random()*(Math.floor(n)-e+1))+e}return Math.round(n)}async function RHe(e,t){let n=IHe(t);for(let e of[`delay`,`initialDelay`,`minDelay`,`maxDelay`,`maxAttempts`,`timeout`]){let t=n[e];if(!Number.isInteger(t)||t<0)throw Error(`Value for ${e} must be an integer greater than or equal to 0`)}if(n.factor.constructor!==Number||n.factor<0)throw Error(`Value for factor must be a number greater than or equal to 0`);if(n.delay<n.minDelay)throw Error(`delay cannot be less than minDelay (delay: ${n.delay}, minDelay: ${n.minDelay}`);let r={attemptNum:0,attemptsRemaining:n.maxAttempts?n.maxAttempts:-1,aborted:!1,abort(){r.aborted=!0}},i=n.calculateDelay||LHe;async function a(){if(n.beforeAttempt&&n.beforeAttempt(r,n),r.aborted){let e=Error(`Attempt aborted`);throw e.code=`ATTEMPT_ABORTED`,e}let t=async e=>{if(n.handleError&&await n.handleError(e,r,n),r.aborted||r.attemptsRemaining===0)throw e;r.attemptNum++;let t=i(r,n);return t&&await lH(t),a()};return r.attemptsRemaining>0&&r.attemptsRemaining--,n.timeout?new Promise((i,a)=>{let o=setTimeout(()=>{if(n.handleTimeout)try{i(n.handleTimeout(r,n))}catch(e){a(e)}else{let e=Error(`Retry timeout (attemptNum: ${r.attemptNum}, timeout: ${n.timeout})`);e.code=`ATTEMPT_TIMEOUT`,a(e)}},n.timeout);e(r,n).then(e=>{clearTimeout(o),i(e)}).catch(e=>{clearTimeout(o),t(e).then(i).catch(a)})}):e(r,n).catch(t)}let o=n.calculateDelay?n.calculateDelay(r,n):n.initialDelay;if(o&&await lH(o),r.attemptNum<1&&n.initialJitter){let e=i(r,n);e&&await lH(e)}return a()}var zHe=(e,t)=>{YN(e,0),eP(e,kIe(t))},BHe=(e,t,n)=>{YN(e,1),eP(e,OIe(t,n))},VHe=(e,t,n)=>BHe(t,n,mP(e)),HHe=(e,t,n,r)=>{try{tI(t,mP(e),n)}catch(e){r?.(e),console.error(`Caught error while handling a Yjs update`,e)}},UHe=(e,t)=>{YN(e,2),eP(e,t)},WHe=HHe,GHe=(e,t,n,r,i)=>{let a=gP(e);switch(a){case 0:VHe(e,t,n);break;case 1:HHe(e,n,r,i);break;case 2:WHe(e,n,r,i);break;default:throw Error(`Unknown message type`)}return a},KHe=class{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){let n=this.callbacks[e];return n&&n.forEach(e=>e.apply(this,t)),this}off(e,t){let n=this.callbacks[e];return n&&(t?this.callbacks[e]=n.filter(e=>e!==t):delete this.callbacks[e]),this}removeAllListeners(){this.callbacks={}}},uH=class{constructor(e){this.data=e,this.encoder=UN(),this.decoder=pP(new Uint8Array(this.data))}peekVarString(){return yP(this.decoder)}readVarUint(){return gP(this.decoder)}readVarString(){return vP(this.decoder)}readVarUint8Array(){return mP(this.decoder)}writeVarUint(e){return YN(this.encoder,e)}writeVarString(e){return QN(this.encoder,e)}writeVarUint8Array(e){return eP(this.encoder,e)}length(){return WN(this.encoder)}},dH=function(e){return e[e.Sync=0]=`Sync`,e[e.Awareness=1]=`Awareness`,e[e.Auth=2]=`Auth`,e[e.QueryAwareness=3]=`QueryAwareness`,e[e.Stateless=5]=`Stateless`,e[e.CLOSE=7]=`CLOSE`,e[e.SyncStatus=8]=`SyncStatus`,e[e.Ping=9]=`Ping`,e[e.Pong=10]=`Pong`,e}({}),fH=function(e){return e.Connecting=`connecting`,e.Connected=`connected`,e.Disconnected=`disconnected`,e}({}),pH=class{constructor(){this.encoder=UN()}get(e){return e.encoder}toUint8Array(){return GN(this.encoder)}},qHe=class extends pH{constructor(...e){super(...e),this.type=dH.CLOSE,this.description=`Ask the server to close the connection`}get(e){return QN(this.encoder,e.documentName),YN(this.encoder,this.type),this.encoder}},JHe=class e extends KHe{static{this.DEDUPLICATABLE_TYPES=new Set([dH.Awareness,dH.QueryAwareness])}constructor(e){super(),this.messageQueue=[],this.configuration={url:``,autoConnect:!0,preserveTrailingSlash:!1,document:void 0,WebSocketPolyfill:void 0,messageReconnectTimeout:3e4,delay:1e3,initialDelay:0,factor:2,maxAttempts:0,minDelay:1e3,maxDelay:3e4,jitter:!0,timeout:0,onOpen:()=>null,onConnect:()=>null,onMessage:()=>null,onOutgoingMessage:()=>null,onStatus:()=>null,onDisconnect:()=>null,onClose:()=>null,onMaxAttemptsFailed:()=>null,onDestroy:()=>null,onAwarenessUpdate:()=>null,onAwarenessChange:()=>null,handleTimeout:null,providerMap:new Map},this.webSocket=null,this.webSocketHandlers={},this.shouldConnect=!0,this.status=fH.Disconnected,this.lastMessageReceived=0,this.identifier=0,this.intervals={connectionChecker:null},this.connectionAttempt=null,this.receivedOnOpenPayload=void 0,this.closeTries=0,this.setConfiguration(e),this.configuration.WebSocketPolyfill=e.WebSocketPolyfill?e.WebSocketPolyfill:WebSocket,this.on(`open`,this.configuration.onOpen),this.on(`open`,this.onOpen.bind(this)),this.on(`connect`,this.configuration.onConnect),this.on(`message`,this.configuration.onMessage),this.on(`outgoingMessage`,this.configuration.onOutgoingMessage),this.on(`status`,this.configuration.onStatus),this.on(`disconnect`,this.configuration.onDisconnect),this.on(`close`,this.configuration.onClose),this.on(`maxAttemptsFailed`,this.configuration.onMaxAttemptsFailed),this.on(`destroy`,this.configuration.onDestroy),this.on(`awarenessUpdate`,this.configuration.onAwarenessUpdate),this.on(`awarenessChange`,this.configuration.onAwarenessChange),this.on(`close`,this.onClose.bind(this)),this.on(`message`,this.onMessage.bind(this)),this.intervals.connectionChecker=setInterval(this.checkConnection.bind(this),this.configuration.messageReconnectTimeout/10),this.shouldConnect&&this.connect()}async onOpen(e){this.status=fH.Connected,this.emit(`status`,{status:fH.Connected}),this.cancelWebsocketRetry=void 0,this.receivedOnOpenPayload=e}attach(e){let t=e.effectiveName,n=this.configuration.providerMap.get(t);if(n&&n!==e&&n.isAuthenticated)throw Error(`Cannot attach two providers with the same effective name "${t}". Use sessionAwareness: true to multiplex providers with the same document name.`);this.configuration.providerMap.set(t,e),this.status===fH.Disconnected&&this.shouldConnect&&this.connect(),this.receivedOnOpenPayload&&this.status===fH.Connected&&e.onOpen(this.receivedOnOpenPayload)}detach(e){let t=e.effectiveName;this.configuration.providerMap.has(t)&&(e.send(qHe,{documentName:t}),this.configuration.providerMap.delete(t))}setConfiguration(e={}){this.configuration={...this.configuration,...e},this.configuration.autoConnect||(this.shouldConnect=!1)}async connect(){if(this.status===fH.Connected)return;this.cancelWebsocketRetry&&=(this.cancelWebsocketRetry(),void 0),this.receivedOnOpenPayload=void 0,this.shouldConnect=!0;let{retryPromise:e,cancelFunc:t}=(()=>{let e=!1;return{retryPromise:RHe(this.createWebSocketConnection.bind(this),{delay:this.configuration.delay,initialDelay:this.configuration.initialDelay,factor:this.configuration.factor,maxAttempts:this.configuration.maxAttempts,minDelay:this.configuration.minDelay,maxDelay:this.configuration.maxDelay,jitter:this.configuration.jitter,timeout:this.configuration.timeout,handleTimeout:this.configuration.handleTimeout,beforeAttempt:t=>{(!this.shouldConnect||e)&&t.abort()}}).catch(e=>{e?.code!==`ATTEMPT_ABORTED`&&this.emit(`maxAttemptsFailed`,{error:e})}),cancelFunc:()=>{e=!0}}})();return this.cancelWebsocketRetry=t,e}attachWebSocketListeners(e,t){let{identifier:n}=e,r=e=>this.emit(`message`,e),i=e=>this.emit(`close`,{event:e}),a=e=>this.emit(`open`,e),o=e=>{t(e)};this.webSocketHandlers[n]={message:r,close:i,open:a,error:o};let s=this.webSocketHandlers[e.identifier];Object.keys(s).forEach(t=>{e.addEventListener(t,s[t])})}cleanupWebSocket(){if(!this.webSocket)return;let{identifier:e}=this.webSocket,t=this.webSocketHandlers[e];Object.keys(t).forEach(n=>{this.webSocket?.removeEventListener(n,t[n]),delete this.webSocketHandlers[e]}),this.webSocket.close(),this.webSocket=null}createWebSocketConnection(){return new Promise((e,t)=>{this.webSocket&&(this.messageQueue=[],this.cleanupWebSocket()),this.lastMessageReceived=0,this.identifier+=1;let n=new this.configuration.WebSocketPolyfill(this.url);n.binaryType=`arraybuffer`,n.identifier=this.identifier,this.attachWebSocketListeners(n,t),this.webSocket=n,this.status=fH.Connecting,this.emit(`status`,{status:fH.Connecting}),this.connectionAttempt={resolve:e,reject:t}})}onMessage(e){this.resolveConnectionAttempt(),this.lastMessageReceived=DP();let t=new Uint8Array(e.data);if(t.length===1&&t[0]===dH.Ping){this.sendPong();return}let n=new uH(t).peekVarString();this.configuration.providerMap.get(n)?.onMessage(e)}sendPong(){let e=UN();YN(e,dH.Pong),this.send(GN(e))}resolveConnectionAttempt(){this.connectionAttempt&&(this.connectionAttempt.resolve(),this.connectionAttempt=null,this.status=fH.Connected,this.emit(`status`,{status:fH.Connected}),this.emit(`connect`),this.messageQueue.forEach(e=>this.send(e)),this.messageQueue=[])}stopConnectionAttempt(){this.connectionAttempt=null}rejectConnectionAttempt(e){this.connectionAttempt?.reject(e),this.connectionAttempt=null}checkConnection(){this.status===fH.Connected&&this.lastMessageReceived&&(this.configuration.messageReconnectTimeout>=DP()-this.lastMessageReceived||(this.closeTries+=1,this.closeTries>2?(this.onClose({event:{code:4408,reason:`forced`}}),this.closeTries=0):(this.webSocket?.close(),this.messageQueue=[])))}get serverUrl(){if(this.configuration.preserveTrailingSlash)return this.configuration.url;let e=this.configuration.url;for(;e[e.length-1]===`/`;)e=e.slice(0,e.length-1);return e}get url(){return this.serverUrl}disconnect(){if(this.shouldConnect=!1,this.webSocket!==null)try{this.webSocket.close(),this.messageQueue=[]}catch(e){console.error(e)}}parseQueuedMessage(e){try{let t=pP(e);return{documentName:vP(t),messageType:gP(t)}}catch{return null}}addToQueue(t){if(t instanceof Uint8Array){let n=this.parseQueuedMessage(t);n&&e.DEDUPLICATABLE_TYPES.has(n.messageType)&&(this.messageQueue=this.messageQueue.filter(e=>{if(!(e instanceof Uint8Array))return!0;let t=this.parseQueuedMessage(e);return t?!(t.documentName===n.documentName&&t.messageType===n.messageType):!0}))}this.messageQueue.push(t)}send(e){this.webSocket?.readyState===NHe.Open?this.webSocket.send(e):this.addToQueue(e)}onClose({event:e}){this.closeTries=0,this.cleanupWebSocket(),this.connectionAttempt&&this.rejectConnectionAttempt(Error(`WebSocket closed before the connection was established (code: ${e?.code}, reason: ${e?.reason||`none`})`)),this.status=fH.Disconnected,this.emit(`status`,{status:fH.Disconnected}),this.emit(`disconnect`,{event:e}),!this.cancelWebsocketRetry&&this.shouldConnect&&setTimeout(()=>{this.connect()},this.configuration.delay)}destroy(){this.emit(`destroy`),clearInterval(this.intervals.connectionChecker),this.stopConnectionAttempt(),this.disconnect(),this.removeAllListeners(),this.cleanupWebSocket()}},YHe=class{constructor(e){this.message=e}apply(e,t){let{message:n}=this,r=n.readVarUint(),i=n.length();switch(r){case dH.Sync:this.applySyncMessage(e,t);break;case dH.Awareness:this.applyAwarenessMessage(e);break;case dH.Auth:this.applyAuthMessage(e);break;case dH.QueryAwareness:this.applyQueryAwarenessMessage(e);break;case dH.Stateless:e.receiveStateless(vP(n.decoder));break;case dH.SyncStatus:this.applySyncStatusMessage(e,_P(n.decoder)===1);break;case dH.CLOSE:{let t={code:1e3,reason:vP(n.decoder)};e.onClose(),e.configuration.onClose({event:t}),e.forwardClose({event:t});break}default:console.error(`Can’t apply message of unknown type: ${r}`)}n.length()>i+1&&e.send(pH,{encoder:n.encoder})}applySyncMessage(e,t){let{message:n}=this;n.writeVarUint(dH.Sync);let r=GHe(n.decoder,n.encoder,e.document,e);t&&r===1&&(e.synced=!0)}applySyncStatusMessage(e,t){t&&e.decrementUnsyncedChanges()}applyAwarenessMessage(e){if(!e.awareness)return;let{message:t}=this;FHe(e.awareness,t.readVarUint8Array(),e)}applyAuthMessage(e){let{message:t}=this;OHe(t.decoder,e.sendToken.bind(e),e.permissionDeniedHandler.bind(e),e.authenticatedHandler.bind(e))}applyQueryAwarenessMessage(e){if(!e.awareness)return;let{message:t}=this;t.writeVarUint(dH.Awareness),t.writeVarUint8Array(cH(e.awareness,Array.from(e.awareness.getStates().keys())))}},XHe=class{constructor(e,t={}){this.message=new e,this.encoder=this.message.get(t)}create(){return GN(this.encoder)}send(e){e?.send(this.create())}},ZHe=`4.7.0`,QHe=class extends pH{constructor(...e){super(...e),this.type=dH.Auth,this.description=`Authentication`}get(e){if(e.token===void 0)throw Error("The authentication message requires `token` as an argument.");return QN(this.encoder,e.documentName),YN(this.encoder,this.type),DHe(this.encoder,e.token),QN(this.encoder,ZHe),this.encoder}},mH=class extends pH{constructor(...e){super(...e),this.type=dH.Awareness,this.description=`Awareness states update`}get(e){if(e.awareness===void 0)throw Error(`The awareness message requires awareness as an argument`);if(e.clients===void 0)throw Error(`The awareness message requires clients as an argument`);QN(this.encoder,e.documentName),YN(this.encoder,this.type);let t;return t=e.states===void 0?cH(e.awareness,e.clients):cH(e.awareness,e.clients,e.states),eP(this.encoder,t),this.encoder}},$He=class extends pH{constructor(...e){super(...e),this.type=dH.Stateless,this.description=`A stateless message`}get(e){return QN(this.encoder,e.documentName),YN(this.encoder,this.type),QN(this.encoder,e.payload??``),this.encoder}},hH=class extends pH{constructor(...e){super(...e),this.type=dH.Sync,this.description=`First sync step`}get(e){if(e.document===void 0)throw Error(`The sync step one message requires document as an argument`);return QN(this.encoder,e.documentName),YN(this.encoder,this.type),zHe(this.encoder,e.document),this.encoder}},eUe=class extends pH{constructor(...e){super(...e),this.type=dH.Sync,this.description=`A document update`}get(e){return QN(this.encoder,e.documentName),YN(this.encoder,this.type),UHe(this.encoder,e.update),this.encoder}},tUe=class extends Error{constructor(...e){super(...e),this.code=1001}},nUe=class extends KHe{get effectiveName(){return this.configuration.sessionAwareness?jHe(this.configuration.name,this.sessionId):this.configuration.name}constructor(e){super(),this.configuration={name:``,document:void 0,awareness:void 0,token:null,sessionAwareness:!1,forceSyncInterval:!1,flushDelay:!1,onAuthenticated:()=>null,onAuthenticationFailed:()=>null,onOpen:()=>null,onConnect:()=>null,onMessage:()=>null,onOutgoingMessage:()=>null,onSynced:()=>null,onStatus:()=>null,onDisconnect:()=>null,onClose:()=>null,onDestroy:()=>null,onAwarenessUpdate:()=>null,onAwarenessChange:()=>null,onStateless:()=>null,onUnsyncedChanges:()=>null},this.isSynced=!1,this.unsyncedChanges=0,this.isAuthenticated=!1,this.authorizedScope=void 0,this.manageSocket=!1,this._isAttached=!1,this.pendingUpdates=[],this.pendingAwarenessClients=new Set,this.flushTimeout=null,this.sessionId=Math.random().toString(36).slice(2),this.intervals={forceSync:null},this.boundDocumentUpdateHandler=this.documentUpdateHandler.bind(this),this.boundAwarenessUpdateHandler=this.awarenessUpdateHandler.bind(this),this.boundPageHide=this.pageHide.bind(this),this.boundOnOpen=this.onOpen.bind(this),this.boundOnClose=this.onClose.bind(this),this.forwardConnect=()=>this.emit(`connect`),this.forwardStatus=e=>this.emit(`status`,e),this.forwardClose=e=>this.emit(`close`,e),this.forwardDisconnect=e=>this.emit(`disconnect`,e),this.forwardDestroy=()=>this.emit(`destroy`),this.setConfiguration(e),this.configuration.document=e.document?e.document:new GF,this.configuration.awareness=e.awareness===void 0?new oH(this.document):e.awareness,this.on(`open`,this.configuration.onOpen),this.on(`message`,this.configuration.onMessage),this.on(`outgoingMessage`,this.configuration.onOutgoingMessage),this.on(`synced`,this.configuration.onSynced),this.on(`destroy`,this.configuration.onDestroy),this.on(`awarenessUpdate`,this.configuration.onAwarenessUpdate),this.on(`awarenessChange`,this.configuration.onAwarenessChange),this.on(`stateless`,this.configuration.onStateless),this.on(`unsyncedChanges`,this.configuration.onUnsyncedChanges),this.on(`authenticated`,this.configuration.onAuthenticated),this.on(`authenticationFailed`,this.configuration.onAuthenticationFailed),this.awareness?.on(`update`,()=>{this.emit(`awarenessUpdate`,{states:kHe(this.awareness.getStates())})}),this.awareness?.on(`change`,()=>{this.emit(`awarenessChange`,{states:kHe(this.awareness.getStates())})}),this.document.on(`update`,this.boundDocumentUpdateHandler),this.awareness?.on(`update`,this.boundAwarenessUpdateHandler),this.registerEventListeners(),this.configuration.forceSyncInterval&&typeof this.configuration.forceSyncInterval==`number`&&(this.intervals.forceSync=setInterval(this.forceSync.bind(this),this.configuration.forceSyncInterval)),this.manageSocket&&this.attach()}setConfiguration(e={}){e.websocketProvider||(this.manageSocket=!0,this.configuration.websocketProvider=new JHe(e)),this.configuration={...this.configuration,...e}}get document(){return this.configuration.document}get isAttached(){return this._isAttached}get awareness(){return this.configuration.awareness}get hasUnsyncedChanges(){return this.unsyncedChanges>0}resetUnsyncedChanges(){this.unsyncedChanges=1,this.emit(`unsyncedChanges`,{number:this.unsyncedChanges})}incrementUnsyncedChanges(){this.unsyncedChanges+=1,this.emit(`unsyncedChanges`,{number:this.unsyncedChanges})}decrementUnsyncedChanges(){this.unsyncedChanges>0&&--this.unsyncedChanges,this.unsyncedChanges===0&&(this.synced=!0),this.emit(`unsyncedChanges`,{number:this.unsyncedChanges})}forceSync(){this.resetUnsyncedChanges(),this.send(hH,{document:this.document,documentName:this.effectiveName})}pageHide(){this.awareness&&sH(this.awareness,[this.document.clientID],`page hide`)}registerEventListeners(){typeof window>`u`||!(`addEventListener`in window)||window.addEventListener(`pagehide`,this.boundPageHide)}sendStateless(e){this.send($He,{documentName:this.effectiveName,payload:e})}async sendToken(){let e;try{e=await this.getToken()}catch(e){this.permissionDeniedHandler(`Failed to get token during sendToken(): ${e}`);return}this.send(QHe,{token:e??``,documentName:this.effectiveName})}get batchingEnabled(){return!!this.configuration.flushDelay&&typeof this.configuration.flushDelay==`number`}documentUpdateHandler(e,t){if(t!==this){if(!this.batchingEnabled){this.incrementUnsyncedChanges(),this.send(eUe,{update:e,documentName:this.effectiveName});return}this.pendingUpdates.length===0&&this.incrementUnsyncedChanges(),this.pendingUpdates.push(e),this.scheduleFlush()}}awarenessUpdateHandler({added:e,updated:t,removed:n},r){if(r===this)return;let i=e.concat(t).concat(n);if(!this.batchingEnabled){this.send(mH,{awareness:this.awareness,clients:i,documentName:this.effectiveName});return}for(let e of i)this.pendingAwarenessClients.add(e);this.scheduleFlush()}scheduleFlush(){this.flushTimeout===null&&(this.flushTimeout=setTimeout(()=>{this.flushTimeout=null,this.flushPendingUpdates()},this.configuration.flushDelay))}flushPendingUpdates(){if(this.flushTimeout!==null&&(clearTimeout(this.flushTimeout),this.flushTimeout=null),this.pendingUpdates.length>0){let e=this.pendingUpdates.length===1?this.pendingUpdates[0]:KIe(this.pendingUpdates);this.pendingUpdates=[],this.send(eUe,{update:e,documentName:this.effectiveName})}if(this.pendingAwarenessClients.size>0){let e=Array.from(this.pendingAwarenessClients);this.pendingAwarenessClients.clear(),this.send(mH,{awareness:this.awareness,clients:e,documentName:this.effectiveName})}}get synced(){return this.isSynced}set synced(e){this.isSynced!==e&&(this.isSynced=e,e&&this.emit(`synced`,{state:e}))}receiveStateless(e){this.emit(`stateless`,{payload:e})}async connect(){if(this.manageSocket)return this.configuration.websocketProvider.connect();console.warn(`HocuspocusProvider::connect() is deprecated and does not do anything. Please connect/disconnect on the websocketProvider, or attach/deattach providers.`)}disconnect(){if(this.manageSocket)return this.configuration.websocketProvider.disconnect();console.warn(`HocuspocusProvider::disconnect() is deprecated and does not do anything. Please connect/disconnect on the websocketProvider, or attach/deattach providers.`)}async onOpen(e){this.isAuthenticated=!1,this.emit(`open`,{event:e}),await this.sendToken(),this.startSync()}async getToken(){return typeof this.configuration.token==`function`?await this.configuration.token():this.configuration.token}startSync(){this.resetUnsyncedChanges(),this.send(hH,{document:this.document,documentName:this.effectiveName}),this.awareness&&this.awareness.getLocalState()!==null&&this.send(mH,{awareness:this.awareness,clients:[this.document.clientID],documentName:this.effectiveName})}send(e,t){if(!this._isAttached)return;let n=new XHe(e,t);this.emit(`outgoingMessage`,{message:n.message}),n.send(this.configuration.websocketProvider)}onMessage(e){let t=new uH(e.data),{documentName:n}=MHe(t.readVarString());t.writeVarString(this.effectiveName),this.emit(`message`,{event:e,message:new uH(e.data)}),new YHe(t).apply(this,!0)}onClose(){this.isAuthenticated=!1,this.synced=!1,this.flushTimeout!==null&&(clearTimeout(this.flushTimeout),this.flushTimeout=null),this.pendingUpdates=[],this.pendingAwarenessClients.clear(),this.awareness&&sH(this.awareness,Array.from(this.awareness.getStates().keys()).filter(e=>e!==this.document.clientID),this)}destroy(){this.emit(`destroy`),this.intervals.forceSync&&clearInterval(this.intervals.forceSync),this.awareness&&(sH(this.awareness,[this.document.clientID],`provider destroy`),this.awareness.off(`update`,this.boundAwarenessUpdateHandler),this.awareness.destroy()),this.flushPendingUpdates(),this.document.off(`update`,this.boundDocumentUpdateHandler),this.removeAllListeners(),this.detach(),this.manageSocket&&this.configuration.websocketProvider.destroy(),!(typeof window>`u`||!(`removeEventListener`in window))&&window.removeEventListener(`pagehide`,this.boundPageHide)}detach(){this.configuration.websocketProvider.off(`connect`,this.configuration.onConnect),this.configuration.websocketProvider.off(`connect`,this.forwardConnect),this.configuration.websocketProvider.off(`status`,this.forwardStatus),this.configuration.websocketProvider.off(`status`,this.configuration.onStatus),this.configuration.websocketProvider.off(`open`,this.boundOnOpen),this.configuration.websocketProvider.off(`close`,this.boundOnClose),this.configuration.websocketProvider.off(`close`,this.configuration.onClose),this.configuration.websocketProvider.off(`close`,this.forwardClose),this.configuration.websocketProvider.off(`disconnect`,this.configuration.onDisconnect),this.configuration.websocketProvider.off(`disconnect`,this.forwardDisconnect),this.configuration.websocketProvider.off(`destroy`,this.configuration.onDestroy),this.configuration.websocketProvider.off(`destroy`,this.forwardDestroy),this.configuration.websocketProvider.detach(this),this._isAttached=!1}attach(){this._isAttached||=(this.configuration.websocketProvider.on(`connect`,this.configuration.onConnect),this.configuration.websocketProvider.on(`connect`,this.forwardConnect),this.configuration.websocketProvider.on(`status`,this.configuration.onStatus),this.configuration.websocketProvider.on(`status`,this.forwardStatus),this.configuration.websocketProvider.on(`open`,this.boundOnOpen),this.configuration.websocketProvider.on(`close`,this.boundOnClose),this.configuration.websocketProvider.on(`close`,this.configuration.onClose),this.configuration.websocketProvider.on(`close`,this.forwardClose),this.configuration.websocketProvider.on(`disconnect`,this.configuration.onDisconnect),this.configuration.websocketProvider.on(`disconnect`,this.forwardDisconnect),this.configuration.websocketProvider.on(`destroy`,this.configuration.onDestroy),this.configuration.websocketProvider.on(`destroy`,this.forwardDestroy),this.configuration.websocketProvider.attach(this),!0)}permissionDeniedHandler(e){this.emit(`authenticationFailed`,{reason:e}),this.isAuthenticated=!1}authenticatedHandler(e){this.isAuthenticated=!0,this.authorizedScope=e,this.emit(`authenticated`,{scope:e})}setAwarenessField(e,t){if(!this.awareness)throw new tUe(`Cannot set awareness field "${e}" to ${JSON.stringify(t)}. You have disabled Awareness for this provider by explicitly passing awareness: null in the provider configuration.`);this.awareness.setLocalStateField(e,t)}},gH=`design:`,rUe=e=>`${gH}${e}`,iUe=e=>{let t=``;for(let n=0;n<e.length;n+=32768)t+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(t)},_H=e=>Uint8Array.from(atob(e),e=>e.charCodeAt(0)),aUe=Symbol(`tool-sync`);function oUe(e,t,{canvasId:n,sync:r,onStatus:i,intervalMs:a=1e3}){let o,s=!1,c,l=async()=>{try{let a=await r({canvasId:n,clientId:e.clientID,stateVector:iUe(kIe(e)),update:iUe(OIe(e,o)),awareness:iUe(cH(t,[e.clientID]))});if(s)return;tI(e,_H(a.update),aUe),o=_H(a.stateVector),a.awareness&&FHe(t,_H(a.awareness),aUe),i(`connected`)}catch{s||i(`disconnected`)}s||(c=setTimeout(l,a))};return l(),()=>{s=!0,clearTimeout(c)}}var sUe=1e3;function cUe(e,t=33,n=sUe){let r,i,a=-1/0,o=()=>e.getStates().size<=1,s=()=>{if(clearTimeout(i),i=void 0,!r)return;let t=r;r=void 0,a=performance.now(),e.setLocalState({...e.getLocalState(),...t})},c=({added:t})=>{r&&t.some(t=>t!==e.clientID)&&s()};return e.on(`change`,c),{send:e=>{if(r={...r,...e},i)return;let c=o()?n:t;i=setTimeout(s,Math.max(0,c-(performance.now()-a)))},flush:s,destroy:()=>{clearTimeout(i),r=void 0,e.off(`change`,c)}}}var vH=[],lUe=e=>{let t=[];return e.getStates().forEach((e,n)=>{e.user&&t.push({clientId:n,...e.user,activity:e.activity,pointer:e.pointer??null,selection:e.selection??[],viewport:e.viewport,connecting:e.connecting})}),t},uUe=e=>[e.clientId,e.name,e.color,e.picture??``,+!!e.agent,e.activity??``,+!!e.pointer].join(`|`);function dUe(e){let t=new Set,n=lUe(e),r=null,i=n,a=n,o=JSON.stringify(e.getLocalState()?.user??null),s=()=>{i=r?[...n,r]:n;let e=i.length?i:vH;e.map(uUe).join()!==a.map(uUe).join()&&(a=e),t.forEach(e=>e())},c=({added:t,updated:r,removed:i})=>{let a=[...t,...r,...i].some(t=>t!==e.clientID),c=JSON.stringify(e.getLocalState()?.user??null);!a&&c===o||(o=c,n=lUe(e),s())};return e.on(`change`,c),{subscribe:e=>(t.add(e),()=>t.delete(e)),getPeers:()=>i,getPeople:()=>a,setLocalAgent:e=>{r=e,s()},destroy:()=>{e.off(`change`,c),t.clear()}}}var fUe={subscribe:()=>()=>{},getPeers:()=>vH,getPeople:()=>vH},yH=e=>{let t=e??fUe;return(0,h.useSyncExternalStore)(t.subscribe,t.getPeople)},pUe=4e3,bH=500,xH=Symbol(`studio-local`),mUe=Symbol(`studio-browser-agent`),SH=Symbol(`studio-status`),hUe=Symbol(`studio-open`),gUe=Symbol(`studio-level-placement`),_Ue={1:new Map,2:new Map},vUe=[`text`,`fontSize`,`angle`],yUe={status:`draft`,history:[]};function bUe({canvasId:e,socketUrl:t,name:n,color:r,picture:i,agent:a,syncViaTools:o,onLayout:s,onContainerResize:c}){let l=(0,h.useRef)(null),[u,d]=(0,h.useState)([]),[f,p]=(0,h.useState)([]),[m,g]=(0,h.useState)(`connecting`),[_,v]=(0,h.useState)(null),[y,b]=(0,h.useState)(null),[x,S]=(0,h.useState)(null),[C,w]=(0,h.useState)({canUndo:!1,canRedo:!1}),[T,E]=(0,h.useState)(),[ee,te]=(0,h.useState)(),[ne,re]=(0,h.useState)(``),[ie,ae]=(0,h.useState)(_Ue),[oe,se]=(0,h.useState)(yUe),[ce,le]=(0,h.useState)(`websocket`),[ue,de]=(0,h.useState)(!1),[fe,pe]=(0,h.useState)([]),[me,he]=(0,h.useState)(null),[ge,_e]=(0,h.useState)(!1),ve=(0,h.useRef)({name:n,color:r});ve.current={name:n,color:r,...i&&{picture:i},...a&&{agent:a}};let ye=(0,h.useRef)(s);ye.current=s;let be=(0,h.useRef)(c);be.current=c,(0,h.useEffect)(()=>{d([]),p([]);let n=new GF,{nodes:r,edges:i,threads:a,meta:s,levelLayouts:c,hotspots:u}=SR(n),f=e=>{let t=new Set([...e.keysChanged].map(e=>Number(e.split(`:`)[0])));ae(e=>{let r={...e};return t.forEach(e=>r[e]=gRe(n,e)),r})};c.observe(f),ae(_Ue);let m=e=>{let t=TR(n);E(t.title),e.keysChanged.has(`diagramLevels`)&&te(t.diagramLevels),(e.keysChanged.has(`status`)||e.keysChanged.has(`statusHistory`))&&se({status:DR(t),history:t.statusHistory??[]}),e.keysChanged.has(`layoutAt`)&&ye.current?.(),e.keysChanged.has(`lockedBy`)&&he(mRe(n))};s.observe(m),he(null);let h=()=>pe(KR(n));u.observe(h),pe([]),E(void 0),re(``),te(void 0),se(yUe);let _=e=>{if(!e.local||e.origin===SH||!SRe(e))return;let t=e.origin===mUe?{name:`${ve.current.name}'s agent`,color:ve.current.color,agent:!0}:ve.current;queueMicrotask(()=>n.transact(()=>{xRe(n,t),TR(n).createdAt||ER(n,{createdAt:Date.now(),createdBy:t.name})},SH))};n.on(`afterTransaction`,_);let y=e=>{e.origin!==xH&&SRe(e)&&re(ORe(Array.from(r.values()),Array.from(i.values())))};n.on(`afterTransaction`,y);let x=new oH(n);x.setLocalStateField(`user`,ve.current);let C=dUe(x);v(C);let T=cUe(x),ee=!1,ne=!1,ie,oe,ce=`connecting`,ue=!1,fe=()=>{ue=!0,clearTimeout(oe),ie?.(),ge.disconnect(),de(!0),g(`disconnected`)},me=()=>{!o||ie||(clearTimeout(oe),le(`tools`),ie=oUe(n,x,{canvasId:e,sync:o,onStatus:g}),ge.disconnect())},ge=new nUe({url:t,name:rUe(e),document:n,awareness:x,onStatus:({status:e})=>{ce=e,e!==`connected`&&(ne=!1),ie||g(e===`connected`&&!ne?`connecting`:e)},onSynced:({state:e})=>_e(e),onAuthenticated:()=>{ee=ne=!0,ie||g(`connected`)},onClose:({event:e})=>{e.reason===`canvas-deleted`&&fe()},onAuthenticationFailed:({reason:e})=>{if(e===`canvas-deleted`)return fe();if(o)return me();ge.disconnect(),g(`disconnected`)}});le(`websocket`),de(!1),_e(!1);let xe=()=>{!ie&&!ue&&ce===`disconnected`&&ge.connect()},Se=()=>{if(document.visibilityState===`visible`)return xe();T.send({pointer:null}),T.flush()};window.addEventListener(`online`,xe),document.addEventListener(`visibilitychange`,Se),o&&(oe=setTimeout(()=>!ee&&me(),pUe));let Ce=new UIe([r,i,a,c,u],{captureTimeout:500,trackedOrigins:new Set([null,xH])}),we=()=>w({canUndo:Ce.undoStack.length>0,canRedo:Ce.redoStack.length>0});Ce.on(`stack-item-added`,we),Ce.on(`stack-item-popped`,we),Ce.on(`stack-cleared`,we),w({canUndo:!1,canRedo:!1}),l.current={doc:n,awareness:x,undoManager:Ce,sender:T},b(n.clientID),S(n);let Te=new Map,D=new Set,Ee=Dz(e=>{let t=new Map([...e].filter(([e])=>Te.has(e)));t.size&&d(e=>tz(e,t))}),De=(e,t)=>{if(t===`local`)return;let i=new Map;x.getStates().forEach((e,t)=>{t===n.clientID||!e.moving||Object.entries(e.moving).forEach(([e,t])=>i.set(e,t))});let a=[...i].some(([e,{x:t,y:n}])=>Te.get(e)?.x!==t||Te.get(e)?.y!==n),o=[...Te.keys()].filter(e=>!i.has(e));if(Te=i,(a||o.length)&&Ee.set(i),o.length===0)return;let s=setTimeout(()=>{D.delete(s);let e=o.flatMap(e=>{let t=Te.has(e)?void 0:r.get(e);return t?[[e,t.position]]:[]});d(t=>tz(t,new Map(e)))},bH);D.add(s)};x.on(`change`,De);let Oe=``,ke=new Set,Ae=(e,t)=>{if(t===`local`)return;let i=new Map;x.getStates().forEach((e,t)=>{let r=e.editing;if(t===n.clientID||!r?.id)return;let{id:a,...o}=r;i.set(a,o)});let a=JSON.stringify([...i]);if(a===Oe)return;Oe=a;let o=ke;ke=new Set(i.keys()),d(e=>{let t;return e.forEach((n,a)=>{let s=i.get(n.id),c=o.has(n.id)?r.get(n.id)?.data:void 0,l=s??(c&&Object.fromEntries(vUe.map(e=>[e,c[e]])));!l||Object.entries(l).every(([e,t])=>n.data[e]===t)||(t??=[...e],t[a]={...n,data:{...n.data,...l}})}),t??e})};x.on(`change`,Ae);let je=e=>{e.transaction.origin!==xH&&(e.keysChanged.forEach(e=>Te.delete(e)),[...e.changes.keys].some(([e,t])=>{let n=r.get(e),i=t.oldValue;return t.action===`update`&&RL(n?.type)&&(n?.width!==i?.width||n?.height!==i?.height)})&&be.current?.(),d(t=>qRe(GRe(t,e.keysChanged,e=>r.get(e),URe),t)))},Me=e=>{e.transaction.origin!==xH&&p(t=>GRe(t,e.keysChanged,e=>i.get(e),WRe))};return r.observe(je),i.observe(Me),()=>{clearTimeout(oe),D.forEach(clearTimeout),window.removeEventListener(`online`,xe),document.removeEventListener(`visibilitychange`,Se),x.off(`change`,De),x.off(`change`,Ae),Ee.stop(),T.destroy(),ie?.(),r.unobserve(je),c.unobserve(f),i.unobserve(Me),s.unobserve(m),u.unobserve(h),n.off(`afterTransaction`,_),n.off(`afterTransaction`,y),C.destroy(),Ce.destroy(),ge.destroy(),n.destroy(),l.current=null,S(null),v(null)}},[e,t,o]),(0,h.useEffect)(()=>{l.current?.awareness.setLocalStateField(`user`,ve.current)},[n,r,i]);let xe=(0,h.useMemo)(()=>u.filter(e=>e.selected).map(e=>e.id).join(`,`),[u]);(0,h.useEffect)(()=>{l.current?.sender.send({selection:xe?xe.split(`,`):[]})},[xe]);let Se=(0,h.useRef)(u);Se.current=u;let Ce=()=>new Map(Se.current.flatMap(e=>e.measured?.width&&e.measured.height?[[e.id,{width:e.measured.width,height:e.measured.height}]]:[])),we=(e,t=null)=>{let n=l.current?.doc;return n?n.transact(()=>e(n),t):void 0},Te=(0,h.useRef)(new Map),D=(0,h.useRef)(new Map),Ee=e=>{Te.current.forEach((t,n)=>wRe(e,n,t)),D.current.forEach(({position:t,width:n,height:r},i)=>CRe(e,i,t,n!==void 0&&r!==void 0?{width:n,height:r}:void 0)),D.current=new Map,Te.current.clear();let t=l.current;t?.sender.send({moving:null}),queueMicrotask(()=>t?.sender.flush())},De=(0,h.useCallback)(e=>{d(t=>fl(e,t));let t=!1,n=[],r=[];for(let i of e)i.type===`position`&&i.position&&(Te.current.set(i.id,i.position),i.dragging||(t=!0)),i.type===`dimensions`&&i.setAttributes&&i.dimensions&&n.push({id:i.id,dimensions:i.dimensions,attributes:i.setAttributes}),i.type===`dimensions`&&i.resizing===!1&&r.push(i.id);t?(l.current?.undoManager.stopCapturing(),we(Ee,xH)):Te.current.size&&l.current?.sender.send({moving:Object.fromEntries(Te.current)}),n.length&&we(e=>n.forEach(({id:t,dimensions:n,attributes:r})=>TRe(e,t,n,r)),xH),r.length&&we(e=>r.forEach(t=>MR(e,t,Ce())));let i=e.filter(e=>e.type===`remove`).map(e=>e.id);i.length&&we(e=>BR(e,i))},[]),Oe=(0,h.useCallback)(e=>{p(t=>pl(e,t));let t=e.filter(e=>e.type===`remove`).map(e=>e.id);t.length&&we(e=>zR(e,t))},[]),ke=(0,h.useCallback)(e=>{we(t=>RR(t,e))},[]),Ae=(0,h.useCallback)((e,t)=>{we(n=>kRe(n,e.id,t))},[]),je=(0,h.useCallback)(e=>{D.current=e,d(t=>{let n;return t.forEach((r,i)=>{let a=e.get(r.id);!a||r.position.x===a.position.x&&r.position.y===a.position.y&&(a.width===void 0||r.width===a.width&&r.height===a.height)||(n??=[...t],n[i]={...r,...a})}),n??t})},[]),Me=(0,h.useCallback)((e,t,n,r,i)=>{let a=wR(e,t,n);return we(t=>{let o=Array.from(SR(t).nodes.values()),s=JL(e)?pR(n,o,i):void 0,c=s?{...a,parentId:s.id,position:fRe(a.position,s.id,o)}:a;kR(t,[c],r?.(c.id,o)??[]),s&&jR(t,s.id,Ce())}),a.id},[]),Ne=(0,h.useCallback)((e,t,n)=>{let r=HL(e);return r?Me(r.type,r.createData(),t,void 0,n):void 0},[Me]),Pe=(0,h.useCallback)((e,t)=>we(n=>PR(n,e,t)),[]),Fe=(0,h.useCallback)(e=>we(t=>BR(t,e)),[]),Ie=(0,h.useCallback)(e=>we(t=>rH(t,e)),[]),Le=(0,h.useCallback)((e,t,n=`person`)=>we(n=>vRe(n,e,t),n===`level`?gUe:null),[]),Re=(0,h.useCallback)((e,t=[])=>we(n=>{kR(n,e,t);let r=new Set(e.map(e=>e.id));new Set(e.flatMap(e=>e.parentId&&!r.has(e.parentId)?[e.parentId]:[])).forEach(e=>jR(n,e,Ce()))}),[]),ze=(0,h.useCallback)(e=>we(t=>(Te.current.size&&Ee(t),NR(t,e,Ce()))),[]),Be=(0,h.useCallback)((e,t)=>we(n=>OR(n,e,ve.current,t),SH),[]),Ve=(0,h.useCallback)(e=>we(t=>ER(t,{title:e||void 0})),[]),He=(0,h.useCallback)(()=>l.current?.undoManager.undo(),[]),Ue=(0,h.useCallback)(()=>l.current?.undoManager.redo(),[]),We=(0,h.useCallback)(e=>{l.current?.sender.send({pointer:e})},[]),Ge=(0,h.useCallback)(e=>{l.current?.sender.send({viewport:e})},[]),Ke=(0,h.useCallback)(e=>{let t=l.current?.sender;t&&(t.send({editing:e&&{...e,...e.text!==void 0&&{text:e.text.slice(0,2e3)}}}),e||t.flush())},[]),qe=(0,h.useCallback)(e=>we(t=>{kR(t,e.nodes,e.edges),e.threads?.length&&jRe(t,e.threads),e.hotspots?.length&&IRe(t,e.hotspots),vRe(t,1,e.levelLayouts[1]),vRe(t,2,e.levelLayouts[2])},hUe),[]);return{nodes:u,edges:f,status:m,presence:_,clientId:y,doc:x,onNodesChange:De,onEdgesChange:Oe,onConnect:ke,onReconnect:Ae,showDragPreview:je,addNode:Ne,insertNode:Me,updateNodeData:Pe,deleteNodes:Fe,applyPositions:Ie,levelLayouts:ie,setLevelLayout:Le,insertNodes:Re,setParents:ze,title:T,diagramLevels:ee,structureKey:ne,rename:Ve,canvasStatus:oe,changeStatus:Be,transport:ce,deleted:ue,hotspots:fe,createHotspot:(0,h.useCallback)(e=>we(t=>qR(t,e)),[]),updateHotspot:(0,h.useCallback)((e,t)=>we(n=>JR(n,e,t)),[]),deleteHotspot:(0,h.useCallback)(e=>we(t=>LRe(t,e)),[]),lockedBy:me,setLocked:(0,h.useCallback)(e=>we(t=>hRe(t,e),SH),[]),sendEditing:Ke,synced:ge,addContent:qe,undo:He,redo:Ue,...C,setPointer:We,setViewport:Ge}}var xUe=3e4,SUe=()=>document.modelContext??navigator.modelContext,CUe=!1,CH=e=>e,wUe=(e,t=!1)=>({content:[{type:`text`,text:JSON.stringify(e,null,2)}],...t&&{isError:t}});function TUe(e){let[t,n]=(0,h.useState)({state:`off`}),r=(0,h.useRef)(null),i=(0,h.useRef)(void 0),a=()=>{let{doc:e}=s.current;if(e)return{change:t=>e.transact(()=>t(e),mUe),present:e=>{let{agent:t,presence:n}=s.current;r.current=e.pointer,n?.setLocalAgent({clientId:-1,name:t.name,color:t.color,agent:!0,...e}),clearTimeout(i.current),i.current=setTimeout(()=>s.current.presence?.setLocalAgent(null),xUe)},lastPointer:r.current}},o=(0,h.useRef)(a);o.current=a;let s=(0,h.useRef)(e);return s.current=e,(0,h.useEffect)(()=>{if(!e.doc)return;if(!SUe()){if(!e.allowPolyfill)return;hHe(),CUe=!0}let t=SUe();if(!t)return;let r=new AbortController,i=TH(()=>s.current,()=>o.current()),a=e=>n(t=>t.state===`on`?{...t,lastCall:e}:t);return Promise.allSettled(i.map(e=>t.registerTool({name:e.name,title:e.title,description:e.description,inputSchema:_M(e.input,{io:`input`,unrepresentable:`any`}),annotations:e.annotations,execute:async t=>{let n=e.input.safeParse(t??{});if(!n.success)return wUe({error:Eke(n.error)},!0);a(e.name);try{let t=await e.execute(n.data);return wUe(t,!!t&&typeof t==`object`&&`error`in t)}catch(e){return wUe({error:String(e?.message??e)},!0)}}},{signal:r.signal}))).then(e=>{r.signal.aborted||n({state:`on`,source:CUe?`polyfill`:`native`,tools:e.length})}),()=>{r.abort(),n({state:`off`})}},[e.doc,e.allowPolyfill]),(0,h.useEffect)(()=>()=>clearTimeout(i.current),[]),t}var wH={error:`The canvas is not connected yet`},TH=(e,t)=>{let n=t=>{let{doc:n}=e();return n?n.transact(()=>t(n),mUe):wH},r=t=>{t.length&&(e().select(t),e().fitView(t))};return[CH({name:`get_canvas`,title:`Read the canvas`,description:`Reads the collaborative canvas open on this page: its nodes (ids, names, positions, the catalog resource they stand for), connections, comment threads, and who is on it. Call it first, and again to see what people changed.`,input:U({}),annotations:{readOnlyHint:!0,untrustedContentHint:!0},execute:()=>n(t=>({...uVe(t),people:e().getPeers().map(e=>`${e.name}${e.agent?` (agent)`:``}`)}))}),CH({name:`search_catalog`,title:`Search the catalog`,description:`Finds EventCatalog resources (domains, systems, services, events, commands, queries, channels, data stores) to add to the canvas with add_to_canvas.`,input:U({query:H().optional().describe(`Matches names and ids`),collection:$M(rRe).optional()}),annotations:{readOnlyHint:!0},execute:({query:t,collection:n})=>{let r=t?.toLowerCase();return e().resources.filter(e=>!n||e.collection===n).filter(e=>!r||`${e.name} ${e.id}`.toLowerCase().includes(r)).slice(0,50).map(({collection:e,id:t,name:n,version:r,summary:i})=>({collection:e,id:t,name:n,version:r,summary:i}))}}),CH({name:`add_to_canvas`,title:`Add to the canvas`,description:`${aVe} Use search_catalog to find catalog resources first.`,input:U({nodes:QBe,edges:$Be.optional()}),execute:async n=>{let i=t();if(!i)return wH;let a=await tH(i,n,e().catalog);return r(a.created.map(e=>e.nodeId)),a}}),CH({name:`update_node`,title:`Update a node`,description:`Renames, re-describes, re-versions or moves a node (x/y: its new centre). Catalog resources keep their catalog name, summary and version. For notes, summary is the note text.`,input:U({nodeId:H(),name:H().optional(),summary:H().optional(),version:H().optional().describe(`e.g. 1.0.0`),x:LM().optional(),y:LM().optional()}),execute:async e=>{let n=t();return n?EHe(n,e):wH}}),CH({name:`connect_nodes`,title:`Connect nodes`,description:`Draws connections between nodes (by id). Labels default to EventCatalog wording, e.g. "publishes event".`,input:U({edges:$Be.min(1)}),execute:async({edges:e})=>{let n=t();return n?nH(n,e):wH}}),CH({name:`remove_from_canvas`,title:`Remove from the canvas`,description:`Removes nodes (and their connections) or connections. Only remove what the user asked for.`,input:U({nodeIds:GM(H()).optional(),connectionIds:GM(H()).optional()}),annotations:{consequentialHint:!0},execute:async({nodeIds:e=[],connectionIds:n=[]})=>{let r=t();return r?(await iH(r,e,n),{removedNodes:e,removedConnections:n}):wH}}),CH({name:`layout_canvas`,title:`Tidy the canvas`,description:`Lays the whole canvas out again with EventCatalog's visualiser layout (left to right, connections routed around nodes), for everyone on it. Call it once when you finish a round of changes, before you hand back to the user, so the canvas is tidy for everyone, and whenever the user asks to tidy up. Don't call it after every change (add_to_canvas already places what you add next to what it connects to while you work), and skip it if the user asked to keep the layout as it is: it moves everything, including what people placed themselves.`,input:U({}),execute:async()=>(await e().reorder(),{laidOut:!0})}),CH({name:`set_canvas_status`,title:`Set the canvas status`,description:`Changes the canvas's status: draft (being worked on, where every canvas starts), proposed (ready for review), accepted (the agreed design) or rejected (decided against). Only change it when the user asks you to. Changing the nodes or connections on an accepted or rejected canvas makes it a draft again.`,input:U({status:$M(pRe),note:H().optional()}),execute:({status:t,note:r})=>n(n=>({status:t,changed:OR(n,t,e().agent,r)}))}),CH({name:`add_comment`,title:`Comment on the canvas`,description:`Starts a comment thread pinned to a node (nodeId) or a spot (x, y). Only use it when the user asks you to comment (e.g. to review the canvas). Don't use comments to greet people or ask the user questions: talk to them in the conversation.`,input:U({text:H(),nodeId:H().optional(),x:LM().optional(),y:LM().optional()}),execute:async n=>{let r=t();return r?wHe(r,n,e().agent):wH}}),CH({name:`reply_to_comment`,title:`Reply to a comment`,description:`Replies to a comment thread (threadId from get_canvas).`,input:U({threadId:H(),text:H()}),execute:({threadId:t,text:r})=>n(n=>NRe(n,t,r,e().agent)?{threadId:t}:{error:`No comment thread "${t}"`})}),CH({name:`resolve_comment`,title:`Resolve a comment`,description:`Resolves (or reopens) a comment thread.`,input:U({threadId:H(),resolved:RM().default(!0)}),execute:({threadId:e,resolved:t})=>n(n=>UR(n,e,t)?{threadId:e,resolved:t}:{error:`No comment thread "${e}"`})}),CH({name:`show_nodes`,title:`Show nodes to the user`,description:`Selects nodes and moves the view to them, to point the user at something. Leave out nodeIds to show the whole canvas.`,input:U({nodeIds:GM(H()).optional()}),execute:({nodeIds:t})=>(t?.length&&e().select(t),e().fitView(t),{shown:t??`everything`})})]};function EUe(e,t){let[n,r]=(0,h.useState)([]);(0,h.useEffect)(()=>{if(!e)return r([]);let{threads:t}=SR(e),n=()=>r(ARe(e));return n(),t.observeDeep(n),()=>t.unobserveDeep(n)},[e]);let i=(0,h.useCallback)((n,r)=>e?HR(e,n,r,t):void 0,[e,t]),a=(0,h.useCallback)((n,r)=>e&&NRe(e,n,r,t),[e,t]),o=(0,h.useCallback)((t,n)=>e&&UR(e,t,n),[e]),s=(0,h.useCallback)((t,n)=>e&&WR(e,t,n),[e]),c=(0,h.useCallback)(t=>e&&GR(e,t),[e]),l=(0,h.useCallback)(t=>e&&PRe(e,t),[e]);return{threads:n,createThread:i,reply:a,setResolved:o,moveThread:s,moveThreads:(0,h.useCallback)(t=>e&&FRe(e,t),[e]),deleteThread:c,deleteThreads:l}}var EH=[`#ef4444`,`#f97316`,`#eab308`,`#22c55e`,`#06b6d4`,`#3b82f6`,`#8b5cf6`,`#ec4899`],DH=EH,DUe=`eventcatalog-studio-name`,OUe=`eventcatalog-studio-color`,kUe=()=>{try{return localStorage.getItem(DUe)}catch{return null}},AUe=e=>{try{return localStorage.setItem(DUe,e),!0}catch{return!1}},OH=e=>{let t=t=>t.key===DUe&&e(t.newValue);return window.addEventListener(`storage`,t),()=>window.removeEventListener(`storage`,t)},kH=e=>{let t=0;for(let n of e)t=t*31+n.charCodeAt(0)|0;return DH[Math.abs(t)%DH.length]},jUe=()=>{try{let e=localStorage.getItem(OUe);return e&&EH.includes(e)?e:null}catch{return null}},MUe=e=>{try{return localStorage.setItem(OUe,e),!0}catch{return!1}},NUe=(0,h.memo)(function({status:e,history:t,onChange:n}){let[r,i]=(0,h.useState)(!1),[a,o]=(0,h.useState)(``),s=(0,h.useRef)(null),c=lB[e];(0,h.useEffect)(()=>{if(!r)return;let e=e=>{s.current?.contains(e.target)||i(!1)},t=e=>e.key===`Escape`&&i(!1);return window.addEventListener(`pointerdown`,e),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`pointerdown`,e),window.removeEventListener(`keydown`,t)}},[r]);let l=t=>{t!==e&&n(t,a),o(``),i(!1)},u=t.slice(-8).reverse();return(0,D.jsxs)(`div`,{ref:s,className:`relative`,children:[(0,D.jsxs)(`button`,{onClick:()=>i(e=>!e),"aria-label":`Status: ${c.label}`,"aria-expanded":r,className:`flex items-center gap-1 rounded-full border px-2 py-0.5 text-[11px] font-semibold ${c.pill}`,children:[c.label,(0,D.jsx)(S,{size:12})]}),r&&(0,D.jsxs)(`div`,{className:`absolute left-0 top-full mt-2 w-72 min-w-56 bg-[rgb(var(--ec-page-bg))] border border-[rgb(var(--ec-page-border))] rounded-lg shadow-xl z-50 py-1.5`,children:[(0,D.jsx)(`p`,{className:`px-3 pb-1 pt-1.5 text-[11px] font-semibold uppercase tracking-wide text-[rgb(var(--ec-page-text-muted))]`,children:`Status`}),pRe.map(t=>{let n=lB[t];return(0,D.jsxs)(`button`,{onClick:()=>l(t),className:`flex items-center px-3 py-2 text-xs text-[rgb(var(--ec-page-text))] hover:bg-[rgb(var(--ec-accent-subtle)/0.3)] cursor-pointer transition-colors gap-2 w-full text-left`,children:[(0,D.jsx)(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${n.dot}`}),(0,D.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,D.jsx)(`span`,{className:`block text-xs font-medium`,children:n.label}),(0,D.jsx)(`span`,{className:`block text-[11px] text-[rgb(var(--ec-page-text-muted))]`,children:n.description})]}),t===e&&(0,D.jsx)(x,{size:14,className:`shrink-0 text-[rgb(var(--ec-accent))]`})]},t)}),(0,D.jsx)(`div`,{className:`px-3 py-2`,children:(0,D.jsx)(`input`,{value:a,onChange:e=>o(e.target.value),placeholder:`Add a note (optional), then pick a status`,"aria-label":`Note for the status change`,className:`w-full rounded-md border px-2 py-1.5 text-xs bg-[rgb(var(--ec-input-bg))] border-[rgb(var(--ec-input-border))] text-[rgb(var(--ec-input-text))] placeholder:text-[rgb(var(--ec-page-text-muted))] focus:outline-none focus:border-[rgb(var(--ec-accent))]`})}),u.length>0&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`div`,{className:`my-1 h-px bg-[rgb(var(--ec-page-border))]`}),(0,D.jsx)(`p`,{className:`px-3 pb-1 pt-1.5 text-[11px] font-semibold uppercase tracking-wide text-[rgb(var(--ec-page-text-muted))]`,children:`History`}),(0,D.jsx)(`ul`,{className:`max-h-48 space-y-1.5 overflow-y-auto px-3 pb-2`,children:u.map(e=>(0,D.jsxs)(`li`,{className:`text-[11px]`,children:[(0,D.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,D.jsx)(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${lB[e.status].dot}`}),(0,D.jsx)(`span`,{className:`font-medium`,children:lB[e.status].label}),(0,D.jsxs)(`span`,{className:`text-[rgb(var(--ec-page-text-muted))]`,children:[`by `,e.by.name,` · `,mB(e.at)]})]}),e.note&&(0,D.jsx)(`span`,{className:`block pl-3 text-[rgb(var(--ec-page-text-muted))]`,children:e.note})]},`${e.at}-${e.status}`))})]})]})]})}),PUe={connected:cB.success.dot,connecting:cB.warning.dot,disconnected:cB.danger.dot},AH=`pointer-events-auto flex h-[38px] items-center rounded-[9px] border border-[rgb(var(--ec-page-border))] bg-[rgb(var(--ec-card-bg))] shadow-sm`,jH=`pointer-events-auto absolute top-full mt-2`,MH=`${jH} ${ZDe}`,FUe=`${$O} w-full text-left`,IUe=4,LUe=typeof navigator<`u`&&/Mac|iPhone|iPad/.test(navigator.platform)?`Cmd`:`Ctrl`,NH=`flex h-[34px] w-full cursor-pointer items-center gap-3 rounded-[7px] px-2 text-left text-sm outline-none hover:bg-[rgb(var(--ec-content-hover))]`,RUe=`flex flex-none [&_svg]:h-[17px] [&_svg]:w-[17px] [&_svg]:stroke-[1.75]`;function zUe(){let[e,t]=(0,h.useState)(!1),n=(0,h.useRef)(null);return(0,h.useEffect)(()=>{if(!e)return;let r=e=>{n.current?.contains(e.target)||t(!1)},i=e=>e.key===`Escape`&&t(!1);return window.addEventListener(`pointerdown`,r),window.addEventListener(`keydown`,i),()=>{window.removeEventListener(`pointerdown`,r),window.removeEventListener(`keydown`,i)}},[e]),{open:e,setOpen:t,ref:n}}function PH({peer:e,size:t=28,children:n}){return(0,D.jsxs)(`span`,{className:`relative flex items-center justify-center rounded-full text-[11px] font-semibold text-white ring-2 ring-[rgb(var(--ec-card-bg))]`,style:{backgroundColor:e.color,width:t,height:t},children:[n??(e.agent?(0,D.jsx)(fB,{name:e.name,size:14}):e.name.slice(0,2).toUpperCase()),!n&&(0,D.jsx)(uB,{src:e.picture})]})}function FH({title:e,status:t,transport:n,onRetitle:r,shareUrl:i,newCanvasUrl:a,onConnectAgent:o,webMcp:s,agentsHere:c,onDelete:l,onOpenFile:u,onSaveToFile:d,onExportImage:f,onLiveCollaboration:p,onHelp:m,children:g}){let _=zUe(),v=(0,h.useRef)(null),[y,b]=(0,h.useState)(null),x={connected:n===`tools`?`Connected through the chat`:`Connected`,connecting:`Connecting…`,disconnected:`Offline, reconnecting…`}[t],S=PUe[t],C=(e,t,n,r,i=``)=>(0,D.jsxs)(`button`,{type:`button`,className:`${NH} ${i}`,onClick:()=>{_.setOpen(!1),n()},children:[(0,D.jsx)(`span`,{className:RUe,children:e}),(0,D.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:t}),typeof r==`string`?(0,D.jsx)(`span`,{className:`flex-none text-xs font-normal text-[rgb(var(--ec-page-text-muted))]`,children:r}):r]});return(0,D.jsxs)(`div`,{ref:_.ref,className:`relative`,children:[(0,D.jsxs)(`div`,{className:`${AH} gap-1.5 pl-3 pr-1`,children:[(0,D.jsx)(`span`,{title:x,className:`h-2 w-2 shrink-0 rounded-full ${S}`}),(0,D.jsx)(`input`,{ref:v,"aria-label":`Canvas title`,value:y??e??``,placeholder:`Untitled canvas`,onChange:e=>b(e.target.value),onBlur:()=>{y!==null&&y.trim()!==(e??``)&&r(y.trim()),b(null)},onKeyDown:e=>e.key===`Enter`&&e.currentTarget.blur(),size:Math.max(12,(y??e??`Untitled canvas`).length),className:`${YDe} max-w-64 truncate rounded-md bg-transparent px-1.5 py-1 placeholder:text-[rgb(var(--ec-page-text-muted))] hover:bg-[rgb(var(--ec-page-border)/0.4)] focus:bg-[rgb(var(--ec-input-bg))] focus:outline-none`}),g,(0,D.jsx)(`button`,{"aria-label":`Canvas menu`,onClick:()=>_.setOpen(e=>!e),className:`group rounded-md p-1 hover:bg-[rgb(var(--ec-accent-subtle))]`,children:(0,D.jsx)(xe,{className:XDe})})]}),_.open&&(0,D.jsxs)(`div`,{className:`${jH} left-0 z-50 w-72 rounded-xl border border-[rgb(var(--ec-page-border))] bg-[rgb(var(--ec-card-bg))] p-1.5 text-[rgb(var(--ec-page-text))] shadow-xl`,children:[u&&C((0,D.jsx)(te,{}),`Open…`,u,`${LUe}+O`),C((0,D.jsx)(w,{}),`Save to file…`,d,`${LUe}+S`),C((0,D.jsx)(re,{}),`Export image…`,f,`${LUe}+Shift+E`),C((0,D.jsx)(_e,{}),`Live collaboration…`,p),C((0,D.jsx)(de,{}),c?`AI agent connected`:`Connect your AI agent…`,o,s.state===`on`||c?(0,D.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full ${cB.success.dot}`}):void 0),C((0,D.jsx)(ye,{}),`Help`,m,`?`),(0,D.jsx)(`div`,{className:`my-1.5 h-px bg-[rgb(var(--ec-page-border))]`}),C((0,D.jsx)(ue,{}),`Rename canvas`,()=>{v.current?.focus(),v.current?.select()}),C((0,D.jsx)(ae,{}),`Copy link`,()=>void navigator.clipboard.writeText(i??window.location.href)),a&&(0,D.jsxs)(`a`,{className:NH,href:a,children:[(0,D.jsx)(`span`,{className:RUe,children:(0,D.jsx)(fe,{})}),(0,D.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:`New canvas`})]}),l&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`div`,{className:`my-1.5 h-px bg-[rgb(var(--ec-page-border))]`}),C((0,D.jsx)(he,{}),`Delete canvas`,l,void 0,`${cB.danger.text} ${cB.danger.hover}`)]}),(0,D.jsx)(`div`,{className:`my-1.5 h-px bg-[rgb(var(--ec-page-border))]`}),(0,D.jsxs)(`p`,{className:`flex items-center gap-2 px-2 py-1.5 text-[11px] text-[rgb(var(--ec-page-text-muted))]`,children:[(0,D.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full ${S}`}),x]})]})]})}var BUe=e=>{let t=e.trim().split(/\s+/).filter(Boolean);return(t.length>1?t.map(e=>e[0]).join(``):e.trim()).slice(0,2).toUpperCase()};function VUe({me:e,onRename:t,onRecolor:n}){let r=zUe(),[i,a]=(0,h.useState)(e.name);(0,h.useEffect)(()=>a(e.name),[e.name]);let o=()=>{let n=i.trim();if(!n)return a(e.name);n!==e.name&&t?.(n)},s=(t,n)=>(0,D.jsxs)(`span`,{className:`relative flex ${t} flex-none items-center justify-center rounded-full text-[10px] font-semibold text-white`,style:{background:e.color},children:[BUe(n),(0,D.jsx)(uB,{src:e.picture})]});return e.agent?(0,D.jsx)(`span`,{title:`You're here as ${e.name} (AI agent)`,className:`${AH} pointer-events-auto w-[38px] justify-center`,children:(0,D.jsx)(`span`,{className:`flex h-6 w-6 items-center justify-center rounded-full text-white`,style:{background:e.color},children:(0,D.jsx)(fB,{name:e.name,size:14})})}):(0,D.jsxs)(`div`,{ref:r.ref,className:`pointer-events-auto relative`,children:[(0,D.jsx)(`button`,{type:`button`,title:t?`${e.name}: change your name and colour`:`${e.name}: change your colour`,onClick:()=>r.setOpen(e=>!e),className:`${AH} w-[38px] justify-center hover:bg-[rgb(var(--ec-content-hover))]`,children:s(`h-6 w-6`,e.name)}),r.open&&(0,D.jsxs)(`div`,{className:`${jH} right-0 z-[70] w-72 rounded-xl border border-[rgb(var(--ec-page-border))] bg-[rgb(var(--ec-card-bg))] p-4 text-[rgb(var(--ec-page-text))] shadow-xl`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-3`,children:[s(`h-9 w-9 text-xs`,i||e.name),(0,D.jsxs)(`div`,{className:`min-w-0`,children:[(0,D.jsx)(`p`,{className:`truncate text-sm font-semibold`,children:i||e.name}),(0,D.jsx)(`p`,{className:`text-xs text-[rgb(var(--ec-page-text-muted))]`,children:`On your pointer and comments`})]})]}),t&&(0,D.jsxs)(`label`,{className:`mt-4 block text-xs font-medium text-[rgb(var(--ec-page-text-muted))]`,children:[`Your name`,(0,D.jsx)(`input`,{value:i,maxLength:60,onChange:e=>a(e.target.value),onBlur:o,onKeyDown:e=>e.key===`Enter`&&e.currentTarget.blur(),className:`mt-1.5 block h-9 w-full rounded-md border border-[rgb(var(--ec-page-border))] bg-[rgb(var(--ec-page-bg))] px-3 text-sm text-[rgb(var(--ec-page-text))] outline-none focus:border-[rgb(var(--ec-accent))]`})]}),(0,D.jsxs)(`div`,{className:`mt-3 text-xs font-medium text-[rgb(var(--ec-page-text-muted))]`,children:[`Your colour`,(0,D.jsx)(`div`,{role:`radiogroup`,"aria-label":`Your colour`,className:`mt-2 flex gap-2`,children:EH.map(t=>(0,D.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":t===e.color,"aria-label":t,onClick:()=>n(t),className:`h-6 w-6 rounded-full transition-transform hover:scale-110 ${t===e.color?`ring-2 ring-[rgb(var(--ec-page-text))] ring-offset-2 ring-offset-[rgb(var(--ec-card-bg))]`:``}`,style:{background:t}},t))})]})]})]})}var HUe=(e,t,n)=>{let r=new Set(n.agent?[n.name]:[]);return e.filter(e=>e.clientId===t?!1:e.agent?r.has(e.name)?!1:(r.add(e.name),!0):!0)};function UUe({peers:e,clientId:t,me:n,onJumpTo:r}){let i=zUe(),a=HUe(e,t,n),o=a.slice(0,IUe),s=a.slice(IUe),c=e=>`${e.name}${e.agent?` (AI agent)${e.activity?`: ${e.activity}`:``}`:``}`;return(0,D.jsx)(`div`,{className:`flex items-center gap-1.5`,children:(0,D.jsxs)(`div`,{className:`flex -space-x-1.5`,children:[o.map(e=>(0,D.jsx)(`button`,{title:`${c(e)}. Click to jump to them`,onClick:()=>r(e),className:`block rounded-full transition-transform hover:z-10 hover:scale-110`,children:(0,D.jsx)(PH,{peer:e})},e.clientId)),s.length>0&&(0,D.jsxs)(`div`,{ref:i.ref,className:`relative`,children:[(0,D.jsxs)(`button`,{title:`${s.length} more`,onClick:()=>i.setOpen(e=>!e),className:`flex h-7 w-7 items-center justify-center rounded-full text-[11px] font-semibold ring-2 ring-[rgb(var(--ec-card-bg))] bg-[rgb(var(--ec-page-border))] text-[rgb(var(--ec-page-text))]`,children:[`+`,s.length]}),i.open&&(0,D.jsx)(`div`,{className:`${MH} right-0`,children:s.map(e=>(0,D.jsxs)(`button`,{className:FUe,onClick:()=>{r(e),i.setOpen(!1)},children:[(0,D.jsx)(PH,{peer:e,size:20}),c(e)]},e.clientId))})]})]})})}var WUe=(0,h.memo)(function({title:e,onRetitle:t,status:n,transport:r,presence:i,clientId:a,onJumpTo:o,me:s,onRename:c,onRecolor:l,onConnectAgent:u,webMcp:d,shareUrl:f,newCanvasUrl:p,onShare:m,onOpenFile:h,onSaveToFile:g,onExportImage:_,onLiveCollaboration:v,onHelp:y,canvasStatus:b,statusHistory:x,onStatusChange:S,onDelete:C}){let w=yH(i),T=w.some(e=>e.agent),E=HUe(w,a,s).length>0;return(0,D.jsxs)(`div`,{className:`pointer-events-none absolute left-3 right-3 top-3 z-10 flex items-start justify-between gap-3`,children:[(0,D.jsx)(FH,{title:e,status:n,transport:r,onRetitle:t,shareUrl:f,newCanvasUrl:p,onConnectAgent:u,webMcp:d,agentsHere:T,onDelete:C,onOpenFile:h,onSaveToFile:g,onExportImage:_,onLiveCollaboration:v,onHelp:y,children:(0,D.jsx)(NUe,{status:b,history:x,onChange:S})}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[E&&(0,D.jsx)(`div`,{className:`${AH} px-1.5`,children:(0,D.jsx)(UUe,{peers:w,clientId:a,me:s,onJumpTo:o})}),(0,D.jsx)(VUe,{me:s,onRename:c,onRecolor:l}),(0,D.jsxs)(`button`,{onClick:m,className:`pointer-events-auto inline-flex h-[38px] items-center gap-2 rounded-[9px] bg-[rgb(var(--ec-page-text))] px-4 text-sm font-semibold text-[rgb(var(--ec-page-bg))] shadow-sm transition-colors hover:bg-[rgb(var(--ec-page-text)/0.85)]`,children:[(0,D.jsx)(me,{size:16,"aria-hidden":!0}),`Share`]})]})]})}),GUe=`npx -y @mcp-b/webmcp-local-relay@5.1.0`,IH=`eventcatalog-webmcp-relay`,KUe=`eventcatalog-webmcp`,LH=e=>{try{return localStorage.getItem(e)===`true`}catch{return!1}},RH=e=>{try{localStorage.setItem(e,`true`)}catch{}},qUe=()=>LH(KUe)||LH(IH),JUe=()=>RH(KUe),zH=()=>LH(IH),YUe=e=>{if(document.querySelector(`script[data-webmcp-relay-embed]`))return;let t=document.createElement(`script`);t.src=e,t.dataset.webmcpRelayEmbed=``,t.dataset.relayPort=`9333`,document.body.appendChild(t)},XUe=e=>{RH(IH),YUe(e)},BH=({canvasId:e,title:t,canvasUrl:n,mcpUrl:r})=>`Join me on an EventCatalog canvas so we can design this together, live.
|
|
156
156
|
|
|
157
157
|
Canvas: ${t?`"${t}"`:`Untitled`}
|
|
158
158
|
Canvas id: ${e}
|
|
@@ -46,7 +46,7 @@ type ModelContextTool = {
|
|
|
46
46
|
title?: string;
|
|
47
47
|
description: string;
|
|
48
48
|
inputSchema?: object;
|
|
49
|
-
annotations?: { readOnlyHint?: boolean; consequentialHint?: boolean };
|
|
49
|
+
annotations?: { readOnlyHint?: boolean; consequentialHint?: boolean; untrustedContentHint?: boolean };
|
|
50
50
|
execute: (input: unknown, options?: { signal?: AbortSignal }) => Promise<ToolResult>;
|
|
51
51
|
};
|
|
52
52
|
type ModelContext = { registerTool: (tool: ModelContextTool, options?: { signal?: AbortSignal }) => Promise<void> | void };
|
|
@@ -204,7 +204,8 @@ const createCanvasTools = (get: () => CanvasWebMcpOptions, getStage: () => Agent
|
|
|
204
204
|
description:
|
|
205
205
|
'Reads the collaborative canvas open on this page: its nodes (ids, names, positions, the catalog resource they stand for), connections, comment threads, and who is on it. Call it first, and again to see what people changed.',
|
|
206
206
|
input: z.object({}),
|
|
207
|
-
|
|
207
|
+
// Names, notes and comments come from people
|
|
208
|
+
annotations: { readOnlyHint: true, untrustedContentHint: true },
|
|
208
209
|
execute: () =>
|
|
209
210
|
withDoc((doc) => ({
|
|
210
211
|
...describeCanvas(doc),
|
|
@@ -342,7 +343,7 @@ const createCanvasTools = (get: () => CanvasWebMcpOptions, getStage: () => Agent
|
|
|
342
343
|
description:
|
|
343
344
|
'Selects nodes and moves the view to them, to point the user at something. Leave out nodeIds to show the whole canvas.',
|
|
344
345
|
input: z.object({ nodeIds: z.array(z.string()).optional() }),
|
|
345
|
-
|
|
346
|
+
// Not read only: it changes the user's selection and view
|
|
346
347
|
execute: ({ nodeIds }) => {
|
|
347
348
|
if (nodeIds?.length) get().select(nodeIds);
|
|
348
349
|
get().fitView(nodeIds);
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
},
|
|
8
8
|
"license": "BUSL-1.1",
|
|
9
9
|
"type": "module",
|
|
10
|
-
"version": "5.4.
|
|
10
|
+
"version": "5.4.1",
|
|
11
11
|
"publishConfig": {
|
|
12
12
|
"access": "public"
|
|
13
13
|
},
|
|
@@ -142,10 +142,10 @@
|
|
|
142
142
|
"yjs": "^13.6.33",
|
|
143
143
|
"zod": "^4.6.6",
|
|
144
144
|
"@eventcatalog/fitness": "0.1.0",
|
|
145
|
-
"@eventcatalog/
|
|
145
|
+
"@eventcatalog/visualiser": "^5.0.0",
|
|
146
146
|
"@eventcatalog/linter": "1.2.4",
|
|
147
|
-
"@eventcatalog/
|
|
148
|
-
"@eventcatalog/
|
|
147
|
+
"@eventcatalog/sdk": "2.31.2",
|
|
148
|
+
"@eventcatalog/exporters": "0.1.2"
|
|
149
149
|
},
|
|
150
150
|
"devDependencies": {
|
|
151
151
|
"@astrojs/check": "^0.9.10",
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createGitHubSourceProvider
|
|
3
|
-
} from "./chunk-352FGP6W.js";
|
|
4
1
|
import {
|
|
5
2
|
createFileSystemSourceProvider
|
|
6
3
|
} from "./chunk-SDZQJTJW.js";
|
|
4
|
+
import {
|
|
5
|
+
createGitHubSourceProvider
|
|
6
|
+
} from "./chunk-352FGP6W.js";
|
|
7
7
|
|
|
8
8
|
// src/federation/source-provider.ts
|
|
9
9
|
var createFederationSourceProvider = (projectDirectory, providers = {}) => {
|