sldeditor 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,200 +1,200 @@
1
- "use strict";var uh=Object.defineProperty;var fh=(e,t,n)=>t in e?uh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var st=(e,t,n)=>fh(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react/jsx-runtime"),S=require("react"),Xo=require("react-dom");function mh(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const xe=mh(S);/**
1
+ "use strict";var fh=Object.defineProperty;var mh=(e,t,n)=>t in e?fh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var it=(e,t,n)=>mh(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react/jsx-runtime"),j=require("react"),Vo=require("react-dom");function hh(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const xe=hh(j);/**
2
2
  * @license lucide-react v0.469.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
5
5
  * See the LICENSE file in the root directory of this source tree.
6
- */const hh=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Vo=(...e)=>e.filter((t,n,o)=>!!t&&t.trim()!==""&&o.indexOf(t)===n).join(" ").trim();/**
6
+ */const ph=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Uo=(...e)=>e.filter((t,n,o)=>!!t&&t.trim()!==""&&o.indexOf(t)===n).join(" ").trim();/**
7
7
  * @license lucide-react v0.469.0 - ISC
8
8
  *
9
9
  * This source code is licensed under the ISC license.
10
10
  * See the LICENSE file in the root directory of this source tree.
11
- */var ph={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
11
+ */var gh={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
12
12
  * @license lucide-react v0.469.0 - ISC
13
13
  *
14
14
  * This source code is licensed under the ISC license.
15
15
  * See the LICENSE file in the root directory of this source tree.
16
- */const gh=S.forwardRef(({color:e="currentColor",size:t=24,strokeWidth:n=2,absoluteStrokeWidth:o,className:r="",children:s,iconNode:i,...a},l)=>S.createElement("svg",{ref:l,...ph,width:t,height:t,stroke:e,strokeWidth:o?Number(n)*24/Number(t):n,className:Vo("lucide",r),...a},[...i.map(([d,u])=>S.createElement(d,u)),...Array.isArray(s)?s:[s]]));/**
16
+ */const xh=j.forwardRef(({color:e="currentColor",size:t=24,strokeWidth:n=2,absoluteStrokeWidth:o,className:r="",children:s,iconNode:i,...a},l)=>j.createElement("svg",{ref:l,...gh,width:t,height:t,stroke:e,strokeWidth:o?Number(n)*24/Number(t):n,className:Uo("lucide",r),...a},[...i.map(([d,u])=>j.createElement(d,u)),...Array.isArray(s)?s:[s]]));/**
17
17
  * @license lucide-react v0.469.0 - ISC
18
18
  *
19
19
  * This source code is licensed under the ISC license.
20
20
  * See the LICENSE file in the root directory of this source tree.
21
- */const V=(e,t)=>{const n=S.forwardRef(({className:o,...r},s)=>S.createElement(gh,{ref:s,iconNode:t,className:Vo(`lucide-${hh(e)}`,o),...r}));return n.displayName=`${e}`,n};/**
21
+ */const U=(e,t)=>{const n=j.forwardRef(({className:o,...r},s)=>j.createElement(xh,{ref:s,iconNode:t,className:Uo(`lucide-${ph(e)}`,o),...r}));return n.displayName=`${e}`,n};/**
22
22
  * @license lucide-react v0.469.0 - ISC
23
23
  *
24
24
  * This source code is licensed under the ISC license.
25
25
  * See the LICENSE file in the root directory of this source tree.
26
- */const Uo=V("Cable",[["path",{d:"M17 21v-2a1 1 0 0 1-1-1v-1a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v1a1 1 0 0 1-1 1",key:"10bnsj"}],["path",{d:"M19 15V6.5a1 1 0 0 0-7 0v11a1 1 0 0 1-7 0V9",key:"1eqmu1"}],["path",{d:"M21 21v-2h-4",key:"14zm7j"}],["path",{d:"M3 5h4V3",key:"z442eg"}],["path",{d:"M7 5a1 1 0 0 1 1 1v1a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a1 1 0 0 1 1-1V3",key:"ebdjd7"}]]);/**
26
+ */const Zo=U("Cable",[["path",{d:"M17 21v-2a1 1 0 0 1-1-1v-1a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v1a1 1 0 0 1-1 1",key:"10bnsj"}],["path",{d:"M19 15V6.5a1 1 0 0 0-7 0v11a1 1 0 0 1-7 0V9",key:"1eqmu1"}],["path",{d:"M21 21v-2h-4",key:"14zm7j"}],["path",{d:"M3 5h4V3",key:"z442eg"}],["path",{d:"M7 5a1 1 0 0 1 1 1v1a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a1 1 0 0 1 1-1V3",key:"ebdjd7"}]]);/**
27
27
  * @license lucide-react v0.469.0 - ISC
28
28
  *
29
29
  * This source code is licensed under the ISC license.
30
30
  * See the LICENSE file in the root directory of this source tree.
31
- */const xh=V("ChevronDown",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);/**
31
+ */const yh=U("ChevronDown",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);/**
32
32
  * @license lucide-react v0.469.0 - ISC
33
33
  *
34
34
  * This source code is licensed under the ISC license.
35
35
  * See the LICENSE file in the root directory of this source tree.
36
- */const Zo=V("Clipboard",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}]]);/**
36
+ */const Jo=U("Clipboard",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}]]);/**
37
37
  * @license lucide-react v0.469.0 - ISC
38
38
  *
39
39
  * This source code is licensed under the ISC license.
40
40
  * See the LICENSE file in the root directory of this source tree.
41
- */const Jo=V("Copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);/**
41
+ */const Qo=U("Copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);/**
42
42
  * @license lucide-react v0.469.0 - ISC
43
43
  *
44
44
  * This source code is licensed under the ISC license.
45
45
  * See the LICENSE file in the root directory of this source tree.
46
- */const yh=V("Download",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"7 10 12 15 17 10",key:"2ggqvy"}],["line",{x1:"12",x2:"12",y1:"15",y2:"3",key:"1vk2je"}]]);/**
46
+ */const bh=U("Download",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"7 10 12 15 17 10",key:"2ggqvy"}],["line",{x1:"12",x2:"12",y1:"15",y2:"3",key:"1vk2je"}]]);/**
47
47
  * @license lucide-react v0.469.0 - ISC
48
48
  *
49
49
  * This source code is licensed under the ISC license.
50
50
  * See the LICENSE file in the root directory of this source tree.
51
- */const cn=V("Ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]]);/**
51
+ */const dn=U("Ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]]);/**
52
52
  * @license lucide-react v0.469.0 - ISC
53
53
  *
54
54
  * This source code is licensed under the ISC license.
55
55
  * See the LICENSE file in the root directory of this source tree.
56
- */const bh=V("FileBox",[["path",{d:"M14.5 22H18a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"16lz6z"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M3 13.1a2 2 0 0 0-1 1.76v3.24a2 2 0 0 0 .97 1.78L6 21.7a2 2 0 0 0 2.03.01L11 19.9a2 2 0 0 0 1-1.76V14.9a2 2 0 0 0-.97-1.78L8 11.3a2 2 0 0 0-2.03-.01Z",key:"99pj1s"}],["path",{d:"M7 17v5",key:"1yj1jh"}],["path",{d:"M11.7 14.2 7 17l-4.7-2.8",key:"1yk8tc"}]]);/**
56
+ */const wh=U("FileBox",[["path",{d:"M14.5 22H18a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"16lz6z"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M3 13.1a2 2 0 0 0-1 1.76v3.24a2 2 0 0 0 .97 1.78L6 21.7a2 2 0 0 0 2.03.01L11 19.9a2 2 0 0 0 1-1.76V14.9a2 2 0 0 0-.97-1.78L8 11.3a2 2 0 0 0-2.03-.01Z",key:"99pj1s"}],["path",{d:"M7 17v5",key:"1yj1jh"}],["path",{d:"M11.7 14.2 7 17l-4.7-2.8",key:"1yk8tc"}]]);/**
57
57
  * @license lucide-react v0.469.0 - ISC
58
58
  *
59
59
  * This source code is licensed under the ISC license.
60
60
  * See the LICENSE file in the root directory of this source tree.
61
- */const wh=V("FileImage",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["circle",{cx:"10",cy:"12",r:"2",key:"737tya"}],["path",{d:"m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22",key:"wt3hpn"}]]);/**
61
+ */const vh=U("FileImage",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["circle",{cx:"10",cy:"12",r:"2",key:"737tya"}],["path",{d:"m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22",key:"wt3hpn"}]]);/**
62
62
  * @license lucide-react v0.469.0 - ISC
63
63
  *
64
64
  * This source code is licensed under the ISC license.
65
65
  * See the LICENSE file in the root directory of this source tree.
66
- */const vh=V("FilePlus",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M9 15h6",key:"cctwl0"}],["path",{d:"M12 18v-6",key:"17g6i2"}]]);/**
66
+ */const kh=U("FilePlus",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M9 15h6",key:"cctwl0"}],["path",{d:"M12 18v-6",key:"17g6i2"}]]);/**
67
67
  * @license lucide-react v0.469.0 - ISC
68
68
  *
69
69
  * This source code is licensed under the ISC license.
70
70
  * See the LICENSE file in the root directory of this source tree.
71
- */const kh=V("FileType",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M9 13v-1h6v1",key:"1bb014"}],["path",{d:"M12 12v6",key:"3ahymv"}],["path",{d:"M11 18h2",key:"12mj7e"}]]);/**
71
+ */const _h=U("FileType",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M9 13v-1h6v1",key:"1bb014"}],["path",{d:"M12 12v6",key:"3ahymv"}],["path",{d:"M11 18h2",key:"12mj7e"}]]);/**
72
72
  * @license lucide-react v0.469.0 - ISC
73
73
  *
74
74
  * This source code is licensed under the ISC license.
75
75
  * See the LICENSE file in the root directory of this source tree.
76
- */const Qo=V("FlipHorizontal",[["path",{d:"M8 3H5a2 2 0 0 0-2 2v14c0 1.1.9 2 2 2h3",key:"1i73f7"}],["path",{d:"M16 3h3a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-3",key:"saxlbk"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"M12 14v2",key:"8jcxud"}],["path",{d:"M12 8v2",key:"1woqiv"}],["path",{d:"M12 2v2",key:"tus03m"}]]);/**
76
+ */const er=U("FlipHorizontal",[["path",{d:"M8 3H5a2 2 0 0 0-2 2v14c0 1.1.9 2 2 2h3",key:"1i73f7"}],["path",{d:"M16 3h3a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-3",key:"saxlbk"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"M12 14v2",key:"8jcxud"}],["path",{d:"M12 8v2",key:"1woqiv"}],["path",{d:"M12 2v2",key:"tus03m"}]]);/**
77
77
  * @license lucide-react v0.469.0 - ISC
78
78
  *
79
79
  * This source code is licensed under the ISC license.
80
80
  * See the LICENSE file in the root directory of this source tree.
81
- */const Wn=V("FolderOpen",[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]]);/**
81
+ */const Gn=U("FolderOpen",[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]]);/**
82
82
  * @license lucide-react v0.469.0 - ISC
83
83
  *
84
84
  * This source code is licensed under the ISC license.
85
85
  * See the LICENSE file in the root directory of this source tree.
86
- */const _h=V("Grid2x2",[["path",{d:"M12 3v18",key:"108xh3"}],["path",{d:"M3 12h18",key:"1i2n21"}],["rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",key:"h1oib"}]]);/**
86
+ */const Sh=U("Grid2x2",[["path",{d:"M12 3v18",key:"108xh3"}],["path",{d:"M3 12h18",key:"1i2n21"}],["rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",key:"h1oib"}]]);/**
87
87
  * @license lucide-react v0.469.0 - ISC
88
88
  *
89
89
  * This source code is licensed under the ISC license.
90
90
  * See the LICENSE file in the root directory of this source tree.
91
- */const Sh=V("Hand",[["path",{d:"M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2",key:"1fvzgz"}],["path",{d:"M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2",key:"1kc0my"}],["path",{d:"M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8",key:"10h0bg"}],["path",{d:"M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15",key:"1s1gnw"}]]);/**
91
+ */const jh=U("Hand",[["path",{d:"M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2",key:"1fvzgz"}],["path",{d:"M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2",key:"1kc0my"}],["path",{d:"M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8",key:"10h0bg"}],["path",{d:"M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15",key:"1s1gnw"}]]);/**
92
92
  * @license lucide-react v0.469.0 - ISC
93
93
  *
94
94
  * This source code is licensed under the ISC license.
95
95
  * See the LICENSE file in the root directory of this source tree.
96
- */const Mt=V("LayoutGrid",[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}]]);/**
96
+ */const Pt=U("LayoutGrid",[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}]]);/**
97
97
  * @license lucide-react v0.469.0 - ISC
98
98
  *
99
99
  * This source code is licensed under the ISC license.
100
100
  * See the LICENSE file in the root directory of this source tree.
101
- */const er=V("ListTree",[["path",{d:"M21 12h-8",key:"1bmf0i"}],["path",{d:"M21 6H8",key:"1pqkrb"}],["path",{d:"M21 18h-8",key:"1tm79t"}],["path",{d:"M3 6v4c0 1.1.9 2 2 2h3",key:"1ywdgy"}],["path",{d:"M3 10v6c0 1.1.9 2 2 2h3",key:"2wc746"}]]);/**
101
+ */const tr=U("ListTree",[["path",{d:"M21 12h-8",key:"1bmf0i"}],["path",{d:"M21 6H8",key:"1pqkrb"}],["path",{d:"M21 18h-8",key:"1tm79t"}],["path",{d:"M3 6v4c0 1.1.9 2 2 2h3",key:"1ywdgy"}],["path",{d:"M3 10v6c0 1.1.9 2 2 2h3",key:"2wc746"}]]);/**
102
102
  * @license lucide-react v0.469.0 - ISC
103
103
  *
104
104
  * This source code is licensed under the ISC license.
105
105
  * See the LICENSE file in the root directory of this source tree.
106
- */const jh=V("Maximize2",[["polyline",{points:"15 3 21 3 21 9",key:"mznyad"}],["polyline",{points:"9 21 3 21 3 15",key:"1avn1i"}],["line",{x1:"21",x2:"14",y1:"3",y2:"10",key:"ota7mn"}],["line",{x1:"3",x2:"10",y1:"21",y2:"14",key:"1atl0r"}]]);/**
106
+ */const $h=U("Maximize2",[["polyline",{points:"15 3 21 3 21 9",key:"mznyad"}],["polyline",{points:"9 21 3 21 3 15",key:"1avn1i"}],["line",{x1:"21",x2:"14",y1:"3",y2:"10",key:"ota7mn"}],["line",{x1:"3",x2:"10",y1:"21",y2:"14",key:"1atl0r"}]]);/**
107
107
  * @license lucide-react v0.469.0 - ISC
108
108
  *
109
109
  * This source code is licensed under the ISC license.
110
110
  * See the LICENSE file in the root directory of this source tree.
111
- */const jn=V("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);/**
111
+ */const $n=U("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);/**
112
112
  * @license lucide-react v0.469.0 - ISC
113
113
  *
114
114
  * This source code is licensed under the ISC license.
115
115
  * See the LICENSE file in the root directory of this source tree.
116
- */const $h=V("MousePointer2",[["path",{d:"M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z",key:"edeuup"}]]);/**
116
+ */const Eh=U("MousePointer2",[["path",{d:"M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z",key:"edeuup"}]]);/**
117
117
  * @license lucide-react v0.469.0 - ISC
118
118
  *
119
119
  * This source code is licensed under the ISC license.
120
120
  * See the LICENSE file in the root directory of this source tree.
121
- */const Eh=V("PanelBottomClose",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 15h18",key:"5xshup"}],["path",{d:"m15 8-3 3-3-3",key:"1oxy1z"}]]);/**
121
+ */const Nh=U("PanelBottomClose",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 15h18",key:"5xshup"}],["path",{d:"m15 8-3 3-3-3",key:"1oxy1z"}]]);/**
122
122
  * @license lucide-react v0.469.0 - ISC
123
123
  *
124
124
  * This source code is licensed under the ISC license.
125
125
  * See the LICENSE file in the root directory of this source tree.
126
- */const Nh=V("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]);/**
126
+ */const Th=U("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]);/**
127
127
  * @license lucide-react v0.469.0 - ISC
128
128
  *
129
129
  * This source code is licensed under the ISC license.
130
130
  * See the LICENSE file in the root directory of this source tree.
131
- */const $n=V("Redo2",[["path",{d:"m15 14 5-5-5-5",key:"12vg1m"}],["path",{d:"M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13",key:"6uklza"}]]);/**
131
+ */const En=U("Redo2",[["path",{d:"m15 14 5-5-5-5",key:"12vg1m"}],["path",{d:"M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13",key:"6uklza"}]]);/**
132
132
  * @license lucide-react v0.469.0 - ISC
133
133
  *
134
134
  * This source code is licensed under the ISC license.
135
135
  * See the LICENSE file in the root directory of this source tree.
136
- */const tr=V("RotateCw",[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]]);/**
136
+ */const nr=U("RotateCw",[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]]);/**
137
137
  * @license lucide-react v0.469.0 - ISC
138
138
  *
139
139
  * This source code is licensed under the ISC license.
140
140
  * See the LICENSE file in the root directory of this source tree.
141
- */const Gn=V("Save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]);/**
141
+ */const qn=U("Save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]);/**
142
142
  * @license lucide-react v0.469.0 - ISC
143
143
  *
144
144
  * This source code is licensed under the ISC license.
145
145
  * See the LICENSE file in the root directory of this source tree.
146
- */const nr=V("Scissors",[["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M8.12 8.12 12 12",key:"1alkpv"}],["path",{d:"M20 4 8.12 15.88",key:"xgtan2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M14.8 14.8 20 20",key:"ptml3r"}]]);/**
146
+ */const or=U("Scissors",[["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M8.12 8.12 12 12",key:"1alkpv"}],["path",{d:"M20 4 8.12 15.88",key:"xgtan2"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M14.8 14.8 20 20",key:"ptml3r"}]]);/**
147
147
  * @license lucide-react v0.469.0 - ISC
148
148
  *
149
149
  * This source code is licensed under the ISC license.
150
150
  * See the LICENSE file in the root directory of this source tree.
151
- */const Th=V("Search",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]]);/**
151
+ */const Ch=U("Search",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]]);/**
152
152
  * @license lucide-react v0.469.0 - ISC
153
153
  *
154
154
  * This source code is licensed under the ISC license.
155
155
  * See the LICENSE file in the root directory of this source tree.
156
- */const or=V("Shapes",[["path",{d:"M8.3 10a.7.7 0 0 1-.626-1.079L11.4 3a.7.7 0 0 1 1.198-.043L16.3 8.9a.7.7 0 0 1-.572 1.1Z",key:"1bo67w"}],["rect",{x:"3",y:"14",width:"7",height:"7",rx:"1",key:"1bkyp8"}],["circle",{cx:"17.5",cy:"17.5",r:"3.5",key:"w3z12y"}]]);/**
156
+ */const rr=U("Shapes",[["path",{d:"M8.3 10a.7.7 0 0 1-.626-1.079L11.4 3a.7.7 0 0 1 1.198-.043L16.3 8.9a.7.7 0 0 1-.572 1.1Z",key:"1bo67w"}],["rect",{x:"3",y:"14",width:"7",height:"7",rx:"1",key:"1bkyp8"}],["circle",{cx:"17.5",cy:"17.5",r:"3.5",key:"w3z12y"}]]);/**
157
157
  * @license lucide-react v0.469.0 - ISC
158
158
  *
159
159
  * This source code is licensed under the ISC license.
160
160
  * See the LICENSE file in the root directory of this source tree.
161
- */const Ch=V("Spline",[["circle",{cx:"19",cy:"5",r:"2",key:"mhkx31"}],["circle",{cx:"5",cy:"19",r:"2",key:"v8kfzx"}],["path",{d:"M5 17A12 12 0 0 1 17 5",key:"1okkup"}]]);/**
161
+ */const Ih=U("Spline",[["circle",{cx:"19",cy:"5",r:"2",key:"mhkx31"}],["circle",{cx:"5",cy:"19",r:"2",key:"v8kfzx"}],["path",{d:"M5 17A12 12 0 0 1 17 5",key:"1okkup"}]]);/**
162
162
  * @license lucide-react v0.469.0 - ISC
163
163
  *
164
164
  * This source code is licensed under the ISC license.
165
165
  * See the LICENSE file in the root directory of this source tree.
166
- */const Ih=V("SquareDashed",[["path",{d:"M5 3a2 2 0 0 0-2 2",key:"y57alp"}],["path",{d:"M19 3a2 2 0 0 1 2 2",key:"18rm91"}],["path",{d:"M21 19a2 2 0 0 1-2 2",key:"1j7049"}],["path",{d:"M5 21a2 2 0 0 1-2-2",key:"sbafld"}],["path",{d:"M9 3h1",key:"1yesri"}],["path",{d:"M9 21h1",key:"15o7lz"}],["path",{d:"M14 3h1",key:"1ec4yj"}],["path",{d:"M14 21h1",key:"v9vybs"}],["path",{d:"M3 9v1",key:"1r0deq"}],["path",{d:"M21 9v1",key:"mxsmne"}],["path",{d:"M3 14v1",key:"vnatye"}],["path",{d:"M21 14v1",key:"169vum"}]]);/**
166
+ */const Ah=U("SquareDashed",[["path",{d:"M5 3a2 2 0 0 0-2 2",key:"y57alp"}],["path",{d:"M19 3a2 2 0 0 1 2 2",key:"18rm91"}],["path",{d:"M21 19a2 2 0 0 1-2 2",key:"1j7049"}],["path",{d:"M5 21a2 2 0 0 1-2-2",key:"sbafld"}],["path",{d:"M9 3h1",key:"1yesri"}],["path",{d:"M9 21h1",key:"15o7lz"}],["path",{d:"M14 3h1",key:"1ec4yj"}],["path",{d:"M14 21h1",key:"v9vybs"}],["path",{d:"M3 9v1",key:"1r0deq"}],["path",{d:"M21 9v1",key:"mxsmne"}],["path",{d:"M3 14v1",key:"vnatye"}],["path",{d:"M21 14v1",key:"169vum"}]]);/**
167
167
  * @license lucide-react v0.469.0 - ISC
168
168
  *
169
169
  * This source code is licensed under the ISC license.
170
170
  * See the LICENSE file in the root directory of this source tree.
171
- */const rr=V("Trash2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]]);/**
171
+ */const sr=U("Trash2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]]);/**
172
172
  * @license lucide-react v0.469.0 - ISC
173
173
  *
174
174
  * This source code is licensed under the ISC license.
175
175
  * See the LICENSE file in the root directory of this source tree.
176
- */const sr=V("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]);/**
176
+ */const ir=U("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]);/**
177
177
  * @license lucide-react v0.469.0 - ISC
178
178
  *
179
179
  * This source code is licensed under the ISC license.
180
180
  * See the LICENSE file in the root directory of this source tree.
181
- */const En=V("Undo2",[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]);/**
181
+ */const Nn=U("Undo2",[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]);/**
182
182
  * @license lucide-react v0.469.0 - ISC
183
183
  *
184
184
  * This source code is licensed under the ISC license.
185
185
  * See the LICENSE file in the root directory of this source tree.
186
- */const pt=V("WandSparkles",[["path",{d:"m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72",key:"ul74o6"}],["path",{d:"m14 7 3 3",key:"1r5n42"}],["path",{d:"M5 6v4",key:"ilb8ba"}],["path",{d:"M19 14v4",key:"blhpug"}],["path",{d:"M10 2v2",key:"7u0qdc"}],["path",{d:"M7 8H3",key:"zfb6yr"}],["path",{d:"M21 16h-4",key:"1cnmox"}],["path",{d:"M11 3H9",key:"1obp7u"}]]);/**
186
+ */const gt=U("WandSparkles",[["path",{d:"m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72",key:"ul74o6"}],["path",{d:"m14 7 3 3",key:"1r5n42"}],["path",{d:"M5 6v4",key:"ilb8ba"}],["path",{d:"M19 14v4",key:"blhpug"}],["path",{d:"M10 2v2",key:"7u0qdc"}],["path",{d:"M7 8H3",key:"zfb6yr"}],["path",{d:"M21 16h-4",key:"1cnmox"}],["path",{d:"M11 3H9",key:"1obp7u"}]]);/**
187
187
  * @license lucide-react v0.469.0 - ISC
188
188
  *
189
189
  * This source code is licensed under the ISC license.
190
190
  * See the LICENSE file in the root directory of this source tree.
191
- */const Nn=V("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);function ir(e){var t,n,o="";if(typeof e=="string"||typeof e=="number")o+=e;else if(typeof e=="object")if(Array.isArray(e)){var r=e.length;for(t=0;t<r;t++)e[t]&&(n=ir(e[t]))&&(o&&(o+=" "),o+=n)}else for(n in e)e[n]&&(o&&(o+=" "),o+=n);return o}function ar(){for(var e,t,n=0,o="",r=arguments.length;n<r;n++)(e=arguments[n])&&(t=ir(e))&&(o&&(o+=" "),o+=t);return o}const Tn="-",Ah=e=>{const t=Ph(e),{conflictingClassGroups:n,conflictingClassGroupModifiers:o}=e;return{getClassGroupId:i=>{const a=i.split(Tn);return a[0]===""&&a.length!==1&&a.shift(),lr(a,t)||Mh(i)},getConflictingClassGroupIds:(i,a)=>{const l=n[i]||[];return a&&o[i]?[...l,...o[i]]:l}}},lr=(e,t)=>{var i;if(e.length===0)return t.classGroupId;const n=e[0],o=t.nextPart.get(n),r=o?lr(e.slice(1),o):void 0;if(r)return r;if(t.validators.length===0)return;const s=e.join(Tn);return(i=t.validators.find(({validator:a})=>a(s)))==null?void 0:i.classGroupId},Kn=/^\[(.+)\]$/,Mh=e=>{if(Kn.test(e)){const t=Kn.exec(e)[1],n=t==null?void 0:t.substring(0,t.indexOf(":"));if(n)return"arbitrary.."+n}},Ph=e=>{const{theme:t,prefix:n}=e,o={nextPart:new Map,validators:[]};return Lh(Object.entries(e.classGroups),n).forEach(([s,i])=>{dn(i,o,s,t)}),o},dn=(e,t,n,o)=>{e.forEach(r=>{if(typeof r=="string"){const s=r===""?t:qn(t,r);s.classGroupId=n;return}if(typeof r=="function"){if(Oh(r)){dn(r(o),t,n,o);return}t.validators.push({validator:r,classGroupId:n});return}Object.entries(r).forEach(([s,i])=>{dn(i,qn(t,s),n,o)})})},qn=(e,t)=>{let n=e;return t.split(Tn).forEach(o=>{n.nextPart.has(o)||n.nextPart.set(o,{nextPart:new Map,validators:[]}),n=n.nextPart.get(o)}),n},Oh=e=>e.isThemeGetter,Lh=(e,t)=>t?e.map(([n,o])=>{const r=o.map(s=>typeof s=="string"?t+s:typeof s=="object"?Object.fromEntries(Object.entries(s).map(([i,a])=>[t+i,a])):s);return[n,r]}):e,Bh=e=>{if(e<1)return{get:()=>{},set:()=>{}};let t=0,n=new Map,o=new Map;const r=(s,i)=>{n.set(s,i),t++,t>e&&(t=0,o=n,n=new Map)};return{get(s){let i=n.get(s);if(i!==void 0)return i;if((i=o.get(s))!==void 0)return r(s,i),i},set(s,i){n.has(s)?n.set(s,i):r(s,i)}}},cr="!",Rh=e=>{const{separator:t,experimentalParseClassName:n}=e,o=t.length===1,r=t[0],s=t.length,i=a=>{const l=[];let d=0,u=0,f;for(let y=0;y<a.length;y++){let v=a[y];if(d===0){if(v===r&&(o||a.slice(y,y+s)===t)){l.push(a.slice(u,y)),u=y+s;continue}if(v==="/"){f=y;continue}}v==="["?d++:v==="]"&&d--}const p=l.length===0?a:a.substring(u),g=p.startsWith(cr),m=g?p.substring(1):p,h=f&&f>u?f-u:void 0;return{modifiers:l,hasImportantModifier:g,baseClassName:m,maybePostfixModifierPosition:h}};return n?a=>n({className:a,parseClassName:i}):i},Dh=e=>{if(e.length<=1)return e;const t=[];let n=[];return e.forEach(o=>{o[0]==="["?(t.push(...n.sort(),o),n=[]):n.push(o)}),t.push(...n.sort()),t},zh=e=>({cache:Bh(e.cacheSize),parseClassName:Rh(e),...Ah(e)}),Fh=/\s+/,Hh=(e,t)=>{const{parseClassName:n,getClassGroupId:o,getConflictingClassGroupIds:r}=t,s=[],i=e.trim().split(Fh);let a="";for(let l=i.length-1;l>=0;l-=1){const d=i[l],{modifiers:u,hasImportantModifier:f,baseClassName:p,maybePostfixModifierPosition:g}=n(d);let m=!!g,h=o(m?p.substring(0,g):p);if(!h){if(!m){a=d+(a.length>0?" "+a:a);continue}if(h=o(p),!h){a=d+(a.length>0?" "+a:a);continue}m=!1}const y=Dh(u).join(":"),v=f?y+cr:y,b=v+h;if(s.includes(b))continue;s.push(b);const _=r(h,m);for(let N=0;N<_.length;++N){const I=_[N];s.push(v+I)}a=d+(a.length>0?" "+a:a)}return a};function Wh(){let e=0,t,n,o="";for(;e<arguments.length;)(t=arguments[e++])&&(n=dr(t))&&(o&&(o+=" "),o+=n);return o}const dr=e=>{if(typeof e=="string")return e;let t,n="";for(let o=0;o<e.length;o++)e[o]&&(t=dr(e[o]))&&(n&&(n+=" "),n+=t);return n};function Gh(e,...t){let n,o,r,s=i;function i(l){const d=t.reduce((u,f)=>f(u),e());return n=zh(d),o=n.cache.get,r=n.cache.set,s=a,a(l)}function a(l){const d=o(l);if(d)return d;const u=Hh(l,n);return r(l,u),u}return function(){return s(Wh.apply(null,arguments))}}const oe=e=>{const t=n=>n[e]||[];return t.isThemeGetter=!0,t},ur=/^\[(?:([a-z-]+):)?(.+)\]$/i,Kh=/^\d+\/\d+$/,qh=new Set(["px","full","screen"]),Yh=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,Xh=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,Vh=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,Uh=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,Zh=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,Pe=e=>Qe(e)||qh.has(e)||Kh.test(e),ze=e=>nt(e,"length",sp),Qe=e=>!!e&&!Number.isNaN(Number(e)),Ut=e=>nt(e,"number",Qe),it=e=>!!e&&Number.isInteger(Number(e)),Jh=e=>e.endsWith("%")&&Qe(e.slice(0,-1)),K=e=>ur.test(e),Fe=e=>Yh.test(e),Qh=new Set(["length","size","percentage"]),ep=e=>nt(e,Qh,fr),tp=e=>nt(e,"position",fr),np=new Set(["image","url"]),op=e=>nt(e,np,ap),rp=e=>nt(e,"",ip),at=()=>!0,nt=(e,t,n)=>{const o=ur.exec(e);return o?o[1]?typeof t=="string"?o[1]===t:t.has(o[1]):n(o[2]):!1},sp=e=>Xh.test(e)&&!Vh.test(e),fr=()=>!1,ip=e=>Uh.test(e),ap=e=>Zh.test(e),lp=()=>{const e=oe("colors"),t=oe("spacing"),n=oe("blur"),o=oe("brightness"),r=oe("borderColor"),s=oe("borderRadius"),i=oe("borderSpacing"),a=oe("borderWidth"),l=oe("contrast"),d=oe("grayscale"),u=oe("hueRotate"),f=oe("invert"),p=oe("gap"),g=oe("gradientColorStops"),m=oe("gradientColorStopPositions"),h=oe("inset"),y=oe("margin"),v=oe("opacity"),b=oe("padding"),_=oe("saturate"),N=oe("scale"),I=oe("sepia"),B=oe("skew"),re=oe("space"),te=oe("translate"),ve=()=>["auto","contain","none"],me=()=>["auto","hidden","clip","visible","scroll"],E=()=>["auto",K,t],M=()=>[K,t],se=()=>["",Pe,ze],ne=()=>["auto",Qe,K],ce=()=>["bottom","center","left","left-bottom","left-top","right","right-bottom","right-top","top"],X=()=>["solid","dashed","dotted","double","none"],ue=()=>["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],ae=()=>["start","end","center","between","around","evenly","stretch"],he=()=>["","0",K],ke=()=>["auto","avoid","all","avoid-page","page","left","right","column"],ye=()=>[Qe,K];return{cacheSize:500,separator:":",theme:{colors:[at],spacing:[Pe,ze],blur:["none","",Fe,K],brightness:ye(),borderColor:[e],borderRadius:["none","","full",Fe,K],borderSpacing:M(),borderWidth:se(),contrast:ye(),grayscale:he(),hueRotate:ye(),invert:he(),gap:M(),gradientColorStops:[e],gradientColorStopPositions:[Jh,ze],inset:E(),margin:E(),opacity:ye(),padding:M(),saturate:ye(),scale:ye(),sepia:he(),skew:ye(),space:M(),translate:M()},classGroups:{aspect:[{aspect:["auto","square","video",K]}],container:["container"],columns:[{columns:[Fe]}],"break-after":[{"break-after":ke()}],"break-before":[{"break-before":ke()}],"break-inside":[{"break-inside":["auto","avoid","avoid-page","avoid-column"]}],"box-decoration":[{"box-decoration":["slice","clone"]}],box:[{box:["border","content"]}],display:["block","inline-block","inline","flex","inline-flex","table","inline-table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row-group","table-row","flow-root","grid","inline-grid","contents","list-item","hidden"],float:[{float:["right","left","none","start","end"]}],clear:[{clear:["left","right","both","none","start","end"]}],isolation:["isolate","isolation-auto"],"object-fit":[{object:["contain","cover","fill","none","scale-down"]}],"object-position":[{object:[...ce(),K]}],overflow:[{overflow:me()}],"overflow-x":[{"overflow-x":me()}],"overflow-y":[{"overflow-y":me()}],overscroll:[{overscroll:ve()}],"overscroll-x":[{"overscroll-x":ve()}],"overscroll-y":[{"overscroll-y":ve()}],position:["static","fixed","absolute","relative","sticky"],inset:[{inset:[h]}],"inset-x":[{"inset-x":[h]}],"inset-y":[{"inset-y":[h]}],start:[{start:[h]}],end:[{end:[h]}],top:[{top:[h]}],right:[{right:[h]}],bottom:[{bottom:[h]}],left:[{left:[h]}],visibility:["visible","invisible","collapse"],z:[{z:["auto",it,K]}],basis:[{basis:E()}],"flex-direction":[{flex:["row","row-reverse","col","col-reverse"]}],"flex-wrap":[{flex:["wrap","wrap-reverse","nowrap"]}],flex:[{flex:["1","auto","initial","none",K]}],grow:[{grow:he()}],shrink:[{shrink:he()}],order:[{order:["first","last","none",it,K]}],"grid-cols":[{"grid-cols":[at]}],"col-start-end":[{col:["auto",{span:["full",it,K]},K]}],"col-start":[{"col-start":ne()}],"col-end":[{"col-end":ne()}],"grid-rows":[{"grid-rows":[at]}],"row-start-end":[{row:["auto",{span:[it,K]},K]}],"row-start":[{"row-start":ne()}],"row-end":[{"row-end":ne()}],"grid-flow":[{"grid-flow":["row","col","dense","row-dense","col-dense"]}],"auto-cols":[{"auto-cols":["auto","min","max","fr",K]}],"auto-rows":[{"auto-rows":["auto","min","max","fr",K]}],gap:[{gap:[p]}],"gap-x":[{"gap-x":[p]}],"gap-y":[{"gap-y":[p]}],"justify-content":[{justify:["normal",...ae()]}],"justify-items":[{"justify-items":["start","end","center","stretch"]}],"justify-self":[{"justify-self":["auto","start","end","center","stretch"]}],"align-content":[{content:["normal",...ae(),"baseline"]}],"align-items":[{items:["start","end","center","baseline","stretch"]}],"align-self":[{self:["auto","start","end","center","stretch","baseline"]}],"place-content":[{"place-content":[...ae(),"baseline"]}],"place-items":[{"place-items":["start","end","center","baseline","stretch"]}],"place-self":[{"place-self":["auto","start","end","center","stretch"]}],p:[{p:[b]}],px:[{px:[b]}],py:[{py:[b]}],ps:[{ps:[b]}],pe:[{pe:[b]}],pt:[{pt:[b]}],pr:[{pr:[b]}],pb:[{pb:[b]}],pl:[{pl:[b]}],m:[{m:[y]}],mx:[{mx:[y]}],my:[{my:[y]}],ms:[{ms:[y]}],me:[{me:[y]}],mt:[{mt:[y]}],mr:[{mr:[y]}],mb:[{mb:[y]}],ml:[{ml:[y]}],"space-x":[{"space-x":[re]}],"space-x-reverse":["space-x-reverse"],"space-y":[{"space-y":[re]}],"space-y-reverse":["space-y-reverse"],w:[{w:["auto","min","max","fit","svw","lvw","dvw",K,t]}],"min-w":[{"min-w":[K,t,"min","max","fit"]}],"max-w":[{"max-w":[K,t,"none","full","min","max","fit","prose",{screen:[Fe]},Fe]}],h:[{h:[K,t,"auto","min","max","fit","svh","lvh","dvh"]}],"min-h":[{"min-h":[K,t,"min","max","fit","svh","lvh","dvh"]}],"max-h":[{"max-h":[K,t,"min","max","fit","svh","lvh","dvh"]}],size:[{size:[K,t,"auto","min","max","fit"]}],"font-size":[{text:["base",Fe,ze]}],"font-smoothing":["antialiased","subpixel-antialiased"],"font-style":["italic","not-italic"],"font-weight":[{font:["thin","extralight","light","normal","medium","semibold","bold","extrabold","black",Ut]}],"font-family":[{font:[at]}],"fvn-normal":["normal-nums"],"fvn-ordinal":["ordinal"],"fvn-slashed-zero":["slashed-zero"],"fvn-figure":["lining-nums","oldstyle-nums"],"fvn-spacing":["proportional-nums","tabular-nums"],"fvn-fraction":["diagonal-fractions","stacked-fractions"],tracking:[{tracking:["tighter","tight","normal","wide","wider","widest",K]}],"line-clamp":[{"line-clamp":["none",Qe,Ut]}],leading:[{leading:["none","tight","snug","normal","relaxed","loose",Pe,K]}],"list-image":[{"list-image":["none",K]}],"list-style-type":[{list:["none","disc","decimal",K]}],"list-style-position":[{list:["inside","outside"]}],"placeholder-color":[{placeholder:[e]}],"placeholder-opacity":[{"placeholder-opacity":[v]}],"text-alignment":[{text:["left","center","right","justify","start","end"]}],"text-color":[{text:[e]}],"text-opacity":[{"text-opacity":[v]}],"text-decoration":["underline","overline","line-through","no-underline"],"text-decoration-style":[{decoration:[...X(),"wavy"]}],"text-decoration-thickness":[{decoration:["auto","from-font",Pe,ze]}],"underline-offset":[{"underline-offset":["auto",Pe,K]}],"text-decoration-color":[{decoration:[e]}],"text-transform":["uppercase","lowercase","capitalize","normal-case"],"text-overflow":["truncate","text-ellipsis","text-clip"],"text-wrap":[{text:["wrap","nowrap","balance","pretty"]}],indent:[{indent:M()}],"vertical-align":[{align:["baseline","top","middle","bottom","text-top","text-bottom","sub","super",K]}],whitespace:[{whitespace:["normal","nowrap","pre","pre-line","pre-wrap","break-spaces"]}],break:[{break:["normal","words","all","keep"]}],hyphens:[{hyphens:["none","manual","auto"]}],content:[{content:["none",K]}],"bg-attachment":[{bg:["fixed","local","scroll"]}],"bg-clip":[{"bg-clip":["border","padding","content","text"]}],"bg-opacity":[{"bg-opacity":[v]}],"bg-origin":[{"bg-origin":["border","padding","content"]}],"bg-position":[{bg:[...ce(),tp]}],"bg-repeat":[{bg:["no-repeat",{repeat:["","x","y","round","space"]}]}],"bg-size":[{bg:["auto","cover","contain",ep]}],"bg-image":[{bg:["none",{"gradient-to":["t","tr","r","br","b","bl","l","tl"]},op]}],"bg-color":[{bg:[e]}],"gradient-from-pos":[{from:[m]}],"gradient-via-pos":[{via:[m]}],"gradient-to-pos":[{to:[m]}],"gradient-from":[{from:[g]}],"gradient-via":[{via:[g]}],"gradient-to":[{to:[g]}],rounded:[{rounded:[s]}],"rounded-s":[{"rounded-s":[s]}],"rounded-e":[{"rounded-e":[s]}],"rounded-t":[{"rounded-t":[s]}],"rounded-r":[{"rounded-r":[s]}],"rounded-b":[{"rounded-b":[s]}],"rounded-l":[{"rounded-l":[s]}],"rounded-ss":[{"rounded-ss":[s]}],"rounded-se":[{"rounded-se":[s]}],"rounded-ee":[{"rounded-ee":[s]}],"rounded-es":[{"rounded-es":[s]}],"rounded-tl":[{"rounded-tl":[s]}],"rounded-tr":[{"rounded-tr":[s]}],"rounded-br":[{"rounded-br":[s]}],"rounded-bl":[{"rounded-bl":[s]}],"border-w":[{border:[a]}],"border-w-x":[{"border-x":[a]}],"border-w-y":[{"border-y":[a]}],"border-w-s":[{"border-s":[a]}],"border-w-e":[{"border-e":[a]}],"border-w-t":[{"border-t":[a]}],"border-w-r":[{"border-r":[a]}],"border-w-b":[{"border-b":[a]}],"border-w-l":[{"border-l":[a]}],"border-opacity":[{"border-opacity":[v]}],"border-style":[{border:[...X(),"hidden"]}],"divide-x":[{"divide-x":[a]}],"divide-x-reverse":["divide-x-reverse"],"divide-y":[{"divide-y":[a]}],"divide-y-reverse":["divide-y-reverse"],"divide-opacity":[{"divide-opacity":[v]}],"divide-style":[{divide:X()}],"border-color":[{border:[r]}],"border-color-x":[{"border-x":[r]}],"border-color-y":[{"border-y":[r]}],"border-color-s":[{"border-s":[r]}],"border-color-e":[{"border-e":[r]}],"border-color-t":[{"border-t":[r]}],"border-color-r":[{"border-r":[r]}],"border-color-b":[{"border-b":[r]}],"border-color-l":[{"border-l":[r]}],"divide-color":[{divide:[r]}],"outline-style":[{outline:["",...X()]}],"outline-offset":[{"outline-offset":[Pe,K]}],"outline-w":[{outline:[Pe,ze]}],"outline-color":[{outline:[e]}],"ring-w":[{ring:se()}],"ring-w-inset":["ring-inset"],"ring-color":[{ring:[e]}],"ring-opacity":[{"ring-opacity":[v]}],"ring-offset-w":[{"ring-offset":[Pe,ze]}],"ring-offset-color":[{"ring-offset":[e]}],shadow:[{shadow:["","inner","none",Fe,rp]}],"shadow-color":[{shadow:[at]}],opacity:[{opacity:[v]}],"mix-blend":[{"mix-blend":[...ue(),"plus-lighter","plus-darker"]}],"bg-blend":[{"bg-blend":ue()}],filter:[{filter:["","none"]}],blur:[{blur:[n]}],brightness:[{brightness:[o]}],contrast:[{contrast:[l]}],"drop-shadow":[{"drop-shadow":["","none",Fe,K]}],grayscale:[{grayscale:[d]}],"hue-rotate":[{"hue-rotate":[u]}],invert:[{invert:[f]}],saturate:[{saturate:[_]}],sepia:[{sepia:[I]}],"backdrop-filter":[{"backdrop-filter":["","none"]}],"backdrop-blur":[{"backdrop-blur":[n]}],"backdrop-brightness":[{"backdrop-brightness":[o]}],"backdrop-contrast":[{"backdrop-contrast":[l]}],"backdrop-grayscale":[{"backdrop-grayscale":[d]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[u]}],"backdrop-invert":[{"backdrop-invert":[f]}],"backdrop-opacity":[{"backdrop-opacity":[v]}],"backdrop-saturate":[{"backdrop-saturate":[_]}],"backdrop-sepia":[{"backdrop-sepia":[I]}],"border-collapse":[{border:["collapse","separate"]}],"border-spacing":[{"border-spacing":[i]}],"border-spacing-x":[{"border-spacing-x":[i]}],"border-spacing-y":[{"border-spacing-y":[i]}],"table-layout":[{table:["auto","fixed"]}],caption:[{caption:["top","bottom"]}],transition:[{transition:["none","all","","colors","opacity","shadow","transform",K]}],duration:[{duration:ye()}],ease:[{ease:["linear","in","out","in-out",K]}],delay:[{delay:ye()}],animate:[{animate:["none","spin","ping","pulse","bounce",K]}],transform:[{transform:["","gpu","none"]}],scale:[{scale:[N]}],"scale-x":[{"scale-x":[N]}],"scale-y":[{"scale-y":[N]}],rotate:[{rotate:[it,K]}],"translate-x":[{"translate-x":[te]}],"translate-y":[{"translate-y":[te]}],"skew-x":[{"skew-x":[B]}],"skew-y":[{"skew-y":[B]}],"transform-origin":[{origin:["center","top","top-right","right","bottom-right","bottom","bottom-left","left","top-left",K]}],accent:[{accent:["auto",e]}],appearance:[{appearance:["none","auto"]}],cursor:[{cursor:["auto","default","pointer","wait","text","move","help","not-allowed","none","context-menu","progress","cell","crosshair","vertical-text","alias","copy","no-drop","grab","grabbing","all-scroll","col-resize","row-resize","n-resize","e-resize","s-resize","w-resize","ne-resize","nw-resize","se-resize","sw-resize","ew-resize","ns-resize","nesw-resize","nwse-resize","zoom-in","zoom-out",K]}],"caret-color":[{caret:[e]}],"pointer-events":[{"pointer-events":["none","auto"]}],resize:[{resize:["none","y","x",""]}],"scroll-behavior":[{scroll:["auto","smooth"]}],"scroll-m":[{"scroll-m":M()}],"scroll-mx":[{"scroll-mx":M()}],"scroll-my":[{"scroll-my":M()}],"scroll-ms":[{"scroll-ms":M()}],"scroll-me":[{"scroll-me":M()}],"scroll-mt":[{"scroll-mt":M()}],"scroll-mr":[{"scroll-mr":M()}],"scroll-mb":[{"scroll-mb":M()}],"scroll-ml":[{"scroll-ml":M()}],"scroll-p":[{"scroll-p":M()}],"scroll-px":[{"scroll-px":M()}],"scroll-py":[{"scroll-py":M()}],"scroll-ps":[{"scroll-ps":M()}],"scroll-pe":[{"scroll-pe":M()}],"scroll-pt":[{"scroll-pt":M()}],"scroll-pr":[{"scroll-pr":M()}],"scroll-pb":[{"scroll-pb":M()}],"scroll-pl":[{"scroll-pl":M()}],"snap-align":[{snap:["start","end","center","align-none"]}],"snap-stop":[{snap:["normal","always"]}],"snap-type":[{snap:["none","x","y","both"]}],"snap-strictness":[{snap:["mandatory","proximity"]}],touch:[{touch:["auto","none","manipulation"]}],"touch-x":[{"touch-pan":["x","left","right"]}],"touch-y":[{"touch-pan":["y","up","down"]}],"touch-pz":["touch-pinch-zoom"],select:[{select:["none","text","all","auto"]}],"will-change":[{"will-change":["auto","scroll","contents","transform",K]}],fill:[{fill:[e,"none"]}],"stroke-w":[{stroke:[Pe,ze,Ut]}],stroke:[{stroke:[e,"none"]}],sr:["sr-only","not-sr-only"],"forced-color-adjust":[{"forced-color-adjust":["auto","none"]}]},conflictingClassGroups:{overflow:["overflow-x","overflow-y"],overscroll:["overscroll-x","overscroll-y"],inset:["inset-x","inset-y","start","end","top","right","bottom","left"],"inset-x":["right","left"],"inset-y":["top","bottom"],flex:["basis","grow","shrink"],gap:["gap-x","gap-y"],p:["px","py","ps","pe","pt","pr","pb","pl"],px:["pr","pl"],py:["pt","pb"],m:["mx","my","ms","me","mt","mr","mb","ml"],mx:["mr","ml"],my:["mt","mb"],size:["w","h"],"font-size":["leading"],"fvn-normal":["fvn-ordinal","fvn-slashed-zero","fvn-figure","fvn-spacing","fvn-fraction"],"fvn-ordinal":["fvn-normal"],"fvn-slashed-zero":["fvn-normal"],"fvn-figure":["fvn-normal"],"fvn-spacing":["fvn-normal"],"fvn-fraction":["fvn-normal"],"line-clamp":["display","overflow"],rounded:["rounded-s","rounded-e","rounded-t","rounded-r","rounded-b","rounded-l","rounded-ss","rounded-se","rounded-ee","rounded-es","rounded-tl","rounded-tr","rounded-br","rounded-bl"],"rounded-s":["rounded-ss","rounded-es"],"rounded-e":["rounded-se","rounded-ee"],"rounded-t":["rounded-tl","rounded-tr"],"rounded-r":["rounded-tr","rounded-br"],"rounded-b":["rounded-br","rounded-bl"],"rounded-l":["rounded-tl","rounded-bl"],"border-spacing":["border-spacing-x","border-spacing-y"],"border-w":["border-w-s","border-w-e","border-w-t","border-w-r","border-w-b","border-w-l"],"border-w-x":["border-w-r","border-w-l"],"border-w-y":["border-w-t","border-w-b"],"border-color":["border-color-s","border-color-e","border-color-t","border-color-r","border-color-b","border-color-l"],"border-color-x":["border-color-r","border-color-l"],"border-color-y":["border-color-t","border-color-b"],"scroll-m":["scroll-mx","scroll-my","scroll-ms","scroll-me","scroll-mt","scroll-mr","scroll-mb","scroll-ml"],"scroll-mx":["scroll-mr","scroll-ml"],"scroll-my":["scroll-mt","scroll-mb"],"scroll-p":["scroll-px","scroll-py","scroll-ps","scroll-pe","scroll-pt","scroll-pr","scroll-pb","scroll-pl"],"scroll-px":["scroll-pr","scroll-pl"],"scroll-py":["scroll-pt","scroll-pb"],touch:["touch-x","touch-y","touch-pz"],"touch-x":["touch"],"touch-y":["touch"],"touch-pz":["touch"]},conflictingClassGroupModifiers:{"font-size":["leading"]}}},cp=Gh(lp);function we(...e){return cp(ar(e))}const mr=S.createContext(null);function dp(){const e=S.useContext(mr);if(!e)throw new Error("useContextMenu must be used inside <ContextMenuHost>");return e}const $t=8;function up({children:e}){const[t,n]=S.useState({open:!1,x:0,y:0,items:[]}),[o,r]=S.useState(null),s=S.useRef(null),i=S.useCallback(()=>{n(d=>d.open?{...d,open:!1}:d)},[]),a=S.useCallback((d,u,f)=>{r(null),n({open:!0,x:d,y:u,items:f})},[]),l=S.useMemo(()=>({open:a,close:i}),[a,i]);return S.useLayoutEffect(()=>{if(!t.open||!s.current)return;const d=s.current.getBoundingClientRect();let u=t.x,f=t.y;u+d.width>window.innerWidth-$t&&(u=Math.max($t,t.x-d.width)),f+d.height>window.innerHeight-$t&&(f=Math.max($t,t.y-d.height)),r({left:u,top:f})},[t]),S.useEffect(()=>{if(!t.open)return;const d=g=>{s.current&&!s.current.contains(g.target)&&i()},u=g=>{g.key==="Escape"&&(g.preventDefault(),i())},f=()=>i(),p=()=>i();return document.addEventListener("pointerdown",d,!0),document.addEventListener("keydown",u,!0),window.addEventListener("wheel",f,{passive:!0}),window.addEventListener("blur",p),()=>{document.removeEventListener("pointerdown",d,!0),document.removeEventListener("keydown",u,!0),window.removeEventListener("wheel",f),window.removeEventListener("blur",p)}},[t.open,i]),c.jsxs(mr.Provider,{value:l,children:[e,t.open&&c.jsx("div",{ref:s,role:"menu","aria-orientation":"vertical",className:"ole-glass fixed z-50 min-w-[200px] rounded-md border border-border p-1 text-sm shadow-md",style:{left:(o==null?void 0:o.left)??t.x,top:(o==null?void 0:o.top)??t.y,visibility:o?"visible":"hidden"},onContextMenu:d=>d.preventDefault(),children:t.items.map((d,u)=>{if(d.type==="separator")return c.jsx("div",{role:"separator",className:"my-1 h-px bg-border"},`sep-${u}`);const f=d.icon;return c.jsxs("button",{type:"button",role:"menuitem",disabled:d.disabled,className:we("flex w-full items-center justify-between gap-3 rounded-sm px-2 py-1.5 text-left","hover:bg-accent hover:text-accent-foreground","focus-visible:bg-accent focus-visible:text-accent-foreground focus-visible:outline-none",d.destructive&&"text-destructive hover:bg-destructive/10 hover:text-destructive",d.disabled&&"pointer-events-none text-muted-foreground opacity-60"),onClick:()=>{i(),d.onSelect()},children:[c.jsxs("span",{className:"flex items-center gap-2",children:[f?c.jsx(f,{className:"size-4"}):null,c.jsx("span",{children:d.label})]}),d.shortcut?c.jsx("span",{className:"text-xs text-muted-foreground",children:d.shortcut}):null]},`${d.label}-${u}`)})})]})}const Yn=e=>{let t;const n=new Set,o=(d,u)=>{const f=typeof d=="function"?d(t):d;if(!Object.is(f,t)){const p=t;t=u??(typeof f!="object"||f===null)?f:Object.assign({},t,f),n.forEach(g=>g(t,p))}},r=()=>t,a={setState:o,getState:r,getInitialState:()=>l,subscribe:d=>(n.add(d),()=>n.delete(d))},l=t=e(o,r,a);return a},fp=(e=>e?Yn(e):Yn),mp=e=>e;function hp(e,t=mp){const n=S.useSyncExternalStore(e.subscribe,S.useCallback(()=>t(e.getState()),[e,t]),S.useCallback(()=>t(e.getInitialState()),[e,t]));return S.useDebugValue(n),n}const Xn=e=>{const t=fp(e),n=o=>hp(t,o);return Object.assign(n,t),n},zt=(e=>e?Xn(e):Xn),Vn={zh:{"common.unnamed":"未命名","common.close":"关闭","common.yes":"是","common.no":"否","topbar.theme.toLight":"切换到亮色","topbar.theme.toDark":"切换到暗色","topbar.theme.currentDark":"当前:暗色主题","topbar.theme.currentLight":"当前:亮色主题","topbar.lang.toEnglish":"Switch to English","topbar.lang.toChinese":"切换到中文","topbar.lang.currentEnglish":"Current: English","topbar.lang.currentChinese":"当前:中文","topbar.export.label":"导出","topbar.export.tooltip":"SVG 矢量(可编辑)、PNG 位图(2× 高清)或 DXF(CAD)","topbar.export.pngFailed":"导出 PNG 失败:{err}","topbar.export.dxfFailed":"导出 DXF 失败:{err}","topbar.file.label":"文件","topbar.file.tooltip":"打开本地 .json 图、保存、或另存为","topbar.file.current":"当前:{name}","topbar.file.new":"新建","topbar.file.open":"打开…","topbar.file.save":"保存","topbar.file.saveAs":"另存为…","topbar.file.newConfirm":"新建会清空当前未保存的内容,是否继续?","topbar.file.openFailed":"打开失败:{err}","topbar.file.saveFailed":"保存失败:{err}","topbar.file.fileDescription":"OneLineEditor 图纸","outline.title":"大纲","outline.collapse":"折叠","outline.collapseAria":"折叠大纲","outline.empty":"(无设备 — 从元件库拖入开始)","props.title":"属性","props.node":"电气节点","props.wire":"连线","props.bus":"母线","props.nSelected":"{n} 选中","props.empty":"未选中","props.multi":"已选中 {n} 个元件","props.name":"名称","props.note":"备注","props.nodeNotFound":"电气节点 {id} 不存在","props.wireNotFound":"连线 {id} 不存在","props.nodeStats":"{terminals} 个端子 · {elements} 个元件","props.selectElement":"选中 {label}","props.selectWholeNode":"选中整个电气节点","view.zoomOut":"缩小","view.zoomOutHint":"按预设档位缩小;也可滚轮 ↓ 或 ⌘−","view.reset":"重置到 100%","view.current":"当前 {z}%","view.zoomIn":"放大","view.zoomInHint":"按预设档位放大;也可滚轮 ↑ 或 ⌘+","view.fit":"适配视图","view.fitHint":"自动缩放并居中所有元件","view.gridHide":"隐藏网格","view.gridShow":"显示网格","view.gridHotkey":"G","view.gridHideHint":"同时关闭对齐吸附(拖动可自由放置)","view.gridShowHint":"同时开启对齐吸附(拖动会贴到 10px 网格)","view.gridHideAria":"隐藏网格并关闭吸附","view.gridShowAria":"显示网格并开启吸附","view.label":"标签","view.labelOff":"关闭标签","view.labelId":"仅显示 ID","view.labelAll":"ID + 参数","view.labelHint":"点击循环切换:关闭 → 仅 ID → ID + 参数","library.title":"元件库","library.empty":"没有匹配的元件","library.searchPlaceholder":"搜索元件…","library.searchAria":"搜索元件","library.clearSearch":"清除搜索","library.itemHint":"单击进入放置模式或拖到画布","tool.select":"选择","tool.selectHint":"点选元件,框选多个,或右键打开菜单","tool.pan":"平移","tool.panHint":"拖动画布;空格键可临时切换","tool.wire":"连线","tool.wireHint":"从一个端子拖动到另一个端子完成连线","tool.bus":"母线","tool.busHint":"画布上拖动一段母线,按下定起点、释放定终点","tool.place":"元件","tool.placeHint":"点击画布放置;或从端子/母线拖出,同时放置并连接","tool.text":"文字","tool.textHint":"点击画布放置一段文字注释;双击文字可重新编辑","mode.selectWithSel":"拖动元件移动 · 拖端子连线 · 右键打开菜单","mode.selectEmpty":"点选元件 · 拖动移动 · 框选多个 · 右键打开菜单","mode.pan":"拖动画布 · 滚轮缩放 · 按住空格可在其他工具下临时平移","mode.wireDragging":"拖到另一个端子或母线上释放完成连线","mode.wireInit":"从端子按下,拖动到另一个端子或母线上释放","mode.busDragging":"拖动决定母线方向,释放定终点","mode.busInit":"在画布按下定起点,拖动后释放定终点","mode.placeNoKind":"从左侧元件库选择一种元件","mode.placeFromTerm":"拖到目标位置释放,新元件将连接到起点端子","mode.placeNormal":"点击空白放置;或从已有端子 / 母线拖出,同时放置并连接","mode.text":"点击画布放置文字;双击已有文字可编辑;选中后可拖动 / 删除","mode.escSelect":"Esc 清除选择","mode.escOther":"右键 / Esc 取消","tool.placeNoKindTooltip":"从左侧元件库选择一个元件后点击画布放置","tool.undo":"撤销","tool.undoHint":"撤销上一次编辑(移动 / 旋转 / 删除等)","tool.redo":"重做","tool.redoHint":"重做被撤销的操作","layout.label":"布局","layout.hint":"自动排版整个图或仅选中范围,并填补空缺","layout.allAuto":"重新自动布局","layout.selAuto":"重新自动布局选区","layout.allFill":"填补未排版位置","layout.selFill":"填补未排版选区","tool.more":"更多","tool.moreHint":"撤销 / 重做 / 布局","view.menu":"视图","view.menuHint":"缩放、适配、网格","ctx.ariaNode":"选中节点操作","ctx.ariaWire":"选中连线操作","ctx.ariaElement":"选中元件操作","ctx.rotate":"旋转 90°","ctx.rotateHint":"顺时针旋转选中元件,连线随端子自动重排","ctx.mirror":"水平镜像","ctx.mirrorTitle":"镜像","ctx.mirrorHint":"左右翻转选中元件","ctx.delete":"删除","ctx.deleteHintNode":"断开此电气节点上的所有连接(保留元件)","ctx.deleteHintWire":"移除这一根连线(其它同节点连线保留)","ctx.deleteHintElement":"移除选中元件及其连接的连线","ctx.resetWirePath":"恢复自动走线","ctx.resetWirePathHint":"清除手动调整的拐点,让连线回到自动路由","menu.undo":"撤销","menu.redo":"重做","menu.cut":"剪切","menu.copy":"复制","menu.paste":"粘贴","menu.rotate":"旋转 90°","menu.mirror":"镜像","menu.selectAll":"全选","menu.disconnect":"断开此连线","menu.delete":"删除","io.parseFailed":"JSON 解析失败:{err}","io.notObject":"文件不是 JSON 对象","io.versionMismatch":'版本不兼容:期望 "1",实际 {actual}',"io.elementsMissing":"elements 字段缺失或不是数组","compile.duplicateId":'元件 ID 重复:"{id}"',"compile.unknownKind":'未知元件类型 kind="{kind}"',"compile.invalidTermRef":'非法端子引用 "{ref}"',"compile.elementMissing":'引用了不存在的元件 "{id}"',"compile.missingPin":'元件 "{id}" (kind={kind}) 没有引脚 "{pin}",可用引脚: {available}',"compile.singleTerminal":"节点只包含一个端子,已忽略","compile.layoutMissingElement":'layout 键 "{id}" 引用了不存在的元件',"compile.elementUnconnected":'元件 "{id}" 没有任何连接',"cat.busbar":"母线 / 接线","cat.switching":"开关","cat.protection":"保护","cat.motor-control":"电机控制","cat.transformer":"变压器","cat.instrument-transformer":"互感器","cat.measurement":"测量仪表","cat.source":"电源","cat.load":"负荷","cat.storage":"储能","cat.compensation":"无功补偿","cat.grounding":"中性点接地","cat.renewable":"新能源 / 电力电子","onboard.title":"上手三步","onboard.step1.title":"画母线","onboard.step1.body":"选择 母线 工具(B),在画布上按下拖动","onboard.step2.title":"从母线拖出元件","onboard.step2.body":"切到 元件(P)选一种,按住母线拖到目标位置 — 自动连接","onboard.step3.title":"继续串接","onboard.step3.body":"从任意端子拖出,落到目标即与该端子相连","onboard.dismiss":"知道了"},en:{"common.unnamed":"Untitled","common.close":"Close","common.yes":"Yes","common.no":"No","topbar.theme.toLight":"Switch to light","topbar.theme.toDark":"Switch to dark","topbar.theme.currentDark":"Current: dark theme","topbar.theme.currentLight":"Current: light theme","topbar.lang.toEnglish":"Switch to English","topbar.lang.toChinese":"切换到中文","topbar.lang.currentEnglish":"Current: English","topbar.lang.currentChinese":"Current: Chinese","topbar.export.label":"Export","topbar.export.tooltip":"SVG vector (editable), PNG bitmap (2× HiDPI), or DXF (CAD)","topbar.export.pngFailed":"PNG export failed: {err}","topbar.export.dxfFailed":"DXF export failed: {err}","topbar.file.label":"File","topbar.file.tooltip":"Open a local .json diagram, save, or save as","topbar.file.current":"Current: {name}","topbar.file.new":"New","topbar.file.open":"Open…","topbar.file.save":"Save","topbar.file.saveAs":"Save as…","topbar.file.newConfirm":"New will discard any unsaved changes. Continue?","topbar.file.openFailed":"Open failed: {err}","topbar.file.saveFailed":"Save failed: {err}","topbar.file.fileDescription":"OneLineEditor diagram","outline.title":"Outline","outline.collapse":"Collapse","outline.collapseAria":"Collapse outline","outline.empty":"(No elements — drag from the library to start)","props.title":"Properties","props.node":"Electrical node","props.wire":"Wire","props.bus":"Bus","props.nSelected":"{n} selected","props.empty":"Nothing selected","props.multi":"{n} elements selected","props.name":"Name","props.note":"Note","props.nodeNotFound":"Electrical node {id} not found","props.wireNotFound":"Wire {id} not found","props.nodeStats":"{terminals} terminals · {elements} elements","props.selectElement":"Select {label}","props.selectWholeNode":"Select whole electrical node","view.zoomOut":"Zoom out","view.zoomOutHint":"Step zoom out; also wheel ↓ or ⌘−","view.reset":"Reset to 100%","view.current":"Current {z}%","view.zoomIn":"Zoom in","view.zoomInHint":"Step zoom in; also wheel ↑ or ⌘+","view.fit":"Fit view","view.fitHint":"Auto-zoom and center all elements","view.gridHide":"Hide grid","view.gridShow":"Show grid","view.gridHotkey":"G","view.gridHideHint":"Also disables snap-to-grid (free placement)","view.gridShowHint":"Also enables snap-to-grid (snaps to 10px on drag)","view.gridHideAria":"Hide grid and disable snap","view.gridShowAria":"Show grid and enable snap","view.label":"Labels","view.labelOff":"Hide labels","view.labelId":"ID only","view.labelAll":"ID + params","view.labelHint":"Cycle: off → ID → ID + params","library.title":"Library","library.empty":"No matching elements","library.searchPlaceholder":"Search elements…","library.searchAria":"Search elements","library.clearSearch":"Clear search","library.itemHint":"Click to enter place mode, or drag onto the canvas","tool.select":"Select","tool.selectHint":"Click to pick, marquee for multiple, right-click for menu","tool.pan":"Pan","tool.panHint":"Drag the canvas; Space toggles temporarily","tool.wire":"Wire","tool.wireHint":"Drag from one terminal to another to wire","tool.bus":"Busbar","tool.busHint":"Drag on the canvas — press to set start, release to set end","tool.place":"Place","tool.placeHint":"Click to place; or drag from a terminal/bus to place and connect","tool.text":"Text","tool.textHint":"Click the canvas to drop a text note; double-click an existing one to edit","mode.selectWithSel":"Drag elements · drag terminals to wire · right-click for menu","mode.selectEmpty":"Click to pick · drag to move · marquee for multiple · right-click for menu","mode.pan":"Drag the canvas · scroll to zoom · hold Space to pan in any tool","mode.wireDragging":"Release on another terminal or busbar to complete the wire","mode.wireInit":"Press on a terminal, drag to another terminal or busbar, release","mode.busDragging":"Drag sets bus direction; release sets the end","mode.busInit":"Press on the canvas to set start, drag, release to set end","mode.placeNoKind":"Pick an element kind from the library on the left","mode.placeFromTerm":"Release at the target — the new element will connect back to the source terminal","mode.placeNormal":"Click empty space to place; or drag from a terminal / bus to place and connect","mode.text":"Click to drop text · double-click to edit · drag selected to move · Del to remove","mode.escSelect":"Esc clears selection","mode.escOther":"Right-click / Esc to cancel","tool.placeNoKindTooltip":"Pick a kind in the library on the left, then click the canvas","tool.undo":"Undo","tool.undoHint":"Undo the last edit (move / rotate / delete, etc.)","tool.redo":"Redo","tool.redoHint":"Redo the last undone edit","layout.label":"Layout","layout.hint":"Auto-layout the whole diagram or just the selection, fill gaps","layout.allAuto":"Auto-layout all","layout.selAuto":"Auto-layout selection","layout.allFill":"Fill unplaced","layout.selFill":"Fill unplaced in selection","tool.more":"More","tool.moreHint":"Undo / redo / layout","view.menu":"View","view.menuHint":"Zoom, fit, grid","ctx.ariaNode":"Node actions","ctx.ariaWire":"Wire actions","ctx.ariaElement":"Element actions","ctx.rotate":"Rotate 90°","ctx.rotateHint":"Rotate selection clockwise; wires re-route through new terminals","ctx.mirror":"Mirror horizontally","ctx.mirrorTitle":"Mirror","ctx.mirrorHint":"Flip selection left-right","ctx.delete":"Delete","ctx.deleteHintNode":"Disconnect every wire on this node (elements stay)","ctx.deleteHintWire":"Remove only this wire (siblings on the same node stay)","ctx.deleteHintElement":"Remove the selection and its wires","ctx.resetWirePath":"Reset to auto-route","ctx.resetWirePathHint":"Drop manual corners and let the router re-draw this wire","menu.undo":"Undo","menu.redo":"Redo","menu.cut":"Cut","menu.copy":"Copy","menu.paste":"Paste","menu.rotate":"Rotate 90°","menu.mirror":"Mirror","menu.selectAll":"Select all","menu.disconnect":"Disconnect this wire","menu.delete":"Delete","io.parseFailed":"JSON parse failed: {err}","io.notObject":"File is not a JSON object","io.versionMismatch":'Version mismatch: expected "1", got {actual}',"io.elementsMissing":"`elements` is missing or not an array","compile.duplicateId":'Duplicate element id: "{id}"',"compile.unknownKind":'Unknown element kind="{kind}"',"compile.invalidTermRef":'Invalid terminal reference "{ref}"',"compile.elementMissing":'Reference to unknown element "{id}"',"compile.missingPin":'Element "{id}" (kind={kind}) has no pin "{pin}"; available: {available}',"compile.singleTerminal":"Node has only one terminal — ignored","compile.layoutMissingElement":'layout key "{id}" references an unknown element',"compile.elementUnconnected":'Element "{id}" has no connections',"cat.busbar":"Busbar / wiring","cat.switching":"Switching","cat.protection":"Protection","cat.motor-control":"Motor control","cat.transformer":"Transformer","cat.instrument-transformer":"Instrument transformer","cat.measurement":"Measurement","cat.source":"Source","cat.load":"Load","cat.storage":"Storage","cat.compensation":"Compensation","cat.grounding":"Grounding","cat.renewable":"Renewables / power electronics","onboard.title":"Quick start","onboard.step1.title":"Draw a busbar","onboard.step1.body":"Pick the busbar tool (B), then press and drag on the canvas","onboard.step2.title":"Drag elements from the bus","onboard.step2.body":"Switch to Place (P), pick a kind, then drag from the bus — it auto-connects","onboard.step3.title":"Chain the next one","onboard.step3.body":"Drag from any terminal — the new element drops pre-connected","onboard.dismiss":"Got it"}},hr="ole-locale";function pp(){if(typeof window>"u")return"zh";try{const e=window.localStorage.getItem(hr);if(e==="zh"||e==="en")return e}catch{}return typeof navigator<"u"&&typeof navigator.language=="string"?navigator.language.toLowerCase().startsWith("zh")?"zh":"en":"zh"}function Un(e){try{window.localStorage.setItem(hr,e)}catch{}}const kt=zt((e,t)=>({locale:pp(),setLocale:n=>{Un(n),e({locale:n})},toggle:()=>{const n=t().locale==="zh"?"en":"zh";Un(n),e({locale:n})}}));function pr(e,t){return t?e.replace(/\{(\w+)\}/g,(n,o)=>t[o]!==void 0?String(t[o]):`{${o}}`):e}function gr(e,t){return Vn[e][t]??Vn.zh[t]??t}function be(e,t){return pr(gr(kt.getState().locale,e),t)}function U(){const e=kt(t=>t.locale);return(t,n)=>pr(gr(e,t),n)}function xr(e,t){let n;try{n=e()}catch{return}return{getItem:r=>{var s;const i=l=>l===null?null:JSON.parse(l,void 0),a=(s=n.getItem(r))!=null?s:null;return a instanceof Promise?a.then(i):i(a)},setItem:(r,s)=>n.setItem(r,JSON.stringify(s,void 0)),removeItem:r=>n.removeItem(r)}}const un=e=>t=>{try{const n=e(t);return n instanceof Promise?n:{then(o){return un(o)(n)},catch(o){return this}}}catch(n){return{then(o){return this},catch(o){return un(o)(n)}}}},gp=(e,t)=>(n,o,r)=>{let s={storage:xr(()=>window.localStorage),partialize:y=>y,version:0,merge:(y,v)=>({...v,...y}),...t},i=!1,a=0;const l=new Set,d=new Set;let u=s.storage;if(!u)return e((...y)=>{console.warn(`[zustand persist middleware] Unable to update item '${s.name}', the given storage is currently unavailable.`),n(...y)},o,r);const f=()=>{const y=s.partialize({...o()});return u.setItem(s.name,{state:y,version:s.version})},p=r.setState;r.setState=(y,v)=>(p(y,v),f());const g=e((...y)=>(n(...y),f()),o,r);r.getInitialState=()=>g;let m;const h=()=>{var y,v;if(!u)return;const b=++a;i=!1,l.forEach(N=>{var I;return N((I=o())!=null?I:g)});const _=((v=s.onRehydrateStorage)==null?void 0:v.call(s,(y=o())!=null?y:g))||void 0;return un(u.getItem.bind(u))(s.name).then(N=>{if(N)if(typeof N.version=="number"&&N.version!==s.version){if(s.migrate){const I=s.migrate(N.state,N.version);return I instanceof Promise?I.then(B=>[!0,B]):[!0,I]}console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return[!1,N.state];return[!1,void 0]}).then(N=>{var I;if(b!==a)return;const[B,re]=N;if(m=s.merge(re,(I=o())!=null?I:g),n(m,!0),B)return f()}).then(()=>{b===a&&(_==null||_(o(),void 0),m=o(),i=!0,d.forEach(N=>N(m)))}).catch(N=>{b===a&&(_==null||_(void 0,N))})};return r.persist={setOptions:y=>{s={...s,...y},y.storage&&(u=y.storage)},clearStorage:()=>{u==null||u.removeItem(s.name)},getOptions:()=>s,rehydrate:()=>h(),hasHydrated:()=>i,onHydrate:y=>(l.add(y),()=>{l.delete(y)}),onFinishHydration:y=>(d.add(y),()=>{d.delete(y)})},s.skipHydration||h(),m||g},xp=gp,Oe=.5;function yr(e){if(e.length<2)return e.map(r=>[r[0],r[1]]);const t=[[e[0][0],e[0][1]]];for(let r=1;r<e.length;r++){const s=t[t.length-1];Math.abs(s[0]-e[r][0])<Oe&&Math.abs(s[1]-e[r][1])<Oe||t.push([e[r][0],e[r][1]])}if(t.length<2)return t;const n=[t[0]];for(let r=1;r<t.length;r++){const s=n[n.length-1],i=t[r],a=Math.abs(s[0]-i[0]),l=Math.abs(s[1]-i[1]);if(a>Oe&&l>Oe){const u=(n.length>=2?Math.abs(n[n.length-2][1]-s[1])<Oe?"h":"v":null)==="h"?[i[0],s[1]]:[s[0],i[1]];n.push(u)}n.push(i)}const o=[n[0]];for(let r=1;r<n.length-1;r++){const s=o[o.length-1],i=n[r],a=n[r+1],l=Math.abs(s[0]-i[0])<Oe&&Math.abs(i[0]-a[0])<Oe,d=Math.abs(s[1]-i[1])<Oe&&Math.abs(i[1]-a[1])<Oe;l||d||o.push(i)}return o.push(n[n.length-1]),o}function br(){return{elements:new Map,buses:new Map,terminals:new Map,nodes:new Map,layout:new Map,wireRenders:new Map,terminalToNode:new Map,elementToTerminals:new Map,diagnostics:[]}}function wr(e){return{at:(e==null?void 0:e.at)??[0,0],rot:(e==null?void 0:e.rot)??0,mirror:(e==null?void 0:e.mirror)??!1}}function fn(e){return e===90||e===270?"y":"x"}function Le(e,t){let[n,o]=e;switch(t.mirror&&(n=-n),t.rot){case 0:break;case 90:[n,o]=[-o,n];break;case 180:[n,o]=[-n,-o];break;case 270:[n,o]=[o,-n];break}return[n+t.at[0],o+t.at[1]]}const yp={n:"e",e:"s",s:"w",w:"n"},bp={n:"n",s:"s",e:"w",w:"e"};function gt(e,t){let n=t.mirror?bp[e]:e;const o=t.rot/90|0;for(let r=0;r<o;r++)n=yp[n];return n}function mn(e){switch(e){case"n":return[0,-1];case"s":return[0,1];case"e":return[1,0];case"w":return[-1,0]}}class vr{constructor(){st(this,"parent",new Map);st(this,"rank",new Map)}add(t){this.parent.has(t)||(this.parent.set(t,t),this.rank.set(t,0))}find(t){this.add(t);let n=t;for(;this.parent.get(n)!==n;){const o=this.parent.get(n),r=this.parent.get(o);this.parent.set(n,r),n=r}return n}union(t,n){const o=this.find(t),r=this.find(n);if(o===r)return;const s=this.rank.get(o),i=this.rank.get(r);s<i?this.parent.set(o,r):s>i?this.parent.set(r,o):(this.parent.set(r,o),this.rank.set(o,s+1))}groups(){const t=new Map;for(const n of this.parent.keys()){const o=this.find(n),r=t.get(o);r?r.push(n):t.set(o,[n])}return t}}const Zn=["n","e","s","w"],Jn={n:"s",s:"n",e:"w",w:"e"};function Qn(e,t){const n=Zn.indexOf(e),r=((Zn.indexOf(t)-n)%4+4)%4;return[0,90,180,270][r]}const wp=320,eo=220,lt=260,to=720,ct=30,no=30,dt=80,oo=10,vp=60,kp=520,_p=80,Sp=80,ro=8,so=new Set(["source","renewable"]);function jp(e){var Bn,Rn,Dn,zn,Fn,Hn;const{elements:t,buses:n,wires:o,library:r,userLayout:s,userBusLayout:i}=e,a=new Map(s),l=new Map(i),d=new Map;for(const w of t)d.set(w.id,w);const u=new Map;for(const w of n)u.set(w.id,w);const f=w=>{const k=d.get(w);if(k)return r.get(k.kind)},p=new Set(n.map(w=>w.id)),g=w=>p.has(w),m=new vr;for(const w of o)m.add(w.ends[0]),m.add(w.ends[1]),m.union(w.ends[0],w.ends[1]);for(const w of t){const k=r.get(w.kind);if(k)for(const j of k.terminals)m.add(`${w.id}.${j.id}`)}for(const w of n)m.add(w.id);const h=[];for(const[,w]of m.groups())w.length>=2&&h.push(w);const y=new Map;for(const w of h)for(const k of w)y.set(k,[w]);const v=new Map;for(const w of h){const k=w.filter(g);if(k.length!==0)for(const j of k){const T=w.filter($=>$!==j),L=v.get(j)??[];L.push(...T),v.set(j,L)}}const b=new Map;for(const w of h){const k=w.filter(g);if(k.length!==0)for(const j of w){if(g(j))continue;const T=j.indexOf(".");if(T<0)continue;const L=j.slice(0,T),$=j.slice(T+1),A=b.get(L)??[];for(const D of k)A.some(P=>P.busId===D&&P.pin===$)||A.push({busId:D,pin:$});b.set(L,A)}}const _=[],N=new Set;for(const[w,k]of b)if(new Set(k.map(T=>T.busId)).size>=2){const T=((Rn=r.get(((Bn=d.get(w))==null?void 0:Bn.kind)??""))==null?void 0:Rn.category)==="transformer"?"vertical":"horizontal";_.push({elementId:w,attachments:k,orientation:T}),T==="vertical"&&N.add(w)}const I=new Map,B=(w,k)=>{w!==k&&(I.has(w)||I.set(w,new Set),I.has(k)||I.set(k,new Set),I.get(w).add(k),I.get(k).add(w))};for(const w of o)B(w.ends[0],w.ends[1]);for(const w of t){const k=r.get(w.kind);if(!k||k.terminals.length<2)continue;const j=k.terminals.map(T=>`${w.id}.${T.id}`);for(let T=0;T<j.length;T++)for(let L=T+1;L<j.length;L++)B(j[T],j[L])}for(const w of t){if(N.has(w.id))continue;const k=r.get(w.kind);if(!k||k.category!=="transformer"||k.terminals.length<2)continue;const j=k.terminals.map($=>`${w.id}.${$.id}`),T=new Map;for(const $ of j){const A=$.slice(w.id.length+1);T.set(A,new Set);const D=new Set(j.filter(z=>z!==$)),P=new Set([$]),H=[$];for(;H.length>0;){const z=H.shift();if(g(z)){T.get(A).add(z);continue}const C=I.get(z);if(C)for(const O of C)P.has(O)||D.has(O)||(P.add(O),H.push(O))}}const L=new Set;for(const $ of T.values())for(const A of $)L.add(A);if(L.size>=2){const $=[];for(const[A,D]of T)for(const P of D)$.push({busId:P,pin:A});_.push({elementId:w.id,attachments:$,orientation:"vertical"}),N.add(w.id)}}const re=(w,k)=>{var D;const j=f(k),T=j?j.terminals.map(P=>`${k}.${P.id}`):[],L=w,$=new Set([L,...T]),A=[L];for(;A.length>0;){const P=A.shift(),H=P.indexOf(".");if(H>0){const C=P.slice(0,H),O=d.get(C);if(O){const R=(D=r.get(O.kind))==null?void 0:D.category;if(R&&so.has(R))return!0}}const z=I.get(P);if(z)for(const C of z)$.has(C)||($.add(C),A.push(C))}return!1};for(const w of _){if(w.orientation!=="horizontal")continue;const k=new Set(w.attachments.map(T=>T.busId));let j=0;for(const T of k)re(T,w.elementId)&&j++;j===1&&(w.orientation="vertical",N.add(w.elementId))}for(const w of t){if(N.has(w.id)||w.kind!=="breaker")continue;const k=r.get(w.kind);if(!k||k.terminals.length!==2)continue;const j=k.terminals.map($=>`${w.id}.${$.id}`),T=new Map;for(const $ of j){const A=$.slice(w.id.length+1),D=new Set(j.filter(z=>z!==$)),P=new Set([$]),H=[$];for(;H.length>0;){const z=H.shift();if(g(z)){T.set(A,z);break}const C=I.get(z);if(C)for(const O of C){if(P.has(O)||D.has(O))continue;const R=O.indexOf(".");if(R>0){const G=O.slice(0,R);if(G!==w.id){const Q=d.get(G),Z=Q?r.get(Q.kind):void 0;if((Z==null?void 0:Z.category)==="transformer")continue}}P.add(O),H.push(O)}}}if(new Set(T.values()).size>=2){const $=[];for(const[A,D]of T)$.push({busId:D,pin:A});_.push({elementId:w.id,attachments:$,orientation:"horizontal"})}}const te=new Map;for(const w of n)te.set(w.id,new Map);for(const w of _){const k=Array.from(new Set(w.attachments.map(j=>j.busId)));for(const j of k)for(const T of k)j!==T&&((Dn=te.get(j))==null||Dn.set(T,w))}const ve=w=>{var j;const k=(j=r.get(w))==null?void 0:j.category;return k?so.has(k):!1},me=[];for(const w of n){const k=v.get(w.id);if(k)for(const j of k){if(g(j))continue;const T=j.indexOf(".");if(T<0)continue;const L=j.slice(0,T),$=d.get(L);if($&&ve($.kind)){me.push(w.id);break}}}me.length===0&&n.length>0&&me.push(n[0].id);const E=new Map;for(const w of me)E.set(w,0);{const w=[...me];for(;w.length>0;){const k=w.shift(),j=E.get(k),T=te.get(k);if(T)for(const[L,$]of T){if(E.has(L))continue;const A=$.orientation==="horizontal"?j:j+1;E.set(L,A),w.push(L)}}}for(const w of n){if(E.has(w.id))continue;const k=E.size===0?-1:Math.max(...Array.from(E.values()));E.set(w.id,k+1)}const M=new Map;for(const w of n){const k=E.get(w.id),j=M.get(k)??[];j.push(w.id),M.set(k,j)}const se=[...M.keys()].sort((w,k)=>w-k),ne=(w,k,j)=>{const T=`${w.elementId}.${j}`,L=k,$=f(w.elementId),A=new Set;if($)for(const C of $.terminals)C.id!==j&&A.add(`${w.elementId}.${C.id}`);const D=new Set([T]),P=[{ref:T,dist:0}],H=new Map,z=(C,O,R,G)=>{D.add(C),H.set(C,O),P.push({ref:C,dist:G+R})};for(;P.length>0;){const{ref:C,dist:O}=P.shift();if(C===L){const Z=H.get(L);let le;if(Z){const q=Z.indexOf(".");if(q>0){const F=Z.slice(0,q);F!==w.elementId&&(le=F)}}return{extent:O,head:le}}const R=C.indexOf(".");if(R<0)continue;const G=C.slice(0,R),Q=C.slice(R+1);if(!g(G)&&!N.has(G)){const Z=f(G),le=Z==null?void 0:Z.terminals.find(q=>q.id===Q);if(Z&&le)for(const q of Z.terminals){if(q.id===Q)continue;const F=`${G}.${q.id}`;D.has(F)||A.has(F)||z(F,C,Math.abs(le.y-q.y),O)}}for(const Z of y.get(C)??[])for(const le of Z){if(le===C||D.has(le)||A.has(le))continue;const q=g(C)||g(le);z(le,C,q?no:ct,O)}}return{extent:0}},ce=(w,k)=>{var C,O,R;const j=(C=te.get(w))==null?void 0:C.get(k);if(!j||j.orientation==="horizontal")return lt;const T=f(j.elementId);if(!T)return lt;const L=(O=j.attachments.find(G=>G.busId===w))==null?void 0:O.pin,$=(R=j.attachments.find(G=>G.busId===k))==null?void 0:R.pin;if(!L||!$)return lt;const A=T.terminals.find(G=>G.id===L),D=T.terminals.find(G=>G.id===$);if(!A||!D)return lt;const P=Math.abs(D.y-A.y),H=ne(j,w,L).extent,z=ne(j,k,$).extent;return H+P+z},X=new Map;for(const w of _){if(w.orientation!=="vertical")continue;const k=w.attachments.slice().sort((D,P)=>(E.get(D.busId)??0)-(E.get(P.busId)??0));if(k.length<2)continue;const j=k[0].busId,T=k[1].busId,L=k[0].pin,A=ne(w,j,L).head??w.elementId;X.set(A,{lowerBusId:T})}const ue=320,ae=new Map,he=(w,k)=>{if(!N.has(w))return!1;const j=_.find(A=>A.elementId===w),T=j==null?void 0:j.attachments.find(A=>A.busId!==k);if(!T)return!1;const L=E.get(k)??0;return(E.get(T.busId)??0)<L},ke=(w,k)=>{const j=X.get(w);if(j){const T=ae.get(j.lowerBusId);if(T!==void 0)return Math.max(k,T+dt)}return Math.max(k,dt)},ye=(w,k)=>{if(ae.has(w))return ae.get(w);if(k.has(w))return ue;k.add(w);const j=v.get(w)??[];let T=0,L=0;for(const A of j){if(g(A))continue;const D=A.indexOf(".");if(D<0)continue;const P=A.slice(0,D),H=A.slice(D+1);if(he(P,w))continue;const z=f(P);if(!z)continue;const C=z.terminals.find(G=>G.id===H);if(!C)continue;const O=X.get(P);O&&ye(O.lowerBusId,k);const R=ke(P,z.width);C.y>0?T+=R:L+=R}const $=Math.max(ue,Math.max(T,L)+dt);return ae.set(w,$),k.delete(w),$};for(const w of n)ye(w.id,new Set);const De=new Map,oh=(w,k,j)=>{const T=f(k);if(!T)return;const L=`${k}.${j}`,$=T.terminals.filter(P=>P.id!==j).map(P=>`${k}.${P.id}`);if($.length===0)return;const A=new Set([L,...$]),D=$.slice();for(;D.length>0;){const P=D.shift();if(g(P)&&P!==w){const z=l.get(P);return z?z.at[0]:void 0}for(const z of y.get(P)??[])for(const C of z)C===P||A.has(C)||(A.add(C),D.push(C));const H=P.indexOf(".");if(H>0){const z=P.slice(0,H);if(!g(z)){const C=f(z);if(C)for(const O of C.terminals){const R=`${z}.${O.id}`;A.has(R)||(A.add(R),D.push(R))}}}}},rh=w=>{const k=v.get(w);if(!k||k.length===0)return;const j=l.get(w);if(!j)return;const T=k.flatMap(C=>{if(g(C))return[];const O=C.indexOf(".");if(O<0)return[];const R=C.slice(0,O),G=C.slice(O+1);if(a.has(R))return[];if(he(R,w))return[];const Q=f(R);if(!Q)return[];const Z=Q.terminals.find(le=>le.id===G);return Z?[{elId:R,lib:Q,localTerm:Z,isLinker:N.has(R)}]:[]});if(T.length===0)return;const L=[],$=[];for(const C of T)C.localTerm.y>0?L.push(C):$.push(C);const A=C=>C.reduce((O,R)=>O+ke(R.elId,R.lib.width),0),D=Math.max(A(L),A($))+dt,P=Math.max(j.span,D);P!==j.span&&l.set(w,{...j,span:P});const H=l.get(w),z=(C,O)=>{if(C.length===0)return;const R=new Map;for(const W of C){const Y=oh(w,W.elId,W.localTerm.id);Y!==void 0&&R.set(W.elId,Y)}C.sort((W,Y)=>{const fe=R.get(W.elId)??H.at[0],_e=R.get(Y.elId)??H.at[0];if(fe!==_e)return fe-_e;const Ae=ke(W.elId,W.lib.width);return ke(Y.elId,Y.lib.width)-Ae});const G=C.map(W=>ke(W.elId,W.lib.width)),Q=G.reduce((W,Y)=>W+Y,0),Z=Math.max(P,Q),le=(Z-Q)/(C.length+1);let q=H.at[0]-Z/2+le;const F=H.at[1]+O*no;for(let W=0;W<C.length;W++){const Y=C[W],fe=G[W],_e=q+fe/2;Y.isLinker?De.has(Y.elId)||De.set(Y.elId,_e):a.set(Y.elId,{at:[ge(_e-Y.localTerm.x),ge(F-Y.localTerm.y)],rot:0,mirror:!1}),q+=fe+le}};z(L,-1),z($,1)},sh=w=>{if(a.has(w.elementId)||w.orientation==="horizontal")return;const k=f(w.elementId);if(!k)return;const j=w.attachments.filter(q=>l.has(q.busId));if(j.length<2)return;const T=j.slice().sort((q,F)=>(E.get(q.busId)??0)-(E.get(F.busId)??0)),L=T[0].busId,$=l.get(L),A=T[0].pin,D=T[T.length-1].pin,P=k.terminals.find(q=>q.id===A),H=k.terminals.find(q=>q.id===D);if(!P||!H)return;const z=P.y<=H.y?0:180,C=E.get(L)??0,O=j.filter(q=>(E.get(q.busId)??0)===C),R=[];let G=0;for(const q of O){const F=ne(w,q.busId,q.pin);G=Math.max(G,F.extent);const W=F.head?a.get(F.head):void 0;W?R.push(W.at[0]):De.has(w.elementId)?R.push(De.get(w.elementId)):R.push(l.get(q.busId).at[0])}let Q;R.length>0?Q=R.reduce((q,F)=>q+F,0)/R.length:De.has(w.elementId)?Q=De.get(w.elementId):Q=$.at[0];const Z=$.at[1]+G,le=z===0?[ge(Q-P.x),ge(Z-P.y)]:[ge(Q+P.x),ge(Z+P.y)];if(a.set(w.elementId,{at:le,rot:z,mirror:!1}),O.length>1){const q=a.get(w.elementId),F=Le([P.x,P.y],q),W=gt(P.orientation,q);ih(`${w.elementId}.${A}`,F,W,Q)}},ih=(w,k,j,T)=>{const L=new Set([w]);let $=w,A=k,D=j;for(;;){const P=y.get($)??[];let H,z=!1;for(const Ce of P){if(Ce.length>=3){z=!0;break}const Ye=Ce.find(Vt=>Vt!==$);if(!(!Ye||L.has(Ye))){if(g(Ye)){z=!0;break}H=Ye;break}}if(z||!H)break;const C=H.indexOf(".");if(C<0)break;const O=H.slice(0,C),R=H.slice(C+1);if(g(O)||N.has(O)||a.has(O))break;const G=f(O);if(!G)break;const Q=G.terminals.find(Ce=>Ce.id===R);if(!Q)break;const Z=mn(D),le=[A[0]+Z[0]*ct,A[1]+Z[1]*ct],q=Jn[D],F=Qn(Q.orientation,q),W=Le([Q.x,Q.y],{at:[0,0],rot:F,mirror:!1}),Y=[ge(T-W[0]),ge(le[1]-W[1])];a.set(O,{at:Y,rot:F,mirror:!1}),L.add(H);const fe=G.terminals.find(Ce=>Ce.id!==R);if(!fe)break;const _e=`${O}.${fe.id}`;L.add(_e);const Ae={at:Y,rot:F,mirror:!1};A=Le([fe.x,fe.y],Ae),D=gt(fe.orientation,Ae),$=_e}},ah=w=>{if(a.has(w.elementId)||w.orientation!=="horizontal")return;const k=f(w.elementId);if(!k)return;const j=w.attachments.filter(O=>l.has(O.busId));if(j.length<2)return;const T=j.map(O=>{const R=ne(w,O.busId,O.pin),G=R.head?a.get(R.head):void 0,Q=G?G.at[0]:l.get(O.busId).at[0];return{att:O,x:Q,extent:R.extent}});T.sort((O,R)=>O.x-R.x);const L=T[0],$=T[T.length-1],A=k.terminals.find(O=>O.id===L.att.pin),D=k.terminals.find(O=>O.id===$.att.pin);if(!A||!D)return;const P=A.y<=D.y?270:90,H=(L.x+$.x)/2,C=l.get(L.att.busId).at[1]+Math.max(L.extent,$.extent);a.set(w.elementId,{at:[ge(H),ge(C)],rot:P,mirror:!1})},lh=100;let jt=eo;for(let w=0;w<se.length;w++){const k=se[w],j=M.get(k);let T;if(w===0)T=eo;else{const $=M.get(se[w-1]);let A=0;for(const D of $)for(const P of j)(zn=te.get(D))!=null&&zn.get(P)&&(A=Math.max(A,ce(D,P)));A===0&&(A=lt),T=jt+A}jt=T;let L=wp;for(const $ of j){if(l.has($)){jt=Math.max(jt,l.get($).at[1]);continue}let A;if(w>0){const P=M.get(se[w-1]),H=[];for(const z of P){const C=(Fn=te.get(z))==null?void 0:Fn.get($);if(!C||C.orientation!=="vertical")continue;const O=(Hn=C.attachments.find(G=>G.busId===z))==null?void 0:Hn.pin;if(!O)continue;const R=ne(C,z,O);R.head&&a.has(R.head)?H.push(a.get(R.head).at[0]):De.has(C.elementId)?H.push(De.get(C.elementId)):H.push(l.get(z).at[0])}H.length>0&&(A=H.reduce((z,C)=>z+C,0)/H.length)}if(A===void 0){const P=ae.get($)??to;A=L+P/2,L+=P+lh}const D=ae.get($)??to;l.set($,{at:[ge(A),ge(T)],rot:0,span:D,axis:fn(0)})}for(const $ of j)rh($);if(w>0)for(const $ of _)a.has($.elementId)||!$.attachments.some(D=>j.includes(D.busId))||sh($);for(const $ of _)$.orientation!=="horizontal"||a.has($.elementId)||!$.attachments.every(D=>j.includes(D.busId))||ah($)}const ch=w=>{if(g(w))return l.has(w);const k=w.indexOf(".");return k<0?!1:a.has(w.slice(0,k))};let Yt=!0,dh=t.length+4;for(;Yt&&dh-- >0;){Yt=!1;for(const w of h){if(w.length<2)continue;const k=[],j=new Map;for(const F of w){if(g(F))continue;const W=F.indexOf(".");if(W<0)continue;const Y=F.slice(0,W),fe=F.slice(W+1);if(a.has(Y)){k.push(F);continue}if(N.has(Y)||j.has(Y))continue;const _e=f(Y);if(!_e)continue;const Ae=_e.terminals.find(Ce=>Ce.id===fe);Ae&&j.set(Y,{ref:F,elId:Y,lib:_e,localTerm:Ae})}if(j.size===0||k.length===0)continue;const T=[...j.values()],L=new Map;for(const F of T)for(const W of y.get(F.ref)??[])for(const Y of W){if(Y===F.ref||g(Y)||!ch(Y))continue;const fe=Y;L.set(fe,(L.get(fe)??0)+1)}let $;if(L.size>0){let F=-1;for(const[W,Y]of L)(Y>F||Y===F&&($===void 0||W<$))&&(F=Y,$=W)}if($||($=[...k].sort()[0]),!$)continue;const A=$.indexOf("."),D=$.slice(0,A),P=$.slice(A+1),H=f(D),z=a.get(D);if(!H||!z)continue;const C=H.terminals.find(F=>F.id===P);if(!C)continue;const O=Le([C.x,C.y],z),R=gt(C.orientation,z),G=mn(R),Q=[-G[1],G[0]];T.sort((F,W)=>F.elId.localeCompare(W.elId));const Z=T.map(F=>Math.max(F.lib.width,dt));let q=-Z.reduce((F,W)=>F+W,0)/2;for(let F=0;F<T.length;F++){const W=T[F],Y=Z[F],fe=q+Y/2;q+=Y;const _e=Jn[R],Ae=Qn(W.localTerm.orientation,_e),Ce=Le([W.localTerm.x,W.localTerm.y],{at:[0,0],rot:Ae,mirror:!1}),Ye=[O[0]+G[0]*ct+Q[0]*fe,O[1]+G[1]*ct+Q[1]*fe],Vt=[ge(Ye[0]-Ce[0]),ge(Ye[1]-Ce[1])];a.set(W.elId,{at:Vt,rot:Ae,mirror:!1}),Yt=!0}}}let Xt=0;for(const w of t){if(a.has(w.id))continue;const k=Xt%ro,j=Math.floor(Xt/ro);a.set(w.id,{at:[ge(vp+k*_p),ge(kp+j*Sp)],rot:0,mirror:!1}),Xt++}return{devices:a,buses:l}}function ge(e){return Math.round(e/oo)*oo}function $p(e,t){const n=e.ends[0],o=e.ends[1],r=io(n,t),s=io(o,t);if(r||s){const l=r?n:o,u=Zt(r?o:n,t);if(!u)return null;const f=t.buses.get(l);if(!f)return null;const{axis:p,at:g,span:m}=f.geometry,h=m/2;let y;if(p==="x")y=[Pt(u[0],g[0]-h,g[0]+h),g[1]];else{const v=Pt(u[1],g[1]-h,g[1]+h);y=[g[0],v]}return{wireId:e.id,path:lo(u,y)}}const i=Zt(n,t),a=Zt(o,t);return!i||!a?null:{wireId:e.id,path:lo(i,a)}}function io(e,t){return!e.includes(".")&&t.buses.has(e)}function Zt(e,t){if(!e.includes(".")){const o=t.buses.get(e);return o?o.geometry.at:null}const n=t.terminals.get(e);return n?n.world:null}function ao(e,t,n){if(!e.includes(".")){const r=n.buses.get(e);if(!r)return null;const{axis:s,at:i,span:a}=r.geometry;if(!t)return[i[0],i[1]];const l=a/2;if(s==="x")return[Pt(t[0],i[0]-l,i[0]+l),i[1]];const d=Pt(t[1],i[1]-l,i[1]+l);return[i[0],d]}const o=n.terminals.get(e);return o?[o.world[0],o.world[1]]:null}function lo(e,t){return e[0]===t[0]||e[1]===t[1]?[e,t]:[e,[e[0],t[1]],t]}function Pt(e,t,n){return e<t?t:e>n?n:e}const kr="ammeter",_r="电流表 (A)",Sr="measurement",jr="-22 -42 44 44",$r=44,Er=44,Nr='<ellipse cx="0" cy="-20" rx="20" ry="20" fill="none" stroke="black" stroke-width="1"/><text x="0" y="-15" text-anchor="middle" font-family="Liberation Sans, Arial, sans-serif" font-size="14">A</text>',Tr=[{id:"t_top",x:0,y:-40,orientation:"n"}],Cr={kind:"inline"},Ep={id:kr,name:_r,category:Sr,viewBox:jr,width:$r,height:Er,svg:Nr,terminals:Tr,source:Cr},Np=Object.freeze(Object.defineProperty({__proto__:null,category:Sr,default:Ep,height:Er,id:kr,name:_r,source:Cr,svg:Nr,terminals:Tr,viewBox:jr,width:$r},Symbol.toStringTag,{value:"Module"})),Ir="arc-suppression-coil",Ar="消弧线圈",Mr="grounding",Pr="中性点谐振接地:电感线圈连接到地",Or="-12 -32 24 67",Lr=24,Br=67,Rr='<line x1="0" y1="-30" x2="0" y2="-12" fill="none" stroke="black" stroke-width="1"/><path d="M 0 -12 A 4 4 0 0 1 0 -4 A 4 4 0 0 1 0 4 A 4 4 0 0 1 0 12" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="12" x2="0" y2="20" fill="none" stroke="black" stroke-width="1"/><line x1="-10" y1="20" x2="10" y2="20" fill="none" stroke="black" stroke-width="1"/><line x1="-7" y1="24" x2="7" y2="24" fill="none" stroke="black" stroke-width="1"/><line x1="-4" y1="28" x2="4" y2="28" fill="none" stroke="black" stroke-width="1"/><line x1="-1.5" y1="32" x2="1.5" y2="32" fill="none" stroke="black" stroke-width="1"/>',Dr=[{id:"t_top",x:0,y:-30,orientation:"n"}],zr={kind:"inline"},Tp={id:Ir,name:Ar,category:Mr,description:Pr,viewBox:Or,width:Lr,height:Br,svg:Rr,terminals:Dr,source:zr},Cp=Object.freeze(Object.defineProperty({__proto__:null,category:Mr,default:Tp,description:Pr,height:Br,id:Ir,name:Ar,source:zr,svg:Rr,terminals:Dr,viewBox:Or,width:Lr},Symbol.toStringTag,{value:"Module"})),Fr="arrester",Hr="避雷器 (FBL)",Wr="protection",Gr="-7 -22 14 44",Kr=14,qr=44,Yr='<line x1="0" y1="-20" x2="0" y2="-5" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="10" x2="0" y2="20" fill="none" stroke="black" stroke-width="1"/><polygon points="-2,-8 2,-8 0,-2" fill="black" stroke="black" stroke-width="1"/><rect x="-5" y="-10" width="10" height="20" rx="0" ry="0" fill="none" stroke="black" stroke-width="1"/>',Xr=[{id:"t1",x:0,y:-20,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],Vr={kind:"elmt",path:"91_en_60617/en_60617_07/en_60617_07_22/en_60617_07_22_03.elmt",qetEnglishName:"Surge diverter; Lightning arrester"},Ip={id:Fr,name:Hr,category:Wr,viewBox:Gr,width:Kr,height:qr,svg:Yr,terminals:Xr,source:Vr},Ap=Object.freeze(Object.defineProperty({__proto__:null,category:Wr,default:Ip,height:qr,id:Fr,name:Hr,source:Vr,svg:Yr,terminals:Xr,viewBox:Gr,width:Kr},Symbol.toStringTag,{value:"Module"})),Ur="async-motor",Zr="异步电动机",Jr="load",Qr="-62 -82 64 84",es=64,ts=84,ns='<ellipse cx="-30" cy="-30" rx="30" ry="30" fill="none" stroke="black" stroke-width="1"/><text x="-34" y="-24.8" font-family="Liberation Sans, Arial, sans-serif" font-size="14" fill="#000000">M</text><text x="-45" y="-7.8" font-family="Liberation Sans, Arial, sans-serif" font-size="14" fill="#000000">3</text><path d="M -25 -20 A 5 2.5 0 0 0 -35 -20" fill="none" stroke="black" stroke-width="1"/><path d="M -25 -20 A 5 2.5 0 0 0 -15 -20" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-80" x2="-30" y2="-60" fill="none" stroke="black" stroke-width="1"/><line x1="-50" y1="-80" x2="-50" y2="-53" fill="none" stroke="black" stroke-width="1"/><line x1="-10" y1="-80" x2="-10" y2="-53" fill="none" stroke="black" stroke-width="1"/>',os=[{id:"t1",x:-50,y:-80,orientation:"n"},{id:"t2",x:-10,y:-80,orientation:"n"},{id:"t3",x:-30,y:-80,orientation:"n"}],rs={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_08/en_60617_06_08_01.elmt",qetEnglishName:"Induction motor, three-phase, squirrel cage"},Mp={id:Ur,name:Zr,category:Jr,viewBox:Qr,width:es,height:ts,svg:ns,terminals:os,source:rs},Pp=Object.freeze(Object.defineProperty({__proto__:null,category:Jr,default:Mp,height:ts,id:Ur,name:Zr,source:rs,svg:ns,terminals:os,viewBox:Qr,width:es},Symbol.toStringTag,{value:"Module"})),ss="autotransformer",is="自耦变压器",as="transformer",ls="-62 -112 64 144",cs=64,ds=144,us='<ellipse cx="-30" cy="-30" rx="30" ry="30" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-110" x2="-30" y2="-90" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="0" x2="-30" y2="20" fill="none" stroke="black" stroke-width="1"/><path d="M 0 -30 A 30 60 0 0 0 -30 -90" fill="none" stroke="black" stroke-width="1"/>',fs=[{id:"t1",x:-30,y:-110,orientation:"n"},{id:"t_bottom",x:-30,y:20,orientation:"s"}],ms={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_09/en_60617_06_09_06.elmt",qetEnglishName:"Auto-transformer, general symbol"},Op={id:ss,name:is,category:as,viewBox:ls,width:cs,height:ds,svg:us,terminals:fs,source:ms},Lp=Object.freeze(Object.defineProperty({__proto__:null,category:as,default:Op,height:ds,id:ss,name:is,source:ms,svg:us,terminals:fs,viewBox:ls,width:cs},Symbol.toStringTag,{value:"Module"})),hs="battery",ps="电池储能",gs="storage",xs="-12 -12 29 24",ys=29,bs=24,ws='<line x1="-10" y1="0" x2="0" y2="0" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="-5" x2="0" y2="5" fill="none" stroke="black" stroke-width="1"/><line x1="5" y1="-10" x2="5" y2="10" fill="none" stroke="black" stroke-width="1"/><line x1="5" y1="0" x2="15" y2="0" fill="none" stroke="black" stroke-width="1"/>',vs=[{id:"t_left",x:-10,y:0,orientation:"w"},{id:"t_right",x:15,y:0,orientation:"e"}],ks=[{name:"E",label:"容量",type:"number",unit:"kWh"}],_s={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_15/en_60617_06_15_01.elmt",qetEnglishName:"Battery cell"},Bp={id:hs,name:ps,category:gs,viewBox:xs,width:ys,height:bs,svg:ws,terminals:vs,params:ks,source:_s},Rp=Object.freeze(Object.defineProperty({__proto__:null,category:gs,default:Bp,height:bs,id:hs,name:ps,params:ks,source:_s,svg:ws,terminals:vs,viewBox:xs,width:ys},Symbol.toStringTag,{value:"Module"})),Ss="breaker",js="断路器 (QF)",$s="switching",Es="-7 -22 15 46",Ns=15,Ts=46,Cs='<polyline points="0,20 0,10 -5,-10" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="-20" x2="0" y2="-10" fill="none" stroke="black" stroke-width="1"/><line x1="2" y1="-8" x2="-2" y2="-12" fill="none" stroke="black" stroke-width="1"/><line x1="2" y1="-12" x2="-2" y2="-8" fill="none" stroke="black" stroke-width="1"/><text x="2" y="-10.8" font-family="Liberation Sans, Arial, sans-serif" font-size="6" fill="#000000">1</text><text x="3" y="21.2" font-family="Liberation Sans, Arial, sans-serif" font-size="6" fill="#000000">2</text>',Is=[{id:"t1",x:0,y:-20,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],As=[{name:"open",type:"boolean",default:!1,label:"断开"}],Ms={x:6,y:-2,anchor:"start"},Ps={kind:"elmt",path:"11_singlepole/200_fuses_protective_gears/11_circuit_breakers/disjoncteur1.elmt",qetEnglishName:"Circuit-breaker"},Dp={id:Ss,name:js,category:$s,viewBox:Es,width:Ns,height:Ts,svg:Cs,terminals:Is,state:As,label:Ms,source:Ps},zp=Object.freeze(Object.defineProperty({__proto__:null,category:$s,default:Dp,height:Ts,id:Ss,label:Ms,name:js,source:Ps,state:As,svg:Cs,terminals:Is,viewBox:Es,width:Ns},Symbol.toStringTag,{value:"Module"})),Os="busbar",Ls="母线段",Bs="busbar",Rs="可拉伸单母线段,多设备挂接",Ds="-42 -4 84 8",zs=84,Fs=8,Hs='<line x1="-40" y1="0" x2="40" y2="0" stroke="black" stroke-width="3" stroke-linecap="round" fill="none"/>',Ws=[{id:"tap",x:0,y:0,orientation:"n"}],Gs={axis:"x",minLength:20,naturalSpan:80},Ks=[{name:"Un",label:"额定电压",type:"number",unit:"kV",showOnCanvas:!0}],qs={x:0,y:-6,anchor:"middle"},Ys={kind:"inline"},Fp={id:Os,name:Ls,category:Bs,description:Rs,viewBox:Ds,width:zs,height:Fs,svg:Hs,terminals:Ws,stretchable:Gs,params:Ks,label:qs,source:Ys},Hp=Object.freeze(Object.defineProperty({__proto__:null,category:Bs,default:Fp,description:Rs,height:Fs,id:Os,label:qs,name:Ls,params:Ks,source:Ys,stretchable:Gs,svg:Hs,terminals:Ws,viewBox:Ds,width:zs},Symbol.toStringTag,{value:"Module"})),Xs="contactor",Vs="接触器 (KM)",Us="motor-control",Zs="主回路接触器, 通常配热继电器和电机使用。",Js="-10 -42 15 64",Qs=15,ei=64,ti='<line x1="0" y1="-20" x2="0" y2="-40" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="0" x2="0" y2="20" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="0" x2="-8" y2="-23" fill="none" stroke="black" stroke-width="1"/><path d="M 0 -24.5 A 2.5 2.5 0 0 0 0 -19.5" fill="none" stroke="black" stroke-width="1"/>',ni=[{id:"t1",x:0,y:-40,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],oi=[{name:"open",type:"boolean",default:!0,label:"断开"}],ri={kind:"elmt",path:"91_en_60617/en_60617_07/en_60617_07_13/en_60617_07_13_02.elmt",qetEnglishName:"Contactor; Main make contact of a contactor"},Wp={id:Xs,name:Vs,category:Us,description:Zs,viewBox:Js,width:Qs,height:ei,svg:ti,terminals:ni,state:oi,source:ri},Gp=Object.freeze(Object.defineProperty({__proto__:null,category:Us,default:Wp,description:Zs,height:ei,id:Xs,name:Vs,source:ri,state:oi,svg:ti,terminals:ni,viewBox:Js,width:Qs},Symbol.toStringTag,{value:"Module"})),si="converter-bidir",ii="双向变流器 (PCS)",ai="renewable",li="储能变流器:双向 AC ↔ DC",ci="-42 -42 44 48",di=44,ui=48,fi='<line x1="-40" y1="0" x2="0" y2="-40" fill="none" stroke="black" stroke-width="1"/><rect x="-40" y="-40" width="40" height="40" rx="0" ry="0" fill="none" stroke="black" stroke-width="1"/><line x1="-20" y1="-10" x2="-4" y2="-10" fill="none" stroke="black" stroke-width="1"/><line x1="-20" y1="-6" x2="-14" y2="-6" fill="none" stroke="black" stroke-width="1"/><line x1="-10" y1="-6" x2="-4" y2="-6" fill="none" stroke="black" stroke-width="1"/><path d="M -25 -30 A 5 2.5 0 0 0 -35 -30" fill="none" stroke="black" stroke-width="1"/><path d="M -25 -30 A 5 2.5 0 0 0 -15 -30" fill="none" stroke="black" stroke-width="1"/><polyline points="-28,-4 -32,0 -28,4" fill="none" stroke="black" stroke-width="1"/><polyline points="-16,-4 -12,0 -16,4" fill="none" stroke="black" stroke-width="1"/>',mi=[{id:"t_ac",x:-20,y:-40,orientation:"n"},{id:"t_dc",x:-20,y:0,orientation:"s"}],hi=[{name:"S",label:"容量",type:"number",unit:"MVA"}],pi={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_14/en_60617_06_14_06.elmt",qetEnglishName:"Rectifier/inverter"},Kp={id:si,name:ii,category:ai,description:li,viewBox:ci,width:di,height:ui,svg:fi,terminals:mi,params:hi,source:pi},qp=Object.freeze(Object.defineProperty({__proto__:null,category:ai,default:Kp,description:li,height:ui,id:si,name:ii,params:hi,source:pi,svg:fi,terminals:mi,viewBox:ci,width:di},Symbol.toStringTag,{value:"Module"})),gi="ct",xi="电流互感器 (CT)",yi="instrument-transformer",bi="-42 -62 54 64",wi=54,vi=64,ki='<line x1="-30" y1="-60" x2="-30" y2="0" fill="none" stroke="black" stroke-width="1"/><line x1="-20" y1="-30" x2="10" y2="-30" fill="none" stroke="black" stroke-width="1"/><ellipse cx="-30" cy="-30" rx="10" ry="10" fill="none" stroke="black" stroke-width="1"/><line x1="-10" y1="-20" x2="0" y2="-40" fill="none" stroke="black" stroke-width="1"/><line x1="-5" y1="-20" x2="5" y2="-40" fill="none" stroke="black" stroke-width="1"/>',_i=[{id:"t1",x:-30,y:0,orientation:"s"},{id:"t2",x:-30,y:-60,orientation:"n"}],Si={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_09/en_60617_06_09_10.elmt",qetEnglishName:"Current transformer, general symbol"},Yp={id:gi,name:xi,category:yi,viewBox:bi,width:wi,height:vi,svg:ki,terminals:_i,source:Si},Xp=Object.freeze(Object.defineProperty({__proto__:null,category:yi,default:Yp,height:vi,id:gi,name:xi,source:Si,svg:ki,terminals:_i,viewBox:bi,width:wi},Symbol.toStringTag,{value:"Module"})),ji="dc-combiner",$i="直流汇流箱",Ei="renewable",Ni="光伏组串汇流箱 (4 路输入示例)。",Ti="-27 -32 54 64",Ci=54,Ii=64,Ai='<rect x="-25" y="-15" width="50" height="30" fill="none" stroke="black" stroke-width="1"/><line x1="-18" y1="-30" x2="-18" y2="-15" stroke="black" stroke-width="1" fill="none"/><line x1="-6" y1="-30" x2="-6" y2="-15" stroke="black" stroke-width="1" fill="none"/><line x1="6" y1="-30" x2="6" y2="-15" stroke="black" stroke-width="1" fill="none"/><line x1="18" y1="-30" x2="18" y2="-15" stroke="black" stroke-width="1" fill="none"/><line x1="0" y1="15" x2="0" y2="30" stroke="black" stroke-width="1" fill="none"/><text x="-9" y="5" font-family="Liberation Sans, Arial, sans-serif" font-size="7" fill="#000000">DC</text>',Mi=[{id:"t_s1",x:-18,y:-30,orientation:"n"},{id:"t_s2",x:-6,y:-30,orientation:"n"},{id:"t_s3",x:6,y:-30,orientation:"n"},{id:"t_s4",x:18,y:-30,orientation:"n"},{id:"t_dc",x:0,y:30,orientation:"s"}],Pi={kind:"inline"},Vp={id:ji,name:$i,category:Ei,description:Ni,viewBox:Ti,width:Ci,height:Ii,svg:Ai,terminals:Mi,source:Pi},Up=Object.freeze(Object.defineProperty({__proto__:null,category:Ei,default:Vp,description:Ni,height:Ii,id:ji,name:$i,source:Pi,svg:Ai,terminals:Mi,viewBox:Ti,width:Ci},Symbol.toStringTag,{value:"Module"})),Oi="dc-disconnector",Li="直流隔离开关",Bi="switching",Ri="DC isolating switch — 光伏组串 / 储能 直流侧隔离。",Di="-12 -32 30 64",zi=30,Fi=64,Hi='<line x1="0" y1="-30" x2="0" y2="-12" stroke="black" stroke-width="1" fill="none"/><line x1="0" y1="0" x2="0" y2="30" stroke="black" stroke-width="1" fill="none"/><line x1="0" y1="0" x2="-8" y2="-15" stroke="black" stroke-width="1" fill="none"/><line x1="6" y1="-4" x2="14" y2="-4" stroke="black" stroke-width="1" fill="none"/><line x1="6" y1="-1" x2="9" y2="-1" stroke="black" stroke-width="0.8" fill="none"/><line x1="11" y1="-1" x2="14" y2="-1" stroke="black" stroke-width="0.8" fill="none"/>',Wi=[{id:"t1",x:0,y:-30,orientation:"n"},{id:"t2",x:0,y:30,orientation:"s"}],Gi=[{name:"open",type:"boolean",default:!1,label:"断开"}],Ki={kind:"inline"},Zp={id:Oi,name:Li,category:Bi,description:Ri,viewBox:Di,width:zi,height:Fi,svg:Hi,terminals:Wi,state:Gi,source:Ki},Jp=Object.freeze(Object.defineProperty({__proto__:null,category:Bi,default:Zp,description:Ri,height:Fi,id:Oi,name:Li,source:Ki,state:Gi,svg:Hi,terminals:Wi,viewBox:Di,width:zi},Symbol.toStringTag,{value:"Module"})),qi="disconnector",Yi="隔离开关 (QS)",Xi="switching",Vi="-10 -42 15 64",Ui=15,Zi=64,Ji='<line x1="0" y1="-20" x2="0" y2="-40" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="0" x2="0" y2="20" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="0" x2="-8" y2="-23" fill="none" stroke="black" stroke-width="1"/><line x1="-3" y1="-20" x2="3" y2="-20" fill="none" stroke="black" stroke-width="1"/>',Qi=[{id:"t1",x:0,y:-40,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],ea=[{name:"open",type:"boolean",default:!1,label:"断开"}],ta={x:6,y:-10,anchor:"start"},na={kind:"elmt",path:"91_en_60617/en_60617_07/en_60617_07_13/en_60617_07_13_06.elmt",qetEnglishName:"Disconnector; Isolator"},Qp={id:qi,name:Yi,category:Xi,viewBox:Vi,width:Ui,height:Zi,svg:Ji,terminals:Qi,state:ea,label:ta,source:na},eg=Object.freeze(Object.defineProperty({__proto__:null,category:Xi,default:Qp,height:Zi,id:qi,label:ta,name:Yi,source:na,state:ea,svg:Ji,terminals:Qi,viewBox:Vi,width:Ui},Symbol.toStringTag,{value:"Module"})),oa="earth",ra="接地",sa="busbar",ia="-12 -17 24 34",aa=24,la=34,ca='<line x1="-10" y1="0" x2="10" y2="0" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="-15" x2="0" y2="0" fill="none" stroke="black" stroke-width="1"/><line x1="-7" y1="5" x2="7" y2="5" fill="none" stroke="black" stroke-width="1"/><line x1="-4" y1="10" x2="4" y2="10" fill="none" stroke="black" stroke-width="1"/><line x1="0.5" y1="15" x2="-0.5" y2="15" fill="none" stroke="black" stroke-width="1"/>',da=[{id:"t1",x:0,y:-15,orientation:"n"}],ua={kind:"elmt",path:"91_en_60617/en_60617_02/en_60617_02_15/en_60617_02_15_01.elmt",qetEnglishName:"Earth or ground, general symbol"},tg={id:oa,name:ra,category:sa,viewBox:ia,width:aa,height:la,svg:ca,terminals:da,source:ua},ng=Object.freeze(Object.defineProperty({__proto__:null,category:sa,default:tg,height:la,id:oa,name:ra,source:ua,svg:ca,terminals:da,viewBox:ia,width:aa},Symbol.toStringTag,{value:"Module"})),fa="earthing-switch",ma="接地刀闸 (QE)",ha="switching",pa="隔离开关 + 接地连接,单端口",ga="-12 -32 24 64",xa=24,ya=64,ba='<line x1="0" y1="-30" x2="0" y2="-12" stroke="black" stroke-width="1" fill="none"/><line x1="0" y1="-12" x2="-9" y2="9" stroke="black" stroke-width="1" fill="none"/><line x1="-3" y1="-12" x2="3" y2="-12" stroke="black" stroke-width="1" fill="none"/><line x1="-10" y1="14" x2="10" y2="14" stroke="black" stroke-width="1" fill="none"/><line x1="-7" y1="19" x2="7" y2="19" stroke="black" stroke-width="1" fill="none"/><line x1="-4" y1="24" x2="4" y2="24" stroke="black" stroke-width="1" fill="none"/><line x1="-1.5" y1="29" x2="1.5" y2="29" stroke="black" stroke-width="1" fill="none"/>',wa=[{id:"t_top",x:0,y:-30,orientation:"n"}],va=[{name:"open",type:"boolean",default:!0,label:"断开"}],ka={x:12,y:-8,anchor:"start"},_a={kind:"inline"},og={id:fa,name:ma,category:ha,description:pa,viewBox:ga,width:xa,height:ya,svg:ba,terminals:wa,state:va,label:ka,source:_a},rg=Object.freeze(Object.defineProperty({__proto__:null,category:ha,default:og,description:pa,height:ya,id:fa,label:ka,name:ma,source:_a,state:va,svg:ba,terminals:wa,viewBox:ga,width:xa},Symbol.toStringTag,{value:"Module"})),Sa="energy-meter",ja="电能表 (Wh)",$a="measurement",Ea="有功电能表 (kWh) — 服务入口 / 子表。",Na="-22 -36 44 72",Ta=44,Ca=72,Ia='<text x="-10" y="19.2" font-family="Liberation Sans, Arial, sans-serif" font-size="9" fill="#000000">Wh</text><rect x="-20" y="-10" width="40" height="40" rx="0" ry="0" fill="none" stroke="black" stroke-width="1"/><rect x="-20" y="-30" width="40" height="20" rx="0" ry="0" fill="none" stroke="black" stroke-width="1"/>',Aa=[{id:"t1",x:0,y:-34,orientation:"n"},{id:"t2",x:0,y:34,orientation:"s"}],Ma={kind:"elmt",path:"11_singlepole/500_home_installation/40_meters/wattheuremetre_08-04-03_en60617.elmt",qetEnglishName:"Watt hour meter (en_60617)"},sg={id:Sa,name:ja,category:$a,description:Ea,viewBox:Na,width:Ta,height:Ca,svg:Ia,terminals:Aa,source:Ma},ig=Object.freeze(Object.defineProperty({__proto__:null,category:$a,default:sg,description:Ea,height:Ca,id:Sa,name:ja,source:Ma,svg:Ia,terminals:Aa,viewBox:Na,width:Ta},Symbol.toStringTag,{value:"Module"})),Pa="ev-charger",Oa="EV 充电桩",La="load",Ba="电动汽车充电站 / 充电桩。",Ra="-17 -27 34 49",Da=34,za=49,Fa='<line x1="0" y1="-25" x2="0" y2="-15" stroke="black" stroke-width="1" fill="none"/><rect x="-15" y="-15" width="30" height="35" fill="none" stroke="black" stroke-width="1"/><rect x="-9" y="-8" width="14" height="6" fill="none" stroke="black" stroke-width="0.8"/><rect x="5" y="-7" width="2" height="4" fill="black"/><text x="-9" y="13" font-family="Liberation Sans, Arial, sans-serif" font-size="7" fill="#000000">EV</text>',Ha=[{id:"t_top",x:0,y:-25,orientation:"n"}],Wa={kind:"inline"},ag={id:Pa,name:Oa,category:La,description:Ba,viewBox:Ra,width:Da,height:za,svg:Fa,terminals:Ha,source:Wa},lg=Object.freeze(Object.defineProperty({__proto__:null,category:La,default:ag,description:Ba,height:za,id:Pa,name:Oa,source:Wa,svg:Fa,terminals:Ha,viewBox:Ra,width:Da},Symbol.toStringTag,{value:"Module"})),Ga="frequency-meter",Ka="频率表 (Hz)",qa="measurement",Ya="-22 -42 44 44",Xa=44,Va=44,Ua='<ellipse cx="0" cy="-20" rx="20" ry="20" fill="none" stroke="black" stroke-width="1"/><text x="-8" y="-8.8" font-family="Liberation Sans, Arial, sans-serif" font-size="9" fill="#000000">Hz</text>',Za=[{id:"t_top",x:0,y:-40,orientation:"n"}],Ja={kind:"elmt",path:"91_en_60617/en_60617_08/en_60617_08_02/en_60617_08_02_07.elmt",qetEnglishName:"Frequency meter"},cg={id:Ga,name:Ka,category:qa,viewBox:Ya,width:Xa,height:Va,svg:Ua,terminals:Za,source:Ja},dg=Object.freeze(Object.defineProperty({__proto__:null,category:qa,default:cg,height:Va,id:Ga,name:Ka,source:Ja,svg:Ua,terminals:Za,viewBox:Ya,width:Xa},Symbol.toStringTag,{value:"Module"})),Qa="fuse",el="熔断器 (FU)",tl="switching",nl="-7 -32 14 64",ol=14,rl=64,sl='<line x1="0" y1="-30" x2="0" y2="30" fill="none" stroke="black" stroke-width="1"/><rect x="-5" y="-15" width="10" height="30" rx="0" ry="0" fill="none" stroke="black" stroke-width="1"/>',il=[{id:"t1",x:0,y:30,orientation:"s"},{id:"t2",x:0,y:-30,orientation:"n"}],al=[{name:"blown",type:"boolean",default:!1,label:"熔断"}],ll={x:7,y:-2,anchor:"start"},cl={kind:"elmt",path:"91_en_60617/en_60617_07/en_60617_07_21/en_60617_07_21_01.elmt",qetEnglishName:"Fuse, general symbol"},ug={id:Qa,name:el,category:tl,viewBox:nl,width:ol,height:rl,svg:sl,terminals:il,state:al,label:ll,source:cl},fg=Object.freeze(Object.defineProperty({__proto__:null,category:tl,default:ug,height:rl,id:Qa,label:ll,name:el,source:cl,state:al,svg:sl,terminals:il,viewBox:nl,width:ol},Symbol.toStringTag,{value:"Module"})),dl="generator",ul="发电机 (G)",fl="source",ml="-42 -42 44 44",hl=44,pl=44,gl='<rect x="-40" y="-40" width="40" height="40" rx="0" ry="0" fill="none" stroke="black" stroke-width="1"/><text x="-24" y="-8.8" font-family="Liberation Sans, Arial, sans-serif" font-size="14" fill="#000000">G</text>',xl=[{id:"t_bottom",x:-20,y:0,orientation:"s"}],yl={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_16/en_60617_06_16_01.elmt",qetEnglishName:"Generator, general symbol"},mg={id:dl,name:ul,category:fl,viewBox:ml,width:hl,height:pl,svg:gl,terminals:xl,source:yl},hg=Object.freeze(Object.defineProperty({__proto__:null,category:fl,default:mg,height:pl,id:dl,name:ul,source:yl,svg:gl,terminals:xl,viewBox:ml,width:hl},Symbol.toStringTag,{value:"Module"})),bl="gfci-breaker",wl="GFCI 断路器 (RCBO)",vl="protection",kl="剩余电流断路器带过流保护 (UL943 / IEC 61009)。北美 GFCI / 欧洲 RCBO。",_l="-18 -22 22 44",Sl=22,jl=44,$l='<text x="-14" y="13.8" font-family="Liberation Sans, Arial, sans-serif" font-size="6" fill="#000000">IΔ</text><line x1="2" y1="-12" x2="-2" y2="-8" fill="none" stroke="black" stroke-width="1"/><line x1="-2" y1="-12" x2="2" y2="-8" fill="none" stroke="black" stroke-width="1"/><polyline points="-5,-10 0,10 0,20" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="-20" x2="0" y2="-10" fill="none" stroke="black" stroke-width="1"/><line x1="-4" y1="-4" x2="-8" y2="-4" fill="none" stroke="black" stroke-width="0.4"/><line x1="-8" y1="-4" x2="-8" y2="-8" fill="none" stroke="black" stroke-width="0.4"/><line x1="-13" y1="-8" x2="-8" y2="-8" fill="none" stroke="black" stroke-width="0.4"/><line x1="-13" y1="-8" x2="-13" y2="-4" fill="none" stroke="black" stroke-width="0.4"/><line x1="-16" y1="-4" x2="-13" y2="-4" fill="none" stroke="black" stroke-width="0.4"/><path d="M -8 1 A 2.5 3.5 0 0 0 -13 1" fill="none" stroke="black" stroke-width="0.4"/><line x1="-8" y1="1" x2="-2" y2="1" fill="none" stroke="black" stroke-width="0.4"/><line x1="-16" y1="1" x2="-13" y2="1" fill="none" stroke="black" stroke-width="0.4"/>',El=[{id:"t1",x:0,y:-20,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],Nl=[{name:"open",type:"boolean",default:!1,label:"断开"}],Tl=[{name:"In",label:"额定电流",type:"number",unit:"A"},{name:"IDn",label:"剩余动作电流",type:"number",unit:"mA",default:30}],Cl={kind:"elmt",path:"11_singlepole/200_fuses_protective_gears/50_residual_current_circuit_breaker/rcbo.elmt",qetEnglishName:"Residual Circuit Breaker with Overload"},pg={id:bl,name:wl,category:vl,description:kl,viewBox:_l,width:Sl,height:jl,svg:$l,terminals:El,state:Nl,params:Tl,source:Cl},gg=Object.freeze(Object.defineProperty({__proto__:null,category:vl,default:pg,description:kl,height:jl,id:bl,name:wl,params:Tl,source:Cl,state:Nl,svg:$l,terminals:El,viewBox:_l,width:Sl},Symbol.toStringTag,{value:"Module"})),Il="grid-source",Al="系统电源",Ml="source",Pl="无穷大母线 / 外部电网",Ol="-16 -31 32 53",Ll=32,Bl=53,Rl='<circle cx="0" cy="-15" r="14" fill="none" stroke="black" stroke-width="1"/><text x="0" y="-12" text-anchor="middle" font-family="Liberation Sans, Arial, sans-serif" font-size="14">~</text><line x1="0" y1="-1" x2="0" y2="20" stroke="black" stroke-width="1" fill="none"/>',Dl=[{id:"t_bottom",x:0,y:20,orientation:"s"}],zl={kind:"inline"},xg={id:Il,name:Al,category:Ml,description:Pl,viewBox:Ol,width:Ll,height:Bl,svg:Rl,terminals:Dl,source:zl},yg=Object.freeze(Object.defineProperty({__proto__:null,category:Ml,default:xg,description:Pl,height:Bl,id:Il,name:Al,source:zl,svg:Rl,terminals:Dl,viewBox:Ol,width:Ll},Symbol.toStringTag,{value:"Module"})),Fl="grounding-transformer",Hl="接地变 (Z形)",Wl="grounding",Gl="星-曲折接线变压器,中性点接地用",Kl="-62 -152 64 164",ql=64,Yl=164,Xl='<line x1="-30" y1="-40" x2="-35" y2="-35" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-40" x2="-25" y2="-35" fill="none" stroke="black" stroke-width="1"/><ellipse cx="-30" cy="-90" rx="30" ry="30" fill="none" stroke="black" stroke-width="1"/><line x1="-35" y1="-35" x2="-40" y2="-38" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-150" x2="-30" y2="-120" fill="none" stroke="black" stroke-width="1"/><line x1="-25" y1="-35" x2="-25" y2="-30" fill="none" stroke="black" stroke-width="1"/><ellipse cx="-30" cy="-50" rx="30" ry="30" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-40" x2="-30" y2="-45" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-20" x2="-30" y2="10" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-45" x2="-25" y2="-48" fill="none" stroke="black" stroke-width="1"/><line x1="-40" y1="-130" x2="-20" y2="-140" fill="none" stroke="black" stroke-width="1"/><line x1="-40" y1="-135" x2="-20" y2="-145" fill="none" stroke="black" stroke-width="1"/><line x1="-40" y1="0" x2="-20" y2="-10" fill="none" stroke="black" stroke-width="1"/><line x1="-40" y1="5" x2="-20" y2="-5" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-85" x2="-30" y2="-95" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-95" x2="-20" y2="-100" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-95" x2="-40" y2="-100" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-40" x2="-20" y2="-40" fill="none" stroke="black" stroke-width="1"/><ellipse cx="-30" cy="-40" rx="2" ry="2" fill="black" stroke="black" stroke-width="1"/>',Vl=[{id:"t1",x:-30,y:10,orientation:"s"},{id:"t2",x:-30,y:-150,orientation:"n"}],Ul={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_10/en_60617_06_10_15.elmt",qetEnglishName:"Three-phase transformer, connection star-zigzag with the neutral brought out"},bg={id:Fl,name:Hl,category:Wl,description:Gl,viewBox:Kl,width:ql,height:Yl,svg:Xl,terminals:Vl,source:Ul},wg=Object.freeze(Object.defineProperty({__proto__:null,category:Wl,default:bg,description:Gl,height:Yl,id:Fl,name:Hl,source:Ul,svg:Xl,terminals:Vl,viewBox:Kl,width:ql},Symbol.toStringTag,{value:"Module"})),Zl="inverter",Jl="逆变器 (DC→AC)",Ql="renewable",ec="-42 -42 44 44",tc=44,nc=44,oc='<path d="M -15 -8 A 5 2.5 0 0 0 -25 -8" fill="none" stroke="black" stroke-width="1"/><line x1="-40" y1="0" x2="0" y2="-40" fill="none" stroke="black" stroke-width="1"/><path d="M -15 -8 A 5 2.5 0 0 0 -5 -8" fill="none" stroke="black" stroke-width="1"/><rect x="-40" y="-40" width="40" height="40" rx="0" ry="0" fill="none" stroke="black" stroke-width="1"/><line x1="-36" y1="-36" x2="-20" y2="-36" fill="none" stroke="black" stroke-width="1"/><line x1="-36" y1="-32" x2="-30" y2="-32" fill="none" stroke="black" stroke-width="1"/><line x1="-26" y1="-32" x2="-20" y2="-32" fill="none" stroke="black" stroke-width="1"/>',rc=[{id:"t_dc",x:-20,y:-40,orientation:"n"},{id:"t_ac",x:-20,y:0,orientation:"s"}],sc={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_14/en_60617_06_14_05.elmt",qetEnglishName:"Inverter"},vg={id:Zl,name:Jl,category:Ql,viewBox:ec,width:tc,height:nc,svg:oc,terminals:rc,source:sc},kg=Object.freeze(Object.defineProperty({__proto__:null,category:Ql,default:vg,height:nc,id:Zl,name:Jl,source:sc,svg:oc,terminals:rc,viewBox:ec,width:tc},Symbol.toStringTag,{value:"Module"})),ic="load-switch",ac="负荷开关",lc="switching",cc="-10 -42 14 64",dc=14,uc=64,fc='<line x1="0" y1="-24" x2="0" y2="-40" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="0" x2="0" y2="20" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="0" x2="-8" y2="-23" fill="none" stroke="black" stroke-width="1"/><ellipse cx="0" cy="-22" rx="2" ry="2" fill="none" stroke="black" stroke-width="1"/><line x1="-2" y1="-24" x2="2" y2="-24" fill="none" stroke="black" stroke-width="1"/>',mc=[{id:"t1",x:0,y:-40,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],hc=[{name:"open",type:"boolean",default:!1,label:"断开"}],pc={kind:"elmt",path:"91_en_60617/en_60617_07/en_60617_07_13/en_60617_07_13_08.elmt",qetEnglishName:"Switch-disconnector; On-load isolating switch"},_g={id:ic,name:ac,category:lc,viewBox:cc,width:dc,height:uc,svg:fc,terminals:mc,state:hc,source:pc},Sg=Object.freeze(Object.defineProperty({__proto__:null,category:lc,default:_g,height:uc,id:ic,name:ac,source:pc,state:hc,svg:fc,terminals:mc,viewBox:cc,width:dc},Symbol.toStringTag,{value:"Module"})),gc="load",xc="负荷",yc="load",bc="抽象负荷(电流流出箭头)",wc="-8 -22 16 46",vc=16,kc=46,_c='<line x1="0" y1="-20" x2="0" y2="10" stroke="black" stroke-width="1" fill="none"/><polygon points="-6,10 6,10 0,22" fill="black" stroke="black" stroke-width="1"/>',Sc=[{id:"t_top",x:0,y:-20,orientation:"n"}],jc=[{name:"P",label:"有功功率",type:"number",unit:"MW",showOnCanvas:!0},{name:"cosphi",label:"功率因数",type:"number"}],$c={x:6,y:0,anchor:"start"},Ec={kind:"inline"},jg={id:gc,name:xc,category:yc,description:bc,viewBox:wc,width:vc,height:kc,svg:_c,terminals:Sc,params:jc,label:$c,source:Ec},$g=Object.freeze(Object.defineProperty({__proto__:null,category:yc,default:jg,description:bc,height:kc,id:gc,label:$c,name:xc,params:jc,source:Ec,svg:_c,terminals:Sc,viewBox:wc,width:vc},Symbol.toStringTag,{value:"Module"})),Nc="motor-starter",Tc="电机启动器",Cc="motor-control",Ic="电机启动器 (IEC 60617 通用符号)。",Ac="-22 -27 44 54",Mc=44,Pc=54,Oc='<rect x="-20" y="-20" width="40" height="40" rx="0" ry="0" fill="none" stroke="black" stroke-width="1"/><polyline points="-20,-20 0,-10 20,-20" fill="none" stroke="black" stroke-width="1"/>',Lc=[{id:"t_top",x:0,y:-25,orientation:"n"},{id:"t_bottom",x:0,y:25,orientation:"s"}],Bc={kind:"elmt",path:"91_en_60617/en_60617_07/en_60617_07_14/en_60617_07_14_01.elmt",qetEnglishName:"Motor starter, general symbol"},Eg={id:Nc,name:Tc,category:Cc,description:Ic,viewBox:Ac,width:Mc,height:Pc,svg:Oc,terminals:Lc,source:Bc},Ng=Object.freeze(Object.defineProperty({__proto__:null,category:Cc,default:Eg,description:Ic,height:Pc,id:Nc,name:Tc,source:Bc,svg:Oc,terminals:Lc,viewBox:Ac,width:Mc},Symbol.toStringTag,{value:"Module"})),Rc="ngr",Dc="中性点电阻 (NGR)",zc="grounding",Fc="小电阻接地:连接变压器中性点到地",Hc="-12 -32 24 62",Wc=24,Gc=62,Kc='<line x1="0" y1="-30" x2="0" y2="-15" fill="none" stroke="black" stroke-width="1"/><rect x="-6" y="-15" width="12" height="22" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="7" x2="0" y2="15" fill="none" stroke="black" stroke-width="1"/><line x1="-10" y1="15" x2="10" y2="15" fill="none" stroke="black" stroke-width="1"/><line x1="-7" y1="19" x2="7" y2="19" fill="none" stroke="black" stroke-width="1"/><line x1="-4" y1="23" x2="4" y2="23" fill="none" stroke="black" stroke-width="1"/><line x1="-1.5" y1="27" x2="1.5" y2="27" fill="none" stroke="black" stroke-width="1"/>',qc=[{id:"t_top",x:0,y:-30,orientation:"n"}],Yc=[{name:"R",label:"电阻",type:"number",unit:"Ω"}],Xc={kind:"inline"},Tg={id:Rc,name:Dc,category:zc,description:Fc,viewBox:Hc,width:Wc,height:Gc,svg:Kc,terminals:qc,params:Yc,source:Xc},Cg=Object.freeze(Object.defineProperty({__proto__:null,category:zc,default:Tg,description:Fc,height:Gc,id:Rc,name:Dc,params:Yc,source:Xc,svg:Kc,terminals:qc,viewBox:Hc,width:Wc},Symbol.toStringTag,{value:"Module"})),Vc="pt",Uc="电压互感器 (PT)",Zc="instrument-transformer",Jc="-22 -42 44 115",Qc=44,ed=115,td='<ellipse cx="0" cy="1" rx="20" ry="20" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="-40" x2="0" y2="-20" fill="none" stroke="black" stroke-width="1"/><ellipse cx="0" cy="30" rx="20" ry="20" fill="none" stroke="black" stroke-width="1"/><line x1="-0.13" y1="51" x2="-0.13" y2="71" fill="none" stroke="black" stroke-width="1"/>',nd=[{id:"t1",x:0,y:71,orientation:"s"},{id:"t2",x:0,y:-40,orientation:"n"}],od={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_13/en_60617_06_13_01A.elmt",qetEnglishName:"Voltage transformer"},Ig={id:Vc,name:Uc,category:Zc,viewBox:Jc,width:Qc,height:ed,svg:td,terminals:nd,source:od},Ag=Object.freeze(Object.defineProperty({__proto__:null,category:Zc,default:Ig,height:ed,id:Vc,name:Uc,source:od,svg:td,terminals:nd,viewBox:Jc,width:Qc},Symbol.toStringTag,{value:"Module"})),rd="pv",sd="光伏组件",id="renewable",ad="-33 -22 85 64",ld=85,cd=64,dd='<line x1="-16" y1="24" x2="-26" y2="14" fill="none" stroke="black" stroke-width="1"/><line x1="-21" y1="29" x2="-31" y2="19" fill="none" stroke="black" stroke-width="1"/><polygon points="-20,23 -17,20 -15,25" fill="black" stroke="black" stroke-width="1"/><polygon points="-22,25 -25,28 -20,30" fill="black" stroke="black" stroke-width="1"/><rect x="-10" y="-20" width="60" height="60" rx="0" ry="0" fill="none" stroke="black" stroke-width="1"/><text x="15" y="7.2" font-family="Liberation Sans, Arial, sans-serif" font-size="14" fill="#000000">G</text><line x1="10" y1="20" x2="20" y2="20" fill="none" stroke="black" stroke-width="1"/><line x1="20" y1="15" x2="20" y2="25" fill="none" stroke="black" stroke-width="1"/><line x1="25" y1="10" x2="25" y2="30" fill="none" stroke="black" stroke-width="1"/><line x1="25" y1="20" x2="35" y2="20" fill="none" stroke="black" stroke-width="1"/>',ud=[{id:"t_dc",x:50,y:10,orientation:"e"}],fd={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_18/en_60617_06_18_06.elmt",qetEnglishName:"Photovoltaic generator"},Mg={id:rd,name:sd,category:id,viewBox:ad,width:ld,height:cd,svg:dd,terminals:ud,source:fd},Pg=Object.freeze(Object.defineProperty({__proto__:null,category:id,default:Mg,height:cd,id:rd,name:sd,source:fd,svg:dd,terminals:ud,viewBox:ad,width:ld},Symbol.toStringTag,{value:"Module"})),md="rcd",hd="剩余电流装置 (RCD)",pd="protection",gd="不带过流保护的剩余电流断路器 (IEC 61008)。",xd="-12 -22 19 44",yd=19,bd=44,wd='<line x1="0" y1="-20" x2="0" y2="-10" fill="none" stroke="black" stroke-width="1"/><line x1="2" y1="-12" x2="-2" y2="-8" fill="none" stroke="black" stroke-width="1"/><line x1="-2" y1="-12" x2="2" y2="-8" fill="none" stroke="black" stroke-width="1"/><polyline points="0,20 0,10 -7,-9" fill="none" stroke="black" stroke-width="1"/><ellipse cx="0" cy="13" rx="4.5" ry="2" fill="none" stroke="black" stroke-width="1"/><polyline points="-4,0 -10,0 -10,13 -5,13" fill="none" stroke="black" stroke-width="0.4" stroke-dasharray="4 2"/>',vd=[{id:"t1",x:0,y:-20,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],kd=[{name:"open",type:"boolean",default:!1,label:"断开"}],_d=[{name:"IDn",label:"剩余动作电流",type:"number",unit:"mA",default:30}],Sd={kind:"elmt",path:"11_singlepole/200_fuses_protective_gears/50_residual_current_circuit_breaker/ddr1.elmt",qetEnglishName:"Residual Circuit Breaker with Overload"},Og={id:md,name:hd,category:pd,description:gd,viewBox:xd,width:yd,height:bd,svg:wd,terminals:vd,state:kd,params:_d,source:Sd},Lg=Object.freeze(Object.defineProperty({__proto__:null,category:pd,default:Og,description:gd,height:bd,id:md,name:hd,params:_d,source:Sd,state:kd,svg:wd,terminals:vd,viewBox:xd,width:yd},Symbol.toStringTag,{value:"Module"})),jd="recloser",$d="重合闸 (Recloser)",Ed="protection",Nd="中压自动重合闸开关。",Td="-12 -32 36 64",Cd=36,Id=64,Ad='<line x1="0" y1="-30" x2="0" y2="-10" stroke="black" stroke-width="1" fill="none"/><line x1="0" y1="0" x2="0" y2="30" stroke="black" stroke-width="1" fill="none"/><line x1="0" y1="0" x2="-8" y2="-13" stroke="black" stroke-width="1" fill="none"/><line x1="-2" y1="-8" x2="2" y2="-12" stroke="black" stroke-width="1" fill="none"/><line x1="-2" y1="-12" x2="2" y2="-8" stroke="black" stroke-width="1" fill="none"/><path d="M 13 -12 A 7 7 0 1 1 6 -5" fill="none" stroke="black" stroke-width="0.8"/><polygon points="4,-7 6,-5 8,-3" fill="black"/><text x="14" y="6" font-family="Liberation Sans, Arial, sans-serif" font-size="6" fill="#000000">AR</text>',Md=[{id:"t1",x:0,y:-30,orientation:"n"},{id:"t2",x:0,y:30,orientation:"s"}],Pd=[{name:"open",type:"boolean",default:!1,label:"断开"}],Od={kind:"inline"},Bg={id:jd,name:$d,category:Ed,description:Nd,viewBox:Td,width:Cd,height:Id,svg:Ad,terminals:Md,state:Pd,source:Od},Rg=Object.freeze(Object.defineProperty({__proto__:null,category:Ed,default:Bg,description:Nd,height:Id,id:jd,name:$d,source:Od,state:Pd,svg:Ad,terminals:Md,viewBox:Td,width:Cd},Symbol.toStringTag,{value:"Module"})),Ld="rectifier",Bd="整流器 (AC→DC)",Rd="renewable",Dd="-42 -42 44 44",zd=44,Fd=44,Hd='<line x1="-40" y1="0" x2="0" y2="-40" fill="none" stroke="black" stroke-width="1"/><rect x="-40" y="-40" width="40" height="40" rx="0" ry="0" fill="none" stroke="black" stroke-width="1"/><line x1="-20" y1="-8" x2="-4" y2="-8" fill="none" stroke="black" stroke-width="1"/><line x1="-20" y1="-4" x2="-14" y2="-4" fill="none" stroke="black" stroke-width="1"/><line x1="-10" y1="-4" x2="-4" y2="-4" fill="none" stroke="black" stroke-width="1"/><path d="M -25 -30 A 5 2.5 0 0 0 -35 -30" fill="none" stroke="black" stroke-width="1"/><path d="M -25 -30 A 5 2.5 0 0 0 -15 -30" fill="none" stroke="black" stroke-width="1"/>',Wd=[{id:"t_ac",x:-20,y:-40,orientation:"n"},{id:"t_dc",x:-20,y:0,orientation:"s"}],Gd={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_14/en_60617_06_14_03.elmt",qetEnglishName:"Rectifier"},Dg={id:Ld,name:Bd,category:Rd,viewBox:Dd,width:zd,height:Fd,svg:Hd,terminals:Wd,source:Gd},zg=Object.freeze(Object.defineProperty({__proto__:null,category:Rd,default:Dg,height:Fd,id:Ld,name:Bd,source:Gd,svg:Hd,terminals:Wd,viewBox:Dd,width:zd},Symbol.toStringTag,{value:"Module"})),Kd="series-reactor",qd="串联电抗器",Yd="compensation",Xd="与并联电抗器同符号;通过用法区分。",Vd="-62 -82 64 104",Ud=64,Zd=104,Jd='<line x1="-30" y1="0" x2="-30" y2="20" fill="none" stroke="black" stroke-width="1"/><path d="M -30 0 A 30 30 0 1 0 -60 -30" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-80" x2="-30" y2="-30" fill="none" stroke="black" stroke-width="1"/><line x1="-60" y1="-30" x2="-30" y2="-30" fill="none" stroke="black" stroke-width="1"/>',Qd=[{id:"t1",x:-30,y:-80,orientation:"n"},{id:"t_bottom",x:-30,y:20,orientation:"s"}],eu={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_09/en_60617_06_09_08.elmt",qetEnglishName:"Choke; Reactor, general symbol"},Fg={id:Kd,name:qd,category:Yd,description:Xd,viewBox:Vd,width:Ud,height:Zd,svg:Jd,terminals:Qd,source:eu},Hg=Object.freeze(Object.defineProperty({__proto__:null,category:Yd,default:Fg,description:Xd,height:Zd,id:Kd,name:qd,source:eu,svg:Jd,terminals:Qd,viewBox:Vd,width:Ud},Symbol.toStringTag,{value:"Module"})),tu="shunt-capacitor",nu="并联电容器",ou="compensation",ru="-7 -23 14 27",su=14,iu=27,au='<line x1="-5" y1="2" x2="5" y2="2" fill="none" stroke="black" stroke-width="1"/><line x1="-5" y1="-2" x2="5" y2="-2" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="-20" x2="0" y2="-2" fill="none" stroke="black" stroke-width="1"/>',lu=[{id:"t1",x:0,y:-21,orientation:"n"},{id:"t_bottom",x:0,y:2,orientation:"s"}],cu=[{name:"Q",label:"无功容量",type:"number",unit:"Mvar"},{name:"stages",label:"分组数",type:"number"}],du={kind:"elmt",path:"11_singlepole/395_electronics_semiconductors/20_capacitors/capacite.elmt",qetEnglishName:"Capacitor"},Wg={id:tu,name:nu,category:ou,viewBox:ru,width:su,height:iu,svg:au,terminals:lu,params:cu,source:du},Gg=Object.freeze(Object.defineProperty({__proto__:null,category:ou,default:Wg,height:iu,id:tu,name:nu,params:cu,source:du,svg:au,terminals:lu,viewBox:ru,width:su},Symbol.toStringTag,{value:"Module"})),uu="shunt-reactor",fu="并联电抗器",mu="compensation",hu="-62 -82 64 104",pu=64,gu=104,xu='<line x1="-30" y1="0" x2="-30" y2="20" fill="none" stroke="black" stroke-width="1"/><path d="M -30 0 A 30 30 0 1 0 -60 -30" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-80" x2="-30" y2="-30" fill="none" stroke="black" stroke-width="1"/><line x1="-60" y1="-30" x2="-30" y2="-30" fill="none" stroke="black" stroke-width="1"/>',yu=[{id:"t1",x:-30,y:-80,orientation:"n"},{id:"t_bottom",x:-30,y:20,orientation:"s"}],bu={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_09/en_60617_06_09_08.elmt",qetEnglishName:"Choke; Reactor, general symbol"},Kg={id:uu,name:fu,category:mu,viewBox:hu,width:pu,height:gu,svg:xu,terminals:yu,source:bu},qg=Object.freeze(Object.defineProperty({__proto__:null,category:mu,default:Kg,height:gu,id:uu,name:fu,source:bu,svg:xu,terminals:yu,viewBox:hu,width:pu},Symbol.toStringTag,{value:"Module"})),wu="soft-starter",vu="软启动器",ku="motor-control",_u="电机软启动器 (晶闸管降压启动)。",Su="-22 -42 44 84",ju=44,$u=84,Eu='<rect x="-20" y="-20" width="40" height="40" fill="none" stroke="black" stroke-width="1"/><line x1="-12" y1="-12" x2="12" y2="12" stroke="black" stroke-width="1" fill="none"/><polygon points="4,8 12,12 8,4" fill="none" stroke="black" stroke-width="1"/><text x="-12" y="-2" font-family="Liberation Sans, Arial, sans-serif" font-size="6" fill="#000000">SS</text><line x1="0" y1="-40" x2="0" y2="-20" stroke="black" stroke-width="1" fill="none"/><line x1="0" y1="20" x2="0" y2="40" stroke="black" stroke-width="1" fill="none"/>',Nu=[{id:"t_in",x:0,y:-40,orientation:"n"},{id:"t_out",x:0,y:40,orientation:"s"}],Tu={kind:"inline"},Yg={id:wu,name:vu,category:ku,description:_u,viewBox:Su,width:ju,height:$u,svg:Eu,terminals:Nu,source:Tu},Xg=Object.freeze(Object.defineProperty({__proto__:null,category:ku,default:Yg,description:_u,height:$u,id:wu,name:vu,source:Tu,svg:Eu,terminals:Nu,viewBox:Su,width:ju},Symbol.toStringTag,{value:"Module"})),Cu="sync-motor",Iu="同步电动机",Au="load",Mu="-62 -82 64 114",Pu=64,Ou=114,Lu='<ellipse cx="-30" cy="-30" rx="30" ry="30" fill="none" stroke="black" stroke-width="1"/><text x="-34" y="-24.8" font-family="Liberation Sans, Arial, sans-serif" font-size="14" fill="#000000">M</text><line x1="-50" y1="-80" x2="-50" y2="-53" fill="none" stroke="black" stroke-width="1"/><line x1="-10" y1="-53" x2="-10" y2="-80" fill="none" stroke="black" stroke-width="1"/><text x="-45" y="-7.8" font-family="Liberation Sans, Arial, sans-serif" font-size="14" fill="#000000">1</text><path d="M -25 -20 A 5 2.5 0 0 0 -35 -20" fill="none" stroke="black" stroke-width="1"/><path d="M -25 -20 A 5 2.5 0 0 0 -15 -20" fill="none" stroke="black" stroke-width="1"/><path d="M -40 10 A 5 5 0 0 0 -50 10" fill="none" stroke="black" stroke-width="1"/><path d="M -30 10 A 5 5 0 0 0 -40 10" fill="none" stroke="black" stroke-width="1"/><path d="M -20 10 A 5 5 0 0 0 -30 10" fill="none" stroke="black" stroke-width="1"/><path d="M -10 10 A 5 5 0 0 0 -20 10" fill="none" stroke="black" stroke-width="1"/><line x1="-50" y1="10" x2="-50" y2="30" fill="none" stroke="black" stroke-width="1"/><line x1="-10" y1="10" x2="-10" y2="30" fill="none" stroke="black" stroke-width="1"/><line x1="-40" y1="15" x2="-20" y2="15" fill="none" stroke="black" stroke-width="1"/><line x1="-40" y1="20" x2="-32" y2="20" fill="none" stroke="black" stroke-width="1"/><line x1="-27" y1="20" x2="-20" y2="20" fill="none" stroke="black" stroke-width="1"/>',Bu=[{id:"t1",x:-10,y:-80,orientation:"n"},{id:"t2",x:-50,y:-80,orientation:"n"}],Ru={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_07/en_60617_06_07_02.elmt",qetEnglishName:"Synchronous motor, single-phase"},Vg={id:Cu,name:Iu,category:Au,viewBox:Mu,width:Pu,height:Ou,svg:Lu,terminals:Bu,source:Ru},Ug=Object.freeze(Object.defineProperty({__proto__:null,category:Au,default:Vg,height:Ou,id:Cu,name:Iu,source:Ru,svg:Lu,terminals:Bu,viewBox:Mu,width:Pu},Symbol.toStringTag,{value:"Module"})),Du="thermal-overload",zu="热过载继电器",Fu="motor-control",Hu="电机热过载保护继电器, 通常串接在接触器和电机之间。",Wu="-9 -32 19 64",Gu=19,Ku=64,qu='<line x1="0" y1="-30" x2="0" y2="-15" stroke="black" stroke-width="1" fill="none"/><rect x="-7" y="-15" width="14" height="30" fill="none" stroke="black" stroke-width="1"/><polyline points="-4,-10 -1,-5 -4,0 -1,5 -4,10" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="15" x2="0" y2="30" stroke="black" stroke-width="1" fill="none"/>',Yu=[{id:"t1",x:0,y:-30,orientation:"n"},{id:"t2",x:0,y:30,orientation:"s"}],Xu=[{name:"tripped",type:"boolean",default:!1,label:"动作"}],Vu={kind:"inline"},Zg={id:Du,name:zu,category:Fu,description:Hu,viewBox:Wu,width:Gu,height:Ku,svg:qu,terminals:Yu,state:Xu,source:Vu},Jg=Object.freeze(Object.defineProperty({__proto__:null,category:Fu,default:Zg,description:Hu,height:Ku,id:Du,name:zu,source:Vu,state:Xu,svg:qu,terminals:Yu,viewBox:Wu,width:Gu},Symbol.toStringTag,{value:"Module"})),Uu="transfer-switch",Zu="切换开关 (ATS)",Ju="switching",Qu="双源切换开关 (Automatic / Manual Transfer Switch)。两个电源输入 + 一个负荷输出, 互锁不并联。",ef="-27 -32 51 64",tf=51,nf=64,of='<line x1="-15" y1="-30" x2="-15" y2="-12" stroke="black" stroke-width="1" fill="none"/><line x1="15" y1="-30" x2="15" y2="-12" stroke="black" stroke-width="1" fill="none"/><text x="-25" y="-20" font-family="Liberation Sans, Arial, sans-serif" font-size="6" fill="#000000">N</text><text x="19" y="-20" font-family="Liberation Sans, Arial, sans-serif" font-size="6" fill="#000000">E</text><circle cx="-15" cy="-10" r="1.5" fill="black"/><circle cx="15" cy="-10" r="1.5" fill="black"/><circle cx="0" cy="6" r="1.5" fill="black"/><line x1="-15" y1="-10" x2="0" y2="6" stroke="black" stroke-width="1" fill="none"/><line x1="15" y1="-10" x2="0" y2="6" stroke="black" stroke-width="0.6" fill="none" stroke-dasharray="2 1.5"/><line x1="0" y1="6" x2="0" y2="30" stroke="black" stroke-width="1" fill="none"/>',rf=[{id:"t_normal",x:-15,y:-30,orientation:"n"},{id:"t_emergency",x:15,y:-30,orientation:"n"},{id:"t_load",x:0,y:30,orientation:"s"}],sf=[{name:"position",type:"string",default:"normal",label:"位置 (normal/emergency/off)"}],af={kind:"inline"},Qg={id:Uu,name:Zu,category:Ju,description:Qu,viewBox:ef,width:tf,height:nf,svg:of,terminals:rf,state:sf,source:af},e0=Object.freeze(Object.defineProperty({__proto__:null,category:Ju,default:Qg,description:Qu,height:nf,id:Uu,name:Zu,source:af,state:sf,svg:of,terminals:rf,viewBox:ef,width:tf},Symbol.toStringTag,{value:"Module"})),lf="transformer-2w",cf="双绕组变压器",df="transformer",uf="-62 -142 64 144",ff=64,mf=144,hf='<ellipse cx="-30" cy="-90" rx="30" ry="30" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-140" x2="-30" y2="-120" fill="none" stroke="black" stroke-width="1"/><ellipse cx="-30" cy="-50" rx="30" ry="30" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-20" x2="-30" y2="0" fill="none" stroke="black" stroke-width="1"/>',pf=[{id:"t1",x:-30,y:0,orientation:"s"},{id:"t2",x:-30,y:-140,orientation:"n"}],gf=[{name:"S",label:"容量",type:"number",unit:"MVA",showOnCanvas:!0},{name:"ratio",label:"变比",type:"string",showOnCanvas:!0}],xf={x:4,y:-68,anchor:"start"},yf={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_09/en_60617_06_09_01.elmt",qetEnglishName:"Transformer with two windings, general symbol"},t0={id:lf,name:cf,category:df,viewBox:uf,width:ff,height:mf,svg:hf,terminals:pf,params:gf,label:xf,source:yf},n0=Object.freeze(Object.defineProperty({__proto__:null,category:df,default:t0,height:mf,id:lf,label:xf,name:cf,params:gf,source:yf,svg:hf,terminals:pf,viewBox:uf,width:ff},Symbol.toStringTag,{value:"Module"})),bf="transformer-3w",wf="三绕组变压器",vf="transformer",kf="-82 -131 114 133",_f=114,Sf=133,jf='<ellipse cx="-30" cy="-80" rx="30" ry="30" fill="none" stroke="black" stroke-width="1"/><line x1="-31" y1="-129" x2="-31" y2="-109" fill="none" stroke="black" stroke-width="1"/><ellipse cx="-50" cy="-50" rx="30" ry="30" fill="none" stroke="black" stroke-width="1"/><ellipse cx="0" cy="-50" rx="30" ry="30" fill="none" stroke="black" stroke-width="1"/><line x1="-50" y1="-20" x2="-50" y2="0" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="-20" x2="0" y2="0" fill="none" stroke="black" stroke-width="1"/>',$f=[{id:"t1",x:-31,y:-129,orientation:"n"},{id:"t_low_left",x:-50,y:0,orientation:"s"},{id:"t_low_right",x:0,y:0,orientation:"s"}],Ef={x:4,y:-64,anchor:"start"},Nf={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_09/en_60617_06_09_04.elmt",qetEnglishName:"Transformer with three windings, general symbol"},o0={id:bf,name:wf,category:vf,viewBox:kf,width:_f,height:Sf,svg:jf,terminals:$f,label:Ef,source:Nf},r0=Object.freeze(Object.defineProperty({__proto__:null,category:vf,default:o0,height:Sf,id:bf,label:Ef,name:wf,source:Nf,svg:jf,terminals:$f,viewBox:kf,width:_f},Symbol.toStringTag,{value:"Module"})),Tf="vfd",Cf="变频器 (VFD)",If="motor-control",Af="Variable Frequency Drive — 异步电动机调速。",Mf="-24 -42 48 84",Pf=48,Of=84,Lf='<rect x="-22" y="-20" width="44" height="40" fill="none" stroke="black" stroke-width="1"/><line x1="-22" y1="20" x2="22" y2="-20" stroke="black" stroke-width="1" fill="none"/><text x="-15" y="-5" font-family="Liberation Sans, Arial, sans-serif" font-size="9" fill="#000000">~</text><text x="6" y="14" font-family="Liberation Sans, Arial, sans-serif" font-size="9" fill="#000000">~f</text><line x1="0" y1="-40" x2="0" y2="-20" stroke="black" stroke-width="1" fill="none"/><line x1="0" y1="20" x2="0" y2="40" stroke="black" stroke-width="1" fill="none"/>',Bf=[{id:"t_in",x:0,y:-40,orientation:"n"},{id:"t_out",x:0,y:40,orientation:"s"}],Rf={kind:"inline"},s0={id:Tf,name:Cf,category:If,description:Af,viewBox:Mf,width:Pf,height:Of,svg:Lf,terminals:Bf,source:Rf},i0=Object.freeze(Object.defineProperty({__proto__:null,category:If,default:s0,description:Af,height:Of,id:Tf,name:Cf,source:Rf,svg:Lf,terminals:Bf,viewBox:Mf,width:Pf},Symbol.toStringTag,{value:"Module"})),Df="voltmeter",zf="电压表 (V)",Ff="measurement",Hf="-22 -42 44 44",Wf=44,Gf=44,Kf='<ellipse cx="0" cy="-20" rx="20" ry="20" fill="none" stroke="black" stroke-width="1"/><text x="-4" y="-8.8" font-family="Liberation Sans, Arial, sans-serif" font-size="9" fill="#000000">V</text>',qf=[{id:"t_top",x:0,y:-40,orientation:"n"}],Yf={kind:"elmt",path:"91_en_60617/en_60617_08/en_60617_08_02/en_60617_08_02_01.elmt",qetEnglishName:"Voltmeter"},a0={id:Df,name:zf,category:Ff,viewBox:Hf,width:Wf,height:Gf,svg:Kf,terminals:qf,source:Yf},l0=Object.freeze(Object.defineProperty({__proto__:null,category:Ff,default:a0,height:Gf,id:Df,name:zf,source:Yf,svg:Kf,terminals:qf,viewBox:Hf,width:Wf},Symbol.toStringTag,{value:"Module"})),Xf="wattmeter",Vf="功率表 (W)",Uf="measurement",Zf="-22 -42 44 44",Jf=44,Qf=44,em='<rect x="-20" y="-40" width="40" height="40" rx="0" ry="0" fill="none" stroke="black" stroke-width="1"/><text x="-6" y="-8.8" font-family="Liberation Sans, Arial, sans-serif" font-size="9" fill="#000000">W</text>',tm=[{id:"t_top",x:0,y:-40,orientation:"n"}],nm={kind:"elmt",path:"91_en_60617/en_60617_08/en_60617_08_03/en_60617_08_03_01.elmt",qetEnglishName:"Recording wattmeter"},c0={id:Xf,name:Vf,category:Uf,viewBox:Zf,width:Jf,height:Qf,svg:em,terminals:tm,source:nm},d0=Object.freeze(Object.defineProperty({__proto__:null,category:Uf,default:c0,height:Qf,id:Xf,name:Vf,source:nm,svg:em,terminals:tm,viewBox:Zf,width:Jf},Symbol.toStringTag,{value:"Module"})),om="wind-turbine",rm="风力发电机",sm="renewable",im="风机:发电机 + 三叶轮标记",am="-22 -46 44 68",lm=44,cm=68,dm='<circle cx="0" cy="0" r="20" fill="none" stroke="black" stroke-width="1"/><text x="0" y="4" text-anchor="middle" font-family="Liberation Sans, Arial, sans-serif" font-size="16">G</text><line x1="0" y1="-20" x2="0" y2="-32" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="-32" x2="-10" y2="-39" fill="none" stroke="black" stroke-width="1.5"/><line x1="0" y1="-32" x2="10" y2="-39" fill="none" stroke="black" stroke-width="1.5"/><line x1="0" y1="-32" x2="0" y2="-44" fill="none" stroke="black" stroke-width="1.5"/>',um=[{id:"t_bottom",x:0,y:20,orientation:"s"}],fm={kind:"inline"},u0={id:om,name:rm,category:sm,description:im,viewBox:am,width:lm,height:cm,svg:dm,terminals:um,source:fm},f0=Object.freeze(Object.defineProperty({__proto__:null,category:sm,default:u0,description:im,height:cm,id:om,name:rm,source:fm,svg:dm,terminals:um,viewBox:am,width:lm},Symbol.toStringTag,{value:"Module"})),m0=Object.assign({"./ammeter.json":Np,"./arc-suppression-coil.json":Cp,"./arrester.json":Ap,"./async-motor.json":Pp,"./autotransformer.json":Lp,"./battery.json":Rp,"./breaker.json":zp,"./busbar.json":Hp,"./contactor.json":Gp,"./converter-bidir.json":qp,"./ct.json":Xp,"./dc-combiner.json":Up,"./dc-disconnector.json":Jp,"./disconnector.json":eg,"./earth.json":ng,"./earthing-switch.json":rg,"./energy-meter.json":ig,"./ev-charger.json":lg,"./frequency-meter.json":dg,"./fuse.json":fg,"./generator.json":hg,"./gfci-breaker.json":gg,"./grid-source.json":yg,"./grounding-transformer.json":wg,"./inverter.json":kg,"./load-switch.json":Sg,"./load.json":$g,"./motor-starter.json":Ng,"./ngr.json":Cg,"./pt.json":Ag,"./pv.json":Pg,"./rcd.json":Lg,"./recloser.json":Rg,"./rectifier.json":zg,"./series-reactor.json":Hg,"./shunt-capacitor.json":Gg,"./shunt-reactor.json":qg,"./soft-starter.json":Xg,"./sync-motor.json":Ug,"./thermal-overload.json":Jg,"./transfer-switch.json":e0,"./transformer-2w.json":n0,"./transformer-3w.json":r0,"./vfd.json":i0,"./voltmeter.json":l0,"./wattmeter.json":d0,"./wind-turbine.json":f0}),mm=Object.values(m0).map(e=>e.default),Ke=Object.fromEntries(mm.map(e=>[e.id,e])),co=["busbar","switching","protection","motor-control","transformer","instrument-transformer","measurement","source","load","storage","compensation","grounding","renewable"],h0=(()=>{var t;const e={};for(const n of mm)(e[t=n.category]??(e[t]=[])).push(n);return e})(),hn=new Map(Object.entries(Ke));function hm(e){return Ke[e]}function p0(e){const n=[...e].sort().join("|");let o=2166136261;for(let r=0;r<n.length;r++)o^=n.charCodeAt(r),o=Math.imul(o,16777619);return`n_${(o>>>0).toString(36)}`}const g0=320;function He(e){var f,p,g,m;const t=br(),n=new Map;e.elements.forEach((h,y)=>{if(n.has(h.id)){t.diagnostics.push({code:"E001",severity:"error",message:be("compile.duplicateId",{id:h.id}),pointer:`/elements/${y}`});return}n.set(h.id,h);const v=hn.get(h.kind);v||t.diagnostics.push({code:"E003",severity:"error",message:`${be("compile.unknownKind",{kind:h.kind})} (id=${h.id})`,pointer:`/elements/${y}`}),t.elements.set(h.id,{element:h,libraryDef:v})});const o=new Map,r=new Map;(e.buses??[]).forEach((h,y)=>{if(n.has(h.id)||o.has(h.id)){t.diagnostics.push({code:"E001",severity:"error",message:be("compile.duplicateId",{id:h.id}),pointer:`/buses/${y}`});return}if(o.set(h.id,h),h.layout){const v=h.layout.rot??0;r.set(h.id,{at:h.layout.at,span:h.layout.span,rot:v,axis:fn(v)})}});const s=h=>!h.includes(".")&&o.has(h),i=(h,y)=>{if(s(h))return!0;const v=h.indexOf(".");if(v<=0)return t.diagnostics.push({code:"E003",severity:"error",message:be("compile.invalidTermRef",{ref:h}),pointer:y}),!1;const b=h.slice(0,v),_=h.slice(v+1),N=t.elements.get(b);if(!N)return t.diagnostics.push({code:"E002",severity:"error",message:be("compile.elementMissing",{id:b}),pointer:y}),!1;if(!N.libraryDef)return!1;if(!N.libraryDef.terminals.find(I=>I.id===_)){const I=N.libraryDef.terminals.map(B=>B.id).join(", ");return t.diagnostics.push({code:"E003",severity:"error",message:be("compile.missingPin",{id:b,kind:N.element.kind,pin:_,available:I}),pointer:y}),!1}return!0},a=[];(e.wires??[]).forEach((h,y)=>{const v=`/wires/${y}`,b=i(h.ends[0],v),_=i(h.ends[1],v);b&&_&&a.push(h)});const l=new Map;if(e.layout)for(const[h,y]of Object.entries(e.layout))t.elements.has(h)?l.set(h,wr(y)):t.diagnostics.push({code:"E004",severity:"error",message:be("compile.layoutMissingElement",{id:h}),pointer:`/layout/${h}`});const d=jp({elements:e.elements,buses:e.buses??[],wires:a,library:hn,userLayout:l,userBusLayout:r});t.layout=d.devices;for(const[h,y]of d.buses){const v=o.get(h);v&&t.buses.set(h,{bus:v,geometry:y})}for(const[h,y]of o)t.buses.has(h)||t.buses.set(h,{bus:y,geometry:{at:((f=y.layout)==null?void 0:f.at)??[0,0],span:((p=y.layout)==null?void 0:p.span)??g0,rot:((g=y.layout)==null?void 0:g.rot)??0,axis:fn(((m=y.layout)==null?void 0:m.rot)??0)}});for(const h of t.elements.values()){if(!h.libraryDef)continue;const y=t.layout.get(h.element.id);if(!y)continue;const v=[];for(const b of h.libraryDef.terminals){const _=`${h.element.id}.${b.id}`,N=Le([b.x,b.y],y),I=gt(b.orientation,y);t.terminals.set(_,{ref:_,elementId:h.element.id,pin:b.id,world:N,orientation:I}),v.push(_)}t.elementToTerminals.set(h.element.id,v)}const u=new vr;for(const h of a)u.add(h.ends[0]),u.add(h.ends[1]),u.union(h.ends[0],h.ends[1]);for(const[,h]of u.groups()){const y=p0(h);t.nodes.set(y,{id:y,terminals:h});for(const v of h)t.terminalToNode.set(v,y)}for(const h of t.elements.values()){const y=t.elementToTerminals.get(h.element.id)??[];if(y.length===0)continue;y.some(b=>t.terminalToNode.has(b))||t.diagnostics.push({code:"W001",severity:"warning",message:be("compile.elementUnconnected",{id:h.element.id})})}for(const h of t.buses.keys())t.terminalToNode.has(h)||t.diagnostics.push({code:"W001",severity:"warning",message:be("compile.elementUnconnected",{id:h})});for(const h of a){if(h.path&&h.path.length>=2){const v=h.path,b=v.length>=2?v[1]:null,_=v.length>=2?v[v.length-2]:null,N=ao(h.ends[0],b,t),I=ao(h.ends[1],_,t);if(N&&I){const B=[[N[0],N[1]],...v.slice(1,-1).map(te=>[te[0],te[1]]),[I[0],I[1]]],re=yr(B);if(re.length>=2){t.wireRenders.set(h.id,{wireId:h.id,path:re,userEdited:!0});continue}}}const y=$p(h,t);y&&t.wireRenders.set(h.id,y)}return t}const x0={earth:"GND",breaker:"QF",disconnector:"QS","earthing-switch":"QE","load-switch":"QL",fuse:"FU","transformer-2w":"T","transformer-3w":"T",autotransformer:"AT",ct:"CT",pt:"PT",generator:"G","sync-motor":"M","async-motor":"M","grid-source":"L",load:"L",battery:"BAT","shunt-reactor":"LR","series-reactor":"LR","shunt-capacitor":"C",arrester:"FBL","grounding-transformer":"TG",ngr:"NGR","arc-suppression-coil":"ASC",pv:"PV","wind-turbine":"WT",rectifier:"RT",inverter:"INV","converter-bidir":"PCS"},uo="B";function pm(e){return new Set([...e.elements.map(t=>t.id),...(e.buses??[]).map(t=>t.id)])}function bt(e,t){const n=x0[t]??t,o=pm(e);let r=1;for(;o.has(`${n}${r}`);)r++;return`${n}${r}`}function pn(e){const t=pm(e);let n=1;for(;t.has(`${uo}${n}`);)n++;return`${uo}${n}`}function y0(e){const t=new Set((e.annotations??[]).map(o=>o.id));let n=1;for(;t.has(`a${n}`);)n++;return`a${n}`}function wt(e,t){const n=[e,t].sort(),o=`${n[0]}|${n[1]}`;let r=2166136261;for(let s=0;s<o.length;s++)r^=o.charCodeAt(s),r=Math.imul(r,16777619);return`w_${(r>>>0).toString(36)}`}const fo={version:"1",elements:[]},b0=100,mo=20;function w0(){if(typeof window>"u")return"select";try{return window.matchMedia("(pointer: coarse)").matches?"pan":"select"}catch{return"select"}}const x=zt()(xp((e,t)=>({diagram:fo,internal:He(fo),fileSession:null,activeTool:w0(),placeKind:null,lastPlaceKind:null,wireFromTerminal:null,placeFromTerminal:null,busbarDrawStart:null,cursorSvg:null,selection:[],selectedWire:null,selectedNode:null,selectedAnnotation:null,editingAnnotation:null,editingElement:null,past:[],future:[],clipboard:null,clipboardPasteIndex:0,setDiagram:n=>e({diagram:n,internal:He(n),past:[],future:[],selection:[],selectedWire:null,selectedNode:null,selectedAnnotation:null,editingAnnotation:null,editingElement:null,wireFromTerminal:null,placeFromTerminal:null}),setFileSession:n=>e({fileSession:n}),loadDiagramFromFile:(n,o)=>e({diagram:n,internal:He(n),fileSession:o,past:[],future:[],selection:[],selectedWire:null,selectedNode:null,selectedAnnotation:null,editingAnnotation:null,editingElement:null,wireFromTerminal:null,placeFromTerminal:null}),dispatch:n=>{const{diagram:o,past:r}=t(),s=n(o);if(s===o)return;const i=r.length>=b0?r.slice(1):r;e({diagram:s,internal:He(s),past:[...i,o],future:[]})},undo:()=>{const{past:n,future:o,diagram:r}=t();if(n.length===0)return;const s=n[n.length-1];e({diagram:s,internal:He(s),past:n.slice(0,-1),future:[...o,r],wireFromTerminal:null,placeFromTerminal:null})},redo:()=>{const{past:n,future:o,diagram:r}=t();if(o.length===0)return;const s=o[o.length-1];e({diagram:s,internal:He(s),past:[...n,r],future:o.slice(0,-1),wireFromTerminal:null,placeFromTerminal:null})},setActiveTool:(n,o)=>{const r=t();let s;(o==null?void 0:o.placeKind)!==void 0?s=o.placeKind:n==="place"?s=r.placeKind??r.lastPlaceKind:s=null,e({activeTool:n,placeKind:s,lastPlaceKind:s??r.lastPlaceKind,wireFromTerminal:n==="wire"?r.wireFromTerminal:null,placeFromTerminal:n==="place"?r.placeFromTerminal:null})},setPlaceKind:n=>e(o=>({placeKind:n,lastPlaceKind:n??o.lastPlaceKind})),setWireFromTerminal:n=>e({wireFromTerminal:n}),setPlaceFromTerminal:n=>e({placeFromTerminal:n}),setBusbarDrawStart:n=>e({busbarDrawStart:n}),setCursorSvg:n=>e({cursorSvg:n}),setSelection:n=>e({selection:v0(n),selectedWire:null,selectedNode:null,selectedAnnotation:n.length?null:t().selectedAnnotation}),toggleInSelection:n=>{const o=t().selection;e({selection:o.includes(n)?o.filter(r=>r!==n):[...o,n],selectedWire:null,selectedNode:null,selectedAnnotation:null})},clearSelection:()=>e({selection:[],selectedWire:null,selectedNode:null,selectedAnnotation:null,editingAnnotation:null,editingElement:null}),setSelectedWire:n=>e({selectedWire:n,selection:n?[]:t().selection,selectedNode:null,selectedAnnotation:n?null:t().selectedAnnotation}),setSelectedNode:n=>e({selectedNode:n,selection:n?[]:t().selection,selectedWire:null,selectedAnnotation:n?null:t().selectedAnnotation}),setSelectedAnnotation:n=>e({selectedAnnotation:n,selection:n?[]:t().selection,selectedWire:n?null:t().selectedWire,selectedNode:n?null:t().selectedNode,editingAnnotation:n?t().editingAnnotation:null}),setEditingAnnotation:n=>e({editingAnnotation:n,selectedAnnotation:n??t().selectedAnnotation,editingElement:n?null:t().editingElement}),setEditingElement:n=>e({editingElement:n,selection:n?[n]:t().selection,editingAnnotation:n?null:t().editingAnnotation,selectedAnnotation:n?null:t().selectedAnnotation,selectedWire:n?null:t().selectedWire,selectedNode:n?null:t().selectedNode}),copySelection:()=>{var f;const{selection:n,diagram:o,internal:r}=t();if(n.length===0)return;const s=new Set(n),i=o.elements.filter(p=>s.has(p.id)).map(p=>structuredClone(p)),a=(o.buses??[]).filter(p=>s.has(p.id)).map(p=>structuredClone(p)),l={};for(const p of n)if(s.has(p)&&!r.buses.has(p)){const g=(f=o.layout)==null?void 0:f[p];if(g){l[p]=structuredClone(g);continue}const m=r.layout.get(p);m&&(l[p]=Et(m))}const d={};for(const p of n){const g=r.buses.get(p);g&&(d[p]=Ue(g.geometry))}const u=(o.wires??[]).filter(p=>p.ends.every(g=>s.has(Jt(g)))).map(p=>structuredClone(p));e({clipboard:{elements:i,buses:a,placements:l,busLayouts:d,wires:u},clipboardPasteIndex:0})},cutSelection:()=>{const{selection:n}=t();n.length!==0&&(t().copySelection(),t().deleteSelection())},pasteClipboard:()=>{const{clipboard:n,clipboardPasteIndex:o,diagram:r}=t();if(!n||n.elements.length===0&&n.buses.length===0)return;const s=o+1,i=mo*s,a=mo*s,l=new Map;let d=r;for(const f of n.elements){const p=bt(d,f.kind);l.set(f.id,p),d={...d,elements:[...d.elements,{id:p,kind:f.kind}]}}for(const f of n.buses){const p=pn(d);l.set(f.id,p),d={...d,buses:[...d.buses??[],{id:p}]}}const u=f=>{const p=f.indexOf("."),g=p<0?f:f.slice(0,p),m=l.get(g);return m?p<0?m:`${m}${f.slice(p)}`:f};t().dispatch(f=>{const p=n.elements.map(v=>{const b=structuredClone(v);return b.id=l.get(v.id),b}),g=n.buses.map(v=>{const b=structuredClone(v);b.id=l.get(v.id);const _=n.busLayouts[v.id];return _&&(b.layout={..._,at:[_.at[0]+i,_.at[1]+a]}),b}),m={...f.layout??{}};for(const[v,b]of l){const _=n.placements[v];_&&(m[b]={..._,at:[_.at[0]+i,_.at[1]+a]})}const h=n.wires.map(v=>{const b=[u(v.ends[0]),u(v.ends[1])];return{id:wt(b[0],b[1]),ends:b}}),y=k0(f.wires??[],h);return{...f,elements:[...f.elements,...p],buses:g.length?[...f.buses??[],...g]:f.buses,wires:y.length?y:void 0,layout:Object.keys(m).length?m:void 0}}),e({selection:Array.from(l.values()),clipboardPasteIndex:s})},autoArrangeAll:()=>{t().dispatch(n=>{var l;const o=n.layout&&Object.keys(n.layout).length>0,r=(n.buses??[]).some(d=>d.layout);if(!o&&!r)return n;const{layout:s,...i}=n,a=(l=n.buses)==null?void 0:l.map(d=>{const{layout:u,...f}=d;return f});return{...i,buses:a}})},autoArrangeSelection:()=>{const{selection:n}=t();if(n.length===0)return;const o=new Set(n);t().dispatch(r=>{let s=!1,i=r.layout;if(i){const l={};for(const[d,u]of Object.entries(i)){if(o.has(d)){s=!0;continue}l[d]=u}s&&(i=Object.keys(l).length?l:void 0)}let a=r.buses;if(a){const l=a.map(d=>{if(o.has(d.id)&&d.layout){s=!0;const{layout:u,...f}=d;return f}return d});s&&(a=l)}return s?{...r,layout:i,buses:a}:r})},fillUnplacedAll:()=>{const n=t().internal;t().dispatch(o=>{const r=o.layout??{},s={};for(const l of o.elements){if(r[l.id])continue;const d=n.layout.get(l.id);d&&(s[l.id]=Et(d))}const i=[];if((o.buses??[]).forEach((l,d)=>{l.layout||n.buses.has(l.id)&&i.push({idx:d,bus:l})}),Object.keys(s).length===0&&i.length===0)return o;let a=o.buses;return i.length>0&&a&&(a=a.map(l=>{const d=n.buses.get(l.id);return!l.layout&&d?{...l,layout:Ue(d.geometry)}:l})),{...o,layout:{...r,...s},buses:a}})},fillUnplacedSelection:()=>{const{selection:n,internal:o}=t();n.length!==0&&t().dispatch(r=>{var d;const s=r.layout??{},i={},a=new Map;for(const u of n)if(o.buses.has(u)){const f=o.buses.get(u);(d=r.buses)!=null&&d.find(p=>p.id===u&&p.layout)||a.set(u,Ue(f.geometry))}else{if(s[u])continue;const f=o.layout.get(u);f&&(i[u]=Et(f))}if(Object.keys(i).length===0&&a.size===0)return r;let l=r.buses;return a.size>0&&l&&(l=l.map(u=>a.has(u.id)?{...u,layout:a.get(u.id)}:u)),{...r,layout:{...s,...i},buses:l}})},moveElements:n=>{if(n.size===0)return;const o=t().internal;t().dispatch(r=>{const s={...r.layout??{}},i=new Map;for(const[l,d]of n){if(o.buses.has(l)){i.set(l,d);continue}const u=o.layout.get(l),f=s[l]??(u?Et(u):{at:[0,0]});s[l]={...f,at:[f.at[0]+d[0],f.at[1]+d[1]]}}let a=r.buses;return i.size>0&&(a=(r.buses??[]).map(l=>{const d=i.get(l.id);if(!d)return l;const u=l.layout??Ue(o.buses.get(l.id).geometry);return{...l,layout:{...u,at:[u.at[0]+d[0],u.at[1]+d[1]]}}})),{...r,layout:s,buses:a}})},deleteSelection:()=>{const{selection:n}=t();if(n.length===0)return;const o=new Set(n);t().dispatch(r=>{const s=r.elements.filter(d=>!o.has(d.id)),i=(r.buses??[]).filter(d=>!o.has(d.id)),a=(r.wires??[]).filter(d=>!o.has(Jt(d.ends[0]))&&!o.has(Jt(d.ends[1]))),l=r.layout?Object.fromEntries(Object.entries(r.layout).filter(([d])=>!o.has(d))):void 0;return{...r,elements:s,buses:i.length?i:void 0,wires:a.length?a:void 0,layout:l&&Object.keys(l).length?l:void 0}}),e({selection:[]})},deleteSelectedWire:()=>{const{selectedWire:n,internal:o}=t();if(!n)return;const r=(t().diagram.wires??[]).find(i=>i.id===n),s=new Set;if(r)for(const i of r.ends){const a=i.indexOf(".");a>0&&s.add(i.slice(0,a))}t().dispatch(i=>{const a=(i.wires??[]).filter(d=>d.id!==n);if(a.length===(i.wires??[]).length)return i;const l={...i.layout??{}};for(const d of s){if(l[d])continue;const u=o.layout.get(d);if(!u)continue;const f={at:u.at};u.rot&&(f.rot=u.rot),u.mirror&&(f.mirror=u.mirror),l[d]=f}return{...i,wires:a.length?a:void 0,layout:Object.keys(l).length?l:void 0}}),e({selectedWire:null})},deleteSelectedNode:()=>{const{selectedNode:n,internal:o}=t();if(!n)return;const r=o.nodes.get(n);if(!r)return;const s=new Set(r.terminals),i=new Set;for(const a of r.terminals){const l=a.indexOf(".");l>0&&i.add(a.slice(0,l))}t().dispatch(a=>{const l={...a.layout??{}};for(const u of i){if(l[u])continue;const f=o.layout.get(u);if(!f)continue;const p={at:f.at};f.rot&&(p.rot=f.rot),f.mirror&&(p.mirror=f.mirror),l[u]=p}const d=(a.wires??[]).filter(u=>!s.has(u.ends[0])&&!s.has(u.ends[1]));return{...a,wires:d.length?d:void 0,layout:Object.keys(l).length?l:void 0}}),e({selectedNode:null})},rotateSelection:n=>{const{selection:o,internal:r}=t();o.length!==0&&t().dispatch(s=>{var d,u,f,p;const i={...s.layout??{}},a=new Map;for(const g of o){if(r.buses.has(g)){const y=r.buses.get(g),b=(((((f=(u=(d=s.buses)==null?void 0:d.find(_=>_.id===g))==null?void 0:u.layout)==null?void 0:f.rot)??y.geometry.rot??0)+n)%360+360)%360;a.set(g,b);continue}const m=i[g]??{at:((p=r.layout.get(g))==null?void 0:p.at)??[0,0]},h=(((m.rot??0)+n)%360+360)%360;i[g]={...m,rot:h}}let l=s.buses;return a.size>0&&(l=(s.buses??[]).map(g=>{if(!a.has(g.id))return g;const m=g.layout??Ue(r.buses.get(g.id).geometry);return{...g,layout:{...m,rot:a.get(g.id)}}})),{...s,layout:i,buses:l}})},mirrorSelection:()=>{const{selection:n,internal:o}=t();n.length!==0&&t().dispatch(r=>{var i;const s={...r.layout??{}};for(const a of n){if(o.buses.has(a))continue;const l=s[a]??{at:((i=o.layout.get(a))==null?void 0:i.at)??[0,0]};s[a]={...l,mirror:!(l.mirror??!1)}}return{...r,layout:s}})},addElement:(n,o,r)=>{if(n==="busbar")return t().addBus(o,320);const s=bt(t().diagram,n);return t().dispatch(i=>{const a={id:s,kind:n,...r??{}};return{...i,elements:[...i.elements,a],layout:{...i.layout??{},[s]:{at:o}}}}),e({selection:[s]}),s},addBus:(n,o,r)=>{const s=pn(t().diagram);return t().dispatch(i=>{const a={id:s,layout:r!==void 0?{at:n,span:o,rot:r}:{at:n,span:o}};return{...i,buses:[...i.buses??[],a]}}),e({selection:[s]}),s},addWire:(n,o)=>{if(n===o)return;const r=wt(n,o);t().dispatch(s=>{const i=s.wires??[];return i.some(a=>a.id===r)?s:{...s,wires:[...i,{id:r,ends:[n,o]}]}})},updateWirePath:(n,o)=>{t().dispatch(r=>{const s=r.wires??[];if(!s.some(d=>d.id===n))return r;const i=o&&o.length>=2?yr(o):null,a=i&&i.length>=2?i:null,l=s.map(d=>{if(d.id!==n)return d;if(a)return{...d,path:a};const{path:u,...f}=d;return f});return{...r,wires:l}})},resetWirePath:n=>{t().updateWirePath(n,null)},updateElement:(n,o)=>{t().dispatch(r=>({...r,elements:r.elements.map(s=>s.id===n?{...s,...o}:s)}))},updatePlacement:(n,o)=>{t().dispatch(r=>{var a;const s=((a=r.layout)==null?void 0:a[n])??t().internal.layout.get(n),i={at:o.at??(s==null?void 0:s.at)??[0,0],...o.rot!==void 0?{rot:o.rot}:s!=null&&s.rot?{rot:s.rot}:{},...o.mirror!==void 0?{mirror:o.mirror}:s!=null&&s.mirror?{mirror:s.mirror}:{}};return{...r,layout:{...r.layout??{},[n]:i}}})},updateBus:(n,o)=>{t().dispatch(r=>{const s=(r.buses??[]).map(i=>{if(i.id!==n)return i;const a=t().internal,l=i.layout??(a.buses.has(n)?Ue(a.buses.get(n).geometry):{at:[0,0],span:320}),d={at:o.at??l.at,span:o.span??l.span,...o.rot!==void 0?{rot:o.rot}:l.rot?{rot:l.rot}:{}};return{...i,layout:d}});return{...r,buses:s}})},addAnnotation:(n,o="")=>{const r=y0(t().diagram);return t().dispatch(s=>{const i={id:r,at:n,text:o};return{...s,annotations:[...s.annotations??[],i]}}),r},updateAnnotation:(n,o)=>{t().dispatch(r=>{const s=r.annotations??[];let i=!1;const a=s.map(l=>l.id!==n?l:(i=!0,{...l,...o,id:l.id}));return i?{...r,annotations:a}:r})},deleteAnnotation:n=>{t().dispatch(o=>{const r=o.annotations??[],s=r.filter(i=>i.id!==n);return s.length===r.length?o:{...o,annotations:s.length?s:void 0}}),t().selectedAnnotation===n&&e({selectedAnnotation:null,editingAnnotation:null})}}),{name:"ole-editor",version:2,storage:xr(()=>localStorage),partialize:e=>({diagram:e.diagram,activeTool:e.activeTool,placeKind:e.placeKind,lastPlaceKind:e.lastPlaceKind}),onRehydrateStorage:()=>e=>{e!=null&&e.diagram&&(e.internal=He(e.diagram))}}));function v0(e){return Array.from(new Set(e))}function Jt(e){const t=e.indexOf(".");return t<0?e:e.slice(0,t)}function k0(e,t){const n=new Set(e.map(r=>r.id)),o=e.slice();for(const r of t)n.has(r.id)||(n.add(r.id),o.push(r));return o}function Et(e){return{at:[e.at[0],e.at[1]],...e.rot?{rot:e.rot}:{},...e.mirror?{mirror:e.mirror}:{}}}function Ue(e){return{at:[e.at[0],e.at[1]],span:e.span,...e.rot?{rot:e.rot}:{}}}let gm=null;function ho(e){gm=e}function Ve(){return gm}const Ot=10;function xm(){if(typeof document>"u")return!0;const e=document.querySelector(".ole-canvas-root");return!!e&&!e.classList.contains("hide-grid")}function ee(e){return xm()?Math.round(e/Ot)*Ot:e}const _0=30,S0=144;function ym(e,t){const n=Ke[e],o=x.getState(),r=o.diagram;if(!n||e==="busbar")return{newElementId:o.addElement(e,t),attachedToBus:!1};const s=j0(r,t);if(!s){const h=bm(n),y=h?[ee(t[0])-h.x,ee(t[1])-h.y]:[ee(t[0]),ee(t[1])];return{newElementId:o.addElement(e,y),attachedToBus:!1}}const{busId:i,busAt:a,axis:l}=s,d=$0(n,l),u=bt(r,e),f=n.terminals.find(h=>h.id===d),p=l==="x"?t[0]:a[0],g=l==="y"?t[1]:a[1],m=f?[ee(p)-f.x,ee(g)-f.y]:[ee(t[0]),ee(t[1])];return o.dispatch(h=>{const y={id:u,kind:e},v={at:m},b=`${u}.${d}`,_={id:wt(i,b),ends:[i,b]};return{...h,elements:[...h.elements,y],wires:[...h.wires??[],_],layout:{...h.layout??{},[u]:v}}}),o.setSelection([u]),{newElementId:u,attachedToBus:!0}}function j0(e,t){const n=x.getState().internal;let o=null;for(const r of e.buses??[]){const s=n.buses.get(r.id);if(!s)continue;const{axis:i,at:a,span:l}=s.geometry;let d;if(i==="x"){const u=a[0]-l/2,f=a[0]+l/2,p=t[0]<u?u-t[0]:t[0]>f?t[0]-f:0,g=Math.abs(t[1]-a[1]);d=Math.sqrt(p*p+g*g)}else{const u=a[1]-l/2,f=a[1]+l/2,p=t[1]<u?u-t[1]:t[1]>f?t[1]-f:0,g=Math.abs(t[0]-a[0]);d=Math.sqrt(g*g+p*p)}d<=_0&&(!o||d<o.dist)&&(o={busId:r.id,busAt:[a[0],a[1]],axis:i,dist:d})}return o?{busId:o.busId,busAt:o.busAt,axis:o.axis}:null}function $0(e,t){return e.terminals.length===0?"t":[...e.terminals].sort((o,r)=>t==="x"?o.y-r.y:o.x-r.x)[0].id}function bm(e){return!e||e.stretchable||e.terminals.length===0?null:[...e.terminals].sort((n,o)=>n.y-o.y)[0]}function wm(e,t){const n=x.getState().internal;if(!e.includes(".")&&n.buses.has(e)){const r=n.buses.get(e),{axis:s,at:i,span:a}=r.geometry;if(s==="x"){const g=i[0]-a/2,m=i[0]+a/2,h=Math.max(g,Math.min(m,t[0])),y=i[1],v=t[1]>=y?"s":"n";return{ref:e,world:[h,y],orientation:v,isBus:!0,busId:e}}const l=i[1]-a/2,d=i[1]+a/2,u=Math.max(l,Math.min(d,t[1])),f=i[0],p=t[0]>=f?"e":"w";return{ref:e,world:[f,u],orientation:p,isBus:!0,busId:e}}const o=n.terminals.get(e);return o?{ref:e,world:o.world,orientation:o.orientation,isBus:!1}:null}const E0={n:"s",s:"n",e:"w",w:"e"};function vm(e,t,n){if(e.terminals.length===0)return{id:"t",x:0,y:0,orientation:"n"};const o=E0[t.orientation],r=e.terminals.filter(l=>l.orientation===o),s=r.length>0?r:e.terminals;let i=s[0],a=po(i,n,t.world);for(let l=1;l<s.length;l++){const d=s[l],u=po(d,n,t.world);u<a&&(a=u,i=d)}return i}function po(e,t,n){const o=t[0]+e.x-n[0],r=t[1]+e.y-n[1];return o*o+r*r}function N0(e,t,n){const o=Ke[e],r=x.getState(),s=r.diagram;if(!o)return null;const i=wm(t,n);if(!i)return null;const a=n[0]-i.world[0],l=n[1]-i.world[1],d=a*a+l*l<=S0,u=[ee(n[0]),ee(n[1])],f=vm(o,i,u),p=d?i.world:u,g=[ee(p[0]-f.x),ee(p[1]-f.y)],m=bt(s,e);return r.dispatch(h=>{const y={id:m,kind:e},v={at:g},b=`${m}.${f.id}`,_=i.isBus&&i.busId?i.busId:t,N={id:wt(_,b),ends:[_,b]};return{...h,elements:[...h.elements,y],wires:[...h.wires??[],N],layout:{...h.layout??{},[m]:v}}}),r.setSelection([m]),{newElementId:m,attachedToBus:i.isBus}}const Ft=9,Lt=7;function Ht(e,t){var s,i;const n=[],o=((s=e.element.name)==null?void 0:s.trim())||e.element.id;if(o&&n.push(o),t!=="all"||!((i=e.libraryDef)!=null&&i.params))return n;const r=e.element.params??{};for(const a of e.libraryDef.params){if(!a.showOnCanvas)continue;const l=r[a.name];l==null||l===""||n.push(`${l}${a.unit??""}`)}return n}function Wt(e){const t=T0(e.viewBox);return t?{x:t.x+t.w+2,y:t.y+4,anchor:"start"}:{x:0,y:0,anchor:"start"}}function Gt(e,t){let n=e.x,o=e.y;switch(t.mirror&&(n=-n),t.rot){case 90:[n,o]=[-o,n];break;case 180:[n,o]=[-n,-o];break;case 270:[n,o]=[o,-n];break}return[n+t.at[0],o+t.at[1]]}function T0(e){const t=e.trim().split(/\s+/).map(Number);return t.length!==4||t.some(n=>Number.isNaN(n))?null:{x:t[0],y:t[1],w:t[2],h:t[3]}}function C0(){const e=x(r=>r.internal.elements),t=x(r=>r.internal.layout),n=x(r=>{var s;return((s=r.diagram.meta)==null?void 0:s.labelMode)??"all"}),o=x(r=>r.editingElement);return c.jsx("g",{className:"ole-annotation-layer",pointerEvents:"none",children:Array.from(e.values()).map(r=>{var u;const s=t.get(r.element.id);if(!s||!r.libraryDef)return null;const i=r.libraryDef.label??Wt(r.libraryDef),a=Gt(i,s),l=i.anchor??"start";if(o===r.element.id)return c.jsx(I0,{elementId:r.element.id,currentName:((u=r.element.name)==null?void 0:u.trim())||r.element.id,world:a,anchor:l},r.element.id);if(n==="off")return null;const d=Ht(r,n);return d.length===0?null:c.jsx("g",{className:"ole-annotation",transform:`translate(${a[0]} ${a[1]})`,children:d.map((f,p)=>c.jsx("text",{x:0,y:p*Ft,textAnchor:l,className:"ole-annotation-text",children:f},p))},r.element.id)})})}const Qt=200,en=9;function I0({elementId:e,currentName:t,world:n,anchor:o}){const r=S.useRef(null);S.useEffect(()=>{const l=r.current;if(!l)return;l.focus();const d=document.createRange();d.selectNodeContents(l);const u=window.getSelection();u==null||u.removeAllRanges(),u==null||u.addRange(d)},[e]);function s(){var p;const l=x.getState(),d=l.diagram.elements.find(g=>g.id===e);if(!d){l.setEditingElement(null);return}const u=(((p=r.current)==null?void 0:p.innerText)??"").replace(/\u00a0/g," ").trim(),f=u===""||u===e?void 0:u;f!==d.name&&l.updateElement(e,{name:f}),l.setEditingElement(null)}function i(l){if(l.key==="Escape"||l.key==="Enter"&&!l.shiftKey){l.preventDefault(),s();return}l.stopPropagation()}let a=n[0];return o==="middle"?a-=Qt/2:o==="end"&&(a-=Qt),c.jsx("foreignObject",{x:a,y:n[1]-en,width:Qt,height:en*2.2,className:"ole-element-name-editor",children:c.jsx("div",{ref:r,contentEditable:!0,suppressContentEditableWarning:!0,onBlur:s,onKeyDown:i,onPointerDown:l=>l.stopPropagation(),onMouseDown:l=>l.stopPropagation(),style:{fontSize:`${en}px`,fontFamily:"ui-sans-serif, system-ui, sans-serif",color:"var(--foreground)",background:"var(--canvas-bg)",outline:"1px dashed var(--selection)",padding:"0 2px",display:"inline-block",minWidth:"20px",lineHeight:1.1,textAlign:o==="middle"?"center":o==="end"?"right":"left",whiteSpace:"nowrap",cursor:"text"},children:t})})}const km=8,Bt=1.25;function A0(){const e=x(o=>o.diagram.annotations),t=x(o=>o.selectedAnnotation),n=x(o=>o.editingAnnotation);return!e||e.length===0?null:c.jsx("g",{className:"ole-free-annotation-layer",children:e.map(o=>n===o.id?c.jsx(P0,{ann:o},o.id):c.jsx(M0,{ann:o,isSelected:t===o.id},o.id))})}function M0({ann:e,isSelected:t}){const n=e.fontSize??km,o=e.text===""?[""]:e.text.split(`
192
- `),r=Math.max(20,...o.map(i=>i.length*n*.55)),s=o.length*n*Bt;return c.jsxs("g",{"data-annotation-id":e.id,className:"ole-free-annotation","data-selected":t?"true":void 0,children:[c.jsx("rect",{x:e.at[0]-1,y:e.at[1]-1,width:r+2,height:s+2,fill:"transparent",className:"ole-free-annotation-hit"}),t&&c.jsx("rect",{x:e.at[0]-1,y:e.at[1]-1,width:r+2,height:s+2,className:"ole-free-annotation-halo"}),o.map((i,a)=>c.jsx("text",{x:e.at[0],y:e.at[1]+n*.85+a*n*Bt,fontSize:n,className:"ole-free-annotation-text",children:i},a))]})}function P0({ann:e}){const t=S.useRef(null),n=e.fontSize??km;S.useEffect(()=>{const a=t.current;if(!a)return;a.focus();const l=document.createRange();l.selectNodeContents(a);const d=window.getSelection();d==null||d.removeAllRanges(),d==null||d.addRange(l)},[e.id]);function o(){var d;const a=x.getState(),l=(((d=t.current)==null?void 0:d.innerText)??"").replace(/\u00a0/g," ").trimEnd();l===""?a.deleteAnnotation(e.id):l!==e.text&&a.updateAnnotation(e.id,{text:l}),a.setEditingAnnotation(null),l!==""&&a.setSelectedAnnotation(e.id),a.activeTool==="text"&&a.setActiveTool("select")}function r(a){if(a.key==="Escape"){a.preventDefault(),o();return}if(a.key==="Enter"&&!a.shiftKey){a.preventDefault(),o();return}a.stopPropagation()}return c.jsx("foreignObject",{x:e.at[0],y:e.at[1],width:320,height:200,"data-annotation-id":e.id,className:"ole-free-annotation-edit-fo",children:c.jsx("div",{ref:t,contentEditable:!0,suppressContentEditableWarning:!0,onBlur:o,onKeyDown:r,onPointerDown:a=>a.stopPropagation(),onMouseDown:a=>a.stopPropagation(),style:{fontSize:`${n}px`,lineHeight:Bt,fontFamily:"ui-sans-serif, system-ui, sans-serif",color:"var(--foreground)",background:"var(--canvas-bg)",outline:"1px dashed var(--selection)",padding:"0 2px",minWidth:`${n}px`,minHeight:`${n*Bt}px`,whiteSpace:"pre-wrap",wordBreak:"break-word",cursor:"text"},children:e.text})})}const O0=20;function L0(){const e=x(u=>u.selection),t=x(u=>u.internal);if(e.length!==1)return null;const n=e[0],o=t.buses.get(n);if(!o)return null;const{axis:r,at:s,span:i}=o.geometry,a=i/2,l=r==="x"?[s[0]-a,s[1]]:[s[0],s[1]-a],d=r==="x"?[s[0]+a,s[1]]:[s[0],s[1]+a];return c.jsxs("g",{className:"ole-bus-handles",pointerEvents:"auto",children:[c.jsx(go,{x:l[0],y:l[1],busId:n,side:"start",axis:r}),c.jsx(go,{x:d[0],y:d[1],busId:n,side:"end",axis:r})]})}function go({x:e,y:t,busId:n,side:o,axis:r}){const s=Ve(),i=S.useRef(null),a=u=>{if(u.button!==0||(u.stopPropagation(),u.preventDefault(),!s))return;const f=x.getState().internal.buses.get(n);f&&(i.current={pointerId:u.pointerId,startSpan:f.geometry.span,startAt:[...f.geometry.at],startSvg:s.screenToSvg(u.clientX,u.clientY)},u.target.setPointerCapture(u.pointerId))},l=u=>{const f=i.current;if(!f||u.pointerId!==f.pointerId||!s)return;const p=s.screenToSvg(u.clientX,u.clientY),g=r==="x"?p[0]-f.startSvg[0]:p[1]-f.startSvg[1],m=xm()?Math.round(g/Ot)*Ot:g,h=f.startSpan+(o==="end"?m:-m);if(h<O0)return;const y=r==="x"?[f.startAt[0]+m/2,f.startAt[1]]:[f.startAt[0],f.startAt[1]+m/2];x.getState().updateBus(n,{span:h,at:y})},d=u=>{const f=i.current;!f||u.pointerId!==f.pointerId||(u.target.hasPointerCapture(u.pointerId)&&u.target.releasePointerCapture(u.pointerId),i.current=null)};return c.jsx("circle",{className:"ole-bus-handle",cx:e,cy:t,r:5,"data-handle":o,onPointerDown:a,onPointerMove:l,onPointerUp:d,onPointerCancel:d})}const gn=.5;function xt(e,t){return Math.abs(e[1]-t[1])<gn?"h":"v"}function B0(){const e=x(a=>a.selectedWire),t=x(a=>a.internal.wireRenders);if(!e)return null;const n=t.get(e);if(!n||n.path.length<2)return null;const o=n.path,r=o.length,s=[];for(let a=1;a<r-1;a++){const l=xt(o[a-1],o[a]),d=xt(o[a],o[a+1]),u=a-1===0,f=a+1===r-1,p=u&&l==="v"||f&&d==="v",g=u&&l==="h"||f&&d==="h";p&&g||s.push(c.jsx(R0,{wireId:e,index:a,xLocked:p,yLocked:g},`v-${a}`))}const i=[];for(let a=0;a<r-1;a++){const l=o[a],d=o[a+1];Math.abs(l[0]-d[0])<gn&&Math.abs(l[1]-d[1])<gn||i.push(c.jsx(D0,{wireId:e,segIndex:a,axis:xt(l,d)},`m-${a}`))}return c.jsxs("g",{className:"ole-wire-handles",pointerEvents:"auto",children:[i,s]})}function R0({wireId:e,index:t,xLocked:n,yLocked:o}){const r=Ve(),s=S.useRef(null),i=x(m=>{var h;return(h=m.internal.wireRenders.get(e))==null?void 0:h.path});if(!i||t<=0||t>=i.length-1)return null;const[a,l]=i[t],d=n&&!o?"ns-resize":!n&&o?"ew-resize":"move",u=m=>{if(m.button!==0||(m.stopPropagation(),m.preventDefault(),!r))return;const h=x.getState().internal.wireRenders.get(e);h&&(s.current={pointerId:m.pointerId,startPath:h.path.map(y=>[y[0],y[1]]),startSvg:r.screenToSvg(m.clientX,m.clientY),index:t,xLocked:n,yLocked:o},document.body.style.cursor=d,m.target.setPointerCapture(m.pointerId))},f=m=>{const h=s.current;if(!h||m.pointerId!==h.pointerId||!r)return;const y=r.screenToSvg(m.clientX,m.clientY),v=h.startPath,b=h.index;if(b<=0||b>=v.length-1)return;const _=v[b],N=[h.xLocked?_[0]:ee(_[0]+(y[0]-h.startSvg[0])),h.yLocked?_[1]:ee(_[1]+(y[1]-h.startSvg[1]))];if(N[0]===_[0]&&N[1]===_[1])return;const I=v.map(te=>[te[0],te[1]]);I[b]=N;const B=xt(v[b-1],v[b]);b-1>0&&(B==="h"?I[b-1]=[v[b-1][0],N[1]]:I[b-1]=[N[0],v[b-1][1]]);const re=xt(v[b],v[b+1]);b+1<v.length-1&&(re==="h"?I[b+1]=[v[b+1][0],N[1]]:I[b+1]=[N[0],v[b+1][1]]),x.getState().updateWirePath(e,I)},p=m=>{const h=s.current;!h||m.pointerId!==h.pointerId||(m.target.hasPointerCapture(m.pointerId)&&m.target.releasePointerCapture(m.pointerId),s.current=null,document.body.style.cursor="")},g=m=>{m.stopPropagation(),m.preventDefault();const h=x.getState().internal.wireRenders.get(e);if(!h||h.path.length<=2||t<=0||t>=h.path.length-1)return;const y=h.path.filter((v,b)=>b!==t);x.getState().updateWirePath(e,y)};return c.jsx("circle",{className:"ole-wire-handle ole-wire-vertex",cx:a,cy:l,r:5,style:{cursor:d},onPointerDown:u,onPointerMove:f,onPointerUp:p,onPointerCancel:p,onDoubleClick:g})}function D0({wireId:e,segIndex:t,axis:n}){const o=Ve(),r=S.useRef(null),s=x(m=>{var h;return(h=m.internal.wireRenders.get(e))==null?void 0:h.path});if(!s||t<0||t>=s.length-1)return null;const i=s[t],a=s[t+1],l=(i[0]+a[0])/2,d=(i[1]+a[1])/2,u=n==="h"?"ns-resize":"ew-resize",f=m=>{if(m.button!==0||(m.stopPropagation(),m.preventDefault(),!o))return;const h=x.getState().internal.wireRenders.get(e);h&&(r.current={pointerId:m.pointerId,startPath:h.path.map(y=>[y[0],y[1]]),startSvg:o.screenToSvg(m.clientX,m.clientY),axis:n,segIndex:t},document.body.style.cursor=u,m.currentTarget.setPointerCapture(m.pointerId))},p=m=>{const h=r.current;if(!h||m.pointerId!==h.pointerId||!o)return;const y=o.screenToSvg(m.clientX,m.clientY),v=h.startPath,b=h.segIndex;if(b>=v.length-1)return;const _=v[b],N=v[b+1],I=[];for(let B=0;B<=b;B++)I.push(v[B]);if(h.axis==="h"){const B=ee(_[1]+(y[1]-h.startSvg[1]));I.push([_[0],B]),I.push([N[0],B])}else{const B=ee(_[0]+(y[0]-h.startSvg[0]));I.push([B,_[1]]),I.push([B,N[1]])}for(let B=b+1;B<v.length;B++)I.push(v[B]);x.getState().updateWirePath(e,I)},g=m=>{const h=r.current;if(!h||m.pointerId!==h.pointerId)return;const y=m.currentTarget;y.hasPointerCapture(m.pointerId)&&y.releasePointerCapture(m.pointerId),r.current=null,document.body.style.cursor=""};return c.jsxs("g",{className:"ole-wire-handle ole-wire-midpoint-group",style:{cursor:u},onPointerDown:f,onPointerMove:p,onPointerUp:g,onPointerCancel:g,children:[c.jsx("circle",{className:"ole-wire-midpoint-hit",cx:l,cy:d,r:8}),c.jsx("circle",{className:"ole-wire-handle ole-wire-midpoint",cx:l,cy:d,r:3.5})]})}const z0=3,tn=12;function F0(){const e=x(a=>a.internal.buses),t=x(a=>a.selection),n=x(a=>a.selectedNode),o=x(a=>a.internal.nodes),r=x(a=>a.internal.terminalToNode),s=new Set(t),i=new Set;if(n){const a=o.get(n);if(a)for(const l of a.terminals)l.includes(".")||i.add(l)}return c.jsx("g",{className:"ole-bus-layer",children:Array.from(e.values()).map(({bus:a,geometry:l})=>{const{axis:d,at:u,span:f}=l,p=f/2,g=d==="x"?u[0]-p:u[0],m=d==="x"?u[1]:u[1]-p,h=d==="x"?u[0]+p:u[0],y=d==="x"?u[1]:u[1]+p,v=s.has(a.id),b=i.has(a.id),_=r.get(a.id)??void 0,N=tn/2,I=d==="x"?u[0]-p:u[0]-N,B=d==="x"?u[1]-N:u[1]-p,re=d==="x"?f:tn,te=d==="x"?tn:f;return c.jsxs("g",{"data-bus-id":a.id,"data-element-id":a.id,"data-node-id":_,"data-selected":v?"true":void 0,"data-node-related":b?"true":void 0,className:"ole-bus",children:[c.jsx("rect",{x:I,y:B,width:re,height:te,fill:"transparent",className:"ole-bus-hit"}),c.jsx("line",{x1:g,y1:m,x2:h,y2:y,stroke:"black",strokeWidth:z0,strokeLinecap:"round",fill:"none"})]},a.id)})})}function H0(){const e=x(a=>a.busbarDrawStart),t=x(a=>a.cursorSvg);if(!e||!t)return null;const n=t[0]-e[0],o=t[1]-e[1],r=Math.abs(n)>=Math.abs(o),s=r?t[0]:e[0],i=r?e[1]:t[1];return c.jsxs("g",{className:"ole-busbar-preview",pointerEvents:"none",children:[c.jsx("line",{x1:e[0],y1:e[1],x2:s,y2:i,className:"ole-busbar-preview-line"}),c.jsx("circle",{cx:e[0],cy:e[1],r:3.5,className:"ole-busbar-preview-anchor"}),c.jsx("circle",{cx:s,cy:i,r:3.5,className:"ole-busbar-preview-anchor"})]})}function Ge(e){const t=[`translate(${e.at[0]} ${e.at[1]})`];return e.rot&&t.push(`rotate(${e.rot})`),e.mirror&&t.push("scale(-1 1)"),t.join(" ")}function W0(e){const t=e.trim().split(/\s+/).map(Number);return t.length!==4||t.some(n=>Number.isNaN(n))?null:{x:t[0],y:t[1],w:t[2],h:t[3]}}function G0({lib:e}){const t=W0(e.viewBox);return t?c.jsx("rect",{className:"ole-element-hit",x:t.x,y:t.y,width:t.w,height:t.h}):null}function K0(){const e=x(a=>a.internal.elements),t=x(a=>a.internal.layout),n=x(a=>a.selection),o=x(a=>a.selectedNode),r=x(a=>a.internal.nodes),s=new Set(n),i=new Set;if(o){const a=r.get(o);if(a)for(const l of a.terminals){const d=l.indexOf(".");d>0&&i.add(l.slice(0,d))}}return c.jsx("g",{className:"ole-element-layer",children:Array.from(e.values()).map(a=>{const l=t.get(a.element.id);if(!l)return null;const d=s.has(a.element.id),u=i.has(a.element.id);return a.libraryDef?c.jsxs("g",{"data-element-id":a.element.id,"data-selected":d?"true":void 0,"data-node-related":u?"true":void 0,transform:Ge(l),className:"ole-element",children:[c.jsx(G0,{lib:a.libraryDef}),c.jsx("g",{dangerouslySetInnerHTML:{__html:a.libraryDef.svg}})]},a.element.id):c.jsxs("g",{"data-element-id":a.element.id,"data-selected":d?"true":void 0,"data-node-related":u?"true":void 0,transform:Ge(l),className:"ole-element ole-element--unknown",children:[c.jsx("rect",{x:-10,y:-10,width:20,height:20,fill:"none",stroke:"#EF4444",strokeWidth:1,strokeDasharray:"2 2"}),c.jsx("text",{x:0,y:4,fontSize:8,fill:"#EF4444",textAnchor:"middle",fontFamily:"system-ui, sans-serif",children:"?"})]},a.element.id)})})}let _m=null;const xn=new Set;function Nt(e){_m=e;for(const t of xn)t(e)}function q0(){return _m}function Y0(e){return xn.add(e),()=>{xn.delete(e)}}function X0(){const[e,t]=S.useState(q0());return S.useEffect(()=>Y0(t),[]),!e||e.w===0&&e.h===0?null:c.jsx("rect",{className:"ole-marquee",x:e.x,y:e.y,width:e.w,height:e.h,pointerEvents:"none"})}function V0(){const e=x(d=>d.activeTool),t=x(d=>d.placeKind),n=x(d=>d.cursorSvg),o=x(d=>d.placeFromTerminal);if(e!=="place"||!t||!n)return null;const r=hm(t);if(!r)return null;let s=null,i=null;if(o){const d=wm(o,n);d&&(s=vm(r,d,n),i={source:d.world,pin:n})}else s=bm(r);const a=n[0]-((s==null?void 0:s.x)??0),l=n[1]-((s==null?void 0:s.y)??0);return c.jsxs("g",{className:"ole-place-ghost-group",pointerEvents:"none",children:[i&&c.jsxs(c.Fragment,{children:[c.jsx("line",{x1:i.source[0],y1:i.source[1],x2:i.pin[0],y2:i.pin[1],className:"ole-wire-preview-line"}),c.jsx("circle",{cx:i.source[0],cy:i.source[1],r:4,className:"ole-wire-preview-anchor"})]}),c.jsx("g",{className:"ole-place-ghost",transform:`translate(${a} ${l})`,opacity:.5,children:c.jsx("g",{dangerouslySetInnerHTML:{__html:r.svg}})})]})}function U0(){const e=x(r=>r.selection),t=x(r=>r.internal.elements),n=x(r=>r.internal.layout),o=x(r=>r.internal.buses);return e.length===0?null:c.jsx("g",{className:"ole-selection-overlay",pointerEvents:"none",children:e.map(r=>{const s=o.get(r);if(s){const{axis:d,at:u,span:f}=s.geometry,p=f/2,g=d==="x"?u[0]-p:u[0]-4,m=d==="x"?u[1]-4:u[1]-p,h=d==="x"?f:8,y=d==="x"?8:f;return c.jsx("rect",{x:g,y:m,width:h,height:y,fill:"none",className:"ole-selection-rect"},r)}const i=t.get(r),a=n.get(r);if(!(i!=null&&i.libraryDef)||!a)return null;const l=Z0(i.libraryDef.viewBox);return l?c.jsx("rect",{x:l.x,y:l.y,width:l.w,height:l.h,fill:"none",className:"ole-selection-rect",transform:Ge(a)},r):null})})}function Z0(e){const t=e.trim().split(/\s+/).map(Number);return t.length!==4||t.some(n=>Number.isNaN(n))?null:{x:t[0],y:t[1],w:t[2],h:t[3]}}function J0(){const e=x(s=>s.internal.terminals),t=x(s=>s.internal.terminalToNode),n=x(s=>s.wireFromTerminal),o=x(s=>s.selection),r=new Set(o);return c.jsx("g",{className:"ole-terminal-layer",children:Array.from(e.values()).map(s=>{const i=t.get(s.ref),a=i!==void 0,l=n===s.ref,d=r.has(s.elementId);return c.jsx("circle",{cx:s.world[0],cy:s.world[1],r:3,"data-element-id":s.elementId,"data-terminal-id":s.ref,"data-node-id":i,"data-connected":a?"true":"false","data-active":l?"true":void 0,"data-on-selected":d?"true":void 0,className:"ole-terminal"},s.ref)})})}function Q0(){const e=x(i=>i.internal.wireRenders),t=x(i=>i.internal.terminalToNode),n=x(i=>i.diagram.wires),o=x(i=>i.selectedWire),r=x(i=>i.selectedNode),s=new Map;for(const i of n??[]){const a=t.get(i.ends[0]);a&&s.set(i.id,a)}return c.jsx("g",{className:"ole-wire-layer",fill:"none",stroke:"currentColor",strokeWidth:1,children:Array.from(e.values()).flatMap(i=>{const a=i.path;if(a.length<2)return[];const l=a.map(p=>`${p[0]},${p[1]}`).join(" "),d=s.get(i.wireId),u=o===i.wireId,f=r!=null&&r===d;return[c.jsx("polyline",{"data-wire-id":i.wireId,"data-node-id":d,className:"ole-wire-hit",points:l},`hit-${i.wireId}`),c.jsx("polyline",{"data-wire-id":i.wireId,"data-node-id":d,"data-manual":i.userEdited?"true":void 0,"data-selected":u||f?"true":void 0,className:"ole-wire",points:l},i.wireId)]})})}let Xe=null;const yn=new Set;function Me(e){if(!(e===null&&Xe===null||e&&Xe&&e.ref===Xe.ref&&e.world[0]===Xe.world[0]&&e.world[1]===Xe.world[1])){Xe=e;for(const t of yn)t(e)}}function ex(){return Xe}function tx(e){return yn.add(e),()=>{yn.delete(e)}}function nx(){var d,u;const e=x(f=>f.wireFromTerminal),t=x(f=>f.cursorSvg),n=x(f=>f.internal.terminals),[o,r]=S.useState(ex());S.useEffect(()=>tx(r),[]);const s=x(f=>f.internal.buses);if(!e||!t)return null;let i;if(e.includes(".")?i=(d=n.get(e))==null?void 0:d.world:i=(u=s.get(e))==null?void 0:u.geometry.at,!i)return null;const a=(o==null?void 0:o.world[0])??t[0],l=(o==null?void 0:o.world[1])??t[1];return c.jsxs("g",{className:"ole-wire-preview",pointerEvents:"none",children:[c.jsx("line",{x1:i[0],y1:i[1],x2:a,y2:l,className:"ole-wire-preview-line"}),c.jsx("circle",{cx:i[0],cy:i[1],r:4,className:"ole-wire-preview-anchor"}),o&&c.jsxs(c.Fragment,{children:[c.jsx("circle",{cx:o.world[0],cy:o.world[1],r:o.isBus?7:8,className:"ole-wire-preview-target-ring"}),c.jsx("circle",{cx:o.world[0],cy:o.world[1],r:o.isBus?3:4,className:"ole-wire-preview-target-dot"})]})]})}function ot(e,t){return e instanceof Element?e.closest(`[${t}]`):null}function tt(e){var t;return((t=ot(e,"data-element-id"))==null?void 0:t.getAttribute("data-element-id"))??null}function ox(e){var t;return((t=ot(e,"data-bus-id"))==null?void 0:t.getAttribute("data-bus-id"))??null}function We(e){var o;const t=(o=ot(e,"data-terminal-id"))==null?void 0:o.getAttribute("data-terminal-id");if(t)return t;const n=ox(e);return n||null}function Kt(e){var t;return((t=ot(e,"data-node-id"))==null?void 0:t.getAttribute("data-node-id"))??null}function rx(e){var t;return((t=ot(e,"data-wire-id"))==null?void 0:t.getAttribute("data-wire-id"))??null}function Rt(e){var t;return((t=ot(e,"data-annotation-id"))==null?void 0:t.getAttribute("data-annotation-id"))??null}function Sm(e,t){try{e.dispatchEvent(new PointerEvent("pointercancel",{pointerId:t,bubbles:!0,cancelable:!0,pointerType:"touch"}))}catch{}}function sx(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable}function jm(){const e=x.getState(),t=e.activeTool;if(e.editingAnnotation||e.editingElement){if(typeof document<"u"){const n=document.querySelector(".ole-free-annotation-edit-fo div[contenteditable], .ole-element-name-editor div[contenteditable]");n==null||n.blur()}e.setEditingAnnotation(null),e.setEditingElement(null);return}if(t==="wire"||t==="busbar"||t==="text"){e.setActiveTool("select");return}if(t==="place"){e.placeFromTerminal?e.setPlaceFromTerminal(null):e.placeKind?e.setPlaceKind(null):e.setActiveTool("select");return}(e.selectedNode||e.selectedWire||e.selection.length>0||e.selectedAnnotation)&&e.clearSelection()}function ix(){S.useEffect(()=>{const e=t=>{if(sx(t.target))return;const n=t.metaKey||t.ctrlKey,o=x.getState();if(n&&t.key.toLowerCase()==="z"){t.preventDefault(),t.shiftKey?o.redo():o.undo();return}if(n&&!t.shiftKey&&t.key.toLowerCase()==="y"){t.preventDefault(),o.redo();return}if(n&&t.key.toLowerCase()==="a"){t.preventDefault();const r=x.getState().diagram.elements.map(s=>s.id);o.setSelection(r);return}if(n&&!t.shiftKey&&!t.altKey){const r=t.key.toLowerCase();if(r==="c"){if(o.selection.length===0)return;t.preventDefault(),o.copySelection();return}if(r==="x"){if(o.selection.length===0)return;t.preventDefault(),o.cutSelection();return}if(r==="v"){if(!o.clipboard)return;t.preventDefault(),o.pasteClipboard();return}}if(!n)switch(t.key){case"v":case"V":o.setActiveTool("select");return;case"h":case"H":o.setActiveTool("pan");return;case"w":case"W":o.setActiveTool("wire");return;case"b":case"B":o.setActiveTool("busbar");return;case"p":case"P":o.setActiveTool("place");return;case"t":case"T":o.setActiveTool("text");return;case"r":case"R":o.selection.length>0&&(t.preventDefault(),o.rotateSelection(90));return;case"m":case"M":o.selection.length>0&&(t.preventDefault(),o.mirrorSelection());return;case"Delete":case"Backspace":o.selectedAnnotation?(t.preventDefault(),o.deleteAnnotation(o.selectedAnnotation)):o.selectedWire?(t.preventDefault(),o.deleteSelectedWire()):o.selectedNode?(t.preventDefault(),o.deleteSelectedNode()):o.selection.length>0&&(t.preventDefault(),o.deleteSelection());return;case"Escape":jm();return}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[])}let bn=null;const wn=new Set;function ax(e){if(e!==bn){bn=e;for(const t of wn)t(e)}}function lx(){return bn}function cx(e){return wn.add(e),()=>{wn.delete(e)}}const xo="ole-hover-element-host",dx="ole-hover-terminal-on",ux="ole-hover-node-on";function fx(e){S.useEffect(()=>{const t=e.current;if(!t)return;let n=null,o=null;const r=new Set,s=new Set,i=(f,p,g)=>{for(const m of f)m.classList.remove(g);f.clear();for(const m of p)m.classList.add(g),f.add(m)},a=f=>{var g,m;if(f===n)return;n&&((g=t.querySelector(`[data-element-id="${Tt(n)}"]`))==null||g.classList.remove(xo)),f&&((m=t.querySelector(`[data-element-id="${Tt(f)}"]`))==null||m.classList.add(xo));const p=f?Array.from(t.querySelectorAll(`.ole-terminal[data-element-id="${Tt(f)}"]`)):[];i(r,p,dx),n=f,f?t.setAttribute("data-hover-element",""):t.removeAttribute("data-hover-element"),ax(f)},l=f=>{if(f===o)return;const p=f?Array.from(t.querySelectorAll(`[data-node-id="${Tt(f)}"]`)):[];i(s,p,ux),o=f,f?t.setAttribute("data-hover-node",""):t.removeAttribute("data-hover-node")},d=f=>{a(tt(f.target));const p=We(f.target);let g=null;p?g=x.getState().internal.terminalToNode.get(p)??null:g=Kt(f.target),l(g)},u=()=>{a(null),l(null)};return t.addEventListener("pointermove",d),t.addEventListener("pointerleave",u),()=>{t.removeEventListener("pointermove",d),t.removeEventListener("pointerleave",u),a(null),l(null)}},[e])}function Tt(e){return e.replace(/(["\\])/g,"\\$1")}function $m(e,t){const n=x.getState().internal;if(!e.includes(".")){const r=n.buses.get(e);if(!r)return null;const{axis:s,at:i,span:a}=r.geometry;if(s==="x"){const f=i[0]-a/2,p=i[0]+a/2,g=Math.max(f,Math.min(p,t[0]));return{ref:e,world:[g,i[1]],isBus:!0}}const l=i[1]-a/2,d=i[1]+a/2,u=Math.max(l,Math.min(d,t[1]));return{ref:e,world:[i[0],u],isBus:!0}}const o=n.terminals.get(e);return o?{ref:e,world:o.world,isBus:!1}:null}const yo=3;let de=null,Se=null,je=null,ie=null;const mx={id:"select",cursor:"default",onPointerDown(e,t){var f,p,g,m;if(e.button!==0||e.target instanceof Element&&e.target.closest(".ole-bus-handle, .ole-wire-handle"))return;const n=x.getState(),o=Rt(e.target);if(o){e.preventDefault(),e.stopPropagation();const h=(f=n.diagram.annotations)==null?void 0:f.find(y=>y.id===o);if(!h)return;n.setSelectedAnnotation(o),ie={pointerId:e.pointerId,id:o,startSvg:t.viewport.screenToSvg(e.clientX,e.clientY),origin:[h.at[0],h.at[1]],moved:!1};return}const s=(e.target instanceof Element?(p=e.target.closest("[data-terminal-id]"))==null?void 0:p.getAttribute("data-terminal-id"):null)?We(e.target):null;if(s){const h=s.indexOf("."),y=h>0?s.slice(0,h):"";if(y&&n.selection.includes(y)){e.preventDefault(),e.stopPropagation(),e.target instanceof Element&&((m=(g=e.target).hasPointerCapture)!=null&&m.call(g,e.pointerId))&&e.target.releasePointerCapture(e.pointerId),t.hostEl.classList.add("tool-wire"),n.setWireFromTerminal(s),n.setCursorSvg(t.viewport.screenToSvg(e.clientX,e.clientY)),je={pointerId:e.pointerId,fromRef:s};return}}const i=tt(e.target);if(!i){const h=rx(e.target);if(h){if(e.preventDefault(),e.altKey){const y=Kt(e.target);if(y){n.setSelectedNode(y);return}}n.setSelectedWire(h);return}e.shiftKey||n.clearSelection(),Se={pointerId:e.pointerId,startSvg:t.viewport.screenToSvg(e.clientX,e.clientY),shiftKey:e.shiftKey,baseSelection:e.shiftKey?n.selection.slice():[]},t.hostEl.setPointerCapture(e.pointerId),e.preventDefault();return}const a=n.selection;e.shiftKey?n.toggleInSelection(i):a.includes(i)||n.setSelection([i]);const l=e.shiftKey?x.getState().selection:a.includes(i)?a:[i];if(l.length===0)return;const d=x.getState().internal,u=new Map;for(const h of l){const y=d.layout.get(h);y&&u.set(h,{...y})}u.size!==0&&(de={pointerId:e.pointerId,startSvg:t.viewport.screenToSvg(e.clientX,e.clientY),originals:u,moved:!1},e.preventDefault())},onPointerMove(e,t){if(ie&&e.pointerId===ie.pointerId){const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=ee(n[0]-ie.startSvg[0]),r=ee(n[1]-ie.startSvg[1]);!ie.moved&&(o!==0||r!==0)&&(ie.moved=!0,t.hostEl.hasPointerCapture(e.pointerId)||t.hostEl.setPointerCapture(e.pointerId));const s=t.hostEl.querySelector(`[data-annotation-id="${ut(ie.id)}"]`);s&&s.setAttribute("transform",`translate(${o} ${r})`);return}if(je&&e.pointerId===je.pointerId){const n=t.viewport.screenToSvg(e.clientX,e.clientY);x.getState().setCursorSvg(n);const o=typeof document<"u"?document.elementFromPoint(e.clientX,e.clientY):null,r=o?We(o):null;if(!r||r===je.fromRef){Me(null);return}Me($m(r,n));return}if(de&&e.pointerId===de.pointerId){const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=ee(n[0]-de.startSvg[0]),r=ee(n[1]-de.startSvg[1]);!de.moved&&(o!==0||r!==0)&&(de.moved=!0,t.hostEl.hasPointerCapture(e.pointerId)||t.hostEl.setPointerCapture(e.pointerId));for(const[s,i]of de.originals){const a=t.hostEl.querySelector(`[data-element-id="${ut(s)}"]`);if(!a)continue;const l={...i,at:[i.at[0]+o,i.at[1]+r]};a.setAttribute("transform",Ge(l))}return}if(Se&&e.pointerId===Se.pointerId){const n=t.viewport.screenToSvg(e.clientX,e.clientY);Nt(bo(Se.startSvg,n));return}},onPointerUp(e,t){if(ie&&e.pointerId===ie.pointerId){t.hostEl.hasPointerCapture(e.pointerId)&&t.hostEl.releasePointerCapture(e.pointerId);const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=ee(n[0]-ie.startSvg[0]),r=ee(n[1]-ie.startSvg[1]),s=t.hostEl.querySelector(`[data-annotation-id="${ut(ie.id)}"]`);s&&s.removeAttribute("transform"),ie.moved&&(o!==0||r!==0)&&x.getState().updateAnnotation(ie.id,{at:[ie.origin[0]+o,ie.origin[1]+r]}),ie=null;return}if(je&&e.pointerId===je.pointerId){const n=x.getState(),o=je.fromRef;je=null,t.hostEl.classList.remove("tool-wire"),n.setWireFromTerminal(null),n.setCursorSvg(null),Me(null);const r=We(e.target);r&&r!==o&&n.addWire(o,r);return}if(de&&e.pointerId===de.pointerId){if(t.hostEl.hasPointerCapture(e.pointerId)&&t.hostEl.releasePointerCapture(e.pointerId),de.moved){const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=ee(n[0]-de.startSvg[0]),r=ee(n[1]-de.startSvg[1]);if(o!==0||r!==0){const s=new Map;for(const i of de.originals.keys())s.set(i,[o,r]);x.getState().moveElements(s)}}de=null;return}if(Se&&e.pointerId===Se.pointerId){t.hostEl.hasPointerCapture(e.pointerId)&&t.hostEl.releasePointerCapture(e.pointerId);const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=bo(Se.startSvg,n);if(o.w>=yo||o.h>=yo){const r=hx(o);if(Se.shiftKey){const s=new Set(Se.baseSelection);for(const i of r)s.has(i)?s.delete(i):s.add(i);x.getState().setSelection([...s])}else x.getState().setSelection(r)}Nt(null),Se=null}},onPointerCancel(e,t){var n,o,r,s,i,a;if(ie&&e.pointerId===ie.pointerId){const l=t.hostEl.querySelector(`[data-annotation-id="${ut(ie.id)}"]`);if(l&&l.removeAttribute("transform"),(o=(n=t.hostEl).hasPointerCapture)!=null&&o.call(n,e.pointerId))try{t.hostEl.releasePointerCapture(e.pointerId)}catch{}ie=null}if(de&&e.pointerId===de.pointerId){for(const[l,d]of de.originals){const u=t.hostEl.querySelector(`[data-element-id="${ut(l)}"]`);u&&u.setAttribute("transform",Ge(d))}if((s=(r=t.hostEl).hasPointerCapture)!=null&&s.call(r,e.pointerId))try{t.hostEl.releasePointerCapture(e.pointerId)}catch{}de=null}if(je&&e.pointerId===je.pointerId){t.hostEl.classList.remove("tool-wire");const l=x.getState();l.setWireFromTerminal(null),l.setCursorSvg(null),Me(null),je=null}if(Se&&e.pointerId===Se.pointerId){if((a=(i=t.hostEl).hasPointerCapture)!=null&&a.call(i,e.pointerId))try{t.hostEl.releasePointerCapture(e.pointerId)}catch{}Nt(null),Se=null}},onDoubleClick(e){const t=x.getState(),n=Rt(e.target);if(n){e.preventDefault(),e.stopPropagation(),t.setEditingAnnotation(n);return}const o=tt(e.target);o&&(e.preventDefault(),e.stopPropagation(),t.setEditingElement(o))},onDeactivate(e){if(de=null,Se=null,ie=null,je){e.hostEl.classList.remove("tool-wire");const t=x.getState();t.setWireFromTerminal(null),t.setCursorSvg(null),Me(null),je=null}Nt(null)}};function bo(e,t){const n=Math.min(e[0],t[0]),o=Math.min(e[1],t[1]),r=Math.abs(t[0]-e[0]),s=Math.abs(t[1]-e[1]);return{x:n,y:o,w:r,h:s}}function hx(e){const{internal:t}=x.getState(),n=[];for(const o of t.elements.values()){if(!o.libraryDef)continue;const r=t.layout.get(o.element.id);if(!r)continue;const s=gx(o.libraryDef.viewBox);if(!s)continue;const i=[[s.x,s.y],[s.x+s.w,s.y],[s.x,s.y+s.h],[s.x+s.w,s.y+s.h]].map(([f,p])=>px([f,p],r));let a=1/0,l=-1/0,d=1/0,u=-1/0;for(const[f,p]of i)f<a&&(a=f),f>l&&(l=f),p<d&&(d=p),p>u&&(u=p);l>=e.x&&a<=e.x+e.w&&u>=e.y&&d<=e.y+e.h&&n.push(o.element.id)}for(const{bus:o,geometry:r}of t.buses.values()){const{axis:s,at:i,span:a}=r,l=a/2,d=s==="x"?i[0]-l:i[0],u=s==="x"?i[0]+l:i[0],f=s==="x"?i[1]:i[1]-l,p=s==="x"?i[1]:i[1]+l;u>=e.x&&d<=e.x+e.w&&p>=e.y&&f<=e.y+e.h&&n.push(o.id)}return n}function px(e,t){let[n,o]=e;switch(t.mirror&&(n=-n),t.rot){case 0:break;case 90:[n,o]=[-o,n];break;case 180:[n,o]=[-n,-o];break;case 270:[n,o]=[o,-n];break}return[n+t.at[0],o+t.at[1]]}function gx(e){const t=e.trim().split(/\s+/).map(Number);return t.length!==4||t.some(n=>Number.isNaN(n))?null:{x:t[0],y:t[1],w:t[2],h:t[3]}}function ut(e){return e.replace(/(["\\])/g,"\\$1")}const xx=4;let J=null;const yx={id:"pan",cursor:"grab",onPointerDown(e,t){if(e.button!==0)return;const n=t.viewport.getViewport(),o=tt(e.target);let r=null;if(o){const s=x.getState();s.selection.includes(o)||s.setSelection([o]);const i=x.getState().selection,a=x.getState().internal,l=new Map;for(const d of i){const u=a.layout.get(d);u&&l.set(d,{...u})}l.size>0&&(r={startSvg:t.viewport.screenToSvg(e.clientX,e.clientY),originals:l})}J={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,startTx:n.tx,startTy:n.ty,startTarget:e.target,moved:!1,elementDrag:r},t.hostEl.style.cursor="grabbing",e.preventDefault()},onPointerMove(e,t){if(!J||e.pointerId!==J.pointerId)return;const n=e.clientX-J.startX,o=e.clientY-J.startY;if(!J.moved&&Math.hypot(n,o)>xx){J.moved=!0;try{t.hostEl.setPointerCapture(e.pointerId)}catch{}}if(J.moved){if(J.elementDrag){const r=t.viewport.screenToSvg(e.clientX,e.clientY),s=ee(r[0]-J.elementDrag.startSvg[0]),i=ee(r[1]-J.elementDrag.startSvg[1]);for(const[a,l]of J.elementDrag.originals){const d=t.hostEl.querySelector(`[data-element-id="${wo(a)}"]`);if(!d)continue;const u={...l,at:[l.at[0]+s,l.at[1]+i]};d.setAttribute("transform",Ge(u))}return}t.viewport.setViewport({tx:J.startTx+n,ty:J.startTy+o})}},onPointerUp(e,t){if(!(!J||e.pointerId!==J.pointerId)){if(t.hostEl.hasPointerCapture(e.pointerId)&&t.hostEl.releasePointerCapture(e.pointerId),t.hostEl.style.cursor="grab",J.elementDrag&&J.moved){const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=ee(n[0]-J.elementDrag.startSvg[0]),r=ee(n[1]-J.elementDrag.startSvg[1]);if(o!==0||r!==0){const s=new Map;for(const i of J.elementDrag.originals.keys())s.set(i,[o,r]);x.getState().moveElements(s)}}else J.moved||bx(J.startTarget);J=null}},onPointerCancel(e,t){if(J!=null&&J.elementDrag)for(const[n,o]of J.elementDrag.originals){const r=t.hostEl.querySelector(`[data-element-id="${wo(n)}"]`);r&&r.setAttribute("transform",Ge(o))}J=null},onDeactivate(){J=null}};function bx(e){if(!e)return;const t=x.getState(),n=Rt(e);if(n){t.setSelectedAnnotation(n);return}const o=tt(e);if(o){t.setSelection([o]);return}const r=Kt(e);if(r){t.setSelectedNode(r);return}t.clearSelection()}function wo(e){return e.replace(/(["\\])/g,"\\$1")}const ht={tight:1024,compact:720,dense:520,mini:380},vo={full:0,tight:1,compact:2,dense:3,mini:4};function Ie(e,t){return vo[e]>=vo[t]}function wx(e){return e>=ht.tight?"full":e>=ht.compact?"tight":e>=ht.dense?"compact":e>=ht.mini?"dense":"mini"}const Em=S.createContext("full");function qe(){return S.useContext(Em)}function vx(e){const[t,n]=S.useState(null);return S.useLayoutEffect(()=>{const o=e.current;if(!o)return;const r=()=>{const i=o.clientWidth;n(a=>a===i?a:i)};if(r(),typeof ResizeObserver>"u")return;const s=new ResizeObserver(r);return s.observe(o),()=>s.disconnect()},[e]),t}function Nm(){if(typeof window>"u")return!1;try{if(!window.matchMedia("(pointer: coarse)").matches)return!1}catch{return!1}return window.innerWidth<ht.dense}function Cn(){Nm()&&x.getState().setActiveTool("pan")}function kx(){Nm()&&x.getState().setPlaceKind(null)}const _x={id:"wire",cursor:"crosshair",onActivate(e){e.hostEl.classList.add("tool-wire")},onDeactivate(e){e.hostEl.classList.remove("tool-wire");const t=x.getState();t.setWireFromTerminal(null),t.setCursorSvg(null),Me(null)},onPointerDown(e,t){var r,s;if(e.button!==0)return;const n=We(e.target);if(!n)return;e.preventDefault(),e.stopPropagation(),e.target instanceof Element&&((s=(r=e.target).hasPointerCapture)!=null&&s.call(r,e.pointerId))&&e.target.releasePointerCapture(e.pointerId);const o=x.getState();o.setWireFromTerminal(n),o.setCursorSvg(t.viewport.screenToSvg(e.clientX,e.clientY))},onPointerMove(e,t){const n=x.getState().wireFromTerminal;if(!n)return;const o=t.viewport.screenToSvg(e.clientX,e.clientY);x.getState().setCursorSvg(o);const r=typeof document<"u"?document.elementFromPoint(e.clientX,e.clientY):null,s=r?We(r):null;if(!s||s===n){Me(null);return}Me($m(s,o))},onPointerUp(e){const t=x.getState(),n=t.wireFromTerminal;if(!n)return;t.setWireFromTerminal(null),t.setCursorSvg(null),Me(null);const o=We(e.target);!o||o===n||(t.addWire(n,o),Cn())},onPointerLeave(){const e=x.getState();e.setWireFromTerminal(null),e.setCursorSvg(null),Me(null)}},ko=10;let ft=!1;function _o(){setTimeout(()=>kx(),0)}const Sx={id:"place",cursor:"copy",onActivate(e){e.hostEl.classList.add("tool-place")},onDeactivate(e){e.hostEl.classList.remove("tool-place");const t=x.getState();t.setPlaceFromTerminal(null),t.setCursorSvg(null),ft=!1},onPointerDown(e,t){var s,i;if(e.button!==0)return;const{placeKind:n}=x.getState();if(!n)return;e.preventDefault();const o=We(e.target);if(o){e.stopPropagation(),e.target instanceof Element&&((i=(s=e.target).hasPointerCapture)!=null&&i.call(s,e.pointerId))&&e.target.releasePointerCapture(e.pointerId);const a=x.getState();a.setPlaceFromTerminal(o),a.setCursorSvg(t.viewport.screenToSvg(e.clientX,e.clientY));return}const r=t.viewport.screenToSvg(e.clientX,e.clientY);ym(n,r),ft=!0},onPointerMove(e,t){const n=t.viewport.screenToSvg(e.clientX,e.clientY);x.getState().setCursorSvg([So(n[0]),So(n[1])])},onPointerUp(e,t){const n=x.getState(),o=n.placeFromTerminal;if(o){n.setPlaceFromTerminal(null);const{placeKind:r}=n;if(!r)return;const s=t.viewport.screenToSvg(e.clientX,e.clientY);N0(r,o,s),_o();return}ft&&(ft=!1,_o())},onPointerLeave(){const e=x.getState();e.setPlaceFromTerminal(null),e.setCursorSvg(null)},onPointerCancel(){const e=x.getState();e.setPlaceFromTerminal(null),e.setCursorSvg(null),ft=!1}};function So(e){return Math.round(e/ko)*ko}const jo=10,$o=20;function Ze(e){return Math.round(e/jo)*jo}const jx={id:"busbar",cursor:"crosshair",onPointerDown(e,t){if(e.button!==0)return;e.preventDefault();const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=[Ze(n[0]),Ze(n[1])];x.getState().setBusbarDrawStart(o),x.getState().setCursorSvg(o)},onPointerMove(e,t){const n=t.viewport.screenToSvg(e.clientX,e.clientY);x.getState().setCursorSvg([Ze(n[0]),Ze(n[1])])},onPointerUp(e,t){const n=x.getState().busbarDrawStart;if(x.getState().setBusbarDrawStart(null),!n)return;const o=t.viewport.screenToSvg(e.clientX,e.clientY),r=Ze(o[0]),s=Ze(o[1]),i=r-n[0],a=s-n[1],l=Math.abs(i)>=Math.abs(a);let d,u,f;if(l){if(u=Math.abs(i),u<$o)return;d=0,f=[(n[0]+r)/2,n[1]]}else{if(u=Math.abs(a),u<$o)return;d=90,f=[n[0],(n[1]+s)/2]}x.getState().addBus(f,u,d),Cn()},onPointerLeave(){const e=x.getState();e.setBusbarDrawStart(null),e.setCursorSvg(null)},onPointerCancel(){const e=x.getState();e.setBusbarDrawStart(null),e.setCursorSvg(null)},onDeactivate(){const e=x.getState();e.setBusbarDrawStart(null),e.setCursorSvg(null)}},$x={id:"text",cursor:"text",onPointerDown(e,t){if(e.button!==0)return;const n=x.getState(),o=Rt(e.target);if(o){e.preventDefault(),e.stopPropagation(),n.setActiveTool("select"),n.setSelectedAnnotation(o);return}e.preventDefault();const r=t.viewport.screenToSvg(e.clientX,e.clientY),s=n.addAnnotation([r[0],r[1]],"");n.setEditingAnnotation(s),Cn()}},Ex={select:mx,pan:yx,wire:_x,place:Sx,busbar:jx,text:$x};function Nx(e,t){const n=x(o=>o.activeTool);S.useEffect(()=>{var p;const o=e.current;if(!o)return;const r=Ex[n],s={viewport:t,hostEl:o};(p=r.onActivate)==null||p.call(r,s),r.cursor&&(o.style.cursor=r.cursor);const i=g=>{var m;return(m=r.onPointerDown)==null?void 0:m.call(r,g,s)},a=g=>{var m;return(m=r.onPointerMove)==null?void 0:m.call(r,g,s)},l=g=>{var m;return(m=r.onPointerUp)==null?void 0:m.call(r,g,s)},d=g=>{var m;return r.onPointerCancel?r.onPointerCancel(g,s):(m=r.onPointerUp)==null?void 0:m.call(r,g,s)},u=g=>{var m;return(m=r.onPointerLeave)==null?void 0:m.call(r,g,s)},f=g=>{var m;return(m=r.onDoubleClick)==null?void 0:m.call(r,g,s)};return o.addEventListener("pointerdown",i),o.addEventListener("pointermove",a),o.addEventListener("pointerup",l),o.addEventListener("pointercancel",d),o.addEventListener("pointerleave",u),o.addEventListener("dblclick",f),()=>{var g;o.removeEventListener("pointerdown",i),o.removeEventListener("pointermove",a),o.removeEventListener("pointerup",l),o.removeEventListener("pointercancel",d),o.removeEventListener("pointerleave",u),o.removeEventListener("dblclick",f),(g=r.onDeactivate)==null||g.call(r,s),o.style.cursor=""}},[n,e,t])}let vn=1;const kn=new Set;function Tx(e){if(e!==vn){vn=e;for(const t of kn)t(e)}}function Cx(){return vn}function Ix(e){return kn.add(e),()=>{kn.delete(e)}}const nn=.1,on=8,Ax=1.0015,Mx=1.02;function Px(e,t,n={tx:0,ty:0,scale:1}){const o=S.useRef({...n}),r=S.useRef(new Set),s=()=>{const i=t.current,a=e.current;if(i&&i.setAttribute("transform",`translate(${o.current.tx} ${o.current.ty}) scale(${o.current.scale})`),a&&a.style.setProperty("--canvas-scale",String(o.current.scale)),Tx(o.current.scale),r.current.size>0){const l={...o.current};for(const d of r.current)d(l)}};return S.useEffect(()=>{const i=e.current;if(!i)return;let a=!1,l=-1,d=0,u=0,f=0,p=0,g=!1;const m=new Map;let h=null,y=!1;const v=()=>{if(m.size<2){h=null;return}const E=[...m.values()],M=E[1].x-E[0].x,se=E[1].y-E[0].y,ne=Math.hypot(M,se)||1,ce=i.getBoundingClientRect();h={startDist:ne,startScale:o.current.scale,startTx:o.current.tx,startTy:o.current.ty,startMidX:(E[0].x+E[1].x)/2-ce.left,startMidY:(E[0].y+E[1].y)/2-ce.top}},b=E=>{if(E.pointerType==="touch"){if(m.set(E.pointerId,{x:E.clientX,y:E.clientY}),m.size>=2&&!y){y=!0;for(const M of m.keys())M!==E.pointerId&&Sm(i,M);v()}if(y){E.stopPropagation(),E.preventDefault();try{i.setPointerCapture(E.pointerId)}catch{}}}},_=E=>{if(E.pointerType!=="touch"||!m.has(E.pointerId)||(m.set(E.pointerId,{x:E.clientX,y:E.clientY}),!y||!h))return;E.stopPropagation();const M=[...m.values()];if(M.length<2)return;const se=M[1].x-M[0].x,ne=M[1].y-M[0].y,ce=Math.hypot(se,ne)||1,X=i.getBoundingClientRect(),ue=(M[0].x+M[1].x)/2-X.left,ae=(M[0].y+M[1].y)/2-X.top,he=ce/h.startDist,ke=rn(h.startScale*he,nn,on),ye=ke/h.startScale;o.current.tx=h.startMidX-(h.startMidX-h.startTx)*ye+(ue-h.startMidX),o.current.ty=h.startMidY-(h.startMidY-h.startTy)*ye+(ae-h.startMidY),o.current.scale=ke,s()},N=E=>{var M;if(E.pointerType==="touch"&&m.has(E.pointerId)&&(m.delete(E.pointerId),y)){if(E.stopPropagation(),(M=i.hasPointerCapture)!=null&&M.call(i,E.pointerId))try{i.releasePointerCapture(E.pointerId)}catch{}m.size>=2?v():h=null,m.size===0&&(y=!1)}},I=E=>{E.preventDefault();const M=i.getBoundingClientRect(),se=E.clientX-M.left,ne=E.clientY-M.top,ce=E.ctrlKey||E.metaKey;if(E.deltaX===0||ce){const ae=Math.pow(ce?Mx:Ax,-E.deltaY),he=rn(o.current.scale*ae,nn,on),ke=he/o.current.scale;o.current.tx=se-(se-o.current.tx)*ke,o.current.ty=ne-(ne-o.current.ty)*ke,o.current.scale=he}else o.current.tx-=E.deltaX,o.current.ty-=E.deltaY;s()},B=E=>{const M=E.button===1,se=g&&E.button===0;!M&&!se||(E.preventDefault(),a=!0,l=E.pointerId,d=E.clientX,u=E.clientY,f=o.current.tx,p=o.current.ty,i.setPointerCapture(E.pointerId),i.style.cursor="grabbing")},re=E=>{!a||E.pointerId!==l||(o.current.tx=f+(E.clientX-d),o.current.ty=p+(E.clientY-u),s())},te=E=>{a&&E.pointerId===l&&(a=!1,i.releasePointerCapture(E.pointerId),i.style.cursor=g?"grab":"")},ve=E=>{if(E.code==="Space"&&!g){const M=E.target;if(M&&(M.tagName==="INPUT"||M.tagName==="TEXTAREA"||M.isContentEditable))return;g=!0,i.style.cursor="grab",E.preventDefault()}},me=E=>{E.code==="Space"&&(g=!1,a||(i.style.cursor=""))};return i.addEventListener("wheel",I,{passive:!1}),i.addEventListener("pointerdown",B),i.addEventListener("pointermove",re),i.addEventListener("pointerup",te),i.addEventListener("pointercancel",te),i.addEventListener("pointerdown",b,{capture:!0}),i.addEventListener("pointermove",_,{capture:!0}),i.addEventListener("pointerup",N,{capture:!0}),i.addEventListener("pointercancel",N,{capture:!0}),window.addEventListener("keydown",ve),window.addEventListener("keyup",me),s(),()=>{i.removeEventListener("wheel",I),i.removeEventListener("pointerdown",B),i.removeEventListener("pointermove",re),i.removeEventListener("pointerup",te),i.removeEventListener("pointercancel",te),i.removeEventListener("pointerdown",b,{capture:!0}),i.removeEventListener("pointermove",_,{capture:!0}),i.removeEventListener("pointerup",N,{capture:!0}),i.removeEventListener("pointercancel",N,{capture:!0}),window.removeEventListener("keydown",ve),window.removeEventListener("keyup",me)}},[]),{screenToSvg(i,a){const l=e.current;if(!l)return[i,a];const d=l.getBoundingClientRect(),u=(i-d.left-o.current.tx)/o.current.scale,f=(a-d.top-o.current.ty)/o.current.scale;return[u,f]},getViewport(){return{...o.current}},setViewport(i){i.tx!==void 0&&(o.current.tx=i.tx),i.ty!==void 0&&(o.current.ty=i.ty),i.scale!==void 0&&(o.current.scale=rn(i.scale,nn,on)),s()},subscribe(i){return r.current.add(i),()=>{r.current.delete(i)}}}}function rn(e,t,n){return e<t?t:e>n?n:e}const Tm=typeof navigator<"u"&&/Mac|iP(ad|hone|od)/.test(navigator.platform),Je=Tm?"⌘":"Ctrl+",Ox=Tm?"⇧":"Shift+",sn=[10,20,50,100,200,500,1e3,2e3,5e3,1e4],Lx=18;function Bx(e){for(const t of sn)if(t*e>=Lx)return t;return sn[sn.length-1]}function Rx(){const e=U(),t=S.useRef(null),n=S.useRef(null),o=S.useRef(null),r=Px(t,n);Nx(t,r),fx(t),S.useEffect(()=>(ho(r),()=>ho(null)),[r]),S.useEffect(()=>{const u=f=>{const p=o.current;if(!p)return;const m=Bx(f.scale)*f.scale;p.setAttribute("width",String(m)),p.setAttribute("height",String(m)),p.setAttribute("patternTransform",`translate(${f.tx} ${f.ty})`)};return u(r.getViewport()),r.subscribe(u)},[r]);const s=dp(),i=S.useCallback((u,f,p)=>{const g=x.getState(),m=g.activeTool;if(m==="wire"||m==="busbar"||m==="place"){jm();return}const h=tt(p);if(h)g.selection.includes(h)||g.setSelection([h]);else{const B=Kt(p);B&&g.selectedNode!==B&&g.setSelectedNode(B)}const y=x.getState(),v=y.selection.length>0,b=y.selectedNode!=null,_=!!y.clipboard,N=y.diagram.elements.length>0,I=[{label:e("menu.undo"),shortcut:`${Je}Z`,icon:En,onSelect:()=>x.getState().undo(),disabled:y.past.length===0},{label:e("menu.redo"),shortcut:`${Je}${Ox}Z`,icon:$n,onSelect:()=>x.getState().redo(),disabled:y.future.length===0},{type:"separator"},{label:e("menu.cut"),shortcut:`${Je}X`,icon:nr,onSelect:()=>x.getState().cutSelection(),disabled:!v},{label:e("menu.copy"),shortcut:`${Je}C`,icon:Jo,onSelect:()=>x.getState().copySelection(),disabled:!v},{label:e("menu.paste"),shortcut:`${Je}V`,icon:Zo,onSelect:()=>x.getState().pasteClipboard(),disabled:!_},{type:"separator"},{label:e("menu.rotate"),shortcut:"R",icon:tr,onSelect:()=>x.getState().rotateSelection(90),disabled:!v},{label:e("menu.mirror"),shortcut:"M",icon:Qo,onSelect:()=>x.getState().mirrorSelection(),disabled:!v},{type:"separator"},{label:e("menu.selectAll"),shortcut:`${Je}A`,icon:Ih,onSelect:()=>{const B=x.getState();B.setSelection(B.diagram.elements.map(re=>re.id))},disabled:!N},{type:"separator"},{label:e(b&&!v?"menu.disconnect":"menu.delete"),shortcut:"Del",icon:rr,destructive:!0,onSelect:()=>b&&!v?x.getState().deleteSelectedNode():x.getState().deleteSelection(),disabled:!v&&!b}];s.open(u,f,I)},[s,e]);S.useEffect(()=>{const u=t.current;if(!u)return;const f=700,p=4;let g,m=null;const h=()=>{g!==void 0&&window.clearTimeout(g),g=void 0,m=null},y=_=>{_.pointerType==="touch"&&(h(),m={pointerId:_.pointerId,x:_.clientX,y:_.clientY,target:_.target},g=window.setTimeout(()=>{const N=m;m=null,g=void 0,N&&(Sm(u,N.pointerId),i(N.x,N.y,N.target))},f))},v=_=>{if(!m||_.pointerId!==m.pointerId)return;const N=_.clientX-m.x,I=_.clientY-m.y;Math.hypot(N,I)>p&&h()},b=_=>{!m||_.pointerId!==m.pointerId||h()};return u.addEventListener("pointerdown",y),u.addEventListener("pointermove",v),u.addEventListener("pointerup",b),u.addEventListener("pointercancel",b),()=>{h(),u.removeEventListener("pointerdown",y),u.removeEventListener("pointermove",v),u.removeEventListener("pointerup",b),u.removeEventListener("pointercancel",b)}},[i]);const a=u=>{u.dataTransfer.types.includes("application/x-oneline-kind")&&(u.preventDefault(),u.dataTransfer.dropEffect="copy")},l=u=>{const f=u.dataTransfer.getData("application/x-oneline-kind");if(!f)return;u.preventDefault();const p=r.screenToSvg(u.clientX,u.clientY);ym(f,p)},d=u=>{u.preventDefault(),i(u.clientX,u.clientY,u.target)};return c.jsx("div",{ref:t,className:"ole-canvas-root absolute inset-0 overflow-hidden",onDragOver:a,onDrop:l,onContextMenu:d,children:c.jsxs("svg",{className:"ole-canvas-svg block h-full w-full",xmlns:"http://www.w3.org/2000/svg",children:[c.jsx("defs",{children:c.jsx("pattern",{ref:o,id:"ole-grid-dots",width:20,height:20,patternUnits:"userSpaceOnUse",children:c.jsx("circle",{cx:0,cy:0,r:2,fill:"var(--canvas-grid-strong)"})})}),c.jsx("rect",{width:"100%",height:"100%",fill:"url(#ole-grid-dots)"}),c.jsxs("g",{ref:n,className:"ole-viewport",children:[c.jsx(F0,{}),c.jsx(Q0,{}),c.jsx(K0,{}),c.jsx(C0,{}),c.jsx(A0,{}),c.jsx(U0,{}),c.jsx(L0,{}),c.jsx(B0,{}),c.jsx(J0,{}),c.jsx(nx,{}),c.jsx(H0,{}),c.jsx(V0,{}),c.jsx(X0,{})]})]})})}const Eo=60,Dx=.1,zx=8,Fx=8;function Hx(e,t,n){return e<t?t:e>n?n:e}function Wx(){return document.querySelector(".ole-canvas-root")}function In(){const e=Ve(),t=Wx();if(!e||!t)return!1;const n=t.getBoundingClientRect();if(n.width===0||n.height===0)return!1;const o=t.querySelectorAll("[data-element-id]");if(o.length===0)return e.setViewport({tx:n.width/2,ty:n.height/2,scale:1}),!0;let r=1/0,s=1/0,i=-1/0,a=-1/0;for(const v of o){const b=v.getBoundingClientRect();b.width===0&&b.height===0||(b.left<r&&(r=b.left),b.top<s&&(s=b.top),b.right>i&&(i=b.right),b.bottom>a&&(a=b.bottom))}if(r===1/0)return!1;const[l,d]=e.screenToSvg(r,s),[u,f]=e.screenToSvg(i,a),p=Math.max(u-l,1),g=Math.max(f-d,1),m=Hx(Math.min((n.width-Eo*2)/p,(n.height-Eo*2)/g),Dx,zx),h=(l+u)/2,y=(d+f)/2;return e.setViewport({tx:n.width/2-m*h,ty:n.height/2-m*y,scale:m}),!0}function An(){let e=Fx;const t=()=>{In()||--e>0&&requestAnimationFrame(t)};requestAnimationFrame(t)}const No=10,Gx=100;function Kx(){return typeof window>"u"||!window.matchMedia?!1:window.matchMedia("(hover: none), (pointer: coarse)").matches}function qx(){const[e,t]=S.useState(lx()),[n,o]=S.useState(!1),[r,s]=S.useState(null),i=S.useRef(null),a=S.useRef(void 0),[l]=S.useState(Kx);S.useEffect(()=>cx(m=>t(m)),[]),S.useEffect(()=>{if(window.clearTimeout(a.current),o(!1),s(null),!!e)return a.current=window.setTimeout(()=>o(!0),Gx),()=>window.clearTimeout(a.current)},[e]);const d=x(m=>e?m.diagram.elements.find(h=>h.id===e)??null:null);if(S.useLayoutEffect(()=>{if(!n||!e)return;let m=0,h=-1,y=-1;const v=()=>{const b=document.querySelector(`[data-element-id="${Yx(e)}"]`),_=i.current;if(b&&_){const N=b.getBoundingClientRect();let I=N.bottom+No;I+_.offsetHeight>window.innerHeight-4&&(I=N.top-_.offsetHeight-No);let B=N.left+N.width/2-_.offsetWidth/2;B=Math.max(4,Math.min(B,window.innerWidth-_.offsetWidth-4)),(I!==h||B!==y)&&(s({top:I,left:B}),h=I,y=B)}m=requestAnimationFrame(v)};return m=requestAnimationFrame(v),()=>cancelAnimationFrame(m)},[n,e]),l||!n||!e||!d)return null;const u=Ke[d.kind],f=d.name??d.id,p=(u==null?void 0:u.name)??d.kind,g=d.name&&d.name!==d.id;return typeof document>"u"?null:Xo.createPortal(c.jsxs("div",{ref:i,role:"tooltip",className:"ole-root ole-glass pointer-events-none fixed z-[100] flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-[11px] leading-snug shadow-md",style:{top:(r==null?void 0:r.top)??-9999,left:(r==null?void 0:r.left)??-9999,opacity:r?1:0,transition:"opacity 80ms ease-out"},children:[c.jsx("span",{className:"font-medium text-foreground",children:f}),g&&c.jsx("span",{className:"font-mono text-[10px] text-muted-foreground",children:d.id}),c.jsx("span",{className:"text-muted-foreground/80",children:"·"}),c.jsx("span",{className:"text-muted-foreground",children:p})]}),document.body)}function Yx(e){return e.replace(/(["\\])/g,"\\$1")}function Xx({width:e,children:t}){const n=e==null?"full":wx(e);return c.jsx(Em.Provider,{value:n,children:t})}function To(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Vx(...e){return t=>{let n=!1;const o=e.map(r=>{const s=To(r,t);return!n&&typeof s=="function"&&(n=!0),s});if(n)return()=>{for(let r=0;r<o.length;r++){const s=o[r];typeof s=="function"?s():To(e[r],null)}}}}var Ux=Symbol.for("react.lazy"),Dt=xe[" use ".trim().toString()];function Zx(e){return typeof e=="object"&&e!==null&&"then"in e}function Cm(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Ux&&"_payload"in e&&Zx(e._payload)}function Jx(e){const t=ey(e),n=xe.forwardRef((o,r)=>{let{children:s,...i}=o;Cm(s)&&typeof Dt=="function"&&(s=Dt(s._payload));const a=xe.Children.toArray(s),l=a.find(ny);if(l){const d=l.props.children,u=a.map(f=>f===l?xe.Children.count(d)>1?xe.Children.only(null):xe.isValidElement(d)?d.props.children:null:f);return c.jsx(t,{...i,ref:r,children:xe.isValidElement(d)?xe.cloneElement(d,void 0,u):null})}return c.jsx(t,{...i,ref:r,children:s})});return n.displayName=`${e}.Slot`,n}var Qx=Jx("Slot");function ey(e){const t=xe.forwardRef((n,o)=>{let{children:r,...s}=n;if(Cm(r)&&typeof Dt=="function"&&(r=Dt(r._payload)),xe.isValidElement(r)){const i=ry(r),a=oy(s,r.props);return r.type!==xe.Fragment&&(a.ref=o?Vx(o,i):i),xe.cloneElement(r,a)}return xe.Children.count(r)>1?xe.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var ty=Symbol("radix.slottable");function ny(e){return xe.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===ty}function oy(e,t){const n={...t};for(const o in t){const r=e[o],s=t[o];/^on[A-Z]/.test(o)?r&&s?n[o]=(...a)=>{const l=s(...a);return r(...a),l}:r&&(n[o]=r):o==="style"?n[o]={...r,...s}:o==="className"&&(n[o]=[r,s].filter(Boolean).join(" "))}return{...e,...n}}function ry(e){var o,r;let t=(o=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:o.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(r=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}const Co=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,Io=ar,sy=(e,t)=>n=>{var o;if((t==null?void 0:t.variants)==null)return Io(e,n==null?void 0:n.class,n==null?void 0:n.className);const{variants:r,defaultVariants:s}=t,i=Object.keys(r).map(d=>{const u=n==null?void 0:n[d],f=s==null?void 0:s[d];if(u===null)return null;const p=Co(u)||Co(f);return r[d][p]}),a=n&&Object.entries(n).reduce((d,u)=>{let[f,p]=u;return p===void 0||(d[f]=p),d},{}),l=t==null||(o=t.compoundVariants)===null||o===void 0?void 0:o.reduce((d,u)=>{let{class:f,className:p,...g}=u;return Object.entries(g).every(m=>{let[h,y]=m;return Array.isArray(y)?y.includes({...s,...a}[h]):{...s,...a}[h]===y})?[...d,f,p]:d},[]);return Io(e,i,l,n==null?void 0:n.class,n==null?void 0:n.className)},iy=sy("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground shadow hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),Ee=xe.forwardRef(({className:e,variant:t,size:n,asChild:o=!1,...r},s)=>{const i=o?Qx:"button";return c.jsx(i,{className:we(iy({variant:t,size:n,className:e})),ref:s,...r})});Ee.displayName="Button";const ay=350;function Ne({content:e,children:t,disabled:n,delayMs:o=ay}){const r=S.useRef(null),s=S.useRef(null),[i,a]=S.useState(!1),[l,d]=S.useState(null),u=S.useId(),f=S.useRef(void 0),p=()=>{n||(window.clearTimeout(f.current),f.current=window.setTimeout(()=>a(!0),o))},g=()=>{window.clearTimeout(f.current),a(!1)};S.useLayoutEffect(()=>{if(!i||!r.current||!s.current)return;const v=r.current.getBoundingClientRect(),b=s.current.getBoundingClientRect(),_=8;let N="top",I=v.top-b.height-_;I<4&&(N="bottom",I=v.bottom+_);let B=v.left+v.width/2-b.width/2;B=Math.max(4,Math.min(B,window.innerWidth-b.width-4)),d({top:I,left:B,side:N})},[i,e]),S.useEffect(()=>()=>window.clearTimeout(f.current),[]),S.useEffect(()=>{if(!i)return;const v=_=>{_.key==="Escape"&&a(!1)},b=()=>a(!1);return window.addEventListener("keydown",v),window.addEventListener("scroll",b,!0),window.addEventListener("resize",b),()=>{window.removeEventListener("keydown",v),window.removeEventListener("scroll",b,!0),window.removeEventListener("resize",b)}},[i]);const m=t,h=m.props,y=S.cloneElement(m,{ref:v=>{r.current=v;const b=m.ref;typeof b=="function"?b(v):b&&typeof b=="object"&&(b.current=v)},onPointerEnter:v=>{var b;(b=h.onPointerEnter)==null||b.call(h,v),p()},onPointerLeave:v=>{var b;(b=h.onPointerLeave)==null||b.call(h,v),g()},onFocus:v=>{var b;(b=h.onFocus)==null||b.call(h,v),p()},onBlur:v=>{var b;(b=h.onBlur)==null||b.call(h,v),g()},"aria-describedby":i?u:h["aria-describedby"]});return c.jsxs(c.Fragment,{children:[y,i&&typeof document<"u"&&Xo.createPortal(c.jsx("div",{ref:s,id:u,role:"tooltip","data-side":(l==null?void 0:l.side)??"top",className:"ole-root ole-glass pointer-events-none fixed z-[100] max-w-[280px] rounded-md border border-border px-2 py-1 text-[11px] leading-snug text-foreground shadow-md",style:{top:(l==null?void 0:l.top)??-9999,left:(l==null?void 0:l.left)??-9999,opacity:l?1:0,transition:"opacity 80ms ease-out"},children:e}),document.body)]})}const Ao=12,ly=56;function cy(){var v;const e=U(),t=x(b=>b.selection),n=x(b=>b.selectedNode),o=x(b=>b.selectedWire),r=x(b=>b.activeTool),s=x(b=>b.rotateSelection),i=x(b=>b.mirrorSelection),a=x(b=>b.deleteSelection),l=x(b=>b.deleteSelectedNode),d=x(b=>b.deleteSelectedWire),u=x(b=>b.resetWirePath),f=x(b=>b.internal.wireRenders),p=o!=null&&((v=f.get(o))==null?void 0:v.userEdited)===!0,g=S.useRef(null);S.useEffect(()=>{const b=g.current;if(!b)return;const _=t.length>0,N=!_&&o!=null,I=!_&&!N&&n!=null;if(!((_||N||I)&&(r==="select"||r==="pan"))){b.style.display="none";return}b.style.display="flex";let re=0,te="";const ve=()=>{let me=1/0,E=-1/0,M=1/0,se=-1/0,ne=!1;const ce=X=>{X.width===0&&X.height===0||(X.left<me&&(me=X.left),X.right>E&&(E=X.right),X.top<M&&(M=X.top),X.bottom>se&&(se=X.bottom),ne=!0)};if(_)for(const X of t){const ue=document.querySelector(`[data-element-id="${CSS.escape(X)}"]`);ue&&ce(ue.getBoundingClientRect())}else if(N&&o){const X=document.querySelector(`polyline.ole-wire[data-wire-id="${CSS.escape(o)}"]`);X&&ce(X.getBoundingClientRect())}else if(I&&n){const X=document.querySelectorAll(`polyline.ole-wire[data-node-id="${CSS.escape(n)}"]`);for(const ue of X)ce(ue.getBoundingClientRect())}if(ne){const X=(me+E)/2;let ue=M-Ao,ae="-100%";ue<ly&&(ue=se+Ao,ae="0%");const he=`translate3d(${X}px, ${ue}px, 0) translate(-50%, ${ae})`;he!==te&&(b.style.transform=he,te=he)}re=requestAnimationFrame(ve)};return re=requestAnimationFrame(ve),()=>cancelAnimationFrame(re)},[t,n,o,r]);const m=t.length===0&&o!=null,h=t.length===0&&!m&&n!=null,y=h||m;return c.jsxs("div",{ref:g,role:"toolbar","aria-label":e(m?"ctx.ariaWire":h?"ctx.ariaNode":"ctx.ariaElement"),className:"ole-glass pointer-events-auto fixed left-0 top-0 z-30 hidden items-center gap-0.5 rounded-2xl border border-border p-1 shadow-md",children:[m&&p&&o&&c.jsxs(c.Fragment,{children:[c.jsx(Ne,{content:c.jsxs("div",{className:"space-y-0.5",children:[c.jsx("div",{children:c.jsx("span",{className:"font-medium",children:e("ctx.resetWirePath")})}),c.jsx("div",{className:"text-muted-foreground",children:e("ctx.resetWirePathHint")})]}),children:c.jsx(Ee,{variant:"ghost",size:"icon",className:"size-7",onClick:()=>u(o),"aria-label":e("ctx.resetWirePath"),children:c.jsx(Ch,{})})}),c.jsx("div",{"aria-hidden":!0,className:"mx-0.5 h-4 w-px bg-border"})]}),!y&&c.jsxs(c.Fragment,{children:[c.jsx(Ne,{content:c.jsxs("div",{className:"space-y-0.5",children:[c.jsxs("div",{children:[c.jsx("span",{className:"font-medium",children:e("ctx.rotate")}),c.jsx("span",{className:"ml-1.5 text-muted-foreground",children:"R"})]}),c.jsx("div",{className:"text-muted-foreground",children:e("ctx.rotateHint")})]}),children:c.jsx(Ee,{variant:"ghost",size:"icon",className:"size-7",onClick:()=>s(90),"aria-label":e("ctx.rotate"),children:c.jsx(tr,{})})}),c.jsx(Ne,{content:c.jsxs("div",{className:"space-y-0.5",children:[c.jsxs("div",{children:[c.jsx("span",{className:"font-medium",children:e("ctx.mirror")}),c.jsx("span",{className:"ml-1.5 text-muted-foreground",children:"M"})]}),c.jsx("div",{className:"text-muted-foreground",children:e("ctx.mirrorHint")})]}),children:c.jsx(Ee,{variant:"ghost",size:"icon",className:"size-7",onClick:()=>i(),"aria-label":e("ctx.mirrorTitle"),children:c.jsx(Qo,{})})}),c.jsx("div",{"aria-hidden":!0,className:"mx-0.5 h-4 w-px bg-border"})]}),c.jsx(Ne,{content:c.jsxs("div",{className:"space-y-0.5",children:[c.jsxs("div",{children:[c.jsx("span",{className:"font-medium",children:e("ctx.delete")}),c.jsx("span",{className:"ml-1.5 text-muted-foreground",children:"Del"})]}),c.jsx("div",{className:"text-muted-foreground",children:e(m?"ctx.deleteHintWire":h?"ctx.deleteHintNode":"ctx.deleteHintElement")})]}),children:c.jsx(Ee,{variant:"ghost",size:"icon",className:"size-7 text-destructive hover:text-destructive",onClick:()=>m?d():h?l():a(),"aria-label":e("ctx.delete"),children:c.jsx(rr,{})})})]})}function Mn({open:e,onOpenChange:t,trigger:n,children:o}){const r=S.useRef(null);return S.useEffect(()=>{if(!e)return;const s=a=>{r.current&&!r.current.contains(a.target)&&t(!1)},i=a=>{a.key==="Escape"&&t(!1)};return window.addEventListener("mousedown",s),window.addEventListener("keydown",i),()=>{window.removeEventListener("mousedown",s),window.removeEventListener("keydown",i)}},[e,t]),c.jsxs("div",{ref:r,className:"relative",children:[n,e&&c.jsx("div",{role:"menu",className:"ole-glass absolute bottom-full right-0 mb-1.5 min-w-52 rounded-md border border-border p-1 shadow-md",children:o})]})}const Im="ole-panel-open";function dy(){if(typeof window>"u")return{outlineOpen:!1};try{const e=window.localStorage.getItem(Im);if(!e)return{outlineOpen:!1};const t=JSON.parse(e);return typeof t!="object"||t===null?{outlineOpen:!1}:{outlineOpen:t.outline===!0}}catch{return{outlineOpen:!1}}}function Mo(e){try{const t={outline:e.outlineOpen};window.localStorage.setItem(Im,JSON.stringify(t))}catch{}}const vt=zt((e,t)=>({...dy(),setOutlineOpen:n=>{e({outlineOpen:n}),Mo(t())},toggleOutline:()=>{e(n=>({outlineOpen:!n.outlineOpen})),Mo(t())}})),At=[.1,.25,.5,.75,1,1.25,1.5,2,3,4,6,8],Am=.1,Mm=8,Pm="ole-grid";function uy(){try{const e=window.localStorage.getItem(Pm);return e==null?!0:e==="1"}catch{return!0}}function fy(e){try{window.localStorage.setItem(Pm,e?"1":"0")}catch{}}function my(e,t,n){return e<t?t:e>n?n:e}function Om(){return document.querySelector(".ole-canvas-root")}function Pn(e){const t=Ve(),n=Om();if(!t||!n)return;const o=n.getBoundingClientRect(),r=o.width/2,s=o.height/2,i=t.getViewport(),a=my(e,Am,Mm),l=a/i.scale;t.setViewport({tx:r-(r-i.tx)*l,ty:s-(s-i.ty)*l,scale:a})}function hy(){const e=Ve();if(!e)return;const t=e.getViewport().scale,n=At.find(o=>o>t+1e-6)??Mm;Pn(n)}function py(){const e=Ve();if(!e)return;const t=e.getViewport().scale;let n=Am;for(let o=At.length-1;o>=0;o--)if(At[o]<t-1e-6){n=At[o];break}Pn(n)}const gy={off:"id",id:"all",all:"off"};function xy(){var o;const e=x.getState(),t=((o=e.diagram.meta)==null?void 0:o.labelMode)??"all",n=gy[t];e.dispatch(r=>{const s={...r.meta??{},labelMode:n};return{...r,meta:s}})}function Lm(){const[e,t]=S.useState(()=>uy());return S.useEffect(()=>{const n=Om();n==null||n.classList.toggle("hide-grid",!e),fy(e)},[e]),S.useEffect(()=>{const n=o=>{if(o.metaKey||o.ctrlKey||o.altKey||o.key!=="g"&&o.key!=="G")return;const r=o.target;r&&(r.tagName==="INPUT"||r.tagName==="TEXTAREA"||r.isContentEditable)||(o.preventDefault(),t(s=>!s))};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[]),[e,t]}function Bm(){const e=U();return c.jsx(Ne,{content:c.jsxs("div",{className:"space-y-0.5",children:[c.jsx("div",{className:"font-medium",children:e("view.zoomOut")}),c.jsx("div",{className:"text-muted-foreground",children:e("view.zoomOutHint")})]}),children:c.jsx(Ee,{variant:"ghost",size:"icon",onClick:py,"aria-label":e("view.zoomOut"),children:c.jsx(jn,{})})})}function Rm(){const e=U();return c.jsx(Ne,{content:c.jsxs("div",{className:"space-y-0.5",children:[c.jsx("div",{className:"font-medium",children:e("view.zoomIn")}),c.jsx("div",{className:"text-muted-foreground",children:e("view.zoomInHint")})]}),children:c.jsx(Ee,{variant:"ghost",size:"icon",onClick:hy,"aria-label":e("view.zoomIn"),children:c.jsx(Nh,{})})})}function Dm(){const e=U(),[t,n]=S.useState(Cx);return S.useEffect(()=>Ix(n),[]),c.jsx(Ne,{content:c.jsxs("div",{className:"space-y-0.5",children:[c.jsx("div",{className:"font-medium",children:e("view.reset")}),c.jsx("div",{className:"text-muted-foreground",children:e("view.current",{z:Math.round(t*100)})})]}),children:c.jsxs("button",{type:"button",onClick:()=>Pn(1),className:"min-w-12 rounded-md px-2 py-1 text-center text-xs tabular-nums text-muted-foreground hover:bg-accent hover:text-accent-foreground","aria-label":e("view.reset"),children:[Math.round(t*100),"%"]})})}function zm(){const e=U();return c.jsx(Ne,{content:c.jsxs("div",{className:"space-y-0.5",children:[c.jsx("div",{className:"font-medium",children:e("view.fit")}),c.jsx("div",{className:"text-muted-foreground",children:e("view.fitHint")})]}),children:c.jsx(Ee,{variant:"ghost",size:"icon",onClick:In,"aria-label":e("view.fit"),children:c.jsx(jh,{})})})}function Fm({grid:e,setGrid:t}){const n=U();return c.jsx(Ne,{content:c.jsxs("div",{className:"space-y-0.5",children:[c.jsxs("div",{children:[c.jsx("span",{className:"font-medium",children:n(e?"view.gridHide":"view.gridShow")}),c.jsx("span",{className:"ml-1.5 text-muted-foreground",children:n("view.gridHotkey")})]}),c.jsx("div",{className:"text-muted-foreground",children:n(e?"view.gridHideHint":"view.gridShowHint")})]}),children:c.jsx(Ee,{variant:"ghost",size:"icon",onClick:()=>t(o=>!o),"aria-label":n(e?"view.gridHideAria":"view.gridShowAria"),"aria-pressed":e,className:we(!e&&"text-muted-foreground/60"),children:c.jsx(_h,{})})})}function Hm(){const e=U(),t=x(n=>{var o;return((o=n.diagram.meta)==null?void 0:o.labelMode)??"all"});return c.jsx(Ne,{content:c.jsxs("div",{className:"space-y-0.5",children:[c.jsx("div",{className:"font-medium",children:e(t==="off"?"view.labelOff":t==="id"?"view.labelId":"view.labelAll")}),c.jsx("div",{className:"text-muted-foreground",children:e("view.labelHint")})]}),children:c.jsx(Ee,{variant:"ghost",size:"icon",onClick:xy,"aria-label":e("view.label"),"aria-pressed":t!=="off",className:we(t==="off"&&"text-muted-foreground/60"),children:c.jsx(sr,{})})})}function yy({stacked:e}={}){const t=U(),[n,o]=S.useState(!1),[r,s]=Lm(),i=c.jsxs("div",{className:"space-y-0.5",children:[c.jsx("div",{className:"font-medium",children:t("view.menu")}),c.jsx("div",{className:"text-muted-foreground",children:t("view.menuHint")})]}),a=e?c.jsx(Ne,{content:i,children:c.jsxs("button",{type:"button",onClick:()=>o(l=>!l),"aria-label":t("view.menu"),"aria-pressed":n,className:we("flex h-12 w-12 flex-col items-center justify-center gap-0.5 rounded-md text-[10px] font-medium leading-tight transition-colors",n?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-accent hover:text-accent-foreground"),children:[c.jsx(cn,{className:"size-4"}),c.jsx("span",{className:"max-w-full truncate",children:t("view.menu")})]})}):c.jsx(Ne,{content:i,children:c.jsx(Ee,{variant:"ghost",size:"icon",onClick:()=>o(l=>!l),"aria-label":t("view.menu"),"aria-pressed":n,children:c.jsx(cn,{})})});return c.jsx(Mn,{open:n,onOpenChange:o,trigger:a,children:c.jsxs("div",{className:"flex flex-col gap-0.5",children:[c.jsx(Dm,{}),c.jsxs("div",{className:"flex items-center gap-0.5",children:[c.jsx(Bm,{}),c.jsx(Rm,{})]}),c.jsx("div",{"aria-hidden":!0,className:"my-1 h-px bg-border"}),c.jsxs("div",{className:"flex items-center gap-0.5",children:[c.jsx(zm,{}),c.jsx(Fm,{grid:r,setGrid:s}),c.jsx(Hm,{})]})]})})}function by(){const e=qe();return Ie(e,"dense")?null:c.jsx(wy,{tier:e})}function wy({tier:e}){const t=Ie(e,"tight"),[n,o]=Lm();return c.jsx("div",{className:"absolute z-20",style:{bottom:"calc(0.75rem + var(--ole-bottom-inset, 0px))",right:"calc(0.75rem + env(safe-area-inset-right, 0px))"},children:c.jsxs("div",{className:"ole-glass flex items-center gap-0.5 rounded-2xl border border-border p-1.5 shadow-sm",children:[c.jsx(Bm,{}),!t&&c.jsx(Dm,{}),c.jsx(Rm,{}),c.jsx("div",{"aria-hidden":!0,className:"mx-1 h-4 w-px bg-border"}),c.jsx(zm,{}),c.jsx(Fm,{grid:n,setGrid:o}),c.jsx(Hm,{})]})})}const Po=[{id:"select",labelKey:"tool.select",hotkey:"V",descriptionKey:"tool.selectHint",icon:$h,switchTo:"select",iconOnly:!0},{id:"pan",labelKey:"tool.pan",hotkey:"H",descriptionKey:"tool.panHint",icon:Sh,switchTo:"pan",groupBreakAfter:!0,iconOnly:!0},{id:"busbar",labelKey:"tool.bus",hotkey:"B",descriptionKey:"tool.busHint",icon:jn,switchTo:"busbar"},{id:"place",labelKey:"tool.place",hotkey:"P",descriptionKey:"tool.placeHint",icon:or,switchTo:"place"},{id:"wire",labelKey:"tool.wire",hotkey:"W",descriptionKey:"tool.wireHint",icon:Uo,switchTo:"wire"},{id:"text",labelKey:"tool.text",hotkey:"T",descriptionKey:"tool.textHint",icon:sr,switchTo:"text",iconOnly:!0}];function vy(){const e=U(),t=x(u=>u.activeTool),n=x(u=>u.placeKind),o=x(u=>u.placeFromTerminal),r=x(u=>u.wireFromTerminal),s=x(u=>u.busbarDrawStart),i=x(u=>u.selection.length>0||u.selectedNode!=null);let a=null,l=!1;switch(t){case"select":a=e(i?"mode.selectWithSel":"mode.selectEmpty"),i&&(l=!0);break;case"pan":a=e("mode.pan");break;case"wire":a=e(r?"mode.wireDragging":"mode.wireInit"),l=!0;break;case"busbar":a=e(s?"mode.busDragging":"mode.busInit"),l=!0;break;case"place":n?o?a=e("mode.placeFromTerm"):a=e("mode.placeNormal"):a=e("mode.placeNoKind"),l=!0;break;case"text":a=e("mode.text"),l=!0;break}if(!a)return null;const d=e(t==="select"?"mode.escSelect":"mode.escOther");return c.jsxs("div",{className:"ole-glass pointer-events-none flex items-center gap-2 rounded-full border border-border px-3 py-1 text-xs text-muted-foreground shadow-sm",children:[c.jsx("span",{children:a}),l&&c.jsxs("span",{className:"text-muted-foreground/70",children:["· ",d]})]})}function ky(){const e=U(),t=x(m=>m.activeTool),n=x(m=>m.placeKind),o=x(m=>m.setActiveTool),r=x(m=>m.past.length),s=x(m=>m.future.length),i=x(m=>m.undo),a=x(m=>m.redo),l=qe(),d=Ie(l,"tight"),u=!Ie(l,"dense"),f=Ie(l,"dense"),p=f?Po.filter(m=>m.id!=="select"&&m.id!=="text"):Po,g=m=>t===m.switchTo;return c.jsxs("div",{className:"absolute left-1/2 z-20 flex -translate-x-1/2 flex-col items-center gap-1.5",style:{bottom:"calc(0.75rem + var(--ole-bottom-inset, 0px))"},children:[u&&c.jsx(vy,{}),c.jsxs("div",{className:we("ole-glass flex flex-row items-center rounded-2xl border border-border shadow-sm",f?"gap-0.5 p-1":"gap-0.5 p-1.5"),children:[f&&c.jsx(_y,{stacked:!0}),p.map(m=>{const h=m.icon,y=g(m),v=m.id==="place"&&y&&n==null?e("tool.placeNoKindTooltip"):e(m.descriptionKey);return c.jsxs(S.Fragment,{children:[c.jsx(et,{icon:h,label:e(m.labelKey),hotkey:m.hotkey,active:y,iconOnly:!f&&(m.iconOnly||d),stacked:f,description:v,onClick:()=>{o(m.switchTo,{placeKind:m.presetPlaceKind!==void 0?m.presetPlaceKind:void 0})}}),m.groupBreakAfter&&!f&&c.jsx("div",{"aria-hidden":!0,className:"mx-1 h-5 w-px bg-border"})]},m.id)}),!f&&c.jsx("div",{"aria-hidden":!0,className:"mx-1 h-5 w-px bg-border"}),f?c.jsx(jy,{stacked:!0}):c.jsxs(c.Fragment,{children:[c.jsx(et,{icon:En,label:e("tool.undo"),hotkey:"⌘Z",description:e("tool.undoHint"),iconOnly:!0,disabled:r===0,onClick:i}),c.jsx(et,{icon:$n,label:e("tool.redo"),hotkey:"⌘⇧Z",description:e("tool.redoHint"),iconOnly:!0,disabled:s===0,onClick:a}),c.jsx("div",{"aria-hidden":!0,className:"mx-1 h-5 w-px bg-border"}),c.jsx(Sy,{iconOnly:d})]}),f&&c.jsx(yy,{stacked:!0})]})]})}function _y({stacked:e}){const t=U(),n=vt(r=>r.outlineOpen),o=vt(r=>r.toggleOutline);return c.jsx(et,{icon:er,label:t("outline.title"),active:n,iconOnly:!0,stacked:e,onClick:o})}function et({icon:e,label:t,hotkey:n,active:o,disabled:r,iconOnly:s,stacked:i,onClick:a,description:l}){const d=c.jsxs("div",{className:"space-y-0.5",children:[c.jsxs("div",{children:[c.jsx("span",{className:"font-medium",children:t}),n&&c.jsx("span",{className:"ml-1.5 text-muted-foreground",children:n})]}),l&&c.jsx("div",{className:"text-muted-foreground",children:l})]});return c.jsx(Ne,{content:d,disabled:r,children:c.jsxs("button",{type:"button",onClick:a,disabled:r,"aria-label":t,"aria-pressed":o,className:we("rounded-md font-medium transition-colors",i?"flex h-12 w-12 flex-col items-center justify-center gap-0.5 text-[10px] leading-tight":"flex h-9 items-center gap-1.5 text-xs",!i&&(s?"w-9 justify-center":"px-2.5"),o?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-accent hover:text-accent-foreground",r&&"pointer-events-none opacity-40"),children:[c.jsxs("span",{className:"relative inline-flex shrink-0",children:[c.jsx(e,{className:"size-4"}),n&&!i&&c.jsx("span",{"aria-hidden":!0,className:we("pointer-events-none absolute -right-1.5 -top-1.5 rounded-sm px-1 font-mono text-[8px] leading-[1.1]",o?"bg-primary-foreground/20 text-primary-foreground/85":"bg-foreground/10 text-muted-foreground"),children:n})]}),i?c.jsx("span",{className:"max-w-full truncate",children:t}):!s&&c.jsx("span",{children:t})]})})}function Wm(){const e=x(r=>r.diagram.elements),t=x(r=>r.diagram.layout),n=x(r=>r.selection),o=t??{};return{hasAnyElement:e.length>0,hasArrangedAny:Object.keys(o).length>0,hasGapsAll:e.some(r=>!o[r.id]),hasSelection:n.length>0,selectionHasArranged:n.some(r=>!!o[r]),selectionHasGaps:n.some(r=>!o[r])}}function Sy({iconOnly:e}){const t=U(),[n,o]=S.useState(!1),r=Wm(),s=i=>()=>{o(!1),i()};return c.jsxs(Mn,{open:n,onOpenChange:o,trigger:c.jsx(et,{icon:pt,label:t("layout.label"),description:t("layout.hint"),active:n,iconOnly:e,onClick:()=>o(i=>!i)}),children:[c.jsx($e,{onClick:s(()=>x.getState().autoArrangeAll()),icon:c.jsx(pt,{}),disabled:!r.hasAnyElement||!r.hasArrangedAny,children:t("layout.allAuto")}),c.jsx($e,{onClick:s(()=>x.getState().autoArrangeSelection()),icon:c.jsx(pt,{}),disabled:!r.hasSelection||!r.selectionHasArranged,children:t("layout.selAuto")}),c.jsx("div",{"aria-hidden":!0,className:"my-1 h-px bg-border"}),c.jsx($e,{onClick:s(()=>x.getState().fillUnplacedAll()),icon:c.jsx(Mt,{}),disabled:!r.hasGapsAll,children:t("layout.allFill")}),c.jsx($e,{onClick:s(()=>x.getState().fillUnplacedSelection()),icon:c.jsx(Mt,{}),disabled:!r.hasSelection||!r.selectionHasGaps,children:t("layout.selFill")})]})}function jy({stacked:e}){const t=U(),[n,o]=S.useState(!1),r=x(p=>p.past.length),s=x(p=>p.future.length),i=x(p=>p.undo),a=x(p=>p.redo),l=x(p=>p.selection.length>0),d=x(p=>p.clipboard!=null),u=Wm(),f=p=>()=>{o(!1),p()};return c.jsxs(Mn,{open:n,onOpenChange:o,trigger:c.jsx(et,{icon:cn,label:t("tool.more"),description:t("tool.moreHint"),active:n,iconOnly:!0,stacked:e,onClick:()=>o(p=>!p)}),children:[c.jsx($e,{onClick:f(i),icon:c.jsx(En,{}),disabled:r===0,children:t("tool.undo")}),c.jsx($e,{onClick:f(a),icon:c.jsx($n,{}),disabled:s===0,children:t("tool.redo")}),c.jsx("div",{"aria-hidden":!0,className:"my-1 h-px bg-border"}),c.jsx($e,{onClick:f(()=>x.getState().cutSelection()),icon:c.jsx(nr,{}),disabled:!l,children:t("menu.cut")}),c.jsx($e,{onClick:f(()=>x.getState().copySelection()),icon:c.jsx(Jo,{}),disabled:!l,children:t("menu.copy")}),c.jsx($e,{onClick:f(()=>x.getState().pasteClipboard()),icon:c.jsx(Zo,{}),disabled:!d,children:t("menu.paste")}),c.jsx("div",{"aria-hidden":!0,className:"my-1 h-px bg-border"}),c.jsx($e,{onClick:f(()=>x.getState().autoArrangeAll()),icon:c.jsx(pt,{}),disabled:!u.hasAnyElement||!u.hasArrangedAny,children:t("layout.allAuto")}),c.jsx($e,{onClick:f(()=>x.getState().autoArrangeSelection()),icon:c.jsx(pt,{}),disabled:!u.hasSelection||!u.selectionHasArranged,children:t("layout.selAuto")}),c.jsx($e,{onClick:f(()=>x.getState().fillUnplacedAll()),icon:c.jsx(Mt,{}),disabled:!u.hasGapsAll,children:t("layout.allFill")}),c.jsx($e,{onClick:f(()=>x.getState().fillUnplacedSelection()),icon:c.jsx(Mt,{}),disabled:!u.hasSelection||!u.selectionHasGaps,children:t("layout.selFill")})]})}function $e({children:e,icon:t,onClick:n,disabled:o}){return c.jsxs("button",{type:"button",role:"menuitem",disabled:o,onClick:n,className:we("flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent hover:text-accent-foreground [&>svg]:size-4",o&&"pointer-events-none text-muted-foreground opacity-60 hover:bg-transparent"),children:[t,c.jsx("span",{className:"flex-1",children:e})]})}function $y(){const e=vt(r=>r.outlineOpen),t=vt(r=>r.setOutlineOpen),n=qe();return Ie(n,"dense")?e?c.jsx("div",{className:"absolute z-10",style:{left:"calc(0.75rem + var(--ole-left-inset, 0px))",right:"calc(0.75rem + var(--ole-right-inset, 0px))",bottom:"calc(4rem + var(--ole-bottom-inset, 0px) + 0.75rem)"},children:c.jsx(Oo,{onClose:()=>t(!1),sheet:!0})}):null:c.jsx("div",{className:"absolute z-10 flex flex-col items-start",style:{bottom:"calc(0.75rem + var(--ole-bottom-inset, 0px))",left:"calc(0.75rem + var(--ole-left-inset, 0px))",maxHeight:"calc(100% - 1.5rem)"},children:e?c.jsx(Oo,{onClose:()=>t(!1)}):c.jsx(Ey,{onClick:()=>t(!0)})})}function Ey({onClick:e}){const t=U(),n=qe(),o=Ie(n,"compact");return c.jsxs("button",{type:"button",onClick:e,"aria-label":t("outline.title"),title:t("outline.title"),className:we("ole-glass flex h-12 items-center rounded-2xl border border-border text-muted-foreground shadow-sm transition-colors hover:bg-accent hover:text-accent-foreground",o?"w-12 justify-center":"gap-2 px-3"),children:[c.jsx(er,{className:"size-4 shrink-0"}),!o&&c.jsx("span",{className:"text-xs font-medium",children:t("outline.title")})]})}function Oo({onClose:e,sheet:t}){const n=U(),o=x(d=>d.diagram.elements),r=x(d=>d.activeTool==="place"),s=qe(),i=Ie(s,"compact"),a=Ie(s,"dense"),l=t?"min(50vh, calc(100vh - 9rem))":r?"min(40vh, calc(100vh - 200px))":"min(70vh, calc(100vh - 100px))";return c.jsxs("aside",{className:we("ole-glass flex flex-col overflow-hidden rounded-2xl border border-border shadow-sm",t?"w-full":i?"w-52":"w-64"),style:{height:l},children:[c.jsxs("button",{type:"button",onClick:e,"aria-label":n("outline.collapseAria"),title:n("outline.collapse"),className:"flex items-center gap-1.5 border-b border-border/40 px-3 py-2 text-left transition-colors hover:bg-muted/40",children:[c.jsx("span",{className:"flex-1 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:n("outline.title")}),!a&&c.jsx(Ty,{children:o.length}),c.jsx(Eh,{className:"size-3.5 text-muted-foreground"})]}),c.jsx("div",{className:"flex-1 overflow-y-auto px-2 pb-2",children:o.length===0?c.jsx("p",{className:"px-2 py-2 text-xs italic text-muted-foreground",children:n("outline.empty")}):c.jsx("ul",{className:"space-y-px",children:o.map(d=>c.jsx(Ny,{element:d},d.id))})})]})}function Ny({element:e}){const t=Ke[e.kind],n=x(l=>l.selection.includes(e.id)),o=x(l=>l.setSelection),r=x(l=>l.toggleInSelection),s=qe(),i=!Ie(s,"compact"),a=l=>{l.shiftKey||l.metaKey||l.ctrlKey?r(e.id):o([e.id])};return c.jsxs("li",{className:"group flex cursor-pointer items-center gap-2 rounded-md px-2 py-1 hover:bg-accent data-[selected=true]:bg-[color-mix(in_oklch,var(--selection)_18%,transparent)]",title:e.note??`${e.name??e.id} (${e.kind})`,"data-element-id":e.id,"data-selected":n?"true":void 0,onClick:a,children:[c.jsx("div",{className:"flex h-4 w-6 shrink-0 items-center justify-center",children:t&&c.jsx("svg",{viewBox:t.viewBox,className:"ole-symbol size-full",preserveAspectRatio:"xMidYMid meet",dangerouslySetInnerHTML:{__html:t.svg}})}),c.jsx("span",{className:"flex-1 truncate text-xs text-foreground/90 group-hover:text-accent-foreground",children:e.name??e.id}),i&&c.jsx("span",{className:"font-mono text-[10px] text-muted-foreground/80",children:e.id})]})}function Ty({children:e}){return c.jsx("span",{className:"rounded bg-muted/50 px-1.5 py-0.5 font-mono text-[10px] tabular-nums text-muted-foreground/80",children:e})}const Cy={"arc-suppression-coil.name":"消弧线圈","arrester.name":"避雷器 (FBL)","async-motor.name":"异步电动机","autotransformer.name":"自耦变压器","battery.name":"电池储能","breaker.name":"断路器 (QF)","busbar.name":"母线段","converter-bidir.name":"双向变流器 (PCS)","ct.name":"电流互感器 (CT)","disconnector.name":"隔离开关 (QS)","earth.name":"接地","earthing-switch.name":"接地刀闸 (QE)","fuse.name":"熔断器 (FU)","generator.name":"发电机 (G)","grid-source.name":"系统电源","grounding-transformer.name":"接地变 (Z形)","inverter.name":"逆变器 (DC→AC)","load-switch.name":"负荷开关","load.name":"负荷","ngr.name":"中性点电阻 (NGR)","pt.name":"电压互感器 (PT)","pv.name":"光伏组件","rectifier.name":"整流器 (AC→DC)","series-reactor.name":"串联电抗器","shunt-capacitor.name":"并联电容器","shunt-reactor.name":"并联电抗器","sync-motor.name":"同步电动机","transformer-2w.name":"双绕组变压器","transformer-3w.name":"三绕组变压器","wind-turbine.name":"风力发电机","gfci-breaker.name":"GFCI 断路器 (RCBO)","rcd.name":"剩余电流装置 (RCD)","recloser.name":"重合闸 (Recloser)","energy-meter.name":"电能表 (Wh)","voltmeter.name":"电压表 (V)","ammeter.name":"电流表 (A)","wattmeter.name":"功率表 (W)","frequency-meter.name":"频率表 (Hz)","contactor.name":"接触器 (KM)","motor-starter.name":"电机启动器","thermal-overload.name":"热过载继电器","vfd.name":"变频器 (VFD)","soft-starter.name":"软启动器","transfer-switch.name":"切换开关 (ATS)","dc-disconnector.name":"直流隔离开关","dc-combiner.name":"直流汇流箱","ev-charger.name":"EV 充电桩","arc-suppression-coil.desc":"中性点谐振接地:电感线圈连接到地","busbar.desc":"可拉伸单母线段,多设备挂接","converter-bidir.desc":"储能变流器:双向 AC ↔ DC","earthing-switch.desc":"隔离开关 + 接地连接,单端口","grid-source.desc":"无穷大母线 / 外部电网","grounding-transformer.desc":"星-曲折接线变压器,中性点接地用","load.desc":"抽象负荷(电流流出箭头)","ngr.desc":"小电阻接地:连接变压器中性点到地","series-reactor.desc":"与并联电抗器同符号;通过用法区分","wind-turbine.desc":"风机:发电机 + 三叶轮标记","gfci-breaker.desc":"剩余电流断路器带过流保护 (UL943 / IEC 61009)。北美 GFCI / 欧洲 RCBO。","rcd.desc":"不带过流保护的剩余电流断路器 (IEC 61008)。","recloser.desc":"中压自动重合闸开关。","energy-meter.desc":"有功电能表 (kWh) — 服务入口 / 子表。","contactor.desc":"主回路接触器, 通常配热继电器和电机使用。","motor-starter.desc":"电机启动器 (IEC 60617 通用符号)。","thermal-overload.desc":"电机热过载保护继电器, 通常串接在接触器和电机之间。","vfd.desc":"Variable Frequency Drive — 异步电动机调速。","soft-starter.desc":"电机软启动器 (晶闸管降压启动)。","transfer-switch.desc":"双源切换开关 (Automatic / Manual Transfer Switch)。两个电源输入 + 一个负荷输出, 互锁不并联。","dc-disconnector.desc":"DC 隔离开关 — 光伏组串 / 储能 直流侧隔离。","dc-combiner.desc":"光伏组串汇流箱 (4 路输入示例)。","ev-charger.desc":"电动汽车充电站 / 充电桩。","breaker.state.open":"断开","disconnector.state.open":"断开","earthing-switch.state.open":"断开","fuse.state.blown":"熔断","load-switch.state.open":"断开","gfci-breaker.state.open":"断开","rcd.state.open":"断开","recloser.state.open":"断开","contactor.state.open":"断开","thermal-overload.state.tripped":"动作","transfer-switch.state.position":"位置 (normal/emergency/off)","dc-disconnector.state.open":"断开","battery.param.E":"容量","busbar.param.Un":"额定电压","converter-bidir.param.S":"容量","load.param.P":"有功功率","load.param.cosphi":"功率因数","ngr.param.R":"电阻","shunt-capacitor.param.Q":"无功容量","shunt-capacitor.param.stages":"分组数","transformer-2w.param.S":"容量","transformer-2w.param.ratio":"变比","gfci-breaker.param.In":"额定电流","gfci-breaker.param.IDn":"剩余动作电流","rcd.param.IDn":"剩余动作电流"},Iy={"arc-suppression-coil.name":"Arc-suppression coil","arrester.name":"Surge arrester (FBL)","async-motor.name":"Asynchronous motor","autotransformer.name":"Autotransformer","battery.name":"Battery storage","breaker.name":"Circuit breaker (QF)","busbar.name":"Busbar segment","converter-bidir.name":"Bidirectional converter (PCS)","ct.name":"Current transformer (CT)","disconnector.name":"Disconnector (QS)","earth.name":"Earth","earthing-switch.name":"Earthing switch (QE)","fuse.name":"Fuse (FU)","generator.name":"Generator (G)","grid-source.name":"Grid source","grounding-transformer.name":"Grounding transformer (zig-zag)","inverter.name":"Inverter (DC→AC)","load-switch.name":"Load break switch","load.name":"Load","ngr.name":"Neutral grounding resistor (NGR)","pt.name":"Voltage transformer (PT)","pv.name":"PV module","rectifier.name":"Rectifier (AC→DC)","series-reactor.name":"Series reactor","shunt-capacitor.name":"Shunt capacitor","shunt-reactor.name":"Shunt reactor","sync-motor.name":"Synchronous motor","transformer-2w.name":"Two-winding transformer","transformer-3w.name":"Three-winding transformer","wind-turbine.name":"Wind turbine","gfci-breaker.name":"GFCI breaker (RCBO)","rcd.name":"Residual current device (RCD)","recloser.name":"Recloser","energy-meter.name":"Energy meter (Wh)","voltmeter.name":"Voltmeter (V)","ammeter.name":"Ammeter (A)","wattmeter.name":"Wattmeter (W)","frequency-meter.name":"Frequency meter (Hz)","contactor.name":"Contactor (KM)","motor-starter.name":"Motor starter","thermal-overload.name":"Thermal overload relay","vfd.name":"Variable frequency drive (VFD)","soft-starter.name":"Soft starter","transfer-switch.name":"Transfer switch (ATS)","dc-disconnector.name":"DC disconnector","dc-combiner.name":"DC combiner box","ev-charger.name":"EV charger","arc-suppression-coil.desc":"Resonant neutral grounding: inductor to earth","busbar.desc":"Stretchable single-bus segment with multiple taps","converter-bidir.desc":"Storage converter: bidirectional AC ↔ DC","earthing-switch.desc":"Disconnector + earth connection, single port","grid-source.desc":"Infinite bus / external grid","grounding-transformer.desc":"Wye-zigzag transformer for neutral grounding","load.desc":"Abstract load (current-out arrow)","ngr.desc":"Low-resistance grounding: transformer neutral to earth","series-reactor.desc":"Same symbol as shunt reactor; distinguished by usage","wind-turbine.desc":"Wind turbine: generator + three-blade rotor mark","gfci-breaker.desc":"Residual-current breaker with overcurrent (UL943 / IEC 61009). NA GFCI / EU RCBO.","rcd.desc":"Residual-current breaker without overcurrent (IEC 61008).","recloser.desc":"Medium-voltage automatic recloser.","energy-meter.desc":"Active energy meter (kWh) — service entrance / submeter.","contactor.desc":"Main-circuit contactor; typically used with a thermal overload and a motor.","motor-starter.desc":"Motor starter (IEC 60617 general symbol).","thermal-overload.desc":"Motor thermal-overload relay; sits between the contactor and the motor.","vfd.desc":"Variable Frequency Drive for induction motor speed control.","soft-starter.desc":"Motor soft-starter (thyristor-based reduced-voltage starting).","transfer-switch.desc":"Two-source transfer switch (ATS / manual). Two source inputs + one load output, mechanically interlocked.","dc-disconnector.desc":"DC isolating switch — PV string / battery DC-side isolation.","dc-combiner.desc":"PV string combiner box (4-input example).","ev-charger.desc":"Electric vehicle charging station.","breaker.state.open":"Open","disconnector.state.open":"Open","earthing-switch.state.open":"Open","fuse.state.blown":"Blown","load-switch.state.open":"Open","gfci-breaker.state.open":"Open","rcd.state.open":"Open","recloser.state.open":"Open","contactor.state.open":"Open","thermal-overload.state.tripped":"Tripped","transfer-switch.state.position":"Position (normal/emergency/off)","dc-disconnector.state.open":"Open","battery.param.E":"Capacity","busbar.param.Un":"Rated voltage","converter-bidir.param.S":"Capacity","load.param.P":"Active power","load.param.cosphi":"Power factor","ngr.param.R":"Resistance","shunt-capacitor.param.Q":"Reactive capacity","shunt-capacitor.param.stages":"Stages","transformer-2w.param.S":"Capacity","transformer-2w.param.ratio":"Ratio","gfci-breaker.param.In":"Rated current","gfci-breaker.param.IDn":"Residual operating current","rcd.param.IDn":"Residual operating current"},Lo={zh:Cy,en:Iy};function Ay(e,t){return Lo[e][t]??Lo.zh[t]}function _t(){const e=kt(t=>t.locale);return(t,n)=>Ay(e,t)??n??t}const Gm="ole-palette-collapsed",My=new Set(["busbar"]),yt=(()=>{const e={};for(const[t,n]of Object.entries(h0)){const o=n.filter(r=>!My.has(r.id));o.length&&(e[t]=o)}return e})(),Py=(()=>{const e=new Set(co),t=Object.keys(yt).filter(n=>!e.has(n));return[...co.filter(n=>{var o;return(o=yt[n])==null?void 0:o.length}),...t]})();function Oy(){try{const e=window.localStorage.getItem(Gm);if(!e)return new Set;const t=JSON.parse(e);return Array.isArray(t)?new Set(t.filter(n=>typeof n=="string")):new Set}catch{return new Set}}function Ly(e){try{window.localStorage.setItem(Gm,JSON.stringify([...e]))}catch{}}function By(){const e=U(),t=x(f=>f.activeTool==="place"),n=x(f=>f.placeKind),o=x(f=>f.setActiveTool),r=vt(f=>f.outlineOpen),s=qe(),i=Ie(s,"dense"),a=68,d=i?void 0:`calc(100vh - ${a}px - ${r?"calc(40vh + 20px)":"68px"})`;if(!t||i&&n!=null)return null;const u=i?{top:`calc(${a}px + var(--ole-top-inset, 0px))`,left:"calc(0.75rem + var(--ole-left-inset, 0px))",right:"calc(0.75rem + var(--ole-right-inset, 0px))",bottom:"calc(4rem + var(--ole-bottom-inset, 0px) + 0.75rem)"}:{top:a};return c.jsx("div",{className:i?"absolute z-20":"absolute left-3 z-20",style:u,role:"dialog","aria-label":e("library.title"),children:c.jsxs("aside",{className:i?"ole-glass flex h-full w-full flex-col overflow-hidden rounded-2xl border border-border shadow-md":"ole-glass flex w-72 flex-col overflow-hidden rounded-2xl border border-border shadow-md",style:d?{maxHeight:d}:void 0,children:[c.jsxs("div",{className:"flex items-center gap-1.5 border-b border-border/40 px-3 py-2",children:[c.jsx("span",{className:"flex-1 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:e("library.title")}),c.jsx("button",{type:"button",onClick:()=>o(i?"pan":"select"),className:"rounded-md p-1 text-muted-foreground hover:bg-accent hover:text-accent-foreground","aria-label":e("common.close"),title:e("common.close"),children:c.jsx(Nn,{className:"size-3.5"})})]}),c.jsx(Ry,{sheet:i})]})})}function Ry({sheet:e}){const t=U(),n=_t(),[o,r]=S.useState(""),[s,i]=S.useState(()=>Oy()),a=S.useMemo(()=>{const f=o.trim().toLowerCase();if(!f)return yt;const p={};for(const[g,m]of Object.entries(yt)){const h=m.filter(y=>{const v=n(`${y.id}.name`,y.name).toLowerCase(),b=n(`${y.id}.desc`,y.description??"").toLowerCase();return v.includes(f)||y.id.toLowerCase().includes(f)||b.includes(f)});h.length&&(p[g]=h)}return p},[o,n]),l=o.trim().length>0,d=l&&Object.values(a).every(f=>!(f!=null&&f.length)),u=S.useCallback((f,p)=>{i(g=>{const m=new Set(g);return p?m.delete(f):m.add(f),Ly(m),m})},[]);return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"px-2 pb-1.5 pt-2",children:c.jsx(Dy,{value:o,onChange:r})}),c.jsx("div",{className:"flex-1 overflow-y-auto px-2 pb-2",children:d?c.jsx("p",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:t("library.empty")}):Py.map(f=>{var y;const p=a[f];if(!(p!=null&&p.length))return null;const g=((y=yt[f])==null?void 0:y.length)??p.length,m=t(`cat.${f}`),h=l||!s.has(f);return c.jsxs("details",{open:h,className:"group mb-2 last:mb-0",onToggle:v=>{l||u(f,v.currentTarget.open)},children:[c.jsxs("summary",{className:"flex cursor-pointer select-none items-center gap-1.5 rounded-md px-2 py-1.5 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground hover:bg-accent hover:text-accent-foreground",children:[c.jsx(xh,{className:"size-3 transition-transform [details:not([open])>summary>&]:-rotate-90"}),c.jsx("span",{className:"flex-1",children:m}),c.jsx(Fy,{children:l&&p.length!==g?`${p.length}/${g}`:g})]}),c.jsx("ul",{className:"mt-0.5 space-y-px",children:p.map(v=>c.jsx(zy,{entry:v,sheet:e},v.id))})]},f)})})]})}function Dy({value:e,onChange:t}){const n=U();return c.jsxs("div",{className:"relative",children:[c.jsx(Th,{className:"pointer-events-none absolute left-2 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground"}),c.jsx("input",{type:"text",value:e,onChange:o=>t(o.target.value),placeholder:n("library.searchPlaceholder"),className:"h-7 w-full rounded-md border border-border/60 bg-background/50 pl-7 pr-7 text-xs placeholder:text-muted-foreground focus:border-border focus:outline-none focus:ring-1 focus:ring-ring","aria-label":n("library.searchAria")}),e&&c.jsx("button",{type:"button","aria-label":n("library.clearSearch"),onClick:()=>t(""),className:"absolute right-1 top-1/2 -translate-y-1/2 rounded-sm p-0.5 text-muted-foreground hover:bg-accent hover:text-accent-foreground",children:c.jsx(Nn,{className:"size-3"})})]})}function zy({entry:e,sheet:t}){const n=U(),o=_t(),r=o(`${e.id}.name`,e.name),s=o(`${e.id}.desc`,e.description??""),i=x(f=>f.setActiveTool),a=x(f=>f.activeTool==="place"&&f.placeKind===e.id),l=x(f=>t&&f.activeTool==="place"&&f.placeKind==null&&f.lastPlaceKind===e.id),d=S.useRef(null);S.useEffect(()=>{var f;l&&((f=d.current)==null||f.scrollIntoView({block:"nearest"}))},[l]);const u=f=>{f.dataTransfer.effectAllowed="copy",f.dataTransfer.setData("application/x-oneline-kind",e.id),f.dataTransfer.setData("text/plain",e.id);const p=document.createElement("div");p.className="ole-glass",p.style.cssText=["position:absolute","top:-9999px","left:-9999px","width:64px","height:64px","display:flex","align-items:center","justify-content:center","border-radius:12px","border:1px solid var(--border)","box-shadow:0 4px 12px rgba(0,0,0,0.12)","color:var(--foreground)","padding:8px"].join(";"),p.innerHTML=`<svg class="ole-symbol" viewBox="${e.viewBox}" width="48" height="48" preserveAspectRatio="xMidYMid meet">${e.svg}</svg>`,document.body.appendChild(p),f.dataTransfer.setDragImage(p,32,32),setTimeout(()=>p.remove(),0)};return c.jsxs("li",{ref:d,className:`group flex cursor-grab items-center gap-2.5 rounded-md px-2 py-1.5 transition-colors hover:bg-accent active:cursor-grabbing ${a?"bg-accent ring-1 ring-[var(--selection)]/60":l?"ring-1 ring-[var(--selection)]/30":""}`,draggable:!0,onDragStart:u,onClick:()=>i("place",{placeKind:e.id}),"data-kind":e.id,title:s?`${r} — ${s}`:`${r} — ${n("library.itemHint")}`,children:[c.jsx("div",{className:"flex h-7 w-12 shrink-0 items-center justify-center",children:c.jsx("svg",{viewBox:e.viewBox,className:"ole-symbol size-full",preserveAspectRatio:"xMidYMid meet",dangerouslySetInnerHTML:{__html:e.svg}})}),c.jsx("span",{className:"truncate text-xs text-foreground/80 group-hover:text-accent-foreground",children:r})]})}function Fy({children:e}){return c.jsx("span",{className:"rounded bg-muted/50 px-1.5 py-0.5 font-mono text-[10px] tabular-nums text-muted-foreground/80",children:e})}const _n="ole-onboarding-dismissed";function Hy(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(_n)==="1"}catch{return!1}}function Bo(e){try{e?window.localStorage.setItem(_n,"1"):window.localStorage.removeItem(_n)}catch{}}const Ro=zt(e=>({dismissed:Hy(),dismiss:()=>{Bo(!0),e({dismissed:!0})},reset:()=>{Bo(!1),e({dismissed:!1})}}));function Wy(){const e=U(),t=Ro(o=>o.dismissed),n=Ro(o=>o.dismiss);return t?null:c.jsxs("div",{role:"dialog","aria-label":e("onboard.title"),className:"ole-glass pointer-events-none absolute left-1/2 top-1/2 z-10 w-[min(420px,calc(100vw-2rem))] -translate-x-1/2 -translate-y-1/2 rounded-2xl border border-border p-5 shadow-md",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("h2",{className:"text-sm font-semibold",children:e("onboard.title")}),c.jsx("button",{type:"button",onClick:n,"aria-label":e("onboard.dismiss"),className:"pointer-events-auto rounded-md p-1 text-muted-foreground hover:bg-accent hover:text-accent-foreground",children:c.jsx(Nn,{className:"size-3.5"})})]}),c.jsxs("ol",{className:"mt-3 space-y-2.5",children:[c.jsx(an,{n:1,icon:c.jsx(jn,{}),title:e("onboard.step1.title"),body:e("onboard.step1.body")}),c.jsx(an,{n:2,icon:c.jsx(or,{}),title:e("onboard.step2.title"),body:e("onboard.step2.body")}),c.jsx(an,{n:3,icon:c.jsx(Uo,{}),title:e("onboard.step3.title"),body:e("onboard.step3.body")})]}),c.jsx("button",{type:"button",onClick:n,className:"pointer-events-auto mt-4 w-full rounded-md bg-primary py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90",children:e("onboard.dismiss")})]})}function an({n:e,icon:t,title:n,body:o}){return c.jsxs("li",{className:"flex items-start gap-2.5",children:[c.jsx("span",{className:"mt-0.5 flex size-5 shrink-0 items-center justify-center rounded-full bg-[color-mix(in_oklch,var(--selection)_18%,transparent)] font-mono text-[10px] font-semibold tabular-nums text-[var(--selection)]","aria-hidden":!0,children:e}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium",children:[c.jsx("span",{className:"text-muted-foreground [&>svg]:size-3.5",children:t}),c.jsx("span",{children:n})]}),c.jsx("p",{className:"mt-0.5 text-[11px] leading-snug text-muted-foreground",children:o})]})]})}function Gy(){const e=U(),t=x(u=>u.selection),n=x(u=>u.diagram.elements),o=x(u=>u.diagram.buses),r=x(u=>u.selectedNode),s=x(u=>u.selectedWire);if(s)return c.jsx(Uy,{wireId:s});if(r)return c.jsx(Zy,{nodeId:r});if(t.length===0)return c.jsx("div",{className:"px-4 py-5 text-center text-xs text-muted-foreground",children:e("props.empty")});if(t.length>1)return c.jsx("div",{className:"px-4 py-5 text-center text-xs text-muted-foreground",children:e("props.multi",{n:t.length})});const i=t[0],a=(o??[]).find(u=>u.id===i);if(a)return c.jsx(Xy,{bus:a});const l=n.find(u=>u.id===i);if(!l)return null;const d=Ke[l.kind];return c.jsxs("div",{className:"flex flex-col gap-2.5 overflow-y-auto px-3 py-3 text-xs",children:[c.jsx(St,{label:e("props.name"),value:l.name??"",placeholder:l.id,onCommit:u=>x.getState().updateElement(i,{name:u.trim()===""?void 0:u.trim()})}),c.jsx(Km,{label:e("props.note"),value:l.note??"",onCommit:u=>x.getState().updateElement(i,{note:u.trim()===""?void 0:u.trim()})}),(d==null?void 0:d.state)&&d.state.length>0&&c.jsx("div",{className:"mt-1 flex flex-col gap-1.5 border-t border-border/40 pt-2.5",children:d.state.map(u=>c.jsx(Jy,{id:i,element:l,field:u},u.name))}),c.jsx(Ky,{id:i,element:l,schema:(d==null?void 0:d.params)??[]})]})}function Ky({id:e,element:t,schema:n}){const o=new Set(n.map(s=>s.name)),r=t.params?Object.entries(t.params).filter(([s])=>!o.has(s)):[];return n.length===0&&r.length===0?null:c.jsxs("div",{className:"mt-1 flex flex-col gap-1.5 border-t border-border/40 pt-2.5",children:[n.map(s=>c.jsx(qy,{id:e,element:t,field:s},s.name)),r.map(([s,i])=>c.jsx(Yy,{id:e,element:t,fieldKey:s,value:i},s))]})}function qy({id:e,element:t,field:n}){var l;const o=U(),r=_t(),s=((l=t.params)==null?void 0:l[n.name])??n.default,i=r(`${t.kind}.param.${n.name}`,n.label??n.name),a=d=>{const u={...t.params??{}};d===void 0||d===n.default?delete u[n.name]:u[n.name]=d,x.getState().updateElement(e,{params:Object.keys(u).length>0?u:void 0})};return n.type==="boolean"?c.jsx(rt,{label:i,children:c.jsx(On,{active:!!s,onClick:()=>a(!s),children:o(s?"common.yes":"common.no")})}):n.type==="number"?c.jsx(qt,{label:i,value:typeof s=="number"?s:0,unit:n.unit,onCommit:a}):c.jsx(St,{label:i,value:typeof s=="string"?s:"",unit:n.unit,onCommit:d=>a(d.trim()===""?void 0:d)})}function Yy({id:e,element:t,fieldKey:n,value:o}){const r=U(),s=i=>{const a={...t.params??{}};i===void 0?delete a[n]:a[n]=i,x.getState().updateElement(e,{params:Object.keys(a).length>0?a:void 0})};return typeof o=="boolean"?c.jsx(rt,{label:n,children:c.jsx(On,{active:o,onClick:()=>s(!o),children:r(o?"common.yes":"common.no")})}):typeof o=="number"?c.jsx(qt,{label:n,value:o,onCommit:s}):c.jsx(St,{label:n,value:o,onCommit:i=>s(i.trim()===""?void 0:i)})}function Xy({bus:e}){const t=U(),n=e.id,o=r=>{const s=r.trim();Sn(n,{name:s===""?void 0:s})};return c.jsxs("div",{className:"flex flex-col gap-2.5 overflow-y-auto px-3 py-3 text-xs",children:[c.jsx(St,{label:t("props.name"),value:e.name??"",placeholder:e.id,onCommit:o}),c.jsx(Km,{label:t("props.note"),value:e.note??"",onCommit:r=>Sn(n,{note:r.trim()===""?void 0:r.trim()})}),c.jsx(Vy,{bus:e})]})}function Vy({bus:e}){const t=(o,r)=>{const s={...e.params??{}};r===void 0||r===""?delete s[o]:s[o]=r,Sn(e.id,{params:Object.keys(s).length>0?s:void 0})},n=e.params??{};return c.jsx("div",{className:"mt-1 flex flex-col gap-1.5 border-t border-border/40 pt-2.5",children:c.jsx(qt,{label:"Un",value:typeof n.Un=="number"?n.Un:0,unit:"kV",onCommit:o=>t("Un",o)})})}function Sn(e,t){x.getState().dispatch(n=>{const o=(n.buses??[]).map(r=>r.id===e?{...r,...t}:r);return{...n,buses:o}})}function Uy({wireId:e}){const t=U(),n=x(m=>m.diagram.wires),o=x(m=>m.diagram.elements),r=x(m=>m.diagram.buses),s=x(m=>m.internal.terminalToNode),i=x(m=>m.setSelectedNode),a=(n??[]).find(m=>m.id===e);if(!a)return c.jsx("div",{className:"px-4 py-5 text-center text-xs text-muted-foreground",children:t("props.wireNotFound",{id:e})});const l=s.get(a.ends[0]),d=new Map(o.map(m=>[m.id,m])),u=new Map((r??[]).map(m=>[m.id,m])),f=m=>{if(!m.includes(".")){const _=u.get(m);return{id:m,label:(_==null?void 0:_.name)??m}}const h=m.indexOf("."),y=m.slice(0,h),v=m.slice(h+1),b=d.get(y);return{id:y,label:(b==null?void 0:b.name)??y,pin:v}},p=f(a.ends[0]),g=f(a.ends[1]);return c.jsxs("div",{className:"flex flex-col gap-3 px-3 py-3 text-xs",children:[c.jsxs("div",{className:"space-y-1",children:[c.jsx("div",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:t("props.wire")}),c.jsx("div",{className:"font-mono text-[12px]",children:a.id})]}),c.jsx("ul",{className:"space-y-0.5 border-t border-border/40 pt-2",children:[p,g].map((m,h)=>c.jsxs("li",{className:"flex cursor-pointer items-center gap-2 rounded-md px-1.5 py-1 hover:bg-accent",onClick:()=>x.getState().setSelection([m.id]),children:[c.jsx("span",{className:"flex-1 truncate font-mono text-[11px]",children:m.id}),c.jsx("span",{className:"truncate text-[10px] text-muted-foreground",children:m.label}),m.pin&&c.jsx("span",{className:"font-mono text-[10px] text-muted-foreground/80",children:m.pin})]},h))}),l&&c.jsx("button",{type:"button",className:"self-start rounded-md border border-border/60 px-2 py-1 text-[11px] text-muted-foreground hover:bg-accent",onClick:()=>i(l),children:t("props.selectWholeNode")})]})}function Zy({nodeId:e}){const t=U(),n=x(a=>a.internal.nodes.get(e)),o=x(a=>a.diagram.elements),r=x(a=>a.setSelection);if(!n)return c.jsx("div",{className:"px-4 py-5 text-center text-xs text-muted-foreground",children:t("props.nodeNotFound",{id:e})});const s=new Map;for(const a of n.terminals){const l=a.indexOf(".");if(l<0)continue;const d=a.slice(0,l),u=a.slice(l+1),f=s.get(d)??[];f.push(u),s.set(d,f)}const i=new Map(o.map(a=>[a.id,a]));return c.jsxs("div",{className:"flex flex-col gap-3 px-3 py-3 text-xs",children:[c.jsxs("div",{className:"space-y-1",children:[c.jsx("div",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:t("props.node")}),c.jsx("div",{className:"font-mono text-[12px]",children:n.id}),c.jsx("div",{className:"text-[11px] text-muted-foreground",children:t("props.nodeStats",{terminals:n.terminals.length,elements:s.size})})]}),c.jsx("ul",{className:"space-y-0.5 border-t border-border/40 pt-2",children:[...s.entries()].map(([a,l])=>{const d=i.get(a);return c.jsxs("li",{className:"flex cursor-pointer items-center gap-2 rounded-md px-1.5 py-1 hover:bg-accent",onClick:()=>r([a]),title:t("props.selectElement",{label:a}),children:[c.jsx("span",{className:"flex-1 truncate font-mono text-[11px]",children:a}),c.jsx("span",{className:"truncate text-[10px] text-muted-foreground",children:(d==null?void 0:d.name)??""}),c.jsx("span",{className:"font-mono text-[10px] text-muted-foreground/80",children:l.join(", ")})]},a)})})]})}function rt({label:e,children:t}){return c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("label",{className:"w-16 shrink-0 truncate text-[11px] text-muted-foreground",children:e}),c.jsx("div",{className:"min-w-0 flex-1",children:t})]})}function St({label:e,value:t,placeholder:n,unit:o,onCommit:r}){const[s,i]=S.useState(t),a=S.useRef(null);return S.useEffect(()=>i(t),[t]),c.jsx(rt,{label:e,children:c.jsxs("div",{className:"relative",children:[c.jsx("input",{ref:a,type:"text",value:s,placeholder:n,onChange:l=>i(l.target.value),onBlur:()=>{s!==t&&r(s)},onKeyDown:l=>{var d,u;l.key==="Enter"&&((d=a.current)==null||d.blur()),l.key==="Escape"&&(i(t),(u=a.current)==null||u.blur())},className:we("h-7 w-full rounded-md border border-border/60 bg-background/50 px-2 text-[11px] focus:border-border focus:outline-none focus:ring-1 focus:ring-ring",o&&"pr-8")}),o&&c.jsx("span",{className:"pointer-events-none absolute right-2 top-1/2 -translate-y-1/2 text-[10px] text-muted-foreground",children:o})]})})}function Km({label:e,value:t,onCommit:n}){const[o,r]=S.useState(t);return S.useEffect(()=>r(t),[t]),c.jsx(rt,{label:e,children:c.jsx("textarea",{rows:2,value:o,onChange:s=>r(s.target.value),onBlur:()=>{o!==t&&n(o)},className:"w-full resize-none rounded-md border border-border/60 bg-background/50 px-2 py-1 text-[11px] focus:border-border focus:outline-none focus:ring-1 focus:ring-ring"})})}function qt({label:e,value:t,min:n,unit:o,onCommit:r}){const[s,i]=S.useState(String(t)),a=S.useRef(null);return S.useEffect(()=>i(String(t)),[t]),c.jsx(rt,{label:e,children:c.jsxs("div",{className:"relative",children:[c.jsx("input",{ref:a,type:"number",value:s,onChange:l=>i(l.target.value),onBlur:()=>{const l=Number(s);Number.isFinite(l)&&l!==t?r(l):i(String(t))},onKeyDown:l=>{var d,u;l.key==="Enter"&&((d=a.current)==null||d.blur()),l.key==="Escape"&&(i(String(t)),(u=a.current)==null||u.blur())},min:n,className:we("h-7 w-full rounded-md border border-border/60 bg-background/50 px-2 font-mono text-[11px] tabular-nums focus:border-border focus:outline-none focus:ring-1 focus:ring-ring",o&&"pr-8")}),o&&c.jsx("span",{className:"pointer-events-none absolute right-2 top-1/2 -translate-y-1/2 text-[10px] text-muted-foreground",children:o})]})})}function On({active:e,onClick:t,children:n}){return c.jsx("button",{type:"button",onClick:t,className:we("flex h-6 w-full items-center justify-center gap-1.5 rounded border text-[10px] transition-colors",e?"border-[var(--selection)] bg-[var(--selection)]/15 text-foreground":"border-border/60 text-muted-foreground hover:bg-accent"),"aria-pressed":e,children:n})}function Jy({id:e,element:t,field:n}){var l;const o=U(),s=_t()(`${t.kind}.state.${n.name}`,n.label??n.name),i=((l=t.state)==null?void 0:l[n.name])??n.default,a=d=>{const u={...t.state??{}};d===void 0||d===n.default?delete u[n.name]:u[n.name]=d,x.getState().updateElement(e,{state:Object.keys(u).length>0?u:void 0})};return n.type==="boolean"?c.jsx(rt,{label:s,children:c.jsx(On,{active:!!i,onClick:()=>a(!i),children:o(i?"common.yes":"common.no")})}):n.type==="number"?c.jsx(qt,{label:s,value:typeof i=="number"?i:0,onCommit:a}):c.jsx(St,{label:s,value:typeof i=="string"?i:"",onCommit:d=>a(d.trim()===""?void 0:d)})}function Qy(){const e=U(),t=_t(),n=x(f=>f.selection),o=x(f=>f.selectedNode),r=x(f=>f.selectedWire),s=x(f=>f.diagram.elements),i=x(f=>f.diagram.buses),a=qe(),l=Ie(a,"dense");if(n.length===0&&!o&&!r)return null;let d=e("props.title"),u=null;if(r)d=e("props.wire");else if(o)d=e("props.node");else if(n.length===1){const f=n[0],p=(i??[]).find(g=>g.id===f);if(p)d=p.name??e("props.bus");else{const g=s.find(m=>m.id===f);if(g){const m=Ke[g.kind];d=m?t(`${m.id}.name`,m.name):g.kind}}}else u=n.length;return c.jsxs("aside",{className:we("ole-glass absolute z-10 flex flex-col overflow-hidden rounded-2xl border border-border shadow-sm",l?"w-48":"w-56"),style:{top:`calc(${l?"4.5rem":"0.75rem"} + var(--ole-top-inset, 0px))`,right:"calc(0.75rem + var(--ole-right-inset, 0px))",maxHeight:`calc(100% - ${l?"5.25rem":"1.5rem"} - var(--ole-top-inset, 0px) - var(--ole-bottom-inset, 0px) - 4.5rem)`},children:[c.jsxs("div",{className:"flex items-center gap-1.5 border-b border-border/40 px-3 py-2",children:[c.jsx("span",{className:"flex-1 truncate text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:d}),u!=null&&c.jsx("span",{className:"rounded bg-muted/50 px-1.5 py-0.5 font-mono text-[10px] tabular-nums text-muted-foreground/80",children:e("props.nSelected",{n:u})})]}),c.jsx(Gy,{})]})}function e1(){S.useEffect(()=>{const e=n=>{const o=n.target;if(!o||o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable)return;const r=o.closest("button");r&&r.closest(".ole-glass")&&n.preventDefault()},t=n=>{const o=n.target;if(!o||!o.closest(".ole-canvas-root"))return;const r=document.activeElement;!r||r===document.body||r.tagName==="INPUT"||r.tagName==="TEXTAREA"||r.isContentEditable||r.blur()};return window.addEventListener("mousedown",e),window.addEventListener("pointerdown",t,!0),()=>{window.removeEventListener("mousedown",e),window.removeEventListener("pointerdown",t,!0)}},[])}function t1(){e1();const e=S.useRef(null),t=vx(e);return c.jsx(up,{children:c.jsx("div",{ref:e,className:"relative h-full w-full overflow-hidden bg-background text-foreground",children:c.jsxs(Xx,{width:t,children:[c.jsx(Rx,{}),c.jsx($y,{}),c.jsx(Qy,{}),c.jsx(ky,{}),c.jsx(by,{}),c.jsx(cy,{}),c.jsx(By,{}),c.jsx(Wy,{}),c.jsx(qx,{})]})})})}const n1="ole-theme";function o1(){try{const e=window.localStorage.getItem(n1);return e==="light"||e==="dark"?e:null}catch{return null}}function r1(){return typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-color-scheme: dark)").matches}function s1(){return typeof window>"u"?"light":o1()??(r1()?"dark":"light")}function qm(e){typeof document>"u"||document.documentElement.classList.toggle("dark",e==="dark")}function i1({className:e,diagram:t,locale:n,theme:o}){return S.useEffect(()=>{if(!t)return;x.getState().diagram.elements.length===0&&x.getState().setDiagram(t)},[t]),S.useEffect(()=>{n&&kt.getState().setLocale(n)},[n]),S.useEffect(()=>{o&&qm(o)},[o]),S.useEffect(()=>{An()},[]),ix(),c.jsx("div",{className:`ole-root ${e??"h-full w-full"}`,children:c.jsx(t1,{})})}const Ym={"application/json":[".json"]},Xm=()=>typeof window<"u"&&typeof window.showOpenFilePicker=="function",Vm=e=>e instanceof DOMException&&e.name==="AbortError";function Do(e){let t;try{t=JSON.parse(e)}catch(o){throw new Error(be("io.parseFailed",{err:o.message}))}if(!t||typeof t!="object"||Array.isArray(t))throw new Error(be("io.notObject"));const n=t;if(n.version!=="1")throw new Error(be("io.versionMismatch",{actual:JSON.stringify(n.version)}));if(!Array.isArray(n.elements))throw new Error(be("io.elementsMissing"));return n}function a1(e){return JSON.stringify(e,null,2)+`
193
- `}async function l1(){if(Xm()){let e;try{[e]=await window.showOpenFilePicker({multiple:!1,types:[{description:be("topbar.file.fileDescription"),accept:Ym}]})}catch(n){if(Vm(n))return null;throw n}const t=await e.getFile();return{diagram:Do(await t.text()),session:{handle:e,name:t.name}}}return new Promise((e,t)=>{const n=document.createElement("input");n.type="file",n.accept=".json,application/json",n.addEventListener("change",async()=>{var r;const o=(r=n.files)==null?void 0:r[0];if(!o)return e(null);try{e({diagram:Do(await o.text()),session:{name:o.name}})}catch(s){t(s)}}),n.addEventListener("cancel",()=>e(null)),n.click()})}async function zo(e,t,n={}){const o=a1(e);if(!n.saveAs&&(t!=null&&t.handle)){const i=await t.handle.createWritable();return await i.write(o),await i.close(),t}if(Xm()){let i;try{i=await window.showSaveFilePicker({suggestedName:(t==null?void 0:t.name)??"diagram.json",types:[{description:be("topbar.file.fileDescription"),accept:Ym}]})}catch(l){if(Vm(l))return null;throw l}const a=await i.createWritable();return await a.write(o),await a.close(),{handle:i,name:i.name}}const r=URL.createObjectURL(new Blob([o],{type:"application/json"})),s=document.createElement("a");return s.href=r,s.download=(t==null?void 0:t.name)??"diagram.json",s.click(),URL.revokeObjectURL(r),t??{name:"diagram.json"}}function c1(){const e=U(),t=x(f=>f.fileSession),n=(t==null?void 0:t.name)??e("common.unnamed"),{onNew:o,onOpen:r,onSave:s,onSaveAs:i}=d1(),[a,l]=S.useState(!1),d=S.useRef(null);S.useEffect(()=>{const f=p=>{if(!(p.metaKey||p.ctrlKey))return;const g=p.key.toLowerCase();g==="o"?(p.preventDefault(),r()):g==="s"&&(p.preventDefault(),p.shiftKey?i():s())};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[r,s,i]),S.useEffect(()=>{if(!a)return;const f=g=>{d.current&&!d.current.contains(g.target)&&l(!1)},p=g=>{g.key==="Escape"&&l(!1)};return window.addEventListener("mousedown",f),window.addEventListener("keydown",p),()=>{window.removeEventListener("mousedown",f),window.removeEventListener("keydown",p)}},[a]);const u=f=>()=>{l(!1),f()};return c.jsxs("div",{ref:d,className:"relative",children:[c.jsxs(Ee,{variant:"ghost",size:"sm",className:"gap-1.5","aria-haspopup":"menu","aria-expanded":a,onClick:()=>l(f=>!f),children:[c.jsx(Wn,{}),e("topbar.file.label")]}),a&&c.jsxs("div",{role:"menu",className:"ole-glass absolute left-0 top-full mt-1.5 min-w-44 rounded-md border border-border p-1 shadow-md",children:[c.jsx("div",{className:"border-b border-border px-2 pb-1.5 pt-1 text-xs text-muted-foreground",children:n}),c.jsx(Ct,{onClick:u(o),icon:c.jsx(vh,{}),children:e("topbar.file.new")}),c.jsx(Ct,{onClick:u(r),icon:c.jsx(Wn,{}),hint:"⌘O",children:e("topbar.file.open")}),c.jsx(Ct,{onClick:u(s),icon:c.jsx(Gn,{}),hint:"⌘S",children:e("topbar.file.save")}),c.jsx(Ct,{onClick:u(i),icon:c.jsx(Gn,{}),hint:"⌘⇧S",children:e("topbar.file.saveAs")})]})]})}function Ct({children:e,icon:t,hint:n,onClick:o}){return c.jsxs("button",{type:"button",role:"menuitem",onClick:o,className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent hover:text-accent-foreground [&>svg]:size-4",children:[t,c.jsx("span",{className:"flex-1",children:e}),n&&c.jsx("span",{className:"text-xs tabular-nums text-muted-foreground",children:n})]})}function d1(){const e=U(),t=x(l=>l.loadDiagramFromFile),n=x(l=>l.setFileSession),o=x(l=>l.setDiagram);return{onNew:()=>{const{diagram:l}=x.getState();l.elements.length>0&&!confirm(e("topbar.file.newConfirm"))||(o({version:"1",elements:[]}),n(null))},onOpen:async()=>{try{const l=await l1();l&&(t(l.diagram,l.session),An())}catch(l){alert(e("topbar.file.openFailed",{err:l.message}))}},onSave:async()=>{try{const{diagram:l,fileSession:d}=x.getState(),u=await zo(l,d);u&&n(u)}catch(l){alert(e("topbar.file.saveFailed",{err:l.message}))}},onSaveAs:async()=>{try{const{diagram:l,fileSession:d}=x.getState(),u=await zo(l,d,{saveAs:!0});u&&n(u)}catch(l){alert(e("topbar.file.saveFailed",{err:l.message}))}}}}const ln="WIRES",Re="ELEMENTS",Fo="LABELS",Ho="ANNOTATIONS",Wo=32,Go=64,u1=8,f1=1.25,m1=6;function Um(e,t={}){const n=new $1(t.precision??6);n.header(t.title),n.tables([{name:ln,color:7},{name:Re,color:7},{name:Fo,color:8},{name:Ho,color:3}]),n.beginEntities();for(const r of e.wireRenders.values())r.path.length<2||n.lwpolyline(ln,r.path.map(Te),!1);for(const{geometry:r}of e.buses.values()){const{axis:s,at:i,span:a}=r,l=a/2,d=s==="x"?[i[0]-l,i[1]]:[i[0],i[1]-l],u=s==="x"?[i[0]+l,i[1]]:[i[0],i[1]+l];n.lwpolyline(ln,[d,u].map(Te),!1)}for(const r of e.elements.values()){const s=e.layout.get(r.element.id),i=r.libraryDef;!s||!i||h1(n,i.svg,s)}const o=t.labelMode??"all";if(o!=="off")for(const r of e.elements.values()){const s=e.layout.get(r.element.id);if(!s||!r.libraryDef)continue;const i=Ht(r,o);if(i.length===0)continue;const a=r.libraryDef.label??Wt(r.libraryDef),[l,d]=Gt(a,s);for(let u=0;u<i.length;u++){const[f,p]=Te([l,d+u*Ft]);n.text(Fo,[f,p],i[u],Lt,0,!1)}}for(const r of t.annotations??[]){if(!r.text)continue;const s=r.fontSize??u1,i=r.text.split(`
194
- `);for(let a=0;a<i.length;a++){const[l,d]=Te([r.at[0],r.at[1]+(a+1)*s*f1]);n.text(Ho,[l,d],i[a],s,0,!1)}}return n.endEntities(),n.toString()}async function Zm(e,t="diagram.dxf",n){const o=Um(e,n),r=URL.createObjectURL(new Blob([o],{type:"application/dxf;charset=utf-8"})),s=document.createElement("a");s.href=r,s.download=t,s.click(),URL.revokeObjectURL(r)}function h1(e,t,n){const o=`<svg xmlns="http://www.w3.org/2000/svg">${t}</svg>`,s=new DOMParser().parseFromString(o,"image/svg+xml").documentElement;if(!(!s||s.querySelector("parsererror")))for(const i of Array.from(s.children))switch(i.tagName.toLowerCase()){case"line":p1(e,i,n);break;case"polyline":Ko(e,i,n,!1);break;case"polygon":Ko(e,i,n,!0);break;case"rect":g1(e,i,n);break;case"circle":x1(e,i,n);break;case"ellipse":y1(e,i,n);break;case"path":k1(e,i,n);break;case"text":v1(e,i,n);break}}function p1(e,t,n){const o=pe(t,"x1"),r=pe(t,"y1"),s=pe(t,"x2"),i=pe(t,"y2"),a=Te(Be([o,r],n)),l=Te(Be([s,i],n));e.line(Re,a,l)}function Ko(e,t,n,o){const r=j1(t.getAttribute("points")??"");if(r.length<2)return;const s=r.map(i=>Te(Be(i,n)));e.lwpolyline(Re,s,o)}function g1(e,t,n){const o=pe(t,"x"),r=pe(t,"y"),s=pe(t,"width"),i=pe(t,"height"),l=[[o,r],[o+s,r],[o+s,r+i],[o,r+i]].map(d=>Te(Be(d,n)));e.lwpolyline(Re,l,!0)}function x1(e,t,n){const o=pe(t,"cx"),r=pe(t,"cy"),s=pe(t,"r"),i=Te(Be([o,r],n));e.circle(Re,i,s)}function y1(e,t,n){const o=pe(t,"cx"),r=pe(t,"cy"),s=pe(t,"rx"),i=pe(t,"ry");if(Math.abs(s-i)<1e-6){b1(e,o,r,s,n);return}w1(e,o,r,s,i,n)}function b1(e,t,n,o,r){const s=Te(Be([t,n],r));e.circle(Re,s,o)}function w1(e,t,n,o,r,s){const i=[];for(let a=0;a<Go;a++){const l=a/Go*Math.PI*2;i.push(Te(Be([t+o*Math.cos(l),n+r*Math.sin(l)],s)))}e.lwpolyline(Re,i,!0)}function v1(e,t,n){const o=pe(t,"x"),r=pe(t,"y"),s=parseFloat(t.getAttribute("font-size")??"")||m1,i=(t.textContent??"").trim();if(!i)return;const a=Te(Be([o,r],n));e.text(Re,a,i,s,n.rot,n.mirror)}function k1(e,t,n){const o=t.getAttribute("d")??"",r=_1(o);if(r.length===0)return;let s=null,i=[];const a=()=>{i.length>=2&&e.lwpolyline(Re,i.map(l=>Te(Be(l,n))),!1),i=[]};for(const l of r)if(l.cmd==="M")a(),s=[l.args[0],l.args[1]],i.push(s);else if(l.cmd==="A"&&s){const[d,u,,f,p,g,m]=l.args,h=S1(s,[g,m],d,u,f!==0,p!==0);if(h)for(let y=1;y<=Wo;y++){const v=h.theta1+h.delta*y/Wo;i.push([h.cx+d*Math.cos(v),h.cy+u*Math.sin(v)])}else i.push([g,m]);s=[g,m]}a()}function _1(e){const t=[],n=/([MmAa])([^MmAa]*)/g;let o;for(;(o=n.exec(e))!==null;){const r=o[1].toUpperCase(),s=o[2].trim().split(/[\s,]+/).filter(i=>i.length>0).map(Number);t.push({cmd:r,args:s})}return t}function S1(e,t,n,o,r,s){if(n<=0||o<=0)return null;const[i,a]=e,[l,d]=t;if(i===l&&a===d)return null;const u=(i-l)/2,f=(a-d)/2;let p=Math.abs(n),g=Math.abs(o);const m=p*p,h=g*g,y=u*u/m+f*f/h;if(y>1){const M=Math.sqrt(y);p*=M,g*=M}const v=r===s?-1:1,b=p*p*g*g-p*p*f*f-g*g*u*u,_=p*p*f*f+g*g*u*u,N=v*Math.sqrt(Math.max(0,b/_)),I=N*(p*f)/g,B=N*-(g*u)/p,re=I+(i+l)/2,te=B+(a+d)/2,ve=(M,se,ne,ce)=>{const X=M*ne+se*ce,ue=Math.hypot(M,se)*Math.hypot(ne,ce);let ae=Math.acos(Math.max(-1,Math.min(1,X/ue)));return M*ce-se*ne<0&&(ae=-ae),ae},me=ve(1,0,(u-I)/p,(f-B)/g);let E=ve((u-I)/p,(f-B)/g,(-u-I)/p,(-f-B)/g);return!s&&E>0?E-=2*Math.PI:s&&E<0&&(E+=2*Math.PI),{cx:re,cy:te,theta1:me,delta:E}}function Be(e,t){return Le(e,t)}function Te(e){return[e[0],-e[1]]}function pe(e,t){const n=parseFloat(e.getAttribute(t)??"");return Number.isFinite(n)?n:0}function j1(e){const t=e.trim().split(/[\s,]+/).map(Number).filter(o=>Number.isFinite(o)),n=[];for(let o=0;o+1<t.length;o+=2)n.push([t[o],t[o+1]]);return n}class $1{constructor(t){st(this,"out",[]);st(this,"precision");this.precision=t}toString(){return this.out.join("")}g(t,n){this.out.push(`${t}
191
+ */const Tn=U("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);function ar(e){var t,n,o="";if(typeof e=="string"||typeof e=="number")o+=e;else if(typeof e=="object")if(Array.isArray(e)){var r=e.length;for(t=0;t<r;t++)e[t]&&(n=ar(e[t]))&&(o&&(o+=" "),o+=n)}else for(n in e)e[n]&&(o&&(o+=" "),o+=n);return o}function lr(){for(var e,t,n=0,o="",r=arguments.length;n<r;n++)(e=arguments[n])&&(t=ar(e))&&(o&&(o+=" "),o+=t);return o}const Cn="-",Mh=e=>{const t=Oh(e),{conflictingClassGroups:n,conflictingClassGroupModifiers:o}=e;return{getClassGroupId:i=>{const a=i.split(Cn);return a[0]===""&&a.length!==1&&a.shift(),cr(a,t)||Ph(i)},getConflictingClassGroupIds:(i,a)=>{const l=n[i]||[];return a&&o[i]?[...l,...o[i]]:l}}},cr=(e,t)=>{var i;if(e.length===0)return t.classGroupId;const n=e[0],o=t.nextPart.get(n),r=o?cr(e.slice(1),o):void 0;if(r)return r;if(t.validators.length===0)return;const s=e.join(Cn);return(i=t.validators.find(({validator:a})=>a(s)))==null?void 0:i.classGroupId},Kn=/^\[(.+)\]$/,Ph=e=>{if(Kn.test(e)){const t=Kn.exec(e)[1],n=t==null?void 0:t.substring(0,t.indexOf(":"));if(n)return"arbitrary.."+n}},Oh=e=>{const{theme:t,prefix:n}=e,o={nextPart:new Map,validators:[]};return Bh(Object.entries(e.classGroups),n).forEach(([s,i])=>{un(i,o,s,t)}),o},un=(e,t,n,o)=>{e.forEach(r=>{if(typeof r=="string"){const s=r===""?t:Yn(t,r);s.classGroupId=n;return}if(typeof r=="function"){if(Lh(r)){un(r(o),t,n,o);return}t.validators.push({validator:r,classGroupId:n});return}Object.entries(r).forEach(([s,i])=>{un(i,Yn(t,s),n,o)})})},Yn=(e,t)=>{let n=e;return t.split(Cn).forEach(o=>{n.nextPart.has(o)||n.nextPart.set(o,{nextPart:new Map,validators:[]}),n=n.nextPart.get(o)}),n},Lh=e=>e.isThemeGetter,Bh=(e,t)=>t?e.map(([n,o])=>{const r=o.map(s=>typeof s=="string"?t+s:typeof s=="object"?Object.fromEntries(Object.entries(s).map(([i,a])=>[t+i,a])):s);return[n,r]}):e,Dh=e=>{if(e<1)return{get:()=>{},set:()=>{}};let t=0,n=new Map,o=new Map;const r=(s,i)=>{n.set(s,i),t++,t>e&&(t=0,o=n,n=new Map)};return{get(s){let i=n.get(s);if(i!==void 0)return i;if((i=o.get(s))!==void 0)return r(s,i),i},set(s,i){n.has(s)?n.set(s,i):r(s,i)}}},dr="!",Rh=e=>{const{separator:t,experimentalParseClassName:n}=e,o=t.length===1,r=t[0],s=t.length,i=a=>{const l=[];let d=0,u=0,f;for(let y=0;y<a.length;y++){let v=a[y];if(d===0){if(v===r&&(o||a.slice(y,y+s)===t)){l.push(a.slice(u,y)),u=y+s;continue}if(v==="/"){f=y;continue}}v==="["?d++:v==="]"&&d--}const h=l.length===0?a:a.substring(u),g=h.startsWith(dr),m=g?h.substring(1):h,p=f&&f>u?f-u:void 0;return{modifiers:l,hasImportantModifier:g,baseClassName:m,maybePostfixModifierPosition:p}};return n?a=>n({className:a,parseClassName:i}):i},zh=e=>{if(e.length<=1)return e;const t=[];let n=[];return e.forEach(o=>{o[0]==="["?(t.push(...n.sort(),o),n=[]):n.push(o)}),t.push(...n.sort()),t},Fh=e=>({cache:Dh(e.cacheSize),parseClassName:Rh(e),...Mh(e)}),Hh=/\s+/,Wh=(e,t)=>{const{parseClassName:n,getClassGroupId:o,getConflictingClassGroupIds:r}=t,s=[],i=e.trim().split(Hh);let a="";for(let l=i.length-1;l>=0;l-=1){const d=i[l],{modifiers:u,hasImportantModifier:f,baseClassName:h,maybePostfixModifierPosition:g}=n(d);let m=!!g,p=o(m?h.substring(0,g):h);if(!p){if(!m){a=d+(a.length>0?" "+a:a);continue}if(p=o(h),!p){a=d+(a.length>0?" "+a:a);continue}m=!1}const y=zh(u).join(":"),v=f?y+dr:y,b=v+p;if(s.includes(b))continue;s.push(b);const k=r(p,m);for(let S=0;S<k.length;++S){const C=k[S];s.push(v+C)}a=d+(a.length>0?" "+a:a)}return a};function Gh(){let e=0,t,n,o="";for(;e<arguments.length;)(t=arguments[e++])&&(n=ur(t))&&(o&&(o+=" "),o+=n);return o}const ur=e=>{if(typeof e=="string")return e;let t,n="";for(let o=0;o<e.length;o++)e[o]&&(t=ur(e[o]))&&(n&&(n+=" "),n+=t);return n};function qh(e,...t){let n,o,r,s=i;function i(l){const d=t.reduce((u,f)=>f(u),e());return n=Fh(d),o=n.cache.get,r=n.cache.set,s=a,a(l)}function a(l){const d=o(l);if(d)return d;const u=Wh(l,n);return r(l,u),u}return function(){return s(Gh.apply(null,arguments))}}const re=e=>{const t=n=>n[e]||[];return t.isThemeGetter=!0,t},fr=/^\[(?:([a-z-]+):)?(.+)\]$/i,Kh=/^\d+\/\d+$/,Yh=new Set(["px","full","screen"]),Xh=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,Vh=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,Uh=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,Zh=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,Jh=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,Pe=e=>et(e)||Yh.has(e)||Kh.test(e),ze=e=>ot(e,"length",ip),et=e=>!!e&&!Number.isNaN(Number(e)),Zt=e=>ot(e,"number",et),at=e=>!!e&&Number.isInteger(Number(e)),Qh=e=>e.endsWith("%")&&et(e.slice(0,-1)),q=e=>fr.test(e),Fe=e=>Xh.test(e),ep=new Set(["length","size","percentage"]),tp=e=>ot(e,ep,mr),np=e=>ot(e,"position",mr),op=new Set(["image","url"]),rp=e=>ot(e,op,lp),sp=e=>ot(e,"",ap),lt=()=>!0,ot=(e,t,n)=>{const o=fr.exec(e);return o?o[1]?typeof t=="string"?o[1]===t:t.has(o[1]):n(o[2]):!1},ip=e=>Vh.test(e)&&!Uh.test(e),mr=()=>!1,ap=e=>Zh.test(e),lp=e=>Jh.test(e),cp=()=>{const e=re("colors"),t=re("spacing"),n=re("blur"),o=re("brightness"),r=re("borderColor"),s=re("borderRadius"),i=re("borderSpacing"),a=re("borderWidth"),l=re("contrast"),d=re("grayscale"),u=re("hueRotate"),f=re("invert"),h=re("gap"),g=re("gradientColorStops"),m=re("gradientColorStopPositions"),p=re("inset"),y=re("margin"),v=re("opacity"),b=re("padding"),k=re("saturate"),S=re("scale"),C=re("sepia"),L=re("skew"),te=re("space"),Q=re("translate"),ve=()=>["auto","contain","none"],me=()=>["auto","hidden","clip","visible","scroll"],N=()=>["auto",q,t],M=()=>[q,t],se=()=>["",Pe,ze],oe=()=>["auto",et,q],de=()=>["bottom","center","left","left-bottom","left-top","right","right-bottom","right-top","top"],X=()=>["solid","dashed","dotted","double","none"],ue=()=>["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],le=()=>["start","end","center","between","around","evenly","stretch"],he=()=>["","0",q],ke=()=>["auto","avoid","all","avoid-page","page","left","right","column"],ye=()=>[et,q];return{cacheSize:500,separator:":",theme:{colors:[lt],spacing:[Pe,ze],blur:["none","",Fe,q],brightness:ye(),borderColor:[e],borderRadius:["none","","full",Fe,q],borderSpacing:M(),borderWidth:se(),contrast:ye(),grayscale:he(),hueRotate:ye(),invert:he(),gap:M(),gradientColorStops:[e],gradientColorStopPositions:[Qh,ze],inset:N(),margin:N(),opacity:ye(),padding:M(),saturate:ye(),scale:ye(),sepia:he(),skew:ye(),space:M(),translate:M()},classGroups:{aspect:[{aspect:["auto","square","video",q]}],container:["container"],columns:[{columns:[Fe]}],"break-after":[{"break-after":ke()}],"break-before":[{"break-before":ke()}],"break-inside":[{"break-inside":["auto","avoid","avoid-page","avoid-column"]}],"box-decoration":[{"box-decoration":["slice","clone"]}],box:[{box:["border","content"]}],display:["block","inline-block","inline","flex","inline-flex","table","inline-table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row-group","table-row","flow-root","grid","inline-grid","contents","list-item","hidden"],float:[{float:["right","left","none","start","end"]}],clear:[{clear:["left","right","both","none","start","end"]}],isolation:["isolate","isolation-auto"],"object-fit":[{object:["contain","cover","fill","none","scale-down"]}],"object-position":[{object:[...de(),q]}],overflow:[{overflow:me()}],"overflow-x":[{"overflow-x":me()}],"overflow-y":[{"overflow-y":me()}],overscroll:[{overscroll:ve()}],"overscroll-x":[{"overscroll-x":ve()}],"overscroll-y":[{"overscroll-y":ve()}],position:["static","fixed","absolute","relative","sticky"],inset:[{inset:[p]}],"inset-x":[{"inset-x":[p]}],"inset-y":[{"inset-y":[p]}],start:[{start:[p]}],end:[{end:[p]}],top:[{top:[p]}],right:[{right:[p]}],bottom:[{bottom:[p]}],left:[{left:[p]}],visibility:["visible","invisible","collapse"],z:[{z:["auto",at,q]}],basis:[{basis:N()}],"flex-direction":[{flex:["row","row-reverse","col","col-reverse"]}],"flex-wrap":[{flex:["wrap","wrap-reverse","nowrap"]}],flex:[{flex:["1","auto","initial","none",q]}],grow:[{grow:he()}],shrink:[{shrink:he()}],order:[{order:["first","last","none",at,q]}],"grid-cols":[{"grid-cols":[lt]}],"col-start-end":[{col:["auto",{span:["full",at,q]},q]}],"col-start":[{"col-start":oe()}],"col-end":[{"col-end":oe()}],"grid-rows":[{"grid-rows":[lt]}],"row-start-end":[{row:["auto",{span:[at,q]},q]}],"row-start":[{"row-start":oe()}],"row-end":[{"row-end":oe()}],"grid-flow":[{"grid-flow":["row","col","dense","row-dense","col-dense"]}],"auto-cols":[{"auto-cols":["auto","min","max","fr",q]}],"auto-rows":[{"auto-rows":["auto","min","max","fr",q]}],gap:[{gap:[h]}],"gap-x":[{"gap-x":[h]}],"gap-y":[{"gap-y":[h]}],"justify-content":[{justify:["normal",...le()]}],"justify-items":[{"justify-items":["start","end","center","stretch"]}],"justify-self":[{"justify-self":["auto","start","end","center","stretch"]}],"align-content":[{content:["normal",...le(),"baseline"]}],"align-items":[{items:["start","end","center","baseline","stretch"]}],"align-self":[{self:["auto","start","end","center","stretch","baseline"]}],"place-content":[{"place-content":[...le(),"baseline"]}],"place-items":[{"place-items":["start","end","center","baseline","stretch"]}],"place-self":[{"place-self":["auto","start","end","center","stretch"]}],p:[{p:[b]}],px:[{px:[b]}],py:[{py:[b]}],ps:[{ps:[b]}],pe:[{pe:[b]}],pt:[{pt:[b]}],pr:[{pr:[b]}],pb:[{pb:[b]}],pl:[{pl:[b]}],m:[{m:[y]}],mx:[{mx:[y]}],my:[{my:[y]}],ms:[{ms:[y]}],me:[{me:[y]}],mt:[{mt:[y]}],mr:[{mr:[y]}],mb:[{mb:[y]}],ml:[{ml:[y]}],"space-x":[{"space-x":[te]}],"space-x-reverse":["space-x-reverse"],"space-y":[{"space-y":[te]}],"space-y-reverse":["space-y-reverse"],w:[{w:["auto","min","max","fit","svw","lvw","dvw",q,t]}],"min-w":[{"min-w":[q,t,"min","max","fit"]}],"max-w":[{"max-w":[q,t,"none","full","min","max","fit","prose",{screen:[Fe]},Fe]}],h:[{h:[q,t,"auto","min","max","fit","svh","lvh","dvh"]}],"min-h":[{"min-h":[q,t,"min","max","fit","svh","lvh","dvh"]}],"max-h":[{"max-h":[q,t,"min","max","fit","svh","lvh","dvh"]}],size:[{size:[q,t,"auto","min","max","fit"]}],"font-size":[{text:["base",Fe,ze]}],"font-smoothing":["antialiased","subpixel-antialiased"],"font-style":["italic","not-italic"],"font-weight":[{font:["thin","extralight","light","normal","medium","semibold","bold","extrabold","black",Zt]}],"font-family":[{font:[lt]}],"fvn-normal":["normal-nums"],"fvn-ordinal":["ordinal"],"fvn-slashed-zero":["slashed-zero"],"fvn-figure":["lining-nums","oldstyle-nums"],"fvn-spacing":["proportional-nums","tabular-nums"],"fvn-fraction":["diagonal-fractions","stacked-fractions"],tracking:[{tracking:["tighter","tight","normal","wide","wider","widest",q]}],"line-clamp":[{"line-clamp":["none",et,Zt]}],leading:[{leading:["none","tight","snug","normal","relaxed","loose",Pe,q]}],"list-image":[{"list-image":["none",q]}],"list-style-type":[{list:["none","disc","decimal",q]}],"list-style-position":[{list:["inside","outside"]}],"placeholder-color":[{placeholder:[e]}],"placeholder-opacity":[{"placeholder-opacity":[v]}],"text-alignment":[{text:["left","center","right","justify","start","end"]}],"text-color":[{text:[e]}],"text-opacity":[{"text-opacity":[v]}],"text-decoration":["underline","overline","line-through","no-underline"],"text-decoration-style":[{decoration:[...X(),"wavy"]}],"text-decoration-thickness":[{decoration:["auto","from-font",Pe,ze]}],"underline-offset":[{"underline-offset":["auto",Pe,q]}],"text-decoration-color":[{decoration:[e]}],"text-transform":["uppercase","lowercase","capitalize","normal-case"],"text-overflow":["truncate","text-ellipsis","text-clip"],"text-wrap":[{text:["wrap","nowrap","balance","pretty"]}],indent:[{indent:M()}],"vertical-align":[{align:["baseline","top","middle","bottom","text-top","text-bottom","sub","super",q]}],whitespace:[{whitespace:["normal","nowrap","pre","pre-line","pre-wrap","break-spaces"]}],break:[{break:["normal","words","all","keep"]}],hyphens:[{hyphens:["none","manual","auto"]}],content:[{content:["none",q]}],"bg-attachment":[{bg:["fixed","local","scroll"]}],"bg-clip":[{"bg-clip":["border","padding","content","text"]}],"bg-opacity":[{"bg-opacity":[v]}],"bg-origin":[{"bg-origin":["border","padding","content"]}],"bg-position":[{bg:[...de(),np]}],"bg-repeat":[{bg:["no-repeat",{repeat:["","x","y","round","space"]}]}],"bg-size":[{bg:["auto","cover","contain",tp]}],"bg-image":[{bg:["none",{"gradient-to":["t","tr","r","br","b","bl","l","tl"]},rp]}],"bg-color":[{bg:[e]}],"gradient-from-pos":[{from:[m]}],"gradient-via-pos":[{via:[m]}],"gradient-to-pos":[{to:[m]}],"gradient-from":[{from:[g]}],"gradient-via":[{via:[g]}],"gradient-to":[{to:[g]}],rounded:[{rounded:[s]}],"rounded-s":[{"rounded-s":[s]}],"rounded-e":[{"rounded-e":[s]}],"rounded-t":[{"rounded-t":[s]}],"rounded-r":[{"rounded-r":[s]}],"rounded-b":[{"rounded-b":[s]}],"rounded-l":[{"rounded-l":[s]}],"rounded-ss":[{"rounded-ss":[s]}],"rounded-se":[{"rounded-se":[s]}],"rounded-ee":[{"rounded-ee":[s]}],"rounded-es":[{"rounded-es":[s]}],"rounded-tl":[{"rounded-tl":[s]}],"rounded-tr":[{"rounded-tr":[s]}],"rounded-br":[{"rounded-br":[s]}],"rounded-bl":[{"rounded-bl":[s]}],"border-w":[{border:[a]}],"border-w-x":[{"border-x":[a]}],"border-w-y":[{"border-y":[a]}],"border-w-s":[{"border-s":[a]}],"border-w-e":[{"border-e":[a]}],"border-w-t":[{"border-t":[a]}],"border-w-r":[{"border-r":[a]}],"border-w-b":[{"border-b":[a]}],"border-w-l":[{"border-l":[a]}],"border-opacity":[{"border-opacity":[v]}],"border-style":[{border:[...X(),"hidden"]}],"divide-x":[{"divide-x":[a]}],"divide-x-reverse":["divide-x-reverse"],"divide-y":[{"divide-y":[a]}],"divide-y-reverse":["divide-y-reverse"],"divide-opacity":[{"divide-opacity":[v]}],"divide-style":[{divide:X()}],"border-color":[{border:[r]}],"border-color-x":[{"border-x":[r]}],"border-color-y":[{"border-y":[r]}],"border-color-s":[{"border-s":[r]}],"border-color-e":[{"border-e":[r]}],"border-color-t":[{"border-t":[r]}],"border-color-r":[{"border-r":[r]}],"border-color-b":[{"border-b":[r]}],"border-color-l":[{"border-l":[r]}],"divide-color":[{divide:[r]}],"outline-style":[{outline:["",...X()]}],"outline-offset":[{"outline-offset":[Pe,q]}],"outline-w":[{outline:[Pe,ze]}],"outline-color":[{outline:[e]}],"ring-w":[{ring:se()}],"ring-w-inset":["ring-inset"],"ring-color":[{ring:[e]}],"ring-opacity":[{"ring-opacity":[v]}],"ring-offset-w":[{"ring-offset":[Pe,ze]}],"ring-offset-color":[{"ring-offset":[e]}],shadow:[{shadow:["","inner","none",Fe,sp]}],"shadow-color":[{shadow:[lt]}],opacity:[{opacity:[v]}],"mix-blend":[{"mix-blend":[...ue(),"plus-lighter","plus-darker"]}],"bg-blend":[{"bg-blend":ue()}],filter:[{filter:["","none"]}],blur:[{blur:[n]}],brightness:[{brightness:[o]}],contrast:[{contrast:[l]}],"drop-shadow":[{"drop-shadow":["","none",Fe,q]}],grayscale:[{grayscale:[d]}],"hue-rotate":[{"hue-rotate":[u]}],invert:[{invert:[f]}],saturate:[{saturate:[k]}],sepia:[{sepia:[C]}],"backdrop-filter":[{"backdrop-filter":["","none"]}],"backdrop-blur":[{"backdrop-blur":[n]}],"backdrop-brightness":[{"backdrop-brightness":[o]}],"backdrop-contrast":[{"backdrop-contrast":[l]}],"backdrop-grayscale":[{"backdrop-grayscale":[d]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[u]}],"backdrop-invert":[{"backdrop-invert":[f]}],"backdrop-opacity":[{"backdrop-opacity":[v]}],"backdrop-saturate":[{"backdrop-saturate":[k]}],"backdrop-sepia":[{"backdrop-sepia":[C]}],"border-collapse":[{border:["collapse","separate"]}],"border-spacing":[{"border-spacing":[i]}],"border-spacing-x":[{"border-spacing-x":[i]}],"border-spacing-y":[{"border-spacing-y":[i]}],"table-layout":[{table:["auto","fixed"]}],caption:[{caption:["top","bottom"]}],transition:[{transition:["none","all","","colors","opacity","shadow","transform",q]}],duration:[{duration:ye()}],ease:[{ease:["linear","in","out","in-out",q]}],delay:[{delay:ye()}],animate:[{animate:["none","spin","ping","pulse","bounce",q]}],transform:[{transform:["","gpu","none"]}],scale:[{scale:[S]}],"scale-x":[{"scale-x":[S]}],"scale-y":[{"scale-y":[S]}],rotate:[{rotate:[at,q]}],"translate-x":[{"translate-x":[Q]}],"translate-y":[{"translate-y":[Q]}],"skew-x":[{"skew-x":[L]}],"skew-y":[{"skew-y":[L]}],"transform-origin":[{origin:["center","top","top-right","right","bottom-right","bottom","bottom-left","left","top-left",q]}],accent:[{accent:["auto",e]}],appearance:[{appearance:["none","auto"]}],cursor:[{cursor:["auto","default","pointer","wait","text","move","help","not-allowed","none","context-menu","progress","cell","crosshair","vertical-text","alias","copy","no-drop","grab","grabbing","all-scroll","col-resize","row-resize","n-resize","e-resize","s-resize","w-resize","ne-resize","nw-resize","se-resize","sw-resize","ew-resize","ns-resize","nesw-resize","nwse-resize","zoom-in","zoom-out",q]}],"caret-color":[{caret:[e]}],"pointer-events":[{"pointer-events":["none","auto"]}],resize:[{resize:["none","y","x",""]}],"scroll-behavior":[{scroll:["auto","smooth"]}],"scroll-m":[{"scroll-m":M()}],"scroll-mx":[{"scroll-mx":M()}],"scroll-my":[{"scroll-my":M()}],"scroll-ms":[{"scroll-ms":M()}],"scroll-me":[{"scroll-me":M()}],"scroll-mt":[{"scroll-mt":M()}],"scroll-mr":[{"scroll-mr":M()}],"scroll-mb":[{"scroll-mb":M()}],"scroll-ml":[{"scroll-ml":M()}],"scroll-p":[{"scroll-p":M()}],"scroll-px":[{"scroll-px":M()}],"scroll-py":[{"scroll-py":M()}],"scroll-ps":[{"scroll-ps":M()}],"scroll-pe":[{"scroll-pe":M()}],"scroll-pt":[{"scroll-pt":M()}],"scroll-pr":[{"scroll-pr":M()}],"scroll-pb":[{"scroll-pb":M()}],"scroll-pl":[{"scroll-pl":M()}],"snap-align":[{snap:["start","end","center","align-none"]}],"snap-stop":[{snap:["normal","always"]}],"snap-type":[{snap:["none","x","y","both"]}],"snap-strictness":[{snap:["mandatory","proximity"]}],touch:[{touch:["auto","none","manipulation"]}],"touch-x":[{"touch-pan":["x","left","right"]}],"touch-y":[{"touch-pan":["y","up","down"]}],"touch-pz":["touch-pinch-zoom"],select:[{select:["none","text","all","auto"]}],"will-change":[{"will-change":["auto","scroll","contents","transform",q]}],fill:[{fill:[e,"none"]}],"stroke-w":[{stroke:[Pe,ze,Zt]}],stroke:[{stroke:[e,"none"]}],sr:["sr-only","not-sr-only"],"forced-color-adjust":[{"forced-color-adjust":["auto","none"]}]},conflictingClassGroups:{overflow:["overflow-x","overflow-y"],overscroll:["overscroll-x","overscroll-y"],inset:["inset-x","inset-y","start","end","top","right","bottom","left"],"inset-x":["right","left"],"inset-y":["top","bottom"],flex:["basis","grow","shrink"],gap:["gap-x","gap-y"],p:["px","py","ps","pe","pt","pr","pb","pl"],px:["pr","pl"],py:["pt","pb"],m:["mx","my","ms","me","mt","mr","mb","ml"],mx:["mr","ml"],my:["mt","mb"],size:["w","h"],"font-size":["leading"],"fvn-normal":["fvn-ordinal","fvn-slashed-zero","fvn-figure","fvn-spacing","fvn-fraction"],"fvn-ordinal":["fvn-normal"],"fvn-slashed-zero":["fvn-normal"],"fvn-figure":["fvn-normal"],"fvn-spacing":["fvn-normal"],"fvn-fraction":["fvn-normal"],"line-clamp":["display","overflow"],rounded:["rounded-s","rounded-e","rounded-t","rounded-r","rounded-b","rounded-l","rounded-ss","rounded-se","rounded-ee","rounded-es","rounded-tl","rounded-tr","rounded-br","rounded-bl"],"rounded-s":["rounded-ss","rounded-es"],"rounded-e":["rounded-se","rounded-ee"],"rounded-t":["rounded-tl","rounded-tr"],"rounded-r":["rounded-tr","rounded-br"],"rounded-b":["rounded-br","rounded-bl"],"rounded-l":["rounded-tl","rounded-bl"],"border-spacing":["border-spacing-x","border-spacing-y"],"border-w":["border-w-s","border-w-e","border-w-t","border-w-r","border-w-b","border-w-l"],"border-w-x":["border-w-r","border-w-l"],"border-w-y":["border-w-t","border-w-b"],"border-color":["border-color-s","border-color-e","border-color-t","border-color-r","border-color-b","border-color-l"],"border-color-x":["border-color-r","border-color-l"],"border-color-y":["border-color-t","border-color-b"],"scroll-m":["scroll-mx","scroll-my","scroll-ms","scroll-me","scroll-mt","scroll-mr","scroll-mb","scroll-ml"],"scroll-mx":["scroll-mr","scroll-ml"],"scroll-my":["scroll-mt","scroll-mb"],"scroll-p":["scroll-px","scroll-py","scroll-ps","scroll-pe","scroll-pt","scroll-pr","scroll-pb","scroll-pl"],"scroll-px":["scroll-pr","scroll-pl"],"scroll-py":["scroll-pt","scroll-pb"],touch:["touch-x","touch-y","touch-pz"],"touch-x":["touch"],"touch-y":["touch"],"touch-pz":["touch"]},conflictingClassGroupModifiers:{"font-size":["leading"]}}},dp=qh(cp);function we(...e){return dp(lr(e))}const hr=j.createContext(null);function up(){const e=j.useContext(hr);if(!e)throw new Error("useContextMenu must be used inside <ContextMenuHost>");return e}const Et=8;function fp({children:e}){const[t,n]=j.useState({open:!1,x:0,y:0,items:[]}),[o,r]=j.useState(null),s=j.useRef(null),i=j.useCallback(()=>{n(d=>d.open?{...d,open:!1}:d)},[]),a=j.useCallback((d,u,f)=>{r(null),n({open:!0,x:d,y:u,items:f})},[]),l=j.useMemo(()=>({open:a,close:i}),[a,i]);return j.useLayoutEffect(()=>{if(!t.open||!s.current)return;const d=s.current.getBoundingClientRect();let u=t.x,f=t.y;u+d.width>window.innerWidth-Et&&(u=Math.max(Et,t.x-d.width)),f+d.height>window.innerHeight-Et&&(f=Math.max(Et,t.y-d.height)),r({left:u,top:f})},[t]),j.useEffect(()=>{if(!t.open)return;const d=g=>{s.current&&!s.current.contains(g.target)&&i()},u=g=>{g.key==="Escape"&&(g.preventDefault(),i())},f=()=>i(),h=()=>i();return document.addEventListener("pointerdown",d,!0),document.addEventListener("keydown",u,!0),window.addEventListener("wheel",f,{passive:!0}),window.addEventListener("blur",h),()=>{document.removeEventListener("pointerdown",d,!0),document.removeEventListener("keydown",u,!0),window.removeEventListener("wheel",f),window.removeEventListener("blur",h)}},[t.open,i]),c.jsxs(hr.Provider,{value:l,children:[e,t.open&&c.jsx("div",{ref:s,role:"menu","aria-orientation":"vertical",className:"ole-glass fixed z-50 min-w-[200px] rounded-md border border-border p-1 text-sm shadow-md",style:{left:(o==null?void 0:o.left)??t.x,top:(o==null?void 0:o.top)??t.y,visibility:o?"visible":"hidden"},onContextMenu:d=>d.preventDefault(),children:t.items.map((d,u)=>{if(d.type==="separator")return c.jsx("div",{role:"separator",className:"my-1 h-px bg-border"},`sep-${u}`);const f=d.icon;return c.jsxs("button",{type:"button",role:"menuitem",disabled:d.disabled,className:we("flex w-full items-center justify-between gap-3 rounded-sm px-2 py-1.5 text-left","hover:bg-accent hover:text-accent-foreground","focus-visible:bg-accent focus-visible:text-accent-foreground focus-visible:outline-none",d.destructive&&"text-destructive hover:bg-destructive/10 hover:text-destructive",d.disabled&&"pointer-events-none text-muted-foreground opacity-60"),onClick:()=>{i(),d.onSelect()},children:[c.jsxs("span",{className:"flex items-center gap-2",children:[f?c.jsx(f,{className:"size-4"}):null,c.jsx("span",{children:d.label})]}),d.shortcut?c.jsx("span",{className:"text-xs text-muted-foreground",children:d.shortcut}):null]},`${d.label}-${u}`)})})]})}const Xn=e=>{let t;const n=new Set,o=(d,u)=>{const f=typeof d=="function"?d(t):d;if(!Object.is(f,t)){const h=t;t=u??(typeof f!="object"||f===null)?f:Object.assign({},t,f),n.forEach(g=>g(t,h))}},r=()=>t,a={setState:o,getState:r,getInitialState:()=>l,subscribe:d=>(n.add(d),()=>n.delete(d))},l=t=e(o,r,a);return a},mp=(e=>e?Xn(e):Xn),hp=e=>e;function pp(e,t=hp){const n=j.useSyncExternalStore(e.subscribe,j.useCallback(()=>t(e.getState()),[e,t]),j.useCallback(()=>t(e.getInitialState()),[e,t]));return j.useDebugValue(n),n}const Vn=e=>{const t=mp(e),n=o=>pp(t,o);return Object.assign(n,t),n},Ft=(e=>e?Vn(e):Vn),Un={zh:{"common.unnamed":"未命名","common.close":"关闭","common.yes":"是","common.no":"否","topbar.theme.toLight":"切换到亮色","topbar.theme.toDark":"切换到暗色","topbar.theme.currentDark":"当前:暗色主题","topbar.theme.currentLight":"当前:亮色主题","topbar.lang.toEnglish":"Switch to English","topbar.lang.toChinese":"切换到中文","topbar.lang.currentEnglish":"Current: English","topbar.lang.currentChinese":"当前:中文","topbar.export.label":"导出","topbar.export.tooltip":"SVG 矢量(可编辑)、PNG 位图(2× 高清)或 DXF(CAD)","topbar.export.pngFailed":"导出 PNG 失败:{err}","topbar.export.dxfFailed":"导出 DXF 失败:{err}","topbar.file.label":"文件","topbar.file.tooltip":"打开本地 .json 图、保存、或另存为","topbar.file.current":"当前:{name}","topbar.file.new":"新建","topbar.file.open":"打开…","topbar.file.save":"保存","topbar.file.saveAs":"另存为…","topbar.file.newConfirm":"新建会清空当前未保存的内容,是否继续?","topbar.file.openFailed":"打开失败:{err}","topbar.file.saveFailed":"保存失败:{err}","topbar.file.fileDescription":"OneLineEditor 图纸","outline.title":"大纲","outline.collapse":"折叠","outline.collapseAria":"折叠大纲","outline.empty":"(无设备 — 从元件库拖入开始)","props.title":"属性","props.node":"电气节点","props.wire":"连线","props.bus":"母线","props.nSelected":"{n} 选中","props.empty":"未选中","props.multi":"已选中 {n} 个元件","props.name":"名称","props.note":"备注","props.nodeNotFound":"电气节点 {id} 不存在","props.wireNotFound":"连线 {id} 不存在","props.nodeStats":"{terminals} 个端子 · {elements} 个元件","props.selectElement":"选中 {label}","props.selectWholeNode":"选中整个电气节点","view.zoomOut":"缩小","view.zoomOutHint":"按预设档位缩小;也可滚轮 ↓ 或 ⌘−","view.reset":"重置到 100%","view.current":"当前 {z}%","view.zoomIn":"放大","view.zoomInHint":"按预设档位放大;也可滚轮 ↑ 或 ⌘+","view.fit":"适配视图","view.fitHint":"自动缩放并居中所有元件","view.gridHide":"隐藏网格","view.gridShow":"显示网格","view.gridHotkey":"G","view.gridHideHint":"同时关闭对齐吸附(拖动可自由放置)","view.gridShowHint":"同时开启对齐吸附(拖动会贴到 10px 网格)","view.gridHideAria":"隐藏网格并关闭吸附","view.gridShowAria":"显示网格并开启吸附","view.label":"标签","view.labelOff":"关闭标签","view.labelId":"仅显示 ID","view.labelAll":"ID + 参数","view.labelHint":"点击循环切换:关闭 → 仅 ID → ID + 参数","library.title":"元件库","library.empty":"没有匹配的元件","library.searchPlaceholder":"搜索元件…","library.searchAria":"搜索元件","library.clearSearch":"清除搜索","library.itemHint":"单击进入放置模式或拖到画布","tool.select":"选择","tool.selectHint":"点选元件,框选多个,或右键打开菜单","tool.pan":"平移","tool.panHint":"拖动画布;空格键可临时切换","tool.wire":"连线","tool.wireHint":"从一个端子拖动到另一个端子完成连线","tool.bus":"母线","tool.busHint":"画布上拖动一段母线,按下定起点、释放定终点","tool.place":"元件","tool.placeHint":"点击画布放置;或从端子/母线拖出,同时放置并连接","tool.text":"文字","tool.textHint":"点击画布放置一段文字注释;双击文字可重新编辑","mode.selectWithSel":"拖动元件移动 · 拖端子连线 · 右键打开菜单","mode.selectEmpty":"点选元件 · 拖动移动 · 框选多个 · 右键打开菜单","mode.pan":"拖动画布 · 滚轮缩放 · 按住空格可在其他工具下临时平移","mode.wireDragging":"拖到另一个端子或母线上释放完成连线","mode.wireInit":"从端子按下,拖动到另一个端子或母线上释放","mode.busDragging":"拖动决定母线方向,释放定终点","mode.busInit":"在画布按下定起点,拖动后释放定终点","mode.placeNoKind":"从左侧元件库选择一种元件","mode.placeFromTerm":"拖到目标位置释放,新元件将连接到起点端子","mode.placeNormal":"点击空白放置;或从已有端子 / 母线拖出,同时放置并连接","mode.text":"点击画布放置文字;双击已有文字可编辑;选中后可拖动 / 删除","mode.escSelect":"Esc 清除选择","mode.escOther":"右键 / Esc 取消","tool.placeNoKindTooltip":"从左侧元件库选择一个元件后点击画布放置","tool.undo":"撤销","tool.undoHint":"撤销上一次编辑(移动 / 旋转 / 删除等)","tool.redo":"重做","tool.redoHint":"重做被撤销的操作","layout.label":"布局","layout.hint":"自动排版整个图或仅选中范围,并填补空缺","layout.allAuto":"重新自动布局","layout.selAuto":"重新自动布局选区","layout.allFill":"填补未排版位置","layout.selFill":"填补未排版选区","tool.more":"更多","tool.moreHint":"撤销 / 重做 / 布局","view.menu":"视图","view.menuHint":"缩放、适配、网格","ctx.ariaNode":"选中节点操作","ctx.ariaWire":"选中连线操作","ctx.ariaElement":"选中元件操作","ctx.rotate":"旋转 90°","ctx.rotateHint":"顺时针旋转选中元件,连线随端子自动重排","ctx.mirror":"水平镜像","ctx.mirrorTitle":"镜像","ctx.mirrorHint":"左右翻转选中元件","ctx.delete":"删除","ctx.deleteHintNode":"断开此电气节点上的所有连接(保留元件)","ctx.deleteHintWire":"移除这一根连线(其它同节点连线保留)","ctx.deleteHintElement":"移除选中元件及其连接的连线","ctx.resetWirePath":"恢复自动走线","ctx.resetWirePathHint":"清除手动调整的拐点,让连线回到自动路由","menu.undo":"撤销","menu.redo":"重做","menu.cut":"剪切","menu.copy":"复制","menu.paste":"粘贴","menu.rotate":"旋转 90°","menu.mirror":"镜像","menu.selectAll":"全选","menu.disconnect":"断开此连线","menu.delete":"删除","io.parseFailed":"JSON 解析失败:{err}","io.notObject":"文件不是 JSON 对象","io.versionMismatch":'版本不兼容:期望 "1",实际 {actual}',"io.elementsMissing":"elements 字段缺失或不是数组","compile.duplicateId":'元件 ID 重复:"{id}"',"compile.unknownKind":'未知元件类型 kind="{kind}"',"compile.invalidTermRef":'非法端子引用 "{ref}"',"compile.elementMissing":'引用了不存在的元件 "{id}"',"compile.missingPin":'元件 "{id}" (kind={kind}) 没有引脚 "{pin}",可用引脚: {available}',"compile.singleTerminal":"节点只包含一个端子,已忽略","compile.layoutMissingElement":'layout 键 "{id}" 引用了不存在的元件',"compile.elementUnconnected":'元件 "{id}" 没有任何连接',"cat.busbar":"母线 / 接线","cat.switching":"开关","cat.protection":"保护","cat.motor-control":"电机控制","cat.transformer":"变压器","cat.instrument-transformer":"互感器","cat.measurement":"测量仪表","cat.source":"电源","cat.load":"负荷","cat.storage":"储能","cat.compensation":"无功补偿","cat.grounding":"中性点接地","cat.renewable":"新能源 / 电力电子","onboard.title":"上手三步","onboard.step1.title":"画母线","onboard.step1.body":"选择 母线 工具(B),在画布上按下拖动","onboard.step2.title":"从母线拖出元件","onboard.step2.body":"切到 元件(P)选一种,按住母线拖到目标位置 — 自动连接","onboard.step3.title":"继续串接","onboard.step3.body":"从任意端子拖出,落到目标即与该端子相连","onboard.dismiss":"知道了"},en:{"common.unnamed":"Untitled","common.close":"Close","common.yes":"Yes","common.no":"No","topbar.theme.toLight":"Switch to light","topbar.theme.toDark":"Switch to dark","topbar.theme.currentDark":"Current: dark theme","topbar.theme.currentLight":"Current: light theme","topbar.lang.toEnglish":"Switch to English","topbar.lang.toChinese":"切换到中文","topbar.lang.currentEnglish":"Current: English","topbar.lang.currentChinese":"Current: Chinese","topbar.export.label":"Export","topbar.export.tooltip":"SVG vector (editable), PNG bitmap (2× HiDPI), or DXF (CAD)","topbar.export.pngFailed":"PNG export failed: {err}","topbar.export.dxfFailed":"DXF export failed: {err}","topbar.file.label":"File","topbar.file.tooltip":"Open a local .json diagram, save, or save as","topbar.file.current":"Current: {name}","topbar.file.new":"New","topbar.file.open":"Open…","topbar.file.save":"Save","topbar.file.saveAs":"Save as…","topbar.file.newConfirm":"New will discard any unsaved changes. Continue?","topbar.file.openFailed":"Open failed: {err}","topbar.file.saveFailed":"Save failed: {err}","topbar.file.fileDescription":"OneLineEditor diagram","outline.title":"Outline","outline.collapse":"Collapse","outline.collapseAria":"Collapse outline","outline.empty":"(No elements — drag from the library to start)","props.title":"Properties","props.node":"Electrical node","props.wire":"Wire","props.bus":"Bus","props.nSelected":"{n} selected","props.empty":"Nothing selected","props.multi":"{n} elements selected","props.name":"Name","props.note":"Note","props.nodeNotFound":"Electrical node {id} not found","props.wireNotFound":"Wire {id} not found","props.nodeStats":"{terminals} terminals · {elements} elements","props.selectElement":"Select {label}","props.selectWholeNode":"Select whole electrical node","view.zoomOut":"Zoom out","view.zoomOutHint":"Step zoom out; also wheel ↓ or ⌘−","view.reset":"Reset to 100%","view.current":"Current {z}%","view.zoomIn":"Zoom in","view.zoomInHint":"Step zoom in; also wheel ↑ or ⌘+","view.fit":"Fit view","view.fitHint":"Auto-zoom and center all elements","view.gridHide":"Hide grid","view.gridShow":"Show grid","view.gridHotkey":"G","view.gridHideHint":"Also disables snap-to-grid (free placement)","view.gridShowHint":"Also enables snap-to-grid (snaps to 10px on drag)","view.gridHideAria":"Hide grid and disable snap","view.gridShowAria":"Show grid and enable snap","view.label":"Labels","view.labelOff":"Hide labels","view.labelId":"ID only","view.labelAll":"ID + params","view.labelHint":"Cycle: off → ID → ID + params","library.title":"Library","library.empty":"No matching elements","library.searchPlaceholder":"Search elements…","library.searchAria":"Search elements","library.clearSearch":"Clear search","library.itemHint":"Click to enter place mode, or drag onto the canvas","tool.select":"Select","tool.selectHint":"Click to pick, marquee for multiple, right-click for menu","tool.pan":"Pan","tool.panHint":"Drag the canvas; Space toggles temporarily","tool.wire":"Wire","tool.wireHint":"Drag from one terminal to another to wire","tool.bus":"Busbar","tool.busHint":"Drag on the canvas — press to set start, release to set end","tool.place":"Place","tool.placeHint":"Click to place; or drag from a terminal/bus to place and connect","tool.text":"Text","tool.textHint":"Click the canvas to drop a text note; double-click an existing one to edit","mode.selectWithSel":"Drag elements · drag terminals to wire · right-click for menu","mode.selectEmpty":"Click to pick · drag to move · marquee for multiple · right-click for menu","mode.pan":"Drag the canvas · scroll to zoom · hold Space to pan in any tool","mode.wireDragging":"Release on another terminal or busbar to complete the wire","mode.wireInit":"Press on a terminal, drag to another terminal or busbar, release","mode.busDragging":"Drag sets bus direction; release sets the end","mode.busInit":"Press on the canvas to set start, drag, release to set end","mode.placeNoKind":"Pick an element kind from the library on the left","mode.placeFromTerm":"Release at the target — the new element will connect back to the source terminal","mode.placeNormal":"Click empty space to place; or drag from a terminal / bus to place and connect","mode.text":"Click to drop text · double-click to edit · drag selected to move · Del to remove","mode.escSelect":"Esc clears selection","mode.escOther":"Right-click / Esc to cancel","tool.placeNoKindTooltip":"Pick a kind in the library on the left, then click the canvas","tool.undo":"Undo","tool.undoHint":"Undo the last edit (move / rotate / delete, etc.)","tool.redo":"Redo","tool.redoHint":"Redo the last undone edit","layout.label":"Layout","layout.hint":"Auto-layout the whole diagram or just the selection, fill gaps","layout.allAuto":"Auto-layout all","layout.selAuto":"Auto-layout selection","layout.allFill":"Fill unplaced","layout.selFill":"Fill unplaced in selection","tool.more":"More","tool.moreHint":"Undo / redo / layout","view.menu":"View","view.menuHint":"Zoom, fit, grid","ctx.ariaNode":"Node actions","ctx.ariaWire":"Wire actions","ctx.ariaElement":"Element actions","ctx.rotate":"Rotate 90°","ctx.rotateHint":"Rotate selection clockwise; wires re-route through new terminals","ctx.mirror":"Mirror horizontally","ctx.mirrorTitle":"Mirror","ctx.mirrorHint":"Flip selection left-right","ctx.delete":"Delete","ctx.deleteHintNode":"Disconnect every wire on this node (elements stay)","ctx.deleteHintWire":"Remove only this wire (siblings on the same node stay)","ctx.deleteHintElement":"Remove the selection and its wires","ctx.resetWirePath":"Reset to auto-route","ctx.resetWirePathHint":"Drop manual corners and let the router re-draw this wire","menu.undo":"Undo","menu.redo":"Redo","menu.cut":"Cut","menu.copy":"Copy","menu.paste":"Paste","menu.rotate":"Rotate 90°","menu.mirror":"Mirror","menu.selectAll":"Select all","menu.disconnect":"Disconnect this wire","menu.delete":"Delete","io.parseFailed":"JSON parse failed: {err}","io.notObject":"File is not a JSON object","io.versionMismatch":'Version mismatch: expected "1", got {actual}',"io.elementsMissing":"`elements` is missing or not an array","compile.duplicateId":'Duplicate element id: "{id}"',"compile.unknownKind":'Unknown element kind="{kind}"',"compile.invalidTermRef":'Invalid terminal reference "{ref}"',"compile.elementMissing":'Reference to unknown element "{id}"',"compile.missingPin":'Element "{id}" (kind={kind}) has no pin "{pin}"; available: {available}',"compile.singleTerminal":"Node has only one terminal — ignored","compile.layoutMissingElement":'layout key "{id}" references an unknown element',"compile.elementUnconnected":'Element "{id}" has no connections',"cat.busbar":"Busbar / wiring","cat.switching":"Switching","cat.protection":"Protection","cat.motor-control":"Motor control","cat.transformer":"Transformer","cat.instrument-transformer":"Instrument transformer","cat.measurement":"Measurement","cat.source":"Source","cat.load":"Load","cat.storage":"Storage","cat.compensation":"Compensation","cat.grounding":"Grounding","cat.renewable":"Renewables / power electronics","onboard.title":"Quick start","onboard.step1.title":"Draw a busbar","onboard.step1.body":"Pick the busbar tool (B), then press and drag on the canvas","onboard.step2.title":"Drag elements from the bus","onboard.step2.body":"Switch to Place (P), pick a kind, then drag from the bus — it auto-connects","onboard.step3.title":"Chain the next one","onboard.step3.body":"Drag from any terminal — the new element drops pre-connected","onboard.dismiss":"Got it"}},pr="ole-locale";function gp(){if(typeof window>"u")return"zh";try{const e=window.localStorage.getItem(pr);if(e==="zh"||e==="en")return e}catch{}return typeof navigator<"u"&&typeof navigator.language=="string"?navigator.language.toLowerCase().startsWith("zh")?"zh":"en":"zh"}function Zn(e){try{window.localStorage.setItem(pr,e)}catch{}}const _t=Ft((e,t)=>({locale:gp(),setLocale:n=>{Zn(n),e({locale:n})},toggle:()=>{const n=t().locale==="zh"?"en":"zh";Zn(n),e({locale:n})}}));function gr(e,t){return t?e.replace(/\{(\w+)\}/g,(n,o)=>t[o]!==void 0?String(t[o]):`{${o}}`):e}function xr(e,t){return Un[e][t]??Un.zh[t]??t}function be(e,t){return gr(xr(_t.getState().locale,e),t)}function Z(){const e=_t(t=>t.locale);return(t,n)=>gr(xr(e,t),n)}function yr(e,t){let n;try{n=e()}catch{return}return{getItem:r=>{var s;const i=l=>l===null?null:JSON.parse(l,void 0),a=(s=n.getItem(r))!=null?s:null;return a instanceof Promise?a.then(i):i(a)},setItem:(r,s)=>n.setItem(r,JSON.stringify(s,void 0)),removeItem:r=>n.removeItem(r)}}const fn=e=>t=>{try{const n=e(t);return n instanceof Promise?n:{then(o){return fn(o)(n)},catch(o){return this}}}catch(n){return{then(o){return this},catch(o){return fn(o)(n)}}}},xp=(e,t)=>(n,o,r)=>{let s={storage:yr(()=>window.localStorage),partialize:y=>y,version:0,merge:(y,v)=>({...v,...y}),...t},i=!1,a=0;const l=new Set,d=new Set;let u=s.storage;if(!u)return e((...y)=>{console.warn(`[zustand persist middleware] Unable to update item '${s.name}', the given storage is currently unavailable.`),n(...y)},o,r);const f=()=>{const y=s.partialize({...o()});return u.setItem(s.name,{state:y,version:s.version})},h=r.setState;r.setState=(y,v)=>(h(y,v),f());const g=e((...y)=>(n(...y),f()),o,r);r.getInitialState=()=>g;let m;const p=()=>{var y,v;if(!u)return;const b=++a;i=!1,l.forEach(S=>{var C;return S((C=o())!=null?C:g)});const k=((v=s.onRehydrateStorage)==null?void 0:v.call(s,(y=o())!=null?y:g))||void 0;return fn(u.getItem.bind(u))(s.name).then(S=>{if(S)if(typeof S.version=="number"&&S.version!==s.version){if(s.migrate){const C=s.migrate(S.state,S.version);return C instanceof Promise?C.then(L=>[!0,L]):[!0,C]}console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return[!1,S.state];return[!1,void 0]}).then(S=>{var C;if(b!==a)return;const[L,te]=S;if(m=s.merge(te,(C=o())!=null?C:g),n(m,!0),L)return f()}).then(()=>{b===a&&(k==null||k(o(),void 0),m=o(),i=!0,d.forEach(S=>S(m)))}).catch(S=>{b===a&&(k==null||k(void 0,S))})};return r.persist={setOptions:y=>{s={...s,...y},y.storage&&(u=y.storage)},clearStorage:()=>{u==null||u.removeItem(s.name)},getOptions:()=>s,rehydrate:()=>p(),hasHydrated:()=>i,onHydrate:y=>(l.add(y),()=>{l.delete(y)}),onFinishHydration:y=>(d.add(y),()=>{d.delete(y)})},s.skipHydration||p(),m||g},yp=xp,Oe=.5;function br(e){if(e.length<2)return e.map(r=>[r[0],r[1]]);const t=[[e[0][0],e[0][1]]];for(let r=1;r<e.length;r++){const s=t[t.length-1];Math.abs(s[0]-e[r][0])<Oe&&Math.abs(s[1]-e[r][1])<Oe||t.push([e[r][0],e[r][1]])}if(t.length<2)return t;const n=[t[0]];for(let r=1;r<t.length;r++){const s=n[n.length-1],i=t[r],a=Math.abs(s[0]-i[0]),l=Math.abs(s[1]-i[1]);if(a>Oe&&l>Oe){const u=(n.length>=2?Math.abs(n[n.length-2][1]-s[1])<Oe?"h":"v":null)==="h"?[i[0],s[1]]:[s[0],i[1]];n.push(u)}n.push(i)}const o=[n[0]];for(let r=1;r<n.length-1;r++){const s=o[o.length-1],i=n[r],a=n[r+1],l=Math.abs(s[0]-i[0])<Oe&&Math.abs(i[0]-a[0])<Oe,d=Math.abs(s[1]-i[1])<Oe&&Math.abs(i[1]-a[1])<Oe;l||d||o.push(i)}return o.push(n[n.length-1]),o}function wr(){return{elements:new Map,buses:new Map,terminals:new Map,nodes:new Map,layout:new Map,wireRenders:new Map,terminalToNode:new Map,elementToTerminals:new Map,diagnostics:[]}}function vr(e){return{at:(e==null?void 0:e.at)??[0,0],rot:(e==null?void 0:e.rot)??0,mirror:(e==null?void 0:e.mirror)??!1}}function mn(e){return e===90||e===270?"y":"x"}function Le(e,t){let[n,o]=e;switch(t.mirror&&(n=-n),t.rot){case 0:break;case 90:[n,o]=[-o,n];break;case 180:[n,o]=[-n,-o];break;case 270:[n,o]=[o,-n];break}return[n+t.at[0],o+t.at[1]]}const bp={n:"e",e:"s",s:"w",w:"n"},wp={n:"n",s:"s",e:"w",w:"e"};function xt(e,t){let n=t.mirror?wp[e]:e;const o=t.rot/90|0;for(let r=0;r<o;r++)n=bp[n];return n}function hn(e){switch(e){case"n":return[0,-1];case"s":return[0,1];case"e":return[1,0];case"w":return[-1,0]}}class kr{constructor(){it(this,"parent",new Map);it(this,"rank",new Map)}add(t){this.parent.has(t)||(this.parent.set(t,t),this.rank.set(t,0))}find(t){this.add(t);let n=t;for(;this.parent.get(n)!==n;){const o=this.parent.get(n),r=this.parent.get(o);this.parent.set(n,r),n=r}return n}union(t,n){const o=this.find(t),r=this.find(n);if(o===r)return;const s=this.rank.get(o),i=this.rank.get(r);s<i?this.parent.set(o,r):s>i?this.parent.set(r,o):(this.parent.set(r,o),this.rank.set(o,s+1))}groups(){const t=new Map;for(const n of this.parent.keys()){const o=this.find(n),r=t.get(o);r?r.push(n):t.set(o,[n])}return t}}const Jn=["n","e","s","w"],Qn={n:"s",s:"n",e:"w",w:"e"};function eo(e,t){const n=Jn.indexOf(e),r=((Jn.indexOf(t)-n)%4+4)%4;return[0,90,180,270][r]}const vp=320,to=220,ct=260,no=720,dt=30,oo=30,ut=80,ro=10,kp=60,_p=520,Sp=80,jp=80,so=8,io=new Set(["source","renewable"]);function $p(e){var Dn,Rn,zn,Fn,Hn,Wn;const{elements:t,buses:n,wires:o,library:r,userLayout:s,userBusLayout:i}=e,a=new Map(s),l=new Map(i),d=new Map;for(const w of t)d.set(w.id,w);const u=new Map;for(const w of n)u.set(w.id,w);const f=w=>{const _=d.get(w);if(_)return r.get(_.kind)},h=new Set(n.map(w=>w.id)),g=w=>h.has(w),m=new kr;for(const w of o)m.add(w.ends[0]),m.add(w.ends[1]),m.union(w.ends[0],w.ends[1]);for(const w of t){const _=r.get(w.kind);if(_)for(const $ of _.terminals)m.add(`${w.id}.${$.id}`)}for(const w of n)m.add(w.id);const p=[];for(const[,w]of m.groups())w.length>=2&&p.push(w);const y=new Map;for(const w of p)for(const _ of w)y.set(_,[w]);const v=new Map;for(const w of p){const _=w.filter(g);if(_.length!==0)for(const $ of _){const T=w.filter(E=>E!==$),B=v.get($)??[];B.push(...T),v.set($,B)}}const b=new Map;for(const w of p){const _=w.filter(g);if(_.length!==0)for(const $ of w){if(g($))continue;const T=$.indexOf(".");if(T<0)continue;const B=$.slice(0,T),E=$.slice(T+1),A=b.get(B)??[];for(const R of _)A.some(P=>P.busId===R&&P.pin===E)||A.push({busId:R,pin:E});b.set(B,A)}}const k=[],S=new Set;for(const[w,_]of b)if(new Set(_.map(T=>T.busId)).size>=2){const T=((Rn=r.get(((Dn=d.get(w))==null?void 0:Dn.kind)??""))==null?void 0:Rn.category)==="transformer"?"vertical":"horizontal";k.push({elementId:w,attachments:_,orientation:T}),T==="vertical"&&S.add(w)}const C=new Map,L=(w,_)=>{w!==_&&(C.has(w)||C.set(w,new Set),C.has(_)||C.set(_,new Set),C.get(w).add(_),C.get(_).add(w))};for(const w of o)L(w.ends[0],w.ends[1]);for(const w of t){const _=r.get(w.kind);if(!_||_.terminals.length<2)continue;const $=_.terminals.map(T=>`${w.id}.${T.id}`);for(let T=0;T<$.length;T++)for(let B=T+1;B<$.length;B++)L($[T],$[B])}for(const w of t){if(S.has(w.id))continue;const _=r.get(w.kind);if(!_||_.category!=="transformer"||_.terminals.length<2)continue;const $=_.terminals.map(E=>`${w.id}.${E.id}`),T=new Map;for(const E of $){const A=E.slice(w.id.length+1);T.set(A,new Set);const R=new Set($.filter(z=>z!==E)),P=new Set([E]),H=[E];for(;H.length>0;){const z=H.shift();if(g(z)){T.get(A).add(z);continue}const I=C.get(z);if(I)for(const O of I)P.has(O)||R.has(O)||(P.add(O),H.push(O))}}const B=new Set;for(const E of T.values())for(const A of E)B.add(A);if(B.size>=2){const E=[];for(const[A,R]of T)for(const P of R)E.push({busId:P,pin:A});k.push({elementId:w.id,attachments:E,orientation:"vertical"}),S.add(w.id)}}const te=(w,_)=>{var R;const $=f(_),T=$?$.terminals.map(P=>`${_}.${P.id}`):[],B=w,E=new Set([B,...T]),A=[B];for(;A.length>0;){const P=A.shift(),H=P.indexOf(".");if(H>0){const I=P.slice(0,H),O=d.get(I);if(O){const D=(R=r.get(O.kind))==null?void 0:R.category;if(D&&io.has(D))return!0}}const z=C.get(P);if(z)for(const I of z)E.has(I)||(E.add(I),A.push(I))}return!1};for(const w of k){if(w.orientation!=="horizontal")continue;const _=new Set(w.attachments.map(T=>T.busId));let $=0;for(const T of _)te(T,w.elementId)&&$++;$===1&&(w.orientation="vertical",S.add(w.elementId))}for(const w of t){if(S.has(w.id)||w.kind!=="breaker")continue;const _=r.get(w.kind);if(!_||_.terminals.length!==2)continue;const $=_.terminals.map(E=>`${w.id}.${E.id}`),T=new Map;for(const E of $){const A=E.slice(w.id.length+1),R=new Set($.filter(z=>z!==E)),P=new Set([E]),H=[E];for(;H.length>0;){const z=H.shift();if(g(z)){T.set(A,z);break}const I=C.get(z);if(I)for(const O of I){if(P.has(O)||R.has(O))continue;const D=O.indexOf(".");if(D>0){const G=O.slice(0,D);if(G!==w.id){const ee=d.get(G),J=ee?r.get(ee.kind):void 0;if((J==null?void 0:J.category)==="transformer")continue}}P.add(O),H.push(O)}}}if(new Set(T.values()).size>=2){const E=[];for(const[A,R]of T)E.push({busId:R,pin:A});k.push({elementId:w.id,attachments:E,orientation:"horizontal"})}}const Q=new Map;for(const w of n)Q.set(w.id,new Map);for(const w of k){const _=Array.from(new Set(w.attachments.map($=>$.busId)));for(const $ of _)for(const T of _)$!==T&&((zn=Q.get($))==null||zn.set(T,w))}const ve=w=>{var $;const _=($=r.get(w))==null?void 0:$.category;return _?io.has(_):!1},me=[];for(const w of n){const _=v.get(w.id);if(_)for(const $ of _){if(g($))continue;const T=$.indexOf(".");if(T<0)continue;const B=$.slice(0,T),E=d.get(B);if(E&&ve(E.kind)){me.push(w.id);break}}}me.length===0&&n.length>0&&me.push(n[0].id);const N=new Map;for(const w of me)N.set(w,0);{const w=[...me];for(;w.length>0;){const _=w.shift(),$=N.get(_),T=Q.get(_);if(T)for(const[B,E]of T){if(N.has(B))continue;const A=E.orientation==="horizontal"?$:$+1;N.set(B,A),w.push(B)}}}for(const w of n){if(N.has(w.id))continue;const _=N.size===0?-1:Math.max(...Array.from(N.values()));N.set(w.id,_+1)}const M=new Map;for(const w of n){const _=N.get(w.id),$=M.get(_)??[];$.push(w.id),M.set(_,$)}const se=[...M.keys()].sort((w,_)=>w-_),oe=(w,_,$)=>{const T=`${w.elementId}.${$}`,B=_,E=f(w.elementId),A=new Set;if(E)for(const I of E.terminals)I.id!==$&&A.add(`${w.elementId}.${I.id}`);const R=new Set([T]),P=[{ref:T,dist:0}],H=new Map,z=(I,O,D,G)=>{R.add(I),H.set(I,O),P.push({ref:I,dist:G+D})};for(;P.length>0;){const{ref:I,dist:O}=P.shift();if(I===B){const J=H.get(B);let ce;if(J){const K=J.indexOf(".");if(K>0){const F=J.slice(0,K);F!==w.elementId&&(ce=F)}}return{extent:O,head:ce}}const D=I.indexOf(".");if(D<0)continue;const G=I.slice(0,D),ee=I.slice(D+1);if(!g(G)&&!S.has(G)){const J=f(G),ce=J==null?void 0:J.terminals.find(K=>K.id===ee);if(J&&ce)for(const K of J.terminals){if(K.id===ee)continue;const F=`${G}.${K.id}`;R.has(F)||A.has(F)||z(F,I,Math.abs(ce.y-K.y),O)}}for(const J of y.get(I)??[])for(const ce of J){if(ce===I||R.has(ce)||A.has(ce))continue;const K=g(I)||g(ce);z(ce,I,K?oo:dt,O)}}return{extent:0}},de=(w,_)=>{var I,O,D;const $=(I=Q.get(w))==null?void 0:I.get(_);if(!$||$.orientation==="horizontal")return ct;const T=f($.elementId);if(!T)return ct;const B=(O=$.attachments.find(G=>G.busId===w))==null?void 0:O.pin,E=(D=$.attachments.find(G=>G.busId===_))==null?void 0:D.pin;if(!B||!E)return ct;const A=T.terminals.find(G=>G.id===B),R=T.terminals.find(G=>G.id===E);if(!A||!R)return ct;const P=Math.abs(R.y-A.y),H=oe($,w,B).extent,z=oe($,_,E).extent;return H+P+z},X=new Map;for(const w of k){if(w.orientation!=="vertical")continue;const _=w.attachments.slice().sort((R,P)=>(N.get(R.busId)??0)-(N.get(P.busId)??0));if(_.length<2)continue;const $=_[0].busId,T=_[1].busId,B=_[0].pin,A=oe(w,$,B).head??w.elementId;X.set(A,{lowerBusId:T})}const ue=320,le=new Map,he=(w,_)=>{if(!S.has(w))return!1;const $=k.find(A=>A.elementId===w),T=$==null?void 0:$.attachments.find(A=>A.busId!==_);if(!T)return!1;const B=N.get(_)??0;return(N.get(T.busId)??0)<B},ke=(w,_)=>{const $=X.get(w);if($){const T=le.get($.lowerBusId);if(T!==void 0)return Math.max(_,T+ut)}return Math.max(_,ut)},ye=(w,_)=>{if(le.has(w))return le.get(w);if(_.has(w))return ue;_.add(w);const $=v.get(w)??[];let T=0,B=0;for(const A of $){if(g(A))continue;const R=A.indexOf(".");if(R<0)continue;const P=A.slice(0,R),H=A.slice(R+1);if(he(P,w))continue;const z=f(P);if(!z)continue;const I=z.terminals.find(G=>G.id===H);if(!I)continue;const O=X.get(P);O&&ye(O.lowerBusId,_);const D=ke(P,z.width);I.y>0?T+=D:B+=D}const E=Math.max(ue,Math.max(T,B)+ut);return le.set(w,E),_.delete(w),E};for(const w of n)ye(w.id,new Set);const Re=new Map,rh=(w,_,$)=>{const T=f(_);if(!T)return;const B=`${_}.${$}`,E=T.terminals.filter(P=>P.id!==$).map(P=>`${_}.${P.id}`);if(E.length===0)return;const A=new Set([B,...E]),R=E.slice();for(;R.length>0;){const P=R.shift();if(g(P)&&P!==w){const z=l.get(P);return z?z.at[0]:void 0}for(const z of y.get(P)??[])for(const I of z)I===P||A.has(I)||(A.add(I),R.push(I));const H=P.indexOf(".");if(H>0){const z=P.slice(0,H);if(!g(z)){const I=f(z);if(I)for(const O of I.terminals){const D=`${z}.${O.id}`;A.has(D)||(A.add(D),R.push(D))}}}}},sh=w=>{const _=v.get(w);if(!_||_.length===0)return;const $=l.get(w);if(!$)return;const T=_.flatMap(I=>{if(g(I))return[];const O=I.indexOf(".");if(O<0)return[];const D=I.slice(0,O),G=I.slice(O+1);if(a.has(D))return[];if(he(D,w))return[];const ee=f(D);if(!ee)return[];const J=ee.terminals.find(ce=>ce.id===G);return J?[{elId:D,lib:ee,localTerm:J,isLinker:S.has(D)}]:[]});if(T.length===0)return;const B=[],E=[];for(const I of T)I.localTerm.y>0?B.push(I):E.push(I);const A=I=>I.reduce((O,D)=>O+ke(D.elId,D.lib.width),0),R=Math.max(A(B),A(E))+ut,P=Math.max($.span,R);P!==$.span&&l.set(w,{...$,span:P});const H=l.get(w),z=(I,O)=>{if(I.length===0)return;const D=new Map;for(const W of I){const Y=rh(w,W.elId,W.localTerm.id);Y!==void 0&&D.set(W.elId,Y)}I.sort((W,Y)=>{const fe=D.get(W.elId)??H.at[0],_e=D.get(Y.elId)??H.at[0];if(fe!==_e)return fe-_e;const Ae=ke(W.elId,W.lib.width);return ke(Y.elId,Y.lib.width)-Ae});const G=I.map(W=>ke(W.elId,W.lib.width)),ee=G.reduce((W,Y)=>W+Y,0),J=Math.max(P,ee),ce=(J-ee)/(I.length+1);let K=H.at[0]-J/2+ce;const F=H.at[1]+O*oo;for(let W=0;W<I.length;W++){const Y=I[W],fe=G[W],_e=K+fe/2;Y.isLinker?Re.has(Y.elId)||Re.set(Y.elId,_e):a.set(Y.elId,{at:[ge(_e-Y.localTerm.x),ge(F-Y.localTerm.y)],rot:0,mirror:!1}),K+=fe+ce}};z(B,-1),z(E,1)},ih=w=>{if(a.has(w.elementId)||w.orientation==="horizontal")return;const _=f(w.elementId);if(!_)return;const $=w.attachments.filter(K=>l.has(K.busId));if($.length<2)return;const T=$.slice().sort((K,F)=>(N.get(K.busId)??0)-(N.get(F.busId)??0)),B=T[0].busId,E=l.get(B),A=T[0].pin,R=T[T.length-1].pin,P=_.terminals.find(K=>K.id===A),H=_.terminals.find(K=>K.id===R);if(!P||!H)return;const z=P.y<=H.y?0:180,I=N.get(B)??0,O=$.filter(K=>(N.get(K.busId)??0)===I),D=[];let G=0;for(const K of O){const F=oe(w,K.busId,K.pin);G=Math.max(G,F.extent);const W=F.head?a.get(F.head):void 0;W?D.push(W.at[0]):Re.has(w.elementId)?D.push(Re.get(w.elementId)):D.push(l.get(K.busId).at[0])}let ee;D.length>0?ee=D.reduce((K,F)=>K+F,0)/D.length:Re.has(w.elementId)?ee=Re.get(w.elementId):ee=E.at[0];const J=E.at[1]+G,ce=z===0?[ge(ee-P.x),ge(J-P.y)]:[ge(ee+P.x),ge(J+P.y)];if(a.set(w.elementId,{at:ce,rot:z,mirror:!1}),O.length>1){const K=a.get(w.elementId),F=Le([P.x,P.y],K),W=xt(P.orientation,K);ah(`${w.elementId}.${A}`,F,W,ee)}},ah=(w,_,$,T)=>{const B=new Set([w]);let E=w,A=_,R=$;for(;;){const P=y.get(E)??[];let H,z=!1;for(const Ce of P){if(Ce.length>=3){z=!0;break}const Xe=Ce.find(Ut=>Ut!==E);if(!(!Xe||B.has(Xe))){if(g(Xe)){z=!0;break}H=Xe;break}}if(z||!H)break;const I=H.indexOf(".");if(I<0)break;const O=H.slice(0,I),D=H.slice(I+1);if(g(O)||S.has(O)||a.has(O))break;const G=f(O);if(!G)break;const ee=G.terminals.find(Ce=>Ce.id===D);if(!ee)break;const J=hn(R),ce=[A[0]+J[0]*dt,A[1]+J[1]*dt],K=Qn[R],F=eo(ee.orientation,K),W=Le([ee.x,ee.y],{at:[0,0],rot:F,mirror:!1}),Y=[ge(T-W[0]),ge(ce[1]-W[1])];a.set(O,{at:Y,rot:F,mirror:!1}),B.add(H);const fe=G.terminals.find(Ce=>Ce.id!==D);if(!fe)break;const _e=`${O}.${fe.id}`;B.add(_e);const Ae={at:Y,rot:F,mirror:!1};A=Le([fe.x,fe.y],Ae),R=xt(fe.orientation,Ae),E=_e}},lh=w=>{if(a.has(w.elementId)||w.orientation!=="horizontal")return;const _=f(w.elementId);if(!_)return;const $=w.attachments.filter(O=>l.has(O.busId));if($.length<2)return;const T=$.map(O=>{const D=oe(w,O.busId,O.pin),G=D.head?a.get(D.head):void 0,ee=G?G.at[0]:l.get(O.busId).at[0];return{att:O,x:ee,extent:D.extent}});T.sort((O,D)=>O.x-D.x);const B=T[0],E=T[T.length-1],A=_.terminals.find(O=>O.id===B.att.pin),R=_.terminals.find(O=>O.id===E.att.pin);if(!A||!R)return;const P=A.y<=R.y?270:90,H=(B.x+E.x)/2,I=l.get(B.att.busId).at[1]+Math.max(B.extent,E.extent);a.set(w.elementId,{at:[ge(H),ge(I)],rot:P,mirror:!1})},ch=100;let $t=to;for(let w=0;w<se.length;w++){const _=se[w],$=M.get(_);let T;if(w===0)T=to;else{const E=M.get(se[w-1]);let A=0;for(const R of E)for(const P of $)(Fn=Q.get(R))!=null&&Fn.get(P)&&(A=Math.max(A,de(R,P)));A===0&&(A=ct),T=$t+A}$t=T;let B=vp;for(const E of $){if(l.has(E)){$t=Math.max($t,l.get(E).at[1]);continue}let A;if(w>0){const P=M.get(se[w-1]),H=[];for(const z of P){const I=(Hn=Q.get(z))==null?void 0:Hn.get(E);if(!I||I.orientation!=="vertical")continue;const O=(Wn=I.attachments.find(G=>G.busId===z))==null?void 0:Wn.pin;if(!O)continue;const D=oe(I,z,O);D.head&&a.has(D.head)?H.push(a.get(D.head).at[0]):Re.has(I.elementId)?H.push(Re.get(I.elementId)):H.push(l.get(z).at[0])}H.length>0&&(A=H.reduce((z,I)=>z+I,0)/H.length)}if(A===void 0){const P=le.get(E)??no;A=B+P/2,B+=P+ch}const R=le.get(E)??no;l.set(E,{at:[ge(A),ge(T)],rot:0,span:R,axis:mn(0)})}for(const E of $)sh(E);if(w>0)for(const E of k)a.has(E.elementId)||!E.attachments.some(R=>$.includes(R.busId))||ih(E);for(const E of k)E.orientation!=="horizontal"||a.has(E.elementId)||!E.attachments.every(R=>$.includes(R.busId))||lh(E)}const dh=w=>{if(g(w))return l.has(w);const _=w.indexOf(".");return _<0?!1:a.has(w.slice(0,_))};let Xt=!0,uh=t.length+4;for(;Xt&&uh-- >0;){Xt=!1;for(const w of p){if(w.length<2)continue;const _=[],$=new Map;for(const F of w){if(g(F))continue;const W=F.indexOf(".");if(W<0)continue;const Y=F.slice(0,W),fe=F.slice(W+1);if(a.has(Y)){_.push(F);continue}if(S.has(Y)||$.has(Y))continue;const _e=f(Y);if(!_e)continue;const Ae=_e.terminals.find(Ce=>Ce.id===fe);Ae&&$.set(Y,{ref:F,elId:Y,lib:_e,localTerm:Ae})}if($.size===0||_.length===0)continue;const T=[...$.values()],B=new Map;for(const F of T)for(const W of y.get(F.ref)??[])for(const Y of W){if(Y===F.ref||g(Y)||!dh(Y))continue;const fe=Y;B.set(fe,(B.get(fe)??0)+1)}let E;if(B.size>0){let F=-1;for(const[W,Y]of B)(Y>F||Y===F&&(E===void 0||W<E))&&(F=Y,E=W)}if(E||(E=[..._].sort()[0]),!E)continue;const A=E.indexOf("."),R=E.slice(0,A),P=E.slice(A+1),H=f(R),z=a.get(R);if(!H||!z)continue;const I=H.terminals.find(F=>F.id===P);if(!I)continue;const O=Le([I.x,I.y],z),D=xt(I.orientation,z),G=hn(D),ee=[-G[1],G[0]];T.sort((F,W)=>F.elId.localeCompare(W.elId));const J=T.map(F=>Math.max(F.lib.width,ut));let K=-J.reduce((F,W)=>F+W,0)/2;for(let F=0;F<T.length;F++){const W=T[F],Y=J[F],fe=K+Y/2;K+=Y;const _e=Qn[D],Ae=eo(W.localTerm.orientation,_e),Ce=Le([W.localTerm.x,W.localTerm.y],{at:[0,0],rot:Ae,mirror:!1}),Xe=[O[0]+G[0]*dt+ee[0]*fe,O[1]+G[1]*dt+ee[1]*fe],Ut=[ge(Xe[0]-Ce[0]),ge(Xe[1]-Ce[1])];a.set(W.elId,{at:Ut,rot:Ae,mirror:!1}),Xt=!0}}}let Vt=0;for(const w of t){if(a.has(w.id))continue;const _=Vt%so,$=Math.floor(Vt/so);a.set(w.id,{at:[ge(kp+_*Sp),ge(_p+$*jp)],rot:0,mirror:!1}),Vt++}return{devices:a,buses:l}}function ge(e){return Math.round(e/ro)*ro}function Ep(e,t){const n=e.ends[0],o=e.ends[1],r=ao(n,t),s=ao(o,t);if(r||s){const l=r?n:o,u=Jt(r?o:n,t);if(!u)return null;const f=t.buses.get(l);if(!f)return null;const{axis:h,at:g,span:m}=f.geometry,p=m/2;let y;if(h==="x")y=[Ot(u[0],g[0]-p,g[0]+p),g[1]];else{const v=Ot(u[1],g[1]-p,g[1]+p);y=[g[0],v]}return{wireId:e.id,path:co(u,y)}}const i=Jt(n,t),a=Jt(o,t);return!i||!a?null:{wireId:e.id,path:co(i,a)}}function ao(e,t){return!e.includes(".")&&t.buses.has(e)}function Jt(e,t){if(!e.includes(".")){const o=t.buses.get(e);return o?o.geometry.at:null}const n=t.terminals.get(e);return n?n.world:null}function lo(e,t,n){if(!e.includes(".")){const r=n.buses.get(e);if(!r)return null;const{axis:s,at:i,span:a}=r.geometry;if(!t)return[i[0],i[1]];const l=a/2;if(s==="x")return[Ot(t[0],i[0]-l,i[0]+l),i[1]];const d=Ot(t[1],i[1]-l,i[1]+l);return[i[0],d]}const o=n.terminals.get(e);return o?[o.world[0],o.world[1]]:null}function co(e,t){return e[0]===t[0]||e[1]===t[1]?[e,t]:[e,[e[0],t[1]],t]}function Ot(e,t,n){return e<t?t:e>n?n:e}const _r="ammeter",Sr="电流表 (A)",jr="measurement",$r="-22 -42 44 44",Er=44,Nr=44,Tr='<ellipse cx="0" cy="-20" rx="20" ry="20" fill="none" stroke="black" stroke-width="1"/><text x="0" y="-15" text-anchor="middle" font-family="Liberation Sans, Arial, sans-serif" font-size="14">A</text>',Cr=[{id:"t_top",x:0,y:-40,orientation:"n"}],Ir={kind:"inline"},Np={id:_r,name:Sr,category:jr,viewBox:$r,width:Er,height:Nr,svg:Tr,terminals:Cr,source:Ir},Tp=Object.freeze(Object.defineProperty({__proto__:null,category:jr,default:Np,height:Nr,id:_r,name:Sr,source:Ir,svg:Tr,terminals:Cr,viewBox:$r,width:Er},Symbol.toStringTag,{value:"Module"})),Ar="arc-suppression-coil",Mr="消弧线圈",Pr="grounding",Or="中性点谐振接地:电感线圈连接到地",Lr="-12 -32 24 67",Br=24,Dr=67,Rr='<line x1="0" y1="-30" x2="0" y2="-12" fill="none" stroke="black" stroke-width="1"/><path d="M 0 -12 A 4 4 0 0 1 0 -4 A 4 4 0 0 1 0 4 A 4 4 0 0 1 0 12" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="12" x2="0" y2="20" fill="none" stroke="black" stroke-width="1"/><line x1="-10" y1="20" x2="10" y2="20" fill="none" stroke="black" stroke-width="1"/><line x1="-7" y1="24" x2="7" y2="24" fill="none" stroke="black" stroke-width="1"/><line x1="-4" y1="28" x2="4" y2="28" fill="none" stroke="black" stroke-width="1"/><line x1="-1.5" y1="32" x2="1.5" y2="32" fill="none" stroke="black" stroke-width="1"/>',zr=[{id:"t_top",x:0,y:-30,orientation:"n"}],Fr={kind:"inline"},Cp={id:Ar,name:Mr,category:Pr,description:Or,viewBox:Lr,width:Br,height:Dr,svg:Rr,terminals:zr,source:Fr},Ip=Object.freeze(Object.defineProperty({__proto__:null,category:Pr,default:Cp,description:Or,height:Dr,id:Ar,name:Mr,source:Fr,svg:Rr,terminals:zr,viewBox:Lr,width:Br},Symbol.toStringTag,{value:"Module"})),Hr="arrester",Wr="避雷器 (FBL)",Gr="protection",qr="-7 -22 14 44",Kr=14,Yr=44,Xr='<line x1="0" y1="-20" x2="0" y2="-5" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="10" x2="0" y2="20" fill="none" stroke="black" stroke-width="1"/><polygon points="-2,-8 2,-8 0,-2" fill="black" stroke="black" stroke-width="1"/><rect x="-5" y="-10" width="10" height="20" rx="0" ry="0" fill="none" stroke="black" stroke-width="1"/>',Vr=[{id:"t1",x:0,y:-20,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],Ur={kind:"elmt",path:"91_en_60617/en_60617_07/en_60617_07_22/en_60617_07_22_03.elmt",qetEnglishName:"Surge diverter; Lightning arrester"},Ap={id:Hr,name:Wr,category:Gr,viewBox:qr,width:Kr,height:Yr,svg:Xr,terminals:Vr,source:Ur},Mp=Object.freeze(Object.defineProperty({__proto__:null,category:Gr,default:Ap,height:Yr,id:Hr,name:Wr,source:Ur,svg:Xr,terminals:Vr,viewBox:qr,width:Kr},Symbol.toStringTag,{value:"Module"})),Zr="async-motor",Jr="异步电动机",Qr="load",es="-62 -82 64 84",ts=64,ns=84,os='<ellipse cx="-30" cy="-30" rx="30" ry="30" fill="none" stroke="black" stroke-width="1"/><text x="-34" y="-24.8" font-family="Liberation Sans, Arial, sans-serif" font-size="14" fill="#000000">M</text><text x="-45" y="-7.8" font-family="Liberation Sans, Arial, sans-serif" font-size="14" fill="#000000">3</text><path d="M -25 -20 A 5 2.5 0 0 0 -35 -20" fill="none" stroke="black" stroke-width="1"/><path d="M -25 -20 A 5 2.5 0 0 0 -15 -20" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-80" x2="-30" y2="-60" fill="none" stroke="black" stroke-width="1"/><line x1="-50" y1="-80" x2="-50" y2="-53" fill="none" stroke="black" stroke-width="1"/><line x1="-10" y1="-80" x2="-10" y2="-53" fill="none" stroke="black" stroke-width="1"/>',rs=[{id:"t1",x:-50,y:-80,orientation:"n"},{id:"t2",x:-10,y:-80,orientation:"n"},{id:"t3",x:-30,y:-80,orientation:"n"}],ss={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_08/en_60617_06_08_01.elmt",qetEnglishName:"Induction motor, three-phase, squirrel cage"},Pp={id:Zr,name:Jr,category:Qr,viewBox:es,width:ts,height:ns,svg:os,terminals:rs,source:ss},Op=Object.freeze(Object.defineProperty({__proto__:null,category:Qr,default:Pp,height:ns,id:Zr,name:Jr,source:ss,svg:os,terminals:rs,viewBox:es,width:ts},Symbol.toStringTag,{value:"Module"})),is="autotransformer",as="自耦变压器",ls="transformer",cs="-62 -112 64 144",ds=64,us=144,fs='<ellipse cx="-30" cy="-30" rx="30" ry="30" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-110" x2="-30" y2="-90" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="0" x2="-30" y2="20" fill="none" stroke="black" stroke-width="1"/><path d="M 0 -30 A 30 60 0 0 0 -30 -90" fill="none" stroke="black" stroke-width="1"/>',ms=[{id:"t1",x:-30,y:-110,orientation:"n"},{id:"t_bottom",x:-30,y:20,orientation:"s"}],hs={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_09/en_60617_06_09_06.elmt",qetEnglishName:"Auto-transformer, general symbol"},Lp={id:is,name:as,category:ls,viewBox:cs,width:ds,height:us,svg:fs,terminals:ms,source:hs},Bp=Object.freeze(Object.defineProperty({__proto__:null,category:ls,default:Lp,height:us,id:is,name:as,source:hs,svg:fs,terminals:ms,viewBox:cs,width:ds},Symbol.toStringTag,{value:"Module"})),ps="battery",gs="电池储能",xs="storage",ys="-12 -12 29 24",bs=29,ws=24,vs='<line x1="-10" y1="0" x2="0" y2="0" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="-5" x2="0" y2="5" fill="none" stroke="black" stroke-width="1"/><line x1="5" y1="-10" x2="5" y2="10" fill="none" stroke="black" stroke-width="1"/><line x1="5" y1="0" x2="15" y2="0" fill="none" stroke="black" stroke-width="1"/>',ks=[{id:"t_left",x:-10,y:0,orientation:"w"},{id:"t_right",x:15,y:0,orientation:"e"}],_s=[{name:"E",label:"容量",type:"number",unit:"kWh"}],Ss={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_15/en_60617_06_15_01.elmt",qetEnglishName:"Battery cell"},Dp={id:ps,name:gs,category:xs,viewBox:ys,width:bs,height:ws,svg:vs,terminals:ks,params:_s,source:Ss},Rp=Object.freeze(Object.defineProperty({__proto__:null,category:xs,default:Dp,height:ws,id:ps,name:gs,params:_s,source:Ss,svg:vs,terminals:ks,viewBox:ys,width:bs},Symbol.toStringTag,{value:"Module"})),js="breaker",$s="断路器 (QF)",Es="switching",Ns="-7 -22 15 46",Ts=15,Cs=46,Is='<polyline points="0,20 0,10 -5,-10" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="-20" x2="0" y2="-10" fill="none" stroke="black" stroke-width="1"/><line x1="2" y1="-8" x2="-2" y2="-12" fill="none" stroke="black" stroke-width="1"/><line x1="2" y1="-12" x2="-2" y2="-8" fill="none" stroke="black" stroke-width="1"/><text x="2" y="-10.8" font-family="Liberation Sans, Arial, sans-serif" font-size="6" fill="#000000">1</text><text x="3" y="21.2" font-family="Liberation Sans, Arial, sans-serif" font-size="6" fill="#000000">2</text>',As=[{id:"t1",x:0,y:-20,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],Ms=[{name:"open",type:"boolean",default:!1,label:"断开"}],Ps={x:6,y:-2,anchor:"start"},Os={kind:"elmt",path:"11_singlepole/200_fuses_protective_gears/11_circuit_breakers/disjoncteur1.elmt",qetEnglishName:"Circuit-breaker"},zp={id:js,name:$s,category:Es,viewBox:Ns,width:Ts,height:Cs,svg:Is,terminals:As,state:Ms,label:Ps,source:Os},Fp=Object.freeze(Object.defineProperty({__proto__:null,category:Es,default:zp,height:Cs,id:js,label:Ps,name:$s,source:Os,state:Ms,svg:Is,terminals:As,viewBox:Ns,width:Ts},Symbol.toStringTag,{value:"Module"})),Ls="busbar",Bs="母线段",Ds="busbar",Rs="可拉伸单母线段,多设备挂接",zs="-42 -4 84 8",Fs=84,Hs=8,Ws='<line x1="-40" y1="0" x2="40" y2="0" stroke="black" stroke-width="3" stroke-linecap="round" fill="none"/>',Gs=[{id:"tap",x:0,y:0,orientation:"n"}],qs={axis:"x",minLength:20,naturalSpan:80},Ks=[{name:"Un",label:"额定电压",type:"number",unit:"kV",showOnCanvas:!0}],Ys={x:0,y:-6,anchor:"middle"},Xs={kind:"inline"},Hp={id:Ls,name:Bs,category:Ds,description:Rs,viewBox:zs,width:Fs,height:Hs,svg:Ws,terminals:Gs,stretchable:qs,params:Ks,label:Ys,source:Xs},Wp=Object.freeze(Object.defineProperty({__proto__:null,category:Ds,default:Hp,description:Rs,height:Hs,id:Ls,label:Ys,name:Bs,params:Ks,source:Xs,stretchable:qs,svg:Ws,terminals:Gs,viewBox:zs,width:Fs},Symbol.toStringTag,{value:"Module"})),Vs="contactor",Us="接触器 (KM)",Zs="motor-control",Js="主回路接触器, 通常配热继电器和电机使用。",Qs="-10 -42 15 64",ei=15,ti=64,ni='<line x1="0" y1="-20" x2="0" y2="-40" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="0" x2="0" y2="20" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="0" x2="-8" y2="-23" fill="none" stroke="black" stroke-width="1"/><path d="M 0 -24.5 A 2.5 2.5 0 0 0 0 -19.5" fill="none" stroke="black" stroke-width="1"/>',oi=[{id:"t1",x:0,y:-40,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],ri=[{name:"open",type:"boolean",default:!0,label:"断开"}],si={kind:"elmt",path:"91_en_60617/en_60617_07/en_60617_07_13/en_60617_07_13_02.elmt",qetEnglishName:"Contactor; Main make contact of a contactor"},Gp={id:Vs,name:Us,category:Zs,description:Js,viewBox:Qs,width:ei,height:ti,svg:ni,terminals:oi,state:ri,source:si},qp=Object.freeze(Object.defineProperty({__proto__:null,category:Zs,default:Gp,description:Js,height:ti,id:Vs,name:Us,source:si,state:ri,svg:ni,terminals:oi,viewBox:Qs,width:ei},Symbol.toStringTag,{value:"Module"})),ii="converter-bidir",ai="双向变流器 (PCS)",li="renewable",ci="储能变流器:双向 AC ↔ DC",di="-42 -42 44 48",ui=44,fi=48,mi='<line x1="-40" y1="0" x2="0" y2="-40" fill="none" stroke="black" stroke-width="1"/><rect x="-40" y="-40" width="40" height="40" rx="0" ry="0" fill="none" stroke="black" stroke-width="1"/><line x1="-20" y1="-10" x2="-4" y2="-10" fill="none" stroke="black" stroke-width="1"/><line x1="-20" y1="-6" x2="-14" y2="-6" fill="none" stroke="black" stroke-width="1"/><line x1="-10" y1="-6" x2="-4" y2="-6" fill="none" stroke="black" stroke-width="1"/><path d="M -25 -30 A 5 2.5 0 0 0 -35 -30" fill="none" stroke="black" stroke-width="1"/><path d="M -25 -30 A 5 2.5 0 0 0 -15 -30" fill="none" stroke="black" stroke-width="1"/><polyline points="-28,-4 -32,0 -28,4" fill="none" stroke="black" stroke-width="1"/><polyline points="-16,-4 -12,0 -16,4" fill="none" stroke="black" stroke-width="1"/>',hi=[{id:"t_ac",x:-20,y:-40,orientation:"n"},{id:"t_dc",x:-20,y:0,orientation:"s"}],pi=[{name:"S",label:"容量",type:"number",unit:"MVA"}],gi={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_14/en_60617_06_14_06.elmt",qetEnglishName:"Rectifier/inverter"},Kp={id:ii,name:ai,category:li,description:ci,viewBox:di,width:ui,height:fi,svg:mi,terminals:hi,params:pi,source:gi},Yp=Object.freeze(Object.defineProperty({__proto__:null,category:li,default:Kp,description:ci,height:fi,id:ii,name:ai,params:pi,source:gi,svg:mi,terminals:hi,viewBox:di,width:ui},Symbol.toStringTag,{value:"Module"})),xi="ct",yi="电流互感器 (CT)",bi="instrument-transformer",wi="-42 -62 54 64",vi=54,ki=64,_i='<line x1="-30" y1="-60" x2="-30" y2="0" fill="none" stroke="black" stroke-width="1"/><line x1="-20" y1="-30" x2="10" y2="-30" fill="none" stroke="black" stroke-width="1"/><ellipse cx="-30" cy="-30" rx="10" ry="10" fill="none" stroke="black" stroke-width="1"/><line x1="-10" y1="-20" x2="0" y2="-40" fill="none" stroke="black" stroke-width="1"/><line x1="-5" y1="-20" x2="5" y2="-40" fill="none" stroke="black" stroke-width="1"/>',Si=[{id:"t1",x:-30,y:0,orientation:"s"},{id:"t2",x:-30,y:-60,orientation:"n"}],ji={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_09/en_60617_06_09_10.elmt",qetEnglishName:"Current transformer, general symbol"},Xp={id:xi,name:yi,category:bi,viewBox:wi,width:vi,height:ki,svg:_i,terminals:Si,source:ji},Vp=Object.freeze(Object.defineProperty({__proto__:null,category:bi,default:Xp,height:ki,id:xi,name:yi,source:ji,svg:_i,terminals:Si,viewBox:wi,width:vi},Symbol.toStringTag,{value:"Module"})),$i="dc-combiner",Ei="直流汇流箱",Ni="renewable",Ti="光伏组串汇流箱 (4 路输入示例)。",Ci="-27 -32 54 64",Ii=54,Ai=64,Mi='<rect x="-25" y="-15" width="50" height="30" fill="none" stroke="black" stroke-width="1"/><line x1="-18" y1="-30" x2="-18" y2="-15" stroke="black" stroke-width="1" fill="none"/><line x1="-6" y1="-30" x2="-6" y2="-15" stroke="black" stroke-width="1" fill="none"/><line x1="6" y1="-30" x2="6" y2="-15" stroke="black" stroke-width="1" fill="none"/><line x1="18" y1="-30" x2="18" y2="-15" stroke="black" stroke-width="1" fill="none"/><line x1="0" y1="15" x2="0" y2="30" stroke="black" stroke-width="1" fill="none"/><text x="-9" y="5" font-family="Liberation Sans, Arial, sans-serif" font-size="7" fill="#000000">DC</text>',Pi=[{id:"t_s1",x:-18,y:-30,orientation:"n"},{id:"t_s2",x:-6,y:-30,orientation:"n"},{id:"t_s3",x:6,y:-30,orientation:"n"},{id:"t_s4",x:18,y:-30,orientation:"n"},{id:"t_dc",x:0,y:30,orientation:"s"}],Oi={kind:"inline"},Up={id:$i,name:Ei,category:Ni,description:Ti,viewBox:Ci,width:Ii,height:Ai,svg:Mi,terminals:Pi,source:Oi},Zp=Object.freeze(Object.defineProperty({__proto__:null,category:Ni,default:Up,description:Ti,height:Ai,id:$i,name:Ei,source:Oi,svg:Mi,terminals:Pi,viewBox:Ci,width:Ii},Symbol.toStringTag,{value:"Module"})),Li="dc-disconnector",Bi="直流隔离开关",Di="switching",Ri="DC isolating switch — 光伏组串 / 储能 直流侧隔离。",zi="-12 -32 30 64",Fi=30,Hi=64,Wi='<line x1="0" y1="-30" x2="0" y2="-12" stroke="black" stroke-width="1" fill="none"/><line x1="0" y1="0" x2="0" y2="30" stroke="black" stroke-width="1" fill="none"/><line x1="0" y1="0" x2="-8" y2="-15" stroke="black" stroke-width="1" fill="none"/><line x1="6" y1="-4" x2="14" y2="-4" stroke="black" stroke-width="1" fill="none"/><line x1="6" y1="-1" x2="9" y2="-1" stroke="black" stroke-width="0.8" fill="none"/><line x1="11" y1="-1" x2="14" y2="-1" stroke="black" stroke-width="0.8" fill="none"/>',Gi=[{id:"t1",x:0,y:-30,orientation:"n"},{id:"t2",x:0,y:30,orientation:"s"}],qi=[{name:"open",type:"boolean",default:!1,label:"断开"}],Ki={kind:"inline"},Jp={id:Li,name:Bi,category:Di,description:Ri,viewBox:zi,width:Fi,height:Hi,svg:Wi,terminals:Gi,state:qi,source:Ki},Qp=Object.freeze(Object.defineProperty({__proto__:null,category:Di,default:Jp,description:Ri,height:Hi,id:Li,name:Bi,source:Ki,state:qi,svg:Wi,terminals:Gi,viewBox:zi,width:Fi},Symbol.toStringTag,{value:"Module"})),Yi="disconnector",Xi="隔离开关 (QS)",Vi="switching",Ui="-10 -42 15 64",Zi=15,Ji=64,Qi='<line x1="0" y1="-20" x2="0" y2="-40" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="0" x2="0" y2="20" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="0" x2="-8" y2="-23" fill="none" stroke="black" stroke-width="1"/><line x1="-3" y1="-20" x2="3" y2="-20" fill="none" stroke="black" stroke-width="1"/>',ea=[{id:"t1",x:0,y:-40,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],ta=[{name:"open",type:"boolean",default:!1,label:"断开"}],na={x:6,y:-10,anchor:"start"},oa={kind:"elmt",path:"91_en_60617/en_60617_07/en_60617_07_13/en_60617_07_13_06.elmt",qetEnglishName:"Disconnector; Isolator"},eg={id:Yi,name:Xi,category:Vi,viewBox:Ui,width:Zi,height:Ji,svg:Qi,terminals:ea,state:ta,label:na,source:oa},tg=Object.freeze(Object.defineProperty({__proto__:null,category:Vi,default:eg,height:Ji,id:Yi,label:na,name:Xi,source:oa,state:ta,svg:Qi,terminals:ea,viewBox:Ui,width:Zi},Symbol.toStringTag,{value:"Module"})),ra="earth",sa="接地",ia="busbar",aa="-12 -17 24 34",la=24,ca=34,da='<line x1="-10" y1="0" x2="10" y2="0" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="-15" x2="0" y2="0" fill="none" stroke="black" stroke-width="1"/><line x1="-7" y1="5" x2="7" y2="5" fill="none" stroke="black" stroke-width="1"/><line x1="-4" y1="10" x2="4" y2="10" fill="none" stroke="black" stroke-width="1"/><line x1="0.5" y1="15" x2="-0.5" y2="15" fill="none" stroke="black" stroke-width="1"/>',ua=[{id:"t1",x:0,y:-15,orientation:"n"}],fa={kind:"elmt",path:"91_en_60617/en_60617_02/en_60617_02_15/en_60617_02_15_01.elmt",qetEnglishName:"Earth or ground, general symbol"},ng={id:ra,name:sa,category:ia,viewBox:aa,width:la,height:ca,svg:da,terminals:ua,source:fa},og=Object.freeze(Object.defineProperty({__proto__:null,category:ia,default:ng,height:ca,id:ra,name:sa,source:fa,svg:da,terminals:ua,viewBox:aa,width:la},Symbol.toStringTag,{value:"Module"})),ma="earthing-switch",ha="接地刀闸 (QE)",pa="switching",ga="隔离开关 + 接地连接,单端口",xa="-12 -32 24 64",ya=24,ba=64,wa='<line x1="0" y1="-30" x2="0" y2="-12" stroke="black" stroke-width="1" fill="none"/><line x1="0" y1="-12" x2="-9" y2="9" stroke="black" stroke-width="1" fill="none"/><line x1="-3" y1="-12" x2="3" y2="-12" stroke="black" stroke-width="1" fill="none"/><line x1="-10" y1="14" x2="10" y2="14" stroke="black" stroke-width="1" fill="none"/><line x1="-7" y1="19" x2="7" y2="19" stroke="black" stroke-width="1" fill="none"/><line x1="-4" y1="24" x2="4" y2="24" stroke="black" stroke-width="1" fill="none"/><line x1="-1.5" y1="29" x2="1.5" y2="29" stroke="black" stroke-width="1" fill="none"/>',va=[{id:"t_top",x:0,y:-30,orientation:"n"}],ka=[{name:"open",type:"boolean",default:!0,label:"断开"}],_a={x:12,y:-8,anchor:"start"},Sa={kind:"inline"},rg={id:ma,name:ha,category:pa,description:ga,viewBox:xa,width:ya,height:ba,svg:wa,terminals:va,state:ka,label:_a,source:Sa},sg=Object.freeze(Object.defineProperty({__proto__:null,category:pa,default:rg,description:ga,height:ba,id:ma,label:_a,name:ha,source:Sa,state:ka,svg:wa,terminals:va,viewBox:xa,width:ya},Symbol.toStringTag,{value:"Module"})),ja="energy-meter",$a="电能表 (Wh)",Ea="measurement",Na="有功电能表 (kWh) — 服务入口 / 子表。",Ta="-22 -36 44 72",Ca=44,Ia=72,Aa='<text x="-10" y="19.2" font-family="Liberation Sans, Arial, sans-serif" font-size="9" fill="#000000">Wh</text><rect x="-20" y="-10" width="40" height="40" rx="0" ry="0" fill="none" stroke="black" stroke-width="1"/><rect x="-20" y="-30" width="40" height="20" rx="0" ry="0" fill="none" stroke="black" stroke-width="1"/>',Ma=[{id:"t1",x:0,y:-34,orientation:"n"},{id:"t2",x:0,y:34,orientation:"s"}],Pa={kind:"elmt",path:"11_singlepole/500_home_installation/40_meters/wattheuremetre_08-04-03_en60617.elmt",qetEnglishName:"Watt hour meter (en_60617)"},ig={id:ja,name:$a,category:Ea,description:Na,viewBox:Ta,width:Ca,height:Ia,svg:Aa,terminals:Ma,source:Pa},ag=Object.freeze(Object.defineProperty({__proto__:null,category:Ea,default:ig,description:Na,height:Ia,id:ja,name:$a,source:Pa,svg:Aa,terminals:Ma,viewBox:Ta,width:Ca},Symbol.toStringTag,{value:"Module"})),Oa="ev-charger",La="EV 充电桩",Ba="load",Da="电动汽车充电站 / 充电桩。",Ra="-17 -27 34 49",za=34,Fa=49,Ha='<line x1="0" y1="-25" x2="0" y2="-15" stroke="black" stroke-width="1" fill="none"/><rect x="-15" y="-15" width="30" height="35" fill="none" stroke="black" stroke-width="1"/><rect x="-9" y="-8" width="14" height="6" fill="none" stroke="black" stroke-width="0.8"/><rect x="5" y="-7" width="2" height="4" fill="black"/><text x="-9" y="13" font-family="Liberation Sans, Arial, sans-serif" font-size="7" fill="#000000">EV</text>',Wa=[{id:"t_top",x:0,y:-25,orientation:"n"}],Ga={kind:"inline"},lg={id:Oa,name:La,category:Ba,description:Da,viewBox:Ra,width:za,height:Fa,svg:Ha,terminals:Wa,source:Ga},cg=Object.freeze(Object.defineProperty({__proto__:null,category:Ba,default:lg,description:Da,height:Fa,id:Oa,name:La,source:Ga,svg:Ha,terminals:Wa,viewBox:Ra,width:za},Symbol.toStringTag,{value:"Module"})),qa="frequency-meter",Ka="频率表 (Hz)",Ya="measurement",Xa="-22 -42 44 44",Va=44,Ua=44,Za='<ellipse cx="0" cy="-20" rx="20" ry="20" fill="none" stroke="black" stroke-width="1"/><text x="-8" y="-8.8" font-family="Liberation Sans, Arial, sans-serif" font-size="9" fill="#000000">Hz</text>',Ja=[{id:"t_top",x:0,y:-40,orientation:"n"}],Qa={kind:"elmt",path:"91_en_60617/en_60617_08/en_60617_08_02/en_60617_08_02_07.elmt",qetEnglishName:"Frequency meter"},dg={id:qa,name:Ka,category:Ya,viewBox:Xa,width:Va,height:Ua,svg:Za,terminals:Ja,source:Qa},ug=Object.freeze(Object.defineProperty({__proto__:null,category:Ya,default:dg,height:Ua,id:qa,name:Ka,source:Qa,svg:Za,terminals:Ja,viewBox:Xa,width:Va},Symbol.toStringTag,{value:"Module"})),el="fuse",tl="熔断器 (FU)",nl="switching",ol="-7 -32 14 64",rl=14,sl=64,il='<line x1="0" y1="-30" x2="0" y2="30" fill="none" stroke="black" stroke-width="1"/><rect x="-5" y="-15" width="10" height="30" rx="0" ry="0" fill="none" stroke="black" stroke-width="1"/>',al=[{id:"t1",x:0,y:30,orientation:"s"},{id:"t2",x:0,y:-30,orientation:"n"}],ll=[{name:"blown",type:"boolean",default:!1,label:"熔断"}],cl={x:7,y:-2,anchor:"start"},dl={kind:"elmt",path:"91_en_60617/en_60617_07/en_60617_07_21/en_60617_07_21_01.elmt",qetEnglishName:"Fuse, general symbol"},fg={id:el,name:tl,category:nl,viewBox:ol,width:rl,height:sl,svg:il,terminals:al,state:ll,label:cl,source:dl},mg=Object.freeze(Object.defineProperty({__proto__:null,category:nl,default:fg,height:sl,id:el,label:cl,name:tl,source:dl,state:ll,svg:il,terminals:al,viewBox:ol,width:rl},Symbol.toStringTag,{value:"Module"})),ul="generator",fl="发电机 (G)",ml="source",hl="-42 -42 44 44",pl=44,gl=44,xl='<rect x="-40" y="-40" width="40" height="40" rx="0" ry="0" fill="none" stroke="black" stroke-width="1"/><text x="-24" y="-8.8" font-family="Liberation Sans, Arial, sans-serif" font-size="14" fill="#000000">G</text>',yl=[{id:"t_bottom",x:-20,y:0,orientation:"s"}],bl={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_16/en_60617_06_16_01.elmt",qetEnglishName:"Generator, general symbol"},hg={id:ul,name:fl,category:ml,viewBox:hl,width:pl,height:gl,svg:xl,terminals:yl,source:bl},pg=Object.freeze(Object.defineProperty({__proto__:null,category:ml,default:hg,height:gl,id:ul,name:fl,source:bl,svg:xl,terminals:yl,viewBox:hl,width:pl},Symbol.toStringTag,{value:"Module"})),wl="gfci-breaker",vl="GFCI 断路器 (RCBO)",kl="protection",_l="剩余电流断路器带过流保护 (UL943 / IEC 61009)。北美 GFCI / 欧洲 RCBO。",Sl="-18 -22 22 44",jl=22,$l=44,El='<text x="-14" y="13.8" font-family="Liberation Sans, Arial, sans-serif" font-size="6" fill="#000000">IΔ</text><line x1="2" y1="-12" x2="-2" y2="-8" fill="none" stroke="black" stroke-width="1"/><line x1="-2" y1="-12" x2="2" y2="-8" fill="none" stroke="black" stroke-width="1"/><polyline points="-5,-10 0,10 0,20" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="-20" x2="0" y2="-10" fill="none" stroke="black" stroke-width="1"/><line x1="-4" y1="-4" x2="-8" y2="-4" fill="none" stroke="black" stroke-width="0.4"/><line x1="-8" y1="-4" x2="-8" y2="-8" fill="none" stroke="black" stroke-width="0.4"/><line x1="-13" y1="-8" x2="-8" y2="-8" fill="none" stroke="black" stroke-width="0.4"/><line x1="-13" y1="-8" x2="-13" y2="-4" fill="none" stroke="black" stroke-width="0.4"/><line x1="-16" y1="-4" x2="-13" y2="-4" fill="none" stroke="black" stroke-width="0.4"/><path d="M -8 1 A 2.5 3.5 0 0 0 -13 1" fill="none" stroke="black" stroke-width="0.4"/><line x1="-8" y1="1" x2="-2" y2="1" fill="none" stroke="black" stroke-width="0.4"/><line x1="-16" y1="1" x2="-13" y2="1" fill="none" stroke="black" stroke-width="0.4"/>',Nl=[{id:"t1",x:0,y:-20,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],Tl=[{name:"open",type:"boolean",default:!1,label:"断开"}],Cl=[{name:"In",label:"额定电流",type:"number",unit:"A"},{name:"IDn",label:"剩余动作电流",type:"number",unit:"mA",default:30}],Il={kind:"elmt",path:"11_singlepole/200_fuses_protective_gears/50_residual_current_circuit_breaker/rcbo.elmt",qetEnglishName:"Residual Circuit Breaker with Overload"},gg={id:wl,name:vl,category:kl,description:_l,viewBox:Sl,width:jl,height:$l,svg:El,terminals:Nl,state:Tl,params:Cl,source:Il},xg=Object.freeze(Object.defineProperty({__proto__:null,category:kl,default:gg,description:_l,height:$l,id:wl,name:vl,params:Cl,source:Il,state:Tl,svg:El,terminals:Nl,viewBox:Sl,width:jl},Symbol.toStringTag,{value:"Module"})),Al="grid-source",Ml="系统电源",Pl="source",Ol="无穷大母线 / 外部电网",Ll="-16 -31 32 53",Bl=32,Dl=53,Rl='<circle cx="0" cy="-15" r="14" fill="none" stroke="black" stroke-width="1"/><text x="0" y="-12" text-anchor="middle" font-family="Liberation Sans, Arial, sans-serif" font-size="14">~</text><line x1="0" y1="-1" x2="0" y2="20" stroke="black" stroke-width="1" fill="none"/>',zl=[{id:"t_bottom",x:0,y:20,orientation:"s"}],Fl={kind:"inline"},yg={id:Al,name:Ml,category:Pl,description:Ol,viewBox:Ll,width:Bl,height:Dl,svg:Rl,terminals:zl,source:Fl},bg=Object.freeze(Object.defineProperty({__proto__:null,category:Pl,default:yg,description:Ol,height:Dl,id:Al,name:Ml,source:Fl,svg:Rl,terminals:zl,viewBox:Ll,width:Bl},Symbol.toStringTag,{value:"Module"})),Hl="grounding-transformer",Wl="接地变 (Z形)",Gl="grounding",ql="星-曲折接线变压器,中性点接地用",Kl="-62 -152 64 164",Yl=64,Xl=164,Vl='<line x1="-30" y1="-40" x2="-35" y2="-35" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-40" x2="-25" y2="-35" fill="none" stroke="black" stroke-width="1"/><ellipse cx="-30" cy="-90" rx="30" ry="30" fill="none" stroke="black" stroke-width="1"/><line x1="-35" y1="-35" x2="-40" y2="-38" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-150" x2="-30" y2="-120" fill="none" stroke="black" stroke-width="1"/><line x1="-25" y1="-35" x2="-25" y2="-30" fill="none" stroke="black" stroke-width="1"/><ellipse cx="-30" cy="-50" rx="30" ry="30" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-40" x2="-30" y2="-45" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-20" x2="-30" y2="10" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-45" x2="-25" y2="-48" fill="none" stroke="black" stroke-width="1"/><line x1="-40" y1="-130" x2="-20" y2="-140" fill="none" stroke="black" stroke-width="1"/><line x1="-40" y1="-135" x2="-20" y2="-145" fill="none" stroke="black" stroke-width="1"/><line x1="-40" y1="0" x2="-20" y2="-10" fill="none" stroke="black" stroke-width="1"/><line x1="-40" y1="5" x2="-20" y2="-5" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-85" x2="-30" y2="-95" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-95" x2="-20" y2="-100" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-95" x2="-40" y2="-100" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-40" x2="-20" y2="-40" fill="none" stroke="black" stroke-width="1"/><ellipse cx="-30" cy="-40" rx="2" ry="2" fill="black" stroke="black" stroke-width="1"/>',Ul=[{id:"t1",x:-30,y:10,orientation:"s"},{id:"t2",x:-30,y:-150,orientation:"n"}],Zl={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_10/en_60617_06_10_15.elmt",qetEnglishName:"Three-phase transformer, connection star-zigzag with the neutral brought out"},wg={id:Hl,name:Wl,category:Gl,description:ql,viewBox:Kl,width:Yl,height:Xl,svg:Vl,terminals:Ul,source:Zl},vg=Object.freeze(Object.defineProperty({__proto__:null,category:Gl,default:wg,description:ql,height:Xl,id:Hl,name:Wl,source:Zl,svg:Vl,terminals:Ul,viewBox:Kl,width:Yl},Symbol.toStringTag,{value:"Module"})),Jl="inverter",Ql="逆变器 (DC→AC)",ec="renewable",tc="-42 -42 44 44",nc=44,oc=44,rc='<path d="M -15 -8 A 5 2.5 0 0 0 -25 -8" fill="none" stroke="black" stroke-width="1"/><line x1="-40" y1="0" x2="0" y2="-40" fill="none" stroke="black" stroke-width="1"/><path d="M -15 -8 A 5 2.5 0 0 0 -5 -8" fill="none" stroke="black" stroke-width="1"/><rect x="-40" y="-40" width="40" height="40" rx="0" ry="0" fill="none" stroke="black" stroke-width="1"/><line x1="-36" y1="-36" x2="-20" y2="-36" fill="none" stroke="black" stroke-width="1"/><line x1="-36" y1="-32" x2="-30" y2="-32" fill="none" stroke="black" stroke-width="1"/><line x1="-26" y1="-32" x2="-20" y2="-32" fill="none" stroke="black" stroke-width="1"/>',sc=[{id:"t_dc",x:-20,y:-40,orientation:"n"},{id:"t_ac",x:-20,y:0,orientation:"s"}],ic={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_14/en_60617_06_14_05.elmt",qetEnglishName:"Inverter"},kg={id:Jl,name:Ql,category:ec,viewBox:tc,width:nc,height:oc,svg:rc,terminals:sc,source:ic},_g=Object.freeze(Object.defineProperty({__proto__:null,category:ec,default:kg,height:oc,id:Jl,name:Ql,source:ic,svg:rc,terminals:sc,viewBox:tc,width:nc},Symbol.toStringTag,{value:"Module"})),ac="load-switch",lc="负荷开关",cc="switching",dc="-10 -42 14 64",uc=14,fc=64,mc='<line x1="0" y1="-24" x2="0" y2="-40" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="0" x2="0" y2="20" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="0" x2="-8" y2="-23" fill="none" stroke="black" stroke-width="1"/><ellipse cx="0" cy="-22" rx="2" ry="2" fill="none" stroke="black" stroke-width="1"/><line x1="-2" y1="-24" x2="2" y2="-24" fill="none" stroke="black" stroke-width="1"/>',hc=[{id:"t1",x:0,y:-40,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],pc=[{name:"open",type:"boolean",default:!1,label:"断开"}],gc={kind:"elmt",path:"91_en_60617/en_60617_07/en_60617_07_13/en_60617_07_13_08.elmt",qetEnglishName:"Switch-disconnector; On-load isolating switch"},Sg={id:ac,name:lc,category:cc,viewBox:dc,width:uc,height:fc,svg:mc,terminals:hc,state:pc,source:gc},jg=Object.freeze(Object.defineProperty({__proto__:null,category:cc,default:Sg,height:fc,id:ac,name:lc,source:gc,state:pc,svg:mc,terminals:hc,viewBox:dc,width:uc},Symbol.toStringTag,{value:"Module"})),xc="load",yc="负荷",bc="load",wc="抽象负荷(电流流出箭头)",vc="-8 -22 16 46",kc=16,_c=46,Sc='<line x1="0" y1="-20" x2="0" y2="10" stroke="black" stroke-width="1" fill="none"/><polygon points="-6,10 6,10 0,22" fill="black" stroke="black" stroke-width="1"/>',jc=[{id:"t_top",x:0,y:-20,orientation:"n"}],$c=[{name:"P",label:"有功功率",type:"number",unit:"MW",showOnCanvas:!0},{name:"cosphi",label:"功率因数",type:"number"}],Ec={x:6,y:0,anchor:"start"},Nc={kind:"inline"},$g={id:xc,name:yc,category:bc,description:wc,viewBox:vc,width:kc,height:_c,svg:Sc,terminals:jc,params:$c,label:Ec,source:Nc},Eg=Object.freeze(Object.defineProperty({__proto__:null,category:bc,default:$g,description:wc,height:_c,id:xc,label:Ec,name:yc,params:$c,source:Nc,svg:Sc,terminals:jc,viewBox:vc,width:kc},Symbol.toStringTag,{value:"Module"})),Tc="motor-starter",Cc="电机启动器",Ic="motor-control",Ac="电机启动器 (IEC 60617 通用符号)。",Mc="-22 -27 44 54",Pc=44,Oc=54,Lc='<rect x="-20" y="-20" width="40" height="40" rx="0" ry="0" fill="none" stroke="black" stroke-width="1"/><polyline points="-20,-20 0,-10 20,-20" fill="none" stroke="black" stroke-width="1"/>',Bc=[{id:"t_top",x:0,y:-25,orientation:"n"},{id:"t_bottom",x:0,y:25,orientation:"s"}],Dc={kind:"elmt",path:"91_en_60617/en_60617_07/en_60617_07_14/en_60617_07_14_01.elmt",qetEnglishName:"Motor starter, general symbol"},Ng={id:Tc,name:Cc,category:Ic,description:Ac,viewBox:Mc,width:Pc,height:Oc,svg:Lc,terminals:Bc,source:Dc},Tg=Object.freeze(Object.defineProperty({__proto__:null,category:Ic,default:Ng,description:Ac,height:Oc,id:Tc,name:Cc,source:Dc,svg:Lc,terminals:Bc,viewBox:Mc,width:Pc},Symbol.toStringTag,{value:"Module"})),Rc="ngr",zc="中性点电阻 (NGR)",Fc="grounding",Hc="小电阻接地:连接变压器中性点到地",Wc="-12 -32 24 62",Gc=24,qc=62,Kc='<line x1="0" y1="-30" x2="0" y2="-15" fill="none" stroke="black" stroke-width="1"/><rect x="-6" y="-15" width="12" height="22" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="7" x2="0" y2="15" fill="none" stroke="black" stroke-width="1"/><line x1="-10" y1="15" x2="10" y2="15" fill="none" stroke="black" stroke-width="1"/><line x1="-7" y1="19" x2="7" y2="19" fill="none" stroke="black" stroke-width="1"/><line x1="-4" y1="23" x2="4" y2="23" fill="none" stroke="black" stroke-width="1"/><line x1="-1.5" y1="27" x2="1.5" y2="27" fill="none" stroke="black" stroke-width="1"/>',Yc=[{id:"t_top",x:0,y:-30,orientation:"n"}],Xc=[{name:"R",label:"电阻",type:"number",unit:"Ω"}],Vc={kind:"inline"},Cg={id:Rc,name:zc,category:Fc,description:Hc,viewBox:Wc,width:Gc,height:qc,svg:Kc,terminals:Yc,params:Xc,source:Vc},Ig=Object.freeze(Object.defineProperty({__proto__:null,category:Fc,default:Cg,description:Hc,height:qc,id:Rc,name:zc,params:Xc,source:Vc,svg:Kc,terminals:Yc,viewBox:Wc,width:Gc},Symbol.toStringTag,{value:"Module"})),Uc="pt",Zc="电压互感器 (PT)",Jc="instrument-transformer",Qc="-22 -42 44 115",ed=44,td=115,nd='<ellipse cx="0" cy="1" rx="20" ry="20" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="-40" x2="0" y2="-20" fill="none" stroke="black" stroke-width="1"/><ellipse cx="0" cy="30" rx="20" ry="20" fill="none" stroke="black" stroke-width="1"/><line x1="-0.13" y1="51" x2="-0.13" y2="71" fill="none" stroke="black" stroke-width="1"/>',od=[{id:"t1",x:0,y:71,orientation:"s"},{id:"t2",x:0,y:-40,orientation:"n"}],rd={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_13/en_60617_06_13_01A.elmt",qetEnglishName:"Voltage transformer"},Ag={id:Uc,name:Zc,category:Jc,viewBox:Qc,width:ed,height:td,svg:nd,terminals:od,source:rd},Mg=Object.freeze(Object.defineProperty({__proto__:null,category:Jc,default:Ag,height:td,id:Uc,name:Zc,source:rd,svg:nd,terminals:od,viewBox:Qc,width:ed},Symbol.toStringTag,{value:"Module"})),sd="pv",id="光伏组件",ad="renewable",ld="-33 -22 85 64",cd=85,dd=64,ud='<line x1="-16" y1="24" x2="-26" y2="14" fill="none" stroke="black" stroke-width="1"/><line x1="-21" y1="29" x2="-31" y2="19" fill="none" stroke="black" stroke-width="1"/><polygon points="-20,23 -17,20 -15,25" fill="black" stroke="black" stroke-width="1"/><polygon points="-22,25 -25,28 -20,30" fill="black" stroke="black" stroke-width="1"/><rect x="-10" y="-20" width="60" height="60" rx="0" ry="0" fill="none" stroke="black" stroke-width="1"/><text x="15" y="7.2" font-family="Liberation Sans, Arial, sans-serif" font-size="14" fill="#000000">G</text><line x1="10" y1="20" x2="20" y2="20" fill="none" stroke="black" stroke-width="1"/><line x1="20" y1="15" x2="20" y2="25" fill="none" stroke="black" stroke-width="1"/><line x1="25" y1="10" x2="25" y2="30" fill="none" stroke="black" stroke-width="1"/><line x1="25" y1="20" x2="35" y2="20" fill="none" stroke="black" stroke-width="1"/>',fd=[{id:"t_dc",x:50,y:10,orientation:"e"}],md={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_18/en_60617_06_18_06.elmt",qetEnglishName:"Photovoltaic generator"},Pg={id:sd,name:id,category:ad,viewBox:ld,width:cd,height:dd,svg:ud,terminals:fd,source:md},Og=Object.freeze(Object.defineProperty({__proto__:null,category:ad,default:Pg,height:dd,id:sd,name:id,source:md,svg:ud,terminals:fd,viewBox:ld,width:cd},Symbol.toStringTag,{value:"Module"})),hd="rcd",pd="剩余电流装置 (RCD)",gd="protection",xd="不带过流保护的剩余电流断路器 (IEC 61008)。",yd="-12 -22 19 44",bd=19,wd=44,vd='<line x1="0" y1="-20" x2="0" y2="-10" fill="none" stroke="black" stroke-width="1"/><line x1="2" y1="-12" x2="-2" y2="-8" fill="none" stroke="black" stroke-width="1"/><line x1="-2" y1="-12" x2="2" y2="-8" fill="none" stroke="black" stroke-width="1"/><polyline points="0,20 0,10 -7,-9" fill="none" stroke="black" stroke-width="1"/><ellipse cx="0" cy="13" rx="4.5" ry="2" fill="none" stroke="black" stroke-width="1"/><polyline points="-4,0 -10,0 -10,13 -5,13" fill="none" stroke="black" stroke-width="0.4" stroke-dasharray="4 2"/>',kd=[{id:"t1",x:0,y:-20,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],_d=[{name:"open",type:"boolean",default:!1,label:"断开"}],Sd=[{name:"IDn",label:"剩余动作电流",type:"number",unit:"mA",default:30}],jd={kind:"elmt",path:"11_singlepole/200_fuses_protective_gears/50_residual_current_circuit_breaker/ddr1.elmt",qetEnglishName:"Residual Circuit Breaker with Overload"},Lg={id:hd,name:pd,category:gd,description:xd,viewBox:yd,width:bd,height:wd,svg:vd,terminals:kd,state:_d,params:Sd,source:jd},Bg=Object.freeze(Object.defineProperty({__proto__:null,category:gd,default:Lg,description:xd,height:wd,id:hd,name:pd,params:Sd,source:jd,state:_d,svg:vd,terminals:kd,viewBox:yd,width:bd},Symbol.toStringTag,{value:"Module"})),$d="recloser",Ed="重合闸 (Recloser)",Nd="protection",Td="中压自动重合闸开关。",Cd="-12 -32 36 64",Id=36,Ad=64,Md='<line x1="0" y1="-30" x2="0" y2="-10" stroke="black" stroke-width="1" fill="none"/><line x1="0" y1="0" x2="0" y2="30" stroke="black" stroke-width="1" fill="none"/><line x1="0" y1="0" x2="-8" y2="-13" stroke="black" stroke-width="1" fill="none"/><line x1="-2" y1="-8" x2="2" y2="-12" stroke="black" stroke-width="1" fill="none"/><line x1="-2" y1="-12" x2="2" y2="-8" stroke="black" stroke-width="1" fill="none"/><path d="M 13 -12 A 7 7 0 1 1 6 -5" fill="none" stroke="black" stroke-width="0.8"/><polygon points="4,-7 6,-5 8,-3" fill="black"/><text x="14" y="6" font-family="Liberation Sans, Arial, sans-serif" font-size="6" fill="#000000">AR</text>',Pd=[{id:"t1",x:0,y:-30,orientation:"n"},{id:"t2",x:0,y:30,orientation:"s"}],Od=[{name:"open",type:"boolean",default:!1,label:"断开"}],Ld={kind:"inline"},Dg={id:$d,name:Ed,category:Nd,description:Td,viewBox:Cd,width:Id,height:Ad,svg:Md,terminals:Pd,state:Od,source:Ld},Rg=Object.freeze(Object.defineProperty({__proto__:null,category:Nd,default:Dg,description:Td,height:Ad,id:$d,name:Ed,source:Ld,state:Od,svg:Md,terminals:Pd,viewBox:Cd,width:Id},Symbol.toStringTag,{value:"Module"})),Bd="rectifier",Dd="整流器 (AC→DC)",Rd="renewable",zd="-42 -42 44 44",Fd=44,Hd=44,Wd='<line x1="-40" y1="0" x2="0" y2="-40" fill="none" stroke="black" stroke-width="1"/><rect x="-40" y="-40" width="40" height="40" rx="0" ry="0" fill="none" stroke="black" stroke-width="1"/><line x1="-20" y1="-8" x2="-4" y2="-8" fill="none" stroke="black" stroke-width="1"/><line x1="-20" y1="-4" x2="-14" y2="-4" fill="none" stroke="black" stroke-width="1"/><line x1="-10" y1="-4" x2="-4" y2="-4" fill="none" stroke="black" stroke-width="1"/><path d="M -25 -30 A 5 2.5 0 0 0 -35 -30" fill="none" stroke="black" stroke-width="1"/><path d="M -25 -30 A 5 2.5 0 0 0 -15 -30" fill="none" stroke="black" stroke-width="1"/>',Gd=[{id:"t_ac",x:-20,y:-40,orientation:"n"},{id:"t_dc",x:-20,y:0,orientation:"s"}],qd={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_14/en_60617_06_14_03.elmt",qetEnglishName:"Rectifier"},zg={id:Bd,name:Dd,category:Rd,viewBox:zd,width:Fd,height:Hd,svg:Wd,terminals:Gd,source:qd},Fg=Object.freeze(Object.defineProperty({__proto__:null,category:Rd,default:zg,height:Hd,id:Bd,name:Dd,source:qd,svg:Wd,terminals:Gd,viewBox:zd,width:Fd},Symbol.toStringTag,{value:"Module"})),Kd="series-reactor",Yd="串联电抗器",Xd="compensation",Vd="与并联电抗器同符号;通过用法区分。",Ud="-62 -82 64 104",Zd=64,Jd=104,Qd='<line x1="-30" y1="0" x2="-30" y2="20" fill="none" stroke="black" stroke-width="1"/><path d="M -30 0 A 30 30 0 1 0 -60 -30" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-80" x2="-30" y2="-30" fill="none" stroke="black" stroke-width="1"/><line x1="-60" y1="-30" x2="-30" y2="-30" fill="none" stroke="black" stroke-width="1"/>',eu=[{id:"t1",x:-30,y:-80,orientation:"n"},{id:"t_bottom",x:-30,y:20,orientation:"s"}],tu={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_09/en_60617_06_09_08.elmt",qetEnglishName:"Choke; Reactor, general symbol"},Hg={id:Kd,name:Yd,category:Xd,description:Vd,viewBox:Ud,width:Zd,height:Jd,svg:Qd,terminals:eu,source:tu},Wg=Object.freeze(Object.defineProperty({__proto__:null,category:Xd,default:Hg,description:Vd,height:Jd,id:Kd,name:Yd,source:tu,svg:Qd,terminals:eu,viewBox:Ud,width:Zd},Symbol.toStringTag,{value:"Module"})),nu="shunt-capacitor",ou="并联电容器",ru="compensation",su="-7 -23 14 27",iu=14,au=27,lu='<line x1="-5" y1="2" x2="5" y2="2" fill="none" stroke="black" stroke-width="1"/><line x1="-5" y1="-2" x2="5" y2="-2" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="-20" x2="0" y2="-2" fill="none" stroke="black" stroke-width="1"/>',cu=[{id:"t1",x:0,y:-21,orientation:"n"},{id:"t_bottom",x:0,y:2,orientation:"s"}],du=[{name:"Q",label:"无功容量",type:"number",unit:"Mvar"},{name:"stages",label:"分组数",type:"number"}],uu={kind:"elmt",path:"11_singlepole/395_electronics_semiconductors/20_capacitors/capacite.elmt",qetEnglishName:"Capacitor"},Gg={id:nu,name:ou,category:ru,viewBox:su,width:iu,height:au,svg:lu,terminals:cu,params:du,source:uu},qg=Object.freeze(Object.defineProperty({__proto__:null,category:ru,default:Gg,height:au,id:nu,name:ou,params:du,source:uu,svg:lu,terminals:cu,viewBox:su,width:iu},Symbol.toStringTag,{value:"Module"})),fu="shunt-reactor",mu="并联电抗器",hu="compensation",pu="-62 -82 64 104",gu=64,xu=104,yu='<line x1="-30" y1="0" x2="-30" y2="20" fill="none" stroke="black" stroke-width="1"/><path d="M -30 0 A 30 30 0 1 0 -60 -30" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-80" x2="-30" y2="-30" fill="none" stroke="black" stroke-width="1"/><line x1="-60" y1="-30" x2="-30" y2="-30" fill="none" stroke="black" stroke-width="1"/>',bu=[{id:"t1",x:-30,y:-80,orientation:"n"},{id:"t_bottom",x:-30,y:20,orientation:"s"}],wu={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_09/en_60617_06_09_08.elmt",qetEnglishName:"Choke; Reactor, general symbol"},Kg={id:fu,name:mu,category:hu,viewBox:pu,width:gu,height:xu,svg:yu,terminals:bu,source:wu},Yg=Object.freeze(Object.defineProperty({__proto__:null,category:hu,default:Kg,height:xu,id:fu,name:mu,source:wu,svg:yu,terminals:bu,viewBox:pu,width:gu},Symbol.toStringTag,{value:"Module"})),vu="soft-starter",ku="软启动器",_u="motor-control",Su="电机软启动器 (晶闸管降压启动)。",ju="-22 -42 44 84",$u=44,Eu=84,Nu='<rect x="-20" y="-20" width="40" height="40" fill="none" stroke="black" stroke-width="1"/><line x1="-12" y1="-12" x2="12" y2="12" stroke="black" stroke-width="1" fill="none"/><polygon points="4,8 12,12 8,4" fill="none" stroke="black" stroke-width="1"/><text x="-12" y="-2" font-family="Liberation Sans, Arial, sans-serif" font-size="6" fill="#000000">SS</text><line x1="0" y1="-40" x2="0" y2="-20" stroke="black" stroke-width="1" fill="none"/><line x1="0" y1="20" x2="0" y2="40" stroke="black" stroke-width="1" fill="none"/>',Tu=[{id:"t_in",x:0,y:-40,orientation:"n"},{id:"t_out",x:0,y:40,orientation:"s"}],Cu={kind:"inline"},Xg={id:vu,name:ku,category:_u,description:Su,viewBox:ju,width:$u,height:Eu,svg:Nu,terminals:Tu,source:Cu},Vg=Object.freeze(Object.defineProperty({__proto__:null,category:_u,default:Xg,description:Su,height:Eu,id:vu,name:ku,source:Cu,svg:Nu,terminals:Tu,viewBox:ju,width:$u},Symbol.toStringTag,{value:"Module"})),Iu="sync-motor",Au="同步电动机",Mu="load",Pu="-62 -82 64 114",Ou=64,Lu=114,Bu='<ellipse cx="-30" cy="-30" rx="30" ry="30" fill="none" stroke="black" stroke-width="1"/><text x="-34" y="-24.8" font-family="Liberation Sans, Arial, sans-serif" font-size="14" fill="#000000">M</text><line x1="-50" y1="-80" x2="-50" y2="-53" fill="none" stroke="black" stroke-width="1"/><line x1="-10" y1="-53" x2="-10" y2="-80" fill="none" stroke="black" stroke-width="1"/><text x="-45" y="-7.8" font-family="Liberation Sans, Arial, sans-serif" font-size="14" fill="#000000">1</text><path d="M -25 -20 A 5 2.5 0 0 0 -35 -20" fill="none" stroke="black" stroke-width="1"/><path d="M -25 -20 A 5 2.5 0 0 0 -15 -20" fill="none" stroke="black" stroke-width="1"/><path d="M -40 10 A 5 5 0 0 0 -50 10" fill="none" stroke="black" stroke-width="1"/><path d="M -30 10 A 5 5 0 0 0 -40 10" fill="none" stroke="black" stroke-width="1"/><path d="M -20 10 A 5 5 0 0 0 -30 10" fill="none" stroke="black" stroke-width="1"/><path d="M -10 10 A 5 5 0 0 0 -20 10" fill="none" stroke="black" stroke-width="1"/><line x1="-50" y1="10" x2="-50" y2="30" fill="none" stroke="black" stroke-width="1"/><line x1="-10" y1="10" x2="-10" y2="30" fill="none" stroke="black" stroke-width="1"/><line x1="-40" y1="15" x2="-20" y2="15" fill="none" stroke="black" stroke-width="1"/><line x1="-40" y1="20" x2="-32" y2="20" fill="none" stroke="black" stroke-width="1"/><line x1="-27" y1="20" x2="-20" y2="20" fill="none" stroke="black" stroke-width="1"/>',Du=[{id:"t1",x:-10,y:-80,orientation:"n"},{id:"t2",x:-50,y:-80,orientation:"n"}],Ru={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_07/en_60617_06_07_02.elmt",qetEnglishName:"Synchronous motor, single-phase"},Ug={id:Iu,name:Au,category:Mu,viewBox:Pu,width:Ou,height:Lu,svg:Bu,terminals:Du,source:Ru},Zg=Object.freeze(Object.defineProperty({__proto__:null,category:Mu,default:Ug,height:Lu,id:Iu,name:Au,source:Ru,svg:Bu,terminals:Du,viewBox:Pu,width:Ou},Symbol.toStringTag,{value:"Module"})),zu="thermal-overload",Fu="热过载继电器",Hu="motor-control",Wu="电机热过载保护继电器, 通常串接在接触器和电机之间。",Gu="-9 -32 19 64",qu=19,Ku=64,Yu='<line x1="0" y1="-30" x2="0" y2="-15" stroke="black" stroke-width="1" fill="none"/><rect x="-7" y="-15" width="14" height="30" fill="none" stroke="black" stroke-width="1"/><polyline points="-4,-10 -1,-5 -4,0 -1,5 -4,10" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="15" x2="0" y2="30" stroke="black" stroke-width="1" fill="none"/>',Xu=[{id:"t1",x:0,y:-30,orientation:"n"},{id:"t2",x:0,y:30,orientation:"s"}],Vu=[{name:"tripped",type:"boolean",default:!1,label:"动作"}],Uu={kind:"inline"},Jg={id:zu,name:Fu,category:Hu,description:Wu,viewBox:Gu,width:qu,height:Ku,svg:Yu,terminals:Xu,state:Vu,source:Uu},Qg=Object.freeze(Object.defineProperty({__proto__:null,category:Hu,default:Jg,description:Wu,height:Ku,id:zu,name:Fu,source:Uu,state:Vu,svg:Yu,terminals:Xu,viewBox:Gu,width:qu},Symbol.toStringTag,{value:"Module"})),Zu="transfer-switch",Ju="切换开关 (ATS)",Qu="switching",ef="双源切换开关 (Automatic / Manual Transfer Switch)。两个电源输入 + 一个负荷输出, 互锁不并联。",tf="-27 -32 51 64",nf=51,of=64,rf='<line x1="-15" y1="-30" x2="-15" y2="-12" stroke="black" stroke-width="1" fill="none"/><line x1="15" y1="-30" x2="15" y2="-12" stroke="black" stroke-width="1" fill="none"/><text x="-25" y="-20" font-family="Liberation Sans, Arial, sans-serif" font-size="6" fill="#000000">N</text><text x="19" y="-20" font-family="Liberation Sans, Arial, sans-serif" font-size="6" fill="#000000">E</text><circle cx="-15" cy="-10" r="1.5" fill="black"/><circle cx="15" cy="-10" r="1.5" fill="black"/><circle cx="0" cy="6" r="1.5" fill="black"/><line x1="-15" y1="-10" x2="0" y2="6" stroke="black" stroke-width="1" fill="none"/><line x1="15" y1="-10" x2="0" y2="6" stroke="black" stroke-width="0.6" fill="none" stroke-dasharray="2 1.5"/><line x1="0" y1="6" x2="0" y2="30" stroke="black" stroke-width="1" fill="none"/>',sf=[{id:"t_normal",x:-15,y:-30,orientation:"n"},{id:"t_emergency",x:15,y:-30,orientation:"n"},{id:"t_load",x:0,y:30,orientation:"s"}],af=[{name:"position",type:"string",default:"normal",label:"位置 (normal/emergency/off)"}],lf={kind:"inline"},e0={id:Zu,name:Ju,category:Qu,description:ef,viewBox:tf,width:nf,height:of,svg:rf,terminals:sf,state:af,source:lf},t0=Object.freeze(Object.defineProperty({__proto__:null,category:Qu,default:e0,description:ef,height:of,id:Zu,name:Ju,source:lf,state:af,svg:rf,terminals:sf,viewBox:tf,width:nf},Symbol.toStringTag,{value:"Module"})),cf="transformer-2w",df="双绕组变压器",uf="transformer",ff="-62 -142 64 144",mf=64,hf=144,pf='<ellipse cx="-30" cy="-90" rx="30" ry="30" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-140" x2="-30" y2="-120" fill="none" stroke="black" stroke-width="1"/><ellipse cx="-30" cy="-50" rx="30" ry="30" fill="none" stroke="black" stroke-width="1"/><line x1="-30" y1="-20" x2="-30" y2="0" fill="none" stroke="black" stroke-width="1"/>',gf=[{id:"t1",x:-30,y:0,orientation:"s"},{id:"t2",x:-30,y:-140,orientation:"n"}],xf=[{name:"S",label:"容量",type:"number",unit:"MVA",showOnCanvas:!0},{name:"ratio",label:"变比",type:"string",showOnCanvas:!0}],yf={x:4,y:-68,anchor:"start"},bf={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_09/en_60617_06_09_01.elmt",qetEnglishName:"Transformer with two windings, general symbol"},n0={id:cf,name:df,category:uf,viewBox:ff,width:mf,height:hf,svg:pf,terminals:gf,params:xf,label:yf,source:bf},o0=Object.freeze(Object.defineProperty({__proto__:null,category:uf,default:n0,height:hf,id:cf,label:yf,name:df,params:xf,source:bf,svg:pf,terminals:gf,viewBox:ff,width:mf},Symbol.toStringTag,{value:"Module"})),wf="transformer-3w",vf="三绕组变压器",kf="transformer",_f="-82 -131 114 133",Sf=114,jf=133,$f='<ellipse cx="-30" cy="-80" rx="30" ry="30" fill="none" stroke="black" stroke-width="1"/><line x1="-31" y1="-129" x2="-31" y2="-109" fill="none" stroke="black" stroke-width="1"/><ellipse cx="-50" cy="-50" rx="30" ry="30" fill="none" stroke="black" stroke-width="1"/><ellipse cx="0" cy="-50" rx="30" ry="30" fill="none" stroke="black" stroke-width="1"/><line x1="-50" y1="-20" x2="-50" y2="0" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="-20" x2="0" y2="0" fill="none" stroke="black" stroke-width="1"/>',Ef=[{id:"t1",x:-31,y:-129,orientation:"n"},{id:"t_low_left",x:-50,y:0,orientation:"s"},{id:"t_low_right",x:0,y:0,orientation:"s"}],Nf={x:4,y:-64,anchor:"start"},Tf={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_09/en_60617_06_09_04.elmt",qetEnglishName:"Transformer with three windings, general symbol"},r0={id:wf,name:vf,category:kf,viewBox:_f,width:Sf,height:jf,svg:$f,terminals:Ef,label:Nf,source:Tf},s0=Object.freeze(Object.defineProperty({__proto__:null,category:kf,default:r0,height:jf,id:wf,label:Nf,name:vf,source:Tf,svg:$f,terminals:Ef,viewBox:_f,width:Sf},Symbol.toStringTag,{value:"Module"})),Cf="vfd",If="变频器 (VFD)",Af="motor-control",Mf="Variable Frequency Drive — 异步电动机调速。",Pf="-24 -42 48 84",Of=48,Lf=84,Bf='<rect x="-22" y="-20" width="44" height="40" fill="none" stroke="black" stroke-width="1"/><line x1="-22" y1="20" x2="22" y2="-20" stroke="black" stroke-width="1" fill="none"/><text x="-15" y="-5" font-family="Liberation Sans, Arial, sans-serif" font-size="9" fill="#000000">~</text><text x="6" y="14" font-family="Liberation Sans, Arial, sans-serif" font-size="9" fill="#000000">~f</text><line x1="0" y1="-40" x2="0" y2="-20" stroke="black" stroke-width="1" fill="none"/><line x1="0" y1="20" x2="0" y2="40" stroke="black" stroke-width="1" fill="none"/>',Df=[{id:"t_in",x:0,y:-40,orientation:"n"},{id:"t_out",x:0,y:40,orientation:"s"}],Rf={kind:"inline"},i0={id:Cf,name:If,category:Af,description:Mf,viewBox:Pf,width:Of,height:Lf,svg:Bf,terminals:Df,source:Rf},a0=Object.freeze(Object.defineProperty({__proto__:null,category:Af,default:i0,description:Mf,height:Lf,id:Cf,name:If,source:Rf,svg:Bf,terminals:Df,viewBox:Pf,width:Of},Symbol.toStringTag,{value:"Module"})),zf="voltmeter",Ff="电压表 (V)",Hf="measurement",Wf="-22 -42 44 44",Gf=44,qf=44,Kf='<ellipse cx="0" cy="-20" rx="20" ry="20" fill="none" stroke="black" stroke-width="1"/><text x="-4" y="-8.8" font-family="Liberation Sans, Arial, sans-serif" font-size="9" fill="#000000">V</text>',Yf=[{id:"t_top",x:0,y:-40,orientation:"n"}],Xf={kind:"elmt",path:"91_en_60617/en_60617_08/en_60617_08_02/en_60617_08_02_01.elmt",qetEnglishName:"Voltmeter"},l0={id:zf,name:Ff,category:Hf,viewBox:Wf,width:Gf,height:qf,svg:Kf,terminals:Yf,source:Xf},c0=Object.freeze(Object.defineProperty({__proto__:null,category:Hf,default:l0,height:qf,id:zf,name:Ff,source:Xf,svg:Kf,terminals:Yf,viewBox:Wf,width:Gf},Symbol.toStringTag,{value:"Module"})),Vf="wattmeter",Uf="功率表 (W)",Zf="measurement",Jf="-22 -42 44 44",Qf=44,em=44,tm='<rect x="-20" y="-40" width="40" height="40" rx="0" ry="0" fill="none" stroke="black" stroke-width="1"/><text x="-6" y="-8.8" font-family="Liberation Sans, Arial, sans-serif" font-size="9" fill="#000000">W</text>',nm=[{id:"t_top",x:0,y:-40,orientation:"n"}],om={kind:"elmt",path:"91_en_60617/en_60617_08/en_60617_08_03/en_60617_08_03_01.elmt",qetEnglishName:"Recording wattmeter"},d0={id:Vf,name:Uf,category:Zf,viewBox:Jf,width:Qf,height:em,svg:tm,terminals:nm,source:om},u0=Object.freeze(Object.defineProperty({__proto__:null,category:Zf,default:d0,height:em,id:Vf,name:Uf,source:om,svg:tm,terminals:nm,viewBox:Jf,width:Qf},Symbol.toStringTag,{value:"Module"})),rm="wind-turbine",sm="风力发电机",im="renewable",am="风机:发电机 + 三叶轮标记",lm="-22 -46 44 68",cm=44,dm=68,um='<circle cx="0" cy="0" r="20" fill="none" stroke="black" stroke-width="1"/><text x="0" y="4" text-anchor="middle" font-family="Liberation Sans, Arial, sans-serif" font-size="16">G</text><line x1="0" y1="-20" x2="0" y2="-32" fill="none" stroke="black" stroke-width="1"/><line x1="0" y1="-32" x2="-10" y2="-39" fill="none" stroke="black" stroke-width="1.5"/><line x1="0" y1="-32" x2="10" y2="-39" fill="none" stroke="black" stroke-width="1.5"/><line x1="0" y1="-32" x2="0" y2="-44" fill="none" stroke="black" stroke-width="1.5"/>',fm=[{id:"t_bottom",x:0,y:20,orientation:"s"}],mm={kind:"inline"},f0={id:rm,name:sm,category:im,description:am,viewBox:lm,width:cm,height:dm,svg:um,terminals:fm,source:mm},m0=Object.freeze(Object.defineProperty({__proto__:null,category:im,default:f0,description:am,height:dm,id:rm,name:sm,source:mm,svg:um,terminals:fm,viewBox:lm,width:cm},Symbol.toStringTag,{value:"Module"})),h0=Object.assign({"./ammeter.json":Tp,"./arc-suppression-coil.json":Ip,"./arrester.json":Mp,"./async-motor.json":Op,"./autotransformer.json":Bp,"./battery.json":Rp,"./breaker.json":Fp,"./busbar.json":Wp,"./contactor.json":qp,"./converter-bidir.json":Yp,"./ct.json":Vp,"./dc-combiner.json":Zp,"./dc-disconnector.json":Qp,"./disconnector.json":tg,"./earth.json":og,"./earthing-switch.json":sg,"./energy-meter.json":ag,"./ev-charger.json":cg,"./frequency-meter.json":ug,"./fuse.json":mg,"./generator.json":pg,"./gfci-breaker.json":xg,"./grid-source.json":bg,"./grounding-transformer.json":vg,"./inverter.json":_g,"./load-switch.json":jg,"./load.json":Eg,"./motor-starter.json":Tg,"./ngr.json":Ig,"./pt.json":Mg,"./pv.json":Og,"./rcd.json":Bg,"./recloser.json":Rg,"./rectifier.json":Fg,"./series-reactor.json":Wg,"./shunt-capacitor.json":qg,"./shunt-reactor.json":Yg,"./soft-starter.json":Vg,"./sync-motor.json":Zg,"./thermal-overload.json":Qg,"./transfer-switch.json":t0,"./transformer-2w.json":o0,"./transformer-3w.json":s0,"./vfd.json":a0,"./voltmeter.json":c0,"./wattmeter.json":u0,"./wind-turbine.json":m0}),hm=Object.values(h0).map(e=>e.default),Ke=Object.fromEntries(hm.map(e=>[e.id,e])),uo=["busbar","switching","protection","motor-control","transformer","instrument-transformer","measurement","source","load","storage","compensation","grounding","renewable"],p0=(()=>{var t;const e={};for(const n of hm)(e[t=n.category]??(e[t]=[])).push(n);return e})(),pn=new Map(Object.entries(Ke));function pm(e){return Ke[e]}function g0(e){const n=[...e].sort().join("|");let o=2166136261;for(let r=0;r<n.length;r++)o^=n.charCodeAt(r),o=Math.imul(o,16777619);return`n_${(o>>>0).toString(36)}`}const x0=320;function We(e){var f,h,g,m;const t=wr(),n=new Map;e.elements.forEach((p,y)=>{if(n.has(p.id)){t.diagnostics.push({code:"E001",severity:"error",message:be("compile.duplicateId",{id:p.id}),pointer:`/elements/${y}`});return}n.set(p.id,p);const v=pn.get(p.kind);v||t.diagnostics.push({code:"E003",severity:"error",message:`${be("compile.unknownKind",{kind:p.kind})} (id=${p.id})`,pointer:`/elements/${y}`}),t.elements.set(p.id,{element:p,libraryDef:v})});const o=new Map,r=new Map;(e.buses??[]).forEach((p,y)=>{if(n.has(p.id)||o.has(p.id)){t.diagnostics.push({code:"E001",severity:"error",message:be("compile.duplicateId",{id:p.id}),pointer:`/buses/${y}`});return}if(o.set(p.id,p),p.layout){const v=p.layout.rot??0;r.set(p.id,{at:p.layout.at,span:p.layout.span,rot:v,axis:mn(v)})}});const s=p=>!p.includes(".")&&o.has(p),i=(p,y)=>{if(s(p))return!0;const v=p.indexOf(".");if(v<=0)return t.diagnostics.push({code:"E003",severity:"error",message:be("compile.invalidTermRef",{ref:p}),pointer:y}),!1;const b=p.slice(0,v),k=p.slice(v+1),S=t.elements.get(b);if(!S)return t.diagnostics.push({code:"E002",severity:"error",message:be("compile.elementMissing",{id:b}),pointer:y}),!1;if(!S.libraryDef)return!1;if(!S.libraryDef.terminals.find(C=>C.id===k)){const C=S.libraryDef.terminals.map(L=>L.id).join(", ");return t.diagnostics.push({code:"E003",severity:"error",message:be("compile.missingPin",{id:b,kind:S.element.kind,pin:k,available:C}),pointer:y}),!1}return!0},a=[];(e.wires??[]).forEach((p,y)=>{const v=`/wires/${y}`,b=i(p.ends[0],v),k=i(p.ends[1],v);b&&k&&a.push(p)});const l=new Map;if(e.layout)for(const[p,y]of Object.entries(e.layout))t.elements.has(p)?l.set(p,vr(y)):t.diagnostics.push({code:"E004",severity:"error",message:be("compile.layoutMissingElement",{id:p}),pointer:`/layout/${p}`});const d=$p({elements:e.elements,buses:e.buses??[],wires:a,library:pn,userLayout:l,userBusLayout:r});t.layout=d.devices;for(const[p,y]of d.buses){const v=o.get(p);v&&t.buses.set(p,{bus:v,geometry:y})}for(const[p,y]of o)t.buses.has(p)||t.buses.set(p,{bus:y,geometry:{at:((f=y.layout)==null?void 0:f.at)??[0,0],span:((h=y.layout)==null?void 0:h.span)??x0,rot:((g=y.layout)==null?void 0:g.rot)??0,axis:mn(((m=y.layout)==null?void 0:m.rot)??0)}});for(const p of t.elements.values()){if(!p.libraryDef)continue;const y=t.layout.get(p.element.id);if(!y)continue;const v=[];for(const b of p.libraryDef.terminals){const k=`${p.element.id}.${b.id}`,S=Le([b.x,b.y],y),C=xt(b.orientation,y);t.terminals.set(k,{ref:k,elementId:p.element.id,pin:b.id,world:S,orientation:C}),v.push(k)}t.elementToTerminals.set(p.element.id,v)}const u=new kr;for(const p of a)u.add(p.ends[0]),u.add(p.ends[1]),u.union(p.ends[0],p.ends[1]);for(const[,p]of u.groups()){const y=g0(p);t.nodes.set(y,{id:y,terminals:p});for(const v of p)t.terminalToNode.set(v,y)}for(const p of t.elements.values()){const y=t.elementToTerminals.get(p.element.id)??[];if(y.length===0)continue;y.some(b=>t.terminalToNode.has(b))||t.diagnostics.push({code:"W001",severity:"warning",message:be("compile.elementUnconnected",{id:p.element.id})})}for(const p of t.buses.keys())t.terminalToNode.has(p)||t.diagnostics.push({code:"W001",severity:"warning",message:be("compile.elementUnconnected",{id:p})});for(const p of a){if(p.path&&p.path.length>=2){const v=p.path,b=v.length>=2?v[1]:null,k=v.length>=2?v[v.length-2]:null,S=lo(p.ends[0],b,t),C=lo(p.ends[1],k,t);if(S&&C){const L=[[S[0],S[1]],...v.slice(1,-1).map(Q=>[Q[0],Q[1]]),[C[0],C[1]]],te=br(L);if(te.length>=2){t.wireRenders.set(p.id,{wireId:p.id,path:te,userEdited:!0});continue}}}const y=Ep(p,t);y&&t.wireRenders.set(p.id,y)}return t}const y0={earth:"GND",breaker:"QF",disconnector:"QS","earthing-switch":"QE","load-switch":"QL",fuse:"FU","transformer-2w":"T","transformer-3w":"T",autotransformer:"AT",ct:"CT",pt:"PT",generator:"G","sync-motor":"M","async-motor":"M","grid-source":"L",load:"L",battery:"BAT","shunt-reactor":"LR","series-reactor":"LR","shunt-capacitor":"C",arrester:"FBL","grounding-transformer":"TG",ngr:"NGR","arc-suppression-coil":"ASC",pv:"PV","wind-turbine":"WT",rectifier:"RT",inverter:"INV","converter-bidir":"PCS"},fo="B";function gm(e){return new Set([...e.elements.map(t=>t.id),...(e.buses??[]).map(t=>t.id)])}function wt(e,t){const n=y0[t]??t,o=gm(e);let r=1;for(;o.has(`${n}${r}`);)r++;return`${n}${r}`}function gn(e){const t=gm(e);let n=1;for(;t.has(`${fo}${n}`);)n++;return`${fo}${n}`}function b0(e){const t=new Set((e.annotations??[]).map(o=>o.id));let n=1;for(;t.has(`a${n}`);)n++;return`a${n}`}function vt(e,t){const n=[e,t].sort(),o=`${n[0]}|${n[1]}`;let r=2166136261;for(let s=0;s<o.length;s++)r^=o.charCodeAt(s),r=Math.imul(r,16777619);return`w_${(r>>>0).toString(36)}`}const mo={version:"1",elements:[]},w0=100,ho=20;function v0(){if(typeof window>"u")return"select";try{return window.matchMedia("(pointer: coarse)").matches?"pan":"select"}catch{return"select"}}const x=Ft()(yp((e,t)=>({diagram:mo,internal:We(mo),fileSession:null,activeTool:v0(),placeKind:null,lastPlaceKind:null,wireFromTerminal:null,placeFromTerminal:null,busbarDrawStart:null,cursorSvg:null,selection:[],selectedWire:null,selectedNode:null,selectedAnnotation:null,editingAnnotation:null,editingElement:null,past:[],future:[],clipboard:null,clipboardPasteIndex:0,setDiagram:n=>e({diagram:n,internal:We(n),past:[],future:[],selection:[],selectedWire:null,selectedNode:null,selectedAnnotation:null,editingAnnotation:null,editingElement:null,wireFromTerminal:null,placeFromTerminal:null}),setFileSession:n=>e({fileSession:n}),loadDiagramFromFile:(n,o)=>e({diagram:n,internal:We(n),fileSession:o,past:[],future:[],selection:[],selectedWire:null,selectedNode:null,selectedAnnotation:null,editingAnnotation:null,editingElement:null,wireFromTerminal:null,placeFromTerminal:null}),dispatch:n=>{const{diagram:o,past:r}=t(),s=n(o);if(s===o)return;const i=r.length>=w0?r.slice(1):r;e({diagram:s,internal:We(s),past:[...i,o],future:[]})},undo:()=>{const{past:n,future:o,diagram:r}=t();if(n.length===0)return;const s=n[n.length-1];e({diagram:s,internal:We(s),past:n.slice(0,-1),future:[...o,r],wireFromTerminal:null,placeFromTerminal:null})},redo:()=>{const{past:n,future:o,diagram:r}=t();if(o.length===0)return;const s=o[o.length-1];e({diagram:s,internal:We(s),past:[...n,r],future:o.slice(0,-1),wireFromTerminal:null,placeFromTerminal:null})},setActiveTool:(n,o)=>{const r=t();let s;(o==null?void 0:o.placeKind)!==void 0?s=o.placeKind:n==="place"?s=r.placeKind??r.lastPlaceKind:s=null,e({activeTool:n,placeKind:s,lastPlaceKind:s??r.lastPlaceKind,wireFromTerminal:n==="wire"?r.wireFromTerminal:null,placeFromTerminal:n==="place"?r.placeFromTerminal:null})},setPlaceKind:n=>e(o=>({placeKind:n,lastPlaceKind:n??o.lastPlaceKind})),setWireFromTerminal:n=>e({wireFromTerminal:n}),setPlaceFromTerminal:n=>e({placeFromTerminal:n}),setBusbarDrawStart:n=>e({busbarDrawStart:n}),setCursorSvg:n=>e({cursorSvg:n}),setSelection:n=>e({selection:k0(n),selectedWire:null,selectedNode:null,selectedAnnotation:n.length?null:t().selectedAnnotation}),toggleInSelection:n=>{const o=t().selection;e({selection:o.includes(n)?o.filter(r=>r!==n):[...o,n],selectedWire:null,selectedNode:null,selectedAnnotation:null})},clearSelection:()=>e({selection:[],selectedWire:null,selectedNode:null,selectedAnnotation:null,editingAnnotation:null,editingElement:null}),setSelectedWire:n=>e({selectedWire:n,selection:n?[]:t().selection,selectedNode:null,selectedAnnotation:n?null:t().selectedAnnotation}),setSelectedNode:n=>e({selectedNode:n,selection:n?[]:t().selection,selectedWire:null,selectedAnnotation:n?null:t().selectedAnnotation}),setSelectedAnnotation:n=>e({selectedAnnotation:n,selection:n?[]:t().selection,selectedWire:n?null:t().selectedWire,selectedNode:n?null:t().selectedNode,editingAnnotation:n?t().editingAnnotation:null}),setEditingAnnotation:n=>e({editingAnnotation:n,selectedAnnotation:n??t().selectedAnnotation,editingElement:n?null:t().editingElement}),setEditingElement:n=>e({editingElement:n,selection:n?[n]:t().selection,editingAnnotation:n?null:t().editingAnnotation,selectedAnnotation:n?null:t().selectedAnnotation,selectedWire:n?null:t().selectedWire,selectedNode:n?null:t().selectedNode}),copySelection:()=>{var f;const{selection:n,diagram:o,internal:r}=t();if(n.length===0)return;const s=new Set(n),i=o.elements.filter(h=>s.has(h.id)).map(h=>structuredClone(h)),a=(o.buses??[]).filter(h=>s.has(h.id)).map(h=>structuredClone(h)),l={};for(const h of n)if(s.has(h)&&!r.buses.has(h)){const g=(f=o.layout)==null?void 0:f[h];if(g){l[h]=structuredClone(g);continue}const m=r.layout.get(h);m&&(l[h]=Nt(m))}const d={};for(const h of n){const g=r.buses.get(h);g&&(d[h]=Ze(g.geometry))}const u=(o.wires??[]).filter(h=>h.ends.every(g=>s.has(Qt(g)))).map(h=>structuredClone(h));e({clipboard:{elements:i,buses:a,placements:l,busLayouts:d,wires:u},clipboardPasteIndex:0})},cutSelection:()=>{const{selection:n}=t();n.length!==0&&(t().copySelection(),t().deleteSelection())},pasteClipboard:()=>{const{clipboard:n,clipboardPasteIndex:o,diagram:r}=t();if(!n||n.elements.length===0&&n.buses.length===0)return;const s=o+1,i=ho*s,a=ho*s,l=new Map;let d=r;for(const f of n.elements){const h=wt(d,f.kind);l.set(f.id,h),d={...d,elements:[...d.elements,{id:h,kind:f.kind}]}}for(const f of n.buses){const h=gn(d);l.set(f.id,h),d={...d,buses:[...d.buses??[],{id:h}]}}const u=f=>{const h=f.indexOf("."),g=h<0?f:f.slice(0,h),m=l.get(g);return m?h<0?m:`${m}${f.slice(h)}`:f};t().dispatch(f=>{const h=n.elements.map(v=>{const b=structuredClone(v);return b.id=l.get(v.id),b}),g=n.buses.map(v=>{const b=structuredClone(v);b.id=l.get(v.id);const k=n.busLayouts[v.id];return k&&(b.layout={...k,at:[k.at[0]+i,k.at[1]+a]}),b}),m={...f.layout??{}};for(const[v,b]of l){const k=n.placements[v];k&&(m[b]={...k,at:[k.at[0]+i,k.at[1]+a]})}const p=n.wires.map(v=>{const b=[u(v.ends[0]),u(v.ends[1])];return{id:vt(b[0],b[1]),ends:b}}),y=_0(f.wires??[],p);return{...f,elements:[...f.elements,...h],buses:g.length?[...f.buses??[],...g]:f.buses,wires:y.length?y:void 0,layout:Object.keys(m).length?m:void 0}}),e({selection:Array.from(l.values()),clipboardPasteIndex:s})},autoArrangeAll:()=>{t().dispatch(n=>{var l;const o=n.layout&&Object.keys(n.layout).length>0,r=(n.buses??[]).some(d=>d.layout);if(!o&&!r)return n;const{layout:s,...i}=n,a=(l=n.buses)==null?void 0:l.map(d=>{const{layout:u,...f}=d;return f});return{...i,buses:a}})},autoArrangeSelection:()=>{const{selection:n}=t();if(n.length===0)return;const o=new Set(n);t().dispatch(r=>{let s=!1,i=r.layout;if(i){const l={};for(const[d,u]of Object.entries(i)){if(o.has(d)){s=!0;continue}l[d]=u}s&&(i=Object.keys(l).length?l:void 0)}let a=r.buses;if(a){const l=a.map(d=>{if(o.has(d.id)&&d.layout){s=!0;const{layout:u,...f}=d;return f}return d});s&&(a=l)}return s?{...r,layout:i,buses:a}:r})},fillUnplacedAll:()=>{const n=t().internal;t().dispatch(o=>{const r=o.layout??{},s={};for(const l of o.elements){if(r[l.id])continue;const d=n.layout.get(l.id);d&&(s[l.id]=Nt(d))}const i=[];if((o.buses??[]).forEach((l,d)=>{l.layout||n.buses.has(l.id)&&i.push({idx:d,bus:l})}),Object.keys(s).length===0&&i.length===0)return o;let a=o.buses;return i.length>0&&a&&(a=a.map(l=>{const d=n.buses.get(l.id);return!l.layout&&d?{...l,layout:Ze(d.geometry)}:l})),{...o,layout:{...r,...s},buses:a}})},fillUnplacedSelection:()=>{const{selection:n,internal:o}=t();n.length!==0&&t().dispatch(r=>{var d;const s=r.layout??{},i={},a=new Map;for(const u of n)if(o.buses.has(u)){const f=o.buses.get(u);(d=r.buses)!=null&&d.find(h=>h.id===u&&h.layout)||a.set(u,Ze(f.geometry))}else{if(s[u])continue;const f=o.layout.get(u);f&&(i[u]=Nt(f))}if(Object.keys(i).length===0&&a.size===0)return r;let l=r.buses;return a.size>0&&l&&(l=l.map(u=>a.has(u.id)?{...u,layout:a.get(u.id)}:u)),{...r,layout:{...s,...i},buses:l}})},moveElements:n=>{if(n.size===0)return;const o=t().internal;t().dispatch(r=>{const s={...r.layout??{}},i=new Map;for(const[l,d]of n){if(o.buses.has(l)){i.set(l,d);continue}const u=o.layout.get(l),f=s[l]??(u?Nt(u):{at:[0,0]});s[l]={...f,at:[f.at[0]+d[0],f.at[1]+d[1]]}}let a=r.buses;return i.size>0&&(a=(r.buses??[]).map(l=>{const d=i.get(l.id);if(!d)return l;const u=l.layout??Ze(o.buses.get(l.id).geometry);return{...l,layout:{...u,at:[u.at[0]+d[0],u.at[1]+d[1]]}}})),{...r,layout:s,buses:a}})},deleteSelection:()=>{const{selection:n}=t();if(n.length===0)return;const o=new Set(n);t().dispatch(r=>{const s=r.elements.filter(d=>!o.has(d.id)),i=(r.buses??[]).filter(d=>!o.has(d.id)),a=(r.wires??[]).filter(d=>!o.has(Qt(d.ends[0]))&&!o.has(Qt(d.ends[1]))),l=r.layout?Object.fromEntries(Object.entries(r.layout).filter(([d])=>!o.has(d))):void 0;return{...r,elements:s,buses:i.length?i:void 0,wires:a.length?a:void 0,layout:l&&Object.keys(l).length?l:void 0}}),e({selection:[]})},deleteSelectedWire:()=>{const{selectedWire:n,internal:o}=t();if(!n)return;const r=(t().diagram.wires??[]).find(i=>i.id===n),s=new Set;if(r)for(const i of r.ends){const a=i.indexOf(".");a>0&&s.add(i.slice(0,a))}t().dispatch(i=>{const a=(i.wires??[]).filter(d=>d.id!==n);if(a.length===(i.wires??[]).length)return i;const l={...i.layout??{}};for(const d of s){if(l[d])continue;const u=o.layout.get(d);if(!u)continue;const f={at:u.at};u.rot&&(f.rot=u.rot),u.mirror&&(f.mirror=u.mirror),l[d]=f}return{...i,wires:a.length?a:void 0,layout:Object.keys(l).length?l:void 0}}),e({selectedWire:null})},deleteSelectedNode:()=>{const{selectedNode:n,internal:o}=t();if(!n)return;const r=o.nodes.get(n);if(!r)return;const s=new Set(r.terminals),i=new Set;for(const a of r.terminals){const l=a.indexOf(".");l>0&&i.add(a.slice(0,l))}t().dispatch(a=>{const l={...a.layout??{}};for(const u of i){if(l[u])continue;const f=o.layout.get(u);if(!f)continue;const h={at:f.at};f.rot&&(h.rot=f.rot),f.mirror&&(h.mirror=f.mirror),l[u]=h}const d=(a.wires??[]).filter(u=>!s.has(u.ends[0])&&!s.has(u.ends[1]));return{...a,wires:d.length?d:void 0,layout:Object.keys(l).length?l:void 0}}),e({selectedNode:null})},rotateSelection:n=>{const{selection:o,internal:r}=t();o.length!==0&&t().dispatch(s=>{var d,u,f,h;const i={...s.layout??{}},a=new Map;for(const g of o){if(r.buses.has(g)){const y=r.buses.get(g),b=(((((f=(u=(d=s.buses)==null?void 0:d.find(k=>k.id===g))==null?void 0:u.layout)==null?void 0:f.rot)??y.geometry.rot??0)+n)%360+360)%360;a.set(g,b);continue}const m=i[g]??{at:((h=r.layout.get(g))==null?void 0:h.at)??[0,0]},p=(((m.rot??0)+n)%360+360)%360;i[g]={...m,rot:p}}let l=s.buses;return a.size>0&&(l=(s.buses??[]).map(g=>{if(!a.has(g.id))return g;const m=g.layout??Ze(r.buses.get(g.id).geometry);return{...g,layout:{...m,rot:a.get(g.id)}}})),{...s,layout:i,buses:l}})},mirrorSelection:()=>{const{selection:n,internal:o}=t();n.length!==0&&t().dispatch(r=>{var i;const s={...r.layout??{}};for(const a of n){if(o.buses.has(a))continue;const l=s[a]??{at:((i=o.layout.get(a))==null?void 0:i.at)??[0,0]};s[a]={...l,mirror:!(l.mirror??!1)}}return{...r,layout:s}})},addElement:(n,o,r)=>{if(n==="busbar")return t().addBus(o,320);const s=wt(t().diagram,n);return t().dispatch(i=>{const a={id:s,kind:n,...r??{}};return{...i,elements:[...i.elements,a],layout:{...i.layout??{},[s]:{at:o}}}}),e({selection:[s]}),s},addBus:(n,o,r)=>{const s=gn(t().diagram);return t().dispatch(i=>{const a={id:s,layout:r!==void 0?{at:n,span:o,rot:r}:{at:n,span:o}};return{...i,buses:[...i.buses??[],a]}}),e({selection:[s]}),s},addWire:(n,o)=>{if(n===o)return;const r=vt(n,o);t().dispatch(s=>{const i=s.wires??[];return i.some(a=>a.id===r)?s:{...s,wires:[...i,{id:r,ends:[n,o]}]}})},updateWirePath:(n,o)=>{t().dispatch(r=>{const s=r.wires??[];if(!s.some(d=>d.id===n))return r;const i=o&&o.length>=2?br(o):null,a=i&&i.length>=2?i:null,l=s.map(d=>{if(d.id!==n)return d;if(a)return{...d,path:a};const{path:u,...f}=d;return f});return{...r,wires:l}})},resetWirePath:n=>{t().updateWirePath(n,null)},updateElement:(n,o)=>{t().dispatch(r=>({...r,elements:r.elements.map(s=>s.id===n?{...s,...o}:s)}))},updatePlacement:(n,o)=>{t().dispatch(r=>{var a;const s=((a=r.layout)==null?void 0:a[n])??t().internal.layout.get(n),i={at:o.at??(s==null?void 0:s.at)??[0,0],...o.rot!==void 0?{rot:o.rot}:s!=null&&s.rot?{rot:s.rot}:{},...o.mirror!==void 0?{mirror:o.mirror}:s!=null&&s.mirror?{mirror:s.mirror}:{}};return{...r,layout:{...r.layout??{},[n]:i}}})},updateBus:(n,o)=>{t().dispatch(r=>{const s=(r.buses??[]).map(i=>{if(i.id!==n)return i;const a=t().internal,l=i.layout??(a.buses.has(n)?Ze(a.buses.get(n).geometry):{at:[0,0],span:320}),d={at:o.at??l.at,span:o.span??l.span,...o.rot!==void 0?{rot:o.rot}:l.rot?{rot:l.rot}:{}};return{...i,layout:d}});return{...r,buses:s}})},addAnnotation:(n,o="")=>{const r=b0(t().diagram);return t().dispatch(s=>{const i={id:r,at:n,text:o};return{...s,annotations:[...s.annotations??[],i]}}),r},updateAnnotation:(n,o)=>{t().dispatch(r=>{const s=r.annotations??[];let i=!1;const a=s.map(l=>l.id!==n?l:(i=!0,{...l,...o,id:l.id}));return i?{...r,annotations:a}:r})},deleteAnnotation:n=>{t().dispatch(o=>{const r=o.annotations??[],s=r.filter(i=>i.id!==n);return s.length===r.length?o:{...o,annotations:s.length?s:void 0}}),t().selectedAnnotation===n&&e({selectedAnnotation:null,editingAnnotation:null})}}),{name:"ole-editor",version:2,storage:yr(()=>localStorage),partialize:e=>({diagram:e.diagram,activeTool:e.activeTool,placeKind:e.placeKind,lastPlaceKind:e.lastPlaceKind}),onRehydrateStorage:()=>e=>{e!=null&&e.diagram&&(e.internal=We(e.diagram))}}));function k0(e){return Array.from(new Set(e))}function Qt(e){const t=e.indexOf(".");return t<0?e:e.slice(0,t)}function _0(e,t){const n=new Set(e.map(r=>r.id)),o=e.slice();for(const r of t)n.has(r.id)||(n.add(r.id),o.push(r));return o}function Nt(e){return{at:[e.at[0],e.at[1]],...e.rot?{rot:e.rot}:{},...e.mirror?{mirror:e.mirror}:{}}}function Ze(e){return{at:[e.at[0],e.at[1]],span:e.span,...e.rot?{rot:e.rot}:{}}}let xm=null;function po(e){xm=e}function Ue(){return xm}const Lt=10;function ym(){if(typeof document>"u")return!0;const e=document.querySelector(".ole-canvas-root");return!!e&&!e.classList.contains("hide-grid")}function ne(e){return ym()?Math.round(e/Lt)*Lt:e}const S0=30,j0=144;function bm(e,t){const n=Ke[e],o=x.getState(),r=o.diagram;if(!n||e==="busbar")return{newElementId:o.addElement(e,t),attachedToBus:!1};const s=$0(r,t);if(!s){const p=wm(n),y=p?[ne(t[0])-p.x,ne(t[1])-p.y]:[ne(t[0]),ne(t[1])];return{newElementId:o.addElement(e,y),attachedToBus:!1}}const{busId:i,busAt:a,axis:l}=s,d=E0(n,l),u=wt(r,e),f=n.terminals.find(p=>p.id===d),h=l==="x"?t[0]:a[0],g=l==="y"?t[1]:a[1],m=f?[ne(h)-f.x,ne(g)-f.y]:[ne(t[0]),ne(t[1])];return o.dispatch(p=>{const y={id:u,kind:e},v={at:m},b=`${u}.${d}`,k={id:vt(i,b),ends:[i,b]};return{...p,elements:[...p.elements,y],wires:[...p.wires??[],k],layout:{...p.layout??{},[u]:v}}}),o.setSelection([u]),{newElementId:u,attachedToBus:!0}}function $0(e,t){const n=x.getState().internal;let o=null;for(const r of e.buses??[]){const s=n.buses.get(r.id);if(!s)continue;const{axis:i,at:a,span:l}=s.geometry;let d;if(i==="x"){const u=a[0]-l/2,f=a[0]+l/2,h=t[0]<u?u-t[0]:t[0]>f?t[0]-f:0,g=Math.abs(t[1]-a[1]);d=Math.sqrt(h*h+g*g)}else{const u=a[1]-l/2,f=a[1]+l/2,h=t[1]<u?u-t[1]:t[1]>f?t[1]-f:0,g=Math.abs(t[0]-a[0]);d=Math.sqrt(g*g+h*h)}d<=S0&&(!o||d<o.dist)&&(o={busId:r.id,busAt:[a[0],a[1]],axis:i,dist:d})}return o?{busId:o.busId,busAt:o.busAt,axis:o.axis}:null}function E0(e,t){return e.terminals.length===0?"t":[...e.terminals].sort((o,r)=>t==="x"?o.y-r.y:o.x-r.x)[0].id}function wm(e){return!e||e.stretchable||e.terminals.length===0?null:[...e.terminals].sort((n,o)=>n.y-o.y)[0]}function vm(e,t){const n=x.getState().internal;if(!e.includes(".")&&n.buses.has(e)){const r=n.buses.get(e),{axis:s,at:i,span:a}=r.geometry;if(s==="x"){const g=i[0]-a/2,m=i[0]+a/2,p=Math.max(g,Math.min(m,t[0])),y=i[1],v=t[1]>=y?"s":"n";return{ref:e,world:[p,y],orientation:v,isBus:!0,busId:e}}const l=i[1]-a/2,d=i[1]+a/2,u=Math.max(l,Math.min(d,t[1])),f=i[0],h=t[0]>=f?"e":"w";return{ref:e,world:[f,u],orientation:h,isBus:!0,busId:e}}const o=n.terminals.get(e);return o?{ref:e,world:o.world,orientation:o.orientation,isBus:!1}:null}const N0={n:"s",s:"n",e:"w",w:"e"};function km(e,t,n){if(e.terminals.length===0)return{id:"t",x:0,y:0,orientation:"n"};const o=N0[t.orientation],r=e.terminals.filter(l=>l.orientation===o),s=r.length>0?r:e.terminals;let i=s[0],a=go(i,n,t.world);for(let l=1;l<s.length;l++){const d=s[l],u=go(d,n,t.world);u<a&&(a=u,i=d)}return i}function go(e,t,n){const o=t[0]+e.x-n[0],r=t[1]+e.y-n[1];return o*o+r*r}function T0(e,t,n){const o=Ke[e],r=x.getState(),s=r.diagram;if(!o)return null;const i=vm(t,n);if(!i)return null;const a=n[0]-i.world[0],l=n[1]-i.world[1],d=a*a+l*l<=j0,u=[ne(n[0]),ne(n[1])],f=km(o,i,u),h=d?i.world:u,g=[ne(h[0]-f.x),ne(h[1]-f.y)],m=wt(s,e);return r.dispatch(p=>{const y={id:m,kind:e},v={at:g},b=`${m}.${f.id}`,k=i.isBus&&i.busId?i.busId:t,S={id:vt(k,b),ends:[k,b]};return{...p,elements:[...p.elements,y],wires:[...p.wires??[],S],layout:{...p.layout??{},[m]:v}}}),r.setSelection([m]),{newElementId:m,attachedToBus:i.isBus}}const Ht=9,Bt=7;function Wt(e,t){var s,i;const n=[],o=((s=e.element.name)==null?void 0:s.trim())||e.element.id;if(o&&n.push(o),t!=="all"||!((i=e.libraryDef)!=null&&i.params))return n;const r=e.element.params??{};for(const a of e.libraryDef.params){if(!a.showOnCanvas)continue;const l=r[a.name];l==null||l===""||n.push(`${l}${a.unit??""}`)}return n}function Gt(e){const t=C0(e.viewBox);return t?{x:t.x+t.w+2,y:t.y+4,anchor:"start"}:{x:0,y:0,anchor:"start"}}function qt(e,t){let n=e.x,o=e.y;switch(t.mirror&&(n=-n),t.rot){case 90:[n,o]=[-o,n];break;case 180:[n,o]=[-n,-o];break;case 270:[n,o]=[o,-n];break}return[n+t.at[0],o+t.at[1]]}function C0(e){const t=e.trim().split(/\s+/).map(Number);return t.length!==4||t.some(n=>Number.isNaN(n))?null:{x:t[0],y:t[1],w:t[2],h:t[3]}}function I0(){const e=x(r=>r.internal.elements),t=x(r=>r.internal.layout),n=x(r=>{var s;return((s=r.diagram.meta)==null?void 0:s.labelMode)??"all"}),o=x(r=>r.editingElement);return c.jsx("g",{className:"ole-annotation-layer",pointerEvents:"none",children:Array.from(e.values()).map(r=>{var u;const s=t.get(r.element.id);if(!s||!r.libraryDef)return null;const i=r.libraryDef.label??Gt(r.libraryDef),a=qt(i,s),l=i.anchor??"start";if(o===r.element.id)return c.jsx(A0,{elementId:r.element.id,currentName:((u=r.element.name)==null?void 0:u.trim())||r.element.id,world:a,anchor:l},r.element.id);if(n==="off")return null;const d=Wt(r,n);return d.length===0?null:c.jsx("g",{className:"ole-annotation",transform:`translate(${a[0]} ${a[1]})`,children:d.map((f,h)=>c.jsx("text",{x:0,y:h*Ht,textAnchor:l,className:"ole-annotation-text",children:f},h))},r.element.id)})})}const en=200,tn=9;function A0({elementId:e,currentName:t,world:n,anchor:o}){const r=j.useRef(null);j.useEffect(()=>{const l=r.current;if(!l)return;l.focus();const d=document.createRange();d.selectNodeContents(l);const u=window.getSelection();u==null||u.removeAllRanges(),u==null||u.addRange(d)},[e]);function s(){var h;const l=x.getState(),d=l.diagram.elements.find(g=>g.id===e);if(!d){l.setEditingElement(null);return}const u=(((h=r.current)==null?void 0:h.innerText)??"").replace(/\u00a0/g," ").trim(),f=u===""||u===e?void 0:u;f!==d.name&&l.updateElement(e,{name:f}),l.setEditingElement(null)}function i(l){if(l.key==="Escape"||l.key==="Enter"&&!l.shiftKey){l.preventDefault(),s();return}l.stopPropagation()}let a=n[0];return o==="middle"?a-=en/2:o==="end"&&(a-=en),c.jsx("foreignObject",{x:a,y:n[1]-tn,width:en,height:tn*2.2,className:"ole-element-name-editor",children:c.jsx("div",{ref:r,contentEditable:!0,suppressContentEditableWarning:!0,onBlur:s,onKeyDown:i,onPointerDown:l=>l.stopPropagation(),onMouseDown:l=>l.stopPropagation(),style:{fontSize:`${tn}px`,fontFamily:"ui-sans-serif, system-ui, sans-serif",color:"var(--foreground)",background:"var(--canvas-bg)",outline:"1px dashed var(--selection)",padding:"0 2px",display:"inline-block",minWidth:"20px",lineHeight:1.1,textAlign:o==="middle"?"center":o==="end"?"right":"left",whiteSpace:"nowrap",cursor:"text"},children:t})})}const _m=8,Dt=1.25;function M0(){const e=x(o=>o.diagram.annotations),t=x(o=>o.selectedAnnotation),n=x(o=>o.editingAnnotation);return!e||e.length===0?null:c.jsx("g",{className:"ole-free-annotation-layer",children:e.map(o=>n===o.id?c.jsx(O0,{ann:o},o.id):c.jsx(P0,{ann:o,isSelected:t===o.id},o.id))})}function P0({ann:e,isSelected:t}){const n=e.fontSize??_m,o=e.text===""?[""]:e.text.split(`
192
+ `),r=Math.max(20,...o.map(i=>i.length*n*.55)),s=o.length*n*Dt;return c.jsxs("g",{"data-annotation-id":e.id,className:"ole-free-annotation","data-selected":t?"true":void 0,children:[c.jsx("rect",{x:e.at[0]-1,y:e.at[1]-1,width:r+2,height:s+2,fill:"transparent",className:"ole-free-annotation-hit"}),t&&c.jsx("rect",{x:e.at[0]-1,y:e.at[1]-1,width:r+2,height:s+2,className:"ole-free-annotation-halo"}),o.map((i,a)=>c.jsx("text",{x:e.at[0],y:e.at[1]+n*.85+a*n*Dt,fontSize:n,className:"ole-free-annotation-text",children:i},a))]})}function O0({ann:e}){const t=j.useRef(null),n=e.fontSize??_m;j.useEffect(()=>{const a=t.current;if(!a)return;a.focus();const l=document.createRange();l.selectNodeContents(a);const d=window.getSelection();d==null||d.removeAllRanges(),d==null||d.addRange(l)},[e.id]);function o(){var d;const a=x.getState(),l=(((d=t.current)==null?void 0:d.innerText)??"").replace(/\u00a0/g," ").trimEnd();l===""?a.deleteAnnotation(e.id):l!==e.text&&a.updateAnnotation(e.id,{text:l}),a.setEditingAnnotation(null),l!==""&&a.setSelectedAnnotation(e.id),a.activeTool==="text"&&a.setActiveTool("select")}function r(a){if(a.key==="Escape"){a.preventDefault(),o();return}if(a.key==="Enter"&&!a.shiftKey){a.preventDefault(),o();return}a.stopPropagation()}return c.jsx("foreignObject",{x:e.at[0],y:e.at[1],width:320,height:200,"data-annotation-id":e.id,className:"ole-free-annotation-edit-fo",children:c.jsx("div",{ref:t,contentEditable:!0,suppressContentEditableWarning:!0,onBlur:o,onKeyDown:r,onPointerDown:a=>a.stopPropagation(),onMouseDown:a=>a.stopPropagation(),style:{fontSize:`${n}px`,lineHeight:Dt,fontFamily:"ui-sans-serif, system-ui, sans-serif",color:"var(--foreground)",background:"var(--canvas-bg)",outline:"1px dashed var(--selection)",padding:"0 2px",minWidth:`${n}px`,minHeight:`${n*Dt}px`,whiteSpace:"pre-wrap",wordBreak:"break-word",cursor:"text"},children:e.text})})}const L0=20;function B0(){const e=x(u=>u.selection),t=x(u=>u.internal);if(e.length!==1)return null;const n=e[0],o=t.buses.get(n);if(!o)return null;const{axis:r,at:s,span:i}=o.geometry,a=i/2,l=r==="x"?[s[0]-a,s[1]]:[s[0],s[1]-a],d=r==="x"?[s[0]+a,s[1]]:[s[0],s[1]+a];return c.jsxs("g",{className:"ole-bus-handles",pointerEvents:"auto",children:[c.jsx(xo,{x:l[0],y:l[1],busId:n,side:"start",axis:r}),c.jsx(xo,{x:d[0],y:d[1],busId:n,side:"end",axis:r})]})}function xo({x:e,y:t,busId:n,side:o,axis:r}){const s=Ue(),i=j.useRef(null),a=u=>{if(u.button!==0||(u.stopPropagation(),u.preventDefault(),!s))return;const f=x.getState().internal.buses.get(n);f&&(i.current={pointerId:u.pointerId,startSpan:f.geometry.span,startAt:[...f.geometry.at],startSvg:s.screenToSvg(u.clientX,u.clientY)},u.target.setPointerCapture(u.pointerId))},l=u=>{const f=i.current;if(!f||u.pointerId!==f.pointerId||!s)return;const h=s.screenToSvg(u.clientX,u.clientY),g=r==="x"?h[0]-f.startSvg[0]:h[1]-f.startSvg[1],m=ym()?Math.round(g/Lt)*Lt:g,p=f.startSpan+(o==="end"?m:-m);if(p<L0)return;const y=r==="x"?[f.startAt[0]+m/2,f.startAt[1]]:[f.startAt[0],f.startAt[1]+m/2];x.getState().updateBus(n,{span:p,at:y})},d=u=>{const f=i.current;!f||u.pointerId!==f.pointerId||(u.target.hasPointerCapture(u.pointerId)&&u.target.releasePointerCapture(u.pointerId),i.current=null)};return c.jsx("circle",{className:"ole-bus-handle",cx:e,cy:t,r:5,"data-handle":o,onPointerDown:a,onPointerMove:l,onPointerUp:d,onPointerCancel:d})}const xn=.5;function yt(e,t){return Math.abs(e[1]-t[1])<xn?"h":"v"}function D0(){const e=x(a=>a.selectedWire),t=x(a=>a.internal.wireRenders);if(!e)return null;const n=t.get(e);if(!n||n.path.length<2)return null;const o=n.path,r=o.length,s=[];for(let a=1;a<r-1;a++){const l=yt(o[a-1],o[a]),d=yt(o[a],o[a+1]),u=a-1===0,f=a+1===r-1,h=u&&l==="v"||f&&d==="v",g=u&&l==="h"||f&&d==="h";h&&g||s.push(c.jsx(R0,{wireId:e,index:a,xLocked:h,yLocked:g},`v-${a}`))}const i=[];for(let a=0;a<r-1;a++){const l=o[a],d=o[a+1];Math.abs(l[0]-d[0])<xn&&Math.abs(l[1]-d[1])<xn||i.push(c.jsx(z0,{wireId:e,segIndex:a,axis:yt(l,d)},`m-${a}`))}return c.jsxs("g",{className:"ole-wire-handles",pointerEvents:"auto",children:[i,s]})}function R0({wireId:e,index:t,xLocked:n,yLocked:o}){const r=Ue(),s=j.useRef(null),i=x(m=>{var p;return(p=m.internal.wireRenders.get(e))==null?void 0:p.path});if(!i||t<=0||t>=i.length-1)return null;const[a,l]=i[t],d=n&&!o?"ns-resize":!n&&o?"ew-resize":"move",u=m=>{if(m.button!==0||(m.stopPropagation(),m.preventDefault(),!r))return;const p=x.getState().internal.wireRenders.get(e);p&&(s.current={pointerId:m.pointerId,startPath:p.path.map(y=>[y[0],y[1]]),startSvg:r.screenToSvg(m.clientX,m.clientY),index:t,xLocked:n,yLocked:o},document.body.style.cursor=d,m.target.setPointerCapture(m.pointerId))},f=m=>{const p=s.current;if(!p||m.pointerId!==p.pointerId||!r)return;const y=r.screenToSvg(m.clientX,m.clientY),v=p.startPath,b=p.index;if(b<=0||b>=v.length-1)return;const k=v[b],S=[p.xLocked?k[0]:ne(k[0]+(y[0]-p.startSvg[0])),p.yLocked?k[1]:ne(k[1]+(y[1]-p.startSvg[1]))];if(S[0]===k[0]&&S[1]===k[1])return;const C=v.map(Q=>[Q[0],Q[1]]);C[b]=S;const L=yt(v[b-1],v[b]);b-1>0&&(L==="h"?C[b-1]=[v[b-1][0],S[1]]:C[b-1]=[S[0],v[b-1][1]]);const te=yt(v[b],v[b+1]);b+1<v.length-1&&(te==="h"?C[b+1]=[v[b+1][0],S[1]]:C[b+1]=[S[0],v[b+1][1]]),x.getState().updateWirePath(e,C)},h=m=>{const p=s.current;!p||m.pointerId!==p.pointerId||(m.target.hasPointerCapture(m.pointerId)&&m.target.releasePointerCapture(m.pointerId),s.current=null,document.body.style.cursor="")},g=m=>{m.stopPropagation(),m.preventDefault();const p=x.getState().internal.wireRenders.get(e);if(!p||p.path.length<=2||t<=0||t>=p.path.length-1)return;const y=p.path.filter((v,b)=>b!==t);x.getState().updateWirePath(e,y)};return c.jsx("circle",{className:"ole-wire-handle ole-wire-vertex",cx:a,cy:l,r:5,style:{cursor:d},onPointerDown:u,onPointerMove:f,onPointerUp:h,onPointerCancel:h,onDoubleClick:g})}function z0({wireId:e,segIndex:t,axis:n}){const o=Ue(),r=j.useRef(null),s=x(m=>{var p;return(p=m.internal.wireRenders.get(e))==null?void 0:p.path});if(!s||t<0||t>=s.length-1)return null;const i=s[t],a=s[t+1],l=(i[0]+a[0])/2,d=(i[1]+a[1])/2,u=n==="h"?"ns-resize":"ew-resize",f=m=>{if(m.button!==0||(m.stopPropagation(),m.preventDefault(),!o))return;const p=x.getState().internal.wireRenders.get(e);p&&(r.current={pointerId:m.pointerId,startPath:p.path.map(y=>[y[0],y[1]]),startSvg:o.screenToSvg(m.clientX,m.clientY),axis:n,segIndex:t},document.body.style.cursor=u,m.currentTarget.setPointerCapture(m.pointerId))},h=m=>{const p=r.current;if(!p||m.pointerId!==p.pointerId||!o)return;const y=o.screenToSvg(m.clientX,m.clientY),v=p.startPath,b=p.segIndex;if(b>=v.length-1)return;const k=v[b],S=v[b+1],C=[];for(let L=0;L<=b;L++)C.push(v[L]);if(p.axis==="h"){const L=ne(k[1]+(y[1]-p.startSvg[1]));C.push([k[0],L]),C.push([S[0],L])}else{const L=ne(k[0]+(y[0]-p.startSvg[0]));C.push([L,k[1]]),C.push([L,S[1]])}for(let L=b+1;L<v.length;L++)C.push(v[L]);x.getState().updateWirePath(e,C)},g=m=>{const p=r.current;if(!p||m.pointerId!==p.pointerId)return;const y=m.currentTarget;y.hasPointerCapture(m.pointerId)&&y.releasePointerCapture(m.pointerId),r.current=null,document.body.style.cursor=""};return c.jsxs("g",{className:"ole-wire-handle ole-wire-midpoint-group",style:{cursor:u},onPointerDown:f,onPointerMove:h,onPointerUp:g,onPointerCancel:g,children:[c.jsx("circle",{className:"ole-wire-midpoint-hit",cx:l,cy:d,r:8}),c.jsx("circle",{className:"ole-wire-handle ole-wire-midpoint",cx:l,cy:d,r:3.5})]})}const F0=3,nn=12;function H0(){const e=x(a=>a.internal.buses),t=x(a=>a.selection),n=x(a=>a.selectedNode),o=x(a=>a.internal.nodes),r=x(a=>a.internal.terminalToNode),s=new Set(t),i=new Set;if(n){const a=o.get(n);if(a)for(const l of a.terminals)l.includes(".")||i.add(l)}return c.jsx("g",{className:"ole-bus-layer",children:Array.from(e.values()).map(({bus:a,geometry:l})=>{const{axis:d,at:u,span:f}=l,h=f/2,g=d==="x"?u[0]-h:u[0],m=d==="x"?u[1]:u[1]-h,p=d==="x"?u[0]+h:u[0],y=d==="x"?u[1]:u[1]+h,v=s.has(a.id),b=i.has(a.id),k=r.get(a.id)??void 0,S=nn/2,C=d==="x"?u[0]-h:u[0]-S,L=d==="x"?u[1]-S:u[1]-h,te=d==="x"?f:nn,Q=d==="x"?nn:f;return c.jsxs("g",{"data-bus-id":a.id,"data-element-id":a.id,"data-node-id":k,"data-selected":v?"true":void 0,"data-node-related":b?"true":void 0,className:"ole-bus",children:[c.jsx("rect",{x:C,y:L,width:te,height:Q,fill:"transparent",className:"ole-bus-hit"}),c.jsx("line",{x1:g,y1:m,x2:p,y2:y,stroke:"currentColor",strokeWidth:F0,strokeLinecap:"round",fill:"none"})]},a.id)})})}function W0(){const e=x(a=>a.busbarDrawStart),t=x(a=>a.cursorSvg);if(!e||!t)return null;const n=t[0]-e[0],o=t[1]-e[1],r=Math.abs(n)>=Math.abs(o),s=r?t[0]:e[0],i=r?e[1]:t[1];return c.jsxs("g",{className:"ole-busbar-preview",pointerEvents:"none",children:[c.jsx("line",{x1:e[0],y1:e[1],x2:s,y2:i,className:"ole-busbar-preview-line"}),c.jsx("circle",{cx:e[0],cy:e[1],r:3.5,className:"ole-busbar-preview-anchor"}),c.jsx("circle",{cx:s,cy:i,r:3.5,className:"ole-busbar-preview-anchor"})]})}function qe(e){const t=[`translate(${e.at[0]} ${e.at[1]})`];return e.rot&&t.push(`rotate(${e.rot})`),e.mirror&&t.push("scale(-1 1)"),t.join(" ")}function G0(e){const t=e.trim().split(/\s+/).map(Number);return t.length!==4||t.some(n=>Number.isNaN(n))?null:{x:t[0],y:t[1],w:t[2],h:t[3]}}function q0({lib:e}){const t=G0(e.viewBox);return t?c.jsx("rect",{className:"ole-element-hit",x:t.x,y:t.y,width:t.w,height:t.h}):null}function K0(){const e=x(a=>a.internal.elements),t=x(a=>a.internal.layout),n=x(a=>a.selection),o=x(a=>a.selectedNode),r=x(a=>a.internal.nodes),s=new Set(n),i=new Set;if(o){const a=r.get(o);if(a)for(const l of a.terminals){const d=l.indexOf(".");d>0&&i.add(l.slice(0,d))}}return c.jsx("g",{className:"ole-element-layer",children:Array.from(e.values()).map(a=>{const l=t.get(a.element.id);if(!l)return null;const d=s.has(a.element.id),u=i.has(a.element.id);return a.libraryDef?c.jsxs("g",{"data-element-id":a.element.id,"data-selected":d?"true":void 0,"data-node-related":u?"true":void 0,transform:qe(l),className:"ole-element",children:[c.jsx(q0,{lib:a.libraryDef}),c.jsx("g",{dangerouslySetInnerHTML:{__html:a.libraryDef.svg}})]},a.element.id):c.jsxs("g",{"data-element-id":a.element.id,"data-selected":d?"true":void 0,"data-node-related":u?"true":void 0,transform:qe(l),className:"ole-element ole-element--unknown",children:[c.jsx("rect",{x:-10,y:-10,width:20,height:20,fill:"none",stroke:"#EF4444",strokeWidth:1,strokeDasharray:"2 2"}),c.jsx("text",{x:0,y:4,fontSize:8,fill:"#EF4444",textAnchor:"middle",fontFamily:"system-ui, sans-serif",children:"?"})]},a.element.id)})})}let Sm=null;const yn=new Set;function Tt(e){Sm=e;for(const t of yn)t(e)}function Y0(){return Sm}function X0(e){return yn.add(e),()=>{yn.delete(e)}}function V0(){const[e,t]=j.useState(Y0());return j.useEffect(()=>X0(t),[]),!e||e.w===0&&e.h===0?null:c.jsx("rect",{className:"ole-marquee",x:e.x,y:e.y,width:e.w,height:e.h,pointerEvents:"none"})}function U0(){const e=x(d=>d.activeTool),t=x(d=>d.placeKind),n=x(d=>d.cursorSvg),o=x(d=>d.placeFromTerminal);if(e!=="place"||!t||!n)return null;const r=pm(t);if(!r)return null;let s=null,i=null;if(o){const d=vm(o,n);d&&(s=km(r,d,n),i={source:d.world,pin:n})}else s=wm(r);const a=n[0]-((s==null?void 0:s.x)??0),l=n[1]-((s==null?void 0:s.y)??0);return c.jsxs("g",{className:"ole-place-ghost-group",pointerEvents:"none",children:[i&&c.jsxs(c.Fragment,{children:[c.jsx("line",{x1:i.source[0],y1:i.source[1],x2:i.pin[0],y2:i.pin[1],className:"ole-wire-preview-line"}),c.jsx("circle",{cx:i.source[0],cy:i.source[1],r:4,className:"ole-wire-preview-anchor"})]}),c.jsx("g",{className:"ole-place-ghost",transform:`translate(${a} ${l})`,opacity:.5,children:c.jsx("g",{dangerouslySetInnerHTML:{__html:r.svg}})})]})}function Z0(){const e=x(r=>r.selection),t=x(r=>r.internal.elements),n=x(r=>r.internal.layout),o=x(r=>r.internal.buses);return e.length===0?null:c.jsx("g",{className:"ole-selection-overlay",pointerEvents:"none",children:e.map(r=>{const s=o.get(r);if(s){const{axis:d,at:u,span:f}=s.geometry,h=f/2,g=d==="x"?u[0]-h:u[0]-4,m=d==="x"?u[1]-4:u[1]-h,p=d==="x"?f:8,y=d==="x"?8:f;return c.jsx("rect",{x:g,y:m,width:p,height:y,fill:"none",className:"ole-selection-rect"},r)}const i=t.get(r),a=n.get(r);if(!(i!=null&&i.libraryDef)||!a)return null;const l=J0(i.libraryDef.viewBox);return l?c.jsx("rect",{x:l.x,y:l.y,width:l.w,height:l.h,fill:"none",className:"ole-selection-rect",transform:qe(a)},r):null})})}function J0(e){const t=e.trim().split(/\s+/).map(Number);return t.length!==4||t.some(n=>Number.isNaN(n))?null:{x:t[0],y:t[1],w:t[2],h:t[3]}}function Q0(){const e=x(s=>s.internal.terminals),t=x(s=>s.internal.terminalToNode),n=x(s=>s.wireFromTerminal),o=x(s=>s.selection),r=new Set(o);return c.jsx("g",{className:"ole-terminal-layer",children:Array.from(e.values()).map(s=>{const i=t.get(s.ref),a=i!==void 0,l=n===s.ref,d=r.has(s.elementId);return c.jsx("circle",{cx:s.world[0],cy:s.world[1],r:3,"data-element-id":s.elementId,"data-terminal-id":s.ref,"data-node-id":i,"data-connected":a?"true":"false","data-active":l?"true":void 0,"data-on-selected":d?"true":void 0,className:"ole-terminal"},s.ref)})})}function ex(){const e=x(i=>i.internal.wireRenders),t=x(i=>i.internal.terminalToNode),n=x(i=>i.diagram.wires),o=x(i=>i.selectedWire),r=x(i=>i.selectedNode),s=new Map;for(const i of n??[]){const a=t.get(i.ends[0]);a&&s.set(i.id,a)}return c.jsx("g",{className:"ole-wire-layer",fill:"none",stroke:"currentColor",strokeWidth:1,children:Array.from(e.values()).flatMap(i=>{const a=i.path;if(a.length<2)return[];const l=a.map(h=>`${h[0]},${h[1]}`).join(" "),d=s.get(i.wireId),u=o===i.wireId,f=r!=null&&r===d;return[c.jsx("polyline",{"data-wire-id":i.wireId,"data-node-id":d,className:"ole-wire-hit",points:l},`hit-${i.wireId}`),c.jsx("polyline",{"data-wire-id":i.wireId,"data-node-id":d,"data-manual":i.userEdited?"true":void 0,"data-selected":u||f?"true":void 0,className:"ole-wire",points:l},i.wireId)]})})}let Ve=null;const bn=new Set;function Me(e){if(!(e===null&&Ve===null||e&&Ve&&e.ref===Ve.ref&&e.world[0]===Ve.world[0]&&e.world[1]===Ve.world[1])){Ve=e;for(const t of bn)t(e)}}function tx(){return Ve}function nx(e){return bn.add(e),()=>{bn.delete(e)}}function ox(){var d,u;const e=x(f=>f.wireFromTerminal),t=x(f=>f.cursorSvg),n=x(f=>f.internal.terminals),[o,r]=j.useState(tx());j.useEffect(()=>nx(r),[]);const s=x(f=>f.internal.buses);if(!e||!t)return null;let i;if(e.includes(".")?i=(d=n.get(e))==null?void 0:d.world:i=(u=s.get(e))==null?void 0:u.geometry.at,!i)return null;const a=(o==null?void 0:o.world[0])??t[0],l=(o==null?void 0:o.world[1])??t[1];return c.jsxs("g",{className:"ole-wire-preview",pointerEvents:"none",children:[c.jsx("line",{x1:i[0],y1:i[1],x2:a,y2:l,className:"ole-wire-preview-line"}),c.jsx("circle",{cx:i[0],cy:i[1],r:4,className:"ole-wire-preview-anchor"}),o&&c.jsxs(c.Fragment,{children:[c.jsx("circle",{cx:o.world[0],cy:o.world[1],r:o.isBus?7:8,className:"ole-wire-preview-target-ring"}),c.jsx("circle",{cx:o.world[0],cy:o.world[1],r:o.isBus?3:4,className:"ole-wire-preview-target-dot"})]})]})}function rt(e,t){return e instanceof Element?e.closest(`[${t}]`):null}function nt(e){var t;return((t=rt(e,"data-element-id"))==null?void 0:t.getAttribute("data-element-id"))??null}function rx(e){var t;return((t=rt(e,"data-bus-id"))==null?void 0:t.getAttribute("data-bus-id"))??null}function Ge(e){var o;const t=(o=rt(e,"data-terminal-id"))==null?void 0:o.getAttribute("data-terminal-id");if(t)return t;const n=rx(e);return n||null}function Kt(e){var t;return((t=rt(e,"data-node-id"))==null?void 0:t.getAttribute("data-node-id"))??null}function yo(e){var t;return((t=rt(e,"data-wire-id"))==null?void 0:t.getAttribute("data-wire-id"))??null}function Rt(e){var t;return((t=rt(e,"data-annotation-id"))==null?void 0:t.getAttribute("data-annotation-id"))??null}function jm(e,t){try{e.dispatchEvent(new PointerEvent("pointercancel",{pointerId:t,bubbles:!0,cancelable:!0,pointerType:"touch"}))}catch{}}function sx(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable}function $m(){const e=x.getState(),t=e.activeTool;if(e.editingAnnotation||e.editingElement){if(typeof document<"u"){const n=document.querySelector(".ole-free-annotation-edit-fo div[contenteditable], .ole-element-name-editor div[contenteditable]");n==null||n.blur()}e.setEditingAnnotation(null),e.setEditingElement(null);return}if(t==="wire"||t==="busbar"||t==="text"){e.setActiveTool("select");return}if(t==="place"){e.placeFromTerminal?e.setPlaceFromTerminal(null):e.placeKind?e.setPlaceKind(null):e.setActiveTool("select");return}(e.selectedNode||e.selectedWire||e.selection.length>0||e.selectedAnnotation)&&e.clearSelection()}function ix(){j.useEffect(()=>{const e=t=>{if(sx(t.target))return;const n=t.metaKey||t.ctrlKey,o=x.getState();if(n&&t.key.toLowerCase()==="z"){t.preventDefault(),t.shiftKey?o.redo():o.undo();return}if(n&&!t.shiftKey&&t.key.toLowerCase()==="y"){t.preventDefault(),o.redo();return}if(n&&t.key.toLowerCase()==="a"){t.preventDefault();const r=x.getState().diagram.elements.map(s=>s.id);o.setSelection(r);return}if(n&&!t.shiftKey&&!t.altKey){const r=t.key.toLowerCase();if(r==="c"){if(o.selection.length===0)return;t.preventDefault(),o.copySelection();return}if(r==="x"){if(o.selection.length===0)return;t.preventDefault(),o.cutSelection();return}if(r==="v"){if(!o.clipboard)return;t.preventDefault(),o.pasteClipboard();return}}if(!n)switch(t.key){case"v":case"V":o.setActiveTool("select");return;case"h":case"H":o.setActiveTool("pan");return;case"w":case"W":o.setActiveTool("wire");return;case"b":case"B":o.setActiveTool("busbar");return;case"p":case"P":o.setActiveTool("place");return;case"t":case"T":o.setActiveTool("text");return;case"r":case"R":o.selection.length>0&&(t.preventDefault(),o.rotateSelection(90));return;case"m":case"M":o.selection.length>0&&(t.preventDefault(),o.mirrorSelection());return;case"Delete":case"Backspace":o.selectedAnnotation?(t.preventDefault(),o.deleteAnnotation(o.selectedAnnotation)):o.selectedWire?(t.preventDefault(),o.deleteSelectedWire()):o.selectedNode?(t.preventDefault(),o.deleteSelectedNode()):o.selection.length>0&&(t.preventDefault(),o.deleteSelection());return;case"Escape":$m();return}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[])}let wn=null;const vn=new Set;function ax(e){if(e!==wn){wn=e;for(const t of vn)t(e)}}function lx(){return wn}function cx(e){return vn.add(e),()=>{vn.delete(e)}}const bo="ole-hover-element-host",dx="ole-hover-terminal-on",ux="ole-hover-node-on";function fx(e){j.useEffect(()=>{const t=e.current;if(!t)return;let n=null,o=null;const r=new Set,s=new Set,i=(f,h,g)=>{for(const m of f)m.classList.remove(g);f.clear();for(const m of h)m.classList.add(g),f.add(m)},a=f=>{var g,m;if(f===n)return;n&&((g=t.querySelector(`[data-element-id="${Ct(n)}"]`))==null||g.classList.remove(bo)),f&&((m=t.querySelector(`[data-element-id="${Ct(f)}"]`))==null||m.classList.add(bo));const h=f?Array.from(t.querySelectorAll(`.ole-terminal[data-element-id="${Ct(f)}"]`)):[];i(r,h,dx),n=f,f?t.setAttribute("data-hover-element",""):t.removeAttribute("data-hover-element"),ax(f)},l=f=>{if(f===o)return;const h=f?Array.from(t.querySelectorAll(`[data-node-id="${Ct(f)}"]`)):[];i(s,h,ux),o=f,f?t.setAttribute("data-hover-node",""):t.removeAttribute("data-hover-node")},d=f=>{a(nt(f.target));const h=Ge(f.target);let g=null;h?g=x.getState().internal.terminalToNode.get(h)??null:g=Kt(f.target),l(g)},u=()=>{a(null),l(null)};return t.addEventListener("pointermove",d),t.addEventListener("pointerleave",u),()=>{t.removeEventListener("pointermove",d),t.removeEventListener("pointerleave",u),a(null),l(null)}},[e])}function Ct(e){return e.replace(/(["\\])/g,"\\$1")}function Em(e,t){const n=x.getState().internal;if(!e.includes(".")){const r=n.buses.get(e);if(!r)return null;const{axis:s,at:i,span:a}=r.geometry;if(s==="x"){const f=i[0]-a/2,h=i[0]+a/2,g=Math.max(f,Math.min(h,t[0]));return{ref:e,world:[g,i[1]],isBus:!0}}const l=i[1]-a/2,d=i[1]+a/2,u=Math.max(l,Math.min(d,t[1]));return{ref:e,world:[i[0],u],isBus:!0}}const o=n.terminals.get(e);return o?{ref:e,world:o.world,isBus:!1}:null}const wo=3;let ie=null,Se=null,je=null,ae=null;const mx={id:"select",cursor:"default",onPointerDown(e,t){var h,g,m,p,y,v,b;if(e.button!==0||e.target instanceof Element&&e.target.closest(".ole-bus-handle, .ole-wire-handle"))return;const n=x.getState(),o=Rt(e.target);if(o){e.preventDefault(),e.stopPropagation();const k=(h=n.diagram.annotations)==null?void 0:h.find(S=>S.id===o);if(!k)return;n.setSelectedAnnotation(o),ae={pointerId:e.pointerId,id:o,startSvg:t.viewport.screenToSvg(e.clientX,e.clientY),origin:[k.at[0],k.at[1]],moved:!1};return}const s=(e.target instanceof Element?(g=e.target.closest("[data-terminal-id]"))==null?void 0:g.getAttribute("data-terminal-id"):null)?Ge(e.target):null;if(s){const k=s.indexOf("."),S=k>0?s.slice(0,k):"";if(S&&n.selection.includes(S)){e.preventDefault(),e.stopPropagation(),e.target instanceof Element&&((p=(m=e.target).hasPointerCapture)!=null&&p.call(m,e.pointerId))&&e.target.releasePointerCapture(e.pointerId),t.hostEl.classList.add("tool-wire"),n.setWireFromTerminal(s),n.setCursorSvg(t.viewport.screenToSvg(e.clientX,e.clientY)),je={pointerId:e.pointerId,fromRef:s};return}}let i=nt(e.target);if(!i){const k=yo(e.target);if(k&&typeof document<"u"){const S=document.elementsFromPoint(e.clientX,e.clientY);for(const C of S){const L=(v=(y=C.closest)==null?void 0:y.call(C,"[data-bus-id]"))==null?void 0:v.getAttribute("data-bus-id");if(!L)continue;const te=(b=n.diagram.wires)==null?void 0:b.find(Q=>Q.id===k);te&&(te.ends[0]===L||te.ends[1]===L)&&(i=L);break}}}if(!i){const k=yo(e.target);if(k){if(e.preventDefault(),e.altKey){const S=Kt(e.target);if(S){n.setSelectedNode(S);return}}n.setSelectedWire(k);return}e.shiftKey||n.clearSelection(),Se={pointerId:e.pointerId,startSvg:t.viewport.screenToSvg(e.clientX,e.clientY),shiftKey:e.shiftKey,baseSelection:e.shiftKey?n.selection.slice():[]},t.hostEl.setPointerCapture(e.pointerId),e.preventDefault();return}const a=n.selection;e.shiftKey?n.toggleInSelection(i):a.includes(i)||n.setSelection([i]);const l=e.shiftKey?x.getState().selection:a.includes(i)?a:[i];if(l.length===0)return;const d=x.getState().internal,u=new Map,f=new Map;for(const k of l){const S=d.buses.get(k);if(S){f.set(k,[S.geometry.at[0],S.geometry.at[1]]);continue}const C=d.layout.get(k);C&&u.set(k,{...C})}u.size===0&&f.size===0||(ie={pointerId:e.pointerId,startSvg:t.viewport.screenToSvg(e.clientX,e.clientY),originals:u,busOriginals:f,moved:!1},e.preventDefault())},onPointerMove(e,t){if(ae&&e.pointerId===ae.pointerId){const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=ne(n[0]-ae.startSvg[0]),r=ne(n[1]-ae.startSvg[1]);!ae.moved&&(o!==0||r!==0)&&(ae.moved=!0,t.hostEl.hasPointerCapture(e.pointerId)||t.hostEl.setPointerCapture(e.pointerId));const s=t.hostEl.querySelector(`[data-annotation-id="${He(ae.id)}"]`);s&&s.setAttribute("transform",`translate(${o} ${r})`);return}if(je&&e.pointerId===je.pointerId){const n=t.viewport.screenToSvg(e.clientX,e.clientY);x.getState().setCursorSvg(n);const o=typeof document<"u"?document.elementFromPoint(e.clientX,e.clientY):null,r=o?Ge(o):null;if(!r||r===je.fromRef){Me(null);return}Me(Em(r,n));return}if(ie&&e.pointerId===ie.pointerId){const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=ne(n[0]-ie.startSvg[0]),r=ne(n[1]-ie.startSvg[1]);!ie.moved&&(o!==0||r!==0)&&(ie.moved=!0,t.hostEl.hasPointerCapture(e.pointerId)||t.hostEl.setPointerCapture(e.pointerId));for(const[s,i]of ie.originals){const a=t.hostEl.querySelector(`[data-element-id="${He(s)}"]`);if(!a)continue;const l={...i,at:[i.at[0]+o,i.at[1]+r]};a.setAttribute("transform",qe(l))}for(const s of ie.busOriginals.keys()){const i=t.hostEl.querySelector(`[data-element-id="${He(s)}"]`);i&&i.setAttribute("transform",`translate(${o} ${r})`)}return}if(Se&&e.pointerId===Se.pointerId){const n=t.viewport.screenToSvg(e.clientX,e.clientY);Tt(vo(Se.startSvg,n));return}},onPointerUp(e,t){if(ae&&e.pointerId===ae.pointerId){t.hostEl.hasPointerCapture(e.pointerId)&&t.hostEl.releasePointerCapture(e.pointerId);const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=ne(n[0]-ae.startSvg[0]),r=ne(n[1]-ae.startSvg[1]),s=t.hostEl.querySelector(`[data-annotation-id="${He(ae.id)}"]`);s&&s.removeAttribute("transform"),ae.moved&&(o!==0||r!==0)&&x.getState().updateAnnotation(ae.id,{at:[ae.origin[0]+o,ae.origin[1]+r]}),ae=null;return}if(je&&e.pointerId===je.pointerId){const n=x.getState(),o=je.fromRef;je=null,t.hostEl.classList.remove("tool-wire"),n.setWireFromTerminal(null),n.setCursorSvg(null),Me(null);const r=Ge(e.target);r&&r!==o&&n.addWire(o,r);return}if(ie&&e.pointerId===ie.pointerId){if(t.hostEl.hasPointerCapture(e.pointerId)&&t.hostEl.releasePointerCapture(e.pointerId),ie.moved){const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=ne(n[0]-ie.startSvg[0]),r=ne(n[1]-ie.startSvg[1]);if(o!==0||r!==0){const s=new Map;for(const i of ie.originals.keys())s.set(i,[o,r]);for(const i of ie.busOriginals.keys())s.set(i,[o,r]);x.getState().moveElements(s)}for(const s of ie.busOriginals.keys()){const i=t.hostEl.querySelector(`[data-element-id="${He(s)}"]`);i&&i.removeAttribute("transform")}}ie=null;return}if(Se&&e.pointerId===Se.pointerId){t.hostEl.hasPointerCapture(e.pointerId)&&t.hostEl.releasePointerCapture(e.pointerId);const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=vo(Se.startSvg,n);if(o.w>=wo||o.h>=wo){const r=hx(o);if(Se.shiftKey){const s=new Set(Se.baseSelection);for(const i of r)s.has(i)?s.delete(i):s.add(i);x.getState().setSelection([...s])}else x.getState().setSelection(r)}Tt(null),Se=null}},onPointerCancel(e,t){var n,o,r,s,i,a;if(ae&&e.pointerId===ae.pointerId){const l=t.hostEl.querySelector(`[data-annotation-id="${He(ae.id)}"]`);if(l&&l.removeAttribute("transform"),(o=(n=t.hostEl).hasPointerCapture)!=null&&o.call(n,e.pointerId))try{t.hostEl.releasePointerCapture(e.pointerId)}catch{}ae=null}if(ie&&e.pointerId===ie.pointerId){for(const[l,d]of ie.originals){const u=t.hostEl.querySelector(`[data-element-id="${He(l)}"]`);u&&u.setAttribute("transform",qe(d))}for(const l of ie.busOriginals.keys()){const d=t.hostEl.querySelector(`[data-element-id="${He(l)}"]`);d&&d.removeAttribute("transform")}if((s=(r=t.hostEl).hasPointerCapture)!=null&&s.call(r,e.pointerId))try{t.hostEl.releasePointerCapture(e.pointerId)}catch{}ie=null}if(je&&e.pointerId===je.pointerId){t.hostEl.classList.remove("tool-wire");const l=x.getState();l.setWireFromTerminal(null),l.setCursorSvg(null),Me(null),je=null}if(Se&&e.pointerId===Se.pointerId){if((a=(i=t.hostEl).hasPointerCapture)!=null&&a.call(i,e.pointerId))try{t.hostEl.releasePointerCapture(e.pointerId)}catch{}Tt(null),Se=null}},onDoubleClick(e){const t=x.getState(),n=Rt(e.target);if(n){e.preventDefault(),e.stopPropagation(),t.setEditingAnnotation(n);return}const o=nt(e.target);o&&(e.preventDefault(),e.stopPropagation(),t.setEditingElement(o))},onDeactivate(e){if(ie=null,Se=null,ae=null,je){e.hostEl.classList.remove("tool-wire");const t=x.getState();t.setWireFromTerminal(null),t.setCursorSvg(null),Me(null),je=null}Tt(null)}};function vo(e,t){const n=Math.min(e[0],t[0]),o=Math.min(e[1],t[1]),r=Math.abs(t[0]-e[0]),s=Math.abs(t[1]-e[1]);return{x:n,y:o,w:r,h:s}}function hx(e){const{internal:t}=x.getState(),n=[];for(const o of t.elements.values()){if(!o.libraryDef)continue;const r=t.layout.get(o.element.id);if(!r)continue;const s=gx(o.libraryDef.viewBox);if(!s)continue;const i=[[s.x,s.y],[s.x+s.w,s.y],[s.x,s.y+s.h],[s.x+s.w,s.y+s.h]].map(([f,h])=>px([f,h],r));let a=1/0,l=-1/0,d=1/0,u=-1/0;for(const[f,h]of i)f<a&&(a=f),f>l&&(l=f),h<d&&(d=h),h>u&&(u=h);l>=e.x&&a<=e.x+e.w&&u>=e.y&&d<=e.y+e.h&&n.push(o.element.id)}for(const{bus:o,geometry:r}of t.buses.values()){const{axis:s,at:i,span:a}=r,l=a/2,d=s==="x"?i[0]-l:i[0],u=s==="x"?i[0]+l:i[0],f=s==="x"?i[1]:i[1]-l,h=s==="x"?i[1]:i[1]+l;u>=e.x&&d<=e.x+e.w&&h>=e.y&&f<=e.y+e.h&&n.push(o.id)}return n}function px(e,t){let[n,o]=e;switch(t.mirror&&(n=-n),t.rot){case 0:break;case 90:[n,o]=[-o,n];break;case 180:[n,o]=[-n,-o];break;case 270:[n,o]=[o,-n];break}return[n+t.at[0],o+t.at[1]]}function gx(e){const t=e.trim().split(/\s+/).map(Number);return t.length!==4||t.some(n=>Number.isNaN(n))?null:{x:t[0],y:t[1],w:t[2],h:t[3]}}function He(e){return e.replace(/(["\\])/g,"\\$1")}const xx=4;let V=null;const yx={id:"pan",cursor:"grab",onPointerDown(e,t){if(e.button!==0)return;const n=t.viewport.getViewport(),o=nt(e.target);let r=null;if(o){const s=x.getState();s.selection.includes(o)||s.setSelection([o]);const i=x.getState().selection,a=x.getState().internal,l=new Map,d=new Map;for(const u of i){const f=a.buses.get(u);if(f){d.set(u,[f.geometry.at[0],f.geometry.at[1]]);continue}const h=a.layout.get(u);h&&l.set(u,{...h})}(l.size>0||d.size>0)&&(r={startSvg:t.viewport.screenToSvg(e.clientX,e.clientY),originals:l,busOriginals:d})}V={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,startTx:n.tx,startTy:n.ty,startTarget:e.target,moved:!1,elementDrag:r},t.hostEl.style.cursor="grabbing",e.preventDefault()},onPointerMove(e,t){if(!V||e.pointerId!==V.pointerId)return;const n=e.clientX-V.startX,o=e.clientY-V.startY;if(!V.moved&&Math.hypot(n,o)>xx){V.moved=!0;try{t.hostEl.setPointerCapture(e.pointerId)}catch{}}if(V.moved){if(V.elementDrag){const r=t.viewport.screenToSvg(e.clientX,e.clientY),s=ne(r[0]-V.elementDrag.startSvg[0]),i=ne(r[1]-V.elementDrag.startSvg[1]);for(const[a,l]of V.elementDrag.originals){const d=t.hostEl.querySelector(`[data-element-id="${ft(a)}"]`);if(!d)continue;const u={...l,at:[l.at[0]+s,l.at[1]+i]};d.setAttribute("transform",qe(u))}for(const a of V.elementDrag.busOriginals.keys()){const l=t.hostEl.querySelector(`[data-element-id="${ft(a)}"]`);l&&l.setAttribute("transform",`translate(${s} ${i})`)}return}t.viewport.setViewport({tx:V.startTx+n,ty:V.startTy+o})}},onPointerUp(e,t){if(!(!V||e.pointerId!==V.pointerId)){if(t.hostEl.hasPointerCapture(e.pointerId)&&t.hostEl.releasePointerCapture(e.pointerId),t.hostEl.style.cursor="grab",V.elementDrag&&V.moved){const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=ne(n[0]-V.elementDrag.startSvg[0]),r=ne(n[1]-V.elementDrag.startSvg[1]);if(o!==0||r!==0){const s=new Map;for(const i of V.elementDrag.originals.keys())s.set(i,[o,r]);for(const i of V.elementDrag.busOriginals.keys())s.set(i,[o,r]);x.getState().moveElements(s)}for(const s of V.elementDrag.busOriginals.keys()){const i=t.hostEl.querySelector(`[data-element-id="${ft(s)}"]`);i&&i.removeAttribute("transform")}}else V.moved||bx(V.startTarget);V=null}},onPointerCancel(e,t){if(V!=null&&V.elementDrag){for(const[n,o]of V.elementDrag.originals){const r=t.hostEl.querySelector(`[data-element-id="${ft(n)}"]`);r&&r.setAttribute("transform",qe(o))}for(const n of V.elementDrag.busOriginals.keys()){const o=t.hostEl.querySelector(`[data-element-id="${ft(n)}"]`);o&&o.removeAttribute("transform")}}V=null},onDeactivate(){V=null}};function bx(e){if(!e)return;const t=x.getState(),n=Rt(e);if(n){t.setSelectedAnnotation(n);return}const o=nt(e);if(o){t.setSelection([o]);return}const r=Kt(e);if(r){t.setSelectedNode(r);return}t.clearSelection()}function ft(e){return e.replace(/(["\\])/g,"\\$1")}const pt={tight:1024,compact:720,dense:520,mini:380},ko={full:0,tight:1,compact:2,dense:3,mini:4};function Ie(e,t){return ko[e]>=ko[t]}function wx(e){return e>=pt.tight?"full":e>=pt.compact?"tight":e>=pt.dense?"compact":e>=pt.mini?"dense":"mini"}const Nm=j.createContext("full");function Ye(){return j.useContext(Nm)}function vx(e){const[t,n]=j.useState(null);return j.useLayoutEffect(()=>{const o=e.current;if(!o)return;const r=()=>{const i=o.clientWidth;n(a=>a===i?a:i)};if(r(),typeof ResizeObserver>"u")return;const s=new ResizeObserver(r);return s.observe(o),()=>s.disconnect()},[e]),t}function Tm(){if(typeof window>"u")return!1;try{if(!window.matchMedia("(pointer: coarse)").matches)return!1}catch{return!1}return window.innerWidth<pt.dense}function In(){Tm()&&x.getState().setActiveTool("pan")}function kx(){Tm()&&x.getState().setPlaceKind(null)}const _x={id:"wire",cursor:"crosshair",onActivate(e){e.hostEl.classList.add("tool-wire")},onDeactivate(e){e.hostEl.classList.remove("tool-wire");const t=x.getState();t.setWireFromTerminal(null),t.setCursorSvg(null),Me(null)},onPointerDown(e,t){var r,s;if(e.button!==0)return;const n=Ge(e.target);if(!n)return;e.preventDefault(),e.stopPropagation(),e.target instanceof Element&&((s=(r=e.target).hasPointerCapture)!=null&&s.call(r,e.pointerId))&&e.target.releasePointerCapture(e.pointerId);const o=x.getState();o.setWireFromTerminal(n),o.setCursorSvg(t.viewport.screenToSvg(e.clientX,e.clientY))},onPointerMove(e,t){const n=x.getState().wireFromTerminal;if(!n)return;const o=t.viewport.screenToSvg(e.clientX,e.clientY);x.getState().setCursorSvg(o);const r=typeof document<"u"?document.elementFromPoint(e.clientX,e.clientY):null,s=r?Ge(r):null;if(!s||s===n){Me(null);return}Me(Em(s,o))},onPointerUp(e){const t=x.getState(),n=t.wireFromTerminal;if(!n)return;t.setWireFromTerminal(null),t.setCursorSvg(null),Me(null);const o=Ge(e.target);!o||o===n||(t.addWire(n,o),In())},onPointerLeave(){const e=x.getState();e.setWireFromTerminal(null),e.setCursorSvg(null),Me(null)}},_o=10;let mt=!1;function So(){setTimeout(()=>kx(),0)}const Sx={id:"place",cursor:"copy",onActivate(e){e.hostEl.classList.add("tool-place")},onDeactivate(e){e.hostEl.classList.remove("tool-place");const t=x.getState();t.setPlaceFromTerminal(null),t.setCursorSvg(null),mt=!1},onPointerDown(e,t){var s,i;if(e.button!==0)return;const{placeKind:n}=x.getState();if(!n)return;e.preventDefault();const o=Ge(e.target);if(o){e.stopPropagation(),e.target instanceof Element&&((i=(s=e.target).hasPointerCapture)!=null&&i.call(s,e.pointerId))&&e.target.releasePointerCapture(e.pointerId);const a=x.getState();a.setPlaceFromTerminal(o),a.setCursorSvg(t.viewport.screenToSvg(e.clientX,e.clientY));return}const r=t.viewport.screenToSvg(e.clientX,e.clientY);bm(n,r),mt=!0},onPointerMove(e,t){const n=t.viewport.screenToSvg(e.clientX,e.clientY);x.getState().setCursorSvg([jo(n[0]),jo(n[1])])},onPointerUp(e,t){const n=x.getState(),o=n.placeFromTerminal;if(o){n.setPlaceFromTerminal(null);const{placeKind:r}=n;if(!r)return;const s=t.viewport.screenToSvg(e.clientX,e.clientY);T0(r,o,s),So();return}mt&&(mt=!1,So())},onPointerLeave(){const e=x.getState();e.setPlaceFromTerminal(null),e.setCursorSvg(null)},onPointerCancel(){const e=x.getState();e.setPlaceFromTerminal(null),e.setCursorSvg(null),mt=!1}};function jo(e){return Math.round(e/_o)*_o}const $o=10,Eo=20;function Je(e){return Math.round(e/$o)*$o}const jx={id:"busbar",cursor:"crosshair",onPointerDown(e,t){if(e.button!==0)return;e.preventDefault();const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=[Je(n[0]),Je(n[1])];x.getState().setBusbarDrawStart(o),x.getState().setCursorSvg(o)},onPointerMove(e,t){const n=t.viewport.screenToSvg(e.clientX,e.clientY);x.getState().setCursorSvg([Je(n[0]),Je(n[1])])},onPointerUp(e,t){const n=x.getState().busbarDrawStart;if(x.getState().setBusbarDrawStart(null),!n)return;const o=t.viewport.screenToSvg(e.clientX,e.clientY),r=Je(o[0]),s=Je(o[1]),i=r-n[0],a=s-n[1],l=Math.abs(i)>=Math.abs(a);let d,u,f;if(l){if(u=Math.abs(i),u<Eo)return;d=0,f=[(n[0]+r)/2,n[1]]}else{if(u=Math.abs(a),u<Eo)return;d=90,f=[n[0],(n[1]+s)/2]}x.getState().addBus(f,u,d),In()},onPointerLeave(){const e=x.getState();e.setBusbarDrawStart(null),e.setCursorSvg(null)},onPointerCancel(){const e=x.getState();e.setBusbarDrawStart(null),e.setCursorSvg(null)},onDeactivate(){const e=x.getState();e.setBusbarDrawStart(null),e.setCursorSvg(null)}},$x={id:"text",cursor:"text",onPointerDown(e,t){if(e.button!==0)return;const n=x.getState(),o=Rt(e.target);if(o){e.preventDefault(),e.stopPropagation(),n.setActiveTool("select"),n.setSelectedAnnotation(o);return}e.preventDefault();const r=t.viewport.screenToSvg(e.clientX,e.clientY),s=n.addAnnotation([r[0],r[1]],"");n.setEditingAnnotation(s),In()}},Ex={select:mx,pan:yx,wire:_x,place:Sx,busbar:jx,text:$x};function Nx(e,t){const n=x(o=>o.activeTool);j.useEffect(()=>{var h;const o=e.current;if(!o)return;const r=Ex[n],s={viewport:t,hostEl:o};(h=r.onActivate)==null||h.call(r,s),r.cursor&&(o.style.cursor=r.cursor);const i=g=>{var m;return(m=r.onPointerDown)==null?void 0:m.call(r,g,s)},a=g=>{var m;return(m=r.onPointerMove)==null?void 0:m.call(r,g,s)},l=g=>{var m;return(m=r.onPointerUp)==null?void 0:m.call(r,g,s)},d=g=>{var m;return r.onPointerCancel?r.onPointerCancel(g,s):(m=r.onPointerUp)==null?void 0:m.call(r,g,s)},u=g=>{var m;return(m=r.onPointerLeave)==null?void 0:m.call(r,g,s)},f=g=>{var m;return(m=r.onDoubleClick)==null?void 0:m.call(r,g,s)};return o.addEventListener("pointerdown",i),o.addEventListener("pointermove",a),o.addEventListener("pointerup",l),o.addEventListener("pointercancel",d),o.addEventListener("pointerleave",u),o.addEventListener("dblclick",f),()=>{var g;o.removeEventListener("pointerdown",i),o.removeEventListener("pointermove",a),o.removeEventListener("pointerup",l),o.removeEventListener("pointercancel",d),o.removeEventListener("pointerleave",u),o.removeEventListener("dblclick",f),(g=r.onDeactivate)==null||g.call(r,s),o.style.cursor=""}},[n,e,t])}let kn=1;const _n=new Set;function Tx(e){if(e!==kn){kn=e;for(const t of _n)t(e)}}function Cx(){return kn}function Ix(e){return _n.add(e),()=>{_n.delete(e)}}const on=.1,rn=8,Ax=1.0015,Mx=1.02;function Px(e,t,n={tx:0,ty:0,scale:1}){const o=j.useRef({...n}),r=j.useRef(new Set),s=()=>{const i=t.current,a=e.current;if(i&&i.setAttribute("transform",`translate(${o.current.tx} ${o.current.ty}) scale(${o.current.scale})`),a&&a.style.setProperty("--canvas-scale",String(o.current.scale)),Tx(o.current.scale),r.current.size>0){const l={...o.current};for(const d of r.current)d(l)}};return j.useEffect(()=>{const i=e.current;if(!i)return;let a=!1,l=-1,d=0,u=0,f=0,h=0,g=!1;const m=new Map;let p=null,y=!1;const v=()=>{if(m.size<2){p=null;return}const N=[...m.values()],M=N[1].x-N[0].x,se=N[1].y-N[0].y,oe=Math.hypot(M,se)||1,de=i.getBoundingClientRect();p={startDist:oe,startScale:o.current.scale,startTx:o.current.tx,startTy:o.current.ty,startMidX:(N[0].x+N[1].x)/2-de.left,startMidY:(N[0].y+N[1].y)/2-de.top}},b=N=>{if(N.pointerType==="touch"){if(m.set(N.pointerId,{x:N.clientX,y:N.clientY}),m.size>=2&&!y){y=!0;for(const M of m.keys())M!==N.pointerId&&jm(i,M);v()}if(y){N.stopPropagation(),N.preventDefault();try{i.setPointerCapture(N.pointerId)}catch{}}}},k=N=>{if(N.pointerType!=="touch"||!m.has(N.pointerId)||(m.set(N.pointerId,{x:N.clientX,y:N.clientY}),!y||!p))return;N.stopPropagation();const M=[...m.values()];if(M.length<2)return;const se=M[1].x-M[0].x,oe=M[1].y-M[0].y,de=Math.hypot(se,oe)||1,X=i.getBoundingClientRect(),ue=(M[0].x+M[1].x)/2-X.left,le=(M[0].y+M[1].y)/2-X.top,he=de/p.startDist,ke=sn(p.startScale*he,on,rn),ye=ke/p.startScale;o.current.tx=p.startMidX-(p.startMidX-p.startTx)*ye+(ue-p.startMidX),o.current.ty=p.startMidY-(p.startMidY-p.startTy)*ye+(le-p.startMidY),o.current.scale=ke,s()},S=N=>{var M;if(N.pointerType==="touch"&&m.has(N.pointerId)&&(m.delete(N.pointerId),y)){if(N.stopPropagation(),(M=i.hasPointerCapture)!=null&&M.call(i,N.pointerId))try{i.releasePointerCapture(N.pointerId)}catch{}m.size>=2?v():p=null,m.size===0&&(y=!1)}},C=N=>{N.preventDefault();const M=i.getBoundingClientRect(),se=N.clientX-M.left,oe=N.clientY-M.top,de=N.ctrlKey||N.metaKey;if(N.deltaX===0||de){const le=Math.pow(de?Mx:Ax,-N.deltaY),he=sn(o.current.scale*le,on,rn),ke=he/o.current.scale;o.current.tx=se-(se-o.current.tx)*ke,o.current.ty=oe-(oe-o.current.ty)*ke,o.current.scale=he}else o.current.tx-=N.deltaX,o.current.ty-=N.deltaY;s()},L=N=>{const M=N.button===1,se=g&&N.button===0;!M&&!se||(N.preventDefault(),a=!0,l=N.pointerId,d=N.clientX,u=N.clientY,f=o.current.tx,h=o.current.ty,i.setPointerCapture(N.pointerId),i.style.cursor="grabbing")},te=N=>{!a||N.pointerId!==l||(o.current.tx=f+(N.clientX-d),o.current.ty=h+(N.clientY-u),s())},Q=N=>{a&&N.pointerId===l&&(a=!1,i.releasePointerCapture(N.pointerId),i.style.cursor=g?"grab":"")},ve=N=>{if(N.code==="Space"&&!g){const M=N.target;if(M&&(M.tagName==="INPUT"||M.tagName==="TEXTAREA"||M.isContentEditable))return;g=!0,i.style.cursor="grab",N.preventDefault()}},me=N=>{N.code==="Space"&&(g=!1,a||(i.style.cursor=""))};return i.addEventListener("wheel",C,{passive:!1}),i.addEventListener("pointerdown",L),i.addEventListener("pointermove",te),i.addEventListener("pointerup",Q),i.addEventListener("pointercancel",Q),i.addEventListener("pointerdown",b,{capture:!0}),i.addEventListener("pointermove",k,{capture:!0}),i.addEventListener("pointerup",S,{capture:!0}),i.addEventListener("pointercancel",S,{capture:!0}),window.addEventListener("keydown",ve),window.addEventListener("keyup",me),s(),()=>{i.removeEventListener("wheel",C),i.removeEventListener("pointerdown",L),i.removeEventListener("pointermove",te),i.removeEventListener("pointerup",Q),i.removeEventListener("pointercancel",Q),i.removeEventListener("pointerdown",b,{capture:!0}),i.removeEventListener("pointermove",k,{capture:!0}),i.removeEventListener("pointerup",S,{capture:!0}),i.removeEventListener("pointercancel",S,{capture:!0}),window.removeEventListener("keydown",ve),window.removeEventListener("keyup",me)}},[]),{screenToSvg(i,a){const l=e.current;if(!l)return[i,a];const d=l.getBoundingClientRect(),u=(i-d.left-o.current.tx)/o.current.scale,f=(a-d.top-o.current.ty)/o.current.scale;return[u,f]},getViewport(){return{...o.current}},setViewport(i){i.tx!==void 0&&(o.current.tx=i.tx),i.ty!==void 0&&(o.current.ty=i.ty),i.scale!==void 0&&(o.current.scale=sn(i.scale,on,rn)),s()},subscribe(i){return r.current.add(i),()=>{r.current.delete(i)}}}}function sn(e,t,n){return e<t?t:e>n?n:e}const Cm=typeof navigator<"u"&&/Mac|iP(ad|hone|od)/.test(navigator.platform),Qe=Cm?"⌘":"Ctrl+",Ox=Cm?"⇧":"Shift+",an=[10,20,50,100,200,500,1e3,2e3,5e3,1e4],Lx=18;function Bx(e){for(const t of an)if(t*e>=Lx)return t;return an[an.length-1]}function Dx(){const e=Z(),t=j.useRef(null),n=j.useRef(null),o=j.useRef(null),r=Px(t,n);Nx(t,r),fx(t),j.useEffect(()=>(po(r),()=>po(null)),[r]),j.useEffect(()=>{const u=f=>{const h=o.current;if(!h)return;const m=Bx(f.scale)*f.scale;h.setAttribute("width",String(m)),h.setAttribute("height",String(m)),h.setAttribute("patternTransform",`translate(${f.tx} ${f.ty})`)};return u(r.getViewport()),r.subscribe(u)},[r]);const s=up(),i=j.useCallback((u,f,h)=>{const g=x.getState(),m=g.activeTool;if(m==="wire"||m==="busbar"||m==="place"){$m();return}const p=nt(h);if(p)g.selection.includes(p)||g.setSelection([p]);else{const L=Kt(h);L&&g.selectedNode!==L&&g.setSelectedNode(L)}const y=x.getState(),v=y.selection.length>0,b=y.selectedNode!=null,k=!!y.clipboard,S=y.diagram.elements.length>0,C=[{label:e("menu.undo"),shortcut:`${Qe}Z`,icon:Nn,onSelect:()=>x.getState().undo(),disabled:y.past.length===0},{label:e("menu.redo"),shortcut:`${Qe}${Ox}Z`,icon:En,onSelect:()=>x.getState().redo(),disabled:y.future.length===0},{type:"separator"},{label:e("menu.cut"),shortcut:`${Qe}X`,icon:or,onSelect:()=>x.getState().cutSelection(),disabled:!v},{label:e("menu.copy"),shortcut:`${Qe}C`,icon:Qo,onSelect:()=>x.getState().copySelection(),disabled:!v},{label:e("menu.paste"),shortcut:`${Qe}V`,icon:Jo,onSelect:()=>x.getState().pasteClipboard(),disabled:!k},{type:"separator"},{label:e("menu.rotate"),shortcut:"R",icon:nr,onSelect:()=>x.getState().rotateSelection(90),disabled:!v},{label:e("menu.mirror"),shortcut:"M",icon:er,onSelect:()=>x.getState().mirrorSelection(),disabled:!v},{type:"separator"},{label:e("menu.selectAll"),shortcut:`${Qe}A`,icon:Ah,onSelect:()=>{const L=x.getState();L.setSelection(L.diagram.elements.map(te=>te.id))},disabled:!S},{type:"separator"},{label:e(b&&!v?"menu.disconnect":"menu.delete"),shortcut:"Del",icon:sr,destructive:!0,onSelect:()=>b&&!v?x.getState().deleteSelectedNode():x.getState().deleteSelection(),disabled:!v&&!b}];s.open(u,f,C)},[s,e]);j.useEffect(()=>{const u=t.current;if(!u)return;const f=700,h=4;let g,m=null;const p=()=>{g!==void 0&&window.clearTimeout(g),g=void 0,m=null},y=k=>{k.pointerType==="touch"&&(p(),m={pointerId:k.pointerId,x:k.clientX,y:k.clientY,target:k.target},g=window.setTimeout(()=>{const S=m;m=null,g=void 0,S&&(jm(u,S.pointerId),i(S.x,S.y,S.target))},f))},v=k=>{if(!m||k.pointerId!==m.pointerId)return;const S=k.clientX-m.x,C=k.clientY-m.y;Math.hypot(S,C)>h&&p()},b=k=>{!m||k.pointerId!==m.pointerId||p()};return u.addEventListener("pointerdown",y),u.addEventListener("pointermove",v),u.addEventListener("pointerup",b),u.addEventListener("pointercancel",b),()=>{p(),u.removeEventListener("pointerdown",y),u.removeEventListener("pointermove",v),u.removeEventListener("pointerup",b),u.removeEventListener("pointercancel",b)}},[i]);const a=u=>{u.dataTransfer.types.includes("application/x-oneline-kind")&&(u.preventDefault(),u.dataTransfer.dropEffect="copy")},l=u=>{const f=u.dataTransfer.getData("application/x-oneline-kind");if(!f)return;u.preventDefault();const h=r.screenToSvg(u.clientX,u.clientY);bm(f,h)},d=u=>{u.preventDefault(),i(u.clientX,u.clientY,u.target)};return c.jsx("div",{ref:t,className:"ole-canvas-root absolute inset-0 overflow-hidden",onDragOver:a,onDrop:l,onContextMenu:d,children:c.jsxs("svg",{className:"ole-canvas-svg block h-full w-full",xmlns:"http://www.w3.org/2000/svg",children:[c.jsx("defs",{children:c.jsx("pattern",{ref:o,id:"ole-grid-dots",width:20,height:20,patternUnits:"userSpaceOnUse",children:c.jsx("circle",{cx:0,cy:0,r:2,fill:"var(--canvas-grid-strong)"})})}),c.jsx("rect",{width:"100%",height:"100%",fill:"url(#ole-grid-dots)"}),c.jsxs("g",{ref:n,className:"ole-viewport",children:[c.jsx(H0,{}),c.jsx(ex,{}),c.jsx(K0,{}),c.jsx(I0,{}),c.jsx(M0,{}),c.jsx(Z0,{}),c.jsx(B0,{}),c.jsx(D0,{}),c.jsx(Q0,{}),c.jsx(ox,{}),c.jsx(W0,{}),c.jsx(U0,{}),c.jsx(V0,{})]})]})})}const No=60,Rx=.1,zx=8,Fx=8;function Hx(e,t,n){return e<t?t:e>n?n:e}function Wx(){return document.querySelector(".ole-canvas-root")}function An(){const e=Ue(),t=Wx();if(!e||!t)return!1;const n=t.getBoundingClientRect();if(n.width===0||n.height===0)return!1;const o=t.querySelectorAll("[data-element-id]");if(o.length===0)return e.setViewport({tx:n.width/2,ty:n.height/2,scale:1}),!0;let r=1/0,s=1/0,i=-1/0,a=-1/0;for(const v of o){const b=v.getBoundingClientRect();b.width===0&&b.height===0||(b.left<r&&(r=b.left),b.top<s&&(s=b.top),b.right>i&&(i=b.right),b.bottom>a&&(a=b.bottom))}if(r===1/0)return!1;const[l,d]=e.screenToSvg(r,s),[u,f]=e.screenToSvg(i,a),h=Math.max(u-l,1),g=Math.max(f-d,1),m=Hx(Math.min((n.width-No*2)/h,(n.height-No*2)/g),Rx,zx),p=(l+u)/2,y=(d+f)/2;return e.setViewport({tx:n.width/2-m*p,ty:n.height/2-m*y,scale:m}),!0}function Mn(){let e=Fx;const t=()=>{An()||--e>0&&requestAnimationFrame(t)};requestAnimationFrame(t)}const To=10,Gx=100;function qx(){return typeof window>"u"||!window.matchMedia?!1:window.matchMedia("(hover: none), (pointer: coarse)").matches}function Kx(){const[e,t]=j.useState(lx()),[n,o]=j.useState(!1),[r,s]=j.useState(null),i=j.useRef(null),a=j.useRef(void 0),[l]=j.useState(qx);j.useEffect(()=>cx(m=>t(m)),[]),j.useEffect(()=>{if(window.clearTimeout(a.current),o(!1),s(null),!!e)return a.current=window.setTimeout(()=>o(!0),Gx),()=>window.clearTimeout(a.current)},[e]);const d=x(m=>e?m.diagram.elements.find(p=>p.id===e)??null:null);if(j.useLayoutEffect(()=>{if(!n||!e)return;let m=0,p=-1,y=-1;const v=()=>{const b=document.querySelector(`[data-element-id="${Yx(e)}"]`),k=i.current;if(b&&k){const S=b.getBoundingClientRect();let C=S.bottom+To;C+k.offsetHeight>window.innerHeight-4&&(C=S.top-k.offsetHeight-To);let L=S.left+S.width/2-k.offsetWidth/2;L=Math.max(4,Math.min(L,window.innerWidth-k.offsetWidth-4)),(C!==p||L!==y)&&(s({top:C,left:L}),p=C,y=L)}m=requestAnimationFrame(v)};return m=requestAnimationFrame(v),()=>cancelAnimationFrame(m)},[n,e]),l||!n||!e||!d)return null;const u=Ke[d.kind],f=d.name??d.id,h=(u==null?void 0:u.name)??d.kind,g=d.name&&d.name!==d.id;return typeof document>"u"?null:Vo.createPortal(c.jsxs("div",{ref:i,role:"tooltip",className:"ole-root ole-glass pointer-events-none fixed z-[100] flex items-center gap-1.5 rounded-md border border-border px-2 py-1 text-[11px] leading-snug shadow-md",style:{top:(r==null?void 0:r.top)??-9999,left:(r==null?void 0:r.left)??-9999,opacity:r?1:0,transition:"opacity 80ms ease-out"},children:[c.jsx("span",{className:"font-medium text-foreground",children:f}),g&&c.jsx("span",{className:"font-mono text-[10px] text-muted-foreground",children:d.id}),c.jsx("span",{className:"text-muted-foreground/80",children:"·"}),c.jsx("span",{className:"text-muted-foreground",children:h})]}),document.body)}function Yx(e){return e.replace(/(["\\])/g,"\\$1")}function Xx({width:e,children:t}){const n=e==null?"full":wx(e);return c.jsx(Nm.Provider,{value:n,children:t})}function Co(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Vx(...e){return t=>{let n=!1;const o=e.map(r=>{const s=Co(r,t);return!n&&typeof s=="function"&&(n=!0),s});if(n)return()=>{for(let r=0;r<o.length;r++){const s=o[r];typeof s=="function"?s():Co(e[r],null)}}}}var Ux=Symbol.for("react.lazy"),zt=xe[" use ".trim().toString()];function Zx(e){return typeof e=="object"&&e!==null&&"then"in e}function Im(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Ux&&"_payload"in e&&Zx(e._payload)}function Jx(e){const t=ey(e),n=xe.forwardRef((o,r)=>{let{children:s,...i}=o;Im(s)&&typeof zt=="function"&&(s=zt(s._payload));const a=xe.Children.toArray(s),l=a.find(ny);if(l){const d=l.props.children,u=a.map(f=>f===l?xe.Children.count(d)>1?xe.Children.only(null):xe.isValidElement(d)?d.props.children:null:f);return c.jsx(t,{...i,ref:r,children:xe.isValidElement(d)?xe.cloneElement(d,void 0,u):null})}return c.jsx(t,{...i,ref:r,children:s})});return n.displayName=`${e}.Slot`,n}var Qx=Jx("Slot");function ey(e){const t=xe.forwardRef((n,o)=>{let{children:r,...s}=n;if(Im(r)&&typeof zt=="function"&&(r=zt(r._payload)),xe.isValidElement(r)){const i=ry(r),a=oy(s,r.props);return r.type!==xe.Fragment&&(a.ref=o?Vx(o,i):i),xe.cloneElement(r,a)}return xe.Children.count(r)>1?xe.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var ty=Symbol("radix.slottable");function ny(e){return xe.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===ty}function oy(e,t){const n={...t};for(const o in t){const r=e[o],s=t[o];/^on[A-Z]/.test(o)?r&&s?n[o]=(...a)=>{const l=s(...a);return r(...a),l}:r&&(n[o]=r):o==="style"?n[o]={...r,...s}:o==="className"&&(n[o]=[r,s].filter(Boolean).join(" "))}return{...e,...n}}function ry(e){var o,r;let t=(o=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:o.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(r=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}const Io=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,Ao=lr,sy=(e,t)=>n=>{var o;if((t==null?void 0:t.variants)==null)return Ao(e,n==null?void 0:n.class,n==null?void 0:n.className);const{variants:r,defaultVariants:s}=t,i=Object.keys(r).map(d=>{const u=n==null?void 0:n[d],f=s==null?void 0:s[d];if(u===null)return null;const h=Io(u)||Io(f);return r[d][h]}),a=n&&Object.entries(n).reduce((d,u)=>{let[f,h]=u;return h===void 0||(d[f]=h),d},{}),l=t==null||(o=t.compoundVariants)===null||o===void 0?void 0:o.reduce((d,u)=>{let{class:f,className:h,...g}=u;return Object.entries(g).every(m=>{let[p,y]=m;return Array.isArray(y)?y.includes({...s,...a}[p]):{...s,...a}[p]===y})?[...d,f,h]:d},[]);return Ao(e,i,l,n==null?void 0:n.class,n==null?void 0:n.className)},iy=sy("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground shadow hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),Ee=xe.forwardRef(({className:e,variant:t,size:n,asChild:o=!1,...r},s)=>{const i=o?Qx:"button";return c.jsx(i,{className:we(iy({variant:t,size:n,className:e})),ref:s,...r})});Ee.displayName="Button";const ay=350;function Ne({content:e,children:t,disabled:n,delayMs:o=ay}){const r=j.useRef(null),s=j.useRef(null),[i,a]=j.useState(!1),[l,d]=j.useState(null),u=j.useId(),f=j.useRef(void 0),h=()=>{n||(window.clearTimeout(f.current),f.current=window.setTimeout(()=>a(!0),o))},g=()=>{window.clearTimeout(f.current),a(!1)};j.useLayoutEffect(()=>{if(!i||!r.current||!s.current)return;const v=r.current.getBoundingClientRect(),b=s.current.getBoundingClientRect(),k=8;let S="top",C=v.top-b.height-k;C<4&&(S="bottom",C=v.bottom+k);let L=v.left+v.width/2-b.width/2;L=Math.max(4,Math.min(L,window.innerWidth-b.width-4)),d({top:C,left:L,side:S})},[i,e]),j.useEffect(()=>()=>window.clearTimeout(f.current),[]),j.useEffect(()=>{if(!i)return;const v=k=>{k.key==="Escape"&&a(!1)},b=()=>a(!1);return window.addEventListener("keydown",v),window.addEventListener("scroll",b,!0),window.addEventListener("resize",b),()=>{window.removeEventListener("keydown",v),window.removeEventListener("scroll",b,!0),window.removeEventListener("resize",b)}},[i]);const m=t,p=m.props,y=j.cloneElement(m,{ref:v=>{r.current=v;const b=m.ref;typeof b=="function"?b(v):b&&typeof b=="object"&&(b.current=v)},onPointerEnter:v=>{var b;(b=p.onPointerEnter)==null||b.call(p,v),h()},onPointerLeave:v=>{var b;(b=p.onPointerLeave)==null||b.call(p,v),g()},onFocus:v=>{var b;(b=p.onFocus)==null||b.call(p,v),h()},onBlur:v=>{var b;(b=p.onBlur)==null||b.call(p,v),g()},"aria-describedby":i?u:p["aria-describedby"]});return c.jsxs(c.Fragment,{children:[y,i&&typeof document<"u"&&Vo.createPortal(c.jsx("div",{ref:s,id:u,role:"tooltip","data-side":(l==null?void 0:l.side)??"top",className:"ole-root ole-glass pointer-events-none fixed z-[100] max-w-[280px] rounded-md border border-border px-2 py-1 text-[11px] leading-snug text-foreground shadow-md",style:{top:(l==null?void 0:l.top)??-9999,left:(l==null?void 0:l.left)??-9999,opacity:l?1:0,transition:"opacity 80ms ease-out"},children:e}),document.body)]})}const Mo=12,ly=56;function cy(){var v;const e=Z(),t=x(b=>b.selection),n=x(b=>b.selectedNode),o=x(b=>b.selectedWire),r=x(b=>b.activeTool),s=x(b=>b.rotateSelection),i=x(b=>b.mirrorSelection),a=x(b=>b.deleteSelection),l=x(b=>b.deleteSelectedNode),d=x(b=>b.deleteSelectedWire),u=x(b=>b.resetWirePath),f=x(b=>b.internal.wireRenders),h=o!=null&&((v=f.get(o))==null?void 0:v.userEdited)===!0,g=j.useRef(null);j.useEffect(()=>{const b=g.current;if(!b)return;const k=t.length>0,S=!k&&o!=null,C=!k&&!S&&n!=null;if(!((k||S||C)&&(r==="select"||r==="pan"))){b.style.display="none";return}b.style.display="flex";let te=0,Q="";const ve=()=>{let me=1/0,N=-1/0,M=1/0,se=-1/0,oe=!1;const de=X=>{X.width===0&&X.height===0||(X.left<me&&(me=X.left),X.right>N&&(N=X.right),X.top<M&&(M=X.top),X.bottom>se&&(se=X.bottom),oe=!0)};if(k)for(const X of t){const ue=document.querySelector(`[data-element-id="${CSS.escape(X)}"]`);ue&&de(ue.getBoundingClientRect())}else if(S&&o){const X=document.querySelector(`polyline.ole-wire[data-wire-id="${CSS.escape(o)}"]`);X&&de(X.getBoundingClientRect())}else if(C&&n){const X=document.querySelectorAll(`polyline.ole-wire[data-node-id="${CSS.escape(n)}"]`);for(const ue of X)de(ue.getBoundingClientRect())}if(oe){const X=(me+N)/2;let ue=M-Mo,le="-100%";ue<ly&&(ue=se+Mo,le="0%");const he=`translate3d(${X}px, ${ue}px, 0) translate(-50%, ${le})`;he!==Q&&(b.style.transform=he,Q=he)}te=requestAnimationFrame(ve)};return te=requestAnimationFrame(ve),()=>cancelAnimationFrame(te)},[t,n,o,r]);const m=t.length===0&&o!=null,p=t.length===0&&!m&&n!=null,y=p||m;return c.jsxs("div",{ref:g,role:"toolbar","aria-label":e(m?"ctx.ariaWire":p?"ctx.ariaNode":"ctx.ariaElement"),className:"ole-glass pointer-events-auto fixed left-0 top-0 z-30 hidden items-center gap-0.5 rounded-2xl border border-border p-1 shadow-md",children:[m&&h&&o&&c.jsxs(c.Fragment,{children:[c.jsx(Ne,{content:c.jsxs("div",{className:"space-y-0.5",children:[c.jsx("div",{children:c.jsx("span",{className:"font-medium",children:e("ctx.resetWirePath")})}),c.jsx("div",{className:"text-muted-foreground",children:e("ctx.resetWirePathHint")})]}),children:c.jsx(Ee,{variant:"ghost",size:"icon",className:"size-7",onClick:()=>u(o),"aria-label":e("ctx.resetWirePath"),children:c.jsx(Ih,{})})}),c.jsx("div",{"aria-hidden":!0,className:"mx-0.5 h-4 w-px bg-border"})]}),!y&&c.jsxs(c.Fragment,{children:[c.jsx(Ne,{content:c.jsxs("div",{className:"space-y-0.5",children:[c.jsxs("div",{children:[c.jsx("span",{className:"font-medium",children:e("ctx.rotate")}),c.jsx("span",{className:"ml-1.5 text-muted-foreground",children:"R"})]}),c.jsx("div",{className:"text-muted-foreground",children:e("ctx.rotateHint")})]}),children:c.jsx(Ee,{variant:"ghost",size:"icon",className:"size-7",onClick:()=>s(90),"aria-label":e("ctx.rotate"),children:c.jsx(nr,{})})}),c.jsx(Ne,{content:c.jsxs("div",{className:"space-y-0.5",children:[c.jsxs("div",{children:[c.jsx("span",{className:"font-medium",children:e("ctx.mirror")}),c.jsx("span",{className:"ml-1.5 text-muted-foreground",children:"M"})]}),c.jsx("div",{className:"text-muted-foreground",children:e("ctx.mirrorHint")})]}),children:c.jsx(Ee,{variant:"ghost",size:"icon",className:"size-7",onClick:()=>i(),"aria-label":e("ctx.mirrorTitle"),children:c.jsx(er,{})})}),c.jsx("div",{"aria-hidden":!0,className:"mx-0.5 h-4 w-px bg-border"})]}),c.jsx(Ne,{content:c.jsxs("div",{className:"space-y-0.5",children:[c.jsxs("div",{children:[c.jsx("span",{className:"font-medium",children:e("ctx.delete")}),c.jsx("span",{className:"ml-1.5 text-muted-foreground",children:"Del"})]}),c.jsx("div",{className:"text-muted-foreground",children:e(m?"ctx.deleteHintWire":p?"ctx.deleteHintNode":"ctx.deleteHintElement")})]}),children:c.jsx(Ee,{variant:"ghost",size:"icon",className:"size-7 text-destructive hover:text-destructive",onClick:()=>m?d():p?l():a(),"aria-label":e("ctx.delete"),children:c.jsx(sr,{})})})]})}function Pn({open:e,onOpenChange:t,trigger:n,children:o}){const r=j.useRef(null);return j.useEffect(()=>{if(!e)return;const s=a=>{r.current&&!r.current.contains(a.target)&&t(!1)},i=a=>{a.key==="Escape"&&t(!1)};return window.addEventListener("mousedown",s),window.addEventListener("keydown",i),()=>{window.removeEventListener("mousedown",s),window.removeEventListener("keydown",i)}},[e,t]),c.jsxs("div",{ref:r,className:"relative",children:[n,e&&c.jsx("div",{role:"menu",className:"ole-glass absolute bottom-full right-0 mb-1.5 min-w-52 rounded-md border border-border p-1 shadow-md",children:o})]})}const Am="ole-panel-open";function dy(){if(typeof window>"u")return{outlineOpen:!1};try{const e=window.localStorage.getItem(Am);if(!e)return{outlineOpen:!1};const t=JSON.parse(e);return typeof t!="object"||t===null?{outlineOpen:!1}:{outlineOpen:t.outline===!0}}catch{return{outlineOpen:!1}}}function Po(e){try{const t={outline:e.outlineOpen};window.localStorage.setItem(Am,JSON.stringify(t))}catch{}}const kt=Ft((e,t)=>({...dy(),setOutlineOpen:n=>{e({outlineOpen:n}),Po(t())},toggleOutline:()=>{e(n=>({outlineOpen:!n.outlineOpen})),Po(t())}})),Mt=[.1,.25,.5,.75,1,1.25,1.5,2,3,4,6,8],Mm=.1,Pm=8,Om="ole-grid";function uy(){try{const e=window.localStorage.getItem(Om);return e==null?!0:e==="1"}catch{return!0}}function fy(e){try{window.localStorage.setItem(Om,e?"1":"0")}catch{}}function my(e,t,n){return e<t?t:e>n?n:e}function Lm(){return document.querySelector(".ole-canvas-root")}function On(e){const t=Ue(),n=Lm();if(!t||!n)return;const o=n.getBoundingClientRect(),r=o.width/2,s=o.height/2,i=t.getViewport(),a=my(e,Mm,Pm),l=a/i.scale;t.setViewport({tx:r-(r-i.tx)*l,ty:s-(s-i.ty)*l,scale:a})}function hy(){const e=Ue();if(!e)return;const t=e.getViewport().scale,n=Mt.find(o=>o>t+1e-6)??Pm;On(n)}function py(){const e=Ue();if(!e)return;const t=e.getViewport().scale;let n=Mm;for(let o=Mt.length-1;o>=0;o--)if(Mt[o]<t-1e-6){n=Mt[o];break}On(n)}const gy={off:"id",id:"all",all:"off"};function xy(){var o;const e=x.getState(),t=((o=e.diagram.meta)==null?void 0:o.labelMode)??"all",n=gy[t];e.dispatch(r=>{const s={...r.meta??{},labelMode:n};return{...r,meta:s}})}function Bm(){const[e,t]=j.useState(()=>uy());return j.useEffect(()=>{const n=Lm();n==null||n.classList.toggle("hide-grid",!e),fy(e)},[e]),j.useEffect(()=>{const n=o=>{if(o.metaKey||o.ctrlKey||o.altKey||o.key!=="g"&&o.key!=="G")return;const r=o.target;r&&(r.tagName==="INPUT"||r.tagName==="TEXTAREA"||r.isContentEditable)||(o.preventDefault(),t(s=>!s))};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[]),[e,t]}function Dm(){const e=Z();return c.jsx(Ne,{content:c.jsxs("div",{className:"space-y-0.5",children:[c.jsx("div",{className:"font-medium",children:e("view.zoomOut")}),c.jsx("div",{className:"text-muted-foreground",children:e("view.zoomOutHint")})]}),children:c.jsx(Ee,{variant:"ghost",size:"icon",onClick:py,"aria-label":e("view.zoomOut"),children:c.jsx($n,{})})})}function Rm(){const e=Z();return c.jsx(Ne,{content:c.jsxs("div",{className:"space-y-0.5",children:[c.jsx("div",{className:"font-medium",children:e("view.zoomIn")}),c.jsx("div",{className:"text-muted-foreground",children:e("view.zoomInHint")})]}),children:c.jsx(Ee,{variant:"ghost",size:"icon",onClick:hy,"aria-label":e("view.zoomIn"),children:c.jsx(Th,{})})})}function zm(){const e=Z(),[t,n]=j.useState(Cx);return j.useEffect(()=>Ix(n),[]),c.jsx(Ne,{content:c.jsxs("div",{className:"space-y-0.5",children:[c.jsx("div",{className:"font-medium",children:e("view.reset")}),c.jsx("div",{className:"text-muted-foreground",children:e("view.current",{z:Math.round(t*100)})})]}),children:c.jsxs("button",{type:"button",onClick:()=>On(1),className:"min-w-12 rounded-md px-2 py-1 text-center text-xs tabular-nums text-muted-foreground hover:bg-accent hover:text-accent-foreground","aria-label":e("view.reset"),children:[Math.round(t*100),"%"]})})}function Fm(){const e=Z();return c.jsx(Ne,{content:c.jsxs("div",{className:"space-y-0.5",children:[c.jsx("div",{className:"font-medium",children:e("view.fit")}),c.jsx("div",{className:"text-muted-foreground",children:e("view.fitHint")})]}),children:c.jsx(Ee,{variant:"ghost",size:"icon",onClick:An,"aria-label":e("view.fit"),children:c.jsx($h,{})})})}function Hm({grid:e,setGrid:t}){const n=Z();return c.jsx(Ne,{content:c.jsxs("div",{className:"space-y-0.5",children:[c.jsxs("div",{children:[c.jsx("span",{className:"font-medium",children:n(e?"view.gridHide":"view.gridShow")}),c.jsx("span",{className:"ml-1.5 text-muted-foreground",children:n("view.gridHotkey")})]}),c.jsx("div",{className:"text-muted-foreground",children:n(e?"view.gridHideHint":"view.gridShowHint")})]}),children:c.jsx(Ee,{variant:"ghost",size:"icon",onClick:()=>t(o=>!o),"aria-label":n(e?"view.gridHideAria":"view.gridShowAria"),"aria-pressed":e,className:we(!e&&"text-muted-foreground/60"),children:c.jsx(Sh,{})})})}function Wm(){const e=Z(),t=x(n=>{var o;return((o=n.diagram.meta)==null?void 0:o.labelMode)??"all"});return c.jsx(Ne,{content:c.jsxs("div",{className:"space-y-0.5",children:[c.jsx("div",{className:"font-medium",children:e(t==="off"?"view.labelOff":t==="id"?"view.labelId":"view.labelAll")}),c.jsx("div",{className:"text-muted-foreground",children:e("view.labelHint")})]}),children:c.jsx(Ee,{variant:"ghost",size:"icon",onClick:xy,"aria-label":e("view.label"),"aria-pressed":t!=="off",className:we(t==="off"&&"text-muted-foreground/60"),children:c.jsx(ir,{})})})}function yy({stacked:e}={}){const t=Z(),[n,o]=j.useState(!1),[r,s]=Bm(),i=c.jsxs("div",{className:"space-y-0.5",children:[c.jsx("div",{className:"font-medium",children:t("view.menu")}),c.jsx("div",{className:"text-muted-foreground",children:t("view.menuHint")})]}),a=e?c.jsx(Ne,{content:i,children:c.jsxs("button",{type:"button",onClick:()=>o(l=>!l),"aria-label":t("view.menu"),"aria-pressed":n,className:we("flex h-12 w-12 flex-col items-center justify-center gap-0.5 rounded-md text-[10px] font-medium leading-tight transition-colors",n?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-accent hover:text-accent-foreground"),children:[c.jsx(dn,{className:"size-4"}),c.jsx("span",{className:"max-w-full truncate",children:t("view.menu")})]})}):c.jsx(Ne,{content:i,children:c.jsx(Ee,{variant:"ghost",size:"icon",onClick:()=>o(l=>!l),"aria-label":t("view.menu"),"aria-pressed":n,children:c.jsx(dn,{})})});return c.jsx(Pn,{open:n,onOpenChange:o,trigger:a,children:c.jsxs("div",{className:"flex flex-col gap-0.5",children:[c.jsx(zm,{}),c.jsxs("div",{className:"flex items-center gap-0.5",children:[c.jsx(Dm,{}),c.jsx(Rm,{})]}),c.jsx("div",{"aria-hidden":!0,className:"my-1 h-px bg-border"}),c.jsxs("div",{className:"flex items-center gap-0.5",children:[c.jsx(Fm,{}),c.jsx(Hm,{grid:r,setGrid:s}),c.jsx(Wm,{})]})]})})}function by(){const e=Ye();return Ie(e,"dense")?null:c.jsx(wy,{tier:e})}function wy({tier:e}){const t=Ie(e,"tight"),[n,o]=Bm();return c.jsx("div",{className:"absolute z-20",style:{bottom:"calc(0.75rem + var(--ole-bottom-inset, 0px))",right:"calc(0.75rem + env(safe-area-inset-right, 0px))"},children:c.jsxs("div",{className:"ole-glass flex items-center gap-0.5 rounded-2xl border border-border p-1.5 shadow-sm",children:[c.jsx(Dm,{}),!t&&c.jsx(zm,{}),c.jsx(Rm,{}),c.jsx("div",{"aria-hidden":!0,className:"mx-1 h-4 w-px bg-border"}),c.jsx(Fm,{}),c.jsx(Hm,{grid:n,setGrid:o}),c.jsx(Wm,{})]})})}const Oo=[{id:"select",labelKey:"tool.select",hotkey:"V",descriptionKey:"tool.selectHint",icon:Eh,switchTo:"select",iconOnly:!0},{id:"pan",labelKey:"tool.pan",hotkey:"H",descriptionKey:"tool.panHint",icon:jh,switchTo:"pan",groupBreakAfter:!0,iconOnly:!0},{id:"busbar",labelKey:"tool.bus",hotkey:"B",descriptionKey:"tool.busHint",icon:$n,switchTo:"busbar"},{id:"place",labelKey:"tool.place",hotkey:"P",descriptionKey:"tool.placeHint",icon:rr,switchTo:"place"},{id:"wire",labelKey:"tool.wire",hotkey:"W",descriptionKey:"tool.wireHint",icon:Zo,switchTo:"wire"},{id:"text",labelKey:"tool.text",hotkey:"T",descriptionKey:"tool.textHint",icon:ir,switchTo:"text",iconOnly:!0}];function vy(){const e=Z(),t=x(u=>u.activeTool),n=x(u=>u.placeKind),o=x(u=>u.placeFromTerminal),r=x(u=>u.wireFromTerminal),s=x(u=>u.busbarDrawStart),i=x(u=>u.selection.length>0||u.selectedNode!=null);let a=null,l=!1;switch(t){case"select":a=e(i?"mode.selectWithSel":"mode.selectEmpty"),i&&(l=!0);break;case"pan":a=e("mode.pan");break;case"wire":a=e(r?"mode.wireDragging":"mode.wireInit"),l=!0;break;case"busbar":a=e(s?"mode.busDragging":"mode.busInit"),l=!0;break;case"place":n?o?a=e("mode.placeFromTerm"):a=e("mode.placeNormal"):a=e("mode.placeNoKind"),l=!0;break;case"text":a=e("mode.text"),l=!0;break}if(!a)return null;const d=e(t==="select"?"mode.escSelect":"mode.escOther");return c.jsxs("div",{className:"ole-glass pointer-events-none flex items-center gap-2 rounded-full border border-border px-3 py-1 text-xs text-muted-foreground shadow-sm",children:[c.jsx("span",{children:a}),l&&c.jsxs("span",{className:"text-muted-foreground/70",children:["· ",d]})]})}function ky(){const e=Z(),t=x(m=>m.activeTool),n=x(m=>m.placeKind),o=x(m=>m.setActiveTool),r=x(m=>m.past.length),s=x(m=>m.future.length),i=x(m=>m.undo),a=x(m=>m.redo),l=Ye(),d=Ie(l,"tight"),u=!Ie(l,"dense"),f=Ie(l,"dense"),h=f?Oo.filter(m=>m.id!=="select"&&m.id!=="text"):Oo,g=m=>t===m.switchTo;return c.jsxs("div",{className:"absolute left-1/2 z-20 flex -translate-x-1/2 flex-col items-center gap-1.5",style:{bottom:"calc(0.75rem + var(--ole-bottom-inset, 0px))"},children:[u&&c.jsx(vy,{}),c.jsxs("div",{className:we("ole-glass flex flex-row items-center rounded-2xl border border-border shadow-sm",f?"gap-0.5 p-1":"gap-0.5 p-1.5"),children:[f&&c.jsx(_y,{stacked:!0}),h.map(m=>{const p=m.icon,y=g(m),v=m.id==="place"&&y&&n==null?e("tool.placeNoKindTooltip"):e(m.descriptionKey);return c.jsxs(j.Fragment,{children:[c.jsx(tt,{icon:p,label:e(m.labelKey),hotkey:m.hotkey,active:y,iconOnly:!f&&(m.iconOnly||d),stacked:f,description:v,onClick:()=>{o(m.switchTo,{placeKind:m.presetPlaceKind!==void 0?m.presetPlaceKind:void 0})}}),m.groupBreakAfter&&!f&&c.jsx("div",{"aria-hidden":!0,className:"mx-1 h-5 w-px bg-border"})]},m.id)}),!f&&c.jsx("div",{"aria-hidden":!0,className:"mx-1 h-5 w-px bg-border"}),f?c.jsx(jy,{stacked:!0}):c.jsxs(c.Fragment,{children:[c.jsx(tt,{icon:Nn,label:e("tool.undo"),hotkey:"⌘Z",description:e("tool.undoHint"),iconOnly:!0,disabled:r===0,onClick:i}),c.jsx(tt,{icon:En,label:e("tool.redo"),hotkey:"⌘⇧Z",description:e("tool.redoHint"),iconOnly:!0,disabled:s===0,onClick:a}),c.jsx("div",{"aria-hidden":!0,className:"mx-1 h-5 w-px bg-border"}),c.jsx(Sy,{iconOnly:d})]}),f&&c.jsx(yy,{stacked:!0})]})]})}function _y({stacked:e}){const t=Z(),n=kt(r=>r.outlineOpen),o=kt(r=>r.toggleOutline);return c.jsx(tt,{icon:tr,label:t("outline.title"),active:n,iconOnly:!0,stacked:e,onClick:o})}function tt({icon:e,label:t,hotkey:n,active:o,disabled:r,iconOnly:s,stacked:i,onClick:a,description:l}){const d=c.jsxs("div",{className:"space-y-0.5",children:[c.jsxs("div",{children:[c.jsx("span",{className:"font-medium",children:t}),n&&c.jsx("span",{className:"ml-1.5 text-muted-foreground",children:n})]}),l&&c.jsx("div",{className:"text-muted-foreground",children:l})]});return c.jsx(Ne,{content:d,disabled:r,children:c.jsxs("button",{type:"button",onClick:a,disabled:r,"aria-label":t,"aria-pressed":o,className:we("rounded-md font-medium transition-colors",i?"flex h-12 w-12 flex-col items-center justify-center gap-0.5 text-[10px] leading-tight":"flex h-9 items-center gap-1.5 text-xs",!i&&(s?"w-9 justify-center":"px-2.5"),o?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-accent hover:text-accent-foreground",r&&"pointer-events-none opacity-40"),children:[c.jsxs("span",{className:"relative inline-flex shrink-0",children:[c.jsx(e,{className:"size-4"}),n&&!i&&c.jsx("span",{"aria-hidden":!0,className:we("pointer-events-none absolute -right-1.5 -top-1.5 rounded-sm px-1 font-mono text-[8px] leading-[1.1]",o?"bg-primary-foreground/20 text-primary-foreground/85":"bg-foreground/10 text-muted-foreground"),children:n})]}),i?c.jsx("span",{className:"max-w-full truncate",children:t}):!s&&c.jsx("span",{children:t})]})})}function Gm(){const e=x(r=>r.diagram.elements),t=x(r=>r.diagram.layout),n=x(r=>r.selection),o=t??{};return{hasAnyElement:e.length>0,hasArrangedAny:Object.keys(o).length>0,hasGapsAll:e.some(r=>!o[r.id]),hasSelection:n.length>0,selectionHasArranged:n.some(r=>!!o[r]),selectionHasGaps:n.some(r=>!o[r])}}function Sy({iconOnly:e}){const t=Z(),[n,o]=j.useState(!1),r=Gm(),s=i=>()=>{o(!1),i()};return c.jsxs(Pn,{open:n,onOpenChange:o,trigger:c.jsx(tt,{icon:gt,label:t("layout.label"),description:t("layout.hint"),active:n,iconOnly:e,onClick:()=>o(i=>!i)}),children:[c.jsx($e,{onClick:s(()=>x.getState().autoArrangeAll()),icon:c.jsx(gt,{}),disabled:!r.hasAnyElement||!r.hasArrangedAny,children:t("layout.allAuto")}),c.jsx($e,{onClick:s(()=>x.getState().autoArrangeSelection()),icon:c.jsx(gt,{}),disabled:!r.hasSelection||!r.selectionHasArranged,children:t("layout.selAuto")}),c.jsx("div",{"aria-hidden":!0,className:"my-1 h-px bg-border"}),c.jsx($e,{onClick:s(()=>x.getState().fillUnplacedAll()),icon:c.jsx(Pt,{}),disabled:!r.hasGapsAll,children:t("layout.allFill")}),c.jsx($e,{onClick:s(()=>x.getState().fillUnplacedSelection()),icon:c.jsx(Pt,{}),disabled:!r.hasSelection||!r.selectionHasGaps,children:t("layout.selFill")})]})}function jy({stacked:e}){const t=Z(),[n,o]=j.useState(!1),r=x(h=>h.past.length),s=x(h=>h.future.length),i=x(h=>h.undo),a=x(h=>h.redo),l=x(h=>h.selection.length>0),d=x(h=>h.clipboard!=null),u=Gm(),f=h=>()=>{o(!1),h()};return c.jsxs(Pn,{open:n,onOpenChange:o,trigger:c.jsx(tt,{icon:dn,label:t("tool.more"),description:t("tool.moreHint"),active:n,iconOnly:!0,stacked:e,onClick:()=>o(h=>!h)}),children:[c.jsx($e,{onClick:f(i),icon:c.jsx(Nn,{}),disabled:r===0,children:t("tool.undo")}),c.jsx($e,{onClick:f(a),icon:c.jsx(En,{}),disabled:s===0,children:t("tool.redo")}),c.jsx("div",{"aria-hidden":!0,className:"my-1 h-px bg-border"}),c.jsx($e,{onClick:f(()=>x.getState().cutSelection()),icon:c.jsx(or,{}),disabled:!l,children:t("menu.cut")}),c.jsx($e,{onClick:f(()=>x.getState().copySelection()),icon:c.jsx(Qo,{}),disabled:!l,children:t("menu.copy")}),c.jsx($e,{onClick:f(()=>x.getState().pasteClipboard()),icon:c.jsx(Jo,{}),disabled:!d,children:t("menu.paste")}),c.jsx("div",{"aria-hidden":!0,className:"my-1 h-px bg-border"}),c.jsx($e,{onClick:f(()=>x.getState().autoArrangeAll()),icon:c.jsx(gt,{}),disabled:!u.hasAnyElement||!u.hasArrangedAny,children:t("layout.allAuto")}),c.jsx($e,{onClick:f(()=>x.getState().autoArrangeSelection()),icon:c.jsx(gt,{}),disabled:!u.hasSelection||!u.selectionHasArranged,children:t("layout.selAuto")}),c.jsx($e,{onClick:f(()=>x.getState().fillUnplacedAll()),icon:c.jsx(Pt,{}),disabled:!u.hasGapsAll,children:t("layout.allFill")}),c.jsx($e,{onClick:f(()=>x.getState().fillUnplacedSelection()),icon:c.jsx(Pt,{}),disabled:!u.hasSelection||!u.selectionHasGaps,children:t("layout.selFill")})]})}function $e({children:e,icon:t,onClick:n,disabled:o}){return c.jsxs("button",{type:"button",role:"menuitem",disabled:o,onClick:n,className:we("flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent hover:text-accent-foreground [&>svg]:size-4",o&&"pointer-events-none text-muted-foreground opacity-60 hover:bg-transparent"),children:[t,c.jsx("span",{className:"flex-1",children:e})]})}function $y(){const e=kt(r=>r.outlineOpen),t=kt(r=>r.setOutlineOpen),n=Ye();return Ie(n,"dense")?e?c.jsx("div",{className:"absolute z-10",style:{left:"calc(0.75rem + var(--ole-left-inset, 0px))",right:"calc(0.75rem + var(--ole-right-inset, 0px))",bottom:"calc(4rem + var(--ole-bottom-inset, 0px) + 0.75rem)"},children:c.jsx(Lo,{onClose:()=>t(!1),sheet:!0})}):null:c.jsx("div",{className:"absolute z-10 flex flex-col items-start",style:{bottom:"calc(0.75rem + var(--ole-bottom-inset, 0px))",left:"calc(0.75rem + var(--ole-left-inset, 0px))",maxHeight:"calc(100% - 1.5rem)"},children:e?c.jsx(Lo,{onClose:()=>t(!1)}):c.jsx(Ey,{onClick:()=>t(!0)})})}function Ey({onClick:e}){const t=Z(),n=Ye(),o=Ie(n,"compact");return c.jsxs("button",{type:"button",onClick:e,"aria-label":t("outline.title"),title:t("outline.title"),className:we("ole-glass flex h-12 items-center rounded-2xl border border-border text-muted-foreground shadow-sm transition-colors hover:bg-accent hover:text-accent-foreground",o?"w-12 justify-center":"gap-2 px-3"),children:[c.jsx(tr,{className:"size-4 shrink-0"}),!o&&c.jsx("span",{className:"text-xs font-medium",children:t("outline.title")})]})}function Lo({onClose:e,sheet:t}){const n=Z(),o=x(d=>d.diagram.elements),r=x(d=>d.activeTool==="place"),s=Ye(),i=Ie(s,"compact"),a=Ie(s,"dense"),l=t?"min(50vh, calc(100vh - 9rem))":r?"min(40vh, calc(100vh - 200px))":"min(70vh, calc(100vh - 100px))";return c.jsxs("aside",{className:we("ole-glass flex flex-col overflow-hidden rounded-2xl border border-border shadow-sm",t?"w-full":i?"w-52":"w-64"),style:{height:l},children:[c.jsxs("button",{type:"button",onClick:e,"aria-label":n("outline.collapseAria"),title:n("outline.collapse"),className:"flex items-center gap-1.5 border-b border-border/40 px-3 py-2 text-left transition-colors hover:bg-muted/40",children:[c.jsx("span",{className:"flex-1 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:n("outline.title")}),!a&&c.jsx(Ty,{children:o.length}),c.jsx(Nh,{className:"size-3.5 text-muted-foreground"})]}),c.jsx("div",{className:"flex-1 overflow-y-auto px-2 pb-2",children:o.length===0?c.jsx("p",{className:"px-2 py-2 text-xs italic text-muted-foreground",children:n("outline.empty")}):c.jsx("ul",{className:"space-y-px",children:o.map(d=>c.jsx(Ny,{element:d},d.id))})})]})}function Ny({element:e}){const t=Ke[e.kind],n=x(l=>l.selection.includes(e.id)),o=x(l=>l.setSelection),r=x(l=>l.toggleInSelection),s=Ye(),i=!Ie(s,"compact"),a=l=>{l.shiftKey||l.metaKey||l.ctrlKey?r(e.id):o([e.id])};return c.jsxs("li",{className:"group flex cursor-pointer items-center gap-2 rounded-md px-2 py-1 hover:bg-accent data-[selected=true]:bg-[color-mix(in_oklch,var(--selection)_18%,transparent)]",title:e.note??`${e.name??e.id} (${e.kind})`,"data-element-id":e.id,"data-selected":n?"true":void 0,onClick:a,children:[c.jsx("div",{className:"flex h-4 w-6 shrink-0 items-center justify-center",children:t&&c.jsx("svg",{viewBox:t.viewBox,className:"ole-symbol size-full",preserveAspectRatio:"xMidYMid meet",dangerouslySetInnerHTML:{__html:t.svg}})}),c.jsx("span",{className:"flex-1 truncate text-xs text-foreground/90 group-hover:text-accent-foreground",children:e.name??e.id}),i&&c.jsx("span",{className:"font-mono text-[10px] text-muted-foreground/80",children:e.id})]})}function Ty({children:e}){return c.jsx("span",{className:"rounded bg-muted/50 px-1.5 py-0.5 font-mono text-[10px] tabular-nums text-muted-foreground/80",children:e})}const Cy={"arc-suppression-coil.name":"消弧线圈","arrester.name":"避雷器 (FBL)","async-motor.name":"异步电动机","autotransformer.name":"自耦变压器","battery.name":"电池储能","breaker.name":"断路器 (QF)","busbar.name":"母线段","converter-bidir.name":"双向变流器 (PCS)","ct.name":"电流互感器 (CT)","disconnector.name":"隔离开关 (QS)","earth.name":"接地","earthing-switch.name":"接地刀闸 (QE)","fuse.name":"熔断器 (FU)","generator.name":"发电机 (G)","grid-source.name":"系统电源","grounding-transformer.name":"接地变 (Z形)","inverter.name":"逆变器 (DC→AC)","load-switch.name":"负荷开关","load.name":"负荷","ngr.name":"中性点电阻 (NGR)","pt.name":"电压互感器 (PT)","pv.name":"光伏组件","rectifier.name":"整流器 (AC→DC)","series-reactor.name":"串联电抗器","shunt-capacitor.name":"并联电容器","shunt-reactor.name":"并联电抗器","sync-motor.name":"同步电动机","transformer-2w.name":"双绕组变压器","transformer-3w.name":"三绕组变压器","wind-turbine.name":"风力发电机","gfci-breaker.name":"GFCI 断路器 (RCBO)","rcd.name":"剩余电流装置 (RCD)","recloser.name":"重合闸 (Recloser)","energy-meter.name":"电能表 (Wh)","voltmeter.name":"电压表 (V)","ammeter.name":"电流表 (A)","wattmeter.name":"功率表 (W)","frequency-meter.name":"频率表 (Hz)","contactor.name":"接触器 (KM)","motor-starter.name":"电机启动器","thermal-overload.name":"热过载继电器","vfd.name":"变频器 (VFD)","soft-starter.name":"软启动器","transfer-switch.name":"切换开关 (ATS)","dc-disconnector.name":"直流隔离开关","dc-combiner.name":"直流汇流箱","ev-charger.name":"EV 充电桩","arc-suppression-coil.desc":"中性点谐振接地:电感线圈连接到地","busbar.desc":"可拉伸单母线段,多设备挂接","converter-bidir.desc":"储能变流器:双向 AC ↔ DC","earthing-switch.desc":"隔离开关 + 接地连接,单端口","grid-source.desc":"无穷大母线 / 外部电网","grounding-transformer.desc":"星-曲折接线变压器,中性点接地用","load.desc":"抽象负荷(电流流出箭头)","ngr.desc":"小电阻接地:连接变压器中性点到地","series-reactor.desc":"与并联电抗器同符号;通过用法区分","wind-turbine.desc":"风机:发电机 + 三叶轮标记","gfci-breaker.desc":"剩余电流断路器带过流保护 (UL943 / IEC 61009)。北美 GFCI / 欧洲 RCBO。","rcd.desc":"不带过流保护的剩余电流断路器 (IEC 61008)。","recloser.desc":"中压自动重合闸开关。","energy-meter.desc":"有功电能表 (kWh) — 服务入口 / 子表。","contactor.desc":"主回路接触器, 通常配热继电器和电机使用。","motor-starter.desc":"电机启动器 (IEC 60617 通用符号)。","thermal-overload.desc":"电机热过载保护继电器, 通常串接在接触器和电机之间。","vfd.desc":"Variable Frequency Drive — 异步电动机调速。","soft-starter.desc":"电机软启动器 (晶闸管降压启动)。","transfer-switch.desc":"双源切换开关 (Automatic / Manual Transfer Switch)。两个电源输入 + 一个负荷输出, 互锁不并联。","dc-disconnector.desc":"DC 隔离开关 — 光伏组串 / 储能 直流侧隔离。","dc-combiner.desc":"光伏组串汇流箱 (4 路输入示例)。","ev-charger.desc":"电动汽车充电站 / 充电桩。","breaker.state.open":"断开","disconnector.state.open":"断开","earthing-switch.state.open":"断开","fuse.state.blown":"熔断","load-switch.state.open":"断开","gfci-breaker.state.open":"断开","rcd.state.open":"断开","recloser.state.open":"断开","contactor.state.open":"断开","thermal-overload.state.tripped":"动作","transfer-switch.state.position":"位置 (normal/emergency/off)","dc-disconnector.state.open":"断开","battery.param.E":"容量","busbar.param.Un":"额定电压","converter-bidir.param.S":"容量","load.param.P":"有功功率","load.param.cosphi":"功率因数","ngr.param.R":"电阻","shunt-capacitor.param.Q":"无功容量","shunt-capacitor.param.stages":"分组数","transformer-2w.param.S":"容量","transformer-2w.param.ratio":"变比","gfci-breaker.param.In":"额定电流","gfci-breaker.param.IDn":"剩余动作电流","rcd.param.IDn":"剩余动作电流"},Iy={"arc-suppression-coil.name":"Arc-suppression coil","arrester.name":"Surge arrester (FBL)","async-motor.name":"Asynchronous motor","autotransformer.name":"Autotransformer","battery.name":"Battery storage","breaker.name":"Circuit breaker (QF)","busbar.name":"Busbar segment","converter-bidir.name":"Bidirectional converter (PCS)","ct.name":"Current transformer (CT)","disconnector.name":"Disconnector (QS)","earth.name":"Earth","earthing-switch.name":"Earthing switch (QE)","fuse.name":"Fuse (FU)","generator.name":"Generator (G)","grid-source.name":"Grid source","grounding-transformer.name":"Grounding transformer (zig-zag)","inverter.name":"Inverter (DC→AC)","load-switch.name":"Load break switch","load.name":"Load","ngr.name":"Neutral grounding resistor (NGR)","pt.name":"Voltage transformer (PT)","pv.name":"PV module","rectifier.name":"Rectifier (AC→DC)","series-reactor.name":"Series reactor","shunt-capacitor.name":"Shunt capacitor","shunt-reactor.name":"Shunt reactor","sync-motor.name":"Synchronous motor","transformer-2w.name":"Two-winding transformer","transformer-3w.name":"Three-winding transformer","wind-turbine.name":"Wind turbine","gfci-breaker.name":"GFCI breaker (RCBO)","rcd.name":"Residual current device (RCD)","recloser.name":"Recloser","energy-meter.name":"Energy meter (Wh)","voltmeter.name":"Voltmeter (V)","ammeter.name":"Ammeter (A)","wattmeter.name":"Wattmeter (W)","frequency-meter.name":"Frequency meter (Hz)","contactor.name":"Contactor (KM)","motor-starter.name":"Motor starter","thermal-overload.name":"Thermal overload relay","vfd.name":"Variable frequency drive (VFD)","soft-starter.name":"Soft starter","transfer-switch.name":"Transfer switch (ATS)","dc-disconnector.name":"DC disconnector","dc-combiner.name":"DC combiner box","ev-charger.name":"EV charger","arc-suppression-coil.desc":"Resonant neutral grounding: inductor to earth","busbar.desc":"Stretchable single-bus segment with multiple taps","converter-bidir.desc":"Storage converter: bidirectional AC ↔ DC","earthing-switch.desc":"Disconnector + earth connection, single port","grid-source.desc":"Infinite bus / external grid","grounding-transformer.desc":"Wye-zigzag transformer for neutral grounding","load.desc":"Abstract load (current-out arrow)","ngr.desc":"Low-resistance grounding: transformer neutral to earth","series-reactor.desc":"Same symbol as shunt reactor; distinguished by usage","wind-turbine.desc":"Wind turbine: generator + three-blade rotor mark","gfci-breaker.desc":"Residual-current breaker with overcurrent (UL943 / IEC 61009). NA GFCI / EU RCBO.","rcd.desc":"Residual-current breaker without overcurrent (IEC 61008).","recloser.desc":"Medium-voltage automatic recloser.","energy-meter.desc":"Active energy meter (kWh) — service entrance / submeter.","contactor.desc":"Main-circuit contactor; typically used with a thermal overload and a motor.","motor-starter.desc":"Motor starter (IEC 60617 general symbol).","thermal-overload.desc":"Motor thermal-overload relay; sits between the contactor and the motor.","vfd.desc":"Variable Frequency Drive for induction motor speed control.","soft-starter.desc":"Motor soft-starter (thyristor-based reduced-voltage starting).","transfer-switch.desc":"Two-source transfer switch (ATS / manual). Two source inputs + one load output, mechanically interlocked.","dc-disconnector.desc":"DC isolating switch — PV string / battery DC-side isolation.","dc-combiner.desc":"PV string combiner box (4-input example).","ev-charger.desc":"Electric vehicle charging station.","breaker.state.open":"Open","disconnector.state.open":"Open","earthing-switch.state.open":"Open","fuse.state.blown":"Blown","load-switch.state.open":"Open","gfci-breaker.state.open":"Open","rcd.state.open":"Open","recloser.state.open":"Open","contactor.state.open":"Open","thermal-overload.state.tripped":"Tripped","transfer-switch.state.position":"Position (normal/emergency/off)","dc-disconnector.state.open":"Open","battery.param.E":"Capacity","busbar.param.Un":"Rated voltage","converter-bidir.param.S":"Capacity","load.param.P":"Active power","load.param.cosphi":"Power factor","ngr.param.R":"Resistance","shunt-capacitor.param.Q":"Reactive capacity","shunt-capacitor.param.stages":"Stages","transformer-2w.param.S":"Capacity","transformer-2w.param.ratio":"Ratio","gfci-breaker.param.In":"Rated current","gfci-breaker.param.IDn":"Residual operating current","rcd.param.IDn":"Residual operating current"},Bo={zh:Cy,en:Iy};function Ay(e,t){return Bo[e][t]??Bo.zh[t]}function St(){const e=_t(t=>t.locale);return(t,n)=>Ay(e,t)??n??t}const qm="ole-palette-collapsed",My=new Set(["busbar"]),bt=(()=>{const e={};for(const[t,n]of Object.entries(p0)){const o=n.filter(r=>!My.has(r.id));o.length&&(e[t]=o)}return e})(),Py=(()=>{const e=new Set(uo),t=Object.keys(bt).filter(n=>!e.has(n));return[...uo.filter(n=>{var o;return(o=bt[n])==null?void 0:o.length}),...t]})();function Oy(){try{const e=window.localStorage.getItem(qm);if(!e)return new Set;const t=JSON.parse(e);return Array.isArray(t)?new Set(t.filter(n=>typeof n=="string")):new Set}catch{return new Set}}function Ly(e){try{window.localStorage.setItem(qm,JSON.stringify([...e]))}catch{}}function By(){const e=Z(),t=x(f=>f.activeTool==="place"),n=x(f=>f.placeKind),o=x(f=>f.setActiveTool),r=kt(f=>f.outlineOpen),s=Ye(),i=Ie(s,"dense"),a=68,d=i?void 0:`calc(100vh - ${a}px - ${r?"calc(40vh + 20px)":"68px"})`;if(!t||i&&n!=null)return null;const u=i?{top:`calc(${a}px + var(--ole-top-inset, 0px))`,left:"calc(0.75rem + var(--ole-left-inset, 0px))",right:"calc(0.75rem + var(--ole-right-inset, 0px))",bottom:"calc(4rem + var(--ole-bottom-inset, 0px) + 0.75rem)"}:{top:a};return c.jsx("div",{className:i?"absolute z-20":"absolute left-3 z-20",style:u,role:"dialog","aria-label":e("library.title"),children:c.jsxs("aside",{className:i?"ole-glass flex h-full w-full flex-col overflow-hidden rounded-2xl border border-border shadow-md":"ole-glass flex w-72 flex-col overflow-hidden rounded-2xl border border-border shadow-md",style:d?{maxHeight:d}:void 0,children:[c.jsxs("div",{className:"flex items-center gap-1.5 border-b border-border/40 px-3 py-2",children:[c.jsx("span",{className:"flex-1 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:e("library.title")}),c.jsx("button",{type:"button",onClick:()=>o(i?"pan":"select"),className:"rounded-md p-1 text-muted-foreground hover:bg-accent hover:text-accent-foreground","aria-label":e("common.close"),title:e("common.close"),children:c.jsx(Tn,{className:"size-3.5"})})]}),c.jsx(Dy,{sheet:i})]})})}function Dy({sheet:e}){const t=Z(),n=St(),[o,r]=j.useState(""),[s,i]=j.useState(()=>Oy()),a=j.useMemo(()=>{const f=o.trim().toLowerCase();if(!f)return bt;const h={};for(const[g,m]of Object.entries(bt)){const p=m.filter(y=>{const v=n(`${y.id}.name`,y.name).toLowerCase(),b=n(`${y.id}.desc`,y.description??"").toLowerCase();return v.includes(f)||y.id.toLowerCase().includes(f)||b.includes(f)});p.length&&(h[g]=p)}return h},[o,n]),l=o.trim().length>0,d=l&&Object.values(a).every(f=>!(f!=null&&f.length)),u=j.useCallback((f,h)=>{i(g=>{const m=new Set(g);return h?m.delete(f):m.add(f),Ly(m),m})},[]);return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"px-2 pb-1.5 pt-2",children:c.jsx(Ry,{value:o,onChange:r})}),c.jsx("div",{className:"flex-1 overflow-y-auto px-2 pb-2",children:d?c.jsx("p",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:t("library.empty")}):Py.map(f=>{var y;const h=a[f];if(!(h!=null&&h.length))return null;const g=((y=bt[f])==null?void 0:y.length)??h.length,m=t(`cat.${f}`),p=l||!s.has(f);return c.jsxs("details",{open:p,className:"group mb-2 last:mb-0",onToggle:v=>{l||u(f,v.currentTarget.open)},children:[c.jsxs("summary",{className:"flex cursor-pointer select-none items-center gap-1.5 rounded-md px-2 py-1.5 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground hover:bg-accent hover:text-accent-foreground",children:[c.jsx(yh,{className:"size-3 transition-transform [details:not([open])>summary>&]:-rotate-90"}),c.jsx("span",{className:"flex-1",children:m}),c.jsx(Fy,{children:l&&h.length!==g?`${h.length}/${g}`:g})]}),c.jsx("ul",{className:"mt-0.5 space-y-px",children:h.map(v=>c.jsx(zy,{entry:v,sheet:e},v.id))})]},f)})})]})}function Ry({value:e,onChange:t}){const n=Z();return c.jsxs("div",{className:"relative",children:[c.jsx(Ch,{className:"pointer-events-none absolute left-2 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground"}),c.jsx("input",{type:"text",value:e,onChange:o=>t(o.target.value),placeholder:n("library.searchPlaceholder"),className:"h-7 w-full rounded-md border border-border/60 bg-background/50 pl-7 pr-7 text-xs placeholder:text-muted-foreground focus:border-border focus:outline-none focus:ring-1 focus:ring-ring","aria-label":n("library.searchAria")}),e&&c.jsx("button",{type:"button","aria-label":n("library.clearSearch"),onClick:()=>t(""),className:"absolute right-1 top-1/2 -translate-y-1/2 rounded-sm p-0.5 text-muted-foreground hover:bg-accent hover:text-accent-foreground",children:c.jsx(Tn,{className:"size-3"})})]})}function zy({entry:e,sheet:t}){const n=Z(),o=St(),r=o(`${e.id}.name`,e.name),s=o(`${e.id}.desc`,e.description??""),i=x(f=>f.setActiveTool),a=x(f=>f.activeTool==="place"&&f.placeKind===e.id),l=x(f=>t&&f.activeTool==="place"&&f.placeKind==null&&f.lastPlaceKind===e.id),d=j.useRef(null);j.useEffect(()=>{var f;l&&((f=d.current)==null||f.scrollIntoView({block:"nearest"}))},[l]);const u=f=>{f.dataTransfer.effectAllowed="copy",f.dataTransfer.setData("application/x-oneline-kind",e.id),f.dataTransfer.setData("text/plain",e.id);const h=document.createElement("div");h.className="ole-glass",h.style.cssText=["position:absolute","top:-9999px","left:-9999px","width:64px","height:64px","display:flex","align-items:center","justify-content:center","border-radius:12px","border:1px solid var(--border)","box-shadow:0 4px 12px rgba(0,0,0,0.12)","color:var(--foreground)","padding:8px"].join(";"),h.innerHTML=`<svg class="ole-symbol" viewBox="${e.viewBox}" width="48" height="48" preserveAspectRatio="xMidYMid meet">${e.svg}</svg>`,document.body.appendChild(h),f.dataTransfer.setDragImage(h,32,32),setTimeout(()=>h.remove(),0)};return c.jsxs("li",{ref:d,className:`group flex cursor-grab items-center gap-2.5 rounded-md px-2 py-1.5 transition-colors hover:bg-accent active:cursor-grabbing ${a?"bg-accent ring-1 ring-[var(--selection)]/60":l?"ring-1 ring-[var(--selection)]/30":""}`,draggable:!0,onDragStart:u,onClick:()=>i("place",{placeKind:e.id}),"data-kind":e.id,title:s?`${r} — ${s}`:`${r} — ${n("library.itemHint")}`,children:[c.jsx("div",{className:"flex h-7 w-12 shrink-0 items-center justify-center",children:c.jsx("svg",{viewBox:e.viewBox,className:"ole-symbol size-full",preserveAspectRatio:"xMidYMid meet",dangerouslySetInnerHTML:{__html:e.svg}})}),c.jsx("span",{className:"truncate text-xs text-foreground/80 group-hover:text-accent-foreground",children:r})]})}function Fy({children:e}){return c.jsx("span",{className:"rounded bg-muted/50 px-1.5 py-0.5 font-mono text-[10px] tabular-nums text-muted-foreground/80",children:e})}const Sn="ole-onboarding-dismissed";function Hy(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(Sn)==="1"}catch{return!1}}function Do(e){try{e?window.localStorage.setItem(Sn,"1"):window.localStorage.removeItem(Sn)}catch{}}const Ro=Ft(e=>({dismissed:Hy(),dismiss:()=>{Do(!0),e({dismissed:!0})},reset:()=>{Do(!1),e({dismissed:!1})}}));function Wy(){const e=Z(),t=Ro(o=>o.dismissed),n=Ro(o=>o.dismiss);return t?null:c.jsxs("div",{role:"dialog","aria-label":e("onboard.title"),className:"ole-glass pointer-events-none absolute left-1/2 top-1/2 z-10 w-[min(420px,calc(100vw-2rem))] -translate-x-1/2 -translate-y-1/2 rounded-2xl border border-border p-5 shadow-md",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("h2",{className:"text-sm font-semibold",children:e("onboard.title")}),c.jsx("button",{type:"button",onClick:n,"aria-label":e("onboard.dismiss"),className:"pointer-events-auto rounded-md p-1 text-muted-foreground hover:bg-accent hover:text-accent-foreground",children:c.jsx(Tn,{className:"size-3.5"})})]}),c.jsxs("ol",{className:"mt-3 space-y-2.5",children:[c.jsx(ln,{n:1,icon:c.jsx($n,{}),title:e("onboard.step1.title"),body:e("onboard.step1.body")}),c.jsx(ln,{n:2,icon:c.jsx(rr,{}),title:e("onboard.step2.title"),body:e("onboard.step2.body")}),c.jsx(ln,{n:3,icon:c.jsx(Zo,{}),title:e("onboard.step3.title"),body:e("onboard.step3.body")})]}),c.jsx("button",{type:"button",onClick:n,className:"pointer-events-auto mt-4 w-full rounded-md bg-primary py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90",children:e("onboard.dismiss")})]})}function ln({n:e,icon:t,title:n,body:o}){return c.jsxs("li",{className:"flex items-start gap-2.5",children:[c.jsx("span",{className:"mt-0.5 flex size-5 shrink-0 items-center justify-center rounded-full bg-[color-mix(in_oklch,var(--selection)_18%,transparent)] font-mono text-[10px] font-semibold tabular-nums text-[var(--selection)]","aria-hidden":!0,children:e}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium",children:[c.jsx("span",{className:"text-muted-foreground [&>svg]:size-3.5",children:t}),c.jsx("span",{children:n})]}),c.jsx("p",{className:"mt-0.5 text-[11px] leading-snug text-muted-foreground",children:o})]})]})}function Gy(){const e=Z(),t=x(u=>u.selection),n=x(u=>u.diagram.elements),o=x(u=>u.diagram.buses),r=x(u=>u.selectedNode),s=x(u=>u.selectedWire);if(s)return c.jsx(Uy,{wireId:s});if(r)return c.jsx(Zy,{nodeId:r});if(t.length===0)return c.jsx("div",{className:"px-4 py-5 text-center text-xs text-muted-foreground",children:e("props.empty")});if(t.length>1)return c.jsx("div",{className:"px-4 py-5 text-center text-xs text-muted-foreground",children:e("props.multi",{n:t.length})});const i=t[0],a=(o??[]).find(u=>u.id===i);if(a)return c.jsx(Xy,{bus:a});const l=n.find(u=>u.id===i);if(!l)return null;const d=Ke[l.kind];return c.jsxs("div",{className:"flex flex-col gap-2.5 overflow-y-auto px-3 py-3 text-xs",children:[c.jsx(jt,{label:e("props.name"),value:l.name??"",placeholder:l.id,onCommit:u=>x.getState().updateElement(i,{name:u.trim()===""?void 0:u.trim()})}),c.jsx(Km,{label:e("props.note"),value:l.note??"",onCommit:u=>x.getState().updateElement(i,{note:u.trim()===""?void 0:u.trim()})}),(d==null?void 0:d.state)&&d.state.length>0&&c.jsx("div",{className:"mt-1 flex flex-col gap-1.5 border-t border-border/40 pt-2.5",children:d.state.map(u=>c.jsx(Jy,{id:i,element:l,field:u},u.name))}),c.jsx(qy,{id:i,element:l,schema:(d==null?void 0:d.params)??[]})]})}function qy({id:e,element:t,schema:n}){const o=new Set(n.map(s=>s.name)),r=t.params?Object.entries(t.params).filter(([s])=>!o.has(s)):[];return n.length===0&&r.length===0?null:c.jsxs("div",{className:"mt-1 flex flex-col gap-1.5 border-t border-border/40 pt-2.5",children:[n.map(s=>c.jsx(Ky,{id:e,element:t,field:s},s.name)),r.map(([s,i])=>c.jsx(Yy,{id:e,element:t,fieldKey:s,value:i},s))]})}function Ky({id:e,element:t,field:n}){var l;const o=Z(),r=St(),s=((l=t.params)==null?void 0:l[n.name])??n.default,i=r(`${t.kind}.param.${n.name}`,n.label??n.name),a=d=>{const u={...t.params??{}};d===void 0||d===n.default?delete u[n.name]:u[n.name]=d,x.getState().updateElement(e,{params:Object.keys(u).length>0?u:void 0})};return n.type==="boolean"?c.jsx(st,{label:i,children:c.jsx(Ln,{active:!!s,onClick:()=>a(!s),children:o(s?"common.yes":"common.no")})}):n.type==="number"?c.jsx(Yt,{label:i,value:typeof s=="number"?s:0,unit:n.unit,onCommit:a}):c.jsx(jt,{label:i,value:typeof s=="string"?s:"",unit:n.unit,onCommit:d=>a(d.trim()===""?void 0:d)})}function Yy({id:e,element:t,fieldKey:n,value:o}){const r=Z(),s=i=>{const a={...t.params??{}};i===void 0?delete a[n]:a[n]=i,x.getState().updateElement(e,{params:Object.keys(a).length>0?a:void 0})};return typeof o=="boolean"?c.jsx(st,{label:n,children:c.jsx(Ln,{active:o,onClick:()=>s(!o),children:r(o?"common.yes":"common.no")})}):typeof o=="number"?c.jsx(Yt,{label:n,value:o,onCommit:s}):c.jsx(jt,{label:n,value:o,onCommit:i=>s(i.trim()===""?void 0:i)})}function Xy({bus:e}){const t=Z(),n=e.id,o=r=>{const s=r.trim();jn(n,{name:s===""?void 0:s})};return c.jsxs("div",{className:"flex flex-col gap-2.5 overflow-y-auto px-3 py-3 text-xs",children:[c.jsx(jt,{label:t("props.name"),value:e.name??"",placeholder:e.id,onCommit:o}),c.jsx(Km,{label:t("props.note"),value:e.note??"",onCommit:r=>jn(n,{note:r.trim()===""?void 0:r.trim()})}),c.jsx(Vy,{bus:e})]})}function Vy({bus:e}){const t=(o,r)=>{const s={...e.params??{}};r===void 0||r===""?delete s[o]:s[o]=r,jn(e.id,{params:Object.keys(s).length>0?s:void 0})},n=e.params??{};return c.jsx("div",{className:"mt-1 flex flex-col gap-1.5 border-t border-border/40 pt-2.5",children:c.jsx(Yt,{label:"Un",value:typeof n.Un=="number"?n.Un:0,unit:"kV",onCommit:o=>t("Un",o)})})}function jn(e,t){x.getState().dispatch(n=>{const o=(n.buses??[]).map(r=>r.id===e?{...r,...t}:r);return{...n,buses:o}})}function Uy({wireId:e}){const t=Z(),n=x(m=>m.diagram.wires),o=x(m=>m.diagram.elements),r=x(m=>m.diagram.buses),s=x(m=>m.internal.terminalToNode),i=x(m=>m.setSelectedNode),a=(n??[]).find(m=>m.id===e);if(!a)return c.jsx("div",{className:"px-4 py-5 text-center text-xs text-muted-foreground",children:t("props.wireNotFound",{id:e})});const l=s.get(a.ends[0]),d=new Map(o.map(m=>[m.id,m])),u=new Map((r??[]).map(m=>[m.id,m])),f=m=>{if(!m.includes(".")){const k=u.get(m);return{id:m,label:(k==null?void 0:k.name)??m}}const p=m.indexOf("."),y=m.slice(0,p),v=m.slice(p+1),b=d.get(y);return{id:y,label:(b==null?void 0:b.name)??y,pin:v}},h=f(a.ends[0]),g=f(a.ends[1]);return c.jsxs("div",{className:"flex flex-col gap-3 px-3 py-3 text-xs",children:[c.jsxs("div",{className:"space-y-1",children:[c.jsx("div",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:t("props.wire")}),c.jsx("div",{className:"font-mono text-[12px]",children:a.id})]}),c.jsx("ul",{className:"space-y-0.5 border-t border-border/40 pt-2",children:[h,g].map((m,p)=>c.jsxs("li",{className:"flex cursor-pointer items-center gap-2 rounded-md px-1.5 py-1 hover:bg-accent",onClick:()=>x.getState().setSelection([m.id]),children:[c.jsx("span",{className:"flex-1 truncate font-mono text-[11px]",children:m.id}),c.jsx("span",{className:"truncate text-[10px] text-muted-foreground",children:m.label}),m.pin&&c.jsx("span",{className:"font-mono text-[10px] text-muted-foreground/80",children:m.pin})]},p))}),l&&c.jsx("button",{type:"button",className:"self-start rounded-md border border-border/60 px-2 py-1 text-[11px] text-muted-foreground hover:bg-accent",onClick:()=>i(l),children:t("props.selectWholeNode")})]})}function Zy({nodeId:e}){const t=Z(),n=x(a=>a.internal.nodes.get(e)),o=x(a=>a.diagram.elements),r=x(a=>a.setSelection);if(!n)return c.jsx("div",{className:"px-4 py-5 text-center text-xs text-muted-foreground",children:t("props.nodeNotFound",{id:e})});const s=new Map;for(const a of n.terminals){const l=a.indexOf(".");if(l<0)continue;const d=a.slice(0,l),u=a.slice(l+1),f=s.get(d)??[];f.push(u),s.set(d,f)}const i=new Map(o.map(a=>[a.id,a]));return c.jsxs("div",{className:"flex flex-col gap-3 px-3 py-3 text-xs",children:[c.jsxs("div",{className:"space-y-1",children:[c.jsx("div",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:t("props.node")}),c.jsx("div",{className:"font-mono text-[12px]",children:n.id}),c.jsx("div",{className:"text-[11px] text-muted-foreground",children:t("props.nodeStats",{terminals:n.terminals.length,elements:s.size})})]}),c.jsx("ul",{className:"space-y-0.5 border-t border-border/40 pt-2",children:[...s.entries()].map(([a,l])=>{const d=i.get(a);return c.jsxs("li",{className:"flex cursor-pointer items-center gap-2 rounded-md px-1.5 py-1 hover:bg-accent",onClick:()=>r([a]),title:t("props.selectElement",{label:a}),children:[c.jsx("span",{className:"flex-1 truncate font-mono text-[11px]",children:a}),c.jsx("span",{className:"truncate text-[10px] text-muted-foreground",children:(d==null?void 0:d.name)??""}),c.jsx("span",{className:"font-mono text-[10px] text-muted-foreground/80",children:l.join(", ")})]},a)})})]})}function st({label:e,children:t}){return c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("label",{className:"w-16 shrink-0 truncate text-[11px] text-muted-foreground",children:e}),c.jsx("div",{className:"min-w-0 flex-1",children:t})]})}function jt({label:e,value:t,placeholder:n,unit:o,onCommit:r}){const[s,i]=j.useState(t),a=j.useRef(null);return j.useEffect(()=>i(t),[t]),c.jsx(st,{label:e,children:c.jsxs("div",{className:"relative",children:[c.jsx("input",{ref:a,type:"text",value:s,placeholder:n,onChange:l=>i(l.target.value),onBlur:()=>{s!==t&&r(s)},onKeyDown:l=>{var d,u;l.key==="Enter"&&((d=a.current)==null||d.blur()),l.key==="Escape"&&(i(t),(u=a.current)==null||u.blur())},className:we("h-7 w-full rounded-md border border-border/60 bg-background/50 px-2 text-[11px] focus:border-border focus:outline-none focus:ring-1 focus:ring-ring",o&&"pr-8")}),o&&c.jsx("span",{className:"pointer-events-none absolute right-2 top-1/2 -translate-y-1/2 text-[10px] text-muted-foreground",children:o})]})})}function Km({label:e,value:t,onCommit:n}){const[o,r]=j.useState(t);return j.useEffect(()=>r(t),[t]),c.jsx(st,{label:e,children:c.jsx("textarea",{rows:2,value:o,onChange:s=>r(s.target.value),onBlur:()=>{o!==t&&n(o)},className:"w-full resize-none rounded-md border border-border/60 bg-background/50 px-2 py-1 text-[11px] focus:border-border focus:outline-none focus:ring-1 focus:ring-ring"})})}function Yt({label:e,value:t,min:n,unit:o,onCommit:r}){const[s,i]=j.useState(String(t)),a=j.useRef(null);return j.useEffect(()=>i(String(t)),[t]),c.jsx(st,{label:e,children:c.jsxs("div",{className:"relative",children:[c.jsx("input",{ref:a,type:"number",value:s,onChange:l=>i(l.target.value),onBlur:()=>{const l=Number(s);Number.isFinite(l)&&l!==t?r(l):i(String(t))},onKeyDown:l=>{var d,u;l.key==="Enter"&&((d=a.current)==null||d.blur()),l.key==="Escape"&&(i(String(t)),(u=a.current)==null||u.blur())},min:n,className:we("h-7 w-full rounded-md border border-border/60 bg-background/50 px-2 font-mono text-[11px] tabular-nums focus:border-border focus:outline-none focus:ring-1 focus:ring-ring",o&&"pr-8")}),o&&c.jsx("span",{className:"pointer-events-none absolute right-2 top-1/2 -translate-y-1/2 text-[10px] text-muted-foreground",children:o})]})})}function Ln({active:e,onClick:t,children:n}){return c.jsx("button",{type:"button",onClick:t,className:we("flex h-6 w-full items-center justify-center gap-1.5 rounded border text-[10px] transition-colors",e?"border-[var(--selection)] bg-[var(--selection)]/15 text-foreground":"border-border/60 text-muted-foreground hover:bg-accent"),"aria-pressed":e,children:n})}function Jy({id:e,element:t,field:n}){var l;const o=Z(),s=St()(`${t.kind}.state.${n.name}`,n.label??n.name),i=((l=t.state)==null?void 0:l[n.name])??n.default,a=d=>{const u={...t.state??{}};d===void 0||d===n.default?delete u[n.name]:u[n.name]=d,x.getState().updateElement(e,{state:Object.keys(u).length>0?u:void 0})};return n.type==="boolean"?c.jsx(st,{label:s,children:c.jsx(Ln,{active:!!i,onClick:()=>a(!i),children:o(i?"common.yes":"common.no")})}):n.type==="number"?c.jsx(Yt,{label:s,value:typeof i=="number"?i:0,onCommit:a}):c.jsx(jt,{label:s,value:typeof i=="string"?i:"",onCommit:d=>a(d.trim()===""?void 0:d)})}function Qy(){const e=Z(),t=St(),n=x(f=>f.selection),o=x(f=>f.selectedNode),r=x(f=>f.selectedWire),s=x(f=>f.diagram.elements),i=x(f=>f.diagram.buses),a=Ye(),l=Ie(a,"dense");if(n.length===0&&!o&&!r)return null;let d=e("props.title"),u=null;if(r)d=e("props.wire");else if(o)d=e("props.node");else if(n.length===1){const f=n[0],h=(i??[]).find(g=>g.id===f);if(h)d=h.name??e("props.bus");else{const g=s.find(m=>m.id===f);if(g){const m=Ke[g.kind];d=m?t(`${m.id}.name`,m.name):g.kind}}}else u=n.length;return c.jsxs("aside",{className:we("ole-glass absolute z-10 flex flex-col overflow-hidden rounded-2xl border border-border shadow-sm",l?"w-48":"w-56"),style:{top:`calc(${l?"4.5rem":"0.75rem"} + var(--ole-top-inset, 0px))`,right:"calc(0.75rem + var(--ole-right-inset, 0px))",maxHeight:`calc(100% - ${l?"5.25rem":"1.5rem"} - var(--ole-top-inset, 0px) - var(--ole-bottom-inset, 0px) - 4.5rem)`},children:[c.jsxs("div",{className:"flex items-center gap-1.5 border-b border-border/40 px-3 py-2",children:[c.jsx("span",{className:"flex-1 truncate text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:d}),u!=null&&c.jsx("span",{className:"rounded bg-muted/50 px-1.5 py-0.5 font-mono text-[10px] tabular-nums text-muted-foreground/80",children:e("props.nSelected",{n:u})})]}),c.jsx(Gy,{})]})}function eb(){j.useEffect(()=>{const e=n=>{const o=n.target;if(!o||o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable)return;const r=o.closest("button");r&&r.closest(".ole-glass")&&n.preventDefault()},t=n=>{const o=n.target;if(!o||!o.closest(".ole-canvas-root"))return;const r=document.activeElement;!r||r===document.body||r.tagName==="INPUT"||r.tagName==="TEXTAREA"||r.isContentEditable||r.blur()};return window.addEventListener("mousedown",e),window.addEventListener("pointerdown",t,!0),()=>{window.removeEventListener("mousedown",e),window.removeEventListener("pointerdown",t,!0)}},[])}function tb(){eb();const e=j.useRef(null),t=vx(e);return c.jsx(fp,{children:c.jsx("div",{ref:e,className:"relative h-full w-full overflow-hidden bg-background text-foreground",children:c.jsxs(Xx,{width:t,children:[c.jsx(Dx,{}),c.jsx($y,{}),c.jsx(Qy,{}),c.jsx(ky,{}),c.jsx(by,{}),c.jsx(cy,{}),c.jsx(By,{}),c.jsx(Wy,{}),c.jsx(Kx,{})]})})})}const nb="ole-theme";function ob(){try{const e=window.localStorage.getItem(nb);return e==="light"||e==="dark"?e:null}catch{return null}}function rb(){return typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-color-scheme: dark)").matches}function sb(){return typeof window>"u"?"light":ob()??(rb()?"dark":"light")}function Ym(e){typeof document>"u"||document.documentElement.classList.toggle("dark",e==="dark")}function ib({className:e,diagram:t,locale:n,theme:o}){return j.useEffect(()=>{if(!t)return;x.getState().diagram.elements.length===0&&x.getState().setDiagram(t)},[t]),j.useEffect(()=>{n&&_t.getState().setLocale(n)},[n]),j.useEffect(()=>{o&&Ym(o)},[o]),j.useEffect(()=>{Mn()},[]),ix(),c.jsx("div",{className:`ole-root ${e??"h-full w-full"}`,children:c.jsx(tb,{})})}const Xm={"application/json":[".json"]},Vm=()=>typeof window<"u"&&typeof window.showOpenFilePicker=="function",Um=e=>e instanceof DOMException&&e.name==="AbortError";function zo(e){let t;try{t=JSON.parse(e)}catch(o){throw new Error(be("io.parseFailed",{err:o.message}))}if(!t||typeof t!="object"||Array.isArray(t))throw new Error(be("io.notObject"));const n=t;if(n.version!=="1")throw new Error(be("io.versionMismatch",{actual:JSON.stringify(n.version)}));if(!Array.isArray(n.elements))throw new Error(be("io.elementsMissing"));return n}function ab(e){return JSON.stringify(e,null,2)+`
193
+ `}async function lb(){if(Vm()){let e;try{[e]=await window.showOpenFilePicker({multiple:!1,types:[{description:be("topbar.file.fileDescription"),accept:Xm}]})}catch(n){if(Um(n))return null;throw n}const t=await e.getFile();return{diagram:zo(await t.text()),session:{handle:e,name:t.name}}}return new Promise((e,t)=>{const n=document.createElement("input");n.type="file",n.accept=".json,application/json",n.addEventListener("change",async()=>{var r;const o=(r=n.files)==null?void 0:r[0];if(!o)return e(null);try{e({diagram:zo(await o.text()),session:{name:o.name}})}catch(s){t(s)}}),n.addEventListener("cancel",()=>e(null)),n.click()})}async function Fo(e,t,n={}){const o=ab(e);if(!n.saveAs&&(t!=null&&t.handle)){const i=await t.handle.createWritable();return await i.write(o),await i.close(),t}if(Vm()){let i;try{i=await window.showSaveFilePicker({suggestedName:(t==null?void 0:t.name)??"diagram.json",types:[{description:be("topbar.file.fileDescription"),accept:Xm}]})}catch(l){if(Um(l))return null;throw l}const a=await i.createWritable();return await a.write(o),await a.close(),{handle:i,name:i.name}}const r=URL.createObjectURL(new Blob([o],{type:"application/json"})),s=document.createElement("a");return s.href=r,s.download=(t==null?void 0:t.name)??"diagram.json",s.click(),URL.revokeObjectURL(r),t??{name:"diagram.json"}}function cb(){const e=Z(),t=x(f=>f.fileSession),n=(t==null?void 0:t.name)??e("common.unnamed"),{onNew:o,onOpen:r,onSave:s,onSaveAs:i}=db(),[a,l]=j.useState(!1),d=j.useRef(null);j.useEffect(()=>{const f=h=>{if(!(h.metaKey||h.ctrlKey))return;const g=h.key.toLowerCase();g==="o"?(h.preventDefault(),r()):g==="s"&&(h.preventDefault(),h.shiftKey?i():s())};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[r,s,i]),j.useEffect(()=>{if(!a)return;const f=g=>{d.current&&!d.current.contains(g.target)&&l(!1)},h=g=>{g.key==="Escape"&&l(!1)};return window.addEventListener("mousedown",f),window.addEventListener("keydown",h),()=>{window.removeEventListener("mousedown",f),window.removeEventListener("keydown",h)}},[a]);const u=f=>()=>{l(!1),f()};return c.jsxs("div",{ref:d,className:"relative",children:[c.jsxs(Ee,{variant:"ghost",size:"sm",className:"gap-1.5","aria-haspopup":"menu","aria-expanded":a,onClick:()=>l(f=>!f),children:[c.jsx(Gn,{}),e("topbar.file.label")]}),a&&c.jsxs("div",{role:"menu",className:"ole-glass absolute left-0 top-full mt-1.5 min-w-44 rounded-md border border-border p-1 shadow-md",children:[c.jsx("div",{className:"border-b border-border px-2 pb-1.5 pt-1 text-xs text-muted-foreground",children:n}),c.jsx(It,{onClick:u(o),icon:c.jsx(kh,{}),children:e("topbar.file.new")}),c.jsx(It,{onClick:u(r),icon:c.jsx(Gn,{}),hint:"⌘O",children:e("topbar.file.open")}),c.jsx(It,{onClick:u(s),icon:c.jsx(qn,{}),hint:"⌘S",children:e("topbar.file.save")}),c.jsx(It,{onClick:u(i),icon:c.jsx(qn,{}),hint:"⌘⇧S",children:e("topbar.file.saveAs")})]})]})}function It({children:e,icon:t,hint:n,onClick:o}){return c.jsxs("button",{type:"button",role:"menuitem",onClick:o,className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent hover:text-accent-foreground [&>svg]:size-4",children:[t,c.jsx("span",{className:"flex-1",children:e}),n&&c.jsx("span",{className:"text-xs tabular-nums text-muted-foreground",children:n})]})}function db(){const e=Z(),t=x(l=>l.loadDiagramFromFile),n=x(l=>l.setFileSession),o=x(l=>l.setDiagram);return{onNew:()=>{const{diagram:l}=x.getState();l.elements.length>0&&!confirm(e("topbar.file.newConfirm"))||(o({version:"1",elements:[]}),n(null))},onOpen:async()=>{try{const l=await lb();l&&(t(l.diagram,l.session),Mn())}catch(l){alert(e("topbar.file.openFailed",{err:l.message}))}},onSave:async()=>{try{const{diagram:l,fileSession:d}=x.getState(),u=await Fo(l,d);u&&n(u)}catch(l){alert(e("topbar.file.saveFailed",{err:l.message}))}},onSaveAs:async()=>{try{const{diagram:l,fileSession:d}=x.getState(),u=await Fo(l,d,{saveAs:!0});u&&n(u)}catch(l){alert(e("topbar.file.saveFailed",{err:l.message}))}}}}const cn="WIRES",De="ELEMENTS",Ho="LABELS",Wo="ANNOTATIONS",Go=32,qo=64,ub=8,fb=1.25,mb=6;function Zm(e,t={}){const n=new $b(t.precision??6);n.header(t.title),n.tables([{name:cn,color:7},{name:De,color:7},{name:Ho,color:8},{name:Wo,color:3}]),n.beginEntities();for(const r of e.wireRenders.values())r.path.length<2||n.lwpolyline(cn,r.path.map(Te),!1);for(const{geometry:r}of e.buses.values()){const{axis:s,at:i,span:a}=r,l=a/2,d=s==="x"?[i[0]-l,i[1]]:[i[0],i[1]-l],u=s==="x"?[i[0]+l,i[1]]:[i[0],i[1]+l];n.lwpolyline(cn,[d,u].map(Te),!1)}for(const r of e.elements.values()){const s=e.layout.get(r.element.id),i=r.libraryDef;!s||!i||hb(n,i.svg,s)}const o=t.labelMode??"all";if(o!=="off")for(const r of e.elements.values()){const s=e.layout.get(r.element.id);if(!s||!r.libraryDef)continue;const i=Wt(r,o);if(i.length===0)continue;const a=r.libraryDef.label??Gt(r.libraryDef),[l,d]=qt(a,s);for(let u=0;u<i.length;u++){const[f,h]=Te([l,d+u*Ht]);n.text(Ho,[f,h],i[u],Bt,0,!1)}}for(const r of t.annotations??[]){if(!r.text)continue;const s=r.fontSize??ub,i=r.text.split(`
194
+ `);for(let a=0;a<i.length;a++){const[l,d]=Te([r.at[0],r.at[1]+(a+1)*s*fb]);n.text(Wo,[l,d],i[a],s,0,!1)}}return n.endEntities(),n.toString()}async function Jm(e,t="diagram.dxf",n){const o=Zm(e,n),r=URL.createObjectURL(new Blob([o],{type:"application/dxf;charset=utf-8"})),s=document.createElement("a");s.href=r,s.download=t,s.click(),URL.revokeObjectURL(r)}function hb(e,t,n){const o=`<svg xmlns="http://www.w3.org/2000/svg">${t}</svg>`,s=new DOMParser().parseFromString(o,"image/svg+xml").documentElement;if(!(!s||s.querySelector("parsererror")))for(const i of Array.from(s.children))switch(i.tagName.toLowerCase()){case"line":pb(e,i,n);break;case"polyline":Ko(e,i,n,!1);break;case"polygon":Ko(e,i,n,!0);break;case"rect":gb(e,i,n);break;case"circle":xb(e,i,n);break;case"ellipse":yb(e,i,n);break;case"path":kb(e,i,n);break;case"text":vb(e,i,n);break}}function pb(e,t,n){const o=pe(t,"x1"),r=pe(t,"y1"),s=pe(t,"x2"),i=pe(t,"y2"),a=Te(Be([o,r],n)),l=Te(Be([s,i],n));e.line(De,a,l)}function Ko(e,t,n,o){const r=jb(t.getAttribute("points")??"");if(r.length<2)return;const s=r.map(i=>Te(Be(i,n)));e.lwpolyline(De,s,o)}function gb(e,t,n){const o=pe(t,"x"),r=pe(t,"y"),s=pe(t,"width"),i=pe(t,"height"),l=[[o,r],[o+s,r],[o+s,r+i],[o,r+i]].map(d=>Te(Be(d,n)));e.lwpolyline(De,l,!0)}function xb(e,t,n){const o=pe(t,"cx"),r=pe(t,"cy"),s=pe(t,"r"),i=Te(Be([o,r],n));e.circle(De,i,s)}function yb(e,t,n){const o=pe(t,"cx"),r=pe(t,"cy"),s=pe(t,"rx"),i=pe(t,"ry");if(Math.abs(s-i)<1e-6){bb(e,o,r,s,n);return}wb(e,o,r,s,i,n)}function bb(e,t,n,o,r){const s=Te(Be([t,n],r));e.circle(De,s,o)}function wb(e,t,n,o,r,s){const i=[];for(let a=0;a<qo;a++){const l=a/qo*Math.PI*2;i.push(Te(Be([t+o*Math.cos(l),n+r*Math.sin(l)],s)))}e.lwpolyline(De,i,!0)}function vb(e,t,n){const o=pe(t,"x"),r=pe(t,"y"),s=parseFloat(t.getAttribute("font-size")??"")||mb,i=(t.textContent??"").trim();if(!i)return;const a=Te(Be([o,r],n));e.text(De,a,i,s,n.rot,n.mirror)}function kb(e,t,n){const o=t.getAttribute("d")??"",r=_b(o);if(r.length===0)return;let s=null,i=[];const a=()=>{i.length>=2&&e.lwpolyline(De,i.map(l=>Te(Be(l,n))),!1),i=[]};for(const l of r)if(l.cmd==="M")a(),s=[l.args[0],l.args[1]],i.push(s);else if(l.cmd==="A"&&s){const[d,u,,f,h,g,m]=l.args,p=Sb(s,[g,m],d,u,f!==0,h!==0);if(p)for(let y=1;y<=Go;y++){const v=p.theta1+p.delta*y/Go;i.push([p.cx+d*Math.cos(v),p.cy+u*Math.sin(v)])}else i.push([g,m]);s=[g,m]}a()}function _b(e){const t=[],n=/([MmAa])([^MmAa]*)/g;let o;for(;(o=n.exec(e))!==null;){const r=o[1].toUpperCase(),s=o[2].trim().split(/[\s,]+/).filter(i=>i.length>0).map(Number);t.push({cmd:r,args:s})}return t}function Sb(e,t,n,o,r,s){if(n<=0||o<=0)return null;const[i,a]=e,[l,d]=t;if(i===l&&a===d)return null;const u=(i-l)/2,f=(a-d)/2;let h=Math.abs(n),g=Math.abs(o);const m=h*h,p=g*g,y=u*u/m+f*f/p;if(y>1){const M=Math.sqrt(y);h*=M,g*=M}const v=r===s?-1:1,b=h*h*g*g-h*h*f*f-g*g*u*u,k=h*h*f*f+g*g*u*u,S=v*Math.sqrt(Math.max(0,b/k)),C=S*(h*f)/g,L=S*-(g*u)/h,te=C+(i+l)/2,Q=L+(a+d)/2,ve=(M,se,oe,de)=>{const X=M*oe+se*de,ue=Math.hypot(M,se)*Math.hypot(oe,de);let le=Math.acos(Math.max(-1,Math.min(1,X/ue)));return M*de-se*oe<0&&(le=-le),le},me=ve(1,0,(u-C)/h,(f-L)/g);let N=ve((u-C)/h,(f-L)/g,(-u-C)/h,(-f-L)/g);return!s&&N>0?N-=2*Math.PI:s&&N<0&&(N+=2*Math.PI),{cx:te,cy:Q,theta1:me,delta:N}}function Be(e,t){return Le(e,t)}function Te(e){return[e[0],-e[1]]}function pe(e,t){const n=parseFloat(e.getAttribute(t)??"");return Number.isFinite(n)?n:0}function jb(e){const t=e.trim().split(/[\s,]+/).map(Number).filter(o=>Number.isFinite(o)),n=[];for(let o=0;o+1<t.length;o+=2)n.push([t[o],t[o+1]]);return n}class $b{constructor(t){it(this,"out",[]);it(this,"precision");this.precision=t}toString(){return this.out.join("")}g(t,n){this.out.push(`${t}
195
195
  ${this.fmt(n)}
196
- `)}fmt(t){return typeof t=="number"?Number.isFinite(t)?Number.isInteger(t)?String(t):t.toFixed(this.precision):"0":t}header(t){this.g(0,"SECTION"),this.g(2,"HEADER"),this.g(9,"$ACADVER"),this.g(1,"AC1009"),this.g(9,"$INSUNITS"),this.g(70,0),t&&(this.g(9,"$PROJECTNAME"),this.g(1,qo(t))),this.g(0,"ENDSEC")}tables(t){this.g(0,"SECTION"),this.g(2,"TABLES"),this.g(0,"TABLE"),this.g(2,"LAYER"),this.g(70,t.length);for(const n of t)this.g(0,"LAYER"),this.g(2,n.name),this.g(70,0),this.g(62,n.color),this.g(6,"CONTINUOUS");this.g(0,"ENDTAB"),this.g(0,"ENDSEC")}beginEntities(){this.g(0,"SECTION"),this.g(2,"ENTITIES")}endEntities(){this.g(0,"ENDSEC"),this.g(0,"EOF")}line(t,n,o){this.g(0,"LINE"),this.g(8,t),this.g(10,n[0]),this.g(20,n[1]),this.g(30,0),this.g(11,o[0]),this.g(21,o[1]),this.g(31,0)}lwpolyline(t,n,o){if(!(n.length<2)){this.g(0,"LWPOLYLINE"),this.g(8,t),this.g(90,n.length),this.g(70,o?1:0);for(const[r,s]of n)this.g(10,r),this.g(20,s)}}circle(t,n,o){this.g(0,"CIRCLE"),this.g(8,t),this.g(10,n[0]),this.g(20,n[1]),this.g(30,0),this.g(40,o)}text(t,n,o,r,s,i){this.g(0,"TEXT"),this.g(8,t),this.g(10,n[0]),this.g(20,n[1]),this.g(30,0),this.g(40,r),this.g(1,qo(o)),s!==0&&this.g(50,s),i&&this.g(71,2)}}function qo(e){return e.replace(/[\r\n]+/g," ").slice(0,250)}const E1="http://www.w3.org/2000/svg",It=24,Jm=8,Qm=1.25;function Ln(e,t={}){const n=N1(e,t),o=Math.floor(n.minX-It),r=Math.floor(n.minY-It),s=Math.ceil(n.maxX+It)-o,i=Math.ceil(n.maxY+It)-r,a=t.background??"#FFFFFF",l=[];l.push('<?xml version="1.0" encoding="UTF-8"?>'),l.push(`<svg xmlns="${E1}" viewBox="${o} ${r} ${s} ${i}" width="${s}" height="${i}">`),t.title&&l.push(` <title>${mt(t.title)}</title>`),a!=="transparent"&&l.push(` <rect x="${o}" y="${r}" width="${s}" height="${i}" fill="${a}"/>`),l.push(' <g fill="none" stroke="black" stroke-width="1">');for(const f of e.wireRenders.values()){if(f.path.length<2)continue;const p=f.path.map(([g,m])=>`${g},${m}`).join(" ");l.push(` <polyline points="${p}"/>`)}l.push(" </g>");for(const{bus:f,geometry:p}of e.buses.values()){const{axis:g,at:m,span:h}=p,y=h/2,v=g==="x"?m[0]-y:m[0],b=g==="x"?m[1]:m[1]-y,_=g==="x"?m[0]+y:m[0],N=g==="x"?m[1]:m[1]+y;l.push(` <line id="${mt(f.id)}" x1="${v}" y1="${b}" x2="${_}" y2="${N}" stroke="black" stroke-width="3" stroke-linecap="round" fill="none"/>`)}for(const f of e.elements.values()){if(!f.libraryDef)continue;const p=e.layout.get(f.element.id);p&&(l.push(` <g id="${mt(f.element.id)}" transform="${Ge(p)}">`),l.push(` ${f.libraryDef.svg}`),l.push(" </g>"))}const d=t.labelMode??"all";if(d!=="off"){const f=a==="transparent"?"#FFFFFF":a;l.push(` <g fill="black" font-family="ui-sans-serif, system-ui, sans-serif" font-size="${Lt}" paint-order="stroke" stroke="${f}" stroke-width="2" stroke-linejoin="round">`);for(const p of e.elements.values()){const g=e.layout.get(p.element.id);if(!g||!p.libraryDef)continue;const m=Ht(p,d);if(m.length===0)continue;const h=p.libraryDef.label??Wt(p.libraryDef),[y,v]=Gt(h,g),b=h.anchor??"start";for(let _=0;_<m.length;_++)l.push(` <text x="${y}" y="${v+_*Ft}" text-anchor="${b}">${mt(m[_])}</text>`)}l.push(" </g>")}const u=t.annotations??[];if(u.length>0){const f=a==="transparent"?"#FFFFFF":a;l.push(` <g fill="black" font-family="ui-sans-serif, system-ui, sans-serif" paint-order="stroke" stroke="${f}" stroke-width="2" stroke-linejoin="round">`);for(const p of u){if(!p.text)continue;const g=p.fontSize??Jm,m=p.text.split(`
197
- `);for(let h=0;h<m.length;h++){const y=p.at[1]+g*.85+h*g*Qm;l.push(` <text x="${p.at[0]}" y="${y}" font-size="${g}">${mt(m[h])}</text>`)}}l.push(" </g>")}return l.push("</svg>"),l.join(`
198
- `)}function N1(e,t){let n=1/0,o=1/0,r=-1/0,s=-1/0;const i=(l,d)=>{l<n&&(n=l),l>r&&(r=l),d<o&&(o=d),d>s&&(s=d)};for(const l of e.terminals.values())i(l.world[0],l.world[1]);for(const l of e.elements.values()){const d=e.layout.get(l.element.id),u=l.libraryDef;if(!d||!u)continue;const f=T1(u.viewBox);if(!f){i(d.at[0],d.at[1]);continue}const p=[[f.x,f.y],[f.x+f.w,f.y],[f.x,f.y+f.h],[f.x+f.w,f.y+f.h]];for(const g of p){const[m,h]=Le(g,d);i(m,h)}}for(const{geometry:l}of e.buses.values()){const{axis:d,at:u,span:f}=l,p=f/2;d==="x"?(i(u[0]-p,u[1]),i(u[0]+p,u[1])):(i(u[0],u[1]-p),i(u[0],u[1]+p))}for(const l of e.wireRenders.values())for(const[d,u]of l.path)i(d,u);const a=t.labelMode??"all";if(a!=="off")for(const l of e.elements.values()){const d=e.layout.get(l.element.id);if(!d||!l.libraryDef)continue;const u=Ht(l,a);if(u.length===0)continue;const f=l.libraryDef.label??Wt(l.libraryDef),[p,g]=Gt(f,d),m=Yo(u,Lt),h=u.length*Ft,y=f.anchor??"start",v=y==="middle"?p-m/2:y==="end"?p-m:p;i(v,g-Lt),i(v+m,g+h)}for(const l of t.annotations??[]){if(!l.text)continue;const d=l.fontSize??Jm,u=l.text.split(`
199
- `),f=Yo(u,d),p=u.length*d*Qm;i(l.at[0],l.at[1]),i(l.at[0]+f,l.at[1]+p)}return n===1/0&&(n=0,o=0,r=0,s=0),{minX:n,minY:o,maxX:r,maxY:s}}function Yo(e,t){let n=0;for(const o of e){const r=o.length*t*.55;r>n&&(n=r)}return Math.max(20,n)}function T1(e){const t=e.trim().split(/\s+/).map(Number);return t.length!==4||t.some(n=>Number.isNaN(n))?null:{x:t[0],y:t[1],w:t[2],h:t[3]}}function mt(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}async function eh(e,t="diagram.svg",n){const o=Ln(e,n);nh(new Blob([o],{type:"image/svg+xml;charset=utf-8"}),t)}async function th(e,t="diagram.png",n){const o=Ln(e,n),r=(n==null?void 0:n.scale)??2,s=URL.createObjectURL(new Blob([o],{type:"image/svg+xml;charset=utf-8"}));try{const i=await C1(s),a=document.createElement("canvas");a.width=Math.round(i.naturalWidth*r),a.height=Math.round(i.naturalHeight*r);const l=a.getContext("2d");if(!l)throw new Error("canvas 2d context unavailable");n!=null&&n.background&&n.background!=="transparent"&&(l.fillStyle=n.background,l.fillRect(0,0,a.width,a.height)),l.drawImage(i,0,0,a.width,a.height);const d=await new Promise((u,f)=>{a.toBlob(p=>p?u(p):f(new Error("toBlob failed")),"image/png")});nh(d,t)}finally{URL.revokeObjectURL(s)}}function C1(e){return new Promise((t,n)=>{const o=new Image;o.onload=()=>t(o),o.onerror=()=>n(new Error("failed to load SVG into image")),o.src=e})}function nh(e,t){const n=URL.createObjectURL(e),o=document.createElement("a");o.href=n,o.download=t,o.click(),URL.revokeObjectURL(n)}function I1(){const e=U(),[t,n]=S.useState(!1),o=S.useRef(null);S.useEffect(()=>{if(!t)return;const s=a=>{o.current&&!o.current.contains(a.target)&&n(!1)},i=a=>{a.key==="Escape"&&n(!1)};return window.addEventListener("mousedown",s),window.addEventListener("keydown",i),()=>{window.removeEventListener("mousedown",s),window.removeEventListener("keydown",i)}},[t]);const r=s=>()=>{var f,p,g,m;n(!1);const{internal:i,diagram:a,fileSession:l}=x.getState(),d=((f=l==null?void 0:l.name)==null?void 0:f.replace(/\.json$/i,""))??((p=a.meta)==null?void 0:p.title)??"diagram",u={title:(g=a.meta)==null?void 0:g.title,labelMode:(m=a.meta)==null?void 0:m.labelMode,annotations:a.annotations};s==="svg"?eh(i,`${d}.svg`,u):s==="png"?th(i,`${d}.png`,{...u,scale:2}).catch(h=>{console.error(h),alert(e("topbar.export.pngFailed",{err:h.message}))}):Zm(i,`${d}.dxf`,u).catch(h=>{console.error(h),alert(e("topbar.export.dxfFailed",{err:h.message}))})};return c.jsxs("div",{ref:o,className:"relative",children:[c.jsxs(Ee,{variant:"ghost",size:"sm",className:"gap-1.5","aria-haspopup":"menu","aria-expanded":t,onClick:()=>n(s=>!s),children:[c.jsx(yh,{}),e("topbar.export.label")]}),t&&c.jsxs("div",{role:"menu",className:"ole-glass absolute left-0 top-full mt-1.5 min-w-40 rounded-md border border-border p-1 shadow-md",children:[c.jsxs("button",{type:"button",role:"menuitem",onClick:r("svg"),className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent hover:text-accent-foreground [&>svg]:size-4",children:[c.jsx(kh,{}),c.jsx("span",{className:"flex-1",children:"SVG"})]}),c.jsxs("button",{type:"button",role:"menuitem",onClick:r("png"),className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent hover:text-accent-foreground [&>svg]:size-4",children:[c.jsx(wh,{}),c.jsx("span",{className:"flex-1",children:"PNG (2×)"})]}),c.jsxs("button",{type:"button",role:"menuitem",onClick:r("dxf"),className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent hover:text-accent-foreground [&>svg]:size-4",children:[c.jsx(bh,{}),c.jsx("span",{className:"flex-1",children:"DXF"})]})]})]})}exports.ExportMenu=I1;exports.FileMenu=c1;exports.LIBRARY=hn;exports.OneLineEditor=i1;exports.applyTheme=qm;exports.buildExportDxf=Um;exports.buildExportSvg=Ln;exports.compile=He;exports.downloadDxf=Zm;exports.downloadPng=th;exports.downloadSvg=eh;exports.emptyInternalModel=br;exports.fitToContent=In;exports.fitToContentSoon=An;exports.getInitialTheme=s1;exports.getLibraryEntry=hm;exports.newBusId=pn;exports.newElementId=bt;exports.orientationVec=mn;exports.resolvePlacement=wr;exports.transformOrientation=gt;exports.transformPoint=Le;exports.useEditorStore=x;exports.useLocale=kt;exports.wireIdFromEnds=wt;
196
+ `)}fmt(t){return typeof t=="number"?Number.isFinite(t)?Number.isInteger(t)?String(t):t.toFixed(this.precision):"0":t}header(t){this.g(0,"SECTION"),this.g(2,"HEADER"),this.g(9,"$ACADVER"),this.g(1,"AC1009"),this.g(9,"$INSUNITS"),this.g(70,0),t&&(this.g(9,"$PROJECTNAME"),this.g(1,Yo(t))),this.g(0,"ENDSEC")}tables(t){this.g(0,"SECTION"),this.g(2,"TABLES"),this.g(0,"TABLE"),this.g(2,"LAYER"),this.g(70,t.length);for(const n of t)this.g(0,"LAYER"),this.g(2,n.name),this.g(70,0),this.g(62,n.color),this.g(6,"CONTINUOUS");this.g(0,"ENDTAB"),this.g(0,"ENDSEC")}beginEntities(){this.g(0,"SECTION"),this.g(2,"ENTITIES")}endEntities(){this.g(0,"ENDSEC"),this.g(0,"EOF")}line(t,n,o){this.g(0,"LINE"),this.g(8,t),this.g(10,n[0]),this.g(20,n[1]),this.g(30,0),this.g(11,o[0]),this.g(21,o[1]),this.g(31,0)}lwpolyline(t,n,o){if(!(n.length<2)){this.g(0,"LWPOLYLINE"),this.g(8,t),this.g(90,n.length),this.g(70,o?1:0);for(const[r,s]of n)this.g(10,r),this.g(20,s)}}circle(t,n,o){this.g(0,"CIRCLE"),this.g(8,t),this.g(10,n[0]),this.g(20,n[1]),this.g(30,0),this.g(40,o)}text(t,n,o,r,s,i){this.g(0,"TEXT"),this.g(8,t),this.g(10,n[0]),this.g(20,n[1]),this.g(30,0),this.g(40,r),this.g(1,Yo(o)),s!==0&&this.g(50,s),i&&this.g(71,2)}}function Yo(e){return e.replace(/[\r\n]+/g," ").slice(0,250)}const Eb="http://www.w3.org/2000/svg",At=24,Qm=8,eh=1.25;function Bn(e,t={}){const n=Nb(e,t),o=Math.floor(n.minX-At),r=Math.floor(n.minY-At),s=Math.ceil(n.maxX+At)-o,i=Math.ceil(n.maxY+At)-r,a=t.background??"#FFFFFF",l=[];l.push('<?xml version="1.0" encoding="UTF-8"?>'),l.push(`<svg xmlns="${Eb}" viewBox="${o} ${r} ${s} ${i}" width="${s}" height="${i}">`),t.title&&l.push(` <title>${ht(t.title)}</title>`),a!=="transparent"&&l.push(` <rect x="${o}" y="${r}" width="${s}" height="${i}" fill="${a}"/>`),l.push(' <g fill="none" stroke="black" stroke-width="1">');for(const f of e.wireRenders.values()){if(f.path.length<2)continue;const h=f.path.map(([g,m])=>`${g},${m}`).join(" ");l.push(` <polyline points="${h}"/>`)}l.push(" </g>");for(const{bus:f,geometry:h}of e.buses.values()){const{axis:g,at:m,span:p}=h,y=p/2,v=g==="x"?m[0]-y:m[0],b=g==="x"?m[1]:m[1]-y,k=g==="x"?m[0]+y:m[0],S=g==="x"?m[1]:m[1]+y;l.push(` <line id="${ht(f.id)}" x1="${v}" y1="${b}" x2="${k}" y2="${S}" stroke="black" stroke-width="3" stroke-linecap="round" fill="none"/>`)}for(const f of e.elements.values()){if(!f.libraryDef)continue;const h=e.layout.get(f.element.id);h&&(l.push(` <g id="${ht(f.element.id)}" transform="${qe(h)}">`),l.push(` ${f.libraryDef.svg}`),l.push(" </g>"))}const d=t.labelMode??"all";if(d!=="off"){const f=a==="transparent"?"#FFFFFF":a;l.push(` <g fill="black" font-family="ui-sans-serif, system-ui, sans-serif" font-size="${Bt}" paint-order="stroke" stroke="${f}" stroke-width="2" stroke-linejoin="round">`);for(const h of e.elements.values()){const g=e.layout.get(h.element.id);if(!g||!h.libraryDef)continue;const m=Wt(h,d);if(m.length===0)continue;const p=h.libraryDef.label??Gt(h.libraryDef),[y,v]=qt(p,g),b=p.anchor??"start";for(let k=0;k<m.length;k++)l.push(` <text x="${y}" y="${v+k*Ht}" text-anchor="${b}">${ht(m[k])}</text>`)}l.push(" </g>")}const u=t.annotations??[];if(u.length>0){const f=a==="transparent"?"#FFFFFF":a;l.push(` <g fill="black" font-family="ui-sans-serif, system-ui, sans-serif" paint-order="stroke" stroke="${f}" stroke-width="2" stroke-linejoin="round">`);for(const h of u){if(!h.text)continue;const g=h.fontSize??Qm,m=h.text.split(`
197
+ `);for(let p=0;p<m.length;p++){const y=h.at[1]+g*.85+p*g*eh;l.push(` <text x="${h.at[0]}" y="${y}" font-size="${g}">${ht(m[p])}</text>`)}}l.push(" </g>")}return l.push("</svg>"),l.join(`
198
+ `)}function Nb(e,t){let n=1/0,o=1/0,r=-1/0,s=-1/0;const i=(l,d)=>{l<n&&(n=l),l>r&&(r=l),d<o&&(o=d),d>s&&(s=d)};for(const l of e.terminals.values())i(l.world[0],l.world[1]);for(const l of e.elements.values()){const d=e.layout.get(l.element.id),u=l.libraryDef;if(!d||!u)continue;const f=Tb(u.viewBox);if(!f){i(d.at[0],d.at[1]);continue}const h=[[f.x,f.y],[f.x+f.w,f.y],[f.x,f.y+f.h],[f.x+f.w,f.y+f.h]];for(const g of h){const[m,p]=Le(g,d);i(m,p)}}for(const{geometry:l}of e.buses.values()){const{axis:d,at:u,span:f}=l,h=f/2;d==="x"?(i(u[0]-h,u[1]),i(u[0]+h,u[1])):(i(u[0],u[1]-h),i(u[0],u[1]+h))}for(const l of e.wireRenders.values())for(const[d,u]of l.path)i(d,u);const a=t.labelMode??"all";if(a!=="off")for(const l of e.elements.values()){const d=e.layout.get(l.element.id);if(!d||!l.libraryDef)continue;const u=Wt(l,a);if(u.length===0)continue;const f=l.libraryDef.label??Gt(l.libraryDef),[h,g]=qt(f,d),m=Xo(u,Bt),p=u.length*Ht,y=f.anchor??"start",v=y==="middle"?h-m/2:y==="end"?h-m:h;i(v,g-Bt),i(v+m,g+p)}for(const l of t.annotations??[]){if(!l.text)continue;const d=l.fontSize??Qm,u=l.text.split(`
199
+ `),f=Xo(u,d),h=u.length*d*eh;i(l.at[0],l.at[1]),i(l.at[0]+f,l.at[1]+h)}return n===1/0&&(n=0,o=0,r=0,s=0),{minX:n,minY:o,maxX:r,maxY:s}}function Xo(e,t){let n=0;for(const o of e){const r=o.length*t*.55;r>n&&(n=r)}return Math.max(20,n)}function Tb(e){const t=e.trim().split(/\s+/).map(Number);return t.length!==4||t.some(n=>Number.isNaN(n))?null:{x:t[0],y:t[1],w:t[2],h:t[3]}}function ht(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}async function th(e,t="diagram.svg",n){const o=Bn(e,n);oh(new Blob([o],{type:"image/svg+xml;charset=utf-8"}),t)}async function nh(e,t="diagram.png",n){const o=Bn(e,n),r=(n==null?void 0:n.scale)??2,s=URL.createObjectURL(new Blob([o],{type:"image/svg+xml;charset=utf-8"}));try{const i=await Cb(s),a=document.createElement("canvas");a.width=Math.round(i.naturalWidth*r),a.height=Math.round(i.naturalHeight*r);const l=a.getContext("2d");if(!l)throw new Error("canvas 2d context unavailable");n!=null&&n.background&&n.background!=="transparent"&&(l.fillStyle=n.background,l.fillRect(0,0,a.width,a.height)),l.drawImage(i,0,0,a.width,a.height);const d=await new Promise((u,f)=>{a.toBlob(h=>h?u(h):f(new Error("toBlob failed")),"image/png")});oh(d,t)}finally{URL.revokeObjectURL(s)}}function Cb(e){return new Promise((t,n)=>{const o=new Image;o.onload=()=>t(o),o.onerror=()=>n(new Error("failed to load SVG into image")),o.src=e})}function oh(e,t){const n=URL.createObjectURL(e),o=document.createElement("a");o.href=n,o.download=t,o.click(),URL.revokeObjectURL(n)}function Ib(){const e=Z(),[t,n]=j.useState(!1),o=j.useRef(null);j.useEffect(()=>{if(!t)return;const s=a=>{o.current&&!o.current.contains(a.target)&&n(!1)},i=a=>{a.key==="Escape"&&n(!1)};return window.addEventListener("mousedown",s),window.addEventListener("keydown",i),()=>{window.removeEventListener("mousedown",s),window.removeEventListener("keydown",i)}},[t]);const r=s=>()=>{var f,h,g,m;n(!1);const{internal:i,diagram:a,fileSession:l}=x.getState(),d=((f=l==null?void 0:l.name)==null?void 0:f.replace(/\.json$/i,""))??((h=a.meta)==null?void 0:h.title)??"diagram",u={title:(g=a.meta)==null?void 0:g.title,labelMode:(m=a.meta)==null?void 0:m.labelMode,annotations:a.annotations};s==="svg"?th(i,`${d}.svg`,u):s==="png"?nh(i,`${d}.png`,{...u,scale:2}).catch(p=>{console.error(p),alert(e("topbar.export.pngFailed",{err:p.message}))}):Jm(i,`${d}.dxf`,u).catch(p=>{console.error(p),alert(e("topbar.export.dxfFailed",{err:p.message}))})};return c.jsxs("div",{ref:o,className:"relative",children:[c.jsxs(Ee,{variant:"ghost",size:"sm",className:"gap-1.5","aria-haspopup":"menu","aria-expanded":t,onClick:()=>n(s=>!s),children:[c.jsx(bh,{}),e("topbar.export.label")]}),t&&c.jsxs("div",{role:"menu",className:"ole-glass absolute left-0 top-full mt-1.5 min-w-40 rounded-md border border-border p-1 shadow-md",children:[c.jsxs("button",{type:"button",role:"menuitem",onClick:r("svg"),className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent hover:text-accent-foreground [&>svg]:size-4",children:[c.jsx(_h,{}),c.jsx("span",{className:"flex-1",children:"SVG"})]}),c.jsxs("button",{type:"button",role:"menuitem",onClick:r("png"),className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent hover:text-accent-foreground [&>svg]:size-4",children:[c.jsx(vh,{}),c.jsx("span",{className:"flex-1",children:"PNG (2×)"})]}),c.jsxs("button",{type:"button",role:"menuitem",onClick:r("dxf"),className:"flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent hover:text-accent-foreground [&>svg]:size-4",children:[c.jsx(wh,{}),c.jsx("span",{className:"flex-1",children:"DXF"})]})]})]})}exports.ExportMenu=Ib;exports.FileMenu=cb;exports.LIBRARY=pn;exports.OneLineEditor=ib;exports.applyTheme=Ym;exports.buildExportDxf=Zm;exports.buildExportSvg=Bn;exports.compile=We;exports.downloadDxf=Jm;exports.downloadPng=nh;exports.downloadSvg=th;exports.emptyInternalModel=wr;exports.fitToContent=An;exports.fitToContentSoon=Mn;exports.getInitialTheme=sb;exports.getLibraryEntry=pm;exports.newBusId=gn;exports.newElementId=wt;exports.orientationVec=hn;exports.resolvePlacement=vr;exports.transformOrientation=xt;exports.transformPoint=Le;exports.useEditorStore=x;exports.useLocale=_t;exports.wireIdFromEnds=vt;
200
200
  //# sourceMappingURL=sldeditor.cjs.map