@tscircuit/runframe 0.0.999 → 0.0.1001

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.
@@ -5298,7 +5298,7 @@ ${A}
5298
5298
  \`\`\`
5299
5299
  ${P.type}: ${k}
5300
5300
  \`\`\``}m(I,$)},children:[ye.jsx(Q0e,{className:"rf-w-4 rf-h-4"}),"Report Issue"]})]})]})};function F_n(t,e,n){const{transform:i,shouldDrawErrors:r}=n;if(!r)return[];const{pcb_port_ids:o}=t,s=e.find(h=>h.type==="pcb_port"&&h.pcb_port_id===o?.[0]),a=e.find(h=>h.type==="pcb_port"&&h.pcb_port_id===o?.[1]);if(!s||!a){const f=t.message?.match(/pcb_via\[#?(pcb_via_\d+)\]/)?.[1],m=e.find(y=>y.type==="pcb_via"&&y.pcb_via_id===f);if(m&&m.type==="pcb_via")return B_n(t,m,n);if(t.center){const y=Yt(i,{x:t.center.x,y:t.center.y});return[{name:"rect",type:"element",attributes:{x:(y.x-5).toString(),y:(y.y-5).toString(),width:"10",height:"10",fill:"red",transform:`rotate(45 ${y.x} ${y.y})`},children:[],value:""},{name:"text",type:"element",attributes:{x:y.x.toString(),y:(y.y-15).toString(),fill:"red","font-family":"sans-serif","font-size":"12","text-anchor":"middle"},children:[{type:"text",value:t.message||"Pcb Trace Error",name:"",attributes:{},children:[]}],value:""}]}else return[]}const c=Yt(i,{x:s.x,y:s.y}),l=Yt(i,{x:a.x,y:a.y}),u={x:(c.x+l.x)/2,y:(c.y+l.y)/2};return isNaN(c.x)||isNaN(c.y)||isNaN(l.x)||isNaN(l.y)||isNaN(u.x)||isNaN(u.y)?[]:[{name:"line",type:"element",attributes:{x1:c.x.toString(),y1:c.y.toString(),x2:u.x.toString(),y2:u.y.toString(),stroke:"red","stroke-width":"1.5","stroke-dasharray":"2,2"},children:[],value:""},{name:"line",type:"element",attributes:{x1:u.x.toString(),y1:u.y.toString(),x2:l.x.toString(),y2:l.y.toString(),stroke:"red","stroke-width":"1.5","stroke-dasharray":"2,2"},children:[],value:""},{name:"rect",type:"element",attributes:{x:(u.x-5).toString(),y:(u.y-5).toString(),width:"10",height:"10",fill:"red",transform:`rotate(45 ${u.x} ${u.y})`},children:[],value:""},{name:"text",type:"element",attributes:{x:u.x.toString(),y:(u.y-15).toString(),fill:"red","font-family":"sans-serif","font-size":"12","text-anchor":"middle"},children:[{type:"text",value:t.message||"Pcb Trace Error",name:"",attributes:{},children:[]}],value:""}]}function B_n(t,e,n){const{transform:i}=n;if(t.center&&e){const r=Yt(i,{x:t.center.x,y:t.center.y}),o=Yt(i,{x:e.x,y:e.y}),s=o.x-r.x,a=o.y-r.y,c=Math.sqrt(s*s+a*a),l=Math.atan2(a,s)*180/Math.PI,d=c+10*2,h=20,f=(r.x+o.x)/2,m=(r.y+o.y)/2;return[{name:"rect",type:"element",attributes:{x:(f-d/2).toString(),y:(m-h/2).toString(),width:d.toString(),height:h.toString(),fill:"none",stroke:"red","stroke-width":"1","stroke-dasharray":"3,2",transform:`rotate(${l} ${f} ${m})`},children:[],value:""},{name:"rect",type:"element",attributes:{x:(f-5).toString(),y:(m-5).toString(),width:"10",height:"10",fill:"red",transform:`rotate(45 ${f} ${m})`},children:[],value:""},{name:"text",type:"element",attributes:{x:f.toString(),y:(m-h/2-5).toString(),fill:"red","font-family":"sans-serif","font-size":"12","text-anchor":"middle"},children:[{type:"text",value:t.message||"Pcb Trace Error",name:"",attributes:{},children:[]}],value:""}]}return[]}function U_n(t,e){const{transform:n,layer:i}=e;if(!t.route||!Array.isArray(t.route))return[];const r=t.route[0],o=t.route[t.route.length-1],s=r.x===o.x&&r.y===o.y,a=t.route.slice(0,s?-1:void 0).map((c,l)=>{const[u,d]=Yt(n,[c.x,c.y]);return l===0?`M ${u} ${d}`:`L ${u} ${d}`}).join(" ")+(s?" Z":"");return[{name:"path",type:"element",attributes:{class:"pcb-fabrication-note-path",stroke:t.color||"rgba(255,255,255,0.5)",fill:"none",d:a,"stroke-width":(t.stroke_width*Math.abs(n.a)).toString(),"data-pcb-component-id":t.pcb_component_id,"data-pcb-fabrication-note-path-id":t.pcb_fabrication_note_path_id},value:"",children:[]}]}function $_n(t,e){const{transform:n,layer:i}=e,{anchor_position:r,anchor_alignment:o,text:s,font_size:a=1,layer:c="top",color:l}=t;if(i&&c!==i)return[];if(!r||typeof r.x!="number"||typeof r.y!="number")return console.error("Invalid anchor_position:",r),[];const[u,d]=Yt(n,[r.x,r.y]),h=a*Math.abs(n.a),f=cs(Cs(u,d),ov(Math.PI/180));return[{name:"text",type:"element",attributes:{x:"0",y:"0","font-family":"Arial, sans-serif","font-size":h.toString(),"text-anchor":"middle","dominant-baseline":"central",transform:aw(f),class:"pcb-fabrication-note-text",fill:l||"rgba(255,255,255,0.5)"},children:[{type:"text",value:s,name:"",attributes:{},children:[]}],value:""}]}function j_n(t,e){const{transform:n,colorMap:i}=e,[r,o]=Yt(n,[t.x,t.y]);if(t.shape==="pill"){const s=t.outer_width*Math.abs(n.a),a=t.outer_height*Math.abs(n.a),c=t.hole_width*Math.abs(n.a),l=t.hole_height*Math.abs(n.a),u=s/2,d=c/2,h=a-s,f=t.ccw_rotation||0,m=f?`translate(${r} ${o}) rotate(${-f})`:`translate(${r} ${o})`,y=f?`translate(${r} ${o}) rotate(${-f})`:`translate(${r} ${o})`;return[{name:"g",type:"element",children:[{name:"path",type:"element",attributes:{class:"pcb-hole-outer",fill:i.copper.top,d:`M${-u},${-h/2} v${h} a${u},${u} 0 0 0 ${s},0 v-${h} a${u},${u} 0 0 0 -${s},0 z`,transform:m},value:"",children:[]},{name:"path",type:"element",attributes:{class:"pcb-hole-inner",fill:i.drill,d:`M${-d},${-(l-c)/2} v${l-c} a${d},${d} 0 0 0 ${c},0 v-${l-c} a${d},${d} 0 0 0 -${c},0 z`,transform:y},value:"",children:[]}],value:"",attributes:{}}]}if(t.shape==="circle"){const s=t.outer_diameter*Math.abs(n.a),a=t.outer_diameter*Math.abs(n.a),c=t.hole_diameter*Math.abs(n.a),l=t.hole_diameter*Math.abs(n.a),u=Math.min(s,a)/2,d=Math.min(c,l)/2;return[{name:"g",type:"element",children:[{name:"circle",type:"element",attributes:{class:"pcb-hole-outer",fill:i.copper.top,cx:r.toString(),cy:o.toString(),r:u.toString()},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"pcb-hole-inner",fill:i.drill,cx:r.toString(),cy:o.toString(),r:d.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(t.shape==="circular_hole_with_rect_pad"){const s=t,a=t.hole_diameter*Math.abs(n.a),c=t.rect_pad_width*Math.abs(n.a),l=t.rect_pad_height*Math.abs(n.a),u=(t.rect_border_radius??0)*Math.abs(n.a),d=a/2,[h,f]=Yt(n,[s.x+(s.hole_offset_x??0),s.y+(s.hole_offset_y??0)]);return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"pcb-hole-outer-pad",fill:i.copper.top,x:(r-c/2).toString(),y:(o-l/2).toString(),width:c.toString(),height:l.toString(),...u?{rx:u.toString(),ry:u.toString()}:{}},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"pcb-hole-inner",fill:i.drill,cx:h.toString(),cy:f.toString(),r:d.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(t.shape==="pill_hole_with_rect_pad"){const s=t,a=s.rect_pad_width*Math.abs(n.a),c=s.rect_pad_height*Math.abs(n.a),l=(s.rect_border_radius??0)*Math.abs(n.a),u=s.hole_height*Math.abs(n.a),d=s.hole_width*Math.abs(n.a),h=s,f=h.hole_offset_x??0,m=h.hole_offset_y??0,[y,g]=Yt(n,[s.x+f,s.y+m]),b=Math.min(u,d)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"pcb-hole-outer-pad",fill:i.copper.top,x:(r-a/2).toString(),y:(o-c/2).toString(),width:a.toString(),height:c.toString(),...l?{rx:l.toString(),ry:l.toString()}:{}},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"pcb-hole-inner",fill:i.drill,x:(y-d/2).toString(),y:(g-u/2).toString(),width:d.toString(),height:u.toString(),rx:b.toString(),ry:b.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(t.shape==="rotated_pill_hole_with_rect_pad"){const s=t,a=s.rect_pad_width*Math.abs(n.a),c=s.rect_pad_height*Math.abs(n.a),l=(s.rect_border_radius??0)*Math.abs(n.a),u=s.hole_height*Math.abs(n.a),d=s.hole_width*Math.abs(n.a),h=s,f=h.hole_offset_x??0,m=h.hole_offset_y??0,[y,g]=Yt(n,[s.x+f,s.y+m]),b=Math.min(u,d)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"pcb-hole-outer-pad",fill:i.copper.top,x:(-a/2).toString(),y:(-c/2).toString(),width:a.toString(),height:c.toString(),transform:`translate(${r} ${o}) rotate(${-s.rect_ccw_rotation})`,...l?{rx:l.toString(),ry:l.toString()}:{}},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"pcb-hole-inner",fill:i.drill,x:(-d/2).toString(),y:(-u/2).toString(),width:d.toString(),height:u.toString(),rx:b.toString(),ry:b.toString(),transform:`translate(${y} ${g}) rotate(${-s.hole_ccw_rotation})`},value:"",children:[]}],value:"",attributes:{}}]}return[]}function H_n(t,e){const{transform:n,layer:i,colorMap:r}=e;if(!t.route||!Array.isArray(t.route))return[];let o=t.route.map((u,d)=>{const[h,f]=Yt(n,[u.x,u.y]);return d===0?`M ${h} ${f}`:`L ${h} ${f}`}).join(" ");const s=t.route[0],a=t.route[t.route.length-1];s&&a&&s.x===a.x&&s.y===a.y&&(o+=" Z");const c=t.layer||"top";if(i&&c!==i)return[];const l=c==="bottom"?r.silkscreen.bottom:r.silkscreen.top;return[{name:"path",type:"element",attributes:{class:`pcb-silkscreen pcb-silkscreen-${c}`,d:o,fill:"none",stroke:l,"stroke-width":(t.stroke_width*Math.abs(n.a)).toString(),"stroke-linecap":"round","stroke-linejoin":"round","data-pcb-component-id":t.pcb_component_id,"data-pcb-silkscreen-path-id":t.pcb_silkscreen_path_id},value:"",children:[]}]}function V_n(t,e){const{transform:n,layer:i,colorMap:r}=e,{anchor_position:o,text:s,font_size:a=1,layer:c="top",ccw_rotation:l=0,anchor_alignment:u="center"}=t;if(i&&c!==i)return[];if(!o||typeof o.x!="number"||typeof o.y!="number")return console.error("Invalid anchor_position:",o),[];const[d,h]=Yt(n,[o.x,o.y]),f=a*Math.abs(n.a);let m="middle",y="central";const g=0,b=0;switch(u){case"top_left":m="start",y="text-before-edge";break;case"top_center":m="middle",y="text-before-edge";break;case"top_right":m="end",y="text-before-edge";break;case"center_left":m="start",y="central";break;case"center_right":m="end",y="central";break;case"bottom_left":m="start",y="text-after-edge";break;case"bottom_center":m="middle",y="text-after-edge";break;case"bottom_right":m="end",y="text-after-edge";break;case"center":default:m="middle",y="central";break}const v=cs(Cs(d,h),ov(-l*Math.PI/180),...c==="bottom"?[kg(-1,1)]:[]),w=c==="bottom"?r.silkscreen.bottom:r.silkscreen.top,T=s.split(`
5301
- `),N=T.length===1?[{type:"text",value:s,name:"",attributes:{},children:[]}]:T.map((P,M)=>({type:"element",name:"tspan",value:"",attributes:{x:"0",...M>0?{dy:f.toString()}:{}},children:[{type:"text",value:P,name:"",attributes:{},children:[]}]}));return[{name:"text",type:"element",attributes:{x:"0",y:"0",dx:g.toString(),dy:b.toString(),fill:w,"font-family":"Arial, sans-serif","font-size":f.toString(),"text-anchor":m,"dominant-baseline":y,transform:aw(v),class:`pcb-silkscreen-text pcb-silkscreen-${c}`,"data-pcb-silkscreen-text-id":t.pcb_component_id,stroke:"none"},children:N,value:""}]}function G_n(t,e){const{transform:n,layer:i,colorMap:r}=e,{center:o,width:s,height:a,layer:c="top",pcb_silkscreen_rect_id:l,stroke_width:u,is_filled:d,has_stroke:h,is_stroke_dashed:f}=t;if(i&&c!==i)return[];if(!o||typeof o.x!="number"||typeof o.y!="number"||typeof s!="number"||typeof a!="number")return console.error("Invalid rectangle data:",{center:o,width:s,height:a}),[];const[m,y]=Yt(n,[o.x,o.y]),g=s*Math.abs(n.a),b=a*Math.abs(n.d),v=u*Math.abs(n.a),w=c==="bottom"?r.silkscreen.bottom:r.silkscreen.top,T={x:(m-g/2).toString(),y:(y-b/2).toString(),width:g.toString(),height:b.toString(),class:`pcb-silkscreen-rect pcb-silkscreen-${c}`,"data-pcb-silkscreen-rect-id":l};T.fill=d?w:"none";let N;if(h===void 0?N=v>0:N=h,N){if(T.stroke=w,T["stroke-width"]=v.toString(),f){const P=.1*Math.abs(n.a),M=.05*Math.abs(n.a);T["stroke-dasharray"]=`${P} ${M}`}}else T.stroke="none";return[{name:"rect",type:"element",attributes:T,value:"",children:[]}]}function Y_n(t,e){const{transform:n,layer:i,colorMap:r}=e,{center:o,radius:s,layer:a="top",pcb_silkscreen_circle_id:c,stroke_width:l=1}=t;if(i&&a!==i)return[];if(!o||typeof o.x!="number"||typeof o.y!="number"||typeof s!="number")return console.error("Invalid PCB Silkscreen Circle data:",{center:o,radius:s}),[];const[u,d]=Yt(n,[o.x,o.y]),h=s*Math.abs(n.a),f=l*Math.abs(n.a),m=a==="bottom"?r.silkscreen.bottom:r.silkscreen.top;return[{name:"circle",type:"element",attributes:{cx:u.toString(),cy:d.toString(),r:h.toString(),class:`pcb-silkscreen-circle pcb-silkscreen-${a}`,stroke:m,"stroke-width":f.toString(),"data-pcb-silkscreen-circle-id":c},value:"",children:[]}]}function q_n(t,e){const{transform:n,layer:i,colorMap:r}=e,{x1:o,y1:s,x2:a,y2:c,stroke_width:l,layer:u="top",pcb_silkscreen_line_id:d}=t;if(i&&u!==i)return[];if(typeof o!="number"||typeof s!="number"||typeof a!="number"||typeof c!="number")return console.error("Invalid coordinates:",{x1:o,y1:s,x2:a,y2:c}),[];const[h,f]=Yt(n,[o,s]),[m,y]=Yt(n,[a,c]),g=l*Math.abs(n.a),b=u==="bottom"?r.silkscreen.bottom:r.silkscreen.top;return[{name:"line",type:"element",attributes:{x1:h.toString(),y1:f.toString(),x2:m.toString(),y2:y.toString(),stroke:b,"stroke-width":g.toString(),class:`pcb-silkscreen-line pcb-silkscreen-${u}`,"data-pcb-silkscreen-line-id":d},value:"",children:[]}]}function X_n(t){const e=[];for(let n=0;n<t.length-1;n++)e.push([t[n],t[n+1]]);return e}var ex={copper:{top:"rgb(200, 52, 52)",bottom:"rgb(77, 127, 196)"},soldermask:{top:"rgb(200, 52, 52)",bottom:"rgb(77, 127, 196)"},drill:"#FF26E2",silkscreen:{top:"#f2eda1",bottom:"#5da9e9"},boardOutline:"rgba(255, 255, 255, 0.5)",debugComponent:{fill:null,stroke:null}};ex.drill,ex.silkscreen.top,ex.silkscreen.bottom,ex.copper.top,ex.copper.bottom;function hM(t,e=ex){return e.copper[t]??"white"}var W_n={bottom:"rgb(105, 105, 105)",top:"rgb(105, 105, 105)"};function Bj(t){return W_n[t]??"rgb(105, 105, 105)"}function Z_n(t,e){const{transform:n,layer:i,colorMap:r,renderSolderMask:o}=e;if(!t.route||!Array.isArray(t.route)||t.route.length<2)return[];const s=X_n(t.route),a=[];for(const[c,l]of s){const u=Yt(n,[c.x,c.y]),d=Yt(n,[l.x,l.y]),h="layer"in c?c.layer:"layer"in l?l.layer:null;if(!h||i&&h!==i)continue;const f=hM(h,r),m=r.soldermask[h]??f,y="width"in c?c.width:"width"in l?l.width:null,g=y?(y*Math.abs(n.a)).toString():"0.3";if(o){const b={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-trace",stroke:f,fill:"none",d:`M ${u[0]} ${u[1]} L ${d[0]} ${d[1]}`,"stroke-width":g,"stroke-linecap":"round","stroke-linejoin":"round","shape-rendering":"crispEdges","data-layer":h}},v={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask",stroke:m,fill:"none",d:`M ${u[0]} ${u[1]} L ${d[0]} ${d[1]}`,"stroke-width":g,"stroke-linecap":"round","stroke-linejoin":"round","shape-rendering":"crispEdges","data-layer":h}};a.push(v,b)}else{const b={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-trace",stroke:m,fill:"none",d:`M ${u[0]} ${u[1]} L ${d[0]} ${d[1]}`,"stroke-width":g,"stroke-linecap":"round","stroke-linejoin":"round","shape-rendering":"crispEdges","data-layer":h}};a.push(b)}}return a.sort((c,l)=>{const u=c.attributes["data-layer"],d=l.attributes["data-layer"];return u==="bottom"&&d!=="bottom"?-1:u==="top"&&d!=="top"?1:0}),a}function K_n(t,e){const{transform:n,layer:i,colorMap:r}=e;if(i&&t.layer!==i)return[];const o=!!t?.is_covered_with_solder_mask,s=r.soldermask[t.layer]??r.soldermask.top;if(t.shape==="rect"||t.shape==="rotated_rect"){const a=t.width*Math.abs(n.a),c=t.height*Math.abs(n.d),[l,u]=Yt(n,[t.x,t.y]),d=(t.rect_border_radius??0)*Math.abs(n.a);if(t.shape==="rotated_rect"&&t.ccw_rotation){const m={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:hM(t.layer,r),x:(-a/2).toString(),y:(-c/2).toString(),width:a.toString(),height:c.toString(),transform:`translate(${l} ${u}) rotate(${-t.ccw_rotation})`,"data-layer":t.layer,...d?{rx:d.toString(),ry:d.toString()}:{}}};if(!o)return[m];const y={name:m.name,type:m.type,value:"",children:[],attributes:{...m.attributes,class:"pcb-solder-mask",fill:s}};return[m,y]}const h={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:hM(t.layer,r),x:(l-a/2).toString(),y:(u-c/2).toString(),width:a.toString(),height:c.toString(),"data-layer":t.layer,...d?{rx:d.toString(),ry:d.toString()}:{}}};if(!o)return[h];const f={name:h.name,type:h.type,value:"",children:[],attributes:{...h.attributes,class:"pcb-solder-mask",fill:s}};return[h,f]}if(t.shape==="pill"){const a=t.width*Math.abs(n.a),c=t.height*Math.abs(n.d),l=t.radius*Math.abs(n.a),[u,d]=Yt(n,[t.x,t.y]),h={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:hM(t.layer,r),x:(u-a/2).toString(),y:(d-c/2).toString(),width:a.toString(),height:c.toString(),rx:l.toString(),ry:l.toString(),"data-layer":t.layer}};if(!o)return[h];const f={name:h.name,type:h.type,value:"",children:[],attributes:{...h.attributes,class:"pcb-solder-mask",fill:s}};return[h,f]}if(t.shape==="circle"){const a=t.radius*Math.abs(n.a),[c,l]=Yt(n,[t.x,t.y]),u={name:"circle",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:hM(t.layer,r),cx:c.toString(),cy:l.toString(),r:a.toString(),"data-layer":t.layer}};if(!o)return[u];const d={name:u.name,type:u.type,value:"",children:[],attributes:{...u.attributes,class:"pcb-solder-mask",fill:s}};return[u,d]}if(t.shape==="polygon"){const a=(t.points??[]).map(u=>Yt(n,[u.x,u.y])),c={name:"polygon",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:hM(t.layer,r),points:a.map(u=>u.join(",")).join(" "),"data-layer":t.layer}};if(!o)return[c];const l={name:c.name,type:c.type,value:"",children:[],attributes:{...c.attributes,class:"pcb-solder-mask",fill:s}};return[c,l]}return[]}function IZe(t,e){const{transform:n,colorMap:i}=e,{width:r,height:o,center:s,outline:a}=t;let c;if(a&&Array.isArray(a)&&a.length>=3)c=a.map((l,u)=>{const[d,h]=Yt(n,[l.x,l.y]);return u===0?`M ${d} ${h}`:`L ${d} ${h}`}).join(" ");else{const l=r/2,u=o/2,d=Yt(n,[s.x-l,s.y-u]),h=Yt(n,[s.x+l,s.y-u]),f=Yt(n,[s.x+l,s.y+u]),m=Yt(n,[s.x-l,s.y+u]);c=`M ${d[0]} ${d[1]} L ${h[0]} ${h[1]} L ${f[0]} ${f[1]} L ${m[0]} ${m[1]}`}return c+=" Z",[{name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-board",d:c,fill:"none",stroke:i.boardOutline,"stroke-width":(.1*Math.abs(n.a)).toString()}}]}function Q_n(t,e){const{transform:n,colorMap:i}=e,[r,o]=Yt(n,[t.x,t.y]),s=t.outer_diameter*Math.abs(n.a),a=t.outer_diameter*Math.abs(n.a),c=t.hole_diameter*Math.abs(n.a),l=t.hole_diameter*Math.abs(n.a),u=Math.min(s,a)/2,d=Math.min(c,l)/2;return{name:"g",type:"element",children:[{name:"circle",type:"element",attributes:{class:"pcb-hole-outer",fill:i.copper.top,cx:r.toString(),cy:o.toString(),r:u.toString()}},{name:"circle",type:"element",attributes:{class:"pcb-hole-inner",fill:i.drill,cx:r.toString(),cy:o.toString(),r:d.toString()}}]}}function J_n(t,e){const{transform:n,colorMap:i}=e,[r,o]=Yt(n,[t.x,t.y]);if(t.hole_shape==="circle"||t.hole_shape==="square"){const s=t.hole_diameter*Math.abs(n.a),a=s/2;return t.hole_shape==="circle"?[{name:"circle",type:"element",attributes:{class:"pcb-hole",cx:r.toString(),cy:o.toString(),r:a.toString(),fill:i.drill},children:[],value:""}]:[{name:"rect",type:"element",attributes:{class:"pcb-hole",x:(r-a).toString(),y:(o-a).toString(),width:s.toString(),height:s.toString(),fill:i.drill},children:[],value:""}]}if(t.hole_shape==="oval"){const s=t.hole_width*Math.abs(n.a),a=t.hole_height*Math.abs(n.a),c=s/2,l=a/2;return[{name:"ellipse",type:"element",attributes:{class:"pcb-hole",cx:r.toString(),cy:o.toString(),rx:c.toString(),ry:l.toString(),fill:i.drill},children:[],value:""}]}return[]}var eyn=(t,e)=>{const n=ea(e).pcb_smtpad.get(t);if(n&&"x"in n&&"y"in n)return{x:n.x,y:n.y};const i=ea(e).pcb_plated_hole.get(t);return i&&"x"in i&&"y"in i?{x:i.x,y:i.y}:null},tyn=(t,e,n,i)=>{const r=n.getIdsConnectedToNet(e);let o=null,s=1/0;for(const a of r){const c=eyn(a,i);if(c){const l=t.x-c.x,u=t.y-c.y,d=Math.sqrt(l*l+u*u);d>0&&d<s&&(s=d,o=c)}}return o};function nyn(t,e){const{transform:n}=e,i=J6(t),r=t.filter(c=>c.type==="pcb_port"),o=t.filter(c=>c.type==="source_trace"),s=[];r.forEach((c,l)=>{const u=c.pcb_port_id;if(!u)return;const d=i.getNetConnectedToId(u);if(!d)return;let h=!1;const f=ea(t).source_port.getWhere({pcb_port_id:u});if(f&&f.source_port_id){const g=f.source_port_id;for(const b of o)if(Array.isArray(b.connected_source_port_ids)&&b.connected_source_port_ids.includes(g)&&Array.isArray(b.connected_source_net_ids)&&b.connected_source_net_ids.length>0){h=!0;break}}const m={x:c.x,y:c.y},y=tyn(m,d,i,t);y&&s.push({key:`${u}-${l}`,startPoint:m,endPoint:y,isInNet:h})});const a=[];for(const c of s){const l=Yt(n,[c.startPoint.x,c.startPoint.y]),u=Yt(n,[c.endPoint.x,c.endPoint.y]),d={x1:l[0].toString(),y1:l[1].toString(),x2:u[0].toString(),y2:u[1].toString(),stroke:"white","stroke-width":"1","stroke-dasharray":"6,6"};a.push({name:"line",type:"element",attributes:d,value:"",children:[]})}return a}function iyn(t,e){const{transform:n,colorMap:i}=e;if(t.shape==="rect"){const r=t,[o,s]=Yt(n,[r.center.x,r.center.y]),a=r.width*Math.abs(n.a),c=r.height*Math.abs(n.d),l=-(r.rotation??0);return[{name:"rect",type:"element",attributes:{class:"pcb-cutout pcb-cutout-rect",x:(-a/2).toString(),y:(-c/2).toString(),width:a.toString(),height:c.toString(),fill:i.drill,transform:aw(cs(Cs(o,s),ov(l*Math.PI/180)))},children:[],value:""}]}if(t.shape==="circle"){const r=t,[o,s]=Yt(n,[r.center.x,r.center.y]),a=r.radius*Math.abs(n.a);return[{name:"circle",type:"element",attributes:{class:"pcb-cutout pcb-cutout-circle",cx:o.toString(),cy:s.toString(),r:a.toString(),fill:i.drill},children:[],value:""}]}if(t.shape==="polygon"){const r=t;return!r.points||r.points.length===0?[]:[{name:"polygon",type:"element",attributes:{class:"pcb-cutout pcb-cutout-polygon",points:r.points.map(a=>Yt(n,[a.x,a.y])).map(a=>`${a[0]},${a[1]}`).join(" "),fill:i.drill},children:[],value:""}]}return[]}function NZe(t,e){if(t.length===0)return"";const n=t.map(r=>{const[o,s]=Yt(e,[r.x,r.y]);return{...r,x:o,y:s}});let i=`M ${n[0].x} ${n[0].y}`;for(let r=0;r<n.length;r++){const o=n[r],s=n[(r+1)%n.length];if(o.bulge){if(Math.hypot(s.x-o.x,s.y-o.y)<1e-9)continue;const a=o.bulge,c=s.x-o.x,l=s.y-o.y,u=Math.hypot(c,l),d=Math.abs(u/4/a*(a*a+1)),h=a<0?1:0,f=Math.abs(a)>1?1:0;i+=` A ${d} ${d} 0 ${f} ${h} ${s.x} ${s.y}`}else i+=` L ${s.x} ${s.y}`}return i+=" Z",i}function ryn(t,e){const{transform:n,layer:i,colorMap:r}=e,{layer:o}=t;if(i&&o!==i)return[];const s=hM(o,r),a="0.5";if(t.shape==="rect"){const[c,l]=Yt(n,[t.center.x,t.center.y]),u=t.width*Math.abs(n.a),d=t.height*Math.abs(n.d),h=-(t.rotation??0);return[{name:"rect",type:"element",attributes:{class:"pcb-copper-pour pcb-copper-pour-rect",x:(-u/2).toString(),y:(-d/2).toString(),width:u.toString(),height:d.toString(),fill:s,"fill-opacity":a,transform:aw(cs(Cs(c,l),ov(h*Math.PI/180))),"data-layer":o},children:[],value:""}]}if(t.shape==="polygon")return!t.points||t.points.length===0?[]:[{name:"polygon",type:"element",attributes:{class:"pcb-copper-pour pcb-copper-pour-polygon",points:t.points.map(u=>Yt(n,[u.x,u.y])).map(u=>`${u[0]},${u[1]}`).join(" "),fill:s,"fill-opacity":a,"data-layer":o},children:[],value:""}];if(t.shape==="brep"){const{brep_shape:c}=t;let l=NZe(c.outer_ring.vertices,n);for(const u of c.inner_rings??[])l+=` ${NZe(u.vertices,n)}`;return[{name:"path",type:"element",attributes:{class:"pcb-copper-pour pcb-copper-pour-brep",d:l,fill:s,"fill-rule":"evenodd","fill-opacity":a,"data-layer":o},children:[],value:""}]}return[]}function oyn(t,e){const{transform:n}=e,{center:i,width:r,height:o,rotation:s=0}=t,[a,c]=Yt(n,[i.x,i.y]),l=r*Math.abs(n.a),u=o*Math.abs(n.d),d=`translate(${a}, ${c}) rotate(${-s}) scale(1, -1)`;return!e.colorMap.debugComponent?.fill&&!e.colorMap.debugComponent?.stroke?[]:[{name:"g",type:"element",attributes:{transform:d},children:[{name:"rect",type:"element",attributes:{class:"pcb-component",x:(-l/2).toString(),y:(-u/2).toString(),width:l.toString(),height:u.toString(),fill:e.colorMap.debugComponent.fill??"transparent",stroke:e.colorMap.debugComponent.stroke??"transparent"}}],value:""}]}function oC(t){return t.find(n=>n.type==="project_software_metadata"||n.type==="source_project_metadata")?.software_used_string}var syn={version:"0.0.200"},sC=syn.version,kZe=["pcb_trace_error","pcb_plated_hole","pcb_fabrication_note_text","pcb_fabrication_note_path","pcb_silkscreen_text","pcb_silkscreen_path","pcb_via","pcb_cutout","pcb_copper_pour","pcb_smtpad","pcb_trace","pcb_component","pcb_board"];function $me(t,e){const n=e?.drawPaddingOutsideBoard??!0,i=e?.layer,r=e?.colorOverrides,o={copper:{top:r?.copper?.top??ex.copper.top,bottom:r?.copper?.bottom??ex.copper.bottom},drill:r?.drill??ex.drill,silkscreen:{top:r?.silkscreen?.top??ex.silkscreen.top,bottom:r?.silkscreen?.bottom??ex.silkscreen.bottom},boardOutline:r?.boardOutline??ex.boardOutline,soldermask:{top:r?.soldermask?.top??ex.soldermask.top,bottom:r?.soldermask?.bottom??ex.soldermask.bottom},debugComponent:{fill:r?.debugComponent?.fill??ex.debugComponent.fill,stroke:r?.debugComponent?.stroke??ex.debugComponent.stroke}};let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY,u=Number.POSITIVE_INFINITY,d=Number.POSITIVE_INFINITY,h=Number.NEGATIVE_INFINITY,f=Number.NEGATIVE_INFINITY;for(const ke of t)if(ke.type==="pcb_board")ke.outline&&Array.isArray(ke.outline)&&ke.outline.length>=3?(Me(ke.outline),Ie(ke.outline)):"center"in ke&&"width"in ke&&"height"in ke&&(ue(ke.center,ke.width,ke.height),he(ke.center,ke.width,ke.height));else if("x"in ke&&"y"in ke)ue({x:ke.x,y:ke.y},0,0);else if(ke.type==="pcb_smtpad"){const ce=ke;ce.shape==="rect"||ce.shape==="rotated_rect"||ce.shape==="pill"?ue({x:ce.x,y:ce.y},ce.width,ce.height):ce.shape==="circle"?ue({x:ce.x,y:ce.y},ce.radius*2,ce.radius*2):ce.shape==="polygon"&&De(ce.points)}else"route"in ke?De(ke.route):ke.type==="pcb_silkscreen_text"||ke.type==="pcb_silkscreen_rect"||ke.type==="pcb_silkscreen_circle"||ke.type==="pcb_silkscreen_line"?Ge(ke):ke.type==="pcb_copper_pour"&&(ke.shape==="rect"?ue(ke.center,ke.width,ke.height):ke.shape==="polygon"&&De(ke.points));const m=n?1:0,y=n||!Number.isFinite(u)?s:u,g=n||!Number.isFinite(d)?a:d,b=n||!Number.isFinite(h)?c:h,v=n||!Number.isFinite(f)?l:f,w=b-y+2*m,T=v-g+2*m;let N=e?.width??800,R=e?.height??600;if(e?.matchBoardAspectRatio){const ke=h-u,ce=f-d;if(ke>0&&ce>0){const we=ke/ce;e?.width&&!e?.height?R=e.width/we:e?.height&&!e?.width?N=e.height*we:R=N/we}}const P=[];for(const ke of t)"route"in ke&&ke.route!==void 0&&P.push(ke.route);const M=N/w,I=R/T,A=Math.min(M,I),$=(N-w*A)/2,k=(R-T*A)/2,V=cs(Cs($-y*A+m*A,R-k+g*A-m*A),kg(A,-A)),X={transform:V,layer:i,shouldDrawErrors:e?.shouldDrawErrors,drawPaddingOutsideBoard:n,colorMap:o,renderSolderMask:e?.renderSolderMask};function W(ke){if(ke.type==="pcb_smtpad")return ke.layer==="top"||ke.layer==="bottom"?ke.layer:void 0;if(ke.type==="pcb_trace")for(const ce of ke.route??[]){const we="layer"in ce&&ce.layer||"from_layer"in ce&&ce.from_layer||"to_layer"in ce&&ce.to_layer||void 0;if(we==="top"||we==="bottom")return we}}function K(ke){return ke.type==="pcb_trace"||ke.type==="pcb_smtpad"}let te=t.sort((ke,ce)=>{const we=W(ke),xe=W(ce);if(K(ke)&&K(ce)&&we!==xe){if(we==="top")return 1;if(xe==="top"||we==="bottom")return-1;if(xe==="bottom")return 1}return(kZe.indexOf(ce.type)??9999)-(kZe.indexOf(ke.type)??9999)}).flatMap(ke=>ayn({elm:ke,circuitJson:t,ctx:X}));for(const ke of t)if("stroke_width"in ke){String(A*ke.stroke_width);break}if(e?.shouldDrawRatsNest){const ke=nyn(t,X);te=te.concat(ke)}const se=[{name:"style",type:"element",value:"",attributes:{},children:[{type:"text",value:"",name:"",attributes:{},children:[]}]},{name:"rect",type:"element",value:"",attributes:{class:"boundary",x:"0",y:"0",fill:e?.backgroundColor??"#000",width:N.toString(),height:R.toString()},children:[]}];n&&se.push(cyn(V,s,a,c,l)),se.push(...te);const de=oC(t),be=sC,re={name:"svg",type:"element",attributes:{xmlns:"http://www.w3.org/2000/svg",width:N.toString(),height:R.toString(),...de&&{"data-software-used-string":de},...e?.includeVersion&&{"data-circuit-to-svg-version":be}},value:"",children:se.filter(ke=>ke!==null)};try{return FP(re)}catch(ke){throw console.error("Error stringifying SVG object:",ke),ke}function ue(ke,ce,we){const xe=ce/2,Ye=we/2;s=Math.min(s,ke.x-xe),a=Math.min(a,ke.y-Ye),c=Math.max(c,ke.x+xe),l=Math.max(l,ke.y+Ye)}function he(ke,ce,we){const xe=ce/2,Ye=we/2;u=Math.min(u,ke.x-xe),d=Math.min(d,ke.y-Ye),h=Math.max(h,ke.x+xe),f=Math.max(f,ke.y+Ye)}function Me(ke){for(const ce of ke)s=Math.min(s,ce.x),a=Math.min(a,ce.y),c=Math.max(c,ce.x),l=Math.max(l,ce.y)}function Ie(ke){for(const ce of ke)u=Math.min(u,ce.x),d=Math.min(d,ce.y),h=Math.max(h,ce.x),f=Math.max(f,ce.y)}function De(ke){for(const ce of ke)s=Math.min(s,ce.x),a=Math.min(a,ce.y),c=Math.max(c,ce.x),l=Math.max(l,ce.y)}function Ge(ke){if(ke.type==="pcb_silkscreen_text")ue(ke.anchor_position,0,0);else if(ke.type==="pcb_silkscreen_path")De(ke.route);else if(ke.type==="pcb_silkscreen_rect")ue(ke.center,ke.width,ke.height);else if(ke.type==="pcb_silkscreen_circle")ue(ke.center,ke.radius*2,ke.radius*2);else if(ke.type==="pcb_silkscreen_line")ue({x:ke.x1,y:ke.y1},0,0),ue({x:ke.x2,y:ke.y2},0,0);else if(ke.type==="pcb_cutout"){const ce=ke;ce.shape==="rect"?ue(ce.center,ce.width,ce.height):ce.shape==="circle"?ue(ce.center,ce.radius*2,ce.radius*2):ce.shape==="polygon"&&De(ce.points)}}}function ayn({elm:t,circuitJson:e,ctx:n}){switch(t.type){case"pcb_trace_error":return F_n(t,e,n).filter(Boolean);case"pcb_component":return oyn(t,n).filter(Boolean);case"pcb_trace":return Z_n(t,n);case"pcb_copper_pour":return ryn(t,n);case"pcb_plated_hole":return j_n(t,n).filter(Boolean);case"pcb_hole":return J_n(t,n);case"pcb_smtpad":return K_n(t,n);case"pcb_silkscreen_text":return V_n(t,n);case"pcb_silkscreen_rect":return G_n(t,n);case"pcb_silkscreen_circle":return Y_n(t,n);case"pcb_silkscreen_line":return q_n(t,n);case"pcb_fabrication_note_path":return U_n(t,n);case"pcb_fabrication_note_text":return $_n(t,n);case"pcb_silkscreen_path":return H_n(t,n);case"pcb_board":return n.drawPaddingOutsideBoard?IZe(t,n):[];case"pcb_via":return Q_n(t,n);case"pcb_cutout":return iyn(t,n);default:return[]}}function cyn(t,e,n,i,r){const[o,s]=Yt(t,[e,n]),[a,c]=Yt(t,[i,r]),l=Math.abs(a-o),u=Math.abs(c-s),d=Math.min(o,a),h=Math.min(s,c);return{name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-boundary",fill:"none",stroke:"#fff","stroke-width":"0.3",x:d.toString(),y:h.toString(),width:l.toString(),height:u.toString()}}}var lyn=$me,Uj={fill:"none",stroke:"rgb(0,0,0)",strokeOpacity:"0.8",strokeWidthFactor:.2};function uyn(t,e,n={}){const{width:i,height:r,center:o,outline:s}=t;let a;if(s&&Array.isArray(s)&&s.length>=3)a=s.map((c,l)=>{const[u,d]=Yt(e,[c.x,c.y]);return l===0?`M ${u} ${d}`:`L ${u} ${d}`}).join(" ");else{const c=i/2,l=r/2,u=Yt(e,[o.x-c,o.y-l]),d=Yt(e,[o.x+c,o.y-l]),h=Yt(e,[o.x+c,o.y+l]),f=Yt(e,[o.x-c,o.y+l]);a=`M ${u[0]} ${u[1]} L ${d[0]} ${d[1]} L ${h[0]} ${h[1]} L ${f[0]} ${f[1]}`}return a+=" Z",[{name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-board",d:a,fill:n.fill??Uj.fill,stroke:n.stroke??Uj.stroke,"stroke-opacity":n.strokeOpacity??Uj.strokeOpacity,"stroke-width":((n.strokeWidthFactor??Uj.strokeWidthFactor)*Math.abs(e.a)).toString()}}]}var dyn={pin_number:.15,negated_pin_number:.15*.8,reference_designator:.18,manufacturer_number:.18,net_label:.18,error:.05},aC=(t,e)=>e??dyn[t],l3=(t,e,n)=>Math.abs(t.a)*aC(e,n);function hyn(t,e){const{elm:n,portPosition:i,name:r,arePinsInterchangeable:o}=t,{transform:s}=e,{center:a,width:c,height:l,rotation:u=0,layer:d="top"}=n;if(!a||typeof c!="number"||typeof l!="number")return null;const[h,f]=Yt(s,[a.x,a.y]),[m,y]=Yt(s,[i.x,i.y]),g=c*Math.abs(s.a),b=l*Math.abs(s.d),v=y>f,w=m<h,T=[pyn(g,b,u,d),fyn(g,b,r??"")];return o||T.push(myn(g,b,u,d,v,w)),{name:"g",type:"element",value:"",attributes:{transform:`translate(${h}, ${f}) scale(1, -1)`},children:T}}function pyn(t,e,n,i){const r=t/2,o=e/2;return{name:"path",type:"element",attributes:{class:"assembly-component",d:_yn(r,o,n),"stroke-width":.8.toFixed(2),transform:`rotate(${-n})`,"stroke-dasharray":i==="bottom"?"2,2":""},value:"",children:[]}}function fyn(t,e,n,i){const r=Math.min(t,e),c=Math.min(58,Math.max(3,r*.8)),l=e>t;return{name:"text",type:"element",attributes:{x:"0",y:"0",class:"assembly-component-label","text-anchor":"middle",dy:".10em",style:"pointer-events: none","font-size":`${c.toFixed(1)}px`,transform:l?"rotate(90) scale(1, -1)":"scale(1, -1)"},children:[{type:"text",value:n||"",name:"",attributes:{},children:[]}],value:""}}function myn(t,e,n,i,r,o){const s=t/2,a=e/2,c=Math.min(s,a)*.5;let l;return r&&o?l=[[-s,-a],[-s+c,-a],[-s,-a+c]]:r&&!o?l=[[s,-a],[s-c,-a],[s,-a+c]]:!r&&o?l=[[-s,a],[-s+c,a],[-s,a-c]]:l=[[s,a],[s-c,a],[s,a-c]],{name:"polygon",type:"element",attributes:{class:"assembly-pin1-indicator",points:l.map(d=>d.join(",")).join(" "),fill:"#333",stroke:"none",transform:`rotate(${-n})`},value:"",children:[]}}function _yn(t,e,n){const i=(a,c,l)=>{const u=Math.PI/180*l,d=Math.cos(u),h=Math.sin(u);return[a*d-c*h,a*h+c*d]};return`${[[-t,-e],[t,-e],[t,e],[-t,e]].map(([a,c])=>i(a,c,n)).map(([a,c],l)=>l===0?`M${a},${c}`:`L${a},${c}`).join(" ")} Z`}var jme="rgb(190, 190, 190)";function yyn(t,e){const{transform:n}=e,[i,r]=Yt(n,[t.x,t.y]);if(t.hole_shape==="circle"||t.hole_shape==="square"){const o=t.hole_diameter*Math.abs(n.a),s=o/2;return t.hole_shape==="circle"?[{name:"circle",type:"element",attributes:{class:"assembly-hole",cx:i.toString(),cy:r.toString(),r:s.toString(),fill:jme},children:[],value:""}]:[{name:"rect",type:"element",attributes:{class:"assembly-hole",x:(i-s).toString(),y:(r-s).toString(),width:o.toString(),height:o.toString(),fill:jme},children:[],value:""}]}if(t.hole_shape==="oval"){const o=t.hole_width*Math.abs(n.a),s=t.hole_height*Math.abs(n.a),a=o/2,c=s/2;return[{name:"ellipse",type:"element",attributes:{class:"assembly-hole",cx:i.toString(),cy:r.toString(),rx:a.toString(),ry:c.toString(),fill:jme},children:[],value:""}]}return[]}var QI="rgb(210, 210, 210)",JI="rgb(190, 190, 190)";function gyn(t,e){const{transform:n}=e,[i,r]=Yt(n,[t.x,t.y]);if(t.shape==="pill"){const o=t.outer_width*Math.abs(n.a),s=t.outer_height*Math.abs(n.a),a=t.hole_width*Math.abs(n.a),c=t.hole_height*Math.abs(n.a),l=o/2,u=s-o,d=a/2;return[{name:"g",type:"element",children:[{name:"path",type:"element",attributes:{class:"assembly-hole-outer",fill:QI,d:`M${i-l},${r-u/2} v${u} a${l},${l} 0 0 0 ${o},0 v-${u} a${l},${l} 0 0 0 -${o},0 z`},value:"",children:[]},{name:"path",type:"element",attributes:{class:"assembly-hole-inner",fill:JI,d:`M${i-d},${r-(c-a)/2} v${c-a} a${d},${d} 0 0 0 ${a},0 v-${c-a} a${d},${d} 0 0 0 -${a},0 z`},value:"",children:[]}],value:"",attributes:{}}]}if(t.shape==="circle"){const o=t.outer_diameter*Math.abs(n.a),s=t.outer_diameter*Math.abs(n.a),a=t.hole_diameter*Math.abs(n.a),c=t.hole_diameter*Math.abs(n.a),l=Math.min(o,s)/2,u=Math.min(a,c)/2;return[{name:"g",type:"element",children:[{name:"circle",type:"element",attributes:{class:"assembly-hole-outer",fill:QI,cx:i.toString(),cy:r.toString(),r:l.toString()},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"assembly-hole-inner",fill:JI,cx:i.toString(),cy:r.toString(),r:u.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(t.shape==="circular_hole_with_rect_pad"){const o=t,s=o.hole_diameter*Math.abs(n.a),a=o.rect_pad_width*Math.abs(n.a),c=o.rect_pad_height*Math.abs(n.a),l=(o.rect_border_radius??0)*Math.abs(n.a),u=s/2,[d,h]=Yt(n,[o.x+o.hole_offset_x,o.y+o.hole_offset_y]);return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"assembly-hole-outer-pad",fill:QI,x:(i-a/2).toString(),y:(r-c/2).toString(),width:a.toString(),height:c.toString(),...l?{rx:l.toString(),ry:l.toString()}:{}},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"assembly-hole-inner",fill:JI,cx:d.toString(),cy:h.toString(),r:u.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(t.shape==="pill_hole_with_rect_pad"){const o=t,s=o.rect_pad_width*Math.abs(n.a),a=o.rect_pad_height*Math.abs(n.a),c=(o.rect_border_radius??0)*Math.abs(n.a),l=o.hole_height*Math.abs(n.a),u=o.hole_width*Math.abs(n.a),d=o,h=d.hole_offset_x??0,f=d.hole_offset_y??0,[m,y]=Yt(n,[o.x+h,o.y+f]),g=Math.min(l,u)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"assembly-hole-outer-pad",fill:QI,x:(i-s/2).toString(),y:(r-a/2).toString(),width:s.toString(),height:a.toString(),...c?{rx:c.toString(),ry:c.toString()}:{}},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"assembly-hole-inner",fill:JI,x:(m-u/2).toString(),y:(y-l/2).toString(),width:u.toString(),height:l.toString(),rx:g.toString(),ry:g.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(t.shape==="rotated_pill_hole_with_rect_pad"){const o=t,s=o.rect_pad_width*Math.abs(n.a),a=o.rect_pad_height*Math.abs(n.a),c=(o.rect_border_radius??0)*Math.abs(n.a),l=o.hole_height*Math.abs(n.a),u=o.hole_width*Math.abs(n.a),d=o,h=d.hole_offset_x??0,f=d.hole_offset_y??0,[m,y]=Yt(n,[o.x+h,o.y+f]),g=Math.min(l,u)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"assembly-hole-outer-pad",fill:QI,x:(-s/2).toString(),y:(-a/2).toString(),width:s.toString(),height:a.toString(),transform:`translate(${i} ${r}) rotate(${-o.rect_ccw_rotation})`,...c?{rx:c.toString(),ry:c.toString()}:{}},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"assembly-hole-inner",fill:JI,x:(-u/2).toString(),y:(-l/2).toString(),width:u.toString(),height:l.toString(),rx:g.toString(),ry:g.toString(),transform:`translate(${m} ${y}) rotate(${-o.hole_ccw_rotation})`},value:"",children:[]}],value:"",attributes:{}}]}return[]}var eN="rgb(210, 210, 210)";function byn(t,e){const{transform:n}=e;if(t.shape==="rect"||t.shape==="rotated_rect"){const i=t.width*Math.abs(n.a),r=t.height*Math.abs(n.d),[o,s]=Yt(n,[t.x,t.y]),a=(t.rect_border_radius??0)*Math.abs(n.a);return t.shape==="rotated_rect"&&t.ccw_rotation?[{name:"rect",type:"element",attributes:{class:"assembly-pad",fill:eN,x:(-i/2).toString(),y:(-r/2).toString(),width:i.toString(),height:r.toString(),transform:`translate(${o} ${s}) rotate(${-t.ccw_rotation})`,"data-layer":t.layer,...a?{rx:a.toString(),ry:a.toString()}:{}},value:"",children:[]}]:[{name:"rect",type:"element",attributes:{class:"assembly-pad",fill:eN,x:(o-i/2).toString(),y:(s-r/2).toString(),width:i.toString(),height:r.toString(),"data-layer":t.layer,...a?{rx:a.toString(),ry:a.toString()}:{}},value:"",children:[]}]}if(t.shape==="pill"){const i=t.width*Math.abs(n.a),r=t.height*Math.abs(n.d),o=t.radius*Math.abs(n.a),[s,a]=Yt(n,[t.x,t.y]);return[{name:"rect",type:"element",attributes:{class:"assembly-pad",fill:eN,x:(s-i/2).toString(),y:(a-r/2).toString(),width:i.toString(),height:r.toString(),rx:o.toString(),ry:o.toString(),"data-layer":t.layer},value:"",children:[]}]}if(t.shape==="circle"){const i=t.radius*Math.abs(n.a),[r,o]=Yt(n,[t.x,t.y]);return[{name:"circle",type:"element",attributes:{class:"assembly-pad",fill:eN,cx:r.toString(),cy:o.toString(),r:i.toString(),"data-layer":t.layer},value:"",children:[]}]}if(t.shape==="polygon"){const i=(t.points??[]).map(r=>Yt(n,[r.x,r.y]));return[{name:"polygon",type:"element",attributes:{class:"assembly-pad",fill:eN,points:i.map(r=>r.join(",")).join(" "),"data-layer":t.layer},value:"",children:[]}]}return[]}var OZe=["pcb_component","pcb_smtpad","pcb_hole","pcb_plated_hole","pcb_board"];function LZe(t,e){let n=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY;for(const R of t)if(R.type==="pcb_board"){const P=R.center,M=R.width||0,I=R.height||0;n=Math.min(n,P.x-M/2),i=Math.min(i,P.y-I/2),r=Math.max(r,P.x+M/2),o=Math.max(o,P.y+I/2)}const s=1,a=r-n+2*s,c=o-i+2*s,l=e?.width??800,u=e?.height??600,d=l/a,h=u/c,f=Math.min(d,h),m=(l-a*f)/2,y=(u-c*f)/2,g=cs(Cs(m-n*f+s*f,u-y+i*f-s*f),kg(f,-f)),b={transform:g},v=t.sort((R,P)=>(OZe.indexOf(P.type)??9999)-(OZe.indexOf(R.type)??9999)).flatMap(R=>xyn(R,b,t)),w=oC(t),T=sC,N={name:"svg",type:"element",attributes:{xmlns:"http://www.w3.org/2000/svg",width:l.toString(),height:u.toString(),...w&&{"data-software-used-string":w},...e?.includeVersion&&{"data-circuit-to-svg-version":T}},value:"",children:[{name:"style",type:"element",children:[{type:"text",value:`
5301
+ `),N=T.length===1?[{type:"text",value:s,name:"",attributes:{},children:[]}]:T.map((P,M)=>({type:"element",name:"tspan",value:"",attributes:{x:"0",...M>0?{dy:f.toString()}:{}},children:[{type:"text",value:P,name:"",attributes:{},children:[]}]}));return[{name:"text",type:"element",attributes:{x:"0",y:"0",dx:g.toString(),dy:b.toString(),fill:w,"font-family":"Arial, sans-serif","font-size":f.toString(),"text-anchor":m,"dominant-baseline":y,transform:aw(v),class:`pcb-silkscreen-text pcb-silkscreen-${c}`,"data-pcb-silkscreen-text-id":t.pcb_component_id,stroke:"none"},children:N,value:""}]}function G_n(t,e){const{transform:n,layer:i,colorMap:r}=e,{center:o,width:s,height:a,layer:c="top",pcb_silkscreen_rect_id:l,stroke_width:u,is_filled:d,has_stroke:h,is_stroke_dashed:f}=t;if(i&&c!==i)return[];if(!o||typeof o.x!="number"||typeof o.y!="number"||typeof s!="number"||typeof a!="number")return console.error("Invalid rectangle data:",{center:o,width:s,height:a}),[];const[m,y]=Yt(n,[o.x,o.y]),g=s*Math.abs(n.a),b=a*Math.abs(n.d),v=u*Math.abs(n.a),w=c==="bottom"?r.silkscreen.bottom:r.silkscreen.top,T={x:(m-g/2).toString(),y:(y-b/2).toString(),width:g.toString(),height:b.toString(),class:`pcb-silkscreen-rect pcb-silkscreen-${c}`,"data-pcb-silkscreen-rect-id":l};T.fill=d?w:"none";let N;if(h===void 0?N=v>0:N=h,N){if(T.stroke=w,T["stroke-width"]=v.toString(),f){const P=.1*Math.abs(n.a),M=.05*Math.abs(n.a);T["stroke-dasharray"]=`${P} ${M}`}}else T.stroke="none";return[{name:"rect",type:"element",attributes:T,value:"",children:[]}]}function Y_n(t,e){const{transform:n,layer:i,colorMap:r}=e,{center:o,radius:s,layer:a="top",pcb_silkscreen_circle_id:c,stroke_width:l=1}=t;if(i&&a!==i)return[];if(!o||typeof o.x!="number"||typeof o.y!="number"||typeof s!="number")return console.error("Invalid PCB Silkscreen Circle data:",{center:o,radius:s}),[];const[u,d]=Yt(n,[o.x,o.y]),h=s*Math.abs(n.a),f=l*Math.abs(n.a),m=a==="bottom"?r.silkscreen.bottom:r.silkscreen.top;return[{name:"circle",type:"element",attributes:{cx:u.toString(),cy:d.toString(),r:h.toString(),class:`pcb-silkscreen-circle pcb-silkscreen-${a}`,stroke:m,"stroke-width":f.toString(),"data-pcb-silkscreen-circle-id":c},value:"",children:[]}]}function q_n(t,e){const{transform:n,layer:i,colorMap:r}=e,{x1:o,y1:s,x2:a,y2:c,stroke_width:l,layer:u="top",pcb_silkscreen_line_id:d}=t;if(i&&u!==i)return[];if(typeof o!="number"||typeof s!="number"||typeof a!="number"||typeof c!="number")return console.error("Invalid coordinates:",{x1:o,y1:s,x2:a,y2:c}),[];const[h,f]=Yt(n,[o,s]),[m,y]=Yt(n,[a,c]),g=l*Math.abs(n.a),b=u==="bottom"?r.silkscreen.bottom:r.silkscreen.top;return[{name:"line",type:"element",attributes:{x1:h.toString(),y1:f.toString(),x2:m.toString(),y2:y.toString(),stroke:b,"stroke-width":g.toString(),class:`pcb-silkscreen-line pcb-silkscreen-${u}`,"data-pcb-silkscreen-line-id":d},value:"",children:[]}]}function X_n(t){const e=[];for(let n=0;n<t.length-1;n++)e.push([t[n],t[n+1]]);return e}var ex={copper:{top:"rgb(200, 52, 52)",bottom:"rgb(77, 127, 196)"},soldermask:{top:"rgb(200, 52, 52)",bottom:"rgb(77, 127, 196)"},drill:"#FF26E2",silkscreen:{top:"#f2eda1",bottom:"#5da9e9"},boardOutline:"rgba(255, 255, 255, 0.5)",debugComponent:{fill:null,stroke:null}};ex.drill,ex.silkscreen.top,ex.silkscreen.bottom,ex.copper.top,ex.copper.bottom;function hM(t,e=ex){return e.copper[t]??"white"}var W_n={bottom:"rgb(105, 105, 105)",top:"rgb(105, 105, 105)"};function Bj(t){return W_n[t]??"rgb(105, 105, 105)"}function Z_n(t,e){const{transform:n,layer:i,colorMap:r,renderSolderMask:o}=e;if(!t.route||!Array.isArray(t.route)||t.route.length<2)return[];const s=X_n(t.route),a=[];for(const[c,l]of s){const u=Yt(n,[c.x,c.y]),d=Yt(n,[l.x,l.y]),h="layer"in c?c.layer:"layer"in l?l.layer:null;if(!h||i&&h!==i)continue;const f=hM(h,r),m=r.soldermask[h]??f,y="width"in c?c.width:"width"in l?l.width:null,g=y?(y*Math.abs(n.a)).toString():"0.3";if(o){const b={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-trace",stroke:f,fill:"none",d:`M ${u[0]} ${u[1]} L ${d[0]} ${d[1]}`,"stroke-width":g,"stroke-linecap":"round","stroke-linejoin":"round","shape-rendering":"crispEdges","data-layer":h}},v={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask",stroke:m,fill:"none",d:`M ${u[0]} ${u[1]} L ${d[0]} ${d[1]}`,"stroke-width":g,"stroke-linecap":"round","stroke-linejoin":"round","shape-rendering":"crispEdges","data-layer":h}};a.push(v,b)}else{const b={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-trace",stroke:m,fill:"none",d:`M ${u[0]} ${u[1]} L ${d[0]} ${d[1]}`,"stroke-width":g,"stroke-linecap":"round","stroke-linejoin":"round","shape-rendering":"crispEdges","data-layer":h}};a.push(b)}}return a.sort((c,l)=>{const u=c.attributes["data-layer"],d=l.attributes["data-layer"];return u==="bottom"&&d!=="bottom"?-1:u==="top"&&d!=="top"?1:0}),a}function K_n(t,e){const{transform:n,layer:i,colorMap:r}=e;if(i&&t.layer!==i)return[];const o=!!t?.is_covered_with_solder_mask,s=r.soldermask[t.layer]??r.soldermask.top;if(t.shape==="rect"||t.shape==="rotated_rect"){const a=t.width*Math.abs(n.a),c=t.height*Math.abs(n.d),[l,u]=Yt(n,[t.x,t.y]),d=(t.rect_border_radius??0)*Math.abs(n.a);if(t.shape==="rotated_rect"&&t.ccw_rotation){const m={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:hM(t.layer,r),x:(-a/2).toString(),y:(-c/2).toString(),width:a.toString(),height:c.toString(),transform:`translate(${l} ${u}) rotate(${-t.ccw_rotation})`,"data-layer":t.layer,...d?{rx:d.toString(),ry:d.toString()}:{}}};if(!o)return[m];const y={name:m.name,type:m.type,value:"",children:[],attributes:{...m.attributes,class:"pcb-solder-mask",fill:s}};return[m,y]}const h={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:hM(t.layer,r),x:(l-a/2).toString(),y:(u-c/2).toString(),width:a.toString(),height:c.toString(),"data-layer":t.layer,...d?{rx:d.toString(),ry:d.toString()}:{}}};if(!o)return[h];const f={name:h.name,type:h.type,value:"",children:[],attributes:{...h.attributes,class:"pcb-solder-mask",fill:s}};return[h,f]}if(t.shape==="pill"){const a=t.width*Math.abs(n.a),c=t.height*Math.abs(n.d),l=t.radius*Math.abs(n.a),[u,d]=Yt(n,[t.x,t.y]),h={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:hM(t.layer,r),x:(u-a/2).toString(),y:(d-c/2).toString(),width:a.toString(),height:c.toString(),rx:l.toString(),ry:l.toString(),"data-layer":t.layer}};if(!o)return[h];const f={name:h.name,type:h.type,value:"",children:[],attributes:{...h.attributes,class:"pcb-solder-mask",fill:s}};return[h,f]}if(t.shape==="circle"){const a=t.radius*Math.abs(n.a),[c,l]=Yt(n,[t.x,t.y]),u={name:"circle",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:hM(t.layer,r),cx:c.toString(),cy:l.toString(),r:a.toString(),"data-layer":t.layer}};if(!o)return[u];const d={name:u.name,type:u.type,value:"",children:[],attributes:{...u.attributes,class:"pcb-solder-mask",fill:s}};return[u,d]}if(t.shape==="polygon"){const a=(t.points??[]).map(u=>Yt(n,[u.x,u.y])),c={name:"polygon",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:hM(t.layer,r),points:a.map(u=>u.join(",")).join(" "),"data-layer":t.layer}};if(!o)return[c];const l={name:c.name,type:c.type,value:"",children:[],attributes:{...c.attributes,class:"pcb-solder-mask",fill:s}};return[c,l]}return[]}function IZe(t,e){const{transform:n,colorMap:i}=e,{width:r,height:o,center:s,outline:a}=t;let c;if(a&&Array.isArray(a)&&a.length>=3)c=a.map((l,u)=>{const[d,h]=Yt(n,[l.x,l.y]);return u===0?`M ${d} ${h}`:`L ${d} ${h}`}).join(" ");else{const l=r/2,u=o/2,d=Yt(n,[s.x-l,s.y-u]),h=Yt(n,[s.x+l,s.y-u]),f=Yt(n,[s.x+l,s.y+u]),m=Yt(n,[s.x-l,s.y+u]);c=`M ${d[0]} ${d[1]} L ${h[0]} ${h[1]} L ${f[0]} ${f[1]} L ${m[0]} ${m[1]}`}return c+=" Z",[{name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-board",d:c,fill:"none",stroke:i.boardOutline,"stroke-width":(.1*Math.abs(n.a)).toString()}}]}function Q_n(t,e){const{transform:n,colorMap:i}=e,[r,o]=Yt(n,[t.x,t.y]),s=t.outer_diameter*Math.abs(n.a),a=t.outer_diameter*Math.abs(n.a),c=t.hole_diameter*Math.abs(n.a),l=t.hole_diameter*Math.abs(n.a),u=Math.min(s,a)/2,d=Math.min(c,l)/2;return{name:"g",type:"element",children:[{name:"circle",type:"element",attributes:{class:"pcb-hole-outer",fill:i.copper.top,cx:r.toString(),cy:o.toString(),r:u.toString()}},{name:"circle",type:"element",attributes:{class:"pcb-hole-inner",fill:i.drill,cx:r.toString(),cy:o.toString(),r:d.toString()}}]}}function J_n(t,e){const{transform:n,colorMap:i}=e,[r,o]=Yt(n,[t.x,t.y]);if(t.hole_shape==="circle"||t.hole_shape==="square"){const s=t.hole_diameter*Math.abs(n.a),a=s/2;return t.hole_shape==="circle"?[{name:"circle",type:"element",attributes:{class:"pcb-hole",cx:r.toString(),cy:o.toString(),r:a.toString(),fill:i.drill},children:[],value:""}]:[{name:"rect",type:"element",attributes:{class:"pcb-hole",x:(r-a).toString(),y:(o-a).toString(),width:s.toString(),height:s.toString(),fill:i.drill},children:[],value:""}]}if(t.hole_shape==="oval"){const s=t.hole_width*Math.abs(n.a),a=t.hole_height*Math.abs(n.a),c=s/2,l=a/2;return[{name:"ellipse",type:"element",attributes:{class:"pcb-hole",cx:r.toString(),cy:o.toString(),rx:c.toString(),ry:l.toString(),fill:i.drill},children:[],value:""}]}return[]}var eyn=(t,e)=>{const n=ea(e).pcb_smtpad.get(t);if(n&&"x"in n&&"y"in n)return{x:n.x,y:n.y};const i=ea(e).pcb_plated_hole.get(t);return i&&"x"in i&&"y"in i?{x:i.x,y:i.y}:null},tyn=(t,e,n,i)=>{const r=n.getIdsConnectedToNet(e);let o=null,s=1/0;for(const a of r){const c=eyn(a,i);if(c){const l=t.x-c.x,u=t.y-c.y,d=Math.sqrt(l*l+u*u);d>0&&d<s&&(s=d,o=c)}}return o};function nyn(t,e){const{transform:n}=e,i=J6(t),r=t.filter(c=>c.type==="pcb_port"),o=t.filter(c=>c.type==="source_trace"),s=[];r.forEach((c,l)=>{const u=c.pcb_port_id;if(!u)return;const d=i.getNetConnectedToId(u);if(!d)return;let h=!1;const f=ea(t).source_port.getWhere({pcb_port_id:u});if(f&&f.source_port_id){const g=f.source_port_id;for(const b of o)if(Array.isArray(b.connected_source_port_ids)&&b.connected_source_port_ids.includes(g)&&Array.isArray(b.connected_source_net_ids)&&b.connected_source_net_ids.length>0){h=!0;break}}const m={x:c.x,y:c.y},y=tyn(m,d,i,t);y&&s.push({key:`${u}-${l}`,startPoint:m,endPoint:y,isInNet:h})});const a=[];for(const c of s){const l=Yt(n,[c.startPoint.x,c.startPoint.y]),u=Yt(n,[c.endPoint.x,c.endPoint.y]),d={x1:l[0].toString(),y1:l[1].toString(),x2:u[0].toString(),y2:u[1].toString(),stroke:"white","stroke-width":"1","stroke-dasharray":"6,6"};a.push({name:"line",type:"element",attributes:d,value:"",children:[]})}return a}function iyn(t,e){const{transform:n,colorMap:i}=e;if(t.shape==="rect"){const r=t,[o,s]=Yt(n,[r.center.x,r.center.y]),a=r.width*Math.abs(n.a),c=r.height*Math.abs(n.d),l=-(r.rotation??0);return[{name:"rect",type:"element",attributes:{class:"pcb-cutout pcb-cutout-rect",x:(-a/2).toString(),y:(-c/2).toString(),width:a.toString(),height:c.toString(),fill:i.drill,transform:aw(cs(Cs(o,s),ov(l*Math.PI/180)))},children:[],value:""}]}if(t.shape==="circle"){const r=t,[o,s]=Yt(n,[r.center.x,r.center.y]),a=r.radius*Math.abs(n.a);return[{name:"circle",type:"element",attributes:{class:"pcb-cutout pcb-cutout-circle",cx:o.toString(),cy:s.toString(),r:a.toString(),fill:i.drill},children:[],value:""}]}if(t.shape==="polygon"){const r=t;return!r.points||r.points.length===0?[]:[{name:"polygon",type:"element",attributes:{class:"pcb-cutout pcb-cutout-polygon",points:r.points.map(a=>Yt(n,[a.x,a.y])).map(a=>`${a[0]},${a[1]}`).join(" "),fill:i.drill},children:[],value:""}]}return[]}function NZe(t,e){if(t.length===0)return"";const n=t.map(r=>{const[o,s]=Yt(e,[r.x,r.y]);return{...r,x:o,y:s}});let i=`M ${n[0].x} ${n[0].y}`;for(let r=0;r<n.length;r++){const o=n[r],s=n[(r+1)%n.length];if(o.bulge){if(Math.hypot(s.x-o.x,s.y-o.y)<1e-9)continue;const a=o.bulge,c=s.x-o.x,l=s.y-o.y,u=Math.hypot(c,l),d=Math.abs(u/4/a*(a*a+1)),h=a<0?1:0,f=Math.abs(a)>1?1:0;i+=` A ${d} ${d} 0 ${f} ${h} ${s.x} ${s.y}`}else i+=` L ${s.x} ${s.y}`}return i+=" Z",i}function ryn(t,e){const{transform:n,layer:i,colorMap:r}=e,{layer:o}=t;if(i&&o!==i)return[];const s=hM(o,r),a="0.5";if(t.shape==="rect"){const[c,l]=Yt(n,[t.center.x,t.center.y]),u=t.width*Math.abs(n.a),d=t.height*Math.abs(n.d),h=-(t.rotation??0);return[{name:"rect",type:"element",attributes:{class:"pcb-copper-pour pcb-copper-pour-rect",x:(-u/2).toString(),y:(-d/2).toString(),width:u.toString(),height:d.toString(),fill:s,"fill-opacity":a,transform:aw(cs(Cs(c,l),ov(h*Math.PI/180))),"data-layer":o},children:[],value:""}]}if(t.shape==="polygon")return!t.points||t.points.length===0?[]:[{name:"polygon",type:"element",attributes:{class:"pcb-copper-pour pcb-copper-pour-polygon",points:t.points.map(u=>Yt(n,[u.x,u.y])).map(u=>`${u[0]},${u[1]}`).join(" "),fill:s,"fill-opacity":a,"data-layer":o},children:[],value:""}];if(t.shape==="brep"){const{brep_shape:c}=t;let l=NZe(c.outer_ring.vertices,n);for(const u of c.inner_rings??[])l+=` ${NZe(u.vertices,n)}`;return[{name:"path",type:"element",attributes:{class:"pcb-copper-pour pcb-copper-pour-brep",d:l,fill:s,"fill-rule":"evenodd","fill-opacity":a,"data-layer":o},children:[],value:""}]}return[]}function oyn(t,e){const{transform:n}=e,{center:i,width:r,height:o,rotation:s=0}=t,[a,c]=Yt(n,[i.x,i.y]),l=r*Math.abs(n.a),u=o*Math.abs(n.d),d=`translate(${a}, ${c}) rotate(${-s}) scale(1, -1)`;return!e.colorMap.debugComponent?.fill&&!e.colorMap.debugComponent?.stroke?[]:[{name:"g",type:"element",attributes:{transform:d},children:[{name:"rect",type:"element",attributes:{class:"pcb-component",x:(-l/2).toString(),y:(-u/2).toString(),width:l.toString(),height:u.toString(),fill:e.colorMap.debugComponent.fill??"transparent",stroke:e.colorMap.debugComponent.stroke??"transparent"}}],value:""}]}function oC(t){return t.find(n=>n.type==="project_software_metadata"||n.type==="source_project_metadata")?.software_used_string}var syn={version:"0.0.201"},sC=syn.version,kZe=["pcb_trace_error","pcb_plated_hole","pcb_fabrication_note_text","pcb_fabrication_note_path","pcb_silkscreen_text","pcb_silkscreen_path","pcb_via","pcb_cutout","pcb_copper_pour","pcb_smtpad","pcb_trace","pcb_component","pcb_board"];function $me(t,e){const n=e?.drawPaddingOutsideBoard??!0,i=e?.layer,r=e?.colorOverrides,o={copper:{top:r?.copper?.top??ex.copper.top,bottom:r?.copper?.bottom??ex.copper.bottom},drill:r?.drill??ex.drill,silkscreen:{top:r?.silkscreen?.top??ex.silkscreen.top,bottom:r?.silkscreen?.bottom??ex.silkscreen.bottom},boardOutline:r?.boardOutline??ex.boardOutline,soldermask:{top:r?.soldermask?.top??ex.soldermask.top,bottom:r?.soldermask?.bottom??ex.soldermask.bottom},debugComponent:{fill:r?.debugComponent?.fill??ex.debugComponent.fill,stroke:r?.debugComponent?.stroke??ex.debugComponent.stroke}};let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY,u=Number.POSITIVE_INFINITY,d=Number.POSITIVE_INFINITY,h=Number.NEGATIVE_INFINITY,f=Number.NEGATIVE_INFINITY;for(const ke of t)if(ke.type==="pcb_board")ke.outline&&Array.isArray(ke.outline)&&ke.outline.length>=3?(Me(ke.outline),Ie(ke.outline)):"center"in ke&&"width"in ke&&"height"in ke&&(ue(ke.center,ke.width,ke.height),he(ke.center,ke.width,ke.height));else if("x"in ke&&"y"in ke)ue({x:ke.x,y:ke.y},0,0);else if(ke.type==="pcb_smtpad"){const ce=ke;ce.shape==="rect"||ce.shape==="rotated_rect"||ce.shape==="pill"?ue({x:ce.x,y:ce.y},ce.width,ce.height):ce.shape==="circle"?ue({x:ce.x,y:ce.y},ce.radius*2,ce.radius*2):ce.shape==="polygon"&&De(ce.points)}else"route"in ke?De(ke.route):ke.type==="pcb_silkscreen_text"||ke.type==="pcb_silkscreen_rect"||ke.type==="pcb_silkscreen_circle"||ke.type==="pcb_silkscreen_line"?Ge(ke):ke.type==="pcb_copper_pour"&&(ke.shape==="rect"?ue(ke.center,ke.width,ke.height):ke.shape==="polygon"&&De(ke.points));const m=n?1:0,y=n||!Number.isFinite(u)?s:u,g=n||!Number.isFinite(d)?a:d,b=n||!Number.isFinite(h)?c:h,v=n||!Number.isFinite(f)?l:f,w=b-y+2*m,T=v-g+2*m;let N=e?.width??800,R=e?.height??600;if(e?.matchBoardAspectRatio){const ke=h-u,ce=f-d;if(ke>0&&ce>0){const we=ke/ce;e?.width&&!e?.height?R=e.width/we:e?.height&&!e?.width?N=e.height*we:R=N/we}}const P=[];for(const ke of t)"route"in ke&&ke.route!==void 0&&P.push(ke.route);const M=N/w,I=R/T,A=Math.min(M,I),$=(N-w*A)/2,k=(R-T*A)/2,V=cs(Cs($-y*A+m*A,R-k+g*A-m*A),kg(A,-A)),X={transform:V,layer:i,shouldDrawErrors:e?.shouldDrawErrors,drawPaddingOutsideBoard:n,colorMap:o,renderSolderMask:e?.renderSolderMask};function W(ke){if(ke.type==="pcb_smtpad")return ke.layer==="top"||ke.layer==="bottom"?ke.layer:void 0;if(ke.type==="pcb_trace")for(const ce of ke.route??[]){const we="layer"in ce&&ce.layer||"from_layer"in ce&&ce.from_layer||"to_layer"in ce&&ce.to_layer||void 0;if(we==="top"||we==="bottom")return we}}function K(ke){return ke.type==="pcb_trace"||ke.type==="pcb_smtpad"}let te=t.sort((ke,ce)=>{const we=W(ke),xe=W(ce);if(K(ke)&&K(ce)&&we!==xe){if(we==="top")return 1;if(xe==="top"||we==="bottom")return-1;if(xe==="bottom")return 1}return(kZe.indexOf(ce.type)??9999)-(kZe.indexOf(ke.type)??9999)}).flatMap(ke=>ayn({elm:ke,circuitJson:t,ctx:X}));for(const ke of t)if("stroke_width"in ke){String(A*ke.stroke_width);break}if(e?.shouldDrawRatsNest){const ke=nyn(t,X);te=te.concat(ke)}const se=[{name:"style",type:"element",value:"",attributes:{},children:[{type:"text",value:"",name:"",attributes:{},children:[]}]},{name:"rect",type:"element",value:"",attributes:{class:"boundary",x:"0",y:"0",fill:e?.backgroundColor??"#000",width:N.toString(),height:R.toString()},children:[]}];n&&se.push(cyn(V,s,a,c,l)),se.push(...te);const de=oC(t),be=sC,re={name:"svg",type:"element",attributes:{xmlns:"http://www.w3.org/2000/svg",width:N.toString(),height:R.toString(),...de&&{"data-software-used-string":de},...e?.includeVersion&&{"data-circuit-to-svg-version":be}},value:"",children:se.filter(ke=>ke!==null)};try{return FP(re)}catch(ke){throw console.error("Error stringifying SVG object:",ke),ke}function ue(ke,ce,we){const xe=ce/2,Ye=we/2;s=Math.min(s,ke.x-xe),a=Math.min(a,ke.y-Ye),c=Math.max(c,ke.x+xe),l=Math.max(l,ke.y+Ye)}function he(ke,ce,we){const xe=ce/2,Ye=we/2;u=Math.min(u,ke.x-xe),d=Math.min(d,ke.y-Ye),h=Math.max(h,ke.x+xe),f=Math.max(f,ke.y+Ye)}function Me(ke){for(const ce of ke)s=Math.min(s,ce.x),a=Math.min(a,ce.y),c=Math.max(c,ce.x),l=Math.max(l,ce.y)}function Ie(ke){for(const ce of ke)u=Math.min(u,ce.x),d=Math.min(d,ce.y),h=Math.max(h,ce.x),f=Math.max(f,ce.y)}function De(ke){for(const ce of ke)s=Math.min(s,ce.x),a=Math.min(a,ce.y),c=Math.max(c,ce.x),l=Math.max(l,ce.y)}function Ge(ke){if(ke.type==="pcb_silkscreen_text")ue(ke.anchor_position,0,0);else if(ke.type==="pcb_silkscreen_path")De(ke.route);else if(ke.type==="pcb_silkscreen_rect")ue(ke.center,ke.width,ke.height);else if(ke.type==="pcb_silkscreen_circle")ue(ke.center,ke.radius*2,ke.radius*2);else if(ke.type==="pcb_silkscreen_line")ue({x:ke.x1,y:ke.y1},0,0),ue({x:ke.x2,y:ke.y2},0,0);else if(ke.type==="pcb_cutout"){const ce=ke;ce.shape==="rect"?ue(ce.center,ce.width,ce.height):ce.shape==="circle"?ue(ce.center,ce.radius*2,ce.radius*2):ce.shape==="polygon"&&De(ce.points)}}}function ayn({elm:t,circuitJson:e,ctx:n}){switch(t.type){case"pcb_trace_error":return F_n(t,e,n).filter(Boolean);case"pcb_component":return oyn(t,n).filter(Boolean);case"pcb_trace":return Z_n(t,n);case"pcb_copper_pour":return ryn(t,n);case"pcb_plated_hole":return j_n(t,n).filter(Boolean);case"pcb_hole":return J_n(t,n);case"pcb_smtpad":return K_n(t,n);case"pcb_silkscreen_text":return V_n(t,n);case"pcb_silkscreen_rect":return G_n(t,n);case"pcb_silkscreen_circle":return Y_n(t,n);case"pcb_silkscreen_line":return q_n(t,n);case"pcb_fabrication_note_path":return U_n(t,n);case"pcb_fabrication_note_text":return $_n(t,n);case"pcb_silkscreen_path":return H_n(t,n);case"pcb_board":return n.drawPaddingOutsideBoard?IZe(t,n):[];case"pcb_via":return Q_n(t,n);case"pcb_cutout":return iyn(t,n);default:return[]}}function cyn(t,e,n,i,r){const[o,s]=Yt(t,[e,n]),[a,c]=Yt(t,[i,r]),l=Math.abs(a-o),u=Math.abs(c-s),d=Math.min(o,a),h=Math.min(s,c);return{name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-boundary",fill:"none",stroke:"#fff","stroke-width":"0.3",x:d.toString(),y:h.toString(),width:l.toString(),height:u.toString()}}}var lyn=$me,Uj={fill:"none",stroke:"rgb(0,0,0)",strokeOpacity:"0.8",strokeWidthFactor:.2};function uyn(t,e,n={}){const{width:i,height:r,center:o,outline:s}=t;let a;if(s&&Array.isArray(s)&&s.length>=3)a=s.map((c,l)=>{const[u,d]=Yt(e,[c.x,c.y]);return l===0?`M ${u} ${d}`:`L ${u} ${d}`}).join(" ");else{const c=i/2,l=r/2,u=Yt(e,[o.x-c,o.y-l]),d=Yt(e,[o.x+c,o.y-l]),h=Yt(e,[o.x+c,o.y+l]),f=Yt(e,[o.x-c,o.y+l]);a=`M ${u[0]} ${u[1]} L ${d[0]} ${d[1]} L ${h[0]} ${h[1]} L ${f[0]} ${f[1]}`}return a+=" Z",[{name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-board",d:a,fill:n.fill??Uj.fill,stroke:n.stroke??Uj.stroke,"stroke-opacity":n.strokeOpacity??Uj.strokeOpacity,"stroke-width":((n.strokeWidthFactor??Uj.strokeWidthFactor)*Math.abs(e.a)).toString()}}]}var dyn={pin_number:.15,negated_pin_number:.15*.8,reference_designator:.18,manufacturer_number:.18,net_label:.18,error:.05},aC=(t,e)=>e??dyn[t],l3=(t,e,n)=>Math.abs(t.a)*aC(e,n);function hyn(t,e){const{elm:n,portPosition:i,name:r,arePinsInterchangeable:o}=t,{transform:s}=e,{center:a,width:c,height:l,rotation:u=0,layer:d="top"}=n;if(!a||typeof c!="number"||typeof l!="number")return null;const[h,f]=Yt(s,[a.x,a.y]),[m,y]=Yt(s,[i.x,i.y]),g=c*Math.abs(s.a),b=l*Math.abs(s.d),v=y>f,w=m<h,T=[pyn(g,b,u,d),fyn(g,b,r??"")];return o||T.push(myn(g,b,u,d,v,w)),{name:"g",type:"element",value:"",attributes:{transform:`translate(${h}, ${f}) scale(1, -1)`},children:T}}function pyn(t,e,n,i){const r=t/2,o=e/2;return{name:"path",type:"element",attributes:{class:"assembly-component",d:_yn(r,o,n),"stroke-width":.8.toFixed(2),transform:`rotate(${-n})`,"stroke-dasharray":i==="bottom"?"2,2":""},value:"",children:[]}}function fyn(t,e,n,i){const r=Math.min(t,e),c=Math.min(58,Math.max(3,r*.8)),l=e>t;return{name:"text",type:"element",attributes:{x:"0",y:"0",class:"assembly-component-label","text-anchor":"middle",dy:".10em",style:"pointer-events: none","font-size":`${c.toFixed(1)}px`,transform:l?"rotate(90) scale(1, -1)":"scale(1, -1)"},children:[{type:"text",value:n||"",name:"",attributes:{},children:[]}],value:""}}function myn(t,e,n,i,r,o){const s=t/2,a=e/2,c=Math.min(s,a)*.5;let l;return r&&o?l=[[-s,-a],[-s+c,-a],[-s,-a+c]]:r&&!o?l=[[s,-a],[s-c,-a],[s,-a+c]]:!r&&o?l=[[-s,a],[-s+c,a],[-s,a-c]]:l=[[s,a],[s-c,a],[s,a-c]],{name:"polygon",type:"element",attributes:{class:"assembly-pin1-indicator",points:l.map(d=>d.join(",")).join(" "),fill:"#333",stroke:"none",transform:`rotate(${-n})`},value:"",children:[]}}function _yn(t,e,n){const i=(a,c,l)=>{const u=Math.PI/180*l,d=Math.cos(u),h=Math.sin(u);return[a*d-c*h,a*h+c*d]};return`${[[-t,-e],[t,-e],[t,e],[-t,e]].map(([a,c])=>i(a,c,n)).map(([a,c],l)=>l===0?`M${a},${c}`:`L${a},${c}`).join(" ")} Z`}var jme="rgb(190, 190, 190)";function yyn(t,e){const{transform:n}=e,[i,r]=Yt(n,[t.x,t.y]);if(t.hole_shape==="circle"||t.hole_shape==="square"){const o=t.hole_diameter*Math.abs(n.a),s=o/2;return t.hole_shape==="circle"?[{name:"circle",type:"element",attributes:{class:"assembly-hole",cx:i.toString(),cy:r.toString(),r:s.toString(),fill:jme},children:[],value:""}]:[{name:"rect",type:"element",attributes:{class:"assembly-hole",x:(i-s).toString(),y:(r-s).toString(),width:o.toString(),height:o.toString(),fill:jme},children:[],value:""}]}if(t.hole_shape==="oval"){const o=t.hole_width*Math.abs(n.a),s=t.hole_height*Math.abs(n.a),a=o/2,c=s/2;return[{name:"ellipse",type:"element",attributes:{class:"assembly-hole",cx:i.toString(),cy:r.toString(),rx:a.toString(),ry:c.toString(),fill:jme},children:[],value:""}]}return[]}var QI="rgb(210, 210, 210)",JI="rgb(190, 190, 190)";function gyn(t,e){const{transform:n}=e,[i,r]=Yt(n,[t.x,t.y]);if(t.shape==="pill"){const o=t.outer_width*Math.abs(n.a),s=t.outer_height*Math.abs(n.a),a=t.hole_width*Math.abs(n.a),c=t.hole_height*Math.abs(n.a),l=o/2,u=s-o,d=a/2;return[{name:"g",type:"element",children:[{name:"path",type:"element",attributes:{class:"assembly-hole-outer",fill:QI,d:`M${i-l},${r-u/2} v${u} a${l},${l} 0 0 0 ${o},0 v-${u} a${l},${l} 0 0 0 -${o},0 z`},value:"",children:[]},{name:"path",type:"element",attributes:{class:"assembly-hole-inner",fill:JI,d:`M${i-d},${r-(c-a)/2} v${c-a} a${d},${d} 0 0 0 ${a},0 v-${c-a} a${d},${d} 0 0 0 -${a},0 z`},value:"",children:[]}],value:"",attributes:{}}]}if(t.shape==="circle"){const o=t.outer_diameter*Math.abs(n.a),s=t.outer_diameter*Math.abs(n.a),a=t.hole_diameter*Math.abs(n.a),c=t.hole_diameter*Math.abs(n.a),l=Math.min(o,s)/2,u=Math.min(a,c)/2;return[{name:"g",type:"element",children:[{name:"circle",type:"element",attributes:{class:"assembly-hole-outer",fill:QI,cx:i.toString(),cy:r.toString(),r:l.toString()},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"assembly-hole-inner",fill:JI,cx:i.toString(),cy:r.toString(),r:u.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(t.shape==="circular_hole_with_rect_pad"){const o=t,s=o.hole_diameter*Math.abs(n.a),a=o.rect_pad_width*Math.abs(n.a),c=o.rect_pad_height*Math.abs(n.a),l=(o.rect_border_radius??0)*Math.abs(n.a),u=s/2,[d,h]=Yt(n,[o.x+o.hole_offset_x,o.y+o.hole_offset_y]);return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"assembly-hole-outer-pad",fill:QI,x:(i-a/2).toString(),y:(r-c/2).toString(),width:a.toString(),height:c.toString(),...l?{rx:l.toString(),ry:l.toString()}:{}},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"assembly-hole-inner",fill:JI,cx:d.toString(),cy:h.toString(),r:u.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(t.shape==="pill_hole_with_rect_pad"){const o=t,s=o.rect_pad_width*Math.abs(n.a),a=o.rect_pad_height*Math.abs(n.a),c=(o.rect_border_radius??0)*Math.abs(n.a),l=o.hole_height*Math.abs(n.a),u=o.hole_width*Math.abs(n.a),d=o,h=d.hole_offset_x??0,f=d.hole_offset_y??0,[m,y]=Yt(n,[o.x+h,o.y+f]),g=Math.min(l,u)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"assembly-hole-outer-pad",fill:QI,x:(i-s/2).toString(),y:(r-a/2).toString(),width:s.toString(),height:a.toString(),...c?{rx:c.toString(),ry:c.toString()}:{}},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"assembly-hole-inner",fill:JI,x:(m-u/2).toString(),y:(y-l/2).toString(),width:u.toString(),height:l.toString(),rx:g.toString(),ry:g.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(t.shape==="rotated_pill_hole_with_rect_pad"){const o=t,s=o.rect_pad_width*Math.abs(n.a),a=o.rect_pad_height*Math.abs(n.a),c=(o.rect_border_radius??0)*Math.abs(n.a),l=o.hole_height*Math.abs(n.a),u=o.hole_width*Math.abs(n.a),d=o,h=d.hole_offset_x??0,f=d.hole_offset_y??0,[m,y]=Yt(n,[o.x+h,o.y+f]),g=Math.min(l,u)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"assembly-hole-outer-pad",fill:QI,x:(-s/2).toString(),y:(-a/2).toString(),width:s.toString(),height:a.toString(),transform:`translate(${i} ${r}) rotate(${-o.rect_ccw_rotation})`,...c?{rx:c.toString(),ry:c.toString()}:{}},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"assembly-hole-inner",fill:JI,x:(-u/2).toString(),y:(-l/2).toString(),width:u.toString(),height:l.toString(),rx:g.toString(),ry:g.toString(),transform:`translate(${m} ${y}) rotate(${-o.hole_ccw_rotation})`},value:"",children:[]}],value:"",attributes:{}}]}return[]}var eN="rgb(210, 210, 210)";function byn(t,e){const{transform:n}=e;if(t.shape==="rect"||t.shape==="rotated_rect"){const i=t.width*Math.abs(n.a),r=t.height*Math.abs(n.d),[o,s]=Yt(n,[t.x,t.y]),a=(t.rect_border_radius??0)*Math.abs(n.a);return t.shape==="rotated_rect"&&t.ccw_rotation?[{name:"rect",type:"element",attributes:{class:"assembly-pad",fill:eN,x:(-i/2).toString(),y:(-r/2).toString(),width:i.toString(),height:r.toString(),transform:`translate(${o} ${s}) rotate(${-t.ccw_rotation})`,"data-layer":t.layer,...a?{rx:a.toString(),ry:a.toString()}:{}},value:"",children:[]}]:[{name:"rect",type:"element",attributes:{class:"assembly-pad",fill:eN,x:(o-i/2).toString(),y:(s-r/2).toString(),width:i.toString(),height:r.toString(),"data-layer":t.layer,...a?{rx:a.toString(),ry:a.toString()}:{}},value:"",children:[]}]}if(t.shape==="pill"){const i=t.width*Math.abs(n.a),r=t.height*Math.abs(n.d),o=t.radius*Math.abs(n.a),[s,a]=Yt(n,[t.x,t.y]);return[{name:"rect",type:"element",attributes:{class:"assembly-pad",fill:eN,x:(s-i/2).toString(),y:(a-r/2).toString(),width:i.toString(),height:r.toString(),rx:o.toString(),ry:o.toString(),"data-layer":t.layer},value:"",children:[]}]}if(t.shape==="circle"){const i=t.radius*Math.abs(n.a),[r,o]=Yt(n,[t.x,t.y]);return[{name:"circle",type:"element",attributes:{class:"assembly-pad",fill:eN,cx:r.toString(),cy:o.toString(),r:i.toString(),"data-layer":t.layer},value:"",children:[]}]}if(t.shape==="polygon"){const i=(t.points??[]).map(r=>Yt(n,[r.x,r.y]));return[{name:"polygon",type:"element",attributes:{class:"assembly-pad",fill:eN,points:i.map(r=>r.join(",")).join(" "),"data-layer":t.layer},value:"",children:[]}]}return[]}var OZe=["pcb_component","pcb_smtpad","pcb_hole","pcb_plated_hole","pcb_board"];function LZe(t,e){let n=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY;for(const R of t)if(R.type==="pcb_board"){const P=R.center,M=R.width||0,I=R.height||0;n=Math.min(n,P.x-M/2),i=Math.min(i,P.y-I/2),r=Math.max(r,P.x+M/2),o=Math.max(o,P.y+I/2)}const s=1,a=r-n+2*s,c=o-i+2*s,l=e?.width??800,u=e?.height??600,d=l/a,h=u/c,f=Math.min(d,h),m=(l-a*f)/2,y=(u-c*f)/2,g=cs(Cs(m-n*f+s*f,u-y+i*f-s*f),kg(f,-f)),b={transform:g},v=t.sort((R,P)=>(OZe.indexOf(P.type)??9999)-(OZe.indexOf(R.type)??9999)).flatMap(R=>xyn(R,b,t)),w=oC(t),T=sC,N={name:"svg",type:"element",attributes:{xmlns:"http://www.w3.org/2000/svg",width:l.toString(),height:u.toString(),...w&&{"data-software-used-string":w},...e?.includeVersion&&{"data-circuit-to-svg-version":T}},value:"",children:[{name:"style",type:"element",children:[{type:"text",value:`
5302
5302
  .assembly-component {
5303
5303
  fill: none;
5304
5304
  stroke: #000;
@@ -5320,7 +5320,7 @@ ${P.type}: ${k}
5320
5320
  stroke: #fff;
5321
5321
  stroke-width: 0.2;
5322
5322
  }
5323
- `,name:"",attributes:{},children:[]}],value:"",attributes:{}},{name:"rect",type:"element",attributes:{fill:"#fff",x:"0",y:"0",width:l.toString(),height:u.toString()},value:"",children:[]},vyn(g,n,i,r,o),...v].filter(R=>R!==null)};return FP(N)}function xyn(t,e,n){const i=ea(n).source_component.list();switch(t.type){case"pcb_board":return uyn(t,e.transform);case"pcb_component":{const r=i.find(a=>a.source_component_id===t.source_component_id),s=ea(n).pcb_port.list().filter(a=>a.pcb_component_id===t.pcb_component_id)[0];if(r&&s){const a=r.are_pins_interchangeable,c=hyn({elm:t,portPosition:{x:s.x,y:s.y},name:r.name,arePinsInterchangeable:a},e);return c?[c]:[]}return[]}case"pcb_smtpad":return byn(t,e);case"pcb_hole":return yyn(t,e);case"pcb_plated_hole":return gyn(t,e);default:return[]}}function vyn(t,e,n,i,r){const[o,s]=Yt(t,[e,n]),[a,c]=Yt(t,[i,r]),l=Math.abs(a-o),u=Math.abs(c-s),d=Math.min(o,a),h=Math.min(s,c);return{name:"rect",type:"element",value:"",children:[],attributes:{class:"assembly-boundary",x:d.toString(),y:h.toString(),width:l.toString(),height:u.toString()}}}var wyn="rgb(26, 115, 143)",Syn="rgba(0,0,0,0.9)";function Eyn(t,e){const{transform:n,soup:i}=e,{width:r,height:o,center:s,outline:a}=t;let c;if(a&&Array.isArray(a)&&a.length>=3)c=a.map((u,d)=>{const[h,f]=Yt(n,[u.x,u.y]);return d===0?`M ${h} ${f}`:`L ${h} ${f}`}).join(" ");else{const u=r/2,d=o/2,h=Yt(n,[s.x-u,s.y-d]),f=Yt(n,[s.x+u,s.y-d]),m=Yt(n,[s.x+u,s.y+d]),y=Yt(n,[s.x-u,s.y+d]);c=`M ${h[0]} ${h[1]} L ${f[0]} ${f[1]} L ${m[0]} ${m[1]} L ${y[0]} ${y[1]}`}c+=" Z";const l=ea(i).pcb_cutout.list();for(const u of l)if(u.shape==="rect"){const{x:d,y:h,width:f,height:m}=u.center?(()=>{const{x:N,y:R}=u.center,{width:P,height:M}=u;return{x:N,y:R,width:P,height:M}})():{x:0,y:0,width:0,height:0},y=f/2,g=m/2,[b,v,w,T]=[Yt(n,[d-y,h-g]),Yt(n,[d+y,h-g]),Yt(n,[d+y,h+g]),Yt(n,[d-y,h+g])];c+=` M ${b[0]} ${b[1]} L ${v[0]} ${v[1]} L ${w[0]} ${w[1]} L ${T[0]} ${T[1]} Z`}else u.shape;return[{name:"path",type:"element",value:"",children:[],attributes:{class:"pinout-board",d:c,fill:wyn,stroke:Syn,"fill-rule":"evenodd","stroke-opacity":"0.8","stroke-width":(.2*Math.abs(n.a)).toString()}}]}var Tyn="rgba(120, 120, 120, 0.6)",Myn="rgba(255, 255, 255, 0.9)";function Ayn(t,e){const{transform:n,soup:i}=e,{center:r,width:o,height:s,rotation:a=0,source_component_id:c}=t,l=ea(i).source_component.get(c);if(!r||typeof o!="number"||typeof s!="number"||o===0||s===0)return[];const[u,d]=Yt(n,[r.x,r.y]),h=o*Math.abs(n.a),f=s*Math.abs(n.d),m=`translate(${u}, ${d}) rotate(${-a})`,y=[{name:"rect",type:"element",attributes:{class:"pinout-component-box",x:(-h/2).toString(),y:(-f/2).toString(),width:h.toString(),height:f.toString(),fill:Tyn},value:"",children:[]}];if(l?.name){const g=f>h*1.5,b=Math.min(h,f)*.4;y.push({name:"text",type:"element",attributes:{x:"0",y:"0",fill:Myn,"font-size":`${b}px`,"font-family":"sans-serif","text-anchor":"middle","dominant-baseline":"middle",transform:g?"rotate(90)":""},children:[{type:"text",value:l.name,name:"",attributes:{},children:[]}],value:""})}return[{name:"g",type:"element",attributes:{transform:m},children:y,value:""}]}var Hme="rgb(50, 50, 50)";function Cyn(t,e){const{transform:n}=e,[i,r]=Yt(n,[t.x,t.y]);if(t.hole_shape==="circle"||t.hole_shape==="square"){const o=t.hole_diameter*Math.abs(n.a),s=o/2;return t.hole_shape==="circle"?[{name:"circle",type:"element",attributes:{class:"pinout-hole",cx:i.toString(),cy:r.toString(),r:s.toString(),fill:Hme},children:[],value:""}]:[{name:"rect",type:"element",attributes:{class:"pinout-hole",x:(i-s).toString(),y:(r-s).toString(),width:o.toString(),height:o.toString(),fill:Hme},children:[],value:""}]}if(t.hole_shape==="oval"){const o=t.hole_width*Math.abs(n.a),s=t.hole_height*Math.abs(n.a),a=o/2,c=s/2;return[{name:"ellipse",type:"element",attributes:{class:"pinout-hole",cx:i.toString(),cy:r.toString(),rx:a.toString(),ry:c.toString(),fill:Hme},children:[],value:""}]}return[]}var tN="rgb(218, 165, 32)",nN="rgb(40, 40, 40)";function Ryn(t,e){const{transform:n}=e,[i,r]=Yt(n,[t.x,t.y]);if(t.shape==="pill"){const o=t.outer_width*Math.abs(n.a),s=t.outer_height*Math.abs(n.a),a=t.hole_width*Math.abs(n.a),c=t.hole_height*Math.abs(n.a),l=o/2,u=s-o,d=a/2;return[{name:"g",type:"element",children:[{name:"path",type:"element",attributes:{class:"pinout-hole-outer",fill:tN,d:`M${i-l},${r-u/2} v${u} a${l},${l} 0 0 0 ${o},0 v-${u} a${l},${l} 0 0 0 -${o},0 z`},value:"",children:[]},{name:"path",type:"element",attributes:{class:"pinout-hole-inner",fill:nN,d:`M${i-d},${r-(c-a)/2} v${c-a} a${d},${d} 0 0 0 ${a},0 v-${c-a} a${d},${d} 0 0 0 -${a},0 z`},value:"",children:[]}],value:"",attributes:{}}]}if(t.shape==="circle"){const o=t.outer_diameter*Math.abs(n.a),s=t.outer_diameter*Math.abs(n.a),a=t.hole_diameter*Math.abs(n.a),c=t.hole_diameter*Math.abs(n.a),l=Math.min(o,s)/2,u=Math.min(a,c)/2;return[{name:"g",type:"element",children:[{name:"circle",type:"element",attributes:{class:"pinout-hole-outer",fill:tN,cx:i.toString(),cy:r.toString(),r:l.toString()},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"pinout-hole-inner",fill:nN,cx:i.toString(),cy:r.toString(),r:u.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(t.shape==="circular_hole_with_rect_pad"){const o=t.hole_diameter*Math.abs(n.a),s=t.rect_pad_width*Math.abs(n.a),a=t.rect_pad_height*Math.abs(n.a),c=o/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"pinout-hole-outer-pad",fill:tN,x:(i-s/2).toString(),y:(r-a/2).toString(),width:s.toString(),height:a.toString()},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"pinout-hole-inner",fill:nN,cx:i.toString(),cy:r.toString(),r:c.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(t.shape==="pill_hole_with_rect_pad"){const o=t.rect_pad_width*Math.abs(n.a),s=t.rect_pad_height*Math.abs(n.a),a=t.hole_height*Math.abs(n.a),c=t.hole_width*Math.abs(n.a),l=Math.min(a,c)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"pinout-hole-outer-pad",fill:tN,x:(i-o/2).toString(),y:(r-s/2).toString(),width:o.toString(),height:s.toString()},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"pinout-hole-inner",fill:nN,x:(i-c/2).toString(),y:(r-a/2).toString(),width:c.toString(),height:a.toString(),rx:l.toString(),ry:l.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(t.shape==="rotated_pill_hole_with_rect_pad"){const o=t.rect_pad_width*Math.abs(n.a),s=t.rect_pad_height*Math.abs(n.a),a=t.hole_height*Math.abs(n.a),c=t.hole_width*Math.abs(n.a),l=Math.min(a,c)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"pinout-hole-outer-pad",fill:tN,x:(-o/2).toString(),y:(-s/2).toString(),width:o.toString(),height:s.toString(),transform:`translate(${i} ${r}) rotate(${-t.rect_ccw_rotation})`},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"pinout-hole-inner",fill:nN,x:(-c/2).toString(),y:(-a/2).toString(),width:c.toString(),height:a.toString(),rx:l.toString(),ry:l.toString(),transform:`translate(${i} ${r}) rotate(${-t.hole_ccw_rotation})`},value:"",children:[]}],value:"",attributes:{}}]}return[]}var iN="rgb(218, 165, 32)";function Pyn(t,e){const{transform:n}=e;if(t.shape==="rect"||t.shape==="rotated_rect"){const i=t.width*Math.abs(n.a),r=t.height*Math.abs(n.d),[o,s]=Yt(n,[t.x,t.y]);return t.shape==="rotated_rect"&&t.ccw_rotation?[{name:"rect",type:"element",attributes:{class:"pinout-pad",fill:iN,x:(-i/2).toString(),y:(-r/2).toString(),width:i.toString(),height:r.toString(),transform:`translate(${o} ${s}) rotate(${-t.ccw_rotation})`,"data-layer":t.layer},value:"",children:[]}]:[{name:"rect",type:"element",attributes:{class:"pinout-pad",fill:iN,x:(o-i/2).toString(),y:(s-r/2).toString(),width:i.toString(),height:r.toString(),"data-layer":t.layer},value:"",children:[]}]}if(t.shape==="pill"){const i=t.width*Math.abs(n.a),r=t.height*Math.abs(n.d),o=t.radius*Math.abs(n.a),[s,a]=Yt(n,[t.x,t.y]);return[{name:"rect",type:"element",attributes:{class:"pinout-pad",fill:iN,x:(s-i/2).toString(),y:(a-r/2).toString(),width:i.toString(),height:r.toString(),rx:o.toString(),ry:o.toString(),"data-layer":t.layer},value:"",children:[]}]}if(t.shape==="circle"){const i=t.radius*Math.abs(n.a),[r,o]=Yt(n,[t.x,t.y]);return[{name:"circle",type:"element",attributes:{class:"pinout-pad",fill:iN,cx:r.toString(),cy:o.toString(),r:i.toString(),"data-layer":t.layer},value:"",children:[]}]}if(t.shape==="polygon"){const i=(t.points??[]).map(r=>Yt(n,[r.x,r.y]));return[{name:"polygon",type:"element",attributes:{class:"pinout-pad",fill:iN,points:i.map(r=>r.join(",")).join(" "),"data-layer":t.layer},value:"",children:[]}]}return[]}var Iyn="rgb(255, 255, 255)",Nyn="rgb(0, 0, 0)",kyn="rgba(0, 0, 0, 0.6)";function Oyn(t,e){const n=e.label_positions.get(t.pcb_port_id);if(!n)return[];const{text:i,aliases:r,elbow_end:o,label_pos:s,edge:a}=n,[c,l]=Yt(e.transform,[t.x,t.y]),u=a==="left"?"x-":a==="right"?"x+":a==="top"?"y-":"y+",d=a==="left"?"x+":a==="right"?"x-":a==="top"?"y+":"y-",f=[...lU({x:c,y:l,facingDirection:u},{x:o.x,y:o.y,facingDirection:d},{}),s].map(P=>`${P.x},${P.y}`).join(" "),m=[i,...r].join(" | "),y=11,g=m.length*y*.6,b=5,v=y+2*b,w=g+2*b,T=s.y;let N,R;return a==="left"?(N=s.x-w,R=s.x-w/2):a==="right"?(N=s.x,R=s.x+w/2):(N=s.x-w/2,R=s.x),[{name:"polyline",type:"element",attributes:{points:f,stroke:kyn,"stroke-width":"1.5",fill:"none"},children:[],value:""},{name:"rect",type:"element",attributes:{x:N.toString(),y:(T-v/2).toString(),width:w.toString(),height:v.toString(),fill:Nyn,rx:"8",ry:"8",stroke:"none"},children:[],value:""},{name:"text",type:"element",attributes:{x:R.toString(),y:T.toString(),fill:Iyn,"font-size":`${y}px`,"font-family":"Arial, sans-serif","font-weight":"bold","text-anchor":"middle","dominant-baseline":"middle"},children:[{type:"text",value:m,name:"",attributes:{},children:[]}],value:""}]}function DZe(t,e){const n=ea(e).source_port.get(t.source_port_id);if(!n)return null;const i=n.port_hints?.filter(s=>!/^\d+$/.test(s)&&!["left","right","top","bottom"].includes(s))??[];let r=i[0];if(r||(r=n.name),!r)return null;const o=i.filter(s=>s!==r);return{text:r,aliases:o}}function Lyn(t,e){const n={left:t.x-e.minX,right:e.maxX-t.x,top:e.maxY-t.y,bottom:t.y-e.minY};let i="left",r=n.left;return n.right<r&&(r=n.right,i="right"),n.top<r&&(r=n.top,i="top"),n.bottom<r&&(r=n.bottom,i="bottom"),i}var zZe=20,FZe=2,$j=15,BZe=10,UZe=11,$Ze=5,Vme=UZe+2*$Ze,jj=5;function jZe(t,e,{transform:n,soup:i,board_bounds:r,svgHeight:o},s){const a=e.map(g=>({port:g,y:Yt(n,[g.x,g.y])[1],label_info:DZe(g,i)})).filter(g=>g.label_info).sort((g,b)=>g.y-b.y);if(a.length===0)return;const c=Yt(n,[t==="left"?r.minX:r.maxX,0])[0],l=a.length,u=(l-1)/2,d=zZe+l*FZe,f=d+u*$j+BZe,m=l*Vme+Math.max(0,l-1)*jj;let y=(o-m)/2+Vme/2;a.forEach(({port:g,label_info:b},v)=>{const w=Math.abs(v-u),T=u-w,N=d+T*$j,R=t==="left"?-1:1,P={x:c+R*N,y},M={x:c+R*f,y};s.set(g.pcb_port_id,{text:b.text,aliases:b.aliases,elbow_end:P,label_pos:M,edge:t}),y+=Vme+jj})}function HZe(t,e,{transform:n,soup:i,board_bounds:r,svgWidth:o},s){const a=e.map(b=>({port:b,x:Yt(n,[b.x,b.y])[0],label_info:DZe(b,i)})).filter(b=>b.label_info).sort((b,v)=>b.x-v.x);if(a.length===0)return;const c=Yt(n,[0,t==="top"?r.maxY:r.minY])[1],l=a.map(b=>{const T=[b.label_info.text,...b.label_info.aliases].join(" | ").length*UZe*.6+2*$Ze;return{...b,rectWidth:T}}),u=l.length,d=(u-1)/2,h=zZe+u*FZe,m=h+d*$j+BZe,y=l.reduce((b,v)=>b+v.rectWidth,0)+Math.max(0,u-1)*jj;let g=(o-y)/2;l.forEach(({port:b,label_info:v,rectWidth:w},T)=>{const N=Math.abs(T-d),R=d-N,P=h+R*$j,M=t==="top"?-1:1,I=g+w/2,A={x:I,y:c+M*P},$={x:I,y:c+M*m};s.set(b.pcb_port_id,{text:v.text,aliases:v.aliases,elbow_end:A,label_pos:$,edge:t}),g+=w+jj})}var Dyn=({ports_by_edge:t,transform:e,soup:n,board_bounds:i,svgWidth:r,svgHeight:o})=>{const s=new Map,a={transform:e,soup:n,board_bounds:i};return jZe("left",t.left,{...a,svgHeight:o},s),jZe("right",t.right,{...a,svgHeight:o},s),HZe("top",t.top,{...a,svgWidth:r},s),HZe("bottom",t.bottom,{...a,svgWidth:r},s),s},VZe=["pcb_board","pcb_smtpad","pcb_hole","pcb_plated_hole","pcb_component","pcb_port"];function GZe(t,e){let n=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY;for(const A of t)if(A.type==="pcb_board")if("outline"in A&&A.outline&&Array.isArray(A.outline)&&A.outline.length>0)for(const $ of A.outline)n=Math.min(n,$.x),i=Math.min(i,$.y),r=Math.max(r,$.x),o=Math.max(o,$.y);else{const $=A.center,k=A.width||0,V=A.height||0;n=Math.min(n,$.x-k/2),i=Math.min(i,$.y-V/2),r=Math.max(r,$.x+k/2),o=Math.max(o,$.y+V/2)}const s=20,a=r-n+2*s,c=o-i+2*s,l=e?.width??800,u=e?.height??600,d=l/a,h=u/c,f=Math.min(d,h),m=(l-a*f)/2,y=(u-c*f)/2,g=cs(Cs(m-n*f+s*f,u-y+i*f-s*f),kg(f,-f)),b={minX:n,minY:i,maxX:r,maxY:o},v=t.filter(A=>A.type==="pcb_port"&&A.is_board_pinout),w={left:[],right:[],top:[],bottom:[]};for(const A of v){const $=Lyn({x:A.x,y:A.y},b);w[$].push(A)}const T=Dyn({ports_by_edge:w,transform:g,soup:t,board_bounds:b,svgWidth:l,svgHeight:u}),N={transform:g,soup:t,label_positions:T},R=t.sort((A,$)=>(VZe.indexOf(A.type)??9999)-(VZe.indexOf($.type)??9999)).flatMap(A=>zyn(A,N)),P=oC(t),M=sC,I={name:"svg",type:"element",attributes:{xmlns:"http://www.w3.org/2000/svg",width:l.toString(),height:u.toString(),...P&&{"data-software-used-string":P},...e?.includeVersion&&{"data-circuit-to-svg-version":M}},value:"",children:[{name:"rect",type:"element",attributes:{fill:"rgb(255, 255, 255)",x:"0",y:"0",width:l.toString(),height:u.toString()},value:"",children:[]},...R].filter(A=>A!==null)};return FP(I)}function zyn(t,e,n){switch(t.type){case"pcb_board":return Eyn(t,e);case"pcb_component":return Ayn(t,e);case"pcb_smtpad":return Pyn(t,e);case"pcb_hole":return Cyn(t,e);case"pcb_plated_hole":return Ryn(t,e);case"pcb_port":return t.is_board_pinout?Oyn(t,e):[];default:return[]}}var Fw={"3d_viewer":{background_bottom:"rgb(102, 102, 128)",background_top:"rgb(204, 204, 230)",board:"rgb(51, 43, 23)",copper:"rgb(179, 156, 0)",silkscreen_bottom:"rgb(230, 230, 230)",silkscreen_top:"rgb(230, 230, 230)",soldermask:"rgb(20, 51, 36)",solderpaste:"rgb(128, 128, 128)"},board:{anchor:"rgb(255, 38, 226)",aux_items:"rgb(255, 255, 255)",b_adhes:"rgb(0, 0, 132)",b_crtyd:"rgb(255, 38, 226)",b_fab:"rgb(88, 93, 132)",b_mask:"rgba(2, 255, 238, 0.400)",b_paste:"rgb(0, 194, 194)",b_silks:"rgb(232, 178, 167)",background:"rgb(0, 16, 35)",cmts_user:"rgb(89, 148, 220)",copper:{b:"rgb(77, 127, 196)",f:"rgb(200, 52, 52)",in1:"rgb(127, 200, 127)",in10:"rgb(237, 124, 51)",in11:"rgb(91, 195, 235)",in12:"rgb(247, 111, 142)",in13:"rgb(167, 165, 198)",in14:"rgb(40, 204, 217)",in15:"rgb(232, 178, 167)",in16:"rgb(242, 237, 161)",in17:"rgb(237, 124, 51)",in18:"rgb(91, 195, 235)",in19:"rgb(247, 111, 142)",in2:"rgb(206, 125, 44)",in20:"rgb(167, 165, 198)",in21:"rgb(40, 204, 217)",in22:"rgb(232, 178, 167)",in23:"rgb(242, 237, 161)",in24:"rgb(237, 124, 51)",in25:"rgb(91, 195, 235)",in26:"rgb(247, 111, 142)",in27:"rgb(167, 165, 198)",in28:"rgb(40, 204, 217)",in29:"rgb(232, 178, 167)",in3:"rgb(79, 203, 203)",in30:"rgb(242, 237, 161)",in4:"rgb(219, 98, 139)",in5:"rgb(167, 165, 198)",in6:"rgb(40, 204, 217)",in7:"rgb(232, 178, 167)",in8:"rgb(242, 237, 161)",in9:"rgb(141, 203, 129)"},cursor:"rgb(255, 255, 255)",drc:"rgb(194, 194, 194)",drc_error:"rgba(215, 91, 107, 0.800)",drc_exclusion:"rgb(255, 255, 255)",drc_warning:"rgba(255, 208, 66, 0.902)",dwgs_user:"rgb(194, 194, 194)",eco1_user:"rgb(180, 219, 210)",eco2_user:"rgb(216, 200, 82)",edge_cuts:"rgb(208, 210, 205)",f_adhes:"rgb(132, 0, 132)",f_crtyd:"rgb(255, 0, 245)",f_fab:"rgb(175, 175, 175)",f_mask:"rgba(216, 100, 255, 0.400)",f_paste:"rgba(180, 160, 154, 0.902)",f_silks:"rgb(242, 237, 161)",footprint_text_back:"rgb(0, 0, 132)",footprint_text_front:"rgb(194, 194, 194)",footprint_text_invisible:"rgb(132, 132, 132)",grid:"rgb(132, 132, 132)",grid_axes:"rgb(194, 194, 194)",margin:"rgb(255, 38, 226)",microvia:"rgb(0, 132, 132)",no_connect:"rgb(0, 0, 132)",pad_back:"rgb(77, 127, 196)",pad_front:"rgb(200, 52, 52)",pad_plated_hole:"rgb(194, 194, 0)",pad_through_hole:"rgb(227, 183, 46)",plated_hole:"rgb(26, 196, 210)",ratsnest:"rgba(245, 255, 213, 0.702)",select_overlay:"rgb(4, 255, 67)",through_via:"rgb(236, 236, 236)",user_1:"rgb(194, 194, 194)",user_2:"rgb(89, 148, 220)",user_3:"rgb(180, 219, 210)",user_4:"rgb(216, 200, 82)",user_5:"rgb(194, 194, 194)",user_6:"rgb(89, 148, 220)",user_7:"rgb(180, 219, 210)",user_8:"rgb(216, 200, 82)",user_9:"rgb(232, 178, 167)",via_blind_buried:"rgb(187, 151, 38)",via_hole:"rgb(227, 183, 46)",via_micro:"rgb(0, 132, 132)",via_through:"rgb(236, 236, 236)",worksheet:"rgb(200, 114, 171)"},gerbview:{axes:"rgb(0, 0, 132)",background:"rgb(0, 0, 0)",dcodes:"rgb(255, 255, 255)",grid:"rgb(132, 132, 132)",layers:["rgb(132, 0, 0)","rgb(194, 194, 0)","rgb(194, 0, 194)","rgb(194, 0, 0)","rgb(0, 132, 132)","rgb(0, 132, 0)","rgb(0, 0, 132)","rgb(132, 132, 132)","rgb(132, 0, 132)","rgb(194, 194, 194)","rgb(132, 0, 132)","rgb(132, 0, 0)","rgb(132, 132, 0)","rgb(194, 194, 194)","rgb(0, 0, 132)","rgb(0, 132, 0)","rgb(132, 0, 0)","rgb(194, 194, 0)","rgb(194, 0, 194)","rgb(194, 0, 0)","rgb(0, 132, 132)","rgb(0, 132, 0)","rgb(0, 0, 132)","rgb(132, 132, 132)","rgb(132, 0, 132)","rgb(194, 194, 194)","rgb(132, 0, 132)","rgb(132, 0, 0)","rgb(132, 132, 0)","rgb(194, 194, 194)","rgb(0, 0, 132)","rgb(0, 132, 0)","rgb(132, 0, 0)","rgb(194, 194, 0)","rgb(194, 0, 194)","rgb(194, 0, 0)","rgb(0, 132, 132)","rgb(0, 132, 0)","rgb(0, 0, 132)","rgb(132, 132, 132)","rgb(132, 0, 132)","rgb(194, 194, 194)","rgb(132, 0, 132)","rgb(132, 0, 0)","rgb(132, 132, 0)","rgb(194, 194, 194)","rgb(0, 0, 132)","rgb(0, 132, 0)","rgb(132, 0, 0)","rgb(194, 194, 0)","rgb(194, 0, 194)","rgb(194, 0, 0)","rgb(0, 132, 132)","rgb(0, 132, 0)","rgb(0, 0, 132)","rgb(132, 132, 132)","rgb(132, 0, 132)","rgb(194, 194, 194)","rgb(132, 0, 132)","rgb(132, 0, 0)"],negative_objects:"rgb(132, 132, 132)",worksheet:"rgb(0, 0, 132)"},meta:{filename:"kicad_2020",name:"KiCad 2020",version:2},palette:["rgb(132, 0, 0)","rgb(194, 194, 0)","rgb(194, 0, 194)","rgb(194, 0, 0)","rgb(0, 132, 132)","rgb(0, 132, 0)","rgb(0, 0, 132)","rgb(132, 132, 132)","rgb(132, 0, 132)","rgb(194, 194, 194)","rgb(132, 0, 132)","rgb(132, 0, 0)","rgb(132, 132, 0)","rgb(194, 194, 194)","rgb(0, 0, 132)","rgb(0, 132, 0)"],schematic:{aux_items:"rgb(46, 46, 46)",background:"rgb(245, 241, 237)",brightened:"rgb(255, 0, 255)",bus:"rgb(0, 0, 132)",bus_junction:"rgb(0, 0, 132)",component_body:"rgb(255, 255, 194)",component_outline:"rgb(132, 0, 0)",cursor:"rgb(15, 15, 15)",erc_error:"rgba(230, 9, 13, 0.800)",erc_warning:"rgba(209, 146, 0, 0.800)",fields:"rgb(132, 0, 132)",grid:"rgb(181, 181, 181)",grid_axes:"rgb(0, 0, 132)",hidden:"rgb(194, 194, 194)",junction:"rgb(0, 150, 0)",label_global:"rgb(132, 0, 0)",label_background:"rgba(255, 255, 255, 0.6)",label_hier:"rgb(114, 86, 0)",label_local:"rgb(15, 15, 15)",net_name:"rgb(132, 132, 132)",no_connect:"rgb(0, 0, 132)",note:"rgb(0, 0, 194)",override_item_colors:!1,pin:"rgb(132, 0, 0)",pin_name:"rgb(0, 100, 100)",pin_number:"rgb(169, 0, 0)",reference:"rgb(0, 100, 100)",shadow:"rgba(102, 179, 255, 0.800)",sheet:"rgb(132, 0, 0)",sheet_background:"rgba(253, 255, 231, 0.000)",sheet_fields:"rgb(132, 0, 132)",sheet_filename:"rgb(114, 86, 0)",sheet_label:"rgb(0, 100, 100)",sheet_name:"rgb(0, 100, 100)",table:"rgb(102, 102, 102)",value:"rgb(0, 100, 100)",wire:"rgb(0, 150, 0)",wire_crossing:"rgb(30, 180, 30)",worksheet:"rgb(132, 0, 0)"}};function Fyn(t){const{minX:e,minY:n,maxX:i,maxY:r}=t.bounds,o=t.cellSize??1,s=t.labelCells??!1,a=[],c=(l,u)=>{const[d,h]=Yt(t.transform,[l,u]);return{x:d,y:h}};for(let l=Math.floor(e);l<=Math.ceil(i);l+=o){const u=c(l,n),d=c(l,r);a.push({name:"line",type:"element",attributes:{x1:u.x.toString(),y1:u.y.toString(),x2:d.x.toString(),y2:d.y.toString(),stroke:Fw.schematic.grid,"stroke-width":(.01*Math.abs(t.transform.a)).toString(),"stroke-opacity":"0.5"}})}for(let l=Math.floor(n);l<=Math.ceil(r);l+=o){const u=c(e,l),d=c(i,l);a.push({name:"line",type:"element",attributes:{x1:u.x.toString(),y1:u.y.toString(),x2:d.x.toString(),y2:d.y.toString(),stroke:Fw.schematic.grid,"stroke-width":(.01*Math.abs(t.transform.a)).toString(),"stroke-opacity":"0.5"}})}if(s){const l=(u,d)=>o<=.1?`${u.toFixed(1)},${d.toFixed(1)}`:`${u},${d}`;for(let u=Math.floor(e);u<=Math.ceil(i);u+=o)for(let d=Math.floor(n);d<=Math.ceil(r);d+=o){const h=c(u,d);a.push({name:"text",type:"element",attributes:{x:(h.x-2.5).toString(),y:(h.y-5).toString(),fill:Fw.schematic.grid,"font-size":(o/5*Math.abs(t.transform.a)).toString(),"fill-opacity":"0.5","text-anchor":"middle","dominant-baseline":"middle","font-family":"sans-serif"},children:[{type:"text",value:l(u,d),name:"",attributes:{},children:[]}]})}}return{name:"g",value:"",type:"element",attributes:{class:"grid"},children:a}}function Byn(t){const{points:e,transform:n}=t,i=[];for(const r of e){const[o,s]=Yt(n,[r.x-.1,r.y-.1]),[a,c]=Yt(n,[r.x+.1,r.y+.1]),[l,u]=Yt(n,[r.x-.1,r.y+.1]),[d,h]=Yt(n,[r.x+.1,r.y-.1]);i.push({name:"path",type:"element",attributes:{d:`M${o},${s} L${a},${c} M${l},${u} L${d},${h}`,stroke:Fw.schematic.grid,"stroke-width":(.02*Math.abs(n.a)).toString(),"stroke-opacity":"0.7"}});const[f,m]=Yt(n,[r.x+.15,r.y-.15]);i.push({name:"text",type:"element",attributes:{x:f.toString(),y:m.toString(),fill:Fw.schematic.grid,"font-size":(.1*Math.abs(n.a)).toString(),"fill-opacity":"0.7","text-anchor":"start","font-family":"sans-serif","dominant-baseline":"middle"},children:[{type:"text",value:r.label||`(${r.x},${r.y})`,name:"",attributes:{},children:[]}]})}return{name:"g",value:"",type:"element",attributes:{class:"labeled-points"},children:i}}var YZe={0:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},1:{width:13,height:27,ascent:22,descent:5,left:-3,right:9},2:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},3:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},4:{width:13,height:27,ascent:22,descent:5,left:0,right:12},5:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},6:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},7:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},8:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},9:{width:13,height:27,ascent:22,descent:5,left:-1,right:12}," ":{width:7,height:27,ascent:22,descent:5,left:0,right:0},"!":{width:7,height:27,ascent:22,descent:5,left:-2,right:5},'"':{width:9,height:27,ascent:22,descent:5,left:-1,right:7},"#":{width:13,height:27,ascent:22,descent:5,left:0,right:13},$:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},"%":{width:21,height:27,ascent:22,descent:5,left:-1,right:20},"&":{width:16,height:27,ascent:22,descent:5,left:-1,right:15},"'":{width:5,height:27,ascent:22,descent:5,left:-1,right:3},"(":{width:8,height:27,ascent:22,descent:5,left:-1,right:7},")":{width:8,height:27,ascent:22,descent:5,left:-1,right:7},"*":{width:9,height:27,ascent:22,descent:5,left:-1,right:8},"+":{width:14,height:27,ascent:22,descent:5,left:-1,right:13},",":{width:7,height:27,ascent:22,descent:5,left:-2,right:5},"-":{width:8,height:27,ascent:22,descent:5,left:-1,right:7},".":{width:7,height:27,ascent:22,descent:5,left:-2,right:5},"/":{width:7,height:27,ascent:22,descent:5,left:0,right:7},":":{width:7,height:27,ascent:22,descent:5,left:-2,right:5},";":{width:7,height:27,ascent:22,descent:5,left:-2,right:5},"<":{width:14,height:27,ascent:22,descent:5,left:-1,right:13},"=":{width:14,height:27,ascent:22,descent:5,left:-1,right:13},">":{width:14,height:27,ascent:22,descent:5,left:-1,right:13},"?":{width:13,height:27,ascent:22,descent:5,left:-1,right:12},"@":{width:24,height:27,ascent:22,descent:5,left:-1,right:23},A:{width:16,height:27,ascent:22,descent:5,left:0,right:16},B:{width:16,height:27,ascent:22,descent:5,left:-2,right:15},C:{width:17,height:27,ascent:22,descent:5,left:-1,right:16},D:{width:17,height:27,ascent:22,descent:5,left:-2,right:16},E:{width:16,height:27,ascent:22,descent:5,left:-2,right:15},F:{width:15,height:27,ascent:22,descent:5,left:-2,right:14},G:{width:19,height:27,ascent:22,descent:5,left:-1,right:17},H:{width:17,height:27,ascent:22,descent:5,left:-2,right:15},I:{width:7,height:27,ascent:22,descent:5,left:-2,right:5},J:{width:12,height:27,ascent:22,descent:5,left:-1,right:10},K:{width:16,height:27,ascent:22,descent:5,left:-2,right:16},L:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},M:{width:20,height:27,ascent:22,descent:5,left:-2,right:18},N:{width:17,height:27,ascent:22,descent:5,left:-2,right:15},O:{width:19,height:27,ascent:22,descent:5,left:-1,right:18},P:{width:16,height:27,ascent:22,descent:5,left:-2,right:15},Q:{width:19,height:27,ascent:22,descent:5,left:-1,right:18},R:{width:17,height:27,ascent:22,descent:5,left:-2,right:17},S:{width:16,height:27,ascent:22,descent:5,left:-1,right:15},T:{width:15,height:27,ascent:22,descent:5,left:-1,right:14},U:{width:17,height:27,ascent:22,descent:5,left:-2,right:15},V:{width:16,height:27,ascent:22,descent:5,left:0,right:16},W:{width:23,height:27,ascent:22,descent:5,left:0,right:22},X:{width:16,height:27,ascent:22,descent:5,left:0,right:16},Y:{width:16,height:27,ascent:22,descent:5,left:0,right:16},Z:{width:15,height:27,ascent:22,descent:5,left:0,right:14},"[":{width:7,height:27,ascent:22,descent:5,left:-2,right:6},"\\":{width:7,height:27,ascent:22,descent:5,left:0,right:7},"]":{width:7,height:27,ascent:22,descent:5,left:0,right:5},"^":{width:11,height:27,ascent:22,descent:5,left:-1,right:11},_:{width:13,height:27,ascent:22,descent:5,left:0,right:14},"`":{width:8,height:27,ascent:22,descent:5,left:-1,right:5},a:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},b:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},c:{width:12,height:27,ascent:22,descent:5,left:-1,right:12},d:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},e:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},f:{width:7,height:27,ascent:22,descent:5,left:0,right:8},g:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},h:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},i:{width:5,height:27,ascent:22,descent:5,left:-2,right:4},j:{width:5,height:27,ascent:22,descent:5,left:1,right:4},k:{width:12,height:27,ascent:22,descent:5,left:-2,right:12},l:{width:5,height:27,ascent:22,descent:5,left:-2,right:4},m:{width:20,height:27,ascent:22,descent:5,left:-2,right:18},n:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},o:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},p:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},q:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},r:{width:8,height:27,ascent:22,descent:5,left:-2,right:8},s:{width:12,height:27,ascent:22,descent:5,left:-1,right:11},t:{width:7,height:27,ascent:22,descent:5,left:0,right:6},u:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},v:{width:12,height:27,ascent:22,descent:5,left:0,right:12},w:{width:17,height:27,ascent:22,descent:5,left:0,right:17},x:{width:12,height:27,ascent:22,descent:5,left:0,right:12},y:{width:12,height:27,ascent:22,descent:5,left:0,right:12},z:{width:12,height:27,ascent:22,descent:5,left:0,right:11},"{":{width:8,height:27,ascent:22,descent:5,left:-1,right:7},"|":{width:6,height:27,ascent:22,descent:5,left:-2,right:4},"}":{width:8,height:27,ascent:22,descent:5,left:-1,right:7},"~":{width:14,height:27,ascent:22,descent:5,left:-1,right:13}},Hj=t=>{if(!t)return 0;let e=0;for(const n of t){const i=YZe[n];i?e+=i.width:e+=YZe["?"].width}return e/27},qZe=(t,e)=>{if(t.column_widths&&t.column_widths.length>0&&t.row_heights&&t.row_heights.length>0){const u=d=>typeof d=="number"?d:d.endsWith("mm")?parseFloat(d):d.endsWith("in")?parseFloat(d)*25.4:parseFloat(d);return{column_widths:t.column_widths.map(u),row_heights:t.row_heights.map(u)}}const n=e.filter(u=>u.type==="schematic_table_cell"&&u.schematic_table_id===t.schematic_table_id);if(n.length===0)return{column_widths:[],row_heights:[]};const i=n.reduce((u,d)=>Math.max(u,d.end_column_index),-1)+1,r=n.reduce((u,d)=>Math.max(u,d.end_row_index),-1)+1,{cell_padding:o=.2}=t,s=new Array(i).fill(0),a=new Array(r).fill(0),c={},l={};for(const u of n){const d=aC("reference_designator",u.font_size),f=Hj(u.text??"")*d+2*o,m=d*1.2+2*o,y=`${u.start_row_index}-${u.start_column_index}`;c[y]=f,l[y]=m}for(let u=0;u<r;u++)for(let d=0;d<i;d++){const h=`${u}-${d}`;c[h]&&c[h]>s[d]&&(s[d]=c[h]),l[h]&&l[h]>a[u]&&(a[u]=l[h])}for(const u of n){if(u.start_column_index===u.end_column_index&&u.start_row_index===u.end_row_index)continue;const d=`${u.start_row_index}-${u.start_column_index}`,h=c[d],f=l[d];if(h===void 0||f===void 0)continue;let m=0;for(let g=u.start_column_index;g<=u.end_column_index;g++)m+=s[g];if(h>m){const b=(h-m)/(u.end_column_index-u.start_column_index+1);for(let v=u.start_column_index;v<=u.end_column_index;v++)s[v]+=b}let y=0;for(let g=u.start_row_index;g<=u.end_row_index;g++)y+=a[g];if(f>y){const b=(f-y)/(u.end_row_index-u.start_row_index+1);for(let v=u.start_row_index;v<=u.end_row_index;v++)a[v]+=b}}return{column_widths:s,row_heights:a}},cC=t=>{switch(t){case"top":return{x:0,y:-1};case"bottom":return{x:0,y:1};case"left":return{x:1,y:0};case"right":return{x:-1,y:0}}throw new Error(`Invalid side: ${t}`)},tE=.3,lC=.3,uC=.06,Uyn={top_left:"start",top_right:"end",middle_left:"start",middle_right:"end",bottom_left:"start",bottom_right:"end",center:"middle",middle_top:"middle",middle_bottom:"middle"},$yn={top_left:"hanging",top_right:"hanging",bottom_left:"ideographic",bottom_right:"ideographic",center:"middle",middle_left:"middle",middle_right:"middle",middle_top:"hanging",middle_bottom:"ideographic"};function jyn(t){return{left:180,top:90,bottom:-90,right:0}[t]??0}function Hyn(t,e,n){const i=n+tE*2+uC*t.text.length+lC,r=cC(t.anchor_side);return t.anchor_position??{x:t.center.x-r.x*i*e/2,y:t.center.y-r.y*i*e/2}}function Vyn(t,e=.5){let n=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY;const s=.2;for(const c of t)if(c.type==="schematic_component")a(c.center,c.size,0);else if(c.type==="schematic_port")a(c.center,{width:s,height:s},0);else if(c.type==="schematic_debug_object")c.shape==="rect"?a(c.center,c.size,0):c.shape==="line"&&(a(c.start,{width:.1,height:.1},0),a(c.end,{width:.1,height:.1},0));else if(c.type==="schematic_net_label"){const l=aC("net_label"),u=Hj(c.text||""),h=(u+tE*2+uC*(c.text?.length||0)+lC)*l,f=1.2*l,m=jyn(c.anchor_side)/180*Math.PI,y=Hyn(c,l,u),g=cC(c.anchor_side),b={x:y.x+g.x*h/2,y:y.y+g.y*h/2};a(b,{width:h,height:f},m)}else if(c.type==="schematic_trace")for(const l of c.edges)a(l.from,{width:.1,height:.1},0),a(l.to,{width:.1,height:.1},0);else if(c.type==="schematic_text"){const u=aC("reference_designator",c.font_size)??.18,h=(c.text??"").length*u,f=u;a(c.position,{width:h,height:f},c.rotation??0)}else if(c.type==="schematic_voltage_probe")a(c.position,{width:.2,height:.4},0);else if(c.type==="schematic_box")a({x:c.x+c.width/2,y:c.y+c.height/2},{width:c.width,height:c.height},0);else if(c.type==="schematic_table"){const{column_widths:l,row_heights:u}=qZe(c,t),d=l.reduce((v,w)=>v+w,0),h=u.reduce((v,w)=>v+w,0),f=c.anchor??"center";let m=c.anchor_position.x,y=c.anchor_position.y;f.includes("center")?m-=d/2:f.includes("right")&&(m-=d),f.includes("center")?y+=h/2:f.includes("bottom")&&(y+=h);const g=m+d/2,b=y-h/2;a({x:g,y:b},{width:d,height:h},0)}else c.type==="schematic_line"?(a({x:c.x1,y:c.y1},{width:.02,height:.02},0),a({x:c.x2,y:c.y2},{width:.02,height:.02},0)):c.type==="schematic_circle"?a(c.center,{width:c.radius*2,height:c.radius*2},0):c.type==="schematic_rect"?a(c.center,{width:c.width,height:c.height},c.rotation):c.type==="schematic_arc"&&a(c.center,{width:c.radius*2,height:c.radius*2},0);return n-=e,i-=e,r+=e,o+=e,{minX:n,minY:i,maxX:r,maxY:o};function a(c,l,u){const d=[{x:-l.width/2,y:-l.height/2},{x:l.width/2,y:-l.height/2},{x:l.width/2,y:l.height/2},{x:-l.width/2,y:l.height/2}];for(const h of d){const f=h.x*Math.cos(u)-h.y*Math.sin(u)+c.x,m=h.x*Math.sin(u)+h.y*Math.cos(u)+c.y;n=Math.min(n,f),i=Math.min(i,m),r=Math.max(r,f),o=Math.max(o,m)}}}var hb=t=>Math.abs(t.a)*.02,Gyn=(t,e)=>{const n=t<0?t+2*Math.PI:t,i=e<0?e+2*Math.PI:e;let r=Math.abs(n-i);return r>Math.PI&&(r=2*Math.PI-r),r},Yyn=({schPorts:t,symbol:e,schComponent:n})=>{const i=t.map(a=>{const c=a.center.x-n.center.x,l=a.center.y-n.center.y;return{port:a,angle:Math.atan2(l,c)}}),r=e.ports.map(a=>{const c=a.x-e.center.x,l=a.y-e.center.y;return{port:a,angle:Math.atan2(l,c)}});i.sort((a,c)=>a.angle-c.angle),r.sort((a,c)=>a.angle-c.angle);const o=[],s=new Set;for(const a of i){let c=null;for(const l of r){if(s.has(l.port))continue;const u=Gyn(a.angle,l.angle);(c===null||u<c.angleDiff)&&(c={symbolPort:l.port,angleDiff:u})}c&&c.angleDiff<Math.PI/4&&(o.push({schPort:a.port,symbolPort:c.symbolPort}),s.add(c.symbolPort))}return o};function qyn(t,e,n,i){const r=e.x-t.x,o=e.y-t.y,s=Math.sqrt((n.x-t.x)**2+(n.y-t.y)**2),c=Math.sqrt((i.x-e.x)**2+(i.y-e.y)**2)/s,l=Cs(r,o),u=kg(c,c);return cs(l,u)}var Gme=({text:t,realCenter:e,realToScreenTransform:n})=>{const i=Yt(n,e);return{type:"element",name:"text",value:"",attributes:{x:i.x.toString(),y:i.y.toString(),fill:"red","text-anchor":"middle","dominant-baseline":"middle","font-family":"sans-serif","font-size":`${l3(n,"error")}px`},children:[{type:"text",value:t,name:"",attributes:{},children:[]}]}},XZe=(t,e)=>{for(const n of t){if(n.type!=="source_trace")continue;const i=n;if(Array.isArray(i.connected_source_port_ids)&&i.connected_source_port_ids.includes(e))return!0}return!1},Xyn={top_left:"start",top_right:"end",middle_left:"start",middle_right:"end",bottom_left:"start",bottom_right:"end",center:"middle",middle_top:"middle",middle_bottom:"middle"},Wyn=({component:t,transform:e,circuitJson:n,colorMap:i})=>{const r=[],o=lv[t.symbol_name];if(!o)return[Gme({text:`Symbol not found: ${t.symbol_name}`,realCenter:t.center,realToScreenTransform:e})];const s=ea(n).schematic_port.list({schematic_component_id:t.schematic_component_id}),a=ea(n).source_component.get(t.source_component_id),c=Yyn({schPorts:s,symbol:o,schComponent:t});if(!c[0])return[Gme({text:`Could not match ports for symbol ${t.symbol_name}`,realCenter:t.center,realToScreenTransform:e})];const l=qyn(c[1]?.symbolPort??o.center,c[1]?.schPort.center??t.center,c[0].symbolPort,c[0].schPort.center),u=o.primitives.filter(M=>M.type==="path"),d=o.primitives.filter(M=>M.type==="text"),h=o.primitives.filter(M=>M.type==="circle"),f=o.primitives.filter(M=>M.type==="box"),m=new Set;for(const M of c)XZe(n,M.schPort.source_port_id)&&m.add(M.symbolPort);const y={minX:Math.min(...u.flatMap(M=>M.points.map(I=>I.x))),maxX:Math.max(...u.flatMap(M=>M.points.map(I=>I.x))),minY:Math.min(...u.flatMap(M=>M.points.map(I=>I.y))),maxY:Math.max(...u.flatMap(M=>M.points.map(I=>I.y)))},[g,b]=Yt(cs(e,l),[y.minX,y.minY]),[v,w]=Yt(cs(e,l),[y.maxX,y.maxY]),T=Math.abs(w-b),N=Math.min(b,w),R=Math.abs(v-g),P=Math.min(g,v);r.push({name:"rect",type:"element",value:"",attributes:{class:"component-overlay",x:P.toString(),y:N.toString(),width:R.toString(),height:T.toString(),fill:"transparent"},children:[]});for(const M of u){const{points:I,color:A,closed:$,fill:k}=M;r.push({type:"element",name:"path",attributes:{d:I.map((V,X)=>{const[W,K]=Yt(cs(e,l),[V.x,V.y]);return`${X===0?"M":"L"} ${W} ${K}`}).join(" ")+($?" Z":""),stroke:i.schematic.component_outline,fill:"none","stroke-width":`${hb(e)}px`,"stroke-linecap":"round"},value:"",children:[]})}for(const M of d){const I=Yt(cs(e,l),M);let A="";M.text==="{REF}"?A=a?.name??"":M.text==="{VAL}"&&(A=t.symbol_display_value??"");const V=Math.abs(y.maxY-y.minY)*.1,X=Math.abs(l.a);let W=0;M.anchor.includes("bottom")?W=V*X:M.anchor.includes("top")&&(W=-V*X);const K=M.anchor.includes("bottom")?"auto":M.anchor.includes("top")?"hanging":"middle",te=M.text==="{REF}";r.push({name:"text",type:"element",attributes:{x:I.x.toString(),y:(I.y+W).toString(),...te?{stroke:i.schematic.background,"stroke-width":`${hb(e)}px`,"paint-order":"stroke"}:{},fill:i.schematic.label_local,"font-family":"sans-serif","text-anchor":Xyn[M.anchor],"dominant-baseline":K,"font-size":`${l3(e,"reference_designator")}px`},value:"",children:[{type:"text",value:A,name:"",attributes:{},children:[]}]})}for(const M of f){const I=Yt(cs(e,l),M),A=cs(e,l).a;r.push({name:"rect",type:"element",attributes:{x:I.x.toString(),y:I.y.toString(),width:(M.width*A).toString(),height:(M.height*A).toString(),fill:"red"},value:"",children:[]})}for(const M of o.ports){if(m.has(M))continue;const I=Yt(cs(e,l),M);r.push({type:"element",name:"circle",attributes:{cx:I.x.toString(),cy:I.y.toString(),r:`${Math.abs(e.a)*.02}px`,"stroke-width":`${hb(e)}px`,fill:"none",stroke:i.schematic.component_outline},value:"",children:[]})}for(const M of h){const I=Yt(cs(e,l),M),A=Math.abs(M.radius*e.a);r.push({type:"element",name:"circle",attributes:{cx:I.x.toString(),cy:I.y.toString(),r:`${A}px`,"stroke-width":`${hb(e)}px`,fill:"none",stroke:i.schematic.component_outline},value:"",children:[]})}return r},rN=.02,WZe=(t,e,n,i,r)=>{const o=Math.PI/6,s={x:t.x-n*Math.cos(e-o),y:t.y-n*Math.sin(e-o)},a={x:t.x-n*Math.cos(e+o),y:t.y-n*Math.sin(e+o)};return{name:"polygon",type:"element",attributes:{points:`${t.x},${t.y} ${s.x},${s.y} ${a.x},${a.y}`,fill:"white",stroke:i,"stroke-width":`${r}px`},value:"",children:[]}},Zyn=({schPort:t,schComponent:e,transform:n,circuitJson:i})=>{const r=[];ea(i).source_port.get(t.source_port_id);const o={x:t.center.x,y:t.center.y},s=t.distance_from_component_edge??.4;switch(t.side_of_component){case"left":o.x+=s;break;case"right":o.x-=s;break;case"top":o.y-=s;break;case"bottom":o.y+=s;break}const a=Yt(n,t.center),c=Yt(n,o),l={...t.center};switch(t.side_of_component){case"left":l.x+=rN;break;case"right":l.x-=rN;break;case"top":l.y-=rN;break;case"bottom":l.y+=rN;break}const u=Yt(n,l);r.push({name:"line",type:"element",attributes:{class:"component-pin",x1:u.x.toString(),y1:u.y.toString(),x2:c.x.toString(),y2:c.y.toString(),"stroke-width":`${hb(n)}px`},value:"",children:[]});const d=XZe(i,t.source_port_id),h=Math.abs(n.a)*rN,f=[];d||f.push({name:"circle",type:"element",attributes:{class:"component-pin",cx:a.x.toString(),cy:a.y.toString(),r:h.toString(),"stroke-width":`${hb(n)}px`},value:"",children:[]}),f.push({name:"rect",type:"element",attributes:{x:(a.x-h).toString(),y:(a.y-h).toString(),width:(h*2).toString(),height:(h*2).toString(),opacity:"0"},value:"",children:[]}),r.push({name:"g",type:"element",value:"",attributes:{"data-schematic-port-id":t.source_port_id},children:f});const{has_input_arrow:m,has_output_arrow:y}=t;if((m||y)&&t.side_of_component){const g=Math.abs(n.a)*.1,b=Fw.schematic.component_outline,v=g*Math.cos(Math.PI/6),w=hb(n)/3;let T=0,N=0;t.side_of_component==="left"?(T=0,N=Math.PI):t.side_of_component==="right"?(T=Math.PI,N=0):t.side_of_component==="top"?(T=Math.PI/2,N=-Math.PI/2):t.side_of_component==="bottom"&&(T=-Math.PI/2,N=Math.PI/2);const R=m&&y;let P={...c},M={...c};if(R){const I=v;t.side_of_component==="left"?M.x-=I:t.side_of_component==="right"?M.x+=I:t.side_of_component==="top"?M.y-=I:t.side_of_component==="bottom"&&(M.y+=I)}if(m&&r.push(WZe(P,T,g,b,w)),y){const I={x:M.x+g*Math.cos(N),y:M.y+g*Math.sin(N)};r.push(WZe(I,N,g,b,w))}}return r},Kyn=t=>{const e=[],{schPort:n,transform:i}=t,r={x:n.center.x,y:n.center.y};if(!n.side_of_component)return[];const o=cC(n.side_of_component),s=n.distance_from_component_edge??.4;r.x+=o.x*s/2,r.y+=o.y*s/2,n.side_of_component==="top"||n.side_of_component==="bottom"?r.x-=.02:r.y+=.02;const a=Yt(i,r);return e.push({name:"text",type:"element",attributes:{class:"pin-number",x:a.x.toString(),y:a.y.toString(),style:"font-family: sans-serif;",fill:Fw.schematic.pin_number,"text-anchor":"middle","dominant-baseline":"auto","font-size":`${l3(i,"pin_number")}px`,transform:n.side_of_component==="top"||n.side_of_component==="bottom"?`rotate(-90 ${a.x} ${a.y})`:""},children:[{type:"text",value:n.pin_number?.toString()||"",name:"",attributes:{},children:[]}],value:""}),e},ZZe=.1,Qyn=t=>{const e=[],{schPort:n,schComponent:i,transform:r}=t,o={x:n.center.x,y:n.center.y};if(!n.side_of_component)return[];const s=cC(n.side_of_component),a=n.distance_from_component_edge??.4;o.x+=s.x*(a+ZZe),o.y+=s.y*(a+ZZe);const c=Yt(r,o),l=n.display_pin_label??i.port_labels?.[`${n.pin_number}`];if(!l)return[];const u=l.startsWith("N_"),d=u?l.slice(2):l;let h=l3(r,u?"negated_pin_number":"pin_number");return e.push({name:"text",type:"element",attributes:{class:"pin-number",x:c.x.toString(),y:c.y.toString(),style:`font-family: sans-serif;${u?" text-decoration: overline;":""}`,fill:Fw.schematic.pin_number,"text-anchor":n.side_of_component==="left"||n.side_of_component==="bottom"?"start":"end","dominant-baseline":"middle","font-size":`${h}px`,transform:n.side_of_component==="top"||n.side_of_component==="bottom"?`rotate(-90 ${c.x} ${c.y})`:""},children:[{type:"text",value:d||"",name:"",attributes:{},children:[]}],value:""}),e},Jyn=t=>{const e=[];return e.push(...Zyn(t)),e.push(...Kyn(t)),e.push(...Qyn(t)),e},KZe=({elm:t,transform:e,colorMap:n})=>{const i=Yt(e,t.position),r={center:"middle",center_right:"end",bottom_left:"start",bottom_center:"middle",bottom_right:"end",left:"start",right:"end",top:"middle",bottom:"middle",top_left:"start",top_center:"middle",top_right:"end",center_left:"start"},o={center:"middle",center_right:"middle",bottom_left:"ideographic",bottom_center:"ideographic",bottom_right:"ideographic",left:"middle",right:"middle",top:"hanging",bottom:"ideographic",top_left:"hanging",top_center:"hanging",top_right:"hanging",center_left:"middle"},s=t.text.split(`
5323
+ `,name:"",attributes:{},children:[]}],value:"",attributes:{}},{name:"rect",type:"element",attributes:{fill:"#fff",x:"0",y:"0",width:l.toString(),height:u.toString()},value:"",children:[]},vyn(g,n,i,r,o),...v].filter(R=>R!==null)};return FP(N)}function xyn(t,e,n){const i=ea(n).source_component.list();switch(t.type){case"pcb_board":return uyn(t,e.transform);case"pcb_component":{const r=i.find(a=>a.source_component_id===t.source_component_id),s=ea(n).pcb_port.list().filter(a=>a.pcb_component_id===t.pcb_component_id)[0];if(r&&s){const a=r.are_pins_interchangeable,c=hyn({elm:t,portPosition:{x:s.x,y:s.y},name:r.name,arePinsInterchangeable:a},e);return c?[c]:[]}return[]}case"pcb_smtpad":return byn(t,e);case"pcb_hole":return yyn(t,e);case"pcb_plated_hole":return gyn(t,e);default:return[]}}function vyn(t,e,n,i,r){const[o,s]=Yt(t,[e,n]),[a,c]=Yt(t,[i,r]),l=Math.abs(a-o),u=Math.abs(c-s),d=Math.min(o,a),h=Math.min(s,c);return{name:"rect",type:"element",value:"",children:[],attributes:{class:"assembly-boundary",x:d.toString(),y:h.toString(),width:l.toString(),height:u.toString()}}}var wyn="rgb(26, 115, 143)",Syn="rgba(0,0,0,0.9)";function Eyn(t,e){const{transform:n,soup:i}=e,{width:r,height:o,center:s,outline:a}=t;let c;if(a&&Array.isArray(a)&&a.length>=3)c=a.map((u,d)=>{const[h,f]=Yt(n,[u.x,u.y]);return d===0?`M ${h} ${f}`:`L ${h} ${f}`}).join(" ");else{const u=r/2,d=o/2,h=Yt(n,[s.x-u,s.y-d]),f=Yt(n,[s.x+u,s.y-d]),m=Yt(n,[s.x+u,s.y+d]),y=Yt(n,[s.x-u,s.y+d]);c=`M ${h[0]} ${h[1]} L ${f[0]} ${f[1]} L ${m[0]} ${m[1]} L ${y[0]} ${y[1]}`}c+=" Z";const l=ea(i).pcb_cutout.list();for(const u of l)if(u.shape==="rect"){const{x:d,y:h,width:f,height:m}=u.center?(()=>{const{x:N,y:R}=u.center,{width:P,height:M}=u;return{x:N,y:R,width:P,height:M}})():{x:0,y:0,width:0,height:0},y=f/2,g=m/2,[b,v,w,T]=[Yt(n,[d-y,h-g]),Yt(n,[d+y,h-g]),Yt(n,[d+y,h+g]),Yt(n,[d-y,h+g])];c+=` M ${b[0]} ${b[1]} L ${v[0]} ${v[1]} L ${w[0]} ${w[1]} L ${T[0]} ${T[1]} Z`}else u.shape;return[{name:"path",type:"element",value:"",children:[],attributes:{class:"pinout-board",d:c,fill:wyn,stroke:Syn,"fill-rule":"evenodd","stroke-opacity":"0.8","stroke-width":(.2*Math.abs(n.a)).toString()}}]}var Tyn="rgba(120, 120, 120, 0.6)",Myn="rgba(255, 255, 255, 0.9)";function Ayn(t,e){const{transform:n,soup:i}=e,{center:r,width:o,height:s,rotation:a=0,source_component_id:c}=t,l=ea(i).source_component.get(c);if(!r||typeof o!="number"||typeof s!="number"||o===0||s===0)return[];const[u,d]=Yt(n,[r.x,r.y]),h=o*Math.abs(n.a),f=s*Math.abs(n.d),m=`translate(${u}, ${d}) rotate(${-a})`,y=[{name:"rect",type:"element",attributes:{class:"pinout-component-box",x:(-h/2).toString(),y:(-f/2).toString(),width:h.toString(),height:f.toString(),fill:Tyn},value:"",children:[]}];if(l?.name){const g=f>h*1.5,b=Math.min(h,f)*.4;y.push({name:"text",type:"element",attributes:{x:"0",y:"0",fill:Myn,"font-size":`${b}px`,"font-family":"sans-serif","text-anchor":"middle","dominant-baseline":"middle",transform:g?"rotate(90)":""},children:[{type:"text",value:l.name,name:"",attributes:{},children:[]}],value:""})}return[{name:"g",type:"element",attributes:{transform:m},children:y,value:""}]}var Hme="rgb(50, 50, 50)";function Cyn(t,e){const{transform:n}=e,[i,r]=Yt(n,[t.x,t.y]);if(t.hole_shape==="circle"||t.hole_shape==="square"){const o=t.hole_diameter*Math.abs(n.a),s=o/2;return t.hole_shape==="circle"?[{name:"circle",type:"element",attributes:{class:"pinout-hole",cx:i.toString(),cy:r.toString(),r:s.toString(),fill:Hme},children:[],value:""}]:[{name:"rect",type:"element",attributes:{class:"pinout-hole",x:(i-s).toString(),y:(r-s).toString(),width:o.toString(),height:o.toString(),fill:Hme},children:[],value:""}]}if(t.hole_shape==="oval"){const o=t.hole_width*Math.abs(n.a),s=t.hole_height*Math.abs(n.a),a=o/2,c=s/2;return[{name:"ellipse",type:"element",attributes:{class:"pinout-hole",cx:i.toString(),cy:r.toString(),rx:a.toString(),ry:c.toString(),fill:Hme},children:[],value:""}]}return[]}var tN="rgb(218, 165, 32)",nN="rgb(40, 40, 40)";function Ryn(t,e){const{transform:n}=e,[i,r]=Yt(n,[t.x,t.y]);if(t.shape==="pill"){const o=t.outer_width*Math.abs(n.a),s=t.outer_height*Math.abs(n.a),a=t.hole_width*Math.abs(n.a),c=t.hole_height*Math.abs(n.a),l=o/2,u=s-o,d=a/2;return[{name:"g",type:"element",children:[{name:"path",type:"element",attributes:{class:"pinout-hole-outer",fill:tN,d:`M${i-l},${r-u/2} v${u} a${l},${l} 0 0 0 ${o},0 v-${u} a${l},${l} 0 0 0 -${o},0 z`},value:"",children:[]},{name:"path",type:"element",attributes:{class:"pinout-hole-inner",fill:nN,d:`M${i-d},${r-(c-a)/2} v${c-a} a${d},${d} 0 0 0 ${a},0 v-${c-a} a${d},${d} 0 0 0 -${a},0 z`},value:"",children:[]}],value:"",attributes:{}}]}if(t.shape==="circle"){const o=t.outer_diameter*Math.abs(n.a),s=t.outer_diameter*Math.abs(n.a),a=t.hole_diameter*Math.abs(n.a),c=t.hole_diameter*Math.abs(n.a),l=Math.min(o,s)/2,u=Math.min(a,c)/2;return[{name:"g",type:"element",children:[{name:"circle",type:"element",attributes:{class:"pinout-hole-outer",fill:tN,cx:i.toString(),cy:r.toString(),r:l.toString()},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"pinout-hole-inner",fill:nN,cx:i.toString(),cy:r.toString(),r:u.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(t.shape==="circular_hole_with_rect_pad"){const o=t.hole_diameter*Math.abs(n.a),s=t.rect_pad_width*Math.abs(n.a),a=t.rect_pad_height*Math.abs(n.a),c=o/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"pinout-hole-outer-pad",fill:tN,x:(i-s/2).toString(),y:(r-a/2).toString(),width:s.toString(),height:a.toString()},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"pinout-hole-inner",fill:nN,cx:i.toString(),cy:r.toString(),r:c.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(t.shape==="pill_hole_with_rect_pad"){const o=t.rect_pad_width*Math.abs(n.a),s=t.rect_pad_height*Math.abs(n.a),a=t.hole_height*Math.abs(n.a),c=t.hole_width*Math.abs(n.a),l=Math.min(a,c)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"pinout-hole-outer-pad",fill:tN,x:(i-o/2).toString(),y:(r-s/2).toString(),width:o.toString(),height:s.toString()},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"pinout-hole-inner",fill:nN,x:(i-c/2).toString(),y:(r-a/2).toString(),width:c.toString(),height:a.toString(),rx:l.toString(),ry:l.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(t.shape==="rotated_pill_hole_with_rect_pad"){const o=t.rect_pad_width*Math.abs(n.a),s=t.rect_pad_height*Math.abs(n.a),a=t.hole_height*Math.abs(n.a),c=t.hole_width*Math.abs(n.a),l=Math.min(a,c)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"pinout-hole-outer-pad",fill:tN,x:(-o/2).toString(),y:(-s/2).toString(),width:o.toString(),height:s.toString(),transform:`translate(${i} ${r}) rotate(${-t.rect_ccw_rotation})`},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"pinout-hole-inner",fill:nN,x:(-c/2).toString(),y:(-a/2).toString(),width:c.toString(),height:a.toString(),rx:l.toString(),ry:l.toString(),transform:`translate(${i} ${r}) rotate(${-t.hole_ccw_rotation})`},value:"",children:[]}],value:"",attributes:{}}]}return[]}var iN="rgb(218, 165, 32)";function Pyn(t,e){const{transform:n}=e;if(t.shape==="rect"||t.shape==="rotated_rect"){const i=t.width*Math.abs(n.a),r=t.height*Math.abs(n.d),[o,s]=Yt(n,[t.x,t.y]);return t.shape==="rotated_rect"&&t.ccw_rotation?[{name:"rect",type:"element",attributes:{class:"pinout-pad",fill:iN,x:(-i/2).toString(),y:(-r/2).toString(),width:i.toString(),height:r.toString(),transform:`translate(${o} ${s}) rotate(${-t.ccw_rotation})`,"data-layer":t.layer},value:"",children:[]}]:[{name:"rect",type:"element",attributes:{class:"pinout-pad",fill:iN,x:(o-i/2).toString(),y:(s-r/2).toString(),width:i.toString(),height:r.toString(),"data-layer":t.layer},value:"",children:[]}]}if(t.shape==="pill"){const i=t.width*Math.abs(n.a),r=t.height*Math.abs(n.d),o=t.radius*Math.abs(n.a),[s,a]=Yt(n,[t.x,t.y]);return[{name:"rect",type:"element",attributes:{class:"pinout-pad",fill:iN,x:(s-i/2).toString(),y:(a-r/2).toString(),width:i.toString(),height:r.toString(),rx:o.toString(),ry:o.toString(),"data-layer":t.layer},value:"",children:[]}]}if(t.shape==="circle"){const i=t.radius*Math.abs(n.a),[r,o]=Yt(n,[t.x,t.y]);return[{name:"circle",type:"element",attributes:{class:"pinout-pad",fill:iN,cx:r.toString(),cy:o.toString(),r:i.toString(),"data-layer":t.layer},value:"",children:[]}]}if(t.shape==="polygon"){const i=(t.points??[]).map(r=>Yt(n,[r.x,r.y]));return[{name:"polygon",type:"element",attributes:{class:"pinout-pad",fill:iN,points:i.map(r=>r.join(",")).join(" "),"data-layer":t.layer},value:"",children:[]}]}return[]}var Iyn="rgb(255, 255, 255)",Nyn="rgb(0, 0, 0)",kyn="rgba(0, 0, 0, 0.6)";function Oyn(t,e){const n=e.label_positions.get(t.pcb_port_id);if(!n)return[];const{text:i,aliases:r,elbow_end:o,label_pos:s,edge:a}=n,[c,l]=Yt(e.transform,[t.x,t.y]),u=a==="left"?"x-":a==="right"?"x+":a==="top"?"y-":"y+",d=a==="left"?"x+":a==="right"?"x-":a==="top"?"y+":"y-",f=[...lU({x:c,y:l,facingDirection:u},{x:o.x,y:o.y,facingDirection:d},{}),s].map(P=>`${P.x},${P.y}`).join(" "),m=[i,...r].join(" | "),y=11,g=m.length*y*.6,b=5,v=y+2*b,w=g+2*b,T=s.y;let N,R;return a==="left"?(N=s.x-w,R=s.x-w/2):a==="right"?(N=s.x,R=s.x+w/2):(N=s.x-w/2,R=s.x),[{name:"polyline",type:"element",attributes:{points:f,stroke:kyn,"stroke-width":"1.5",fill:"none"},children:[],value:""},{name:"rect",type:"element",attributes:{x:N.toString(),y:(T-v/2).toString(),width:w.toString(),height:v.toString(),fill:Nyn,rx:"8",ry:"8",stroke:"none"},children:[],value:""},{name:"text",type:"element",attributes:{x:R.toString(),y:T.toString(),fill:Iyn,"font-size":`${y}px`,"font-family":"Arial, sans-serif","font-weight":"bold","text-anchor":"middle","dominant-baseline":"middle"},children:[{type:"text",value:m,name:"",attributes:{},children:[]}],value:""}]}function DZe(t,e){const n=ea(e).source_port.get(t.source_port_id);if(!n)return null;const i=n.port_hints?.filter(s=>!/^\d+$/.test(s)&&!["left","right","top","bottom"].includes(s))??[];let r=i[0];if(r||(r=n.name),!r)return null;const o=i.filter(s=>s!==r);return{text:r,aliases:o}}function Lyn(t,e){const n={left:t.x-e.minX,right:e.maxX-t.x,top:e.maxY-t.y,bottom:t.y-e.minY};let i="left",r=n.left;return n.right<r&&(r=n.right,i="right"),n.top<r&&(r=n.top,i="top"),n.bottom<r&&(r=n.bottom,i="bottom"),i}var zZe=20,FZe=2,$j=15,BZe=10,UZe=11,$Ze=5,Vme=UZe+2*$Ze,jj=5;function jZe(t,e,{transform:n,soup:i,board_bounds:r,svgHeight:o},s){const a=e.map(g=>({port:g,y:Yt(n,[g.x,g.y])[1],label_info:DZe(g,i)})).filter(g=>g.label_info).sort((g,b)=>g.y-b.y);if(a.length===0)return;const c=Yt(n,[t==="left"?r.minX:r.maxX,0])[0],l=a.length,u=(l-1)/2,d=zZe+l*FZe,f=d+u*$j+BZe,m=l*Vme+Math.max(0,l-1)*jj;let y=(o-m)/2+Vme/2;a.forEach(({port:g,label_info:b},v)=>{const w=Math.abs(v-u),T=u-w,N=d+T*$j,R=t==="left"?-1:1,P={x:c+R*N,y},M={x:c+R*f,y};s.set(g.pcb_port_id,{text:b.text,aliases:b.aliases,elbow_end:P,label_pos:M,edge:t}),y+=Vme+jj})}function HZe(t,e,{transform:n,soup:i,board_bounds:r,svgWidth:o},s){const a=e.map(b=>({port:b,x:Yt(n,[b.x,b.y])[0],label_info:DZe(b,i)})).filter(b=>b.label_info).sort((b,v)=>b.x-v.x);if(a.length===0)return;const c=Yt(n,[0,t==="top"?r.maxY:r.minY])[1],l=a.map(b=>{const T=[b.label_info.text,...b.label_info.aliases].join(" | ").length*UZe*.6+2*$Ze;return{...b,rectWidth:T}}),u=l.length,d=(u-1)/2,h=zZe+u*FZe,m=h+d*$j+BZe,y=l.reduce((b,v)=>b+v.rectWidth,0)+Math.max(0,u-1)*jj;let g=(o-y)/2;l.forEach(({port:b,label_info:v,rectWidth:w},T)=>{const N=Math.abs(T-d),R=d-N,P=h+R*$j,M=t==="top"?-1:1,I=g+w/2,A={x:I,y:c+M*P},$={x:I,y:c+M*m};s.set(b.pcb_port_id,{text:v.text,aliases:v.aliases,elbow_end:A,label_pos:$,edge:t}),g+=w+jj})}var Dyn=({ports_by_edge:t,transform:e,soup:n,board_bounds:i,svgWidth:r,svgHeight:o})=>{const s=new Map,a={transform:e,soup:n,board_bounds:i};return jZe("left",t.left,{...a,svgHeight:o},s),jZe("right",t.right,{...a,svgHeight:o},s),HZe("top",t.top,{...a,svgWidth:r},s),HZe("bottom",t.bottom,{...a,svgWidth:r},s),s},VZe=["pcb_board","pcb_smtpad","pcb_hole","pcb_plated_hole","pcb_component","pcb_port"];function GZe(t,e){let n=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY;for(const A of t)if(A.type==="pcb_board")if("outline"in A&&A.outline&&Array.isArray(A.outline)&&A.outline.length>0)for(const $ of A.outline)n=Math.min(n,$.x),i=Math.min(i,$.y),r=Math.max(r,$.x),o=Math.max(o,$.y);else{const $=A.center,k=A.width||0,V=A.height||0;n=Math.min(n,$.x-k/2),i=Math.min(i,$.y-V/2),r=Math.max(r,$.x+k/2),o=Math.max(o,$.y+V/2)}const s=20,a=r-n+2*s,c=o-i+2*s,l=e?.width??800,u=e?.height??600,d=l/a,h=u/c,f=Math.min(d,h),m=(l-a*f)/2,y=(u-c*f)/2,g=cs(Cs(m-n*f+s*f,u-y+i*f-s*f),kg(f,-f)),b={minX:n,minY:i,maxX:r,maxY:o},v=t.filter(A=>A.type==="pcb_port"&&A.is_board_pinout),w={left:[],right:[],top:[],bottom:[]};for(const A of v){const $=Lyn({x:A.x,y:A.y},b);w[$].push(A)}const T=Dyn({ports_by_edge:w,transform:g,soup:t,board_bounds:b,svgWidth:l,svgHeight:u}),N={transform:g,soup:t,label_positions:T},R=t.sort((A,$)=>(VZe.indexOf(A.type)??9999)-(VZe.indexOf($.type)??9999)).flatMap(A=>zyn(A,N)),P=oC(t),M=sC,I={name:"svg",type:"element",attributes:{xmlns:"http://www.w3.org/2000/svg",width:l.toString(),height:u.toString(),...P&&{"data-software-used-string":P},...e?.includeVersion&&{"data-circuit-to-svg-version":M}},value:"",children:[{name:"rect",type:"element",attributes:{fill:"rgb(255, 255, 255)",x:"0",y:"0",width:l.toString(),height:u.toString()},value:"",children:[]},...R].filter(A=>A!==null)};return FP(I)}function zyn(t,e,n){switch(t.type){case"pcb_board":return Eyn(t,e);case"pcb_component":return Ayn(t,e);case"pcb_smtpad":return Pyn(t,e);case"pcb_hole":return Cyn(t,e);case"pcb_plated_hole":return Ryn(t,e);case"pcb_port":return t.is_board_pinout?Oyn(t,e):[];default:return[]}}var Fw={"3d_viewer":{background_bottom:"rgb(102, 102, 128)",background_top:"rgb(204, 204, 230)",board:"rgb(51, 43, 23)",copper:"rgb(179, 156, 0)",silkscreen_bottom:"rgb(230, 230, 230)",silkscreen_top:"rgb(230, 230, 230)",soldermask:"rgb(20, 51, 36)",solderpaste:"rgb(128, 128, 128)"},board:{anchor:"rgb(255, 38, 226)",aux_items:"rgb(255, 255, 255)",b_adhes:"rgb(0, 0, 132)",b_crtyd:"rgb(255, 38, 226)",b_fab:"rgb(88, 93, 132)",b_mask:"rgba(2, 255, 238, 0.400)",b_paste:"rgb(0, 194, 194)",b_silks:"rgb(232, 178, 167)",background:"rgb(0, 16, 35)",cmts_user:"rgb(89, 148, 220)",copper:{b:"rgb(77, 127, 196)",f:"rgb(200, 52, 52)",in1:"rgb(127, 200, 127)",in10:"rgb(237, 124, 51)",in11:"rgb(91, 195, 235)",in12:"rgb(247, 111, 142)",in13:"rgb(167, 165, 198)",in14:"rgb(40, 204, 217)",in15:"rgb(232, 178, 167)",in16:"rgb(242, 237, 161)",in17:"rgb(237, 124, 51)",in18:"rgb(91, 195, 235)",in19:"rgb(247, 111, 142)",in2:"rgb(206, 125, 44)",in20:"rgb(167, 165, 198)",in21:"rgb(40, 204, 217)",in22:"rgb(232, 178, 167)",in23:"rgb(242, 237, 161)",in24:"rgb(237, 124, 51)",in25:"rgb(91, 195, 235)",in26:"rgb(247, 111, 142)",in27:"rgb(167, 165, 198)",in28:"rgb(40, 204, 217)",in29:"rgb(232, 178, 167)",in3:"rgb(79, 203, 203)",in30:"rgb(242, 237, 161)",in4:"rgb(219, 98, 139)",in5:"rgb(167, 165, 198)",in6:"rgb(40, 204, 217)",in7:"rgb(232, 178, 167)",in8:"rgb(242, 237, 161)",in9:"rgb(141, 203, 129)"},cursor:"rgb(255, 255, 255)",drc:"rgb(194, 194, 194)",drc_error:"rgba(215, 91, 107, 0.800)",drc_exclusion:"rgb(255, 255, 255)",drc_warning:"rgba(255, 208, 66, 0.902)",dwgs_user:"rgb(194, 194, 194)",eco1_user:"rgb(180, 219, 210)",eco2_user:"rgb(216, 200, 82)",edge_cuts:"rgb(208, 210, 205)",f_adhes:"rgb(132, 0, 132)",f_crtyd:"rgb(255, 0, 245)",f_fab:"rgb(175, 175, 175)",f_mask:"rgba(216, 100, 255, 0.400)",f_paste:"rgba(180, 160, 154, 0.902)",f_silks:"rgb(242, 237, 161)",footprint_text_back:"rgb(0, 0, 132)",footprint_text_front:"rgb(194, 194, 194)",footprint_text_invisible:"rgb(132, 132, 132)",grid:"rgb(132, 132, 132)",grid_axes:"rgb(194, 194, 194)",margin:"rgb(255, 38, 226)",microvia:"rgb(0, 132, 132)",no_connect:"rgb(0, 0, 132)",pad_back:"rgb(77, 127, 196)",pad_front:"rgb(200, 52, 52)",pad_plated_hole:"rgb(194, 194, 0)",pad_through_hole:"rgb(227, 183, 46)",plated_hole:"rgb(26, 196, 210)",ratsnest:"rgba(245, 255, 213, 0.702)",select_overlay:"rgb(4, 255, 67)",through_via:"rgb(236, 236, 236)",user_1:"rgb(194, 194, 194)",user_2:"rgb(89, 148, 220)",user_3:"rgb(180, 219, 210)",user_4:"rgb(216, 200, 82)",user_5:"rgb(194, 194, 194)",user_6:"rgb(89, 148, 220)",user_7:"rgb(180, 219, 210)",user_8:"rgb(216, 200, 82)",user_9:"rgb(232, 178, 167)",via_blind_buried:"rgb(187, 151, 38)",via_hole:"rgb(227, 183, 46)",via_micro:"rgb(0, 132, 132)",via_through:"rgb(236, 236, 236)",worksheet:"rgb(200, 114, 171)"},gerbview:{axes:"rgb(0, 0, 132)",background:"rgb(0, 0, 0)",dcodes:"rgb(255, 255, 255)",grid:"rgb(132, 132, 132)",layers:["rgb(132, 0, 0)","rgb(194, 194, 0)","rgb(194, 0, 194)","rgb(194, 0, 0)","rgb(0, 132, 132)","rgb(0, 132, 0)","rgb(0, 0, 132)","rgb(132, 132, 132)","rgb(132, 0, 132)","rgb(194, 194, 194)","rgb(132, 0, 132)","rgb(132, 0, 0)","rgb(132, 132, 0)","rgb(194, 194, 194)","rgb(0, 0, 132)","rgb(0, 132, 0)","rgb(132, 0, 0)","rgb(194, 194, 0)","rgb(194, 0, 194)","rgb(194, 0, 0)","rgb(0, 132, 132)","rgb(0, 132, 0)","rgb(0, 0, 132)","rgb(132, 132, 132)","rgb(132, 0, 132)","rgb(194, 194, 194)","rgb(132, 0, 132)","rgb(132, 0, 0)","rgb(132, 132, 0)","rgb(194, 194, 194)","rgb(0, 0, 132)","rgb(0, 132, 0)","rgb(132, 0, 0)","rgb(194, 194, 0)","rgb(194, 0, 194)","rgb(194, 0, 0)","rgb(0, 132, 132)","rgb(0, 132, 0)","rgb(0, 0, 132)","rgb(132, 132, 132)","rgb(132, 0, 132)","rgb(194, 194, 194)","rgb(132, 0, 132)","rgb(132, 0, 0)","rgb(132, 132, 0)","rgb(194, 194, 194)","rgb(0, 0, 132)","rgb(0, 132, 0)","rgb(132, 0, 0)","rgb(194, 194, 0)","rgb(194, 0, 194)","rgb(194, 0, 0)","rgb(0, 132, 132)","rgb(0, 132, 0)","rgb(0, 0, 132)","rgb(132, 132, 132)","rgb(132, 0, 132)","rgb(194, 194, 194)","rgb(132, 0, 132)","rgb(132, 0, 0)"],negative_objects:"rgb(132, 132, 132)",worksheet:"rgb(0, 0, 132)"},meta:{filename:"kicad_2020",name:"KiCad 2020",version:2},palette:["rgb(132, 0, 0)","rgb(194, 194, 0)","rgb(194, 0, 194)","rgb(194, 0, 0)","rgb(0, 132, 132)","rgb(0, 132, 0)","rgb(0, 0, 132)","rgb(132, 132, 132)","rgb(132, 0, 132)","rgb(194, 194, 194)","rgb(132, 0, 132)","rgb(132, 0, 0)","rgb(132, 132, 0)","rgb(194, 194, 194)","rgb(0, 0, 132)","rgb(0, 132, 0)"],schematic:{aux_items:"rgb(46, 46, 46)",background:"rgb(245, 241, 237)",brightened:"rgb(255, 0, 255)",bus:"rgb(0, 0, 132)",bus_junction:"rgb(0, 0, 132)",component_body:"rgb(255, 255, 194)",component_outline:"rgb(132, 0, 0)",cursor:"rgb(15, 15, 15)",erc_error:"rgba(230, 9, 13, 0.800)",erc_warning:"rgba(209, 146, 0, 0.800)",fields:"rgb(132, 0, 132)",grid:"rgb(181, 181, 181)",grid_axes:"rgb(0, 0, 132)",hidden:"rgb(194, 194, 194)",junction:"rgb(0, 150, 0)",label_global:"rgb(132, 0, 0)",label_background:"rgba(255, 255, 255, 0.6)",label_hier:"rgb(114, 86, 0)",label_local:"rgb(15, 15, 15)",net_name:"rgb(132, 132, 132)",no_connect:"rgb(0, 0, 132)",note:"rgb(0, 0, 194)",override_item_colors:!1,pin:"rgb(132, 0, 0)",pin_name:"rgb(0, 100, 100)",pin_number:"rgb(169, 0, 0)",reference:"rgb(0, 100, 100)",shadow:"rgba(102, 179, 255, 0.800)",sheet:"rgb(132, 0, 0)",sheet_background:"rgba(253, 255, 231, 0.000)",sheet_fields:"rgb(132, 0, 132)",sheet_filename:"rgb(114, 86, 0)",sheet_label:"rgb(0, 100, 100)",sheet_name:"rgb(0, 100, 100)",table:"rgb(102, 102, 102)",value:"rgb(0, 100, 100)",wire:"rgb(0, 150, 0)",wire_crossing:"rgb(30, 180, 30)",worksheet:"rgb(132, 0, 0)"}};function Fyn(t){const{minX:e,minY:n,maxX:i,maxY:r}=t.bounds,o=t.cellSize??1,s=t.labelCells??!1,a=[],c=(l,u)=>{const[d,h]=Yt(t.transform,[l,u]);return{x:d,y:h}};for(let l=Math.floor(e);l<=Math.ceil(i);l+=o){const u=c(l,n),d=c(l,r);a.push({name:"line",type:"element",attributes:{x1:u.x.toString(),y1:u.y.toString(),x2:d.x.toString(),y2:d.y.toString(),stroke:Fw.schematic.grid,"stroke-width":(.01*Math.abs(t.transform.a)).toString(),"stroke-opacity":"0.5"}})}for(let l=Math.floor(n);l<=Math.ceil(r);l+=o){const u=c(e,l),d=c(i,l);a.push({name:"line",type:"element",attributes:{x1:u.x.toString(),y1:u.y.toString(),x2:d.x.toString(),y2:d.y.toString(),stroke:Fw.schematic.grid,"stroke-width":(.01*Math.abs(t.transform.a)).toString(),"stroke-opacity":"0.5"}})}if(s){const l=(u,d)=>o<=.1?`${u.toFixed(1)},${d.toFixed(1)}`:`${u},${d}`;for(let u=Math.floor(e);u<=Math.ceil(i);u+=o)for(let d=Math.floor(n);d<=Math.ceil(r);d+=o){const h=c(u,d);a.push({name:"text",type:"element",attributes:{x:(h.x-2.5).toString(),y:(h.y-5).toString(),fill:Fw.schematic.grid,"font-size":(o/5*Math.abs(t.transform.a)).toString(),"fill-opacity":"0.5","text-anchor":"middle","dominant-baseline":"middle","font-family":"sans-serif"},children:[{type:"text",value:l(u,d),name:"",attributes:{},children:[]}]})}}return{name:"g",value:"",type:"element",attributes:{class:"grid"},children:a}}function Byn(t){const{points:e,transform:n}=t,i=[];for(const r of e){const[o,s]=Yt(n,[r.x-.1,r.y-.1]),[a,c]=Yt(n,[r.x+.1,r.y+.1]),[l,u]=Yt(n,[r.x-.1,r.y+.1]),[d,h]=Yt(n,[r.x+.1,r.y-.1]);i.push({name:"path",type:"element",attributes:{d:`M${o},${s} L${a},${c} M${l},${u} L${d},${h}`,stroke:Fw.schematic.grid,"stroke-width":(.02*Math.abs(n.a)).toString(),"stroke-opacity":"0.7"}});const[f,m]=Yt(n,[r.x+.15,r.y-.15]);i.push({name:"text",type:"element",attributes:{x:f.toString(),y:m.toString(),fill:Fw.schematic.grid,"font-size":(.1*Math.abs(n.a)).toString(),"fill-opacity":"0.7","text-anchor":"start","font-family":"sans-serif","dominant-baseline":"middle"},children:[{type:"text",value:r.label||`(${r.x},${r.y})`,name:"",attributes:{},children:[]}]})}return{name:"g",value:"",type:"element",attributes:{class:"labeled-points"},children:i}}var YZe={0:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},1:{width:13,height:27,ascent:22,descent:5,left:-3,right:9},2:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},3:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},4:{width:13,height:27,ascent:22,descent:5,left:0,right:12},5:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},6:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},7:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},8:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},9:{width:13,height:27,ascent:22,descent:5,left:-1,right:12}," ":{width:7,height:27,ascent:22,descent:5,left:0,right:0},"!":{width:7,height:27,ascent:22,descent:5,left:-2,right:5},'"':{width:9,height:27,ascent:22,descent:5,left:-1,right:7},"#":{width:13,height:27,ascent:22,descent:5,left:0,right:13},$:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},"%":{width:21,height:27,ascent:22,descent:5,left:-1,right:20},"&":{width:16,height:27,ascent:22,descent:5,left:-1,right:15},"'":{width:5,height:27,ascent:22,descent:5,left:-1,right:3},"(":{width:8,height:27,ascent:22,descent:5,left:-1,right:7},")":{width:8,height:27,ascent:22,descent:5,left:-1,right:7},"*":{width:9,height:27,ascent:22,descent:5,left:-1,right:8},"+":{width:14,height:27,ascent:22,descent:5,left:-1,right:13},",":{width:7,height:27,ascent:22,descent:5,left:-2,right:5},"-":{width:8,height:27,ascent:22,descent:5,left:-1,right:7},".":{width:7,height:27,ascent:22,descent:5,left:-2,right:5},"/":{width:7,height:27,ascent:22,descent:5,left:0,right:7},":":{width:7,height:27,ascent:22,descent:5,left:-2,right:5},";":{width:7,height:27,ascent:22,descent:5,left:-2,right:5},"<":{width:14,height:27,ascent:22,descent:5,left:-1,right:13},"=":{width:14,height:27,ascent:22,descent:5,left:-1,right:13},">":{width:14,height:27,ascent:22,descent:5,left:-1,right:13},"?":{width:13,height:27,ascent:22,descent:5,left:-1,right:12},"@":{width:24,height:27,ascent:22,descent:5,left:-1,right:23},A:{width:16,height:27,ascent:22,descent:5,left:0,right:16},B:{width:16,height:27,ascent:22,descent:5,left:-2,right:15},C:{width:17,height:27,ascent:22,descent:5,left:-1,right:16},D:{width:17,height:27,ascent:22,descent:5,left:-2,right:16},E:{width:16,height:27,ascent:22,descent:5,left:-2,right:15},F:{width:15,height:27,ascent:22,descent:5,left:-2,right:14},G:{width:19,height:27,ascent:22,descent:5,left:-1,right:17},H:{width:17,height:27,ascent:22,descent:5,left:-2,right:15},I:{width:7,height:27,ascent:22,descent:5,left:-2,right:5},J:{width:12,height:27,ascent:22,descent:5,left:-1,right:10},K:{width:16,height:27,ascent:22,descent:5,left:-2,right:16},L:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},M:{width:20,height:27,ascent:22,descent:5,left:-2,right:18},N:{width:17,height:27,ascent:22,descent:5,left:-2,right:15},O:{width:19,height:27,ascent:22,descent:5,left:-1,right:18},P:{width:16,height:27,ascent:22,descent:5,left:-2,right:15},Q:{width:19,height:27,ascent:22,descent:5,left:-1,right:18},R:{width:17,height:27,ascent:22,descent:5,left:-2,right:17},S:{width:16,height:27,ascent:22,descent:5,left:-1,right:15},T:{width:15,height:27,ascent:22,descent:5,left:-1,right:14},U:{width:17,height:27,ascent:22,descent:5,left:-2,right:15},V:{width:16,height:27,ascent:22,descent:5,left:0,right:16},W:{width:23,height:27,ascent:22,descent:5,left:0,right:22},X:{width:16,height:27,ascent:22,descent:5,left:0,right:16},Y:{width:16,height:27,ascent:22,descent:5,left:0,right:16},Z:{width:15,height:27,ascent:22,descent:5,left:0,right:14},"[":{width:7,height:27,ascent:22,descent:5,left:-2,right:6},"\\":{width:7,height:27,ascent:22,descent:5,left:0,right:7},"]":{width:7,height:27,ascent:22,descent:5,left:0,right:5},"^":{width:11,height:27,ascent:22,descent:5,left:-1,right:11},_:{width:13,height:27,ascent:22,descent:5,left:0,right:14},"`":{width:8,height:27,ascent:22,descent:5,left:-1,right:5},a:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},b:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},c:{width:12,height:27,ascent:22,descent:5,left:-1,right:12},d:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},e:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},f:{width:7,height:27,ascent:22,descent:5,left:0,right:8},g:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},h:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},i:{width:5,height:27,ascent:22,descent:5,left:-2,right:4},j:{width:5,height:27,ascent:22,descent:5,left:1,right:4},k:{width:12,height:27,ascent:22,descent:5,left:-2,right:12},l:{width:5,height:27,ascent:22,descent:5,left:-2,right:4},m:{width:20,height:27,ascent:22,descent:5,left:-2,right:18},n:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},o:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},p:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},q:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},r:{width:8,height:27,ascent:22,descent:5,left:-2,right:8},s:{width:12,height:27,ascent:22,descent:5,left:-1,right:11},t:{width:7,height:27,ascent:22,descent:5,left:0,right:6},u:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},v:{width:12,height:27,ascent:22,descent:5,left:0,right:12},w:{width:17,height:27,ascent:22,descent:5,left:0,right:17},x:{width:12,height:27,ascent:22,descent:5,left:0,right:12},y:{width:12,height:27,ascent:22,descent:5,left:0,right:12},z:{width:12,height:27,ascent:22,descent:5,left:0,right:11},"{":{width:8,height:27,ascent:22,descent:5,left:-1,right:7},"|":{width:6,height:27,ascent:22,descent:5,left:-2,right:4},"}":{width:8,height:27,ascent:22,descent:5,left:-1,right:7},"~":{width:14,height:27,ascent:22,descent:5,left:-1,right:13}},Hj=t=>{if(!t)return 0;let e=0;for(const n of t){const i=YZe[n];i?e+=i.width:e+=YZe["?"].width}return e/27},qZe=(t,e)=>{if(t.column_widths&&t.column_widths.length>0&&t.row_heights&&t.row_heights.length>0){const u=d=>typeof d=="number"?d:d.endsWith("mm")?parseFloat(d):d.endsWith("in")?parseFloat(d)*25.4:parseFloat(d);return{column_widths:t.column_widths.map(u),row_heights:t.row_heights.map(u)}}const n=e.filter(u=>u.type==="schematic_table_cell"&&u.schematic_table_id===t.schematic_table_id);if(n.length===0)return{column_widths:[],row_heights:[]};const i=n.reduce((u,d)=>Math.max(u,d.end_column_index),-1)+1,r=n.reduce((u,d)=>Math.max(u,d.end_row_index),-1)+1,{cell_padding:o=.2}=t,s=new Array(i).fill(0),a=new Array(r).fill(0),c={},l={};for(const u of n){const d=aC("reference_designator",u.font_size),f=Hj(u.text??"")*d+2*o,m=d*1.2+2*o,y=`${u.start_row_index}-${u.start_column_index}`;c[y]=f,l[y]=m}for(let u=0;u<r;u++)for(let d=0;d<i;d++){const h=`${u}-${d}`;c[h]&&c[h]>s[d]&&(s[d]=c[h]),l[h]&&l[h]>a[u]&&(a[u]=l[h])}for(const u of n){if(u.start_column_index===u.end_column_index&&u.start_row_index===u.end_row_index)continue;const d=`${u.start_row_index}-${u.start_column_index}`,h=c[d],f=l[d];if(h===void 0||f===void 0)continue;let m=0;for(let g=u.start_column_index;g<=u.end_column_index;g++)m+=s[g];if(h>m){const b=(h-m)/(u.end_column_index-u.start_column_index+1);for(let v=u.start_column_index;v<=u.end_column_index;v++)s[v]+=b}let y=0;for(let g=u.start_row_index;g<=u.end_row_index;g++)y+=a[g];if(f>y){const b=(f-y)/(u.end_row_index-u.start_row_index+1);for(let v=u.start_row_index;v<=u.end_row_index;v++)a[v]+=b}}return{column_widths:s,row_heights:a}},cC=t=>{switch(t){case"top":return{x:0,y:-1};case"bottom":return{x:0,y:1};case"left":return{x:1,y:0};case"right":return{x:-1,y:0}}throw new Error(`Invalid side: ${t}`)},tE=.3,lC=.3,uC=.06,Uyn={top_left:"start",top_right:"end",middle_left:"start",middle_right:"end",bottom_left:"start",bottom_right:"end",center:"middle",middle_top:"middle",middle_bottom:"middle"},$yn={top_left:"hanging",top_right:"hanging",bottom_left:"ideographic",bottom_right:"ideographic",center:"middle",middle_left:"middle",middle_right:"middle",middle_top:"hanging",middle_bottom:"ideographic"};function jyn(t){return{left:180,top:90,bottom:-90,right:0}[t]??0}function Hyn(t,e,n){const i=n+tE*2+uC*t.text.length+lC,r=cC(t.anchor_side);return t.anchor_position??{x:t.center.x-r.x*i*e/2,y:t.center.y-r.y*i*e/2}}function Vyn(t,e=.5){let n=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY;const s=.2;for(const c of t)if(c.type==="schematic_component")a(c.center,c.size,0);else if(c.type==="schematic_port")a(c.center,{width:s,height:s},0);else if(c.type==="schematic_debug_object")c.shape==="rect"?a(c.center,c.size,0):c.shape==="line"&&(a(c.start,{width:.1,height:.1},0),a(c.end,{width:.1,height:.1},0));else if(c.type==="schematic_net_label"){const l=aC("net_label"),u=Hj(c.text||""),h=(u+tE*2+uC*(c.text?.length||0)+lC)*l,f=1.2*l,m=jyn(c.anchor_side)/180*Math.PI,y=Hyn(c,l,u),g=cC(c.anchor_side),b={x:y.x+g.x*h/2,y:y.y+g.y*h/2};a(b,{width:h,height:f},m)}else if(c.type==="schematic_trace")for(const l of c.edges)a(l.from,{width:.1,height:.1},0),a(l.to,{width:.1,height:.1},0);else if(c.type==="schematic_text"){const u=aC("reference_designator",c.font_size)??.18,h=(c.text??"").length*u,f=u;a(c.position,{width:h,height:f},c.rotation??0)}else if(c.type==="schematic_voltage_probe")a(c.position,{width:.2,height:.4},0);else if(c.type==="schematic_box")a({x:c.x+c.width/2,y:c.y+c.height/2},{width:c.width,height:c.height},0);else if(c.type==="schematic_table"){const{column_widths:l,row_heights:u}=qZe(c,t),d=l.reduce((v,w)=>v+w,0),h=u.reduce((v,w)=>v+w,0),f=c.anchor??"center";let m=c.anchor_position.x,y=c.anchor_position.y;f.includes("center")?m-=d/2:f.includes("right")&&(m-=d),f.includes("center")?y+=h/2:f.includes("bottom")&&(y+=h);const g=m+d/2,b=y-h/2;a({x:g,y:b},{width:d,height:h},0)}else c.type==="schematic_line"?(a({x:c.x1,y:c.y1},{width:.02,height:.02},0),a({x:c.x2,y:c.y2},{width:.02,height:.02},0)):c.type==="schematic_circle"?a(c.center,{width:c.radius*2,height:c.radius*2},0):c.type==="schematic_rect"?a(c.center,{width:c.width,height:c.height},c.rotation):c.type==="schematic_arc"&&a(c.center,{width:c.radius*2,height:c.radius*2},0);return n-=e,i-=e,r+=e,o+=e,{minX:n,minY:i,maxX:r,maxY:o};function a(c,l,u){const d=[{x:-l.width/2,y:-l.height/2},{x:l.width/2,y:-l.height/2},{x:l.width/2,y:l.height/2},{x:-l.width/2,y:l.height/2}];for(const h of d){const f=h.x*Math.cos(u)-h.y*Math.sin(u)+c.x,m=h.x*Math.sin(u)+h.y*Math.cos(u)+c.y;n=Math.min(n,f),i=Math.min(i,m),r=Math.max(r,f),o=Math.max(o,m)}}}var hb=t=>Math.abs(t.a)*.02,Gyn=(t,e)=>{const n=t<0?t+2*Math.PI:t,i=e<0?e+2*Math.PI:e;let r=Math.abs(n-i);return r>Math.PI&&(r=2*Math.PI-r),r},Yyn=({schPorts:t,symbol:e,schComponent:n})=>{const i=t.map(a=>{const c=a.center.x-n.center.x,l=a.center.y-n.center.y;return{port:a,angle:Math.atan2(l,c)}}),r=e.ports.map(a=>{const c=a.x-e.center.x,l=a.y-e.center.y;return{port:a,angle:Math.atan2(l,c)}});i.sort((a,c)=>a.angle-c.angle),r.sort((a,c)=>a.angle-c.angle);const o=[],s=new Set;for(const a of i){let c=null;for(const l of r){if(s.has(l.port))continue;const u=Gyn(a.angle,l.angle);(c===null||u<c.angleDiff)&&(c={symbolPort:l.port,angleDiff:u})}c&&c.angleDiff<Math.PI/4&&(o.push({schPort:a.port,symbolPort:c.symbolPort}),s.add(c.symbolPort))}return o};function qyn(t,e,n,i){const r=e.x-t.x,o=e.y-t.y,s=Math.sqrt((n.x-t.x)**2+(n.y-t.y)**2),c=Math.sqrt((i.x-e.x)**2+(i.y-e.y)**2)/s,l=Cs(r,o),u=kg(c,c);return cs(l,u)}var Gme=({text:t,realCenter:e,realToScreenTransform:n})=>{const i=Yt(n,e);return{type:"element",name:"text",value:"",attributes:{x:i.x.toString(),y:i.y.toString(),fill:"red","text-anchor":"middle","dominant-baseline":"middle","font-family":"sans-serif","font-size":`${l3(n,"error")}px`},children:[{type:"text",value:t,name:"",attributes:{},children:[]}]}},XZe=(t,e)=>{for(const n of t){if(n.type!=="source_trace")continue;const i=n;if(Array.isArray(i.connected_source_port_ids)&&i.connected_source_port_ids.includes(e))return!0}return!1},Xyn={top_left:"start",top_right:"end",middle_left:"start",middle_right:"end",bottom_left:"start",bottom_right:"end",center:"middle",middle_top:"middle",middle_bottom:"middle"},Wyn=({component:t,transform:e,circuitJson:n,colorMap:i})=>{const r=[],o=lv[t.symbol_name];if(!o)return[Gme({text:`Symbol not found: ${t.symbol_name}`,realCenter:t.center,realToScreenTransform:e})];const s=ea(n).schematic_port.list({schematic_component_id:t.schematic_component_id}),a=ea(n).source_component.get(t.source_component_id),c=Yyn({schPorts:s,symbol:o,schComponent:t});if(!c[0])return[Gme({text:`Could not match ports for symbol ${t.symbol_name}`,realCenter:t.center,realToScreenTransform:e})];const l=qyn(c[1]?.symbolPort??o.center,c[1]?.schPort.center??t.center,c[0].symbolPort,c[0].schPort.center),u=o.primitives.filter(M=>M.type==="path"),d=o.primitives.filter(M=>M.type==="text"),h=o.primitives.filter(M=>M.type==="circle"),f=o.primitives.filter(M=>M.type==="box"),m=new Set;for(const M of c)XZe(n,M.schPort.source_port_id)&&m.add(M.symbolPort);const y={minX:Math.min(...u.flatMap(M=>M.points.map(I=>I.x))),maxX:Math.max(...u.flatMap(M=>M.points.map(I=>I.x))),minY:Math.min(...u.flatMap(M=>M.points.map(I=>I.y))),maxY:Math.max(...u.flatMap(M=>M.points.map(I=>I.y)))},[g,b]=Yt(cs(e,l),[y.minX,y.minY]),[v,w]=Yt(cs(e,l),[y.maxX,y.maxY]),T=Math.abs(w-b),N=Math.min(b,w),R=Math.abs(v-g),P=Math.min(g,v);r.push({name:"rect",type:"element",value:"",attributes:{class:"component-overlay",x:P.toString(),y:N.toString(),width:R.toString(),height:T.toString(),fill:"transparent"},children:[]});for(const M of u){const{points:I,color:A,closed:$,fill:k}=M;r.push({type:"element",name:"path",attributes:{d:I.map((V,X)=>{const[W,K]=Yt(cs(e,l),[V.x,V.y]);return`${X===0?"M":"L"} ${W} ${K}`}).join(" ")+($?" Z":""),stroke:i.schematic.component_outline,fill:"none","stroke-width":`${hb(e)}px`,"stroke-linecap":"round"},value:"",children:[]})}for(const M of d){const I=Yt(cs(e,l),M);let A="";M.text==="{REF}"?A=a?.name??"":M.text==="{VAL}"&&(A=t.symbol_display_value??"");const V=Math.abs(y.maxY-y.minY)*.1,X=Math.abs(l.a);let W=0;M.anchor.includes("bottom")?W=V*X:M.anchor.includes("top")&&(W=-V*X);const K=M.anchor.includes("bottom")?"auto":M.anchor.includes("top")?"hanging":"middle",te=M.text==="{REF}";r.push({name:"text",type:"element",attributes:{x:I.x.toString(),y:(I.y+W).toString(),...te?{stroke:i.schematic.background,"stroke-width":`${hb(e)}px`,"paint-order":"stroke"}:{},fill:i.schematic.label_local,"font-family":"sans-serif","text-anchor":Xyn[M.anchor],"dominant-baseline":K,"font-size":`${l3(e,"reference_designator")}px`},value:"",children:[{type:"text",value:A,name:"",attributes:{},children:[]}]})}for(const M of f){const I=Yt(cs(e,l),M),A=cs(e,l).a;r.push({name:"rect",type:"element",attributes:{x:I.x.toString(),y:I.y.toString(),width:(M.width*A).toString(),height:(M.height*A).toString(),fill:"red"},value:"",children:[]})}for(const M of o.ports){if(m.has(M))continue;const I=Yt(cs(e,l),M);r.push({type:"element",name:"circle",attributes:{cx:I.x.toString(),cy:I.y.toString(),r:`${Math.abs(e.a)*.02}px`,"stroke-width":`${hb(e)}px`,fill:"none",stroke:i.schematic.component_outline},value:"",children:[]})}for(const M of h){const I=Yt(cs(e,l),M),A=Math.abs(M.radius*e.a);r.push({type:"element",name:"circle",attributes:{cx:I.x.toString(),cy:I.y.toString(),r:`${A}px`,"stroke-width":`${hb(e)}px`,fill:"none",stroke:i.schematic.component_outline},value:"",children:[]})}return r},rN=.02,WZe=(t,e,n,i,r)=>{const o=Math.PI/6,s={x:t.x-n*Math.cos(e-o),y:t.y-n*Math.sin(e-o)},a={x:t.x-n*Math.cos(e+o),y:t.y-n*Math.sin(e+o)};return{name:"polygon",type:"element",attributes:{points:`${t.x},${t.y} ${s.x},${s.y} ${a.x},${a.y}`,fill:"white",stroke:i,"stroke-width":`${r}px`},value:"",children:[]}},Zyn=({schPort:t,schComponent:e,transform:n,circuitJson:i})=>{const r=[];ea(i).source_port.get(t.source_port_id);const o={x:t.center.x,y:t.center.y},s=t.distance_from_component_edge??.4;switch(t.side_of_component){case"left":o.x+=s;break;case"right":o.x-=s;break;case"top":o.y-=s;break;case"bottom":o.y+=s;break}const a=Yt(n,t.center),c=Yt(n,o),l=XZe(i,t.source_port_id),u={...t.center};if(!l)switch(t.side_of_component){case"left":u.x+=rN;break;case"right":u.x-=rN;break;case"top":u.y-=rN;break;case"bottom":u.y+=rN;break}const d=Yt(n,u);r.push({name:"line",type:"element",attributes:{class:"component-pin",x1:c.x.toString(),y1:c.y.toString(),x2:d.x.toString(),y2:d.y.toString(),"stroke-width":`${hb(n)}px`},value:"",children:[]});const h=Math.abs(n.a)*rN,f=[];l||f.push({name:"circle",type:"element",attributes:{class:"component-pin",cx:a.x.toString(),cy:a.y.toString(),r:h.toString(),"stroke-width":`${hb(n)}px`},value:"",children:[]}),f.push({name:"rect",type:"element",attributes:{x:(a.x-h).toString(),y:(a.y-h).toString(),width:(h*2).toString(),height:(h*2).toString(),opacity:"0"},value:"",children:[]}),r.push({name:"g",type:"element",value:"",attributes:{"data-schematic-port-id":t.source_port_id},children:f});const{has_input_arrow:m,has_output_arrow:y}=t;if((m||y)&&t.side_of_component){const g=Math.abs(n.a)*.1,b=Fw.schematic.component_outline,v=g*Math.cos(Math.PI/6),w=hb(n)/3;let T=0,N=0;t.side_of_component==="left"?(T=0,N=Math.PI):t.side_of_component==="right"?(T=Math.PI,N=0):t.side_of_component==="top"?(T=Math.PI/2,N=-Math.PI/2):t.side_of_component==="bottom"&&(T=-Math.PI/2,N=Math.PI/2);const R=m&&y;let P={...c},M={...c};if(R){const I=v;t.side_of_component==="left"?M.x-=I:t.side_of_component==="right"?M.x+=I:t.side_of_component==="top"?M.y-=I:t.side_of_component==="bottom"&&(M.y+=I)}if(m&&r.push(WZe(P,T,g,b,w)),y){const I={x:M.x+g*Math.cos(N),y:M.y+g*Math.sin(N)};r.push(WZe(I,N,g,b,w))}}return r},Kyn=t=>{const e=[],{schPort:n,transform:i}=t,r={x:n.center.x,y:n.center.y};if(!n.side_of_component)return[];const o=cC(n.side_of_component),s=n.distance_from_component_edge??.4;r.x+=o.x*s/2,r.y+=o.y*s/2,n.side_of_component==="top"||n.side_of_component==="bottom"?r.x-=.02:r.y+=.02;const a=Yt(i,r);return e.push({name:"text",type:"element",attributes:{class:"pin-number",x:a.x.toString(),y:a.y.toString(),style:"font-family: sans-serif;",fill:Fw.schematic.pin_number,"text-anchor":"middle","dominant-baseline":"auto","font-size":`${l3(i,"pin_number")}px`,transform:n.side_of_component==="top"||n.side_of_component==="bottom"?`rotate(-90 ${a.x} ${a.y})`:""},children:[{type:"text",value:n.pin_number?.toString()||"",name:"",attributes:{},children:[]}],value:""}),e},ZZe=.1,Qyn=t=>{const e=[],{schPort:n,schComponent:i,transform:r}=t,o={x:n.center.x,y:n.center.y};if(!n.side_of_component)return[];const s=cC(n.side_of_component),a=n.distance_from_component_edge??.4;o.x+=s.x*(a+ZZe),o.y+=s.y*(a+ZZe);const c=Yt(r,o),l=n.display_pin_label??i.port_labels?.[`${n.pin_number}`];if(!l)return[];const u=l.startsWith("N_"),d=u?l.slice(2):l;let h=l3(r,u?"negated_pin_number":"pin_number");return e.push({name:"text",type:"element",attributes:{class:"pin-number",x:c.x.toString(),y:c.y.toString(),style:`font-family: sans-serif;${u?" text-decoration: overline;":""}`,fill:Fw.schematic.pin_number,"text-anchor":n.side_of_component==="left"||n.side_of_component==="bottom"?"start":"end","dominant-baseline":"middle","font-size":`${h}px`,transform:n.side_of_component==="top"||n.side_of_component==="bottom"?`rotate(-90 ${c.x} ${c.y})`:""},children:[{type:"text",value:d||"",name:"",attributes:{},children:[]}],value:""}),e},Jyn=t=>{const e=[];return e.push(...Zyn(t)),e.push(...Kyn(t)),e.push(...Qyn(t)),e},KZe=({elm:t,transform:e,colorMap:n})=>{const i=Yt(e,t.position),r={center:"middle",center_right:"end",bottom_left:"start",bottom_center:"middle",bottom_right:"end",left:"start",right:"end",top:"middle",bottom:"middle",top_left:"start",top_center:"middle",top_right:"end",center_left:"start"},o={center:"middle",center_right:"middle",bottom_left:"ideographic",bottom_center:"ideographic",bottom_right:"ideographic",left:"middle",right:"middle",top:"hanging",bottom:"ideographic",top_left:"hanging",top_center:"hanging",top_right:"hanging",center_left:"middle"},s=t.text.split(`
5324
5324
  `),a=s.length===1?[{type:"text",value:t.text,name:t.schematic_text_id,attributes:{},children:[]}]:s.map((c,l)=>({type:"element",name:"tspan",value:"",attributes:{x:i.x.toString(),...l>0?{dy:"1em"}:{}},children:[{type:"text",value:c,name:l===0?t.schematic_text_id:"",attributes:{},children:[]}]}));return{type:"element",name:"text",value:"",attributes:{x:i.x.toString(),y:i.y.toString(),fill:t.color??n.schematic.sheet_label,"text-anchor":r[t.anchor],"dominant-baseline":o[t.anchor],"font-family":"sans-serif","font-size":`${l3(e,"reference_designator",t.font_size)}px`,transform:`rotate(${t.rotation}, ${i.x}, ${i.y})`},children:a}},egn=({component:t,transform:e,circuitJson:n,colorMap:i})=>{const r=[],o=Yt(e,{x:t.center.x-t.size.width/2,y:t.center.y+t.size.height/2}),s=Yt(e,{x:t.center.x+t.size.width/2,y:t.center.y-t.size.height/2}),a=s.x-o.x,c=s.y-o.y;r.push({name:"rect",type:"element",value:"",attributes:{class:"component chip",x:o.x.toString(),y:o.y.toString(),width:a.toString(),height:c.toString(),"stroke-width":`${hb(e)}px`,fill:i.schematic.component_body,stroke:i.schematic.component_outline},children:[]}),r.push({name:"rect",type:"element",value:"",attributes:{class:"component-overlay",x:o.x.toString(),y:o.y.toString(),width:a.toString(),height:c.toString(),fill:"transparent"},children:[]});const l=ea(n).schematic_text.list();for(const d of l)d.schematic_component_id===t.schematic_component_id&&r.push(KZe({elm:d,transform:e,colorMap:i}));const u=ea(n).schematic_port.list({schematic_component_id:t.schematic_component_id});for(const d of u)r.push(...Jyn({schPort:d,schComponent:t,transform:e,circuitJson:n}));return r};function tgn(t){const{component:e}=t;if(e.is_box_with_pins===!1)return[];const n=e.symbol_name?Wyn(t):egn(t);return[{type:"element",name:"g",attributes:{"data-circuit-json-type":"schematic_component","data-schematic-component-id":e.schematic_component_id},children:n,value:""}]}function ngn({probe:t,transform:e,colorMap:n}){const[i,r]=Yt(e,[t.position.x,t.position.y]),o=Math.abs(e.a)*.6,s=Math.abs(e.a)*.28,a=i+o*Math.cos(-50*Math.PI/180),c=r+o*Math.sin(-50*Math.PI/180),l=i,u=r;return[{name:"path",type:"element",attributes:{d:[`M ${a},${c}`,`L ${l},${u}`,`M ${l},${u}`,`L ${l-s*Math.cos(100*Math.PI/180)},${u-s*Math.sin(100*Math.PI/180)}`,`L ${l-s*Math.cos(160*Math.PI/180)},${u-s*Math.sin(160*Math.PI/180)}`,"Z"].join(" "),stroke:n.schematic.reference,fill:n.schematic.reference,"stroke-width":`${hb(e)}px`},value:"",children:[]},{type:"element",name:"text",value:"",attributes:{x:(a+8-(a-a)).toString(),y:(c-10+(c-c)).toString(),fill:n.schematic.reference,"text-anchor":"middle","dominant-baseline":"middle","font-family":"sans-serif","font-size":`${l3(e,"reference_designator")}px`,"font-weight":"bold","data-schematic-voltage-probe-id":t.schematic_voltage_probe_id},children:[{type:"text",value:t.voltage?`${t.voltage}V`:"",name:"",attributes:{},children:[]}]}]}function ign({debugObject:t,transform:e}){if(t.shape==="rect"){let[n,i]=Yt(e,[t.center.x-t.size.width/2,t.center.y-t.size.height/2]),[r,o]=Yt(e,[t.center.x+t.size.width/2,t.center.y+t.size.height/2]);[i,o]=[Math.min(i,o),Math.max(i,o)];const s=Math.abs(r-n),a=Math.abs(o-i),[c,l]=Yt(e,[t.center.x,t.center.y]);return[{name:"rect",type:"element",value:"",attributes:{x:n.toString(),y:i.toString(),width:s.toString(),height:a.toString(),fill:"none",stroke:"red","stroke-width":(.02*Math.abs(e.a)).toString(),"stroke-dasharray":"5,5"},children:t.label?[{name:"text",type:"element",value:"",attributes:{x:c.toString(),y:(l-10).toString(),"text-anchor":"middle","font-size":(.2*Math.abs(e.a)).toString(),fill:"red"},children:[{type:"text",value:t.label,name:"",attributes:{},children:[]}]}]:[]}]}if(t.shape==="line"){const[n,i]=Yt(e,[t.start.x,t.start.y]),[r,o]=Yt(e,[t.end.x,t.end.y]),s=(n+r)/2,a=(i+o)/2;return[{name:"line",type:"element",value:"",attributes:{x1:n.toString(),y1:i.toString(),x2:r.toString(),y2:o.toString(),stroke:"red","stroke-width":(.02*Math.abs(e.a)).toString(),"stroke-dasharray":"5,5"},children:t.label?[{name:"text",type:"element",value:"",attributes:{x:s.toString(),y:(a-10).toString(),"text-anchor":"middle","font-size":(.2*Math.abs(e.a)).toString(),fill:"red"},children:[{type:"text",value:t.label,name:"",attributes:{},children:[]}]}]:[]}]}return[]}function rgn({trace:t,transform:e,colorMap:n}){const i=t.edges;if(i.length===0)return[];const r=[],o=[];let s="";for(let a=0;a<i.length;a++){const c=i[a];if(c.is_crossing)continue;const[l,u]=Yt(e,[c.from.x,c.from.y]),[d,h]=Yt(e,[c.to.x,c.to.y]);a===0||i[a-1]?.is_crossing?s+=`M ${l} ${u} L ${d} ${h}`:s+=` L ${d} ${h}`}s&&(r.push({name:"path",type:"element",attributes:{d:s,class:"trace-invisible-hover-outline",stroke:n.schematic.wire,fill:"none","stroke-width":`${hb(e)*8}px`,"stroke-linecap":"round",opacity:"0","stroke-linejoin":"round"},value:"",children:[]}),r.push({name:"path",type:"element",attributes:{d:s,stroke:n.schematic.wire,fill:"none","stroke-width":`${hb(e)}px`,"stroke-linecap":"round","stroke-linejoin":"round"},value:"",children:[]}));for(const a of i){if(!a.is_crossing)continue;const[c,l]=Yt(e,[a.from.x,a.from.y]),[u,d]=Yt(e,[a.to.x,a.to.y]),h=(c+u)/2,f=(l+d)/2,m=u-c,y=d-l,g=Math.sqrt(m*m+y*y),b=g*.7,v=-y/g*b,w=m/g*b,T=h+v,N=f-Math.abs(w);o.push({name:"path",type:"element",attributes:{class:"trace-crossing-outline",d:`M ${c} ${l} Q ${T} ${N} ${u} ${d}`,stroke:n.schematic.background,fill:"none","stroke-width":`${hb(e)*1.5}px`,"stroke-linecap":"butt"},value:"",children:[]}),o.push({name:"path",type:"element",attributes:{d:`M ${c} ${l} Q ${T} ${N} ${u} ${d}`,stroke:n.schematic.wire,fill:"none","stroke-width":`${hb(e)}px`,"stroke-linecap":"round"},value:"",children:[]})}if(t.junctions)for(const a of t.junctions){const[c,l]=Yt(e,[a.x,a.y]);o.push({name:"circle",type:"element",attributes:{cx:c.toString(),cy:l.toString(),r:(Math.abs(e.a)*.03).toString(),class:"trace-junction",fill:n.schematic.junction},value:"",children:[]})}return[{name:"g",type:"element",value:"",attributes:{class:"trace","data-layer":"base","data-circuit-json-type":"schematic_trace","data-schematic-trace-id":t.schematic_trace_id,...t.subcircuit_connectivity_map_key&&{"data-subcircuit-connectivity-map-key":t.subcircuit_connectivity_map_key}},children:r},{name:"g",type:"element",value:"",attributes:{class:"trace-overlays","data-layer":"overlay","data-circuit-json-type":"schematic_trace","data-schematic-trace-id":t.schematic_trace_id,...t.subcircuit_connectivity_map_key&&{"data-subcircuit-connectivity-map-key":t.subcircuit_connectivity_map_key}},children:o}]}var ogn=({schNetLabel:t,realToScreenTransform:e,colorMap:n})=>{if(!t.text)return[];const i=t.text.startsWith("N_"),r=i?t.text.slice(2):t.text,o=[],s=lv[t.symbol_name];if(!s)return o.push(Gme({text:`Symbol not found: ${t.symbol_name}`,realCenter:t.center,realToScreenTransform:e})),o;const a=s.primitives.filter(W=>W.type==="path"),c=s.primitives.filter(W=>W.type==="text"),l=s.primitives.filter(W=>W.type==="circle"),u=s.primitives.filter(W=>W.type==="box"),d={minX:Math.min(...a.flatMap(W=>W.points.map(K=>K.x))),maxX:Math.max(...a.flatMap(W=>W.points.map(K=>K.x))),minY:Math.min(...a.flatMap(W=>W.points.map(K=>K.y))),maxY:Math.max(...a.flatMap(W=>W.points.map(K=>K.y)))},h=aC("net_label"),m=Hj(r||"")+tE*2+uC*r.length+lC,y=cC(t.anchor_side),g=t.anchor_position??{x:t.center.x-y.x*m*h/2,y:t.center.y-y.y*m*h/2},v=ov(0/180*Math.PI),w={minX:Math.min(...s.primitives.flatMap(W=>W.type==="path"?W.points.map(K=>K.x):[])),maxX:Math.max(...s.primitives.flatMap(W=>W.type==="path"?W.points.map(K=>K.x):[])),minY:Math.min(...s.primitives.flatMap(W=>W.type==="path"?W.points.map(K=>K.y):[])),maxY:Math.max(...s.primitives.flatMap(W=>W.type==="path"?W.points.map(K=>K.y):[]))},T=s.ports?.[0]?{x:s.ports[0].x,y:s.ports[0].y}:{x:w.minX,y:(w.minY+w.maxY)/2},N=Yt(v,T),R=cs(Cs(g.x-N.x,g.y-N.y),v,kg(1)),[P,M]=Yt(cs(e,R),[d.minX,d.minY]),[I,A]=Yt(cs(e,R),[d.maxX,d.maxY]),$=Math.abs(A-M),k=Math.min(M,A),V=Math.abs(I-P),X=Math.min(P,I);o.push({name:"rect",type:"element",value:"",attributes:{class:"component-overlay",x:X.toString(),y:k.toString(),width:V.toString(),height:$.toString(),fill:"transparent"},children:[]});for(const W of a){const K=W.points.map((te,se)=>{const[de,be]=Yt(cs(e,R),[te.x,te.y]);return`${se===0?"M":"L"} ${de} ${be}`}).join(" ");o.push({name:"path",type:"element",attributes:{d:K+(W.closed?" Z":""),stroke:n.schematic.component_outline,fill:"none","stroke-width":`${hb(e)}px`,"stroke-linecap":"round"},value:"",children:[]})}for(const W of c){const K=Yt(cs(e,R),W);let te=W.text;te==="{REF}"?te=r||"":te==="{VAL}"&&(te=""),Math.abs(e.a);const se={x:K.x,y:K.y};o.push({name:"text",type:"element",attributes:{x:se.x.toString(),y:se.y.toString(),fill:n.schematic.label_local,"font-family":"sans-serif","text-anchor":Uyn[W.anchor],"dominant-baseline":$yn[W.anchor],"font-size":`${l3(e,"reference_designator")}px`,...i&&te===r?{style:"text-decoration: overline;"}:{}},children:[{type:"text",value:te,name:"",attributes:{},children:[]}],value:""})}for(const W of u){const K=Yt(cs(e,R),W),te=cs(e,R).a;o.push({name:"rect",type:"element",attributes:{x:K.x.toString(),y:K.y.toString(),width:(W.width*te).toString(),height:(W.height*te).toString(),fill:"red"},value:"",children:[]})}for(const W of l){const K=Yt(cs(e,R),W),te=cs(e,R).a;o.push({name:"circle",type:"element",attributes:{cx:K.x.toString(),cy:K.y.toString(),r:(W.radius*te).toString(),fill:"none",stroke:n.schematic.component_outline,"stroke-width":`${hb(e)}px`},value:"",children:[]})}return o},sgn=({schNetLabel:t,realToScreenTransform:e,colorMap:n})=>{if(!t.text)return[];const i=t.text;if(t.symbol_name)return ogn({schNetLabel:t,realToScreenTransform:e,colorMap:n});const r=[],o=l3(e,"net_label"),s=aC("net_label"),a=Hj(i||""),c=Yt(e,t.center),l=cC(t.anchor_side),u={...l};u.y*=-1;const d=a+tE*2+uC*i.length+lC,h=t.anchor_position?Yt(e,t.anchor_position):{x:c.x-u.x*d*o/2,y:c.y-u.y*d*o/2},f=t.anchor_position??{x:t.center.x-l.x*d*s/2,y:t.center.y-l.y*d*s/2},m={left:0,top:-90,bottom:90,right:180}[t.anchor_side],y=[{x:0,y:0},{x:tE,y:.6},{x:tE*2+lC+uC*i.length+a,y:.6},{x:tE*2+lC+uC*i.length+a,y:-.6},{x:tE,y:-.6}].map(T=>Yt(cs(e,Cs(f.x,f.y),kg(s),ov(m/180*Math.PI)),T)),g=`
5325
5325
  M ${y[0].x},${y[0].y}
5326
5326
  L ${y[1].x},${y[1].y}
@@ -5364,7 +5364,7 @@ ${A}
5364
5364
  \`\`\`
5365
5365
  ${P.type}: ${k}
5366
5366
  \`\`\``}m(I,U)},children:[he.jsx(jme,{className:"rf-w-4 rf-h-4"}),"Report Issue"]})]})]})};function zgn(n,e,t){const{transform:i,shouldDrawErrors:r}=t;if(!r)return[];const{pcb_port_ids:o}=n,s=e.find(h=>h.type==="pcb_port"&&h.pcb_port_id===o?.[0]),a=e.find(h=>h.type==="pcb_port"&&h.pcb_port_id===o?.[1]);if(!s||!a){const f=n.message?.match(/pcb_via\[#?(pcb_via_\d+)\]/)?.[1],m=e.find(y=>y.type==="pcb_via"&&y.pcb_via_id===f);if(m&&m.type==="pcb_via")return Fgn(n,m,t);if(n.center){const y=Yt(i,{x:n.center.x,y:n.center.y});return[{name:"rect",type:"element",attributes:{x:(y.x-5).toString(),y:(y.y-5).toString(),width:"10",height:"10",fill:"red",transform:`rotate(45 ${y.x} ${y.y})`},children:[],value:""},{name:"text",type:"element",attributes:{x:y.x.toString(),y:(y.y-15).toString(),fill:"red","font-family":"sans-serif","font-size":"12","text-anchor":"middle"},children:[{type:"text",value:n.message||"Pcb Trace Error",name:"",attributes:{},children:[]}],value:""}]}else return[]}const c=Yt(i,{x:s.x,y:s.y}),l=Yt(i,{x:a.x,y:a.y}),u={x:(c.x+l.x)/2,y:(c.y+l.y)/2};return isNaN(c.x)||isNaN(c.y)||isNaN(l.x)||isNaN(l.y)||isNaN(u.x)||isNaN(u.y)?[]:[{name:"line",type:"element",attributes:{x1:c.x.toString(),y1:c.y.toString(),x2:u.x.toString(),y2:u.y.toString(),stroke:"red","stroke-width":"1.5","stroke-dasharray":"2,2"},children:[],value:""},{name:"line",type:"element",attributes:{x1:u.x.toString(),y1:u.y.toString(),x2:l.x.toString(),y2:l.y.toString(),stroke:"red","stroke-width":"1.5","stroke-dasharray":"2,2"},children:[],value:""},{name:"rect",type:"element",attributes:{x:(u.x-5).toString(),y:(u.y-5).toString(),width:"10",height:"10",fill:"red",transform:`rotate(45 ${u.x} ${u.y})`},children:[],value:""},{name:"text",type:"element",attributes:{x:u.x.toString(),y:(u.y-15).toString(),fill:"red","font-family":"sans-serif","font-size":"12","text-anchor":"middle"},children:[{type:"text",value:n.message||"Pcb Trace Error",name:"",attributes:{},children:[]}],value:""}]}function Fgn(n,e,t){const{transform:i}=t;if(n.center&&e){const r=Yt(i,{x:n.center.x,y:n.center.y}),o=Yt(i,{x:e.x,y:e.y}),s=o.x-r.x,a=o.y-r.y,c=Math.sqrt(s*s+a*a),l=Math.atan2(a,s)*180/Math.PI,d=c+10*2,h=20,f=(r.x+o.x)/2,m=(r.y+o.y)/2;return[{name:"rect",type:"element",attributes:{x:(f-d/2).toString(),y:(m-h/2).toString(),width:d.toString(),height:h.toString(),fill:"none",stroke:"red","stroke-width":"1","stroke-dasharray":"3,2",transform:`rotate(${l} ${f} ${m})`},children:[],value:""},{name:"rect",type:"element",attributes:{x:(f-5).toString(),y:(m-5).toString(),width:"10",height:"10",fill:"red",transform:`rotate(45 ${f} ${m})`},children:[],value:""},{name:"text",type:"element",attributes:{x:f.toString(),y:(m-h/2-5).toString(),fill:"red","font-family":"sans-serif","font-size":"12","text-anchor":"middle"},children:[{type:"text",value:n.message||"Pcb Trace Error",name:"",attributes:{},children:[]}],value:""}]}return[]}function $gn(n,e){const{transform:t,layer:i}=e;if(!n.route||!Array.isArray(n.route))return[];const r=n.route[0],o=n.route[n.route.length-1],s=r.x===o.x&&r.y===o.y,a=n.route.slice(0,s?-1:void 0).map((c,l)=>{const[u,d]=Yt(t,[c.x,c.y]);return l===0?`M ${u} ${d}`:`L ${u} ${d}`}).join(" ")+(s?" Z":"");return[{name:"path",type:"element",attributes:{class:"pcb-fabrication-note-path",stroke:n.color||"rgba(255,255,255,0.5)",fill:"none",d:a,"stroke-width":(n.stroke_width*Math.abs(t.a)).toString(),"data-pcb-component-id":n.pcb_component_id,"data-pcb-fabrication-note-path-id":n.pcb_fabrication_note_path_id},value:"",children:[]}]}function Bgn(n,e){const{transform:t,layer:i}=e,{anchor_position:r,anchor_alignment:o,text:s,font_size:a=1,layer:c="top",color:l}=n;if(i&&c!==i)return[];if(!r||typeof r.x!="number"||typeof r.y!="number")return console.error("Invalid anchor_position:",r),[];const[u,d]=Yt(t,[r.x,r.y]),h=a*Math.abs(t.a),f=ls(Rs(u,d),sv(Math.PI/180));return[{name:"text",type:"element",attributes:{x:"0",y:"0","font-family":"Arial, sans-serif","font-size":h.toString(),"text-anchor":"middle","dominant-baseline":"central",transform:iw(f),class:"pcb-fabrication-note-text",fill:l||"rgba(255,255,255,0.5)"},children:[{type:"text",value:s,name:"",attributes:{},children:[]}],value:""}]}function Ugn(n,e){const{transform:t,colorMap:i}=e,[r,o]=Yt(t,[n.x,n.y]);if(n.shape==="pill"){const s=n.outer_width*Math.abs(t.a),a=n.outer_height*Math.abs(t.a),c=n.hole_width*Math.abs(t.a),l=n.hole_height*Math.abs(t.a),u=s/2,d=c/2,h=a-s,f=n.ccw_rotation||0,m=f?`translate(${r} ${o}) rotate(${-f})`:`translate(${r} ${o})`,y=f?`translate(${r} ${o}) rotate(${-f})`:`translate(${r} ${o})`;return[{name:"g",type:"element",children:[{name:"path",type:"element",attributes:{class:"pcb-hole-outer",fill:i.copper.top,d:`M${-u},${-h/2} v${h} a${u},${u} 0 0 0 ${s},0 v-${h} a${u},${u} 0 0 0 -${s},0 z`,transform:m},value:"",children:[]},{name:"path",type:"element",attributes:{class:"pcb-hole-inner",fill:i.drill,d:`M${-d},${-(l-c)/2} v${l-c} a${d},${d} 0 0 0 ${c},0 v-${l-c} a${d},${d} 0 0 0 -${c},0 z`,transform:y},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="circle"){const s=n.outer_diameter*Math.abs(t.a),a=n.outer_diameter*Math.abs(t.a),c=n.hole_diameter*Math.abs(t.a),l=n.hole_diameter*Math.abs(t.a),u=Math.min(s,a)/2,d=Math.min(c,l)/2;return[{name:"g",type:"element",children:[{name:"circle",type:"element",attributes:{class:"pcb-hole-outer",fill:i.copper.top,cx:r.toString(),cy:o.toString(),r:u.toString()},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"pcb-hole-inner",fill:i.drill,cx:r.toString(),cy:o.toString(),r:d.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="circular_hole_with_rect_pad"){const s=n,a=n.hole_diameter*Math.abs(t.a),c=n.rect_pad_width*Math.abs(t.a),l=n.rect_pad_height*Math.abs(t.a),u=(n.rect_border_radius??0)*Math.abs(t.a),d=a/2,[h,f]=Yt(t,[s.x+(s.hole_offset_x??0),s.y+(s.hole_offset_y??0)]);return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"pcb-hole-outer-pad",fill:i.copper.top,x:(r-c/2).toString(),y:(o-l/2).toString(),width:c.toString(),height:l.toString(),...u?{rx:u.toString(),ry:u.toString()}:{}},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"pcb-hole-inner",fill:i.drill,cx:h.toString(),cy:f.toString(),r:d.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="pill_hole_with_rect_pad"){const s=n,a=s.rect_pad_width*Math.abs(t.a),c=s.rect_pad_height*Math.abs(t.a),l=(s.rect_border_radius??0)*Math.abs(t.a),u=s.hole_height*Math.abs(t.a),d=s.hole_width*Math.abs(t.a),h=s,f=h.hole_offset_x??0,m=h.hole_offset_y??0,[y,g]=Yt(t,[s.x+f,s.y+m]),b=Math.min(u,d)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"pcb-hole-outer-pad",fill:i.copper.top,x:(r-a/2).toString(),y:(o-c/2).toString(),width:a.toString(),height:c.toString(),...l?{rx:l.toString(),ry:l.toString()}:{}},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"pcb-hole-inner",fill:i.drill,x:(y-d/2).toString(),y:(g-u/2).toString(),width:d.toString(),height:u.toString(),rx:b.toString(),ry:b.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="rotated_pill_hole_with_rect_pad"){const s=n,a=s.rect_pad_width*Math.abs(t.a),c=s.rect_pad_height*Math.abs(t.a),l=(s.rect_border_radius??0)*Math.abs(t.a),u=s.hole_height*Math.abs(t.a),d=s.hole_width*Math.abs(t.a),h=s,f=h.hole_offset_x??0,m=h.hole_offset_y??0,[y,g]=Yt(t,[s.x+f,s.y+m]),b=Math.min(u,d)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"pcb-hole-outer-pad",fill:i.copper.top,x:(-a/2).toString(),y:(-c/2).toString(),width:a.toString(),height:c.toString(),transform:`translate(${r} ${o}) rotate(${-s.rect_ccw_rotation})`,...l?{rx:l.toString(),ry:l.toString()}:{}},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"pcb-hole-inner",fill:i.drill,x:(-d/2).toString(),y:(-u/2).toString(),width:d.toString(),height:u.toString(),rx:b.toString(),ry:b.toString(),transform:`translate(${y} ${g}) rotate(${-s.hole_ccw_rotation})`},value:"",children:[]}],value:"",attributes:{}}]}return[]}function jgn(n,e){const{transform:t,layer:i,colorMap:r}=e;if(!n.route||!Array.isArray(n.route))return[];let o=n.route.map((u,d)=>{const[h,f]=Yt(t,[u.x,u.y]);return d===0?`M ${h} ${f}`:`L ${h} ${f}`}).join(" ");const s=n.route[0],a=n.route[n.route.length-1];s&&a&&s.x===a.x&&s.y===a.y&&(o+=" Z");const c=n.layer||"top";if(i&&c!==i)return[];const l=c==="bottom"?r.silkscreen.bottom:r.silkscreen.top;return[{name:"path",type:"element",attributes:{class:`pcb-silkscreen pcb-silkscreen-${c}`,d:o,fill:"none",stroke:l,"stroke-width":(n.stroke_width*Math.abs(t.a)).toString(),"stroke-linecap":"round","stroke-linejoin":"round","data-pcb-component-id":n.pcb_component_id,"data-pcb-silkscreen-path-id":n.pcb_silkscreen_path_id},value:"",children:[]}]}function Hgn(n,e){const{transform:t,layer:i,colorMap:r}=e,{anchor_position:o,text:s,font_size:a=1,layer:c="top",ccw_rotation:l=0,anchor_alignment:u="center"}=n;if(i&&c!==i)return[];if(!o||typeof o.x!="number"||typeof o.y!="number")return console.error("Invalid anchor_position:",o),[];const[d,h]=Yt(t,[o.x,o.y]),f=a*Math.abs(t.a);let m="middle",y="central";const g=0,b=0;switch(u){case"top_left":m="start",y="text-before-edge";break;case"top_center":m="middle",y="text-before-edge";break;case"top_right":m="end",y="text-before-edge";break;case"center_left":m="start",y="central";break;case"center_right":m="end",y="central";break;case"bottom_left":m="start",y="text-after-edge";break;case"bottom_center":m="middle",y="text-after-edge";break;case"bottom_right":m="end",y="text-after-edge";break;case"center":default:m="middle",y="central";break}const v=ls(Rs(d,h),sv(-l*Math.PI/180),...c==="bottom"?[kg(-1,1)]:[]),w=c==="bottom"?r.silkscreen.bottom:r.silkscreen.top,T=s.split(`
5367
- `),N=T.length===1?[{type:"text",value:s,name:"",attributes:{},children:[]}]:T.map((P,M)=>({type:"element",name:"tspan",value:"",attributes:{x:"0",...M>0?{dy:f.toString()}:{}},children:[{type:"text",value:P,name:"",attributes:{},children:[]}]}));return[{name:"text",type:"element",attributes:{x:"0",y:"0",dx:g.toString(),dy:b.toString(),fill:w,"font-family":"Arial, sans-serif","font-size":f.toString(),"text-anchor":m,"dominant-baseline":y,transform:iw(v),class:`pcb-silkscreen-text pcb-silkscreen-${c}`,"data-pcb-silkscreen-text-id":n.pcb_component_id,stroke:"none"},children:N,value:""}]}function Vgn(n,e){const{transform:t,layer:i,colorMap:r}=e,{center:o,width:s,height:a,layer:c="top",pcb_silkscreen_rect_id:l,stroke_width:u,is_filled:d,has_stroke:h,is_stroke_dashed:f}=n;if(i&&c!==i)return[];if(!o||typeof o.x!="number"||typeof o.y!="number"||typeof s!="number"||typeof a!="number")return console.error("Invalid rectangle data:",{center:o,width:s,height:a}),[];const[m,y]=Yt(t,[o.x,o.y]),g=s*Math.abs(t.a),b=a*Math.abs(t.d),v=u*Math.abs(t.a),w=c==="bottom"?r.silkscreen.bottom:r.silkscreen.top,T={x:(m-g/2).toString(),y:(y-b/2).toString(),width:g.toString(),height:b.toString(),class:`pcb-silkscreen-rect pcb-silkscreen-${c}`,"data-pcb-silkscreen-rect-id":l};T.fill=d?w:"none";let N;if(h===void 0?N=v>0:N=h,N){if(T.stroke=w,T["stroke-width"]=v.toString(),f){const P=.1*Math.abs(t.a),M=.05*Math.abs(t.a);T["stroke-dasharray"]=`${P} ${M}`}}else T.stroke="none";return[{name:"rect",type:"element",attributes:T,value:"",children:[]}]}function Ggn(n,e){const{transform:t,layer:i,colorMap:r}=e,{center:o,radius:s,layer:a="top",pcb_silkscreen_circle_id:c,stroke_width:l=1}=n;if(i&&a!==i)return[];if(!o||typeof o.x!="number"||typeof o.y!="number"||typeof s!="number")return console.error("Invalid PCB Silkscreen Circle data:",{center:o,radius:s}),[];const[u,d]=Yt(t,[o.x,o.y]),h=s*Math.abs(t.a),f=l*Math.abs(t.a),m=a==="bottom"?r.silkscreen.bottom:r.silkscreen.top;return[{name:"circle",type:"element",attributes:{cx:u.toString(),cy:d.toString(),r:h.toString(),class:`pcb-silkscreen-circle pcb-silkscreen-${a}`,stroke:m,"stroke-width":f.toString(),"data-pcb-silkscreen-circle-id":c},value:"",children:[]}]}function Ygn(n,e){const{transform:t,layer:i,colorMap:r}=e,{x1:o,y1:s,x2:a,y2:c,stroke_width:l,layer:u="top",pcb_silkscreen_line_id:d}=n;if(i&&u!==i)return[];if(typeof o!="number"||typeof s!="number"||typeof a!="number"||typeof c!="number")return console.error("Invalid coordinates:",{x1:o,y1:s,x2:a,y2:c}),[];const[h,f]=Yt(t,[o,s]),[m,y]=Yt(t,[a,c]),g=l*Math.abs(t.a),b=u==="bottom"?r.silkscreen.bottom:r.silkscreen.top;return[{name:"line",type:"element",attributes:{x1:h.toString(),y1:f.toString(),x2:m.toString(),y2:y.toString(),stroke:b,"stroke-width":g.toString(),class:`pcb-silkscreen-line pcb-silkscreen-${u}`,"data-pcb-silkscreen-line-id":d},value:"",children:[]}]}function qgn(n){const e=[];for(let t=0;t<n.length-1;t++)e.push([n[t],n[t+1]]);return e}var ex={copper:{top:"rgb(200, 52, 52)",bottom:"rgb(77, 127, 196)"},soldermask:{top:"rgb(200, 52, 52)",bottom:"rgb(77, 127, 196)"},drill:"#FF26E2",silkscreen:{top:"#f2eda1",bottom:"#5da9e9"},boardOutline:"rgba(255, 255, 255, 0.5)",debugComponent:{fill:null,stroke:null}};ex.drill,ex.silkscreen.top,ex.silkscreen.bottom,ex.copper.top,ex.copper.bottom;function vM(n,e=ex){return e.copper[n]??"white"}var Xgn={bottom:"rgb(105, 105, 105)",top:"rgb(105, 105, 105)"};function fH(n){return Xgn[n]??"rgb(105, 105, 105)"}function Wgn(n,e){const{transform:t,layer:i,colorMap:r,renderSolderMask:o}=e;if(!n.route||!Array.isArray(n.route)||n.route.length<2)return[];const s=qgn(n.route),a=[];for(const[c,l]of s){const u=Yt(t,[c.x,c.y]),d=Yt(t,[l.x,l.y]),h="layer"in c?c.layer:"layer"in l?l.layer:null;if(!h||i&&h!==i)continue;const f=vM(h,r),m=r.soldermask[h]??f,y="width"in c?c.width:"width"in l?l.width:null,g=y?(y*Math.abs(t.a)).toString():"0.3";if(o){const b={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-trace",stroke:f,fill:"none",d:`M ${u[0]} ${u[1]} L ${d[0]} ${d[1]}`,"stroke-width":g,"stroke-linecap":"round","stroke-linejoin":"round","shape-rendering":"crispEdges","data-layer":h}},v={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask",stroke:m,fill:"none",d:`M ${u[0]} ${u[1]} L ${d[0]} ${d[1]}`,"stroke-width":g,"stroke-linecap":"round","stroke-linejoin":"round","shape-rendering":"crispEdges","data-layer":h}};a.push(v,b)}else{const b={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-trace",stroke:m,fill:"none",d:`M ${u[0]} ${u[1]} L ${d[0]} ${d[1]}`,"stroke-width":g,"stroke-linecap":"round","stroke-linejoin":"round","shape-rendering":"crispEdges","data-layer":h}};a.push(b)}}return a.sort((c,l)=>{const u=c.attributes["data-layer"],d=l.attributes["data-layer"];return u==="bottom"&&d!=="bottom"?-1:u==="top"&&d!=="top"?1:0}),a}function Zgn(n,e){const{transform:t,layer:i,colorMap:r}=e;if(i&&n.layer!==i)return[];const o=!!n?.is_covered_with_solder_mask,s=r.soldermask[n.layer]??r.soldermask.top;if(n.shape==="rect"||n.shape==="rotated_rect"){const a=n.width*Math.abs(t.a),c=n.height*Math.abs(t.d),[l,u]=Yt(t,[n.x,n.y]),d=(n.rect_border_radius??0)*Math.abs(t.a);if(n.shape==="rotated_rect"&&n.ccw_rotation){const m={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:vM(n.layer,r),x:(-a/2).toString(),y:(-c/2).toString(),width:a.toString(),height:c.toString(),transform:`translate(${l} ${u}) rotate(${-n.ccw_rotation})`,"data-layer":n.layer,...d?{rx:d.toString(),ry:d.toString()}:{}}};if(!o)return[m];const y={name:m.name,type:m.type,value:"",children:[],attributes:{...m.attributes,class:"pcb-solder-mask",fill:s}};return[m,y]}const h={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:vM(n.layer,r),x:(l-a/2).toString(),y:(u-c/2).toString(),width:a.toString(),height:c.toString(),"data-layer":n.layer,...d?{rx:d.toString(),ry:d.toString()}:{}}};if(!o)return[h];const f={name:h.name,type:h.type,value:"",children:[],attributes:{...h.attributes,class:"pcb-solder-mask",fill:s}};return[h,f]}if(n.shape==="pill"){const a=n.width*Math.abs(t.a),c=n.height*Math.abs(t.d),l=n.radius*Math.abs(t.a),[u,d]=Yt(t,[n.x,n.y]),h={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:vM(n.layer,r),x:(u-a/2).toString(),y:(d-c/2).toString(),width:a.toString(),height:c.toString(),rx:l.toString(),ry:l.toString(),"data-layer":n.layer}};if(!o)return[h];const f={name:h.name,type:h.type,value:"",children:[],attributes:{...h.attributes,class:"pcb-solder-mask",fill:s}};return[h,f]}if(n.shape==="circle"){const a=n.radius*Math.abs(t.a),[c,l]=Yt(t,[n.x,n.y]),u={name:"circle",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:vM(n.layer,r),cx:c.toString(),cy:l.toString(),r:a.toString(),"data-layer":n.layer}};if(!o)return[u];const d={name:u.name,type:u.type,value:"",children:[],attributes:{...u.attributes,class:"pcb-solder-mask",fill:s}};return[u,d]}if(n.shape==="polygon"){const a=(n.points??[]).map(u=>Yt(t,[u.x,u.y])),c={name:"polygon",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:vM(n.layer,r),points:a.map(u=>u.join(",")).join(" "),"data-layer":n.layer}};if(!o)return[c];const l={name:c.name,type:c.type,value:"",children:[],attributes:{...c.attributes,class:"pcb-solder-mask",fill:s}};return[c,l]}return[]}function zKe(n,e){const{transform:t,colorMap:i}=e,{width:r,height:o,center:s,outline:a}=n;let c;if(a&&Array.isArray(a)&&a.length>=3)c=a.map((l,u)=>{const[d,h]=Yt(t,[l.x,l.y]);return u===0?`M ${d} ${h}`:`L ${d} ${h}`}).join(" ");else{const l=r/2,u=o/2,d=Yt(t,[s.x-l,s.y-u]),h=Yt(t,[s.x+l,s.y-u]),f=Yt(t,[s.x+l,s.y+u]),m=Yt(t,[s.x-l,s.y+u]);c=`M ${d[0]} ${d[1]} L ${h[0]} ${h[1]} L ${f[0]} ${f[1]} L ${m[0]} ${m[1]}`}return c+=" Z",[{name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-board",d:c,fill:"none",stroke:i.boardOutline,"stroke-width":(.1*Math.abs(t.a)).toString()}}]}function Kgn(n,e){const{transform:t,colorMap:i}=e,[r,o]=Yt(t,[n.x,n.y]),s=n.outer_diameter*Math.abs(t.a),a=n.outer_diameter*Math.abs(t.a),c=n.hole_diameter*Math.abs(t.a),l=n.hole_diameter*Math.abs(t.a),u=Math.min(s,a)/2,d=Math.min(c,l)/2;return{name:"g",type:"element",children:[{name:"circle",type:"element",attributes:{class:"pcb-hole-outer",fill:i.copper.top,cx:r.toString(),cy:o.toString(),r:u.toString()}},{name:"circle",type:"element",attributes:{class:"pcb-hole-inner",fill:i.drill,cx:r.toString(),cy:o.toString(),r:d.toString()}}]}}function Qgn(n,e){const{transform:t,colorMap:i}=e,[r,o]=Yt(t,[n.x,n.y]);if(n.hole_shape==="circle"||n.hole_shape==="square"){const s=n.hole_diameter*Math.abs(t.a),a=s/2;return n.hole_shape==="circle"?[{name:"circle",type:"element",attributes:{class:"pcb-hole",cx:r.toString(),cy:o.toString(),r:a.toString(),fill:i.drill},children:[],value:""}]:[{name:"rect",type:"element",attributes:{class:"pcb-hole",x:(r-a).toString(),y:(o-a).toString(),width:s.toString(),height:s.toString(),fill:i.drill},children:[],value:""}]}if(n.hole_shape==="oval"){const s=n.hole_width*Math.abs(t.a),a=n.hole_height*Math.abs(t.a),c=s/2,l=a/2;return[{name:"ellipse",type:"element",attributes:{class:"pcb-hole",cx:r.toString(),cy:o.toString(),rx:c.toString(),ry:l.toString(),fill:i.drill},children:[],value:""}]}return[]}var Jgn=(n,e)=>{const t=ta(e).pcb_smtpad.get(n);if(t&&"x"in t&&"y"in t)return{x:t.x,y:t.y};const i=ta(e).pcb_plated_hole.get(n);return i&&"x"in i&&"y"in i?{x:i.x,y:i.y}:null},e1n=(n,e,t,i)=>{const r=t.getIdsConnectedToNet(e);let o=null,s=1/0;for(const a of r){const c=Jgn(a,i);if(c){const l=n.x-c.x,u=n.y-c.y,d=Math.sqrt(l*l+u*u);d>0&&d<s&&(s=d,o=c)}}return o};function t1n(n,e){const{transform:t}=e,i=e6(n),r=n.filter(c=>c.type==="pcb_port"),o=n.filter(c=>c.type==="source_trace"),s=[];r.forEach((c,l)=>{const u=c.pcb_port_id;if(!u)return;const d=i.getNetConnectedToId(u);if(!d)return;let h=!1;const f=ta(n).source_port.getWhere({pcb_port_id:u});if(f&&f.source_port_id){const g=f.source_port_id;for(const b of o)if(Array.isArray(b.connected_source_port_ids)&&b.connected_source_port_ids.includes(g)&&Array.isArray(b.connected_source_net_ids)&&b.connected_source_net_ids.length>0){h=!0;break}}const m={x:c.x,y:c.y},y=e1n(m,d,i,n);y&&s.push({key:`${u}-${l}`,startPoint:m,endPoint:y,isInNet:h})});const a=[];for(const c of s){const l=Yt(t,[c.startPoint.x,c.startPoint.y]),u=Yt(t,[c.endPoint.x,c.endPoint.y]),d={x1:l[0].toString(),y1:l[1].toString(),x2:u[0].toString(),y2:u[1].toString(),stroke:"white","stroke-width":"1","stroke-dasharray":"6,6"};a.push({name:"line",type:"element",attributes:d,value:"",children:[]})}return a}function n1n(n,e){const{transform:t,colorMap:i}=e;if(n.shape==="rect"){const r=n,[o,s]=Yt(t,[r.center.x,r.center.y]),a=r.width*Math.abs(t.a),c=r.height*Math.abs(t.d),l=-(r.rotation??0);return[{name:"rect",type:"element",attributes:{class:"pcb-cutout pcb-cutout-rect",x:(-a/2).toString(),y:(-c/2).toString(),width:a.toString(),height:c.toString(),fill:i.drill,transform:iw(ls(Rs(o,s),sv(l*Math.PI/180)))},children:[],value:""}]}if(n.shape==="circle"){const r=n,[o,s]=Yt(t,[r.center.x,r.center.y]),a=r.radius*Math.abs(t.a);return[{name:"circle",type:"element",attributes:{class:"pcb-cutout pcb-cutout-circle",cx:o.toString(),cy:s.toString(),r:a.toString(),fill:i.drill},children:[],value:""}]}if(n.shape==="polygon"){const r=n;return!r.points||r.points.length===0?[]:[{name:"polygon",type:"element",attributes:{class:"pcb-cutout pcb-cutout-polygon",points:r.points.map(a=>Yt(t,[a.x,a.y])).map(a=>`${a[0]},${a[1]}`).join(" "),fill:i.drill},children:[],value:""}]}return[]}function FKe(n,e){if(n.length===0)return"";const t=n.map(r=>{const[o,s]=Yt(e,[r.x,r.y]);return{...r,x:o,y:s}});let i=`M ${t[0].x} ${t[0].y}`;for(let r=0;r<t.length;r++){const o=t[r],s=t[(r+1)%t.length];if(o.bulge){if(Math.hypot(s.x-o.x,s.y-o.y)<1e-9)continue;const a=o.bulge,c=s.x-o.x,l=s.y-o.y,u=Math.hypot(c,l),d=Math.abs(u/4/a*(a*a+1)),h=a<0?1:0,f=Math.abs(a)>1?1:0;i+=` A ${d} ${d} 0 ${f} ${h} ${s.x} ${s.y}`}else i+=` L ${s.x} ${s.y}`}return i+=" Z",i}function i1n(n,e){const{transform:t,layer:i,colorMap:r}=e,{layer:o}=n;if(i&&o!==i)return[];const s=vM(o,r),a="0.5";if(n.shape==="rect"){const[c,l]=Yt(t,[n.center.x,n.center.y]),u=n.width*Math.abs(t.a),d=n.height*Math.abs(t.d),h=-(n.rotation??0);return[{name:"rect",type:"element",attributes:{class:"pcb-copper-pour pcb-copper-pour-rect",x:(-u/2).toString(),y:(-d/2).toString(),width:u.toString(),height:d.toString(),fill:s,"fill-opacity":a,transform:iw(ls(Rs(c,l),sv(h*Math.PI/180))),"data-layer":o},children:[],value:""}]}if(n.shape==="polygon")return!n.points||n.points.length===0?[]:[{name:"polygon",type:"element",attributes:{class:"pcb-copper-pour pcb-copper-pour-polygon",points:n.points.map(u=>Yt(t,[u.x,u.y])).map(u=>`${u[0]},${u[1]}`).join(" "),fill:s,"fill-opacity":a,"data-layer":o},children:[],value:""}];if(n.shape==="brep"){const{brep_shape:c}=n;let l=FKe(c.outer_ring.vertices,t);for(const u of c.inner_rings??[])l+=` ${FKe(u.vertices,t)}`;return[{name:"path",type:"element",attributes:{class:"pcb-copper-pour pcb-copper-pour-brep",d:l,fill:s,"fill-rule":"evenodd","fill-opacity":a,"data-layer":o},children:[],value:""}]}return[]}function r1n(n,e){const{transform:t}=e,{center:i,width:r,height:o,rotation:s=0}=n,[a,c]=Yt(t,[i.x,i.y]),l=r*Math.abs(t.a),u=o*Math.abs(t.d),d=`translate(${a}, ${c}) rotate(${-s}) scale(1, -1)`;return!e.colorMap.debugComponent?.fill&&!e.colorMap.debugComponent?.stroke?[]:[{name:"g",type:"element",attributes:{transform:d},children:[{name:"rect",type:"element",attributes:{class:"pcb-component",x:(-l/2).toString(),y:(-u/2).toString(),width:l.toString(),height:u.toString(),fill:e.colorMap.debugComponent.fill??"transparent",stroke:e.colorMap.debugComponent.stroke??"transparent"}}],value:""}]}function mC(n){return n.find(t=>t.type==="project_software_metadata"||t.type==="source_project_metadata")?.software_used_string}var o1n={version:"0.0.200"},_C=o1n.version,$Ke=["pcb_trace_error","pcb_plated_hole","pcb_fabrication_note_text","pcb_fabrication_note_path","pcb_silkscreen_text","pcb_silkscreen_path","pcb_via","pcb_cutout","pcb_copper_pour","pcb_smtpad","pcb_trace","pcb_component","pcb_board"];function P_e(n,e){const t=e?.drawPaddingOutsideBoard??!0,i=e?.layer,r=e?.colorOverrides,o={copper:{top:r?.copper?.top??ex.copper.top,bottom:r?.copper?.bottom??ex.copper.bottom},drill:r?.drill??ex.drill,silkscreen:{top:r?.silkscreen?.top??ex.silkscreen.top,bottom:r?.silkscreen?.bottom??ex.silkscreen.bottom},boardOutline:r?.boardOutline??ex.boardOutline,soldermask:{top:r?.soldermask?.top??ex.soldermask.top,bottom:r?.soldermask?.bottom??ex.soldermask.bottom},debugComponent:{fill:r?.debugComponent?.fill??ex.debugComponent.fill,stroke:r?.debugComponent?.stroke??ex.debugComponent.stroke}};let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY,u=Number.POSITIVE_INFINITY,d=Number.POSITIVE_INFINITY,h=Number.NEGATIVE_INFINITY,f=Number.NEGATIVE_INFINITY;for(const Ne of n)if(Ne.type==="pcb_board")Ne.outline&&Array.isArray(Ne.outline)&&Ne.outline.length>=3?(Ee(Ne.outline),Re(Ne.outline)):"center"in Ne&&"width"in Ne&&"height"in Ne&&(oe(Ne.center,Ne.width,Ne.height),pe(Ne.center,Ne.width,Ne.height));else if("x"in Ne&&"y"in Ne)oe({x:Ne.x,y:Ne.y},0,0);else if(Ne.type==="pcb_smtpad"){const le=Ne;le.shape==="rect"||le.shape==="rotated_rect"||le.shape==="pill"?oe({x:le.x,y:le.y},le.width,le.height):le.shape==="circle"?oe({x:le.x,y:le.y},le.radius*2,le.radius*2):le.shape==="polygon"&&Oe(le.points)}else"route"in Ne?Oe(Ne.route):Ne.type==="pcb_silkscreen_text"||Ne.type==="pcb_silkscreen_rect"||Ne.type==="pcb_silkscreen_circle"||Ne.type==="pcb_silkscreen_line"?Ve(Ne):Ne.type==="pcb_copper_pour"&&(Ne.shape==="rect"?oe(Ne.center,Ne.width,Ne.height):Ne.shape==="polygon"&&Oe(Ne.points));const m=t?1:0,y=t||!Number.isFinite(u)?s:u,g=t||!Number.isFinite(d)?a:d,b=t||!Number.isFinite(h)?c:h,v=t||!Number.isFinite(f)?l:f,w=b-y+2*m,T=v-g+2*m;let N=e?.width??800,R=e?.height??600;if(e?.matchBoardAspectRatio){const Ne=h-u,le=f-d;if(Ne>0&&le>0){const Se=Ne/le;e?.width&&!e?.height?R=e.width/Se:e?.height&&!e?.width?N=e.height*Se:R=N/Se}}const P=[];for(const Ne of n)"route"in Ne&&Ne.route!==void 0&&P.push(Ne.route);const M=N/w,I=R/T,A=Math.min(M,I),U=(N-w*A)/2,k=(R-T*A)/2,V=ls(Rs(U-y*A+m*A,R-k+g*A-m*A),kg(A,-A)),Y={transform:V,layer:i,shouldDrawErrors:e?.shouldDrawErrors,drawPaddingOutsideBoard:t,colorMap:o,renderSolderMask:e?.renderSolderMask};function W(Ne){if(Ne.type==="pcb_smtpad")return Ne.layer==="top"||Ne.layer==="bottom"?Ne.layer:void 0;if(Ne.type==="pcb_trace")for(const le of Ne.route??[]){const Se="layer"in le&&le.layer||"from_layer"in le&&le.from_layer||"to_layer"in le&&le.to_layer||void 0;if(Se==="top"||Se==="bottom")return Se}}function K(Ne){return Ne.type==="pcb_trace"||Ne.type==="pcb_smtpad"}let ee=n.sort((Ne,le)=>{const Se=W(Ne),xe=W(le);if(K(Ne)&&K(le)&&Se!==xe){if(Se==="top")return 1;if(xe==="top"||Se==="bottom")return-1;if(xe==="bottom")return 1}return($Ke.indexOf(le.type)??9999)-($Ke.indexOf(Ne.type)??9999)}).flatMap(Ne=>s1n({elm:Ne,circuitJson:n,ctx:Y}));for(const Ne of n)if("stroke_width"in Ne){String(A*Ne.stroke_width);break}if(e?.shouldDrawRatsNest){const Ne=t1n(n,Y);ee=ee.concat(Ne)}const ae=[{name:"style",type:"element",value:"",attributes:{},children:[{type:"text",value:"",name:"",attributes:{},children:[]}]},{name:"rect",type:"element",value:"",attributes:{class:"boundary",x:"0",y:"0",fill:e?.backgroundColor??"#000",width:N.toString(),height:R.toString()},children:[]}];t&&ae.push(a1n(V,s,a,c,l)),ae.push(...ee);const ue=mC(n),ge=_C,re={name:"svg",type:"element",attributes:{xmlns:"http://www.w3.org/2000/svg",width:N.toString(),height:R.toString(),...ue&&{"data-software-used-string":ue},...e?.includeVersion&&{"data-circuit-to-svg-version":ge}},value:"",children:ae.filter(Ne=>Ne!==null)};try{return Y7(re)}catch(Ne){throw console.error("Error stringifying SVG object:",Ne),Ne}function oe(Ne,le,Se){const xe=le/2,Ye=Se/2;s=Math.min(s,Ne.x-xe),a=Math.min(a,Ne.y-Ye),c=Math.max(c,Ne.x+xe),l=Math.max(l,Ne.y+Ye)}function pe(Ne,le,Se){const xe=le/2,Ye=Se/2;u=Math.min(u,Ne.x-xe),d=Math.min(d,Ne.y-Ye),h=Math.max(h,Ne.x+xe),f=Math.max(f,Ne.y+Ye)}function Ee(Ne){for(const le of Ne)s=Math.min(s,le.x),a=Math.min(a,le.y),c=Math.max(c,le.x),l=Math.max(l,le.y)}function Re(Ne){for(const le of Ne)u=Math.min(u,le.x),d=Math.min(d,le.y),h=Math.max(h,le.x),f=Math.max(f,le.y)}function Oe(Ne){for(const le of Ne)s=Math.min(s,le.x),a=Math.min(a,le.y),c=Math.max(c,le.x),l=Math.max(l,le.y)}function Ve(Ne){if(Ne.type==="pcb_silkscreen_text")oe(Ne.anchor_position,0,0);else if(Ne.type==="pcb_silkscreen_path")Oe(Ne.route);else if(Ne.type==="pcb_silkscreen_rect")oe(Ne.center,Ne.width,Ne.height);else if(Ne.type==="pcb_silkscreen_circle")oe(Ne.center,Ne.radius*2,Ne.radius*2);else if(Ne.type==="pcb_silkscreen_line")oe({x:Ne.x1,y:Ne.y1},0,0),oe({x:Ne.x2,y:Ne.y2},0,0);else if(Ne.type==="pcb_cutout"){const le=Ne;le.shape==="rect"?oe(le.center,le.width,le.height):le.shape==="circle"?oe(le.center,le.radius*2,le.radius*2):le.shape==="polygon"&&Oe(le.points)}}}function s1n({elm:n,circuitJson:e,ctx:t}){switch(n.type){case"pcb_trace_error":return zgn(n,e,t).filter(Boolean);case"pcb_component":return r1n(n,t).filter(Boolean);case"pcb_trace":return Wgn(n,t);case"pcb_copper_pour":return i1n(n,t);case"pcb_plated_hole":return Ugn(n,t).filter(Boolean);case"pcb_hole":return Qgn(n,t);case"pcb_smtpad":return Zgn(n,t);case"pcb_silkscreen_text":return Hgn(n,t);case"pcb_silkscreen_rect":return Vgn(n,t);case"pcb_silkscreen_circle":return Ggn(n,t);case"pcb_silkscreen_line":return Ygn(n,t);case"pcb_fabrication_note_path":return $gn(n,t);case"pcb_fabrication_note_text":return Bgn(n,t);case"pcb_silkscreen_path":return jgn(n,t);case"pcb_board":return t.drawPaddingOutsideBoard?zKe(n,t):[];case"pcb_via":return Kgn(n,t);case"pcb_cutout":return n1n(n,t);default:return[]}}function a1n(n,e,t,i,r){const[o,s]=Yt(n,[e,t]),[a,c]=Yt(n,[i,r]),l=Math.abs(a-o),u=Math.abs(c-s),d=Math.min(o,a),h=Math.min(s,c);return{name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-boundary",fill:"none",stroke:"#fff","stroke-width":"0.3",x:d.toString(),y:h.toString(),width:l.toString(),height:u.toString()}}}var c1n=P_e,mH={fill:"none",stroke:"rgb(0,0,0)",strokeOpacity:"0.8",strokeWidthFactor:.2};function l1n(n,e,t={}){const{width:i,height:r,center:o,outline:s}=n;let a;if(s&&Array.isArray(s)&&s.length>=3)a=s.map((c,l)=>{const[u,d]=Yt(e,[c.x,c.y]);return l===0?`M ${u} ${d}`:`L ${u} ${d}`}).join(" ");else{const c=i/2,l=r/2,u=Yt(e,[o.x-c,o.y-l]),d=Yt(e,[o.x+c,o.y-l]),h=Yt(e,[o.x+c,o.y+l]),f=Yt(e,[o.x-c,o.y+l]);a=`M ${u[0]} ${u[1]} L ${d[0]} ${d[1]} L ${h[0]} ${h[1]} L ${f[0]} ${f[1]}`}return a+=" Z",[{name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-board",d:a,fill:t.fill??mH.fill,stroke:t.stroke??mH.stroke,"stroke-opacity":t.strokeOpacity??mH.strokeOpacity,"stroke-width":((t.strokeWidthFactor??mH.strokeWidthFactor)*Math.abs(e.a)).toString()}}]}var u1n={pin_number:.15,negated_pin_number:.15*.8,reference_designator:.18,manufacturer_number:.18,net_label:.18,error:.05},yC=(n,e)=>e??u1n[n],m3=(n,e,t)=>Math.abs(n.a)*yC(e,t);function d1n(n,e){const{elm:t,portPosition:i,name:r,arePinsInterchangeable:o}=n,{transform:s}=e,{center:a,width:c,height:l,rotation:u=0,layer:d="top"}=t;if(!a||typeof c!="number"||typeof l!="number")return null;const[h,f]=Yt(s,[a.x,a.y]),[m,y]=Yt(s,[i.x,i.y]),g=c*Math.abs(s.a),b=l*Math.abs(s.d),v=y>f,w=m<h,T=[h1n(g,b,u,d),p1n(g,b,r??"")];return o||T.push(f1n(g,b,u,d,v,w)),{name:"g",type:"element",value:"",attributes:{transform:`translate(${h}, ${f}) scale(1, -1)`},children:T}}function h1n(n,e,t,i){const r=n/2,o=e/2;return{name:"path",type:"element",attributes:{class:"assembly-component",d:m1n(r,o,t),"stroke-width":.8.toFixed(2),transform:`rotate(${-t})`,"stroke-dasharray":i==="bottom"?"2,2":""},value:"",children:[]}}function p1n(n,e,t,i){const r=Math.min(n,e),c=Math.min(58,Math.max(3,r*.8)),l=e>n;return{name:"text",type:"element",attributes:{x:"0",y:"0",class:"assembly-component-label","text-anchor":"middle",dy:".10em",style:"pointer-events: none","font-size":`${c.toFixed(1)}px`,transform:l?"rotate(90) scale(1, -1)":"scale(1, -1)"},children:[{type:"text",value:t||"",name:"",attributes:{},children:[]}],value:""}}function f1n(n,e,t,i,r,o){const s=n/2,a=e/2,c=Math.min(s,a)*.5;let l;return r&&o?l=[[-s,-a],[-s+c,-a],[-s,-a+c]]:r&&!o?l=[[s,-a],[s-c,-a],[s,-a+c]]:!r&&o?l=[[-s,a],[-s+c,a],[-s,a-c]]:l=[[s,a],[s-c,a],[s,a-c]],{name:"polygon",type:"element",attributes:{class:"assembly-pin1-indicator",points:l.map(d=>d.join(",")).join(" "),fill:"#333",stroke:"none",transform:`rotate(${-t})`},value:"",children:[]}}function m1n(n,e,t){const i=(a,c,l)=>{const u=Math.PI/180*l,d=Math.cos(u),h=Math.sin(u);return[a*d-c*h,a*h+c*d]};return`${[[-n,-e],[n,-e],[n,e],[-n,e]].map(([a,c])=>i(a,c,t)).map(([a,c],l)=>l===0?`M${a},${c}`:`L${a},${c}`).join(" ")} Z`}var I_e="rgb(190, 190, 190)";function _1n(n,e){const{transform:t}=e,[i,r]=Yt(t,[n.x,n.y]);if(n.hole_shape==="circle"||n.hole_shape==="square"){const o=n.hole_diameter*Math.abs(t.a),s=o/2;return n.hole_shape==="circle"?[{name:"circle",type:"element",attributes:{class:"assembly-hole",cx:i.toString(),cy:r.toString(),r:s.toString(),fill:I_e},children:[],value:""}]:[{name:"rect",type:"element",attributes:{class:"assembly-hole",x:(i-s).toString(),y:(r-s).toString(),width:o.toString(),height:o.toString(),fill:I_e},children:[],value:""}]}if(n.hole_shape==="oval"){const o=n.hole_width*Math.abs(t.a),s=n.hole_height*Math.abs(t.a),a=o/2,c=s/2;return[{name:"ellipse",type:"element",attributes:{class:"assembly-hole",cx:i.toString(),cy:r.toString(),rx:a.toString(),ry:c.toString(),fill:I_e},children:[],value:""}]}return[]}var uN="rgb(210, 210, 210)",dN="rgb(190, 190, 190)";function y1n(n,e){const{transform:t}=e,[i,r]=Yt(t,[n.x,n.y]);if(n.shape==="pill"){const o=n.outer_width*Math.abs(t.a),s=n.outer_height*Math.abs(t.a),a=n.hole_width*Math.abs(t.a),c=n.hole_height*Math.abs(t.a),l=o/2,u=s-o,d=a/2;return[{name:"g",type:"element",children:[{name:"path",type:"element",attributes:{class:"assembly-hole-outer",fill:uN,d:`M${i-l},${r-u/2} v${u} a${l},${l} 0 0 0 ${o},0 v-${u} a${l},${l} 0 0 0 -${o},0 z`},value:"",children:[]},{name:"path",type:"element",attributes:{class:"assembly-hole-inner",fill:dN,d:`M${i-d},${r-(c-a)/2} v${c-a} a${d},${d} 0 0 0 ${a},0 v-${c-a} a${d},${d} 0 0 0 -${a},0 z`},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="circle"){const o=n.outer_diameter*Math.abs(t.a),s=n.outer_diameter*Math.abs(t.a),a=n.hole_diameter*Math.abs(t.a),c=n.hole_diameter*Math.abs(t.a),l=Math.min(o,s)/2,u=Math.min(a,c)/2;return[{name:"g",type:"element",children:[{name:"circle",type:"element",attributes:{class:"assembly-hole-outer",fill:uN,cx:i.toString(),cy:r.toString(),r:l.toString()},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"assembly-hole-inner",fill:dN,cx:i.toString(),cy:r.toString(),r:u.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="circular_hole_with_rect_pad"){const o=n,s=o.hole_diameter*Math.abs(t.a),a=o.rect_pad_width*Math.abs(t.a),c=o.rect_pad_height*Math.abs(t.a),l=(o.rect_border_radius??0)*Math.abs(t.a),u=s/2,[d,h]=Yt(t,[o.x+o.hole_offset_x,o.y+o.hole_offset_y]);return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"assembly-hole-outer-pad",fill:uN,x:(i-a/2).toString(),y:(r-c/2).toString(),width:a.toString(),height:c.toString(),...l?{rx:l.toString(),ry:l.toString()}:{}},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"assembly-hole-inner",fill:dN,cx:d.toString(),cy:h.toString(),r:u.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="pill_hole_with_rect_pad"){const o=n,s=o.rect_pad_width*Math.abs(t.a),a=o.rect_pad_height*Math.abs(t.a),c=(o.rect_border_radius??0)*Math.abs(t.a),l=o.hole_height*Math.abs(t.a),u=o.hole_width*Math.abs(t.a),d=o,h=d.hole_offset_x??0,f=d.hole_offset_y??0,[m,y]=Yt(t,[o.x+h,o.y+f]),g=Math.min(l,u)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"assembly-hole-outer-pad",fill:uN,x:(i-s/2).toString(),y:(r-a/2).toString(),width:s.toString(),height:a.toString(),...c?{rx:c.toString(),ry:c.toString()}:{}},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"assembly-hole-inner",fill:dN,x:(m-u/2).toString(),y:(y-l/2).toString(),width:u.toString(),height:l.toString(),rx:g.toString(),ry:g.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="rotated_pill_hole_with_rect_pad"){const o=n,s=o.rect_pad_width*Math.abs(t.a),a=o.rect_pad_height*Math.abs(t.a),c=(o.rect_border_radius??0)*Math.abs(t.a),l=o.hole_height*Math.abs(t.a),u=o.hole_width*Math.abs(t.a),d=o,h=d.hole_offset_x??0,f=d.hole_offset_y??0,[m,y]=Yt(t,[o.x+h,o.y+f]),g=Math.min(l,u)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"assembly-hole-outer-pad",fill:uN,x:(-s/2).toString(),y:(-a/2).toString(),width:s.toString(),height:a.toString(),transform:`translate(${i} ${r}) rotate(${-o.rect_ccw_rotation})`,...c?{rx:c.toString(),ry:c.toString()}:{}},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"assembly-hole-inner",fill:dN,x:(-u/2).toString(),y:(-l/2).toString(),width:u.toString(),height:l.toString(),rx:g.toString(),ry:g.toString(),transform:`translate(${m} ${y}) rotate(${-o.hole_ccw_rotation})`},value:"",children:[]}],value:"",attributes:{}}]}return[]}var hN="rgb(210, 210, 210)";function g1n(n,e){const{transform:t}=e;if(n.shape==="rect"||n.shape==="rotated_rect"){const i=n.width*Math.abs(t.a),r=n.height*Math.abs(t.d),[o,s]=Yt(t,[n.x,n.y]),a=(n.rect_border_radius??0)*Math.abs(t.a);return n.shape==="rotated_rect"&&n.ccw_rotation?[{name:"rect",type:"element",attributes:{class:"assembly-pad",fill:hN,x:(-i/2).toString(),y:(-r/2).toString(),width:i.toString(),height:r.toString(),transform:`translate(${o} ${s}) rotate(${-n.ccw_rotation})`,"data-layer":n.layer,...a?{rx:a.toString(),ry:a.toString()}:{}},value:"",children:[]}]:[{name:"rect",type:"element",attributes:{class:"assembly-pad",fill:hN,x:(o-i/2).toString(),y:(s-r/2).toString(),width:i.toString(),height:r.toString(),"data-layer":n.layer,...a?{rx:a.toString(),ry:a.toString()}:{}},value:"",children:[]}]}if(n.shape==="pill"){const i=n.width*Math.abs(t.a),r=n.height*Math.abs(t.d),o=n.radius*Math.abs(t.a),[s,a]=Yt(t,[n.x,n.y]);return[{name:"rect",type:"element",attributes:{class:"assembly-pad",fill:hN,x:(s-i/2).toString(),y:(a-r/2).toString(),width:i.toString(),height:r.toString(),rx:o.toString(),ry:o.toString(),"data-layer":n.layer},value:"",children:[]}]}if(n.shape==="circle"){const i=n.radius*Math.abs(t.a),[r,o]=Yt(t,[n.x,n.y]);return[{name:"circle",type:"element",attributes:{class:"assembly-pad",fill:hN,cx:r.toString(),cy:o.toString(),r:i.toString(),"data-layer":n.layer},value:"",children:[]}]}if(n.shape==="polygon"){const i=(n.points??[]).map(r=>Yt(t,[r.x,r.y]));return[{name:"polygon",type:"element",attributes:{class:"assembly-pad",fill:hN,points:i.map(r=>r.join(",")).join(" "),"data-layer":n.layer},value:"",children:[]}]}return[]}var BKe=["pcb_component","pcb_smtpad","pcb_hole","pcb_plated_hole","pcb_board"];function UKe(n,e){let t=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY;for(const R of n)if(R.type==="pcb_board"){const P=R.center,M=R.width||0,I=R.height||0;t=Math.min(t,P.x-M/2),i=Math.min(i,P.y-I/2),r=Math.max(r,P.x+M/2),o=Math.max(o,P.y+I/2)}const s=1,a=r-t+2*s,c=o-i+2*s,l=e?.width??800,u=e?.height??600,d=l/a,h=u/c,f=Math.min(d,h),m=(l-a*f)/2,y=(u-c*f)/2,g=ls(Rs(m-t*f+s*f,u-y+i*f-s*f),kg(f,-f)),b={transform:g},v=n.sort((R,P)=>(BKe.indexOf(P.type)??9999)-(BKe.indexOf(R.type)??9999)).flatMap(R=>b1n(R,b,n)),w=mC(n),T=_C,N={name:"svg",type:"element",attributes:{xmlns:"http://www.w3.org/2000/svg",width:l.toString(),height:u.toString(),...w&&{"data-software-used-string":w},...e?.includeVersion&&{"data-circuit-to-svg-version":T}},value:"",children:[{name:"style",type:"element",children:[{type:"text",value:`
5367
+ `),N=T.length===1?[{type:"text",value:s,name:"",attributes:{},children:[]}]:T.map((P,M)=>({type:"element",name:"tspan",value:"",attributes:{x:"0",...M>0?{dy:f.toString()}:{}},children:[{type:"text",value:P,name:"",attributes:{},children:[]}]}));return[{name:"text",type:"element",attributes:{x:"0",y:"0",dx:g.toString(),dy:b.toString(),fill:w,"font-family":"Arial, sans-serif","font-size":f.toString(),"text-anchor":m,"dominant-baseline":y,transform:iw(v),class:`pcb-silkscreen-text pcb-silkscreen-${c}`,"data-pcb-silkscreen-text-id":n.pcb_component_id,stroke:"none"},children:N,value:""}]}function Vgn(n,e){const{transform:t,layer:i,colorMap:r}=e,{center:o,width:s,height:a,layer:c="top",pcb_silkscreen_rect_id:l,stroke_width:u,is_filled:d,has_stroke:h,is_stroke_dashed:f}=n;if(i&&c!==i)return[];if(!o||typeof o.x!="number"||typeof o.y!="number"||typeof s!="number"||typeof a!="number")return console.error("Invalid rectangle data:",{center:o,width:s,height:a}),[];const[m,y]=Yt(t,[o.x,o.y]),g=s*Math.abs(t.a),b=a*Math.abs(t.d),v=u*Math.abs(t.a),w=c==="bottom"?r.silkscreen.bottom:r.silkscreen.top,T={x:(m-g/2).toString(),y:(y-b/2).toString(),width:g.toString(),height:b.toString(),class:`pcb-silkscreen-rect pcb-silkscreen-${c}`,"data-pcb-silkscreen-rect-id":l};T.fill=d?w:"none";let N;if(h===void 0?N=v>0:N=h,N){if(T.stroke=w,T["stroke-width"]=v.toString(),f){const P=.1*Math.abs(t.a),M=.05*Math.abs(t.a);T["stroke-dasharray"]=`${P} ${M}`}}else T.stroke="none";return[{name:"rect",type:"element",attributes:T,value:"",children:[]}]}function Ggn(n,e){const{transform:t,layer:i,colorMap:r}=e,{center:o,radius:s,layer:a="top",pcb_silkscreen_circle_id:c,stroke_width:l=1}=n;if(i&&a!==i)return[];if(!o||typeof o.x!="number"||typeof o.y!="number"||typeof s!="number")return console.error("Invalid PCB Silkscreen Circle data:",{center:o,radius:s}),[];const[u,d]=Yt(t,[o.x,o.y]),h=s*Math.abs(t.a),f=l*Math.abs(t.a),m=a==="bottom"?r.silkscreen.bottom:r.silkscreen.top;return[{name:"circle",type:"element",attributes:{cx:u.toString(),cy:d.toString(),r:h.toString(),class:`pcb-silkscreen-circle pcb-silkscreen-${a}`,stroke:m,"stroke-width":f.toString(),"data-pcb-silkscreen-circle-id":c},value:"",children:[]}]}function Ygn(n,e){const{transform:t,layer:i,colorMap:r}=e,{x1:o,y1:s,x2:a,y2:c,stroke_width:l,layer:u="top",pcb_silkscreen_line_id:d}=n;if(i&&u!==i)return[];if(typeof o!="number"||typeof s!="number"||typeof a!="number"||typeof c!="number")return console.error("Invalid coordinates:",{x1:o,y1:s,x2:a,y2:c}),[];const[h,f]=Yt(t,[o,s]),[m,y]=Yt(t,[a,c]),g=l*Math.abs(t.a),b=u==="bottom"?r.silkscreen.bottom:r.silkscreen.top;return[{name:"line",type:"element",attributes:{x1:h.toString(),y1:f.toString(),x2:m.toString(),y2:y.toString(),stroke:b,"stroke-width":g.toString(),class:`pcb-silkscreen-line pcb-silkscreen-${u}`,"data-pcb-silkscreen-line-id":d},value:"",children:[]}]}function qgn(n){const e=[];for(let t=0;t<n.length-1;t++)e.push([n[t],n[t+1]]);return e}var ex={copper:{top:"rgb(200, 52, 52)",bottom:"rgb(77, 127, 196)"},soldermask:{top:"rgb(200, 52, 52)",bottom:"rgb(77, 127, 196)"},drill:"#FF26E2",silkscreen:{top:"#f2eda1",bottom:"#5da9e9"},boardOutline:"rgba(255, 255, 255, 0.5)",debugComponent:{fill:null,stroke:null}};ex.drill,ex.silkscreen.top,ex.silkscreen.bottom,ex.copper.top,ex.copper.bottom;function vM(n,e=ex){return e.copper[n]??"white"}var Xgn={bottom:"rgb(105, 105, 105)",top:"rgb(105, 105, 105)"};function fH(n){return Xgn[n]??"rgb(105, 105, 105)"}function Wgn(n,e){const{transform:t,layer:i,colorMap:r,renderSolderMask:o}=e;if(!n.route||!Array.isArray(n.route)||n.route.length<2)return[];const s=qgn(n.route),a=[];for(const[c,l]of s){const u=Yt(t,[c.x,c.y]),d=Yt(t,[l.x,l.y]),h="layer"in c?c.layer:"layer"in l?l.layer:null;if(!h||i&&h!==i)continue;const f=vM(h,r),m=r.soldermask[h]??f,y="width"in c?c.width:"width"in l?l.width:null,g=y?(y*Math.abs(t.a)).toString():"0.3";if(o){const b={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-trace",stroke:f,fill:"none",d:`M ${u[0]} ${u[1]} L ${d[0]} ${d[1]}`,"stroke-width":g,"stroke-linecap":"round","stroke-linejoin":"round","shape-rendering":"crispEdges","data-layer":h}},v={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask",stroke:m,fill:"none",d:`M ${u[0]} ${u[1]} L ${d[0]} ${d[1]}`,"stroke-width":g,"stroke-linecap":"round","stroke-linejoin":"round","shape-rendering":"crispEdges","data-layer":h}};a.push(v,b)}else{const b={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-trace",stroke:m,fill:"none",d:`M ${u[0]} ${u[1]} L ${d[0]} ${d[1]}`,"stroke-width":g,"stroke-linecap":"round","stroke-linejoin":"round","shape-rendering":"crispEdges","data-layer":h}};a.push(b)}}return a.sort((c,l)=>{const u=c.attributes["data-layer"],d=l.attributes["data-layer"];return u==="bottom"&&d!=="bottom"?-1:u==="top"&&d!=="top"?1:0}),a}function Zgn(n,e){const{transform:t,layer:i,colorMap:r}=e;if(i&&n.layer!==i)return[];const o=!!n?.is_covered_with_solder_mask,s=r.soldermask[n.layer]??r.soldermask.top;if(n.shape==="rect"||n.shape==="rotated_rect"){const a=n.width*Math.abs(t.a),c=n.height*Math.abs(t.d),[l,u]=Yt(t,[n.x,n.y]),d=(n.rect_border_radius??0)*Math.abs(t.a);if(n.shape==="rotated_rect"&&n.ccw_rotation){const m={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:vM(n.layer,r),x:(-a/2).toString(),y:(-c/2).toString(),width:a.toString(),height:c.toString(),transform:`translate(${l} ${u}) rotate(${-n.ccw_rotation})`,"data-layer":n.layer,...d?{rx:d.toString(),ry:d.toString()}:{}}};if(!o)return[m];const y={name:m.name,type:m.type,value:"",children:[],attributes:{...m.attributes,class:"pcb-solder-mask",fill:s}};return[m,y]}const h={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:vM(n.layer,r),x:(l-a/2).toString(),y:(u-c/2).toString(),width:a.toString(),height:c.toString(),"data-layer":n.layer,...d?{rx:d.toString(),ry:d.toString()}:{}}};if(!o)return[h];const f={name:h.name,type:h.type,value:"",children:[],attributes:{...h.attributes,class:"pcb-solder-mask",fill:s}};return[h,f]}if(n.shape==="pill"){const a=n.width*Math.abs(t.a),c=n.height*Math.abs(t.d),l=n.radius*Math.abs(t.a),[u,d]=Yt(t,[n.x,n.y]),h={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:vM(n.layer,r),x:(u-a/2).toString(),y:(d-c/2).toString(),width:a.toString(),height:c.toString(),rx:l.toString(),ry:l.toString(),"data-layer":n.layer}};if(!o)return[h];const f={name:h.name,type:h.type,value:"",children:[],attributes:{...h.attributes,class:"pcb-solder-mask",fill:s}};return[h,f]}if(n.shape==="circle"){const a=n.radius*Math.abs(t.a),[c,l]=Yt(t,[n.x,n.y]),u={name:"circle",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:vM(n.layer,r),cx:c.toString(),cy:l.toString(),r:a.toString(),"data-layer":n.layer}};if(!o)return[u];const d={name:u.name,type:u.type,value:"",children:[],attributes:{...u.attributes,class:"pcb-solder-mask",fill:s}};return[u,d]}if(n.shape==="polygon"){const a=(n.points??[]).map(u=>Yt(t,[u.x,u.y])),c={name:"polygon",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:vM(n.layer,r),points:a.map(u=>u.join(",")).join(" "),"data-layer":n.layer}};if(!o)return[c];const l={name:c.name,type:c.type,value:"",children:[],attributes:{...c.attributes,class:"pcb-solder-mask",fill:s}};return[c,l]}return[]}function zKe(n,e){const{transform:t,colorMap:i}=e,{width:r,height:o,center:s,outline:a}=n;let c;if(a&&Array.isArray(a)&&a.length>=3)c=a.map((l,u)=>{const[d,h]=Yt(t,[l.x,l.y]);return u===0?`M ${d} ${h}`:`L ${d} ${h}`}).join(" ");else{const l=r/2,u=o/2,d=Yt(t,[s.x-l,s.y-u]),h=Yt(t,[s.x+l,s.y-u]),f=Yt(t,[s.x+l,s.y+u]),m=Yt(t,[s.x-l,s.y+u]);c=`M ${d[0]} ${d[1]} L ${h[0]} ${h[1]} L ${f[0]} ${f[1]} L ${m[0]} ${m[1]}`}return c+=" Z",[{name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-board",d:c,fill:"none",stroke:i.boardOutline,"stroke-width":(.1*Math.abs(t.a)).toString()}}]}function Kgn(n,e){const{transform:t,colorMap:i}=e,[r,o]=Yt(t,[n.x,n.y]),s=n.outer_diameter*Math.abs(t.a),a=n.outer_diameter*Math.abs(t.a),c=n.hole_diameter*Math.abs(t.a),l=n.hole_diameter*Math.abs(t.a),u=Math.min(s,a)/2,d=Math.min(c,l)/2;return{name:"g",type:"element",children:[{name:"circle",type:"element",attributes:{class:"pcb-hole-outer",fill:i.copper.top,cx:r.toString(),cy:o.toString(),r:u.toString()}},{name:"circle",type:"element",attributes:{class:"pcb-hole-inner",fill:i.drill,cx:r.toString(),cy:o.toString(),r:d.toString()}}]}}function Qgn(n,e){const{transform:t,colorMap:i}=e,[r,o]=Yt(t,[n.x,n.y]);if(n.hole_shape==="circle"||n.hole_shape==="square"){const s=n.hole_diameter*Math.abs(t.a),a=s/2;return n.hole_shape==="circle"?[{name:"circle",type:"element",attributes:{class:"pcb-hole",cx:r.toString(),cy:o.toString(),r:a.toString(),fill:i.drill},children:[],value:""}]:[{name:"rect",type:"element",attributes:{class:"pcb-hole",x:(r-a).toString(),y:(o-a).toString(),width:s.toString(),height:s.toString(),fill:i.drill},children:[],value:""}]}if(n.hole_shape==="oval"){const s=n.hole_width*Math.abs(t.a),a=n.hole_height*Math.abs(t.a),c=s/2,l=a/2;return[{name:"ellipse",type:"element",attributes:{class:"pcb-hole",cx:r.toString(),cy:o.toString(),rx:c.toString(),ry:l.toString(),fill:i.drill},children:[],value:""}]}return[]}var Jgn=(n,e)=>{const t=ta(e).pcb_smtpad.get(n);if(t&&"x"in t&&"y"in t)return{x:t.x,y:t.y};const i=ta(e).pcb_plated_hole.get(n);return i&&"x"in i&&"y"in i?{x:i.x,y:i.y}:null},e1n=(n,e,t,i)=>{const r=t.getIdsConnectedToNet(e);let o=null,s=1/0;for(const a of r){const c=Jgn(a,i);if(c){const l=n.x-c.x,u=n.y-c.y,d=Math.sqrt(l*l+u*u);d>0&&d<s&&(s=d,o=c)}}return o};function t1n(n,e){const{transform:t}=e,i=e6(n),r=n.filter(c=>c.type==="pcb_port"),o=n.filter(c=>c.type==="source_trace"),s=[];r.forEach((c,l)=>{const u=c.pcb_port_id;if(!u)return;const d=i.getNetConnectedToId(u);if(!d)return;let h=!1;const f=ta(n).source_port.getWhere({pcb_port_id:u});if(f&&f.source_port_id){const g=f.source_port_id;for(const b of o)if(Array.isArray(b.connected_source_port_ids)&&b.connected_source_port_ids.includes(g)&&Array.isArray(b.connected_source_net_ids)&&b.connected_source_net_ids.length>0){h=!0;break}}const m={x:c.x,y:c.y},y=e1n(m,d,i,n);y&&s.push({key:`${u}-${l}`,startPoint:m,endPoint:y,isInNet:h})});const a=[];for(const c of s){const l=Yt(t,[c.startPoint.x,c.startPoint.y]),u=Yt(t,[c.endPoint.x,c.endPoint.y]),d={x1:l[0].toString(),y1:l[1].toString(),x2:u[0].toString(),y2:u[1].toString(),stroke:"white","stroke-width":"1","stroke-dasharray":"6,6"};a.push({name:"line",type:"element",attributes:d,value:"",children:[]})}return a}function n1n(n,e){const{transform:t,colorMap:i}=e;if(n.shape==="rect"){const r=n,[o,s]=Yt(t,[r.center.x,r.center.y]),a=r.width*Math.abs(t.a),c=r.height*Math.abs(t.d),l=-(r.rotation??0);return[{name:"rect",type:"element",attributes:{class:"pcb-cutout pcb-cutout-rect",x:(-a/2).toString(),y:(-c/2).toString(),width:a.toString(),height:c.toString(),fill:i.drill,transform:iw(ls(Rs(o,s),sv(l*Math.PI/180)))},children:[],value:""}]}if(n.shape==="circle"){const r=n,[o,s]=Yt(t,[r.center.x,r.center.y]),a=r.radius*Math.abs(t.a);return[{name:"circle",type:"element",attributes:{class:"pcb-cutout pcb-cutout-circle",cx:o.toString(),cy:s.toString(),r:a.toString(),fill:i.drill},children:[],value:""}]}if(n.shape==="polygon"){const r=n;return!r.points||r.points.length===0?[]:[{name:"polygon",type:"element",attributes:{class:"pcb-cutout pcb-cutout-polygon",points:r.points.map(a=>Yt(t,[a.x,a.y])).map(a=>`${a[0]},${a[1]}`).join(" "),fill:i.drill},children:[],value:""}]}return[]}function FKe(n,e){if(n.length===0)return"";const t=n.map(r=>{const[o,s]=Yt(e,[r.x,r.y]);return{...r,x:o,y:s}});let i=`M ${t[0].x} ${t[0].y}`;for(let r=0;r<t.length;r++){const o=t[r],s=t[(r+1)%t.length];if(o.bulge){if(Math.hypot(s.x-o.x,s.y-o.y)<1e-9)continue;const a=o.bulge,c=s.x-o.x,l=s.y-o.y,u=Math.hypot(c,l),d=Math.abs(u/4/a*(a*a+1)),h=a<0?1:0,f=Math.abs(a)>1?1:0;i+=` A ${d} ${d} 0 ${f} ${h} ${s.x} ${s.y}`}else i+=` L ${s.x} ${s.y}`}return i+=" Z",i}function i1n(n,e){const{transform:t,layer:i,colorMap:r}=e,{layer:o}=n;if(i&&o!==i)return[];const s=vM(o,r),a="0.5";if(n.shape==="rect"){const[c,l]=Yt(t,[n.center.x,n.center.y]),u=n.width*Math.abs(t.a),d=n.height*Math.abs(t.d),h=-(n.rotation??0);return[{name:"rect",type:"element",attributes:{class:"pcb-copper-pour pcb-copper-pour-rect",x:(-u/2).toString(),y:(-d/2).toString(),width:u.toString(),height:d.toString(),fill:s,"fill-opacity":a,transform:iw(ls(Rs(c,l),sv(h*Math.PI/180))),"data-layer":o},children:[],value:""}]}if(n.shape==="polygon")return!n.points||n.points.length===0?[]:[{name:"polygon",type:"element",attributes:{class:"pcb-copper-pour pcb-copper-pour-polygon",points:n.points.map(u=>Yt(t,[u.x,u.y])).map(u=>`${u[0]},${u[1]}`).join(" "),fill:s,"fill-opacity":a,"data-layer":o},children:[],value:""}];if(n.shape==="brep"){const{brep_shape:c}=n;let l=FKe(c.outer_ring.vertices,t);for(const u of c.inner_rings??[])l+=` ${FKe(u.vertices,t)}`;return[{name:"path",type:"element",attributes:{class:"pcb-copper-pour pcb-copper-pour-brep",d:l,fill:s,"fill-rule":"evenodd","fill-opacity":a,"data-layer":o},children:[],value:""}]}return[]}function r1n(n,e){const{transform:t}=e,{center:i,width:r,height:o,rotation:s=0}=n,[a,c]=Yt(t,[i.x,i.y]),l=r*Math.abs(t.a),u=o*Math.abs(t.d),d=`translate(${a}, ${c}) rotate(${-s}) scale(1, -1)`;return!e.colorMap.debugComponent?.fill&&!e.colorMap.debugComponent?.stroke?[]:[{name:"g",type:"element",attributes:{transform:d},children:[{name:"rect",type:"element",attributes:{class:"pcb-component",x:(-l/2).toString(),y:(-u/2).toString(),width:l.toString(),height:u.toString(),fill:e.colorMap.debugComponent.fill??"transparent",stroke:e.colorMap.debugComponent.stroke??"transparent"}}],value:""}]}function mC(n){return n.find(t=>t.type==="project_software_metadata"||t.type==="source_project_metadata")?.software_used_string}var o1n={version:"0.0.201"},_C=o1n.version,$Ke=["pcb_trace_error","pcb_plated_hole","pcb_fabrication_note_text","pcb_fabrication_note_path","pcb_silkscreen_text","pcb_silkscreen_path","pcb_via","pcb_cutout","pcb_copper_pour","pcb_smtpad","pcb_trace","pcb_component","pcb_board"];function P_e(n,e){const t=e?.drawPaddingOutsideBoard??!0,i=e?.layer,r=e?.colorOverrides,o={copper:{top:r?.copper?.top??ex.copper.top,bottom:r?.copper?.bottom??ex.copper.bottom},drill:r?.drill??ex.drill,silkscreen:{top:r?.silkscreen?.top??ex.silkscreen.top,bottom:r?.silkscreen?.bottom??ex.silkscreen.bottom},boardOutline:r?.boardOutline??ex.boardOutline,soldermask:{top:r?.soldermask?.top??ex.soldermask.top,bottom:r?.soldermask?.bottom??ex.soldermask.bottom},debugComponent:{fill:r?.debugComponent?.fill??ex.debugComponent.fill,stroke:r?.debugComponent?.stroke??ex.debugComponent.stroke}};let s=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,l=Number.NEGATIVE_INFINITY,u=Number.POSITIVE_INFINITY,d=Number.POSITIVE_INFINITY,h=Number.NEGATIVE_INFINITY,f=Number.NEGATIVE_INFINITY;for(const Ne of n)if(Ne.type==="pcb_board")Ne.outline&&Array.isArray(Ne.outline)&&Ne.outline.length>=3?(Ee(Ne.outline),Re(Ne.outline)):"center"in Ne&&"width"in Ne&&"height"in Ne&&(oe(Ne.center,Ne.width,Ne.height),pe(Ne.center,Ne.width,Ne.height));else if("x"in Ne&&"y"in Ne)oe({x:Ne.x,y:Ne.y},0,0);else if(Ne.type==="pcb_smtpad"){const le=Ne;le.shape==="rect"||le.shape==="rotated_rect"||le.shape==="pill"?oe({x:le.x,y:le.y},le.width,le.height):le.shape==="circle"?oe({x:le.x,y:le.y},le.radius*2,le.radius*2):le.shape==="polygon"&&Oe(le.points)}else"route"in Ne?Oe(Ne.route):Ne.type==="pcb_silkscreen_text"||Ne.type==="pcb_silkscreen_rect"||Ne.type==="pcb_silkscreen_circle"||Ne.type==="pcb_silkscreen_line"?Ve(Ne):Ne.type==="pcb_copper_pour"&&(Ne.shape==="rect"?oe(Ne.center,Ne.width,Ne.height):Ne.shape==="polygon"&&Oe(Ne.points));const m=t?1:0,y=t||!Number.isFinite(u)?s:u,g=t||!Number.isFinite(d)?a:d,b=t||!Number.isFinite(h)?c:h,v=t||!Number.isFinite(f)?l:f,w=b-y+2*m,T=v-g+2*m;let N=e?.width??800,R=e?.height??600;if(e?.matchBoardAspectRatio){const Ne=h-u,le=f-d;if(Ne>0&&le>0){const Se=Ne/le;e?.width&&!e?.height?R=e.width/Se:e?.height&&!e?.width?N=e.height*Se:R=N/Se}}const P=[];for(const Ne of n)"route"in Ne&&Ne.route!==void 0&&P.push(Ne.route);const M=N/w,I=R/T,A=Math.min(M,I),U=(N-w*A)/2,k=(R-T*A)/2,V=ls(Rs(U-y*A+m*A,R-k+g*A-m*A),kg(A,-A)),Y={transform:V,layer:i,shouldDrawErrors:e?.shouldDrawErrors,drawPaddingOutsideBoard:t,colorMap:o,renderSolderMask:e?.renderSolderMask};function W(Ne){if(Ne.type==="pcb_smtpad")return Ne.layer==="top"||Ne.layer==="bottom"?Ne.layer:void 0;if(Ne.type==="pcb_trace")for(const le of Ne.route??[]){const Se="layer"in le&&le.layer||"from_layer"in le&&le.from_layer||"to_layer"in le&&le.to_layer||void 0;if(Se==="top"||Se==="bottom")return Se}}function K(Ne){return Ne.type==="pcb_trace"||Ne.type==="pcb_smtpad"}let ee=n.sort((Ne,le)=>{const Se=W(Ne),xe=W(le);if(K(Ne)&&K(le)&&Se!==xe){if(Se==="top")return 1;if(xe==="top"||Se==="bottom")return-1;if(xe==="bottom")return 1}return($Ke.indexOf(le.type)??9999)-($Ke.indexOf(Ne.type)??9999)}).flatMap(Ne=>s1n({elm:Ne,circuitJson:n,ctx:Y}));for(const Ne of n)if("stroke_width"in Ne){String(A*Ne.stroke_width);break}if(e?.shouldDrawRatsNest){const Ne=t1n(n,Y);ee=ee.concat(Ne)}const ae=[{name:"style",type:"element",value:"",attributes:{},children:[{type:"text",value:"",name:"",attributes:{},children:[]}]},{name:"rect",type:"element",value:"",attributes:{class:"boundary",x:"0",y:"0",fill:e?.backgroundColor??"#000",width:N.toString(),height:R.toString()},children:[]}];t&&ae.push(a1n(V,s,a,c,l)),ae.push(...ee);const ue=mC(n),ge=_C,re={name:"svg",type:"element",attributes:{xmlns:"http://www.w3.org/2000/svg",width:N.toString(),height:R.toString(),...ue&&{"data-software-used-string":ue},...e?.includeVersion&&{"data-circuit-to-svg-version":ge}},value:"",children:ae.filter(Ne=>Ne!==null)};try{return Y7(re)}catch(Ne){throw console.error("Error stringifying SVG object:",Ne),Ne}function oe(Ne,le,Se){const xe=le/2,Ye=Se/2;s=Math.min(s,Ne.x-xe),a=Math.min(a,Ne.y-Ye),c=Math.max(c,Ne.x+xe),l=Math.max(l,Ne.y+Ye)}function pe(Ne,le,Se){const xe=le/2,Ye=Se/2;u=Math.min(u,Ne.x-xe),d=Math.min(d,Ne.y-Ye),h=Math.max(h,Ne.x+xe),f=Math.max(f,Ne.y+Ye)}function Ee(Ne){for(const le of Ne)s=Math.min(s,le.x),a=Math.min(a,le.y),c=Math.max(c,le.x),l=Math.max(l,le.y)}function Re(Ne){for(const le of Ne)u=Math.min(u,le.x),d=Math.min(d,le.y),h=Math.max(h,le.x),f=Math.max(f,le.y)}function Oe(Ne){for(const le of Ne)s=Math.min(s,le.x),a=Math.min(a,le.y),c=Math.max(c,le.x),l=Math.max(l,le.y)}function Ve(Ne){if(Ne.type==="pcb_silkscreen_text")oe(Ne.anchor_position,0,0);else if(Ne.type==="pcb_silkscreen_path")Oe(Ne.route);else if(Ne.type==="pcb_silkscreen_rect")oe(Ne.center,Ne.width,Ne.height);else if(Ne.type==="pcb_silkscreen_circle")oe(Ne.center,Ne.radius*2,Ne.radius*2);else if(Ne.type==="pcb_silkscreen_line")oe({x:Ne.x1,y:Ne.y1},0,0),oe({x:Ne.x2,y:Ne.y2},0,0);else if(Ne.type==="pcb_cutout"){const le=Ne;le.shape==="rect"?oe(le.center,le.width,le.height):le.shape==="circle"?oe(le.center,le.radius*2,le.radius*2):le.shape==="polygon"&&Oe(le.points)}}}function s1n({elm:n,circuitJson:e,ctx:t}){switch(n.type){case"pcb_trace_error":return zgn(n,e,t).filter(Boolean);case"pcb_component":return r1n(n,t).filter(Boolean);case"pcb_trace":return Wgn(n,t);case"pcb_copper_pour":return i1n(n,t);case"pcb_plated_hole":return Ugn(n,t).filter(Boolean);case"pcb_hole":return Qgn(n,t);case"pcb_smtpad":return Zgn(n,t);case"pcb_silkscreen_text":return Hgn(n,t);case"pcb_silkscreen_rect":return Vgn(n,t);case"pcb_silkscreen_circle":return Ggn(n,t);case"pcb_silkscreen_line":return Ygn(n,t);case"pcb_fabrication_note_path":return $gn(n,t);case"pcb_fabrication_note_text":return Bgn(n,t);case"pcb_silkscreen_path":return jgn(n,t);case"pcb_board":return t.drawPaddingOutsideBoard?zKe(n,t):[];case"pcb_via":return Kgn(n,t);case"pcb_cutout":return n1n(n,t);default:return[]}}function a1n(n,e,t,i,r){const[o,s]=Yt(n,[e,t]),[a,c]=Yt(n,[i,r]),l=Math.abs(a-o),u=Math.abs(c-s),d=Math.min(o,a),h=Math.min(s,c);return{name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-boundary",fill:"none",stroke:"#fff","stroke-width":"0.3",x:d.toString(),y:h.toString(),width:l.toString(),height:u.toString()}}}var c1n=P_e,mH={fill:"none",stroke:"rgb(0,0,0)",strokeOpacity:"0.8",strokeWidthFactor:.2};function l1n(n,e,t={}){const{width:i,height:r,center:o,outline:s}=n;let a;if(s&&Array.isArray(s)&&s.length>=3)a=s.map((c,l)=>{const[u,d]=Yt(e,[c.x,c.y]);return l===0?`M ${u} ${d}`:`L ${u} ${d}`}).join(" ");else{const c=i/2,l=r/2,u=Yt(e,[o.x-c,o.y-l]),d=Yt(e,[o.x+c,o.y-l]),h=Yt(e,[o.x+c,o.y+l]),f=Yt(e,[o.x-c,o.y+l]);a=`M ${u[0]} ${u[1]} L ${d[0]} ${d[1]} L ${h[0]} ${h[1]} L ${f[0]} ${f[1]}`}return a+=" Z",[{name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-board",d:a,fill:t.fill??mH.fill,stroke:t.stroke??mH.stroke,"stroke-opacity":t.strokeOpacity??mH.strokeOpacity,"stroke-width":((t.strokeWidthFactor??mH.strokeWidthFactor)*Math.abs(e.a)).toString()}}]}var u1n={pin_number:.15,negated_pin_number:.15*.8,reference_designator:.18,manufacturer_number:.18,net_label:.18,error:.05},yC=(n,e)=>e??u1n[n],m3=(n,e,t)=>Math.abs(n.a)*yC(e,t);function d1n(n,e){const{elm:t,portPosition:i,name:r,arePinsInterchangeable:o}=n,{transform:s}=e,{center:a,width:c,height:l,rotation:u=0,layer:d="top"}=t;if(!a||typeof c!="number"||typeof l!="number")return null;const[h,f]=Yt(s,[a.x,a.y]),[m,y]=Yt(s,[i.x,i.y]),g=c*Math.abs(s.a),b=l*Math.abs(s.d),v=y>f,w=m<h,T=[h1n(g,b,u,d),p1n(g,b,r??"")];return o||T.push(f1n(g,b,u,d,v,w)),{name:"g",type:"element",value:"",attributes:{transform:`translate(${h}, ${f}) scale(1, -1)`},children:T}}function h1n(n,e,t,i){const r=n/2,o=e/2;return{name:"path",type:"element",attributes:{class:"assembly-component",d:m1n(r,o,t),"stroke-width":.8.toFixed(2),transform:`rotate(${-t})`,"stroke-dasharray":i==="bottom"?"2,2":""},value:"",children:[]}}function p1n(n,e,t,i){const r=Math.min(n,e),c=Math.min(58,Math.max(3,r*.8)),l=e>n;return{name:"text",type:"element",attributes:{x:"0",y:"0",class:"assembly-component-label","text-anchor":"middle",dy:".10em",style:"pointer-events: none","font-size":`${c.toFixed(1)}px`,transform:l?"rotate(90) scale(1, -1)":"scale(1, -1)"},children:[{type:"text",value:t||"",name:"",attributes:{},children:[]}],value:""}}function f1n(n,e,t,i,r,o){const s=n/2,a=e/2,c=Math.min(s,a)*.5;let l;return r&&o?l=[[-s,-a],[-s+c,-a],[-s,-a+c]]:r&&!o?l=[[s,-a],[s-c,-a],[s,-a+c]]:!r&&o?l=[[-s,a],[-s+c,a],[-s,a-c]]:l=[[s,a],[s-c,a],[s,a-c]],{name:"polygon",type:"element",attributes:{class:"assembly-pin1-indicator",points:l.map(d=>d.join(",")).join(" "),fill:"#333",stroke:"none",transform:`rotate(${-t})`},value:"",children:[]}}function m1n(n,e,t){const i=(a,c,l)=>{const u=Math.PI/180*l,d=Math.cos(u),h=Math.sin(u);return[a*d-c*h,a*h+c*d]};return`${[[-n,-e],[n,-e],[n,e],[-n,e]].map(([a,c])=>i(a,c,t)).map(([a,c],l)=>l===0?`M${a},${c}`:`L${a},${c}`).join(" ")} Z`}var I_e="rgb(190, 190, 190)";function _1n(n,e){const{transform:t}=e,[i,r]=Yt(t,[n.x,n.y]);if(n.hole_shape==="circle"||n.hole_shape==="square"){const o=n.hole_diameter*Math.abs(t.a),s=o/2;return n.hole_shape==="circle"?[{name:"circle",type:"element",attributes:{class:"assembly-hole",cx:i.toString(),cy:r.toString(),r:s.toString(),fill:I_e},children:[],value:""}]:[{name:"rect",type:"element",attributes:{class:"assembly-hole",x:(i-s).toString(),y:(r-s).toString(),width:o.toString(),height:o.toString(),fill:I_e},children:[],value:""}]}if(n.hole_shape==="oval"){const o=n.hole_width*Math.abs(t.a),s=n.hole_height*Math.abs(t.a),a=o/2,c=s/2;return[{name:"ellipse",type:"element",attributes:{class:"assembly-hole",cx:i.toString(),cy:r.toString(),rx:a.toString(),ry:c.toString(),fill:I_e},children:[],value:""}]}return[]}var uN="rgb(210, 210, 210)",dN="rgb(190, 190, 190)";function y1n(n,e){const{transform:t}=e,[i,r]=Yt(t,[n.x,n.y]);if(n.shape==="pill"){const o=n.outer_width*Math.abs(t.a),s=n.outer_height*Math.abs(t.a),a=n.hole_width*Math.abs(t.a),c=n.hole_height*Math.abs(t.a),l=o/2,u=s-o,d=a/2;return[{name:"g",type:"element",children:[{name:"path",type:"element",attributes:{class:"assembly-hole-outer",fill:uN,d:`M${i-l},${r-u/2} v${u} a${l},${l} 0 0 0 ${o},0 v-${u} a${l},${l} 0 0 0 -${o},0 z`},value:"",children:[]},{name:"path",type:"element",attributes:{class:"assembly-hole-inner",fill:dN,d:`M${i-d},${r-(c-a)/2} v${c-a} a${d},${d} 0 0 0 ${a},0 v-${c-a} a${d},${d} 0 0 0 -${a},0 z`},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="circle"){const o=n.outer_diameter*Math.abs(t.a),s=n.outer_diameter*Math.abs(t.a),a=n.hole_diameter*Math.abs(t.a),c=n.hole_diameter*Math.abs(t.a),l=Math.min(o,s)/2,u=Math.min(a,c)/2;return[{name:"g",type:"element",children:[{name:"circle",type:"element",attributes:{class:"assembly-hole-outer",fill:uN,cx:i.toString(),cy:r.toString(),r:l.toString()},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"assembly-hole-inner",fill:dN,cx:i.toString(),cy:r.toString(),r:u.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="circular_hole_with_rect_pad"){const o=n,s=o.hole_diameter*Math.abs(t.a),a=o.rect_pad_width*Math.abs(t.a),c=o.rect_pad_height*Math.abs(t.a),l=(o.rect_border_radius??0)*Math.abs(t.a),u=s/2,[d,h]=Yt(t,[o.x+o.hole_offset_x,o.y+o.hole_offset_y]);return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"assembly-hole-outer-pad",fill:uN,x:(i-a/2).toString(),y:(r-c/2).toString(),width:a.toString(),height:c.toString(),...l?{rx:l.toString(),ry:l.toString()}:{}},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"assembly-hole-inner",fill:dN,cx:d.toString(),cy:h.toString(),r:u.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="pill_hole_with_rect_pad"){const o=n,s=o.rect_pad_width*Math.abs(t.a),a=o.rect_pad_height*Math.abs(t.a),c=(o.rect_border_radius??0)*Math.abs(t.a),l=o.hole_height*Math.abs(t.a),u=o.hole_width*Math.abs(t.a),d=o,h=d.hole_offset_x??0,f=d.hole_offset_y??0,[m,y]=Yt(t,[o.x+h,o.y+f]),g=Math.min(l,u)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"assembly-hole-outer-pad",fill:uN,x:(i-s/2).toString(),y:(r-a/2).toString(),width:s.toString(),height:a.toString(),...c?{rx:c.toString(),ry:c.toString()}:{}},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"assembly-hole-inner",fill:dN,x:(m-u/2).toString(),y:(y-l/2).toString(),width:u.toString(),height:l.toString(),rx:g.toString(),ry:g.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="rotated_pill_hole_with_rect_pad"){const o=n,s=o.rect_pad_width*Math.abs(t.a),a=o.rect_pad_height*Math.abs(t.a),c=(o.rect_border_radius??0)*Math.abs(t.a),l=o.hole_height*Math.abs(t.a),u=o.hole_width*Math.abs(t.a),d=o,h=d.hole_offset_x??0,f=d.hole_offset_y??0,[m,y]=Yt(t,[o.x+h,o.y+f]),g=Math.min(l,u)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"assembly-hole-outer-pad",fill:uN,x:(-s/2).toString(),y:(-a/2).toString(),width:s.toString(),height:a.toString(),transform:`translate(${i} ${r}) rotate(${-o.rect_ccw_rotation})`,...c?{rx:c.toString(),ry:c.toString()}:{}},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"assembly-hole-inner",fill:dN,x:(-u/2).toString(),y:(-l/2).toString(),width:u.toString(),height:l.toString(),rx:g.toString(),ry:g.toString(),transform:`translate(${m} ${y}) rotate(${-o.hole_ccw_rotation})`},value:"",children:[]}],value:"",attributes:{}}]}return[]}var hN="rgb(210, 210, 210)";function g1n(n,e){const{transform:t}=e;if(n.shape==="rect"||n.shape==="rotated_rect"){const i=n.width*Math.abs(t.a),r=n.height*Math.abs(t.d),[o,s]=Yt(t,[n.x,n.y]),a=(n.rect_border_radius??0)*Math.abs(t.a);return n.shape==="rotated_rect"&&n.ccw_rotation?[{name:"rect",type:"element",attributes:{class:"assembly-pad",fill:hN,x:(-i/2).toString(),y:(-r/2).toString(),width:i.toString(),height:r.toString(),transform:`translate(${o} ${s}) rotate(${-n.ccw_rotation})`,"data-layer":n.layer,...a?{rx:a.toString(),ry:a.toString()}:{}},value:"",children:[]}]:[{name:"rect",type:"element",attributes:{class:"assembly-pad",fill:hN,x:(o-i/2).toString(),y:(s-r/2).toString(),width:i.toString(),height:r.toString(),"data-layer":n.layer,...a?{rx:a.toString(),ry:a.toString()}:{}},value:"",children:[]}]}if(n.shape==="pill"){const i=n.width*Math.abs(t.a),r=n.height*Math.abs(t.d),o=n.radius*Math.abs(t.a),[s,a]=Yt(t,[n.x,n.y]);return[{name:"rect",type:"element",attributes:{class:"assembly-pad",fill:hN,x:(s-i/2).toString(),y:(a-r/2).toString(),width:i.toString(),height:r.toString(),rx:o.toString(),ry:o.toString(),"data-layer":n.layer},value:"",children:[]}]}if(n.shape==="circle"){const i=n.radius*Math.abs(t.a),[r,o]=Yt(t,[n.x,n.y]);return[{name:"circle",type:"element",attributes:{class:"assembly-pad",fill:hN,cx:r.toString(),cy:o.toString(),r:i.toString(),"data-layer":n.layer},value:"",children:[]}]}if(n.shape==="polygon"){const i=(n.points??[]).map(r=>Yt(t,[r.x,r.y]));return[{name:"polygon",type:"element",attributes:{class:"assembly-pad",fill:hN,points:i.map(r=>r.join(",")).join(" "),"data-layer":n.layer},value:"",children:[]}]}return[]}var BKe=["pcb_component","pcb_smtpad","pcb_hole","pcb_plated_hole","pcb_board"];function UKe(n,e){let t=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY;for(const R of n)if(R.type==="pcb_board"){const P=R.center,M=R.width||0,I=R.height||0;t=Math.min(t,P.x-M/2),i=Math.min(i,P.y-I/2),r=Math.max(r,P.x+M/2),o=Math.max(o,P.y+I/2)}const s=1,a=r-t+2*s,c=o-i+2*s,l=e?.width??800,u=e?.height??600,d=l/a,h=u/c,f=Math.min(d,h),m=(l-a*f)/2,y=(u-c*f)/2,g=ls(Rs(m-t*f+s*f,u-y+i*f-s*f),kg(f,-f)),b={transform:g},v=n.sort((R,P)=>(BKe.indexOf(P.type)??9999)-(BKe.indexOf(R.type)??9999)).flatMap(R=>b1n(R,b,n)),w=mC(n),T=_C,N={name:"svg",type:"element",attributes:{xmlns:"http://www.w3.org/2000/svg",width:l.toString(),height:u.toString(),...w&&{"data-software-used-string":w},...e?.includeVersion&&{"data-circuit-to-svg-version":T}},value:"",children:[{name:"style",type:"element",children:[{type:"text",value:`
5368
5368
  .assembly-component {
5369
5369
  fill: none;
5370
5370
  stroke: #000;
@@ -5386,7 +5386,7 @@ ${P.type}: ${k}
5386
5386
  stroke: #fff;
5387
5387
  stroke-width: 0.2;
5388
5388
  }
5389
- `,name:"",attributes:{},children:[]}],value:"",attributes:{}},{name:"rect",type:"element",attributes:{fill:"#fff",x:"0",y:"0",width:l.toString(),height:u.toString()},value:"",children:[]},x1n(g,t,i,r,o),...v].filter(R=>R!==null)};return Y7(N)}function b1n(n,e,t){const i=ta(t).source_component.list();switch(n.type){case"pcb_board":return l1n(n,e.transform);case"pcb_component":{const r=i.find(a=>a.source_component_id===n.source_component_id),s=ta(t).pcb_port.list().filter(a=>a.pcb_component_id===n.pcb_component_id)[0];if(r&&s){const a=r.are_pins_interchangeable,c=d1n({elm:n,portPosition:{x:s.x,y:s.y},name:r.name,arePinsInterchangeable:a},e);return c?[c]:[]}return[]}case"pcb_smtpad":return g1n(n,e);case"pcb_hole":return _1n(n,e);case"pcb_plated_hole":return y1n(n,e);default:return[]}}function x1n(n,e,t,i,r){const[o,s]=Yt(n,[e,t]),[a,c]=Yt(n,[i,r]),l=Math.abs(a-o),u=Math.abs(c-s),d=Math.min(o,a),h=Math.min(s,c);return{name:"rect",type:"element",value:"",children:[],attributes:{class:"assembly-boundary",x:d.toString(),y:h.toString(),width:l.toString(),height:u.toString()}}}var v1n="rgb(26, 115, 143)",w1n="rgba(0,0,0,0.9)";function S1n(n,e){const{transform:t,soup:i}=e,{width:r,height:o,center:s,outline:a}=n;let c;if(a&&Array.isArray(a)&&a.length>=3)c=a.map((u,d)=>{const[h,f]=Yt(t,[u.x,u.y]);return d===0?`M ${h} ${f}`:`L ${h} ${f}`}).join(" ");else{const u=r/2,d=o/2,h=Yt(t,[s.x-u,s.y-d]),f=Yt(t,[s.x+u,s.y-d]),m=Yt(t,[s.x+u,s.y+d]),y=Yt(t,[s.x-u,s.y+d]);c=`M ${h[0]} ${h[1]} L ${f[0]} ${f[1]} L ${m[0]} ${m[1]} L ${y[0]} ${y[1]}`}c+=" Z";const l=ta(i).pcb_cutout.list();for(const u of l)if(u.shape==="rect"){const{x:d,y:h,width:f,height:m}=u.center?(()=>{const{x:N,y:R}=u.center,{width:P,height:M}=u;return{x:N,y:R,width:P,height:M}})():{x:0,y:0,width:0,height:0},y=f/2,g=m/2,[b,v,w,T]=[Yt(t,[d-y,h-g]),Yt(t,[d+y,h-g]),Yt(t,[d+y,h+g]),Yt(t,[d-y,h+g])];c+=` M ${b[0]} ${b[1]} L ${v[0]} ${v[1]} L ${w[0]} ${w[1]} L ${T[0]} ${T[1]} Z`}else u.shape;return[{name:"path",type:"element",value:"",children:[],attributes:{class:"pinout-board",d:c,fill:v1n,stroke:w1n,"fill-rule":"evenodd","stroke-opacity":"0.8","stroke-width":(.2*Math.abs(t.a)).toString()}}]}var E1n="rgba(120, 120, 120, 0.6)",T1n="rgba(255, 255, 255, 0.9)";function M1n(n,e){const{transform:t,soup:i}=e,{center:r,width:o,height:s,rotation:a=0,source_component_id:c}=n,l=ta(i).source_component.get(c);if(!r||typeof o!="number"||typeof s!="number"||o===0||s===0)return[];const[u,d]=Yt(t,[r.x,r.y]),h=o*Math.abs(t.a),f=s*Math.abs(t.d),m=`translate(${u}, ${d}) rotate(${-a})`,y=[{name:"rect",type:"element",attributes:{class:"pinout-component-box",x:(-h/2).toString(),y:(-f/2).toString(),width:h.toString(),height:f.toString(),fill:E1n},value:"",children:[]}];if(l?.name){const g=f>h*1.5,b=Math.min(h,f)*.4;y.push({name:"text",type:"element",attributes:{x:"0",y:"0",fill:T1n,"font-size":`${b}px`,"font-family":"sans-serif","text-anchor":"middle","dominant-baseline":"middle",transform:g?"rotate(90)":""},children:[{type:"text",value:l.name,name:"",attributes:{},children:[]}],value:""})}return[{name:"g",type:"element",attributes:{transform:m},children:y,value:""}]}var N_e="rgb(50, 50, 50)";function A1n(n,e){const{transform:t}=e,[i,r]=Yt(t,[n.x,n.y]);if(n.hole_shape==="circle"||n.hole_shape==="square"){const o=n.hole_diameter*Math.abs(t.a),s=o/2;return n.hole_shape==="circle"?[{name:"circle",type:"element",attributes:{class:"pinout-hole",cx:i.toString(),cy:r.toString(),r:s.toString(),fill:N_e},children:[],value:""}]:[{name:"rect",type:"element",attributes:{class:"pinout-hole",x:(i-s).toString(),y:(r-s).toString(),width:o.toString(),height:o.toString(),fill:N_e},children:[],value:""}]}if(n.hole_shape==="oval"){const o=n.hole_width*Math.abs(t.a),s=n.hole_height*Math.abs(t.a),a=o/2,c=s/2;return[{name:"ellipse",type:"element",attributes:{class:"pinout-hole",cx:i.toString(),cy:r.toString(),rx:a.toString(),ry:c.toString(),fill:N_e},children:[],value:""}]}return[]}var pN="rgb(218, 165, 32)",fN="rgb(40, 40, 40)";function C1n(n,e){const{transform:t}=e,[i,r]=Yt(t,[n.x,n.y]);if(n.shape==="pill"){const o=n.outer_width*Math.abs(t.a),s=n.outer_height*Math.abs(t.a),a=n.hole_width*Math.abs(t.a),c=n.hole_height*Math.abs(t.a),l=o/2,u=s-o,d=a/2;return[{name:"g",type:"element",children:[{name:"path",type:"element",attributes:{class:"pinout-hole-outer",fill:pN,d:`M${i-l},${r-u/2} v${u} a${l},${l} 0 0 0 ${o},0 v-${u} a${l},${l} 0 0 0 -${o},0 z`},value:"",children:[]},{name:"path",type:"element",attributes:{class:"pinout-hole-inner",fill:fN,d:`M${i-d},${r-(c-a)/2} v${c-a} a${d},${d} 0 0 0 ${a},0 v-${c-a} a${d},${d} 0 0 0 -${a},0 z`},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="circle"){const o=n.outer_diameter*Math.abs(t.a),s=n.outer_diameter*Math.abs(t.a),a=n.hole_diameter*Math.abs(t.a),c=n.hole_diameter*Math.abs(t.a),l=Math.min(o,s)/2,u=Math.min(a,c)/2;return[{name:"g",type:"element",children:[{name:"circle",type:"element",attributes:{class:"pinout-hole-outer",fill:pN,cx:i.toString(),cy:r.toString(),r:l.toString()},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"pinout-hole-inner",fill:fN,cx:i.toString(),cy:r.toString(),r:u.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="circular_hole_with_rect_pad"){const o=n.hole_diameter*Math.abs(t.a),s=n.rect_pad_width*Math.abs(t.a),a=n.rect_pad_height*Math.abs(t.a),c=o/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"pinout-hole-outer-pad",fill:pN,x:(i-s/2).toString(),y:(r-a/2).toString(),width:s.toString(),height:a.toString()},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"pinout-hole-inner",fill:fN,cx:i.toString(),cy:r.toString(),r:c.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="pill_hole_with_rect_pad"){const o=n.rect_pad_width*Math.abs(t.a),s=n.rect_pad_height*Math.abs(t.a),a=n.hole_height*Math.abs(t.a),c=n.hole_width*Math.abs(t.a),l=Math.min(a,c)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"pinout-hole-outer-pad",fill:pN,x:(i-o/2).toString(),y:(r-s/2).toString(),width:o.toString(),height:s.toString()},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"pinout-hole-inner",fill:fN,x:(i-c/2).toString(),y:(r-a/2).toString(),width:c.toString(),height:a.toString(),rx:l.toString(),ry:l.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="rotated_pill_hole_with_rect_pad"){const o=n.rect_pad_width*Math.abs(t.a),s=n.rect_pad_height*Math.abs(t.a),a=n.hole_height*Math.abs(t.a),c=n.hole_width*Math.abs(t.a),l=Math.min(a,c)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"pinout-hole-outer-pad",fill:pN,x:(-o/2).toString(),y:(-s/2).toString(),width:o.toString(),height:s.toString(),transform:`translate(${i} ${r}) rotate(${-n.rect_ccw_rotation})`},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"pinout-hole-inner",fill:fN,x:(-c/2).toString(),y:(-a/2).toString(),width:c.toString(),height:a.toString(),rx:l.toString(),ry:l.toString(),transform:`translate(${i} ${r}) rotate(${-n.hole_ccw_rotation})`},value:"",children:[]}],value:"",attributes:{}}]}return[]}var mN="rgb(218, 165, 32)";function R1n(n,e){const{transform:t}=e;if(n.shape==="rect"||n.shape==="rotated_rect"){const i=n.width*Math.abs(t.a),r=n.height*Math.abs(t.d),[o,s]=Yt(t,[n.x,n.y]);return n.shape==="rotated_rect"&&n.ccw_rotation?[{name:"rect",type:"element",attributes:{class:"pinout-pad",fill:mN,x:(-i/2).toString(),y:(-r/2).toString(),width:i.toString(),height:r.toString(),transform:`translate(${o} ${s}) rotate(${-n.ccw_rotation})`,"data-layer":n.layer},value:"",children:[]}]:[{name:"rect",type:"element",attributes:{class:"pinout-pad",fill:mN,x:(o-i/2).toString(),y:(s-r/2).toString(),width:i.toString(),height:r.toString(),"data-layer":n.layer},value:"",children:[]}]}if(n.shape==="pill"){const i=n.width*Math.abs(t.a),r=n.height*Math.abs(t.d),o=n.radius*Math.abs(t.a),[s,a]=Yt(t,[n.x,n.y]);return[{name:"rect",type:"element",attributes:{class:"pinout-pad",fill:mN,x:(s-i/2).toString(),y:(a-r/2).toString(),width:i.toString(),height:r.toString(),rx:o.toString(),ry:o.toString(),"data-layer":n.layer},value:"",children:[]}]}if(n.shape==="circle"){const i=n.radius*Math.abs(t.a),[r,o]=Yt(t,[n.x,n.y]);return[{name:"circle",type:"element",attributes:{class:"pinout-pad",fill:mN,cx:r.toString(),cy:o.toString(),r:i.toString(),"data-layer":n.layer},value:"",children:[]}]}if(n.shape==="polygon"){const i=(n.points??[]).map(r=>Yt(t,[r.x,r.y]));return[{name:"polygon",type:"element",attributes:{class:"pinout-pad",fill:mN,points:i.map(r=>r.join(",")).join(" "),"data-layer":n.layer},value:"",children:[]}]}return[]}var P1n="rgb(255, 255, 255)",I1n="rgb(0, 0, 0)",N1n="rgba(0, 0, 0, 0.6)";function k1n(n,e){const t=e.label_positions.get(n.pcb_port_id);if(!t)return[];const{text:i,aliases:r,elbow_end:o,label_pos:s,edge:a}=t,[c,l]=Yt(e.transform,[n.x,n.y]),u=a==="left"?"x-":a==="right"?"x+":a==="top"?"y-":"y+",d=a==="left"?"x+":a==="right"?"x-":a==="top"?"y+":"y-",f=[...zF({x:c,y:l,facingDirection:u},{x:o.x,y:o.y,facingDirection:d},{}),s].map(P=>`${P.x},${P.y}`).join(" "),m=[i,...r].join(" | "),y=11,g=m.length*y*.6,b=5,v=y+2*b,w=g+2*b,T=s.y;let N,R;return a==="left"?(N=s.x-w,R=s.x-w/2):a==="right"?(N=s.x,R=s.x+w/2):(N=s.x-w/2,R=s.x),[{name:"polyline",type:"element",attributes:{points:f,stroke:N1n,"stroke-width":"1.5",fill:"none"},children:[],value:""},{name:"rect",type:"element",attributes:{x:N.toString(),y:(T-v/2).toString(),width:w.toString(),height:v.toString(),fill:I1n,rx:"8",ry:"8",stroke:"none"},children:[],value:""},{name:"text",type:"element",attributes:{x:R.toString(),y:T.toString(),fill:P1n,"font-size":`${y}px`,"font-family":"Arial, sans-serif","font-weight":"bold","text-anchor":"middle","dominant-baseline":"middle"},children:[{type:"text",value:m,name:"",attributes:{},children:[]}],value:""}]}function jKe(n,e){const t=ta(e).source_port.get(n.source_port_id);if(!t)return null;const i=t.port_hints?.filter(s=>!/^\d+$/.test(s)&&!["left","right","top","bottom"].includes(s))??[];let r=i[0];if(r||(r=t.name),!r)return null;const o=i.filter(s=>s!==r);return{text:r,aliases:o}}function O1n(n,e){const t={left:n.x-e.minX,right:e.maxX-n.x,top:e.maxY-n.y,bottom:n.y-e.minY};let i="left",r=t.left;return t.right<r&&(r=t.right,i="right"),t.top<r&&(r=t.top,i="top"),t.bottom<r&&(r=t.bottom,i="bottom"),i}var HKe=20,VKe=2,_H=15,GKe=10,YKe=11,qKe=5,k_e=YKe+2*qKe,yH=5;function XKe(n,e,{transform:t,soup:i,board_bounds:r,svgHeight:o},s){const a=e.map(g=>({port:g,y:Yt(t,[g.x,g.y])[1],label_info:jKe(g,i)})).filter(g=>g.label_info).sort((g,b)=>g.y-b.y);if(a.length===0)return;const c=Yt(t,[n==="left"?r.minX:r.maxX,0])[0],l=a.length,u=(l-1)/2,d=HKe+l*VKe,f=d+u*_H+GKe,m=l*k_e+Math.max(0,l-1)*yH;let y=(o-m)/2+k_e/2;a.forEach(({port:g,label_info:b},v)=>{const w=Math.abs(v-u),T=u-w,N=d+T*_H,R=n==="left"?-1:1,P={x:c+R*N,y},M={x:c+R*f,y};s.set(g.pcb_port_id,{text:b.text,aliases:b.aliases,elbow_end:P,label_pos:M,edge:n}),y+=k_e+yH})}function WKe(n,e,{transform:t,soup:i,board_bounds:r,svgWidth:o},s){const a=e.map(b=>({port:b,x:Yt(t,[b.x,b.y])[0],label_info:jKe(b,i)})).filter(b=>b.label_info).sort((b,v)=>b.x-v.x);if(a.length===0)return;const c=Yt(t,[0,n==="top"?r.maxY:r.minY])[1],l=a.map(b=>{const T=[b.label_info.text,...b.label_info.aliases].join(" | ").length*YKe*.6+2*qKe;return{...b,rectWidth:T}}),u=l.length,d=(u-1)/2,h=HKe+u*VKe,m=h+d*_H+GKe,y=l.reduce((b,v)=>b+v.rectWidth,0)+Math.max(0,u-1)*yH;let g=(o-y)/2;l.forEach(({port:b,label_info:v,rectWidth:w},T)=>{const N=Math.abs(T-d),R=d-N,P=h+R*_H,M=n==="top"?-1:1,I=g+w/2,A={x:I,y:c+M*P},U={x:I,y:c+M*m};s.set(b.pcb_port_id,{text:v.text,aliases:v.aliases,elbow_end:A,label_pos:U,edge:n}),g+=w+yH})}var L1n=({ports_by_edge:n,transform:e,soup:t,board_bounds:i,svgWidth:r,svgHeight:o})=>{const s=new Map,a={transform:e,soup:t,board_bounds:i};return XKe("left",n.left,{...a,svgHeight:o},s),XKe("right",n.right,{...a,svgHeight:o},s),WKe("top",n.top,{...a,svgWidth:r},s),WKe("bottom",n.bottom,{...a,svgWidth:r},s),s},ZKe=["pcb_board","pcb_smtpad","pcb_hole","pcb_plated_hole","pcb_component","pcb_port"];function KKe(n,e){let t=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY;for(const A of n)if(A.type==="pcb_board")if("outline"in A&&A.outline&&Array.isArray(A.outline)&&A.outline.length>0)for(const U of A.outline)t=Math.min(t,U.x),i=Math.min(i,U.y),r=Math.max(r,U.x),o=Math.max(o,U.y);else{const U=A.center,k=A.width||0,V=A.height||0;t=Math.min(t,U.x-k/2),i=Math.min(i,U.y-V/2),r=Math.max(r,U.x+k/2),o=Math.max(o,U.y+V/2)}const s=20,a=r-t+2*s,c=o-i+2*s,l=e?.width??800,u=e?.height??600,d=l/a,h=u/c,f=Math.min(d,h),m=(l-a*f)/2,y=(u-c*f)/2,g=ls(Rs(m-t*f+s*f,u-y+i*f-s*f),kg(f,-f)),b={minX:t,minY:i,maxX:r,maxY:o},v=n.filter(A=>A.type==="pcb_port"&&A.is_board_pinout),w={left:[],right:[],top:[],bottom:[]};for(const A of v){const U=O1n({x:A.x,y:A.y},b);w[U].push(A)}const T=L1n({ports_by_edge:w,transform:g,soup:n,board_bounds:b,svgWidth:l,svgHeight:u}),N={transform:g,soup:n,label_positions:T},R=n.sort((A,U)=>(ZKe.indexOf(A.type)??9999)-(ZKe.indexOf(U.type)??9999)).flatMap(A=>D1n(A,N)),P=mC(n),M=_C,I={name:"svg",type:"element",attributes:{xmlns:"http://www.w3.org/2000/svg",width:l.toString(),height:u.toString(),...P&&{"data-software-used-string":P},...e?.includeVersion&&{"data-circuit-to-svg-version":M}},value:"",children:[{name:"rect",type:"element",attributes:{fill:"rgb(255, 255, 255)",x:"0",y:"0",width:l.toString(),height:u.toString()},value:"",children:[]},...R].filter(A=>A!==null)};return Y7(I)}function D1n(n,e,t){switch(n.type){case"pcb_board":return S1n(n,e);case"pcb_component":return M1n(n,e);case"pcb_smtpad":return R1n(n,e);case"pcb_hole":return A1n(n,e);case"pcb_plated_hole":return C1n(n,e);case"pcb_port":return n.is_board_pinout?k1n(n,e):[];default:return[]}}var Vw={"3d_viewer":{background_bottom:"rgb(102, 102, 128)",background_top:"rgb(204, 204, 230)",board:"rgb(51, 43, 23)",copper:"rgb(179, 156, 0)",silkscreen_bottom:"rgb(230, 230, 230)",silkscreen_top:"rgb(230, 230, 230)",soldermask:"rgb(20, 51, 36)",solderpaste:"rgb(128, 128, 128)"},board:{anchor:"rgb(255, 38, 226)",aux_items:"rgb(255, 255, 255)",b_adhes:"rgb(0, 0, 132)",b_crtyd:"rgb(255, 38, 226)",b_fab:"rgb(88, 93, 132)",b_mask:"rgba(2, 255, 238, 0.400)",b_paste:"rgb(0, 194, 194)",b_silks:"rgb(232, 178, 167)",background:"rgb(0, 16, 35)",cmts_user:"rgb(89, 148, 220)",copper:{b:"rgb(77, 127, 196)",f:"rgb(200, 52, 52)",in1:"rgb(127, 200, 127)",in10:"rgb(237, 124, 51)",in11:"rgb(91, 195, 235)",in12:"rgb(247, 111, 142)",in13:"rgb(167, 165, 198)",in14:"rgb(40, 204, 217)",in15:"rgb(232, 178, 167)",in16:"rgb(242, 237, 161)",in17:"rgb(237, 124, 51)",in18:"rgb(91, 195, 235)",in19:"rgb(247, 111, 142)",in2:"rgb(206, 125, 44)",in20:"rgb(167, 165, 198)",in21:"rgb(40, 204, 217)",in22:"rgb(232, 178, 167)",in23:"rgb(242, 237, 161)",in24:"rgb(237, 124, 51)",in25:"rgb(91, 195, 235)",in26:"rgb(247, 111, 142)",in27:"rgb(167, 165, 198)",in28:"rgb(40, 204, 217)",in29:"rgb(232, 178, 167)",in3:"rgb(79, 203, 203)",in30:"rgb(242, 237, 161)",in4:"rgb(219, 98, 139)",in5:"rgb(167, 165, 198)",in6:"rgb(40, 204, 217)",in7:"rgb(232, 178, 167)",in8:"rgb(242, 237, 161)",in9:"rgb(141, 203, 129)"},cursor:"rgb(255, 255, 255)",drc:"rgb(194, 194, 194)",drc_error:"rgba(215, 91, 107, 0.800)",drc_exclusion:"rgb(255, 255, 255)",drc_warning:"rgba(255, 208, 66, 0.902)",dwgs_user:"rgb(194, 194, 194)",eco1_user:"rgb(180, 219, 210)",eco2_user:"rgb(216, 200, 82)",edge_cuts:"rgb(208, 210, 205)",f_adhes:"rgb(132, 0, 132)",f_crtyd:"rgb(255, 0, 245)",f_fab:"rgb(175, 175, 175)",f_mask:"rgba(216, 100, 255, 0.400)",f_paste:"rgba(180, 160, 154, 0.902)",f_silks:"rgb(242, 237, 161)",footprint_text_back:"rgb(0, 0, 132)",footprint_text_front:"rgb(194, 194, 194)",footprint_text_invisible:"rgb(132, 132, 132)",grid:"rgb(132, 132, 132)",grid_axes:"rgb(194, 194, 194)",margin:"rgb(255, 38, 226)",microvia:"rgb(0, 132, 132)",no_connect:"rgb(0, 0, 132)",pad_back:"rgb(77, 127, 196)",pad_front:"rgb(200, 52, 52)",pad_plated_hole:"rgb(194, 194, 0)",pad_through_hole:"rgb(227, 183, 46)",plated_hole:"rgb(26, 196, 210)",ratsnest:"rgba(245, 255, 213, 0.702)",select_overlay:"rgb(4, 255, 67)",through_via:"rgb(236, 236, 236)",user_1:"rgb(194, 194, 194)",user_2:"rgb(89, 148, 220)",user_3:"rgb(180, 219, 210)",user_4:"rgb(216, 200, 82)",user_5:"rgb(194, 194, 194)",user_6:"rgb(89, 148, 220)",user_7:"rgb(180, 219, 210)",user_8:"rgb(216, 200, 82)",user_9:"rgb(232, 178, 167)",via_blind_buried:"rgb(187, 151, 38)",via_hole:"rgb(227, 183, 46)",via_micro:"rgb(0, 132, 132)",via_through:"rgb(236, 236, 236)",worksheet:"rgb(200, 114, 171)"},gerbview:{axes:"rgb(0, 0, 132)",background:"rgb(0, 0, 0)",dcodes:"rgb(255, 255, 255)",grid:"rgb(132, 132, 132)",layers:["rgb(132, 0, 0)","rgb(194, 194, 0)","rgb(194, 0, 194)","rgb(194, 0, 0)","rgb(0, 132, 132)","rgb(0, 132, 0)","rgb(0, 0, 132)","rgb(132, 132, 132)","rgb(132, 0, 132)","rgb(194, 194, 194)","rgb(132, 0, 132)","rgb(132, 0, 0)","rgb(132, 132, 0)","rgb(194, 194, 194)","rgb(0, 0, 132)","rgb(0, 132, 0)","rgb(132, 0, 0)","rgb(194, 194, 0)","rgb(194, 0, 194)","rgb(194, 0, 0)","rgb(0, 132, 132)","rgb(0, 132, 0)","rgb(0, 0, 132)","rgb(132, 132, 132)","rgb(132, 0, 132)","rgb(194, 194, 194)","rgb(132, 0, 132)","rgb(132, 0, 0)","rgb(132, 132, 0)","rgb(194, 194, 194)","rgb(0, 0, 132)","rgb(0, 132, 0)","rgb(132, 0, 0)","rgb(194, 194, 0)","rgb(194, 0, 194)","rgb(194, 0, 0)","rgb(0, 132, 132)","rgb(0, 132, 0)","rgb(0, 0, 132)","rgb(132, 132, 132)","rgb(132, 0, 132)","rgb(194, 194, 194)","rgb(132, 0, 132)","rgb(132, 0, 0)","rgb(132, 132, 0)","rgb(194, 194, 194)","rgb(0, 0, 132)","rgb(0, 132, 0)","rgb(132, 0, 0)","rgb(194, 194, 0)","rgb(194, 0, 194)","rgb(194, 0, 0)","rgb(0, 132, 132)","rgb(0, 132, 0)","rgb(0, 0, 132)","rgb(132, 132, 132)","rgb(132, 0, 132)","rgb(194, 194, 194)","rgb(132, 0, 132)","rgb(132, 0, 0)"],negative_objects:"rgb(132, 132, 132)",worksheet:"rgb(0, 0, 132)"},meta:{filename:"kicad_2020",name:"KiCad 2020",version:2},palette:["rgb(132, 0, 0)","rgb(194, 194, 0)","rgb(194, 0, 194)","rgb(194, 0, 0)","rgb(0, 132, 132)","rgb(0, 132, 0)","rgb(0, 0, 132)","rgb(132, 132, 132)","rgb(132, 0, 132)","rgb(194, 194, 194)","rgb(132, 0, 132)","rgb(132, 0, 0)","rgb(132, 132, 0)","rgb(194, 194, 194)","rgb(0, 0, 132)","rgb(0, 132, 0)"],schematic:{aux_items:"rgb(46, 46, 46)",background:"rgb(245, 241, 237)",brightened:"rgb(255, 0, 255)",bus:"rgb(0, 0, 132)",bus_junction:"rgb(0, 0, 132)",component_body:"rgb(255, 255, 194)",component_outline:"rgb(132, 0, 0)",cursor:"rgb(15, 15, 15)",erc_error:"rgba(230, 9, 13, 0.800)",erc_warning:"rgba(209, 146, 0, 0.800)",fields:"rgb(132, 0, 132)",grid:"rgb(181, 181, 181)",grid_axes:"rgb(0, 0, 132)",hidden:"rgb(194, 194, 194)",junction:"rgb(0, 150, 0)",label_global:"rgb(132, 0, 0)",label_background:"rgba(255, 255, 255, 0.6)",label_hier:"rgb(114, 86, 0)",label_local:"rgb(15, 15, 15)",net_name:"rgb(132, 132, 132)",no_connect:"rgb(0, 0, 132)",note:"rgb(0, 0, 194)",override_item_colors:!1,pin:"rgb(132, 0, 0)",pin_name:"rgb(0, 100, 100)",pin_number:"rgb(169, 0, 0)",reference:"rgb(0, 100, 100)",shadow:"rgba(102, 179, 255, 0.800)",sheet:"rgb(132, 0, 0)",sheet_background:"rgba(253, 255, 231, 0.000)",sheet_fields:"rgb(132, 0, 132)",sheet_filename:"rgb(114, 86, 0)",sheet_label:"rgb(0, 100, 100)",sheet_name:"rgb(0, 100, 100)",table:"rgb(102, 102, 102)",value:"rgb(0, 100, 100)",wire:"rgb(0, 150, 0)",wire_crossing:"rgb(30, 180, 30)",worksheet:"rgb(132, 0, 0)"}};function z1n(n){const{minX:e,minY:t,maxX:i,maxY:r}=n.bounds,o=n.cellSize??1,s=n.labelCells??!1,a=[],c=(l,u)=>{const[d,h]=Yt(n.transform,[l,u]);return{x:d,y:h}};for(let l=Math.floor(e);l<=Math.ceil(i);l+=o){const u=c(l,t),d=c(l,r);a.push({name:"line",type:"element",attributes:{x1:u.x.toString(),y1:u.y.toString(),x2:d.x.toString(),y2:d.y.toString(),stroke:Vw.schematic.grid,"stroke-width":(.01*Math.abs(n.transform.a)).toString(),"stroke-opacity":"0.5"}})}for(let l=Math.floor(t);l<=Math.ceil(r);l+=o){const u=c(e,l),d=c(i,l);a.push({name:"line",type:"element",attributes:{x1:u.x.toString(),y1:u.y.toString(),x2:d.x.toString(),y2:d.y.toString(),stroke:Vw.schematic.grid,"stroke-width":(.01*Math.abs(n.transform.a)).toString(),"stroke-opacity":"0.5"}})}if(s){const l=(u,d)=>o<=.1?`${u.toFixed(1)},${d.toFixed(1)}`:`${u},${d}`;for(let u=Math.floor(e);u<=Math.ceil(i);u+=o)for(let d=Math.floor(t);d<=Math.ceil(r);d+=o){const h=c(u,d);a.push({name:"text",type:"element",attributes:{x:(h.x-2.5).toString(),y:(h.y-5).toString(),fill:Vw.schematic.grid,"font-size":(o/5*Math.abs(n.transform.a)).toString(),"fill-opacity":"0.5","text-anchor":"middle","dominant-baseline":"middle","font-family":"sans-serif"},children:[{type:"text",value:l(u,d),name:"",attributes:{},children:[]}]})}}return{name:"g",value:"",type:"element",attributes:{class:"grid"},children:a}}function F1n(n){const{points:e,transform:t}=n,i=[];for(const r of e){const[o,s]=Yt(t,[r.x-.1,r.y-.1]),[a,c]=Yt(t,[r.x+.1,r.y+.1]),[l,u]=Yt(t,[r.x-.1,r.y+.1]),[d,h]=Yt(t,[r.x+.1,r.y-.1]);i.push({name:"path",type:"element",attributes:{d:`M${o},${s} L${a},${c} M${l},${u} L${d},${h}`,stroke:Vw.schematic.grid,"stroke-width":(.02*Math.abs(t.a)).toString(),"stroke-opacity":"0.7"}});const[f,m]=Yt(t,[r.x+.15,r.y-.15]);i.push({name:"text",type:"element",attributes:{x:f.toString(),y:m.toString(),fill:Vw.schematic.grid,"font-size":(.1*Math.abs(t.a)).toString(),"fill-opacity":"0.7","text-anchor":"start","font-family":"sans-serif","dominant-baseline":"middle"},children:[{type:"text",value:r.label||`(${r.x},${r.y})`,name:"",attributes:{},children:[]}]})}return{name:"g",value:"",type:"element",attributes:{class:"labeled-points"},children:i}}var QKe={0:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},1:{width:13,height:27,ascent:22,descent:5,left:-3,right:9},2:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},3:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},4:{width:13,height:27,ascent:22,descent:5,left:0,right:12},5:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},6:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},7:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},8:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},9:{width:13,height:27,ascent:22,descent:5,left:-1,right:12}," ":{width:7,height:27,ascent:22,descent:5,left:0,right:0},"!":{width:7,height:27,ascent:22,descent:5,left:-2,right:5},'"':{width:9,height:27,ascent:22,descent:5,left:-1,right:7},"#":{width:13,height:27,ascent:22,descent:5,left:0,right:13},$:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},"%":{width:21,height:27,ascent:22,descent:5,left:-1,right:20},"&":{width:16,height:27,ascent:22,descent:5,left:-1,right:15},"'":{width:5,height:27,ascent:22,descent:5,left:-1,right:3},"(":{width:8,height:27,ascent:22,descent:5,left:-1,right:7},")":{width:8,height:27,ascent:22,descent:5,left:-1,right:7},"*":{width:9,height:27,ascent:22,descent:5,left:-1,right:8},"+":{width:14,height:27,ascent:22,descent:5,left:-1,right:13},",":{width:7,height:27,ascent:22,descent:5,left:-2,right:5},"-":{width:8,height:27,ascent:22,descent:5,left:-1,right:7},".":{width:7,height:27,ascent:22,descent:5,left:-2,right:5},"/":{width:7,height:27,ascent:22,descent:5,left:0,right:7},":":{width:7,height:27,ascent:22,descent:5,left:-2,right:5},";":{width:7,height:27,ascent:22,descent:5,left:-2,right:5},"<":{width:14,height:27,ascent:22,descent:5,left:-1,right:13},"=":{width:14,height:27,ascent:22,descent:5,left:-1,right:13},">":{width:14,height:27,ascent:22,descent:5,left:-1,right:13},"?":{width:13,height:27,ascent:22,descent:5,left:-1,right:12},"@":{width:24,height:27,ascent:22,descent:5,left:-1,right:23},A:{width:16,height:27,ascent:22,descent:5,left:0,right:16},B:{width:16,height:27,ascent:22,descent:5,left:-2,right:15},C:{width:17,height:27,ascent:22,descent:5,left:-1,right:16},D:{width:17,height:27,ascent:22,descent:5,left:-2,right:16},E:{width:16,height:27,ascent:22,descent:5,left:-2,right:15},F:{width:15,height:27,ascent:22,descent:5,left:-2,right:14},G:{width:19,height:27,ascent:22,descent:5,left:-1,right:17},H:{width:17,height:27,ascent:22,descent:5,left:-2,right:15},I:{width:7,height:27,ascent:22,descent:5,left:-2,right:5},J:{width:12,height:27,ascent:22,descent:5,left:-1,right:10},K:{width:16,height:27,ascent:22,descent:5,left:-2,right:16},L:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},M:{width:20,height:27,ascent:22,descent:5,left:-2,right:18},N:{width:17,height:27,ascent:22,descent:5,left:-2,right:15},O:{width:19,height:27,ascent:22,descent:5,left:-1,right:18},P:{width:16,height:27,ascent:22,descent:5,left:-2,right:15},Q:{width:19,height:27,ascent:22,descent:5,left:-1,right:18},R:{width:17,height:27,ascent:22,descent:5,left:-2,right:17},S:{width:16,height:27,ascent:22,descent:5,left:-1,right:15},T:{width:15,height:27,ascent:22,descent:5,left:-1,right:14},U:{width:17,height:27,ascent:22,descent:5,left:-2,right:15},V:{width:16,height:27,ascent:22,descent:5,left:0,right:16},W:{width:23,height:27,ascent:22,descent:5,left:0,right:22},X:{width:16,height:27,ascent:22,descent:5,left:0,right:16},Y:{width:16,height:27,ascent:22,descent:5,left:0,right:16},Z:{width:15,height:27,ascent:22,descent:5,left:0,right:14},"[":{width:7,height:27,ascent:22,descent:5,left:-2,right:6},"\\":{width:7,height:27,ascent:22,descent:5,left:0,right:7},"]":{width:7,height:27,ascent:22,descent:5,left:0,right:5},"^":{width:11,height:27,ascent:22,descent:5,left:-1,right:11},_:{width:13,height:27,ascent:22,descent:5,left:0,right:14},"`":{width:8,height:27,ascent:22,descent:5,left:-1,right:5},a:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},b:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},c:{width:12,height:27,ascent:22,descent:5,left:-1,right:12},d:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},e:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},f:{width:7,height:27,ascent:22,descent:5,left:0,right:8},g:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},h:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},i:{width:5,height:27,ascent:22,descent:5,left:-2,right:4},j:{width:5,height:27,ascent:22,descent:5,left:1,right:4},k:{width:12,height:27,ascent:22,descent:5,left:-2,right:12},l:{width:5,height:27,ascent:22,descent:5,left:-2,right:4},m:{width:20,height:27,ascent:22,descent:5,left:-2,right:18},n:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},o:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},p:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},q:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},r:{width:8,height:27,ascent:22,descent:5,left:-2,right:8},s:{width:12,height:27,ascent:22,descent:5,left:-1,right:11},t:{width:7,height:27,ascent:22,descent:5,left:0,right:6},u:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},v:{width:12,height:27,ascent:22,descent:5,left:0,right:12},w:{width:17,height:27,ascent:22,descent:5,left:0,right:17},x:{width:12,height:27,ascent:22,descent:5,left:0,right:12},y:{width:12,height:27,ascent:22,descent:5,left:0,right:12},z:{width:12,height:27,ascent:22,descent:5,left:0,right:11},"{":{width:8,height:27,ascent:22,descent:5,left:-1,right:7},"|":{width:6,height:27,ascent:22,descent:5,left:-2,right:4},"}":{width:8,height:27,ascent:22,descent:5,left:-1,right:7},"~":{width:14,height:27,ascent:22,descent:5,left:-1,right:13}},gH=n=>{if(!n)return 0;let e=0;for(const t of n){const i=QKe[t];i?e+=i.width:e+=QKe["?"].width}return e/27},JKe=(n,e)=>{if(n.column_widths&&n.column_widths.length>0&&n.row_heights&&n.row_heights.length>0){const u=d=>typeof d=="number"?d:d.endsWith("mm")?parseFloat(d):d.endsWith("in")?parseFloat(d)*25.4:parseFloat(d);return{column_widths:n.column_widths.map(u),row_heights:n.row_heights.map(u)}}const t=e.filter(u=>u.type==="schematic_table_cell"&&u.schematic_table_id===n.schematic_table_id);if(t.length===0)return{column_widths:[],row_heights:[]};const i=t.reduce((u,d)=>Math.max(u,d.end_column_index),-1)+1,r=t.reduce((u,d)=>Math.max(u,d.end_row_index),-1)+1,{cell_padding:o=.2}=n,s=new Array(i).fill(0),a=new Array(r).fill(0),c={},l={};for(const u of t){const d=yC("reference_designator",u.font_size),f=gH(u.text??"")*d+2*o,m=d*1.2+2*o,y=`${u.start_row_index}-${u.start_column_index}`;c[y]=f,l[y]=m}for(let u=0;u<r;u++)for(let d=0;d<i;d++){const h=`${u}-${d}`;c[h]&&c[h]>s[d]&&(s[d]=c[h]),l[h]&&l[h]>a[u]&&(a[u]=l[h])}for(const u of t){if(u.start_column_index===u.end_column_index&&u.start_row_index===u.end_row_index)continue;const d=`${u.start_row_index}-${u.start_column_index}`,h=c[d],f=l[d];if(h===void 0||f===void 0)continue;let m=0;for(let g=u.start_column_index;g<=u.end_column_index;g++)m+=s[g];if(h>m){const b=(h-m)/(u.end_column_index-u.start_column_index+1);for(let v=u.start_column_index;v<=u.end_column_index;v++)s[v]+=b}let y=0;for(let g=u.start_row_index;g<=u.end_row_index;g++)y+=a[g];if(f>y){const b=(f-y)/(u.end_row_index-u.start_row_index+1);for(let v=u.start_row_index;v<=u.end_row_index;v++)a[v]+=b}}return{column_widths:s,row_heights:a}},gC=n=>{switch(n){case"top":return{x:0,y:-1};case"bottom":return{x:0,y:1};case"left":return{x:1,y:0};case"right":return{x:-1,y:0}}throw new Error(`Invalid side: ${n}`)},sE=.3,bC=.3,xC=.06,$1n={top_left:"start",top_right:"end",middle_left:"start",middle_right:"end",bottom_left:"start",bottom_right:"end",center:"middle",middle_top:"middle",middle_bottom:"middle"},B1n={top_left:"hanging",top_right:"hanging",bottom_left:"ideographic",bottom_right:"ideographic",center:"middle",middle_left:"middle",middle_right:"middle",middle_top:"hanging",middle_bottom:"ideographic"};function U1n(n){return{left:180,top:90,bottom:-90,right:0}[n]??0}function j1n(n,e,t){const i=t+sE*2+xC*n.text.length+bC,r=gC(n.anchor_side);return n.anchor_position??{x:n.center.x-r.x*i*e/2,y:n.center.y-r.y*i*e/2}}function H1n(n,e=.5){let t=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY;const s=.2;for(const c of n)if(c.type==="schematic_component")a(c.center,c.size,0);else if(c.type==="schematic_port")a(c.center,{width:s,height:s},0);else if(c.type==="schematic_debug_object")c.shape==="rect"?a(c.center,c.size,0):c.shape==="line"&&(a(c.start,{width:.1,height:.1},0),a(c.end,{width:.1,height:.1},0));else if(c.type==="schematic_net_label"){const l=yC("net_label"),u=gH(c.text||""),h=(u+sE*2+xC*(c.text?.length||0)+bC)*l,f=1.2*l,m=U1n(c.anchor_side)/180*Math.PI,y=j1n(c,l,u),g=gC(c.anchor_side),b={x:y.x+g.x*h/2,y:y.y+g.y*h/2};a(b,{width:h,height:f},m)}else if(c.type==="schematic_trace")for(const l of c.edges)a(l.from,{width:.1,height:.1},0),a(l.to,{width:.1,height:.1},0);else if(c.type==="schematic_text"){const u=yC("reference_designator",c.font_size)??.18,h=(c.text??"").length*u,f=u;a(c.position,{width:h,height:f},c.rotation??0)}else if(c.type==="schematic_voltage_probe")a(c.position,{width:.2,height:.4},0);else if(c.type==="schematic_box")a({x:c.x+c.width/2,y:c.y+c.height/2},{width:c.width,height:c.height},0);else if(c.type==="schematic_table"){const{column_widths:l,row_heights:u}=JKe(c,n),d=l.reduce((v,w)=>v+w,0),h=u.reduce((v,w)=>v+w,0),f=c.anchor??"center";let m=c.anchor_position.x,y=c.anchor_position.y;f.includes("center")?m-=d/2:f.includes("right")&&(m-=d),f.includes("center")?y+=h/2:f.includes("bottom")&&(y+=h);const g=m+d/2,b=y-h/2;a({x:g,y:b},{width:d,height:h},0)}else c.type==="schematic_line"?(a({x:c.x1,y:c.y1},{width:.02,height:.02},0),a({x:c.x2,y:c.y2},{width:.02,height:.02},0)):c.type==="schematic_circle"?a(c.center,{width:c.radius*2,height:c.radius*2},0):c.type==="schematic_rect"?a(c.center,{width:c.width,height:c.height},c.rotation):c.type==="schematic_arc"&&a(c.center,{width:c.radius*2,height:c.radius*2},0);return t-=e,i-=e,r+=e,o+=e,{minX:t,minY:i,maxX:r,maxY:o};function a(c,l,u){const d=[{x:-l.width/2,y:-l.height/2},{x:l.width/2,y:-l.height/2},{x:l.width/2,y:l.height/2},{x:-l.width/2,y:l.height/2}];for(const h of d){const f=h.x*Math.cos(u)-h.y*Math.sin(u)+c.x,m=h.x*Math.sin(u)+h.y*Math.cos(u)+c.y;t=Math.min(t,f),i=Math.min(i,m),r=Math.max(r,f),o=Math.max(o,m)}}}var hb=n=>Math.abs(n.a)*.02,V1n=(n,e)=>{const t=n<0?n+2*Math.PI:n,i=e<0?e+2*Math.PI:e;let r=Math.abs(t-i);return r>Math.PI&&(r=2*Math.PI-r),r},G1n=({schPorts:n,symbol:e,schComponent:t})=>{const i=n.map(a=>{const c=a.center.x-t.center.x,l=a.center.y-t.center.y;return{port:a,angle:Math.atan2(l,c)}}),r=e.ports.map(a=>{const c=a.x-e.center.x,l=a.y-e.center.y;return{port:a,angle:Math.atan2(l,c)}});i.sort((a,c)=>a.angle-c.angle),r.sort((a,c)=>a.angle-c.angle);const o=[],s=new Set;for(const a of i){let c=null;for(const l of r){if(s.has(l.port))continue;const u=V1n(a.angle,l.angle);(c===null||u<c.angleDiff)&&(c={symbolPort:l.port,angleDiff:u})}c&&c.angleDiff<Math.PI/4&&(o.push({schPort:a.port,symbolPort:c.symbolPort}),s.add(c.symbolPort))}return o};function Y1n(n,e,t,i){const r=e.x-n.x,o=e.y-n.y,s=Math.sqrt((t.x-n.x)**2+(t.y-n.y)**2),c=Math.sqrt((i.x-e.x)**2+(i.y-e.y)**2)/s,l=Rs(r,o),u=kg(c,c);return ls(l,u)}var O_e=({text:n,realCenter:e,realToScreenTransform:t})=>{const i=Yt(t,e);return{type:"element",name:"text",value:"",attributes:{x:i.x.toString(),y:i.y.toString(),fill:"red","text-anchor":"middle","dominant-baseline":"middle","font-family":"sans-serif","font-size":`${m3(t,"error")}px`},children:[{type:"text",value:n,name:"",attributes:{},children:[]}]}},eQe=(n,e)=>{for(const t of n){if(t.type!=="source_trace")continue;const i=t;if(Array.isArray(i.connected_source_port_ids)&&i.connected_source_port_ids.includes(e))return!0}return!1},q1n={top_left:"start",top_right:"end",middle_left:"start",middle_right:"end",bottom_left:"start",bottom_right:"end",center:"middle",middle_top:"middle",middle_bottom:"middle"},X1n=({component:n,transform:e,circuitJson:t,colorMap:i})=>{const r=[],o=av[n.symbol_name];if(!o)return[O_e({text:`Symbol not found: ${n.symbol_name}`,realCenter:n.center,realToScreenTransform:e})];const s=ta(t).schematic_port.list({schematic_component_id:n.schematic_component_id}),a=ta(t).source_component.get(n.source_component_id),c=G1n({schPorts:s,symbol:o,schComponent:n});if(!c[0])return[O_e({text:`Could not match ports for symbol ${n.symbol_name}`,realCenter:n.center,realToScreenTransform:e})];const l=Y1n(c[1]?.symbolPort??o.center,c[1]?.schPort.center??n.center,c[0].symbolPort,c[0].schPort.center),u=o.primitives.filter(M=>M.type==="path"),d=o.primitives.filter(M=>M.type==="text"),h=o.primitives.filter(M=>M.type==="circle"),f=o.primitives.filter(M=>M.type==="box"),m=new Set;for(const M of c)eQe(t,M.schPort.source_port_id)&&m.add(M.symbolPort);const y={minX:Math.min(...u.flatMap(M=>M.points.map(I=>I.x))),maxX:Math.max(...u.flatMap(M=>M.points.map(I=>I.x))),minY:Math.min(...u.flatMap(M=>M.points.map(I=>I.y))),maxY:Math.max(...u.flatMap(M=>M.points.map(I=>I.y)))},[g,b]=Yt(ls(e,l),[y.minX,y.minY]),[v,w]=Yt(ls(e,l),[y.maxX,y.maxY]),T=Math.abs(w-b),N=Math.min(b,w),R=Math.abs(v-g),P=Math.min(g,v);r.push({name:"rect",type:"element",value:"",attributes:{class:"component-overlay",x:P.toString(),y:N.toString(),width:R.toString(),height:T.toString(),fill:"transparent"},children:[]});for(const M of u){const{points:I,color:A,closed:U,fill:k}=M;r.push({type:"element",name:"path",attributes:{d:I.map((V,Y)=>{const[W,K]=Yt(ls(e,l),[V.x,V.y]);return`${Y===0?"M":"L"} ${W} ${K}`}).join(" ")+(U?" Z":""),stroke:i.schematic.component_outline,fill:"none","stroke-width":`${hb(e)}px`,"stroke-linecap":"round"},value:"",children:[]})}for(const M of d){const I=Yt(ls(e,l),M);let A="";M.text==="{REF}"?A=a?.name??"":M.text==="{VAL}"&&(A=n.symbol_display_value??"");const V=Math.abs(y.maxY-y.minY)*.1,Y=Math.abs(l.a);let W=0;M.anchor.includes("bottom")?W=V*Y:M.anchor.includes("top")&&(W=-V*Y);const K=M.anchor.includes("bottom")?"auto":M.anchor.includes("top")?"hanging":"middle",ee=M.text==="{REF}";r.push({name:"text",type:"element",attributes:{x:I.x.toString(),y:(I.y+W).toString(),...ee?{stroke:i.schematic.background,"stroke-width":`${hb(e)}px`,"paint-order":"stroke"}:{},fill:i.schematic.label_local,"font-family":"sans-serif","text-anchor":q1n[M.anchor],"dominant-baseline":K,"font-size":`${m3(e,"reference_designator")}px`},value:"",children:[{type:"text",value:A,name:"",attributes:{},children:[]}]})}for(const M of f){const I=Yt(ls(e,l),M),A=ls(e,l).a;r.push({name:"rect",type:"element",attributes:{x:I.x.toString(),y:I.y.toString(),width:(M.width*A).toString(),height:(M.height*A).toString(),fill:"red"},value:"",children:[]})}for(const M of o.ports){if(m.has(M))continue;const I=Yt(ls(e,l),M);r.push({type:"element",name:"circle",attributes:{cx:I.x.toString(),cy:I.y.toString(),r:`${Math.abs(e.a)*.02}px`,"stroke-width":`${hb(e)}px`,fill:"none",stroke:i.schematic.component_outline},value:"",children:[]})}for(const M of h){const I=Yt(ls(e,l),M),A=Math.abs(M.radius*e.a);r.push({type:"element",name:"circle",attributes:{cx:I.x.toString(),cy:I.y.toString(),r:`${A}px`,"stroke-width":`${hb(e)}px`,fill:"none",stroke:i.schematic.component_outline},value:"",children:[]})}return r},_N=.02,tQe=(n,e,t,i,r)=>{const o=Math.PI/6,s={x:n.x-t*Math.cos(e-o),y:n.y-t*Math.sin(e-o)},a={x:n.x-t*Math.cos(e+o),y:n.y-t*Math.sin(e+o)};return{name:"polygon",type:"element",attributes:{points:`${n.x},${n.y} ${s.x},${s.y} ${a.x},${a.y}`,fill:"white",stroke:i,"stroke-width":`${r}px`},value:"",children:[]}},W1n=({schPort:n,schComponent:e,transform:t,circuitJson:i})=>{const r=[];ta(i).source_port.get(n.source_port_id);const o={x:n.center.x,y:n.center.y},s=n.distance_from_component_edge??.4;switch(n.side_of_component){case"left":o.x+=s;break;case"right":o.x-=s;break;case"top":o.y-=s;break;case"bottom":o.y+=s;break}const a=Yt(t,n.center),c=Yt(t,o),l={...n.center};switch(n.side_of_component){case"left":l.x+=_N;break;case"right":l.x-=_N;break;case"top":l.y-=_N;break;case"bottom":l.y+=_N;break}const u=Yt(t,l);r.push({name:"line",type:"element",attributes:{class:"component-pin",x1:u.x.toString(),y1:u.y.toString(),x2:c.x.toString(),y2:c.y.toString(),"stroke-width":`${hb(t)}px`},value:"",children:[]});const d=eQe(i,n.source_port_id),h=Math.abs(t.a)*_N,f=[];d||f.push({name:"circle",type:"element",attributes:{class:"component-pin",cx:a.x.toString(),cy:a.y.toString(),r:h.toString(),"stroke-width":`${hb(t)}px`},value:"",children:[]}),f.push({name:"rect",type:"element",attributes:{x:(a.x-h).toString(),y:(a.y-h).toString(),width:(h*2).toString(),height:(h*2).toString(),opacity:"0"},value:"",children:[]}),r.push({name:"g",type:"element",value:"",attributes:{"data-schematic-port-id":n.source_port_id},children:f});const{has_input_arrow:m,has_output_arrow:y}=n;if((m||y)&&n.side_of_component){const g=Math.abs(t.a)*.1,b=Vw.schematic.component_outline,v=g*Math.cos(Math.PI/6),w=hb(t)/3;let T=0,N=0;n.side_of_component==="left"?(T=0,N=Math.PI):n.side_of_component==="right"?(T=Math.PI,N=0):n.side_of_component==="top"?(T=Math.PI/2,N=-Math.PI/2):n.side_of_component==="bottom"&&(T=-Math.PI/2,N=Math.PI/2);const R=m&&y;let P={...c},M={...c};if(R){const I=v;n.side_of_component==="left"?M.x-=I:n.side_of_component==="right"?M.x+=I:n.side_of_component==="top"?M.y-=I:n.side_of_component==="bottom"&&(M.y+=I)}if(m&&r.push(tQe(P,T,g,b,w)),y){const I={x:M.x+g*Math.cos(N),y:M.y+g*Math.sin(N)};r.push(tQe(I,N,g,b,w))}}return r},Z1n=n=>{const e=[],{schPort:t,transform:i}=n,r={x:t.center.x,y:t.center.y};if(!t.side_of_component)return[];const o=gC(t.side_of_component),s=t.distance_from_component_edge??.4;r.x+=o.x*s/2,r.y+=o.y*s/2,t.side_of_component==="top"||t.side_of_component==="bottom"?r.x-=.02:r.y+=.02;const a=Yt(i,r);return e.push({name:"text",type:"element",attributes:{class:"pin-number",x:a.x.toString(),y:a.y.toString(),style:"font-family: sans-serif;",fill:Vw.schematic.pin_number,"text-anchor":"middle","dominant-baseline":"auto","font-size":`${m3(i,"pin_number")}px`,transform:t.side_of_component==="top"||t.side_of_component==="bottom"?`rotate(-90 ${a.x} ${a.y})`:""},children:[{type:"text",value:t.pin_number?.toString()||"",name:"",attributes:{},children:[]}],value:""}),e},nQe=.1,K1n=n=>{const e=[],{schPort:t,schComponent:i,transform:r}=n,o={x:t.center.x,y:t.center.y};if(!t.side_of_component)return[];const s=gC(t.side_of_component),a=t.distance_from_component_edge??.4;o.x+=s.x*(a+nQe),o.y+=s.y*(a+nQe);const c=Yt(r,o),l=t.display_pin_label??i.port_labels?.[`${t.pin_number}`];if(!l)return[];const u=l.startsWith("N_"),d=u?l.slice(2):l;let h=m3(r,u?"negated_pin_number":"pin_number");return e.push({name:"text",type:"element",attributes:{class:"pin-number",x:c.x.toString(),y:c.y.toString(),style:`font-family: sans-serif;${u?" text-decoration: overline;":""}`,fill:Vw.schematic.pin_number,"text-anchor":t.side_of_component==="left"||t.side_of_component==="bottom"?"start":"end","dominant-baseline":"middle","font-size":`${h}px`,transform:t.side_of_component==="top"||t.side_of_component==="bottom"?`rotate(-90 ${c.x} ${c.y})`:""},children:[{type:"text",value:d||"",name:"",attributes:{},children:[]}],value:""}),e},Q1n=n=>{const e=[];return e.push(...W1n(n)),e.push(...Z1n(n)),e.push(...K1n(n)),e},iQe=({elm:n,transform:e,colorMap:t})=>{const i=Yt(e,n.position),r={center:"middle",center_right:"end",bottom_left:"start",bottom_center:"middle",bottom_right:"end",left:"start",right:"end",top:"middle",bottom:"middle",top_left:"start",top_center:"middle",top_right:"end",center_left:"start"},o={center:"middle",center_right:"middle",bottom_left:"ideographic",bottom_center:"ideographic",bottom_right:"ideographic",left:"middle",right:"middle",top:"hanging",bottom:"ideographic",top_left:"hanging",top_center:"hanging",top_right:"hanging",center_left:"middle"},s=n.text.split(`
5389
+ `,name:"",attributes:{},children:[]}],value:"",attributes:{}},{name:"rect",type:"element",attributes:{fill:"#fff",x:"0",y:"0",width:l.toString(),height:u.toString()},value:"",children:[]},x1n(g,t,i,r,o),...v].filter(R=>R!==null)};return Y7(N)}function b1n(n,e,t){const i=ta(t).source_component.list();switch(n.type){case"pcb_board":return l1n(n,e.transform);case"pcb_component":{const r=i.find(a=>a.source_component_id===n.source_component_id),s=ta(t).pcb_port.list().filter(a=>a.pcb_component_id===n.pcb_component_id)[0];if(r&&s){const a=r.are_pins_interchangeable,c=d1n({elm:n,portPosition:{x:s.x,y:s.y},name:r.name,arePinsInterchangeable:a},e);return c?[c]:[]}return[]}case"pcb_smtpad":return g1n(n,e);case"pcb_hole":return _1n(n,e);case"pcb_plated_hole":return y1n(n,e);default:return[]}}function x1n(n,e,t,i,r){const[o,s]=Yt(n,[e,t]),[a,c]=Yt(n,[i,r]),l=Math.abs(a-o),u=Math.abs(c-s),d=Math.min(o,a),h=Math.min(s,c);return{name:"rect",type:"element",value:"",children:[],attributes:{class:"assembly-boundary",x:d.toString(),y:h.toString(),width:l.toString(),height:u.toString()}}}var v1n="rgb(26, 115, 143)",w1n="rgba(0,0,0,0.9)";function S1n(n,e){const{transform:t,soup:i}=e,{width:r,height:o,center:s,outline:a}=n;let c;if(a&&Array.isArray(a)&&a.length>=3)c=a.map((u,d)=>{const[h,f]=Yt(t,[u.x,u.y]);return d===0?`M ${h} ${f}`:`L ${h} ${f}`}).join(" ");else{const u=r/2,d=o/2,h=Yt(t,[s.x-u,s.y-d]),f=Yt(t,[s.x+u,s.y-d]),m=Yt(t,[s.x+u,s.y+d]),y=Yt(t,[s.x-u,s.y+d]);c=`M ${h[0]} ${h[1]} L ${f[0]} ${f[1]} L ${m[0]} ${m[1]} L ${y[0]} ${y[1]}`}c+=" Z";const l=ta(i).pcb_cutout.list();for(const u of l)if(u.shape==="rect"){const{x:d,y:h,width:f,height:m}=u.center?(()=>{const{x:N,y:R}=u.center,{width:P,height:M}=u;return{x:N,y:R,width:P,height:M}})():{x:0,y:0,width:0,height:0},y=f/2,g=m/2,[b,v,w,T]=[Yt(t,[d-y,h-g]),Yt(t,[d+y,h-g]),Yt(t,[d+y,h+g]),Yt(t,[d-y,h+g])];c+=` M ${b[0]} ${b[1]} L ${v[0]} ${v[1]} L ${w[0]} ${w[1]} L ${T[0]} ${T[1]} Z`}else u.shape;return[{name:"path",type:"element",value:"",children:[],attributes:{class:"pinout-board",d:c,fill:v1n,stroke:w1n,"fill-rule":"evenodd","stroke-opacity":"0.8","stroke-width":(.2*Math.abs(t.a)).toString()}}]}var E1n="rgba(120, 120, 120, 0.6)",T1n="rgba(255, 255, 255, 0.9)";function M1n(n,e){const{transform:t,soup:i}=e,{center:r,width:o,height:s,rotation:a=0,source_component_id:c}=n,l=ta(i).source_component.get(c);if(!r||typeof o!="number"||typeof s!="number"||o===0||s===0)return[];const[u,d]=Yt(t,[r.x,r.y]),h=o*Math.abs(t.a),f=s*Math.abs(t.d),m=`translate(${u}, ${d}) rotate(${-a})`,y=[{name:"rect",type:"element",attributes:{class:"pinout-component-box",x:(-h/2).toString(),y:(-f/2).toString(),width:h.toString(),height:f.toString(),fill:E1n},value:"",children:[]}];if(l?.name){const g=f>h*1.5,b=Math.min(h,f)*.4;y.push({name:"text",type:"element",attributes:{x:"0",y:"0",fill:T1n,"font-size":`${b}px`,"font-family":"sans-serif","text-anchor":"middle","dominant-baseline":"middle",transform:g?"rotate(90)":""},children:[{type:"text",value:l.name,name:"",attributes:{},children:[]}],value:""})}return[{name:"g",type:"element",attributes:{transform:m},children:y,value:""}]}var N_e="rgb(50, 50, 50)";function A1n(n,e){const{transform:t}=e,[i,r]=Yt(t,[n.x,n.y]);if(n.hole_shape==="circle"||n.hole_shape==="square"){const o=n.hole_diameter*Math.abs(t.a),s=o/2;return n.hole_shape==="circle"?[{name:"circle",type:"element",attributes:{class:"pinout-hole",cx:i.toString(),cy:r.toString(),r:s.toString(),fill:N_e},children:[],value:""}]:[{name:"rect",type:"element",attributes:{class:"pinout-hole",x:(i-s).toString(),y:(r-s).toString(),width:o.toString(),height:o.toString(),fill:N_e},children:[],value:""}]}if(n.hole_shape==="oval"){const o=n.hole_width*Math.abs(t.a),s=n.hole_height*Math.abs(t.a),a=o/2,c=s/2;return[{name:"ellipse",type:"element",attributes:{class:"pinout-hole",cx:i.toString(),cy:r.toString(),rx:a.toString(),ry:c.toString(),fill:N_e},children:[],value:""}]}return[]}var pN="rgb(218, 165, 32)",fN="rgb(40, 40, 40)";function C1n(n,e){const{transform:t}=e,[i,r]=Yt(t,[n.x,n.y]);if(n.shape==="pill"){const o=n.outer_width*Math.abs(t.a),s=n.outer_height*Math.abs(t.a),a=n.hole_width*Math.abs(t.a),c=n.hole_height*Math.abs(t.a),l=o/2,u=s-o,d=a/2;return[{name:"g",type:"element",children:[{name:"path",type:"element",attributes:{class:"pinout-hole-outer",fill:pN,d:`M${i-l},${r-u/2} v${u} a${l},${l} 0 0 0 ${o},0 v-${u} a${l},${l} 0 0 0 -${o},0 z`},value:"",children:[]},{name:"path",type:"element",attributes:{class:"pinout-hole-inner",fill:fN,d:`M${i-d},${r-(c-a)/2} v${c-a} a${d},${d} 0 0 0 ${a},0 v-${c-a} a${d},${d} 0 0 0 -${a},0 z`},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="circle"){const o=n.outer_diameter*Math.abs(t.a),s=n.outer_diameter*Math.abs(t.a),a=n.hole_diameter*Math.abs(t.a),c=n.hole_diameter*Math.abs(t.a),l=Math.min(o,s)/2,u=Math.min(a,c)/2;return[{name:"g",type:"element",children:[{name:"circle",type:"element",attributes:{class:"pinout-hole-outer",fill:pN,cx:i.toString(),cy:r.toString(),r:l.toString()},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"pinout-hole-inner",fill:fN,cx:i.toString(),cy:r.toString(),r:u.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="circular_hole_with_rect_pad"){const o=n.hole_diameter*Math.abs(t.a),s=n.rect_pad_width*Math.abs(t.a),a=n.rect_pad_height*Math.abs(t.a),c=o/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"pinout-hole-outer-pad",fill:pN,x:(i-s/2).toString(),y:(r-a/2).toString(),width:s.toString(),height:a.toString()},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"pinout-hole-inner",fill:fN,cx:i.toString(),cy:r.toString(),r:c.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="pill_hole_with_rect_pad"){const o=n.rect_pad_width*Math.abs(t.a),s=n.rect_pad_height*Math.abs(t.a),a=n.hole_height*Math.abs(t.a),c=n.hole_width*Math.abs(t.a),l=Math.min(a,c)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"pinout-hole-outer-pad",fill:pN,x:(i-o/2).toString(),y:(r-s/2).toString(),width:o.toString(),height:s.toString()},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"pinout-hole-inner",fill:fN,x:(i-c/2).toString(),y:(r-a/2).toString(),width:c.toString(),height:a.toString(),rx:l.toString(),ry:l.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(n.shape==="rotated_pill_hole_with_rect_pad"){const o=n.rect_pad_width*Math.abs(t.a),s=n.rect_pad_height*Math.abs(t.a),a=n.hole_height*Math.abs(t.a),c=n.hole_width*Math.abs(t.a),l=Math.min(a,c)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"pinout-hole-outer-pad",fill:pN,x:(-o/2).toString(),y:(-s/2).toString(),width:o.toString(),height:s.toString(),transform:`translate(${i} ${r}) rotate(${-n.rect_ccw_rotation})`},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"pinout-hole-inner",fill:fN,x:(-c/2).toString(),y:(-a/2).toString(),width:c.toString(),height:a.toString(),rx:l.toString(),ry:l.toString(),transform:`translate(${i} ${r}) rotate(${-n.hole_ccw_rotation})`},value:"",children:[]}],value:"",attributes:{}}]}return[]}var mN="rgb(218, 165, 32)";function R1n(n,e){const{transform:t}=e;if(n.shape==="rect"||n.shape==="rotated_rect"){const i=n.width*Math.abs(t.a),r=n.height*Math.abs(t.d),[o,s]=Yt(t,[n.x,n.y]);return n.shape==="rotated_rect"&&n.ccw_rotation?[{name:"rect",type:"element",attributes:{class:"pinout-pad",fill:mN,x:(-i/2).toString(),y:(-r/2).toString(),width:i.toString(),height:r.toString(),transform:`translate(${o} ${s}) rotate(${-n.ccw_rotation})`,"data-layer":n.layer},value:"",children:[]}]:[{name:"rect",type:"element",attributes:{class:"pinout-pad",fill:mN,x:(o-i/2).toString(),y:(s-r/2).toString(),width:i.toString(),height:r.toString(),"data-layer":n.layer},value:"",children:[]}]}if(n.shape==="pill"){const i=n.width*Math.abs(t.a),r=n.height*Math.abs(t.d),o=n.radius*Math.abs(t.a),[s,a]=Yt(t,[n.x,n.y]);return[{name:"rect",type:"element",attributes:{class:"pinout-pad",fill:mN,x:(s-i/2).toString(),y:(a-r/2).toString(),width:i.toString(),height:r.toString(),rx:o.toString(),ry:o.toString(),"data-layer":n.layer},value:"",children:[]}]}if(n.shape==="circle"){const i=n.radius*Math.abs(t.a),[r,o]=Yt(t,[n.x,n.y]);return[{name:"circle",type:"element",attributes:{class:"pinout-pad",fill:mN,cx:r.toString(),cy:o.toString(),r:i.toString(),"data-layer":n.layer},value:"",children:[]}]}if(n.shape==="polygon"){const i=(n.points??[]).map(r=>Yt(t,[r.x,r.y]));return[{name:"polygon",type:"element",attributes:{class:"pinout-pad",fill:mN,points:i.map(r=>r.join(",")).join(" "),"data-layer":n.layer},value:"",children:[]}]}return[]}var P1n="rgb(255, 255, 255)",I1n="rgb(0, 0, 0)",N1n="rgba(0, 0, 0, 0.6)";function k1n(n,e){const t=e.label_positions.get(n.pcb_port_id);if(!t)return[];const{text:i,aliases:r,elbow_end:o,label_pos:s,edge:a}=t,[c,l]=Yt(e.transform,[n.x,n.y]),u=a==="left"?"x-":a==="right"?"x+":a==="top"?"y-":"y+",d=a==="left"?"x+":a==="right"?"x-":a==="top"?"y+":"y-",f=[...zF({x:c,y:l,facingDirection:u},{x:o.x,y:o.y,facingDirection:d},{}),s].map(P=>`${P.x},${P.y}`).join(" "),m=[i,...r].join(" | "),y=11,g=m.length*y*.6,b=5,v=y+2*b,w=g+2*b,T=s.y;let N,R;return a==="left"?(N=s.x-w,R=s.x-w/2):a==="right"?(N=s.x,R=s.x+w/2):(N=s.x-w/2,R=s.x),[{name:"polyline",type:"element",attributes:{points:f,stroke:N1n,"stroke-width":"1.5",fill:"none"},children:[],value:""},{name:"rect",type:"element",attributes:{x:N.toString(),y:(T-v/2).toString(),width:w.toString(),height:v.toString(),fill:I1n,rx:"8",ry:"8",stroke:"none"},children:[],value:""},{name:"text",type:"element",attributes:{x:R.toString(),y:T.toString(),fill:P1n,"font-size":`${y}px`,"font-family":"Arial, sans-serif","font-weight":"bold","text-anchor":"middle","dominant-baseline":"middle"},children:[{type:"text",value:m,name:"",attributes:{},children:[]}],value:""}]}function jKe(n,e){const t=ta(e).source_port.get(n.source_port_id);if(!t)return null;const i=t.port_hints?.filter(s=>!/^\d+$/.test(s)&&!["left","right","top","bottom"].includes(s))??[];let r=i[0];if(r||(r=t.name),!r)return null;const o=i.filter(s=>s!==r);return{text:r,aliases:o}}function O1n(n,e){const t={left:n.x-e.minX,right:e.maxX-n.x,top:e.maxY-n.y,bottom:n.y-e.minY};let i="left",r=t.left;return t.right<r&&(r=t.right,i="right"),t.top<r&&(r=t.top,i="top"),t.bottom<r&&(r=t.bottom,i="bottom"),i}var HKe=20,VKe=2,_H=15,GKe=10,YKe=11,qKe=5,k_e=YKe+2*qKe,yH=5;function XKe(n,e,{transform:t,soup:i,board_bounds:r,svgHeight:o},s){const a=e.map(g=>({port:g,y:Yt(t,[g.x,g.y])[1],label_info:jKe(g,i)})).filter(g=>g.label_info).sort((g,b)=>g.y-b.y);if(a.length===0)return;const c=Yt(t,[n==="left"?r.minX:r.maxX,0])[0],l=a.length,u=(l-1)/2,d=HKe+l*VKe,f=d+u*_H+GKe,m=l*k_e+Math.max(0,l-1)*yH;let y=(o-m)/2+k_e/2;a.forEach(({port:g,label_info:b},v)=>{const w=Math.abs(v-u),T=u-w,N=d+T*_H,R=n==="left"?-1:1,P={x:c+R*N,y},M={x:c+R*f,y};s.set(g.pcb_port_id,{text:b.text,aliases:b.aliases,elbow_end:P,label_pos:M,edge:n}),y+=k_e+yH})}function WKe(n,e,{transform:t,soup:i,board_bounds:r,svgWidth:o},s){const a=e.map(b=>({port:b,x:Yt(t,[b.x,b.y])[0],label_info:jKe(b,i)})).filter(b=>b.label_info).sort((b,v)=>b.x-v.x);if(a.length===0)return;const c=Yt(t,[0,n==="top"?r.maxY:r.minY])[1],l=a.map(b=>{const T=[b.label_info.text,...b.label_info.aliases].join(" | ").length*YKe*.6+2*qKe;return{...b,rectWidth:T}}),u=l.length,d=(u-1)/2,h=HKe+u*VKe,m=h+d*_H+GKe,y=l.reduce((b,v)=>b+v.rectWidth,0)+Math.max(0,u-1)*yH;let g=(o-y)/2;l.forEach(({port:b,label_info:v,rectWidth:w},T)=>{const N=Math.abs(T-d),R=d-N,P=h+R*_H,M=n==="top"?-1:1,I=g+w/2,A={x:I,y:c+M*P},U={x:I,y:c+M*m};s.set(b.pcb_port_id,{text:v.text,aliases:v.aliases,elbow_end:A,label_pos:U,edge:n}),g+=w+yH})}var L1n=({ports_by_edge:n,transform:e,soup:t,board_bounds:i,svgWidth:r,svgHeight:o})=>{const s=new Map,a={transform:e,soup:t,board_bounds:i};return XKe("left",n.left,{...a,svgHeight:o},s),XKe("right",n.right,{...a,svgHeight:o},s),WKe("top",n.top,{...a,svgWidth:r},s),WKe("bottom",n.bottom,{...a,svgWidth:r},s),s},ZKe=["pcb_board","pcb_smtpad","pcb_hole","pcb_plated_hole","pcb_component","pcb_port"];function KKe(n,e){let t=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY;for(const A of n)if(A.type==="pcb_board")if("outline"in A&&A.outline&&Array.isArray(A.outline)&&A.outline.length>0)for(const U of A.outline)t=Math.min(t,U.x),i=Math.min(i,U.y),r=Math.max(r,U.x),o=Math.max(o,U.y);else{const U=A.center,k=A.width||0,V=A.height||0;t=Math.min(t,U.x-k/2),i=Math.min(i,U.y-V/2),r=Math.max(r,U.x+k/2),o=Math.max(o,U.y+V/2)}const s=20,a=r-t+2*s,c=o-i+2*s,l=e?.width??800,u=e?.height??600,d=l/a,h=u/c,f=Math.min(d,h),m=(l-a*f)/2,y=(u-c*f)/2,g=ls(Rs(m-t*f+s*f,u-y+i*f-s*f),kg(f,-f)),b={minX:t,minY:i,maxX:r,maxY:o},v=n.filter(A=>A.type==="pcb_port"&&A.is_board_pinout),w={left:[],right:[],top:[],bottom:[]};for(const A of v){const U=O1n({x:A.x,y:A.y},b);w[U].push(A)}const T=L1n({ports_by_edge:w,transform:g,soup:n,board_bounds:b,svgWidth:l,svgHeight:u}),N={transform:g,soup:n,label_positions:T},R=n.sort((A,U)=>(ZKe.indexOf(A.type)??9999)-(ZKe.indexOf(U.type)??9999)).flatMap(A=>D1n(A,N)),P=mC(n),M=_C,I={name:"svg",type:"element",attributes:{xmlns:"http://www.w3.org/2000/svg",width:l.toString(),height:u.toString(),...P&&{"data-software-used-string":P},...e?.includeVersion&&{"data-circuit-to-svg-version":M}},value:"",children:[{name:"rect",type:"element",attributes:{fill:"rgb(255, 255, 255)",x:"0",y:"0",width:l.toString(),height:u.toString()},value:"",children:[]},...R].filter(A=>A!==null)};return Y7(I)}function D1n(n,e,t){switch(n.type){case"pcb_board":return S1n(n,e);case"pcb_component":return M1n(n,e);case"pcb_smtpad":return R1n(n,e);case"pcb_hole":return A1n(n,e);case"pcb_plated_hole":return C1n(n,e);case"pcb_port":return n.is_board_pinout?k1n(n,e):[];default:return[]}}var Vw={"3d_viewer":{background_bottom:"rgb(102, 102, 128)",background_top:"rgb(204, 204, 230)",board:"rgb(51, 43, 23)",copper:"rgb(179, 156, 0)",silkscreen_bottom:"rgb(230, 230, 230)",silkscreen_top:"rgb(230, 230, 230)",soldermask:"rgb(20, 51, 36)",solderpaste:"rgb(128, 128, 128)"},board:{anchor:"rgb(255, 38, 226)",aux_items:"rgb(255, 255, 255)",b_adhes:"rgb(0, 0, 132)",b_crtyd:"rgb(255, 38, 226)",b_fab:"rgb(88, 93, 132)",b_mask:"rgba(2, 255, 238, 0.400)",b_paste:"rgb(0, 194, 194)",b_silks:"rgb(232, 178, 167)",background:"rgb(0, 16, 35)",cmts_user:"rgb(89, 148, 220)",copper:{b:"rgb(77, 127, 196)",f:"rgb(200, 52, 52)",in1:"rgb(127, 200, 127)",in10:"rgb(237, 124, 51)",in11:"rgb(91, 195, 235)",in12:"rgb(247, 111, 142)",in13:"rgb(167, 165, 198)",in14:"rgb(40, 204, 217)",in15:"rgb(232, 178, 167)",in16:"rgb(242, 237, 161)",in17:"rgb(237, 124, 51)",in18:"rgb(91, 195, 235)",in19:"rgb(247, 111, 142)",in2:"rgb(206, 125, 44)",in20:"rgb(167, 165, 198)",in21:"rgb(40, 204, 217)",in22:"rgb(232, 178, 167)",in23:"rgb(242, 237, 161)",in24:"rgb(237, 124, 51)",in25:"rgb(91, 195, 235)",in26:"rgb(247, 111, 142)",in27:"rgb(167, 165, 198)",in28:"rgb(40, 204, 217)",in29:"rgb(232, 178, 167)",in3:"rgb(79, 203, 203)",in30:"rgb(242, 237, 161)",in4:"rgb(219, 98, 139)",in5:"rgb(167, 165, 198)",in6:"rgb(40, 204, 217)",in7:"rgb(232, 178, 167)",in8:"rgb(242, 237, 161)",in9:"rgb(141, 203, 129)"},cursor:"rgb(255, 255, 255)",drc:"rgb(194, 194, 194)",drc_error:"rgba(215, 91, 107, 0.800)",drc_exclusion:"rgb(255, 255, 255)",drc_warning:"rgba(255, 208, 66, 0.902)",dwgs_user:"rgb(194, 194, 194)",eco1_user:"rgb(180, 219, 210)",eco2_user:"rgb(216, 200, 82)",edge_cuts:"rgb(208, 210, 205)",f_adhes:"rgb(132, 0, 132)",f_crtyd:"rgb(255, 0, 245)",f_fab:"rgb(175, 175, 175)",f_mask:"rgba(216, 100, 255, 0.400)",f_paste:"rgba(180, 160, 154, 0.902)",f_silks:"rgb(242, 237, 161)",footprint_text_back:"rgb(0, 0, 132)",footprint_text_front:"rgb(194, 194, 194)",footprint_text_invisible:"rgb(132, 132, 132)",grid:"rgb(132, 132, 132)",grid_axes:"rgb(194, 194, 194)",margin:"rgb(255, 38, 226)",microvia:"rgb(0, 132, 132)",no_connect:"rgb(0, 0, 132)",pad_back:"rgb(77, 127, 196)",pad_front:"rgb(200, 52, 52)",pad_plated_hole:"rgb(194, 194, 0)",pad_through_hole:"rgb(227, 183, 46)",plated_hole:"rgb(26, 196, 210)",ratsnest:"rgba(245, 255, 213, 0.702)",select_overlay:"rgb(4, 255, 67)",through_via:"rgb(236, 236, 236)",user_1:"rgb(194, 194, 194)",user_2:"rgb(89, 148, 220)",user_3:"rgb(180, 219, 210)",user_4:"rgb(216, 200, 82)",user_5:"rgb(194, 194, 194)",user_6:"rgb(89, 148, 220)",user_7:"rgb(180, 219, 210)",user_8:"rgb(216, 200, 82)",user_9:"rgb(232, 178, 167)",via_blind_buried:"rgb(187, 151, 38)",via_hole:"rgb(227, 183, 46)",via_micro:"rgb(0, 132, 132)",via_through:"rgb(236, 236, 236)",worksheet:"rgb(200, 114, 171)"},gerbview:{axes:"rgb(0, 0, 132)",background:"rgb(0, 0, 0)",dcodes:"rgb(255, 255, 255)",grid:"rgb(132, 132, 132)",layers:["rgb(132, 0, 0)","rgb(194, 194, 0)","rgb(194, 0, 194)","rgb(194, 0, 0)","rgb(0, 132, 132)","rgb(0, 132, 0)","rgb(0, 0, 132)","rgb(132, 132, 132)","rgb(132, 0, 132)","rgb(194, 194, 194)","rgb(132, 0, 132)","rgb(132, 0, 0)","rgb(132, 132, 0)","rgb(194, 194, 194)","rgb(0, 0, 132)","rgb(0, 132, 0)","rgb(132, 0, 0)","rgb(194, 194, 0)","rgb(194, 0, 194)","rgb(194, 0, 0)","rgb(0, 132, 132)","rgb(0, 132, 0)","rgb(0, 0, 132)","rgb(132, 132, 132)","rgb(132, 0, 132)","rgb(194, 194, 194)","rgb(132, 0, 132)","rgb(132, 0, 0)","rgb(132, 132, 0)","rgb(194, 194, 194)","rgb(0, 0, 132)","rgb(0, 132, 0)","rgb(132, 0, 0)","rgb(194, 194, 0)","rgb(194, 0, 194)","rgb(194, 0, 0)","rgb(0, 132, 132)","rgb(0, 132, 0)","rgb(0, 0, 132)","rgb(132, 132, 132)","rgb(132, 0, 132)","rgb(194, 194, 194)","rgb(132, 0, 132)","rgb(132, 0, 0)","rgb(132, 132, 0)","rgb(194, 194, 194)","rgb(0, 0, 132)","rgb(0, 132, 0)","rgb(132, 0, 0)","rgb(194, 194, 0)","rgb(194, 0, 194)","rgb(194, 0, 0)","rgb(0, 132, 132)","rgb(0, 132, 0)","rgb(0, 0, 132)","rgb(132, 132, 132)","rgb(132, 0, 132)","rgb(194, 194, 194)","rgb(132, 0, 132)","rgb(132, 0, 0)"],negative_objects:"rgb(132, 132, 132)",worksheet:"rgb(0, 0, 132)"},meta:{filename:"kicad_2020",name:"KiCad 2020",version:2},palette:["rgb(132, 0, 0)","rgb(194, 194, 0)","rgb(194, 0, 194)","rgb(194, 0, 0)","rgb(0, 132, 132)","rgb(0, 132, 0)","rgb(0, 0, 132)","rgb(132, 132, 132)","rgb(132, 0, 132)","rgb(194, 194, 194)","rgb(132, 0, 132)","rgb(132, 0, 0)","rgb(132, 132, 0)","rgb(194, 194, 194)","rgb(0, 0, 132)","rgb(0, 132, 0)"],schematic:{aux_items:"rgb(46, 46, 46)",background:"rgb(245, 241, 237)",brightened:"rgb(255, 0, 255)",bus:"rgb(0, 0, 132)",bus_junction:"rgb(0, 0, 132)",component_body:"rgb(255, 255, 194)",component_outline:"rgb(132, 0, 0)",cursor:"rgb(15, 15, 15)",erc_error:"rgba(230, 9, 13, 0.800)",erc_warning:"rgba(209, 146, 0, 0.800)",fields:"rgb(132, 0, 132)",grid:"rgb(181, 181, 181)",grid_axes:"rgb(0, 0, 132)",hidden:"rgb(194, 194, 194)",junction:"rgb(0, 150, 0)",label_global:"rgb(132, 0, 0)",label_background:"rgba(255, 255, 255, 0.6)",label_hier:"rgb(114, 86, 0)",label_local:"rgb(15, 15, 15)",net_name:"rgb(132, 132, 132)",no_connect:"rgb(0, 0, 132)",note:"rgb(0, 0, 194)",override_item_colors:!1,pin:"rgb(132, 0, 0)",pin_name:"rgb(0, 100, 100)",pin_number:"rgb(169, 0, 0)",reference:"rgb(0, 100, 100)",shadow:"rgba(102, 179, 255, 0.800)",sheet:"rgb(132, 0, 0)",sheet_background:"rgba(253, 255, 231, 0.000)",sheet_fields:"rgb(132, 0, 132)",sheet_filename:"rgb(114, 86, 0)",sheet_label:"rgb(0, 100, 100)",sheet_name:"rgb(0, 100, 100)",table:"rgb(102, 102, 102)",value:"rgb(0, 100, 100)",wire:"rgb(0, 150, 0)",wire_crossing:"rgb(30, 180, 30)",worksheet:"rgb(132, 0, 0)"}};function z1n(n){const{minX:e,minY:t,maxX:i,maxY:r}=n.bounds,o=n.cellSize??1,s=n.labelCells??!1,a=[],c=(l,u)=>{const[d,h]=Yt(n.transform,[l,u]);return{x:d,y:h}};for(let l=Math.floor(e);l<=Math.ceil(i);l+=o){const u=c(l,t),d=c(l,r);a.push({name:"line",type:"element",attributes:{x1:u.x.toString(),y1:u.y.toString(),x2:d.x.toString(),y2:d.y.toString(),stroke:Vw.schematic.grid,"stroke-width":(.01*Math.abs(n.transform.a)).toString(),"stroke-opacity":"0.5"}})}for(let l=Math.floor(t);l<=Math.ceil(r);l+=o){const u=c(e,l),d=c(i,l);a.push({name:"line",type:"element",attributes:{x1:u.x.toString(),y1:u.y.toString(),x2:d.x.toString(),y2:d.y.toString(),stroke:Vw.schematic.grid,"stroke-width":(.01*Math.abs(n.transform.a)).toString(),"stroke-opacity":"0.5"}})}if(s){const l=(u,d)=>o<=.1?`${u.toFixed(1)},${d.toFixed(1)}`:`${u},${d}`;for(let u=Math.floor(e);u<=Math.ceil(i);u+=o)for(let d=Math.floor(t);d<=Math.ceil(r);d+=o){const h=c(u,d);a.push({name:"text",type:"element",attributes:{x:(h.x-2.5).toString(),y:(h.y-5).toString(),fill:Vw.schematic.grid,"font-size":(o/5*Math.abs(n.transform.a)).toString(),"fill-opacity":"0.5","text-anchor":"middle","dominant-baseline":"middle","font-family":"sans-serif"},children:[{type:"text",value:l(u,d),name:"",attributes:{},children:[]}]})}}return{name:"g",value:"",type:"element",attributes:{class:"grid"},children:a}}function F1n(n){const{points:e,transform:t}=n,i=[];for(const r of e){const[o,s]=Yt(t,[r.x-.1,r.y-.1]),[a,c]=Yt(t,[r.x+.1,r.y+.1]),[l,u]=Yt(t,[r.x-.1,r.y+.1]),[d,h]=Yt(t,[r.x+.1,r.y-.1]);i.push({name:"path",type:"element",attributes:{d:`M${o},${s} L${a},${c} M${l},${u} L${d},${h}`,stroke:Vw.schematic.grid,"stroke-width":(.02*Math.abs(t.a)).toString(),"stroke-opacity":"0.7"}});const[f,m]=Yt(t,[r.x+.15,r.y-.15]);i.push({name:"text",type:"element",attributes:{x:f.toString(),y:m.toString(),fill:Vw.schematic.grid,"font-size":(.1*Math.abs(t.a)).toString(),"fill-opacity":"0.7","text-anchor":"start","font-family":"sans-serif","dominant-baseline":"middle"},children:[{type:"text",value:r.label||`(${r.x},${r.y})`,name:"",attributes:{},children:[]}]})}return{name:"g",value:"",type:"element",attributes:{class:"labeled-points"},children:i}}var QKe={0:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},1:{width:13,height:27,ascent:22,descent:5,left:-3,right:9},2:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},3:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},4:{width:13,height:27,ascent:22,descent:5,left:0,right:12},5:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},6:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},7:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},8:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},9:{width:13,height:27,ascent:22,descent:5,left:-1,right:12}," ":{width:7,height:27,ascent:22,descent:5,left:0,right:0},"!":{width:7,height:27,ascent:22,descent:5,left:-2,right:5},'"':{width:9,height:27,ascent:22,descent:5,left:-1,right:7},"#":{width:13,height:27,ascent:22,descent:5,left:0,right:13},$:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},"%":{width:21,height:27,ascent:22,descent:5,left:-1,right:20},"&":{width:16,height:27,ascent:22,descent:5,left:-1,right:15},"'":{width:5,height:27,ascent:22,descent:5,left:-1,right:3},"(":{width:8,height:27,ascent:22,descent:5,left:-1,right:7},")":{width:8,height:27,ascent:22,descent:5,left:-1,right:7},"*":{width:9,height:27,ascent:22,descent:5,left:-1,right:8},"+":{width:14,height:27,ascent:22,descent:5,left:-1,right:13},",":{width:7,height:27,ascent:22,descent:5,left:-2,right:5},"-":{width:8,height:27,ascent:22,descent:5,left:-1,right:7},".":{width:7,height:27,ascent:22,descent:5,left:-2,right:5},"/":{width:7,height:27,ascent:22,descent:5,left:0,right:7},":":{width:7,height:27,ascent:22,descent:5,left:-2,right:5},";":{width:7,height:27,ascent:22,descent:5,left:-2,right:5},"<":{width:14,height:27,ascent:22,descent:5,left:-1,right:13},"=":{width:14,height:27,ascent:22,descent:5,left:-1,right:13},">":{width:14,height:27,ascent:22,descent:5,left:-1,right:13},"?":{width:13,height:27,ascent:22,descent:5,left:-1,right:12},"@":{width:24,height:27,ascent:22,descent:5,left:-1,right:23},A:{width:16,height:27,ascent:22,descent:5,left:0,right:16},B:{width:16,height:27,ascent:22,descent:5,left:-2,right:15},C:{width:17,height:27,ascent:22,descent:5,left:-1,right:16},D:{width:17,height:27,ascent:22,descent:5,left:-2,right:16},E:{width:16,height:27,ascent:22,descent:5,left:-2,right:15},F:{width:15,height:27,ascent:22,descent:5,left:-2,right:14},G:{width:19,height:27,ascent:22,descent:5,left:-1,right:17},H:{width:17,height:27,ascent:22,descent:5,left:-2,right:15},I:{width:7,height:27,ascent:22,descent:5,left:-2,right:5},J:{width:12,height:27,ascent:22,descent:5,left:-1,right:10},K:{width:16,height:27,ascent:22,descent:5,left:-2,right:16},L:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},M:{width:20,height:27,ascent:22,descent:5,left:-2,right:18},N:{width:17,height:27,ascent:22,descent:5,left:-2,right:15},O:{width:19,height:27,ascent:22,descent:5,left:-1,right:18},P:{width:16,height:27,ascent:22,descent:5,left:-2,right:15},Q:{width:19,height:27,ascent:22,descent:5,left:-1,right:18},R:{width:17,height:27,ascent:22,descent:5,left:-2,right:17},S:{width:16,height:27,ascent:22,descent:5,left:-1,right:15},T:{width:15,height:27,ascent:22,descent:5,left:-1,right:14},U:{width:17,height:27,ascent:22,descent:5,left:-2,right:15},V:{width:16,height:27,ascent:22,descent:5,left:0,right:16},W:{width:23,height:27,ascent:22,descent:5,left:0,right:22},X:{width:16,height:27,ascent:22,descent:5,left:0,right:16},Y:{width:16,height:27,ascent:22,descent:5,left:0,right:16},Z:{width:15,height:27,ascent:22,descent:5,left:0,right:14},"[":{width:7,height:27,ascent:22,descent:5,left:-2,right:6},"\\":{width:7,height:27,ascent:22,descent:5,left:0,right:7},"]":{width:7,height:27,ascent:22,descent:5,left:0,right:5},"^":{width:11,height:27,ascent:22,descent:5,left:-1,right:11},_:{width:13,height:27,ascent:22,descent:5,left:0,right:14},"`":{width:8,height:27,ascent:22,descent:5,left:-1,right:5},a:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},b:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},c:{width:12,height:27,ascent:22,descent:5,left:-1,right:12},d:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},e:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},f:{width:7,height:27,ascent:22,descent:5,left:0,right:8},g:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},h:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},i:{width:5,height:27,ascent:22,descent:5,left:-2,right:4},j:{width:5,height:27,ascent:22,descent:5,left:1,right:4},k:{width:12,height:27,ascent:22,descent:5,left:-2,right:12},l:{width:5,height:27,ascent:22,descent:5,left:-2,right:4},m:{width:20,height:27,ascent:22,descent:5,left:-2,right:18},n:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},o:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},p:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},q:{width:13,height:27,ascent:22,descent:5,left:-1,right:12},r:{width:8,height:27,ascent:22,descent:5,left:-2,right:8},s:{width:12,height:27,ascent:22,descent:5,left:-1,right:11},t:{width:7,height:27,ascent:22,descent:5,left:0,right:6},u:{width:13,height:27,ascent:22,descent:5,left:-2,right:12},v:{width:12,height:27,ascent:22,descent:5,left:0,right:12},w:{width:17,height:27,ascent:22,descent:5,left:0,right:17},x:{width:12,height:27,ascent:22,descent:5,left:0,right:12},y:{width:12,height:27,ascent:22,descent:5,left:0,right:12},z:{width:12,height:27,ascent:22,descent:5,left:0,right:11},"{":{width:8,height:27,ascent:22,descent:5,left:-1,right:7},"|":{width:6,height:27,ascent:22,descent:5,left:-2,right:4},"}":{width:8,height:27,ascent:22,descent:5,left:-1,right:7},"~":{width:14,height:27,ascent:22,descent:5,left:-1,right:13}},gH=n=>{if(!n)return 0;let e=0;for(const t of n){const i=QKe[t];i?e+=i.width:e+=QKe["?"].width}return e/27},JKe=(n,e)=>{if(n.column_widths&&n.column_widths.length>0&&n.row_heights&&n.row_heights.length>0){const u=d=>typeof d=="number"?d:d.endsWith("mm")?parseFloat(d):d.endsWith("in")?parseFloat(d)*25.4:parseFloat(d);return{column_widths:n.column_widths.map(u),row_heights:n.row_heights.map(u)}}const t=e.filter(u=>u.type==="schematic_table_cell"&&u.schematic_table_id===n.schematic_table_id);if(t.length===0)return{column_widths:[],row_heights:[]};const i=t.reduce((u,d)=>Math.max(u,d.end_column_index),-1)+1,r=t.reduce((u,d)=>Math.max(u,d.end_row_index),-1)+1,{cell_padding:o=.2}=n,s=new Array(i).fill(0),a=new Array(r).fill(0),c={},l={};for(const u of t){const d=yC("reference_designator",u.font_size),f=gH(u.text??"")*d+2*o,m=d*1.2+2*o,y=`${u.start_row_index}-${u.start_column_index}`;c[y]=f,l[y]=m}for(let u=0;u<r;u++)for(let d=0;d<i;d++){const h=`${u}-${d}`;c[h]&&c[h]>s[d]&&(s[d]=c[h]),l[h]&&l[h]>a[u]&&(a[u]=l[h])}for(const u of t){if(u.start_column_index===u.end_column_index&&u.start_row_index===u.end_row_index)continue;const d=`${u.start_row_index}-${u.start_column_index}`,h=c[d],f=l[d];if(h===void 0||f===void 0)continue;let m=0;for(let g=u.start_column_index;g<=u.end_column_index;g++)m+=s[g];if(h>m){const b=(h-m)/(u.end_column_index-u.start_column_index+1);for(let v=u.start_column_index;v<=u.end_column_index;v++)s[v]+=b}let y=0;for(let g=u.start_row_index;g<=u.end_row_index;g++)y+=a[g];if(f>y){const b=(f-y)/(u.end_row_index-u.start_row_index+1);for(let v=u.start_row_index;v<=u.end_row_index;v++)a[v]+=b}}return{column_widths:s,row_heights:a}},gC=n=>{switch(n){case"top":return{x:0,y:-1};case"bottom":return{x:0,y:1};case"left":return{x:1,y:0};case"right":return{x:-1,y:0}}throw new Error(`Invalid side: ${n}`)},sE=.3,bC=.3,xC=.06,$1n={top_left:"start",top_right:"end",middle_left:"start",middle_right:"end",bottom_left:"start",bottom_right:"end",center:"middle",middle_top:"middle",middle_bottom:"middle"},B1n={top_left:"hanging",top_right:"hanging",bottom_left:"ideographic",bottom_right:"ideographic",center:"middle",middle_left:"middle",middle_right:"middle",middle_top:"hanging",middle_bottom:"ideographic"};function U1n(n){return{left:180,top:90,bottom:-90,right:0}[n]??0}function j1n(n,e,t){const i=t+sE*2+xC*n.text.length+bC,r=gC(n.anchor_side);return n.anchor_position??{x:n.center.x-r.x*i*e/2,y:n.center.y-r.y*i*e/2}}function H1n(n,e=.5){let t=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY;const s=.2;for(const c of n)if(c.type==="schematic_component")a(c.center,c.size,0);else if(c.type==="schematic_port")a(c.center,{width:s,height:s},0);else if(c.type==="schematic_debug_object")c.shape==="rect"?a(c.center,c.size,0):c.shape==="line"&&(a(c.start,{width:.1,height:.1},0),a(c.end,{width:.1,height:.1},0));else if(c.type==="schematic_net_label"){const l=yC("net_label"),u=gH(c.text||""),h=(u+sE*2+xC*(c.text?.length||0)+bC)*l,f=1.2*l,m=U1n(c.anchor_side)/180*Math.PI,y=j1n(c,l,u),g=gC(c.anchor_side),b={x:y.x+g.x*h/2,y:y.y+g.y*h/2};a(b,{width:h,height:f},m)}else if(c.type==="schematic_trace")for(const l of c.edges)a(l.from,{width:.1,height:.1},0),a(l.to,{width:.1,height:.1},0);else if(c.type==="schematic_text"){const u=yC("reference_designator",c.font_size)??.18,h=(c.text??"").length*u,f=u;a(c.position,{width:h,height:f},c.rotation??0)}else if(c.type==="schematic_voltage_probe")a(c.position,{width:.2,height:.4},0);else if(c.type==="schematic_box")a({x:c.x+c.width/2,y:c.y+c.height/2},{width:c.width,height:c.height},0);else if(c.type==="schematic_table"){const{column_widths:l,row_heights:u}=JKe(c,n),d=l.reduce((v,w)=>v+w,0),h=u.reduce((v,w)=>v+w,0),f=c.anchor??"center";let m=c.anchor_position.x,y=c.anchor_position.y;f.includes("center")?m-=d/2:f.includes("right")&&(m-=d),f.includes("center")?y+=h/2:f.includes("bottom")&&(y+=h);const g=m+d/2,b=y-h/2;a({x:g,y:b},{width:d,height:h},0)}else c.type==="schematic_line"?(a({x:c.x1,y:c.y1},{width:.02,height:.02},0),a({x:c.x2,y:c.y2},{width:.02,height:.02},0)):c.type==="schematic_circle"?a(c.center,{width:c.radius*2,height:c.radius*2},0):c.type==="schematic_rect"?a(c.center,{width:c.width,height:c.height},c.rotation):c.type==="schematic_arc"&&a(c.center,{width:c.radius*2,height:c.radius*2},0);return t-=e,i-=e,r+=e,o+=e,{minX:t,minY:i,maxX:r,maxY:o};function a(c,l,u){const d=[{x:-l.width/2,y:-l.height/2},{x:l.width/2,y:-l.height/2},{x:l.width/2,y:l.height/2},{x:-l.width/2,y:l.height/2}];for(const h of d){const f=h.x*Math.cos(u)-h.y*Math.sin(u)+c.x,m=h.x*Math.sin(u)+h.y*Math.cos(u)+c.y;t=Math.min(t,f),i=Math.min(i,m),r=Math.max(r,f),o=Math.max(o,m)}}}var hb=n=>Math.abs(n.a)*.02,V1n=(n,e)=>{const t=n<0?n+2*Math.PI:n,i=e<0?e+2*Math.PI:e;let r=Math.abs(t-i);return r>Math.PI&&(r=2*Math.PI-r),r},G1n=({schPorts:n,symbol:e,schComponent:t})=>{const i=n.map(a=>{const c=a.center.x-t.center.x,l=a.center.y-t.center.y;return{port:a,angle:Math.atan2(l,c)}}),r=e.ports.map(a=>{const c=a.x-e.center.x,l=a.y-e.center.y;return{port:a,angle:Math.atan2(l,c)}});i.sort((a,c)=>a.angle-c.angle),r.sort((a,c)=>a.angle-c.angle);const o=[],s=new Set;for(const a of i){let c=null;for(const l of r){if(s.has(l.port))continue;const u=V1n(a.angle,l.angle);(c===null||u<c.angleDiff)&&(c={symbolPort:l.port,angleDiff:u})}c&&c.angleDiff<Math.PI/4&&(o.push({schPort:a.port,symbolPort:c.symbolPort}),s.add(c.symbolPort))}return o};function Y1n(n,e,t,i){const r=e.x-n.x,o=e.y-n.y,s=Math.sqrt((t.x-n.x)**2+(t.y-n.y)**2),c=Math.sqrt((i.x-e.x)**2+(i.y-e.y)**2)/s,l=Rs(r,o),u=kg(c,c);return ls(l,u)}var O_e=({text:n,realCenter:e,realToScreenTransform:t})=>{const i=Yt(t,e);return{type:"element",name:"text",value:"",attributes:{x:i.x.toString(),y:i.y.toString(),fill:"red","text-anchor":"middle","dominant-baseline":"middle","font-family":"sans-serif","font-size":`${m3(t,"error")}px`},children:[{type:"text",value:n,name:"",attributes:{},children:[]}]}},eQe=(n,e)=>{for(const t of n){if(t.type!=="source_trace")continue;const i=t;if(Array.isArray(i.connected_source_port_ids)&&i.connected_source_port_ids.includes(e))return!0}return!1},q1n={top_left:"start",top_right:"end",middle_left:"start",middle_right:"end",bottom_left:"start",bottom_right:"end",center:"middle",middle_top:"middle",middle_bottom:"middle"},X1n=({component:n,transform:e,circuitJson:t,colorMap:i})=>{const r=[],o=av[n.symbol_name];if(!o)return[O_e({text:`Symbol not found: ${n.symbol_name}`,realCenter:n.center,realToScreenTransform:e})];const s=ta(t).schematic_port.list({schematic_component_id:n.schematic_component_id}),a=ta(t).source_component.get(n.source_component_id),c=G1n({schPorts:s,symbol:o,schComponent:n});if(!c[0])return[O_e({text:`Could not match ports for symbol ${n.symbol_name}`,realCenter:n.center,realToScreenTransform:e})];const l=Y1n(c[1]?.symbolPort??o.center,c[1]?.schPort.center??n.center,c[0].symbolPort,c[0].schPort.center),u=o.primitives.filter(M=>M.type==="path"),d=o.primitives.filter(M=>M.type==="text"),h=o.primitives.filter(M=>M.type==="circle"),f=o.primitives.filter(M=>M.type==="box"),m=new Set;for(const M of c)eQe(t,M.schPort.source_port_id)&&m.add(M.symbolPort);const y={minX:Math.min(...u.flatMap(M=>M.points.map(I=>I.x))),maxX:Math.max(...u.flatMap(M=>M.points.map(I=>I.x))),minY:Math.min(...u.flatMap(M=>M.points.map(I=>I.y))),maxY:Math.max(...u.flatMap(M=>M.points.map(I=>I.y)))},[g,b]=Yt(ls(e,l),[y.minX,y.minY]),[v,w]=Yt(ls(e,l),[y.maxX,y.maxY]),T=Math.abs(w-b),N=Math.min(b,w),R=Math.abs(v-g),P=Math.min(g,v);r.push({name:"rect",type:"element",value:"",attributes:{class:"component-overlay",x:P.toString(),y:N.toString(),width:R.toString(),height:T.toString(),fill:"transparent"},children:[]});for(const M of u){const{points:I,color:A,closed:U,fill:k}=M;r.push({type:"element",name:"path",attributes:{d:I.map((V,Y)=>{const[W,K]=Yt(ls(e,l),[V.x,V.y]);return`${Y===0?"M":"L"} ${W} ${K}`}).join(" ")+(U?" Z":""),stroke:i.schematic.component_outline,fill:"none","stroke-width":`${hb(e)}px`,"stroke-linecap":"round"},value:"",children:[]})}for(const M of d){const I=Yt(ls(e,l),M);let A="";M.text==="{REF}"?A=a?.name??"":M.text==="{VAL}"&&(A=n.symbol_display_value??"");const V=Math.abs(y.maxY-y.minY)*.1,Y=Math.abs(l.a);let W=0;M.anchor.includes("bottom")?W=V*Y:M.anchor.includes("top")&&(W=-V*Y);const K=M.anchor.includes("bottom")?"auto":M.anchor.includes("top")?"hanging":"middle",ee=M.text==="{REF}";r.push({name:"text",type:"element",attributes:{x:I.x.toString(),y:(I.y+W).toString(),...ee?{stroke:i.schematic.background,"stroke-width":`${hb(e)}px`,"paint-order":"stroke"}:{},fill:i.schematic.label_local,"font-family":"sans-serif","text-anchor":q1n[M.anchor],"dominant-baseline":K,"font-size":`${m3(e,"reference_designator")}px`},value:"",children:[{type:"text",value:A,name:"",attributes:{},children:[]}]})}for(const M of f){const I=Yt(ls(e,l),M),A=ls(e,l).a;r.push({name:"rect",type:"element",attributes:{x:I.x.toString(),y:I.y.toString(),width:(M.width*A).toString(),height:(M.height*A).toString(),fill:"red"},value:"",children:[]})}for(const M of o.ports){if(m.has(M))continue;const I=Yt(ls(e,l),M);r.push({type:"element",name:"circle",attributes:{cx:I.x.toString(),cy:I.y.toString(),r:`${Math.abs(e.a)*.02}px`,"stroke-width":`${hb(e)}px`,fill:"none",stroke:i.schematic.component_outline},value:"",children:[]})}for(const M of h){const I=Yt(ls(e,l),M),A=Math.abs(M.radius*e.a);r.push({type:"element",name:"circle",attributes:{cx:I.x.toString(),cy:I.y.toString(),r:`${A}px`,"stroke-width":`${hb(e)}px`,fill:"none",stroke:i.schematic.component_outline},value:"",children:[]})}return r},_N=.02,tQe=(n,e,t,i,r)=>{const o=Math.PI/6,s={x:n.x-t*Math.cos(e-o),y:n.y-t*Math.sin(e-o)},a={x:n.x-t*Math.cos(e+o),y:n.y-t*Math.sin(e+o)};return{name:"polygon",type:"element",attributes:{points:`${n.x},${n.y} ${s.x},${s.y} ${a.x},${a.y}`,fill:"white",stroke:i,"stroke-width":`${r}px`},value:"",children:[]}},W1n=({schPort:n,schComponent:e,transform:t,circuitJson:i})=>{const r=[];ta(i).source_port.get(n.source_port_id);const o={x:n.center.x,y:n.center.y},s=n.distance_from_component_edge??.4;switch(n.side_of_component){case"left":o.x+=s;break;case"right":o.x-=s;break;case"top":o.y-=s;break;case"bottom":o.y+=s;break}const a=Yt(t,n.center),c=Yt(t,o),l=eQe(i,n.source_port_id),u={...n.center};if(!l)switch(n.side_of_component){case"left":u.x+=_N;break;case"right":u.x-=_N;break;case"top":u.y-=_N;break;case"bottom":u.y+=_N;break}const d=Yt(t,u);r.push({name:"line",type:"element",attributes:{class:"component-pin",x1:c.x.toString(),y1:c.y.toString(),x2:d.x.toString(),y2:d.y.toString(),"stroke-width":`${hb(t)}px`},value:"",children:[]});const h=Math.abs(t.a)*_N,f=[];l||f.push({name:"circle",type:"element",attributes:{class:"component-pin",cx:a.x.toString(),cy:a.y.toString(),r:h.toString(),"stroke-width":`${hb(t)}px`},value:"",children:[]}),f.push({name:"rect",type:"element",attributes:{x:(a.x-h).toString(),y:(a.y-h).toString(),width:(h*2).toString(),height:(h*2).toString(),opacity:"0"},value:"",children:[]}),r.push({name:"g",type:"element",value:"",attributes:{"data-schematic-port-id":n.source_port_id},children:f});const{has_input_arrow:m,has_output_arrow:y}=n;if((m||y)&&n.side_of_component){const g=Math.abs(t.a)*.1,b=Vw.schematic.component_outline,v=g*Math.cos(Math.PI/6),w=hb(t)/3;let T=0,N=0;n.side_of_component==="left"?(T=0,N=Math.PI):n.side_of_component==="right"?(T=Math.PI,N=0):n.side_of_component==="top"?(T=Math.PI/2,N=-Math.PI/2):n.side_of_component==="bottom"&&(T=-Math.PI/2,N=Math.PI/2);const R=m&&y;let P={...c},M={...c};if(R){const I=v;n.side_of_component==="left"?M.x-=I:n.side_of_component==="right"?M.x+=I:n.side_of_component==="top"?M.y-=I:n.side_of_component==="bottom"&&(M.y+=I)}if(m&&r.push(tQe(P,T,g,b,w)),y){const I={x:M.x+g*Math.cos(N),y:M.y+g*Math.sin(N)};r.push(tQe(I,N,g,b,w))}}return r},Z1n=n=>{const e=[],{schPort:t,transform:i}=n,r={x:t.center.x,y:t.center.y};if(!t.side_of_component)return[];const o=gC(t.side_of_component),s=t.distance_from_component_edge??.4;r.x+=o.x*s/2,r.y+=o.y*s/2,t.side_of_component==="top"||t.side_of_component==="bottom"?r.x-=.02:r.y+=.02;const a=Yt(i,r);return e.push({name:"text",type:"element",attributes:{class:"pin-number",x:a.x.toString(),y:a.y.toString(),style:"font-family: sans-serif;",fill:Vw.schematic.pin_number,"text-anchor":"middle","dominant-baseline":"auto","font-size":`${m3(i,"pin_number")}px`,transform:t.side_of_component==="top"||t.side_of_component==="bottom"?`rotate(-90 ${a.x} ${a.y})`:""},children:[{type:"text",value:t.pin_number?.toString()||"",name:"",attributes:{},children:[]}],value:""}),e},nQe=.1,K1n=n=>{const e=[],{schPort:t,schComponent:i,transform:r}=n,o={x:t.center.x,y:t.center.y};if(!t.side_of_component)return[];const s=gC(t.side_of_component),a=t.distance_from_component_edge??.4;o.x+=s.x*(a+nQe),o.y+=s.y*(a+nQe);const c=Yt(r,o),l=t.display_pin_label??i.port_labels?.[`${t.pin_number}`];if(!l)return[];const u=l.startsWith("N_"),d=u?l.slice(2):l;let h=m3(r,u?"negated_pin_number":"pin_number");return e.push({name:"text",type:"element",attributes:{class:"pin-number",x:c.x.toString(),y:c.y.toString(),style:`font-family: sans-serif;${u?" text-decoration: overline;":""}`,fill:Vw.schematic.pin_number,"text-anchor":t.side_of_component==="left"||t.side_of_component==="bottom"?"start":"end","dominant-baseline":"middle","font-size":`${h}px`,transform:t.side_of_component==="top"||t.side_of_component==="bottom"?`rotate(-90 ${c.x} ${c.y})`:""},children:[{type:"text",value:d||"",name:"",attributes:{},children:[]}],value:""}),e},Q1n=n=>{const e=[];return e.push(...W1n(n)),e.push(...Z1n(n)),e.push(...K1n(n)),e},iQe=({elm:n,transform:e,colorMap:t})=>{const i=Yt(e,n.position),r={center:"middle",center_right:"end",bottom_left:"start",bottom_center:"middle",bottom_right:"end",left:"start",right:"end",top:"middle",bottom:"middle",top_left:"start",top_center:"middle",top_right:"end",center_left:"start"},o={center:"middle",center_right:"middle",bottom_left:"ideographic",bottom_center:"ideographic",bottom_right:"ideographic",left:"middle",right:"middle",top:"hanging",bottom:"ideographic",top_left:"hanging",top_center:"hanging",top_right:"hanging",center_left:"middle"},s=n.text.split(`
5390
5390
  `),a=s.length===1?[{type:"text",value:n.text,name:n.schematic_text_id,attributes:{},children:[]}]:s.map((c,l)=>({type:"element",name:"tspan",value:"",attributes:{x:i.x.toString(),...l>0?{dy:"1em"}:{}},children:[{type:"text",value:c,name:l===0?n.schematic_text_id:"",attributes:{},children:[]}]}));return{type:"element",name:"text",value:"",attributes:{x:i.x.toString(),y:i.y.toString(),fill:n.color??t.schematic.sheet_label,"text-anchor":r[n.anchor],"dominant-baseline":o[n.anchor],"font-family":"sans-serif","font-size":`${m3(e,"reference_designator",n.font_size)}px`,transform:`rotate(${n.rotation}, ${i.x}, ${i.y})`},children:a}},J1n=({component:n,transform:e,circuitJson:t,colorMap:i})=>{const r=[],o=Yt(e,{x:n.center.x-n.size.width/2,y:n.center.y+n.size.height/2}),s=Yt(e,{x:n.center.x+n.size.width/2,y:n.center.y-n.size.height/2}),a=s.x-o.x,c=s.y-o.y;r.push({name:"rect",type:"element",value:"",attributes:{class:"component chip",x:o.x.toString(),y:o.y.toString(),width:a.toString(),height:c.toString(),"stroke-width":`${hb(e)}px`,fill:i.schematic.component_body,stroke:i.schematic.component_outline},children:[]}),r.push({name:"rect",type:"element",value:"",attributes:{class:"component-overlay",x:o.x.toString(),y:o.y.toString(),width:a.toString(),height:c.toString(),fill:"transparent"},children:[]});const l=ta(t).schematic_text.list();for(const d of l)d.schematic_component_id===n.schematic_component_id&&r.push(iQe({elm:d,transform:e,colorMap:i}));const u=ta(t).schematic_port.list({schematic_component_id:n.schematic_component_id});for(const d of u)r.push(...Q1n({schPort:d,schComponent:n,transform:e,circuitJson:t}));return r};function ebn(n){const{component:e}=n;if(e.is_box_with_pins===!1)return[];const t=e.symbol_name?X1n(n):J1n(n);return[{type:"element",name:"g",attributes:{"data-circuit-json-type":"schematic_component","data-schematic-component-id":e.schematic_component_id},children:t,value:""}]}function tbn({probe:n,transform:e,colorMap:t}){const[i,r]=Yt(e,[n.position.x,n.position.y]),o=Math.abs(e.a)*.6,s=Math.abs(e.a)*.28,a=i+o*Math.cos(-50*Math.PI/180),c=r+o*Math.sin(-50*Math.PI/180),l=i,u=r;return[{name:"path",type:"element",attributes:{d:[`M ${a},${c}`,`L ${l},${u}`,`M ${l},${u}`,`L ${l-s*Math.cos(100*Math.PI/180)},${u-s*Math.sin(100*Math.PI/180)}`,`L ${l-s*Math.cos(160*Math.PI/180)},${u-s*Math.sin(160*Math.PI/180)}`,"Z"].join(" "),stroke:t.schematic.reference,fill:t.schematic.reference,"stroke-width":`${hb(e)}px`},value:"",children:[]},{type:"element",name:"text",value:"",attributes:{x:(a+8-(a-a)).toString(),y:(c-10+(c-c)).toString(),fill:t.schematic.reference,"text-anchor":"middle","dominant-baseline":"middle","font-family":"sans-serif","font-size":`${m3(e,"reference_designator")}px`,"font-weight":"bold","data-schematic-voltage-probe-id":n.schematic_voltage_probe_id},children:[{type:"text",value:n.voltage?`${n.voltage}V`:"",name:"",attributes:{},children:[]}]}]}function nbn({debugObject:n,transform:e}){if(n.shape==="rect"){let[t,i]=Yt(e,[n.center.x-n.size.width/2,n.center.y-n.size.height/2]),[r,o]=Yt(e,[n.center.x+n.size.width/2,n.center.y+n.size.height/2]);[i,o]=[Math.min(i,o),Math.max(i,o)];const s=Math.abs(r-t),a=Math.abs(o-i),[c,l]=Yt(e,[n.center.x,n.center.y]);return[{name:"rect",type:"element",value:"",attributes:{x:t.toString(),y:i.toString(),width:s.toString(),height:a.toString(),fill:"none",stroke:"red","stroke-width":(.02*Math.abs(e.a)).toString(),"stroke-dasharray":"5,5"},children:n.label?[{name:"text",type:"element",value:"",attributes:{x:c.toString(),y:(l-10).toString(),"text-anchor":"middle","font-size":(.2*Math.abs(e.a)).toString(),fill:"red"},children:[{type:"text",value:n.label,name:"",attributes:{},children:[]}]}]:[]}]}if(n.shape==="line"){const[t,i]=Yt(e,[n.start.x,n.start.y]),[r,o]=Yt(e,[n.end.x,n.end.y]),s=(t+r)/2,a=(i+o)/2;return[{name:"line",type:"element",value:"",attributes:{x1:t.toString(),y1:i.toString(),x2:r.toString(),y2:o.toString(),stroke:"red","stroke-width":(.02*Math.abs(e.a)).toString(),"stroke-dasharray":"5,5"},children:n.label?[{name:"text",type:"element",value:"",attributes:{x:s.toString(),y:(a-10).toString(),"text-anchor":"middle","font-size":(.2*Math.abs(e.a)).toString(),fill:"red"},children:[{type:"text",value:n.label,name:"",attributes:{},children:[]}]}]:[]}]}return[]}function ibn({trace:n,transform:e,colorMap:t}){const i=n.edges;if(i.length===0)return[];const r=[],o=[];let s="";for(let a=0;a<i.length;a++){const c=i[a];if(c.is_crossing)continue;const[l,u]=Yt(e,[c.from.x,c.from.y]),[d,h]=Yt(e,[c.to.x,c.to.y]);a===0||i[a-1]?.is_crossing?s+=`M ${l} ${u} L ${d} ${h}`:s+=` L ${d} ${h}`}s&&(r.push({name:"path",type:"element",attributes:{d:s,class:"trace-invisible-hover-outline",stroke:t.schematic.wire,fill:"none","stroke-width":`${hb(e)*8}px`,"stroke-linecap":"round",opacity:"0","stroke-linejoin":"round"},value:"",children:[]}),r.push({name:"path",type:"element",attributes:{d:s,stroke:t.schematic.wire,fill:"none","stroke-width":`${hb(e)}px`,"stroke-linecap":"round","stroke-linejoin":"round"},value:"",children:[]}));for(const a of i){if(!a.is_crossing)continue;const[c,l]=Yt(e,[a.from.x,a.from.y]),[u,d]=Yt(e,[a.to.x,a.to.y]),h=(c+u)/2,f=(l+d)/2,m=u-c,y=d-l,g=Math.sqrt(m*m+y*y),b=g*.7,v=-y/g*b,w=m/g*b,T=h+v,N=f-Math.abs(w);o.push({name:"path",type:"element",attributes:{class:"trace-crossing-outline",d:`M ${c} ${l} Q ${T} ${N} ${u} ${d}`,stroke:t.schematic.background,fill:"none","stroke-width":`${hb(e)*1.5}px`,"stroke-linecap":"butt"},value:"",children:[]}),o.push({name:"path",type:"element",attributes:{d:`M ${c} ${l} Q ${T} ${N} ${u} ${d}`,stroke:t.schematic.wire,fill:"none","stroke-width":`${hb(e)}px`,"stroke-linecap":"round"},value:"",children:[]})}if(n.junctions)for(const a of n.junctions){const[c,l]=Yt(e,[a.x,a.y]);o.push({name:"circle",type:"element",attributes:{cx:c.toString(),cy:l.toString(),r:(Math.abs(e.a)*.03).toString(),class:"trace-junction",fill:t.schematic.junction},value:"",children:[]})}return[{name:"g",type:"element",value:"",attributes:{class:"trace","data-layer":"base","data-circuit-json-type":"schematic_trace","data-schematic-trace-id":n.schematic_trace_id,...n.subcircuit_connectivity_map_key&&{"data-subcircuit-connectivity-map-key":n.subcircuit_connectivity_map_key}},children:r},{name:"g",type:"element",value:"",attributes:{class:"trace-overlays","data-layer":"overlay","data-circuit-json-type":"schematic_trace","data-schematic-trace-id":n.schematic_trace_id,...n.subcircuit_connectivity_map_key&&{"data-subcircuit-connectivity-map-key":n.subcircuit_connectivity_map_key}},children:o}]}var rbn=({schNetLabel:n,realToScreenTransform:e,colorMap:t})=>{if(!n.text)return[];const i=n.text.startsWith("N_"),r=i?n.text.slice(2):n.text,o=[],s=av[n.symbol_name];if(!s)return o.push(O_e({text:`Symbol not found: ${n.symbol_name}`,realCenter:n.center,realToScreenTransform:e})),o;const a=s.primitives.filter(W=>W.type==="path"),c=s.primitives.filter(W=>W.type==="text"),l=s.primitives.filter(W=>W.type==="circle"),u=s.primitives.filter(W=>W.type==="box"),d={minX:Math.min(...a.flatMap(W=>W.points.map(K=>K.x))),maxX:Math.max(...a.flatMap(W=>W.points.map(K=>K.x))),minY:Math.min(...a.flatMap(W=>W.points.map(K=>K.y))),maxY:Math.max(...a.flatMap(W=>W.points.map(K=>K.y)))},h=yC("net_label"),m=gH(r||"")+sE*2+xC*r.length+bC,y=gC(n.anchor_side),g=n.anchor_position??{x:n.center.x-y.x*m*h/2,y:n.center.y-y.y*m*h/2},v=sv(0/180*Math.PI),w={minX:Math.min(...s.primitives.flatMap(W=>W.type==="path"?W.points.map(K=>K.x):[])),maxX:Math.max(...s.primitives.flatMap(W=>W.type==="path"?W.points.map(K=>K.x):[])),minY:Math.min(...s.primitives.flatMap(W=>W.type==="path"?W.points.map(K=>K.y):[])),maxY:Math.max(...s.primitives.flatMap(W=>W.type==="path"?W.points.map(K=>K.y):[]))},T=s.ports?.[0]?{x:s.ports[0].x,y:s.ports[0].y}:{x:w.minX,y:(w.minY+w.maxY)/2},N=Yt(v,T),R=ls(Rs(g.x-N.x,g.y-N.y),v,kg(1)),[P,M]=Yt(ls(e,R),[d.minX,d.minY]),[I,A]=Yt(ls(e,R),[d.maxX,d.maxY]),U=Math.abs(A-M),k=Math.min(M,A),V=Math.abs(I-P),Y=Math.min(P,I);o.push({name:"rect",type:"element",value:"",attributes:{class:"component-overlay",x:Y.toString(),y:k.toString(),width:V.toString(),height:U.toString(),fill:"transparent"},children:[]});for(const W of a){const K=W.points.map((ee,ae)=>{const[ue,ge]=Yt(ls(e,R),[ee.x,ee.y]);return`${ae===0?"M":"L"} ${ue} ${ge}`}).join(" ");o.push({name:"path",type:"element",attributes:{d:K+(W.closed?" Z":""),stroke:t.schematic.component_outline,fill:"none","stroke-width":`${hb(e)}px`,"stroke-linecap":"round"},value:"",children:[]})}for(const W of c){const K=Yt(ls(e,R),W);let ee=W.text;ee==="{REF}"?ee=r||"":ee==="{VAL}"&&(ee=""),Math.abs(e.a);const ae={x:K.x,y:K.y};o.push({name:"text",type:"element",attributes:{x:ae.x.toString(),y:ae.y.toString(),fill:t.schematic.label_local,"font-family":"sans-serif","text-anchor":$1n[W.anchor],"dominant-baseline":B1n[W.anchor],"font-size":`${m3(e,"reference_designator")}px`,...i&&ee===r?{style:"text-decoration: overline;"}:{}},children:[{type:"text",value:ee,name:"",attributes:{},children:[]}],value:""})}for(const W of u){const K=Yt(ls(e,R),W),ee=ls(e,R).a;o.push({name:"rect",type:"element",attributes:{x:K.x.toString(),y:K.y.toString(),width:(W.width*ee).toString(),height:(W.height*ee).toString(),fill:"red"},value:"",children:[]})}for(const W of l){const K=Yt(ls(e,R),W),ee=ls(e,R).a;o.push({name:"circle",type:"element",attributes:{cx:K.x.toString(),cy:K.y.toString(),r:(W.radius*ee).toString(),fill:"none",stroke:t.schematic.component_outline,"stroke-width":`${hb(e)}px`},value:"",children:[]})}return o},obn=({schNetLabel:n,realToScreenTransform:e,colorMap:t})=>{if(!n.text)return[];const i=n.text;if(n.symbol_name)return rbn({schNetLabel:n,realToScreenTransform:e,colorMap:t});const r=[],o=m3(e,"net_label"),s=yC("net_label"),a=gH(i||""),c=Yt(e,n.center),l=gC(n.anchor_side),u={...l};u.y*=-1;const d=a+sE*2+xC*i.length+bC,h=n.anchor_position?Yt(e,n.anchor_position):{x:c.x-u.x*d*o/2,y:c.y-u.y*d*o/2},f=n.anchor_position??{x:n.center.x-l.x*d*s/2,y:n.center.y-l.y*d*s/2},m={left:0,top:-90,bottom:90,right:180}[n.anchor_side],y=[{x:0,y:0},{x:sE,y:.6},{x:sE*2+bC+xC*i.length+a,y:.6},{x:sE*2+bC+xC*i.length+a,y:-.6},{x:sE,y:-.6}].map(T=>Yt(ls(e,Rs(f.x,f.y),kg(s),sv(m/180*Math.PI)),T)),g=`
5391
5391
  M ${y[0].x},${y[0].y}
5392
5392
  L ${y[1].x},${y[1].y}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tscircuit/runframe",
3
3
  "main": "dist/preview.js",
4
4
  "type": "module",
5
- "version": "0.0.999",
5
+ "version": "0.0.1001",
6
6
  "exports": {
7
7
  ".": "./dist/preview.js",
8
8
  "./preview": "./dist/preview.js",
@@ -47,7 +47,7 @@
47
47
  "@tscircuit/assembly-viewer": "^0.0.5",
48
48
  "@tscircuit/checks": "^0.0.77",
49
49
  "@tscircuit/create-snippet-url": "^0.0.9",
50
- "@tscircuit/eval": "^0.0.337",
50
+ "@tscircuit/eval": "^0.0.338",
51
51
  "@tscircuit/fake-snippets": "^0.0.87",
52
52
  "@tscircuit/file-server": "^0.0.31",
53
53
  "@tscircuit/footprinter": "^0.0.236",
@@ -69,7 +69,7 @@
69
69
  "circuit-json-to-gerber": "^0.0.34",
70
70
  "circuit-json-to-gltf": "^0.0.7",
71
71
  "circuit-json-to-pnp-csv": "^0.0.7",
72
- "circuit-to-svg": "^0.0.201",
72
+ "circuit-to-svg": "^0.0.202",
73
73
  "class-variance-authority": "^0.7.1",
74
74
  "clsx": "^2.1.1",
75
75
  "comlink": "^4.4.2",