sldeditor 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas/AnnotationLayer.d.ts.map +1 -1
- package/dist/canvas/tools/PanTool.d.ts.map +1 -1
- package/dist/canvas/tools/SelectTool.d.ts.map +1 -1
- package/dist/lib/element-labels.d.ts +15 -0
- package/dist/lib/element-labels.d.ts.map +1 -0
- package/dist/lib/export-dxf.d.ts.map +1 -1
- package/dist/lib/export-image.d.ts +6 -0
- package/dist/lib/export-image.d.ts.map +1 -1
- package/dist/sldeditor.cjs +45 -43
- package/dist/sldeditor.cjs.map +1 -1
- package/dist/sldeditor.js +2953 -2973
- package/dist/sldeditor.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/dist/sldeditor.cjs
CHANGED
|
@@ -1,193 +1,195 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var ih=Object.defineProperty;var ah=(e,t,n)=>t in e?ih(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var ot=(e,t,n)=>ah(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react/jsx-runtime"),_=require("react"),Go=require("react-dom");function lh(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 he=lh(_);/**
|
|
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
|
|
6
|
+
*/const ch=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Ko=(...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
|
|
11
|
+
*/var dh={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
|
|
16
|
+
*/const uh=_.forwardRef(({color:e="currentColor",size:t=24,strokeWidth:n=2,absoluteStrokeWidth:o,className:r="",children:s,iconNode:i,...a},l)=>_.createElement("svg",{ref:l,...dh,width:t,height:t,stroke:e,strokeWidth:o?Number(n)*24/Number(t):n,className:Ko("lucide",r),...a},[...i.map(([u,d])=>_.createElement(u,d)),...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
|
|
21
|
+
*/const X=(e,t)=>{const n=_.forwardRef(({className:o,...r},s)=>_.createElement(uh,{ref:s,iconNode:t,className:Ko(`lucide-${ch(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
|
|
26
|
+
*/const qo=X("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
|
|
31
|
+
*/const fh=X("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
|
|
36
|
+
*/const Yo=X("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
|
|
41
|
+
*/const Xo=X("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
|
|
46
|
+
*/const mh=X("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
|
|
51
|
+
*/const sn=X("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
|
|
56
|
+
*/const hh=X("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
|
|
61
|
+
*/const ph=X("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
|
|
66
|
+
*/const gh=X("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
|
|
71
|
+
*/const xh=X("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
|
|
76
|
+
*/const Vo=X("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
|
|
81
|
+
*/const Rn=X("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
|
|
86
|
+
*/const yh=X("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
|
|
91
|
+
*/const bh=X("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 It=
|
|
96
|
+
*/const It=X("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
|
|
101
|
+
*/const Uo=X("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
|
|
106
|
+
*/const wh=X("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
|
|
111
|
+
*/const vn=X("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
|
|
116
|
+
*/const vh=X("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
|
|
121
|
+
*/const kh=X("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
|
|
126
|
+
*/const _h=X("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
|
|
131
|
+
*/const kn=X("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
|
|
136
|
+
*/const Zo=X("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
|
|
141
|
+
*/const zn=X("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
|
|
146
|
+
*/const Jo=X("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
|
|
151
|
+
*/const Sh=X("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
|
|
156
|
+
*/const Qo=X("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
|
|
161
|
+
*/const jh=X("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"}]]);/**
|
|
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
|
|
166
|
+
*/const er=X("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"}]]);/**
|
|
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
|
|
171
|
+
*/const tr=X("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"}]]);/**
|
|
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
|
|
176
|
+
*/const _n=X("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"}]]);/**
|
|
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
|
|
181
|
+
*/const mt=X("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"}]]);/**
|
|
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 wn=V("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);function Uo(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=Uo(e[t]))&&(o&&(o+=" "),o+=n)}else for(n in e)e[n]&&(o&&(o+=" "),o+=n);return o}function Zo(){for(var e,t,n=0,o="",r=arguments.length;n<r;n++)(e=arguments[n])&&(t=Uo(e))&&(o&&(o+=" "),o+=t);return o}const vn="-",yp=e=>{const t=wp(e),{conflictingClassGroups:n,conflictingClassGroupModifiers:o}=e;return{getClassGroupId:i=>{const a=i.split(vn);return a[0]===""&&a.length!==1&&a.shift(),Jo(a,t)||bp(i)},getConflictingClassGroupIds:(i,a)=>{const l=n[i]||[];return a&&o[i]?[...l,...o[i]]:l}}},Jo=(e,t)=>{var i;if(e.length===0)return t.classGroupId;const n=e[0],o=t.nextPart.get(n),r=o?Jo(e.slice(1),o):void 0;if(r)return r;if(t.validators.length===0)return;const s=e.join(vn);return(i=t.validators.find(({validator:a})=>a(s)))==null?void 0:i.classGroupId},Bn=/^\[(.+)\]$/,bp=e=>{if(Bn.test(e)){const t=Bn.exec(e)[1],n=t==null?void 0:t.substring(0,t.indexOf(":"));if(n)return"arbitrary.."+n}},wp=e=>{const{theme:t,prefix:n}=e,o={nextPart:new Map,validators:[]};return kp(Object.entries(e.classGroups),n).forEach(([s,i])=>{nn(i,o,s,t)}),o},nn=(e,t,n,o)=>{e.forEach(r=>{if(typeof r=="string"){const s=r===""?t:Dn(t,r);s.classGroupId=n;return}if(typeof r=="function"){if(vp(r)){nn(r(o),t,n,o);return}t.validators.push({validator:r,classGroupId:n});return}Object.entries(r).forEach(([s,i])=>{nn(i,Dn(t,s),n,o)})})},Dn=(e,t)=>{let n=e;return t.split(vn).forEach(o=>{n.nextPart.has(o)||n.nextPart.set(o,{nextPart:new Map,validators:[]}),n=n.nextPart.get(o)}),n},vp=e=>e.isThemeGetter,kp=(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,_p=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)}}},Qo="!",Sp=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 w=a[y];if(d===0){if(w===r&&(o||a.slice(y,y+s)===t)){l.push(a.slice(u,y)),u=y+s;continue}if(w==="/"){f=y;continue}}w==="["?d++:w==="]"&&d--}const m=l.length===0?a:a.substring(u),g=m.startsWith(Qo),p=g?m.substring(1):m,h=f&&f>u?f-u:void 0;return{modifiers:l,hasImportantModifier:g,baseClassName:p,maybePostfixModifierPosition:h}};return n?a=>n({className:a,parseClassName:i}):i},jp=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},$p=e=>({cache:_p(e.cacheSize),parseClassName:Sp(e),...yp(e)}),Ep=/\s+/,Np=(e,t)=>{const{parseClassName:n,getClassGroupId:o,getConflictingClassGroupIds:r}=t,s=[],i=e.trim().split(Ep);let a="";for(let l=i.length-1;l>=0;l-=1){const d=i[l],{modifiers:u,hasImportantModifier:f,baseClassName:m,maybePostfixModifierPosition:g}=n(d);let p=!!g,h=o(p?m.substring(0,g):m);if(!h){if(!p){a=d+(a.length>0?" "+a:a);continue}if(h=o(m),!h){a=d+(a.length>0?" "+a:a);continue}p=!1}const y=jp(u).join(":"),w=f?y+Qo:y,v=w+h;if(s.includes(v))continue;s.push(v);const N=r(h,p);for(let I=0;I<N.length;++I){const L=N[I];s.push(w+L)}a=d+(a.length>0?" "+a:a)}return a};function Tp(){let e=0,t,n,o="";for(;e<arguments.length;)(t=arguments[e++])&&(n=er(t))&&(o&&(o+=" "),o+=n);return o}const er=e=>{if(typeof e=="string")return e;let t,n="";for(let o=0;o<e.length;o++)e[o]&&(t=er(e[o]))&&(n&&(n+=" "),n+=t);return n};function Cp(e,...t){let n,o,r,s=i;function i(l){const d=t.reduce((u,f)=>f(u),e());return n=$p(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=Np(l,n);return r(l,u),u}return function(){return s(Tp.apply(null,arguments))}}const te=e=>{const t=n=>n[e]||[];return t.isThemeGetter=!0,t},tr=/^\[(?:([a-z-]+):)?(.+)\]$/i,Ip=/^\d+\/\d+$/,Ap=new Set(["px","full","screen"]),Mp=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,Pp=/\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$/,Op=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,Lp=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,Bp=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,Pe=e=>Je(e)||Ap.has(e)||Ip.test(e),Re=e=>tt(e,"length",qp),Je=e=>!!e&&!Number.isNaN(Number(e)),Ht=e=>tt(e,"number",Je),rt=e=>!!e&&Number.isInteger(Number(e)),Dp=e=>e.endsWith("%")&&Je(e.slice(0,-1)),q=e=>tr.test(e),ze=e=>Mp.test(e),Rp=new Set(["length","size","percentage"]),zp=e=>tt(e,Rp,nr),Fp=e=>tt(e,"position",nr),Hp=new Set(["image","url"]),Wp=e=>tt(e,Hp,Yp),Gp=e=>tt(e,"",Kp),st=()=>!0,tt=(e,t,n)=>{const o=tr.exec(e);return o?o[1]?typeof t=="string"?o[1]===t:t.has(o[1]):n(o[2]):!1},qp=e=>Pp.test(e)&&!Op.test(e),nr=()=>!1,Kp=e=>Lp.test(e),Yp=e=>Bp.test(e),Xp=()=>{const e=te("colors"),t=te("spacing"),n=te("blur"),o=te("brightness"),r=te("borderColor"),s=te("borderRadius"),i=te("borderSpacing"),a=te("borderWidth"),l=te("contrast"),d=te("grayscale"),u=te("hueRotate"),f=te("invert"),m=te("gap"),g=te("gradientColorStops"),p=te("gradientColorStopPositions"),h=te("inset"),y=te("margin"),w=te("opacity"),v=te("padding"),N=te("saturate"),I=te("scale"),L=te("sepia"),W=te("skew"),le=te("space"),se=te("translate"),he=()=>["auto","contain","none"],ue=()=>["auto","hidden","clip","visible","scroll"],$=()=>["auto",q,t],T=()=>[q,t],J=()=>["",Pe,Re],ee=()=>["auto",Je,q],ae=()=>["bottom","center","left","left-bottom","left-top","right","right-bottom","right-top","top"],be=()=>["solid","dashed","dotted","double","none"],Ie=()=>["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],de=()=>["start","end","center","between","around","evenly","stretch"],_e=()=>["","0",q],we=()=>["auto","avoid","all","avoid-page","page","left","right","column"],ge=()=>[Je,q];return{cacheSize:500,separator:":",theme:{colors:[st],spacing:[Pe,Re],blur:["none","",ze,q],brightness:ge(),borderColor:[e],borderRadius:["none","","full",ze,q],borderSpacing:T(),borderWidth:J(),contrast:ge(),grayscale:_e(),hueRotate:ge(),invert:_e(),gap:T(),gradientColorStops:[e],gradientColorStopPositions:[Dp,Re],inset:$(),margin:$(),opacity:ge(),padding:T(),saturate:ge(),scale:ge(),sepia:_e(),skew:ge(),space:T(),translate:T()},classGroups:{aspect:[{aspect:["auto","square","video",q]}],container:["container"],columns:[{columns:[ze]}],"break-after":[{"break-after":we()}],"break-before":[{"break-before":we()}],"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:[...ae(),q]}],overflow:[{overflow:ue()}],"overflow-x":[{"overflow-x":ue()}],"overflow-y":[{"overflow-y":ue()}],overscroll:[{overscroll:he()}],"overscroll-x":[{"overscroll-x":he()}],"overscroll-y":[{"overscroll-y":he()}],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",rt,q]}],basis:[{basis:$()}],"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:_e()}],shrink:[{shrink:_e()}],order:[{order:["first","last","none",rt,q]}],"grid-cols":[{"grid-cols":[st]}],"col-start-end":[{col:["auto",{span:["full",rt,q]},q]}],"col-start":[{"col-start":ee()}],"col-end":[{"col-end":ee()}],"grid-rows":[{"grid-rows":[st]}],"row-start-end":[{row:["auto",{span:[rt,q]},q]}],"row-start":[{"row-start":ee()}],"row-end":[{"row-end":ee()}],"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:[m]}],"gap-x":[{"gap-x":[m]}],"gap-y":[{"gap-y":[m]}],"justify-content":[{justify:["normal",...de()]}],"justify-items":[{"justify-items":["start","end","center","stretch"]}],"justify-self":[{"justify-self":["auto","start","end","center","stretch"]}],"align-content":[{content:["normal",...de(),"baseline"]}],"align-items":[{items:["start","end","center","baseline","stretch"]}],"align-self":[{self:["auto","start","end","center","stretch","baseline"]}],"place-content":[{"place-content":[...de(),"baseline"]}],"place-items":[{"place-items":["start","end","center","baseline","stretch"]}],"place-self":[{"place-self":["auto","start","end","center","stretch"]}],p:[{p:[v]}],px:[{px:[v]}],py:[{py:[v]}],ps:[{ps:[v]}],pe:[{pe:[v]}],pt:[{pt:[v]}],pr:[{pr:[v]}],pb:[{pb:[v]}],pl:[{pl:[v]}],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":[le]}],"space-x-reverse":["space-x-reverse"],"space-y":[{"space-y":[le]}],"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:[ze]},ze]}],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",ze,Re]}],"font-smoothing":["antialiased","subpixel-antialiased"],"font-style":["italic","not-italic"],"font-weight":[{font:["thin","extralight","light","normal","medium","semibold","bold","extrabold","black",Ht]}],"font-family":[{font:[st]}],"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",Je,Ht]}],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":[w]}],"text-alignment":[{text:["left","center","right","justify","start","end"]}],"text-color":[{text:[e]}],"text-opacity":[{"text-opacity":[w]}],"text-decoration":["underline","overline","line-through","no-underline"],"text-decoration-style":[{decoration:[...be(),"wavy"]}],"text-decoration-thickness":[{decoration:["auto","from-font",Pe,Re]}],"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:T()}],"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":[w]}],"bg-origin":[{"bg-origin":["border","padding","content"]}],"bg-position":[{bg:[...ae(),Fp]}],"bg-repeat":[{bg:["no-repeat",{repeat:["","x","y","round","space"]}]}],"bg-size":[{bg:["auto","cover","contain",zp]}],"bg-image":[{bg:["none",{"gradient-to":["t","tr","r","br","b","bl","l","tl"]},Wp]}],"bg-color":[{bg:[e]}],"gradient-from-pos":[{from:[p]}],"gradient-via-pos":[{via:[p]}],"gradient-to-pos":[{to:[p]}],"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":[w]}],"border-style":[{border:[...be(),"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":[w]}],"divide-style":[{divide:be()}],"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:["",...be()]}],"outline-offset":[{"outline-offset":[Pe,q]}],"outline-w":[{outline:[Pe,Re]}],"outline-color":[{outline:[e]}],"ring-w":[{ring:J()}],"ring-w-inset":["ring-inset"],"ring-color":[{ring:[e]}],"ring-opacity":[{"ring-opacity":[w]}],"ring-offset-w":[{"ring-offset":[Pe,Re]}],"ring-offset-color":[{"ring-offset":[e]}],shadow:[{shadow:["","inner","none",ze,Gp]}],"shadow-color":[{shadow:[st]}],opacity:[{opacity:[w]}],"mix-blend":[{"mix-blend":[...Ie(),"plus-lighter","plus-darker"]}],"bg-blend":[{"bg-blend":Ie()}],filter:[{filter:["","none"]}],blur:[{blur:[n]}],brightness:[{brightness:[o]}],contrast:[{contrast:[l]}],"drop-shadow":[{"drop-shadow":["","none",ze,q]}],grayscale:[{grayscale:[d]}],"hue-rotate":[{"hue-rotate":[u]}],invert:[{invert:[f]}],saturate:[{saturate:[N]}],sepia:[{sepia:[L]}],"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":[w]}],"backdrop-saturate":[{"backdrop-saturate":[N]}],"backdrop-sepia":[{"backdrop-sepia":[L]}],"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:ge()}],ease:[{ease:["linear","in","out","in-out",q]}],delay:[{delay:ge()}],animate:[{animate:["none","spin","ping","pulse","bounce",q]}],transform:[{transform:["","gpu","none"]}],scale:[{scale:[I]}],"scale-x":[{"scale-x":[I]}],"scale-y":[{"scale-y":[I]}],rotate:[{rotate:[rt,q]}],"translate-x":[{"translate-x":[se]}],"translate-y":[{"translate-y":[se]}],"skew-x":[{"skew-x":[W]}],"skew-y":[{"skew-y":[W]}],"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":T()}],"scroll-mx":[{"scroll-mx":T()}],"scroll-my":[{"scroll-my":T()}],"scroll-ms":[{"scroll-ms":T()}],"scroll-me":[{"scroll-me":T()}],"scroll-mt":[{"scroll-mt":T()}],"scroll-mr":[{"scroll-mr":T()}],"scroll-mb":[{"scroll-mb":T()}],"scroll-ml":[{"scroll-ml":T()}],"scroll-p":[{"scroll-p":T()}],"scroll-px":[{"scroll-px":T()}],"scroll-py":[{"scroll-py":T()}],"scroll-ps":[{"scroll-ps":T()}],"scroll-pe":[{"scroll-pe":T()}],"scroll-pt":[{"scroll-pt":T()}],"scroll-pr":[{"scroll-pr":T()}],"scroll-pb":[{"scroll-pb":T()}],"scroll-pl":[{"scroll-pl":T()}],"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,Re,Ht]}],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"]}}},Vp=Cp(Xp);function ye(...e){return Vp(Zo(e))}const or=_.createContext(null);function Up(){const e=_.useContext(or);if(!e)throw new Error("useContextMenu must be used inside <ContextMenuHost>");return e}const St=8;function Zp({children:e}){const[t,n]=_.useState({open:!1,x:0,y:0,items:[]}),[o,r]=_.useState(null),s=_.useRef(null),i=_.useCallback(()=>{n(d=>d.open?{...d,open:!1}:d)},[]),a=_.useCallback((d,u,f)=>{r(null),n({open:!0,x:d,y:u,items:f})},[]),l=_.useMemo(()=>({open:a,close:i}),[a,i]);return _.useLayoutEffect(()=>{if(!t.open||!s.current)return;const d=s.current.getBoundingClientRect();let u=t.x,f=t.y;u+d.width>window.innerWidth-St&&(u=Math.max(St,t.x-d.width)),f+d.height>window.innerHeight-St&&(f=Math.max(St,t.y-d.height)),r({left:u,top:f})},[t]),_.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(),m=()=>i();return document.addEventListener("pointerdown",d,!0),document.addEventListener("keydown",u,!0),window.addEventListener("wheel",f,{passive:!0}),window.addEventListener("blur",m),()=>{document.removeEventListener("pointerdown",d,!0),document.removeEventListener("keydown",u,!0),window.removeEventListener("wheel",f),window.removeEventListener("blur",m)}},[t.open,i]),c.jsxs(or.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:ye("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 Rn=e=>{let t;const n=new Set,o=(d,u)=>{const f=typeof d=="function"?d(t):d;if(!Object.is(f,t)){const m=t;t=u??(typeof f!="object"||f===null)?f:Object.assign({},t,f),n.forEach(g=>g(t,m))}},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},Jp=(e=>e?Rn(e):Rn),Qp=e=>e;function eh(e,t=Qp){const n=_.useSyncExternalStore(e.subscribe,_.useCallback(()=>t(e.getState()),[e,t]),_.useCallback(()=>t(e.getInitialState()),[e,t]));return _.useDebugValue(n),n}const zn=e=>{const t=Jp(e),n=o=>eh(t,o);return Object.assign(n,t),n},Lt=(e=>e?zn(e):zn),Fn={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":"移除选中元件及其连接的连线","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","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"}},rr="ole-locale";function th(){if(typeof window>"u")return"zh";try{const e=window.localStorage.getItem(rr);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 Hn(e){try{window.localStorage.setItem(rr,e)}catch{}}const yt=Lt((e,t)=>({locale:th(),setLocale:n=>{Hn(n),e({locale:n})},toggle:()=>{const n=t().locale==="zh"?"en":"zh";Hn(n),e({locale:n})}}));function sr(e,t){return t?e.replace(/\{(\w+)\}/g,(n,o)=>t[o]!==void 0?String(t[o]):`{${o}}`):e}function ir(e,t){return Fn[e][t]??Fn.zh[t]??t}function xe(e,t){return sr(ir(yt.getState().locale,e),t)}function U(){const e=yt(t=>t.locale);return(t,n)=>sr(ir(e,t),n)}function ar(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 on=e=>t=>{try{const n=e(t);return n instanceof Promise?n:{then(o){return on(o)(n)},catch(o){return this}}}catch(n){return{then(o){return this},catch(o){return on(o)(n)}}}},nh=(e,t)=>(n,o,r)=>{let s={storage:ar(()=>window.localStorage),partialize:y=>y,version:0,merge:(y,w)=>({...w,...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})},m=r.setState;r.setState=(y,w)=>(m(y,w),f());const g=e((...y)=>(n(...y),f()),o,r);r.getInitialState=()=>g;let p;const h=()=>{var y,w;if(!u)return;const v=++a;i=!1,l.forEach(I=>{var L;return I((L=o())!=null?L:g)});const N=((w=s.onRehydrateStorage)==null?void 0:w.call(s,(y=o())!=null?y:g))||void 0;return on(u.getItem.bind(u))(s.name).then(I=>{if(I)if(typeof I.version=="number"&&I.version!==s.version){if(s.migrate){const L=s.migrate(I.state,I.version);return L instanceof Promise?L.then(W=>[!0,W]):[!0,L]}console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return[!1,I.state];return[!1,void 0]}).then(I=>{var L;if(v!==a)return;const[W,le]=I;if(p=s.merge(le,(L=o())!=null?L:g),n(p,!0),W)return f()}).then(()=>{v===a&&(N==null||N(o(),void 0),p=o(),i=!0,d.forEach(I=>I(p)))}).catch(I=>{v===a&&(N==null||N(void 0,I))})};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(),p||g},oh=nh;function lr(){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 cr(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 rn(e){return e===90||e===270?"y":"x"}function Oe(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 rh={n:"e",e:"s",s:"w",w:"n"},sh={n:"n",s:"s",e:"w",w:"e"};function mt(e,t){let n=t.mirror?sh[e]:e;const o=t.rot/90|0;for(let r=0;r<o;r++)n=rh[n];return n}function sn(e){switch(e){case"n":return[0,-1];case"s":return[0,1];case"e":return[1,0];case"w":return[-1,0]}}class dr{constructor(){_t(this,"parent",new Map);_t(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 Wn=["n","e","s","w"],Gn={n:"s",s:"n",e:"w",w:"e"};function qn(e,t){const n=Wn.indexOf(e),r=((Wn.indexOf(t)-n)%4+4)%4;return[0,90,180,270][r]}const ih=320,Kn=220,it=260,Yn=720,at=30,Xn=30,lt=80,Vn=10,ah=60,lh=520,ch=80,dh=80,Un=8,Zn=new Set(["source","renewable"]);function uh(e){var Tn,Cn,In,An,Mn,Pn;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 b of t)d.set(b.id,b);const u=new Map;for(const b of n)u.set(b.id,b);const f=b=>{const k=d.get(b);if(k)return r.get(k.kind)},m=new Set(n.map(b=>b.id)),g=b=>m.has(b),p=new dr;for(const b of o)p.add(b.ends[0]),p.add(b.ends[1]),p.union(b.ends[0],b.ends[1]);for(const b of t){const k=r.get(b.kind);if(k)for(const S of k.terminals)p.add(`${b.id}.${S.id}`)}for(const b of n)p.add(b.id);const h=[];for(const[,b]of p.groups())b.length>=2&&h.push(b);const y=new Map;for(const b of h)for(const k of b)y.set(k,[b]);const w=new Map;for(const b of h){const k=b.filter(g);if(k.length!==0)for(const S of k){const E=b.filter(j=>j!==S),O=w.get(S)??[];O.push(...E),w.set(S,O)}}const v=new Map;for(const b of h){const k=b.filter(g);if(k.length!==0)for(const S of b){if(g(S))continue;const E=S.indexOf(".");if(E<0)continue;const O=S.slice(0,E),j=S.slice(E+1),A=v.get(O)??[];for(const D of k)A.some(M=>M.busId===D&&M.pin===j)||A.push({busId:D,pin:j});v.set(O,A)}}const N=[],I=new Set;for(const[b,k]of v)if(new Set(k.map(E=>E.busId)).size>=2){const E=((Cn=r.get(((Tn=d.get(b))==null?void 0:Tn.kind)??""))==null?void 0:Cn.category)==="transformer"?"vertical":"horizontal";N.push({elementId:b,attachments:k,orientation:E}),E==="vertical"&&I.add(b)}const L=new Map,W=(b,k)=>{b!==k&&(L.has(b)||L.set(b,new Set),L.has(k)||L.set(k,new Set),L.get(b).add(k),L.get(k).add(b))};for(const b of o)W(b.ends[0],b.ends[1]);for(const b of t){const k=r.get(b.kind);if(!k||k.terminals.length<2)continue;const S=k.terminals.map(E=>`${b.id}.${E.id}`);for(let E=0;E<S.length;E++)for(let O=E+1;O<S.length;O++)W(S[E],S[O])}for(const b of t){if(I.has(b.id))continue;const k=r.get(b.kind);if(!k||k.category!=="transformer"||k.terminals.length<2)continue;const S=k.terminals.map(j=>`${b.id}.${j.id}`),E=new Map;for(const j of S){const A=j.slice(b.id.length+1);E.set(A,new Set);const D=new Set(S.filter(R=>R!==j)),M=new Set([j]),F=[j];for(;F.length>0;){const R=F.shift();if(g(R)){E.get(A).add(R);continue}const C=L.get(R);if(C)for(const P of C)M.has(P)||D.has(P)||(M.add(P),F.push(P))}}const O=new Set;for(const j of E.values())for(const A of j)O.add(A);if(O.size>=2){const j=[];for(const[A,D]of E)for(const M of D)j.push({busId:M,pin:A});N.push({elementId:b.id,attachments:j,orientation:"vertical"}),I.add(b.id)}}const le=(b,k)=>{var D;const S=f(k),E=S?S.terminals.map(M=>`${k}.${M.id}`):[],O=b,j=new Set([O,...E]),A=[O];for(;A.length>0;){const M=A.shift(),F=M.indexOf(".");if(F>0){const C=M.slice(0,F),P=d.get(C);if(P){const B=(D=r.get(P.kind))==null?void 0:D.category;if(B&&Zn.has(B))return!0}}const R=L.get(M);if(R)for(const C of R)j.has(C)||(j.add(C),A.push(C))}return!1};for(const b of N){if(b.orientation!=="horizontal")continue;const k=new Set(b.attachments.map(E=>E.busId));let S=0;for(const E of k)le(E,b.elementId)&&S++;S===1&&(b.orientation="vertical",I.add(b.elementId))}for(const b of t){if(I.has(b.id)||b.kind!=="breaker")continue;const k=r.get(b.kind);if(!k||k.terminals.length!==2)continue;const S=k.terminals.map(j=>`${b.id}.${j.id}`),E=new Map;for(const j of S){const A=j.slice(b.id.length+1),D=new Set(S.filter(R=>R!==j)),M=new Set([j]),F=[j];for(;F.length>0;){const R=F.shift();if(g(R)){E.set(A,R);break}const C=L.get(R);if(C)for(const P of C){if(M.has(P)||D.has(P))continue;const B=P.indexOf(".");if(B>0){const G=P.slice(0,B);if(G!==b.id){const Q=d.get(G),Z=Q?r.get(Q.kind):void 0;if((Z==null?void 0:Z.category)==="transformer")continue}}M.add(P),F.push(P)}}}if(new Set(E.values()).size>=2){const j=[];for(const[A,D]of E)j.push({busId:D,pin:A});N.push({elementId:b.id,attachments:j,orientation:"horizontal"})}}const se=new Map;for(const b of n)se.set(b.id,new Map);for(const b of N){const k=Array.from(new Set(b.attachments.map(S=>S.busId)));for(const S of k)for(const E of k)S!==E&&((In=se.get(S))==null||In.set(E,b))}const he=b=>{var S;const k=(S=r.get(b))==null?void 0:S.category;return k?Zn.has(k):!1},ue=[];for(const b of n){const k=w.get(b.id);if(k)for(const S of k){if(g(S))continue;const E=S.indexOf(".");if(E<0)continue;const O=S.slice(0,E),j=d.get(O);if(j&&he(j.kind)){ue.push(b.id);break}}}ue.length===0&&n.length>0&&ue.push(n[0].id);const $=new Map;for(const b of ue)$.set(b,0);{const b=[...ue];for(;b.length>0;){const k=b.shift(),S=$.get(k),E=se.get(k);if(E)for(const[O,j]of E){if($.has(O))continue;const A=j.orientation==="horizontal"?S:S+1;$.set(O,A),b.push(O)}}}for(const b of n){if($.has(b.id))continue;const k=$.size===0?-1:Math.max(...Array.from($.values()));$.set(b.id,k+1)}const T=new Map;for(const b of n){const k=$.get(b.id),S=T.get(k)??[];S.push(b.id),T.set(k,S)}const J=[...T.keys()].sort((b,k)=>b-k),ee=(b,k,S)=>{const E=`${b.elementId}.${S}`,O=k,j=f(b.elementId),A=new Set;if(j)for(const C of j.terminals)C.id!==S&&A.add(`${b.elementId}.${C.id}`);const D=new Set([E]),M=[{ref:E,dist:0}],F=new Map,R=(C,P,B,G)=>{D.add(C),F.set(C,P),M.push({ref:C,dist:G+B})};for(;M.length>0;){const{ref:C,dist:P}=M.shift();if(C===O){const Z=F.get(O);let ie;if(Z){const K=Z.indexOf(".");if(K>0){const z=Z.slice(0,K);z!==b.elementId&&(ie=z)}}return{extent:P,head:ie}}const B=C.indexOf(".");if(B<0)continue;const G=C.slice(0,B),Q=C.slice(B+1);if(!g(G)&&!I.has(G)){const Z=f(G),ie=Z==null?void 0:Z.terminals.find(K=>K.id===Q);if(Z&&ie)for(const K of Z.terminals){if(K.id===Q)continue;const z=`${G}.${K.id}`;D.has(z)||A.has(z)||R(z,C,Math.abs(ie.y-K.y),P)}}for(const Z of y.get(C)??[])for(const ie of Z){if(ie===C||D.has(ie)||A.has(ie))continue;const K=g(C)||g(ie);R(ie,C,K?Xn:at,P)}}return{extent:0}},ae=(b,k)=>{var C,P,B;const S=(C=se.get(b))==null?void 0:C.get(k);if(!S||S.orientation==="horizontal")return it;const E=f(S.elementId);if(!E)return it;const O=(P=S.attachments.find(G=>G.busId===b))==null?void 0:P.pin,j=(B=S.attachments.find(G=>G.busId===k))==null?void 0:B.pin;if(!O||!j)return it;const A=E.terminals.find(G=>G.id===O),D=E.terminals.find(G=>G.id===j);if(!A||!D)return it;const M=Math.abs(D.y-A.y),F=ee(S,b,O).extent,R=ee(S,k,j).extent;return F+M+R},be=new Map;for(const b of N){if(b.orientation!=="vertical")continue;const k=b.attachments.slice().sort((D,M)=>($.get(D.busId)??0)-($.get(M.busId)??0));if(k.length<2)continue;const S=k[0].busId,E=k[1].busId,O=k[0].pin,A=ee(b,S,O).head??b.elementId;be.set(A,{lowerBusId:E})}const Ie=320,de=new Map,_e=(b,k)=>{if(!I.has(b))return!1;const S=N.find(A=>A.elementId===b),E=S==null?void 0:S.attachments.find(A=>A.busId!==k);if(!E)return!1;const O=$.get(k)??0;return($.get(E.busId)??0)<O},we=(b,k)=>{const S=be.get(b);if(S){const E=de.get(S.lowerBusId);if(E!==void 0)return Math.max(k,E+lt)}return Math.max(k,lt)},ge=(b,k)=>{if(de.has(b))return de.get(b);if(k.has(b))return Ie;k.add(b);const S=w.get(b)??[];let E=0,O=0;for(const A of S){if(g(A))continue;const D=A.indexOf(".");if(D<0)continue;const M=A.slice(0,D),F=A.slice(D+1);if(_e(M,b))continue;const R=f(M);if(!R)continue;const C=R.terminals.find(G=>G.id===F);if(!C)continue;const P=be.get(M);P&&ge(P.lowerBusId,k);const B=we(M,R.width);C.y>0?E+=B:O+=B}const j=Math.max(Ie,Math.max(E,O)+lt);return de.set(b,j),k.delete(b),j};for(const b of n)ge(b.id,new Set);const De=new Map,Gm=(b,k,S)=>{const E=f(k);if(!E)return;const O=`${k}.${S}`,j=E.terminals.filter(M=>M.id!==S).map(M=>`${k}.${M.id}`);if(j.length===0)return;const A=new Set([O,...j]),D=j.slice();for(;D.length>0;){const M=D.shift();if(g(M)&&M!==b){const R=l.get(M);return R?R.at[0]:void 0}for(const R of y.get(M)??[])for(const C of R)C===M||A.has(C)||(A.add(C),D.push(C));const F=M.indexOf(".");if(F>0){const R=M.slice(0,F);if(!g(R)){const C=f(R);if(C)for(const P of C.terminals){const B=`${R}.${P.id}`;A.has(B)||(A.add(B),D.push(B))}}}}},qm=b=>{const k=w.get(b);if(!k||k.length===0)return;const S=l.get(b);if(!S)return;const E=k.flatMap(C=>{if(g(C))return[];const P=C.indexOf(".");if(P<0)return[];const B=C.slice(0,P),G=C.slice(P+1);if(a.has(B))return[];if(_e(B,b))return[];const Q=f(B);if(!Q)return[];const Z=Q.terminals.find(ie=>ie.id===G);return Z?[{elId:B,lib:Q,localTerm:Z,isLinker:I.has(B)}]:[]});if(E.length===0)return;const O=[],j=[];for(const C of E)C.localTerm.y>0?O.push(C):j.push(C);const A=C=>C.reduce((P,B)=>P+we(B.elId,B.lib.width),0),D=Math.max(A(O),A(j))+lt,M=Math.max(S.span,D);M!==S.span&&l.set(b,{...S,span:M});const F=l.get(b),R=(C,P)=>{if(C.length===0)return;const B=new Map;for(const H of C){const Y=Gm(b,H.elId,H.localTerm.id);Y!==void 0&&B.set(H.elId,Y)}C.sort((H,Y)=>{const ce=B.get(H.elId)??F.at[0],ve=B.get(Y.elId)??F.at[0];if(ce!==ve)return ce-ve;const Ae=we(H.elId,H.lib.width);return we(Y.elId,Y.lib.width)-Ae});const G=C.map(H=>we(H.elId,H.lib.width)),Q=G.reduce((H,Y)=>H+Y,0),Z=Math.max(M,Q),ie=(Z-Q)/(C.length+1);let K=F.at[0]-Z/2+ie;const z=F.at[1]+P*Xn;for(let H=0;H<C.length;H++){const Y=C[H],ce=G[H],ve=K+ce/2;Y.isLinker?De.has(Y.elId)||De.set(Y.elId,ve):a.set(Y.elId,{at:[me(ve-Y.localTerm.x),me(z-Y.localTerm.y)],rot:0,mirror:!1}),K+=ce+ie}};R(O,-1),R(j,1)},Km=b=>{if(a.has(b.elementId)||b.orientation==="horizontal")return;const k=f(b.elementId);if(!k)return;const S=b.attachments.filter(K=>l.has(K.busId));if(S.length<2)return;const E=S.slice().sort((K,z)=>($.get(K.busId)??0)-($.get(z.busId)??0)),O=E[0].busId,j=l.get(O),A=E[0].pin,D=E[E.length-1].pin,M=k.terminals.find(K=>K.id===A),F=k.terminals.find(K=>K.id===D);if(!M||!F)return;const R=M.y<=F.y?0:180,C=$.get(O)??0,P=S.filter(K=>($.get(K.busId)??0)===C),B=[];let G=0;for(const K of P){const z=ee(b,K.busId,K.pin);G=Math.max(G,z.extent);const H=z.head?a.get(z.head):void 0;H?B.push(H.at[0]):De.has(b.elementId)?B.push(De.get(b.elementId)):B.push(l.get(K.busId).at[0])}let Q;B.length>0?Q=B.reduce((K,z)=>K+z,0)/B.length:De.has(b.elementId)?Q=De.get(b.elementId):Q=j.at[0];const Z=j.at[1]+G,ie=R===0?[me(Q-M.x),me(Z-M.y)]:[me(Q+M.x),me(Z+M.y)];if(a.set(b.elementId,{at:ie,rot:R,mirror:!1}),P.length>1){const K=a.get(b.elementId),z=Oe([M.x,M.y],K),H=mt(M.orientation,K);Ym(`${b.elementId}.${A}`,z,H,Q)}},Ym=(b,k,S,E)=>{const O=new Set([b]);let j=b,A=k,D=S;for(;;){const M=y.get(j)??[];let F,R=!1;for(const Ee of M){if(Ee.length>=3){R=!0;break}const Ye=Ee.find(Ft=>Ft!==j);if(!(!Ye||O.has(Ye))){if(g(Ye)){R=!0;break}F=Ye;break}}if(R||!F)break;const C=F.indexOf(".");if(C<0)break;const P=F.slice(0,C),B=F.slice(C+1);if(g(P)||I.has(P)||a.has(P))break;const G=f(P);if(!G)break;const Q=G.terminals.find(Ee=>Ee.id===B);if(!Q)break;const Z=sn(D),ie=[A[0]+Z[0]*at,A[1]+Z[1]*at],K=Gn[D],z=qn(Q.orientation,K),H=Oe([Q.x,Q.y],{at:[0,0],rot:z,mirror:!1}),Y=[me(E-H[0]),me(ie[1]-H[1])];a.set(P,{at:Y,rot:z,mirror:!1}),O.add(F);const ce=G.terminals.find(Ee=>Ee.id!==B);if(!ce)break;const ve=`${P}.${ce.id}`;O.add(ve);const Ae={at:Y,rot:z,mirror:!1};A=Oe([ce.x,ce.y],Ae),D=mt(ce.orientation,Ae),j=ve}},Xm=b=>{if(a.has(b.elementId)||b.orientation!=="horizontal")return;const k=f(b.elementId);if(!k)return;const S=b.attachments.filter(P=>l.has(P.busId));if(S.length<2)return;const E=S.map(P=>{const B=ee(b,P.busId,P.pin),G=B.head?a.get(B.head):void 0,Q=G?G.at[0]:l.get(P.busId).at[0];return{att:P,x:Q,extent:B.extent}});E.sort((P,B)=>P.x-B.x);const O=E[0],j=E[E.length-1],A=k.terminals.find(P=>P.id===O.att.pin),D=k.terminals.find(P=>P.id===j.att.pin);if(!A||!D)return;const M=A.y<=D.y?270:90,F=(O.x+j.x)/2,C=l.get(O.att.busId).at[1]+Math.max(O.extent,j.extent);a.set(b.elementId,{at:[me(F),me(C)],rot:M,mirror:!1})},Vm=100;let kt=Kn;for(let b=0;b<J.length;b++){const k=J[b],S=T.get(k);let E;if(b===0)E=Kn;else{const j=T.get(J[b-1]);let A=0;for(const D of j)for(const M of S)(An=se.get(D))!=null&&An.get(M)&&(A=Math.max(A,ae(D,M)));A===0&&(A=it),E=kt+A}kt=E;let O=ih;for(const j of S){if(l.has(j)){kt=Math.max(kt,l.get(j).at[1]);continue}let A;if(b>0){const M=T.get(J[b-1]),F=[];for(const R of M){const C=(Mn=se.get(R))==null?void 0:Mn.get(j);if(!C||C.orientation!=="vertical")continue;const P=(Pn=C.attachments.find(G=>G.busId===R))==null?void 0:Pn.pin;if(!P)continue;const B=ee(C,R,P);B.head&&a.has(B.head)?F.push(a.get(B.head).at[0]):De.has(C.elementId)?F.push(De.get(C.elementId)):F.push(l.get(R).at[0])}F.length>0&&(A=F.reduce((R,C)=>R+C,0)/F.length)}if(A===void 0){const M=de.get(j)??Yn;A=O+M/2,O+=M+Vm}const D=de.get(j)??Yn;l.set(j,{at:[me(A),me(E)],rot:0,span:D,axis:rn(0)})}for(const j of S)qm(j);if(b>0)for(const j of N)a.has(j.elementId)||!j.attachments.some(D=>S.includes(D.busId))||Km(j);for(const j of N)j.orientation!=="horizontal"||a.has(j.elementId)||!j.attachments.every(D=>S.includes(D.busId))||Xm(j)}const Um=b=>{if(g(b))return l.has(b);const k=b.indexOf(".");return k<0?!1:a.has(b.slice(0,k))};let Rt=!0,Zm=t.length+4;for(;Rt&&Zm-- >0;){Rt=!1;for(const b of h){if(b.length<2)continue;const k=[],S=new Map;for(const z of b){if(g(z))continue;const H=z.indexOf(".");if(H<0)continue;const Y=z.slice(0,H),ce=z.slice(H+1);if(a.has(Y)){k.push(z);continue}if(I.has(Y)||S.has(Y))continue;const ve=f(Y);if(!ve)continue;const Ae=ve.terminals.find(Ee=>Ee.id===ce);Ae&&S.set(Y,{ref:z,elId:Y,lib:ve,localTerm:Ae})}if(S.size===0||k.length===0)continue;const E=[...S.values()],O=new Map;for(const z of E)for(const H of y.get(z.ref)??[])for(const Y of H){if(Y===z.ref||g(Y)||!Um(Y))continue;const ce=Y;O.set(ce,(O.get(ce)??0)+1)}let j;if(O.size>0){let z=-1;for(const[H,Y]of O)(Y>z||Y===z&&(j===void 0||H<j))&&(z=Y,j=H)}if(j||(j=[...k].sort()[0]),!j)continue;const A=j.indexOf("."),D=j.slice(0,A),M=j.slice(A+1),F=f(D),R=a.get(D);if(!F||!R)continue;const C=F.terminals.find(z=>z.id===M);if(!C)continue;const P=Oe([C.x,C.y],R),B=mt(C.orientation,R),G=sn(B),Q=[-G[1],G[0]];E.sort((z,H)=>z.elId.localeCompare(H.elId));const Z=E.map(z=>Math.max(z.lib.width,lt));let K=-Z.reduce((z,H)=>z+H,0)/2;for(let z=0;z<E.length;z++){const H=E[z],Y=Z[z],ce=K+Y/2;K+=Y;const ve=Gn[B],Ae=qn(H.localTerm.orientation,ve),Ee=Oe([H.localTerm.x,H.localTerm.y],{at:[0,0],rot:Ae,mirror:!1}),Ye=[P[0]+G[0]*at+Q[0]*ce,P[1]+G[1]*at+Q[1]*ce],Ft=[me(Ye[0]-Ee[0]),me(Ye[1]-Ee[1])];a.set(H.elId,{at:Ft,rot:Ae,mirror:!1}),Rt=!0}}}let zt=0;for(const b of t){if(a.has(b.id))continue;const k=zt%Un,S=Math.floor(zt/Un);a.set(b.id,{at:[me(ah+k*ch),me(lh+S*dh)],rot:0,mirror:!1}),zt++}return{devices:a,buses:l}}function me(e){return Math.round(e/Vn)*Vn}function fh(e,t){const n=e.ends[0],o=e.ends[1],r=Jn(n,t),s=Jn(o,t);if(r||s){const l=r?n:o,u=Wt(r?o:n,t);if(!u)return null;const f=t.buses.get(l);if(!f)return null;const{axis:m,at:g,span:p}=f.geometry,h=p/2;let y;if(m==="x")y=[eo(u[0],g[0]-h,g[0]+h),g[1]];else{const w=eo(u[1],g[1]-h,g[1]+h);y=[g[0],w]}return{wireId:e.id,path:Qn(u,y)}}const i=Wt(n,t),a=Wt(o,t);return!i||!a?null:{wireId:e.id,path:Qn(i,a)}}function Jn(e,t){return!e.includes(".")&&t.buses.has(e)}function Wt(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 Qn(e,t){return e[0]===t[0]||e[1]===t[1]?[e,t]:[e,[e[0],t[1]],t]}function eo(e,t,n){return e<t?t:e>n?n:e}const ur="ammeter",fr="电流表 (A)",mr="measurement",pr="-22 -42 44 44",hr=44,gr=44,xr='<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>',yr=[{id:"t_top",x:0,y:-40,orientation:"n"}],br={kind:"inline"},mh={id:ur,name:fr,category:mr,viewBox:pr,width:hr,height:gr,svg:xr,terminals:yr,source:br},ph=Object.freeze(Object.defineProperty({__proto__:null,category:mr,default:mh,height:gr,id:ur,name:fr,source:br,svg:xr,terminals:yr,viewBox:pr,width:hr},Symbol.toStringTag,{value:"Module"})),wr="arc-suppression-coil",vr="消弧线圈",kr="grounding",_r="中性点谐振接地:电感线圈连接到地",Sr="-12 -32 24 67",jr=24,$r=67,Er='<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"/>',Nr=[{id:"t_top",x:0,y:-30,orientation:"n"}],Tr={kind:"inline"},hh={id:wr,name:vr,category:kr,description:_r,viewBox:Sr,width:jr,height:$r,svg:Er,terminals:Nr,source:Tr},gh=Object.freeze(Object.defineProperty({__proto__:null,category:kr,default:hh,description:_r,height:$r,id:wr,name:vr,source:Tr,svg:Er,terminals:Nr,viewBox:Sr,width:jr},Symbol.toStringTag,{value:"Module"})),Cr="arrester",Ir="避雷器 (FBL)",Ar="protection",Mr="-7 -22 14 44",Pr=14,Or=44,Lr='<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"/>',Br=[{id:"t1",x:0,y:-20,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],Dr={kind:"elmt",path:"91_en_60617/en_60617_07/en_60617_07_22/en_60617_07_22_03.elmt",qetEnglishName:"Surge diverter; Lightning arrester"},xh={id:Cr,name:Ir,category:Ar,viewBox:Mr,width:Pr,height:Or,svg:Lr,terminals:Br,source:Dr},yh=Object.freeze(Object.defineProperty({__proto__:null,category:Ar,default:xh,height:Or,id:Cr,name:Ir,source:Dr,svg:Lr,terminals:Br,viewBox:Mr,width:Pr},Symbol.toStringTag,{value:"Module"})),Rr="async-motor",zr="异步电动机",Fr="load",Hr="-62 -82 64 84",Wr=64,Gr=84,qr='<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"/>',Kr=[{id:"t1",x:-50,y:-80,orientation:"n"},{id:"t2",x:-10,y:-80,orientation:"n"},{id:"t3",x:-30,y:-80,orientation:"n"}],Yr={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"},bh={id:Rr,name:zr,category:Fr,viewBox:Hr,width:Wr,height:Gr,svg:qr,terminals:Kr,source:Yr},wh=Object.freeze(Object.defineProperty({__proto__:null,category:Fr,default:bh,height:Gr,id:Rr,name:zr,source:Yr,svg:qr,terminals:Kr,viewBox:Hr,width:Wr},Symbol.toStringTag,{value:"Module"})),Xr="autotransformer",Vr="自耦变压器",Ur="transformer",Zr="-62 -112 64 144",Jr=64,Qr=144,es='<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"/>',ts=[{id:"t1",x:-30,y:-110,orientation:"n"},{id:"t_bottom",x:-30,y:20,orientation:"s"}],ns={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_09/en_60617_06_09_06.elmt",qetEnglishName:"Auto-transformer, general symbol"},vh={id:Xr,name:Vr,category:Ur,viewBox:Zr,width:Jr,height:Qr,svg:es,terminals:ts,source:ns},kh=Object.freeze(Object.defineProperty({__proto__:null,category:Ur,default:vh,height:Qr,id:Xr,name:Vr,source:ns,svg:es,terminals:ts,viewBox:Zr,width:Jr},Symbol.toStringTag,{value:"Module"})),os="battery",rs="电池储能",ss="storage",is="-12 -12 29 24",as=29,ls=24,cs='<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"/>',ds=[{id:"t_left",x:-10,y:0,orientation:"w"},{id:"t_right",x:15,y:0,orientation:"e"}],us=[{name:"E",label:"容量",type:"number",unit:"kWh"}],fs={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_15/en_60617_06_15_01.elmt",qetEnglishName:"Battery cell"},_h={id:os,name:rs,category:ss,viewBox:is,width:as,height:ls,svg:cs,terminals:ds,params:us,source:fs},Sh=Object.freeze(Object.defineProperty({__proto__:null,category:ss,default:_h,height:ls,id:os,name:rs,params:us,source:fs,svg:cs,terminals:ds,viewBox:is,width:as},Symbol.toStringTag,{value:"Module"})),ms="breaker",ps="断路器 (QF)",hs="switching",gs="-7 -22 15 46",xs=15,ys=46,bs='<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>',ws=[{id:"t1",x:0,y:-20,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],vs=[{name:"open",type:"boolean",default:!1,label:"断开"}],ks={x:6,y:-2,anchor:"start"},_s={kind:"elmt",path:"11_singlepole/200_fuses_protective_gears/11_circuit_breakers/disjoncteur1.elmt",qetEnglishName:"Circuit-breaker"},jh={id:ms,name:ps,category:hs,viewBox:gs,width:xs,height:ys,svg:bs,terminals:ws,state:vs,label:ks,source:_s},$h=Object.freeze(Object.defineProperty({__proto__:null,category:hs,default:jh,height:ys,id:ms,label:ks,name:ps,source:_s,state:vs,svg:bs,terminals:ws,viewBox:gs,width:xs},Symbol.toStringTag,{value:"Module"})),Ss="busbar",js="母线段",$s="busbar",Es="可拉伸单母线段,多设备挂接",Ns="-42 -4 84 8",Ts=84,Cs=8,Is='<line x1="-40" y1="0" x2="40" y2="0" stroke="black" stroke-width="3" stroke-linecap="round" fill="none"/>',As=[{id:"tap",x:0,y:0,orientation:"n"}],Ms={axis:"x",minLength:20,naturalSpan:80},Ps=[{name:"Un",label:"额定电压",type:"number",unit:"kV",showOnCanvas:!0}],Os={x:0,y:-6,anchor:"middle"},Ls={kind:"inline"},Eh={id:Ss,name:js,category:$s,description:Es,viewBox:Ns,width:Ts,height:Cs,svg:Is,terminals:As,stretchable:Ms,params:Ps,label:Os,source:Ls},Nh=Object.freeze(Object.defineProperty({__proto__:null,category:$s,default:Eh,description:Es,height:Cs,id:Ss,label:Os,name:js,params:Ps,source:Ls,stretchable:Ms,svg:Is,terminals:As,viewBox:Ns,width:Ts},Symbol.toStringTag,{value:"Module"})),Bs="contactor",Ds="接触器 (KM)",Rs="motor-control",zs="主回路接触器, 通常配热继电器和电机使用。",Fs="-10 -42 15 64",Hs=15,Ws=64,Gs='<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"/>',qs=[{id:"t1",x:0,y:-40,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],Ks=[{name:"open",type:"boolean",default:!0,label:"断开"}],Ys={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"},Th={id:Bs,name:Ds,category:Rs,description:zs,viewBox:Fs,width:Hs,height:Ws,svg:Gs,terminals:qs,state:Ks,source:Ys},Ch=Object.freeze(Object.defineProperty({__proto__:null,category:Rs,default:Th,description:zs,height:Ws,id:Bs,name:Ds,source:Ys,state:Ks,svg:Gs,terminals:qs,viewBox:Fs,width:Hs},Symbol.toStringTag,{value:"Module"})),Xs="converter-bidir",Vs="双向变流器 (PCS)",Us="renewable",Zs="储能变流器:双向 AC ↔ DC",Js="-42 -42 44 48",Qs=44,ei=48,ti='<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"/>',ni=[{id:"t_ac",x:-20,y:-40,orientation:"n"},{id:"t_dc",x:-20,y:0,orientation:"s"}],oi=[{name:"S",label:"容量",type:"number",unit:"MVA"}],ri={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_14/en_60617_06_14_06.elmt",qetEnglishName:"Rectifier/inverter"},Ih={id:Xs,name:Vs,category:Us,description:Zs,viewBox:Js,width:Qs,height:ei,svg:ti,terminals:ni,params:oi,source:ri},Ah=Object.freeze(Object.defineProperty({__proto__:null,category:Us,default:Ih,description:Zs,height:ei,id:Xs,name:Vs,params:oi,source:ri,svg:ti,terminals:ni,viewBox:Js,width:Qs},Symbol.toStringTag,{value:"Module"})),si="ct",ii="电流互感器 (CT)",ai="instrument-transformer",li="-42 -62 54 64",ci=54,di=64,ui='<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"/>',fi=[{id:"t1",x:-30,y:0,orientation:"s"},{id:"t2",x:-30,y:-60,orientation:"n"}],mi={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_09/en_60617_06_09_10.elmt",qetEnglishName:"Current transformer, general symbol"},Mh={id:si,name:ii,category:ai,viewBox:li,width:ci,height:di,svg:ui,terminals:fi,source:mi},Ph=Object.freeze(Object.defineProperty({__proto__:null,category:ai,default:Mh,height:di,id:si,name:ii,source:mi,svg:ui,terminals:fi,viewBox:li,width:ci},Symbol.toStringTag,{value:"Module"})),pi="dc-combiner",hi="直流汇流箱",gi="renewable",xi="光伏组串汇流箱 (4 路输入示例)。",yi="-27 -32 54 64",bi=54,wi=64,vi='<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>',ki=[{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"}],_i={kind:"inline"},Oh={id:pi,name:hi,category:gi,description:xi,viewBox:yi,width:bi,height:wi,svg:vi,terminals:ki,source:_i},Lh=Object.freeze(Object.defineProperty({__proto__:null,category:gi,default:Oh,description:xi,height:wi,id:pi,name:hi,source:_i,svg:vi,terminals:ki,viewBox:yi,width:bi},Symbol.toStringTag,{value:"Module"})),Si="dc-disconnector",ji="直流隔离开关",$i="switching",Ei="DC isolating switch — 光伏组串 / 储能 直流侧隔离。",Ni="-12 -32 30 64",Ti=30,Ci=64,Ii='<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"/>',Ai=[{id:"t1",x:0,y:-30,orientation:"n"},{id:"t2",x:0,y:30,orientation:"s"}],Mi=[{name:"open",type:"boolean",default:!1,label:"断开"}],Pi={kind:"inline"},Bh={id:Si,name:ji,category:$i,description:Ei,viewBox:Ni,width:Ti,height:Ci,svg:Ii,terminals:Ai,state:Mi,source:Pi},Dh=Object.freeze(Object.defineProperty({__proto__:null,category:$i,default:Bh,description:Ei,height:Ci,id:Si,name:ji,source:Pi,state:Mi,svg:Ii,terminals:Ai,viewBox:Ni,width:Ti},Symbol.toStringTag,{value:"Module"})),Oi="disconnector",Li="隔离开关 (QS)",Bi="switching",Di="-10 -42 15 64",Ri=15,zi=64,Fi='<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"/>',Hi=[{id:"t1",x:0,y:-40,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],Wi=[{name:"open",type:"boolean",default:!1,label:"断开"}],Gi={x:6,y:-10,anchor:"start"},qi={kind:"elmt",path:"91_en_60617/en_60617_07/en_60617_07_13/en_60617_07_13_06.elmt",qetEnglishName:"Disconnector; Isolator"},Rh={id:Oi,name:Li,category:Bi,viewBox:Di,width:Ri,height:zi,svg:Fi,terminals:Hi,state:Wi,label:Gi,source:qi},zh=Object.freeze(Object.defineProperty({__proto__:null,category:Bi,default:Rh,height:zi,id:Oi,label:Gi,name:Li,source:qi,state:Wi,svg:Fi,terminals:Hi,viewBox:Di,width:Ri},Symbol.toStringTag,{value:"Module"})),Ki="earth",Yi="接地",Xi="busbar",Vi="-12 -17 24 34",Ui=24,Zi=34,Ji='<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"/>',Qi=[{id:"t1",x:0,y:-15,orientation:"n"}],ea={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"},Fh={id:Ki,name:Yi,category:Xi,viewBox:Vi,width:Ui,height:Zi,svg:Ji,terminals:Qi,source:ea},Hh=Object.freeze(Object.defineProperty({__proto__:null,category:Xi,default:Fh,height:Zi,id:Ki,name:Yi,source:ea,svg:Ji,terminals:Qi,viewBox:Vi,width:Ui},Symbol.toStringTag,{value:"Module"})),ta="earthing-switch",na="接地刀闸 (QE)",oa="switching",ra="隔离开关 + 接地连接,单端口",sa="-12 -32 24 64",ia=24,aa=64,la='<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"/>',ca=[{id:"t_top",x:0,y:-30,orientation:"n"}],da=[{name:"open",type:"boolean",default:!0,label:"断开"}],ua={x:12,y:-8,anchor:"start"},fa={kind:"inline"},Wh={id:ta,name:na,category:oa,description:ra,viewBox:sa,width:ia,height:aa,svg:la,terminals:ca,state:da,label:ua,source:fa},Gh=Object.freeze(Object.defineProperty({__proto__:null,category:oa,default:Wh,description:ra,height:aa,id:ta,label:ua,name:na,source:fa,state:da,svg:la,terminals:ca,viewBox:sa,width:ia},Symbol.toStringTag,{value:"Module"})),ma="energy-meter",pa="电能表 (Wh)",ha="measurement",ga="有功电能表 (kWh) — 服务入口 / 子表。",xa="-22 -36 44 72",ya=44,ba=72,wa='<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"/>',va=[{id:"t1",x:0,y:-34,orientation:"n"},{id:"t2",x:0,y:34,orientation:"s"}],ka={kind:"elmt",path:"11_singlepole/500_home_installation/40_meters/wattheuremetre_08-04-03_en60617.elmt",qetEnglishName:"Watt hour meter (en_60617)"},qh={id:ma,name:pa,category:ha,description:ga,viewBox:xa,width:ya,height:ba,svg:wa,terminals:va,source:ka},Kh=Object.freeze(Object.defineProperty({__proto__:null,category:ha,default:qh,description:ga,height:ba,id:ma,name:pa,source:ka,svg:wa,terminals:va,viewBox:xa,width:ya},Symbol.toStringTag,{value:"Module"})),_a="ev-charger",Sa="EV 充电桩",ja="load",$a="电动汽车充电站 / 充电桩。",Ea="-17 -27 34 49",Na=34,Ta=49,Ca='<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>',Ia=[{id:"t_top",x:0,y:-25,orientation:"n"}],Aa={kind:"inline"},Yh={id:_a,name:Sa,category:ja,description:$a,viewBox:Ea,width:Na,height:Ta,svg:Ca,terminals:Ia,source:Aa},Xh=Object.freeze(Object.defineProperty({__proto__:null,category:ja,default:Yh,description:$a,height:Ta,id:_a,name:Sa,source:Aa,svg:Ca,terminals:Ia,viewBox:Ea,width:Na},Symbol.toStringTag,{value:"Module"})),Ma="frequency-meter",Pa="频率表 (Hz)",Oa="measurement",La="-22 -42 44 44",Ba=44,Da=44,Ra='<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"}],Fa={kind:"elmt",path:"91_en_60617/en_60617_08/en_60617_08_02/en_60617_08_02_07.elmt",qetEnglishName:"Frequency meter"},Vh={id:Ma,name:Pa,category:Oa,viewBox:La,width:Ba,height:Da,svg:Ra,terminals:za,source:Fa},Uh=Object.freeze(Object.defineProperty({__proto__:null,category:Oa,default:Vh,height:Da,id:Ma,name:Pa,source:Fa,svg:Ra,terminals:za,viewBox:La,width:Ba},Symbol.toStringTag,{value:"Module"})),Ha="fuse",Wa="熔断器 (FU)",Ga="switching",qa="-7 -32 14 64",Ka=14,Ya=64,Xa='<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"/>',Va=[{id:"t1",x:0,y:30,orientation:"s"},{id:"t2",x:0,y:-30,orientation:"n"}],Ua=[{name:"blown",type:"boolean",default:!1,label:"熔断"}],Za={x:7,y:-2,anchor:"start"},Ja={kind:"elmt",path:"91_en_60617/en_60617_07/en_60617_07_21/en_60617_07_21_01.elmt",qetEnglishName:"Fuse, general symbol"},Zh={id:Ha,name:Wa,category:Ga,viewBox:qa,width:Ka,height:Ya,svg:Xa,terminals:Va,state:Ua,label:Za,source:Ja},Jh=Object.freeze(Object.defineProperty({__proto__:null,category:Ga,default:Zh,height:Ya,id:Ha,label:Za,name:Wa,source:Ja,state:Ua,svg:Xa,terminals:Va,viewBox:qa,width:Ka},Symbol.toStringTag,{value:"Module"})),Qa="generator",el="发电机 (G)",tl="source",nl="-42 -42 44 44",ol=44,rl=44,sl='<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>',il=[{id:"t_bottom",x:-20,y:0,orientation:"s"}],al={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_16/en_60617_06_16_01.elmt",qetEnglishName:"Generator, general symbol"},Qh={id:Qa,name:el,category:tl,viewBox:nl,width:ol,height:rl,svg:sl,terminals:il,source:al},eg=Object.freeze(Object.defineProperty({__proto__:null,category:tl,default:Qh,height:rl,id:Qa,name:el,source:al,svg:sl,terminals:il,viewBox:nl,width:ol},Symbol.toStringTag,{value:"Module"})),ll="gfci-breaker",cl="GFCI 断路器 (RCBO)",dl="protection",ul="剩余电流断路器带过流保护 (UL943 / IEC 61009)。北美 GFCI / 欧洲 RCBO。",fl="-18 -22 22 44",ml=22,pl=44,hl='<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"/>',gl=[{id:"t1",x:0,y:-20,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],xl=[{name:"open",type:"boolean",default:!1,label:"断开"}],yl=[{name:"In",label:"额定电流",type:"number",unit:"A"},{name:"IDn",label:"剩余动作电流",type:"number",unit:"mA",default:30}],bl={kind:"elmt",path:"11_singlepole/200_fuses_protective_gears/50_residual_current_circuit_breaker/rcbo.elmt",qetEnglishName:"Residual Circuit Breaker with Overload"},tg={id:ll,name:cl,category:dl,description:ul,viewBox:fl,width:ml,height:pl,svg:hl,terminals:gl,state:xl,params:yl,source:bl},ng=Object.freeze(Object.defineProperty({__proto__:null,category:dl,default:tg,description:ul,height:pl,id:ll,name:cl,params:yl,source:bl,state:xl,svg:hl,terminals:gl,viewBox:fl,width:ml},Symbol.toStringTag,{value:"Module"})),wl="grid-source",vl="系统电源",kl="source",_l="无穷大母线 / 外部电网",Sl="-16 -31 32 53",jl=32,$l=53,El='<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"/>',Nl=[{id:"t_bottom",x:0,y:20,orientation:"s"}],Tl={kind:"inline"},og={id:wl,name:vl,category:kl,description:_l,viewBox:Sl,width:jl,height:$l,svg:El,terminals:Nl,source:Tl},rg=Object.freeze(Object.defineProperty({__proto__:null,category:kl,default:og,description:_l,height:$l,id:wl,name:vl,source:Tl,svg:El,terminals:Nl,viewBox:Sl,width:jl},Symbol.toStringTag,{value:"Module"})),Cl="grounding-transformer",Il="接地变 (Z形)",Al="grounding",Ml="星-曲折接线变压器,中性点接地用",Pl="-62 -152 64 164",Ol=64,Ll=164,Bl='<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"/>',Dl=[{id:"t1",x:-30,y:10,orientation:"s"},{id:"t2",x:-30,y:-150,orientation:"n"}],Rl={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"},sg={id:Cl,name:Il,category:Al,description:Ml,viewBox:Pl,width:Ol,height:Ll,svg:Bl,terminals:Dl,source:Rl},ig=Object.freeze(Object.defineProperty({__proto__:null,category:Al,default:sg,description:Ml,height:Ll,id:Cl,name:Il,source:Rl,svg:Bl,terminals:Dl,viewBox:Pl,width:Ol},Symbol.toStringTag,{value:"Module"})),zl="inverter",Fl="逆变器 (DC→AC)",Hl="renewable",Wl="-42 -42 44 44",Gl=44,ql=44,Kl='<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"/>',Yl=[{id:"t_dc",x:-20,y:-40,orientation:"n"},{id:"t_ac",x:-20,y:0,orientation:"s"}],Xl={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_14/en_60617_06_14_05.elmt",qetEnglishName:"Inverter"},ag={id:zl,name:Fl,category:Hl,viewBox:Wl,width:Gl,height:ql,svg:Kl,terminals:Yl,source:Xl},lg=Object.freeze(Object.defineProperty({__proto__:null,category:Hl,default:ag,height:ql,id:zl,name:Fl,source:Xl,svg:Kl,terminals:Yl,viewBox:Wl,width:Gl},Symbol.toStringTag,{value:"Module"})),Vl="load-switch",Ul="负荷开关",Zl="switching",Jl="-10 -42 14 64",Ql=14,ec=64,tc='<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"/>',nc=[{id:"t1",x:0,y:-40,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],oc=[{name:"open",type:"boolean",default:!1,label:"断开"}],rc={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"},cg={id:Vl,name:Ul,category:Zl,viewBox:Jl,width:Ql,height:ec,svg:tc,terminals:nc,state:oc,source:rc},dg=Object.freeze(Object.defineProperty({__proto__:null,category:Zl,default:cg,height:ec,id:Vl,name:Ul,source:rc,state:oc,svg:tc,terminals:nc,viewBox:Jl,width:Ql},Symbol.toStringTag,{value:"Module"})),sc="load",ic="负荷",ac="load",lc="抽象负荷(电流流出箭头)",cc="-8 -22 16 46",dc=16,uc=46,fc='<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"/>',mc=[{id:"t_top",x:0,y:-20,orientation:"n"}],pc=[{name:"P",label:"有功功率",type:"number",unit:"MW",showOnCanvas:!0},{name:"cosphi",label:"功率因数",type:"number"}],hc={x:6,y:0,anchor:"start"},gc={kind:"inline"},ug={id:sc,name:ic,category:ac,description:lc,viewBox:cc,width:dc,height:uc,svg:fc,terminals:mc,params:pc,label:hc,source:gc},fg=Object.freeze(Object.defineProperty({__proto__:null,category:ac,default:ug,description:lc,height:uc,id:sc,label:hc,name:ic,params:pc,source:gc,svg:fc,terminals:mc,viewBox:cc,width:dc},Symbol.toStringTag,{value:"Module"})),xc="motor-starter",yc="电机启动器",bc="motor-control",wc="电机启动器 (IEC 60617 通用符号)。",vc="-22 -27 44 54",kc=44,_c=54,Sc='<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"/>',jc=[{id:"t_top",x:0,y:-25,orientation:"n"},{id:"t_bottom",x:0,y:25,orientation:"s"}],$c={kind:"elmt",path:"91_en_60617/en_60617_07/en_60617_07_14/en_60617_07_14_01.elmt",qetEnglishName:"Motor starter, general symbol"},mg={id:xc,name:yc,category:bc,description:wc,viewBox:vc,width:kc,height:_c,svg:Sc,terminals:jc,source:$c},pg=Object.freeze(Object.defineProperty({__proto__:null,category:bc,default:mg,description:wc,height:_c,id:xc,name:yc,source:$c,svg:Sc,terminals:jc,viewBox:vc,width:kc},Symbol.toStringTag,{value:"Module"})),Ec="ngr",Nc="中性点电阻 (NGR)",Tc="grounding",Cc="小电阻接地:连接变压器中性点到地",Ic="-12 -32 24 62",Ac=24,Mc=62,Pc='<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"/>',Oc=[{id:"t_top",x:0,y:-30,orientation:"n"}],Lc=[{name:"R",label:"电阻",type:"number",unit:"Ω"}],Bc={kind:"inline"},hg={id:Ec,name:Nc,category:Tc,description:Cc,viewBox:Ic,width:Ac,height:Mc,svg:Pc,terminals:Oc,params:Lc,source:Bc},gg=Object.freeze(Object.defineProperty({__proto__:null,category:Tc,default:hg,description:Cc,height:Mc,id:Ec,name:Nc,params:Lc,source:Bc,svg:Pc,terminals:Oc,viewBox:Ic,width:Ac},Symbol.toStringTag,{value:"Module"})),Dc="pt",Rc="电压互感器 (PT)",zc="instrument-transformer",Fc="-22 -42 44 115",Hc=44,Wc=115,Gc='<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"/>',qc=[{id:"t1",x:0,y:71,orientation:"s"},{id:"t2",x:0,y:-40,orientation:"n"}],Kc={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_13/en_60617_06_13_01A.elmt",qetEnglishName:"Voltage transformer"},xg={id:Dc,name:Rc,category:zc,viewBox:Fc,width:Hc,height:Wc,svg:Gc,terminals:qc,source:Kc},yg=Object.freeze(Object.defineProperty({__proto__:null,category:zc,default:xg,height:Wc,id:Dc,name:Rc,source:Kc,svg:Gc,terminals:qc,viewBox:Fc,width:Hc},Symbol.toStringTag,{value:"Module"})),Yc="pv",Xc="光伏组件",Vc="renewable",Uc="-33 -22 85 64",Zc=85,Jc=64,Qc='<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"/>',ed=[{id:"t_dc",x:50,y:10,orientation:"e"}],td={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_18/en_60617_06_18_06.elmt",qetEnglishName:"Photovoltaic generator"},bg={id:Yc,name:Xc,category:Vc,viewBox:Uc,width:Zc,height:Jc,svg:Qc,terminals:ed,source:td},wg=Object.freeze(Object.defineProperty({__proto__:null,category:Vc,default:bg,height:Jc,id:Yc,name:Xc,source:td,svg:Qc,terminals:ed,viewBox:Uc,width:Zc},Symbol.toStringTag,{value:"Module"})),nd="rcd",od="剩余电流装置 (RCD)",rd="protection",sd="不带过流保护的剩余电流断路器 (IEC 61008)。",id="-12 -22 19 44",ad=19,ld=44,cd='<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"/>',dd=[{id:"t1",x:0,y:-20,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],ud=[{name:"open",type:"boolean",default:!1,label:"断开"}],fd=[{name:"IDn",label:"剩余动作电流",type:"number",unit:"mA",default:30}],md={kind:"elmt",path:"11_singlepole/200_fuses_protective_gears/50_residual_current_circuit_breaker/ddr1.elmt",qetEnglishName:"Residual Circuit Breaker with Overload"},vg={id:nd,name:od,category:rd,description:sd,viewBox:id,width:ad,height:ld,svg:cd,terminals:dd,state:ud,params:fd,source:md},kg=Object.freeze(Object.defineProperty({__proto__:null,category:rd,default:vg,description:sd,height:ld,id:nd,name:od,params:fd,source:md,state:ud,svg:cd,terminals:dd,viewBox:id,width:ad},Symbol.toStringTag,{value:"Module"})),pd="recloser",hd="重合闸 (Recloser)",gd="protection",xd="中压自动重合闸开关。",yd="-12 -32 36 64",bd=36,wd=64,vd='<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>',kd=[{id:"t1",x:0,y:-30,orientation:"n"},{id:"t2",x:0,y:30,orientation:"s"}],_d=[{name:"open",type:"boolean",default:!1,label:"断开"}],Sd={kind:"inline"},_g={id:pd,name:hd,category:gd,description:xd,viewBox:yd,width:bd,height:wd,svg:vd,terminals:kd,state:_d,source:Sd},Sg=Object.freeze(Object.defineProperty({__proto__:null,category:gd,default:_g,description:xd,height:wd,id:pd,name:hd,source:Sd,state:_d,svg:vd,terminals:kd,viewBox:yd,width:bd},Symbol.toStringTag,{value:"Module"})),jd="rectifier",$d="整流器 (AC→DC)",Ed="renewable",Nd="-42 -42 44 44",Td=44,Cd=44,Id='<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"/>',Ad=[{id:"t_ac",x:-20,y:-40,orientation:"n"},{id:"t_dc",x:-20,y:0,orientation:"s"}],Md={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_14/en_60617_06_14_03.elmt",qetEnglishName:"Rectifier"},jg={id:jd,name:$d,category:Ed,viewBox:Nd,width:Td,height:Cd,svg:Id,terminals:Ad,source:Md},$g=Object.freeze(Object.defineProperty({__proto__:null,category:Ed,default:jg,height:Cd,id:jd,name:$d,source:Md,svg:Id,terminals:Ad,viewBox:Nd,width:Td},Symbol.toStringTag,{value:"Module"})),Pd="series-reactor",Od="串联电抗器",Ld="compensation",Bd="与并联电抗器同符号;通过用法区分。",Dd="-62 -82 64 104",Rd=64,zd=104,Fd='<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"/>',Hd=[{id:"t1",x:-30,y:-80,orientation:"n"},{id:"t_bottom",x:-30,y:20,orientation:"s"}],Wd={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_09/en_60617_06_09_08.elmt",qetEnglishName:"Choke; Reactor, general symbol"},Eg={id:Pd,name:Od,category:Ld,description:Bd,viewBox:Dd,width:Rd,height:zd,svg:Fd,terminals:Hd,source:Wd},Ng=Object.freeze(Object.defineProperty({__proto__:null,category:Ld,default:Eg,description:Bd,height:zd,id:Pd,name:Od,source:Wd,svg:Fd,terminals:Hd,viewBox:Dd,width:Rd},Symbol.toStringTag,{value:"Module"})),Gd="shunt-capacitor",qd="并联电容器",Kd="compensation",Yd="-7 -23 14 27",Xd=14,Vd=27,Ud='<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"/>',Zd=[{id:"t1",x:0,y:-21,orientation:"n"},{id:"t_bottom",x:0,y:2,orientation:"s"}],Jd=[{name:"Q",label:"无功容量",type:"number",unit:"Mvar"},{name:"stages",label:"分组数",type:"number"}],Qd={kind:"elmt",path:"11_singlepole/395_electronics_semiconductors/20_capacitors/capacite.elmt",qetEnglishName:"Capacitor"},Tg={id:Gd,name:qd,category:Kd,viewBox:Yd,width:Xd,height:Vd,svg:Ud,terminals:Zd,params:Jd,source:Qd},Cg=Object.freeze(Object.defineProperty({__proto__:null,category:Kd,default:Tg,height:Vd,id:Gd,name:qd,params:Jd,source:Qd,svg:Ud,terminals:Zd,viewBox:Yd,width:Xd},Symbol.toStringTag,{value:"Module"})),eu="shunt-reactor",tu="并联电抗器",nu="compensation",ou="-62 -82 64 104",ru=64,su=104,iu='<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"/>',au=[{id:"t1",x:-30,y:-80,orientation:"n"},{id:"t_bottom",x:-30,y:20,orientation:"s"}],lu={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_09/en_60617_06_09_08.elmt",qetEnglishName:"Choke; Reactor, general symbol"},Ig={id:eu,name:tu,category:nu,viewBox:ou,width:ru,height:su,svg:iu,terminals:au,source:lu},Ag=Object.freeze(Object.defineProperty({__proto__:null,category:nu,default:Ig,height:su,id:eu,name:tu,source:lu,svg:iu,terminals:au,viewBox:ou,width:ru},Symbol.toStringTag,{value:"Module"})),cu="soft-starter",du="软启动器",uu="motor-control",fu="电机软启动器 (晶闸管降压启动)。",mu="-22 -42 44 84",pu=44,hu=84,gu='<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"/>',xu=[{id:"t_in",x:0,y:-40,orientation:"n"},{id:"t_out",x:0,y:40,orientation:"s"}],yu={kind:"inline"},Mg={id:cu,name:du,category:uu,description:fu,viewBox:mu,width:pu,height:hu,svg:gu,terminals:xu,source:yu},Pg=Object.freeze(Object.defineProperty({__proto__:null,category:uu,default:Mg,description:fu,height:hu,id:cu,name:du,source:yu,svg:gu,terminals:xu,viewBox:mu,width:pu},Symbol.toStringTag,{value:"Module"})),bu="sync-motor",wu="同步电动机",vu="load",ku="-62 -82 64 114",_u=64,Su=114,ju='<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"/>',$u=[{id:"t1",x:-10,y:-80,orientation:"n"},{id:"t2",x:-50,y:-80,orientation:"n"}],Eu={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_07/en_60617_06_07_02.elmt",qetEnglishName:"Synchronous motor, single-phase"},Og={id:bu,name:wu,category:vu,viewBox:ku,width:_u,height:Su,svg:ju,terminals:$u,source:Eu},Lg=Object.freeze(Object.defineProperty({__proto__:null,category:vu,default:Og,height:Su,id:bu,name:wu,source:Eu,svg:ju,terminals:$u,viewBox:ku,width:_u},Symbol.toStringTag,{value:"Module"})),Nu="thermal-overload",Tu="热过载继电器",Cu="motor-control",Iu="电机热过载保护继电器, 通常串接在接触器和电机之间。",Au="-9 -32 19 64",Mu=19,Pu=64,Ou='<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"/>',Lu=[{id:"t1",x:0,y:-30,orientation:"n"},{id:"t2",x:0,y:30,orientation:"s"}],Bu=[{name:"tripped",type:"boolean",default:!1,label:"动作"}],Du={kind:"inline"},Bg={id:Nu,name:Tu,category:Cu,description:Iu,viewBox:Au,width:Mu,height:Pu,svg:Ou,terminals:Lu,state:Bu,source:Du},Dg=Object.freeze(Object.defineProperty({__proto__:null,category:Cu,default:Bg,description:Iu,height:Pu,id:Nu,name:Tu,source:Du,state:Bu,svg:Ou,terminals:Lu,viewBox:Au,width:Mu},Symbol.toStringTag,{value:"Module"})),Ru="transfer-switch",zu="切换开关 (ATS)",Fu="switching",Hu="双源切换开关 (Automatic / Manual Transfer Switch)。两个电源输入 + 一个负荷输出, 互锁不并联。",Wu="-27 -32 51 64",Gu=51,qu=64,Ku='<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"/>',Yu=[{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"}],Xu=[{name:"position",type:"string",default:"normal",label:"位置 (normal/emergency/off)"}],Vu={kind:"inline"},Rg={id:Ru,name:zu,category:Fu,description:Hu,viewBox:Wu,width:Gu,height:qu,svg:Ku,terminals:Yu,state:Xu,source:Vu},zg=Object.freeze(Object.defineProperty({__proto__:null,category:Fu,default:Rg,description:Hu,height:qu,id:Ru,name:zu,source:Vu,state:Xu,svg:Ku,terminals:Yu,viewBox:Wu,width:Gu},Symbol.toStringTag,{value:"Module"})),Uu="transformer-2w",Zu="双绕组变压器",Ju="transformer",Qu="-62 -142 64 144",ef=64,tf=144,nf='<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"/>',of=[{id:"t1",x:-30,y:0,orientation:"s"},{id:"t2",x:-30,y:-140,orientation:"n"}],rf=[{name:"S",label:"容量",type:"number",unit:"MVA",showOnCanvas:!0},{name:"ratio",label:"变比",type:"string",showOnCanvas:!0}],sf={x:4,y:-68,anchor:"start"},af={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"},Fg={id:Uu,name:Zu,category:Ju,viewBox:Qu,width:ef,height:tf,svg:nf,terminals:of,params:rf,label:sf,source:af},Hg=Object.freeze(Object.defineProperty({__proto__:null,category:Ju,default:Fg,height:tf,id:Uu,label:sf,name:Zu,params:rf,source:af,svg:nf,terminals:of,viewBox:Qu,width:ef},Symbol.toStringTag,{value:"Module"})),lf="transformer-3w",cf="三绕组变压器",df="transformer",uf="-82 -131 114 133",ff=114,mf=133,pf='<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"/>',hf=[{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"}],gf={x:4,y:-64,anchor:"start"},xf={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"},Wg={id:lf,name:cf,category:df,viewBox:uf,width:ff,height:mf,svg:pf,terminals:hf,label:gf,source:xf},Gg=Object.freeze(Object.defineProperty({__proto__:null,category:df,default:Wg,height:mf,id:lf,label:gf,name:cf,source:xf,svg:pf,terminals:hf,viewBox:uf,width:ff},Symbol.toStringTag,{value:"Module"})),yf="vfd",bf="变频器 (VFD)",wf="motor-control",vf="Variable Frequency Drive — 异步电动机调速。",kf="-24 -42 48 84",_f=48,Sf=84,jf='<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"/>',$f=[{id:"t_in",x:0,y:-40,orientation:"n"},{id:"t_out",x:0,y:40,orientation:"s"}],Ef={kind:"inline"},qg={id:yf,name:bf,category:wf,description:vf,viewBox:kf,width:_f,height:Sf,svg:jf,terminals:$f,source:Ef},Kg=Object.freeze(Object.defineProperty({__proto__:null,category:wf,default:qg,description:vf,height:Sf,id:yf,name:bf,source:Ef,svg:jf,terminals:$f,viewBox:kf,width:_f},Symbol.toStringTag,{value:"Module"})),Nf="voltmeter",Tf="电压表 (V)",Cf="measurement",If="-22 -42 44 44",Af=44,Mf=44,Pf='<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>',Of=[{id:"t_top",x:0,y:-40,orientation:"n"}],Lf={kind:"elmt",path:"91_en_60617/en_60617_08/en_60617_08_02/en_60617_08_02_01.elmt",qetEnglishName:"Voltmeter"},Yg={id:Nf,name:Tf,category:Cf,viewBox:If,width:Af,height:Mf,svg:Pf,terminals:Of,source:Lf},Xg=Object.freeze(Object.defineProperty({__proto__:null,category:Cf,default:Yg,height:Mf,id:Nf,name:Tf,source:Lf,svg:Pf,terminals:Of,viewBox:If,width:Af},Symbol.toStringTag,{value:"Module"})),Bf="wattmeter",Df="功率表 (W)",Rf="measurement",zf="-22 -42 44 44",Ff=44,Hf=44,Wf='<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>',Gf=[{id:"t_top",x:0,y:-40,orientation:"n"}],qf={kind:"elmt",path:"91_en_60617/en_60617_08/en_60617_08_03/en_60617_08_03_01.elmt",qetEnglishName:"Recording wattmeter"},Vg={id:Bf,name:Df,category:Rf,viewBox:zf,width:Ff,height:Hf,svg:Wf,terminals:Gf,source:qf},Ug=Object.freeze(Object.defineProperty({__proto__:null,category:Rf,default:Vg,height:Hf,id:Bf,name:Df,source:qf,svg:Wf,terminals:Gf,viewBox:zf,width:Ff},Symbol.toStringTag,{value:"Module"})),Kf="wind-turbine",Yf="风力发电机",Xf="renewable",Vf="风机:发电机 + 三叶轮标记",Uf="-22 -46 44 68",Zf=44,Jf=68,Qf='<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"/>',em=[{id:"t_bottom",x:0,y:20,orientation:"s"}],tm={kind:"inline"},Zg={id:Kf,name:Yf,category:Xf,description:Vf,viewBox:Uf,width:Zf,height:Jf,svg:Qf,terminals:em,source:tm},Jg=Object.freeze(Object.defineProperty({__proto__:null,category:Xf,default:Zg,description:Vf,height:Jf,id:Kf,name:Yf,source:tm,svg:Qf,terminals:em,viewBox:Uf,width:Zf},Symbol.toStringTag,{value:"Module"})),Qg=Object.assign({"./ammeter.json":ph,"./arc-suppression-coil.json":gh,"./arrester.json":yh,"./async-motor.json":wh,"./autotransformer.json":kh,"./battery.json":Sh,"./breaker.json":$h,"./busbar.json":Nh,"./contactor.json":Ch,"./converter-bidir.json":Ah,"./ct.json":Ph,"./dc-combiner.json":Lh,"./dc-disconnector.json":Dh,"./disconnector.json":zh,"./earth.json":Hh,"./earthing-switch.json":Gh,"./energy-meter.json":Kh,"./ev-charger.json":Xh,"./frequency-meter.json":Uh,"./fuse.json":Jh,"./generator.json":eg,"./gfci-breaker.json":ng,"./grid-source.json":rg,"./grounding-transformer.json":ig,"./inverter.json":lg,"./load-switch.json":dg,"./load.json":fg,"./motor-starter.json":pg,"./ngr.json":gg,"./pt.json":yg,"./pv.json":wg,"./rcd.json":kg,"./recloser.json":Sg,"./rectifier.json":$g,"./series-reactor.json":Ng,"./shunt-capacitor.json":Cg,"./shunt-reactor.json":Ag,"./soft-starter.json":Pg,"./sync-motor.json":Lg,"./thermal-overload.json":Dg,"./transfer-switch.json":zg,"./transformer-2w.json":Hg,"./transformer-3w.json":Gg,"./vfd.json":Kg,"./voltmeter.json":Xg,"./wattmeter.json":Ug,"./wind-turbine.json":Jg}),nm=Object.values(Qg).map(e=>e.default),qe=Object.fromEntries(nm.map(e=>[e.id,e])),to=["busbar","switching","protection","motor-control","transformer","instrument-transformer","measurement","source","load","storage","compensation","grounding","renewable"],e0=(()=>{var t;const e={};for(const n of nm)(e[t=n.category]??(e[t]=[])).push(n);return e})(),an=new Map(Object.entries(qe));function om(e){return qe[e]}function t0(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 n0=320;function He(e){var f,m,g,p;const t=lr(),n=new Map;e.elements.forEach((h,y)=>{if(n.has(h.id)){t.diagnostics.push({code:"E001",severity:"error",message:xe("compile.duplicateId",{id:h.id}),pointer:`/elements/${y}`});return}n.set(h.id,h);const w=an.get(h.kind);w||t.diagnostics.push({code:"E003",severity:"error",message:`${xe("compile.unknownKind",{kind:h.kind})} (id=${h.id})`,pointer:`/elements/${y}`}),t.elements.set(h.id,{element:h,libraryDef:w})});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:xe("compile.duplicateId",{id:h.id}),pointer:`/buses/${y}`});return}if(o.set(h.id,h),h.layout){const w=h.layout.rot??0;r.set(h.id,{at:h.layout.at,span:h.layout.span,rot:w,axis:rn(w)})}});const s=h=>!h.includes(".")&&o.has(h),i=(h,y)=>{if(s(h))return!0;const w=h.indexOf(".");if(w<=0)return t.diagnostics.push({code:"E003",severity:"error",message:xe("compile.invalidTermRef",{ref:h}),pointer:y}),!1;const v=h.slice(0,w),N=h.slice(w+1),I=t.elements.get(v);if(!I)return t.diagnostics.push({code:"E002",severity:"error",message:xe("compile.elementMissing",{id:v}),pointer:y}),!1;if(!I.libraryDef)return!1;if(!I.libraryDef.terminals.find(L=>L.id===N)){const L=I.libraryDef.terminals.map(W=>W.id).join(", ");return t.diagnostics.push({code:"E003",severity:"error",message:xe("compile.missingPin",{id:v,kind:I.element.kind,pin:N,available:L}),pointer:y}),!1}return!0},a=[];(e.wires??[]).forEach((h,y)=>{const w=`/wires/${y}`,v=i(h.ends[0],w),N=i(h.ends[1],w);v&&N&&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,cr(y)):t.diagnostics.push({code:"E004",severity:"error",message:xe("compile.layoutMissingElement",{id:h}),pointer:`/layout/${h}`});const d=uh({elements:e.elements,buses:e.buses??[],wires:a,library:an,userLayout:l,userBusLayout:r});t.layout=d.devices;for(const[h,y]of d.buses){const w=o.get(h);w&&t.buses.set(h,{bus:w,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:((m=y.layout)==null?void 0:m.span)??n0,rot:((g=y.layout)==null?void 0:g.rot)??0,axis:rn(((p=y.layout)==null?void 0:p.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 w=[];for(const v of h.libraryDef.terminals){const N=`${h.element.id}.${v.id}`,I=Oe([v.x,v.y],y),L=mt(v.orientation,y);t.terminals.set(N,{ref:N,elementId:h.element.id,pin:v.id,world:I,orientation:L}),w.push(N)}t.elementToTerminals.set(h.element.id,w)}const u=new dr;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=t0(h);t.nodes.set(y,{id:y,terminals:h});for(const w of h)t.terminalToNode.set(w,y)}for(const h of t.elements.values()){const y=t.elementToTerminals.get(h.element.id)??[];if(y.length===0)continue;y.some(v=>t.terminalToNode.has(v))||t.diagnostics.push({code:"W001",severity:"warning",message:xe("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:xe("compile.elementUnconnected",{id:h})});for(const h of a){if(h.path&&h.path.length>=2){t.wireRenders.set(h.id,{wireId:h.id,path:h.path,userEdited:!0});continue}const y=fh(h,t);y&&t.wireRenders.set(h.id,y)}return t}const o0={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"},no="B";function rm(e){return new Set([...e.elements.map(t=>t.id),...(e.buses??[]).map(t=>t.id)])}function ht(e,t){const n=o0[t]??t,o=rm(e);let r=1;for(;o.has(`${n}${r}`);)r++;return`${n}${r}`}function ln(e){const t=rm(e);let n=1;for(;t.has(`${no}${n}`);)n++;return`${no}${n}`}function r0(e){const t=new Set((e.annotations??[]).map(o=>o.id));let n=1;for(;t.has(`a${n}`);)n++;return`a${n}`}function gt(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 oo={version:"1",elements:[]},s0=100,ro=20;function i0(){if(typeof window>"u")return"select";try{return window.matchMedia("(pointer: coarse)").matches?"pan":"select"}catch{return"select"}}const x=Lt()(oh((e,t)=>({diagram:oo,internal:He(oo),fileSession:null,activeTool:i0(),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>=s0?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:a0(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(m=>s.has(m.id)).map(m=>structuredClone(m)),a=(o.buses??[]).filter(m=>s.has(m.id)).map(m=>structuredClone(m)),l={};for(const m of n)if(s.has(m)&&!r.buses.has(m)){const g=(f=o.layout)==null?void 0:f[m];if(g){l[m]=structuredClone(g);continue}const p=r.layout.get(m);p&&(l[m]=jt(p))}const d={};for(const m of n){const g=r.buses.get(m);g&&(d[m]=Ve(g.geometry))}const u=(o.wires??[]).filter(m=>m.ends.every(g=>s.has(Gt(g)))).map(m=>structuredClone(m));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=ro*s,a=ro*s,l=new Map;let d=r;for(const f of n.elements){const m=ht(d,f.kind);l.set(f.id,m),d={...d,elements:[...d.elements,{id:m,kind:f.kind}]}}for(const f of n.buses){const m=ln(d);l.set(f.id,m),d={...d,buses:[...d.buses??[],{id:m}]}}const u=f=>{const m=f.indexOf("."),g=m<0?f:f.slice(0,m),p=l.get(g);return p?m<0?p:`${p}${f.slice(m)}`:f};t().dispatch(f=>{const m=n.elements.map(w=>{const v=structuredClone(w);return v.id=l.get(w.id),v}),g=n.buses.map(w=>{const v=structuredClone(w);v.id=l.get(w.id);const N=n.busLayouts[w.id];return N&&(v.layout={...N,at:[N.at[0]+i,N.at[1]+a]}),v}),p={...f.layout??{}};for(const[w,v]of l){const N=n.placements[w];N&&(p[v]={...N,at:[N.at[0]+i,N.at[1]+a]})}const h=n.wires.map(w=>{const v=[u(w.ends[0]),u(w.ends[1])];return{id:gt(v[0],v[1]),ends:v}}),y=l0(f.wires??[],h);return{...f,elements:[...f.elements,...m],buses:g.length?[...f.buses??[],...g]:f.buses,wires:y.length?y:void 0,layout:Object.keys(p).length?p: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]=jt(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:Ve(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(m=>m.id===u&&m.layout)||a.set(u,Ve(f.geometry))}else{if(s[u])continue;const f=o.layout.get(u);f&&(i[u]=jt(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?jt(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??Ve(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(Gt(d.ends[0]))&&!o.has(Gt(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}=t();n&&(t().dispatch(o=>{const r=(o.wires??[]).filter(s=>s.id!==n);return r.length===(o.wires??[]).length?o:{...o,wires:r.length?r: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 m={at:f.at};f.rot&&(m.rot=f.rot),f.mirror&&(m.mirror=f.mirror),l[u]=m}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,m;const i={...s.layout??{}},a=new Map;for(const g of o){if(r.buses.has(g)){const y=r.buses.get(g),v=(((((f=(u=(d=s.buses)==null?void 0:d.find(N=>N.id===g))==null?void 0:u.layout)==null?void 0:f.rot)??y.geometry.rot??0)+n)%360+360)%360;a.set(g,v);continue}const p=i[g]??{at:((m=r.layout.get(g))==null?void 0:m.at)??[0,0]},h=(((p.rot??0)+n)%360+360)%360;i[g]={...p,rot:h}}let l=s.buses;return a.size>0&&(l=(s.buses??[]).map(g=>{if(!a.has(g.id))return g;const p=g.layout??Ve(r.buses.get(g.id).geometry);return{...g,layout:{...p,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=ht(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=ln(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=gt(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]}]}})},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)?Ve(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=r0(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:ar(()=>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 a0(e){return Array.from(new Set(e))}function Gt(e){const t=e.indexOf(".");return t<0?e:e.slice(0,t)}function l0(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 jt(e){return{at:[e.at[0],e.at[1]],...e.rot?{rot:e.rot}:{},...e.mirror?{mirror:e.mirror}:{}}}function Ve(e){return{at:[e.at[0],e.at[1]],span:e.span,...e.rot?{rot:e.rot}:{}}}let sm=null;function so(e){sm=e}function bt(){return sm}const At=10;function im(){if(typeof document>"u")return!0;const e=document.querySelector(".ole-canvas-root");return!!e&&!e.classList.contains("hide-grid")}function oe(e){return im()?Math.round(e/At)*At:e}const c0=30,d0=144;function am(e,t){const n=qe[e],o=x.getState(),r=o.diagram;if(!n||e==="busbar")return{newElementId:o.addElement(e,t),attachedToBus:!1};const s=u0(r,t);if(!s){const h=lm(n),y=h?[oe(t[0])-h.x,oe(t[1])-h.y]:[oe(t[0]),oe(t[1])];return{newElementId:o.addElement(e,y),attachedToBus:!1}}const{busId:i,busAt:a,axis:l}=s,d=f0(n,l),u=ht(r,e),f=n.terminals.find(h=>h.id===d),m=l==="x"?t[0]:a[0],g=l==="y"?t[1]:a[1],p=f?[oe(m)-f.x,oe(g)-f.y]:[oe(t[0]),oe(t[1])];return o.dispatch(h=>{const y={id:u,kind:e},w={at:p},v=`${u}.${d}`,N={id:gt(i,v),ends:[i,v]};return{...h,elements:[...h.elements,y],wires:[...h.wires??[],N],layout:{...h.layout??{},[u]:w}}}),o.setSelection([u]),{newElementId:u,attachedToBus:!0}}function u0(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,m=t[0]<u?u-t[0]:t[0]>f?t[0]-f:0,g=Math.abs(t[1]-a[1]);d=Math.sqrt(m*m+g*g)}else{const u=a[1]-l/2,f=a[1]+l/2,m=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+m*m)}d<=c0&&(!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 f0(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 lm(e){return!e||e.stretchable||e.terminals.length===0?null:[...e.terminals].sort((n,o)=>n.y-o.y)[0]}function cm(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,p=i[0]+a/2,h=Math.max(g,Math.min(p,t[0])),y=i[1],w=t[1]>=y?"s":"n";return{ref:e,world:[h,y],orientation:w,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],m=t[0]>=f?"e":"w";return{ref:e,world:[f,u],orientation:m,isBus:!0,busId:e}}const o=n.terminals.get(e);return o?{ref:e,world:o.world,orientation:o.orientation,isBus:!1}:null}const m0={n:"s",s:"n",e:"w",w:"e"};function dm(e,t,n){if(e.terminals.length===0)return{id:"t",x:0,y:0,orientation:"n"};const o=m0[t.orientation],r=e.terminals.filter(l=>l.orientation===o),s=r.length>0?r:e.terminals;let i=s[0],a=io(i,n,t.world);for(let l=1;l<s.length;l++){const d=s[l],u=io(d,n,t.world);u<a&&(a=u,i=d)}return i}function io(e,t,n){const o=t[0]+e.x-n[0],r=t[1]+e.y-n[1];return o*o+r*r}function p0(e,t,n){const o=qe[e],r=x.getState(),s=r.diagram;if(!o)return null;const i=cm(t,n);if(!i)return null;const a=n[0]-i.world[0],l=n[1]-i.world[1],d=a*a+l*l<=d0,u=[oe(n[0]),oe(n[1])],f=dm(o,i,u),m=d?i.world:u,g=[oe(m[0]-f.x),oe(m[1]-f.y)],p=ht(s,e);return r.dispatch(h=>{const y={id:p,kind:e},w={at:g},v=`${p}.${f.id}`,N=i.isBus&&i.busId?i.busId:t,I={id:gt(N,v),ends:[N,v]};return{...h,elements:[...h.elements,y],wires:[...h.wires??[],I],layout:{...h.layout??{},[p]:w}}}),r.setSelection([p]),{newElementId:p,attachedToBus:i.isBus}}const h0=9;function g0(){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??b0(r.libraryDef),a=v0(i,s,r.libraryDef),l=i.anchor??"start";if(o===r.element.id)return c.jsx(x0,{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=y0(r,n);return d.length===0?null:c.jsx("g",{className:"ole-annotation",transform:`translate(${a[0]} ${a[1]})`,children:d.map((f,m)=>c.jsx("text",{x:0,y:m*h0,textAnchor:l,className:"ole-annotation-text",children:f},m))},r.element.id)})})}const qt=200,Kt=9;function x0({elementId:e,currentName:t,world:n,anchor:o}){const r=_.useRef(null);_.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 m;const l=x.getState(),d=l.diagram.elements.find(g=>g.id===e);if(!d){l.setEditingElement(null);return}const u=(((m=r.current)==null?void 0:m.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]-Kt,width:qt,height:Kt*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:`${Kt}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})})}function y0(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 b0(e){const t=w0(e.viewBox);return t?{x:t.x+t.w+2,y:t.y+4,anchor:"start"}:{x:0,y:0,anchor:"start"}}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 v0(e,t,n){let o=e.x,r=e.y;switch(t.mirror&&(o=-o),t.rot){case 90:[o,r]=[-r,o];break;case 180:[o,r]=[-o,-r];break;case 270:[o,r]=[r,-o];break}return[o+t.at[0],r+t.at[1]]}const um=8,Mt=1.25;function k0(){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(S0,{ann:o},o.id):c.jsx(_0,{ann:o,isSelected:t===o.id},o.id))})}function _0({ann:e,isSelected:t}){const n=e.fontSize??um,o=e.text===""?[""]:e.text.split(`
|
|
187
|
-
`),r=Math.max(20,...o.map(i=>i.length*n*.55)),s=o.length*n*Mt;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*Mt,fontSize:n,className:"ole-free-annotation-text",children:i},a))]})}function S0({ann:e}){const t=_.useRef(null),n=e.fontSize??um;_.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:Mt,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*Mt}px`,whiteSpace:"pre-wrap",wordBreak:"break-word",cursor:"text"},children:e.text})})}const j0=20;function $0(){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(ao,{x:l[0],y:l[1],busId:n,side:"start",axis:r}),c.jsx(ao,{x:d[0],y:d[1],busId:n,side:"end",axis:r})]})}function ao({x:e,y:t,busId:n,side:o,axis:r}){const s=bt(),i=_.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 m=s.screenToSvg(u.clientX,u.clientY),g=r==="x"?m[0]-f.startSvg[0]:m[1]-f.startSvg[1],p=im()?Math.round(g/At)*At:g,h=f.startSpan+(o==="end"?p:-p);if(h<j0)return;const y=r==="x"?[f.startAt[0]+p/2,f.startAt[1]]:[f.startAt[0],f.startAt[1]+p/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 E0=3,Yt=12;function N0(){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,m=f/2,g=d==="x"?u[0]-m:u[0],p=d==="x"?u[1]:u[1]-m,h=d==="x"?u[0]+m:u[0],y=d==="x"?u[1]:u[1]+m,w=s.has(a.id),v=i.has(a.id),N=r.get(a.id)??void 0,I=Yt/2,L=d==="x"?u[0]-m:u[0]-I,W=d==="x"?u[1]-I:u[1]-m,le=d==="x"?f:Yt,se=d==="x"?Yt:f;return c.jsxs("g",{"data-bus-id":a.id,"data-element-id":a.id,"data-node-id":N,"data-selected":w?"true":void 0,"data-node-related":v?"true":void 0,className:"ole-bus",children:[c.jsx("rect",{x:L,y:W,width:le,height:se,fill:"transparent",className:"ole-bus-hit"}),c.jsx("line",{x1:g,y1:p,x2:h,y2:y,stroke:"currentColor",strokeWidth:E0,strokeLinecap:"round",fill:"none"})]},a.id)})})}function T0(){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 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({lib:e}){const t=C0(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 A0(){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(I0,{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 fm=null;const cn=new Set;function $t(e){fm=e;for(const t of cn)t(e)}function M0(){return fm}function P0(e){return cn.add(e),()=>{cn.delete(e)}}function O0(){const[e,t]=_.useState(M0());return _.useEffect(()=>P0(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 L0(){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=om(t);if(!r)return null;let s=null,i=null;if(o){const d=cm(o,n);d&&(s=dm(r,d,n),i={source:d.world,pin:n})}else s=lm(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 B0(){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,m=f/2,g=d==="x"?u[0]-m:u[0]-4,p=d==="x"?u[1]-4:u[1]-m,h=d==="x"?f:8,y=d==="x"?8:f;return c.jsx("rect",{x:g,y:p,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=D0(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 D0(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 R0(){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 z0(){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(m=>`${m[0]},${m[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 dn=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 dn)t(e)}}function F0(){return Xe}function H0(e){return dn.add(e),()=>{dn.delete(e)}}function W0(){var d,u;const e=x(f=>f.wireFromTerminal),t=x(f=>f.cursorSvg),n=x(f=>f.internal.terminals),[o,r]=_.useState(F0());_.useEffect(()=>H0(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 nt(e,t){return e instanceof Element?e.closest(`[${t}]`):null}function et(e){var t;return((t=nt(e,"data-element-id"))==null?void 0:t.getAttribute("data-element-id"))??null}function G0(e){var t;return((t=nt(e,"data-bus-id"))==null?void 0:t.getAttribute("data-bus-id"))??null}function We(e){var o;const t=(o=nt(e,"data-terminal-id"))==null?void 0:o.getAttribute("data-terminal-id");if(t)return t;const n=G0(e);return n||null}function Bt(e){var t;return((t=nt(e,"data-node-id"))==null?void 0:t.getAttribute("data-node-id"))??null}function q0(e){var t;return((t=nt(e,"data-wire-id"))==null?void 0:t.getAttribute("data-wire-id"))??null}function Pt(e){var t;return((t=nt(e,"data-annotation-id"))==null?void 0:t.getAttribute("data-annotation-id"))??null}function mm(e,t){try{e.dispatchEvent(new PointerEvent("pointercancel",{pointerId:t,bubbles:!0,cancelable:!0,pointerType:"touch"}))}catch{}}function K0(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable}function pm(){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 Y0(){_.useEffect(()=>{const e=t=>{if(K0(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":pm();return}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[])}let un=null;const fn=new Set;function X0(e){if(e!==un){un=e;for(const t of fn)t(e)}}function V0(){return un}function U0(e){return fn.add(e),()=>{fn.delete(e)}}const lo="ole-hover-element-host",Z0="ole-hover-terminal-on",J0="ole-hover-node-on";function Q0(e){_.useEffect(()=>{const t=e.current;if(!t)return;let n=null,o=null;const r=new Set,s=new Set,i=(f,m,g)=>{for(const p of f)p.classList.remove(g);f.clear();for(const p of m)p.classList.add(g),f.add(p)},a=f=>{var g,p;if(f===n)return;n&&((g=t.querySelector(`[data-element-id="${Et(n)}"]`))==null||g.classList.remove(lo)),f&&((p=t.querySelector(`[data-element-id="${Et(f)}"]`))==null||p.classList.add(lo));const m=f?Array.from(t.querySelectorAll(`.ole-terminal[data-element-id="${Et(f)}"]`)):[];i(r,m,Z0),n=f,f?t.setAttribute("data-hover-element",""):t.removeAttribute("data-hover-element"),X0(f)},l=f=>{if(f===o)return;const m=f?Array.from(t.querySelectorAll(`[data-node-id="${Et(f)}"]`)):[];i(s,m,J0),o=f,f?t.setAttribute("data-hover-node",""):t.removeAttribute("data-hover-node")},d=f=>{a(et(f.target));const m=We(f.target);let g=null;m?g=x.getState().internal.terminalToNode.get(m)??null:g=Bt(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 Et(e){return e.replace(/(["\\])/g,"\\$1")}function hm(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,m=i[0]+a/2,g=Math.max(f,Math.min(m,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 co=3;let ne=null,ke=null,Se=null,re=null;const ex={id:"select",cursor:"default",onPointerDown(e,t){var m,g,p,h;if(e.button!==0||e.target instanceof Element&&e.target.closest(".ole-bus-handle"))return;const n=x.getState(),o=Pt(e.target);if(o){e.preventDefault(),e.stopPropagation();const y=(m=n.diagram.annotations)==null?void 0:m.find(w=>w.id===o);if(!y)return;n.setSelectedAnnotation(o),re={pointerId:e.pointerId,id:o,startSvg:t.viewport.screenToSvg(e.clientX,e.clientY),origin:[y.at[0],y.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)?We(e.target):null;if(s){const y=s.indexOf("."),w=y>0?s.slice(0,y):"";if(w&&n.selection.includes(w)){e.preventDefault(),e.stopPropagation(),e.target instanceof Element&&((h=(p=e.target).hasPointerCapture)!=null&&h.call(p,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)),Se={pointerId:e.pointerId,fromRef:s};return}}const i=et(e.target);if(!i){const y=q0(e.target);if(y){if(e.preventDefault(),e.altKey){const w=Bt(e.target);if(w){n.setSelectedNode(w);return}}n.setSelectedWire(y);return}e.shiftKey||n.clearSelection(),ke={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 y of l){const w=d.buses.get(y);if(w){f.set(y,[w.geometry.at[0],w.geometry.at[1]]);continue}const v=d.layout.get(y);v&&u.set(y,{...v})}u.size===0&&f.size===0||(ne={pointerId:e.pointerId,startSvg:t.viewport.screenToSvg(e.clientX,e.clientY),originals:u,busOriginals:f,moved:!1},e.preventDefault())},onPointerMove(e,t){if(re&&e.pointerId===re.pointerId){const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=oe(n[0]-re.startSvg[0]),r=oe(n[1]-re.startSvg[1]);!re.moved&&(o!==0||r!==0)&&(re.moved=!0,t.hostEl.hasPointerCapture(e.pointerId)||t.hostEl.setPointerCapture(e.pointerId));const s=t.hostEl.querySelector(`[data-annotation-id="${Fe(re.id)}"]`);s&&s.setAttribute("transform",`translate(${o} ${r})`);return}if(Se&&e.pointerId===Se.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===Se.fromRef){Me(null);return}Me(hm(r,n));return}if(ne&&e.pointerId===ne.pointerId){const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=oe(n[0]-ne.startSvg[0]),r=oe(n[1]-ne.startSvg[1]);!ne.moved&&(o!==0||r!==0)&&(ne.moved=!0,t.hostEl.hasPointerCapture(e.pointerId)||t.hostEl.setPointerCapture(e.pointerId));for(const[s,i]of ne.originals){const a=t.hostEl.querySelector(`[data-element-id="${Fe(s)}"]`);if(!a)continue;const l={...i,at:[i.at[0]+o,i.at[1]+r]};a.setAttribute("transform",Ge(l))}for(const s of ne.busOriginals.keys()){const i=t.hostEl.querySelector(`[data-element-id="${Fe(s)}"]`);i&&i.setAttribute("transform",`translate(${o} ${r})`)}return}if(ke&&e.pointerId===ke.pointerId){const n=t.viewport.screenToSvg(e.clientX,e.clientY);$t(uo(ke.startSvg,n));return}},onPointerUp(e,t){if(re&&e.pointerId===re.pointerId){t.hostEl.hasPointerCapture(e.pointerId)&&t.hostEl.releasePointerCapture(e.pointerId);const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=oe(n[0]-re.startSvg[0]),r=oe(n[1]-re.startSvg[1]),s=t.hostEl.querySelector(`[data-annotation-id="${Fe(re.id)}"]`);s&&s.removeAttribute("transform"),re.moved&&(o!==0||r!==0)&&x.getState().updateAnnotation(re.id,{at:[re.origin[0]+o,re.origin[1]+r]}),re=null;return}if(Se&&e.pointerId===Se.pointerId){const n=x.getState(),o=Se.fromRef;Se=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(ne&&e.pointerId===ne.pointerId){if(t.hostEl.hasPointerCapture(e.pointerId)&&t.hostEl.releasePointerCapture(e.pointerId),ne.moved){const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=oe(n[0]-ne.startSvg[0]),r=oe(n[1]-ne.startSvg[1]);if(o!==0||r!==0){const s=new Map;for(const i of ne.originals.keys())s.set(i,[o,r]);for(const i of ne.busOriginals.keys())s.set(i,[o,r]);x.getState().moveElements(s)}for(const s of ne.busOriginals.keys()){const i=t.hostEl.querySelector(`[data-element-id="${Fe(s)}"]`);i&&i.removeAttribute("transform")}}ne=null;return}if(ke&&e.pointerId===ke.pointerId){t.hostEl.hasPointerCapture(e.pointerId)&&t.hostEl.releasePointerCapture(e.pointerId);const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=uo(ke.startSvg,n);if(o.w>=co||o.h>=co){const r=tx(o);if(ke.shiftKey){const s=new Set(ke.baseSelection);for(const i of r)s.has(i)?s.delete(i):s.add(i);x.getState().setSelection([...s])}else x.getState().setSelection(r)}$t(null),ke=null}},onPointerCancel(e,t){var n,o,r,s,i,a;if(re&&e.pointerId===re.pointerId){const l=t.hostEl.querySelector(`[data-annotation-id="${Fe(re.id)}"]`);if(l&&l.removeAttribute("transform"),(o=(n=t.hostEl).hasPointerCapture)!=null&&o.call(n,e.pointerId))try{t.hostEl.releasePointerCapture(e.pointerId)}catch{}re=null}if(ne&&e.pointerId===ne.pointerId){for(const[l,d]of ne.originals){const u=t.hostEl.querySelector(`[data-element-id="${Fe(l)}"]`);u&&u.setAttribute("transform",Ge(d))}for(const l of ne.busOriginals.keys()){const d=t.hostEl.querySelector(`[data-element-id="${Fe(l)}"]`);d&&d.removeAttribute("transform")}if((s=(r=t.hostEl).hasPointerCapture)!=null&&s.call(r,e.pointerId))try{t.hostEl.releasePointerCapture(e.pointerId)}catch{}ne=null}if(Se&&e.pointerId===Se.pointerId){t.hostEl.classList.remove("tool-wire");const l=x.getState();l.setWireFromTerminal(null),l.setCursorSvg(null),Me(null),Se=null}if(ke&&e.pointerId===ke.pointerId){if((a=(i=t.hostEl).hasPointerCapture)!=null&&a.call(i,e.pointerId))try{t.hostEl.releasePointerCapture(e.pointerId)}catch{}$t(null),ke=null}},onDoubleClick(e){const t=x.getState(),n=Pt(e.target);if(n){e.preventDefault(),e.stopPropagation(),t.setEditingAnnotation(n);return}const o=et(e.target);o&&(e.preventDefault(),e.stopPropagation(),t.setEditingElement(o))},onDeactivate(e){if(ne=null,ke=null,re=null,Se){e.hostEl.classList.remove("tool-wire");const t=x.getState();t.setWireFromTerminal(null),t.setCursorSvg(null),Me(null),Se=null}$t(null)}};function uo(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 tx(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=ox(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,m])=>nx([f,m],r));let a=1/0,l=-1/0,d=1/0,u=-1/0;for(const[f,m]of i)f<a&&(a=f),f>l&&(l=f),m<d&&(d=m),m>u&&(u=m);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,m=s==="x"?i[1]:i[1]+l;u>=e.x&&d<=e.x+e.w&&m>=e.y&&f<=e.y+e.h&&n.push(o.id)}return n}function nx(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 ox(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 Fe(e){return e.replace(/(["\\])/g,"\\$1")}const rx=4;let X=null;const sx={id:"pan",cursor:"grab",onPointerDown(e,t){if(e.button!==0)return;const n=t.viewport.getViewport(),o=et(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 m=a.layout.get(u);m&&l.set(u,{...m})}(l.size>0||d.size>0)&&(r={startSvg:t.viewport.screenToSvg(e.clientX,e.clientY),originals:l,busOriginals:d})}X={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(!X||e.pointerId!==X.pointerId)return;const n=e.clientX-X.startX,o=e.clientY-X.startY;if(!X.moved&&Math.hypot(n,o)>rx){X.moved=!0;try{t.hostEl.setPointerCapture(e.pointerId)}catch{}}if(X.moved){if(X.elementDrag){const r=t.viewport.screenToSvg(e.clientX,e.clientY),s=oe(r[0]-X.elementDrag.startSvg[0]),i=oe(r[1]-X.elementDrag.startSvg[1]);for(const[a,l]of X.elementDrag.originals){const d=t.hostEl.querySelector(`[data-element-id="${ct(a)}"]`);if(!d)continue;const u={...l,at:[l.at[0]+s,l.at[1]+i]};d.setAttribute("transform",Ge(u))}for(const a of X.elementDrag.busOriginals.keys()){const l=t.hostEl.querySelector(`[data-element-id="${ct(a)}"]`);l&&l.setAttribute("transform",`translate(${s} ${i})`)}return}t.viewport.setViewport({tx:X.startTx+n,ty:X.startTy+o})}},onPointerUp(e,t){if(!(!X||e.pointerId!==X.pointerId)){if(t.hostEl.hasPointerCapture(e.pointerId)&&t.hostEl.releasePointerCapture(e.pointerId),t.hostEl.style.cursor="grab",X.elementDrag&&X.moved){const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=oe(n[0]-X.elementDrag.startSvg[0]),r=oe(n[1]-X.elementDrag.startSvg[1]);if(o!==0||r!==0){const s=new Map;for(const i of X.elementDrag.originals.keys())s.set(i,[o,r]);for(const i of X.elementDrag.busOriginals.keys())s.set(i,[o,r]);x.getState().moveElements(s)}for(const s of X.elementDrag.busOriginals.keys()){const i=t.hostEl.querySelector(`[data-element-id="${ct(s)}"]`);i&&i.removeAttribute("transform")}}else X.moved||ix(X.startTarget);X=null}},onPointerCancel(e,t){if(X!=null&&X.elementDrag){for(const[n,o]of X.elementDrag.originals){const r=t.hostEl.querySelector(`[data-element-id="${ct(n)}"]`);r&&r.setAttribute("transform",Ge(o))}for(const n of X.elementDrag.busOriginals.keys()){const o=t.hostEl.querySelector(`[data-element-id="${ct(n)}"]`);o&&o.removeAttribute("transform")}}X=null},onDeactivate(){X=null}};function ix(e){if(!e)return;const t=x.getState(),n=Pt(e);if(n){t.setSelectedAnnotation(n);return}const o=et(e);if(o){t.setSelection([o]);return}const r=Bt(e);if(r){t.setSelectedNode(r);return}t.clearSelection()}function ct(e){return e.replace(/(["\\])/g,"\\$1")}const ut={tight:1024,compact:720,dense:520,mini:380},fo={full:0,tight:1,compact:2,dense:3,mini:4};function Ne(e,t){return fo[e]>=fo[t]}function ax(e){return e>=ut.tight?"full":e>=ut.compact?"tight":e>=ut.dense?"compact":e>=ut.mini?"dense":"mini"}const gm=_.createContext("full");function Ke(){return _.useContext(gm)}function lx(e){const[t,n]=_.useState(null);return _.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 xm(){if(typeof window>"u")return!1;try{if(!window.matchMedia("(pointer: coarse)").matches)return!1}catch{return!1}return window.innerWidth<ut.dense}function kn(){xm()&&x.getState().setActiveTool("pan")}function cx(){xm()&&x.getState().setPlaceKind(null)}const dx={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(hm(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),kn())},onPointerLeave(){const e=x.getState();e.setWireFromTerminal(null),e.setCursorSvg(null),Me(null)}},mo=10;let dt=!1;function po(){setTimeout(()=>cx(),0)}const ux={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),dt=!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);am(n,r),dt=!0},onPointerMove(e,t){const n=t.viewport.screenToSvg(e.clientX,e.clientY);x.getState().setCursorSvg([ho(n[0]),ho(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);p0(r,o,s),po();return}dt&&(dt=!1,po())},onPointerLeave(){const e=x.getState();e.setPlaceFromTerminal(null),e.setCursorSvg(null)},onPointerCancel(){const e=x.getState();e.setPlaceFromTerminal(null),e.setCursorSvg(null),dt=!1}};function ho(e){return Math.round(e/mo)*mo}const go=10,xo=20;function Ue(e){return Math.round(e/go)*go}const fx={id:"busbar",cursor:"crosshair",onPointerDown(e,t){if(e.button!==0)return;e.preventDefault();const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=[Ue(n[0]),Ue(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([Ue(n[0]),Ue(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=Ue(o[0]),s=Ue(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<xo)return;d=0,f=[(n[0]+r)/2,n[1]]}else{if(u=Math.abs(a),u<xo)return;d=90,f=[n[0],(n[1]+s)/2]}x.getState().addBus(f,u,d),kn()},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)}},mx={id:"text",cursor:"text",onPointerDown(e,t){if(e.button!==0)return;const n=x.getState(),o=Pt(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),kn()}},px={select:ex,pan:sx,wire:dx,place:ux,busbar:fx,text:mx};function hx(e,t){const n=x(o=>o.activeTool);_.useEffect(()=>{var m;const o=e.current;if(!o)return;const r=px[n],s={viewport:t,hostEl:o};(m=r.onActivate)==null||m.call(r,s),r.cursor&&(o.style.cursor=r.cursor);const i=g=>{var p;return(p=r.onPointerDown)==null?void 0:p.call(r,g,s)},a=g=>{var p;return(p=r.onPointerMove)==null?void 0:p.call(r,g,s)},l=g=>{var p;return(p=r.onPointerUp)==null?void 0:p.call(r,g,s)},d=g=>{var p;return r.onPointerCancel?r.onPointerCancel(g,s):(p=r.onPointerUp)==null?void 0:p.call(r,g,s)},u=g=>{var p;return(p=r.onPointerLeave)==null?void 0:p.call(r,g,s)},f=g=>{var p;return(p=r.onDoubleClick)==null?void 0:p.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 mn=1;const pn=new Set;function gx(e){if(e!==mn){mn=e;for(const t of pn)t(e)}}function xx(){return mn}function yx(e){return pn.add(e),()=>{pn.delete(e)}}const Xt=.1,Vt=8,bx=1.0015,wx=1.02;function vx(e,t,n={tx:0,ty:0,scale:1}){const o=_.useRef({...n}),r=_.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)),gx(o.current.scale),r.current.size>0){const l={...o.current};for(const d of r.current)d(l)}};return _.useEffect(()=>{const i=e.current;if(!i)return;let a=!1,l=-1,d=0,u=0,f=0,m=0,g=!1;const p=new Map;let h=null,y=!1;const w=()=>{if(p.size<2){h=null;return}const $=[...p.values()],T=$[1].x-$[0].x,J=$[1].y-$[0].y,ee=Math.hypot(T,J)||1,ae=i.getBoundingClientRect();h={startDist:ee,startScale:o.current.scale,startTx:o.current.tx,startTy:o.current.ty,startMidX:($[0].x+$[1].x)/2-ae.left,startMidY:($[0].y+$[1].y)/2-ae.top}},v=$=>{if($.pointerType==="touch"){if(p.set($.pointerId,{x:$.clientX,y:$.clientY}),p.size>=2&&!y){y=!0;for(const T of p.keys())T!==$.pointerId&&mm(i,T);w()}if(y){$.stopPropagation(),$.preventDefault();try{i.setPointerCapture($.pointerId)}catch{}}}},N=$=>{if($.pointerType!=="touch"||!p.has($.pointerId)||(p.set($.pointerId,{x:$.clientX,y:$.clientY}),!y||!h))return;$.stopPropagation();const T=[...p.values()];if(T.length<2)return;const J=T[1].x-T[0].x,ee=T[1].y-T[0].y,ae=Math.hypot(J,ee)||1,be=i.getBoundingClientRect(),Ie=(T[0].x+T[1].x)/2-be.left,de=(T[0].y+T[1].y)/2-be.top,_e=ae/h.startDist,we=Ut(h.startScale*_e,Xt,Vt),ge=we/h.startScale;o.current.tx=h.startMidX-(h.startMidX-h.startTx)*ge+(Ie-h.startMidX),o.current.ty=h.startMidY-(h.startMidY-h.startTy)*ge+(de-h.startMidY),o.current.scale=we,s()},I=$=>{var T;if($.pointerType==="touch"&&p.has($.pointerId)&&(p.delete($.pointerId),y)){if($.stopPropagation(),(T=i.hasPointerCapture)!=null&&T.call(i,$.pointerId))try{i.releasePointerCapture($.pointerId)}catch{}p.size>=2?w():h=null,p.size===0&&(y=!1)}},L=$=>{$.preventDefault();const T=i.getBoundingClientRect(),J=$.clientX-T.left,ee=$.clientY-T.top,ae=$.ctrlKey||$.metaKey;if($.deltaX===0||ae){const de=Math.pow(ae?wx:bx,-$.deltaY),_e=Ut(o.current.scale*de,Xt,Vt),we=_e/o.current.scale;o.current.tx=J-(J-o.current.tx)*we,o.current.ty=ee-(ee-o.current.ty)*we,o.current.scale=_e}else o.current.tx-=$.deltaX,o.current.ty-=$.deltaY;s()},W=$=>{const T=$.button===1,J=g&&$.button===0;!T&&!J||($.preventDefault(),a=!0,l=$.pointerId,d=$.clientX,u=$.clientY,f=o.current.tx,m=o.current.ty,i.setPointerCapture($.pointerId),i.style.cursor="grabbing")},le=$=>{!a||$.pointerId!==l||(o.current.tx=f+($.clientX-d),o.current.ty=m+($.clientY-u),s())},se=$=>{a&&$.pointerId===l&&(a=!1,i.releasePointerCapture($.pointerId),i.style.cursor=g?"grab":"")},he=$=>{if($.code==="Space"&&!g){const T=$.target;if(T&&(T.tagName==="INPUT"||T.tagName==="TEXTAREA"||T.isContentEditable))return;g=!0,i.style.cursor="grab",$.preventDefault()}},ue=$=>{$.code==="Space"&&(g=!1,a||(i.style.cursor=""))};return i.addEventListener("wheel",L,{passive:!1}),i.addEventListener("pointerdown",W),i.addEventListener("pointermove",le),i.addEventListener("pointerup",se),i.addEventListener("pointercancel",se),i.addEventListener("pointerdown",v,{capture:!0}),i.addEventListener("pointermove",N,{capture:!0}),i.addEventListener("pointerup",I,{capture:!0}),i.addEventListener("pointercancel",I,{capture:!0}),window.addEventListener("keydown",he),window.addEventListener("keyup",ue),s(),()=>{i.removeEventListener("wheel",L),i.removeEventListener("pointerdown",W),i.removeEventListener("pointermove",le),i.removeEventListener("pointerup",se),i.removeEventListener("pointercancel",se),i.removeEventListener("pointerdown",v,{capture:!0}),i.removeEventListener("pointermove",N,{capture:!0}),i.removeEventListener("pointerup",I,{capture:!0}),i.removeEventListener("pointercancel",I,{capture:!0}),window.removeEventListener("keydown",he),window.removeEventListener("keyup",ue)}},[]),{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=Ut(i.scale,Xt,Vt)),s()},subscribe(i){return r.current.add(i),()=>{r.current.delete(i)}}}}function Ut(e,t,n){return e<t?t:e>n?n:e}const ym=typeof navigator<"u"&&/Mac|iP(ad|hone|od)/.test(navigator.platform),Ze=ym?"⌘":"Ctrl+",kx=ym?"⇧":"Shift+",Zt=[10,20,50,100,200,500,1e3,2e3,5e3,1e4],_x=18;function Sx(e){for(const t of Zt)if(t*e>=_x)return t;return Zt[Zt.length-1]}function jx(){const e=U(),t=_.useRef(null),n=_.useRef(null),o=_.useRef(null),r=vx(t,n);hx(t,r),Q0(t),_.useEffect(()=>(so(r),()=>so(null)),[r]),_.useEffect(()=>{const u=f=>{const m=o.current;if(!m)return;const p=Sx(f.scale)*f.scale;m.setAttribute("width",String(p)),m.setAttribute("height",String(p)),m.setAttribute("patternTransform",`translate(${f.tx} ${f.ty})`)};return u(r.getViewport()),r.subscribe(u)},[r]);const s=Up(),i=_.useCallback((u,f,m)=>{const g=x.getState(),p=g.activeTool;if(p==="wire"||p==="busbar"||p==="place"){pm();return}const h=et(m);if(h)g.selection.includes(h)||g.setSelection([h]);else{const W=Bt(m);W&&g.selectedNode!==W&&g.setSelectedNode(W)}const y=x.getState(),w=y.selection.length>0,v=y.selectedNode!=null,N=!!y.clipboard,I=y.diagram.elements.length>0,L=[{label:e("menu.undo"),shortcut:`${Ze}Z`,icon:bn,onSelect:()=>x.getState().undo(),disabled:y.past.length===0},{label:e("menu.redo"),shortcut:`${Ze}${kx}Z`,icon:yn,onSelect:()=>x.getState().redo(),disabled:y.future.length===0},{type:"separator"},{label:e("menu.cut"),shortcut:`${Ze}X`,icon:Ko,onSelect:()=>x.getState().cutSelection(),disabled:!w},{label:e("menu.copy"),shortcut:`${Ze}C`,icon:Ho,onSelect:()=>x.getState().copySelection(),disabled:!w},{label:e("menu.paste"),shortcut:`${Ze}V`,icon:Fo,onSelect:()=>x.getState().pasteClipboard(),disabled:!N},{type:"separator"},{label:e("menu.rotate"),shortcut:"R",icon:qo,onSelect:()=>x.getState().rotateSelection(90),disabled:!w},{label:e("menu.mirror"),shortcut:"M",icon:Wo,onSelect:()=>x.getState().mirrorSelection(),disabled:!w},{type:"separator"},{label:e("menu.selectAll"),shortcut:`${Ze}A`,icon:xp,onSelect:()=>{const W=x.getState();W.setSelection(W.diagram.elements.map(le=>le.id))},disabled:!I},{type:"separator"},{label:e(v&&!w?"menu.disconnect":"menu.delete"),shortcut:"Del",icon:Xo,destructive:!0,onSelect:()=>v&&!w?x.getState().deleteSelectedNode():x.getState().deleteSelection(),disabled:!w&&!v}];s.open(u,f,L)},[s,e]);_.useEffect(()=>{const u=t.current;if(!u)return;const f=700,m=4;let g,p=null;const h=()=>{g!==void 0&&window.clearTimeout(g),g=void 0,p=null},y=N=>{N.pointerType==="touch"&&(h(),p={pointerId:N.pointerId,x:N.clientX,y:N.clientY,target:N.target},g=window.setTimeout(()=>{const I=p;p=null,g=void 0,I&&(mm(u,I.pointerId),i(I.x,I.y,I.target))},f))},w=N=>{if(!p||N.pointerId!==p.pointerId)return;const I=N.clientX-p.x,L=N.clientY-p.y;Math.hypot(I,L)>m&&h()},v=N=>{!p||N.pointerId!==p.pointerId||h()};return u.addEventListener("pointerdown",y),u.addEventListener("pointermove",w),u.addEventListener("pointerup",v),u.addEventListener("pointercancel",v),()=>{h(),u.removeEventListener("pointerdown",y),u.removeEventListener("pointermove",w),u.removeEventListener("pointerup",v),u.removeEventListener("pointercancel",v)}},[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 m=r.screenToSvg(u.clientX,u.clientY);am(f,m)},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(N0,{}),c.jsx(z0,{}),c.jsx(A0,{}),c.jsx(g0,{}),c.jsx(k0,{}),c.jsx(B0,{}),c.jsx($0,{}),c.jsx(R0,{}),c.jsx(W0,{}),c.jsx(T0,{}),c.jsx(L0,{}),c.jsx(O0,{})]})]})})}const yo=60,$x=.1,Ex=8,Nx=8;function Tx(e,t,n){return e<t?t:e>n?n:e}function Cx(){return document.querySelector(".ole-canvas-root")}function _n(){const e=bt(),t=Cx();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 w of o){const v=w.getBoundingClientRect();v.width===0&&v.height===0||(v.left<r&&(r=v.left),v.top<s&&(s=v.top),v.right>i&&(i=v.right),v.bottom>a&&(a=v.bottom))}if(r===1/0)return!1;const[l,d]=e.screenToSvg(r,s),[u,f]=e.screenToSvg(i,a),m=Math.max(u-l,1),g=Math.max(f-d,1),p=Tx(Math.min((n.width-yo*2)/m,(n.height-yo*2)/g),$x,Ex),h=(l+u)/2,y=(d+f)/2;return e.setViewport({tx:n.width/2-p*h,ty:n.height/2-p*y,scale:p}),!0}function Sn(){let e=Nx;const t=()=>{_n()||--e>0&&requestAnimationFrame(t)};requestAnimationFrame(t)}const bo=10,Ix=100;function Ax(){return typeof window>"u"||!window.matchMedia?!1:window.matchMedia("(hover: none), (pointer: coarse)").matches}function Mx(){const[e,t]=_.useState(V0()),[n,o]=_.useState(!1),[r,s]=_.useState(null),i=_.useRef(null),a=_.useRef(void 0),[l]=_.useState(Ax);_.useEffect(()=>U0(p=>t(p)),[]),_.useEffect(()=>{if(window.clearTimeout(a.current),o(!1),s(null),!!e)return a.current=window.setTimeout(()=>o(!0),Ix),()=>window.clearTimeout(a.current)},[e]);const d=x(p=>e?p.diagram.elements.find(h=>h.id===e)??null:null);if(_.useLayoutEffect(()=>{if(!n||!e)return;let p=0,h=-1,y=-1;const w=()=>{const v=document.querySelector(`[data-element-id="${Px(e)}"]`),N=i.current;if(v&&N){const I=v.getBoundingClientRect();let L=I.bottom+bo;L+N.offsetHeight>window.innerHeight-4&&(L=I.top-N.offsetHeight-bo);let W=I.left+I.width/2-N.offsetWidth/2;W=Math.max(4,Math.min(W,window.innerWidth-N.offsetWidth-4)),(L!==h||W!==y)&&(s({top:L,left:W}),h=L,y=W)}p=requestAnimationFrame(w)};return p=requestAnimationFrame(w),()=>cancelAnimationFrame(p)},[n,e]),l||!n||!e||!d)return null;const u=qe[d.kind],f=d.name??d.id,m=(u==null?void 0:u.name)??d.kind,g=d.name&&d.name!==d.id;return typeof document>"u"?null:Do.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:m})]}),document.body)}function Px(e){return e.replace(/(["\\])/g,"\\$1")}function Ox({width:e,children:t}){const n=e==null?"full":ax(e);return c.jsx(gm.Provider,{value:n,children:t})}function wo(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Lx(...e){return t=>{let n=!1;const o=e.map(r=>{const s=wo(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():wo(e[r],null)}}}}var Bx=Symbol.for("react.lazy"),Ot=pe[" use ".trim().toString()];function Dx(e){return typeof e=="object"&&e!==null&&"then"in e}function bm(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Bx&&"_payload"in e&&Dx(e._payload)}function Rx(e){const t=Fx(e),n=pe.forwardRef((o,r)=>{let{children:s,...i}=o;bm(s)&&typeof Ot=="function"&&(s=Ot(s._payload));const a=pe.Children.toArray(s),l=a.find(Wx);if(l){const d=l.props.children,u=a.map(f=>f===l?pe.Children.count(d)>1?pe.Children.only(null):pe.isValidElement(d)?d.props.children:null:f);return c.jsx(t,{...i,ref:r,children:pe.isValidElement(d)?pe.cloneElement(d,void 0,u):null})}return c.jsx(t,{...i,ref:r,children:s})});return n.displayName=`${e}.Slot`,n}var zx=Rx("Slot");function Fx(e){const t=pe.forwardRef((n,o)=>{let{children:r,...s}=n;if(bm(r)&&typeof Ot=="function"&&(r=Ot(r._payload)),pe.isValidElement(r)){const i=qx(r),a=Gx(s,r.props);return r.type!==pe.Fragment&&(a.ref=o?Lx(o,i):i),pe.cloneElement(r,a)}return pe.Children.count(r)>1?pe.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var Hx=Symbol("radix.slottable");function Wx(e){return pe.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===Hx}function Gx(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 qx(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 vo=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,ko=Zo,Kx=(e,t)=>n=>{var o;if((t==null?void 0:t.variants)==null)return ko(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 m=vo(u)||vo(f);return r[d][m]}),a=n&&Object.entries(n).reduce((d,u)=>{let[f,m]=u;return m===void 0||(d[f]=m),d},{}),l=t==null||(o=t.compoundVariants)===null||o===void 0?void 0:o.reduce((d,u)=>{let{class:f,className:m,...g}=u;return Object.entries(g).every(p=>{let[h,y]=p;return Array.isArray(y)?y.includes({...s,...a}[h]):{...s,...a}[h]===y})?[...d,f,m]:d},[]);return ko(e,i,l,n==null?void 0:n.class,n==null?void 0:n.className)},Yx=Kx("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"}}),Te=pe.forwardRef(({className:e,variant:t,size:n,asChild:o=!1,...r},s)=>{const i=o?zx:"button";return c.jsx(i,{className:ye(Yx({variant:t,size:n,className:e})),ref:s,...r})});Te.displayName="Button";const Xx=350;function Ce({content:e,children:t,disabled:n,delayMs:o=Xx}){const r=_.useRef(null),s=_.useRef(null),[i,a]=_.useState(!1),[l,d]=_.useState(null),u=_.useId(),f=_.useRef(void 0),m=()=>{n||(window.clearTimeout(f.current),f.current=window.setTimeout(()=>a(!0),o))},g=()=>{window.clearTimeout(f.current),a(!1)};_.useLayoutEffect(()=>{if(!i||!r.current||!s.current)return;const w=r.current.getBoundingClientRect(),v=s.current.getBoundingClientRect(),N=8;let I="top",L=w.top-v.height-N;L<4&&(I="bottom",L=w.bottom+N);let W=w.left+w.width/2-v.width/2;W=Math.max(4,Math.min(W,window.innerWidth-v.width-4)),d({top:L,left:W,side:I})},[i,e]),_.useEffect(()=>()=>window.clearTimeout(f.current),[]),_.useEffect(()=>{if(!i)return;const w=N=>{N.key==="Escape"&&a(!1)},v=()=>a(!1);return window.addEventListener("keydown",w),window.addEventListener("scroll",v,!0),window.addEventListener("resize",v),()=>{window.removeEventListener("keydown",w),window.removeEventListener("scroll",v,!0),window.removeEventListener("resize",v)}},[i]);const p=t,h=p.props,y=_.cloneElement(p,{ref:w=>{r.current=w;const v=p.ref;typeof v=="function"?v(w):v&&typeof v=="object"&&(v.current=w)},onPointerEnter:w=>{var v;(v=h.onPointerEnter)==null||v.call(h,w),m()},onPointerLeave:w=>{var v;(v=h.onPointerLeave)==null||v.call(h,w),g()},onFocus:w=>{var v;(v=h.onFocus)==null||v.call(h,w),m()},onBlur:w=>{var v;(v=h.onBlur)==null||v.call(h,w),g()},"aria-describedby":i?u:h["aria-describedby"]});return c.jsxs(c.Fragment,{children:[y,i&&typeof document<"u"&&Do.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 _o=12,Vx=56;function Ux(){const e=U(),t=x(p=>p.selection),n=x(p=>p.selectedNode),o=x(p=>p.selectedWire),r=x(p=>p.activeTool),s=x(p=>p.rotateSelection),i=x(p=>p.mirrorSelection),a=x(p=>p.deleteSelection),l=x(p=>p.deleteSelectedNode),d=x(p=>p.deleteSelectedWire),u=_.useRef(null);_.useEffect(()=>{const p=u.current;if(!p)return;const h=t.length>0,y=!h&&o!=null,w=!h&&!y&&n!=null;if(!((h||y||w)&&(r==="select"||r==="pan"))){p.style.display="none";return}p.style.display="flex";let N=0,I="";const L=()=>{let W=1/0,le=-1/0,se=1/0,he=-1/0,ue=!1;const $=T=>{T.width===0&&T.height===0||(T.left<W&&(W=T.left),T.right>le&&(le=T.right),T.top<se&&(se=T.top),T.bottom>he&&(he=T.bottom),ue=!0)};if(h)for(const T of t){const J=document.querySelector(`[data-element-id="${CSS.escape(T)}"]`);J&&$(J.getBoundingClientRect())}else if(y&&o){const T=document.querySelector(`polyline.ole-wire[data-wire-id="${CSS.escape(o)}"]`);T&&$(T.getBoundingClientRect())}else if(w&&n){const T=document.querySelectorAll(`polyline.ole-wire[data-node-id="${CSS.escape(n)}"]`);for(const J of T)$(J.getBoundingClientRect())}if(ue){const T=(W+le)/2;let J=se-_o,ee="-100%";J<Vx&&(J=he+_o,ee="0%");const ae=`translate3d(${T}px, ${J}px, 0) translate(-50%, ${ee})`;ae!==I&&(p.style.transform=ae,I=ae)}N=requestAnimationFrame(L)};return N=requestAnimationFrame(L),()=>cancelAnimationFrame(N)},[t,n,o,r]);const f=t.length===0&&o!=null,m=t.length===0&&!f&&n!=null,g=m||f;return c.jsxs("div",{ref:u,role:"toolbar","aria-label":e(f?"ctx.ariaWire":m?"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:[!g&&c.jsxs(c.Fragment,{children:[c.jsx(Ce,{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(Te,{variant:"ghost",size:"icon",className:"size-7",onClick:()=>s(90),"aria-label":e("ctx.rotate"),children:c.jsx(qo,{})})}),c.jsx(Ce,{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(Te,{variant:"ghost",size:"icon",className:"size-7",onClick:()=>i(),"aria-label":e("ctx.mirrorTitle"),children:c.jsx(Wo,{})})}),c.jsx("div",{"aria-hidden":!0,className:"mx-0.5 h-4 w-px bg-border"})]}),c.jsx(Ce,{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(f?"ctx.deleteHintWire":m?"ctx.deleteHintNode":"ctx.deleteHintElement")})]}),children:c.jsx(Te,{variant:"ghost",size:"icon",className:"size-7 text-destructive hover:text-destructive",onClick:()=>f?d():m?l():a(),"aria-label":e("ctx.delete"),children:c.jsx(Xo,{})})})]})}function jn({open:e,onOpenChange:t,trigger:n,children:o}){const r=_.useRef(null);return _.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 wm="ole-panel-open";function Zx(){if(typeof window>"u")return{outlineOpen:!1};try{const e=window.localStorage.getItem(wm);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 So(e){try{const t={outline:e.outlineOpen};window.localStorage.setItem(wm,JSON.stringify(t))}catch{}}const xt=Lt((e,t)=>({...Zx(),setOutlineOpen:n=>{e({outlineOpen:n}),So(t())},toggleOutline:()=>{e(n=>({outlineOpen:!n.outlineOpen})),So(t())}})),Ct=[.1,.25,.5,.75,1,1.25,1.5,2,3,4,6,8],vm=.1,km=8,_m="ole-grid";function Jx(){try{const e=window.localStorage.getItem(_m);return e==null?!0:e==="1"}catch{return!0}}function Qx(e){try{window.localStorage.setItem(_m,e?"1":"0")}catch{}}function ey(e,t,n){return e<t?t:e>n?n:e}function Sm(){return document.querySelector(".ole-canvas-root")}function $n(e){const t=bt(),n=Sm();if(!t||!n)return;const o=n.getBoundingClientRect(),r=o.width/2,s=o.height/2,i=t.getViewport(),a=ey(e,vm,km),l=a/i.scale;t.setViewport({tx:r-(r-i.tx)*l,ty:s-(s-i.ty)*l,scale:a})}function ty(){const e=bt();if(!e)return;const t=e.getViewport().scale,n=Ct.find(o=>o>t+1e-6)??km;$n(n)}function ny(){const e=bt();if(!e)return;const t=e.getViewport().scale;let n=vm;for(let o=Ct.length-1;o>=0;o--)if(Ct[o]<t-1e-6){n=Ct[o];break}$n(n)}const oy={off:"id",id:"all",all:"off"};function ry(){var o;const e=x.getState(),t=((o=e.diagram.meta)==null?void 0:o.labelMode)??"all",n=oy[t];e.dispatch(r=>{const s={...r.meta??{},labelMode:n};return{...r,meta:s}})}function jm(){const[e,t]=_.useState(()=>Jx());return _.useEffect(()=>{const n=Sm();n==null||n.classList.toggle("hide-grid",!e),Qx(e)},[e]),_.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 $m(){const e=U();return c.jsx(Ce,{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(Te,{variant:"ghost",size:"icon",onClick:ny,"aria-label":e("view.zoomOut"),children:c.jsx(xn,{})})})}function Em(){const e=U();return c.jsx(Ce,{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(Te,{variant:"ghost",size:"icon",onClick:ty,"aria-label":e("view.zoomIn"),children:c.jsx(hp,{})})})}function Nm(){const e=U(),[t,n]=_.useState(xx);return _.useEffect(()=>yx(n),[]),c.jsx(Ce,{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:()=>$n(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 Tm(){const e=U();return c.jsx(Ce,{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(Te,{variant:"ghost",size:"icon",onClick:_n,"aria-label":e("view.fit"),children:c.jsx(fp,{})})})}function Cm({grid:e,setGrid:t}){const n=U();return c.jsx(Ce,{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(Te,{variant:"ghost",size:"icon",onClick:()=>t(o=>!o),"aria-label":n(e?"view.gridHideAria":"view.gridShowAria"),"aria-pressed":e,className:ye(!e&&"text-muted-foreground/60"),children:c.jsx(dp,{})})})}function Im(){const e=U(),t=x(n=>{var o;return((o=n.diagram.meta)==null?void 0:o.labelMode)??"all"});return c.jsx(Ce,{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(Te,{variant:"ghost",size:"icon",onClick:ry,"aria-label":e("view.label"),"aria-pressed":t!=="off",className:ye(t==="off"&&"text-muted-foreground/60"),children:c.jsx(Vo,{})})})}function sy({stacked:e}={}){const t=U(),[n,o]=_.useState(!1),[r,s]=jm(),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(Ce,{content:i,children:c.jsxs("button",{type:"button",onClick:()=>o(l=>!l),"aria-label":t("view.menu"),"aria-pressed":n,className:ye("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(tn,{className:"size-4"}),c.jsx("span",{className:"max-w-full truncate",children:t("view.menu")})]})}):c.jsx(Ce,{content:i,children:c.jsx(Te,{variant:"ghost",size:"icon",onClick:()=>o(l=>!l),"aria-label":t("view.menu"),"aria-pressed":n,children:c.jsx(tn,{})})});return c.jsx(jn,{open:n,onOpenChange:o,trigger:a,children:c.jsxs("div",{className:"flex flex-col gap-0.5",children:[c.jsx(Nm,{}),c.jsxs("div",{className:"flex items-center gap-0.5",children:[c.jsx($m,{}),c.jsx(Em,{})]}),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(Tm,{}),c.jsx(Cm,{grid:r,setGrid:s}),c.jsx(Im,{})]})]})})}function iy(){const e=Ke();return Ne(e,"dense")?null:c.jsx(ay,{tier:e})}function ay({tier:e}){const t=Ne(e,"tight"),[n,o]=jm();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($m,{}),!t&&c.jsx(Nm,{}),c.jsx(Em,{}),c.jsx("div",{"aria-hidden":!0,className:"mx-1 h-4 w-px bg-border"}),c.jsx(Tm,{}),c.jsx(Cm,{grid:n,setGrid:o}),c.jsx(Im,{})]})})}const jo=[{id:"select",labelKey:"tool.select",hotkey:"V",descriptionKey:"tool.selectHint",icon:mp,switchTo:"select",iconOnly:!0},{id:"pan",labelKey:"tool.pan",hotkey:"H",descriptionKey:"tool.panHint",icon:up,switchTo:"pan",groupBreakAfter:!0,iconOnly:!0},{id:"busbar",labelKey:"tool.bus",hotkey:"B",descriptionKey:"tool.busHint",icon:xn,switchTo:"busbar"},{id:"place",labelKey:"tool.place",hotkey:"P",descriptionKey:"tool.placeHint",icon:Yo,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:Vo,switchTo:"text",iconOnly:!0}];function ly(){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 cy(){const e=U(),t=x(p=>p.activeTool),n=x(p=>p.placeKind),o=x(p=>p.setActiveTool),r=x(p=>p.past.length),s=x(p=>p.future.length),i=x(p=>p.undo),a=x(p=>p.redo),l=Ke(),d=Ne(l,"tight"),u=!Ne(l,"dense"),f=Ne(l,"dense"),m=f?jo.filter(p=>p.id!=="select"&&p.id!=="text"):jo,g=p=>t===p.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(ly,{}),c.jsxs("div",{className:ye("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(dy,{stacked:!0}),m.map(p=>{const h=p.icon,y=g(p),w=p.id==="place"&&y&&n==null?e("tool.placeNoKindTooltip"):e(p.descriptionKey);return c.jsxs(_.Fragment,{children:[c.jsx(Qe,{icon:h,label:e(p.labelKey),hotkey:p.hotkey,active:y,iconOnly:!f&&(p.iconOnly||d),stacked:f,description:w,onClick:()=>{o(p.switchTo,{placeKind:p.presetPlaceKind!==void 0?p.presetPlaceKind:void 0})}}),p.groupBreakAfter&&!f&&c.jsx("div",{"aria-hidden":!0,className:"mx-1 h-5 w-px bg-border"})]},p.id)}),!f&&c.jsx("div",{"aria-hidden":!0,className:"mx-1 h-5 w-px bg-border"}),f?c.jsx(fy,{stacked:!0}):c.jsxs(c.Fragment,{children:[c.jsx(Qe,{icon:bn,label:e("tool.undo"),hotkey:"⌘Z",description:e("tool.undoHint"),iconOnly:!0,disabled:r===0,onClick:i}),c.jsx(Qe,{icon:yn,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(uy,{iconOnly:d})]}),f&&c.jsx(sy,{stacked:!0})]})]})}function dy({stacked:e}){const t=U(),n=xt(r=>r.outlineOpen),o=xt(r=>r.toggleOutline);return c.jsx(Qe,{icon:Go,label:t("outline.title"),active:n,iconOnly:!0,stacked:e,onClick:o})}function Qe({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(Ce,{content:d,disabled:r,children:c.jsxs("button",{type:"button",onClick:a,disabled:r,"aria-label":t,"aria-pressed":o,className:ye("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:ye("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 Am(){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 uy({iconOnly:e}){const t=U(),[n,o]=_.useState(!1),r=Am(),s=i=>()=>{o(!1),i()};return c.jsxs(jn,{open:n,onOpenChange:o,trigger:c.jsx(Qe,{icon:ft,label:t("layout.label"),description:t("layout.hint"),active:n,iconOnly:e,onClick:()=>o(i=>!i)}),children:[c.jsx(je,{onClick:s(()=>x.getState().autoArrangeAll()),icon:c.jsx(ft,{}),disabled:!r.hasAnyElement||!r.hasArrangedAny,children:t("layout.allAuto")}),c.jsx(je,{onClick:s(()=>x.getState().autoArrangeSelection()),icon:c.jsx(ft,{}),disabled:!r.hasSelection||!r.selectionHasArranged,children:t("layout.selAuto")}),c.jsx("div",{"aria-hidden":!0,className:"my-1 h-px bg-border"}),c.jsx(je,{onClick:s(()=>x.getState().fillUnplacedAll()),icon:c.jsx(It,{}),disabled:!r.hasGapsAll,children:t("layout.allFill")}),c.jsx(je,{onClick:s(()=>x.getState().fillUnplacedSelection()),icon:c.jsx(It,{}),disabled:!r.hasSelection||!r.selectionHasGaps,children:t("layout.selFill")})]})}function fy({stacked:e}){const t=U(),[n,o]=_.useState(!1),r=x(m=>m.past.length),s=x(m=>m.future.length),i=x(m=>m.undo),a=x(m=>m.redo),l=x(m=>m.selection.length>0),d=x(m=>m.clipboard!=null),u=Am(),f=m=>()=>{o(!1),m()};return c.jsxs(jn,{open:n,onOpenChange:o,trigger:c.jsx(Qe,{icon:tn,label:t("tool.more"),description:t("tool.moreHint"),active:n,iconOnly:!0,stacked:e,onClick:()=>o(m=>!m)}),children:[c.jsx(je,{onClick:f(i),icon:c.jsx(bn,{}),disabled:r===0,children:t("tool.undo")}),c.jsx(je,{onClick:f(a),icon:c.jsx(yn,{}),disabled:s===0,children:t("tool.redo")}),c.jsx("div",{"aria-hidden":!0,className:"my-1 h-px bg-border"}),c.jsx(je,{onClick:f(()=>x.getState().cutSelection()),icon:c.jsx(Ko,{}),disabled:!l,children:t("menu.cut")}),c.jsx(je,{onClick:f(()=>x.getState().copySelection()),icon:c.jsx(Ho,{}),disabled:!l,children:t("menu.copy")}),c.jsx(je,{onClick:f(()=>x.getState().pasteClipboard()),icon:c.jsx(Fo,{}),disabled:!d,children:t("menu.paste")}),c.jsx("div",{"aria-hidden":!0,className:"my-1 h-px bg-border"}),c.jsx(je,{onClick:f(()=>x.getState().autoArrangeAll()),icon:c.jsx(ft,{}),disabled:!u.hasAnyElement||!u.hasArrangedAny,children:t("layout.allAuto")}),c.jsx(je,{onClick:f(()=>x.getState().autoArrangeSelection()),icon:c.jsx(ft,{}),disabled:!u.hasSelection||!u.selectionHasArranged,children:t("layout.selAuto")}),c.jsx(je,{onClick:f(()=>x.getState().fillUnplacedAll()),icon:c.jsx(It,{}),disabled:!u.hasGapsAll,children:t("layout.allFill")}),c.jsx(je,{onClick:f(()=>x.getState().fillUnplacedSelection()),icon:c.jsx(It,{}),disabled:!u.hasSelection||!u.selectionHasGaps,children:t("layout.selFill")})]})}function je({children:e,icon:t,onClick:n,disabled:o}){return c.jsxs("button",{type:"button",role:"menuitem",disabled:o,onClick:n,className:ye("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 my(){const e=xt(r=>r.outlineOpen),t=xt(r=>r.setOutlineOpen),n=Ke();return Ne(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($o,{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($o,{onClose:()=>t(!1)}):c.jsx(py,{onClick:()=>t(!0)})})}function py({onClick:e}){const t=U(),n=Ke(),o=Ne(n,"compact");return c.jsxs("button",{type:"button",onClick:e,"aria-label":t("outline.title"),title:t("outline.title"),className:ye("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(Go,{className:"size-4 shrink-0"}),!o&&c.jsx("span",{className:"text-xs font-medium",children:t("outline.title")})]})}function $o({onClose:e,sheet:t}){const n=U(),o=x(d=>d.diagram.elements),r=x(d=>d.activeTool==="place"),s=Ke(),i=Ne(s,"compact"),a=Ne(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:ye("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(gy,{children:o.length}),c.jsx(pp,{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(hy,{element:d},d.id))})})]})}function hy({element:e}){const t=qe[e.kind],n=x(l=>l.selection.includes(e.id)),o=x(l=>l.setSelection),r=x(l=>l.toggleInSelection),s=Ke(),i=!Ne(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 gy({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 xy={"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":"剩余动作电流"},yy={"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"},Eo={zh:xy,en:yy};function by(e,t){return Eo[e][t]??Eo.zh[t]}function wt(){const e=yt(t=>t.locale);return(t,n)=>by(e,t)??n??t}const Mm="ole-palette-collapsed",wy=new Set(["busbar"]),pt=(()=>{const e={};for(const[t,n]of Object.entries(e0)){const o=n.filter(r=>!wy.has(r.id));o.length&&(e[t]=o)}return e})(),vy=(()=>{const e=new Set(to),t=Object.keys(pt).filter(n=>!e.has(n));return[...to.filter(n=>{var o;return(o=pt[n])==null?void 0:o.length}),...t]})();function ky(){try{const e=window.localStorage.getItem(Mm);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 _y(e){try{window.localStorage.setItem(Mm,JSON.stringify([...e]))}catch{}}function Sy(){const e=U(),t=x(f=>f.activeTool==="place"),n=x(f=>f.placeKind),o=x(f=>f.setActiveTool),r=xt(f=>f.outlineOpen),s=Ke(),i=Ne(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(wn,{className:"size-3.5"})})]}),c.jsx(jy,{sheet:i})]})})}function jy({sheet:e}){const t=U(),n=wt(),[o,r]=_.useState(""),[s,i]=_.useState(()=>ky()),a=_.useMemo(()=>{const f=o.trim().toLowerCase();if(!f)return pt;const m={};for(const[g,p]of Object.entries(pt)){const h=p.filter(y=>{const w=n(`${y.id}.name`,y.name).toLowerCase(),v=n(`${y.id}.desc`,y.description??"").toLowerCase();return w.includes(f)||y.id.toLowerCase().includes(f)||v.includes(f)});h.length&&(m[g]=h)}return m},[o,n]),l=o.trim().length>0,d=l&&Object.values(a).every(f=>!(f!=null&&f.length)),u=_.useCallback((f,m)=>{i(g=>{const p=new Set(g);return m?p.delete(f):p.add(f),_y(p),p})},[]);return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"px-2 pb-1.5 pt-2",children:c.jsx($y,{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")}):vy.map(f=>{var y;const m=a[f];if(!(m!=null&&m.length))return null;const g=((y=pt[f])==null?void 0:y.length)??m.length,p=t(`cat.${f}`),h=l||!s.has(f);return c.jsxs("details",{open:h,className:"group mb-2 last:mb-0",onToggle:w=>{l||u(f,w.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(rp,{className:"size-3 transition-transform [details:not([open])>summary>&]:-rotate-90"}),c.jsx("span",{className:"flex-1",children:p}),c.jsx(Ny,{children:l&&m.length!==g?`${m.length}/${g}`:g})]}),c.jsx("ul",{className:"mt-0.5 space-y-px",children:m.map(w=>c.jsx(Ey,{entry:w,sheet:e},w.id))})]},f)})})]})}function $y({value:e,onChange:t}){const n=U();return c.jsxs("div",{className:"relative",children:[c.jsx(gp,{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(wn,{className:"size-3"})})]})}function Ey({entry:e,sheet:t}){const n=U(),o=wt(),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=_.useRef(null);_.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 m=document.createElement("div");m.className="ole-glass",m.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(";"),m.innerHTML=`<svg class="ole-symbol" viewBox="${e.viewBox}" width="48" height="48" preserveAspectRatio="xMidYMid meet">${e.svg}</svg>`,document.body.appendChild(m),f.dataTransfer.setDragImage(m,32,32),setTimeout(()=>m.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 Ny({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 hn="ole-onboarding-dismissed";function Ty(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(hn)==="1"}catch{return!1}}function No(e){try{e?window.localStorage.setItem(hn,"1"):window.localStorage.removeItem(hn)}catch{}}const To=Lt(e=>({dismissed:Ty(),dismiss:()=>{No(!0),e({dismissed:!0})},reset:()=>{No(!1),e({dismissed:!1})}}));function Cy(){const e=U(),t=To(o=>o.dismissed),n=To(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(wn,{className:"size-3.5"})})]}),c.jsxs("ol",{className:"mt-3 space-y-2.5",children:[c.jsx(Jt,{n:1,icon:c.jsx(xn,{}),title:e("onboard.step1.title"),body:e("onboard.step1.body")}),c.jsx(Jt,{n:2,icon:c.jsx(Yo,{}),title:e("onboard.step2.title"),body:e("onboard.step2.body")}),c.jsx(Jt,{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 Jt({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 Iy(){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(By,{wireId:s});if(r)return c.jsx(Dy,{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(Oy,{bus:a});const l=n.find(u=>u.id===i);if(!l)return null;const d=qe[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(vt,{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(Pm,{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(Ry,{id:i,element:l,field:u},u.name))}),c.jsx(Ay,{id:i,element:l,schema:(d==null?void 0:d.params)??[]})]})}function Ay({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(My,{id:e,element:t,field:s},s.name)),r.map(([s,i])=>c.jsx(Py,{id:e,element:t,fieldKey:s,value:i},s))]})}function My({id:e,element:t,field:n}){var l;const o=U(),r=wt(),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(ot,{label:i,children:c.jsx(En,{active:!!s,onClick:()=>a(!s),children:o(s?"common.yes":"common.no")})}):n.type==="number"?c.jsx(Dt,{label:i,value:typeof s=="number"?s:0,unit:n.unit,onCommit:a}):c.jsx(vt,{label:i,value:typeof s=="string"?s:"",unit:n.unit,onCommit:d=>a(d.trim()===""?void 0:d)})}function Py({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(ot,{label:n,children:c.jsx(En,{active:o,onClick:()=>s(!o),children:r(o?"common.yes":"common.no")})}):typeof o=="number"?c.jsx(Dt,{label:n,value:o,onCommit:s}):c.jsx(vt,{label:n,value:o,onCommit:i=>s(i.trim()===""?void 0:i)})}function Oy({bus:e}){const t=U(),n=e.id,o=r=>{const s=r.trim();gn(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(vt,{label:t("props.name"),value:e.name??"",placeholder:e.id,onCommit:o}),c.jsx(Pm,{label:t("props.note"),value:e.note??"",onCommit:r=>gn(n,{note:r.trim()===""?void 0:r.trim()})}),c.jsx(Ly,{bus:e})]})}function Ly({bus:e}){const t=(o,r)=>{const s={...e.params??{}};r===void 0||r===""?delete s[o]:s[o]=r,gn(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(Dt,{label:"Un",value:typeof n.Un=="number"?n.Un:0,unit:"kV",onCommit:o=>t("Un",o)})})}function gn(e,t){x.getState().dispatch(n=>{const o=(n.buses??[]).map(r=>r.id===e?{...r,...t}:r);return{...n,buses:o}})}function By({wireId:e}){const t=U(),n=x(p=>p.diagram.wires),o=x(p=>p.diagram.elements),r=x(p=>p.diagram.buses),s=x(p=>p.internal.terminalToNode),i=x(p=>p.setSelectedNode),a=(n??[]).find(p=>p.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(p=>[p.id,p])),u=new Map((r??[]).map(p=>[p.id,p])),f=p=>{if(!p.includes(".")){const N=u.get(p);return{id:p,label:(N==null?void 0:N.name)??p}}const h=p.indexOf("."),y=p.slice(0,h),w=p.slice(h+1),v=d.get(y);return{id:y,label:(v==null?void 0:v.name)??y,pin:w}},m=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:[m,g].map((p,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([p.id]),children:[c.jsx("span",{className:"flex-1 truncate font-mono text-[11px]",children:p.id}),c.jsx("span",{className:"truncate text-[10px] text-muted-foreground",children:p.label}),p.pin&&c.jsx("span",{className:"font-mono text-[10px] text-muted-foreground/80",children:p.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 Dy({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 ot({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 vt({label:e,value:t,placeholder:n,unit:o,onCommit:r}){const[s,i]=_.useState(t),a=_.useRef(null);return _.useEffect(()=>i(t),[t]),c.jsx(ot,{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:ye("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 Pm({label:e,value:t,onCommit:n}){const[o,r]=_.useState(t);return _.useEffect(()=>r(t),[t]),c.jsx(ot,{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 Dt({label:e,value:t,min:n,unit:o,onCommit:r}){const[s,i]=_.useState(String(t)),a=_.useRef(null);return _.useEffect(()=>i(String(t)),[t]),c.jsx(ot,{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:ye("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 En({active:e,onClick:t,children:n}){return c.jsx("button",{type:"button",onClick:t,className:ye("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 Ry({id:e,element:t,field:n}){var l;const o=U(),s=wt()(`${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(ot,{label:s,children:c.jsx(En,{active:!!i,onClick:()=>a(!i),children:o(i?"common.yes":"common.no")})}):n.type==="number"?c.jsx(Dt,{label:s,value:typeof i=="number"?i:0,onCommit:a}):c.jsx(vt,{label:s,value:typeof i=="string"?i:"",onCommit:d=>a(d.trim()===""?void 0:d)})}function zy(){const e=U(),t=wt(),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=Ke(),l=Ne(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],m=(i??[]).find(g=>g.id===f);if(m)d=m.name??e("props.bus");else{const g=s.find(p=>p.id===f);if(g){const p=qe[g.kind];d=p?t(`${p.id}.name`,p.name):g.kind}}}else u=n.length;return c.jsxs("aside",{className:ye("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(Iy,{})]})}function Fy(){_.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 Hy(){Fy();const e=_.useRef(null),t=lx(e);return c.jsx(Zp,{children:c.jsx("div",{ref:e,className:"relative h-full w-full overflow-hidden bg-background text-foreground",children:c.jsxs(Ox,{width:t,children:[c.jsx(jx,{}),c.jsx(my,{}),c.jsx(zy,{}),c.jsx(cy,{}),c.jsx(iy,{}),c.jsx(Ux,{}),c.jsx(Sy,{}),c.jsx(Cy,{}),c.jsx(Mx,{})]})})})}const Wy="ole-theme";function Gy(){try{const e=window.localStorage.getItem(Wy);return e==="light"||e==="dark"?e:null}catch{return null}}function qy(){return typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-color-scheme: dark)").matches}function Ky(){return typeof window>"u"?"light":Gy()??(qy()?"dark":"light")}function Om(e){typeof document>"u"||document.documentElement.classList.toggle("dark",e==="dark")}function Yy({className:e,diagram:t,locale:n,theme:o}){return _.useEffect(()=>{if(!t)return;x.getState().diagram.elements.length===0&&x.getState().setDiagram(t)},[t]),_.useEffect(()=>{n&&yt.getState().setLocale(n)},[n]),_.useEffect(()=>{o&&Om(o)},[o]),_.useEffect(()=>{Sn()},[]),Y0(),c.jsx("div",{className:`ole-root ${e??"h-full w-full"}`,children:c.jsx(Hy,{})})}const Lm={"application/json":[".json"]},Bm=()=>typeof window<"u"&&typeof window.showOpenFilePicker=="function",Dm=e=>e instanceof DOMException&&e.name==="AbortError";function Co(e){let t;try{t=JSON.parse(e)}catch(o){throw new Error(xe("io.parseFailed",{err:o.message}))}if(!t||typeof t!="object"||Array.isArray(t))throw new Error(xe("io.notObject"));const n=t;if(n.version!=="1")throw new Error(xe("io.versionMismatch",{actual:JSON.stringify(n.version)}));if(!Array.isArray(n.elements))throw new Error(xe("io.elementsMissing"));return n}function Xy(e){return JSON.stringify(e,null,2)+`
|
|
188
|
-
`}async function
|
|
189
|
-
`);for(let a=0;a<i.length;a++){const[l,
|
|
186
|
+
*/const Sn=X("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);function nr(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=nr(e[t]))&&(o&&(o+=" "),o+=n)}else for(n in e)e[n]&&(o&&(o+=" "),o+=n);return o}function or(){for(var e,t,n=0,o="",r=arguments.length;n<r;n++)(e=arguments[n])&&(t=nr(e))&&(o&&(o+=" "),o+=t);return o}const jn="-",$h=e=>{const t=Nh(e),{conflictingClassGroups:n,conflictingClassGroupModifiers:o}=e;return{getClassGroupId:i=>{const a=i.split(jn);return a[0]===""&&a.length!==1&&a.shift(),rr(a,t)||Eh(i)},getConflictingClassGroupIds:(i,a)=>{const l=n[i]||[];return a&&o[i]?[...l,...o[i]]:l}}},rr=(e,t)=>{var i;if(e.length===0)return t.classGroupId;const n=e[0],o=t.nextPart.get(n),r=o?rr(e.slice(1),o):void 0;if(r)return r;if(t.validators.length===0)return;const s=e.join(jn);return(i=t.validators.find(({validator:a})=>a(s)))==null?void 0:i.classGroupId},Fn=/^\[(.+)\]$/,Eh=e=>{if(Fn.test(e)){const t=Fn.exec(e)[1],n=t==null?void 0:t.substring(0,t.indexOf(":"));if(n)return"arbitrary.."+n}},Nh=e=>{const{theme:t,prefix:n}=e,o={nextPart:new Map,validators:[]};return Ch(Object.entries(e.classGroups),n).forEach(([s,i])=>{an(i,o,s,t)}),o},an=(e,t,n,o)=>{e.forEach(r=>{if(typeof r=="string"){const s=r===""?t:Hn(t,r);s.classGroupId=n;return}if(typeof r=="function"){if(Th(r)){an(r(o),t,n,o);return}t.validators.push({validator:r,classGroupId:n});return}Object.entries(r).forEach(([s,i])=>{an(i,Hn(t,s),n,o)})})},Hn=(e,t)=>{let n=e;return t.split(jn).forEach(o=>{n.nextPart.has(o)||n.nextPart.set(o,{nextPart:new Map,validators:[]}),n=n.nextPart.get(o)}),n},Th=e=>e.isThemeGetter,Ch=(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,Ih=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)}}},sr="!",Ah=e=>{const{separator:t,experimentalParseClassName:n}=e,o=t.length===1,r=t[0],s=t.length,i=a=>{const l=[];let u=0,d=0,f;for(let y=0;y<a.length;y++){let w=a[y];if(u===0){if(w===r&&(o||a.slice(y,y+s)===t)){l.push(a.slice(d,y)),d=y+s;continue}if(w==="/"){f=y;continue}}w==="["?u++:w==="]"&&u--}const m=l.length===0?a:a.substring(d),g=m.startsWith(sr),h=g?m.substring(1):m,p=f&&f>d?f-d:void 0;return{modifiers:l,hasImportantModifier:g,baseClassName:h,maybePostfixModifierPosition:p}};return n?a=>n({className:a,parseClassName:i}):i},Mh=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},Ph=e=>({cache:Ih(e.cacheSize),parseClassName:Ah(e),...$h(e)}),Oh=/\s+/,Lh=(e,t)=>{const{parseClassName:n,getClassGroupId:o,getConflictingClassGroupIds:r}=t,s=[],i=e.trim().split(Oh);let a="";for(let l=i.length-1;l>=0;l-=1){const u=i[l],{modifiers:d,hasImportantModifier:f,baseClassName:m,maybePostfixModifierPosition:g}=n(u);let h=!!g,p=o(h?m.substring(0,g):m);if(!p){if(!h){a=u+(a.length>0?" "+a:a);continue}if(p=o(m),!p){a=u+(a.length>0?" "+a:a);continue}h=!1}const y=Mh(d).join(":"),w=f?y+sr:y,v=w+p;if(s.includes(v))continue;s.push(v);const E=r(p,h);for(let I=0;I<E.length;++I){const L=E[I];s.push(w+L)}a=u+(a.length>0?" "+a:a)}return a};function Bh(){let e=0,t,n,o="";for(;e<arguments.length;)(t=arguments[e++])&&(n=ir(t))&&(o&&(o+=" "),o+=n);return o}const ir=e=>{if(typeof e=="string")return e;let t,n="";for(let o=0;o<e.length;o++)e[o]&&(t=ir(e[o]))&&(n&&(n+=" "),n+=t);return n};function Dh(e,...t){let n,o,r,s=i;function i(l){const u=t.reduce((d,f)=>f(d),e());return n=Ph(u),o=n.cache.get,r=n.cache.set,s=a,a(l)}function a(l){const u=o(l);if(u)return u;const d=Lh(l,n);return r(l,d),d}return function(){return s(Bh.apply(null,arguments))}}const te=e=>{const t=n=>n[e]||[];return t.isThemeGetter=!0,t},ar=/^\[(?:([a-z-]+):)?(.+)\]$/i,Rh=/^\d+\/\d+$/,zh=new Set(["px","full","screen"]),Fh=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,Hh=/\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$/,Wh=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,Gh=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,Kh=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,Pe=e=>Ze(e)||zh.has(e)||Rh.test(e),Re=e=>et(e,"length",Qh),Ze=e=>!!e&&!Number.isNaN(Number(e)),Yt=e=>et(e,"number",Ze),rt=e=>!!e&&Number.isInteger(Number(e)),qh=e=>e.endsWith("%")&&Ze(e.slice(0,-1)),K=e=>ar.test(e),ze=e=>Fh.test(e),Yh=new Set(["length","size","percentage"]),Xh=e=>et(e,Yh,lr),Vh=e=>et(e,"position",lr),Uh=new Set(["image","url"]),Zh=e=>et(e,Uh,tp),Jh=e=>et(e,"",ep),st=()=>!0,et=(e,t,n)=>{const o=ar.exec(e);return o?o[1]?typeof t=="string"?o[1]===t:t.has(o[1]):n(o[2]):!1},Qh=e=>Hh.test(e)&&!Wh.test(e),lr=()=>!1,ep=e=>Gh.test(e),tp=e=>Kh.test(e),np=()=>{const e=te("colors"),t=te("spacing"),n=te("blur"),o=te("brightness"),r=te("borderColor"),s=te("borderRadius"),i=te("borderSpacing"),a=te("borderWidth"),l=te("contrast"),u=te("grayscale"),d=te("hueRotate"),f=te("invert"),m=te("gap"),g=te("gradientColorStops"),h=te("gradientColorStopPositions"),p=te("inset"),y=te("margin"),w=te("opacity"),v=te("padding"),E=te("saturate"),I=te("scale"),L=te("sepia"),W=te("skew"),le=te("space"),re=te("translate"),pe=()=>["auto","contain","none"],ue=()=>["auto","hidden","clip","visible","scroll"],$=()=>["auto",K,t],T=()=>[K,t],J=()=>["",Pe,Re],ee=()=>["auto",Ze,K],ie=()=>["bottom","center","left","left-bottom","left-top","right","right-bottom","right-top","top"],be=()=>["solid","dashed","dotted","double","none"],Ie=()=>["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],de=()=>["start","end","center","between","around","evenly","stretch"],_e=()=>["","0",K],we=()=>["auto","avoid","all","avoid-page","page","left","right","column"],ge=()=>[Ze,K];return{cacheSize:500,separator:":",theme:{colors:[st],spacing:[Pe,Re],blur:["none","",ze,K],brightness:ge(),borderColor:[e],borderRadius:["none","","full",ze,K],borderSpacing:T(),borderWidth:J(),contrast:ge(),grayscale:_e(),hueRotate:ge(),invert:_e(),gap:T(),gradientColorStops:[e],gradientColorStopPositions:[qh,Re],inset:$(),margin:$(),opacity:ge(),padding:T(),saturate:ge(),scale:ge(),sepia:_e(),skew:ge(),space:T(),translate:T()},classGroups:{aspect:[{aspect:["auto","square","video",K]}],container:["container"],columns:[{columns:[ze]}],"break-after":[{"break-after":we()}],"break-before":[{"break-before":we()}],"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:[...ie(),K]}],overflow:[{overflow:ue()}],"overflow-x":[{"overflow-x":ue()}],"overflow-y":[{"overflow-y":ue()}],overscroll:[{overscroll:pe()}],"overscroll-x":[{"overscroll-x":pe()}],"overscroll-y":[{"overscroll-y":pe()}],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",rt,K]}],basis:[{basis:$()}],"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:_e()}],shrink:[{shrink:_e()}],order:[{order:["first","last","none",rt,K]}],"grid-cols":[{"grid-cols":[st]}],"col-start-end":[{col:["auto",{span:["full",rt,K]},K]}],"col-start":[{"col-start":ee()}],"col-end":[{"col-end":ee()}],"grid-rows":[{"grid-rows":[st]}],"row-start-end":[{row:["auto",{span:[rt,K]},K]}],"row-start":[{"row-start":ee()}],"row-end":[{"row-end":ee()}],"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:[m]}],"gap-x":[{"gap-x":[m]}],"gap-y":[{"gap-y":[m]}],"justify-content":[{justify:["normal",...de()]}],"justify-items":[{"justify-items":["start","end","center","stretch"]}],"justify-self":[{"justify-self":["auto","start","end","center","stretch"]}],"align-content":[{content:["normal",...de(),"baseline"]}],"align-items":[{items:["start","end","center","baseline","stretch"]}],"align-self":[{self:["auto","start","end","center","stretch","baseline"]}],"place-content":[{"place-content":[...de(),"baseline"]}],"place-items":[{"place-items":["start","end","center","baseline","stretch"]}],"place-self":[{"place-self":["auto","start","end","center","stretch"]}],p:[{p:[v]}],px:[{px:[v]}],py:[{py:[v]}],ps:[{ps:[v]}],pe:[{pe:[v]}],pt:[{pt:[v]}],pr:[{pr:[v]}],pb:[{pb:[v]}],pl:[{pl:[v]}],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":[le]}],"space-x-reverse":["space-x-reverse"],"space-y":[{"space-y":[le]}],"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:[ze]},ze]}],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",ze,Re]}],"font-smoothing":["antialiased","subpixel-antialiased"],"font-style":["italic","not-italic"],"font-weight":[{font:["thin","extralight","light","normal","medium","semibold","bold","extrabold","black",Yt]}],"font-family":[{font:[st]}],"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",Ze,Yt]}],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":[w]}],"text-alignment":[{text:["left","center","right","justify","start","end"]}],"text-color":[{text:[e]}],"text-opacity":[{"text-opacity":[w]}],"text-decoration":["underline","overline","line-through","no-underline"],"text-decoration-style":[{decoration:[...be(),"wavy"]}],"text-decoration-thickness":[{decoration:["auto","from-font",Pe,Re]}],"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:T()}],"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":[w]}],"bg-origin":[{"bg-origin":["border","padding","content"]}],"bg-position":[{bg:[...ie(),Vh]}],"bg-repeat":[{bg:["no-repeat",{repeat:["","x","y","round","space"]}]}],"bg-size":[{bg:["auto","cover","contain",Xh]}],"bg-image":[{bg:["none",{"gradient-to":["t","tr","r","br","b","bl","l","tl"]},Zh]}],"bg-color":[{bg:[e]}],"gradient-from-pos":[{from:[h]}],"gradient-via-pos":[{via:[h]}],"gradient-to-pos":[{to:[h]}],"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":[w]}],"border-style":[{border:[...be(),"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":[w]}],"divide-style":[{divide:be()}],"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:["",...be()]}],"outline-offset":[{"outline-offset":[Pe,K]}],"outline-w":[{outline:[Pe,Re]}],"outline-color":[{outline:[e]}],"ring-w":[{ring:J()}],"ring-w-inset":["ring-inset"],"ring-color":[{ring:[e]}],"ring-opacity":[{"ring-opacity":[w]}],"ring-offset-w":[{"ring-offset":[Pe,Re]}],"ring-offset-color":[{"ring-offset":[e]}],shadow:[{shadow:["","inner","none",ze,Jh]}],"shadow-color":[{shadow:[st]}],opacity:[{opacity:[w]}],"mix-blend":[{"mix-blend":[...Ie(),"plus-lighter","plus-darker"]}],"bg-blend":[{"bg-blend":Ie()}],filter:[{filter:["","none"]}],blur:[{blur:[n]}],brightness:[{brightness:[o]}],contrast:[{contrast:[l]}],"drop-shadow":[{"drop-shadow":["","none",ze,K]}],grayscale:[{grayscale:[u]}],"hue-rotate":[{"hue-rotate":[d]}],invert:[{invert:[f]}],saturate:[{saturate:[E]}],sepia:[{sepia:[L]}],"backdrop-filter":[{"backdrop-filter":["","none"]}],"backdrop-blur":[{"backdrop-blur":[n]}],"backdrop-brightness":[{"backdrop-brightness":[o]}],"backdrop-contrast":[{"backdrop-contrast":[l]}],"backdrop-grayscale":[{"backdrop-grayscale":[u]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[d]}],"backdrop-invert":[{"backdrop-invert":[f]}],"backdrop-opacity":[{"backdrop-opacity":[w]}],"backdrop-saturate":[{"backdrop-saturate":[E]}],"backdrop-sepia":[{"backdrop-sepia":[L]}],"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:ge()}],ease:[{ease:["linear","in","out","in-out",K]}],delay:[{delay:ge()}],animate:[{animate:["none","spin","ping","pulse","bounce",K]}],transform:[{transform:["","gpu","none"]}],scale:[{scale:[I]}],"scale-x":[{"scale-x":[I]}],"scale-y":[{"scale-y":[I]}],rotate:[{rotate:[rt,K]}],"translate-x":[{"translate-x":[re]}],"translate-y":[{"translate-y":[re]}],"skew-x":[{"skew-x":[W]}],"skew-y":[{"skew-y":[W]}],"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":T()}],"scroll-mx":[{"scroll-mx":T()}],"scroll-my":[{"scroll-my":T()}],"scroll-ms":[{"scroll-ms":T()}],"scroll-me":[{"scroll-me":T()}],"scroll-mt":[{"scroll-mt":T()}],"scroll-mr":[{"scroll-mr":T()}],"scroll-mb":[{"scroll-mb":T()}],"scroll-ml":[{"scroll-ml":T()}],"scroll-p":[{"scroll-p":T()}],"scroll-px":[{"scroll-px":T()}],"scroll-py":[{"scroll-py":T()}],"scroll-ps":[{"scroll-ps":T()}],"scroll-pe":[{"scroll-pe":T()}],"scroll-pt":[{"scroll-pt":T()}],"scroll-pr":[{"scroll-pr":T()}],"scroll-pb":[{"scroll-pb":T()}],"scroll-pl":[{"scroll-pl":T()}],"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,Re,Yt]}],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"]}}},op=Dh(np);function ye(...e){return op(or(e))}const cr=_.createContext(null);function rp(){const e=_.useContext(cr);if(!e)throw new Error("useContextMenu must be used inside <ContextMenuHost>");return e}const St=8;function sp({children:e}){const[t,n]=_.useState({open:!1,x:0,y:0,items:[]}),[o,r]=_.useState(null),s=_.useRef(null),i=_.useCallback(()=>{n(u=>u.open?{...u,open:!1}:u)},[]),a=_.useCallback((u,d,f)=>{r(null),n({open:!0,x:u,y:d,items:f})},[]),l=_.useMemo(()=>({open:a,close:i}),[a,i]);return _.useLayoutEffect(()=>{if(!t.open||!s.current)return;const u=s.current.getBoundingClientRect();let d=t.x,f=t.y;d+u.width>window.innerWidth-St&&(d=Math.max(St,t.x-u.width)),f+u.height>window.innerHeight-St&&(f=Math.max(St,t.y-u.height)),r({left:d,top:f})},[t]),_.useEffect(()=>{if(!t.open)return;const u=g=>{s.current&&!s.current.contains(g.target)&&i()},d=g=>{g.key==="Escape"&&(g.preventDefault(),i())},f=()=>i(),m=()=>i();return document.addEventListener("pointerdown",u,!0),document.addEventListener("keydown",d,!0),window.addEventListener("wheel",f,{passive:!0}),window.addEventListener("blur",m),()=>{document.removeEventListener("pointerdown",u,!0),document.removeEventListener("keydown",d,!0),window.removeEventListener("wheel",f),window.removeEventListener("blur",m)}},[t.open,i]),c.jsxs(cr.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:u=>u.preventDefault(),children:t.items.map((u,d)=>{if(u.type==="separator")return c.jsx("div",{role:"separator",className:"my-1 h-px bg-border"},`sep-${d}`);const f=u.icon;return c.jsxs("button",{type:"button",role:"menuitem",disabled:u.disabled,className:ye("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",u.destructive&&"text-destructive hover:bg-destructive/10 hover:text-destructive",u.disabled&&"pointer-events-none text-muted-foreground opacity-60"),onClick:()=>{i(),u.onSelect()},children:[c.jsxs("span",{className:"flex items-center gap-2",children:[f?c.jsx(f,{className:"size-4"}):null,c.jsx("span",{children:u.label})]}),u.shortcut?c.jsx("span",{className:"text-xs text-muted-foreground",children:u.shortcut}):null]},`${u.label}-${d}`)})})]})}const Wn=e=>{let t;const n=new Set,o=(u,d)=>{const f=typeof u=="function"?u(t):u;if(!Object.is(f,t)){const m=t;t=d??(typeof f!="object"||f===null)?f:Object.assign({},t,f),n.forEach(g=>g(t,m))}},r=()=>t,a={setState:o,getState:r,getInitialState:()=>l,subscribe:u=>(n.add(u),()=>n.delete(u))},l=t=e(o,r,a);return a},ip=(e=>e?Wn(e):Wn),ap=e=>e;function lp(e,t=ap){const n=_.useSyncExternalStore(e.subscribe,_.useCallback(()=>t(e.getState()),[e,t]),_.useCallback(()=>t(e.getInitialState()),[e,t]));return _.useDebugValue(n),n}const Gn=e=>{const t=ip(e),n=o=>lp(t,o);return Object.assign(n,t),n},Bt=(e=>e?Gn(e):Gn),Kn={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":"移除选中元件及其连接的连线","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","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"}},dr="ole-locale";function cp(){if(typeof window>"u")return"zh";try{const e=window.localStorage.getItem(dr);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 qn(e){try{window.localStorage.setItem(dr,e)}catch{}}const bt=Bt((e,t)=>({locale:cp(),setLocale:n=>{qn(n),e({locale:n})},toggle:()=>{const n=t().locale==="zh"?"en":"zh";qn(n),e({locale:n})}}));function ur(e,t){return t?e.replace(/\{(\w+)\}/g,(n,o)=>t[o]!==void 0?String(t[o]):`{${o}}`):e}function fr(e,t){return Kn[e][t]??Kn.zh[t]??t}function xe(e,t){return ur(fr(bt.getState().locale,e),t)}function V(){const e=bt(t=>t.locale);return(t,n)=>ur(fr(e,t),n)}function mr(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 ln=e=>t=>{try{const n=e(t);return n instanceof Promise?n:{then(o){return ln(o)(n)},catch(o){return this}}}catch(n){return{then(o){return this},catch(o){return ln(o)(n)}}}},dp=(e,t)=>(n,o,r)=>{let s={storage:mr(()=>window.localStorage),partialize:y=>y,version:0,merge:(y,w)=>({...w,...y}),...t},i=!1,a=0;const l=new Set,u=new Set;let d=s.storage;if(!d)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 d.setItem(s.name,{state:y,version:s.version})},m=r.setState;r.setState=(y,w)=>(m(y,w),f());const g=e((...y)=>(n(...y),f()),o,r);r.getInitialState=()=>g;let h;const p=()=>{var y,w;if(!d)return;const v=++a;i=!1,l.forEach(I=>{var L;return I((L=o())!=null?L:g)});const E=((w=s.onRehydrateStorage)==null?void 0:w.call(s,(y=o())!=null?y:g))||void 0;return ln(d.getItem.bind(d))(s.name).then(I=>{if(I)if(typeof I.version=="number"&&I.version!==s.version){if(s.migrate){const L=s.migrate(I.state,I.version);return L instanceof Promise?L.then(W=>[!0,W]):[!0,L]}console.error("State loaded from storage couldn't be migrated since no migrate function was provided")}else return[!1,I.state];return[!1,void 0]}).then(I=>{var L;if(v!==a)return;const[W,le]=I;if(h=s.merge(le,(L=o())!=null?L:g),n(h,!0),W)return f()}).then(()=>{v===a&&(E==null||E(o(),void 0),h=o(),i=!0,u.forEach(I=>I(h)))}).catch(I=>{v===a&&(E==null||E(void 0,I))})};return r.persist={setOptions:y=>{s={...s,...y},y.storage&&(d=y.storage)},clearStorage:()=>{d==null||d.removeItem(s.name)},getOptions:()=>s,rehydrate:()=>p(),hasHydrated:()=>i,onHydrate:y=>(l.add(y),()=>{l.delete(y)}),onFinishHydration:y=>(u.add(y),()=>{u.delete(y)})},s.skipHydration||p(),h||g},up=dp;function hr(){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 pr(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 cn(e){return e===90||e===270?"y":"x"}function Oe(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 fp={n:"e",e:"s",s:"w",w:"n"},mp={n:"n",s:"s",e:"w",w:"e"};function ht(e,t){let n=t.mirror?mp[e]:e;const o=t.rot/90|0;for(let r=0;r<o;r++)n=fp[n];return n}function dn(e){switch(e){case"n":return[0,-1];case"s":return[0,1];case"e":return[1,0];case"w":return[-1,0]}}class gr{constructor(){ot(this,"parent",new Map);ot(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 Yn=["n","e","s","w"],Xn={n:"s",s:"n",e:"w",w:"e"};function Vn(e,t){const n=Yn.indexOf(e),r=((Yn.indexOf(t)-n)%4+4)%4;return[0,90,180,270][r]}const hp=320,Un=220,it=260,Zn=720,at=30,Jn=30,lt=80,Qn=10,pp=60,gp=520,xp=80,yp=80,eo=8,to=new Set(["source","renewable"]);function bp(e){var Mn,Pn,On,Ln,Bn,Dn;const{elements:t,buses:n,wires:o,library:r,userLayout:s,userBusLayout:i}=e,a=new Map(s),l=new Map(i),u=new Map;for(const b of t)u.set(b.id,b);const d=new Map;for(const b of n)d.set(b.id,b);const f=b=>{const k=u.get(b);if(k)return r.get(k.kind)},m=new Set(n.map(b=>b.id)),g=b=>m.has(b),h=new gr;for(const b of o)h.add(b.ends[0]),h.add(b.ends[1]),h.union(b.ends[0],b.ends[1]);for(const b of t){const k=r.get(b.kind);if(k)for(const S of k.terminals)h.add(`${b.id}.${S.id}`)}for(const b of n)h.add(b.id);const p=[];for(const[,b]of h.groups())b.length>=2&&p.push(b);const y=new Map;for(const b of p)for(const k of b)y.set(k,[b]);const w=new Map;for(const b of p){const k=b.filter(g);if(k.length!==0)for(const S of k){const N=b.filter(j=>j!==S),O=w.get(S)??[];O.push(...N),w.set(S,O)}}const v=new Map;for(const b of p){const k=b.filter(g);if(k.length!==0)for(const S of b){if(g(S))continue;const N=S.indexOf(".");if(N<0)continue;const O=S.slice(0,N),j=S.slice(N+1),A=v.get(O)??[];for(const D of k)A.some(M=>M.busId===D&&M.pin===j)||A.push({busId:D,pin:j});v.set(O,A)}}const E=[],I=new Set;for(const[b,k]of v)if(new Set(k.map(N=>N.busId)).size>=2){const N=((Pn=r.get(((Mn=u.get(b))==null?void 0:Mn.kind)??""))==null?void 0:Pn.category)==="transformer"?"vertical":"horizontal";E.push({elementId:b,attachments:k,orientation:N}),N==="vertical"&&I.add(b)}const L=new Map,W=(b,k)=>{b!==k&&(L.has(b)||L.set(b,new Set),L.has(k)||L.set(k,new Set),L.get(b).add(k),L.get(k).add(b))};for(const b of o)W(b.ends[0],b.ends[1]);for(const b of t){const k=r.get(b.kind);if(!k||k.terminals.length<2)continue;const S=k.terminals.map(N=>`${b.id}.${N.id}`);for(let N=0;N<S.length;N++)for(let O=N+1;O<S.length;O++)W(S[N],S[O])}for(const b of t){if(I.has(b.id))continue;const k=r.get(b.kind);if(!k||k.category!=="transformer"||k.terminals.length<2)continue;const S=k.terminals.map(j=>`${b.id}.${j.id}`),N=new Map;for(const j of S){const A=j.slice(b.id.length+1);N.set(A,new Set);const D=new Set(S.filter(R=>R!==j)),M=new Set([j]),F=[j];for(;F.length>0;){const R=F.shift();if(g(R)){N.get(A).add(R);continue}const C=L.get(R);if(C)for(const P of C)M.has(P)||D.has(P)||(M.add(P),F.push(P))}}const O=new Set;for(const j of N.values())for(const A of j)O.add(A);if(O.size>=2){const j=[];for(const[A,D]of N)for(const M of D)j.push({busId:M,pin:A});E.push({elementId:b.id,attachments:j,orientation:"vertical"}),I.add(b.id)}}const le=(b,k)=>{var D;const S=f(k),N=S?S.terminals.map(M=>`${k}.${M.id}`):[],O=b,j=new Set([O,...N]),A=[O];for(;A.length>0;){const M=A.shift(),F=M.indexOf(".");if(F>0){const C=M.slice(0,F),P=u.get(C);if(P){const B=(D=r.get(P.kind))==null?void 0:D.category;if(B&&to.has(B))return!0}}const R=L.get(M);if(R)for(const C of R)j.has(C)||(j.add(C),A.push(C))}return!1};for(const b of E){if(b.orientation!=="horizontal")continue;const k=new Set(b.attachments.map(N=>N.busId));let S=0;for(const N of k)le(N,b.elementId)&&S++;S===1&&(b.orientation="vertical",I.add(b.elementId))}for(const b of t){if(I.has(b.id)||b.kind!=="breaker")continue;const k=r.get(b.kind);if(!k||k.terminals.length!==2)continue;const S=k.terminals.map(j=>`${b.id}.${j.id}`),N=new Map;for(const j of S){const A=j.slice(b.id.length+1),D=new Set(S.filter(R=>R!==j)),M=new Set([j]),F=[j];for(;F.length>0;){const R=F.shift();if(g(R)){N.set(A,R);break}const C=L.get(R);if(C)for(const P of C){if(M.has(P)||D.has(P))continue;const B=P.indexOf(".");if(B>0){const G=P.slice(0,B);if(G!==b.id){const Q=u.get(G),U=Q?r.get(Q.kind):void 0;if((U==null?void 0:U.category)==="transformer")continue}}M.add(P),F.push(P)}}}if(new Set(N.values()).size>=2){const j=[];for(const[A,D]of N)j.push({busId:D,pin:A});E.push({elementId:b.id,attachments:j,orientation:"horizontal"})}}const re=new Map;for(const b of n)re.set(b.id,new Map);for(const b of E){const k=Array.from(new Set(b.attachments.map(S=>S.busId)));for(const S of k)for(const N of k)S!==N&&((On=re.get(S))==null||On.set(N,b))}const pe=b=>{var S;const k=(S=r.get(b))==null?void 0:S.category;return k?to.has(k):!1},ue=[];for(const b of n){const k=w.get(b.id);if(k)for(const S of k){if(g(S))continue;const N=S.indexOf(".");if(N<0)continue;const O=S.slice(0,N),j=u.get(O);if(j&&pe(j.kind)){ue.push(b.id);break}}}ue.length===0&&n.length>0&&ue.push(n[0].id);const $=new Map;for(const b of ue)$.set(b,0);{const b=[...ue];for(;b.length>0;){const k=b.shift(),S=$.get(k),N=re.get(k);if(N)for(const[O,j]of N){if($.has(O))continue;const A=j.orientation==="horizontal"?S:S+1;$.set(O,A),b.push(O)}}}for(const b of n){if($.has(b.id))continue;const k=$.size===0?-1:Math.max(...Array.from($.values()));$.set(b.id,k+1)}const T=new Map;for(const b of n){const k=$.get(b.id),S=T.get(k)??[];S.push(b.id),T.set(k,S)}const J=[...T.keys()].sort((b,k)=>b-k),ee=(b,k,S)=>{const N=`${b.elementId}.${S}`,O=k,j=f(b.elementId),A=new Set;if(j)for(const C of j.terminals)C.id!==S&&A.add(`${b.elementId}.${C.id}`);const D=new Set([N]),M=[{ref:N,dist:0}],F=new Map,R=(C,P,B,G)=>{D.add(C),F.set(C,P),M.push({ref:C,dist:G+B})};for(;M.length>0;){const{ref:C,dist:P}=M.shift();if(C===O){const U=F.get(O);let se;if(U){const q=U.indexOf(".");if(q>0){const z=U.slice(0,q);z!==b.elementId&&(se=z)}}return{extent:P,head:se}}const B=C.indexOf(".");if(B<0)continue;const G=C.slice(0,B),Q=C.slice(B+1);if(!g(G)&&!I.has(G)){const U=f(G),se=U==null?void 0:U.terminals.find(q=>q.id===Q);if(U&&se)for(const q of U.terminals){if(q.id===Q)continue;const z=`${G}.${q.id}`;D.has(z)||A.has(z)||R(z,C,Math.abs(se.y-q.y),P)}}for(const U of y.get(C)??[])for(const se of U){if(se===C||D.has(se)||A.has(se))continue;const q=g(C)||g(se);R(se,C,q?Jn:at,P)}}return{extent:0}},ie=(b,k)=>{var C,P,B;const S=(C=re.get(b))==null?void 0:C.get(k);if(!S||S.orientation==="horizontal")return it;const N=f(S.elementId);if(!N)return it;const O=(P=S.attachments.find(G=>G.busId===b))==null?void 0:P.pin,j=(B=S.attachments.find(G=>G.busId===k))==null?void 0:B.pin;if(!O||!j)return it;const A=N.terminals.find(G=>G.id===O),D=N.terminals.find(G=>G.id===j);if(!A||!D)return it;const M=Math.abs(D.y-A.y),F=ee(S,b,O).extent,R=ee(S,k,j).extent;return F+M+R},be=new Map;for(const b of E){if(b.orientation!=="vertical")continue;const k=b.attachments.slice().sort((D,M)=>($.get(D.busId)??0)-($.get(M.busId)??0));if(k.length<2)continue;const S=k[0].busId,N=k[1].busId,O=k[0].pin,A=ee(b,S,O).head??b.elementId;be.set(A,{lowerBusId:N})}const Ie=320,de=new Map,_e=(b,k)=>{if(!I.has(b))return!1;const S=E.find(A=>A.elementId===b),N=S==null?void 0:S.attachments.find(A=>A.busId!==k);if(!N)return!1;const O=$.get(k)??0;return($.get(N.busId)??0)<O},we=(b,k)=>{const S=be.get(b);if(S){const N=de.get(S.lowerBusId);if(N!==void 0)return Math.max(k,N+lt)}return Math.max(k,lt)},ge=(b,k)=>{if(de.has(b))return de.get(b);if(k.has(b))return Ie;k.add(b);const S=w.get(b)??[];let N=0,O=0;for(const A of S){if(g(A))continue;const D=A.indexOf(".");if(D<0)continue;const M=A.slice(0,D),F=A.slice(D+1);if(_e(M,b))continue;const R=f(M);if(!R)continue;const C=R.terminals.find(G=>G.id===F);if(!C)continue;const P=be.get(M);P&&ge(P.lowerBusId,k);const B=we(M,R.width);C.y>0?N+=B:O+=B}const j=Math.max(Ie,Math.max(N,O)+lt);return de.set(b,j),k.delete(b),j};for(const b of n)ge(b.id,new Set);const De=new Map,Jm=(b,k,S)=>{const N=f(k);if(!N)return;const O=`${k}.${S}`,j=N.terminals.filter(M=>M.id!==S).map(M=>`${k}.${M.id}`);if(j.length===0)return;const A=new Set([O,...j]),D=j.slice();for(;D.length>0;){const M=D.shift();if(g(M)&&M!==b){const R=l.get(M);return R?R.at[0]:void 0}for(const R of y.get(M)??[])for(const C of R)C===M||A.has(C)||(A.add(C),D.push(C));const F=M.indexOf(".");if(F>0){const R=M.slice(0,F);if(!g(R)){const C=f(R);if(C)for(const P of C.terminals){const B=`${R}.${P.id}`;A.has(B)||(A.add(B),D.push(B))}}}}},Qm=b=>{const k=w.get(b);if(!k||k.length===0)return;const S=l.get(b);if(!S)return;const N=k.flatMap(C=>{if(g(C))return[];const P=C.indexOf(".");if(P<0)return[];const B=C.slice(0,P),G=C.slice(P+1);if(a.has(B))return[];if(_e(B,b))return[];const Q=f(B);if(!Q)return[];const U=Q.terminals.find(se=>se.id===G);return U?[{elId:B,lib:Q,localTerm:U,isLinker:I.has(B)}]:[]});if(N.length===0)return;const O=[],j=[];for(const C of N)C.localTerm.y>0?O.push(C):j.push(C);const A=C=>C.reduce((P,B)=>P+we(B.elId,B.lib.width),0),D=Math.max(A(O),A(j))+lt,M=Math.max(S.span,D);M!==S.span&&l.set(b,{...S,span:M});const F=l.get(b),R=(C,P)=>{if(C.length===0)return;const B=new Map;for(const H of C){const Y=Jm(b,H.elId,H.localTerm.id);Y!==void 0&&B.set(H.elId,Y)}C.sort((H,Y)=>{const ce=B.get(H.elId)??F.at[0],ve=B.get(Y.elId)??F.at[0];if(ce!==ve)return ce-ve;const Ae=we(H.elId,H.lib.width);return we(Y.elId,Y.lib.width)-Ae});const G=C.map(H=>we(H.elId,H.lib.width)),Q=G.reduce((H,Y)=>H+Y,0),U=Math.max(M,Q),se=(U-Q)/(C.length+1);let q=F.at[0]-U/2+se;const z=F.at[1]+P*Jn;for(let H=0;H<C.length;H++){const Y=C[H],ce=G[H],ve=q+ce/2;Y.isLinker?De.has(Y.elId)||De.set(Y.elId,ve):a.set(Y.elId,{at:[me(ve-Y.localTerm.x),me(z-Y.localTerm.y)],rot:0,mirror:!1}),q+=ce+se}};R(O,-1),R(j,1)},eh=b=>{if(a.has(b.elementId)||b.orientation==="horizontal")return;const k=f(b.elementId);if(!k)return;const S=b.attachments.filter(q=>l.has(q.busId));if(S.length<2)return;const N=S.slice().sort((q,z)=>($.get(q.busId)??0)-($.get(z.busId)??0)),O=N[0].busId,j=l.get(O),A=N[0].pin,D=N[N.length-1].pin,M=k.terminals.find(q=>q.id===A),F=k.terminals.find(q=>q.id===D);if(!M||!F)return;const R=M.y<=F.y?0:180,C=$.get(O)??0,P=S.filter(q=>($.get(q.busId)??0)===C),B=[];let G=0;for(const q of P){const z=ee(b,q.busId,q.pin);G=Math.max(G,z.extent);const H=z.head?a.get(z.head):void 0;H?B.push(H.at[0]):De.has(b.elementId)?B.push(De.get(b.elementId)):B.push(l.get(q.busId).at[0])}let Q;B.length>0?Q=B.reduce((q,z)=>q+z,0)/B.length:De.has(b.elementId)?Q=De.get(b.elementId):Q=j.at[0];const U=j.at[1]+G,se=R===0?[me(Q-M.x),me(U-M.y)]:[me(Q+M.x),me(U+M.y)];if(a.set(b.elementId,{at:se,rot:R,mirror:!1}),P.length>1){const q=a.get(b.elementId),z=Oe([M.x,M.y],q),H=ht(M.orientation,q);th(`${b.elementId}.${A}`,z,H,Q)}},th=(b,k,S,N)=>{const O=new Set([b]);let j=b,A=k,D=S;for(;;){const M=y.get(j)??[];let F,R=!1;for(const Ee of M){if(Ee.length>=3){R=!0;break}const qe=Ee.find(qt=>qt!==j);if(!(!qe||O.has(qe))){if(g(qe)){R=!0;break}F=qe;break}}if(R||!F)break;const C=F.indexOf(".");if(C<0)break;const P=F.slice(0,C),B=F.slice(C+1);if(g(P)||I.has(P)||a.has(P))break;const G=f(P);if(!G)break;const Q=G.terminals.find(Ee=>Ee.id===B);if(!Q)break;const U=dn(D),se=[A[0]+U[0]*at,A[1]+U[1]*at],q=Xn[D],z=Vn(Q.orientation,q),H=Oe([Q.x,Q.y],{at:[0,0],rot:z,mirror:!1}),Y=[me(N-H[0]),me(se[1]-H[1])];a.set(P,{at:Y,rot:z,mirror:!1}),O.add(F);const ce=G.terminals.find(Ee=>Ee.id!==B);if(!ce)break;const ve=`${P}.${ce.id}`;O.add(ve);const Ae={at:Y,rot:z,mirror:!1};A=Oe([ce.x,ce.y],Ae),D=ht(ce.orientation,Ae),j=ve}},nh=b=>{if(a.has(b.elementId)||b.orientation!=="horizontal")return;const k=f(b.elementId);if(!k)return;const S=b.attachments.filter(P=>l.has(P.busId));if(S.length<2)return;const N=S.map(P=>{const B=ee(b,P.busId,P.pin),G=B.head?a.get(B.head):void 0,Q=G?G.at[0]:l.get(P.busId).at[0];return{att:P,x:Q,extent:B.extent}});N.sort((P,B)=>P.x-B.x);const O=N[0],j=N[N.length-1],A=k.terminals.find(P=>P.id===O.att.pin),D=k.terminals.find(P=>P.id===j.att.pin);if(!A||!D)return;const M=A.y<=D.y?270:90,F=(O.x+j.x)/2,C=l.get(O.att.busId).at[1]+Math.max(O.extent,j.extent);a.set(b.elementId,{at:[me(F),me(C)],rot:M,mirror:!1})},oh=100;let _t=Un;for(let b=0;b<J.length;b++){const k=J[b],S=T.get(k);let N;if(b===0)N=Un;else{const j=T.get(J[b-1]);let A=0;for(const D of j)for(const M of S)(Ln=re.get(D))!=null&&Ln.get(M)&&(A=Math.max(A,ie(D,M)));A===0&&(A=it),N=_t+A}_t=N;let O=hp;for(const j of S){if(l.has(j)){_t=Math.max(_t,l.get(j).at[1]);continue}let A;if(b>0){const M=T.get(J[b-1]),F=[];for(const R of M){const C=(Bn=re.get(R))==null?void 0:Bn.get(j);if(!C||C.orientation!=="vertical")continue;const P=(Dn=C.attachments.find(G=>G.busId===R))==null?void 0:Dn.pin;if(!P)continue;const B=ee(C,R,P);B.head&&a.has(B.head)?F.push(a.get(B.head).at[0]):De.has(C.elementId)?F.push(De.get(C.elementId)):F.push(l.get(R).at[0])}F.length>0&&(A=F.reduce((R,C)=>R+C,0)/F.length)}if(A===void 0){const M=de.get(j)??Zn;A=O+M/2,O+=M+oh}const D=de.get(j)??Zn;l.set(j,{at:[me(A),me(N)],rot:0,span:D,axis:cn(0)})}for(const j of S)Qm(j);if(b>0)for(const j of E)a.has(j.elementId)||!j.attachments.some(D=>S.includes(D.busId))||eh(j);for(const j of E)j.orientation!=="horizontal"||a.has(j.elementId)||!j.attachments.every(D=>S.includes(D.busId))||nh(j)}const rh=b=>{if(g(b))return l.has(b);const k=b.indexOf(".");return k<0?!1:a.has(b.slice(0,k))};let Gt=!0,sh=t.length+4;for(;Gt&&sh-- >0;){Gt=!1;for(const b of p){if(b.length<2)continue;const k=[],S=new Map;for(const z of b){if(g(z))continue;const H=z.indexOf(".");if(H<0)continue;const Y=z.slice(0,H),ce=z.slice(H+1);if(a.has(Y)){k.push(z);continue}if(I.has(Y)||S.has(Y))continue;const ve=f(Y);if(!ve)continue;const Ae=ve.terminals.find(Ee=>Ee.id===ce);Ae&&S.set(Y,{ref:z,elId:Y,lib:ve,localTerm:Ae})}if(S.size===0||k.length===0)continue;const N=[...S.values()],O=new Map;for(const z of N)for(const H of y.get(z.ref)??[])for(const Y of H){if(Y===z.ref||g(Y)||!rh(Y))continue;const ce=Y;O.set(ce,(O.get(ce)??0)+1)}let j;if(O.size>0){let z=-1;for(const[H,Y]of O)(Y>z||Y===z&&(j===void 0||H<j))&&(z=Y,j=H)}if(j||(j=[...k].sort()[0]),!j)continue;const A=j.indexOf("."),D=j.slice(0,A),M=j.slice(A+1),F=f(D),R=a.get(D);if(!F||!R)continue;const C=F.terminals.find(z=>z.id===M);if(!C)continue;const P=Oe([C.x,C.y],R),B=ht(C.orientation,R),G=dn(B),Q=[-G[1],G[0]];N.sort((z,H)=>z.elId.localeCompare(H.elId));const U=N.map(z=>Math.max(z.lib.width,lt));let q=-U.reduce((z,H)=>z+H,0)/2;for(let z=0;z<N.length;z++){const H=N[z],Y=U[z],ce=q+Y/2;q+=Y;const ve=Xn[B],Ae=Vn(H.localTerm.orientation,ve),Ee=Oe([H.localTerm.x,H.localTerm.y],{at:[0,0],rot:Ae,mirror:!1}),qe=[P[0]+G[0]*at+Q[0]*ce,P[1]+G[1]*at+Q[1]*ce],qt=[me(qe[0]-Ee[0]),me(qe[1]-Ee[1])];a.set(H.elId,{at:qt,rot:Ae,mirror:!1}),Gt=!0}}}let Kt=0;for(const b of t){if(a.has(b.id))continue;const k=Kt%eo,S=Math.floor(Kt/eo);a.set(b.id,{at:[me(pp+k*xp),me(gp+S*yp)],rot:0,mirror:!1}),Kt++}return{devices:a,buses:l}}function me(e){return Math.round(e/Qn)*Qn}function wp(e,t){const n=e.ends[0],o=e.ends[1],r=no(n,t),s=no(o,t);if(r||s){const l=r?n:o,d=Xt(r?o:n,t);if(!d)return null;const f=t.buses.get(l);if(!f)return null;const{axis:m,at:g,span:h}=f.geometry,p=h/2;let y;if(m==="x")y=[ro(d[0],g[0]-p,g[0]+p),g[1]];else{const w=ro(d[1],g[1]-p,g[1]+p);y=[g[0],w]}return{wireId:e.id,path:oo(d,y)}}const i=Xt(n,t),a=Xt(o,t);return!i||!a?null:{wireId:e.id,path:oo(i,a)}}function no(e,t){return!e.includes(".")&&t.buses.has(e)}function Xt(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 oo(e,t){return e[0]===t[0]||e[1]===t[1]?[e,t]:[e,[e[0],t[1]],t]}function ro(e,t,n){return e<t?t:e>n?n:e}const xr="ammeter",yr="电流表 (A)",br="measurement",wr="-22 -42 44 44",vr=44,kr=44,_r='<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>',Sr=[{id:"t_top",x:0,y:-40,orientation:"n"}],jr={kind:"inline"},vp={id:xr,name:yr,category:br,viewBox:wr,width:vr,height:kr,svg:_r,terminals:Sr,source:jr},kp=Object.freeze(Object.defineProperty({__proto__:null,category:br,default:vp,height:kr,id:xr,name:yr,source:jr,svg:_r,terminals:Sr,viewBox:wr,width:vr},Symbol.toStringTag,{value:"Module"})),$r="arc-suppression-coil",Er="消弧线圈",Nr="grounding",Tr="中性点谐振接地:电感线圈连接到地",Cr="-12 -32 24 67",Ir=24,Ar=67,Mr='<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"/>',Pr=[{id:"t_top",x:0,y:-30,orientation:"n"}],Or={kind:"inline"},_p={id:$r,name:Er,category:Nr,description:Tr,viewBox:Cr,width:Ir,height:Ar,svg:Mr,terminals:Pr,source:Or},Sp=Object.freeze(Object.defineProperty({__proto__:null,category:Nr,default:_p,description:Tr,height:Ar,id:$r,name:Er,source:Or,svg:Mr,terminals:Pr,viewBox:Cr,width:Ir},Symbol.toStringTag,{value:"Module"})),Lr="arrester",Br="避雷器 (FBL)",Dr="protection",Rr="-7 -22 14 44",zr=14,Fr=44,Hr='<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"/>',Wr=[{id:"t1",x:0,y:-20,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],Gr={kind:"elmt",path:"91_en_60617/en_60617_07/en_60617_07_22/en_60617_07_22_03.elmt",qetEnglishName:"Surge diverter; Lightning arrester"},jp={id:Lr,name:Br,category:Dr,viewBox:Rr,width:zr,height:Fr,svg:Hr,terminals:Wr,source:Gr},$p=Object.freeze(Object.defineProperty({__proto__:null,category:Dr,default:jp,height:Fr,id:Lr,name:Br,source:Gr,svg:Hr,terminals:Wr,viewBox:Rr,width:zr},Symbol.toStringTag,{value:"Module"})),Kr="async-motor",qr="异步电动机",Yr="load",Xr="-62 -82 64 84",Vr=64,Ur=84,Zr='<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"/>',Jr=[{id:"t1",x:-50,y:-80,orientation:"n"},{id:"t2",x:-10,y:-80,orientation:"n"},{id:"t3",x:-30,y:-80,orientation:"n"}],Qr={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"},Ep={id:Kr,name:qr,category:Yr,viewBox:Xr,width:Vr,height:Ur,svg:Zr,terminals:Jr,source:Qr},Np=Object.freeze(Object.defineProperty({__proto__:null,category:Yr,default:Ep,height:Ur,id:Kr,name:qr,source:Qr,svg:Zr,terminals:Jr,viewBox:Xr,width:Vr},Symbol.toStringTag,{value:"Module"})),es="autotransformer",ts="自耦变压器",ns="transformer",os="-62 -112 64 144",rs=64,ss=144,is='<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"/>',as=[{id:"t1",x:-30,y:-110,orientation:"n"},{id:"t_bottom",x:-30,y:20,orientation:"s"}],ls={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_09/en_60617_06_09_06.elmt",qetEnglishName:"Auto-transformer, general symbol"},Tp={id:es,name:ts,category:ns,viewBox:os,width:rs,height:ss,svg:is,terminals:as,source:ls},Cp=Object.freeze(Object.defineProperty({__proto__:null,category:ns,default:Tp,height:ss,id:es,name:ts,source:ls,svg:is,terminals:as,viewBox:os,width:rs},Symbol.toStringTag,{value:"Module"})),cs="battery",ds="电池储能",us="storage",fs="-12 -12 29 24",ms=29,hs=24,ps='<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"/>',gs=[{id:"t_left",x:-10,y:0,orientation:"w"},{id:"t_right",x:15,y:0,orientation:"e"}],xs=[{name:"E",label:"容量",type:"number",unit:"kWh"}],ys={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_15/en_60617_06_15_01.elmt",qetEnglishName:"Battery cell"},Ip={id:cs,name:ds,category:us,viewBox:fs,width:ms,height:hs,svg:ps,terminals:gs,params:xs,source:ys},Ap=Object.freeze(Object.defineProperty({__proto__:null,category:us,default:Ip,height:hs,id:cs,name:ds,params:xs,source:ys,svg:ps,terminals:gs,viewBox:fs,width:ms},Symbol.toStringTag,{value:"Module"})),bs="breaker",ws="断路器 (QF)",vs="switching",ks="-7 -22 15 46",_s=15,Ss=46,js='<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>',$s=[{id:"t1",x:0,y:-20,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],Es=[{name:"open",type:"boolean",default:!1,label:"断开"}],Ns={x:6,y:-2,anchor:"start"},Ts={kind:"elmt",path:"11_singlepole/200_fuses_protective_gears/11_circuit_breakers/disjoncteur1.elmt",qetEnglishName:"Circuit-breaker"},Mp={id:bs,name:ws,category:vs,viewBox:ks,width:_s,height:Ss,svg:js,terminals:$s,state:Es,label:Ns,source:Ts},Pp=Object.freeze(Object.defineProperty({__proto__:null,category:vs,default:Mp,height:Ss,id:bs,label:Ns,name:ws,source:Ts,state:Es,svg:js,terminals:$s,viewBox:ks,width:_s},Symbol.toStringTag,{value:"Module"})),Cs="busbar",Is="母线段",As="busbar",Ms="可拉伸单母线段,多设备挂接",Ps="-42 -4 84 8",Os=84,Ls=8,Bs='<line x1="-40" y1="0" x2="40" y2="0" stroke="black" stroke-width="3" stroke-linecap="round" fill="none"/>',Ds=[{id:"tap",x:0,y:0,orientation:"n"}],Rs={axis:"x",minLength:20,naturalSpan:80},zs=[{name:"Un",label:"额定电压",type:"number",unit:"kV",showOnCanvas:!0}],Fs={x:0,y:-6,anchor:"middle"},Hs={kind:"inline"},Op={id:Cs,name:Is,category:As,description:Ms,viewBox:Ps,width:Os,height:Ls,svg:Bs,terminals:Ds,stretchable:Rs,params:zs,label:Fs,source:Hs},Lp=Object.freeze(Object.defineProperty({__proto__:null,category:As,default:Op,description:Ms,height:Ls,id:Cs,label:Fs,name:Is,params:zs,source:Hs,stretchable:Rs,svg:Bs,terminals:Ds,viewBox:Ps,width:Os},Symbol.toStringTag,{value:"Module"})),Ws="contactor",Gs="接触器 (KM)",Ks="motor-control",qs="主回路接触器, 通常配热继电器和电机使用。",Ys="-10 -42 15 64",Xs=15,Vs=64,Us='<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"/>',Zs=[{id:"t1",x:0,y:-40,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],Js=[{name:"open",type:"boolean",default:!0,label:"断开"}],Qs={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"},Bp={id:Ws,name:Gs,category:Ks,description:qs,viewBox:Ys,width:Xs,height:Vs,svg:Us,terminals:Zs,state:Js,source:Qs},Dp=Object.freeze(Object.defineProperty({__proto__:null,category:Ks,default:Bp,description:qs,height:Vs,id:Ws,name:Gs,source:Qs,state:Js,svg:Us,terminals:Zs,viewBox:Ys,width:Xs},Symbol.toStringTag,{value:"Module"})),ei="converter-bidir",ti="双向变流器 (PCS)",ni="renewable",oi="储能变流器:双向 AC ↔ DC",ri="-42 -42 44 48",si=44,ii=48,ai='<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"/>',li=[{id:"t_ac",x:-20,y:-40,orientation:"n"},{id:"t_dc",x:-20,y:0,orientation:"s"}],ci=[{name:"S",label:"容量",type:"number",unit:"MVA"}],di={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_14/en_60617_06_14_06.elmt",qetEnglishName:"Rectifier/inverter"},Rp={id:ei,name:ti,category:ni,description:oi,viewBox:ri,width:si,height:ii,svg:ai,terminals:li,params:ci,source:di},zp=Object.freeze(Object.defineProperty({__proto__:null,category:ni,default:Rp,description:oi,height:ii,id:ei,name:ti,params:ci,source:di,svg:ai,terminals:li,viewBox:ri,width:si},Symbol.toStringTag,{value:"Module"})),ui="ct",fi="电流互感器 (CT)",mi="instrument-transformer",hi="-42 -62 54 64",pi=54,gi=64,xi='<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"/>',yi=[{id:"t1",x:-30,y:0,orientation:"s"},{id:"t2",x:-30,y:-60,orientation:"n"}],bi={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_09/en_60617_06_09_10.elmt",qetEnglishName:"Current transformer, general symbol"},Fp={id:ui,name:fi,category:mi,viewBox:hi,width:pi,height:gi,svg:xi,terminals:yi,source:bi},Hp=Object.freeze(Object.defineProperty({__proto__:null,category:mi,default:Fp,height:gi,id:ui,name:fi,source:bi,svg:xi,terminals:yi,viewBox:hi,width:pi},Symbol.toStringTag,{value:"Module"})),wi="dc-combiner",vi="直流汇流箱",ki="renewable",_i="光伏组串汇流箱 (4 路输入示例)。",Si="-27 -32 54 64",ji=54,$i=64,Ei='<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>',Ni=[{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"}],Ti={kind:"inline"},Wp={id:wi,name:vi,category:ki,description:_i,viewBox:Si,width:ji,height:$i,svg:Ei,terminals:Ni,source:Ti},Gp=Object.freeze(Object.defineProperty({__proto__:null,category:ki,default:Wp,description:_i,height:$i,id:wi,name:vi,source:Ti,svg:Ei,terminals:Ni,viewBox:Si,width:ji},Symbol.toStringTag,{value:"Module"})),Ci="dc-disconnector",Ii="直流隔离开关",Ai="switching",Mi="DC isolating switch — 光伏组串 / 储能 直流侧隔离。",Pi="-12 -32 30 64",Oi=30,Li=64,Bi='<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"/>',Di=[{id:"t1",x:0,y:-30,orientation:"n"},{id:"t2",x:0,y:30,orientation:"s"}],Ri=[{name:"open",type:"boolean",default:!1,label:"断开"}],zi={kind:"inline"},Kp={id:Ci,name:Ii,category:Ai,description:Mi,viewBox:Pi,width:Oi,height:Li,svg:Bi,terminals:Di,state:Ri,source:zi},qp=Object.freeze(Object.defineProperty({__proto__:null,category:Ai,default:Kp,description:Mi,height:Li,id:Ci,name:Ii,source:zi,state:Ri,svg:Bi,terminals:Di,viewBox:Pi,width:Oi},Symbol.toStringTag,{value:"Module"})),Fi="disconnector",Hi="隔离开关 (QS)",Wi="switching",Gi="-10 -42 15 64",Ki=15,qi=64,Yi='<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"/>',Xi=[{id:"t1",x:0,y:-40,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],Vi=[{name:"open",type:"boolean",default:!1,label:"断开"}],Ui={x:6,y:-10,anchor:"start"},Zi={kind:"elmt",path:"91_en_60617/en_60617_07/en_60617_07_13/en_60617_07_13_06.elmt",qetEnglishName:"Disconnector; Isolator"},Yp={id:Fi,name:Hi,category:Wi,viewBox:Gi,width:Ki,height:qi,svg:Yi,terminals:Xi,state:Vi,label:Ui,source:Zi},Xp=Object.freeze(Object.defineProperty({__proto__:null,category:Wi,default:Yp,height:qi,id:Fi,label:Ui,name:Hi,source:Zi,state:Vi,svg:Yi,terminals:Xi,viewBox:Gi,width:Ki},Symbol.toStringTag,{value:"Module"})),Ji="earth",Qi="接地",ea="busbar",ta="-12 -17 24 34",na=24,oa=34,ra='<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"/>',sa=[{id:"t1",x:0,y:-15,orientation:"n"}],ia={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"},Vp={id:Ji,name:Qi,category:ea,viewBox:ta,width:na,height:oa,svg:ra,terminals:sa,source:ia},Up=Object.freeze(Object.defineProperty({__proto__:null,category:ea,default:Vp,height:oa,id:Ji,name:Qi,source:ia,svg:ra,terminals:sa,viewBox:ta,width:na},Symbol.toStringTag,{value:"Module"})),aa="earthing-switch",la="接地刀闸 (QE)",ca="switching",da="隔离开关 + 接地连接,单端口",ua="-12 -32 24 64",fa=24,ma=64,ha='<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"/>',pa=[{id:"t_top",x:0,y:-30,orientation:"n"}],ga=[{name:"open",type:"boolean",default:!0,label:"断开"}],xa={x:12,y:-8,anchor:"start"},ya={kind:"inline"},Zp={id:aa,name:la,category:ca,description:da,viewBox:ua,width:fa,height:ma,svg:ha,terminals:pa,state:ga,label:xa,source:ya},Jp=Object.freeze(Object.defineProperty({__proto__:null,category:ca,default:Zp,description:da,height:ma,id:aa,label:xa,name:la,source:ya,state:ga,svg:ha,terminals:pa,viewBox:ua,width:fa},Symbol.toStringTag,{value:"Module"})),ba="energy-meter",wa="电能表 (Wh)",va="measurement",ka="有功电能表 (kWh) — 服务入口 / 子表。",_a="-22 -36 44 72",Sa=44,ja=72,$a='<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"/>',Ea=[{id:"t1",x:0,y:-34,orientation:"n"},{id:"t2",x:0,y:34,orientation:"s"}],Na={kind:"elmt",path:"11_singlepole/500_home_installation/40_meters/wattheuremetre_08-04-03_en60617.elmt",qetEnglishName:"Watt hour meter (en_60617)"},Qp={id:ba,name:wa,category:va,description:ka,viewBox:_a,width:Sa,height:ja,svg:$a,terminals:Ea,source:Na},eg=Object.freeze(Object.defineProperty({__proto__:null,category:va,default:Qp,description:ka,height:ja,id:ba,name:wa,source:Na,svg:$a,terminals:Ea,viewBox:_a,width:Sa},Symbol.toStringTag,{value:"Module"})),Ta="ev-charger",Ca="EV 充电桩",Ia="load",Aa="电动汽车充电站 / 充电桩。",Ma="-17 -27 34 49",Pa=34,Oa=49,La='<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>',Ba=[{id:"t_top",x:0,y:-25,orientation:"n"}],Da={kind:"inline"},tg={id:Ta,name:Ca,category:Ia,description:Aa,viewBox:Ma,width:Pa,height:Oa,svg:La,terminals:Ba,source:Da},ng=Object.freeze(Object.defineProperty({__proto__:null,category:Ia,default:tg,description:Aa,height:Oa,id:Ta,name:Ca,source:Da,svg:La,terminals:Ba,viewBox:Ma,width:Pa},Symbol.toStringTag,{value:"Module"})),Ra="frequency-meter",za="频率表 (Hz)",Fa="measurement",Ha="-22 -42 44 44",Wa=44,Ga=44,Ka='<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>',qa=[{id:"t_top",x:0,y:-40,orientation:"n"}],Ya={kind:"elmt",path:"91_en_60617/en_60617_08/en_60617_08_02/en_60617_08_02_07.elmt",qetEnglishName:"Frequency meter"},og={id:Ra,name:za,category:Fa,viewBox:Ha,width:Wa,height:Ga,svg:Ka,terminals:qa,source:Ya},rg=Object.freeze(Object.defineProperty({__proto__:null,category:Fa,default:og,height:Ga,id:Ra,name:za,source:Ya,svg:Ka,terminals:qa,viewBox:Ha,width:Wa},Symbol.toStringTag,{value:"Module"})),Xa="fuse",Va="熔断器 (FU)",Ua="switching",Za="-7 -32 14 64",Ja=14,Qa=64,el='<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"/>',tl=[{id:"t1",x:0,y:30,orientation:"s"},{id:"t2",x:0,y:-30,orientation:"n"}],nl=[{name:"blown",type:"boolean",default:!1,label:"熔断"}],ol={x:7,y:-2,anchor:"start"},rl={kind:"elmt",path:"91_en_60617/en_60617_07/en_60617_07_21/en_60617_07_21_01.elmt",qetEnglishName:"Fuse, general symbol"},sg={id:Xa,name:Va,category:Ua,viewBox:Za,width:Ja,height:Qa,svg:el,terminals:tl,state:nl,label:ol,source:rl},ig=Object.freeze(Object.defineProperty({__proto__:null,category:Ua,default:sg,height:Qa,id:Xa,label:ol,name:Va,source:rl,state:nl,svg:el,terminals:tl,viewBox:Za,width:Ja},Symbol.toStringTag,{value:"Module"})),sl="generator",il="发电机 (G)",al="source",ll="-42 -42 44 44",cl=44,dl=44,ul='<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>',fl=[{id:"t_bottom",x:-20,y:0,orientation:"s"}],ml={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_16/en_60617_06_16_01.elmt",qetEnglishName:"Generator, general symbol"},ag={id:sl,name:il,category:al,viewBox:ll,width:cl,height:dl,svg:ul,terminals:fl,source:ml},lg=Object.freeze(Object.defineProperty({__proto__:null,category:al,default:ag,height:dl,id:sl,name:il,source:ml,svg:ul,terminals:fl,viewBox:ll,width:cl},Symbol.toStringTag,{value:"Module"})),hl="gfci-breaker",pl="GFCI 断路器 (RCBO)",gl="protection",xl="剩余电流断路器带过流保护 (UL943 / IEC 61009)。北美 GFCI / 欧洲 RCBO。",yl="-18 -22 22 44",bl=22,wl=44,vl='<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"/>',kl=[{id:"t1",x:0,y:-20,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],_l=[{name:"open",type:"boolean",default:!1,label:"断开"}],Sl=[{name:"In",label:"额定电流",type:"number",unit:"A"},{name:"IDn",label:"剩余动作电流",type:"number",unit:"mA",default:30}],jl={kind:"elmt",path:"11_singlepole/200_fuses_protective_gears/50_residual_current_circuit_breaker/rcbo.elmt",qetEnglishName:"Residual Circuit Breaker with Overload"},cg={id:hl,name:pl,category:gl,description:xl,viewBox:yl,width:bl,height:wl,svg:vl,terminals:kl,state:_l,params:Sl,source:jl},dg=Object.freeze(Object.defineProperty({__proto__:null,category:gl,default:cg,description:xl,height:wl,id:hl,name:pl,params:Sl,source:jl,state:_l,svg:vl,terminals:kl,viewBox:yl,width:bl},Symbol.toStringTag,{value:"Module"})),$l="grid-source",El="系统电源",Nl="source",Tl="无穷大母线 / 外部电网",Cl="-16 -31 32 53",Il=32,Al=53,Ml='<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"/>',Pl=[{id:"t_bottom",x:0,y:20,orientation:"s"}],Ol={kind:"inline"},ug={id:$l,name:El,category:Nl,description:Tl,viewBox:Cl,width:Il,height:Al,svg:Ml,terminals:Pl,source:Ol},fg=Object.freeze(Object.defineProperty({__proto__:null,category:Nl,default:ug,description:Tl,height:Al,id:$l,name:El,source:Ol,svg:Ml,terminals:Pl,viewBox:Cl,width:Il},Symbol.toStringTag,{value:"Module"})),Ll="grounding-transformer",Bl="接地变 (Z形)",Dl="grounding",Rl="星-曲折接线变压器,中性点接地用",zl="-62 -152 64 164",Fl=64,Hl=164,Wl='<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"/>',Gl=[{id:"t1",x:-30,y:10,orientation:"s"},{id:"t2",x:-30,y:-150,orientation:"n"}],Kl={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"},mg={id:Ll,name:Bl,category:Dl,description:Rl,viewBox:zl,width:Fl,height:Hl,svg:Wl,terminals:Gl,source:Kl},hg=Object.freeze(Object.defineProperty({__proto__:null,category:Dl,default:mg,description:Rl,height:Hl,id:Ll,name:Bl,source:Kl,svg:Wl,terminals:Gl,viewBox:zl,width:Fl},Symbol.toStringTag,{value:"Module"})),ql="inverter",Yl="逆变器 (DC→AC)",Xl="renewable",Vl="-42 -42 44 44",Ul=44,Zl=44,Jl='<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"/>',Ql=[{id:"t_dc",x:-20,y:-40,orientation:"n"},{id:"t_ac",x:-20,y:0,orientation:"s"}],ec={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_14/en_60617_06_14_05.elmt",qetEnglishName:"Inverter"},pg={id:ql,name:Yl,category:Xl,viewBox:Vl,width:Ul,height:Zl,svg:Jl,terminals:Ql,source:ec},gg=Object.freeze(Object.defineProperty({__proto__:null,category:Xl,default:pg,height:Zl,id:ql,name:Yl,source:ec,svg:Jl,terminals:Ql,viewBox:Vl,width:Ul},Symbol.toStringTag,{value:"Module"})),tc="load-switch",nc="负荷开关",oc="switching",rc="-10 -42 14 64",sc=14,ic=64,ac='<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"/>',lc=[{id:"t1",x:0,y:-40,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],cc=[{name:"open",type:"boolean",default:!1,label:"断开"}],dc={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"},xg={id:tc,name:nc,category:oc,viewBox:rc,width:sc,height:ic,svg:ac,terminals:lc,state:cc,source:dc},yg=Object.freeze(Object.defineProperty({__proto__:null,category:oc,default:xg,height:ic,id:tc,name:nc,source:dc,state:cc,svg:ac,terminals:lc,viewBox:rc,width:sc},Symbol.toStringTag,{value:"Module"})),uc="load",fc="负荷",mc="load",hc="抽象负荷(电流流出箭头)",pc="-8 -22 16 46",gc=16,xc=46,yc='<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"/>',bc=[{id:"t_top",x:0,y:-20,orientation:"n"}],wc=[{name:"P",label:"有功功率",type:"number",unit:"MW",showOnCanvas:!0},{name:"cosphi",label:"功率因数",type:"number"}],vc={x:6,y:0,anchor:"start"},kc={kind:"inline"},bg={id:uc,name:fc,category:mc,description:hc,viewBox:pc,width:gc,height:xc,svg:yc,terminals:bc,params:wc,label:vc,source:kc},wg=Object.freeze(Object.defineProperty({__proto__:null,category:mc,default:bg,description:hc,height:xc,id:uc,label:vc,name:fc,params:wc,source:kc,svg:yc,terminals:bc,viewBox:pc,width:gc},Symbol.toStringTag,{value:"Module"})),_c="motor-starter",Sc="电机启动器",jc="motor-control",$c="电机启动器 (IEC 60617 通用符号)。",Ec="-22 -27 44 54",Nc=44,Tc=54,Cc='<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"/>',Ic=[{id:"t_top",x:0,y:-25,orientation:"n"},{id:"t_bottom",x:0,y:25,orientation:"s"}],Ac={kind:"elmt",path:"91_en_60617/en_60617_07/en_60617_07_14/en_60617_07_14_01.elmt",qetEnglishName:"Motor starter, general symbol"},vg={id:_c,name:Sc,category:jc,description:$c,viewBox:Ec,width:Nc,height:Tc,svg:Cc,terminals:Ic,source:Ac},kg=Object.freeze(Object.defineProperty({__proto__:null,category:jc,default:vg,description:$c,height:Tc,id:_c,name:Sc,source:Ac,svg:Cc,terminals:Ic,viewBox:Ec,width:Nc},Symbol.toStringTag,{value:"Module"})),Mc="ngr",Pc="中性点电阻 (NGR)",Oc="grounding",Lc="小电阻接地:连接变压器中性点到地",Bc="-12 -32 24 62",Dc=24,Rc=62,zc='<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"/>',Fc=[{id:"t_top",x:0,y:-30,orientation:"n"}],Hc=[{name:"R",label:"电阻",type:"number",unit:"Ω"}],Wc={kind:"inline"},_g={id:Mc,name:Pc,category:Oc,description:Lc,viewBox:Bc,width:Dc,height:Rc,svg:zc,terminals:Fc,params:Hc,source:Wc},Sg=Object.freeze(Object.defineProperty({__proto__:null,category:Oc,default:_g,description:Lc,height:Rc,id:Mc,name:Pc,params:Hc,source:Wc,svg:zc,terminals:Fc,viewBox:Bc,width:Dc},Symbol.toStringTag,{value:"Module"})),Gc="pt",Kc="电压互感器 (PT)",qc="instrument-transformer",Yc="-22 -42 44 115",Xc=44,Vc=115,Uc='<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"/>',Zc=[{id:"t1",x:0,y:71,orientation:"s"},{id:"t2",x:0,y:-40,orientation:"n"}],Jc={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_13/en_60617_06_13_01A.elmt",qetEnglishName:"Voltage transformer"},jg={id:Gc,name:Kc,category:qc,viewBox:Yc,width:Xc,height:Vc,svg:Uc,terminals:Zc,source:Jc},$g=Object.freeze(Object.defineProperty({__proto__:null,category:qc,default:jg,height:Vc,id:Gc,name:Kc,source:Jc,svg:Uc,terminals:Zc,viewBox:Yc,width:Xc},Symbol.toStringTag,{value:"Module"})),Qc="pv",ed="光伏组件",td="renewable",nd="-33 -22 85 64",od=85,rd=64,sd='<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"/>',id=[{id:"t_dc",x:50,y:10,orientation:"e"}],ad={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_18/en_60617_06_18_06.elmt",qetEnglishName:"Photovoltaic generator"},Eg={id:Qc,name:ed,category:td,viewBox:nd,width:od,height:rd,svg:sd,terminals:id,source:ad},Ng=Object.freeze(Object.defineProperty({__proto__:null,category:td,default:Eg,height:rd,id:Qc,name:ed,source:ad,svg:sd,terminals:id,viewBox:nd,width:od},Symbol.toStringTag,{value:"Module"})),ld="rcd",cd="剩余电流装置 (RCD)",dd="protection",ud="不带过流保护的剩余电流断路器 (IEC 61008)。",fd="-12 -22 19 44",md=19,hd=44,pd='<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"/>',gd=[{id:"t1",x:0,y:-20,orientation:"n"},{id:"t2",x:0,y:20,orientation:"s"}],xd=[{name:"open",type:"boolean",default:!1,label:"断开"}],yd=[{name:"IDn",label:"剩余动作电流",type:"number",unit:"mA",default:30}],bd={kind:"elmt",path:"11_singlepole/200_fuses_protective_gears/50_residual_current_circuit_breaker/ddr1.elmt",qetEnglishName:"Residual Circuit Breaker with Overload"},Tg={id:ld,name:cd,category:dd,description:ud,viewBox:fd,width:md,height:hd,svg:pd,terminals:gd,state:xd,params:yd,source:bd},Cg=Object.freeze(Object.defineProperty({__proto__:null,category:dd,default:Tg,description:ud,height:hd,id:ld,name:cd,params:yd,source:bd,state:xd,svg:pd,terminals:gd,viewBox:fd,width:md},Symbol.toStringTag,{value:"Module"})),wd="recloser",vd="重合闸 (Recloser)",kd="protection",_d="中压自动重合闸开关。",Sd="-12 -32 36 64",jd=36,$d=64,Ed='<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>',Nd=[{id:"t1",x:0,y:-30,orientation:"n"},{id:"t2",x:0,y:30,orientation:"s"}],Td=[{name:"open",type:"boolean",default:!1,label:"断开"}],Cd={kind:"inline"},Ig={id:wd,name:vd,category:kd,description:_d,viewBox:Sd,width:jd,height:$d,svg:Ed,terminals:Nd,state:Td,source:Cd},Ag=Object.freeze(Object.defineProperty({__proto__:null,category:kd,default:Ig,description:_d,height:$d,id:wd,name:vd,source:Cd,state:Td,svg:Ed,terminals:Nd,viewBox:Sd,width:jd},Symbol.toStringTag,{value:"Module"})),Id="rectifier",Ad="整流器 (AC→DC)",Md="renewable",Pd="-42 -42 44 44",Od=44,Ld=44,Bd='<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"/>',Dd=[{id:"t_ac",x:-20,y:-40,orientation:"n"},{id:"t_dc",x:-20,y:0,orientation:"s"}],Rd={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_14/en_60617_06_14_03.elmt",qetEnglishName:"Rectifier"},Mg={id:Id,name:Ad,category:Md,viewBox:Pd,width:Od,height:Ld,svg:Bd,terminals:Dd,source:Rd},Pg=Object.freeze(Object.defineProperty({__proto__:null,category:Md,default:Mg,height:Ld,id:Id,name:Ad,source:Rd,svg:Bd,terminals:Dd,viewBox:Pd,width:Od},Symbol.toStringTag,{value:"Module"})),zd="series-reactor",Fd="串联电抗器",Hd="compensation",Wd="与并联电抗器同符号;通过用法区分。",Gd="-62 -82 64 104",Kd=64,qd=104,Yd='<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"/>',Xd=[{id:"t1",x:-30,y:-80,orientation:"n"},{id:"t_bottom",x:-30,y:20,orientation:"s"}],Vd={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_09/en_60617_06_09_08.elmt",qetEnglishName:"Choke; Reactor, general symbol"},Og={id:zd,name:Fd,category:Hd,description:Wd,viewBox:Gd,width:Kd,height:qd,svg:Yd,terminals:Xd,source:Vd},Lg=Object.freeze(Object.defineProperty({__proto__:null,category:Hd,default:Og,description:Wd,height:qd,id:zd,name:Fd,source:Vd,svg:Yd,terminals:Xd,viewBox:Gd,width:Kd},Symbol.toStringTag,{value:"Module"})),Ud="shunt-capacitor",Zd="并联电容器",Jd="compensation",Qd="-7 -23 14 27",eu=14,tu=27,nu='<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"/>',ou=[{id:"t1",x:0,y:-21,orientation:"n"},{id:"t_bottom",x:0,y:2,orientation:"s"}],ru=[{name:"Q",label:"无功容量",type:"number",unit:"Mvar"},{name:"stages",label:"分组数",type:"number"}],su={kind:"elmt",path:"11_singlepole/395_electronics_semiconductors/20_capacitors/capacite.elmt",qetEnglishName:"Capacitor"},Bg={id:Ud,name:Zd,category:Jd,viewBox:Qd,width:eu,height:tu,svg:nu,terminals:ou,params:ru,source:su},Dg=Object.freeze(Object.defineProperty({__proto__:null,category:Jd,default:Bg,height:tu,id:Ud,name:Zd,params:ru,source:su,svg:nu,terminals:ou,viewBox:Qd,width:eu},Symbol.toStringTag,{value:"Module"})),iu="shunt-reactor",au="并联电抗器",lu="compensation",cu="-62 -82 64 104",du=64,uu=104,fu='<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"/>',mu=[{id:"t1",x:-30,y:-80,orientation:"n"},{id:"t_bottom",x:-30,y:20,orientation:"s"}],hu={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_09/en_60617_06_09_08.elmt",qetEnglishName:"Choke; Reactor, general symbol"},Rg={id:iu,name:au,category:lu,viewBox:cu,width:du,height:uu,svg:fu,terminals:mu,source:hu},zg=Object.freeze(Object.defineProperty({__proto__:null,category:lu,default:Rg,height:uu,id:iu,name:au,source:hu,svg:fu,terminals:mu,viewBox:cu,width:du},Symbol.toStringTag,{value:"Module"})),pu="soft-starter",gu="软启动器",xu="motor-control",yu="电机软启动器 (晶闸管降压启动)。",bu="-22 -42 44 84",wu=44,vu=84,ku='<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"/>',_u=[{id:"t_in",x:0,y:-40,orientation:"n"},{id:"t_out",x:0,y:40,orientation:"s"}],Su={kind:"inline"},Fg={id:pu,name:gu,category:xu,description:yu,viewBox:bu,width:wu,height:vu,svg:ku,terminals:_u,source:Su},Hg=Object.freeze(Object.defineProperty({__proto__:null,category:xu,default:Fg,description:yu,height:vu,id:pu,name:gu,source:Su,svg:ku,terminals:_u,viewBox:bu,width:wu},Symbol.toStringTag,{value:"Module"})),ju="sync-motor",$u="同步电动机",Eu="load",Nu="-62 -82 64 114",Tu=64,Cu=114,Iu='<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"/>',Au=[{id:"t1",x:-10,y:-80,orientation:"n"},{id:"t2",x:-50,y:-80,orientation:"n"}],Mu={kind:"elmt",path:"91_en_60617/en_60617_06/en_60617_06_07/en_60617_06_07_02.elmt",qetEnglishName:"Synchronous motor, single-phase"},Wg={id:ju,name:$u,category:Eu,viewBox:Nu,width:Tu,height:Cu,svg:Iu,terminals:Au,source:Mu},Gg=Object.freeze(Object.defineProperty({__proto__:null,category:Eu,default:Wg,height:Cu,id:ju,name:$u,source:Mu,svg:Iu,terminals:Au,viewBox:Nu,width:Tu},Symbol.toStringTag,{value:"Module"})),Pu="thermal-overload",Ou="热过载继电器",Lu="motor-control",Bu="电机热过载保护继电器, 通常串接在接触器和电机之间。",Du="-9 -32 19 64",Ru=19,zu=64,Fu='<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"/>',Hu=[{id:"t1",x:0,y:-30,orientation:"n"},{id:"t2",x:0,y:30,orientation:"s"}],Wu=[{name:"tripped",type:"boolean",default:!1,label:"动作"}],Gu={kind:"inline"},Kg={id:Pu,name:Ou,category:Lu,description:Bu,viewBox:Du,width:Ru,height:zu,svg:Fu,terminals:Hu,state:Wu,source:Gu},qg=Object.freeze(Object.defineProperty({__proto__:null,category:Lu,default:Kg,description:Bu,height:zu,id:Pu,name:Ou,source:Gu,state:Wu,svg:Fu,terminals:Hu,viewBox:Du,width:Ru},Symbol.toStringTag,{value:"Module"})),Ku="transfer-switch",qu="切换开关 (ATS)",Yu="switching",Xu="双源切换开关 (Automatic / Manual Transfer Switch)。两个电源输入 + 一个负荷输出, 互锁不并联。",Vu="-27 -32 51 64",Uu=51,Zu=64,Ju='<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"/>',Qu=[{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"}],ef=[{name:"position",type:"string",default:"normal",label:"位置 (normal/emergency/off)"}],tf={kind:"inline"},Yg={id:Ku,name:qu,category:Yu,description:Xu,viewBox:Vu,width:Uu,height:Zu,svg:Ju,terminals:Qu,state:ef,source:tf},Xg=Object.freeze(Object.defineProperty({__proto__:null,category:Yu,default:Yg,description:Xu,height:Zu,id:Ku,name:qu,source:tf,state:ef,svg:Ju,terminals:Qu,viewBox:Vu,width:Uu},Symbol.toStringTag,{value:"Module"})),nf="transformer-2w",of="双绕组变压器",rf="transformer",sf="-62 -142 64 144",af=64,lf=144,cf='<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"/>',df=[{id:"t1",x:-30,y:0,orientation:"s"},{id:"t2",x:-30,y:-140,orientation:"n"}],uf=[{name:"S",label:"容量",type:"number",unit:"MVA",showOnCanvas:!0},{name:"ratio",label:"变比",type:"string",showOnCanvas:!0}],ff={x:4,y:-68,anchor:"start"},mf={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"},Vg={id:nf,name:of,category:rf,viewBox:sf,width:af,height:lf,svg:cf,terminals:df,params:uf,label:ff,source:mf},Ug=Object.freeze(Object.defineProperty({__proto__:null,category:rf,default:Vg,height:lf,id:nf,label:ff,name:of,params:uf,source:mf,svg:cf,terminals:df,viewBox:sf,width:af},Symbol.toStringTag,{value:"Module"})),hf="transformer-3w",pf="三绕组变压器",gf="transformer",xf="-82 -131 114 133",yf=114,bf=133,wf='<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"/>',vf=[{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"}],kf={x:4,y:-64,anchor:"start"},_f={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"},Zg={id:hf,name:pf,category:gf,viewBox:xf,width:yf,height:bf,svg:wf,terminals:vf,label:kf,source:_f},Jg=Object.freeze(Object.defineProperty({__proto__:null,category:gf,default:Zg,height:bf,id:hf,label:kf,name:pf,source:_f,svg:wf,terminals:vf,viewBox:xf,width:yf},Symbol.toStringTag,{value:"Module"})),Sf="vfd",jf="变频器 (VFD)",$f="motor-control",Ef="Variable Frequency Drive — 异步电动机调速。",Nf="-24 -42 48 84",Tf=48,Cf=84,If='<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"/>',Af=[{id:"t_in",x:0,y:-40,orientation:"n"},{id:"t_out",x:0,y:40,orientation:"s"}],Mf={kind:"inline"},Qg={id:Sf,name:jf,category:$f,description:Ef,viewBox:Nf,width:Tf,height:Cf,svg:If,terminals:Af,source:Mf},e0=Object.freeze(Object.defineProperty({__proto__:null,category:$f,default:Qg,description:Ef,height:Cf,id:Sf,name:jf,source:Mf,svg:If,terminals:Af,viewBox:Nf,width:Tf},Symbol.toStringTag,{value:"Module"})),Pf="voltmeter",Of="电压表 (V)",Lf="measurement",Bf="-22 -42 44 44",Df=44,Rf=44,zf='<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>',Ff=[{id:"t_top",x:0,y:-40,orientation:"n"}],Hf={kind:"elmt",path:"91_en_60617/en_60617_08/en_60617_08_02/en_60617_08_02_01.elmt",qetEnglishName:"Voltmeter"},t0={id:Pf,name:Of,category:Lf,viewBox:Bf,width:Df,height:Rf,svg:zf,terminals:Ff,source:Hf},n0=Object.freeze(Object.defineProperty({__proto__:null,category:Lf,default:t0,height:Rf,id:Pf,name:Of,source:Hf,svg:zf,terminals:Ff,viewBox:Bf,width:Df},Symbol.toStringTag,{value:"Module"})),Wf="wattmeter",Gf="功率表 (W)",Kf="measurement",qf="-22 -42 44 44",Yf=44,Xf=44,Vf='<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>',Uf=[{id:"t_top",x:0,y:-40,orientation:"n"}],Zf={kind:"elmt",path:"91_en_60617/en_60617_08/en_60617_08_03/en_60617_08_03_01.elmt",qetEnglishName:"Recording wattmeter"},o0={id:Wf,name:Gf,category:Kf,viewBox:qf,width:Yf,height:Xf,svg:Vf,terminals:Uf,source:Zf},r0=Object.freeze(Object.defineProperty({__proto__:null,category:Kf,default:o0,height:Xf,id:Wf,name:Gf,source:Zf,svg:Vf,terminals:Uf,viewBox:qf,width:Yf},Symbol.toStringTag,{value:"Module"})),Jf="wind-turbine",Qf="风力发电机",em="renewable",tm="风机:发电机 + 三叶轮标记",nm="-22 -46 44 68",om=44,rm=68,sm='<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"/>',im=[{id:"t_bottom",x:0,y:20,orientation:"s"}],am={kind:"inline"},s0={id:Jf,name:Qf,category:em,description:tm,viewBox:nm,width:om,height:rm,svg:sm,terminals:im,source:am},i0=Object.freeze(Object.defineProperty({__proto__:null,category:em,default:s0,description:tm,height:rm,id:Jf,name:Qf,source:am,svg:sm,terminals:im,viewBox:nm,width:om},Symbol.toStringTag,{value:"Module"})),a0=Object.assign({"./ammeter.json":kp,"./arc-suppression-coil.json":Sp,"./arrester.json":$p,"./async-motor.json":Np,"./autotransformer.json":Cp,"./battery.json":Ap,"./breaker.json":Pp,"./busbar.json":Lp,"./contactor.json":Dp,"./converter-bidir.json":zp,"./ct.json":Hp,"./dc-combiner.json":Gp,"./dc-disconnector.json":qp,"./disconnector.json":Xp,"./earth.json":Up,"./earthing-switch.json":Jp,"./energy-meter.json":eg,"./ev-charger.json":ng,"./frequency-meter.json":rg,"./fuse.json":ig,"./generator.json":lg,"./gfci-breaker.json":dg,"./grid-source.json":fg,"./grounding-transformer.json":hg,"./inverter.json":gg,"./load-switch.json":yg,"./load.json":wg,"./motor-starter.json":kg,"./ngr.json":Sg,"./pt.json":$g,"./pv.json":Ng,"./rcd.json":Cg,"./recloser.json":Ag,"./rectifier.json":Pg,"./series-reactor.json":Lg,"./shunt-capacitor.json":Dg,"./shunt-reactor.json":zg,"./soft-starter.json":Hg,"./sync-motor.json":Gg,"./thermal-overload.json":qg,"./transfer-switch.json":Xg,"./transformer-2w.json":Ug,"./transformer-3w.json":Jg,"./vfd.json":e0,"./voltmeter.json":n0,"./wattmeter.json":r0,"./wind-turbine.json":i0}),lm=Object.values(a0).map(e=>e.default),Ge=Object.fromEntries(lm.map(e=>[e.id,e])),so=["busbar","switching","protection","motor-control","transformer","instrument-transformer","measurement","source","load","storage","compensation","grounding","renewable"],l0=(()=>{var t;const e={};for(const n of lm)(e[t=n.category]??(e[t]=[])).push(n);return e})(),un=new Map(Object.entries(Ge));function cm(e){return Ge[e]}function c0(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 d0=320;function Fe(e){var f,m,g,h;const t=hr(),n=new Map;e.elements.forEach((p,y)=>{if(n.has(p.id)){t.diagnostics.push({code:"E001",severity:"error",message:xe("compile.duplicateId",{id:p.id}),pointer:`/elements/${y}`});return}n.set(p.id,p);const w=un.get(p.kind);w||t.diagnostics.push({code:"E003",severity:"error",message:`${xe("compile.unknownKind",{kind:p.kind})} (id=${p.id})`,pointer:`/elements/${y}`}),t.elements.set(p.id,{element:p,libraryDef:w})});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:xe("compile.duplicateId",{id:p.id}),pointer:`/buses/${y}`});return}if(o.set(p.id,p),p.layout){const w=p.layout.rot??0;r.set(p.id,{at:p.layout.at,span:p.layout.span,rot:w,axis:cn(w)})}});const s=p=>!p.includes(".")&&o.has(p),i=(p,y)=>{if(s(p))return!0;const w=p.indexOf(".");if(w<=0)return t.diagnostics.push({code:"E003",severity:"error",message:xe("compile.invalidTermRef",{ref:p}),pointer:y}),!1;const v=p.slice(0,w),E=p.slice(w+1),I=t.elements.get(v);if(!I)return t.diagnostics.push({code:"E002",severity:"error",message:xe("compile.elementMissing",{id:v}),pointer:y}),!1;if(!I.libraryDef)return!1;if(!I.libraryDef.terminals.find(L=>L.id===E)){const L=I.libraryDef.terminals.map(W=>W.id).join(", ");return t.diagnostics.push({code:"E003",severity:"error",message:xe("compile.missingPin",{id:v,kind:I.element.kind,pin:E,available:L}),pointer:y}),!1}return!0},a=[];(e.wires??[]).forEach((p,y)=>{const w=`/wires/${y}`,v=i(p.ends[0],w),E=i(p.ends[1],w);v&&E&&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,pr(y)):t.diagnostics.push({code:"E004",severity:"error",message:xe("compile.layoutMissingElement",{id:p}),pointer:`/layout/${p}`});const u=bp({elements:e.elements,buses:e.buses??[],wires:a,library:un,userLayout:l,userBusLayout:r});t.layout=u.devices;for(const[p,y]of u.buses){const w=o.get(p);w&&t.buses.set(p,{bus:w,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:((m=y.layout)==null?void 0:m.span)??d0,rot:((g=y.layout)==null?void 0:g.rot)??0,axis:cn(((h=y.layout)==null?void 0:h.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 w=[];for(const v of p.libraryDef.terminals){const E=`${p.element.id}.${v.id}`,I=Oe([v.x,v.y],y),L=ht(v.orientation,y);t.terminals.set(E,{ref:E,elementId:p.element.id,pin:v.id,world:I,orientation:L}),w.push(E)}t.elementToTerminals.set(p.element.id,w)}const d=new gr;for(const p of a)d.add(p.ends[0]),d.add(p.ends[1]),d.union(p.ends[0],p.ends[1]);for(const[,p]of d.groups()){const y=c0(p);t.nodes.set(y,{id:y,terminals:p});for(const w of p)t.terminalToNode.set(w,y)}for(const p of t.elements.values()){const y=t.elementToTerminals.get(p.element.id)??[];if(y.length===0)continue;y.some(v=>t.terminalToNode.has(v))||t.diagnostics.push({code:"W001",severity:"warning",message:xe("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:xe("compile.elementUnconnected",{id:p})});for(const p of a){if(p.path&&p.path.length>=2){t.wireRenders.set(p.id,{wireId:p.id,path:p.path,userEdited:!0});continue}const y=wp(p,t);y&&t.wireRenders.set(p.id,y)}return t}const u0={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"},io="B";function dm(e){return new Set([...e.elements.map(t=>t.id),...(e.buses??[]).map(t=>t.id)])}function gt(e,t){const n=u0[t]??t,o=dm(e);let r=1;for(;o.has(`${n}${r}`);)r++;return`${n}${r}`}function fn(e){const t=dm(e);let n=1;for(;t.has(`${io}${n}`);)n++;return`${io}${n}`}function f0(e){const t=new Set((e.annotations??[]).map(o=>o.id));let n=1;for(;t.has(`a${n}`);)n++;return`a${n}`}function xt(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 ao={version:"1",elements:[]},m0=100,lo=20;function h0(){if(typeof window>"u")return"select";try{return window.matchMedia("(pointer: coarse)").matches?"pan":"select"}catch{return"select"}}const x=Bt()(up((e,t)=>({diagram:ao,internal:Fe(ao),fileSession:null,activeTool:h0(),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:Fe(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:Fe(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>=m0?r.slice(1):r;e({diagram:s,internal:Fe(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:Fe(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:Fe(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:p0(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(m=>s.has(m.id)).map(m=>structuredClone(m)),a=(o.buses??[]).filter(m=>s.has(m.id)).map(m=>structuredClone(m)),l={};for(const m of n)if(s.has(m)&&!r.buses.has(m)){const g=(f=o.layout)==null?void 0:f[m];if(g){l[m]=structuredClone(g);continue}const h=r.layout.get(m);h&&(l[m]=jt(h))}const u={};for(const m of n){const g=r.buses.get(m);g&&(u[m]=Xe(g.geometry))}const d=(o.wires??[]).filter(m=>m.ends.every(g=>s.has(Vt(g)))).map(m=>structuredClone(m));e({clipboard:{elements:i,buses:a,placements:l,busLayouts:u,wires:d},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=lo*s,a=lo*s,l=new Map;let u=r;for(const f of n.elements){const m=gt(u,f.kind);l.set(f.id,m),u={...u,elements:[...u.elements,{id:m,kind:f.kind}]}}for(const f of n.buses){const m=fn(u);l.set(f.id,m),u={...u,buses:[...u.buses??[],{id:m}]}}const d=f=>{const m=f.indexOf("."),g=m<0?f:f.slice(0,m),h=l.get(g);return h?m<0?h:`${h}${f.slice(m)}`:f};t().dispatch(f=>{const m=n.elements.map(w=>{const v=structuredClone(w);return v.id=l.get(w.id),v}),g=n.buses.map(w=>{const v=structuredClone(w);v.id=l.get(w.id);const E=n.busLayouts[w.id];return E&&(v.layout={...E,at:[E.at[0]+i,E.at[1]+a]}),v}),h={...f.layout??{}};for(const[w,v]of l){const E=n.placements[w];E&&(h[v]={...E,at:[E.at[0]+i,E.at[1]+a]})}const p=n.wires.map(w=>{const v=[d(w.ends[0]),d(w.ends[1])];return{id:xt(v[0],v[1]),ends:v}}),y=g0(f.wires??[],p);return{...f,elements:[...f.elements,...m],buses:g.length?[...f.buses??[],...g]:f.buses,wires:y.length?y:void 0,layout:Object.keys(h).length?h: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(u=>u.layout);if(!o&&!r)return n;const{layout:s,...i}=n,a=(l=n.buses)==null?void 0:l.map(u=>{const{layout:d,...f}=u;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[u,d]of Object.entries(i)){if(o.has(u)){s=!0;continue}l[u]=d}s&&(i=Object.keys(l).length?l:void 0)}let a=r.buses;if(a){const l=a.map(u=>{if(o.has(u.id)&&u.layout){s=!0;const{layout:d,...f}=u;return f}return u});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 u=n.layout.get(l.id);u&&(s[l.id]=jt(u))}const i=[];if((o.buses??[]).forEach((l,u)=>{l.layout||n.buses.has(l.id)&&i.push({idx:u,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 u=n.buses.get(l.id);return!l.layout&&u?{...l,layout:Xe(u.geometry)}:l})),{...o,layout:{...r,...s},buses:a}})},fillUnplacedSelection:()=>{const{selection:n,internal:o}=t();n.length!==0&&t().dispatch(r=>{var u;const s=r.layout??{},i={},a=new Map;for(const d of n)if(o.buses.has(d)){const f=o.buses.get(d);(u=r.buses)!=null&&u.find(m=>m.id===d&&m.layout)||a.set(d,Xe(f.geometry))}else{if(s[d])continue;const f=o.layout.get(d);f&&(i[d]=jt(f))}if(Object.keys(i).length===0&&a.size===0)return r;let l=r.buses;return a.size>0&&l&&(l=l.map(d=>a.has(d.id)?{...d,layout:a.get(d.id)}:d)),{...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,u]of n){if(o.buses.has(l)){i.set(l,u);continue}const d=o.layout.get(l),f=s[l]??(d?jt(d):{at:[0,0]});s[l]={...f,at:[f.at[0]+u[0],f.at[1]+u[1]]}}let a=r.buses;return i.size>0&&(a=(r.buses??[]).map(l=>{const u=i.get(l.id);if(!u)return l;const d=l.layout??Xe(o.buses.get(l.id).geometry);return{...l,layout:{...d,at:[d.at[0]+u[0],d.at[1]+u[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(u=>!o.has(u.id)),i=(r.buses??[]).filter(u=>!o.has(u.id)),a=(r.wires??[]).filter(u=>!o.has(Vt(u.ends[0]))&&!o.has(Vt(u.ends[1]))),l=r.layout?Object.fromEntries(Object.entries(r.layout).filter(([u])=>!o.has(u))):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}=t();n&&(t().dispatch(o=>{const r=(o.wires??[]).filter(s=>s.id!==n);return r.length===(o.wires??[]).length?o:{...o,wires:r.length?r: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 d of i){if(l[d])continue;const f=o.layout.get(d);if(!f)continue;const m={at:f.at};f.rot&&(m.rot=f.rot),f.mirror&&(m.mirror=f.mirror),l[d]=m}const u=(a.wires??[]).filter(d=>!s.has(d.ends[0])&&!s.has(d.ends[1]));return{...a,wires:u.length?u: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 u,d,f,m;const i={...s.layout??{}},a=new Map;for(const g of o){if(r.buses.has(g)){const y=r.buses.get(g),v=(((((f=(d=(u=s.buses)==null?void 0:u.find(E=>E.id===g))==null?void 0:d.layout)==null?void 0:f.rot)??y.geometry.rot??0)+n)%360+360)%360;a.set(g,v);continue}const h=i[g]??{at:((m=r.layout.get(g))==null?void 0:m.at)??[0,0]},p=(((h.rot??0)+n)%360+360)%360;i[g]={...h,rot:p}}let l=s.buses;return a.size>0&&(l=(s.buses??[]).map(g=>{if(!a.has(g.id))return g;const h=g.layout??Xe(r.buses.get(g.id).geometry);return{...g,layout:{...h,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=gt(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=fn(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=xt(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]}]}})},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)?Xe(a.buses.get(n).geometry):{at:[0,0],span:320}),u={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:u}});return{...r,buses:s}})},addAnnotation:(n,o="")=>{const r=f0(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:mr(()=>localStorage),partialize:e=>({diagram:e.diagram,activeTool:e.activeTool,placeKind:e.placeKind,lastPlaceKind:e.lastPlaceKind}),onRehydrateStorage:()=>e=>{e!=null&&e.diagram&&(e.internal=Fe(e.diagram))}}));function p0(e){return Array.from(new Set(e))}function Vt(e){const t=e.indexOf(".");return t<0?e:e.slice(0,t)}function g0(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 jt(e){return{at:[e.at[0],e.at[1]],...e.rot?{rot:e.rot}:{},...e.mirror?{mirror:e.mirror}:{}}}function Xe(e){return{at:[e.at[0],e.at[1]],span:e.span,...e.rot?{rot:e.rot}:{}}}let um=null;function co(e){um=e}function wt(){return um}const At=10;function fm(){if(typeof document>"u")return!0;const e=document.querySelector(".ole-canvas-root");return!!e&&!e.classList.contains("hide-grid")}function ne(e){return fm()?Math.round(e/At)*At:e}const x0=30,y0=144;function mm(e,t){const n=Ge[e],o=x.getState(),r=o.diagram;if(!n||e==="busbar")return{newElementId:o.addElement(e,t),attachedToBus:!1};const s=b0(r,t);if(!s){const p=hm(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,u=w0(n,l),d=gt(r,e),f=n.terminals.find(p=>p.id===u),m=l==="x"?t[0]:a[0],g=l==="y"?t[1]:a[1],h=f?[ne(m)-f.x,ne(g)-f.y]:[ne(t[0]),ne(t[1])];return o.dispatch(p=>{const y={id:d,kind:e},w={at:h},v=`${d}.${u}`,E={id:xt(i,v),ends:[i,v]};return{...p,elements:[...p.elements,y],wires:[...p.wires??[],E],layout:{...p.layout??{},[d]:w}}}),o.setSelection([d]),{newElementId:d,attachedToBus:!0}}function b0(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 u;if(i==="x"){const d=a[0]-l/2,f=a[0]+l/2,m=t[0]<d?d-t[0]:t[0]>f?t[0]-f:0,g=Math.abs(t[1]-a[1]);u=Math.sqrt(m*m+g*g)}else{const d=a[1]-l/2,f=a[1]+l/2,m=t[1]<d?d-t[1]:t[1]>f?t[1]-f:0,g=Math.abs(t[0]-a[0]);u=Math.sqrt(g*g+m*m)}u<=x0&&(!o||u<o.dist)&&(o={busId:r.id,busAt:[a[0],a[1]],axis:i,dist:u})}return o?{busId:o.busId,busAt:o.busAt,axis:o.axis}:null}function w0(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 hm(e){return!e||e.stretchable||e.terminals.length===0?null:[...e.terminals].sort((n,o)=>n.y-o.y)[0]}function pm(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,h=i[0]+a/2,p=Math.max(g,Math.min(h,t[0])),y=i[1],w=t[1]>=y?"s":"n";return{ref:e,world:[p,y],orientation:w,isBus:!0,busId:e}}const l=i[1]-a/2,u=i[1]+a/2,d=Math.max(l,Math.min(u,t[1])),f=i[0],m=t[0]>=f?"e":"w";return{ref:e,world:[f,d],orientation:m,isBus:!0,busId:e}}const o=n.terminals.get(e);return o?{ref:e,world:o.world,orientation:o.orientation,isBus:!1}:null}const v0={n:"s",s:"n",e:"w",w:"e"};function gm(e,t,n){if(e.terminals.length===0)return{id:"t",x:0,y:0,orientation:"n"};const o=v0[t.orientation],r=e.terminals.filter(l=>l.orientation===o),s=r.length>0?r:e.terminals;let i=s[0],a=uo(i,n,t.world);for(let l=1;l<s.length;l++){const u=s[l],d=uo(u,n,t.world);d<a&&(a=d,i=u)}return i}function uo(e,t,n){const o=t[0]+e.x-n[0],r=t[1]+e.y-n[1];return o*o+r*r}function k0(e,t,n){const o=Ge[e],r=x.getState(),s=r.diagram;if(!o)return null;const i=pm(t,n);if(!i)return null;const a=n[0]-i.world[0],l=n[1]-i.world[1],u=a*a+l*l<=y0,d=[ne(n[0]),ne(n[1])],f=gm(o,i,d),m=u?i.world:d,g=[ne(m[0]-f.x),ne(m[1]-f.y)],h=gt(s,e);return r.dispatch(p=>{const y={id:h,kind:e},w={at:g},v=`${h}.${f.id}`,E=i.isBus&&i.busId?i.busId:t,I={id:xt(E,v),ends:[E,v]};return{...p,elements:[...p.elements,y],wires:[...p.wires??[],I],layout:{...p.layout??{},[h]:w}}}),r.setSelection([h]),{newElementId:h,attachedToBus:i.isBus}}const Dt=9,Mt=7;function Rt(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 zt(e){const t=_0(e.viewBox);return t?{x:t.x+t.w+2,y:t.y+4,anchor:"start"}:{x:0,y:0,anchor:"start"}}function Ft(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 _0(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 S0(){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 d;const s=t.get(r.element.id);if(!s||!r.libraryDef)return null;const i=r.libraryDef.label??zt(r.libraryDef),a=Ft(i,s),l=i.anchor??"start";if(o===r.element.id)return c.jsx(j0,{elementId:r.element.id,currentName:((d=r.element.name)==null?void 0:d.trim())||r.element.id,world:a,anchor:l},r.element.id);if(n==="off")return null;const u=Rt(r,n);return u.length===0?null:c.jsx("g",{className:"ole-annotation",transform:`translate(${a[0]} ${a[1]})`,children:u.map((f,m)=>c.jsx("text",{x:0,y:m*Dt,textAnchor:l,className:"ole-annotation-text",children:f},m))},r.element.id)})})}const Ut=200,Zt=9;function j0({elementId:e,currentName:t,world:n,anchor:o}){const r=_.useRef(null);_.useEffect(()=>{const l=r.current;if(!l)return;l.focus();const u=document.createRange();u.selectNodeContents(l);const d=window.getSelection();d==null||d.removeAllRanges(),d==null||d.addRange(u)},[e]);function s(){var m;const l=x.getState(),u=l.diagram.elements.find(g=>g.id===e);if(!u){l.setEditingElement(null);return}const d=(((m=r.current)==null?void 0:m.innerText)??"").replace(/\u00a0/g," ").trim(),f=d===""||d===e?void 0:d;f!==u.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-=Ut/2:o==="end"&&(a-=Ut),c.jsx("foreignObject",{x:a,y:n[1]-Zt,width:Ut,height:Zt*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:`${Zt}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 xm=8,Pt=1.25;function $0(){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(N0,{ann:o},o.id):c.jsx(E0,{ann:o,isSelected:t===o.id},o.id))})}function E0({ann:e,isSelected:t}){const n=e.fontSize??xm,o=e.text===""?[""]:e.text.split(`
|
|
187
|
+
`),r=Math.max(20,...o.map(i=>i.length*n*.55)),s=o.length*n*Pt;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*Pt,fontSize:n,className:"ole-free-annotation-text",children:i},a))]})}function N0({ann:e}){const t=_.useRef(null),n=e.fontSize??xm;_.useEffect(()=>{const a=t.current;if(!a)return;a.focus();const l=document.createRange();l.selectNodeContents(a);const u=window.getSelection();u==null||u.removeAllRanges(),u==null||u.addRange(l)},[e.id]);function o(){var u;const a=x.getState(),l=(((u=t.current)==null?void 0:u.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:Pt,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*Pt}px`,whiteSpace:"pre-wrap",wordBreak:"break-word",cursor:"text"},children:e.text})})}const T0=20;function C0(){const e=x(d=>d.selection),t=x(d=>d.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],u=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(fo,{x:l[0],y:l[1],busId:n,side:"start",axis:r}),c.jsx(fo,{x:u[0],y:u[1],busId:n,side:"end",axis:r})]})}function fo({x:e,y:t,busId:n,side:o,axis:r}){const s=wt(),i=_.useRef(null),a=d=>{if(d.button!==0||(d.stopPropagation(),d.preventDefault(),!s))return;const f=x.getState().internal.buses.get(n);f&&(i.current={pointerId:d.pointerId,startSpan:f.geometry.span,startAt:[...f.geometry.at],startSvg:s.screenToSvg(d.clientX,d.clientY)},d.target.setPointerCapture(d.pointerId))},l=d=>{const f=i.current;if(!f||d.pointerId!==f.pointerId||!s)return;const m=s.screenToSvg(d.clientX,d.clientY),g=r==="x"?m[0]-f.startSvg[0]:m[1]-f.startSvg[1],h=fm()?Math.round(g/At)*At:g,p=f.startSpan+(o==="end"?h:-h);if(p<T0)return;const y=r==="x"?[f.startAt[0]+h/2,f.startAt[1]]:[f.startAt[0],f.startAt[1]+h/2];x.getState().updateBus(n,{span:p,at:y})},u=d=>{const f=i.current;!f||d.pointerId!==f.pointerId||(d.target.hasPointerCapture(d.pointerId)&&d.target.releasePointerCapture(d.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:u,onPointerCancel:u})}const I0=3,Jt=12;function A0(){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:u,at:d,span:f}=l,m=f/2,g=u==="x"?d[0]-m:d[0],h=u==="x"?d[1]:d[1]-m,p=u==="x"?d[0]+m:d[0],y=u==="x"?d[1]:d[1]+m,w=s.has(a.id),v=i.has(a.id),E=r.get(a.id)??void 0,I=Jt/2,L=u==="x"?d[0]-m:d[0]-I,W=u==="x"?d[1]-I:d[1]-m,le=u==="x"?f:Jt,re=u==="x"?Jt:f;return c.jsxs("g",{"data-bus-id":a.id,"data-element-id":a.id,"data-node-id":E,"data-selected":w?"true":void 0,"data-node-related":v?"true":void 0,className:"ole-bus",children:[c.jsx("rect",{x:L,y:W,width:le,height:re,fill:"transparent",className:"ole-bus-hit"}),c.jsx("line",{x1:g,y1:h,x2:p,y2:y,stroke:"black",strokeWidth:I0,strokeLinecap:"round",fill:"none"})]},a.id)})})}function M0(){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 We(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 P0(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 O0({lib:e}){const t=P0(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 L0(){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 u=l.indexOf(".");u>0&&i.add(l.slice(0,u))}}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 u=s.has(a.element.id),d=i.has(a.element.id);return a.libraryDef?c.jsxs("g",{"data-element-id":a.element.id,"data-selected":u?"true":void 0,"data-node-related":d?"true":void 0,transform:We(l),className:"ole-element",children:[c.jsx(O0,{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":u?"true":void 0,"data-node-related":d?"true":void 0,transform:We(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 ym=null;const mn=new Set;function $t(e){ym=e;for(const t of mn)t(e)}function B0(){return ym}function D0(e){return mn.add(e),()=>{mn.delete(e)}}function R0(){const[e,t]=_.useState(B0());return _.useEffect(()=>D0(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 z0(){const e=x(u=>u.activeTool),t=x(u=>u.placeKind),n=x(u=>u.cursorSvg),o=x(u=>u.placeFromTerminal);if(e!=="place"||!t||!n)return null;const r=cm(t);if(!r)return null;let s=null,i=null;if(o){const u=pm(o,n);u&&(s=gm(r,u,n),i={source:u.world,pin:n})}else s=hm(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 F0(){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:u,at:d,span:f}=s.geometry,m=f/2,g=u==="x"?d[0]-m:d[0]-4,h=u==="x"?d[1]-4:d[1]-m,p=u==="x"?f:8,y=u==="x"?8:f;return c.jsx("rect",{x:g,y:h,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=H0(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:We(a)},r):null})})}function H0(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 W0(){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,u=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":u?"true":void 0,className:"ole-terminal"},s.ref)})})}function G0(){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(m=>`${m[0]},${m[1]}`).join(" "),u=s.get(i.wireId),d=o===i.wireId,f=r!=null&&r===u;return[c.jsx("polyline",{"data-wire-id":i.wireId,"data-node-id":u,className:"ole-wire-hit",points:l},`hit-${i.wireId}`),c.jsx("polyline",{"data-wire-id":i.wireId,"data-node-id":u,"data-manual":i.userEdited?"true":void 0,"data-selected":d||f?"true":void 0,className:"ole-wire",points:l},i.wireId)]})})}let Ye=null;const hn=new Set;function Me(e){if(!(e===null&&Ye===null||e&&Ye&&e.ref===Ye.ref&&e.world[0]===Ye.world[0]&&e.world[1]===Ye.world[1])){Ye=e;for(const t of hn)t(e)}}function K0(){return Ye}function q0(e){return hn.add(e),()=>{hn.delete(e)}}function Y0(){var u,d;const e=x(f=>f.wireFromTerminal),t=x(f=>f.cursorSvg),n=x(f=>f.internal.terminals),[o,r]=_.useState(K0());_.useEffect(()=>q0(r),[]);const s=x(f=>f.internal.buses);if(!e||!t)return null;let i;if(e.includes(".")?i=(u=n.get(e))==null?void 0:u.world:i=(d=s.get(e))==null?void 0:d.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 tt(e,t){return e instanceof Element?e.closest(`[${t}]`):null}function Qe(e){var t;return((t=tt(e,"data-element-id"))==null?void 0:t.getAttribute("data-element-id"))??null}function X0(e){var t;return((t=tt(e,"data-bus-id"))==null?void 0:t.getAttribute("data-bus-id"))??null}function He(e){var o;const t=(o=tt(e,"data-terminal-id"))==null?void 0:o.getAttribute("data-terminal-id");if(t)return t;const n=X0(e);return n||null}function Ht(e){var t;return((t=tt(e,"data-node-id"))==null?void 0:t.getAttribute("data-node-id"))??null}function V0(e){var t;return((t=tt(e,"data-wire-id"))==null?void 0:t.getAttribute("data-wire-id"))??null}function Ot(e){var t;return((t=tt(e,"data-annotation-id"))==null?void 0:t.getAttribute("data-annotation-id"))??null}function bm(e,t){try{e.dispatchEvent(new PointerEvent("pointercancel",{pointerId:t,bubbles:!0,cancelable:!0,pointerType:"touch"}))}catch{}}function U0(e){if(!(e instanceof HTMLElement))return!1;const t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable}function wm(){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 Z0(){_.useEffect(()=>{const e=t=>{if(U0(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":wm();return}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[])}let pn=null;const gn=new Set;function J0(e){if(e!==pn){pn=e;for(const t of gn)t(e)}}function Q0(){return pn}function ex(e){return gn.add(e),()=>{gn.delete(e)}}const mo="ole-hover-element-host",tx="ole-hover-terminal-on",nx="ole-hover-node-on";function ox(e){_.useEffect(()=>{const t=e.current;if(!t)return;let n=null,o=null;const r=new Set,s=new Set,i=(f,m,g)=>{for(const h of f)h.classList.remove(g);f.clear();for(const h of m)h.classList.add(g),f.add(h)},a=f=>{var g,h;if(f===n)return;n&&((g=t.querySelector(`[data-element-id="${Et(n)}"]`))==null||g.classList.remove(mo)),f&&((h=t.querySelector(`[data-element-id="${Et(f)}"]`))==null||h.classList.add(mo));const m=f?Array.from(t.querySelectorAll(`.ole-terminal[data-element-id="${Et(f)}"]`)):[];i(r,m,tx),n=f,f?t.setAttribute("data-hover-element",""):t.removeAttribute("data-hover-element"),J0(f)},l=f=>{if(f===o)return;const m=f?Array.from(t.querySelectorAll(`[data-node-id="${Et(f)}"]`)):[];i(s,m,nx),o=f,f?t.setAttribute("data-hover-node",""):t.removeAttribute("data-hover-node")},u=f=>{a(Qe(f.target));const m=He(f.target);let g=null;m?g=x.getState().internal.terminalToNode.get(m)??null:g=Ht(f.target),l(g)},d=()=>{a(null),l(null)};return t.addEventListener("pointermove",u),t.addEventListener("pointerleave",d),()=>{t.removeEventListener("pointermove",u),t.removeEventListener("pointerleave",d),a(null),l(null)}},[e])}function Et(e){return e.replace(/(["\\])/g,"\\$1")}function vm(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,m=i[0]+a/2,g=Math.max(f,Math.min(m,t[0]));return{ref:e,world:[g,i[1]],isBus:!0}}const l=i[1]-a/2,u=i[1]+a/2,d=Math.max(l,Math.min(u,t[1]));return{ref:e,world:[i[0],d],isBus:!0}}const o=n.terminals.get(e);return o?{ref:e,world:o.world,isBus:!1}:null}const ho=3;let ae=null,ke=null,Se=null,oe=null;const rx={id:"select",cursor:"default",onPointerDown(e,t){var f,m,g,h;if(e.button!==0||e.target instanceof Element&&e.target.closest(".ole-bus-handle"))return;const n=x.getState(),o=Ot(e.target);if(o){e.preventDefault(),e.stopPropagation();const p=(f=n.diagram.annotations)==null?void 0:f.find(y=>y.id===o);if(!p)return;n.setSelectedAnnotation(o),oe={pointerId:e.pointerId,id:o,startSvg:t.viewport.screenToSvg(e.clientX,e.clientY),origin:[p.at[0],p.at[1]],moved:!1};return}const s=(e.target instanceof Element?(m=e.target.closest("[data-terminal-id]"))==null?void 0:m.getAttribute("data-terminal-id"):null)?He(e.target):null;if(s){const p=s.indexOf("."),y=p>0?s.slice(0,p):"";if(y&&n.selection.includes(y)){e.preventDefault(),e.stopPropagation(),e.target instanceof Element&&((h=(g=e.target).hasPointerCapture)!=null&&h.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)),Se={pointerId:e.pointerId,fromRef:s};return}}const i=Qe(e.target);if(!i){const p=V0(e.target);if(p){if(e.preventDefault(),e.altKey){const y=Ht(e.target);if(y){n.setSelectedNode(y);return}}n.setSelectedWire(p);return}e.shiftKey||n.clearSelection(),ke={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 u=x.getState().internal,d=new Map;for(const p of l){const y=u.layout.get(p);y&&d.set(p,{...y})}d.size!==0&&(ae={pointerId:e.pointerId,startSvg:t.viewport.screenToSvg(e.clientX,e.clientY),originals:d,moved:!1},e.preventDefault())},onPointerMove(e,t){if(oe&&e.pointerId===oe.pointerId){const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=ne(n[0]-oe.startSvg[0]),r=ne(n[1]-oe.startSvg[1]);!oe.moved&&(o!==0||r!==0)&&(oe.moved=!0,t.hostEl.hasPointerCapture(e.pointerId)||t.hostEl.setPointerCapture(e.pointerId));const s=t.hostEl.querySelector(`[data-annotation-id="${ct(oe.id)}"]`);s&&s.setAttribute("transform",`translate(${o} ${r})`);return}if(Se&&e.pointerId===Se.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?He(o):null;if(!r||r===Se.fromRef){Me(null);return}Me(vm(r,n));return}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));for(const[s,i]of ae.originals){const a=t.hostEl.querySelector(`[data-element-id="${ct(s)}"]`);if(!a)continue;const l={...i,at:[i.at[0]+o,i.at[1]+r]};a.setAttribute("transform",We(l))}return}if(ke&&e.pointerId===ke.pointerId){const n=t.viewport.screenToSvg(e.clientX,e.clientY);$t(po(ke.startSvg,n));return}},onPointerUp(e,t){if(oe&&e.pointerId===oe.pointerId){t.hostEl.hasPointerCapture(e.pointerId)&&t.hostEl.releasePointerCapture(e.pointerId);const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=ne(n[0]-oe.startSvg[0]),r=ne(n[1]-oe.startSvg[1]),s=t.hostEl.querySelector(`[data-annotation-id="${ct(oe.id)}"]`);s&&s.removeAttribute("transform"),oe.moved&&(o!==0||r!==0)&&x.getState().updateAnnotation(oe.id,{at:[oe.origin[0]+o,oe.origin[1]+r]}),oe=null;return}if(Se&&e.pointerId===Se.pointerId){const n=x.getState(),o=Se.fromRef;Se=null,t.hostEl.classList.remove("tool-wire"),n.setWireFromTerminal(null),n.setCursorSvg(null),Me(null);const r=He(e.target);r&&r!==o&&n.addWire(o,r);return}if(ae&&e.pointerId===ae.pointerId){if(t.hostEl.hasPointerCapture(e.pointerId)&&t.hostEl.releasePointerCapture(e.pointerId),ae.moved){const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=ne(n[0]-ae.startSvg[0]),r=ne(n[1]-ae.startSvg[1]);if(o!==0||r!==0){const s=new Map;for(const i of ae.originals.keys())s.set(i,[o,r]);x.getState().moveElements(s)}}ae=null;return}if(ke&&e.pointerId===ke.pointerId){t.hostEl.hasPointerCapture(e.pointerId)&&t.hostEl.releasePointerCapture(e.pointerId);const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=po(ke.startSvg,n);if(o.w>=ho||o.h>=ho){const r=sx(o);if(ke.shiftKey){const s=new Set(ke.baseSelection);for(const i of r)s.has(i)?s.delete(i):s.add(i);x.getState().setSelection([...s])}else x.getState().setSelection(r)}$t(null),ke=null}},onPointerCancel(e,t){var n,o,r,s,i,a;if(oe&&e.pointerId===oe.pointerId){const l=t.hostEl.querySelector(`[data-annotation-id="${ct(oe.id)}"]`);if(l&&l.removeAttribute("transform"),(o=(n=t.hostEl).hasPointerCapture)!=null&&o.call(n,e.pointerId))try{t.hostEl.releasePointerCapture(e.pointerId)}catch{}oe=null}if(ae&&e.pointerId===ae.pointerId){for(const[l,u]of ae.originals){const d=t.hostEl.querySelector(`[data-element-id="${ct(l)}"]`);d&&d.setAttribute("transform",We(u))}if((s=(r=t.hostEl).hasPointerCapture)!=null&&s.call(r,e.pointerId))try{t.hostEl.releasePointerCapture(e.pointerId)}catch{}ae=null}if(Se&&e.pointerId===Se.pointerId){t.hostEl.classList.remove("tool-wire");const l=x.getState();l.setWireFromTerminal(null),l.setCursorSvg(null),Me(null),Se=null}if(ke&&e.pointerId===ke.pointerId){if((a=(i=t.hostEl).hasPointerCapture)!=null&&a.call(i,e.pointerId))try{t.hostEl.releasePointerCapture(e.pointerId)}catch{}$t(null),ke=null}},onDoubleClick(e){const t=x.getState(),n=Ot(e.target);if(n){e.preventDefault(),e.stopPropagation(),t.setEditingAnnotation(n);return}const o=Qe(e.target);o&&(e.preventDefault(),e.stopPropagation(),t.setEditingElement(o))},onDeactivate(e){if(ae=null,ke=null,oe=null,Se){e.hostEl.classList.remove("tool-wire");const t=x.getState();t.setWireFromTerminal(null),t.setCursorSvg(null),Me(null),Se=null}$t(null)}};function po(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 sx(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=ax(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,m])=>ix([f,m],r));let a=1/0,l=-1/0,u=1/0,d=-1/0;for(const[f,m]of i)f<a&&(a=f),f>l&&(l=f),m<u&&(u=m),m>d&&(d=m);l>=e.x&&a<=e.x+e.w&&d>=e.y&&u<=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,u=s==="x"?i[0]-l:i[0],d=s==="x"?i[0]+l:i[0],f=s==="x"?i[1]:i[1]-l,m=s==="x"?i[1]:i[1]+l;d>=e.x&&u<=e.x+e.w&&m>=e.y&&f<=e.y+e.h&&n.push(o.id)}return n}function ix(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 ax(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 ct(e){return e.replace(/(["\\])/g,"\\$1")}const lx=4;let Z=null;const cx={id:"pan",cursor:"grab",onPointerDown(e,t){if(e.button!==0)return;const n=t.viewport.getViewport(),o=Qe(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 u of i){const d=a.layout.get(u);d&&l.set(u,{...d})}l.size>0&&(r={startSvg:t.viewport.screenToSvg(e.clientX,e.clientY),originals:l})}Z={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(!Z||e.pointerId!==Z.pointerId)return;const n=e.clientX-Z.startX,o=e.clientY-Z.startY;if(!Z.moved&&Math.hypot(n,o)>lx){Z.moved=!0;try{t.hostEl.setPointerCapture(e.pointerId)}catch{}}if(Z.moved){if(Z.elementDrag){const r=t.viewport.screenToSvg(e.clientX,e.clientY),s=ne(r[0]-Z.elementDrag.startSvg[0]),i=ne(r[1]-Z.elementDrag.startSvg[1]);for(const[a,l]of Z.elementDrag.originals){const u=t.hostEl.querySelector(`[data-element-id="${go(a)}"]`);if(!u)continue;const d={...l,at:[l.at[0]+s,l.at[1]+i]};u.setAttribute("transform",We(d))}return}t.viewport.setViewport({tx:Z.startTx+n,ty:Z.startTy+o})}},onPointerUp(e,t){if(!(!Z||e.pointerId!==Z.pointerId)){if(t.hostEl.hasPointerCapture(e.pointerId)&&t.hostEl.releasePointerCapture(e.pointerId),t.hostEl.style.cursor="grab",Z.elementDrag&&Z.moved){const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=ne(n[0]-Z.elementDrag.startSvg[0]),r=ne(n[1]-Z.elementDrag.startSvg[1]);if(o!==0||r!==0){const s=new Map;for(const i of Z.elementDrag.originals.keys())s.set(i,[o,r]);x.getState().moveElements(s)}}else Z.moved||dx(Z.startTarget);Z=null}},onPointerCancel(e,t){if(Z!=null&&Z.elementDrag)for(const[n,o]of Z.elementDrag.originals){const r=t.hostEl.querySelector(`[data-element-id="${go(n)}"]`);r&&r.setAttribute("transform",We(o))}Z=null},onDeactivate(){Z=null}};function dx(e){if(!e)return;const t=x.getState(),n=Ot(e);if(n){t.setSelectedAnnotation(n);return}const o=Qe(e);if(o){t.setSelection([o]);return}const r=Ht(e);if(r){t.setSelectedNode(r);return}t.clearSelection()}function go(e){return e.replace(/(["\\])/g,"\\$1")}const ft={tight:1024,compact:720,dense:520,mini:380},xo={full:0,tight:1,compact:2,dense:3,mini:4};function Ne(e,t){return xo[e]>=xo[t]}function ux(e){return e>=ft.tight?"full":e>=ft.compact?"tight":e>=ft.dense?"compact":e>=ft.mini?"dense":"mini"}const km=_.createContext("full");function Ke(){return _.useContext(km)}function fx(e){const[t,n]=_.useState(null);return _.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 _m(){if(typeof window>"u")return!1;try{if(!window.matchMedia("(pointer: coarse)").matches)return!1}catch{return!1}return window.innerWidth<ft.dense}function $n(){_m()&&x.getState().setActiveTool("pan")}function mx(){_m()&&x.getState().setPlaceKind(null)}const hx={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=He(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?He(r):null;if(!s||s===n){Me(null);return}Me(vm(s,o))},onPointerUp(e){const t=x.getState(),n=t.wireFromTerminal;if(!n)return;t.setWireFromTerminal(null),t.setCursorSvg(null),Me(null);const o=He(e.target);!o||o===n||(t.addWire(n,o),$n())},onPointerLeave(){const e=x.getState();e.setWireFromTerminal(null),e.setCursorSvg(null),Me(null)}},yo=10;let dt=!1;function bo(){setTimeout(()=>mx(),0)}const px={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),dt=!1},onPointerDown(e,t){var s,i;if(e.button!==0)return;const{placeKind:n}=x.getState();if(!n)return;e.preventDefault();const o=He(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);mm(n,r),dt=!0},onPointerMove(e,t){const n=t.viewport.screenToSvg(e.clientX,e.clientY);x.getState().setCursorSvg([wo(n[0]),wo(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);k0(r,o,s),bo();return}dt&&(dt=!1,bo())},onPointerLeave(){const e=x.getState();e.setPlaceFromTerminal(null),e.setCursorSvg(null)},onPointerCancel(){const e=x.getState();e.setPlaceFromTerminal(null),e.setCursorSvg(null),dt=!1}};function wo(e){return Math.round(e/yo)*yo}const vo=10,ko=20;function Ve(e){return Math.round(e/vo)*vo}const gx={id:"busbar",cursor:"crosshair",onPointerDown(e,t){if(e.button!==0)return;e.preventDefault();const n=t.viewport.screenToSvg(e.clientX,e.clientY),o=[Ve(n[0]),Ve(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([Ve(n[0]),Ve(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=Ve(o[0]),s=Ve(o[1]),i=r-n[0],a=s-n[1],l=Math.abs(i)>=Math.abs(a);let u,d,f;if(l){if(d=Math.abs(i),d<ko)return;u=0,f=[(n[0]+r)/2,n[1]]}else{if(d=Math.abs(a),d<ko)return;u=90,f=[n[0],(n[1]+s)/2]}x.getState().addBus(f,d,u),$n()},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)}},xx={id:"text",cursor:"text",onPointerDown(e,t){if(e.button!==0)return;const n=x.getState(),o=Ot(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),$n()}},yx={select:rx,pan:cx,wire:hx,place:px,busbar:gx,text:xx};function bx(e,t){const n=x(o=>o.activeTool);_.useEffect(()=>{var m;const o=e.current;if(!o)return;const r=yx[n],s={viewport:t,hostEl:o};(m=r.onActivate)==null||m.call(r,s),r.cursor&&(o.style.cursor=r.cursor);const i=g=>{var h;return(h=r.onPointerDown)==null?void 0:h.call(r,g,s)},a=g=>{var h;return(h=r.onPointerMove)==null?void 0:h.call(r,g,s)},l=g=>{var h;return(h=r.onPointerUp)==null?void 0:h.call(r,g,s)},u=g=>{var h;return r.onPointerCancel?r.onPointerCancel(g,s):(h=r.onPointerUp)==null?void 0:h.call(r,g,s)},d=g=>{var h;return(h=r.onPointerLeave)==null?void 0:h.call(r,g,s)},f=g=>{var h;return(h=r.onDoubleClick)==null?void 0:h.call(r,g,s)};return o.addEventListener("pointerdown",i),o.addEventListener("pointermove",a),o.addEventListener("pointerup",l),o.addEventListener("pointercancel",u),o.addEventListener("pointerleave",d),o.addEventListener("dblclick",f),()=>{var g;o.removeEventListener("pointerdown",i),o.removeEventListener("pointermove",a),o.removeEventListener("pointerup",l),o.removeEventListener("pointercancel",u),o.removeEventListener("pointerleave",d),o.removeEventListener("dblclick",f),(g=r.onDeactivate)==null||g.call(r,s),o.style.cursor=""}},[n,e,t])}let xn=1;const yn=new Set;function wx(e){if(e!==xn){xn=e;for(const t of yn)t(e)}}function vx(){return xn}function kx(e){return yn.add(e),()=>{yn.delete(e)}}const Qt=.1,en=8,_x=1.0015,Sx=1.02;function jx(e,t,n={tx:0,ty:0,scale:1}){const o=_.useRef({...n}),r=_.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)),wx(o.current.scale),r.current.size>0){const l={...o.current};for(const u of r.current)u(l)}};return _.useEffect(()=>{const i=e.current;if(!i)return;let a=!1,l=-1,u=0,d=0,f=0,m=0,g=!1;const h=new Map;let p=null,y=!1;const w=()=>{if(h.size<2){p=null;return}const $=[...h.values()],T=$[1].x-$[0].x,J=$[1].y-$[0].y,ee=Math.hypot(T,J)||1,ie=i.getBoundingClientRect();p={startDist:ee,startScale:o.current.scale,startTx:o.current.tx,startTy:o.current.ty,startMidX:($[0].x+$[1].x)/2-ie.left,startMidY:($[0].y+$[1].y)/2-ie.top}},v=$=>{if($.pointerType==="touch"){if(h.set($.pointerId,{x:$.clientX,y:$.clientY}),h.size>=2&&!y){y=!0;for(const T of h.keys())T!==$.pointerId&&bm(i,T);w()}if(y){$.stopPropagation(),$.preventDefault();try{i.setPointerCapture($.pointerId)}catch{}}}},E=$=>{if($.pointerType!=="touch"||!h.has($.pointerId)||(h.set($.pointerId,{x:$.clientX,y:$.clientY}),!y||!p))return;$.stopPropagation();const T=[...h.values()];if(T.length<2)return;const J=T[1].x-T[0].x,ee=T[1].y-T[0].y,ie=Math.hypot(J,ee)||1,be=i.getBoundingClientRect(),Ie=(T[0].x+T[1].x)/2-be.left,de=(T[0].y+T[1].y)/2-be.top,_e=ie/p.startDist,we=tn(p.startScale*_e,Qt,en),ge=we/p.startScale;o.current.tx=p.startMidX-(p.startMidX-p.startTx)*ge+(Ie-p.startMidX),o.current.ty=p.startMidY-(p.startMidY-p.startTy)*ge+(de-p.startMidY),o.current.scale=we,s()},I=$=>{var T;if($.pointerType==="touch"&&h.has($.pointerId)&&(h.delete($.pointerId),y)){if($.stopPropagation(),(T=i.hasPointerCapture)!=null&&T.call(i,$.pointerId))try{i.releasePointerCapture($.pointerId)}catch{}h.size>=2?w():p=null,h.size===0&&(y=!1)}},L=$=>{$.preventDefault();const T=i.getBoundingClientRect(),J=$.clientX-T.left,ee=$.clientY-T.top,ie=$.ctrlKey||$.metaKey;if($.deltaX===0||ie){const de=Math.pow(ie?Sx:_x,-$.deltaY),_e=tn(o.current.scale*de,Qt,en),we=_e/o.current.scale;o.current.tx=J-(J-o.current.tx)*we,o.current.ty=ee-(ee-o.current.ty)*we,o.current.scale=_e}else o.current.tx-=$.deltaX,o.current.ty-=$.deltaY;s()},W=$=>{const T=$.button===1,J=g&&$.button===0;!T&&!J||($.preventDefault(),a=!0,l=$.pointerId,u=$.clientX,d=$.clientY,f=o.current.tx,m=o.current.ty,i.setPointerCapture($.pointerId),i.style.cursor="grabbing")},le=$=>{!a||$.pointerId!==l||(o.current.tx=f+($.clientX-u),o.current.ty=m+($.clientY-d),s())},re=$=>{a&&$.pointerId===l&&(a=!1,i.releasePointerCapture($.pointerId),i.style.cursor=g?"grab":"")},pe=$=>{if($.code==="Space"&&!g){const T=$.target;if(T&&(T.tagName==="INPUT"||T.tagName==="TEXTAREA"||T.isContentEditable))return;g=!0,i.style.cursor="grab",$.preventDefault()}},ue=$=>{$.code==="Space"&&(g=!1,a||(i.style.cursor=""))};return i.addEventListener("wheel",L,{passive:!1}),i.addEventListener("pointerdown",W),i.addEventListener("pointermove",le),i.addEventListener("pointerup",re),i.addEventListener("pointercancel",re),i.addEventListener("pointerdown",v,{capture:!0}),i.addEventListener("pointermove",E,{capture:!0}),i.addEventListener("pointerup",I,{capture:!0}),i.addEventListener("pointercancel",I,{capture:!0}),window.addEventListener("keydown",pe),window.addEventListener("keyup",ue),s(),()=>{i.removeEventListener("wheel",L),i.removeEventListener("pointerdown",W),i.removeEventListener("pointermove",le),i.removeEventListener("pointerup",re),i.removeEventListener("pointercancel",re),i.removeEventListener("pointerdown",v,{capture:!0}),i.removeEventListener("pointermove",E,{capture:!0}),i.removeEventListener("pointerup",I,{capture:!0}),i.removeEventListener("pointercancel",I,{capture:!0}),window.removeEventListener("keydown",pe),window.removeEventListener("keyup",ue)}},[]),{screenToSvg(i,a){const l=e.current;if(!l)return[i,a];const u=l.getBoundingClientRect(),d=(i-u.left-o.current.tx)/o.current.scale,f=(a-u.top-o.current.ty)/o.current.scale;return[d,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=tn(i.scale,Qt,en)),s()},subscribe(i){return r.current.add(i),()=>{r.current.delete(i)}}}}function tn(e,t,n){return e<t?t:e>n?n:e}const Sm=typeof navigator<"u"&&/Mac|iP(ad|hone|od)/.test(navigator.platform),Ue=Sm?"⌘":"Ctrl+",$x=Sm?"⇧":"Shift+",nn=[10,20,50,100,200,500,1e3,2e3,5e3,1e4],Ex=18;function Nx(e){for(const t of nn)if(t*e>=Ex)return t;return nn[nn.length-1]}function Tx(){const e=V(),t=_.useRef(null),n=_.useRef(null),o=_.useRef(null),r=jx(t,n);bx(t,r),ox(t),_.useEffect(()=>(co(r),()=>co(null)),[r]),_.useEffect(()=>{const d=f=>{const m=o.current;if(!m)return;const h=Nx(f.scale)*f.scale;m.setAttribute("width",String(h)),m.setAttribute("height",String(h)),m.setAttribute("patternTransform",`translate(${f.tx} ${f.ty})`)};return d(r.getViewport()),r.subscribe(d)},[r]);const s=rp(),i=_.useCallback((d,f,m)=>{const g=x.getState(),h=g.activeTool;if(h==="wire"||h==="busbar"||h==="place"){wm();return}const p=Qe(m);if(p)g.selection.includes(p)||g.setSelection([p]);else{const W=Ht(m);W&&g.selectedNode!==W&&g.setSelectedNode(W)}const y=x.getState(),w=y.selection.length>0,v=y.selectedNode!=null,E=!!y.clipboard,I=y.diagram.elements.length>0,L=[{label:e("menu.undo"),shortcut:`${Ue}Z`,icon:_n,onSelect:()=>x.getState().undo(),disabled:y.past.length===0},{label:e("menu.redo"),shortcut:`${Ue}${$x}Z`,icon:kn,onSelect:()=>x.getState().redo(),disabled:y.future.length===0},{type:"separator"},{label:e("menu.cut"),shortcut:`${Ue}X`,icon:Jo,onSelect:()=>x.getState().cutSelection(),disabled:!w},{label:e("menu.copy"),shortcut:`${Ue}C`,icon:Xo,onSelect:()=>x.getState().copySelection(),disabled:!w},{label:e("menu.paste"),shortcut:`${Ue}V`,icon:Yo,onSelect:()=>x.getState().pasteClipboard(),disabled:!E},{type:"separator"},{label:e("menu.rotate"),shortcut:"R",icon:Zo,onSelect:()=>x.getState().rotateSelection(90),disabled:!w},{label:e("menu.mirror"),shortcut:"M",icon:Vo,onSelect:()=>x.getState().mirrorSelection(),disabled:!w},{type:"separator"},{label:e("menu.selectAll"),shortcut:`${Ue}A`,icon:jh,onSelect:()=>{const W=x.getState();W.setSelection(W.diagram.elements.map(le=>le.id))},disabled:!I},{type:"separator"},{label:e(v&&!w?"menu.disconnect":"menu.delete"),shortcut:"Del",icon:er,destructive:!0,onSelect:()=>v&&!w?x.getState().deleteSelectedNode():x.getState().deleteSelection(),disabled:!w&&!v}];s.open(d,f,L)},[s,e]);_.useEffect(()=>{const d=t.current;if(!d)return;const f=700,m=4;let g,h=null;const p=()=>{g!==void 0&&window.clearTimeout(g),g=void 0,h=null},y=E=>{E.pointerType==="touch"&&(p(),h={pointerId:E.pointerId,x:E.clientX,y:E.clientY,target:E.target},g=window.setTimeout(()=>{const I=h;h=null,g=void 0,I&&(bm(d,I.pointerId),i(I.x,I.y,I.target))},f))},w=E=>{if(!h||E.pointerId!==h.pointerId)return;const I=E.clientX-h.x,L=E.clientY-h.y;Math.hypot(I,L)>m&&p()},v=E=>{!h||E.pointerId!==h.pointerId||p()};return d.addEventListener("pointerdown",y),d.addEventListener("pointermove",w),d.addEventListener("pointerup",v),d.addEventListener("pointercancel",v),()=>{p(),d.removeEventListener("pointerdown",y),d.removeEventListener("pointermove",w),d.removeEventListener("pointerup",v),d.removeEventListener("pointercancel",v)}},[i]);const a=d=>{d.dataTransfer.types.includes("application/x-oneline-kind")&&(d.preventDefault(),d.dataTransfer.dropEffect="copy")},l=d=>{const f=d.dataTransfer.getData("application/x-oneline-kind");if(!f)return;d.preventDefault();const m=r.screenToSvg(d.clientX,d.clientY);mm(f,m)},u=d=>{d.preventDefault(),i(d.clientX,d.clientY,d.target)};return c.jsx("div",{ref:t,className:"ole-canvas-root absolute inset-0 overflow-hidden",onDragOver:a,onDrop:l,onContextMenu:u,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(A0,{}),c.jsx(G0,{}),c.jsx(L0,{}),c.jsx(S0,{}),c.jsx($0,{}),c.jsx(F0,{}),c.jsx(C0,{}),c.jsx(W0,{}),c.jsx(Y0,{}),c.jsx(M0,{}),c.jsx(z0,{}),c.jsx(R0,{})]})]})})}const _o=60,Cx=.1,Ix=8,Ax=8;function Mx(e,t,n){return e<t?t:e>n?n:e}function Px(){return document.querySelector(".ole-canvas-root")}function En(){const e=wt(),t=Px();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 w of o){const v=w.getBoundingClientRect();v.width===0&&v.height===0||(v.left<r&&(r=v.left),v.top<s&&(s=v.top),v.right>i&&(i=v.right),v.bottom>a&&(a=v.bottom))}if(r===1/0)return!1;const[l,u]=e.screenToSvg(r,s),[d,f]=e.screenToSvg(i,a),m=Math.max(d-l,1),g=Math.max(f-u,1),h=Mx(Math.min((n.width-_o*2)/m,(n.height-_o*2)/g),Cx,Ix),p=(l+d)/2,y=(u+f)/2;return e.setViewport({tx:n.width/2-h*p,ty:n.height/2-h*y,scale:h}),!0}function Nn(){let e=Ax;const t=()=>{En()||--e>0&&requestAnimationFrame(t)};requestAnimationFrame(t)}const So=10,Ox=100;function Lx(){return typeof window>"u"||!window.matchMedia?!1:window.matchMedia("(hover: none), (pointer: coarse)").matches}function Bx(){const[e,t]=_.useState(Q0()),[n,o]=_.useState(!1),[r,s]=_.useState(null),i=_.useRef(null),a=_.useRef(void 0),[l]=_.useState(Lx);_.useEffect(()=>ex(h=>t(h)),[]),_.useEffect(()=>{if(window.clearTimeout(a.current),o(!1),s(null),!!e)return a.current=window.setTimeout(()=>o(!0),Ox),()=>window.clearTimeout(a.current)},[e]);const u=x(h=>e?h.diagram.elements.find(p=>p.id===e)??null:null);if(_.useLayoutEffect(()=>{if(!n||!e)return;let h=0,p=-1,y=-1;const w=()=>{const v=document.querySelector(`[data-element-id="${Dx(e)}"]`),E=i.current;if(v&&E){const I=v.getBoundingClientRect();let L=I.bottom+So;L+E.offsetHeight>window.innerHeight-4&&(L=I.top-E.offsetHeight-So);let W=I.left+I.width/2-E.offsetWidth/2;W=Math.max(4,Math.min(W,window.innerWidth-E.offsetWidth-4)),(L!==p||W!==y)&&(s({top:L,left:W}),p=L,y=W)}h=requestAnimationFrame(w)};return h=requestAnimationFrame(w),()=>cancelAnimationFrame(h)},[n,e]),l||!n||!e||!u)return null;const d=Ge[u.kind],f=u.name??u.id,m=(d==null?void 0:d.name)??u.kind,g=u.name&&u.name!==u.id;return typeof document>"u"?null:Go.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:u.id}),c.jsx("span",{className:"text-muted-foreground/80",children:"·"}),c.jsx("span",{className:"text-muted-foreground",children:m})]}),document.body)}function Dx(e){return e.replace(/(["\\])/g,"\\$1")}function Rx({width:e,children:t}){const n=e==null?"full":ux(e);return c.jsx(km.Provider,{value:n,children:t})}function jo(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function zx(...e){return t=>{let n=!1;const o=e.map(r=>{const s=jo(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():jo(e[r],null)}}}}var Fx=Symbol.for("react.lazy"),Lt=he[" use ".trim().toString()];function Hx(e){return typeof e=="object"&&e!==null&&"then"in e}function jm(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===Fx&&"_payload"in e&&Hx(e._payload)}function Wx(e){const t=Kx(e),n=he.forwardRef((o,r)=>{let{children:s,...i}=o;jm(s)&&typeof Lt=="function"&&(s=Lt(s._payload));const a=he.Children.toArray(s),l=a.find(Yx);if(l){const u=l.props.children,d=a.map(f=>f===l?he.Children.count(u)>1?he.Children.only(null):he.isValidElement(u)?u.props.children:null:f);return c.jsx(t,{...i,ref:r,children:he.isValidElement(u)?he.cloneElement(u,void 0,d):null})}return c.jsx(t,{...i,ref:r,children:s})});return n.displayName=`${e}.Slot`,n}var Gx=Wx("Slot");function Kx(e){const t=he.forwardRef((n,o)=>{let{children:r,...s}=n;if(jm(r)&&typeof Lt=="function"&&(r=Lt(r._payload)),he.isValidElement(r)){const i=Vx(r),a=Xx(s,r.props);return r.type!==he.Fragment&&(a.ref=o?zx(o,i):i),he.cloneElement(r,a)}return he.Children.count(r)>1?he.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var qx=Symbol("radix.slottable");function Yx(e){return he.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===qx}function Xx(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 Vx(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 $o=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,Eo=or,Ux=(e,t)=>n=>{var o;if((t==null?void 0:t.variants)==null)return Eo(e,n==null?void 0:n.class,n==null?void 0:n.className);const{variants:r,defaultVariants:s}=t,i=Object.keys(r).map(u=>{const d=n==null?void 0:n[u],f=s==null?void 0:s[u];if(d===null)return null;const m=$o(d)||$o(f);return r[u][m]}),a=n&&Object.entries(n).reduce((u,d)=>{let[f,m]=d;return m===void 0||(u[f]=m),u},{}),l=t==null||(o=t.compoundVariants)===null||o===void 0?void 0:o.reduce((u,d)=>{let{class:f,className:m,...g}=d;return Object.entries(g).every(h=>{let[p,y]=h;return Array.isArray(y)?y.includes({...s,...a}[p]):{...s,...a}[p]===y})?[...u,f,m]:u},[]);return Eo(e,i,l,n==null?void 0:n.class,n==null?void 0:n.className)},Zx=Ux("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"}}),Te=he.forwardRef(({className:e,variant:t,size:n,asChild:o=!1,...r},s)=>{const i=o?Gx:"button";return c.jsx(i,{className:ye(Zx({variant:t,size:n,className:e})),ref:s,...r})});Te.displayName="Button";const Jx=350;function Ce({content:e,children:t,disabled:n,delayMs:o=Jx}){const r=_.useRef(null),s=_.useRef(null),[i,a]=_.useState(!1),[l,u]=_.useState(null),d=_.useId(),f=_.useRef(void 0),m=()=>{n||(window.clearTimeout(f.current),f.current=window.setTimeout(()=>a(!0),o))},g=()=>{window.clearTimeout(f.current),a(!1)};_.useLayoutEffect(()=>{if(!i||!r.current||!s.current)return;const w=r.current.getBoundingClientRect(),v=s.current.getBoundingClientRect(),E=8;let I="top",L=w.top-v.height-E;L<4&&(I="bottom",L=w.bottom+E);let W=w.left+w.width/2-v.width/2;W=Math.max(4,Math.min(W,window.innerWidth-v.width-4)),u({top:L,left:W,side:I})},[i,e]),_.useEffect(()=>()=>window.clearTimeout(f.current),[]),_.useEffect(()=>{if(!i)return;const w=E=>{E.key==="Escape"&&a(!1)},v=()=>a(!1);return window.addEventListener("keydown",w),window.addEventListener("scroll",v,!0),window.addEventListener("resize",v),()=>{window.removeEventListener("keydown",w),window.removeEventListener("scroll",v,!0),window.removeEventListener("resize",v)}},[i]);const h=t,p=h.props,y=_.cloneElement(h,{ref:w=>{r.current=w;const v=h.ref;typeof v=="function"?v(w):v&&typeof v=="object"&&(v.current=w)},onPointerEnter:w=>{var v;(v=p.onPointerEnter)==null||v.call(p,w),m()},onPointerLeave:w=>{var v;(v=p.onPointerLeave)==null||v.call(p,w),g()},onFocus:w=>{var v;(v=p.onFocus)==null||v.call(p,w),m()},onBlur:w=>{var v;(v=p.onBlur)==null||v.call(p,w),g()},"aria-describedby":i?d:p["aria-describedby"]});return c.jsxs(c.Fragment,{children:[y,i&&typeof document<"u"&&Go.createPortal(c.jsx("div",{ref:s,id:d,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 No=12,Qx=56;function ey(){const e=V(),t=x(h=>h.selection),n=x(h=>h.selectedNode),o=x(h=>h.selectedWire),r=x(h=>h.activeTool),s=x(h=>h.rotateSelection),i=x(h=>h.mirrorSelection),a=x(h=>h.deleteSelection),l=x(h=>h.deleteSelectedNode),u=x(h=>h.deleteSelectedWire),d=_.useRef(null);_.useEffect(()=>{const h=d.current;if(!h)return;const p=t.length>0,y=!p&&o!=null,w=!p&&!y&&n!=null;if(!((p||y||w)&&(r==="select"||r==="pan"))){h.style.display="none";return}h.style.display="flex";let E=0,I="";const L=()=>{let W=1/0,le=-1/0,re=1/0,pe=-1/0,ue=!1;const $=T=>{T.width===0&&T.height===0||(T.left<W&&(W=T.left),T.right>le&&(le=T.right),T.top<re&&(re=T.top),T.bottom>pe&&(pe=T.bottom),ue=!0)};if(p)for(const T of t){const J=document.querySelector(`[data-element-id="${CSS.escape(T)}"]`);J&&$(J.getBoundingClientRect())}else if(y&&o){const T=document.querySelector(`polyline.ole-wire[data-wire-id="${CSS.escape(o)}"]`);T&&$(T.getBoundingClientRect())}else if(w&&n){const T=document.querySelectorAll(`polyline.ole-wire[data-node-id="${CSS.escape(n)}"]`);for(const J of T)$(J.getBoundingClientRect())}if(ue){const T=(W+le)/2;let J=re-No,ee="-100%";J<Qx&&(J=pe+No,ee="0%");const ie=`translate3d(${T}px, ${J}px, 0) translate(-50%, ${ee})`;ie!==I&&(h.style.transform=ie,I=ie)}E=requestAnimationFrame(L)};return E=requestAnimationFrame(L),()=>cancelAnimationFrame(E)},[t,n,o,r]);const f=t.length===0&&o!=null,m=t.length===0&&!f&&n!=null,g=m||f;return c.jsxs("div",{ref:d,role:"toolbar","aria-label":e(f?"ctx.ariaWire":m?"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:[!g&&c.jsxs(c.Fragment,{children:[c.jsx(Ce,{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(Te,{variant:"ghost",size:"icon",className:"size-7",onClick:()=>s(90),"aria-label":e("ctx.rotate"),children:c.jsx(Zo,{})})}),c.jsx(Ce,{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(Te,{variant:"ghost",size:"icon",className:"size-7",onClick:()=>i(),"aria-label":e("ctx.mirrorTitle"),children:c.jsx(Vo,{})})}),c.jsx("div",{"aria-hidden":!0,className:"mx-0.5 h-4 w-px bg-border"})]}),c.jsx(Ce,{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(f?"ctx.deleteHintWire":m?"ctx.deleteHintNode":"ctx.deleteHintElement")})]}),children:c.jsx(Te,{variant:"ghost",size:"icon",className:"size-7 text-destructive hover:text-destructive",onClick:()=>f?u():m?l():a(),"aria-label":e("ctx.delete"),children:c.jsx(er,{})})})]})}function Tn({open:e,onOpenChange:t,trigger:n,children:o}){const r=_.useRef(null);return _.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 $m="ole-panel-open";function ty(){if(typeof window>"u")return{outlineOpen:!1};try{const e=window.localStorage.getItem($m);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 To(e){try{const t={outline:e.outlineOpen};window.localStorage.setItem($m,JSON.stringify(t))}catch{}}const yt=Bt((e,t)=>({...ty(),setOutlineOpen:n=>{e({outlineOpen:n}),To(t())},toggleOutline:()=>{e(n=>({outlineOpen:!n.outlineOpen})),To(t())}})),Ct=[.1,.25,.5,.75,1,1.25,1.5,2,3,4,6,8],Em=.1,Nm=8,Tm="ole-grid";function ny(){try{const e=window.localStorage.getItem(Tm);return e==null?!0:e==="1"}catch{return!0}}function oy(e){try{window.localStorage.setItem(Tm,e?"1":"0")}catch{}}function ry(e,t,n){return e<t?t:e>n?n:e}function Cm(){return document.querySelector(".ole-canvas-root")}function Cn(e){const t=wt(),n=Cm();if(!t||!n)return;const o=n.getBoundingClientRect(),r=o.width/2,s=o.height/2,i=t.getViewport(),a=ry(e,Em,Nm),l=a/i.scale;t.setViewport({tx:r-(r-i.tx)*l,ty:s-(s-i.ty)*l,scale:a})}function sy(){const e=wt();if(!e)return;const t=e.getViewport().scale,n=Ct.find(o=>o>t+1e-6)??Nm;Cn(n)}function iy(){const e=wt();if(!e)return;const t=e.getViewport().scale;let n=Em;for(let o=Ct.length-1;o>=0;o--)if(Ct[o]<t-1e-6){n=Ct[o];break}Cn(n)}const ay={off:"id",id:"all",all:"off"};function ly(){var o;const e=x.getState(),t=((o=e.diagram.meta)==null?void 0:o.labelMode)??"all",n=ay[t];e.dispatch(r=>{const s={...r.meta??{},labelMode:n};return{...r,meta:s}})}function Im(){const[e,t]=_.useState(()=>ny());return _.useEffect(()=>{const n=Cm();n==null||n.classList.toggle("hide-grid",!e),oy(e)},[e]),_.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 Am(){const e=V();return c.jsx(Ce,{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(Te,{variant:"ghost",size:"icon",onClick:iy,"aria-label":e("view.zoomOut"),children:c.jsx(vn,{})})})}function Mm(){const e=V();return c.jsx(Ce,{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(Te,{variant:"ghost",size:"icon",onClick:sy,"aria-label":e("view.zoomIn"),children:c.jsx(_h,{})})})}function Pm(){const e=V(),[t,n]=_.useState(vx);return _.useEffect(()=>kx(n),[]),c.jsx(Ce,{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:()=>Cn(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 Om(){const e=V();return c.jsx(Ce,{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(Te,{variant:"ghost",size:"icon",onClick:En,"aria-label":e("view.fit"),children:c.jsx(wh,{})})})}function Lm({grid:e,setGrid:t}){const n=V();return c.jsx(Ce,{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(Te,{variant:"ghost",size:"icon",onClick:()=>t(o=>!o),"aria-label":n(e?"view.gridHideAria":"view.gridShowAria"),"aria-pressed":e,className:ye(!e&&"text-muted-foreground/60"),children:c.jsx(yh,{})})})}function Bm(){const e=V(),t=x(n=>{var o;return((o=n.diagram.meta)==null?void 0:o.labelMode)??"all"});return c.jsx(Ce,{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(Te,{variant:"ghost",size:"icon",onClick:ly,"aria-label":e("view.label"),"aria-pressed":t!=="off",className:ye(t==="off"&&"text-muted-foreground/60"),children:c.jsx(tr,{})})})}function cy({stacked:e}={}){const t=V(),[n,o]=_.useState(!1),[r,s]=Im(),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(Ce,{content:i,children:c.jsxs("button",{type:"button",onClick:()=>o(l=>!l),"aria-label":t("view.menu"),"aria-pressed":n,className:ye("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(sn,{className:"size-4"}),c.jsx("span",{className:"max-w-full truncate",children:t("view.menu")})]})}):c.jsx(Ce,{content:i,children:c.jsx(Te,{variant:"ghost",size:"icon",onClick:()=>o(l=>!l),"aria-label":t("view.menu"),"aria-pressed":n,children:c.jsx(sn,{})})});return c.jsx(Tn,{open:n,onOpenChange:o,trigger:a,children:c.jsxs("div",{className:"flex flex-col gap-0.5",children:[c.jsx(Pm,{}),c.jsxs("div",{className:"flex items-center gap-0.5",children:[c.jsx(Am,{}),c.jsx(Mm,{})]}),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(Om,{}),c.jsx(Lm,{grid:r,setGrid:s}),c.jsx(Bm,{})]})]})})}function dy(){const e=Ke();return Ne(e,"dense")?null:c.jsx(uy,{tier:e})}function uy({tier:e}){const t=Ne(e,"tight"),[n,o]=Im();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(Am,{}),!t&&c.jsx(Pm,{}),c.jsx(Mm,{}),c.jsx("div",{"aria-hidden":!0,className:"mx-1 h-4 w-px bg-border"}),c.jsx(Om,{}),c.jsx(Lm,{grid:n,setGrid:o}),c.jsx(Bm,{})]})})}const Co=[{id:"select",labelKey:"tool.select",hotkey:"V",descriptionKey:"tool.selectHint",icon:vh,switchTo:"select",iconOnly:!0},{id:"pan",labelKey:"tool.pan",hotkey:"H",descriptionKey:"tool.panHint",icon:bh,switchTo:"pan",groupBreakAfter:!0,iconOnly:!0},{id:"busbar",labelKey:"tool.bus",hotkey:"B",descriptionKey:"tool.busHint",icon:vn,switchTo:"busbar"},{id:"place",labelKey:"tool.place",hotkey:"P",descriptionKey:"tool.placeHint",icon:Qo,switchTo:"place"},{id:"wire",labelKey:"tool.wire",hotkey:"W",descriptionKey:"tool.wireHint",icon:qo,switchTo:"wire"},{id:"text",labelKey:"tool.text",hotkey:"T",descriptionKey:"tool.textHint",icon:tr,switchTo:"text",iconOnly:!0}];function fy(){const e=V(),t=x(d=>d.activeTool),n=x(d=>d.placeKind),o=x(d=>d.placeFromTerminal),r=x(d=>d.wireFromTerminal),s=x(d=>d.busbarDrawStart),i=x(d=>d.selection.length>0||d.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 u=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:["· ",u]})]})}function my(){const e=V(),t=x(h=>h.activeTool),n=x(h=>h.placeKind),o=x(h=>h.setActiveTool),r=x(h=>h.past.length),s=x(h=>h.future.length),i=x(h=>h.undo),a=x(h=>h.redo),l=Ke(),u=Ne(l,"tight"),d=!Ne(l,"dense"),f=Ne(l,"dense"),m=f?Co.filter(h=>h.id!=="select"&&h.id!=="text"):Co,g=h=>t===h.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:[d&&c.jsx(fy,{}),c.jsxs("div",{className:ye("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(hy,{stacked:!0}),m.map(h=>{const p=h.icon,y=g(h),w=h.id==="place"&&y&&n==null?e("tool.placeNoKindTooltip"):e(h.descriptionKey);return c.jsxs(_.Fragment,{children:[c.jsx(Je,{icon:p,label:e(h.labelKey),hotkey:h.hotkey,active:y,iconOnly:!f&&(h.iconOnly||u),stacked:f,description:w,onClick:()=>{o(h.switchTo,{placeKind:h.presetPlaceKind!==void 0?h.presetPlaceKind:void 0})}}),h.groupBreakAfter&&!f&&c.jsx("div",{"aria-hidden":!0,className:"mx-1 h-5 w-px bg-border"})]},h.id)}),!f&&c.jsx("div",{"aria-hidden":!0,className:"mx-1 h-5 w-px bg-border"}),f?c.jsx(gy,{stacked:!0}):c.jsxs(c.Fragment,{children:[c.jsx(Je,{icon:_n,label:e("tool.undo"),hotkey:"⌘Z",description:e("tool.undoHint"),iconOnly:!0,disabled:r===0,onClick:i}),c.jsx(Je,{icon:kn,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(py,{iconOnly:u})]}),f&&c.jsx(cy,{stacked:!0})]})]})}function hy({stacked:e}){const t=V(),n=yt(r=>r.outlineOpen),o=yt(r=>r.toggleOutline);return c.jsx(Je,{icon:Uo,label:t("outline.title"),active:n,iconOnly:!0,stacked:e,onClick:o})}function Je({icon:e,label:t,hotkey:n,active:o,disabled:r,iconOnly:s,stacked:i,onClick:a,description:l}){const u=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(Ce,{content:u,disabled:r,children:c.jsxs("button",{type:"button",onClick:a,disabled:r,"aria-label":t,"aria-pressed":o,className:ye("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:ye("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 Dm(){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 py({iconOnly:e}){const t=V(),[n,o]=_.useState(!1),r=Dm(),s=i=>()=>{o(!1),i()};return c.jsxs(Tn,{open:n,onOpenChange:o,trigger:c.jsx(Je,{icon:mt,label:t("layout.label"),description:t("layout.hint"),active:n,iconOnly:e,onClick:()=>o(i=>!i)}),children:[c.jsx(je,{onClick:s(()=>x.getState().autoArrangeAll()),icon:c.jsx(mt,{}),disabled:!r.hasAnyElement||!r.hasArrangedAny,children:t("layout.allAuto")}),c.jsx(je,{onClick:s(()=>x.getState().autoArrangeSelection()),icon:c.jsx(mt,{}),disabled:!r.hasSelection||!r.selectionHasArranged,children:t("layout.selAuto")}),c.jsx("div",{"aria-hidden":!0,className:"my-1 h-px bg-border"}),c.jsx(je,{onClick:s(()=>x.getState().fillUnplacedAll()),icon:c.jsx(It,{}),disabled:!r.hasGapsAll,children:t("layout.allFill")}),c.jsx(je,{onClick:s(()=>x.getState().fillUnplacedSelection()),icon:c.jsx(It,{}),disabled:!r.hasSelection||!r.selectionHasGaps,children:t("layout.selFill")})]})}function gy({stacked:e}){const t=V(),[n,o]=_.useState(!1),r=x(m=>m.past.length),s=x(m=>m.future.length),i=x(m=>m.undo),a=x(m=>m.redo),l=x(m=>m.selection.length>0),u=x(m=>m.clipboard!=null),d=Dm(),f=m=>()=>{o(!1),m()};return c.jsxs(Tn,{open:n,onOpenChange:o,trigger:c.jsx(Je,{icon:sn,label:t("tool.more"),description:t("tool.moreHint"),active:n,iconOnly:!0,stacked:e,onClick:()=>o(m=>!m)}),children:[c.jsx(je,{onClick:f(i),icon:c.jsx(_n,{}),disabled:r===0,children:t("tool.undo")}),c.jsx(je,{onClick:f(a),icon:c.jsx(kn,{}),disabled:s===0,children:t("tool.redo")}),c.jsx("div",{"aria-hidden":!0,className:"my-1 h-px bg-border"}),c.jsx(je,{onClick:f(()=>x.getState().cutSelection()),icon:c.jsx(Jo,{}),disabled:!l,children:t("menu.cut")}),c.jsx(je,{onClick:f(()=>x.getState().copySelection()),icon:c.jsx(Xo,{}),disabled:!l,children:t("menu.copy")}),c.jsx(je,{onClick:f(()=>x.getState().pasteClipboard()),icon:c.jsx(Yo,{}),disabled:!u,children:t("menu.paste")}),c.jsx("div",{"aria-hidden":!0,className:"my-1 h-px bg-border"}),c.jsx(je,{onClick:f(()=>x.getState().autoArrangeAll()),icon:c.jsx(mt,{}),disabled:!d.hasAnyElement||!d.hasArrangedAny,children:t("layout.allAuto")}),c.jsx(je,{onClick:f(()=>x.getState().autoArrangeSelection()),icon:c.jsx(mt,{}),disabled:!d.hasSelection||!d.selectionHasArranged,children:t("layout.selAuto")}),c.jsx(je,{onClick:f(()=>x.getState().fillUnplacedAll()),icon:c.jsx(It,{}),disabled:!d.hasGapsAll,children:t("layout.allFill")}),c.jsx(je,{onClick:f(()=>x.getState().fillUnplacedSelection()),icon:c.jsx(It,{}),disabled:!d.hasSelection||!d.selectionHasGaps,children:t("layout.selFill")})]})}function je({children:e,icon:t,onClick:n,disabled:o}){return c.jsxs("button",{type:"button",role:"menuitem",disabled:o,onClick:n,className:ye("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 xy(){const e=yt(r=>r.outlineOpen),t=yt(r=>r.setOutlineOpen),n=Ke();return Ne(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(Io,{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(Io,{onClose:()=>t(!1)}):c.jsx(yy,{onClick:()=>t(!0)})})}function yy({onClick:e}){const t=V(),n=Ke(),o=Ne(n,"compact");return c.jsxs("button",{type:"button",onClick:e,"aria-label":t("outline.title"),title:t("outline.title"),className:ye("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(Uo,{className:"size-4 shrink-0"}),!o&&c.jsx("span",{className:"text-xs font-medium",children:t("outline.title")})]})}function Io({onClose:e,sheet:t}){const n=V(),o=x(u=>u.diagram.elements),r=x(u=>u.activeTool==="place"),s=Ke(),i=Ne(s,"compact"),a=Ne(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:ye("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(wy,{children:o.length}),c.jsx(kh,{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(u=>c.jsx(by,{element:u},u.id))})})]})}function by({element:e}){const t=Ge[e.kind],n=x(l=>l.selection.includes(e.id)),o=x(l=>l.setSelection),r=x(l=>l.toggleInSelection),s=Ke(),i=!Ne(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 wy({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 vy={"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":"剩余动作电流"},ky={"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"},Ao={zh:vy,en:ky};function _y(e,t){return Ao[e][t]??Ao.zh[t]}function vt(){const e=bt(t=>t.locale);return(t,n)=>_y(e,t)??n??t}const Rm="ole-palette-collapsed",Sy=new Set(["busbar"]),pt=(()=>{const e={};for(const[t,n]of Object.entries(l0)){const o=n.filter(r=>!Sy.has(r.id));o.length&&(e[t]=o)}return e})(),jy=(()=>{const e=new Set(so),t=Object.keys(pt).filter(n=>!e.has(n));return[...so.filter(n=>{var o;return(o=pt[n])==null?void 0:o.length}),...t]})();function $y(){try{const e=window.localStorage.getItem(Rm);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 Ey(e){try{window.localStorage.setItem(Rm,JSON.stringify([...e]))}catch{}}function Ny(){const e=V(),t=x(f=>f.activeTool==="place"),n=x(f=>f.placeKind),o=x(f=>f.setActiveTool),r=yt(f=>f.outlineOpen),s=Ke(),i=Ne(s,"dense"),a=68,u=i?void 0:`calc(100vh - ${a}px - ${r?"calc(40vh + 20px)":"68px"})`;if(!t||i&&n!=null)return null;const d=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:d,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:u?{maxHeight:u}: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(Sn,{className:"size-3.5"})})]}),c.jsx(Ty,{sheet:i})]})})}function Ty({sheet:e}){const t=V(),n=vt(),[o,r]=_.useState(""),[s,i]=_.useState(()=>$y()),a=_.useMemo(()=>{const f=o.trim().toLowerCase();if(!f)return pt;const m={};for(const[g,h]of Object.entries(pt)){const p=h.filter(y=>{const w=n(`${y.id}.name`,y.name).toLowerCase(),v=n(`${y.id}.desc`,y.description??"").toLowerCase();return w.includes(f)||y.id.toLowerCase().includes(f)||v.includes(f)});p.length&&(m[g]=p)}return m},[o,n]),l=o.trim().length>0,u=l&&Object.values(a).every(f=>!(f!=null&&f.length)),d=_.useCallback((f,m)=>{i(g=>{const h=new Set(g);return m?h.delete(f):h.add(f),Ey(h),h})},[]);return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"px-2 pb-1.5 pt-2",children:c.jsx(Cy,{value:o,onChange:r})}),c.jsx("div",{className:"flex-1 overflow-y-auto px-2 pb-2",children:u?c.jsx("p",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:t("library.empty")}):jy.map(f=>{var y;const m=a[f];if(!(m!=null&&m.length))return null;const g=((y=pt[f])==null?void 0:y.length)??m.length,h=t(`cat.${f}`),p=l||!s.has(f);return c.jsxs("details",{open:p,className:"group mb-2 last:mb-0",onToggle:w=>{l||d(f,w.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(fh,{className:"size-3 transition-transform [details:not([open])>summary>&]:-rotate-90"}),c.jsx("span",{className:"flex-1",children:h}),c.jsx(Ay,{children:l&&m.length!==g?`${m.length}/${g}`:g})]}),c.jsx("ul",{className:"mt-0.5 space-y-px",children:m.map(w=>c.jsx(Iy,{entry:w,sheet:e},w.id))})]},f)})})]})}function Cy({value:e,onChange:t}){const n=V();return c.jsxs("div",{className:"relative",children:[c.jsx(Sh,{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(Sn,{className:"size-3"})})]})}function Iy({entry:e,sheet:t}){const n=V(),o=vt(),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),u=_.useRef(null);_.useEffect(()=>{var f;l&&((f=u.current)==null||f.scrollIntoView({block:"nearest"}))},[l]);const d=f=>{f.dataTransfer.effectAllowed="copy",f.dataTransfer.setData("application/x-oneline-kind",e.id),f.dataTransfer.setData("text/plain",e.id);const m=document.createElement("div");m.className="ole-glass",m.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(";"),m.innerHTML=`<svg class="ole-symbol" viewBox="${e.viewBox}" width="48" height="48" preserveAspectRatio="xMidYMid meet">${e.svg}</svg>`,document.body.appendChild(m),f.dataTransfer.setDragImage(m,32,32),setTimeout(()=>m.remove(),0)};return c.jsxs("li",{ref:u,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:d,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 Ay({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 bn="ole-onboarding-dismissed";function My(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(bn)==="1"}catch{return!1}}function Mo(e){try{e?window.localStorage.setItem(bn,"1"):window.localStorage.removeItem(bn)}catch{}}const Po=Bt(e=>({dismissed:My(),dismiss:()=>{Mo(!0),e({dismissed:!0})},reset:()=>{Mo(!1),e({dismissed:!1})}}));function Py(){const e=V(),t=Po(o=>o.dismissed),n=Po(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(Sn,{className:"size-3.5"})})]}),c.jsxs("ol",{className:"mt-3 space-y-2.5",children:[c.jsx(on,{n:1,icon:c.jsx(vn,{}),title:e("onboard.step1.title"),body:e("onboard.step1.body")}),c.jsx(on,{n:2,icon:c.jsx(Qo,{}),title:e("onboard.step2.title"),body:e("onboard.step2.body")}),c.jsx(on,{n:3,icon:c.jsx(qo,{}),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 on({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 Oy(){const e=V(),t=x(d=>d.selection),n=x(d=>d.diagram.elements),o=x(d=>d.diagram.buses),r=x(d=>d.selectedNode),s=x(d=>d.selectedWire);if(s)return c.jsx(Fy,{wireId:s});if(r)return c.jsx(Hy,{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(d=>d.id===i);if(a)return c.jsx(Ry,{bus:a});const l=n.find(d=>d.id===i);if(!l)return null;const u=Ge[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(kt,{label:e("props.name"),value:l.name??"",placeholder:l.id,onCommit:d=>x.getState().updateElement(i,{name:d.trim()===""?void 0:d.trim()})}),c.jsx(zm,{label:e("props.note"),value:l.note??"",onCommit:d=>x.getState().updateElement(i,{note:d.trim()===""?void 0:d.trim()})}),(u==null?void 0:u.state)&&u.state.length>0&&c.jsx("div",{className:"mt-1 flex flex-col gap-1.5 border-t border-border/40 pt-2.5",children:u.state.map(d=>c.jsx(Wy,{id:i,element:l,field:d},d.name))}),c.jsx(Ly,{id:i,element:l,schema:(u==null?void 0:u.params)??[]})]})}function Ly({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(By,{id:e,element:t,field:s},s.name)),r.map(([s,i])=>c.jsx(Dy,{id:e,element:t,fieldKey:s,value:i},s))]})}function By({id:e,element:t,field:n}){var l;const o=V(),r=vt(),s=((l=t.params)==null?void 0:l[n.name])??n.default,i=r(`${t.kind}.param.${n.name}`,n.label??n.name),a=u=>{const d={...t.params??{}};u===void 0||u===n.default?delete d[n.name]:d[n.name]=u,x.getState().updateElement(e,{params:Object.keys(d).length>0?d:void 0})};return n.type==="boolean"?c.jsx(nt,{label:i,children:c.jsx(In,{active:!!s,onClick:()=>a(!s),children:o(s?"common.yes":"common.no")})}):n.type==="number"?c.jsx(Wt,{label:i,value:typeof s=="number"?s:0,unit:n.unit,onCommit:a}):c.jsx(kt,{label:i,value:typeof s=="string"?s:"",unit:n.unit,onCommit:u=>a(u.trim()===""?void 0:u)})}function Dy({id:e,element:t,fieldKey:n,value:o}){const r=V(),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(nt,{label:n,children:c.jsx(In,{active:o,onClick:()=>s(!o),children:r(o?"common.yes":"common.no")})}):typeof o=="number"?c.jsx(Wt,{label:n,value:o,onCommit:s}):c.jsx(kt,{label:n,value:o,onCommit:i=>s(i.trim()===""?void 0:i)})}function Ry({bus:e}){const t=V(),n=e.id,o=r=>{const s=r.trim();wn(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(kt,{label:t("props.name"),value:e.name??"",placeholder:e.id,onCommit:o}),c.jsx(zm,{label:t("props.note"),value:e.note??"",onCommit:r=>wn(n,{note:r.trim()===""?void 0:r.trim()})}),c.jsx(zy,{bus:e})]})}function zy({bus:e}){const t=(o,r)=>{const s={...e.params??{}};r===void 0||r===""?delete s[o]:s[o]=r,wn(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(Wt,{label:"Un",value:typeof n.Un=="number"?n.Un:0,unit:"kV",onCommit:o=>t("Un",o)})})}function wn(e,t){x.getState().dispatch(n=>{const o=(n.buses??[]).map(r=>r.id===e?{...r,...t}:r);return{...n,buses:o}})}function Fy({wireId:e}){const t=V(),n=x(h=>h.diagram.wires),o=x(h=>h.diagram.elements),r=x(h=>h.diagram.buses),s=x(h=>h.internal.terminalToNode),i=x(h=>h.setSelectedNode),a=(n??[]).find(h=>h.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]),u=new Map(o.map(h=>[h.id,h])),d=new Map((r??[]).map(h=>[h.id,h])),f=h=>{if(!h.includes(".")){const E=d.get(h);return{id:h,label:(E==null?void 0:E.name)??h}}const p=h.indexOf("."),y=h.slice(0,p),w=h.slice(p+1),v=u.get(y);return{id:y,label:(v==null?void 0:v.name)??y,pin:w}},m=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:[m,g].map((h,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([h.id]),children:[c.jsx("span",{className:"flex-1 truncate font-mono text-[11px]",children:h.id}),c.jsx("span",{className:"truncate text-[10px] text-muted-foreground",children:h.label}),h.pin&&c.jsx("span",{className:"font-mono text-[10px] text-muted-foreground/80",children:h.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 Hy({nodeId:e}){const t=V(),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 u=a.slice(0,l),d=a.slice(l+1),f=s.get(u)??[];f.push(d),s.set(u,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 u=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:(u==null?void 0:u.name)??""}),c.jsx("span",{className:"font-mono text-[10px] text-muted-foreground/80",children:l.join(", ")})]},a)})})]})}function nt({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 kt({label:e,value:t,placeholder:n,unit:o,onCommit:r}){const[s,i]=_.useState(t),a=_.useRef(null);return _.useEffect(()=>i(t),[t]),c.jsx(nt,{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 u,d;l.key==="Enter"&&((u=a.current)==null||u.blur()),l.key==="Escape"&&(i(t),(d=a.current)==null||d.blur())},className:ye("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 zm({label:e,value:t,onCommit:n}){const[o,r]=_.useState(t);return _.useEffect(()=>r(t),[t]),c.jsx(nt,{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 Wt({label:e,value:t,min:n,unit:o,onCommit:r}){const[s,i]=_.useState(String(t)),a=_.useRef(null);return _.useEffect(()=>i(String(t)),[t]),c.jsx(nt,{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 u,d;l.key==="Enter"&&((u=a.current)==null||u.blur()),l.key==="Escape"&&(i(String(t)),(d=a.current)==null||d.blur())},min:n,className:ye("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 In({active:e,onClick:t,children:n}){return c.jsx("button",{type:"button",onClick:t,className:ye("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 Wy({id:e,element:t,field:n}){var l;const o=V(),s=vt()(`${t.kind}.state.${n.name}`,n.label??n.name),i=((l=t.state)==null?void 0:l[n.name])??n.default,a=u=>{const d={...t.state??{}};u===void 0||u===n.default?delete d[n.name]:d[n.name]=u,x.getState().updateElement(e,{state:Object.keys(d).length>0?d:void 0})};return n.type==="boolean"?c.jsx(nt,{label:s,children:c.jsx(In,{active:!!i,onClick:()=>a(!i),children:o(i?"common.yes":"common.no")})}):n.type==="number"?c.jsx(Wt,{label:s,value:typeof i=="number"?i:0,onCommit:a}):c.jsx(kt,{label:s,value:typeof i=="string"?i:"",onCommit:u=>a(u.trim()===""?void 0:u)})}function Gy(){const e=V(),t=vt(),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=Ke(),l=Ne(a,"dense");if(n.length===0&&!o&&!r)return null;let u=e("props.title"),d=null;if(r)u=e("props.wire");else if(o)u=e("props.node");else if(n.length===1){const f=n[0],m=(i??[]).find(g=>g.id===f);if(m)u=m.name??e("props.bus");else{const g=s.find(h=>h.id===f);if(g){const h=Ge[g.kind];u=h?t(`${h.id}.name`,h.name):g.kind}}}else d=n.length;return c.jsxs("aside",{className:ye("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:u}),d!=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:d})})]}),c.jsx(Oy,{})]})}function Ky(){_.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 qy(){Ky();const e=_.useRef(null),t=fx(e);return c.jsx(sp,{children:c.jsx("div",{ref:e,className:"relative h-full w-full overflow-hidden bg-background text-foreground",children:c.jsxs(Rx,{width:t,children:[c.jsx(Tx,{}),c.jsx(xy,{}),c.jsx(Gy,{}),c.jsx(my,{}),c.jsx(dy,{}),c.jsx(ey,{}),c.jsx(Ny,{}),c.jsx(Py,{}),c.jsx(Bx,{})]})})})}const Yy="ole-theme";function Xy(){try{const e=window.localStorage.getItem(Yy);return e==="light"||e==="dark"?e:null}catch{return null}}function Vy(){return typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-color-scheme: dark)").matches}function Uy(){return typeof window>"u"?"light":Xy()??(Vy()?"dark":"light")}function Fm(e){typeof document>"u"||document.documentElement.classList.toggle("dark",e==="dark")}function Zy({className:e,diagram:t,locale:n,theme:o}){return _.useEffect(()=>{if(!t)return;x.getState().diagram.elements.length===0&&x.getState().setDiagram(t)},[t]),_.useEffect(()=>{n&&bt.getState().setLocale(n)},[n]),_.useEffect(()=>{o&&Fm(o)},[o]),_.useEffect(()=>{Nn()},[]),Z0(),c.jsx("div",{className:`ole-root ${e??"h-full w-full"}`,children:c.jsx(qy,{})})}const Hm={"application/json":[".json"]},Wm=()=>typeof window<"u"&&typeof window.showOpenFilePicker=="function",Gm=e=>e instanceof DOMException&&e.name==="AbortError";function Oo(e){let t;try{t=JSON.parse(e)}catch(o){throw new Error(xe("io.parseFailed",{err:o.message}))}if(!t||typeof t!="object"||Array.isArray(t))throw new Error(xe("io.notObject"));const n=t;if(n.version!=="1")throw new Error(xe("io.versionMismatch",{actual:JSON.stringify(n.version)}));if(!Array.isArray(n.elements))throw new Error(xe("io.elementsMissing"));return n}function Jy(e){return JSON.stringify(e,null,2)+`
|
|
188
|
+
`}async function Qy(){if(Wm()){let e;try{[e]=await window.showOpenFilePicker({multiple:!1,types:[{description:xe("topbar.file.fileDescription"),accept:Hm}]})}catch(n){if(Gm(n))return null;throw n}const t=await e.getFile();return{diagram:Oo(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:Oo(await o.text()),session:{name:o.name}})}catch(s){t(s)}}),n.addEventListener("cancel",()=>e(null)),n.click()})}async function Lo(e,t,n={}){const o=Jy(e);if(!n.saveAs&&(t!=null&&t.handle)){const i=await t.handle.createWritable();return await i.write(o),await i.close(),t}if(Wm()){let i;try{i=await window.showSaveFilePicker({suggestedName:(t==null?void 0:t.name)??"diagram.json",types:[{description:xe("topbar.file.fileDescription"),accept:Hm}]})}catch(l){if(Gm(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 eb(){const e=V(),t=x(f=>f.fileSession),n=(t==null?void 0:t.name)??e("common.unnamed"),{onNew:o,onOpen:r,onSave:s,onSaveAs:i}=tb(),[a,l]=_.useState(!1),u=_.useRef(null);_.useEffect(()=>{const f=m=>{if(!(m.metaKey||m.ctrlKey))return;const g=m.key.toLowerCase();g==="o"?(m.preventDefault(),r()):g==="s"&&(m.preventDefault(),m.shiftKey?i():s())};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[r,s,i]),_.useEffect(()=>{if(!a)return;const f=g=>{u.current&&!u.current.contains(g.target)&&l(!1)},m=g=>{g.key==="Escape"&&l(!1)};return window.addEventListener("mousedown",f),window.addEventListener("keydown",m),()=>{window.removeEventListener("mousedown",f),window.removeEventListener("keydown",m)}},[a]);const d=f=>()=>{l(!1),f()};return c.jsxs("div",{ref:u,className:"relative",children:[c.jsxs(Te,{variant:"ghost",size:"sm",className:"gap-1.5","aria-haspopup":"menu","aria-expanded":a,onClick:()=>l(f=>!f),children:[c.jsx(Rn,{}),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(Nt,{onClick:d(o),icon:c.jsx(gh,{}),children:e("topbar.file.new")}),c.jsx(Nt,{onClick:d(r),icon:c.jsx(Rn,{}),hint:"⌘O",children:e("topbar.file.open")}),c.jsx(Nt,{onClick:d(s),icon:c.jsx(zn,{}),hint:"⌘S",children:e("topbar.file.save")}),c.jsx(Nt,{onClick:d(i),icon:c.jsx(zn,{}),hint:"⌘⇧S",children:e("topbar.file.saveAs")})]})]})}function Nt({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 tb(){const e=V(),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 Qy();l&&(t(l.diagram,l.session),Nn())}catch(l){alert(e("topbar.file.openFailed",{err:l.message}))}},onSave:async()=>{try{const{diagram:l,fileSession:u}=x.getState(),d=await Lo(l,u);d&&n(d)}catch(l){alert(e("topbar.file.saveFailed",{err:l.message}))}},onSaveAs:async()=>{try{const{diagram:l,fileSession:u}=x.getState(),d=await Lo(l,u,{saveAs:!0});d&&n(d)}catch(l){alert(e("topbar.file.saveFailed",{err:l.message}))}}}}const rn="WIRES",Be="ELEMENTS",Bo="LABELS",Do="ANNOTATIONS",Ro=32,zo=64,nb=8,ob=1.25,rb=6;function Km(e,t={}){const n=new xb(t.precision??6);n.header(t.title),n.tables([{name:rn,color:7},{name:Be,color:7},{name:Bo,color:8},{name:Do,color:3}]),n.beginEntities();for(const r of e.wireRenders.values())r.path.length<2||n.lwpolyline(rn,r.path.map($e),!1);for(const{geometry:r}of e.buses.values()){const{axis:s,at:i,span:a}=r,l=a/2,u=s==="x"?[i[0]-l,i[1]]:[i[0],i[1]-l],d=s==="x"?[i[0]+l,i[1]]:[i[0],i[1]+l];n.lwpolyline(rn,[u,d].map($e),!1)}for(const r of e.elements.values()){const s=e.layout.get(r.element.id),i=r.libraryDef;!s||!i||sb(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=Rt(r,o);if(i.length===0)continue;const a=r.libraryDef.label??zt(r.libraryDef),[l,u]=Ft(a,s);for(let d=0;d<i.length;d++){const[f,m]=$e([l,u+d*Dt]);n.text(Bo,[f,m],i[d],Mt,0,!1)}}for(const r of t.annotations??[]){if(!r.text)continue;const s=r.fontSize??nb,i=r.text.split(`
|
|
189
|
+
`);for(let a=0;a<i.length;a++){const[l,u]=$e([r.at[0],r.at[1]+(a+1)*s*ob]);n.text(Do,[l,u],i[a],s,0,!1)}}return n.endEntities(),n.toString()}async function qm(e,t="diagram.dxf",n){const o=Km(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 sb(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":ib(e,i,n);break;case"polyline":Fo(e,i,n,!1);break;case"polygon":Fo(e,i,n,!0);break;case"rect":ab(e,i,n);break;case"circle":lb(e,i,n);break;case"ellipse":cb(e,i,n);break;case"path":mb(e,i,n);break;case"text":fb(e,i,n);break}}function ib(e,t,n){const o=fe(t,"x1"),r=fe(t,"y1"),s=fe(t,"x2"),i=fe(t,"y2"),a=$e(Le([o,r],n)),l=$e(Le([s,i],n));e.line(Be,a,l)}function Fo(e,t,n,o){const r=gb(t.getAttribute("points")??"");if(r.length<2)return;const s=r.map(i=>$e(Le(i,n)));e.lwpolyline(Be,s,o)}function ab(e,t,n){const o=fe(t,"x"),r=fe(t,"y"),s=fe(t,"width"),i=fe(t,"height"),l=[[o,r],[o+s,r],[o+s,r+i],[o,r+i]].map(u=>$e(Le(u,n)));e.lwpolyline(Be,l,!0)}function lb(e,t,n){const o=fe(t,"cx"),r=fe(t,"cy"),s=fe(t,"r"),i=$e(Le([o,r],n));e.circle(Be,i,s)}function cb(e,t,n){const o=fe(t,"cx"),r=fe(t,"cy"),s=fe(t,"rx"),i=fe(t,"ry");if(Math.abs(s-i)<1e-6){db(e,o,r,s,n);return}ub(e,o,r,s,i,n)}function db(e,t,n,o,r){const s=$e(Le([t,n],r));e.circle(Be,s,o)}function ub(e,t,n,o,r,s){const i=[];for(let a=0;a<zo;a++){const l=a/zo*Math.PI*2;i.push($e(Le([t+o*Math.cos(l),n+r*Math.sin(l)],s)))}e.lwpolyline(Be,i,!0)}function fb(e,t,n){const o=fe(t,"x"),r=fe(t,"y"),s=parseFloat(t.getAttribute("font-size")??"")||rb,i=(t.textContent??"").trim();if(!i)return;const a=$e(Le([o,r],n));e.text(Be,a,i,s,n.rot,n.mirror)}function mb(e,t,n){const o=t.getAttribute("d")??"",r=hb(o);if(r.length===0)return;let s=null,i=[];const a=()=>{i.length>=2&&e.lwpolyline(Be,i.map(l=>$e(Le(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[u,d,,f,m,g,h]=l.args,p=pb(s,[g,h],u,d,f!==0,m!==0);if(p)for(let y=1;y<=Ro;y++){const w=p.theta1+p.delta*y/Ro;i.push([p.cx+u*Math.cos(w),p.cy+d*Math.sin(w)])}else i.push([g,h]);s=[g,h]}a()}function hb(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 pb(e,t,n,o,r,s){if(n<=0||o<=0)return null;const[i,a]=e,[l,u]=t;if(i===l&&a===u)return null;const d=(i-l)/2,f=(a-u)/2;let m=Math.abs(n),g=Math.abs(o);const h=m*m,p=g*g,y=d*d/h+f*f/p;if(y>1){const T=Math.sqrt(y);m*=T,g*=T}const w=r===s?-1:1,v=m*m*g*g-m*m*f*f-g*g*d*d,E=m*m*f*f+g*g*d*d,I=w*Math.sqrt(Math.max(0,v/E)),L=I*(m*f)/g,W=I*-(g*d)/m,le=L+(i+l)/2,re=W+(a+u)/2,pe=(T,J,ee,ie)=>{const be=T*ee+J*ie,Ie=Math.hypot(T,J)*Math.hypot(ee,ie);let de=Math.acos(Math.max(-1,Math.min(1,be/Ie)));return T*ie-J*ee<0&&(de=-de),de},ue=pe(1,0,(d-L)/m,(f-W)/g);let $=pe((d-L)/m,(f-W)/g,(-d-L)/m,(-f-W)/g);return!s&&$>0?$-=2*Math.PI:s&&$<0&&($+=2*Math.PI),{cx:le,cy:re,theta1:ue,delta:$}}function Le(e,t){return Oe(e,t)}function $e(e){return[e[0],-e[1]]}function fe(e,t){const n=parseFloat(e.getAttribute(t)??"");return Number.isFinite(n)?n:0}function gb(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 xb{constructor(t){ot(this,"out",[]);ot(this,"precision");this.precision=t}toString(){return this.out.join("")}g(t,n){this.out.push(`${t}
|
|
190
190
|
${this.fmt(n)}
|
|
191
|
-
`)}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,
|
|
192
|
-
`)
|
|
191
|
+
`)}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,Ho(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,Ho(o)),s!==0&&this.g(50,s),i&&this.g(71,2)}}function Ho(e){return e.replace(/[\r\n]+/g," ").slice(0,250)}const yb="http://www.w3.org/2000/svg",Tt=24,Ym=8,Xm=1.25;function An(e,t={}){const n=bb(e,t),o=Math.floor(n.minX-Tt),r=Math.floor(n.minY-Tt),s=Math.ceil(n.maxX+Tt)-o,i=Math.ceil(n.maxY+Tt)-r,a=t.background??"#FFFFFF",l=[];l.push('<?xml version="1.0" encoding="UTF-8"?>'),l.push(`<svg xmlns="${yb}" viewBox="${o} ${r} ${s} ${i}" width="${s}" height="${i}">`),t.title&&l.push(` <title>${ut(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 m=f.path.map(([g,h])=>`${g},${h}`).join(" ");l.push(` <polyline points="${m}"/>`)}l.push(" </g>");for(const{bus:f,geometry:m}of e.buses.values()){const{axis:g,at:h,span:p}=m,y=p/2,w=g==="x"?h[0]-y:h[0],v=g==="x"?h[1]:h[1]-y,E=g==="x"?h[0]+y:h[0],I=g==="x"?h[1]:h[1]+y;l.push(` <line id="${ut(f.id)}" x1="${w}" y1="${v}" x2="${E}" y2="${I}" stroke="black" stroke-width="3" stroke-linecap="round" fill="none"/>`)}for(const f of e.elements.values()){if(!f.libraryDef)continue;const m=e.layout.get(f.element.id);m&&(l.push(` <g id="${ut(f.element.id)}" transform="${We(m)}">`),l.push(` ${f.libraryDef.svg}`),l.push(" </g>"))}const u=t.labelMode??"all";if(u!=="off"){const f=a==="transparent"?"#FFFFFF":a;l.push(` <g fill="black" font-family="ui-sans-serif, system-ui, sans-serif" font-size="${Mt}" paint-order="stroke" stroke="${f}" stroke-width="2" stroke-linejoin="round">`);for(const m of e.elements.values()){const g=e.layout.get(m.element.id);if(!g||!m.libraryDef)continue;const h=Rt(m,u);if(h.length===0)continue;const p=m.libraryDef.label??zt(m.libraryDef),[y,w]=Ft(p,g),v=p.anchor??"start";for(let E=0;E<h.length;E++)l.push(` <text x="${y}" y="${w+E*Dt}" text-anchor="${v}">${ut(h[E])}</text>`)}l.push(" </g>")}const d=t.annotations??[];if(d.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 m of d){if(!m.text)continue;const g=m.fontSize??Ym,h=m.text.split(`
|
|
192
|
+
`);for(let p=0;p<h.length;p++){const y=m.at[1]+g*.85+p*g*Xm;l.push(` <text x="${m.at[0]}" y="${y}" font-size="${g}">${ut(h[p])}</text>`)}}l.push(" </g>")}return l.push("</svg>"),l.join(`
|
|
193
|
+
`)}function bb(e,t){let n=1/0,o=1/0,r=-1/0,s=-1/0;const i=(l,u)=>{l<n&&(n=l),l>r&&(r=l),u<o&&(o=u),u>s&&(s=u)};for(const l of e.terminals.values())i(l.world[0],l.world[1]);for(const l of e.elements.values()){const u=e.layout.get(l.element.id),d=l.libraryDef;if(!u||!d)continue;const f=wb(d.viewBox);if(!f){i(u.at[0],u.at[1]);continue}const m=[[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 m){const[h,p]=Oe(g,u);i(h,p)}}for(const{geometry:l}of e.buses.values()){const{axis:u,at:d,span:f}=l,m=f/2;u==="x"?(i(d[0]-m,d[1]),i(d[0]+m,d[1])):(i(d[0],d[1]-m),i(d[0],d[1]+m))}for(const l of e.wireRenders.values())for(const[u,d]of l.path)i(u,d);const a=t.labelMode??"all";if(a!=="off")for(const l of e.elements.values()){const u=e.layout.get(l.element.id);if(!u||!l.libraryDef)continue;const d=Rt(l,a);if(d.length===0)continue;const f=l.libraryDef.label??zt(l.libraryDef),[m,g]=Ft(f,u),h=Wo(d,Mt),p=d.length*Dt,y=f.anchor??"start",w=y==="middle"?m-h/2:y==="end"?m-h:m;i(w,g-Mt),i(w+h,g+p)}for(const l of t.annotations??[]){if(!l.text)continue;const u=l.fontSize??Ym,d=l.text.split(`
|
|
194
|
+
`),f=Wo(d,u),m=d.length*u*Xm;i(l.at[0],l.at[1]),i(l.at[0]+f,l.at[1]+m)}return n===1/0&&(n=0,o=0,r=0,s=0),{minX:n,minY:o,maxX:r,maxY:s}}function Wo(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 wb(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,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}async function Vm(e,t="diagram.svg",n){const o=An(e,n);Zm(new Blob([o],{type:"image/svg+xml;charset=utf-8"}),t)}async function Um(e,t="diagram.png",n){const o=An(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 vb(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 u=await new Promise((d,f)=>{a.toBlob(m=>m?d(m):f(new Error("toBlob failed")),"image/png")});Zm(u,t)}finally{URL.revokeObjectURL(s)}}function vb(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 Zm(e,t){const n=URL.createObjectURL(e),o=document.createElement("a");o.href=n,o.download=t,o.click(),URL.revokeObjectURL(n)}function kb(){const e=V(),[t,n]=_.useState(!1),o=_.useRef(null);_.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,m,g,h;n(!1);const{internal:i,diagram:a,fileSession:l}=x.getState(),u=((f=l==null?void 0:l.name)==null?void 0:f.replace(/\.json$/i,""))??((m=a.meta)==null?void 0:m.title)??"diagram",d={title:(g=a.meta)==null?void 0:g.title,labelMode:(h=a.meta)==null?void 0:h.labelMode,annotations:a.annotations};s==="svg"?Vm(i,`${u}.svg`,d):s==="png"?Um(i,`${u}.png`,{...d,scale:2}).catch(p=>{console.error(p),alert(e("topbar.export.pngFailed",{err:p.message}))}):qm(i,`${u}.dxf`,d).catch(p=>{console.error(p),alert(e("topbar.export.dxfFailed",{err:p.message}))})};return c.jsxs("div",{ref:o,className:"relative",children:[c.jsxs(Te,{variant:"ghost",size:"sm",className:"gap-1.5","aria-haspopup":"menu","aria-expanded":t,onClick:()=>n(s=>!s),children:[c.jsx(mh,{}),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(xh,{}),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(ph,{}),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(hh,{}),c.jsx("span",{className:"flex-1",children:"DXF"})]})]})]})}exports.ExportMenu=kb;exports.FileMenu=eb;exports.LIBRARY=un;exports.OneLineEditor=Zy;exports.applyTheme=Fm;exports.buildExportDxf=Km;exports.buildExportSvg=An;exports.compile=Fe;exports.downloadDxf=qm;exports.downloadPng=Um;exports.downloadSvg=Vm;exports.emptyInternalModel=hr;exports.fitToContent=En;exports.fitToContentSoon=Nn;exports.getInitialTheme=Uy;exports.getLibraryEntry=cm;exports.newBusId=fn;exports.newElementId=gt;exports.orientationVec=dn;exports.resolvePlacement=pr;exports.transformOrientation=ht;exports.transformPoint=Oe;exports.useEditorStore=x;exports.useLocale=bt;exports.wireIdFromEnds=xt;
|
|
193
195
|
//# sourceMappingURL=sldeditor.cjs.map
|