@tscircuit/eval 0.0.860 → 0.0.861
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blob-url.js +1 -1
- package/dist/webworker/entrypoint.js +3 -3
- package/package.json +2 -2
|
@@ -224,8 +224,8 @@ React keys must be passed directly to JSX without using spread:
|
|
|
224
224
|
`+filler+" | "+peg$padEnd2("",s3.column-1," ")+peg$padEnd2("",hatLen,"^")}else str+=`
|
|
225
225
|
at `+loc}return str};peg$SyntaxError2.buildMessage=function(expected,found){var DESCRIBE_EXPECTATION_FNS={literal:function(expectation){return'"'+literalEscape(expectation.text)+'"'},class:function(expectation){var escapedParts=expectation.parts.map(function(part){return Array.isArray(part)?classEscape(part[0])+"-"+classEscape(part[1]):classEscape(part)});return"["+(expectation.inverted?"^":"")+escapedParts.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(expectation){return expectation.description}};function hex(ch3){return ch3.charCodeAt(0).toString(16).toUpperCase()}function literalEscape(s3){return s3.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(ch3){return"\\x0"+hex(ch3)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(ch3){return"\\x"+hex(ch3)})}function classEscape(s3){return s3.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(ch3){return"\\x0"+hex(ch3)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(ch3){return"\\x"+hex(ch3)})}function describeExpectation(expectation){return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation)}function describeExpected(expected2){var descriptions=expected2.map(describeExpectation),i3,j4;if(descriptions.sort(),descriptions.length>0){for(i3=1,j4=1;i3<descriptions.length;i3++)descriptions[i3-1]!==descriptions[i3]&&(descriptions[j4]=descriptions[i3],j4++);descriptions.length=j4}switch(descriptions.length){case 1:return descriptions[0];case 2:return descriptions[0]+" or "+descriptions[1];default:return descriptions.slice(0,-1).join(", ")+", or "+descriptions[descriptions.length-1]}}function describeFound(found2){return found2?'"'+literalEscape(found2)+'"':"end of input"}return"Expected "+describeExpected(expected)+" but "+describeFound(found)+" found."}}});var init_fromTransformAttribute2=__esm({"node_modules/circuit-to-svg/node_modules/transformation-matrix/src/fromTransformAttribute.js"(){"use strict";init_fromTransformAttribute_autogenerated2()}});var init_decompose2=__esm({"node_modules/circuit-to-svg/node_modules/transformation-matrix/src/decompose.js"(){"use strict";init_scale2();init_transform2()}});var init_flip2=__esm({"node_modules/circuit-to-svg/node_modules/transformation-matrix/src/flip.js"(){"use strict"}});var init_fromMovingPoints2=__esm({"node_modules/circuit-to-svg/node_modules/transformation-matrix/src/fromMovingPoints.js"(){"use strict";init_translate2();init_applyToPoint2();init_rotate2();init_scale2();init_transform2()}});var init_src2=__esm({"node_modules/circuit-to-svg/node_modules/transformation-matrix/src/index.js"(){"use strict";init_applyToPoint2();init_fromObject2();init_fromString2();init_identity2();init_inverse2();init_isAffineMatrix2();init_rotate2();init_scale2();init_shear2();init_skew2();init_toString2();init_transform2();init_translate2();init_fromTriangles2();init_smoothMatrix2();init_fromDefinition2();init_fromTransformAttribute2();init_decompose2();init_flip2();init_fromMovingPoints2()}});var svgAlphabet,lineAlphabet,init_dist7=__esm({"node_modules/@tscircuit/alphabet/dist/index.js"(){"use strict";svgAlphabet={0:"M0.301025 0.257813 L0.206593 0.283385 L0.122042 0.361307 L0.075923 0.474441 L0.064942 0.642221 L0.091296 0.78289 L0.159376 0.899463 L0.257104 0.961214 L0.344948 0.961214 L0.442678 0.899463 L0.510757 0.78289 L0.537111 0.642221 L0.526131 0.474441 L0.480012 0.361307 L0.39546 0.283385 L0.301025 0.257813",1:"M0.220426 0.40845 L0.381626 0.270996 L0.381626 0.948966",2:"M0.110409 0.39212 L0.125621 0.342293 L0.170571 0.295823 L0.244237 0.26431 L0.291518 0.257813 L0.373319 0.263799 L0.434683 0.290705 L0.468239 0.331966 L0.480292 0.379913 L0.479492 0.411806 L0.465088 0.465192 L0.402571 0.568988 L0.245134 0.766438 L0.07959 0.948045 L0.522462 0.948045",3:"M0.081606 0.345073 L0.119154 0.315633 L0.178996 0.284091 L0.255265 0.257813 L0.349133 0.263062 L0.43127 0.289348 L0.48994 0.336662 L0.525141 0.394491 L0.513407 0.457577 L0.466472 0.504892 L0.384334 0.541692 L0.290464 0.56272 L0.20833 0.573235 L0.290464 0.583749 L0.384334 0.610035 L0.466472 0.652092 L0.519274 0.709922 L0.531007 0.773007 L0.50754 0.841351 L0.454738 0.899179 L0.3726 0.946494 L0.310412 0.961214 L0.209503 0.959111 L0.127367 0.946494 L0.071046 0.929671",4:"M0.418494 0.270996 L0.048828 0.724199 L0.553224 0.724199 M0.414181 0.578167 L0.414181 0.94897",5:"M0.074951 0.270996 L0.074951 0.614701 L0.267655 0.5695 L0.405247 0.586502 L0.460002 0.617189 L0.498028 0.660731 L0.527101 0.779401 L0.513352 0.841049 L0.477274 0.889568 L0.406378 0.93463 L0.324445 0.958337 L0.247399 0.962139 L0.182516 0.949767 L0.130068 0.925508 L0.074951 0.875607 M0.074951 0.270996 L0.527101 0.270996",6:"M0.428549 0.257813 L0.341433 0.285053 L0.26073 0.312099 L0.192188 0.360182 L0.138902 0.410969 L0.098219 0.500422 L0.070249 0.584267 L0.067264 0.670716 L0.065164 0.756863 L0.087163 0.820973 L0.108168 0.861042 L0.157916 0.913131 L0.210981 0.948192 L0.29279 0.961214 L0.384548 0.956206 L0.456409 0.924151 L0.507262 0.881077 L0.5349 0.821975 L0.537111 0.771889 L0.521634 0.718798 L0.498418 0.67372 L0.463042 0.636657 L0.414398 0.613617 L0.34696 0.598591 L0.28284 0.595587 L0.215403 0.605604 L0.145756 0.641665 L0.109274 0.678729 L0.064942 0.724006",7:"M0.071534 0.270996 L0.530519 0.270996 L0.495935 0.291702 L0.477752 0.305407 L0.435186 0.346112 L0.412067 0.374136 L0.388565 0.40796 L0.365315 0.448098 L0.342943 0.495062 L0.322081 0.549366 L0.303364 0.611524 L0.287416 0.68205 L0.270077 0.80465 L0.26253 0.94897",8:"M0.286761 0.257813 L0.210684 0.27162 L0.1414 0.305622 L0.092494 0.382125 L0.111513 0.450128 L0.16857 0.502193 L0.228345 0.539382 L0.377781 0.594635 L0.470161 0.645637 L0.52586 0.706203 L0.538087 0.792269 L0.506841 0.87621 L0.438915 0.927212 L0.339743 0.961214 L0.263666 0.959089 L0.174004 0.929337 L0.102003 0.881523 L0.063965 0.811395 L0.066682 0.741266 L0.102003 0.671139 L0.180797 0.608448 L0.259591 0.580822 L0.358762 0.548945 L0.456576 0.49688 L0.486463 0.446941 L0.487822 0.362999 L0.453859 0.302434 L0.384574 0.265245 L0.286761 0.257813",9:"M0.511026 0.437812 L0.491026 0.347812 L0.451026 0.297812 L0.391026 0.267812 L0.311026 0.257813 L0.231026 0.267812 L0.161026 0.297812 L0.111026 0.347812 L0.091026 0.417812 L0.111026 0.487812 L0.161026 0.537812 L0.231026 0.567812 L0.311026 0.577812 L0.391026 0.557812 L0.451026 0.517812 L0.491026 0.477812 L0.511026 0.437812 M0.510026 0.438812 L0.434026 0.636812 L0.381026 0.777812 L0.337026 0.879812 L0.301026 0.957812","!":"M0.301026 0.270996 L0.301026 0.749566 M0.251466 0.94897 L0.350587 0.94897",'"':"M0.16504 0.270996 L0.16504 0.523022 M0.437013 0.270996 L0.437013 0.523022","#":"M0.20958 0.282227 L0.146515 0.949754 M0.461844 0.282227 L0.398779 0.949754 M0.032999 0.526969 L0.600587 0.452796 M0.001465 0.82366 L0.569055 0.749486",$:"M0.307121 0.240234 L0.307121 1.083502 M0.490031 0.415915 L0.404676 0.328075 L0.23396 0.310507 L0.136407 0.398347 L0.099828 0.521324 L0.124213 0.591596 L0.197379 0.644299 L0.429061 0.697003 L0.502224 0.749708 L0.526613 0.837547 L0.477836 0.960526 L0.355897 1.013228 L0.197379 0.99566 L0.112021 0.942957 L0.07544 0.837547","'":"M0.301026 0.270996 L0.301026 0.523022","(":"M0.413087 0.241211 L0.372337 0.28347 L0.331589 0.334184 L0.290838 0.393349 L0.25009 0.460965 L0.219528 0.528584 L0.199153 0.5962 L0.188966 0.655364 L0.199153 0.714529 L0.219528 0.782146 L0.25009 0.849764 L0.290838 0.91738 L0.331589 0.976544 L0.372337 1.027258 L0.413087 1.069491",")":"M0.188966 0.241211 L0.229716 0.28347 L0.270466 0.334184 L0.311213 0.393349 L0.351964 0.460965 L0.382526 0.528584 L0.4029 0.5962 L0.413087 0.655364 L0.4029 0.714529 L0.382526 0.782146 L0.351964 0.849764 L0.311213 0.91738 L0.270466 0.976544 L0.229716 1.027258 L0.188966 1.069491","*":"M0.301026 0.458702 L0.301026 0.681942 M0.301026 0.458702 L0.520997 0.536834 M0.301026 0.458702 L0.439954 0.257813 M0.301026 0.458702 L0.162098 0.257813 M0.301026 0.458702 L0.081055 0.536834","+":"M0.042969 0.66845 L0.559083 0.66845 M0.301023 0.428223 L0.301023 0.908661",",":"M0.38672 0.852051 L0.215333 1.030661 L0.301025 1.119971","-":"M0.173829 0.686035 L0.428224 0.686035",".":"M0.362549 0.851074 L0.239503 0.851074","/":"M0.062501 1.035249 L0.539551 0.270996","<":"M0.559083 0.441895 L0.042969 0.66939 L0.042969 0.66939 L0.559083 0.896902","=":"M0.042969 0.545898 L0.559083 0.545898 M0.042969 0.80837 L0.559083 0.80837",">":"M0.042969 0.441895 L0.559083 0.66939 L0.559083 0.66939 L0.042969 0.896902",A:"M0.018067 0.94897 L0.290179 0.270996 L0.583986 0.94897 M0.155303 0.684521 L0.433548 0.684521",B:"M0.063965 0.94897 L0.063965 0.278953 L0.209356 0.270996 L0.342486 0.294394 L0.432179 0.37292 L0.418224 0.48773 L0.312686 0.549166 L0.084728 0.575531 L0.306377 0.589434 L0.468877 0.647456 L0.538087 0.736658 L0.5324 0.85202 L0.501247 0.902983 L0.42355 0.944398 L0.063965 0.94897",C:"M0.529054 0.419847 L0.498425 0.345196 L0.442238 0.292341 L0.33583 0.257813 L0.257199 0.268357 L0.187906 0.303748 L0.120243 0.385432 L0.072998 0.599844 L0.110073 0.815385 L0.165381 0.902183 L0.222883 0.942801 L0.334904 0.961214 L0.43253 0.937679 L0.504816 0.868999 L0.529054 0.772065",D:"M0.064454 0.94897 L0.071838 0.285078 L0.171217 0.270996 L0.247348 0.272633 L0.37101 0.306078 L0.462461 0.378304 L0.514748 0.475555 L0.535591 0.576392 L0.537599 0.652313 L0.528065 0.717381 L0.508562 0.772419 L0.445948 0.855695 L0.362356 0.90871 L0.225203 0.945862 L0.064454 0.94897",E:"M0.080078 0.270996 L0.080078 0.94897 M0.080078 0.270996 L0.521974 0.270996 M0.080078 0.609981 L0.389405 0.609981 M0.080078 0.94897 L0.521974 0.94897",F:"M0.086426 0.270996 L0.086426 0.94897 M0.091304 0.275607 L0.515626 0.275607 M0.091304 0.607677 L0.447344 0.607677",G:"M0.498034 0.284943 L0.374621 0.257813 L0.244219 0.268648 L0.160577 0.311997 L0.094556 0.398116 L0.056397 0.58404 L0.076752 0.785532 L0.120865 0.858197 L0.188947 0.916734 L0.271008 0.953591 L0.357069 0.961214 L0.43715 0.932047 L0.501262 0.858539 L0.545656 0.648611 L0.329595 0.648131",H:"M0.066895 0.270996 L0.066895 0.94897 M0.066895 0.595658 L0.530009 0.595658 M0.535157 0.270996 L0.535157 0.94897",I:"M0.301026 0.270996 L0.301026 0.94897",J:"M0.506839 0.270996 L0.507814 0.782193 L0.498468 0.846168 L0.480733 0.880789 L0.455864 0.90832 L0.426095 0.929408 L0.360746 0.954812 L0.302508 0.962139 L0.223573 0.953638 L0.16538 0.930312 L0.137072 0.907715 L0.116428 0.880312 L0.102822 0.848819 L0.095633 0.813947 L0.094239 0.776413",K:"M0.035401 0.270996 L0.035401 0.94897 M0.502258 0.316194 L0.035401 0.687823 M0.212484 0.582361 L0.566652 0.933903",L:"M0.07544 0.270996 L0.07544 0.94897 L0.526613 0.94897",M:"M0.042481 0.94897 L0.042481 0.270996 L0.301027 0.712492 L0.559571 0.270996 L0.559571 0.94897",N:"M0.067871 0.94897 L0.067871 0.270996 L0.534181 0.94897 L0.525031 0.270996",O:"M0.287293 0.961214 L0.19843 0.933567 L0.1172 0.849451 L0.057129 0.563945 L0.114348 0.350255 L0.18455 0.289392 L0.306101 0.257813 L0.42054 0.29572 L0.487543 0.365003 L0.544923 0.625294 L0.516366 0.789624 L0.465476 0.884596 L0.375084 0.949287 L0.287293 0.961214",P:"M0.070557 0.94897 L0.070557 0.28379 L0.20704 0.270996 L0.329134 0.278993 L0.408525 0.300514 L0.444022 0.317908 L0.500637 0.368929 L0.525796 0.423728 L0.531496 0.50384 L0.508934 0.554205 L0.473724 0.582043 L0.417577 0.604365 L0.336375 0.620372 L0.226014 0.629268 L0.082368 0.630258",Q:"M0.282435 1.050813 L0.195447 1.019646 L0.115933 0.924817 L0.057129 0.602943 L0.113139 0.362034 L0.18186 0.293418 L0.300844 0.257813 L0.412868 0.300553 L0.478457 0.37866 L0.534625 0.672103 L0.506671 0.857367 L0.456855 0.964437 L0.368371 1.037368 L0.282435 1.050813 M0.341225 0.815559 L0.544923 1.070653",R:"M0.034912 0.944112 L0.034912 0.288556 L0.227127 0.270996 L0.362038 0.276867 L0.443423 0.294907 L0.477644 0.309614 L0.505809 0.328757 L0.526616 0.352817 L0.544963 0.418061 L0.543241 0.475921 L0.524463 0.517817 L0.49076 0.546518 L0.444265 0.564799 L0.355195 0.578739 L0.047653 0.589627 M0.303054 0.617306 L0.56714 0.94897",S:"M0.483037 0.364333 L0.407613 0.267477 L0.22883 0.257813 L0.128623 0.327565 L0.087712 0.455539 L0.104656 0.518727 L0.168054 0.573307 L0.41928 0.617318 L0.503796 0.669342 L0.535157 0.759324 L0.493846 0.900055 L0.367668 0.961214 L0.205436 0.956661 L0.116711 0.907038 L0.066895 0.790334",T:"M0.022949 0.270996 L0.579103 0.270996 M0.309284 0.270996 L0.309284 0.94897",U:"M0.072022 0.270996 L0.07308 0.648875 L0.080372 0.75167 L0.099024 0.827813 L0.134786 0.885729 L0.181571 0.924023 L0.251464 0.95168 L0.339655 0.962139 L0.401553 0.951668 L0.45232 0.924086 L0.482701 0.891771 L0.495745 0.870529 L0.515699 0.81637 L0.525014 0.744626 L0.530031 0.272017",V:"M0.027832 0.270996 L0.320083 0.94897 L0.57422 0.270996",W:"M0 0.270996 L0.079799 0.940377 L0.285198 0.472884 L0.505255 0.94897 L0.602052 0.270996",X:"M0.009034 0.270996 L0.586805 0.94897 M0.593019 0.270996 L0.015246 0.94897",Y:"M0.018067 0.270996 L0.293132 0.574135 M0.583986 0.271959 L0.294954 0.57606 L0.305277 0.94897",Z:"M0.053711 0.270996 L0.548341 0.270996 L0.053711 0.94897 L0.548341 0.94897","[":"M0.404542 0.240234 L0.197511 0.240234 L0.197511 1.069424 L0.404542 1.069424","\\":"M0.062501 0.270996 L0.539551 1.035249","]":"M0.19751 0.240234 L0.404542 0.240234 L0.404542 1.069424 L0.19751 1.069424","^":"M0.035156 0.523931 L0.301024 0.270996 L0.566896 0.523931",_:"M0 1.160601 L0.602052 1.160601",a:"M0.527101 0.439941 L0.527101 0.973965 M0.527101 0.553824 L0.451366 0.477535 L0.376759 0.439941 L0.263722 0.439941 L0.187989 0.477535 L0.112255 0.553824 L0.074951 0.66881 L0.074951 0.745099 L0.112255 0.85898 L0.187989 0.93527 L0.263722 0.973965 L0.376759 0.973965 L0.451366 0.93527 L0.527101 0.85898",b:"M0.07666 0.240234 L0.07666 0.959985 M0.07666 0.582737 L0.151822 0.514237 L0.225865 0.480483 L0.338045 0.480483 L0.413211 0.514237 L0.488374 0.582737 L0.525392 0.685983 L0.525392 0.754485 L0.488374 0.856739 L0.413211 0.92524 L0.338045 0.959985 L0.225865 0.959985 L0.151822 0.92524 L0.07666 0.856739",c:"M0.512452 0.553823 L0.441624 0.477535 L0.371854 0.439941 L0.26614 0.439941 L0.195312 0.477535 L0.124486 0.553823 L0.0896 0.668808 L0.0896 0.745099 L0.124486 0.858979 L0.195312 0.93527 L0.26614 0.973965 L0.371854 0.973965 L0.441624 0.93527 L0.512452 0.858979",d:"M0.525392 0.240234 L0.525392 0.959985 M0.525392 0.582737 L0.450232 0.514237 L0.376189 0.480483 L0.264006 0.480483 L0.188844 0.514237 L0.11368 0.582737 L0.076661 0.685983 L0.076661 0.754485 L0.11368 0.856739 L0.188844 0.92524 L0.264006 0.959985 L0.376189 0.959985 L0.450232 0.92524 L0.525392 0.856739",e:"M0.059571 0.668808 L0.542482 0.668808 M0.542482 0.592521 L0.502641 0.516231 L0.461594 0.477535 L0.381914 0.439941 L0.261186 0.439941 L0.180299 0.477535 L0.099412 0.553823 L0.059571 0.668808 L0.059571 0.745099 L0.099412 0.858979 L0.180299 0.93527 L0.261186 0.973965 L0.381914 0.973965 L0.461594 0.93527 L0.542482 0.858979",f:"M0.512941 0.240234 L0.406984 0.240234 L0.301026 0.274346 L0.248047 0.374731 L0.248047 0.946817 M0.089112 0.476088 L0.459965 0.476088",g:"M0.525392 0.439941 L0.525392 0.989395 L0.488373 1.091918 L0.45023 1.126757 L0.376189 1.160601 L0.264004 1.160601 L0.188844 1.126757 L0.113681 1.058075 L0.076661 0.954555 M0.525392 0.542467 L0.45023 0.473786 L0.376189 0.439941 L0.264004 0.439941 L0.188844 0.473786 L0.113681 0.542467 L0.076661 0.645988 L0.076661 0.714669 L0.113681 0.817193 L0.188844 0.885875 L0.264004 0.920713 L0.376189 0.920713 L0.45023 0.885875 L0.525392 0.817193",h:"M0.092041 0.240234 L0.092041 0.946817 M0.092041 0.61058 L0.205937 0.509225 L0.282214 0.476086 L0.396109 0.476086 L0.47187 0.509225 L0.510011 0.61058 L0.510011 0.946817",i:"M0.261026 0.240234 L0.341026 0.240234 M0.300978 0.476089 L0.300978 0.946817",j:"M0.3853 0.240234 L0.447023 0.240234 M0.416159 0.465708 L0.416159 1.011689 L0.383887 1.108586 L0.252832 1.140264 L0.15503 1.108586",k:"M0.065186 0.240234 L0.065186 0.946817 M0.493824 0.476086 L0.065186 0.812323 M0.236758 0.677829 L0.536867 0.946817",l:"M0.301026 0.234863 L0.301026 0.946441",m:"M0.050538 0.439941 L0.050538 0.960796 M0.050538 0.588758 L0.114405 0.476607 L0.157178 0.439941 L0.236864 0.439941 L0.279637 0.476607 L0.32241 0.588758 L0.32241 0.960796 M0.32241 0.588758 L0.386281 0.476607 L0.428467 0.439941 L0.50874 0.439941 L0.551515 0.476607 L0.551515 0.960796",n:"M0.092041 0.439941 L0.092041 0.960796 M0.092041 0.588758 L0.205936 0.476607 L0.282216 0.439941 L0.396113 0.439941 L0.471871 0.476607 L0.510011 0.588758 L0.510011 0.960796",o:"M0.247175 0.439941 L0.175178 0.477535 L0.103186 0.553823 L0.066895 0.668808 L0.066895 0.745099 L0.103186 0.858979 L0.175178 0.93527 L0.247175 0.973965 L0.354874 0.973965 L0.426872 0.93527 L0.498866 0.858979 L0.535157 0.745099 L0.535157 0.668808 L0.498866 0.553823 L0.426872 0.477535 L0.354874 0.439941 L0.247175 0.439941",p:"M0.076904 0.439941 L0.076904 1.154244 M0.076904 0.541563 L0.151986 0.473487 L0.225944 0.439941 L0.338005 0.439941 L0.413087 0.473487 L0.488166 0.541563 L0.525148 0.644169 L0.525148 0.712246 L0.488166 0.813866 L0.413087 0.881942 L0.338005 0.916471 L0.225944 0.916471 L0.151986 0.881942 L0.076904 0.813866",q:"M0.525148 0.441895 L0.525148 1.156195 M0.525148 0.5435 L0.450067 0.47544 L0.376106 0.441895 L0.264042 0.441895 L0.188966 0.47544 L0.113885 0.5435 L0.076905 0.646108 L0.076905 0.714187 L0.113885 0.815809 L0.188966 0.883886 L0.264042 0.918418 L0.376106 0.918418 L0.450067 0.883886 L0.525148 0.815809",r:"M0.107422 0.439941 L0.107422 0.960796 M0.107422 0.663164 L0.155824 0.551014 L0.252626 0.476607 L0.349428 0.439941 L0.49463 0.439941",s:"M0.475556 0.477535 L0.400757 0.439941 L0.276092 0.439941 L0.176361 0.477535 L0.101563 0.553823 L0.101563 0.630112 L0.176361 0.668808 L0.301024 0.668808 L0.425688 0.745099 L0.50049 0.821387 L0.50049 0.897677 L0.425688 0.93527 L0.325956 0.973965 L0.201295 0.973965 L0.126496 0.93527 L0.101563 0.858979",t:"M0.246032 0.297852 L0.246032 0.826549 L0.301023 0.919323 L0.411011 0.950848 L0.520997 0.950848 M0.081055 0.515799 L0.466004 0.515799",u:"M0.092041 0.454102 L0.092041 0.826134 L0.13018 0.937211 L0.205936 0.974954 L0.319832 0.974954 L0.396113 0.937211 L0.510011 0.826134 M0.510011 0.454102 L0.510011 0.974954",v:"M0.048828 0.453125 L0.301026 0.961719 M0.553224 0.453125 L0.301026 0.961719",w:"M0 0.453125 L0.150512 0.961719 M0.301024 0.453125 L0.150512 0.961719 M0.301024 0.453125 L0.451539 0.961719 M0.602052 0.453125 L0.451539 0.961719",x:"M0.03711 0.453125 L0.564943 0.961719 M0.564943 0.453125 L0.03711 0.961719",y:"M0.084618 0.453125 L0.320232 0.921476 M0.55713 0.453125 L0.320232 0.921476 L0.242119 1.055289 L0.163369 1.122196 L0.084618 1.155166 L0.044922 1.155166",z:"M0.505373 0.452148 L0.09668 0.961651 M0.09668 0.452148 L0.505373 0.452148 M0.09668 0.961651 L0.505373 0.961651"},lineAlphabet={};for(let letter in svgAlphabet){lineAlphabet[letter]=[];let segs=svgAlphabet[letter].split("M").slice(1).map(seg=>seg.split("L").map(pr3=>pr3.trim().split(" ").map(parseFloat)));for(let seg of segs)for(let i3=0;i3<seg.length-1;i3++)lineAlphabet[letter].push({x1:seg[i3][0],y1:1-seg[i3][1],x2:seg[i3+1][0],y2:1-seg[i3+1][1]})}}});var dist_exports3={};__export(dist_exports3,{CIRCUIT_TO_SVG_VERSION:()=>CIRCUIT_TO_SVG_VERSION,circuitJsonToPcbSvg:()=>circuitJsonToPcbSvg,circuitJsonToSchematicSvg:()=>circuitJsonToSchematicSvg,convertCircuitJsonToAssemblySvg:()=>convertCircuitJsonToAssemblySvg,convertCircuitJsonToPcbSvg:()=>convertCircuitJsonToPcbSvg,convertCircuitJsonToPinoutSvg:()=>convertCircuitJsonToPinoutSvg,convertCircuitJsonToSchematicSimulationSvg:()=>convertCircuitJsonToSchematicSimulationSvg,convertCircuitJsonToSchematicSvg:()=>convertCircuitJsonToSchematicSvg,convertCircuitJsonToSimulationGraphSvg:()=>convertCircuitJsonToSimulationGraphSvg,convertCircuitJsonToSolderPasteMask:()=>convertCircuitJsonToSolderPasteMask,createErrorTextOverlay:()=>createErrorTextOverlay,createSvgObjectsForSchComponentPortHovers:()=>createSvgObjectsForSchComponentPortHovers,getSoftwareUsedString:()=>getSoftwareUsedString,isSimulationExperiment:()=>isSimulationExperiment,isSimulationTransientVoltageGraph:()=>isSimulationTransientVoltageGraph,isSimulationVoltageProbe:()=>isSimulationVoltageProbe});function createSvgObjectsFromPcbTraceError(pcbTraceError,circuitJson,ctx){let{transform:transform6,shouldDrawErrors}=ctx;if(!shouldDrawErrors)return[];let{pcb_port_ids}=pcbTraceError,port1=circuitJson.find(el3=>el3.type==="pcb_port"&&el3.pcb_port_id===pcb_port_ids?.[0]),port2=circuitJson.find(el3=>el3.type==="pcb_port"&&el3.pcb_port_id===pcb_port_ids?.[1]);if(!port1||!port2){let viaId=pcbTraceError.message?.match(/pcb_via\[#?(pcb_via_\d+)\]/)?.[1],via=circuitJson.find(el3=>el3.type==="pcb_via"&&el3.pcb_via_id===viaId);if(via&&via.type==="pcb_via")return createSvgObjectsForViaTraceError(pcbTraceError,via,ctx);if(pcbTraceError.center){let screenCenter=applyToPoint3(transform6,{x:pcbTraceError.center.x,y:pcbTraceError.center.y});return annotateTraceErrorSvgObjects([{name:"rect",type:"element",attributes:{x:(screenCenter.x-5).toString(),y:(screenCenter.y-5).toString(),width:"10",height:"10",fill:"red",transform:`rotate(45 ${screenCenter.x} ${screenCenter.y})`},children:[],value:""},{name:"text",type:"element",attributes:{x:screenCenter.x.toString(),y:(screenCenter.y-15).toString(),fill:"red","font-family":"sans-serif","font-size":"12","text-anchor":"middle"},children:[{type:"text",value:pcbTraceError.message||"Pcb Trace Error",name:"",attributes:{},children:[]}],value:""}])}else return[]}let screenPort1=applyToPoint3(transform6,{x:port1.x,y:port1.y}),screenPort2=applyToPoint3(transform6,{x:port2.x,y:port2.y}),errorCenter={x:(screenPort1.x+screenPort2.x)/2,y:(screenPort1.y+screenPort2.y)/2};if(isNaN(screenPort1.x)||isNaN(screenPort1.y)||isNaN(screenPort2.x)||isNaN(screenPort2.y)||isNaN(errorCenter.x)||isNaN(errorCenter.y))return[];let svgObjects=[{name:"line",type:"element",attributes:{x1:screenPort1.x.toString(),y1:screenPort1.y.toString(),x2:errorCenter.x.toString(),y2:errorCenter.y.toString(),stroke:"red","stroke-width":"1.5","stroke-dasharray":"2,2"},children:[],value:""},{name:"line",type:"element",attributes:{x1:errorCenter.x.toString(),y1:errorCenter.y.toString(),x2:screenPort2.x.toString(),y2:screenPort2.y.toString(),stroke:"red","stroke-width":"1.5","stroke-dasharray":"2,2"},children:[],value:""},{name:"rect",type:"element",attributes:{x:(errorCenter.x-5).toString(),y:(errorCenter.y-5).toString(),width:"10",height:"10",fill:"red",transform:`rotate(45 ${errorCenter.x} ${errorCenter.y})`},children:[],value:""},{name:"text",type:"element",attributes:{x:errorCenter.x.toString(),y:(errorCenter.y-15).toString(),fill:"red","font-family":"sans-serif","font-size":"12","text-anchor":"middle"},children:[{type:"text",value:pcbTraceError.message||"Pcb Trace Error",name:"",attributes:{},children:[]}],value:""}];return annotateTraceErrorSvgObjects(svgObjects)}function createSvgObjectsForViaTraceError(pcbTraceError,via,ctx){let{transform:transform6}=ctx;if(pcbTraceError.center&&via){let screenCenter=applyToPoint3(transform6,{x:pcbTraceError.center.x,y:pcbTraceError.center.y}),screenVia=applyToPoint3(transform6,{x:via.x,y:via.y}),dx3=screenVia.x-screenCenter.x,dy3=screenVia.y-screenCenter.y,dist=Math.sqrt(dx3*dx3+dy3*dy3),angle=Math.atan2(dy3,dx3)*180/Math.PI,boxWidth=dist+10*2,boxHeight=20,midX=(screenCenter.x+screenVia.x)/2,midY=(screenCenter.y+screenVia.y)/2;return annotateTraceErrorSvgObjects([{name:"rect",type:"element",attributes:{x:(midX-boxWidth/2).toString(),y:(midY-boxHeight/2).toString(),width:boxWidth.toString(),height:boxHeight.toString(),fill:"none",stroke:"red","stroke-width":"1","stroke-dasharray":"3,2",transform:`rotate(${angle} ${midX} ${midY})`},children:[],value:""},{name:"rect",type:"element",attributes:{x:(midX-5).toString(),y:(midY-5).toString(),width:"10",height:"10",fill:"red",transform:`rotate(45 ${midX} ${midY})`},children:[],value:""},{name:"text",type:"element",attributes:{x:midX.toString(),y:(midY-boxHeight/2-5).toString(),fill:"red","font-family":"sans-serif","font-size":"12","text-anchor":"middle"},children:[{type:"text",value:pcbTraceError.message||"Pcb Trace Error",name:"",attributes:{},children:[]}],value:""}])}return[]}function annotateTraceErrorSvgObjects(objects){return objects.map(object=>({...object,attributes:{...object.attributes??{},"data-type":object.attributes?.["data-type"]??"pcb_trace_error","data-pcb-layer":object.attributes?.["data-pcb-layer"]??"overlay"},children:(object.children??[]).map(child=>child?.type==="element"?{...child,attributes:{...child.attributes??{},"data-type":child.attributes?.["data-type"]??"pcb_trace_error","data-pcb-layer":child.attributes?.["data-pcb-layer"]??"overlay"}}:child)}))}function annotateFootprintErrorSvgObjects(objects){return objects.map(object=>({...object,attributes:{...object.attributes??{},"data-type":object.attributes?.["data-type"]??"pcb_footprint_overlap_error","data-pcb-layer":object.attributes?.["data-pcb-layer"]??"overlay"},children:(object.children??[]).map(child=>child?.type==="element"?{...child,attributes:{...child.attributes??{},"data-type":child.attributes?.["data-type"]??"pcb_footprint_overlap_error","data-pcb-layer":child.attributes?.["data-pcb-layer"]??"overlay"}}:child)}))}function createSvgObjectsFromPcbFootprintOverlapError(error2,circuitJson,ctx){let{transform:transform6,shouldDrawErrors}=ctx;if(!shouldDrawErrors)return[];let svgObjects=[],referencedElements=[],padPortIds=[];if(error2.pcb_smtpad_ids)for(let padId of error2.pcb_smtpad_ids){let pad2=circuitJson.find(el3=>el3.type==="pcb_smtpad"&&el3.pcb_smtpad_id===padId);pad2&&(referencedElements.push({x:pad2.x,y:pad2.y,type:"pcb_smtpad",id:padId,pcb_port_id:pad2.pcb_port_id}),pad2.pcb_port_id&&padPortIds.push(pad2.pcb_port_id))}let allPadsSamePort=padPortIds.length>1&&padPortIds.every(id2=>id2===padPortIds[0]),filteredReferencedElements=referencedElements;if(allPadsSamePort&&(filteredReferencedElements=referencedElements.filter(e5=>e5.type!=="pcb_smtpad")),error2.pcb_plated_hole_ids)for(let holeId of error2.pcb_plated_hole_ids){let hole=circuitJson.find(el3=>el3.type==="pcb_plated_hole"&&el3.pcb_plated_hole_id===holeId);hole&&filteredReferencedElements.push({x:hole.x,y:hole.y,type:"pcb_plated_hole",id:holeId})}if(error2.pcb_hole_ids)for(let holeId of error2.pcb_hole_ids){let hole=circuitJson.find(el3=>el3.type==="pcb_hole"&&el3.pcb_hole_id===holeId);hole&&filteredReferencedElements.push({x:hole.x,y:hole.y,type:"pcb_hole",id:holeId})}if(filteredReferencedElements.length>0){let centerX=filteredReferencedElements.reduce((sum,el3)=>sum+el3.x,0)/filteredReferencedElements.length,centerY=filteredReferencedElements.reduce((sum,el3)=>sum+el3.y,0)/filteredReferencedElements.length,screenCenter=applyToPoint3(transform6,{x:centerX,y:centerY});svgObjects.push({name:"rect",type:"element",attributes:{x:(screenCenter.x-5).toString(),y:(screenCenter.y-5).toString(),width:"10",height:"10",fill:"red",transform:`rotate(45 ${screenCenter.x} ${screenCenter.y})`},children:[],value:""}),svgObjects.push({name:"text",type:"element",attributes:{x:screenCenter.x.toString(),y:(screenCenter.y-15).toString(),fill:"red","font-family":"sans-serif","font-size":"12","text-anchor":"middle"},children:[{type:"text",value:error2.message||"PCB Footprint Overlap Error",name:"",attributes:{},children:[]}],value:""});for(let element of filteredReferencedElements){let screenPos=applyToPoint3(transform6,{x:element.x,y:element.y});svgObjects.push({name:"rect",type:"element",attributes:{x:(screenPos.x-5).toString(),y:(screenPos.y-5).toString(),width:"10",height:"10",fill:"red",transform:`rotate(45 ${screenPos.x} ${screenPos.y})`},children:[],value:""}),filteredReferencedElements.length>1&&svgObjects.push({name:"line",type:"element",attributes:{x1:screenCenter.x.toString(),y1:screenCenter.y.toString(),x2:screenPos.x.toString(),y2:screenPos.y.toString(),stroke:"red","stroke-width":"1.5","stroke-dasharray":"2,2"},children:[],value:""})}}return annotateFootprintErrorSvgObjects(svgObjects)}function createSvgObjectsFromPcbCourtyardOverlapError(error2,circuitJson,ctx){let{transform:transform6,shouldDrawErrors}=ctx;if(!shouldDrawErrors)return[];let svgObjects=[],componentCenters=[];for(let compId of error2.pcb_component_ids){let comp=circuitJson.find(el3=>el3.type==="pcb_component"&&el3.pcb_component_id===compId);comp&&componentCenters.push(comp.center)}if(componentCenters.length===0)return[];let midX=componentCenters.reduce((s3,c4)=>s3+c4.x,0)/componentCenters.length,midY=componentCenters.reduce((s3,c4)=>s3+c4.y,0)/componentCenters.length,screenMid=applyToPoint3(transform6,{x:midX,y:midY});svgObjects.push({name:"rect",type:"element",attributes:{x:(screenMid.x-5).toString(),y:(screenMid.y-5).toString(),width:"10",height:"10",fill:"red",transform:`rotate(45 ${screenMid.x} ${screenMid.y})`,"data-type":"pcb_courtyard_overlap_error","data-pcb-layer":"overlay"},children:[],value:""}),svgObjects.push({name:"text",type:"element",attributes:{x:screenMid.x.toString(),y:(screenMid.y-15).toString(),fill:"red","font-family":"sans-serif","font-size":"12","text-anchor":"middle","data-type":"pcb_courtyard_overlap_error","data-pcb-layer":"overlay"},children:[{type:"text",value:error2.message||"PCB Courtyard Overlap",name:"",attributes:{},children:[]}],value:""});for(let center2 of componentCenters){let screenPos=applyToPoint3(transform6,center2);svgObjects.push({name:"rect",type:"element",attributes:{x:(screenPos.x-5).toString(),y:(screenPos.y-5).toString(),width:"10",height:"10",fill:"red",transform:`rotate(45 ${screenPos.x} ${screenPos.y})`,"data-type":"pcb_courtyard_overlap_error","data-pcb-layer":"overlay"},children:[],value:""})}if(componentCenters.length===2){let mapped=componentCenters.map(c4=>applyToPoint3(transform6,c4)),s12=mapped[0],s22=mapped[1];svgObjects.push({name:"line",type:"element",attributes:{x1:s12.x.toString(),y1:s12.y.toString(),x2:s22.x.toString(),y2:s22.y.toString(),stroke:"red","stroke-width":"1.5","stroke-dasharray":"4,3","data-type":"pcb_courtyard_overlap_error","data-pcb-layer":"overlay"},children:[],value:""})}return svgObjects}function annotateError(objects){return objects.map(object=>({...object,attributes:{...object.attributes??{},"data-type":object.attributes?.["data-type"]??"pcb_component_outside_board_error","data-pcb-layer":object.attributes?.["data-pcb-layer"]??"overlay"}}))}function getComponentBounds2(error2,circuitJson){let pcbComponentId=error2.pcb_component_id;if(!pcbComponentId)return error2.component_bounds??null;let pcbComponent=circuitJson.find(elm=>elm.type==="pcb_component"&&elm.pcb_component_id===pcbComponentId);return pcbComponent?.center&&pcbComponent?.width&&pcbComponent?.height?{min_x:pcbComponent.center.x-pcbComponent.width/2,max_x:pcbComponent.center.x+pcbComponent.width/2,min_y:pcbComponent.center.y-pcbComponent.height/2,max_y:pcbComponent.center.y+pcbComponent.height/2}:error2.component_bounds??null}function createSvgObjectsFromPcbComponentOutsideBoardError(error2,circuitJson,ctx){let{shouldDrawErrors,transform:transform6}=ctx;if(!shouldDrawErrors)return[];let bounds=getComponentBounds2(error2,circuitJson);if(!bounds)return[];let topLeft=applyToPoint3(transform6,{x:bounds.min_x,y:bounds.min_y}),bottomRight=applyToPoint3(transform6,{x:bounds.max_x,y:bounds.max_y}),x4=Math.min(topLeft.x,bottomRight.x),y4=Math.min(topLeft.y,bottomRight.y),width=Math.abs(bottomRight.x-topLeft.x),height=Math.abs(bottomRight.y-topLeft.y),centerX=x4+width/2,centerY=y4+height/2,svgObjects=[{type:"element",name:"rect",value:"",attributes:{x:x4.toString(),y:y4.toString(),width:width.toString(),height:height.toString(),fill:"none",stroke:"red","stroke-width":"1.5","stroke-dasharray":"4,2"},children:[]},{type:"element",name:"rect",value:"",attributes:{x:(centerX-5).toString(),y:(centerY-5).toString(),width:"10",height:"10",fill:"red",transform:`rotate(45 ${centerX} ${centerY})`},children:[]},{type:"element",name:"text",value:"",attributes:{x:centerX.toString(),y:(y4-10).toString(),fill:"red","font-family":"sans-serif","font-size":"12","text-anchor":"middle"},children:[{type:"text",name:"",value:error2.message??"PCB component extends outside board boundaries",attributes:{},children:[]}]}];return annotateError(svgObjects)}function annotateError2(objects){return objects.map(object=>({...object,attributes:{...object.attributes??{},"data-type":object.attributes?.["data-type"]??"pcb_via_trace_clearance_error","data-pcb-layer":object.attributes?.["data-pcb-layer"]??"overlay"}}))}function createSvgObjectsFromPcbViaTraceClearanceError(error2,_circuitJson,ctx){let{shouldDrawErrors,transform:transform6}=ctx;if(!shouldDrawErrors)return[];let center2=error2.center;if(!center2||typeof center2.x!="number"||typeof center2.y!="number")return[];let screenCenter=applyToPoint3(transform6,center2),actualClearance=error2.actual_clearance,minimumClearance=error2.minimum_clearance,defaultMessage=actualClearance&&minimumClearance?`Via/trace clearance ${actualClearance} is below minimum ${minimumClearance}`:"Via and trace too close",message=error2.message??defaultMessage,svgObjects=[{type:"element",name:"rect",value:"",attributes:{x:(screenCenter.x-5).toString(),y:(screenCenter.y-5).toString(),width:"10",height:"10",fill:"red",transform:`rotate(45 ${screenCenter.x} ${screenCenter.y})`},children:[]},{type:"element",name:"text",value:"",attributes:{x:screenCenter.x.toString(),y:(screenCenter.y-15).toString(),fill:"red","font-family":"sans-serif","font-size":"12","text-anchor":"middle"},children:[{type:"text",name:"",value:message,attributes:{},children:[]}]}];return annotateError2(svgObjects)}function createSvgObjectsFromPcbFabricationNotePath(fabNotePath,ctx){let{transform:transform6,layer:layerFilter}=ctx;if(!fabNotePath.route||!Array.isArray(fabNotePath.route))return[];let firstPoint=fabNotePath.route[0],lastPoint=fabNotePath.route[fabNotePath.route.length-1],isClosed=firstPoint.x===lastPoint.x&&firstPoint.y===lastPoint.y,path=fabNotePath.route.slice(0,isClosed?-1:void 0).map((point7,index)=>{let[x4,y4]=applyToPoint3(transform6,[point7.x,point7.y]);return index===0?`M ${x4} ${y4}`:`L ${x4} ${y4}`}).join(" ")+(isClosed?" Z":"");return[{name:"path",type:"element",attributes:{class:"pcb-fabrication-note-path",stroke:fabNotePath.color||"rgba(255,255,255,0.5)",fill:"none",d:path,"stroke-width":(fabNotePath.stroke_width*Math.abs(transform6.a)).toString(),"data-pcb-component-id":fabNotePath.pcb_component_id,"data-pcb-fabrication-note-path-id":fabNotePath.pcb_fabrication_note_path_id,"data-type":"pcb_fabrication_note_path","data-pcb-layer":"overlay"},value:"",children:[]}]}function createSvgObjectsFromPcbFabricationNoteText(pcbFabNoteText,ctx){let{transform:transform6,layer:layerFilter}=ctx,{anchor_position,anchor_alignment="center",text,font_size=1,layer="top",color}=pcbFabNoteText;if(layerFilter&&layer!==layerFilter)return[];if(!anchor_position||typeof anchor_position.x!="number"||typeof anchor_position.y!="number")return debugPcb(`[pcb_fabrication_note_text] Invalid anchor_position for "${pcbFabNoteText.pcb_fabrication_note_text_id}": expected {x: number, y: number}, got ${JSON.stringify(anchor_position)}`),[];let[transformedX,transformedY]=applyToPoint3(transform6,[anchor_position.x,anchor_position.y]),transformedFontSize=font_size*Math.abs(transform6.a),textAnchor="middle",dominantBaseline="central";switch(anchor_alignment){case"top_left":textAnchor="start",dominantBaseline="text-before-edge";break;case"top_right":textAnchor="end",dominantBaseline="text-before-edge";break;case"bottom_left":textAnchor="start",dominantBaseline="text-after-edge";break;case"bottom_right":textAnchor="end",dominantBaseline="text-after-edge";break}let textTransform=compose3(translate3(transformedX,transformedY),rotate3(Math.PI/180));return[{name:"text",type:"element",attributes:{x:"0",y:"0","font-family":"Arial, sans-serif","font-size":transformedFontSize.toString(),"text-anchor":textAnchor,"dominant-baseline":dominantBaseline,transform:toString2(textTransform),class:"pcb-fabrication-note-text",fill:color||"rgba(255,255,255,0.5)","data-type":"pcb_fabrication_note_text","data-pcb-layer":"overlay"},children:[{type:"text",value:text,name:"",attributes:{},children:[]}],value:""}]}function createSvgObjectsFromPcbFabricationNoteRect(fabricationNoteRect,ctx){let{transform:transform6,layer:layerFilter}=ctx,{center:center2,width,height,stroke_width,is_filled,has_stroke,is_stroke_dashed,color,layer="top",pcb_component_id,pcb_fabrication_note_rect_id,corner_radius}=fabricationNoteRect;if(layerFilter&&layer!==layerFilter)return[];if(!center2||typeof center2.x!="number"||typeof center2.y!="number"||typeof width!="number"||typeof height!="number")return debugPcb(`[pcb_fabrication_note_rect] Invalid data for "${pcb_fabrication_note_rect_id}": expected center {x: number, y: number}, width: number, height: number, got center=${JSON.stringify(center2)}, width=${JSON.stringify(width)}, height=${JSON.stringify(height)}`),[];let halfWidth=width/2,halfHeight=height/2,[topLeftX,topLeftY]=applyToPoint3(transform6,[center2.x-halfWidth,center2.y+halfHeight]),[bottomRightX,bottomRightY]=applyToPoint3(transform6,[center2.x+halfWidth,center2.y-halfHeight]),rectX=Math.min(topLeftX,bottomRightX),rectY=Math.min(topLeftY,bottomRightY),rectWidth=Math.abs(bottomRightX-topLeftX),rectHeight=Math.abs(bottomRightY-topLeftY),transformedStrokeWidth=(typeof stroke_width=="number"?stroke_width:0)*Math.abs(transform6.a),overlayStrokeColor=color??DEFAULT_OVERLAY_STROKE_COLOR,baseCornerRadius=typeof corner_radius=="number"&&corner_radius>0?corner_radius:0,transformedCornerRadiusX=baseCornerRadius*Math.abs(transform6.a),transformedCornerRadiusY=baseCornerRadius*Math.abs(transform6.d),attributes2={x:rectX.toString(),y:rectY.toString(),width:rectWidth.toString(),height:rectHeight.toString(),class:"pcb-fabrication-note-rect","data-type":"pcb_fabrication_note_rect","data-pcb-fabrication-note-rect-id":pcb_fabrication_note_rect_id,"data-pcb-layer":"overlay"};if(pcb_component_id!==void 0&&(attributes2["data-pcb-component-id"]=pcb_component_id),transformedCornerRadiusX>0&&(attributes2.rx=transformedCornerRadiusX.toString()),transformedCornerRadiusY>0&&(attributes2.ry=transformedCornerRadiusY.toString()),is_filled?attributes2.fill=color??DEFAULT_OVERLAY_FILL_COLOR:attributes2.fill="none",has_stroke??transformedStrokeWidth>0){if(attributes2.stroke=overlayStrokeColor,attributes2["stroke-width"]=transformedStrokeWidth.toString(),is_stroke_dashed){let dash=.2*Math.abs(transform6.a),gap=.1*Math.abs(transform6.a);attributes2["stroke-dasharray"]=`${dash} ${gap}`}}else attributes2.stroke="none";return[{name:"rect",type:"element",value:"",attributes:attributes2,children:[]}]}function normalize(vector2){let length4=Math.hypot(vector2.x,vector2.y)||1;return{x:vector2.x/length4,y:vector2.y/length4}}function toPath(points){return points.map((point7,index)=>index===0?`M ${point7.x} ${point7.y}`:`L ${point7.x} ${point7.y}`).join(" ")}function createSvgObjectsFromPcbFabricationNoteDimension(dimension,ctx){let{transform:transform6,layer:layerFilter}=ctx,{from,to:to3,text,font_size=1,color,arrow_size,layer,pcb_component_id,pcb_fabrication_note_dimension_id,offset_distance,offset_direction,text_ccw_rotation}=dimension;if(layerFilter&&layer&&layer!==layerFilter)return[];if(!from||!to3||typeof from!="object"||typeof to3!="object")return debugPcb(`[pcb_fabrication_note_dimension] Invalid endpoints for "${pcb_fabrication_note_dimension_id}": expected {from: {x, y}, to: {x, y}}, got from=${JSON.stringify(from)}, to=${JSON.stringify(to3)}`),[];if(typeof from.x!="number"||typeof from.y!="number"||typeof to3.x!="number"||typeof to3.y!="number")return debugPcb(`[pcb_fabrication_note_dimension] Invalid point values for "${pcb_fabrication_note_dimension_id}": x and y must be numbers, got from=${JSON.stringify(from)}, to=${JSON.stringify(to3)}`),[];let numericArrowSize=typeof arrow_size=="number"?arrow_size:void 0;if(numericArrowSize===void 0||!Number.isFinite(numericArrowSize)||numericArrowSize<=0)return debugPcb(`[pcb_fabrication_note_dimension] Invalid arrow_size for "${pcb_fabrication_note_dimension_id}": expected positive number, got ${JSON.stringify(arrow_size)}`),[];let arrowSize=numericArrowSize,direction2=normalize({x:to3.x-from.x,y:to3.y-from.y});if(Number.isNaN(direction2.x)||Number.isNaN(direction2.y))return[];let perpendicular={x:-direction2.y,y:direction2.x},hasOffsetDirection=offset_direction&&typeof offset_direction.x=="number"&&typeof offset_direction.y=="number",normalizedOffsetDirection=hasOffsetDirection?normalize({x:offset_direction.x,y:offset_direction.y}):{x:0,y:0},offsetMagnitude=typeof offset_distance=="number"?offset_distance:0,offsetVector={x:normalizedOffsetDirection.x*offsetMagnitude,y:normalizedOffsetDirection.y*offsetMagnitude},applyOffset=point7=>({x:point7.x+offsetVector.x,y:point7.y+offsetVector.y}),fromOffset=applyOffset(from),toOffset=applyOffset(to3),arrowHalfWidth=arrowSize/2,fromBase={x:fromOffset.x+direction2.x*arrowSize,y:fromOffset.y+direction2.y*arrowSize},toBase={x:toOffset.x-direction2.x*arrowSize,y:toOffset.y-direction2.y*arrowSize},fromTriangle=[toScreen(fromOffset),toScreen({x:fromBase.x+perpendicular.x*arrowHalfWidth,y:fromBase.y+perpendicular.y*arrowHalfWidth}),toScreen({x:fromBase.x-perpendicular.x*arrowHalfWidth,y:fromBase.y-perpendicular.y*arrowHalfWidth})],toTriangle=[toScreen(toOffset),toScreen({x:toBase.x+perpendicular.x*arrowHalfWidth,y:toBase.y+perpendicular.y*arrowHalfWidth}),toScreen({x:toBase.x-perpendicular.x*arrowHalfWidth,y:toBase.y-perpendicular.y*arrowHalfWidth})],[lineStartX,lineStartY]=applyToPoint3(transform6,[fromBase.x,fromBase.y]),[lineEndX,lineEndY]=applyToPoint3(transform6,[toBase.x,toBase.y]),strokeWidth=arrowSize/5*Math.abs(transform6.a),lineColor=color||"rgba(255,255,255,0.5)",extensionDirection=hasOffsetDirection&&(Math.abs(normalizedOffsetDirection.x)>Number.EPSILON||Math.abs(normalizedOffsetDirection.y)>Number.EPSILON)?normalizedOffsetDirection:perpendicular,extensionLength=offsetMagnitude+arrowSize,createExtensionLine=anchor=>{let endPoint={x:anchor.x+extensionDirection.x*extensionLength,y:anchor.y+extensionDirection.y*extensionLength},[startX,startY]=applyToPoint3(transform6,[anchor.x,anchor.y]),[endX,endY]=applyToPoint3(transform6,[endPoint.x,endPoint.y]);return{name:"path",type:"element",value:"",attributes:{d:`M ${startX} ${startY} L ${endX} ${endY}`,stroke:lineColor,fill:"none","stroke-width":strokeWidth.toString(),"stroke-linecap":"round",class:"pcb-fabrication-note-dimension-extension"},children:[]}},extensionSegments=[createExtensionLine(from),createExtensionLine(to3)],midPoint2={x:(from.x+to3.x)/2+offsetVector.x,y:(from.y+to3.y)/2+offsetVector.y},[screenFromX,screenFromY]=applyToPoint3(transform6,[fromOffset.x,fromOffset.y]),[screenToX,screenToY]=applyToPoint3(transform6,[toOffset.x,toOffset.y]),screenDirection=normalize({x:screenToX-screenFromX,y:screenToY-screenFromY}),textAngle=Math.atan2(screenDirection.y,screenDirection.x)*180/Math.PI;(textAngle>90||textAngle<-90)&&(textAngle+=180);let finalTextAngle=typeof text_ccw_rotation=="number"&&Number.isFinite(text_ccw_rotation)?textAngle-text_ccw_rotation:textAngle,additionalOffset=0;if(text&&typeof text_ccw_rotation=="number"&&Number.isFinite(text_ccw_rotation)){let textWidth=text.length*font_size*CHARACTER_WIDTH_MULTIPLIER,textHeight=font_size,rotationRad=text_ccw_rotation*Math.PI/180,sinRot=Math.abs(Math.sin(rotationRad)),cosRot=Math.abs(Math.cos(rotationRad)),halfWidth=textWidth/2,halfHeight=textHeight/2;additionalOffset=halfWidth*sinRot+halfHeight*cosRot+font_size*TEXT_INTERSECTION_PADDING_MULTIPLIER}let textOffset=arrowSize*TEXT_OFFSET_MULTIPLIER+additionalOffset,textPoint={x:midPoint2.x+perpendicular.x*textOffset,y:midPoint2.y+perpendicular.y*textOffset},[textX,textY]=applyToPoint3(transform6,[textPoint.x,textPoint.y]),transformedFontSize=font_size*Math.abs(transform6.a),children=[...extensionSegments,{name:"path",type:"element",value:"",attributes:{d:`M ${lineStartX} ${lineStartY} L ${lineEndX} ${lineEndY}`,stroke:lineColor,fill:"none","stroke-width":strokeWidth.toString(),"stroke-linecap":"round",class:"pcb-fabrication-note-dimension-line"},children:[]},{name:"path",type:"element",value:"",attributes:{d:`${toPath(fromTriangle)} Z`,fill:lineColor,class:"pcb-fabrication-note-dimension-arrow"},children:[]},{name:"path",type:"element",value:"",attributes:{d:`${toPath(toTriangle)} Z`,fill:lineColor,class:"pcb-fabrication-note-dimension-arrow"},children:[]}];text&&children.push({name:"text",type:"element",value:"",attributes:{x:textX.toString(),y:textY.toString(),fill:lineColor,"font-size":transformedFontSize.toString(),"font-family":"Arial, sans-serif","text-anchor":"middle","dominant-baseline":"central",class:"pcb-fabrication-note-dimension-text",transform:`rotate(${finalTextAngle} ${textX} ${textY})`},children:[{type:"text",name:"",value:text,attributes:{},children:[]}]});let attributes2={class:"pcb-fabrication-note-dimension","data-type":"pcb_fabrication_note_dimension","data-pcb-fabrication-note-dimension-id":pcb_fabrication_note_dimension_id,"data-pcb-layer":layer??"overlay"};return pcb_component_id!==void 0&&(attributes2["data-pcb-component-id"]=pcb_component_id),[{name:"g",type:"element",value:"",attributes:attributes2,children}];function toScreen(point7){let[x4,y4]=applyToPoint3(transform6,[point7.x,point7.y]);return{x:x4,y:y4}}}function normalize2(vector2){let length4=Math.hypot(vector2.x,vector2.y)||1;return{x:vector2.x/length4,y:vector2.y/length4}}function toPath2(points){return points.map((point7,index)=>index===0?`M ${point7.x} ${point7.y}`:`L ${point7.x} ${point7.y}`).join(" ")}function createSvgObjectsFromPcbNoteDimension(dimension,ctx){let{transform:transform6}=ctx,{from,to:to3,text,font_size=1,color,arrow_size,offset_distance,offset_direction,text_ccw_rotation}=dimension;if(!from||!to3)return debugPcb(`[pcb_note_dimension] Invalid endpoints for "${dimension.pcb_note_dimension_id}": expected {from: {x, y}, to: {x, y}}, got from=${JSON.stringify(from)}, to=${JSON.stringify(to3)}`),[];if(!Number.isFinite(arrow_size)||arrow_size<=0)return debugPcb(`[pcb_note_dimension] Invalid arrow_size for "${dimension.pcb_note_dimension_id}": expected positive number, got ${JSON.stringify(arrow_size)}`),[];let direction2=normalize2({x:to3.x-from.x,y:to3.y-from.y});if(Number.isNaN(direction2.x)||Number.isNaN(direction2.y))return[];let perpendicular={x:-direction2.y,y:direction2.x},hasOffsetDirection=offset_direction&&typeof offset_direction.x=="number"&&typeof offset_direction.y=="number",normalizedOffsetDirection=hasOffsetDirection?normalize2({x:offset_direction.x,y:offset_direction.y}):{x:0,y:0},offsetMagnitude=typeof offset_distance=="number"?offset_distance:0,offsetVector={x:normalizedOffsetDirection.x*offsetMagnitude,y:normalizedOffsetDirection.y*offsetMagnitude},applyOffset=point7=>({x:point7.x+offsetVector.x,y:point7.y+offsetVector.y}),fromOffset=applyOffset(from),toOffset=applyOffset(to3),arrowHalfWidth=arrow_size/2,fromBase={x:fromOffset.x+direction2.x*arrow_size,y:fromOffset.y+direction2.y*arrow_size},toBase={x:toOffset.x-direction2.x*arrow_size,y:toOffset.y-direction2.y*arrow_size},fromTriangle=[toScreen(fromOffset),toScreen({x:fromBase.x+perpendicular.x*arrowHalfWidth,y:fromBase.y+perpendicular.y*arrowHalfWidth}),toScreen({x:fromBase.x-perpendicular.x*arrowHalfWidth,y:fromBase.y-perpendicular.y*arrowHalfWidth})],toTriangle=[toScreen(toOffset),toScreen({x:toBase.x+perpendicular.x*arrowHalfWidth,y:toBase.y+perpendicular.y*arrowHalfWidth}),toScreen({x:toBase.x-perpendicular.x*arrowHalfWidth,y:toBase.y-perpendicular.y*arrowHalfWidth})],[lineStartX,lineStartY]=applyToPoint3(transform6,[fromBase.x,fromBase.y]),[lineEndX,lineEndY]=applyToPoint3(transform6,[toBase.x,toBase.y]),strokeWidth=arrow_size/5*Math.abs(transform6.a),lineColor=color||colorMap.board.user_2,extensionDirection=hasOffsetDirection&&(Math.abs(normalizedOffsetDirection.x)>Number.EPSILON||Math.abs(normalizedOffsetDirection.y)>Number.EPSILON)?normalizedOffsetDirection:perpendicular,extensionLength=offsetMagnitude+arrow_size,createExtensionLine=anchor=>{let endPoint={x:anchor.x+extensionDirection.x*extensionLength,y:anchor.y+extensionDirection.y*extensionLength},[startX,startY]=applyToPoint3(transform6,[anchor.x,anchor.y]),[endX,endY]=applyToPoint3(transform6,[endPoint.x,endPoint.y]);return{name:"path",type:"element",value:"",attributes:{d:`M ${startX} ${startY} L ${endX} ${endY}`,stroke:lineColor,fill:"none","stroke-width":strokeWidth.toString(),"stroke-linecap":"round",class:"pcb-note-dimension-extension"},children:[]}},extensionSegments=[createExtensionLine(from),createExtensionLine(to3)],midPoint2={x:(from.x+to3.x)/2+offsetVector.x,y:(from.y+to3.y)/2+offsetVector.y},[screenFromX,screenFromY]=applyToPoint3(transform6,[fromOffset.x,fromOffset.y]),[screenToX,screenToY]=applyToPoint3(transform6,[toOffset.x,toOffset.y]),screenDirection=normalize2({x:screenToX-screenFromX,y:screenToY-screenFromY}),textAngle=Math.atan2(screenDirection.y,screenDirection.x)*180/Math.PI;(textAngle>90||textAngle<-90)&&(textAngle+=180);let finalTextAngle=typeof text_ccw_rotation=="number"&&Number.isFinite(text_ccw_rotation)?textAngle-text_ccw_rotation:textAngle,additionalOffset=0;if(text&&typeof text_ccw_rotation=="number"&&Number.isFinite(text_ccw_rotation)){let textWidth=text.length*font_size*.6,textHeight=font_size,rotationRad=text_ccw_rotation*Math.PI/180,sinRot=Math.abs(Math.sin(rotationRad)),cosRot=Math.abs(Math.cos(rotationRad)),halfWidth=textWidth/2,halfHeight=textHeight/2;additionalOffset=halfWidth*sinRot+halfHeight*cosRot+font_size*.3}let textOffset=arrow_size*1.5+additionalOffset,textPoint={x:midPoint2.x+perpendicular.x*textOffset,y:midPoint2.y+perpendicular.y*textOffset},[textX,textY]=applyToPoint3(transform6,[textPoint.x,textPoint.y]),transformedFontSize=font_size*Math.abs(transform6.a),children=[...extensionSegments,{name:"path",type:"element",value:"",attributes:{d:`M ${lineStartX} ${lineStartY} L ${lineEndX} ${lineEndY}`,stroke:lineColor,fill:"none","stroke-width":strokeWidth.toString(),"stroke-linecap":"round",class:"pcb-note-dimension-line"},children:[]},{name:"path",type:"element",value:"",attributes:{d:`${toPath2(fromTriangle)} Z`,fill:lineColor,class:"pcb-note-dimension-arrow"},children:[]},{name:"path",type:"element",value:"",attributes:{d:`${toPath2(toTriangle)} Z`,fill:lineColor,class:"pcb-note-dimension-arrow"},children:[]}];return text&&children.push({name:"text",type:"element",value:"",attributes:{x:textX.toString(),y:textY.toString(),fill:lineColor,"font-size":transformedFontSize.toString(),"font-family":"Arial, sans-serif","text-anchor":"middle","dominant-baseline":"central",class:"pcb-note-dimension-text",transform:`rotate(${finalTextAngle} ${textX} ${textY})`},children:[{type:"text",name:"",value:text,attributes:{},children:[]}]}),[{name:"g",type:"element",value:"",attributes:{class:"pcb-note-dimension","data-type":"pcb_note_dimension","data-pcb-note-dimension-id":dimension.pcb_note_dimension_id,"data-pcb-layer":"overlay"},children}];function toScreen(point7){let[x4,y4]=applyToPoint3(transform6,[point7.x,point7.y]);return{x:x4,y:y4}}}function createSvgObjectsFromPcbNoteText(note,ctx){let{transform:transform6}=ctx,{anchor_position,text,font_size=1,anchor_alignment="center",color}=note;if(!anchor_position||typeof anchor_position.x!="number"||typeof anchor_position.y!="number")return debugPcb(`[pcb_note_text] Invalid anchor_position for "${note.pcb_note_text_id}": expected {x: number, y: number}, got ${JSON.stringify(anchor_position)}`),[];if(typeof text!="string"||text.length===0)return debugPcb(`[pcb_note_text] Invalid text for "${note.pcb_note_text_id}": expected non-empty string, got ${JSON.stringify(text)}`),[];let[x4,y4]=applyToPoint3(transform6,[anchor_position.x,anchor_position.y]),transformedFontSize=font_size*Math.abs(transform6.a),textAnchor="middle",dominantBaseline="central";switch(anchor_alignment){case"top_left":textAnchor="start",dominantBaseline="text-before-edge";break;case"top_right":textAnchor="end",dominantBaseline="text-before-edge";break;case"bottom_left":textAnchor="start",dominantBaseline="text-after-edge";break;case"bottom_right":textAnchor="end",dominantBaseline="text-after-edge";break;default:textAnchor="middle",dominantBaseline="central";break}let lines=text.split(`
|
|
226
226
|
`),children=lines.length===1?[{type:"text",name:"",value:text,attributes:{},children:[]}]:lines.map((line2,index)=>({type:"element",name:"tspan",value:"",attributes:{x:x4.toString(),...index>0?{dy:"1em"}:{}},children:[{type:"text",name:"",value:line2,attributes:{},children:[]}]}));return[{name:"text",type:"element",value:"",attributes:{x:x4.toString(),y:y4.toString(),fill:color??DEFAULT_OVERLAY_COLOR,"font-family":"Arial, sans-serif","font-size":transformedFontSize.toString(),"text-anchor":textAnchor,"dominant-baseline":dominantBaseline,class:"pcb-note-text","data-type":"pcb_note_text","data-pcb-note-text-id":note.pcb_note_text_id,"data-pcb-layer":"overlay"},children}]}function createSvgObjectsFromPcbNoteRect(noteRect,ctx){let{transform:transform6}=ctx,{center:center2,width,height,stroke_width,is_filled,has_stroke,is_stroke_dashed,color,corner_radius}=noteRect;if(!center2||typeof center2.x!="number"||typeof center2.y!="number"||typeof width!="number"||typeof height!="number")return debugPcb(`[pcb_note_rect] Invalid data for "${noteRect.pcb_note_rect_id}": expected center {x: number, y: number}, width: number, height: number, got center=${JSON.stringify(center2)}, width=${JSON.stringify(width)}, height=${JSON.stringify(height)}`),[];let halfWidth=width/2,halfHeight=height/2,[topLeftX,topLeftY]=applyToPoint3(transform6,[center2.x-halfWidth,center2.y+halfHeight]),[bottomRightX,bottomRightY]=applyToPoint3(transform6,[center2.x+halfWidth,center2.y-halfHeight]),rectX=Math.min(topLeftX,bottomRightX),rectY=Math.min(topLeftY,bottomRightY),rectWidth=Math.abs(bottomRightX-topLeftX),rectHeight=Math.abs(bottomRightY-topLeftY),transformedStrokeWidth=(typeof stroke_width=="number"?stroke_width:0)*Math.abs(transform6.a),baseCornerRadius=typeof corner_radius=="number"&&corner_radius>0?corner_radius:0,transformedCornerRadiusX=baseCornerRadius*Math.abs(transform6.a),transformedCornerRadiusY=baseCornerRadius*Math.abs(transform6.d),overlayColor=color??DEFAULT_OVERLAY_COLOR2,attributes2={x:rectX.toString(),y:rectY.toString(),width:rectWidth.toString(),height:rectHeight.toString(),class:"pcb-note-rect","data-type":"pcb_note_rect","data-pcb-note-rect-id":noteRect.pcb_note_rect_id,"data-pcb-layer":"overlay"};if(transformedCornerRadiusX>0&&(attributes2.rx=transformedCornerRadiusX.toString()),transformedCornerRadiusY>0&&(attributes2.ry=transformedCornerRadiusY.toString()),is_filled?attributes2.fill=color??DEFAULT_FILL_COLOR:attributes2.fill="none",has_stroke??transformedStrokeWidth>0){if(attributes2.stroke=overlayColor,attributes2["stroke-width"]=transformedStrokeWidth.toString(),is_stroke_dashed){let dash=.2*Math.abs(transform6.a),gap=.1*Math.abs(transform6.a);attributes2["stroke-dasharray"]=`${dash} ${gap}`}}else attributes2.stroke="none";return[{name:"rect",type:"element",value:"",attributes:attributes2,children:[]}]}function createSvgObjectsFromPcbNotePath(notePath,ctx){let{transform:transform6}=ctx;if(!Array.isArray(notePath.route)||notePath.route.length===0)return debugPcb(`[pcb_note_path] Invalid route for "${notePath.pcb_note_path_id}": expected non-empty array of points, got ${JSON.stringify(notePath.route)}`),[];for(let point7 of notePath.route)if(typeof point7.x!="number"||typeof point7.y!="number")return debugPcb(`[pcb_note_path] Invalid point in route for "${notePath.pcb_note_path_id}": expected {x: number, y: number}, got ${JSON.stringify(point7)}`),[];let pathD=notePath.route.map((point7,index)=>{let[x4,y4]=applyToPoint3(transform6,[point7.x,point7.y]);return index===0?`M ${x4} ${y4}`:`L ${x4} ${y4}`}).join(" "),strokeWidth=notePath.stroke_width*Math.abs(transform6.a);return[{name:"path",type:"element",value:"",attributes:{d:pathD,stroke:notePath.color??DEFAULT_OVERLAY_COLOR3,fill:"none","stroke-width":strokeWidth.toString(),class:"pcb-note-path","data-type":"pcb_note_path","data-pcb-note-path-id":notePath.pcb_note_path_id,"data-pcb-layer":"overlay"},children:[]}]}function createSvgObjectsFromPcbNoteLine(noteLine,ctx){let{transform:transform6}=ctx,{x1:x12,y1:y12,x2:x22,y2:y22,stroke_width,color,is_dashed}=noteLine;if(typeof x12!="number"||typeof y12!="number"||typeof x22!="number"||typeof y22!="number")return debugPcb(`[pcb_note_line] Invalid coordinates for "${noteLine.pcb_note_line_id}": expected x1, y1, x2, y2 as numbers, got x1=${JSON.stringify(x12)}, y1=${JSON.stringify(y12)}, x2=${JSON.stringify(x22)}, y2=${JSON.stringify(y22)}`),[];let[startX,startY]=applyToPoint3(transform6,[x12,y12]),[endX,endY]=applyToPoint3(transform6,[x22,y22]),transformedStrokeWidth=(typeof stroke_width=="number"?stroke_width:0)*Math.abs(transform6.a),attributes2={x1:startX.toString(),y1:startY.toString(),x2:endX.toString(),y2:endY.toString(),stroke:color??DEFAULT_OVERLAY_COLOR4,"stroke-width":transformedStrokeWidth.toString(),"stroke-linecap":"round",class:"pcb-note-line","data-type":"pcb_note_line","data-pcb-note-line-id":noteLine.pcb_note_line_id,"data-pcb-layer":"overlay"};if(is_dashed){let dash=.2*Math.abs(transform6.a),gap=.1*Math.abs(transform6.a);attributes2["stroke-dasharray"]=`${dash} ${gap}`}return[{name:"line",type:"element",value:"",attributes:attributes2,children:[]}]}function createSvgObjectsFromPcbPlatedHole(hole,ctx){let{transform:transform6,colorMap:colorMap2,showSolderMask}=ctx,[x4,y4]=applyToPoint3(transform6,[hole.x,hole.y]),layer=Array.isArray(hole.layers)&&hole.layers[0]||hole.layer||"top",maskLayer=layer,isCoveredWithSolderMask=!!hole.is_covered_with_solder_mask,soldermaskMargin=(hole.soldermask_margin??0)*Math.abs(transform6.a),shouldShowSolderMask=showSolderMask&&isCoveredWithSolderMask&&soldermaskMargin!==0,solderMaskColor=colorMap2.soldermaskWithCopperUnderneath.top;if(hole.shape==="pill"){let scaledOuterWidth=hole.outer_width*Math.abs(transform6.a),scaledOuterHeight=hole.outer_height*Math.abs(transform6.a),scaledHoleWidth=hole.hole_width*Math.abs(transform6.a),scaledHoleHeight=hole.hole_height*Math.abs(transform6.a),rotation5=hole.ccw_rotation||0,outerTransform=rotation5?`translate(${x4} ${y4}) rotate(${-rotation5})`:`translate(${x4} ${y4})`,innerTransform=rotation5?`translate(${x4} ${y4}) rotate(${-rotation5})`:`translate(${x4} ${y4})`,createPillPath=(width,height)=>{if(width>height){let radius=height/2,straightLength=width-2*radius;return`M${-width/2+radius},${-radius} h${straightLength} a${radius},${radius} 0 0 1 0,${height} h${-straightLength} a${radius},${radius} 0 0 1 0,${-height} z`}else if(height>width){let radius=width/2,straightLength=height-2*radius;return`M${radius},${-height/2+radius} v${straightLength} a${radius},${radius} 0 0 1 ${-width},0 v${-straightLength} a${radius},${radius} 0 0 1 ${width},0 z`}else{let radius=width/2;return`M${-radius},0 a${radius},${radius} 0 0 1 ${width},0 a${radius},${radius} 0 0 1 ${-width},0 z`}},children=[{name:"path",type:"element",attributes:{class:"pcb-hole-outer",fill:colorMap2.copper.top,d:createPillPath(scaledOuterWidth,scaledOuterHeight),transform:outerTransform,"data-type":"pcb_plated_hole","data-pcb-layer":layer},value:"",children:[]},{name:"path",type:"element",attributes:{class:"pcb-hole-inner",fill:colorMap2.drill,d:createPillPath(scaledHoleWidth,scaledHoleHeight),transform:innerTransform,"data-type":"pcb_plated_hole_drill","data-pcb-layer":"drill"},value:"",children:[]}];if(shouldShowSolderMask){let maskWidth=scaledOuterWidth+2*soldermaskMargin,maskHeight=scaledOuterHeight+2*soldermaskMargin;soldermaskMargin<0?children=[{name:"path",type:"element",attributes:{class:"pcb-hole-outer-covered",fill:solderMaskColor,d:createPillPath(scaledOuterWidth,scaledOuterHeight),transform:outerTransform,"data-type":"pcb_plated_hole","data-pcb-layer":layer},value:"",children:[]},{name:"path",type:"element",attributes:{class:"pcb-hole-outer-exposed",fill:colorMap2.copper.top,d:createPillPath(maskWidth,maskHeight),transform:outerTransform,"data-type":"pcb_soldermask","data-pcb-layer":maskLayer},value:"",children:[]},children[1]]:children.unshift({name:"path",type:"element",attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,d:createPillPath(maskWidth,maskHeight),transform:outerTransform,"data-type":"pcb_soldermask_opening","data-pcb-layer":maskLayer},value:"",children:[]})}return[{name:"g",type:"element",attributes:{"data-type":"pcb_plated_hole","data-pcb-layer":"through"},children,value:""}]}if(hole.shape==="oval"){let scaledOuterWidth=hole.outer_width*Math.abs(transform6.a),scaledOuterHeight=hole.outer_height*Math.abs(transform6.a),scaledHoleWidth=hole.hole_width*Math.abs(transform6.a),scaledHoleHeight=hole.hole_height*Math.abs(transform6.a),rotation5=hole.ccw_rotation||0,transformStr=rotation5?`translate(${x4} ${y4}) rotate(${-rotation5})`:`translate(${x4} ${y4})`,children=[{name:"ellipse",type:"element",attributes:{class:"pcb-hole-outer",fill:colorMap2.copper.top,cx:"0",cy:"0",rx:(scaledOuterWidth/2).toString(),ry:(scaledOuterHeight/2).toString(),transform:transformStr,"data-type":"pcb_plated_hole","data-pcb-layer":layer},value:"",children:[]},{name:"ellipse",type:"element",attributes:{class:"pcb-hole-inner",fill:colorMap2.drill,cx:"0",cy:"0",rx:(scaledHoleWidth/2).toString(),ry:(scaledHoleHeight/2).toString(),transform:transformStr,"data-type":"pcb_plated_hole_drill","data-pcb-layer":"drill"},value:"",children:[]}];return[{name:"g",type:"element",attributes:{"data-type":"pcb_plated_hole","data-pcb-layer":"through"},children,value:""}]}if(hole.shape==="circle"){let scaledOuterWidth=hole.outer_diameter*Math.abs(transform6.a),scaledOuterHeight=hole.outer_diameter*Math.abs(transform6.a),scaledHoleWidth=hole.hole_diameter*Math.abs(transform6.a),scaledHoleHeight=hole.hole_diameter*Math.abs(transform6.a),outerRadius=Math.min(scaledOuterWidth,scaledOuterHeight)/2,innerRadius=Math.min(scaledHoleWidth,scaledHoleHeight)/2,children=[{name:"circle",type:"element",attributes:{class:"pcb-hole-outer",fill:colorMap2.copper.top,cx:x4.toString(),cy:y4.toString(),r:outerRadius.toString(),"data-type":"pcb_plated_hole","data-pcb-layer":layer},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"pcb-hole-inner",fill:colorMap2.drill,cx:x4.toString(),cy:y4.toString(),r:innerRadius.toString(),"data-type":"pcb_plated_hole_drill","data-pcb-layer":"drill"},value:"",children:[]}];if(shouldShowSolderMask){let maskRadius=outerRadius+soldermaskMargin;soldermaskMargin<0?children=[{name:"circle",type:"element",attributes:{class:"pcb-hole-outer-covered",fill:solderMaskColor,cx:x4.toString(),cy:y4.toString(),r:outerRadius.toString(),"data-type":"pcb_plated_hole","data-pcb-layer":layer},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"pcb-hole-outer-exposed",fill:colorMap2.copper.top,cx:x4.toString(),cy:y4.toString(),r:maskRadius.toString(),"data-type":"pcb_soldermask","data-pcb-layer":maskLayer},value:"",children:[]},children[1]]:children.unshift({name:"circle",type:"element",attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,cx:x4.toString(),cy:y4.toString(),r:maskRadius.toString(),"data-type":"pcb_soldermask_opening","data-pcb-layer":maskLayer},value:"",children:[]})}return[{name:"g",type:"element",attributes:{"data-type":"pcb_plated_hole","data-pcb-layer":"through"},children,value:""}]}if(hole.shape==="circular_hole_with_rect_pad"){let h6=hole,scaledHoleDiameter=hole.hole_diameter*Math.abs(transform6.a),scaledRectPadWidth=hole.rect_pad_width*Math.abs(transform6.a),scaledRectPadHeight=hole.rect_pad_height*Math.abs(transform6.a),scaledRectBorderRadius=(hole.rect_border_radius??0)*Math.abs(transform6.a),rectCcwRotation=hole.rect_ccw_rotation??0,rotation5=h6.rect_ccw_rotation??0,rectTransform=rotation5?`translate(${x4} ${y4}) rotate(${-rotation5})`:void 0,xStr=rotation5?(-scaledRectPadWidth/2).toString():(x4-scaledRectPadWidth/2).toString(),yStr=rotation5?(-scaledRectPadHeight/2).toString():(y4-scaledRectPadHeight/2).toString(),holeRadius=scaledHoleDiameter/2,[holeCx,holeCy]=applyToPoint3(transform6,[h6.x+(h6.hole_offset_x??0),h6.y+(h6.hole_offset_y??0)]),children=[{name:"rect",type:"element",attributes:{class:"pcb-hole-outer-pad",fill:colorMap2.copper.top,...rectCcwRotation?{x:(-scaledRectPadWidth/2).toString(),y:(-scaledRectPadHeight/2).toString(),transform:`translate(${x4} ${y4}) rotate(${-rectCcwRotation})`}:{x:(x4-scaledRectPadWidth/2).toString(),y:(y4-scaledRectPadHeight/2).toString()},width:scaledRectPadWidth.toString(),height:scaledRectPadHeight.toString(),...rectTransform?{transform:rectTransform}:{},...scaledRectBorderRadius?{rx:scaledRectBorderRadius.toString(),ry:scaledRectBorderRadius.toString()}:{},"data-type":"pcb_plated_hole","data-pcb-layer":layer},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"pcb-hole-inner",fill:colorMap2.drill,cx:holeCx.toString(),cy:holeCy.toString(),r:holeRadius.toString(),"data-type":"pcb_plated_hole_drill","data-pcb-layer":"drill"},value:"",children:[]}];if(shouldShowSolderMask){let maskWidth=scaledRectPadWidth+2*soldermaskMargin,maskHeight=scaledRectPadHeight+2*soldermaskMargin,maskBorderRadius=scaledRectBorderRadius+soldermaskMargin;soldermaskMargin<0?children=[{name:"rect",type:"element",attributes:{class:"pcb-hole-outer-covered",fill:solderMaskColor,...rectCcwRotation?{x:(-scaledRectPadWidth/2).toString(),y:(-scaledRectPadHeight/2).toString(),transform:`translate(${x4} ${y4}) rotate(${-rectCcwRotation})`}:{x:(x4-scaledRectPadWidth/2).toString(),y:(y4-scaledRectPadHeight/2).toString()},width:scaledRectPadWidth.toString(),height:scaledRectPadHeight.toString(),...rectTransform?{transform:rectTransform}:{},...scaledRectBorderRadius?{rx:scaledRectBorderRadius.toString(),ry:scaledRectBorderRadius.toString()}:{},"data-type":"pcb_plated_hole","data-pcb-layer":layer},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"pcb-hole-outer-exposed",fill:colorMap2.copper.top,...rectCcwRotation?{x:(-maskWidth/2).toString(),y:(-maskHeight/2).toString(),transform:`translate(${x4} ${y4}) rotate(${-rectCcwRotation})`}:{x:(x4-maskWidth/2).toString(),y:(y4-maskHeight/2).toString()},width:maskWidth.toString(),height:maskHeight.toString(),...rectTransform?{transform:rectTransform}:{},...maskBorderRadius>0?{rx:maskBorderRadius.toString(),ry:maskBorderRadius.toString()}:{},"data-type":"pcb_soldermask","data-pcb-layer":maskLayer},value:"",children:[]},children[1]]:children.unshift({name:"rect",type:"element",attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,...rectCcwRotation?{x:(-maskWidth/2).toString(),y:(-maskHeight/2).toString(),transform:`translate(${x4} ${y4}) rotate(${-rectCcwRotation})`}:{x:(x4-maskWidth/2).toString(),y:(y4-maskHeight/2).toString()},width:maskWidth.toString(),height:maskHeight.toString(),...rectTransform?{transform:rectTransform}:{},...scaledRectBorderRadius?{rx:maskBorderRadius.toString(),ry:maskBorderRadius.toString()}:{},"data-type":"pcb_soldermask_opening","data-pcb-layer":maskLayer},value:"",children:[]})}return[{name:"g",type:"element",attributes:{"data-type":"pcb_plated_hole","data-pcb-layer":"through"},children,value:""}]}if(hole.shape==="pill_hole_with_rect_pad"){let pillHole=hole,scaledRectPadWidth=pillHole.rect_pad_width*Math.abs(transform6.a),scaledRectPadHeight=pillHole.rect_pad_height*Math.abs(transform6.a),scaledRectBorderRadius=(pillHole.rect_border_radius??0)*Math.abs(transform6.a),scaledHoleHeight=pillHole.hole_height*Math.abs(transform6.a),scaledHoleWidth=pillHole.hole_width*Math.abs(transform6.a),pillHoleWithOffsets=pillHole,holeOffsetX=pillHoleWithOffsets.hole_offset_x??0,holeOffsetY=pillHoleWithOffsets.hole_offset_y??0,[holeCenterX,holeCenterY]=applyToPoint3(transform6,[pillHole.x+holeOffsetX,pillHole.y+holeOffsetY]),holeRadius=Math.min(scaledHoleHeight,scaledHoleWidth)/2,children=[{name:"rect",type:"element",attributes:{class:"pcb-hole-outer-pad",fill:colorMap2.copper.top,x:(x4-scaledRectPadWidth/2).toString(),y:(y4-scaledRectPadHeight/2).toString(),width:scaledRectPadWidth.toString(),height:scaledRectPadHeight.toString(),...scaledRectBorderRadius?{rx:scaledRectBorderRadius.toString(),ry:scaledRectBorderRadius.toString()}:{},"data-type":"pcb_plated_hole","data-pcb-layer":layer},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"pcb-hole-inner",fill:colorMap2.drill,x:(holeCenterX-scaledHoleWidth/2).toString(),y:(holeCenterY-scaledHoleHeight/2).toString(),width:scaledHoleWidth.toString(),height:scaledHoleHeight.toString(),rx:holeRadius.toString(),ry:holeRadius.toString(),"data-type":"pcb_plated_hole_drill","data-pcb-layer":"drill"},value:"",children:[]}];if(shouldShowSolderMask){let maskWidth=scaledRectPadWidth+2*soldermaskMargin,maskHeight=scaledRectPadHeight+2*soldermaskMargin,maskBorderRadius=scaledRectBorderRadius+soldermaskMargin;soldermaskMargin<0?children=[{name:"rect",type:"element",attributes:{class:"pcb-hole-outer-covered",fill:solderMaskColor,x:(x4-scaledRectPadWidth/2).toString(),y:(y4-scaledRectPadHeight/2).toString(),width:scaledRectPadWidth.toString(),height:scaledRectPadHeight.toString(),...scaledRectBorderRadius?{rx:scaledRectBorderRadius.toString(),ry:scaledRectBorderRadius.toString()}:{},"data-type":"pcb_plated_hole","data-pcb-layer":layer},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"pcb-hole-outer-exposed",fill:colorMap2.copper.top,x:(x4-maskWidth/2).toString(),y:(y4-maskHeight/2).toString(),width:maskWidth.toString(),height:maskHeight.toString(),...maskBorderRadius>0?{rx:maskBorderRadius.toString(),ry:maskBorderRadius.toString()}:{},"data-type":"pcb_soldermask","data-pcb-layer":maskLayer},value:"",children:[]},children[1]]:children.unshift({name:"rect",type:"element",attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,x:(x4-maskWidth/2).toString(),y:(y4-maskHeight/2).toString(),width:maskWidth.toString(),height:maskHeight.toString(),...scaledRectBorderRadius?{rx:maskBorderRadius.toString(),ry:maskBorderRadius.toString()}:{},"data-type":"pcb_soldermask_opening","data-pcb-layer":maskLayer},value:"",children:[]})}return[{name:"g",type:"element",attributes:{"data-type":"pcb_plated_hole","data-pcb-layer":"through"},children,value:""}]}if(hole.shape==="rotated_pill_hole_with_rect_pad"){let rotatedHole=hole,scaledRectPadWidth=rotatedHole.rect_pad_width*Math.abs(transform6.a),scaledRectPadHeight=rotatedHole.rect_pad_height*Math.abs(transform6.a),scaledRectBorderRadius=(rotatedHole.rect_border_radius??0)*Math.abs(transform6.a),scaledHoleHeight=rotatedHole.hole_height*Math.abs(transform6.a),scaledHoleWidth=rotatedHole.hole_width*Math.abs(transform6.a),rotatedHoleWithOffsets=rotatedHole,holeOffsetX=rotatedHoleWithOffsets.hole_offset_x??0,holeOffsetY=rotatedHoleWithOffsets.hole_offset_y??0,[holeCenterX,holeCenterY]=applyToPoint3(transform6,[rotatedHole.x+holeOffsetX,rotatedHole.y+holeOffsetY]),holeRadius=Math.min(scaledHoleHeight,scaledHoleWidth)/2,children=[{name:"rect",type:"element",attributes:{class:"pcb-hole-outer-pad",fill:colorMap2.copper.top,x:(-scaledRectPadWidth/2).toString(),y:(-scaledRectPadHeight/2).toString(),width:scaledRectPadWidth.toString(),height:scaledRectPadHeight.toString(),transform:`translate(${x4} ${y4}) rotate(${-rotatedHole.rect_ccw_rotation})`,...scaledRectBorderRadius?{rx:scaledRectBorderRadius.toString(),ry:scaledRectBorderRadius.toString()}:{},"data-type":"pcb_plated_hole","data-pcb-layer":layer},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"pcb-hole-inner",fill:colorMap2.drill,x:(-scaledHoleWidth/2).toString(),y:(-scaledHoleHeight/2).toString(),width:scaledHoleWidth.toString(),height:scaledHoleHeight.toString(),rx:holeRadius.toString(),ry:holeRadius.toString(),transform:`translate(${holeCenterX} ${holeCenterY}) rotate(${-rotatedHole.hole_ccw_rotation})`,"data-type":"pcb_plated_hole_drill","data-pcb-layer":"drill"},value:"",children:[]}];if(shouldShowSolderMask){let maskWidth=scaledRectPadWidth+2*soldermaskMargin,maskHeight=scaledRectPadHeight+2*soldermaskMargin,maskBorderRadius=scaledRectBorderRadius+soldermaskMargin;soldermaskMargin<0?children=[{name:"rect",type:"element",attributes:{class:"pcb-hole-outer-covered",fill:solderMaskColor,x:(-scaledRectPadWidth/2).toString(),y:(-scaledRectPadHeight/2).toString(),width:scaledRectPadWidth.toString(),height:scaledRectPadHeight.toString(),transform:`translate(${x4} ${y4}) rotate(${-rotatedHole.rect_ccw_rotation})`,...scaledRectBorderRadius?{rx:scaledRectBorderRadius.toString(),ry:scaledRectBorderRadius.toString()}:{},"data-type":"pcb_plated_hole","data-pcb-layer":layer},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"pcb-hole-outer-exposed",fill:colorMap2.copper.top,x:(-maskWidth/2).toString(),y:(-maskHeight/2).toString(),width:maskWidth.toString(),height:maskHeight.toString(),transform:`translate(${x4} ${y4}) rotate(${-rotatedHole.rect_ccw_rotation})`,...maskBorderRadius>0?{rx:maskBorderRadius.toString(),ry:maskBorderRadius.toString()}:{},"data-type":"pcb_soldermask","data-pcb-layer":maskLayer},value:"",children:[]},children[1]]:children.push({name:"rect",type:"element",attributes:{class:"pcb-solder-mask",fill:solderMaskColor,x:(-maskWidth/2).toString(),y:(-maskHeight/2).toString(),width:maskWidth.toString(),height:maskHeight.toString(),transform:`translate(${x4} ${y4}) rotate(${-rotatedHole.rect_ccw_rotation})`,...scaledRectBorderRadius?{rx:maskBorderRadius.toString(),ry:maskBorderRadius.toString()}:{},"data-type":"pcb_soldermask","data-pcb-layer":maskLayer},value:"",children:[]})}return[{name:"g",type:"element",attributes:{"data-type":"pcb_plated_hole","data-pcb-layer":"through"},children,value:""}]}if(hole.shape==="hole_with_polygon_pad"){let polygonHole=hole,padOutline=polygonHole.pad_outline||[],holeX=polygonHole.x??0,holeY=polygonHole.y??0,padPointsString=padOutline.map(point7=>applyToPoint3(transform6,[holeX+point7.x,holeY+point7.y])).map(p4=>p4.join(",")).join(" "),[holeCenterX,holeCenterY]=applyToPoint3(transform6,[holeX+polygonHole.hole_offset_x,holeY+polygonHole.hole_offset_y]),createHoleSvgObject=()=>{if(polygonHole.hole_shape==="circle"){let radius=(polygonHole.hole_diameter??0)*Math.abs(transform6.a)/2;return{name:"circle",type:"element",attributes:{class:"pcb-hole-inner",fill:colorMap2.drill,cx:holeCenterX.toString(),cy:holeCenterY.toString(),r:radius.toString(),"data-type":"pcb_plated_hole_drill","data-pcb-layer":"drill"},value:"",children:[]}}if(polygonHole.hole_shape==="oval"){let scaledWidth=(polygonHole.hole_width??0)*Math.abs(transform6.a),scaledHeight=(polygonHole.hole_height??0)*Math.abs(transform6.a),rx3=scaledWidth/2,ry3=scaledHeight/2;return{name:"ellipse",type:"element",attributes:{class:"pcb-hole-inner",fill:colorMap2.drill,cx:holeCenterX.toString(),cy:holeCenterY.toString(),rx:rx3.toString(),ry:ry3.toString(),"data-type":"pcb_plated_hole_drill","data-pcb-layer":"drill"},value:"",children:[]}}if(polygonHole.hole_shape==="pill"||polygonHole.hole_shape==="rotated_pill"){let scaledWidth=(polygonHole.hole_width??0)*Math.abs(transform6.a),scaledHeight=(polygonHole.hole_height??0)*Math.abs(transform6.a),isHorizontal3=scaledWidth>scaledHeight,radius=Math.min(scaledWidth,scaledHeight)/2,straightLength=Math.abs(isHorizontal3?scaledWidth-scaledHeight:scaledHeight-scaledWidth),pathD=isHorizontal3?`M${-straightLength/2},${-radius} h${straightLength} a${radius},${radius} 0 0 1 0,${scaledHeight} h-${straightLength} a${radius},${radius} 0 0 1 0,-${scaledHeight} z`:`M${-radius},${-straightLength/2} v${straightLength} a${radius},${radius} 0 0 0 ${scaledWidth},0 v-${straightLength} a${radius},${radius} 0 0 0 -${scaledWidth},0 z`;return{name:"path",type:"element",attributes:{class:"pcb-hole-inner",fill:colorMap2.drill,d:pathD,transform:`translate(${holeCenterX} ${holeCenterY})`,"data-type":"pcb_plated_hole_drill","data-pcb-layer":"drill"},value:"",children:[]}}return{name:"g",type:"element",attributes:{},value:"",children:[]}};return[{name:"g",type:"element",attributes:{"data-type":"pcb_plated_hole","data-pcb-layer":"through"},children:[{name:"polygon",type:"element",attributes:{class:"pcb-hole-outer-pad",fill:colorMap2.copper.top,points:padPointsString,"data-type":"pcb_plated_hole","data-pcb-layer":layer},value:"",children:[]},createHoleSvgObject()],value:""}]}return[]}function createSvgObjectsFromPcbSilkscreenPath(silkscreenPath,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2}=ctx;if(!silkscreenPath.route||!Array.isArray(silkscreenPath.route))return[];let path=silkscreenPath.route.map((point7,index)=>{let[x4,y4]=applyToPoint3(transform6,[point7.x,point7.y]);return index===0?`M ${x4} ${y4}`:`L ${x4} ${y4}`}).join(" "),firstPoint=silkscreenPath.route[0],lastPoint=silkscreenPath.route[silkscreenPath.route.length-1];firstPoint&&lastPoint&&firstPoint.x===lastPoint.x&&firstPoint.y===lastPoint.y&&(path+=" Z");let layer=silkscreenPath.layer||"top";if(layerFilter&&layer!==layerFilter)return[];let color=layer==="bottom"?colorMap2.silkscreen.bottom:colorMap2.silkscreen.top;return[{name:"path",type:"element",attributes:{class:`pcb-silkscreen pcb-silkscreen-${layer}`,d:path,fill:"none",stroke:color,"stroke-width":(silkscreenPath.stroke_width*Math.abs(transform6.a)).toString(),"stroke-linecap":"round","stroke-linejoin":"round","data-pcb-component-id":silkscreenPath.pcb_component_id,"data-pcb-silkscreen-path-id":silkscreenPath.pcb_silkscreen_path_id,"data-type":"pcb_silkscreen_path","data-pcb-layer":layer},value:"",children:[]}]}function createPcbAlphabetTextGeometry(params){let{text,anchorAlignment,fontSize,charAdvance,spaceAdvance,trailingSpacing,lineHeight,mapSegment}=params,textLines=text.split(`
|
|
227
|
-
`),totalHeight=textLines.length*lineHeight,lineWidths=textLines.map(line2=>getLineWidth(line2,charAdvance,spaceAdvance,trailingSpacing)),baseSegments=[],y4=-totalHeight/2;for(let lineIndex=0;lineIndex<textLines.length;lineIndex++){let line2=textLines[lineIndex]??"",x4=-(lineWidths[lineIndex]??0)/2;for(let char of line2){if(char===" "){x4+=spaceAdvance;continue}let charLines=lineAlphabet[char];if(charLines)for(let segment2 of charLines)baseSegments.push(mapSegment(segment2,x4,y4,fontSize));x4+=charAdvance}y4+=lineHeight}let baseBounds=getSegmentBounds(baseSegments);if(!baseBounds)return{pathData:"",bounds:null};let anchorOffset=
|
|
228
|
-
`),children=lines.length===1?[{type:"text",value:text,name:"",attributes:{},children:[]}]:lines.map((line2,idx)=>({type:"element",name:"tspan",value:"",attributes:{x:"0",...idx>0?{dy:transformedFontSize.toString()}:{}},children:[{type:"text",value:line2,name:"",attributes:{},children:[]}]}));return[{name:"text",type:"element",attributes:{x:"0",y:"0",dx:"0",dy:"0",fill:silkscreenColor,"font-family":"Arial, sans-serif","font-size":transformedFontSize.toString(),"text-anchor":textAnchor,"dominant-baseline":dominantBaseline,transform:toString2(textTransform),class:`pcb-silkscreen-text pcb-silkscreen-${layer}`,"data-pcb-silkscreen-text-id":pcbSilkscreenText.pcb_silkscreen_text_id,stroke:"none","data-type":"pcb_silkscreen_text","data-pcb-layer":layer},children,value:""}]}function createSvgObjectsFromPcbSilkscreenRect(pcbSilkscreenRect,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2}=ctx,{center:center2,width,height,layer="top",pcb_silkscreen_rect_id,stroke_width,is_filled,has_stroke,is_stroke_dashed,corner_radius,ccw_rotation=0}=pcbSilkscreenRect;if(layerFilter&&layer!==layerFilter)return[];if(!center2||typeof center2.x!="number"||typeof center2.y!="number"||typeof width!="number"||typeof height!="number")return debugPcb(`[pcb_silkscreen_rect] Invalid data for "${pcb_silkscreen_rect_id}": expected center {x: number, y: number}, width: number, height: number, got center=${JSON.stringify(center2)}, width=${JSON.stringify(width)}, height=${JSON.stringify(height)}`),[];let[transformedX,transformedY]=applyToPoint3(transform6,[center2.x,center2.y]),baseCornerRadius=typeof corner_radius=="number"&&corner_radius>0?corner_radius:0,transformedCornerRadiusX=baseCornerRadius*Math.abs(transform6.a),transformedCornerRadiusY=baseCornerRadius*Math.abs(transform6.d),transformedWidth=width*Math.abs(transform6.a),transformedHeight=height*Math.abs(transform6.d),transformedStrokeWidth=stroke_width*Math.abs(transform6.a),color=layer==="bottom"?colorMap2.silkscreen.bottom:colorMap2.silkscreen.top,attributes2={x:(-transformedWidth/2).toString(),y:(-transformedHeight/2).toString(),width:transformedWidth.toString(),height:transformedHeight.toString(),class:`pcb-silkscreen-rect pcb-silkscreen-${layer}`,"data-pcb-silkscreen-rect-id":pcb_silkscreen_rect_id,"data-type":"pcb_silkscreen_rect","data-pcb-layer":layer};typeof ccw_rotation=="number"&&ccw_rotation!==0?attributes2.transform=`translate(${transformedX} ${transformedY}) rotate(${-ccw_rotation})`:(attributes2.x=(transformedX-transformedWidth/2).toString(),attributes2.y=(transformedY-transformedHeight/2).toString()),transformedCornerRadiusX>0&&(attributes2.rx=transformedCornerRadiusX.toString()),transformedCornerRadiusY>0&&(attributes2.ry=transformedCornerRadiusY.toString()),attributes2.fill=is_filled?color:"none";let actualHasStroke;if(has_stroke===void 0?actualHasStroke=transformedStrokeWidth>0:actualHasStroke=has_stroke,actualHasStroke){if(attributes2.stroke=color,attributes2["stroke-width"]=transformedStrokeWidth.toString(),is_stroke_dashed){let dashLength=.1*Math.abs(transform6.a),gapLength=.05*Math.abs(transform6.a);attributes2["stroke-dasharray"]=`${dashLength} ${gapLength}`}}else attributes2.stroke="none";return[{name:"rect",type:"element",attributes:attributes2,value:"",children:[]}]}function layerNameToColor(layerName,colorMap2=DEFAULT_PCB_COLOR_MAP){return colorMap2.copper[layerName]??"white"}function solderPasteLayerNameToColor(layerName){return SOLDER_PASTE_LAYER_NAME_TO_COLOR[layerName]??"rgb(105, 105, 105)"}function createSvgObjectsFromPcbCopperText(pcbCopperText,ctx){let{transform:transform6,layer:filterLayer,colorMap:colorMap2}=ctx,{anchor_position,text,font_size="0.2mm",layer,ccw_rotation=0,anchor_alignment="center",is_knockout=!1,knockout_padding,is_mirrored=!1}=pcbCopperText,layerName=layer??"top";if(filterLayer&&filterLayer!==layerName)return[];if(!anchor_position)return[];if(!text)return[];let[ax3,ay3]=applyToPoint3(transform6,[anchor_position.x,anchor_position.y]),fontSizeNum=distance.parse(font_size)??.2,scaleFactor=Math.abs(transform6.a),copperColor=layerNameToColor(layerName,colorMap2),applyMirror=layerName==="bottom"?!0:is_mirrored===!0;if(is_knockout){let scaledFontSize2=fontSizeNum*FONT_SCALE,geometry2=createPcbAlphabetTextGeometry({text,anchorAlignment:anchor_alignment,fontSize:scaledFontSize2,charAdvance:(CHAR_WIDTH+CHAR_SPACING)*scaledFontSize2,spaceAdvance:(CHAR_WIDTH+CHAR_SPACING)*scaledFontSize2*.6,trailingSpacing:CHAR_SPACING*scaledFontSize2,lineHeight:scaledFontSize2*LINE_HEIGHT,mapSegment:(segment2,offsetX,offsetY,fontSize)=>({x1:offsetX+segment2.x1*fontSize,y1:offsetY+(1-segment2.y1)*fontSize,x2:offsetX+segment2.x2*fontSize,y2:offsetY+(1-segment2.y2)*fontSize})});if(!geometry2.bounds||!geometry2.pathData)return[];let padLeft=knockout_padding?.left??scaledFontSize2*.5,padRight=knockout_padding?.right??scaledFontSize2*.5,padTop=knockout_padding?.top??scaledFontSize2*.3,padBottom=knockout_padding?.bottom??scaledFontSize2*.3,rectX=geometry2.bounds.minX-padLeft,rectY=geometry2.bounds.minY-padTop,rectW=geometry2.bounds.maxX-geometry2.bounds.minX+padLeft+padRight,rectH=geometry2.bounds.maxY-geometry2.bounds.minY+padTop+padBottom,strokeWidth2=scaledFontSize2*.15,knockoutTransform=toString2(compose3(translate3(ax3,ay3),rotate3(-ccw_rotation*Math.PI/180),...applyMirror?[scale3(-1,1)]:[],scale3(scaleFactor,scaleFactor))),maskId=`knockout-mask-${pcbCopperText.pcb_copper_text_id}-${maskIdCounter++}`;return[{name:"defs",type:"element",value:"",children:[{name:"mask",type:"element",value:"",attributes:{id:maskId},children:[{name:"rect",type:"element",value:"",attributes:{x:rectX.toString(),y:rectY.toString(),width:rectW.toString(),height:rectH.toString(),fill:"white"},children:[]},{name:"path",type:"element",value:"",attributes:{d:geometry2.pathData,fill:"none",stroke:"black","stroke-width":strokeWidth2.toString(),"stroke-linecap":"round","stroke-linejoin":"round"},children:[]}]}],attributes:{}},{name:"rect",type:"element",value:"",children:[],attributes:{x:rectX.toString(),y:rectY.toString(),width:rectW.toString(),height:rectH.toString(),fill:copperColor,mask:`url(#${maskId})`,transform:knockoutTransform,class:`pcb-copper-text-knockout pcb-copper-${layerName}`,"data-type":"pcb_copper_text","data-pcb-copper-text-id":pcbCopperText.pcb_copper_text_id}}]}let scaledFontSize=fontSizeNum*FONT_SCALE,geometry=createPcbAlphabetTextGeometry({text,anchorAlignment:anchor_alignment,fontSize:scaledFontSize,charAdvance:(CHAR_WIDTH+CHAR_SPACING)*scaledFontSize,spaceAdvance:(CHAR_WIDTH+CHAR_SPACING)*scaledFontSize*.6,trailingSpacing:CHAR_SPACING*scaledFontSize,lineHeight:scaledFontSize*LINE_HEIGHT,mapSegment:(segment2,offsetX,offsetY,fontSize)=>({x1:offsetX+segment2.x1*fontSize,y1:offsetY+(1-segment2.y1)*fontSize,x2:offsetX+segment2.x2*fontSize,y2:offsetY+(1-segment2.y2)*fontSize})});if(!geometry.pathData)return[];let textTransform=toString2(compose3(translate3(ax3,ay3),rotate3(-ccw_rotation*Math.PI/180),...applyMirror?[scale3(-1,1)]:[],scale3(scaleFactor,scaleFactor))),strokeWidth=scaledFontSize*.15;return[{name:"path",type:"element",attributes:{d:geometry.pathData,fill:"none",stroke:copperColor,"stroke-width":strokeWidth.toString(),"stroke-linecap":"round","stroke-linejoin":"round",transform:textTransform,class:`pcb-copper-text pcb-copper-${layerName}`,"data-type":"pcb_copper_text","data-pcb-copper-text-id":pcbCopperText.pcb_copper_text_id},children:[],value:""}]}function createSvgObjectsFromPcbSilkscreenCircle(pcbSilkscreenCircle,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2}=ctx,{center:center2,radius,layer="top",pcb_silkscreen_circle_id,stroke_width=1,is_filled}=pcbSilkscreenCircle;if(layerFilter&&layer!==layerFilter)return[];if(!center2||typeof center2.x!="number"||typeof center2.y!="number"||typeof radius!="number")return console.error("Invalid PCB Silkscreen Circle data:",{center:center2,radius}),[];let[transformedX,transformedY]=applyToPoint3(transform6,[center2.x,center2.y]),transformedRadius=radius*Math.abs(transform6.a),transformedStrokeWidth=stroke_width*Math.abs(transform6.a),color=layer==="bottom"?colorMap2.silkscreen.bottom:colorMap2.silkscreen.top;return[{name:"circle",type:"element",attributes:{cx:transformedX.toString(),cy:transformedY.toString(),r:transformedRadius.toString(),class:`pcb-silkscreen-circle pcb-silkscreen-${layer}`,fill:is_filled?color:"none",stroke:color,"stroke-width":transformedStrokeWidth.toString(),"data-pcb-silkscreen-circle-id":pcb_silkscreen_circle_id,"data-type":"pcb_silkscreen_circle","data-pcb-layer":layer},value:"",children:[]}]}function createSvgObjectsFromPcbSilkscreenLine(pcbSilkscreenLine,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2}=ctx,{x1:x12,y1:y12,x2:x22,y2:y22,stroke_width,layer="top",pcb_silkscreen_line_id}=pcbSilkscreenLine;if(layerFilter&&layer!==layerFilter)return[];if(typeof x12!="number"||typeof y12!="number"||typeof x22!="number"||typeof y22!="number")return debugPcb(`[pcb_silkscreen_line] Invalid coordinates for "${pcb_silkscreen_line_id}": expected x1, y1, x2, y2 as numbers, got x1=${JSON.stringify(x12)}, y1=${JSON.stringify(y12)}, x2=${JSON.stringify(x22)}, y2=${JSON.stringify(y22)}`),[];let[transformedX1,transformedY1]=applyToPoint3(transform6,[x12,y12]),[transformedX2,transformedY2]=applyToPoint3(transform6,[x22,y22]),transformedStrokeWidth=stroke_width*Math.abs(transform6.a),color=layer==="bottom"?colorMap2.silkscreen.bottom:colorMap2.silkscreen.top;return[{name:"line",type:"element",attributes:{x1:transformedX1.toString(),y1:transformedY1.toString(),x2:transformedX2.toString(),y2:transformedY2.toString(),stroke:color,"stroke-width":transformedStrokeWidth.toString(),class:`pcb-silkscreen-line pcb-silkscreen-${layer}`,"data-pcb-silkscreen-line-id":pcb_silkscreen_line_id,"data-type":"pcb_silkscreen_line","data-pcb-layer":layer},value:"",children:[]}]}function createSvgObjectsFromPcbSilkscreenPill(pcbSilkscreenPill,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2}=ctx,{center:center2,width,height,layer="top",pcb_silkscreen_pill_id}=pcbSilkscreenPill;if(layerFilter&&layer!==layerFilter)return[];let[transformedX,transformedY]=applyToPoint3(transform6,[center2.x,center2.y]),transformedWidth=width*Math.abs(transform6.a),transformedHeight=height*Math.abs(transform6.d),baseCornerRadius=Math.min(width,height)/2,transformedCornerRadiusX=baseCornerRadius*Math.abs(transform6.a),transformedCornerRadiusY=baseCornerRadius*Math.abs(transform6.d),color=layer==="bottom"?colorMap2.silkscreen.bottom:colorMap2.silkscreen.top;return[{name:"rect",type:"element",attributes:{x:(transformedX-transformedWidth/2).toString(),y:(transformedY-transformedHeight/2).toString(),width:transformedWidth.toString(),height:transformedHeight.toString(),rx:transformedCornerRadiusX.toString(),ry:transformedCornerRadiusY.toString(),fill:"none",stroke:color,"stroke-width":(.1*Math.abs(transform6.a)).toString(),class:`pcb-silkscreen-pill pcb-silkscreen-${layer}`,"data-pcb-silkscreen-pill-id":pcb_silkscreen_pill_id,"data-type":"pcb_silkscreen_pill","data-pcb-layer":layer},value:"",children:[]}]}function createSvgObjectsFromPcbSilkscreenOval(pcbSilkscreenOval,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2}=ctx,{center:center2,radius_x,radius_y,layer="top",pcb_silkscreen_oval_id,ccw_rotation=0}=pcbSilkscreenOval;if(layerFilter&&layer!==layerFilter)return[];if(!center2||typeof center2.x!="number"||typeof center2.y!="number"||typeof radius_x!="number"||typeof radius_y!="number")return debugPcb(`[pcb_silkscreen_oval] Invalid data for "${pcb_silkscreen_oval_id}": expected center {x: number, y: number}, radius_x: number, radius_y: number, got center=${JSON.stringify(center2)}, radius_x=${JSON.stringify(radius_x)}, radius_y=${JSON.stringify(radius_y)}`),[];let[transformedX,transformedY]=applyToPoint3(transform6,[center2.x,center2.y]),transformedRadiusX=radius_x*Math.abs(transform6.a),transformedRadiusY=radius_y*Math.abs(transform6.d),color=layer==="bottom"?colorMap2.silkscreen.bottom:colorMap2.silkscreen.top;return[{name:"ellipse",type:"element",attributes:{cx:transformedX.toString(),cy:transformedY.toString(),rx:transformedRadiusX.toString(),ry:transformedRadiusY.toString(),fill:"none",stroke:color,"stroke-width":(.1*Math.abs(transform6.a)).toString(),class:`pcb-silkscreen-oval pcb-silkscreen-${layer}`,"data-pcb-silkscreen-oval-id":pcb_silkscreen_oval_id,"data-type":"pcb_silkscreen_oval","data-pcb-layer":layer,...ccw_rotation!==0&&{transform:`rotate(${-ccw_rotation} ${transformedX} ${transformedY})`}},value:"",children:[]}]}function createSvgObjectsFromPcbCourtyardRect(pcbCourtyardRect,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2}=ctx,{center:center2,width,height,layer="top",pcb_courtyard_rect_id,ccw_rotation=0}=pcbCourtyardRect;if(layerFilter&&layer!==layerFilter)return[];if(!center2||typeof center2.x!="number"||typeof center2.y!="number"||typeof width!="number"||typeof height!="number")return debugPcb(`[pcb_courtyard_rect] Invalid data for "${pcb_courtyard_rect_id}": expected center {x: number, y: number}, width: number, height: number, got center=${JSON.stringify(center2)}, width=${JSON.stringify(width)}, height=${JSON.stringify(height)}`),[];let[transformedX,transformedY]=applyToPoint3(transform6,[center2.x,center2.y]),transformedWidth=width*Math.abs(transform6.a),transformedHeight=height*Math.abs(transform6.d),transformedStrokeWidth=.05*Math.abs(transform6.a),color=layer==="bottom"?colorMap2.courtyard.bottom:colorMap2.courtyard.top,attributes2={x:(-transformedWidth/2).toString(),y:(-transformedHeight/2).toString(),width:transformedWidth.toString(),height:transformedHeight.toString(),class:`pcb-courtyard-rect pcb-courtyard-${layer}`,"data-pcb-courtyard-rect-id":pcb_courtyard_rect_id,"data-type":"pcb_courtyard_rect","data-pcb-layer":layer,"stroke-linejoin":"round"};return typeof ccw_rotation=="number"&&ccw_rotation!==0?attributes2.transform=`translate(${transformedX} ${transformedY}) rotate(${-ccw_rotation})`:(attributes2.x=(transformedX-transformedWidth/2).toString(),attributes2.y=(transformedY-transformedHeight/2).toString()),attributes2.fill="none",attributes2.stroke=color,attributes2["stroke-width"]=transformedStrokeWidth.toString(),[{name:"rect",type:"element",attributes:attributes2,value:"",children:[]}]}function createSvgObjectsFromPcbCourtyardPolygon(pcbCourtyardPolygon,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2}=ctx,{layer="top",pcb_courtyard_polygon_id,points,color}=pcbCourtyardPolygon;if(layerFilter&&layer!==layerFilter)return[];if(!points||points.length===0)return debugPcb(`[pcb_courtyard_polygon] Invalid data for "${pcb_courtyard_polygon_id}": expected non-empty array of points, got ${JSON.stringify(points)}`),[];let pointsString=points.map(p4=>applyToPoint3(transform6,[p4.x,p4.y])).map(p4=>`${p4[0]},${p4[1]}`).join(" "),transformedStrokeWidth=.05*Math.abs(transform6.a),strokeColor=color??(layer==="bottom"?colorMap2.courtyard.bottom:colorMap2.courtyard.top);return[{name:"polygon",type:"element",attributes:{points:pointsString,class:`pcb-courtyard-polygon pcb-courtyard-${layer}`,"data-pcb-courtyard-polygon-id":pcb_courtyard_polygon_id,"data-type":"pcb_courtyard_polygon","data-pcb-layer":layer,fill:"none",stroke:strokeColor,"stroke-width":transformedStrokeWidth.toString(),"stroke-linejoin":"round"},value:"",children:[]}]}function createSvgObjectsFromPcbCourtyardOutline(pcbCourtyardOutline,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2}=ctx,{layer,pcb_courtyard_outline_id,outline}=pcbCourtyardOutline;if(layerFilter&&layer!==layerFilter)return[];if(!outline||outline.length===0)return debugPcb(`[pcb_courtyard_outline] Invalid data for "${pcb_courtyard_outline_id}": expected non-empty array of points, got ${JSON.stringify(outline)}`),[];let pointsString=outline.map(p4=>applyToPoint3(transform6,[p4.x,p4.y])).map(p4=>`${p4[0]},${p4[1]}`).join(" "),transformedStrokeWidth=.05*Math.abs(transform6.a),strokeColor=layer==="bottom"?colorMap2.courtyard.bottom:colorMap2.courtyard.top;return[{name:"polygon",type:"element",attributes:{points:pointsString,class:`pcb-courtyard-outline pcb-courtyard-${layer}`,"data-pcb-courtyard-outline-id":pcb_courtyard_outline_id,"data-type":"pcb_courtyard_outline","data-pcb-layer":layer,fill:"none",stroke:strokeColor,"stroke-width":transformedStrokeWidth.toString(),"stroke-linejoin":"round"},value:"",children:[]}]}function createSvgObjectsFromPcbCourtyardCircle(pcbCourtyardCircle,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2}=ctx,{center:center2,radius,layer="top",pcb_courtyard_circle_id}=pcbCourtyardCircle;if(layerFilter&&layer!==layerFilter)return[];if(!center2||typeof center2.x!="number"||typeof center2.y!="number"||typeof radius!="number")return console.error(`[pcb_courtyard_circle] Invalid data for "${pcb_courtyard_circle_id}": expected center {x: number, y: number}, radius: number, got center=${JSON.stringify(center2)}, radius=${JSON.stringify(radius)}`),[];let[transformedX,transformedY]=applyToPoint3(transform6,[center2.x,center2.y]),transformedRadius=radius*Math.abs(transform6.a),transformedStrokeWidth=.05*Math.abs(transform6.a),color=layer==="bottom"?colorMap2.courtyard.bottom:colorMap2.courtyard.top,attributes2={cx:transformedX.toString(),cy:transformedY.toString(),r:transformedRadius.toString(),class:`pcb-courtyard-circle pcb-courtyard-${layer}`,"data-pcb-courtyard-circle-id":pcb_courtyard_circle_id,"data-type":"pcb_courtyard_circle","data-pcb-layer":layer};return attributes2.fill="none",attributes2.stroke=color,attributes2["stroke-width"]=transformedStrokeWidth.toString(),[{name:"circle",type:"element",attributes:attributes2,value:"",children:[]}]}function getPcbTracePoints(point7){return point7.route_type==="through_pad"?[point7.start,point7.end]:[point7]}function getPcbTraceSegments(route){let segments=[];for(let i3=0;i3<route.length-1;i3++){let start=route[i3],end=route[i3+1];if(!start||!end)continue;let startAnchor=start.route_type==="through_pad"?start.end:start,endAnchor=end.route_type==="through_pad"?end.start:end,layer=start.route_type==="wire"?start.layer:start.route_type==="through_pad"?start.end_layer:end.route_type==="wire"?end.layer:end.route_type==="through_pad"?end.start_layer:null;layer&&segments.push({start:startAnchor,end:endAnchor,layer,width:"width"in start?start.width:"width"in end?end.width:0,isInsideCopperPour:isInsideCopperPour(start)&&isInsideCopperPour(end)})}for(let point7 of route)if(point7.route_type==="through_pad")for(let layer of new Set([point7.start_layer,point7.end_layer]))segments.push({start:point7.start,end:point7.end,layer,width:point7.width,isInsideCopperPour:!1});return segments}function isInsideCopperPour(point7){return"is_inside_copper_pour"in point7&&point7.is_inside_copper_pour===!0}function createSvgObjectsFromPcbTrace(trace,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2,showSolderMask}=ctx;if(!trace.route||!Array.isArray(trace.route)||trace.route.length<2)return[];let svgObjects=[];for(let segment2 of getPcbTraceSegments(trace.route)){if(segment2.isInsideCopperPour)continue;let startPoint=applyToPoint3(transform6,[segment2.start.x,segment2.start.y]),endPoint=applyToPoint3(transform6,[segment2.end.x,segment2.end.y]),layer=segment2.layer;if(!layer||layerFilter&&layer!==layerFilter)continue;let copperColor=layerNameToColor(layer,colorMap2),maskColor=colorMap2.soldermaskWithCopperUnderneath[layer],width=segment2.width?(segment2.width*Math.abs(transform6.a)).toString():"0.3";if(showSolderMask){let maskObject={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask",stroke:maskColor,fill:"none",d:`M ${startPoint[0]} ${startPoint[1]} L ${endPoint[0]} ${endPoint[1]}`,"stroke-width":width,"stroke-linecap":"round","stroke-linejoin":"round","shape-rendering":"crispEdges","data-type":"pcb_trace_soldermask","data-pcb-layer":layer}};svgObjects.push(maskObject)}else{let maskOnlyObject={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-trace",stroke:copperColor,fill:"none",d:`M ${startPoint[0]} ${startPoint[1]} L ${endPoint[0]} ${endPoint[1]}`,"stroke-width":width,"stroke-linecap":"round","stroke-linejoin":"round","shape-rendering":"crispEdges","data-type":showSolderMask?"pcb_soldermask":"pcb_trace","data-pcb-layer":layer}};svgObjects.push(maskOnlyObject)}}return svgObjects}function createSvgObjectsFromSmtPad(pad2,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2,showSolderMask}=ctx;if(layerFilter&&pad2.layer!==layerFilter)return[];let isCoveredWithSolderMask=!!pad2?.is_covered_with_solder_mask,shouldShowSolderMask=showSolderMask&&isCoveredWithSolderMask,soldermaskWithCopperUnderneathColor=colorMap2.soldermaskWithCopperUnderneath[pad2.layer]??colorMap2.soldermaskWithCopperUnderneath.top,soldermaskMargin=(pad2.soldermask_margin??0)*Math.abs(transform6.a);if(pad2.shape==="rect"||pad2.shape==="rotated_rect"){let width=pad2.width*Math.abs(transform6.a),height=pad2.height*Math.abs(transform6.d),[x4,y4]=applyToPoint3(transform6,[pad2.x,pad2.y]),scaledBorderRadius=(pad2.corner_radius??pad2.rect_border_radius??0)*Math.abs(transform6.a),m4={left:(pad2.soldermask_margin_left??pad2.soldermask_margin??0)*Math.abs(transform6.a),right:(pad2.soldermask_margin_right??pad2.soldermask_margin??0)*Math.abs(transform6.a),top:(pad2.soldermask_margin_top??pad2.soldermask_margin??0)*Math.abs(transform6.a),bottom:(pad2.soldermask_margin_bottom??pad2.soldermask_margin??0)*Math.abs(transform6.a)},isNegativeMargin=m4.left<0||m4.right<0||m4.top<0||m4.bottom<0,isZeroMargin=m4.left===0&&m4.right===0&&m4.top===0&&m4.bottom===0;if(pad2.shape==="rotated_rect"&&pad2.ccw_rotation){let padElement2={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:layerNameToColor(pad2.layer,colorMap2),x:(-width/2).toString(),y:(-height/2).toString(),width:width.toString(),height:height.toString(),transform:`translate(${x4} ${y4}) rotate(${-pad2.ccw_rotation})`,"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer,...scaledBorderRadius?{rx:scaledBorderRadius.toString(),ry:scaledBorderRadius.toString()}:{}}};if(!shouldShowSolderMask)return[padElement2];let maskWidth2=width+m4.left+m4.right,maskHeight2=height+m4.top+m4.bottom,maskBorderRadius2=scaledBorderRadius?scaledBorderRadius+soldermaskMargin:0;if(isNegativeMargin){let coveredPadElement={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad-covered",fill:soldermaskWithCopperUnderneathColor,x:(-width/2).toString(),y:(-height/2).toString(),width:width.toString(),height:height.toString(),transform:`translate(${x4} ${y4}) rotate(${-pad2.ccw_rotation})`,"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer,...scaledBorderRadius?{rx:scaledBorderRadius.toString(),ry:scaledBorderRadius.toString()}:{}}},exposedOpeningElement={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad-exposed",fill:layerNameToColor(pad2.layer,colorMap2),x:(-width/2-m4.left).toString(),y:(-height/2-m4.top).toString(),width:maskWidth2.toString(),height:maskHeight2.toString(),transform:`translate(${x4} ${y4}) rotate(${-pad2.ccw_rotation})`,"data-type":"pcb_soldermask","data-pcb-layer":pad2.layer,...maskBorderRadius2>0?{rx:maskBorderRadius2.toString(),ry:maskBorderRadius2.toString()}:{}}};return[coveredPadElement,exposedOpeningElement]}return isZeroMargin?[{name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad-covered",fill:soldermaskWithCopperUnderneathColor,x:(-width/2).toString(),y:(-height/2).toString(),width:width.toString(),height:height.toString(),transform:`translate(${x4} ${y4}) rotate(${-pad2.ccw_rotation})`,"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer,...scaledBorderRadius?{rx:scaledBorderRadius.toString(),ry:scaledBorderRadius.toString()}:{}}}]:[{name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,x:(-width/2-m4.left).toString(),y:(-height/2-m4.top).toString(),width:maskWidth2.toString(),height:maskHeight2.toString(),transform:`translate(${x4} ${y4}) rotate(${-pad2.ccw_rotation})`,...maskBorderRadius2>0?{rx:maskBorderRadius2.toString(),ry:maskBorderRadius2.toString()}:{},"data-type":"pcb_soldermask_opening","data-pcb-layer":pad2.layer}},padElement2]}let padElement={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:layerNameToColor(pad2.layer,colorMap2),x:(x4-width/2).toString(),y:(y4-height/2).toString(),width:width.toString(),height:height.toString(),"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer,...scaledBorderRadius?{rx:scaledBorderRadius.toString(),ry:scaledBorderRadius.toString()}:{}}};if(!shouldShowSolderMask)return[padElement];let maskWidth=width+m4.left+m4.right,maskHeight=height+m4.top+m4.bottom,maskBorderRadius=scaledBorderRadius?scaledBorderRadius+soldermaskMargin:0;if(isNegativeMargin){let coveredPadElement={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad-covered",fill:soldermaskWithCopperUnderneathColor,x:(x4-width/2).toString(),y:(y4-height/2).toString(),width:width.toString(),height:height.toString(),"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer,...scaledBorderRadius?{rx:scaledBorderRadius.toString(),ry:scaledBorderRadius.toString()}:{}}},exposedOpeningElement={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad-exposed",fill:layerNameToColor(pad2.layer,colorMap2),x:(x4-width/2-m4.left).toString(),y:(y4-height/2-m4.top).toString(),width:maskWidth.toString(),height:maskHeight.toString(),"data-type":"pcb_soldermask","data-pcb-layer":pad2.layer,...maskBorderRadius>0?{rx:maskBorderRadius.toString(),ry:maskBorderRadius.toString()}:{}}};return[coveredPadElement,exposedOpeningElement]}return isZeroMargin?[{name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad-covered",fill:soldermaskWithCopperUnderneathColor,x:(x4-width/2).toString(),y:(y4-height/2).toString(),width:width.toString(),height:height.toString(),...maskBorderRadius>0?{rx:scaledBorderRadius.toString(),ry:scaledBorderRadius.toString()}:{},"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer}}]:[{name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,x:(x4-width/2-m4.left).toString(),y:(y4-height/2-m4.top).toString(),width:maskWidth.toString(),height:maskHeight.toString(),...maskBorderRadius>0?{rx:maskBorderRadius.toString(),ry:maskBorderRadius.toString()}:{},"data-type":"pcb_soldermask_opening","data-pcb-layer":pad2.layer}},padElement]}if(pad2.shape==="pill"||pad2.shape==="rotated_pill"){let isRotated=pad2.shape==="rotated_pill",width=pad2.width*Math.abs(transform6.a),height=pad2.height*Math.abs(transform6.d),radius=pad2.radius*Math.abs(transform6.a),[x4,y4]=applyToPoint3(transform6,[pad2.x,pad2.y]),rotationTransformAttributes=isRotated?{transform:`translate(${x4} ${y4}) rotate(${-(pad2.ccw_rotation??0)})`}:void 0,baseAttributes={class:"pcb-pad",fill:layerNameToColor(pad2.layer,colorMap2),x:isRotated?(-width/2).toString():(x4-width/2).toString(),y:isRotated?(-height/2).toString():(y4-height/2).toString(),width:width.toString(),height:height.toString(),rx:radius.toString(),ry:radius.toString(),"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer,...rotationTransformAttributes??{}},padElement={name:"rect",type:"element",value:"",children:[],attributes:baseAttributes};if(!shouldShowSolderMask)return[padElement];let maskWidth=width+2*soldermaskMargin,maskHeight=height+2*soldermaskMargin,maskRadius=radius+soldermaskMargin;if(soldermaskMargin<0){let coveredPadElement={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad-covered",fill:soldermaskWithCopperUnderneathColor,x:isRotated?(-width/2).toString():(x4-width/2).toString(),y:isRotated?(-height/2).toString():(y4-height/2).toString(),width:width.toString(),height:height.toString(),rx:radius.toString(),ry:radius.toString(),"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer,...rotationTransformAttributes??{}}},exposedAttributes={class:"pcb-pad-exposed",fill:layerNameToColor(pad2.layer,colorMap2),x:isRotated?(-maskWidth/2).toString():(x4-maskWidth/2).toString(),y:isRotated?(-maskHeight/2).toString():(y4-maskHeight/2).toString(),width:maskWidth.toString(),height:maskHeight.toString(),rx:maskRadius.toString(),ry:maskRadius.toString(),"data-type":"pcb_soldermask","data-pcb-layer":pad2.layer,...rotationTransformAttributes??{}};return[coveredPadElement,{name:"rect",type:"element",value:"",children:[],attributes:exposedAttributes}]}if(soldermaskMargin===0)return[{name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad-covered",fill:soldermaskWithCopperUnderneathColor,x:isRotated?(-width/2).toString():(x4-width/2).toString(),y:isRotated?(-height/2).toString():(y4-height/2).toString(),width:width.toString(),height:height.toString(),rx:radius.toString(),ry:radius.toString(),"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer,...rotationTransformAttributes??{}}}];let substrateAttributes={class:"pcb-soldermask-cutout",fill:colorMap2.substrate,x:isRotated?(-maskWidth/2).toString():(x4-maskWidth/2).toString(),y:isRotated?(-maskHeight/2).toString():(y4-maskHeight/2).toString(),width:maskWidth.toString(),height:maskHeight.toString(),rx:maskRadius.toString(),ry:maskRadius.toString(),"data-type":"pcb_soldermask_opening","data-pcb-layer":pad2.layer,...rotationTransformAttributes??{}};return[{name:"rect",type:"element",value:"",children:[],attributes:substrateAttributes},padElement]}if(pad2.shape==="circle"){let radius=pad2.radius*Math.abs(transform6.a),[x4,y4]=applyToPoint3(transform6,[pad2.x,pad2.y]),padElement={name:"circle",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:layerNameToColor(pad2.layer,colorMap2),cx:x4.toString(),cy:y4.toString(),r:radius.toString(),"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer}};if(!shouldShowSolderMask)return[padElement];let maskRadius=radius+soldermaskMargin;if(soldermaskMargin<0){let coveredPadElement={name:"circle",type:"element",value:"",children:[],attributes:{class:"pcb-pad-covered",fill:soldermaskWithCopperUnderneathColor,cx:x4.toString(),cy:y4.toString(),r:radius.toString(),"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer}},exposedOpeningElement={name:"circle",type:"element",value:"",children:[],attributes:{class:"pcb-pad-exposed",fill:layerNameToColor(pad2.layer,colorMap2),cx:x4.toString(),cy:y4.toString(),r:maskRadius.toString(),"data-type":"pcb_soldermask","data-pcb-layer":pad2.layer}};return[coveredPadElement,exposedOpeningElement]}return soldermaskMargin===0?[{name:"circle",type:"element",value:"",children:[],attributes:{class:"pcb-pad-covered",fill:soldermaskWithCopperUnderneathColor,cx:x4.toString(),cy:y4.toString(),r:radius.toString(),"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer}}]:[{name:"circle",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,cx:x4.toString(),cy:y4.toString(),r:maskRadius.toString(),"data-type":"pcb_soldermask_opening","data-pcb-layer":pad2.layer}},padElement]}if(pad2.shape==="polygon"){let points=(pad2.points??[]).map(point7=>applyToPoint3(transform6,[point7.x,point7.y])),padElement={name:"polygon",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:layerNameToColor(pad2.layer,colorMap2),points:points.map(p4=>p4.join(",")).join(" "),"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer}};if(!shouldShowSolderMask)return[padElement];let maskPoints=points;if(soldermaskMargin!==0){let centroidX=points.reduce((sum,p4)=>sum+p4[0],0)/points.length,centroidY=points.reduce((sum,p4)=>sum+p4[1],0)/points.length;maskPoints=points.map(([px3,py3])=>{let dx3=px3-centroidX,dy3=py3-centroidY,distance62=Math.sqrt(dx3*dx3+dy3*dy3);if(distance62===0)return[px3,py3];let normalizedDx=dx3/distance62,normalizedDy=dy3/distance62;return[px3+normalizedDx*soldermaskMargin,py3+normalizedDy*soldermaskMargin]})}if(soldermaskMargin<0){let coveredPadElement={name:"polygon",type:"element",value:"",children:[],attributes:{class:"pcb-pad-covered",fill:soldermaskWithCopperUnderneathColor,points:points.map(p4=>p4.join(",")).join(" "),"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer}},exposedOpeningElement={name:"polygon",type:"element",value:"",children:[],attributes:{class:"pcb-pad-exposed",fill:layerNameToColor(pad2.layer,colorMap2),points:maskPoints.map(p4=>p4.join(",")).join(" "),"data-type":"pcb_soldermask","data-pcb-layer":pad2.layer}};return[coveredPadElement,exposedOpeningElement]}return soldermaskMargin===0?[{name:"polygon",type:"element",value:"",children:[],attributes:{class:"pcb-pad-covered",fill:soldermaskWithCopperUnderneathColor,points:points.map(p4=>p4.join(",")).join(" "),"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer}}]:[{name:"polygon",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,points:maskPoints.map(p4=>p4.join(",")).join(" "),"data-type":"pcb_soldermask_opening","data-pcb-layer":pad2.layer}},padElement]}return[]}function createAnchorOffsetIndicators(params){let{groupAnchorPosition,componentPosition,transform:transform6,componentWidth=0,componentHeight=0,displayXOffset,displayYOffset}=params,objects=[],[screenGroupAnchorX,screenGroupAnchorY]=applyToPoint3(transform6,[groupAnchorPosition.x,groupAnchorPosition.y]),[screenComponentX,screenComponentY]=applyToPoint3(transform6,[componentPosition.x,componentPosition.y]),offsetX=componentPosition.x-groupAnchorPosition.x,offsetY=componentPosition.y-groupAnchorPosition.y,scale10=Math.abs(transform6.a),screenComponentWidth=componentWidth*scale10,screenComponentHeight=componentHeight*scale10;objects.push(createAnchorMarker(screenGroupAnchorX,screenGroupAnchorY));let trimmedConnector=getTrimmedConnectorLine(screenGroupAnchorX,screenGroupAnchorY,screenComponentX,screenComponentY);objects.push({name:"line",type:"element",attributes:{x1:trimmedConnector.x1.toString(),y1:trimmedConnector.y1.toString(),x2:trimmedConnector.x2.toString(),y2:trimmedConnector.y2.toString(),stroke:"#ffffff","stroke-width":"0.5","stroke-dasharray":"3,3",opacity:"0.5",class:"anchor-offset-connector"},children:[],value:""}),objects.push({name:"circle",type:"element",attributes:{cx:screenComponentX.toString(),cy:screenComponentY.toString(),r:COMPONENT_ANCHOR_MARKER_RADIUS_PX.toString(),fill:"#ffffff",opacity:"0.7",class:"anchor-offset-component-marker"},children:[],value:""});let yDistance=Math.abs(screenComponentY-screenGroupAnchorY),xDistance=Math.abs(screenComponentX-screenGroupAnchorX),totalDistance=Math.sqrt(xDistance*xDistance+yDistance*yDistance),componentHeightOffset=screenComponentHeight/2+COMPONENT_GAP_PX,dynamicOffset=Math.max(componentHeightOffset,Math.min(MAX_OFFSET_PX,totalDistance*DISTANCE_MULTIPLIER)),horizontalLineY=offsetY>0?screenComponentY-dynamicOffset:screenComponentY+dynamicOffset,componentWidthOffset=screenComponentWidth/2+COMPONENT_SIDE_GAP_PX,verticalLineX=offsetX>0?screenComponentX+componentWidthOffset:screenComponentX-componentWidthOffset;if(isTooCloseToAnchor(horizontalLineY,screenGroupAnchorY)||isTooCloseToAnchor(horizontalLineY,screenComponentY)){let minY=Math.min(screenGroupAnchorY,screenComponentY),maxY=Math.max(screenGroupAnchorY,screenComponentY),candidateAbove=minY-DIMENSION_ANCHOR_CLEARANCE_PX,candidateBelow=maxY+DIMENSION_ANCHOR_CLEARANCE_PX;horizontalLineY=Math.abs(horizontalLineY-candidateAbove)<Math.abs(horizontalLineY-candidateBelow)?candidateAbove:candidateBelow}if(isTooCloseToAnchor(verticalLineX,screenGroupAnchorX)||isTooCloseToAnchor(verticalLineX,screenComponentX)){let minX=Math.min(screenGroupAnchorX,screenComponentX),maxX=Math.max(screenGroupAnchorX,screenComponentX),candidateLeft=minX-DIMENSION_ANCHOR_CLEARANCE_PX,candidateRight=maxX+DIMENSION_ANCHOR_CLEARANCE_PX;verticalLineX=Math.abs(verticalLineX-candidateLeft)<Math.abs(verticalLineX-candidateRight)?candidateLeft:candidateRight}return Math.abs(offsetX)>OFFSET_THRESHOLD_MM&&objects.push(...createHorizontalDimension({startX:screenGroupAnchorX,endX:screenComponentX,y:horizontalLineY,offsetMm:offsetX,offsetY,displayOffset:displayXOffset})),Math.abs(offsetY)>OFFSET_THRESHOLD_MM&&objects.push(...createVerticalDimension({x:verticalLineX,startY:screenGroupAnchorY,endY:screenComponentY,offsetMm:offsetY,offsetX,displayOffset:displayYOffset})),objects}function getTrimmedConnectorLine(x12,y12,x22,y22){let dx3=x22-x12,dy3=y22-y12,distance62=Math.hypot(dx3,dy3),totalTrim=CONNECTOR_GROUP_GAP_PX+CONNECTOR_COMPONENT_GAP_PX;if(!(distance62>totalTrim))return{x1:x12,y1:y12,x2:x22,y2:y22};let ux3=dx3/distance62,uy3=dy3/distance62;return{x1:x12+ux3*CONNECTOR_GROUP_GAP_PX,y1:y12+uy3*CONNECTOR_GROUP_GAP_PX,x2:x22-ux3*CONNECTOR_COMPONENT_GAP_PX,y2:y22-uy3*CONNECTOR_COMPONENT_GAP_PX}}function isTooCloseToAnchor(value,anchorValue){return Math.abs(value-anchorValue)<DIMENSION_ANCHOR_CLEARANCE_PX}function createAnchorMarker(x4,y4){return{name:"g",type:"element",attributes:{class:"anchor-offset-marker","data-type":"anchor_offset_marker"},children:[{name:"line",type:"element",attributes:{x1:x4.toString(),y1:(y4-ANCHOR_MARKER_SIZE_PX).toString(),x2:x4.toString(),y2:(y4+ANCHOR_MARKER_SIZE_PX).toString(),stroke:"#ffffff","stroke-width":ANCHOR_MARKER_STROKE_WIDTH_PX.toString(),"stroke-linecap":"round"},children:[],value:""},{name:"line",type:"element",attributes:{x1:(x4-ANCHOR_MARKER_SIZE_PX).toString(),y1:y4.toString(),x2:(x4+ANCHOR_MARKER_SIZE_PX).toString(),y2:y4.toString(),stroke:"#ffffff","stroke-width":ANCHOR_MARKER_STROKE_WIDTH_PX.toString(),"stroke-linecap":"round"},children:[],value:""}],value:""}}function createHorizontalDimension({startX,endX,y:y4,offsetMm,offsetY,displayOffset}){let objects=[];objects.push({name:"line",type:"element",attributes:{x1:startX.toString(),y1:y4.toString(),x2:endX.toString(),y2:y4.toString(),stroke:"#ffffff","stroke-width":STROKE_WIDTH_PX.toString(),class:"anchor-offset-dimension-x"},children:[],value:""}),objects.push({name:"line",type:"element",attributes:{x1:startX.toString(),y1:(y4-TICK_SIZE_PX).toString(),x2:startX.toString(),y2:(y4+TICK_SIZE_PX).toString(),stroke:"#ffffff","stroke-width":STROKE_WIDTH_PX.toString()},children:[],value:""}),objects.push({name:"line",type:"element",attributes:{x1:endX.toString(),y1:(y4-TICK_SIZE_PX).toString(),x2:endX.toString(),y2:(y4+TICK_SIZE_PX).toString(),stroke:"#ffffff","stroke-width":STROKE_WIDTH_PX.toString()},children:[],value:""});let midX=(startX+endX)/2,labelY=offsetY>0?y4-TICK_SIZE_PX-LABEL_GAP_PX:y4+TICK_SIZE_PX+LABEL_GAP_PX;return objects.push({name:"text",type:"element",attributes:{x:midX.toString(),y:labelY.toString(),fill:"#ffffff","font-size":LABEL_FONT_SIZE_PX.toString(),"font-family":"Arial, sans-serif","text-anchor":"middle","dominant-baseline":offsetY>0?"baseline":"hanging",class:"anchor-offset-label"},children:[{type:"text",value:formatOffsetLabel("X",offsetMm,displayOffset),name:"",attributes:{},children:[]}],value:""}),objects}function createVerticalDimension({x:x4,startY,endY,offsetMm,offsetX,displayOffset}){let objects=[];objects.push({name:"line",type:"element",attributes:{x1:x4.toString(),y1:startY.toString(),x2:x4.toString(),y2:endY.toString(),stroke:"#ffffff","stroke-width":STROKE_WIDTH_PX.toString(),class:"anchor-offset-dimension-y"},children:[],value:""}),objects.push({name:"line",type:"element",attributes:{x1:(x4-TICK_SIZE_PX).toString(),y1:startY.toString(),x2:(x4+TICK_SIZE_PX).toString(),y2:startY.toString(),stroke:"#ffffff","stroke-width":STROKE_WIDTH_PX.toString()},children:[],value:""}),objects.push({name:"line",type:"element",attributes:{x1:(x4-TICK_SIZE_PX).toString(),y1:endY.toString(),x2:(x4+TICK_SIZE_PX).toString(),y2:endY.toString(),stroke:"#ffffff","stroke-width":STROKE_WIDTH_PX.toString()},children:[],value:""});let midY=(startY+endY)/2,labelX=offsetX<0?x4-TICK_SIZE_PX-4:x4+TICK_SIZE_PX+4;return objects.push({name:"text",type:"element",attributes:{x:labelX.toString(),y:midY.toString(),fill:"#ffffff","font-size":LABEL_FONT_SIZE_PX.toString(),"font-family":"Arial, sans-serif","text-anchor":offsetX<0?"end":"start","dominant-baseline":"middle",class:"anchor-offset-label"},children:[{type:"text",value:formatOffsetLabel("Y",offsetMm,displayOffset),name:"",attributes:{},children:[]}],value:""}),objects}function formatOffsetLabel(axis,offsetMm,displayOffset){let valueStr=typeof displayOffset=="string"?displayOffset:offsetMm.toFixed(2),unitSuffix=typeof valueStr=="string"&&valueStr.trim().endsWith("mm")?"":"mm";return`${axis}: ${valueStr}${unitSuffix}`}function getPointFromElm(elm){let candidate=elm?.anchor_position??elm?.center;if(candidate&&typeof candidate.x=="number"&&typeof candidate.y=="number")return{x:candidate.x,y:candidate.y}}function createSvgObjectsFromPcbBoard(pcbBoard,ctx){let{transform:transform6,colorMap:colorMap2,showSolderMask,circuitJson}=ctx,{width,height,center:center2,outline,position_mode,anchor_position:boardAnchorPosition,display_offset_x,display_offset_y}=pcbBoard,path;if(outline&&Array.isArray(outline)&&outline.length>=3)path=outline.map((point7,index)=>{let[x4,y4]=applyToPoint3(transform6,[point7.x,point7.y]);return index===0?`M ${x4} ${y4}`:`L ${x4} ${y4}`}).join(" ");else{let halfWidth=width/2,halfHeight=height/2,topLeft=applyToPoint3(transform6,[center2.x-halfWidth,center2.y-halfHeight]),topRight=applyToPoint3(transform6,[center2.x+halfWidth,center2.y-halfHeight]),bottomRight=applyToPoint3(transform6,[center2.x+halfWidth,center2.y+halfHeight]),bottomLeft=applyToPoint3(transform6,[center2.x-halfWidth,center2.y+halfHeight]);path=`M ${topLeft[0]} ${topLeft[1]} L ${topRight[0]} ${topRight[1]} L ${bottomRight[0]} ${bottomRight[1]} L ${bottomLeft[0]} ${bottomLeft[1]}`}path+=" Z";let svgObjects=[];if(showSolderMask){let maskLayer=(ctx.layer??"top")==="bottom"?"soldermask-bottom":"soldermask-top";svgObjects.push({name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-board-soldermask",d:path,fill:colorMap2.soldermask.top,"fill-opacity":"0.8",stroke:"none","data-type":"pcb_soldermask","data-pcb-layer":maskLayer}})}if(svgObjects.push({name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-board",d:path,fill:"none",stroke:colorMap2.boardOutline,"stroke-width":(.1*Math.abs(transform6.a)).toString(),"data-type":"pcb_board","data-pcb-layer":"board"}}),ctx.showAnchorOffsets&&circuitJson&&position_mode==="relative_to_panel_anchor"){let panel=circuitJson.find(elm=>elm.type==="pcb_panel");if(panel){let panelAnchorPosition=getPointFromElm(panel);panelAnchorPosition&&svgObjects.push(...createAnchorOffsetIndicators({groupAnchorPosition:panelAnchorPosition,componentPosition:boardAnchorPosition??center2,transform:transform6,componentWidth:width,componentHeight:height,displayXOffset:display_offset_x,displayYOffset:display_offset_y}))}}return svgObjects}function createSvgObjectsFromPcbPanel(pcbPanel,ctx){let{transform:transform6,colorMap:colorMap2,showSolderMask}=ctx,width=Number(pcbPanel.width),height=Number(pcbPanel.height),center2=pcbPanel.center??{x:width/2,y:height/2},halfWidth=width/2,halfHeight=height/2,topLeft=applyToPoint3(transform6,[center2.x-halfWidth,center2.y-halfHeight]),topRight=applyToPoint3(transform6,[center2.x+halfWidth,center2.y-halfHeight]),bottomRight=applyToPoint3(transform6,[center2.x+halfWidth,center2.y+halfHeight]),bottomLeft=applyToPoint3(transform6,[center2.x-halfWidth,center2.y+halfHeight]),path=`M ${topLeft[0]} ${topLeft[1]} L ${topRight[0]} ${topRight[1]} L ${bottomRight[0]} ${bottomRight[1]} L ${bottomLeft[0]} ${bottomLeft[1]} Z`,isCoveredWithSolderMask=pcbPanel.covered_with_solder_mask!==!1,shouldShowSolderMask=!!(showSolderMask&&isCoveredWithSolderMask);return[{name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-panel",d:path,fill:"none",stroke:colorMap2.boardOutline,"stroke-width":(.1*Math.abs(transform6.a)).toString(),"data-type":"pcb_panel","data-pcb-layer":"board"}}]}function createSvgObjectsFromPcbVia(hole,ctx){let{transform:transform6,colorMap:colorMap2}=ctx,[x4,y4]=applyToPoint3(transform6,[hole.x,hole.y]),scaledOuterWidth=hole.outer_diameter*Math.abs(transform6.a),scaledOuterHeight=hole.outer_diameter*Math.abs(transform6.a),scaledHoleWidth=hole.hole_diameter*Math.abs(transform6.a),scaledHoleHeight=hole.hole_diameter*Math.abs(transform6.a),outerRadius=Math.min(scaledOuterWidth,scaledOuterHeight)/2,innerRadius=Math.min(scaledHoleWidth,scaledHoleHeight)/2;return{name:"g",type:"element",attributes:{"data-type":"pcb_via","data-pcb-layer":"through"},children:[{name:"circle",type:"element",attributes:{class:"pcb-hole-outer",fill:colorMap2.copper.top,cx:x4.toString(),cy:y4.toString(),r:outerRadius.toString(),"data-type":"pcb_via","data-pcb-layer":"top"}},{name:"circle",type:"element",attributes:{class:"pcb-hole-inner",fill:colorMap2.drill,cx:x4.toString(),cy:y4.toString(),r:innerRadius.toString(),"data-type":"pcb_via","data-pcb-layer":"drill"}}]}}function createSvgObjectsFromPcbHole(hole,ctx){let{transform:transform6,colorMap:colorMap2,showSolderMask}=ctx,layer=ctx.layer??"top",[x4,y4]=applyToPoint3(transform6,[hole.x,hole.y]),isCoveredWithSolderMask=!!hole.is_covered_with_solder_mask,soldermaskMargin=(hole.soldermask_margin??0)*Math.abs(transform6.a),shouldShowSolderMask=showSolderMask&&isCoveredWithSolderMask&&soldermaskMargin!==0,solderMaskColor=colorMap2.soldermask.top;if(hole.hole_shape==="circle"||hole.hole_shape==="square"){let scaledDiameter=hole.hole_diameter*Math.abs(transform6.a),radius=scaledDiameter/2;if(hole.hole_shape==="circle"){let holeElement2={name:"circle",type:"element",attributes:{class:"pcb-hole",cx:x4.toString(),cy:y4.toString(),r:radius.toString(),fill:colorMap2.drill,"data-type":"pcb_hole","data-pcb-layer":"drill"},children:[],value:""};if(!shouldShowSolderMask)return[holeElement2];let maskRadius=radius+soldermaskMargin;if(soldermaskMargin<0){let coveredElement={name:"circle",type:"element",value:"",children:[],attributes:{class:"pcb-hole-covered",fill:solderMaskColor,cx:x4.toString(),cy:y4.toString(),r:radius.toString(),"data-type":"pcb_hole","data-pcb-layer":"drill"}},exposedElement={name:"circle",type:"element",value:"",children:[],attributes:{class:"pcb-hole-exposed",fill:colorMap2.drill,cx:x4.toString(),cy:y4.toString(),r:maskRadius.toString(),"data-type":"pcb_soldermask","data-pcb-layer":"drill"}};return[coveredElement,exposedElement]}return[{name:"circle",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,cx:x4.toString(),cy:y4.toString(),r:maskRadius.toString(),"data-type":"pcb_soldermask_opening","data-pcb-layer":layer}},holeElement2]}let holeElement={name:"rect",type:"element",attributes:{class:"pcb-hole",x:(x4-radius).toString(),y:(y4-radius).toString(),width:scaledDiameter.toString(),height:scaledDiameter.toString(),fill:colorMap2.drill,"data-type":"pcb_hole","data-pcb-layer":"drill"},children:[],value:""};if(!shouldShowSolderMask)return[holeElement];let maskDiameter=scaledDiameter+2*soldermaskMargin;if(soldermaskMargin<0){let coveredElement={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-hole-covered",fill:solderMaskColor,x:(x4-radius).toString(),y:(y4-radius).toString(),width:scaledDiameter.toString(),height:scaledDiameter.toString(),"data-type":"pcb_hole","data-pcb-layer":"drill"}},exposedElement={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-hole-exposed",fill:colorMap2.drill,x:(x4-maskDiameter/2).toString(),y:(y4-maskDiameter/2).toString(),width:maskDiameter.toString(),height:maskDiameter.toString(),"data-type":"pcb_soldermask","data-pcb-layer":"drill"}};return[coveredElement,exposedElement]}return[{name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,x:(x4-maskDiameter/2).toString(),y:(y4-maskDiameter/2).toString(),width:maskDiameter.toString(),height:maskDiameter.toString(),"data-type":"pcb_soldermask_opening","data-pcb-layer":layer}},holeElement]}if(hole.hole_shape==="oval"){let scaledWidth=hole.hole_width*Math.abs(transform6.a),scaledHeight=hole.hole_height*Math.abs(transform6.a),rx3=scaledWidth/2,ry3=scaledHeight/2,holeElement={name:"ellipse",type:"element",attributes:{class:"pcb-hole",cx:x4.toString(),cy:y4.toString(),rx:rx3.toString(),ry:ry3.toString(),fill:colorMap2.drill,"data-type":"pcb_hole","data-pcb-layer":"drill"},children:[],value:""};if(!shouldShowSolderMask)return[holeElement];let maskRx=rx3+soldermaskMargin,maskRy=ry3+soldermaskMargin;if(soldermaskMargin<0){let coveredElement={name:"ellipse",type:"element",value:"",children:[],attributes:{class:"pcb-hole-covered",fill:solderMaskColor,cx:x4.toString(),cy:y4.toString(),rx:rx3.toString(),ry:ry3.toString(),"data-type":"pcb_hole","data-pcb-layer":"drill"}},exposedElement={name:"ellipse",type:"element",value:"",children:[],attributes:{class:"pcb-hole-exposed",fill:colorMap2.drill,cx:x4.toString(),cy:y4.toString(),rx:maskRx.toString(),ry:maskRy.toString(),"data-type":"pcb_soldermask","data-pcb-layer":"drill"}};return[coveredElement,exposedElement]}return[{name:"ellipse",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,cx:x4.toString(),cy:y4.toString(),rx:maskRx.toString(),ry:maskRy.toString(),"data-type":"pcb_soldermask_opening","data-pcb-layer":layer}},holeElement]}if(hole.hole_shape==="rect"){let scaledWidth=hole.hole_width*Math.abs(transform6.a),scaledHeight=hole.hole_height*Math.abs(transform6.a),holeElement={name:"rect",type:"element",attributes:{class:"pcb-hole",x:(x4-scaledWidth/2).toString(),y:(y4-scaledHeight/2).toString(),width:scaledWidth.toString(),height:scaledHeight.toString(),fill:colorMap2.drill,"data-type":"pcb_hole","data-pcb-layer":"drill"},children:[],value:""};if(!shouldShowSolderMask)return[holeElement];let maskWidth=scaledWidth+2*soldermaskMargin,maskHeight=scaledHeight+2*soldermaskMargin;if(soldermaskMargin<0){let coveredElement={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-hole-covered",fill:solderMaskColor,x:(x4-scaledWidth/2).toString(),y:(y4-scaledHeight/2).toString(),width:scaledWidth.toString(),height:scaledHeight.toString(),"data-type":"pcb_hole","data-pcb-layer":"drill"}},exposedElement={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-hole-exposed",fill:colorMap2.drill,x:(x4-maskWidth/2).toString(),y:(y4-maskHeight/2).toString(),width:maskWidth.toString(),height:maskHeight.toString(),"data-type":"pcb_soldermask","data-pcb-layer":"drill"}};return[coveredElement,exposedElement]}return[{name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,x:(x4-maskWidth/2).toString(),y:(y4-maskHeight/2).toString(),width:maskWidth.toString(),height:maskHeight.toString(),"data-type":"pcb_soldermask_opening","data-pcb-layer":layer}},holeElement]}if(hole.hole_shape==="pill"){let scaledWidth=hole.hole_width*Math.abs(transform6.a),scaledHeight=hole.hole_height*Math.abs(transform6.a),isHorizontal3=scaledWidth>scaledHeight,radius=Math.min(scaledWidth,scaledHeight)/2,straightLength=Math.abs(isHorizontal3?scaledWidth-scaledHeight:scaledHeight-scaledWidth),pathD=isHorizontal3?`M${x4-straightLength/2},${y4-radius} h${straightLength} a${radius},${radius} 0 0 1 0,${scaledHeight} h-${straightLength} a${radius},${radius} 0 0 1 0,-${scaledHeight} z`:`M${x4-radius},${y4-straightLength/2} v${straightLength} a${radius},${radius} 0 0 0 ${scaledWidth},0 v-${straightLength} a${radius},${radius} 0 0 0 -${scaledWidth},0 z`,holeElement={name:"path",type:"element",attributes:{class:"pcb-hole",fill:colorMap2.drill,d:pathD,"data-type":"pcb_hole","data-pcb-layer":"drill"},children:[],value:""};if(!shouldShowSolderMask)return[holeElement];let maskWidth=scaledWidth+2*soldermaskMargin,maskHeight=scaledHeight+2*soldermaskMargin,maskIsHorizontal=maskWidth>maskHeight,maskRadius=Math.min(maskWidth,maskHeight)/2,maskStraightLength=Math.abs(maskIsHorizontal?maskWidth-maskHeight:maskHeight-maskWidth),maskPathD=maskIsHorizontal?`M${x4-maskStraightLength/2},${y4-maskRadius} h${maskStraightLength} a${maskRadius},${maskRadius} 0 0 1 0,${maskHeight} h-${maskStraightLength} a${maskRadius},${maskRadius} 0 0 1 0,-${maskHeight} z`:`M${x4-maskRadius},${y4-maskStraightLength/2} v${maskStraightLength} a${maskRadius},${maskRadius} 0 0 0 ${maskWidth},0 v-${maskStraightLength} a${maskRadius},${maskRadius} 0 0 0 -${maskWidth},0 z`;if(soldermaskMargin<0){let coveredElement={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-hole-covered",fill:solderMaskColor,d:pathD,"data-type":"pcb_hole","data-pcb-layer":"drill"}},exposedElement={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-hole-exposed",fill:colorMap2.drill,d:maskPathD,"data-type":"pcb_soldermask","data-pcb-layer":"drill"}};return[coveredElement,exposedElement]}return[{name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,d:maskPathD,"data-type":"pcb_soldermask_opening","data-pcb-layer":layer}},holeElement]}if(hole.hole_shape==="rotated_pill"){let scaledWidth=hole.hole_width*Math.abs(transform6.a),scaledHeight=hole.hole_height*Math.abs(transform6.a),rotation5="ccw_rotation"in hole?hole.ccw_rotation??0:0,isHorizontal3=scaledWidth>scaledHeight,radius=Math.min(scaledWidth,scaledHeight)/2,straightLength=Math.abs(isHorizontal3?scaledWidth-scaledHeight:scaledHeight-scaledWidth),pathD=isHorizontal3?`M${-straightLength/2},${-radius} h${straightLength} a${radius},${radius} 0 0 1 0,${scaledHeight} h-${straightLength} a${radius},${radius} 0 0 1 0,-${scaledHeight} z`:`M${-radius},${-straightLength/2} v${straightLength} a${radius},${radius} 0 0 0 ${scaledWidth},0 v-${straightLength} a${radius},${radius} 0 0 0 -${scaledWidth},0 z`,holeElement={name:"path",type:"element",attributes:{class:"pcb-hole",fill:colorMap2.drill,d:pathD,transform:`translate(${x4} ${y4}) rotate(${-rotation5})`,"data-type":"pcb_hole","data-pcb-layer":"drill"},children:[],value:""};if(!shouldShowSolderMask)return[holeElement];let maskWidth=scaledWidth+2*soldermaskMargin,maskHeight=scaledHeight+2*soldermaskMargin,maskIsHorizontal=maskWidth>maskHeight,maskRadius=Math.min(maskWidth,maskHeight)/2,maskStraightLength=Math.abs(maskIsHorizontal?maskWidth-maskHeight:maskHeight-maskWidth),maskPathD=maskIsHorizontal?`M${-maskStraightLength/2},${-maskRadius} h${maskStraightLength} a${maskRadius},${maskRadius} 0 0 1 0,${maskHeight} h-${maskStraightLength} a${maskRadius},${maskRadius} 0 0 1 0,-${maskHeight} z`:`M${-maskRadius},${-maskStraightLength/2} v${maskStraightLength} a${maskRadius},${maskRadius} 0 0 0 ${maskWidth},0 v-${maskStraightLength} a${maskRadius},${maskRadius} 0 0 0 -${maskWidth},0 z`;if(soldermaskMargin<0){let coveredElement={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-hole-covered",fill:solderMaskColor,d:pathD,transform:`translate(${x4} ${y4}) rotate(${-rotation5})`,"data-type":"pcb_hole","data-pcb-layer":"drill"}},exposedElement={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-hole-exposed",fill:colorMap2.drill,d:maskPathD,transform:`translate(${x4} ${y4}) rotate(${-rotation5})`,"data-type":"pcb_soldermask","data-pcb-layer":"drill"}};return[coveredElement,exposedElement]}return[{name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,d:maskPathD,"data-type":"pcb_soldermask_opening","data-pcb-layer":layer}},holeElement]}return[]}function createSvgObjectsForRatsNest(circuitJson,ctx){let{transform:transform6}=ctx,connectivity=getFullConnectivityMapFromCircuitJson(circuitJson),pcbPorts=circuitJson.filter(elm=>elm.type==="pcb_port"),sourceTraces=circuitJson.filter(elm=>elm.type==="source_trace"),ratsNestLines=[];pcbPorts.forEach((port,index)=>{let portId=port.pcb_port_id;if(!portId)return;let netId=connectivity.getNetConnectedToId(portId);if(!netId)return;let isInNet=!1,sourcePort=su2(circuitJson).source_port.getWhere({pcb_port_id:portId});if(sourcePort&&sourcePort.source_port_id){let sourcePortId=sourcePort.source_port_id;for(let trace of sourceTraces)if(Array.isArray(trace.connected_source_port_ids)&&trace.connected_source_port_ids.includes(sourcePortId)&&Array.isArray(trace.connected_source_net_ids)&&trace.connected_source_net_ids.length>0){isInNet=!0;break}}let startPoint={x:port.x,y:port.y},nearestPoint=findNearestPointInNet(startPoint,netId,connectivity,circuitJson);nearestPoint&&ratsNestLines.push({key:`${portId}-${index}`,startPoint,endPoint:nearestPoint,isInNet})});let svgObjects=[];for(let line2 of ratsNestLines){let transformedStart=applyToPoint3(transform6,[line2.startPoint.x,line2.startPoint.y]),transformedEnd=applyToPoint3(transform6,[line2.endPoint.x,line2.endPoint.y]),attributes2={x1:transformedStart[0].toString(),y1:transformedStart[1].toString(),x2:transformedEnd[0].toString(),y2:transformedEnd[1].toString(),stroke:"white","stroke-width":"1","stroke-dasharray":"6,6","data-type":"pcb_rats_nest","data-pcb-layer":"overlay"};svgObjects.push({name:"line",type:"element",attributes:attributes2,value:"",children:[]})}return svgObjects}function createSvgObjectsFromPcbCutout(cutout,ctx){let{transform:transform6,colorMap:colorMap2}=ctx;if(cutout.shape==="rect"){let rectCutout=cutout,[cx3,cy3]=applyToPoint3(transform6,[rectCutout.center.x,rectCutout.center.y]),scaledWidth=rectCutout.width*Math.abs(transform6.a),scaledHeight=rectCutout.height*Math.abs(transform6.d),svgRotation=-(rectCutout.rotation??0),{corner_radius}=rectCutout,baseCornerRadius=typeof corner_radius=="number"&&corner_radius>0?corner_radius:0,transformedCornerRadiusX=baseCornerRadius*Math.abs(transform6.a),transformedCornerRadiusY=baseCornerRadius*Math.abs(transform6.d),attributes2={class:"pcb-cutout pcb-cutout-rect",x:(-scaledWidth/2).toString(),y:(-scaledHeight/2).toString(),width:scaledWidth.toString(),height:scaledHeight.toString(),fill:colorMap2.drill,transform:toString2(compose3(translate3(cx3,cy3),rotate3(svgRotation*Math.PI/180))),"data-type":"pcb_cutout","data-pcb-layer":"drill"};return transformedCornerRadiusX>0&&(attributes2.rx=transformedCornerRadiusX.toString()),transformedCornerRadiusY>0&&(attributes2.ry=transformedCornerRadiusY.toString()),[{name:"rect",type:"element",attributes:attributes2,children:[],value:""}]}if(cutout.shape==="circle"){let circleCutout=cutout,[cx3,cy3]=applyToPoint3(transform6,[circleCutout.center.x,circleCutout.center.y]),scaledRadius=circleCutout.radius*Math.abs(transform6.a);return[{name:"circle",type:"element",attributes:{class:"pcb-cutout pcb-cutout-circle",cx:cx3.toString(),cy:cy3.toString(),r:scaledRadius.toString(),fill:colorMap2.drill,"data-type":"pcb_cutout","data-pcb-layer":"drill"},children:[],value:""}]}if(cutout.shape==="polygon"){let polygonCutout=cutout;return!polygonCutout.points||polygonCutout.points.length===0?[]:[{name:"polygon",type:"element",attributes:{class:"pcb-cutout pcb-cutout-polygon",points:polygonCutout.points.map(p4=>applyToPoint3(transform6,[p4.x,p4.y])).map(p4=>`${p4[0]},${p4[1]}`).join(" "),fill:colorMap2.drill,"data-type":"pcb_cutout","data-pcb-layer":"drill"},children:[],value:""}]}return[]}function createSvgObjectsFromPcbCutoutPath(cutoutPath,ctx){let{transform:transform6,colorMap:colorMap2}=ctx;if(!cutoutPath.route||!Array.isArray(cutoutPath.route))return[];let firstPoint=cutoutPath.route[0],lastPoint=cutoutPath.route[cutoutPath.route.length-1],isClosed=firstPoint&&lastPoint&&firstPoint.x===lastPoint.x&&firstPoint.y===lastPoint.y;return[{name:"path",type:"element",attributes:{class:"pcb-cutout pcb-cutout-path",d:cutoutPath.route.slice(0,isClosed?-1:void 0).map((point7,index)=>{let[x4,y4]=applyToPoint3(transform6,[point7.x,point7.y]);return index===0?`M ${x4} ${y4}`:`L ${x4} ${y4}`}).join(" ")+(isClosed?" Z":""),fill:colorMap2.drill,"data-type":"pcb_cutout_path","data-pcb-cutout-id":cutoutPath.pcb_cutout_id,"data-pcb-layer":"drill"},value:"",children:[]}]}function createKeepoutPatternLines(keepoutColor){let patternLines=[];for(let i3=-KEEPOUT_PATTERN_SIZE;i3<=KEEPOUT_PATTERN_SIZE;i3+=KEEPOUT_LINE_SPACING)patternLines.push({name:"line",type:"element",value:"",attributes:{x1:i3.toString(),y1:"0",x2:(i3+KEEPOUT_PATTERN_SIZE).toString(),y2:KEEPOUT_PATTERN_SIZE.toString(),stroke:keepoutColor,"stroke-width":"1"},children:[]});return patternLines}function createKeepoutPatternDefs(keepoutColor){return{name:"defs",type:"element",value:"",attributes:{},children:[{name:"pattern",type:"element",value:"",attributes:{id:KEEPOUT_PATTERN_ID,width:KEEPOUT_PATTERN_SIZE.toString(),height:KEEPOUT_PATTERN_SIZE.toString(),patternUnits:"userSpaceOnUse"},children:createKeepoutPatternLines(keepoutColor)}]}}function createKeepoutBaseAttributes(keepoutId,layer,shapeClass,description){let attributes2={class:`pcb-keepout ${shapeClass} pcb-keepout-background`,"data-type":"pcb_keepout","data-pcb-layer":layer,"data-pcb-keepout-id":keepoutId,stroke:"none"};return description&&(attributes2["data-description"]=description),attributes2}function createKeepoutPatternAttributes(keepoutId,layer,shapeClass,description){let attributes2={class:`pcb-keepout ${shapeClass} pcb-keepout-pattern`,fill:`url(#${KEEPOUT_PATTERN_ID})`,"data-type":"pcb_keepout","data-pcb-layer":layer,"data-pcb-keepout-id":keepoutId,stroke:"none"};return description&&(attributes2["data-description"]=description),attributes2}function createSvgObjectsFromPcbKeepout(keepout,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2}=ctx;if(layerFilter&&!keepout.layers.includes(layerFilter))return[];let svgObjects=[],keepoutColor=colorMap2.keepout;for(let layer of keepout.layers)if(!(layerFilter&&layer!==layerFilter)){if(keepout.shape==="rect"){let rectKeepout=keepout,[cx3,cy3]=applyToPoint3(transform6,[rectKeepout.center.x,rectKeepout.center.y]),scaledWidth=rectKeepout.width*Math.abs(transform6.a),scaledHeight=rectKeepout.height*Math.abs(transform6.d),baseTransform=toString2(compose3(translate3(cx3,cy3))),backgroundAttributes={...createKeepoutBaseAttributes(rectKeepout.pcb_keepout_id,layer,"pcb-keepout-rect",rectKeepout.description),x:(-scaledWidth/2).toString(),y:(-scaledHeight/2).toString(),width:scaledWidth.toString(),height:scaledHeight.toString(),fill:KEEPOUT_BACKGROUND_COLOR,transform:baseTransform},patternAttributes={...createKeepoutPatternAttributes(rectKeepout.pcb_keepout_id,layer,"pcb-keepout-rect",rectKeepout.description),x:(-scaledWidth/2).toString(),y:(-scaledHeight/2).toString(),width:scaledWidth.toString(),height:scaledHeight.toString(),transform:baseTransform};svgObjects.push({name:"rect",type:"element",attributes:backgroundAttributes,children:[],value:""},{name:"rect",type:"element",attributes:patternAttributes,children:[],value:""})}else if(keepout.shape==="circle"){let circleKeepout=keepout,[cx3,cy3]=applyToPoint3(transform6,[circleKeepout.center.x,circleKeepout.center.y]),scaledRadius=circleKeepout.radius*Math.abs(transform6.a),backgroundAttributes={...createKeepoutBaseAttributes(circleKeepout.pcb_keepout_id,layer,"pcb-keepout-circle",circleKeepout.description),cx:cx3.toString(),cy:cy3.toString(),r:scaledRadius.toString(),fill:KEEPOUT_BACKGROUND_COLOR},patternAttributes={...createKeepoutPatternAttributes(circleKeepout.pcb_keepout_id,layer,"pcb-keepout-circle",circleKeepout.description),cx:cx3.toString(),cy:cy3.toString(),r:scaledRadius.toString()};svgObjects.push({name:"circle",type:"element",attributes:backgroundAttributes,children:[],value:""},{name:"circle",type:"element",attributes:patternAttributes,children:[],value:""})}}return svgObjects}function ringToPathD(vertices,transform6){if(vertices.length===0)return"";let transformedVertices=vertices.map(v4=>{let[x4,y4]=applyToPoint3(transform6,[v4.x,v4.y]);return{...v4,x:x4,y:y4}}),d4=`M ${transformedVertices[0].x} ${transformedVertices[0].y}`;for(let i3=0;i3<transformedVertices.length;i3++){let start=transformedVertices[i3],end=transformedVertices[(i3+1)%transformedVertices.length];if(start.bulge){if(Math.hypot(end.x-start.x,end.y-start.y)<1e-9)continue;let bulge=start.bulge,dx3=end.x-start.x,dy3=end.y-start.y,dist=Math.hypot(dx3,dy3),radius=Math.abs(dist/4/bulge*(bulge*bulge+1)),sweepFlag=bulge<0?1:0,largeArcFlag=Math.abs(bulge)>1?1:0;d4+=` A ${radius} ${radius} 0 ${largeArcFlag} ${sweepFlag} ${end.x} ${end.y}`}else d4+=` L ${end.x} ${end.y}`}return d4+=" Z",d4}function createSoldermaskCutoutElement({elementType,shapeAttributes,layer,colorMap:colorMap2,additionalAttributes}){let baseAttributes={class:"pcb-soldermask-cutout",fill:colorMap2.substrate,"data-type":"pcb_soldermask_opening","data-pcb-layer":layer,...shapeAttributes,...additionalAttributes};return{name:elementType,type:"element",value:"",children:[],attributes:baseAttributes}}function createSoldermaskOverlayElement({elementType,shapeAttributes,layer,fillColor,fillOpacity,className,additionalAttributes}){let baseAttributes={class:className,fill:fillColor,"fill-opacity":fillOpacity,"data-type":"pcb_soldermask","data-pcb-layer":layer,...shapeAttributes,...additionalAttributes};return{name:elementType,type:"element",value:"",children:[],attributes:baseAttributes}}function createSvgObjectsFromPcbCopperPour(pour,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2,showSolderMask}=ctx,{layer}=pour;if(layerFilter&&layer!==layerFilter)return[];let color=layerNameToColor(layer,colorMap2),opacity="0.5",isCoveredWithSolderMask=pour.covered_with_solder_mask!==!1,maskOverlayColor=layer==="bottom"?colorMap2.soldermaskOverCopper.bottom:colorMap2.soldermaskOverCopper.top,maskOverlayOpacity="0.9";if(pour.shape==="rect"){let[cx3,cy3]=applyToPoint3(transform6,[pour.center.x,pour.center.y]),scaledWidth=pour.width*Math.abs(transform6.a),scaledHeight=pour.height*Math.abs(transform6.d),svgRotation=-(pour.rotation??0),rectAttributes={x:(-scaledWidth/2).toString(),y:(-scaledHeight/2).toString(),width:scaledWidth.toString(),height:scaledHeight.toString(),transform:toString2(compose3(translate3(cx3,cy3),rotate3(svgRotation*Math.PI/180)))},copperRect={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-copper-pour pcb-copper-pour-rect",...rectAttributes,fill:color,"fill-opacity":opacity,"data-type":"pcb_copper_pour","data-pcb-layer":layer}},maskRect=showSolderMask?isCoveredWithSolderMask?createSoldermaskOverlayElement({elementType:"rect",shapeAttributes:rectAttributes,layer,fillColor:maskOverlayColor,fillOpacity:maskOverlayOpacity,className:"pcb-soldermask-covered-pour"}):createSoldermaskCutoutElement({elementType:"rect",shapeAttributes:rectAttributes,layer,colorMap:colorMap2}):null;return maskRect?!isCoveredWithSolderMask&&pour.pcb_copper_pour_id?.includes("substrate_only")?[maskRect]:[copperRect,maskRect]:[copperRect]}if(pour.shape==="polygon"){if(!pour.points||pour.points.length===0)return[];let pointsString=pour.points.map(p4=>applyToPoint3(transform6,[p4.x,p4.y])).map(p4=>`${p4[0]},${p4[1]}`).join(" "),copperPolygon={name:"polygon",type:"element",value:"",children:[],attributes:{class:"pcb-copper-pour pcb-copper-pour-polygon",points:pointsString,fill:color,"fill-opacity":opacity,"data-type":"pcb_copper_pour","data-pcb-layer":layer}},maskPolygon=showSolderMask?isCoveredWithSolderMask?createSoldermaskOverlayElement({elementType:"polygon",shapeAttributes:{points:pointsString},layer,fillColor:maskOverlayColor,fillOpacity:maskOverlayOpacity,className:"pcb-soldermask-covered-pour"}):createSoldermaskCutoutElement({elementType:"polygon",shapeAttributes:{points:pointsString},layer,colorMap:colorMap2}):null;return maskPolygon?!isCoveredWithSolderMask&&pour.pcb_copper_pour_id?.includes("substrate_only")?[maskPolygon]:[copperPolygon,maskPolygon]:[copperPolygon]}if(pour.shape==="brep"){let{brep_shape:brep_shape3}=pour,d4=ringToPathD(brep_shape3.outer_ring.vertices,transform6);for(let inner_ring of brep_shape3.inner_rings??[])d4+=` ${ringToPathD(inner_ring.vertices,transform6)}`;let copperPath={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-copper-pour pcb-copper-pour-brep",d:d4,fill:color,"fill-rule":"evenodd","fill-opacity":opacity,"data-type":"pcb_copper_pour","data-pcb-layer":layer}},maskPath=showSolderMask?isCoveredWithSolderMask?createSoldermaskOverlayElement({elementType:"path",shapeAttributes:{d:d4,"fill-rule":"evenodd"},layer,fillColor:maskOverlayColor,fillOpacity:maskOverlayOpacity,className:"pcb-soldermask-covered-pour"}):createSoldermaskCutoutElement({elementType:"path",shapeAttributes:{d:d4,"fill-rule":"evenodd"},layer,colorMap:colorMap2}):null;return maskPath?!isCoveredWithSolderMask&&pour.pcb_copper_pour_id?.includes("substrate_only")?[maskPath]:[copperPath,maskPath]:[copperPath]}return[]}function createSvgObjectsForPcbGrid({grid:grid4,svgWidth,svgHeight}){if(!grid4)return{};let gridLineColor=grid4.lineColor??DEFAULT_GRID_LINE_COLOR,gridCellSize=grid4.cellSize,majorCellSize=grid4.majorCellSize,majorLineColor=grid4.majorLineColor??gridLineColor;if(majorCellSize!==void 0){if(!gridCellSize||gridCellSize<=0)throw new Error("grid.majorCellSize requires a positive grid.cellSize");if(majorCellSize<=0)throw new Error("grid.majorCellSize must be a positive multiple of grid.cellSize");let ratio=majorCellSize/gridCellSize,nearestInteger=Math.round(ratio);if(!Number.isFinite(ratio)||Math.abs(ratio-nearestInteger)>1e-6)throw new Error("grid.majorCellSize must be a positive multiple of grid.cellSize")}if(!gridCellSize||gridCellSize<=0)return{};let hasMajorGrid=majorCellSize!==void 0,patternChildren=hasMajorGrid?createMajorGridPatternChildren(gridCellSize,majorCellSize,gridLineColor,majorLineColor):[{name:"path",type:"element",value:"",attributes:{d:`M ${gridCellSize} 0 L 0 0 0 ${gridCellSize}`,fill:"none",stroke:gridLineColor,"stroke-width":"1","shape-rendering":"crispEdges"},children:[]}],defs={name:"defs",type:"element",value:"",attributes:{},children:[{name:"pattern",type:"element",value:"",attributes:{id:GRID_PATTERN_ID,width:hasMajorGrid?majorCellSize.toString():gridCellSize.toString(),height:hasMajorGrid?majorCellSize.toString():gridCellSize.toString(),patternUnits:"userSpaceOnUse"},children:patternChildren}]},rect={name:"rect",type:"element",value:"",attributes:{x:"0",y:"0",width:svgWidth.toString(),height:svgHeight.toString(),fill:`url(#${GRID_PATTERN_ID})`,"pointer-events":"none","data-type":"pcb_grid","data-pcb-layer":"global"},children:[]};return{defs,rect}}function createMajorGridPatternChildren(cellSize,majorCellSize,lineColor,majorLineColor){let children=[],steps=Math.round(majorCellSize/cellSize);for(let step=0;step<steps;step+=1){let offsetString=Number((step*cellSize).toFixed(6)).toString(),color=step===0?majorLineColor:lineColor,majorSizeString=majorCellSize.toString();children.push({name:"line",type:"element",value:"",attributes:{x1:offsetString,y1:"0",x2:offsetString,y2:majorSizeString,stroke:color,"stroke-width":"1","shape-rendering":"crispEdges"},children:[]}),children.push({name:"line",type:"element",value:"",attributes:{x1:"0",y1:offsetString,x2:majorSizeString,y2:offsetString,stroke:color,"stroke-width":"1","shape-rendering":"crispEdges"},children:[]})}return children}function createSvgObjectsFromPcbComponent(component,ctx){let{transform:transform6,circuitJson}=ctx,{center:center2,width,height,rotation:rotation5=0}=component,[x4,y4]=applyToPoint3(transform6,[center2.x,center2.y]),scaledWidth=width*Math.abs(transform6.a),scaledHeight=height*Math.abs(transform6.d),transformStr=`translate(${x4}, ${y4}) rotate(${-rotation5}) scale(1, -1)`,svgObjects=[];if(ctx.showAnchorOffsets&&circuitJson&&component.position_mode==="relative_to_group_anchor"&&(component.positioned_relative_to_pcb_group_id||component.positioned_relative_to_pcb_board_id)){let parentAnchorPosition=getParentAnchorPosition(component,circuitJson);parentAnchorPosition&&svgObjects.push(...createAnchorOffsetIndicators({groupAnchorPosition:parentAnchorPosition,componentPosition:center2,transform:transform6,componentWidth:width,componentHeight:height,displayXOffset:component.display_offset_x,displayYOffset:component.display_offset_y}))}return!ctx.colorMap.debugComponent?.fill&&!ctx.colorMap.debugComponent?.stroke||svgObjects.push({name:"g",type:"element",attributes:{transform:transformStr,"data-type":"pcb_component","data-pcb-layer":component.layer??"top"},children:[{name:"rect",type:"element",attributes:{class:"pcb-component",x:(-scaledWidth/2).toString(),y:(-scaledHeight/2).toString(),width:scaledWidth.toString(),height:scaledHeight.toString(),fill:ctx.colorMap.debugComponent.fill??"transparent",stroke:ctx.colorMap.debugComponent.stroke??"transparent","data-type":"pcb_component","data-pcb-layer":component.layer??"top"}}],value:""}),svgObjects}function getParentAnchorPosition(component,circuitJson){if(component.positioned_relative_to_pcb_group_id){let pcbGroup=circuitJson.find(elm=>elm.type==="pcb_group"&&elm.pcb_group_id===component.positioned_relative_to_pcb_group_id),point7=getPointFromElm(pcbGroup);if(point7)return point7}if(component.positioned_relative_to_pcb_board_id){let pcbBoard=circuitJson.find(elm=>elm.type==="pcb_board"&&elm.pcb_board_id===component.positioned_relative_to_pcb_board_id),point7=getPointFromElm(pcbBoard);if(point7)return point7}}function createSvgObjectsFromPcbGroup(pcbGroup,ctx){let{transform:transform6,circuitJson}=ctx,{center:center2,width,height}=pcbGroup,svgObjects=[];if(ctx.showAnchorOffsets&&pcbGroup.position_mode==="relative_to_group_anchor"&&circuitJson){let parentAnchorPosition=getParentAnchorPosition2(pcbGroup,circuitJson);parentAnchorPosition&&svgObjects.push(...createAnchorOffsetIndicators({groupAnchorPosition:parentAnchorPosition,componentPosition:pcbGroup.anchor_position??pcbGroup.center,transform:transform6,componentWidth:pcbGroup.width,componentHeight:pcbGroup.height,displayXOffset:pcbGroup.display_offset_x,displayYOffset:pcbGroup.display_offset_y}))}let outline=Array.isArray(pcbGroup.outline)?pcbGroup.outline:void 0,transformedStrokeWidth=DEFAULT_STROKE_WIDTH*Math.abs(transform6.a),dashLength=.3*Math.abs(transform6.a),gapLength=.15*Math.abs(transform6.a),baseAttributes={class:"pcb-group",fill:"none",stroke:getGroupColor(pcbGroup.pcb_group_id),"stroke-width":transformedStrokeWidth.toString(),"stroke-dasharray":`${dashLength} ${gapLength}`,"data-type":"pcb_group","data-pcb-group-id":pcbGroup.pcb_group_id,"data-pcb-layer":"overlay"};if(pcbGroup.name&&(baseAttributes["data-group-name"]=pcbGroup.name),outline&&outline.length>=3&&outline.every(point7=>point7&&typeof point7.x=="number"&&typeof point7.y=="number")){let path=outline.map((point7,index)=>{let[x4,y4]=applyToPoint3(transform6,[point7.x,point7.y]);return index===0?`M ${x4} ${y4}`:`L ${x4} ${y4}`}).join(" ");return svgObjects.push({name:"path",type:"element",value:"",children:[],attributes:{...baseAttributes,d:`${path} Z`}}),svgObjects}if(!center2||typeof center2.x!="number"||typeof center2.y!="number"||typeof width!="number"||typeof height!="number")return debugPcb(`[pcb_group] Invalid data for "${pcbGroup.pcb_group_id}"${pcbGroup.name?` (name: "${pcbGroup.name}")`:""}: expected center {x: number, y: number}, width: number, height: number, got center=${JSON.stringify(center2)}, width=${JSON.stringify(width)}, height=${JSON.stringify(height)}`),svgObjects;let halfWidth=width/2,halfHeight=height/2,[topLeftX,topLeftY]=applyToPoint3(transform6,[center2.x-halfWidth,center2.y+halfHeight]),[bottomRightX,bottomRightY]=applyToPoint3(transform6,[center2.x+halfWidth,center2.y-halfHeight]),rectX=Math.min(topLeftX,bottomRightX),rectY=Math.min(topLeftY,bottomRightY),rectWidth=Math.abs(bottomRightX-topLeftX),rectHeight=Math.abs(bottomRightY-topLeftY),svgObject={name:"rect",type:"element",value:"",attributes:{...baseAttributes,x:rectX.toString(),y:rectY.toString(),width:rectWidth.toString(),height:rectHeight.toString()},children:[]};return svgObjects.push(svgObject),svgObjects}function getGroupColor(pcbGroupId){let match2=pcbGroupId.match(/(\d+)$/),index=match2?Number.parseInt(match2[1],10):0;return GROUP_COLOR_PALETTE[index%GROUP_COLOR_PALETTE.length]}function getParentAnchorPosition2(group,circuitJson){if(group.positioned_relative_to_pcb_group_id){let pcbGroup=circuitJson.find(elm=>elm.type==="pcb_group"&&elm.pcb_group_id===group.positioned_relative_to_pcb_group_id),point7=getPointFromElm(pcbGroup);if(point7)return point7}if(group.positioned_relative_to_pcb_board_id){let pcbBoard=circuitJson.find(elm=>elm.type==="pcb_board"&&elm.pcb_board_id===group.positioned_relative_to_pcb_board_id),point7=getPointFromElm(pcbBoard);if(point7)return point7}}function getSoftwareUsedString(circuitJson){return circuitJson.find(e5=>e5.type==="project_software_metadata"||e5.type==="source_project_metadata")?.software_used_string}function sortSvgObjectsByPcbLayer(objects){return objects.map((object,index)=>({object,index,layerPriority:getLayerPriority(object.attributes?.["data-pcb-layer"]??void 0),typePriority:getTypePriority(object.attributes?.["data-type"]??void 0)})).sort((a3,b3)=>a3.layerPriority!==b3.layerPriority?a3.layerPriority-b3.layerPriority:a3.typePriority!==b3.typePriority?a3.typePriority-b3.typePriority:a3.index-b3.index).map(({object})=>object)}function getLayerPriority(layer){if(!layer)return 500;let normalized=layer.toLowerCase();if(normalized==="global")return-100;if(normalized==="bottom")return 4;if(normalized==="board")return 2;if(normalized==="soldermask-top"||normalized==="soldermask-bottom")return 3;if(normalized.startsWith("inner")){let match2=normalized.match(/\d+/);return 5+(match2?Number.parseInt(match2[0],10):0)}return normalized==="through"?18:normalized==="top"?17:normalized==="drill"?30:normalized==="overlay"?40:10}function getTypePriority(type){return type?TYPE_PRIORITY[type]??DEFAULT_TYPE_PRIORITY:DEFAULT_TYPE_PRIORITY}function createErrorTextOverlay(circuitJson,dataType="error_text_overlay"){let errorElms=circuitJson.filter(elm=>elm.type.endsWith("_error"));if(errorElms.length===0)return null;let errorMessages=errorElms.map(e5=>e5.message).filter(m4=>!!m4);return errorMessages.length===0?null:{name:"text",type:"element",value:"",attributes:{x:"10",y:"20",fill:"red","font-family":"monospace","font-size":"12px","data-type":dataType,"data-layer":"global"},children:errorMessages.map((msg,i3)=>({name:"tspan",type:"element",value:"",attributes:{x:"10",dy:i3===0?"0":"1.2em"},children:[{type:"text",value:msg,name:"",attributes:{},children:[]}]}))}}function getPcbBoundsFromCircuitJson(circuitJson){let minX=Number.POSITIVE_INFINITY,minY=Number.POSITIVE_INFINITY,maxX=Number.NEGATIVE_INFINITY,maxY=Number.NEGATIVE_INFINITY,hasBounds2=!1,boardMinX=Number.POSITIVE_INFINITY,boardMinY=Number.POSITIVE_INFINITY,boardMaxX=Number.NEGATIVE_INFINITY,boardMaxY=Number.NEGATIVE_INFINITY,hasBoardBounds=!1;for(let circuitJsonElm of circuitJson)if(circuitJsonElm.type==="pcb_panel"){let panel=circuitJsonElm,width=distance.parse(panel.width),height=distance.parse(panel.height);if(width===void 0||height===void 0)continue;let center2=panel.center??{x:width/2,y:height/2};updateBounds({center:center2,width,height})}else if(circuitJsonElm.type==="pcb_board")circuitJsonElm.outline&&Array.isArray(circuitJsonElm.outline)&&circuitJsonElm.outline.length>=3?(updateBoundsToIncludeOutline(circuitJsonElm.outline),updateBoardBoundsToIncludeOutline(circuitJsonElm.outline)):"center"in circuitJsonElm&&"width"in circuitJsonElm&&"height"in circuitJsonElm&&(updateBounds({center:circuitJsonElm.center,width:circuitJsonElm.width,height:circuitJsonElm.height}),updateBoardBounds({center:circuitJsonElm.center,width:circuitJsonElm.width,height:circuitJsonElm.height}));else if(circuitJsonElm.type==="pcb_smtpad"){let pad2=circuitJsonElm;if(pad2.shape==="rect"||pad2.shape==="rotated_rect"||pad2.shape==="pill")updateBounds({center:{x:pad2.x,y:pad2.y},width:pad2.width,height:pad2.height});else if(pad2.shape==="circle"){let radius=distance.parse(pad2.radius);radius!==void 0&&updateBounds({center:{x:pad2.x,y:pad2.y},width:radius*2,height:radius*2})}else pad2.shape==="polygon"&&updateTraceBounds(pad2.points)}else if("x"in circuitJsonElm&&"y"in circuitJsonElm)updateBounds({center:{x:circuitJsonElm.x,y:circuitJsonElm.y},width:0,height:0});else if("route"in circuitJsonElm)updateTraceBounds(circuitJsonElm.route);else if(circuitJsonElm.type==="pcb_note_rect"||circuitJsonElm.type==="pcb_fabrication_note_rect")updateBounds({center:circuitJsonElm.center,width:circuitJsonElm.width,height:circuitJsonElm.height});else if(circuitJsonElm.type==="pcb_note_dimension"||circuitJsonElm.type==="pcb_fabrication_note_dimension"){let dimension=circuitJsonElm,{from,to:to3,text,font_size=1,arrow_size,offset_distance,offset_direction}=dimension;if(!from||!to3||!arrow_size)continue;updateBounds({center:from,width:0,height:0}),updateBounds({center:to3,width:0,height:0});let normalize3=v4=>{let l4=Math.hypot(v4.x,v4.y)||1;return{x:v4.x/l4,y:v4.y/l4}},direction2=normalize3({x:to3.x-from.x,y:to3.y-from.y});if(Number.isNaN(direction2.x)||Number.isNaN(direction2.y))continue;let perpendicular={x:-direction2.y,y:direction2.x},hasOffsetDirection=offset_direction&&typeof offset_direction.x=="number"&&typeof offset_direction.y=="number",normalizedOffsetDirection=hasOffsetDirection?normalize3(offset_direction):{x:0,y:0},offsetMagnitude=typeof offset_distance=="number"?offset_distance:0,offsetVector={x:normalizedOffsetDirection.x*offsetMagnitude,y:normalizedOffsetDirection.y*offsetMagnitude},fromOffset={x:from.x+offsetVector.x,y:from.y+offsetVector.y},toOffset={x:to3.x+offsetVector.x,y:to3.y+offsetVector.y};updateBounds({center:fromOffset,width:0,height:0}),updateBounds({center:toOffset,width:0,height:0});let extensionDirection=hasOffsetDirection&&(Math.abs(normalizedOffsetDirection.x)>Number.EPSILON||Math.abs(normalizedOffsetDirection.y)>Number.EPSILON)?normalizedOffsetDirection:perpendicular,extensionLength=offsetMagnitude+arrow_size,fromExtEnd={x:from.x+extensionDirection.x*extensionLength,y:from.y+extensionDirection.y*extensionLength},toExtEnd={x:to3.x+extensionDirection.x*extensionLength,y:to3.y+extensionDirection.y*extensionLength};updateBounds({center:fromExtEnd,width:0,height:0}),updateBounds({center:toExtEnd,width:0,height:0});let arrowHalfWidth=arrow_size/2,fromBase={x:fromOffset.x+direction2.x*arrow_size,y:fromOffset.y+direction2.y*arrow_size},toBase={x:toOffset.x-direction2.x*arrow_size,y:toOffset.y-direction2.y*arrow_size},fromArrowP2={x:fromBase.x+perpendicular.x*arrowHalfWidth,y:fromBase.y+perpendicular.y*arrowHalfWidth},fromArrowP3={x:fromBase.x-perpendicular.x*arrowHalfWidth,y:fromBase.y-perpendicular.y*arrowHalfWidth};updateBounds({center:fromArrowP2,width:0,height:0}),updateBounds({center:fromArrowP3,width:0,height:0});let toArrowP2={x:toBase.x+perpendicular.x*arrowHalfWidth,y:toBase.y+perpendicular.y*arrowHalfWidth},toArrowP3={x:toBase.x-perpendicular.x*arrowHalfWidth,y:toBase.y-perpendicular.y*arrowHalfWidth};if(updateBounds({center:toArrowP2,width:0,height:0}),updateBounds({center:toArrowP3,width:0,height:0}),text){let midPoint2={x:(from.x+to3.x)/2+offsetVector.x,y:(from.y+to3.y)/2+offsetVector.y},textOffset=arrow_size*1.5,textPoint={x:midPoint2.x+perpendicular.x*textOffset,y:midPoint2.y+perpendicular.y*textOffset},textWidth=text.length*font_size*.6;updateBounds({center:textPoint,width:textWidth,height:font_size})}}else if(circuitJsonElm.type==="pcb_cutout"){let cutout=circuitJsonElm;if(cutout.shape==="rect")updateBounds({center:cutout.center,width:cutout.width,height:cutout.height});else if(cutout.shape==="circle"){let radius=distance.parse(cutout.radius);radius!==void 0&&updateBounds({center:cutout.center,width:radius*2,height:radius*2})}else if(cutout.shape==="polygon")updateTraceBounds(cutout.points);else if(cutout.shape==="path"){let cutoutPath=cutout;cutoutPath.route&&Array.isArray(cutoutPath.route)&&updateTraceBounds(cutoutPath.route)}}else if(circuitJsonElm.type==="pcb_keepout"){let keepout=circuitJsonElm;if(keepout.shape==="rect")updateBounds({center:keepout.center,width:keepout.width,height:keepout.height});else if(keepout.shape==="circle"){let radius=typeof keepout.radius=="number"?keepout.radius:distance.parse(keepout.radius)??0;radius>0&&updateBounds({center:keepout.center,width:radius*2,height:radius*2})}}else circuitJsonElm.type==="pcb_silkscreen_text"||circuitJsonElm.type==="pcb_silkscreen_rect"||circuitJsonElm.type==="pcb_silkscreen_circle"||circuitJsonElm.type==="pcb_silkscreen_line"||circuitJsonElm.type==="pcb_silkscreen_oval"?updateSilkscreenBounds(circuitJsonElm):circuitJsonElm.type==="pcb_copper_text"?updateBounds({center:circuitJsonElm.anchor_position,width:0,height:0}):circuitJsonElm.type==="pcb_copper_pour"&&(circuitJsonElm.shape==="rect"?updateBounds({center:circuitJsonElm.center,width:circuitJsonElm.width,height:circuitJsonElm.height}):circuitJsonElm.shape==="polygon"&&updateTraceBounds(circuitJsonElm.points));return{minX,minY,maxX,maxY,boardMinX,boardMinY,boardMaxX,boardMaxY,hasBounds:hasBounds2,hasBoardBounds};function updateBounds({center:center2,width,height}){if(!center2)return;let centerX=distance.parse(center2.x),centerY=distance.parse(center2.y);if(centerX===void 0||centerY===void 0)return;let numericWidth=distance.parse(width)??0,numericHeight=distance.parse(height)??0,halfWidth=numericWidth/2,halfHeight=numericHeight/2;minX=Math.min(minX,centerX-halfWidth),minY=Math.min(minY,centerY-halfHeight),maxX=Math.max(maxX,centerX+halfWidth),maxY=Math.max(maxY,centerY+halfHeight),hasBounds2=!0}function updateBoardBounds({center:center2,width,height}){if(!center2)return;let centerX=distance.parse(center2.x),centerY=distance.parse(center2.y);if(centerX===void 0||centerY===void 0)return;let numericWidth=distance.parse(width)??0,numericHeight=distance.parse(height)??0,halfWidth=numericWidth/2,halfHeight=numericHeight/2;boardMinX=Math.min(boardMinX,centerX-halfWidth),boardMinY=Math.min(boardMinY,centerY-halfHeight),boardMaxX=Math.max(boardMaxX,centerX+halfWidth),boardMaxY=Math.max(boardMaxY,centerY+halfHeight),hasBounds2=!0,hasBoardBounds=!0}function updateBoundsToIncludeOutline(outline){let updated=!1;for(let point7 of outline){let x4=distance.parse(point7.x),y4=distance.parse(point7.y);x4===void 0||y4===void 0||(minX=Math.min(minX,x4),minY=Math.min(minY,y4),maxX=Math.max(maxX,x4),maxY=Math.max(maxY,y4),updated=!0)}updated&&(hasBounds2=!0)}function updateBoardBoundsToIncludeOutline(outline){let updated=!1;for(let point7 of outline){let x4=distance.parse(point7.x),y4=distance.parse(point7.y);x4===void 0||y4===void 0||(boardMinX=Math.min(boardMinX,x4),boardMinY=Math.min(boardMinY,y4),boardMaxX=Math.max(boardMaxX,x4),boardMaxY=Math.max(boardMaxY,y4),updated=!0)}updated&&(hasBounds2=!0,hasBoardBounds=!0)}function updateTraceBounds(route){let updated=!1;for(let point7 of route)for(let anchor of getTracePoints(point7)){let x4=distance.parse(anchor.x),y4=distance.parse(anchor.y);x4===void 0||y4===void 0||(minX=Math.min(minX,x4),minY=Math.min(minY,y4),maxX=Math.max(maxX,x4),maxY=Math.max(maxY,y4),updated=!0)}updated&&(hasBounds2=!0)}function getTracePoints(point7){return"route_type"in point7?getPcbTracePoints(point7):[point7]}function updateSilkscreenBounds(item){if(item.type==="pcb_silkscreen_text")updateBounds({center:item.anchor_position,width:0,height:0});else if(item.type==="pcb_silkscreen_path")updateTraceBounds(item.route);else if(item.type==="pcb_silkscreen_rect")updateBounds({center:item.center,width:item.width,height:item.height});else if(item.type==="pcb_silkscreen_circle"){let radius=distance.parse(item.radius);radius!==void 0&&updateBounds({center:item.center,width:radius*2,height:radius*2})}else if(item.type==="pcb_silkscreen_line")updateBounds({center:{x:item.x1,y:item.y1},width:0,height:0}),updateBounds({center:{x:item.x2,y:item.y2},width:0,height:0});else if(item.type==="pcb_silkscreen_oval"){let radiusX=distance.parse(item.radius_x),radiusY=distance.parse(item.radius_y);radiusX!==void 0&&radiusY!==void 0&&updateBounds({center:item.center,width:radiusX*2,height:radiusY*2})}else if(item.type==="pcb_cutout"){let cutout=item;if(cutout.shape==="rect")updateBounds({center:cutout.center,width:cutout.width,height:cutout.height});else if(cutout.shape==="circle"){let radius=distance.parse(cutout.radius);radius!==void 0&&updateBounds({center:cutout.center,width:radius*2,height:radius*2})}else if(cutout.shape==="polygon")updateTraceBounds(cutout.points);else if(cutout.shape==="path"){let cutoutPath=cutout;cutoutPath.route&&Array.isArray(cutoutPath.route)&&updateTraceBounds(cutoutPath.route)}}}}function rectBounds(center2,width,height){if(!center2||width===void 0||height===void 0)return;let cx3=distance.parse(center2.x),cy3=distance.parse(center2.y);if(cx3===void 0||cy3===void 0)return;let numericWidth=distance.parse(width),numericHeight=distance.parse(height);if(numericWidth===void 0||numericHeight===void 0)return;let halfW=numericWidth/2,halfH=numericHeight/2;return{minX:cx3-halfW,minY:cy3-halfH,maxX:cx3+halfW,maxY:cy3+halfH}}function getOutlineBounds(outline){if(!outline||outline.length<3)return;let minX=Number.POSITIVE_INFINITY,minY=Number.POSITIVE_INFINITY,maxX=Number.NEGATIVE_INFINITY,maxY=Number.NEGATIVE_INFINITY;for(let pt3 of outline){let x4=distance.parse(pt3.x),y4=distance.parse(pt3.y);x4===void 0||y4===void 0||(minX=Math.min(minX,x4),minY=Math.min(minY,y4),maxX=Math.max(maxX,x4),maxY=Math.max(maxY,y4))}if(!(!Number.isFinite(minX)||!Number.isFinite(minY))&&!(!Number.isFinite(maxX)||!Number.isFinite(maxY)))return{minX,minY,maxX,maxY}}function convertCircuitJsonToPcbSvg(circuitJson,options){let drawPaddingOutsideBoard=options?.drawPaddingOutsideBoard??!0,layer=options?.layer,colorOverrides=options?.colorOverrides,copperColors={...DEFAULT_PCB_COLOR_MAP.copper};if(colorOverrides?.copper)for(let[layerName,color]of Object.entries(colorOverrides.copper))color!==void 0&&(copperColors[layerName]=color);let colorMap2={copper:copperColors,drill:colorOverrides?.drill??DEFAULT_PCB_COLOR_MAP.drill,silkscreen:{top:colorOverrides?.silkscreen?.top??DEFAULT_PCB_COLOR_MAP.silkscreen.top,bottom:colorOverrides?.silkscreen?.bottom??DEFAULT_PCB_COLOR_MAP.silkscreen.bottom},boardOutline:colorOverrides?.boardOutline??DEFAULT_PCB_COLOR_MAP.boardOutline,soldermask:{top:colorOverrides?.soldermask?.top??DEFAULT_PCB_COLOR_MAP.soldermask.top,bottom:colorOverrides?.soldermask?.bottom??DEFAULT_PCB_COLOR_MAP.soldermask.bottom},soldermaskOverCopper:{top:colorOverrides?.soldermaskOverCopper?.top??DEFAULT_PCB_COLOR_MAP.soldermaskOverCopper.top,bottom:colorOverrides?.soldermaskOverCopper?.bottom??DEFAULT_PCB_COLOR_MAP.soldermaskOverCopper.bottom},soldermaskWithCopperUnderneath:{top:colorOverrides?.soldermaskWithCopperUnderneath?.top??DEFAULT_PCB_COLOR_MAP.soldermaskWithCopperUnderneath.top,bottom:colorOverrides?.soldermaskWithCopperUnderneath?.bottom??DEFAULT_PCB_COLOR_MAP.soldermaskWithCopperUnderneath.bottom},substrate:colorOverrides?.substrate??DEFAULT_PCB_COLOR_MAP.substrate,courtyard:{top:colorOverrides?.courtyard?.top??DEFAULT_PCB_COLOR_MAP.courtyard.top,bottom:colorOverrides?.courtyard?.bottom??DEFAULT_PCB_COLOR_MAP.courtyard.bottom},keepout:colorOverrides?.keepout??DEFAULT_PCB_COLOR_MAP.keepout,debugComponent:{fill:colorOverrides?.debugComponent?.fill??DEFAULT_PCB_COLOR_MAP.debugComponent.fill,stroke:colorOverrides?.debugComponent?.stroke??DEFAULT_PCB_COLOR_MAP.debugComponent.stroke}},{minX,minY,maxX,maxY,boardMinX,boardMinY,boardMaxX,boardMaxY,hasBoardBounds}=getPcbBoundsFromCircuitJson(circuitJson),{boundsMinX,boundsMinY,boundsMaxX,boundsMaxY,padding}=getViewportBounds({circuitJson,drawPaddingOutsideBoard,baseBounds:{minX,minY,maxX,maxY,boardMinX,boardMinY,boardMaxX,boardMaxY,hasBoardBounds},viewportOptions:{viewport:options?.viewport,viewportTarget:options?.viewportTarget}}),circuitWidth=boundsMaxX-boundsMinX+2*padding,circuitHeight=boundsMaxY-boundsMinY+2*padding,svgWidth=options?.width??800,svgHeight=options?.height??600;if(options?.matchBoardAspectRatio){let viewportWidth=boundsMaxX-boundsMinX,viewportHeight=boundsMaxY-boundsMinY;if(viewportWidth>0&&viewportHeight>0){let aspect=viewportWidth/viewportHeight;options?.width&&!options?.height?svgHeight=options.width/aspect:options?.height&&!options?.width?svgWidth=options.height*aspect:svgHeight=svgWidth/aspect}}let paths=[];for(let circuitJsonElm of circuitJson)"route"in circuitJsonElm&&circuitJsonElm.route!==void 0&&paths.push(circuitJsonElm.route);let scaleX=svgWidth/circuitWidth,scaleY=svgHeight/circuitHeight,scaleFactor=Math.min(scaleX,scaleY),offsetX=(svgWidth-circuitWidth*scaleFactor)/2,offsetY=(svgHeight-circuitHeight*scaleFactor)/2,transform6=compose3(translate3(offsetX-boundsMinX*scaleFactor+padding*scaleFactor,svgHeight-offsetY+boundsMinY*scaleFactor-padding*scaleFactor),scale3(scaleFactor,-scaleFactor)),ctx={transform:transform6,layer,shouldDrawErrors:options?.shouldDrawErrors,showCourtyards:options?.showCourtyards,showPcbGroups:options?.showPcbGroups,drawPaddingOutsideBoard,colorMap:colorMap2,showSolderMask:options?.showSolderMask,showPcbNotes:options?.showPcbNotes??!0,showAnchorOffsets:options?.showAnchorOffsets,circuitJson},unsortedSvgObjects=circuitJson.flatMap(elm=>createSvgObjects({elm,circuitJson,ctx})),strokeWidth=String(.05*scaleFactor);for(let element of circuitJson)if("stroke_width"in element){strokeWidth=String(scaleFactor*element.stroke_width);break}if(options?.shouldDrawRatsNest){let ratsNestObjects=createSvgObjectsForRatsNest(circuitJson,ctx);unsortedSvgObjects=[...unsortedSvgObjects,...ratsNestObjects]}let svgObjects=sortSvgObjectsByPcbLayer(unsortedSvgObjects),children=[{name:"style",type:"element",value:"",attributes:{},children:[{type:"text",value:"",name:"",attributes:{},children:[]}]}],gridObjects=createSvgObjectsForPcbGrid({grid:options?.grid,svgWidth,svgHeight});if(gridObjects.defs&&children.push(gridObjects.defs),circuitJson.some(elm=>elm.type==="pcb_keepout")&&children.push(createKeepoutPatternDefs(colorMap2.keepout??DEFAULT_PCB_COLOR_MAP.keepout)),children.push({name:"rect",type:"element",value:"",attributes:{class:"boundary",x:"0",y:"0",fill:options?.backgroundColor??"#000",width:svgWidth.toString(),height:svgHeight.toString(),"data-type":"pcb_background","data-pcb-layer":"global"},children:[]}),drawPaddingOutsideBoard&&children.push(createSvgObjectFromPcbBoundary(transform6,minX,minY,maxX,maxY)),children.push(...svgObjects),gridObjects.rect&&children.push(gridObjects.rect),options?.showErrorsInTextOverlay){let errorOverlay=createErrorTextOverlay(circuitJson,"pcb_error_text_overlay");errorOverlay&&children.push(errorOverlay)}let softwareUsedString=getSoftwareUsedString(circuitJson),version2=CIRCUIT_TO_SVG_VERSION,svgObject={name:"svg",type:"element",attributes:{xmlns:"http://www.w3.org/2000/svg",width:svgWidth.toString(),height:svgHeight.toString(),...softwareUsedString&&{"data-software-used-string":softwareUsedString},...options?.includeVersion&&{"data-circuit-to-svg-version":version2}},value:"",children:children.filter(child=>child!==null)};try{return(0,import_svgson2.stringify)(svgObject)}catch(error2){throw console.error("Error stringifying SVG object:",error2),error2}}function createSvgObjects({elm,circuitJson,ctx}){switch(elm.type){case"pcb_trace_error":return createSvgObjectsFromPcbTraceError(elm,circuitJson,ctx).filter(Boolean);case"pcb_footprint_overlap_error":return createSvgObjectsFromPcbFootprintOverlapError(elm,circuitJson,ctx).filter(Boolean);case"pcb_courtyard_overlap_error":return createSvgObjectsFromPcbCourtyardOverlapError(elm,circuitJson,ctx).filter(Boolean);case"pcb_component_outside_board_error":return createSvgObjectsFromPcbComponentOutsideBoardError(elm,circuitJson,ctx).filter(Boolean);case"pcb_via_trace_clearance_error":return createSvgObjectsFromPcbViaTraceClearanceError(elm,circuitJson,ctx).filter(Boolean);case"pcb_component":return createSvgObjectsFromPcbComponent(elm,ctx).filter(Boolean);case"pcb_trace":return createSvgObjectsFromPcbTrace(elm,ctx);case"pcb_copper_pour":return createSvgObjectsFromPcbCopperPour(elm,ctx);case"pcb_plated_hole":return createSvgObjectsFromPcbPlatedHole(elm,ctx).filter(Boolean);case"pcb_hole":return createSvgObjectsFromPcbHole(elm,ctx);case"pcb_smtpad":return createSvgObjectsFromSmtPad(elm,ctx);case"pcb_silkscreen_text":return createSvgObjectsFromPcbSilkscreenText(elm,ctx);case"pcb_silkscreen_rect":return createSvgObjectsFromPcbSilkscreenRect(elm,ctx);case"pcb_silkscreen_circle":return createSvgObjectsFromPcbSilkscreenCircle(elm,ctx);case"pcb_silkscreen_line":return createSvgObjectsFromPcbSilkscreenLine(elm,ctx);case"pcb_silkscreen_pill":return createSvgObjectsFromPcbSilkscreenPill(elm,ctx);case"pcb_silkscreen_oval":return createSvgObjectsFromPcbSilkscreenOval(elm,ctx);case"pcb_copper_text":return createSvgObjectsFromPcbCopperText(elm,ctx);case"pcb_courtyard_rect":return ctx.showCourtyards?createSvgObjectsFromPcbCourtyardRect(elm,ctx):[];case"pcb_courtyard_polygon":return ctx.showCourtyards?createSvgObjectsFromPcbCourtyardPolygon(elm,ctx):[];case"pcb_courtyard_circle":return ctx.showCourtyards?createSvgObjectsFromPcbCourtyardCircle(elm,ctx):[];case"pcb_courtyard_outline":return ctx.showCourtyards?createSvgObjectsFromPcbCourtyardOutline(elm,ctx):[];case"pcb_fabrication_note_path":return createSvgObjectsFromPcbFabricationNotePath(elm,ctx);case"pcb_fabrication_note_text":return createSvgObjectsFromPcbFabricationNoteText(elm,ctx);case"pcb_fabrication_note_rect":return createSvgObjectsFromPcbFabricationNoteRect(elm,ctx);case"pcb_fabrication_note_dimension":return createSvgObjectsFromPcbFabricationNoteDimension(elm,ctx);case"pcb_note_dimension":return ctx.showPcbNotes?createSvgObjectsFromPcbNoteDimension(elm,ctx):[];case"pcb_note_text":return ctx.showPcbNotes?createSvgObjectsFromPcbNoteText(elm,ctx):[];case"pcb_note_rect":return ctx.showPcbNotes?createSvgObjectsFromPcbNoteRect(elm,ctx):[];case"pcb_note_path":return ctx.showPcbNotes?createSvgObjectsFromPcbNotePath(elm,ctx):[];case"pcb_note_line":return ctx.showPcbNotes?createSvgObjectsFromPcbNoteLine(elm,ctx):[];case"pcb_silkscreen_path":return createSvgObjectsFromPcbSilkscreenPath(elm,ctx);case"pcb_panel":return ctx.drawPaddingOutsideBoard?createSvgObjectsFromPcbPanel(elm,ctx):[];case"pcb_board":return ctx.drawPaddingOutsideBoard?createSvgObjectsFromPcbBoard(elm,ctx):[];case"pcb_via":return createSvgObjectsFromPcbVia(elm,ctx);case"pcb_cutout":let cutout=elm;return cutout.shape==="path"?createSvgObjectsFromPcbCutoutPath(cutout,ctx):createSvgObjectsFromPcbCutout(elm,ctx);case"pcb_keepout":return createSvgObjectsFromPcbKeepout(elm,ctx);case"pcb_group":return ctx.showPcbGroups?createSvgObjectsFromPcbGroup(elm,ctx):[];default:return[]}}function createSvgObjectFromPcbBoundary(transform6,minX,minY,maxX,maxY){let[x12,y12]=applyToPoint3(transform6,[minX,minY]),[x22,y22]=applyToPoint3(transform6,[maxX,maxY]),width=Math.abs(x22-x12),height=Math.abs(y22-y12),x4=Math.min(x12,x22),y4=Math.min(y12,y22);return{name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-boundary",fill:"none",stroke:"#fff","stroke-width":"0.3",x:x4.toString(),y:y4.toString(),width:width.toString(),height:height.toString(),"data-type":"pcb_boundary","data-pcb-layer":"global"}}}function createSvgObjectsFromAssemblyBoard(pcbBoard,transform6,style={}){let{width,height,center:center2,outline}=pcbBoard,path;if(outline&&Array.isArray(outline)&&outline.length>=3)path=outline.map((point7,index)=>{let[x4,y4]=applyToPoint3(transform6,[point7.x,point7.y]);return index===0?`M ${x4} ${y4}`:`L ${x4} ${y4}`}).join(" ");else{let halfWidth=width/2,halfHeight=height/2,topLeft=applyToPoint3(transform6,[center2.x-halfWidth,center2.y-halfHeight]),topRight=applyToPoint3(transform6,[center2.x+halfWidth,center2.y-halfHeight]),bottomRight=applyToPoint3(transform6,[center2.x+halfWidth,center2.y+halfHeight]),bottomLeft=applyToPoint3(transform6,[center2.x-halfWidth,center2.y+halfHeight]);path=`M ${topLeft[0]} ${topLeft[1]} L ${topRight[0]} ${topRight[1]} L ${bottomRight[0]} ${bottomRight[1]} L ${bottomLeft[0]} ${bottomLeft[1]}`}return path+=" Z",[{name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-board",d:path,fill:style.fill??DEFAULT_BOARD_STYLE.fill,stroke:style.stroke??DEFAULT_BOARD_STYLE.stroke,"stroke-opacity":style.strokeOpacity??DEFAULT_BOARD_STYLE.strokeOpacity,"stroke-width":((style.strokeWidthFactor??DEFAULT_BOARD_STYLE.strokeWidthFactor)*Math.abs(transform6.a)).toString()}}]}function createSvgObjectsFromAssemblyComponent(params,ctx){let{elm,portPosition,name,arePinsInterchangeable}=params,{transform:transform6}=ctx,{center:center2,width,height,rotation:rotation5=0,layer="top"}=elm;if(!center2||typeof width!="number"||typeof height!="number")return null;let[x4,y4]=applyToPoint3(transform6,[center2.x,center2.y]),[pinX,pinY]=applyToPoint3(transform6,[portPosition.x,portPosition.y]),scaledWidth=width*Math.abs(transform6.a),scaledHeight=height*Math.abs(transform6.d),isTopLayer=layer==="top",isPinTop=pinY>y4,isPinLeft=pinX<x4,children=[createComponentPath(scaledWidth,scaledHeight,rotation5,layer),createComponentLabel(scaledWidth,scaledHeight,name??"",transform6)];return arePinsInterchangeable||children.push(createPin1Indicator(scaledWidth,scaledHeight,rotation5,layer,isPinTop,isPinLeft)),{name:"g",type:"element",value:"",attributes:{transform:`translate(${x4}, ${y4}) scale(1, -1)`},children}}function createComponentPath(scaledWidth,scaledHeight,rotation5,layer){let w4=scaledWidth/2,h6=scaledHeight/2;return{name:"path",type:"element",attributes:{class:"assembly-component",d:getRectPathData(w4,h6,rotation5),"stroke-width":.8.toFixed(2),transform:`rotate(${-rotation5})`,"stroke-dasharray":layer==="bottom"?"2,2":""},value:"",children:[]}}function createComponentLabel(scaledWidth,scaledHeight,name,transform6){let size3=Math.min(scaledWidth,scaledHeight),fontSize=Math.min(58,Math.max(3,size3*.8)),isTall=scaledHeight>scaledWidth;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":`${fontSize.toFixed(1)}px`,transform:isTall?"rotate(90) scale(1, -1)":"scale(1, -1)"},children:[{type:"text",value:name||"",name:"",attributes:{},children:[]}],value:""}}function createPin1Indicator(scaledWidth,scaledHeight,rotation5,layer,isPinTop,isPinLeft){let w4=scaledWidth/2,h6=scaledHeight/2,indicatorSize=Math.min(w4,h6)*.5,points;return isPinTop&&isPinLeft?points=[[-w4,-h6],[-w4+indicatorSize,-h6],[-w4,-h6+indicatorSize]]:isPinTop&&!isPinLeft?points=[[w4,-h6],[w4-indicatorSize,-h6],[w4,-h6+indicatorSize]]:!isPinTop&&isPinLeft?points=[[-w4,h6],[-w4+indicatorSize,h6],[-w4,h6-indicatorSize]]:points=[[w4,h6],[w4-indicatorSize,h6],[w4,h6-indicatorSize]],{name:"polygon",type:"element",attributes:{class:"assembly-pin1-indicator",points:points.map(p4=>p4.join(",")).join(" "),fill:"#333",stroke:"none",transform:`rotate(${-rotation5})`},value:"",children:[]}}function getRectPathData(w4,h6,rotation5){let rotatePoint6=(x4,y4,angle)=>{let rad=Math.PI/180*angle,cos6=Math.cos(rad),sin6=Math.sin(rad);return[x4*cos6-y4*sin6,x4*sin6+y4*cos6]};return`${[[-w4,-h6],[w4,-h6],[w4,h6],[-w4,h6]].map(([x4,y4])=>rotatePoint6(x4,y4,rotation5)).map(([x4,y4],i3)=>i3===0?`M${x4},${y4}`:`L${x4},${y4}`).join(" ")} Z`}function createSvgObjectsFromAssemblyHole(hole,ctx){let{transform:transform6}=ctx,[x4,y4]=applyToPoint3(transform6,[hole.x,hole.y]);if(hole.hole_shape==="circle"||hole.hole_shape==="square"){let scaledDiameter=hole.hole_diameter*Math.abs(transform6.a),radius=scaledDiameter/2;return hole.hole_shape==="circle"?[{name:"circle",type:"element",attributes:{class:"assembly-hole",cx:x4.toString(),cy:y4.toString(),r:radius.toString(),fill:HOLE_COLOR2},children:[],value:""}]:[{name:"rect",type:"element",attributes:{class:"assembly-hole",x:(x4-radius).toString(),y:(y4-radius).toString(),width:scaledDiameter.toString(),height:scaledDiameter.toString(),fill:HOLE_COLOR2},children:[],value:""}]}if(hole.hole_shape==="oval"){let scaledWidth=hole.hole_width*Math.abs(transform6.a),scaledHeight=hole.hole_height*Math.abs(transform6.a),rx3=scaledWidth/2,ry3=scaledHeight/2;return[{name:"ellipse",type:"element",attributes:{class:"assembly-hole",cx:x4.toString(),cy:y4.toString(),rx:rx3.toString(),ry:ry3.toString(),fill:HOLE_COLOR2},children:[],value:""}]}return[]}function createSvgObjectsFromAssemblyPlatedHole(hole,ctx){let{transform:transform6}=ctx,[x4,y4]=applyToPoint3(transform6,[hole.x,hole.y]);if(hole.shape==="pill"){let scaledOuterWidth=hole.outer_width*Math.abs(transform6.a),scaledOuterHeight=hole.outer_height*Math.abs(transform6.a),scaledHoleWidth=hole.hole_width*Math.abs(transform6.a),scaledHoleHeight=hole.hole_height*Math.abs(transform6.a),outerRadiusX=scaledOuterWidth/2,straightLength=scaledOuterHeight-scaledOuterWidth,innerRadiusX=scaledHoleWidth/2;return[{name:"g",type:"element",children:[{name:"path",type:"element",attributes:{class:"assembly-hole-outer",fill:PAD_COLOR,d:`M${x4-outerRadiusX},${y4-straightLength/2} v${straightLength} a${outerRadiusX},${outerRadiusX} 0 0 0 ${scaledOuterWidth},0 v-${straightLength} a${outerRadiusX},${outerRadiusX} 0 0 0 -${scaledOuterWidth},0 z`},value:"",children:[]},{name:"path",type:"element",attributes:{class:"assembly-hole-inner",fill:HOLE_COLOR3,d:`M${x4-innerRadiusX},${y4-(scaledHoleHeight-scaledHoleWidth)/2} v${scaledHoleHeight-scaledHoleWidth} a${innerRadiusX},${innerRadiusX} 0 0 0 ${scaledHoleWidth},0 v-${scaledHoleHeight-scaledHoleWidth} a${innerRadiusX},${innerRadiusX} 0 0 0 -${scaledHoleWidth},0 z`},value:"",children:[]}],value:"",attributes:{}}]}if(hole.shape==="circle"){let scaledOuterWidth=hole.outer_diameter*Math.abs(transform6.a),scaledOuterHeight=hole.outer_diameter*Math.abs(transform6.a),scaledHoleWidth=hole.hole_diameter*Math.abs(transform6.a),scaledHoleHeight=hole.hole_diameter*Math.abs(transform6.a),outerRadius=Math.min(scaledOuterWidth,scaledOuterHeight)/2,innerRadius=Math.min(scaledHoleWidth,scaledHoleHeight)/2;return[{name:"g",type:"element",children:[{name:"circle",type:"element",attributes:{class:"assembly-hole-outer",fill:PAD_COLOR,cx:x4.toString(),cy:y4.toString(),r:outerRadius.toString()},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"assembly-hole-inner",fill:HOLE_COLOR3,cx:x4.toString(),cy:y4.toString(),r:innerRadius.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(hole.shape==="circular_hole_with_rect_pad"){let circularHole=hole,scaledHoleDiameter=circularHole.hole_diameter*Math.abs(transform6.a),scaledRectPadWidth=circularHole.rect_pad_width*Math.abs(transform6.a),scaledRectPadHeight=circularHole.rect_pad_height*Math.abs(transform6.a),scaledRectBorderRadius=(circularHole.rect_border_radius??0)*Math.abs(transform6.a),rectCcwRotation=circularHole.rect_ccw_rotation??0,holeRadius=scaledHoleDiameter/2,[holeCx,holeCy]=applyToPoint3(transform6,[circularHole.x+circularHole.hole_offset_x,circularHole.y+circularHole.hole_offset_y]);return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"assembly-hole-outer-pad",fill:PAD_COLOR,...rectCcwRotation?{x:(-scaledRectPadWidth/2).toString(),y:(-scaledRectPadHeight/2).toString(),transform:`translate(${x4} ${y4}) rotate(${-rectCcwRotation})`}:{x:(x4-scaledRectPadWidth/2).toString(),y:(y4-scaledRectPadHeight/2).toString()},width:scaledRectPadWidth.toString(),height:scaledRectPadHeight.toString(),...scaledRectBorderRadius?{rx:scaledRectBorderRadius.toString(),ry:scaledRectBorderRadius.toString()}:{}},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"assembly-hole-inner",fill:HOLE_COLOR3,cx:holeCx.toString(),cy:holeCy.toString(),r:holeRadius.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(hole.shape==="pill_hole_with_rect_pad"){let pillHole=hole,scaledRectPadWidth=pillHole.rect_pad_width*Math.abs(transform6.a),scaledRectPadHeight=pillHole.rect_pad_height*Math.abs(transform6.a),scaledRectBorderRadius=(pillHole.rect_border_radius??0)*Math.abs(transform6.a),scaledHoleHeight=pillHole.hole_height*Math.abs(transform6.a),scaledHoleWidth=pillHole.hole_width*Math.abs(transform6.a),pillHoleWithOffsets=pillHole,holeOffsetX=pillHoleWithOffsets.hole_offset_x??0,holeOffsetY=pillHoleWithOffsets.hole_offset_y??0,[holeCenterX,holeCenterY]=applyToPoint3(transform6,[pillHole.x+holeOffsetX,pillHole.y+holeOffsetY]),holeRadius=Math.min(scaledHoleHeight,scaledHoleWidth)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"assembly-hole-outer-pad",fill:PAD_COLOR,x:(x4-scaledRectPadWidth/2).toString(),y:(y4-scaledRectPadHeight/2).toString(),width:scaledRectPadWidth.toString(),height:scaledRectPadHeight.toString(),...scaledRectBorderRadius?{rx:scaledRectBorderRadius.toString(),ry:scaledRectBorderRadius.toString()}:{}},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"assembly-hole-inner",fill:HOLE_COLOR3,x:(holeCenterX-scaledHoleWidth/2).toString(),y:(holeCenterY-scaledHoleHeight/2).toString(),width:scaledHoleWidth.toString(),height:scaledHoleHeight.toString(),rx:holeRadius.toString(),ry:holeRadius.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(hole.shape==="rotated_pill_hole_with_rect_pad"){let rotatedHole=hole,scaledRectPadWidth=rotatedHole.rect_pad_width*Math.abs(transform6.a),scaledRectPadHeight=rotatedHole.rect_pad_height*Math.abs(transform6.a),scaledRectBorderRadius=(rotatedHole.rect_border_radius??0)*Math.abs(transform6.a),scaledHoleHeight=rotatedHole.hole_height*Math.abs(transform6.a),scaledHoleWidth=rotatedHole.hole_width*Math.abs(transform6.a),rotatedHoleWithOffsets=rotatedHole,holeOffsetX=rotatedHoleWithOffsets.hole_offset_x??0,holeOffsetY=rotatedHoleWithOffsets.hole_offset_y??0,[holeCenterX,holeCenterY]=applyToPoint3(transform6,[rotatedHole.x+holeOffsetX,rotatedHole.y+holeOffsetY]),holeRadius=Math.min(scaledHoleHeight,scaledHoleWidth)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"assembly-hole-outer-pad",fill:PAD_COLOR,x:(-scaledRectPadWidth/2).toString(),y:(-scaledRectPadHeight/2).toString(),width:scaledRectPadWidth.toString(),height:scaledRectPadHeight.toString(),transform:`translate(${x4} ${y4}) rotate(${-rotatedHole.rect_ccw_rotation})`,...scaledRectBorderRadius?{rx:scaledRectBorderRadius.toString(),ry:scaledRectBorderRadius.toString()}:{}},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"assembly-hole-inner",fill:HOLE_COLOR3,x:(-scaledHoleWidth/2).toString(),y:(-scaledHoleHeight/2).toString(),width:scaledHoleWidth.toString(),height:scaledHoleHeight.toString(),rx:holeRadius.toString(),ry:holeRadius.toString(),transform:`translate(${holeCenterX} ${holeCenterY}) rotate(${-rotatedHole.hole_ccw_rotation})`},value:"",children:[]}],value:"",attributes:{}}]}return[]}function createSvgObjectsFromAssemblySmtPad(pad2,ctx){let{transform:transform6}=ctx;if(pad2.shape==="rect"||pad2.shape==="rotated_rect"){let width=pad2.width*Math.abs(transform6.a),height=pad2.height*Math.abs(transform6.d),[x4,y4]=applyToPoint3(transform6,[pad2.x,pad2.y]),scaledBorderRadius=(pad2.rect_border_radius??0)*Math.abs(transform6.a);return pad2.shape==="rotated_rect"&&pad2.ccw_rotation?[{name:"rect",type:"element",attributes:{class:"assembly-pad",fill:PAD_COLOR2,x:(-width/2).toString(),y:(-height/2).toString(),width:width.toString(),height:height.toString(),transform:`translate(${x4} ${y4}) rotate(${-pad2.ccw_rotation})`,"data-layer":pad2.layer,...scaledBorderRadius?{rx:scaledBorderRadius.toString(),ry:scaledBorderRadius.toString()}:{}},value:"",children:[]}]:[{name:"rect",type:"element",attributes:{class:"assembly-pad",fill:PAD_COLOR2,x:(x4-width/2).toString(),y:(y4-height/2).toString(),width:width.toString(),height:height.toString(),"data-layer":pad2.layer,...scaledBorderRadius?{rx:scaledBorderRadius.toString(),ry:scaledBorderRadius.toString()}:{}},value:"",children:[]}]}if(pad2.shape==="pill"){let width=pad2.width*Math.abs(transform6.a),height=pad2.height*Math.abs(transform6.d),radius=pad2.radius*Math.abs(transform6.a),[x4,y4]=applyToPoint3(transform6,[pad2.x,pad2.y]);return[{name:"rect",type:"element",attributes:{class:"assembly-pad",fill:PAD_COLOR2,x:(x4-width/2).toString(),y:(y4-height/2).toString(),width:width.toString(),height:height.toString(),rx:radius.toString(),ry:radius.toString(),"data-layer":pad2.layer},value:"",children:[]}]}if(pad2.shape==="circle"){let radius=pad2.radius*Math.abs(transform6.a),[x4,y4]=applyToPoint3(transform6,[pad2.x,pad2.y]);return[{name:"circle",type:"element",attributes:{class:"assembly-pad",fill:PAD_COLOR2,cx:x4.toString(),cy:y4.toString(),r:radius.toString(),"data-layer":pad2.layer},value:"",children:[]}]}if(pad2.shape==="polygon"){let points=(pad2.points??[]).map(point7=>applyToPoint3(transform6,[point7.x,point7.y]));return[{name:"polygon",type:"element",attributes:{class:"assembly-pad",fill:PAD_COLOR2,points:points.map(p4=>p4.join(",")).join(" "),"data-layer":pad2.layer},value:"",children:[]}]}return[]}function convertCircuitJsonToAssemblySvg(soup,options){let minX=Number.POSITIVE_INFINITY,minY=Number.POSITIVE_INFINITY,maxX=Number.NEGATIVE_INFINITY,maxY=Number.NEGATIVE_INFINITY;for(let item of soup)if(item.type==="pcb_board"){let center2=item.center,width=item.width||0,height=item.height||0;minX=Math.min(minX,center2.x-width/2),minY=Math.min(minY,center2.y-height/2),maxX=Math.max(maxX,center2.x+width/2),maxY=Math.max(maxY,center2.y+height/2)}let padding=1,circuitWidth=maxX-minX+2*padding,circuitHeight=maxY-minY+2*padding,svgWidth=options?.width??800,svgHeight=options?.height??600,scaleX=svgWidth/circuitWidth,scaleY=svgHeight/circuitHeight,scaleFactor=Math.min(scaleX,scaleY),offsetX=(svgWidth-circuitWidth*scaleFactor)/2,offsetY=(svgHeight-circuitHeight*scaleFactor)/2,transform6=compose3(translate3(offsetX-minX*scaleFactor+padding*scaleFactor,svgHeight-offsetY+minY*scaleFactor-padding*scaleFactor),scale3(scaleFactor,-scaleFactor)),ctx={transform:transform6},svgObjects=soup.sort((a3,b3)=>(OBJECT_ORDER.indexOf(b3.type)??9999)-(OBJECT_ORDER.indexOf(a3.type)??9999)).flatMap(item=>createSvgObjects2(item,ctx,soup)),softwareUsedString=getSoftwareUsedString(soup),version2=CIRCUIT_TO_SVG_VERSION,children=[{name:"style",type:"element",children:[{type:"text",value:`
|
|
227
|
+
`),totalHeight=textLines.length*lineHeight,lineWidths=textLines.map(line2=>getLineWidth(line2,charAdvance,spaceAdvance,trailingSpacing)),baseSegments=[],y4=-totalHeight/2;for(let lineIndex=0;lineIndex<textLines.length;lineIndex++){let line2=textLines[lineIndex]??"",x4=-(lineWidths[lineIndex]??0)/2;for(let char of line2){if(char===" "){x4+=spaceAdvance;continue}let charLines=lineAlphabet[char];if(charLines)for(let segment2 of charLines)baseSegments.push(mapSegment(segment2,x4,y4,fontSize));x4+=charAdvance}y4+=lineHeight}let baseBounds=getSegmentBounds(baseSegments);if(!baseBounds)return{pathData:"",bounds:null};let anchorOffset=getAnchorOffsetForBounds(anchorAlignment,baseBounds),anchoredSegments=translateSegments(baseSegments,anchorOffset),anchoredBounds=translateBounds(baseBounds,anchorOffset);return{pathData:segmentsToPathData(anchoredSegments),bounds:anchoredBounds}}function getLineWidth(line2,charAdvance,spaceAdvance,trailingSpacing){let width=0;for(let char of line2)width+=char===" "?spaceAdvance:charAdvance;return width>0?width-trailingSpacing:0}function getSegmentBounds(segments){if(segments.length===0)return null;let minX=Number.POSITIVE_INFINITY,minY=Number.POSITIVE_INFINITY,maxX=Number.NEGATIVE_INFINITY,maxY=Number.NEGATIVE_INFINITY;for(let segment2 of segments)minX=Math.min(minX,segment2.x1,segment2.x2),minY=Math.min(minY,segment2.y1,segment2.y2),maxX=Math.max(maxX,segment2.x1,segment2.x2),maxY=Math.max(maxY,segment2.y1,segment2.y2);return{minX,minY,maxX,maxY}}function getAnchorOffsetForBounds(anchorAlignment,bounds){return{x:-getHorizontalAnchorPosition(anchorAlignment,bounds),y:-getVerticalAnchorPosition(anchorAlignment,bounds)}}function getHorizontalAnchorPosition(anchorAlignment,bounds){return anchorAlignment==="top_left"||anchorAlignment==="center_left"||anchorAlignment==="bottom_left"?bounds.minX:anchorAlignment==="top_right"||anchorAlignment==="center_right"||anchorAlignment==="bottom_right"?bounds.maxX:(bounds.minX+bounds.maxX)/2}function getVerticalAnchorPosition(anchorAlignment,bounds){return anchorAlignment==="top_left"||anchorAlignment==="top_center"||anchorAlignment==="top_right"?bounds.minY:anchorAlignment==="bottom_left"||anchorAlignment==="bottom_center"||anchorAlignment==="bottom_right"?bounds.maxY:(bounds.minY+bounds.maxY)/2}function translateSegments(segments,offset){return offset.x===0&&offset.y===0?segments:segments.map(segment2=>({x1:segment2.x1+offset.x,y1:segment2.y1+offset.y,x2:segment2.x2+offset.x,y2:segment2.y2+offset.y}))}function translateBounds(bounds,offset){return{minX:bounds.minX+offset.x,minY:bounds.minY+offset.y,maxX:bounds.maxX+offset.x,maxY:bounds.maxY+offset.y}}function segmentsToPathData(segments){return segments.map(segment2=>`M${segment2.x1} ${segment2.y1}L${segment2.x2} ${segment2.y2}`).join(" ")}function createSvgObjectsFromPcbSilkscreenText(pcbSilkscreenText,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2}=ctx,{anchor_position,text,font_size=1,layer="top",ccw_rotation=0,anchor_alignment="center",is_knockout=!1,knockout_padding,is_mirrored=!1}=pcbSilkscreenText;if(layerFilter&&layer!==layerFilter)return[];if(!anchor_position||typeof anchor_position.x!="number"||typeof anchor_position.y!="number")return debugPcb(`[pcb_silkscreen_text] Invalid anchor_position for "${pcbSilkscreenText.pcb_silkscreen_text_id}": expected {x: number, y: number}, got ${JSON.stringify(anchor_position)}`),[];if(!text)return[];let[transformedX,transformedY]=applyToPoint3(transform6,[anchor_position.x,anchor_position.y]),scaleFactor=Math.abs(transform6.a),silkscreenColor=layer==="bottom"?colorMap2.silkscreen.bottom:colorMap2.silkscreen.top,applyMirror=layer==="bottom"?!0:is_mirrored===!0;if(is_knockout){let scaledFontSize=font_size*.6666666666666666/alphabetBounds.height,charSpacing=alphabetBounds.width*INTER_CHAR_SPACING_RATIO,geometry=createPcbAlphabetTextGeometry({text,anchorAlignment:anchor_alignment,fontSize:scaledFontSize,charAdvance:(alphabetBounds.width+charSpacing)*scaledFontSize,spaceAdvance:(alphabetBounds.width+charSpacing)*scaledFontSize*.6,trailingSpacing:charSpacing*scaledFontSize,lineHeight:scaledFontSize*alphabetBounds.height*LINE_HEIGHT_MULTIPLIER,mapSegment:(segment2,offsetX,offsetY,fontSize)=>({x1:offsetX+segment2.x1*fontSize,y1:offsetY+(1-segment2.y1)*fontSize,x2:offsetX+segment2.x2*fontSize,y2:offsetY+(1-segment2.y2)*fontSize})});if(!geometry.bounds||!geometry.pathData)return[];let padLeft=knockout_padding?.left??scaledFontSize*.5,padRight=knockout_padding?.right??scaledFontSize*.5,padTop=knockout_padding?.top??scaledFontSize*.3,padBottom=knockout_padding?.bottom??scaledFontSize*.3,rectX=geometry.bounds.minX-padLeft,rectY=geometry.bounds.minY-padTop,rectW=geometry.bounds.maxX-geometry.bounds.minX+padLeft+padRight,rectH=geometry.bounds.maxY-geometry.bounds.minY+padTop+padBottom,strokeWidth=scaledFontSize*.15,knockoutBounds={minX:rectX,minY:rectY,maxX:rectX+rectW,maxY:rectY+rectH},knockoutAnchorOffset=getAnchorOffsetForBounds(anchor_alignment,knockoutBounds),alignedRectX=rectX+knockoutAnchorOffset.x,alignedRectY=rectY+knockoutAnchorOffset.y,maskCutoutChildren=[{name:"rect",type:"element",value:"",attributes:{x:rectX.toString(),y:rectY.toString(),width:rectW.toString(),height:rectH.toString(),fill:"white"},children:[]},{name:"path",type:"element",value:"",attributes:{d:geometry.pathData,fill:"none",stroke:"black","stroke-width":strokeWidth.toString(),"stroke-linecap":"round","stroke-linejoin":"round"},children:[]}],maskChildren=knockoutAnchorOffset.x!==0||knockoutAnchorOffset.y!==0?[{name:"g",type:"element",value:"",attributes:{transform:`translate(${knockoutAnchorOffset.x} ${knockoutAnchorOffset.y})`},children:maskCutoutChildren}]:maskCutoutChildren,knockoutTransform=toString2(compose3(translate3(transformedX,transformedY),rotate3(-ccw_rotation*Math.PI/180),...applyMirror?[scale3(-1,1)]:[],scale3(scaleFactor,scaleFactor))),maskId=`silkscreen-knockout-mask-${pcbSilkscreenText.pcb_silkscreen_text_id}-${silkscreenMaskIdCounter++}`;return[{name:"defs",type:"element",value:"",children:[{name:"mask",type:"element",value:"",attributes:{id:maskId},children:maskChildren}],attributes:{}},{name:"rect",type:"element",value:"",children:[],attributes:{x:alignedRectX.toString(),y:alignedRectY.toString(),width:rectW.toString(),height:rectH.toString(),fill:silkscreenColor,mask:`url(#${maskId})`,transform:knockoutTransform,class:`pcb-silkscreen-text-knockout pcb-silkscreen-${layer}`,"data-type":"pcb_silkscreen_text","data-pcb-silkscreen-text-id":pcbSilkscreenText.pcb_silkscreen_text_id,"data-pcb-layer":layer}}]}let transformedFontSize=font_size*scaleFactor,textAnchor="middle",dominantBaseline="central";switch(anchor_alignment){case"top_left":textAnchor="start",dominantBaseline="text-before-edge";break;case"top_center":textAnchor="middle",dominantBaseline="text-before-edge";break;case"top_right":textAnchor="end",dominantBaseline="text-before-edge";break;case"center_left":textAnchor="start",dominantBaseline="central";break;case"center_right":textAnchor="end",dominantBaseline="central";break;case"bottom_left":textAnchor="start",dominantBaseline="text-after-edge";break;case"bottom_center":textAnchor="middle",dominantBaseline="text-after-edge";break;case"bottom_right":textAnchor="end",dominantBaseline="text-after-edge";break;default:textAnchor="middle",dominantBaseline="central";break}let textTransform=compose3(translate3(transformedX,transformedY),rotate3(-ccw_rotation*Math.PI/180),...applyMirror?[scale3(-1,1)]:[]),lines=text.split(`
|
|
228
|
+
`),children=lines.length===1?[{type:"text",value:text,name:"",attributes:{},children:[]}]:lines.map((line2,idx)=>({type:"element",name:"tspan",value:"",attributes:{x:"0",...idx>0?{dy:transformedFontSize.toString()}:{}},children:[{type:"text",value:line2,name:"",attributes:{},children:[]}]}));return[{name:"text",type:"element",attributes:{x:"0",y:"0",dx:"0",dy:"0",fill:silkscreenColor,"font-family":"Arial, sans-serif","font-size":transformedFontSize.toString(),"text-anchor":textAnchor,"dominant-baseline":dominantBaseline,transform:toString2(textTransform),class:`pcb-silkscreen-text pcb-silkscreen-${layer}`,"data-pcb-silkscreen-text-id":pcbSilkscreenText.pcb_silkscreen_text_id,stroke:"none","data-type":"pcb_silkscreen_text","data-pcb-layer":layer},children,value:""}]}function createSvgObjectsFromPcbSilkscreenRect(pcbSilkscreenRect,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2}=ctx,{center:center2,width,height,layer="top",pcb_silkscreen_rect_id,stroke_width,is_filled,has_stroke,is_stroke_dashed,corner_radius,ccw_rotation=0}=pcbSilkscreenRect;if(layerFilter&&layer!==layerFilter)return[];if(!center2||typeof center2.x!="number"||typeof center2.y!="number"||typeof width!="number"||typeof height!="number")return debugPcb(`[pcb_silkscreen_rect] Invalid data for "${pcb_silkscreen_rect_id}": expected center {x: number, y: number}, width: number, height: number, got center=${JSON.stringify(center2)}, width=${JSON.stringify(width)}, height=${JSON.stringify(height)}`),[];let[transformedX,transformedY]=applyToPoint3(transform6,[center2.x,center2.y]),baseCornerRadius=typeof corner_radius=="number"&&corner_radius>0?corner_radius:0,transformedCornerRadiusX=baseCornerRadius*Math.abs(transform6.a),transformedCornerRadiusY=baseCornerRadius*Math.abs(transform6.d),transformedWidth=width*Math.abs(transform6.a),transformedHeight=height*Math.abs(transform6.d),transformedStrokeWidth=stroke_width*Math.abs(transform6.a),color=layer==="bottom"?colorMap2.silkscreen.bottom:colorMap2.silkscreen.top,attributes2={x:(-transformedWidth/2).toString(),y:(-transformedHeight/2).toString(),width:transformedWidth.toString(),height:transformedHeight.toString(),class:`pcb-silkscreen-rect pcb-silkscreen-${layer}`,"data-pcb-silkscreen-rect-id":pcb_silkscreen_rect_id,"data-type":"pcb_silkscreen_rect","data-pcb-layer":layer};typeof ccw_rotation=="number"&&ccw_rotation!==0?attributes2.transform=`translate(${transformedX} ${transformedY}) rotate(${-ccw_rotation})`:(attributes2.x=(transformedX-transformedWidth/2).toString(),attributes2.y=(transformedY-transformedHeight/2).toString()),transformedCornerRadiusX>0&&(attributes2.rx=transformedCornerRadiusX.toString()),transformedCornerRadiusY>0&&(attributes2.ry=transformedCornerRadiusY.toString()),attributes2.fill=is_filled?color:"none";let actualHasStroke;if(has_stroke===void 0?actualHasStroke=transformedStrokeWidth>0:actualHasStroke=has_stroke,actualHasStroke){if(attributes2.stroke=color,attributes2["stroke-width"]=transformedStrokeWidth.toString(),is_stroke_dashed){let dashLength=.1*Math.abs(transform6.a),gapLength=.05*Math.abs(transform6.a);attributes2["stroke-dasharray"]=`${dashLength} ${gapLength}`}}else attributes2.stroke="none";return[{name:"rect",type:"element",attributes:attributes2,value:"",children:[]}]}function layerNameToColor(layerName,colorMap2=DEFAULT_PCB_COLOR_MAP){return colorMap2.copper[layerName]??"white"}function solderPasteLayerNameToColor(layerName){return SOLDER_PASTE_LAYER_NAME_TO_COLOR[layerName]??"rgb(105, 105, 105)"}function createSvgObjectsFromPcbCopperText(pcbCopperText,ctx){let{transform:transform6,layer:filterLayer,colorMap:colorMap2}=ctx,{anchor_position,text,font_size="0.2mm",layer,ccw_rotation=0,anchor_alignment="center",is_knockout=!1,knockout_padding,is_mirrored=!1}=pcbCopperText,layerName=layer??"top";if(filterLayer&&filterLayer!==layerName)return[];if(!anchor_position)return[];if(!text)return[];let[ax3,ay3]=applyToPoint3(transform6,[anchor_position.x,anchor_position.y]),fontSizeNum=distance.parse(font_size)??.2,scaleFactor=Math.abs(transform6.a),copperColor=layerNameToColor(layerName,colorMap2),applyMirror=layerName==="bottom"?!0:is_mirrored===!0;if(is_knockout){let scaledFontSize2=fontSizeNum*FONT_SCALE,geometry2=createPcbAlphabetTextGeometry({text,anchorAlignment:anchor_alignment,fontSize:scaledFontSize2,charAdvance:(CHAR_WIDTH+CHAR_SPACING)*scaledFontSize2,spaceAdvance:(CHAR_WIDTH+CHAR_SPACING)*scaledFontSize2*.6,trailingSpacing:CHAR_SPACING*scaledFontSize2,lineHeight:scaledFontSize2*LINE_HEIGHT,mapSegment:(segment2,offsetX,offsetY,fontSize)=>({x1:offsetX+segment2.x1*fontSize,y1:offsetY+(1-segment2.y1)*fontSize,x2:offsetX+segment2.x2*fontSize,y2:offsetY+(1-segment2.y2)*fontSize})});if(!geometry2.bounds||!geometry2.pathData)return[];let padLeft=knockout_padding?.left??scaledFontSize2*.5,padRight=knockout_padding?.right??scaledFontSize2*.5,padTop=knockout_padding?.top??scaledFontSize2*.3,padBottom=knockout_padding?.bottom??scaledFontSize2*.3,rectX=geometry2.bounds.minX-padLeft,rectY=geometry2.bounds.minY-padTop,rectW=geometry2.bounds.maxX-geometry2.bounds.minX+padLeft+padRight,rectH=geometry2.bounds.maxY-geometry2.bounds.minY+padTop+padBottom,strokeWidth2=scaledFontSize2*.15,knockoutBounds={minX:rectX,minY:rectY,maxX:rectX+rectW,maxY:rectY+rectH},knockoutAnchorOffset=getAnchorOffsetForBounds(anchor_alignment,knockoutBounds),alignedRectX=rectX+knockoutAnchorOffset.x,alignedRectY=rectY+knockoutAnchorOffset.y,maskCutoutChildren=[{name:"rect",type:"element",value:"",attributes:{x:rectX.toString(),y:rectY.toString(),width:rectW.toString(),height:rectH.toString(),fill:"white"},children:[]},{name:"path",type:"element",value:"",attributes:{d:geometry2.pathData,fill:"none",stroke:"black","stroke-width":strokeWidth2.toString(),"stroke-linecap":"round","stroke-linejoin":"round"},children:[]}],maskChildren=knockoutAnchorOffset.x!==0||knockoutAnchorOffset.y!==0?[{name:"g",type:"element",value:"",attributes:{transform:`translate(${knockoutAnchorOffset.x} ${knockoutAnchorOffset.y})`},children:maskCutoutChildren}]:maskCutoutChildren,knockoutTransform=toString2(compose3(translate3(ax3,ay3),rotate3(-ccw_rotation*Math.PI/180),...applyMirror?[scale3(-1,1)]:[],scale3(scaleFactor,scaleFactor))),maskId=`knockout-mask-${pcbCopperText.pcb_copper_text_id}-${maskIdCounter++}`;return[{name:"defs",type:"element",value:"",children:[{name:"mask",type:"element",value:"",attributes:{id:maskId},children:maskChildren}],attributes:{}},{name:"rect",type:"element",value:"",children:[],attributes:{x:alignedRectX.toString(),y:alignedRectY.toString(),width:rectW.toString(),height:rectH.toString(),fill:copperColor,mask:`url(#${maskId})`,transform:knockoutTransform,class:`pcb-copper-text-knockout pcb-copper-${layerName}`,"data-type":"pcb_copper_text","data-pcb-copper-text-id":pcbCopperText.pcb_copper_text_id}}]}let scaledFontSize=fontSizeNum*FONT_SCALE,geometry=createPcbAlphabetTextGeometry({text,anchorAlignment:anchor_alignment,fontSize:scaledFontSize,charAdvance:(CHAR_WIDTH+CHAR_SPACING)*scaledFontSize,spaceAdvance:(CHAR_WIDTH+CHAR_SPACING)*scaledFontSize*.6,trailingSpacing:CHAR_SPACING*scaledFontSize,lineHeight:scaledFontSize*LINE_HEIGHT,mapSegment:(segment2,offsetX,offsetY,fontSize)=>({x1:offsetX+segment2.x1*fontSize,y1:offsetY+(1-segment2.y1)*fontSize,x2:offsetX+segment2.x2*fontSize,y2:offsetY+(1-segment2.y2)*fontSize})});if(!geometry.pathData)return[];let textTransform=toString2(compose3(translate3(ax3,ay3),rotate3(-ccw_rotation*Math.PI/180),...applyMirror?[scale3(-1,1)]:[],scale3(scaleFactor,scaleFactor))),strokeWidth=scaledFontSize*.15;return[{name:"path",type:"element",attributes:{d:geometry.pathData,fill:"none",stroke:copperColor,"stroke-width":strokeWidth.toString(),"stroke-linecap":"round","stroke-linejoin":"round",transform:textTransform,class:`pcb-copper-text pcb-copper-${layerName}`,"data-type":"pcb_copper_text","data-pcb-copper-text-id":pcbCopperText.pcb_copper_text_id},children:[],value:""}]}function createSvgObjectsFromPcbSilkscreenCircle(pcbSilkscreenCircle,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2}=ctx,{center:center2,radius,layer="top",pcb_silkscreen_circle_id,stroke_width=1,is_filled}=pcbSilkscreenCircle;if(layerFilter&&layer!==layerFilter)return[];if(!center2||typeof center2.x!="number"||typeof center2.y!="number"||typeof radius!="number")return console.error("Invalid PCB Silkscreen Circle data:",{center:center2,radius}),[];let[transformedX,transformedY]=applyToPoint3(transform6,[center2.x,center2.y]),transformedRadius=radius*Math.abs(transform6.a),transformedStrokeWidth=stroke_width*Math.abs(transform6.a),color=layer==="bottom"?colorMap2.silkscreen.bottom:colorMap2.silkscreen.top;return[{name:"circle",type:"element",attributes:{cx:transformedX.toString(),cy:transformedY.toString(),r:transformedRadius.toString(),class:`pcb-silkscreen-circle pcb-silkscreen-${layer}`,fill:is_filled?color:"none",stroke:color,"stroke-width":transformedStrokeWidth.toString(),"data-pcb-silkscreen-circle-id":pcb_silkscreen_circle_id,"data-type":"pcb_silkscreen_circle","data-pcb-layer":layer},value:"",children:[]}]}function createSvgObjectsFromPcbSilkscreenLine(pcbSilkscreenLine,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2}=ctx,{x1:x12,y1:y12,x2:x22,y2:y22,stroke_width,layer="top",pcb_silkscreen_line_id}=pcbSilkscreenLine;if(layerFilter&&layer!==layerFilter)return[];if(typeof x12!="number"||typeof y12!="number"||typeof x22!="number"||typeof y22!="number")return debugPcb(`[pcb_silkscreen_line] Invalid coordinates for "${pcb_silkscreen_line_id}": expected x1, y1, x2, y2 as numbers, got x1=${JSON.stringify(x12)}, y1=${JSON.stringify(y12)}, x2=${JSON.stringify(x22)}, y2=${JSON.stringify(y22)}`),[];let[transformedX1,transformedY1]=applyToPoint3(transform6,[x12,y12]),[transformedX2,transformedY2]=applyToPoint3(transform6,[x22,y22]),transformedStrokeWidth=stroke_width*Math.abs(transform6.a),color=layer==="bottom"?colorMap2.silkscreen.bottom:colorMap2.silkscreen.top;return[{name:"line",type:"element",attributes:{x1:transformedX1.toString(),y1:transformedY1.toString(),x2:transformedX2.toString(),y2:transformedY2.toString(),stroke:color,"stroke-width":transformedStrokeWidth.toString(),class:`pcb-silkscreen-line pcb-silkscreen-${layer}`,"data-pcb-silkscreen-line-id":pcb_silkscreen_line_id,"data-type":"pcb_silkscreen_line","data-pcb-layer":layer},value:"",children:[]}]}function createSvgObjectsFromPcbSilkscreenPill(pcbSilkscreenPill,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2}=ctx,{center:center2,width,height,layer="top",pcb_silkscreen_pill_id}=pcbSilkscreenPill;if(layerFilter&&layer!==layerFilter)return[];let[transformedX,transformedY]=applyToPoint3(transform6,[center2.x,center2.y]),transformedWidth=width*Math.abs(transform6.a),transformedHeight=height*Math.abs(transform6.d),baseCornerRadius=Math.min(width,height)/2,transformedCornerRadiusX=baseCornerRadius*Math.abs(transform6.a),transformedCornerRadiusY=baseCornerRadius*Math.abs(transform6.d),color=layer==="bottom"?colorMap2.silkscreen.bottom:colorMap2.silkscreen.top;return[{name:"rect",type:"element",attributes:{x:(transformedX-transformedWidth/2).toString(),y:(transformedY-transformedHeight/2).toString(),width:transformedWidth.toString(),height:transformedHeight.toString(),rx:transformedCornerRadiusX.toString(),ry:transformedCornerRadiusY.toString(),fill:"none",stroke:color,"stroke-width":(.1*Math.abs(transform6.a)).toString(),class:`pcb-silkscreen-pill pcb-silkscreen-${layer}`,"data-pcb-silkscreen-pill-id":pcb_silkscreen_pill_id,"data-type":"pcb_silkscreen_pill","data-pcb-layer":layer},value:"",children:[]}]}function createSvgObjectsFromPcbSilkscreenOval(pcbSilkscreenOval,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2}=ctx,{center:center2,radius_x,radius_y,layer="top",pcb_silkscreen_oval_id,ccw_rotation=0}=pcbSilkscreenOval;if(layerFilter&&layer!==layerFilter)return[];if(!center2||typeof center2.x!="number"||typeof center2.y!="number"||typeof radius_x!="number"||typeof radius_y!="number")return debugPcb(`[pcb_silkscreen_oval] Invalid data for "${pcb_silkscreen_oval_id}": expected center {x: number, y: number}, radius_x: number, radius_y: number, got center=${JSON.stringify(center2)}, radius_x=${JSON.stringify(radius_x)}, radius_y=${JSON.stringify(radius_y)}`),[];let[transformedX,transformedY]=applyToPoint3(transform6,[center2.x,center2.y]),transformedRadiusX=radius_x*Math.abs(transform6.a),transformedRadiusY=radius_y*Math.abs(transform6.d),color=layer==="bottom"?colorMap2.silkscreen.bottom:colorMap2.silkscreen.top;return[{name:"ellipse",type:"element",attributes:{cx:transformedX.toString(),cy:transformedY.toString(),rx:transformedRadiusX.toString(),ry:transformedRadiusY.toString(),fill:"none",stroke:color,"stroke-width":(.1*Math.abs(transform6.a)).toString(),class:`pcb-silkscreen-oval pcb-silkscreen-${layer}`,"data-pcb-silkscreen-oval-id":pcb_silkscreen_oval_id,"data-type":"pcb_silkscreen_oval","data-pcb-layer":layer,...ccw_rotation!==0&&{transform:`rotate(${-ccw_rotation} ${transformedX} ${transformedY})`}},value:"",children:[]}]}function createSvgObjectsFromPcbCourtyardRect(pcbCourtyardRect,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2}=ctx,{center:center2,width,height,layer="top",pcb_courtyard_rect_id,ccw_rotation=0}=pcbCourtyardRect;if(layerFilter&&layer!==layerFilter)return[];if(!center2||typeof center2.x!="number"||typeof center2.y!="number"||typeof width!="number"||typeof height!="number")return debugPcb(`[pcb_courtyard_rect] Invalid data for "${pcb_courtyard_rect_id}": expected center {x: number, y: number}, width: number, height: number, got center=${JSON.stringify(center2)}, width=${JSON.stringify(width)}, height=${JSON.stringify(height)}`),[];let[transformedX,transformedY]=applyToPoint3(transform6,[center2.x,center2.y]),transformedWidth=width*Math.abs(transform6.a),transformedHeight=height*Math.abs(transform6.d),transformedStrokeWidth=.05*Math.abs(transform6.a),color=layer==="bottom"?colorMap2.courtyard.bottom:colorMap2.courtyard.top,attributes2={x:(-transformedWidth/2).toString(),y:(-transformedHeight/2).toString(),width:transformedWidth.toString(),height:transformedHeight.toString(),class:`pcb-courtyard-rect pcb-courtyard-${layer}`,"data-pcb-courtyard-rect-id":pcb_courtyard_rect_id,"data-type":"pcb_courtyard_rect","data-pcb-layer":layer,"stroke-linejoin":"round"};return typeof ccw_rotation=="number"&&ccw_rotation!==0?attributes2.transform=`translate(${transformedX} ${transformedY}) rotate(${-ccw_rotation})`:(attributes2.x=(transformedX-transformedWidth/2).toString(),attributes2.y=(transformedY-transformedHeight/2).toString()),attributes2.fill="none",attributes2.stroke=color,attributes2["stroke-width"]=transformedStrokeWidth.toString(),[{name:"rect",type:"element",attributes:attributes2,value:"",children:[]}]}function createSvgObjectsFromPcbCourtyardPolygon(pcbCourtyardPolygon,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2}=ctx,{layer="top",pcb_courtyard_polygon_id,points,color}=pcbCourtyardPolygon;if(layerFilter&&layer!==layerFilter)return[];if(!points||points.length===0)return debugPcb(`[pcb_courtyard_polygon] Invalid data for "${pcb_courtyard_polygon_id}": expected non-empty array of points, got ${JSON.stringify(points)}`),[];let pointsString=points.map(p4=>applyToPoint3(transform6,[p4.x,p4.y])).map(p4=>`${p4[0]},${p4[1]}`).join(" "),transformedStrokeWidth=.05*Math.abs(transform6.a),strokeColor=color??(layer==="bottom"?colorMap2.courtyard.bottom:colorMap2.courtyard.top);return[{name:"polygon",type:"element",attributes:{points:pointsString,class:`pcb-courtyard-polygon pcb-courtyard-${layer}`,"data-pcb-courtyard-polygon-id":pcb_courtyard_polygon_id,"data-type":"pcb_courtyard_polygon","data-pcb-layer":layer,fill:"none",stroke:strokeColor,"stroke-width":transformedStrokeWidth.toString(),"stroke-linejoin":"round"},value:"",children:[]}]}function createSvgObjectsFromPcbCourtyardOutline(pcbCourtyardOutline,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2}=ctx,{layer,pcb_courtyard_outline_id,outline}=pcbCourtyardOutline;if(layerFilter&&layer!==layerFilter)return[];if(!outline||outline.length===0)return debugPcb(`[pcb_courtyard_outline] Invalid data for "${pcb_courtyard_outline_id}": expected non-empty array of points, got ${JSON.stringify(outline)}`),[];let pointsString=outline.map(p4=>applyToPoint3(transform6,[p4.x,p4.y])).map(p4=>`${p4[0]},${p4[1]}`).join(" "),transformedStrokeWidth=.05*Math.abs(transform6.a),strokeColor=layer==="bottom"?colorMap2.courtyard.bottom:colorMap2.courtyard.top;return[{name:"polygon",type:"element",attributes:{points:pointsString,class:`pcb-courtyard-outline pcb-courtyard-${layer}`,"data-pcb-courtyard-outline-id":pcb_courtyard_outline_id,"data-type":"pcb_courtyard_outline","data-pcb-layer":layer,fill:"none",stroke:strokeColor,"stroke-width":transformedStrokeWidth.toString(),"stroke-linejoin":"round"},value:"",children:[]}]}function createSvgObjectsFromPcbCourtyardCircle(pcbCourtyardCircle,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2}=ctx,{center:center2,radius,layer="top",pcb_courtyard_circle_id}=pcbCourtyardCircle;if(layerFilter&&layer!==layerFilter)return[];if(!center2||typeof center2.x!="number"||typeof center2.y!="number"||typeof radius!="number")return console.error(`[pcb_courtyard_circle] Invalid data for "${pcb_courtyard_circle_id}": expected center {x: number, y: number}, radius: number, got center=${JSON.stringify(center2)}, radius=${JSON.stringify(radius)}`),[];let[transformedX,transformedY]=applyToPoint3(transform6,[center2.x,center2.y]),transformedRadius=radius*Math.abs(transform6.a),transformedStrokeWidth=.05*Math.abs(transform6.a),color=layer==="bottom"?colorMap2.courtyard.bottom:colorMap2.courtyard.top,attributes2={cx:transformedX.toString(),cy:transformedY.toString(),r:transformedRadius.toString(),class:`pcb-courtyard-circle pcb-courtyard-${layer}`,"data-pcb-courtyard-circle-id":pcb_courtyard_circle_id,"data-type":"pcb_courtyard_circle","data-pcb-layer":layer};return attributes2.fill="none",attributes2.stroke=color,attributes2["stroke-width"]=transformedStrokeWidth.toString(),[{name:"circle",type:"element",attributes:attributes2,value:"",children:[]}]}function getPcbTracePoints(point7){return point7.route_type==="through_pad"?[point7.start,point7.end]:[point7]}function getPcbTraceSegments(route){let segments=[];for(let i3=0;i3<route.length-1;i3++){let start=route[i3],end=route[i3+1];if(!start||!end)continue;let startAnchor=start.route_type==="through_pad"?start.end:start,endAnchor=end.route_type==="through_pad"?end.start:end,layer=start.route_type==="wire"?start.layer:start.route_type==="through_pad"?start.end_layer:end.route_type==="wire"?end.layer:end.route_type==="through_pad"?end.start_layer:null;layer&&segments.push({start:startAnchor,end:endAnchor,layer,width:"width"in start?start.width:"width"in end?end.width:0,isInsideCopperPour:isInsideCopperPour(start)&&isInsideCopperPour(end)})}for(let point7 of route)if(point7.route_type==="through_pad")for(let layer of new Set([point7.start_layer,point7.end_layer]))segments.push({start:point7.start,end:point7.end,layer,width:point7.width,isInsideCopperPour:!1});return segments}function isInsideCopperPour(point7){return"is_inside_copper_pour"in point7&&point7.is_inside_copper_pour===!0}function createSvgObjectsFromPcbTrace(trace,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2,showSolderMask}=ctx;if(!trace.route||!Array.isArray(trace.route)||trace.route.length<2)return[];let svgObjects=[];for(let segment2 of getPcbTraceSegments(trace.route)){if(segment2.isInsideCopperPour)continue;let startPoint=applyToPoint3(transform6,[segment2.start.x,segment2.start.y]),endPoint=applyToPoint3(transform6,[segment2.end.x,segment2.end.y]),layer=segment2.layer;if(!layer||layerFilter&&layer!==layerFilter)continue;let copperColor=layerNameToColor(layer,colorMap2),maskColor=colorMap2.soldermaskWithCopperUnderneath[layer],width=segment2.width?(segment2.width*Math.abs(transform6.a)).toString():"0.3";if(showSolderMask){let maskObject={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask",stroke:maskColor,fill:"none",d:`M ${startPoint[0]} ${startPoint[1]} L ${endPoint[0]} ${endPoint[1]}`,"stroke-width":width,"stroke-linecap":"round","stroke-linejoin":"round","shape-rendering":"crispEdges","data-type":"pcb_trace_soldermask","data-pcb-layer":layer}};svgObjects.push(maskObject)}else{let maskOnlyObject={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-trace",stroke:copperColor,fill:"none",d:`M ${startPoint[0]} ${startPoint[1]} L ${endPoint[0]} ${endPoint[1]}`,"stroke-width":width,"stroke-linecap":"round","stroke-linejoin":"round","shape-rendering":"crispEdges","data-type":showSolderMask?"pcb_soldermask":"pcb_trace","data-pcb-layer":layer}};svgObjects.push(maskOnlyObject)}}return svgObjects}function createSvgObjectsFromSmtPad(pad2,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2,showSolderMask}=ctx;if(layerFilter&&pad2.layer!==layerFilter)return[];let isCoveredWithSolderMask=!!pad2?.is_covered_with_solder_mask,shouldShowSolderMask=showSolderMask&&isCoveredWithSolderMask,soldermaskWithCopperUnderneathColor=colorMap2.soldermaskWithCopperUnderneath[pad2.layer]??colorMap2.soldermaskWithCopperUnderneath.top,soldermaskMargin=(pad2.soldermask_margin??0)*Math.abs(transform6.a);if(pad2.shape==="rect"||pad2.shape==="rotated_rect"){let width=pad2.width*Math.abs(transform6.a),height=pad2.height*Math.abs(transform6.d),[x4,y4]=applyToPoint3(transform6,[pad2.x,pad2.y]),scaledBorderRadius=(pad2.corner_radius??pad2.rect_border_radius??0)*Math.abs(transform6.a),m4={left:(pad2.soldermask_margin_left??pad2.soldermask_margin??0)*Math.abs(transform6.a),right:(pad2.soldermask_margin_right??pad2.soldermask_margin??0)*Math.abs(transform6.a),top:(pad2.soldermask_margin_top??pad2.soldermask_margin??0)*Math.abs(transform6.a),bottom:(pad2.soldermask_margin_bottom??pad2.soldermask_margin??0)*Math.abs(transform6.a)},isNegativeMargin=m4.left<0||m4.right<0||m4.top<0||m4.bottom<0,isZeroMargin=m4.left===0&&m4.right===0&&m4.top===0&&m4.bottom===0;if(pad2.shape==="rotated_rect"&&pad2.ccw_rotation){let padElement2={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:layerNameToColor(pad2.layer,colorMap2),x:(-width/2).toString(),y:(-height/2).toString(),width:width.toString(),height:height.toString(),transform:`translate(${x4} ${y4}) rotate(${-pad2.ccw_rotation})`,"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer,...scaledBorderRadius?{rx:scaledBorderRadius.toString(),ry:scaledBorderRadius.toString()}:{}}};if(!shouldShowSolderMask)return[padElement2];let maskWidth2=width+m4.left+m4.right,maskHeight2=height+m4.top+m4.bottom,maskBorderRadius2=scaledBorderRadius?scaledBorderRadius+soldermaskMargin:0;if(isNegativeMargin){let coveredPadElement={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad-covered",fill:soldermaskWithCopperUnderneathColor,x:(-width/2).toString(),y:(-height/2).toString(),width:width.toString(),height:height.toString(),transform:`translate(${x4} ${y4}) rotate(${-pad2.ccw_rotation})`,"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer,...scaledBorderRadius?{rx:scaledBorderRadius.toString(),ry:scaledBorderRadius.toString()}:{}}},exposedOpeningElement={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad-exposed",fill:layerNameToColor(pad2.layer,colorMap2),x:(-width/2-m4.left).toString(),y:(-height/2-m4.top).toString(),width:maskWidth2.toString(),height:maskHeight2.toString(),transform:`translate(${x4} ${y4}) rotate(${-pad2.ccw_rotation})`,"data-type":"pcb_soldermask","data-pcb-layer":pad2.layer,...maskBorderRadius2>0?{rx:maskBorderRadius2.toString(),ry:maskBorderRadius2.toString()}:{}}};return[coveredPadElement,exposedOpeningElement]}return isZeroMargin?[{name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad-covered",fill:soldermaskWithCopperUnderneathColor,x:(-width/2).toString(),y:(-height/2).toString(),width:width.toString(),height:height.toString(),transform:`translate(${x4} ${y4}) rotate(${-pad2.ccw_rotation})`,"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer,...scaledBorderRadius?{rx:scaledBorderRadius.toString(),ry:scaledBorderRadius.toString()}:{}}}]:[{name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,x:(-width/2-m4.left).toString(),y:(-height/2-m4.top).toString(),width:maskWidth2.toString(),height:maskHeight2.toString(),transform:`translate(${x4} ${y4}) rotate(${-pad2.ccw_rotation})`,...maskBorderRadius2>0?{rx:maskBorderRadius2.toString(),ry:maskBorderRadius2.toString()}:{},"data-type":"pcb_soldermask_opening","data-pcb-layer":pad2.layer}},padElement2]}let padElement={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:layerNameToColor(pad2.layer,colorMap2),x:(x4-width/2).toString(),y:(y4-height/2).toString(),width:width.toString(),height:height.toString(),"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer,...scaledBorderRadius?{rx:scaledBorderRadius.toString(),ry:scaledBorderRadius.toString()}:{}}};if(!shouldShowSolderMask)return[padElement];let maskWidth=width+m4.left+m4.right,maskHeight=height+m4.top+m4.bottom,maskBorderRadius=scaledBorderRadius?scaledBorderRadius+soldermaskMargin:0;if(isNegativeMargin){let coveredPadElement={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad-covered",fill:soldermaskWithCopperUnderneathColor,x:(x4-width/2).toString(),y:(y4-height/2).toString(),width:width.toString(),height:height.toString(),"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer,...scaledBorderRadius?{rx:scaledBorderRadius.toString(),ry:scaledBorderRadius.toString()}:{}}},exposedOpeningElement={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad-exposed",fill:layerNameToColor(pad2.layer,colorMap2),x:(x4-width/2-m4.left).toString(),y:(y4-height/2-m4.top).toString(),width:maskWidth.toString(),height:maskHeight.toString(),"data-type":"pcb_soldermask","data-pcb-layer":pad2.layer,...maskBorderRadius>0?{rx:maskBorderRadius.toString(),ry:maskBorderRadius.toString()}:{}}};return[coveredPadElement,exposedOpeningElement]}return isZeroMargin?[{name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad-covered",fill:soldermaskWithCopperUnderneathColor,x:(x4-width/2).toString(),y:(y4-height/2).toString(),width:width.toString(),height:height.toString(),...maskBorderRadius>0?{rx:scaledBorderRadius.toString(),ry:scaledBorderRadius.toString()}:{},"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer}}]:[{name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,x:(x4-width/2-m4.left).toString(),y:(y4-height/2-m4.top).toString(),width:maskWidth.toString(),height:maskHeight.toString(),...maskBorderRadius>0?{rx:maskBorderRadius.toString(),ry:maskBorderRadius.toString()}:{},"data-type":"pcb_soldermask_opening","data-pcb-layer":pad2.layer}},padElement]}if(pad2.shape==="pill"||pad2.shape==="rotated_pill"){let isRotated=pad2.shape==="rotated_pill",width=pad2.width*Math.abs(transform6.a),height=pad2.height*Math.abs(transform6.d),radius=pad2.radius*Math.abs(transform6.a),[x4,y4]=applyToPoint3(transform6,[pad2.x,pad2.y]),rotationTransformAttributes=isRotated?{transform:`translate(${x4} ${y4}) rotate(${-(pad2.ccw_rotation??0)})`}:void 0,baseAttributes={class:"pcb-pad",fill:layerNameToColor(pad2.layer,colorMap2),x:isRotated?(-width/2).toString():(x4-width/2).toString(),y:isRotated?(-height/2).toString():(y4-height/2).toString(),width:width.toString(),height:height.toString(),rx:radius.toString(),ry:radius.toString(),"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer,...rotationTransformAttributes??{}},padElement={name:"rect",type:"element",value:"",children:[],attributes:baseAttributes};if(!shouldShowSolderMask)return[padElement];let maskWidth=width+2*soldermaskMargin,maskHeight=height+2*soldermaskMargin,maskRadius=radius+soldermaskMargin;if(soldermaskMargin<0){let coveredPadElement={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad-covered",fill:soldermaskWithCopperUnderneathColor,x:isRotated?(-width/2).toString():(x4-width/2).toString(),y:isRotated?(-height/2).toString():(y4-height/2).toString(),width:width.toString(),height:height.toString(),rx:radius.toString(),ry:radius.toString(),"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer,...rotationTransformAttributes??{}}},exposedAttributes={class:"pcb-pad-exposed",fill:layerNameToColor(pad2.layer,colorMap2),x:isRotated?(-maskWidth/2).toString():(x4-maskWidth/2).toString(),y:isRotated?(-maskHeight/2).toString():(y4-maskHeight/2).toString(),width:maskWidth.toString(),height:maskHeight.toString(),rx:maskRadius.toString(),ry:maskRadius.toString(),"data-type":"pcb_soldermask","data-pcb-layer":pad2.layer,...rotationTransformAttributes??{}};return[coveredPadElement,{name:"rect",type:"element",value:"",children:[],attributes:exposedAttributes}]}if(soldermaskMargin===0)return[{name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-pad-covered",fill:soldermaskWithCopperUnderneathColor,x:isRotated?(-width/2).toString():(x4-width/2).toString(),y:isRotated?(-height/2).toString():(y4-height/2).toString(),width:width.toString(),height:height.toString(),rx:radius.toString(),ry:radius.toString(),"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer,...rotationTransformAttributes??{}}}];let substrateAttributes={class:"pcb-soldermask-cutout",fill:colorMap2.substrate,x:isRotated?(-maskWidth/2).toString():(x4-maskWidth/2).toString(),y:isRotated?(-maskHeight/2).toString():(y4-maskHeight/2).toString(),width:maskWidth.toString(),height:maskHeight.toString(),rx:maskRadius.toString(),ry:maskRadius.toString(),"data-type":"pcb_soldermask_opening","data-pcb-layer":pad2.layer,...rotationTransformAttributes??{}};return[{name:"rect",type:"element",value:"",children:[],attributes:substrateAttributes},padElement]}if(pad2.shape==="circle"){let radius=pad2.radius*Math.abs(transform6.a),[x4,y4]=applyToPoint3(transform6,[pad2.x,pad2.y]),padElement={name:"circle",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:layerNameToColor(pad2.layer,colorMap2),cx:x4.toString(),cy:y4.toString(),r:radius.toString(),"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer}};if(!shouldShowSolderMask)return[padElement];let maskRadius=radius+soldermaskMargin;if(soldermaskMargin<0){let coveredPadElement={name:"circle",type:"element",value:"",children:[],attributes:{class:"pcb-pad-covered",fill:soldermaskWithCopperUnderneathColor,cx:x4.toString(),cy:y4.toString(),r:radius.toString(),"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer}},exposedOpeningElement={name:"circle",type:"element",value:"",children:[],attributes:{class:"pcb-pad-exposed",fill:layerNameToColor(pad2.layer,colorMap2),cx:x4.toString(),cy:y4.toString(),r:maskRadius.toString(),"data-type":"pcb_soldermask","data-pcb-layer":pad2.layer}};return[coveredPadElement,exposedOpeningElement]}return soldermaskMargin===0?[{name:"circle",type:"element",value:"",children:[],attributes:{class:"pcb-pad-covered",fill:soldermaskWithCopperUnderneathColor,cx:x4.toString(),cy:y4.toString(),r:radius.toString(),"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer}}]:[{name:"circle",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,cx:x4.toString(),cy:y4.toString(),r:maskRadius.toString(),"data-type":"pcb_soldermask_opening","data-pcb-layer":pad2.layer}},padElement]}if(pad2.shape==="polygon"){let points=(pad2.points??[]).map(point7=>applyToPoint3(transform6,[point7.x,point7.y])),padElement={name:"polygon",type:"element",value:"",children:[],attributes:{class:"pcb-pad",fill:layerNameToColor(pad2.layer,colorMap2),points:points.map(p4=>p4.join(",")).join(" "),"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer}};if(!shouldShowSolderMask)return[padElement];let maskPoints=points;if(soldermaskMargin!==0){let centroidX=points.reduce((sum,p4)=>sum+p4[0],0)/points.length,centroidY=points.reduce((sum,p4)=>sum+p4[1],0)/points.length;maskPoints=points.map(([px3,py3])=>{let dx3=px3-centroidX,dy3=py3-centroidY,distance62=Math.sqrt(dx3*dx3+dy3*dy3);if(distance62===0)return[px3,py3];let normalizedDx=dx3/distance62,normalizedDy=dy3/distance62;return[px3+normalizedDx*soldermaskMargin,py3+normalizedDy*soldermaskMargin]})}if(soldermaskMargin<0){let coveredPadElement={name:"polygon",type:"element",value:"",children:[],attributes:{class:"pcb-pad-covered",fill:soldermaskWithCopperUnderneathColor,points:points.map(p4=>p4.join(",")).join(" "),"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer}},exposedOpeningElement={name:"polygon",type:"element",value:"",children:[],attributes:{class:"pcb-pad-exposed",fill:layerNameToColor(pad2.layer,colorMap2),points:maskPoints.map(p4=>p4.join(",")).join(" "),"data-type":"pcb_soldermask","data-pcb-layer":pad2.layer}};return[coveredPadElement,exposedOpeningElement]}return soldermaskMargin===0?[{name:"polygon",type:"element",value:"",children:[],attributes:{class:"pcb-pad-covered",fill:soldermaskWithCopperUnderneathColor,points:points.map(p4=>p4.join(",")).join(" "),"data-type":"pcb_smtpad","data-pcb-layer":pad2.layer}}]:[{name:"polygon",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,points:maskPoints.map(p4=>p4.join(",")).join(" "),"data-type":"pcb_soldermask_opening","data-pcb-layer":pad2.layer}},padElement]}return[]}function createAnchorOffsetIndicators(params){let{groupAnchorPosition,componentPosition,transform:transform6,componentWidth=0,componentHeight=0,displayXOffset,displayYOffset}=params,objects=[],[screenGroupAnchorX,screenGroupAnchorY]=applyToPoint3(transform6,[groupAnchorPosition.x,groupAnchorPosition.y]),[screenComponentX,screenComponentY]=applyToPoint3(transform6,[componentPosition.x,componentPosition.y]),offsetX=componentPosition.x-groupAnchorPosition.x,offsetY=componentPosition.y-groupAnchorPosition.y,scale10=Math.abs(transform6.a),screenComponentWidth=componentWidth*scale10,screenComponentHeight=componentHeight*scale10;objects.push(createAnchorMarker(screenGroupAnchorX,screenGroupAnchorY));let trimmedConnector=getTrimmedConnectorLine(screenGroupAnchorX,screenGroupAnchorY,screenComponentX,screenComponentY);objects.push({name:"line",type:"element",attributes:{x1:trimmedConnector.x1.toString(),y1:trimmedConnector.y1.toString(),x2:trimmedConnector.x2.toString(),y2:trimmedConnector.y2.toString(),stroke:"#ffffff","stroke-width":"0.5","stroke-dasharray":"3,3",opacity:"0.5",class:"anchor-offset-connector"},children:[],value:""}),objects.push({name:"circle",type:"element",attributes:{cx:screenComponentX.toString(),cy:screenComponentY.toString(),r:COMPONENT_ANCHOR_MARKER_RADIUS_PX.toString(),fill:"#ffffff",opacity:"0.7",class:"anchor-offset-component-marker"},children:[],value:""});let yDistance=Math.abs(screenComponentY-screenGroupAnchorY),xDistance=Math.abs(screenComponentX-screenGroupAnchorX),totalDistance=Math.sqrt(xDistance*xDistance+yDistance*yDistance),componentHeightOffset=screenComponentHeight/2+COMPONENT_GAP_PX,dynamicOffset=Math.max(componentHeightOffset,Math.min(MAX_OFFSET_PX,totalDistance*DISTANCE_MULTIPLIER)),horizontalLineY=offsetY>0?screenComponentY-dynamicOffset:screenComponentY+dynamicOffset,componentWidthOffset=screenComponentWidth/2+COMPONENT_SIDE_GAP_PX,verticalLineX=offsetX>0?screenComponentX+componentWidthOffset:screenComponentX-componentWidthOffset;if(isTooCloseToAnchor(horizontalLineY,screenGroupAnchorY)||isTooCloseToAnchor(horizontalLineY,screenComponentY)){let minY=Math.min(screenGroupAnchorY,screenComponentY),maxY=Math.max(screenGroupAnchorY,screenComponentY),candidateAbove=minY-DIMENSION_ANCHOR_CLEARANCE_PX,candidateBelow=maxY+DIMENSION_ANCHOR_CLEARANCE_PX;horizontalLineY=Math.abs(horizontalLineY-candidateAbove)<Math.abs(horizontalLineY-candidateBelow)?candidateAbove:candidateBelow}if(isTooCloseToAnchor(verticalLineX,screenGroupAnchorX)||isTooCloseToAnchor(verticalLineX,screenComponentX)){let minX=Math.min(screenGroupAnchorX,screenComponentX),maxX=Math.max(screenGroupAnchorX,screenComponentX),candidateLeft=minX-DIMENSION_ANCHOR_CLEARANCE_PX,candidateRight=maxX+DIMENSION_ANCHOR_CLEARANCE_PX;verticalLineX=Math.abs(verticalLineX-candidateLeft)<Math.abs(verticalLineX-candidateRight)?candidateLeft:candidateRight}return Math.abs(offsetX)>OFFSET_THRESHOLD_MM&&objects.push(...createHorizontalDimension({startX:screenGroupAnchorX,endX:screenComponentX,y:horizontalLineY,offsetMm:offsetX,offsetY,displayOffset:displayXOffset})),Math.abs(offsetY)>OFFSET_THRESHOLD_MM&&objects.push(...createVerticalDimension({x:verticalLineX,startY:screenGroupAnchorY,endY:screenComponentY,offsetMm:offsetY,offsetX,displayOffset:displayYOffset})),objects}function getTrimmedConnectorLine(x12,y12,x22,y22){let dx3=x22-x12,dy3=y22-y12,distance62=Math.hypot(dx3,dy3),totalTrim=CONNECTOR_GROUP_GAP_PX+CONNECTOR_COMPONENT_GAP_PX;if(!(distance62>totalTrim))return{x1:x12,y1:y12,x2:x22,y2:y22};let ux3=dx3/distance62,uy3=dy3/distance62;return{x1:x12+ux3*CONNECTOR_GROUP_GAP_PX,y1:y12+uy3*CONNECTOR_GROUP_GAP_PX,x2:x22-ux3*CONNECTOR_COMPONENT_GAP_PX,y2:y22-uy3*CONNECTOR_COMPONENT_GAP_PX}}function isTooCloseToAnchor(value,anchorValue){return Math.abs(value-anchorValue)<DIMENSION_ANCHOR_CLEARANCE_PX}function createAnchorMarker(x4,y4){return{name:"g",type:"element",attributes:{class:"anchor-offset-marker","data-type":"anchor_offset_marker"},children:[{name:"line",type:"element",attributes:{x1:x4.toString(),y1:(y4-ANCHOR_MARKER_SIZE_PX).toString(),x2:x4.toString(),y2:(y4+ANCHOR_MARKER_SIZE_PX).toString(),stroke:"#ffffff","stroke-width":ANCHOR_MARKER_STROKE_WIDTH_PX.toString(),"stroke-linecap":"round"},children:[],value:""},{name:"line",type:"element",attributes:{x1:(x4-ANCHOR_MARKER_SIZE_PX).toString(),y1:y4.toString(),x2:(x4+ANCHOR_MARKER_SIZE_PX).toString(),y2:y4.toString(),stroke:"#ffffff","stroke-width":ANCHOR_MARKER_STROKE_WIDTH_PX.toString(),"stroke-linecap":"round"},children:[],value:""}],value:""}}function createHorizontalDimension({startX,endX,y:y4,offsetMm,offsetY,displayOffset}){let objects=[];objects.push({name:"line",type:"element",attributes:{x1:startX.toString(),y1:y4.toString(),x2:endX.toString(),y2:y4.toString(),stroke:"#ffffff","stroke-width":STROKE_WIDTH_PX.toString(),class:"anchor-offset-dimension-x"},children:[],value:""}),objects.push({name:"line",type:"element",attributes:{x1:startX.toString(),y1:(y4-TICK_SIZE_PX).toString(),x2:startX.toString(),y2:(y4+TICK_SIZE_PX).toString(),stroke:"#ffffff","stroke-width":STROKE_WIDTH_PX.toString()},children:[],value:""}),objects.push({name:"line",type:"element",attributes:{x1:endX.toString(),y1:(y4-TICK_SIZE_PX).toString(),x2:endX.toString(),y2:(y4+TICK_SIZE_PX).toString(),stroke:"#ffffff","stroke-width":STROKE_WIDTH_PX.toString()},children:[],value:""});let midX=(startX+endX)/2,labelY=offsetY>0?y4-TICK_SIZE_PX-LABEL_GAP_PX:y4+TICK_SIZE_PX+LABEL_GAP_PX;return objects.push({name:"text",type:"element",attributes:{x:midX.toString(),y:labelY.toString(),fill:"#ffffff","font-size":LABEL_FONT_SIZE_PX.toString(),"font-family":"Arial, sans-serif","text-anchor":"middle","dominant-baseline":offsetY>0?"baseline":"hanging",class:"anchor-offset-label"},children:[{type:"text",value:formatOffsetLabel("X",offsetMm,displayOffset),name:"",attributes:{},children:[]}],value:""}),objects}function createVerticalDimension({x:x4,startY,endY,offsetMm,offsetX,displayOffset}){let objects=[];objects.push({name:"line",type:"element",attributes:{x1:x4.toString(),y1:startY.toString(),x2:x4.toString(),y2:endY.toString(),stroke:"#ffffff","stroke-width":STROKE_WIDTH_PX.toString(),class:"anchor-offset-dimension-y"},children:[],value:""}),objects.push({name:"line",type:"element",attributes:{x1:(x4-TICK_SIZE_PX).toString(),y1:startY.toString(),x2:(x4+TICK_SIZE_PX).toString(),y2:startY.toString(),stroke:"#ffffff","stroke-width":STROKE_WIDTH_PX.toString()},children:[],value:""}),objects.push({name:"line",type:"element",attributes:{x1:(x4-TICK_SIZE_PX).toString(),y1:endY.toString(),x2:(x4+TICK_SIZE_PX).toString(),y2:endY.toString(),stroke:"#ffffff","stroke-width":STROKE_WIDTH_PX.toString()},children:[],value:""});let midY=(startY+endY)/2,labelX=offsetX<0?x4-TICK_SIZE_PX-4:x4+TICK_SIZE_PX+4;return objects.push({name:"text",type:"element",attributes:{x:labelX.toString(),y:midY.toString(),fill:"#ffffff","font-size":LABEL_FONT_SIZE_PX.toString(),"font-family":"Arial, sans-serif","text-anchor":offsetX<0?"end":"start","dominant-baseline":"middle",class:"anchor-offset-label"},children:[{type:"text",value:formatOffsetLabel("Y",offsetMm,displayOffset),name:"",attributes:{},children:[]}],value:""}),objects}function formatOffsetLabel(axis,offsetMm,displayOffset){let valueStr=typeof displayOffset=="string"?displayOffset:offsetMm.toFixed(2),unitSuffix=typeof valueStr=="string"&&valueStr.trim().endsWith("mm")?"":"mm";return`${axis}: ${valueStr}${unitSuffix}`}function getPointFromElm(elm){let candidate=elm?.anchor_position??elm?.center;if(candidate&&typeof candidate.x=="number"&&typeof candidate.y=="number")return{x:candidate.x,y:candidate.y}}function createSvgObjectsFromPcbBoard(pcbBoard,ctx){let{transform:transform6,colorMap:colorMap2,showSolderMask,circuitJson}=ctx,{width,height,center:center2,outline,position_mode,anchor_position:boardAnchorPosition,display_offset_x,display_offset_y}=pcbBoard,path;if(outline&&Array.isArray(outline)&&outline.length>=3)path=outline.map((point7,index)=>{let[x4,y4]=applyToPoint3(transform6,[point7.x,point7.y]);return index===0?`M ${x4} ${y4}`:`L ${x4} ${y4}`}).join(" ");else{let halfWidth=width/2,halfHeight=height/2,topLeft=applyToPoint3(transform6,[center2.x-halfWidth,center2.y-halfHeight]),topRight=applyToPoint3(transform6,[center2.x+halfWidth,center2.y-halfHeight]),bottomRight=applyToPoint3(transform6,[center2.x+halfWidth,center2.y+halfHeight]),bottomLeft=applyToPoint3(transform6,[center2.x-halfWidth,center2.y+halfHeight]);path=`M ${topLeft[0]} ${topLeft[1]} L ${topRight[0]} ${topRight[1]} L ${bottomRight[0]} ${bottomRight[1]} L ${bottomLeft[0]} ${bottomLeft[1]}`}path+=" Z";let svgObjects=[];if(showSolderMask){let maskLayer=(ctx.layer??"top")==="bottom"?"soldermask-bottom":"soldermask-top";svgObjects.push({name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-board-soldermask",d:path,fill:colorMap2.soldermask.top,"fill-opacity":"0.8",stroke:"none","data-type":"pcb_soldermask","data-pcb-layer":maskLayer}})}if(svgObjects.push({name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-board",d:path,fill:"none",stroke:colorMap2.boardOutline,"stroke-width":(.1*Math.abs(transform6.a)).toString(),"data-type":"pcb_board","data-pcb-layer":"board"}}),ctx.showAnchorOffsets&&circuitJson&&position_mode==="relative_to_panel_anchor"){let panel=circuitJson.find(elm=>elm.type==="pcb_panel");if(panel){let panelAnchorPosition=getPointFromElm(panel);panelAnchorPosition&&svgObjects.push(...createAnchorOffsetIndicators({groupAnchorPosition:panelAnchorPosition,componentPosition:boardAnchorPosition??center2,transform:transform6,componentWidth:width,componentHeight:height,displayXOffset:display_offset_x,displayYOffset:display_offset_y}))}}return svgObjects}function createSvgObjectsFromPcbPanel(pcbPanel,ctx){let{transform:transform6,colorMap:colorMap2,showSolderMask}=ctx,width=Number(pcbPanel.width),height=Number(pcbPanel.height),center2=pcbPanel.center??{x:width/2,y:height/2},halfWidth=width/2,halfHeight=height/2,topLeft=applyToPoint3(transform6,[center2.x-halfWidth,center2.y-halfHeight]),topRight=applyToPoint3(transform6,[center2.x+halfWidth,center2.y-halfHeight]),bottomRight=applyToPoint3(transform6,[center2.x+halfWidth,center2.y+halfHeight]),bottomLeft=applyToPoint3(transform6,[center2.x-halfWidth,center2.y+halfHeight]),path=`M ${topLeft[0]} ${topLeft[1]} L ${topRight[0]} ${topRight[1]} L ${bottomRight[0]} ${bottomRight[1]} L ${bottomLeft[0]} ${bottomLeft[1]} Z`,isCoveredWithSolderMask=pcbPanel.covered_with_solder_mask!==!1,shouldShowSolderMask=!!(showSolderMask&&isCoveredWithSolderMask);return[{name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-panel",d:path,fill:"none",stroke:colorMap2.boardOutline,"stroke-width":(.1*Math.abs(transform6.a)).toString(),"data-type":"pcb_panel","data-pcb-layer":"board"}}]}function createSvgObjectsFromPcbVia(hole,ctx){let{transform:transform6,colorMap:colorMap2}=ctx,[x4,y4]=applyToPoint3(transform6,[hole.x,hole.y]),scaledOuterWidth=hole.outer_diameter*Math.abs(transform6.a),scaledOuterHeight=hole.outer_diameter*Math.abs(transform6.a),scaledHoleWidth=hole.hole_diameter*Math.abs(transform6.a),scaledHoleHeight=hole.hole_diameter*Math.abs(transform6.a),outerRadius=Math.min(scaledOuterWidth,scaledOuterHeight)/2,innerRadius=Math.min(scaledHoleWidth,scaledHoleHeight)/2;return{name:"g",type:"element",attributes:{"data-type":"pcb_via","data-pcb-layer":"through"},children:[{name:"circle",type:"element",attributes:{class:"pcb-hole-outer",fill:colorMap2.copper.top,cx:x4.toString(),cy:y4.toString(),r:outerRadius.toString(),"data-type":"pcb_via","data-pcb-layer":"top"}},{name:"circle",type:"element",attributes:{class:"pcb-hole-inner",fill:colorMap2.drill,cx:x4.toString(),cy:y4.toString(),r:innerRadius.toString(),"data-type":"pcb_via","data-pcb-layer":"drill"}}]}}function createSvgObjectsFromPcbHole(hole,ctx){let{transform:transform6,colorMap:colorMap2,showSolderMask}=ctx,layer=ctx.layer??"top",[x4,y4]=applyToPoint3(transform6,[hole.x,hole.y]),isCoveredWithSolderMask=!!hole.is_covered_with_solder_mask,soldermaskMargin=(hole.soldermask_margin??0)*Math.abs(transform6.a),shouldShowSolderMask=showSolderMask&&isCoveredWithSolderMask&&soldermaskMargin!==0,solderMaskColor=colorMap2.soldermask.top;if(hole.hole_shape==="circle"||hole.hole_shape==="square"){let scaledDiameter=hole.hole_diameter*Math.abs(transform6.a),radius=scaledDiameter/2;if(hole.hole_shape==="circle"){let holeElement2={name:"circle",type:"element",attributes:{class:"pcb-hole",cx:x4.toString(),cy:y4.toString(),r:radius.toString(),fill:colorMap2.drill,"data-type":"pcb_hole","data-pcb-layer":"drill"},children:[],value:""};if(!shouldShowSolderMask)return[holeElement2];let maskRadius=radius+soldermaskMargin;if(soldermaskMargin<0){let coveredElement={name:"circle",type:"element",value:"",children:[],attributes:{class:"pcb-hole-covered",fill:solderMaskColor,cx:x4.toString(),cy:y4.toString(),r:radius.toString(),"data-type":"pcb_hole","data-pcb-layer":"drill"}},exposedElement={name:"circle",type:"element",value:"",children:[],attributes:{class:"pcb-hole-exposed",fill:colorMap2.drill,cx:x4.toString(),cy:y4.toString(),r:maskRadius.toString(),"data-type":"pcb_soldermask","data-pcb-layer":"drill"}};return[coveredElement,exposedElement]}return[{name:"circle",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,cx:x4.toString(),cy:y4.toString(),r:maskRadius.toString(),"data-type":"pcb_soldermask_opening","data-pcb-layer":layer}},holeElement2]}let holeElement={name:"rect",type:"element",attributes:{class:"pcb-hole",x:(x4-radius).toString(),y:(y4-radius).toString(),width:scaledDiameter.toString(),height:scaledDiameter.toString(),fill:colorMap2.drill,"data-type":"pcb_hole","data-pcb-layer":"drill"},children:[],value:""};if(!shouldShowSolderMask)return[holeElement];let maskDiameter=scaledDiameter+2*soldermaskMargin;if(soldermaskMargin<0){let coveredElement={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-hole-covered",fill:solderMaskColor,x:(x4-radius).toString(),y:(y4-radius).toString(),width:scaledDiameter.toString(),height:scaledDiameter.toString(),"data-type":"pcb_hole","data-pcb-layer":"drill"}},exposedElement={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-hole-exposed",fill:colorMap2.drill,x:(x4-maskDiameter/2).toString(),y:(y4-maskDiameter/2).toString(),width:maskDiameter.toString(),height:maskDiameter.toString(),"data-type":"pcb_soldermask","data-pcb-layer":"drill"}};return[coveredElement,exposedElement]}return[{name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,x:(x4-maskDiameter/2).toString(),y:(y4-maskDiameter/2).toString(),width:maskDiameter.toString(),height:maskDiameter.toString(),"data-type":"pcb_soldermask_opening","data-pcb-layer":layer}},holeElement]}if(hole.hole_shape==="oval"){let scaledWidth=hole.hole_width*Math.abs(transform6.a),scaledHeight=hole.hole_height*Math.abs(transform6.a),rx3=scaledWidth/2,ry3=scaledHeight/2,holeElement={name:"ellipse",type:"element",attributes:{class:"pcb-hole",cx:x4.toString(),cy:y4.toString(),rx:rx3.toString(),ry:ry3.toString(),fill:colorMap2.drill,"data-type":"pcb_hole","data-pcb-layer":"drill"},children:[],value:""};if(!shouldShowSolderMask)return[holeElement];let maskRx=rx3+soldermaskMargin,maskRy=ry3+soldermaskMargin;if(soldermaskMargin<0){let coveredElement={name:"ellipse",type:"element",value:"",children:[],attributes:{class:"pcb-hole-covered",fill:solderMaskColor,cx:x4.toString(),cy:y4.toString(),rx:rx3.toString(),ry:ry3.toString(),"data-type":"pcb_hole","data-pcb-layer":"drill"}},exposedElement={name:"ellipse",type:"element",value:"",children:[],attributes:{class:"pcb-hole-exposed",fill:colorMap2.drill,cx:x4.toString(),cy:y4.toString(),rx:maskRx.toString(),ry:maskRy.toString(),"data-type":"pcb_soldermask","data-pcb-layer":"drill"}};return[coveredElement,exposedElement]}return[{name:"ellipse",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,cx:x4.toString(),cy:y4.toString(),rx:maskRx.toString(),ry:maskRy.toString(),"data-type":"pcb_soldermask_opening","data-pcb-layer":layer}},holeElement]}if(hole.hole_shape==="rect"){let scaledWidth=hole.hole_width*Math.abs(transform6.a),scaledHeight=hole.hole_height*Math.abs(transform6.a),holeElement={name:"rect",type:"element",attributes:{class:"pcb-hole",x:(x4-scaledWidth/2).toString(),y:(y4-scaledHeight/2).toString(),width:scaledWidth.toString(),height:scaledHeight.toString(),fill:colorMap2.drill,"data-type":"pcb_hole","data-pcb-layer":"drill"},children:[],value:""};if(!shouldShowSolderMask)return[holeElement];let maskWidth=scaledWidth+2*soldermaskMargin,maskHeight=scaledHeight+2*soldermaskMargin;if(soldermaskMargin<0){let coveredElement={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-hole-covered",fill:solderMaskColor,x:(x4-scaledWidth/2).toString(),y:(y4-scaledHeight/2).toString(),width:scaledWidth.toString(),height:scaledHeight.toString(),"data-type":"pcb_hole","data-pcb-layer":"drill"}},exposedElement={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-hole-exposed",fill:colorMap2.drill,x:(x4-maskWidth/2).toString(),y:(y4-maskHeight/2).toString(),width:maskWidth.toString(),height:maskHeight.toString(),"data-type":"pcb_soldermask","data-pcb-layer":"drill"}};return[coveredElement,exposedElement]}return[{name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,x:(x4-maskWidth/2).toString(),y:(y4-maskHeight/2).toString(),width:maskWidth.toString(),height:maskHeight.toString(),"data-type":"pcb_soldermask_opening","data-pcb-layer":layer}},holeElement]}if(hole.hole_shape==="pill"){let scaledWidth=hole.hole_width*Math.abs(transform6.a),scaledHeight=hole.hole_height*Math.abs(transform6.a),isHorizontal3=scaledWidth>scaledHeight,radius=Math.min(scaledWidth,scaledHeight)/2,straightLength=Math.abs(isHorizontal3?scaledWidth-scaledHeight:scaledHeight-scaledWidth),pathD=isHorizontal3?`M${x4-straightLength/2},${y4-radius} h${straightLength} a${radius},${radius} 0 0 1 0,${scaledHeight} h-${straightLength} a${radius},${radius} 0 0 1 0,-${scaledHeight} z`:`M${x4-radius},${y4-straightLength/2} v${straightLength} a${radius},${radius} 0 0 0 ${scaledWidth},0 v-${straightLength} a${radius},${radius} 0 0 0 -${scaledWidth},0 z`,holeElement={name:"path",type:"element",attributes:{class:"pcb-hole",fill:colorMap2.drill,d:pathD,"data-type":"pcb_hole","data-pcb-layer":"drill"},children:[],value:""};if(!shouldShowSolderMask)return[holeElement];let maskWidth=scaledWidth+2*soldermaskMargin,maskHeight=scaledHeight+2*soldermaskMargin,maskIsHorizontal=maskWidth>maskHeight,maskRadius=Math.min(maskWidth,maskHeight)/2,maskStraightLength=Math.abs(maskIsHorizontal?maskWidth-maskHeight:maskHeight-maskWidth),maskPathD=maskIsHorizontal?`M${x4-maskStraightLength/2},${y4-maskRadius} h${maskStraightLength} a${maskRadius},${maskRadius} 0 0 1 0,${maskHeight} h-${maskStraightLength} a${maskRadius},${maskRadius} 0 0 1 0,-${maskHeight} z`:`M${x4-maskRadius},${y4-maskStraightLength/2} v${maskStraightLength} a${maskRadius},${maskRadius} 0 0 0 ${maskWidth},0 v-${maskStraightLength} a${maskRadius},${maskRadius} 0 0 0 -${maskWidth},0 z`;if(soldermaskMargin<0){let coveredElement={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-hole-covered",fill:solderMaskColor,d:pathD,"data-type":"pcb_hole","data-pcb-layer":"drill"}},exposedElement={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-hole-exposed",fill:colorMap2.drill,d:maskPathD,"data-type":"pcb_soldermask","data-pcb-layer":"drill"}};return[coveredElement,exposedElement]}return[{name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,d:maskPathD,"data-type":"pcb_soldermask_opening","data-pcb-layer":layer}},holeElement]}if(hole.hole_shape==="rotated_pill"){let scaledWidth=hole.hole_width*Math.abs(transform6.a),scaledHeight=hole.hole_height*Math.abs(transform6.a),rotation5="ccw_rotation"in hole?hole.ccw_rotation??0:0,isHorizontal3=scaledWidth>scaledHeight,radius=Math.min(scaledWidth,scaledHeight)/2,straightLength=Math.abs(isHorizontal3?scaledWidth-scaledHeight:scaledHeight-scaledWidth),pathD=isHorizontal3?`M${-straightLength/2},${-radius} h${straightLength} a${radius},${radius} 0 0 1 0,${scaledHeight} h-${straightLength} a${radius},${radius} 0 0 1 0,-${scaledHeight} z`:`M${-radius},${-straightLength/2} v${straightLength} a${radius},${radius} 0 0 0 ${scaledWidth},0 v-${straightLength} a${radius},${radius} 0 0 0 -${scaledWidth},0 z`,holeElement={name:"path",type:"element",attributes:{class:"pcb-hole",fill:colorMap2.drill,d:pathD,transform:`translate(${x4} ${y4}) rotate(${-rotation5})`,"data-type":"pcb_hole","data-pcb-layer":"drill"},children:[],value:""};if(!shouldShowSolderMask)return[holeElement];let maskWidth=scaledWidth+2*soldermaskMargin,maskHeight=scaledHeight+2*soldermaskMargin,maskIsHorizontal=maskWidth>maskHeight,maskRadius=Math.min(maskWidth,maskHeight)/2,maskStraightLength=Math.abs(maskIsHorizontal?maskWidth-maskHeight:maskHeight-maskWidth),maskPathD=maskIsHorizontal?`M${-maskStraightLength/2},${-maskRadius} h${maskStraightLength} a${maskRadius},${maskRadius} 0 0 1 0,${maskHeight} h-${maskStraightLength} a${maskRadius},${maskRadius} 0 0 1 0,-${maskHeight} z`:`M${-maskRadius},${-maskStraightLength/2} v${maskStraightLength} a${maskRadius},${maskRadius} 0 0 0 ${maskWidth},0 v-${maskStraightLength} a${maskRadius},${maskRadius} 0 0 0 -${maskWidth},0 z`;if(soldermaskMargin<0){let coveredElement={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-hole-covered",fill:solderMaskColor,d:pathD,transform:`translate(${x4} ${y4}) rotate(${-rotation5})`,"data-type":"pcb_hole","data-pcb-layer":"drill"}},exposedElement={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-hole-exposed",fill:colorMap2.drill,d:maskPathD,transform:`translate(${x4} ${y4}) rotate(${-rotation5})`,"data-type":"pcb_soldermask","data-pcb-layer":"drill"}};return[coveredElement,exposedElement]}return[{name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-soldermask-cutout",fill:colorMap2.substrate,d:maskPathD,"data-type":"pcb_soldermask_opening","data-pcb-layer":layer}},holeElement]}return[]}function createSvgObjectsForRatsNest(circuitJson,ctx){let{transform:transform6}=ctx,connectivity=getFullConnectivityMapFromCircuitJson(circuitJson),pcbPorts=circuitJson.filter(elm=>elm.type==="pcb_port"),sourceTraces=circuitJson.filter(elm=>elm.type==="source_trace"),ratsNestLines=[];pcbPorts.forEach((port,index)=>{let portId=port.pcb_port_id;if(!portId)return;let netId=connectivity.getNetConnectedToId(portId);if(!netId)return;let isInNet=!1,sourcePort=su2(circuitJson).source_port.getWhere({pcb_port_id:portId});if(sourcePort&&sourcePort.source_port_id){let sourcePortId=sourcePort.source_port_id;for(let trace of sourceTraces)if(Array.isArray(trace.connected_source_port_ids)&&trace.connected_source_port_ids.includes(sourcePortId)&&Array.isArray(trace.connected_source_net_ids)&&trace.connected_source_net_ids.length>0){isInNet=!0;break}}let startPoint={x:port.x,y:port.y},nearestPoint=findNearestPointInNet(startPoint,netId,connectivity,circuitJson);nearestPoint&&ratsNestLines.push({key:`${portId}-${index}`,startPoint,endPoint:nearestPoint,isInNet})});let svgObjects=[];for(let line2 of ratsNestLines){let transformedStart=applyToPoint3(transform6,[line2.startPoint.x,line2.startPoint.y]),transformedEnd=applyToPoint3(transform6,[line2.endPoint.x,line2.endPoint.y]),attributes2={x1:transformedStart[0].toString(),y1:transformedStart[1].toString(),x2:transformedEnd[0].toString(),y2:transformedEnd[1].toString(),stroke:"white","stroke-width":"1","stroke-dasharray":"6,6","data-type":"pcb_rats_nest","data-pcb-layer":"overlay"};svgObjects.push({name:"line",type:"element",attributes:attributes2,value:"",children:[]})}return svgObjects}function createSvgObjectsFromPcbCutout(cutout,ctx){let{transform:transform6,colorMap:colorMap2}=ctx;if(cutout.shape==="rect"){let rectCutout=cutout,[cx3,cy3]=applyToPoint3(transform6,[rectCutout.center.x,rectCutout.center.y]),scaledWidth=rectCutout.width*Math.abs(transform6.a),scaledHeight=rectCutout.height*Math.abs(transform6.d),svgRotation=-(rectCutout.rotation??0),{corner_radius}=rectCutout,baseCornerRadius=typeof corner_radius=="number"&&corner_radius>0?corner_radius:0,transformedCornerRadiusX=baseCornerRadius*Math.abs(transform6.a),transformedCornerRadiusY=baseCornerRadius*Math.abs(transform6.d),attributes2={class:"pcb-cutout pcb-cutout-rect",x:(-scaledWidth/2).toString(),y:(-scaledHeight/2).toString(),width:scaledWidth.toString(),height:scaledHeight.toString(),fill:colorMap2.drill,transform:toString2(compose3(translate3(cx3,cy3),rotate3(svgRotation*Math.PI/180))),"data-type":"pcb_cutout","data-pcb-layer":"drill"};return transformedCornerRadiusX>0&&(attributes2.rx=transformedCornerRadiusX.toString()),transformedCornerRadiusY>0&&(attributes2.ry=transformedCornerRadiusY.toString()),[{name:"rect",type:"element",attributes:attributes2,children:[],value:""}]}if(cutout.shape==="circle"){let circleCutout=cutout,[cx3,cy3]=applyToPoint3(transform6,[circleCutout.center.x,circleCutout.center.y]),scaledRadius=circleCutout.radius*Math.abs(transform6.a);return[{name:"circle",type:"element",attributes:{class:"pcb-cutout pcb-cutout-circle",cx:cx3.toString(),cy:cy3.toString(),r:scaledRadius.toString(),fill:colorMap2.drill,"data-type":"pcb_cutout","data-pcb-layer":"drill"},children:[],value:""}]}if(cutout.shape==="polygon"){let polygonCutout=cutout;return!polygonCutout.points||polygonCutout.points.length===0?[]:[{name:"polygon",type:"element",attributes:{class:"pcb-cutout pcb-cutout-polygon",points:polygonCutout.points.map(p4=>applyToPoint3(transform6,[p4.x,p4.y])).map(p4=>`${p4[0]},${p4[1]}`).join(" "),fill:colorMap2.drill,"data-type":"pcb_cutout","data-pcb-layer":"drill"},children:[],value:""}]}return[]}function createSvgObjectsFromPcbCutoutPath(cutoutPath,ctx){let{transform:transform6,colorMap:colorMap2}=ctx;if(!cutoutPath.route||!Array.isArray(cutoutPath.route))return[];let firstPoint=cutoutPath.route[0],lastPoint=cutoutPath.route[cutoutPath.route.length-1],isClosed=firstPoint&&lastPoint&&firstPoint.x===lastPoint.x&&firstPoint.y===lastPoint.y;return[{name:"path",type:"element",attributes:{class:"pcb-cutout pcb-cutout-path",d:cutoutPath.route.slice(0,isClosed?-1:void 0).map((point7,index)=>{let[x4,y4]=applyToPoint3(transform6,[point7.x,point7.y]);return index===0?`M ${x4} ${y4}`:`L ${x4} ${y4}`}).join(" ")+(isClosed?" Z":""),fill:colorMap2.drill,"data-type":"pcb_cutout_path","data-pcb-cutout-id":cutoutPath.pcb_cutout_id,"data-pcb-layer":"drill"},value:"",children:[]}]}function createKeepoutPatternLines(keepoutColor){let patternLines=[];for(let i3=-KEEPOUT_PATTERN_SIZE;i3<=KEEPOUT_PATTERN_SIZE;i3+=KEEPOUT_LINE_SPACING)patternLines.push({name:"line",type:"element",value:"",attributes:{x1:i3.toString(),y1:"0",x2:(i3+KEEPOUT_PATTERN_SIZE).toString(),y2:KEEPOUT_PATTERN_SIZE.toString(),stroke:keepoutColor,"stroke-width":"1"},children:[]});return patternLines}function createKeepoutPatternDefs(keepoutColor){return{name:"defs",type:"element",value:"",attributes:{},children:[{name:"pattern",type:"element",value:"",attributes:{id:KEEPOUT_PATTERN_ID,width:KEEPOUT_PATTERN_SIZE.toString(),height:KEEPOUT_PATTERN_SIZE.toString(),patternUnits:"userSpaceOnUse"},children:createKeepoutPatternLines(keepoutColor)}]}}function createKeepoutBaseAttributes(keepoutId,layer,shapeClass,description){let attributes2={class:`pcb-keepout ${shapeClass} pcb-keepout-background`,"data-type":"pcb_keepout","data-pcb-layer":layer,"data-pcb-keepout-id":keepoutId,stroke:"none"};return description&&(attributes2["data-description"]=description),attributes2}function createKeepoutPatternAttributes(keepoutId,layer,shapeClass,description){let attributes2={class:`pcb-keepout ${shapeClass} pcb-keepout-pattern`,fill:`url(#${KEEPOUT_PATTERN_ID})`,"data-type":"pcb_keepout","data-pcb-layer":layer,"data-pcb-keepout-id":keepoutId,stroke:"none"};return description&&(attributes2["data-description"]=description),attributes2}function createSvgObjectsFromPcbKeepout(keepout,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2}=ctx;if(layerFilter&&!keepout.layers.includes(layerFilter))return[];let svgObjects=[],keepoutColor=colorMap2.keepout;for(let layer of keepout.layers)if(!(layerFilter&&layer!==layerFilter)){if(keepout.shape==="rect"){let rectKeepout=keepout,[cx3,cy3]=applyToPoint3(transform6,[rectKeepout.center.x,rectKeepout.center.y]),scaledWidth=rectKeepout.width*Math.abs(transform6.a),scaledHeight=rectKeepout.height*Math.abs(transform6.d),baseTransform=toString2(compose3(translate3(cx3,cy3))),backgroundAttributes={...createKeepoutBaseAttributes(rectKeepout.pcb_keepout_id,layer,"pcb-keepout-rect",rectKeepout.description),x:(-scaledWidth/2).toString(),y:(-scaledHeight/2).toString(),width:scaledWidth.toString(),height:scaledHeight.toString(),fill:KEEPOUT_BACKGROUND_COLOR,transform:baseTransform},patternAttributes={...createKeepoutPatternAttributes(rectKeepout.pcb_keepout_id,layer,"pcb-keepout-rect",rectKeepout.description),x:(-scaledWidth/2).toString(),y:(-scaledHeight/2).toString(),width:scaledWidth.toString(),height:scaledHeight.toString(),transform:baseTransform};svgObjects.push({name:"rect",type:"element",attributes:backgroundAttributes,children:[],value:""},{name:"rect",type:"element",attributes:patternAttributes,children:[],value:""})}else if(keepout.shape==="circle"){let circleKeepout=keepout,[cx3,cy3]=applyToPoint3(transform6,[circleKeepout.center.x,circleKeepout.center.y]),scaledRadius=circleKeepout.radius*Math.abs(transform6.a),backgroundAttributes={...createKeepoutBaseAttributes(circleKeepout.pcb_keepout_id,layer,"pcb-keepout-circle",circleKeepout.description),cx:cx3.toString(),cy:cy3.toString(),r:scaledRadius.toString(),fill:KEEPOUT_BACKGROUND_COLOR},patternAttributes={...createKeepoutPatternAttributes(circleKeepout.pcb_keepout_id,layer,"pcb-keepout-circle",circleKeepout.description),cx:cx3.toString(),cy:cy3.toString(),r:scaledRadius.toString()};svgObjects.push({name:"circle",type:"element",attributes:backgroundAttributes,children:[],value:""},{name:"circle",type:"element",attributes:patternAttributes,children:[],value:""})}}return svgObjects}function ringToPathD(vertices,transform6){if(vertices.length===0)return"";let transformedVertices=vertices.map(v4=>{let[x4,y4]=applyToPoint3(transform6,[v4.x,v4.y]);return{...v4,x:x4,y:y4}}),d4=`M ${transformedVertices[0].x} ${transformedVertices[0].y}`;for(let i3=0;i3<transformedVertices.length;i3++){let start=transformedVertices[i3],end=transformedVertices[(i3+1)%transformedVertices.length];if(start.bulge){if(Math.hypot(end.x-start.x,end.y-start.y)<1e-9)continue;let bulge=start.bulge,dx3=end.x-start.x,dy3=end.y-start.y,dist=Math.hypot(dx3,dy3),radius=Math.abs(dist/4/bulge*(bulge*bulge+1)),sweepFlag=bulge<0?1:0,largeArcFlag=Math.abs(bulge)>1?1:0;d4+=` A ${radius} ${radius} 0 ${largeArcFlag} ${sweepFlag} ${end.x} ${end.y}`}else d4+=` L ${end.x} ${end.y}`}return d4+=" Z",d4}function createSoldermaskCutoutElement({elementType,shapeAttributes,layer,colorMap:colorMap2,additionalAttributes}){let baseAttributes={class:"pcb-soldermask-cutout",fill:colorMap2.substrate,"data-type":"pcb_soldermask_opening","data-pcb-layer":layer,...shapeAttributes,...additionalAttributes};return{name:elementType,type:"element",value:"",children:[],attributes:baseAttributes}}function createSoldermaskOverlayElement({elementType,shapeAttributes,layer,fillColor,fillOpacity,className,additionalAttributes}){let baseAttributes={class:className,fill:fillColor,"fill-opacity":fillOpacity,"data-type":"pcb_soldermask","data-pcb-layer":layer,...shapeAttributes,...additionalAttributes};return{name:elementType,type:"element",value:"",children:[],attributes:baseAttributes}}function createSvgObjectsFromPcbCopperPour(pour,ctx){let{transform:transform6,layer:layerFilter,colorMap:colorMap2,showSolderMask}=ctx,{layer}=pour;if(layerFilter&&layer!==layerFilter)return[];let color=layerNameToColor(layer,colorMap2),opacity="0.5",isCoveredWithSolderMask=pour.covered_with_solder_mask!==!1,maskOverlayColor=layer==="bottom"?colorMap2.soldermaskOverCopper.bottom:colorMap2.soldermaskOverCopper.top,maskOverlayOpacity="0.9";if(pour.shape==="rect"){let[cx3,cy3]=applyToPoint3(transform6,[pour.center.x,pour.center.y]),scaledWidth=pour.width*Math.abs(transform6.a),scaledHeight=pour.height*Math.abs(transform6.d),svgRotation=-(pour.rotation??0),rectAttributes={x:(-scaledWidth/2).toString(),y:(-scaledHeight/2).toString(),width:scaledWidth.toString(),height:scaledHeight.toString(),transform:toString2(compose3(translate3(cx3,cy3),rotate3(svgRotation*Math.PI/180)))},copperRect={name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-copper-pour pcb-copper-pour-rect",...rectAttributes,fill:color,"fill-opacity":opacity,"data-type":"pcb_copper_pour","data-pcb-layer":layer}},maskRect=showSolderMask?isCoveredWithSolderMask?createSoldermaskOverlayElement({elementType:"rect",shapeAttributes:rectAttributes,layer,fillColor:maskOverlayColor,fillOpacity:maskOverlayOpacity,className:"pcb-soldermask-covered-pour"}):createSoldermaskCutoutElement({elementType:"rect",shapeAttributes:rectAttributes,layer,colorMap:colorMap2}):null;return maskRect?!isCoveredWithSolderMask&&pour.pcb_copper_pour_id?.includes("substrate_only")?[maskRect]:[copperRect,maskRect]:[copperRect]}if(pour.shape==="polygon"){if(!pour.points||pour.points.length===0)return[];let pointsString=pour.points.map(p4=>applyToPoint3(transform6,[p4.x,p4.y])).map(p4=>`${p4[0]},${p4[1]}`).join(" "),copperPolygon={name:"polygon",type:"element",value:"",children:[],attributes:{class:"pcb-copper-pour pcb-copper-pour-polygon",points:pointsString,fill:color,"fill-opacity":opacity,"data-type":"pcb_copper_pour","data-pcb-layer":layer}},maskPolygon=showSolderMask?isCoveredWithSolderMask?createSoldermaskOverlayElement({elementType:"polygon",shapeAttributes:{points:pointsString},layer,fillColor:maskOverlayColor,fillOpacity:maskOverlayOpacity,className:"pcb-soldermask-covered-pour"}):createSoldermaskCutoutElement({elementType:"polygon",shapeAttributes:{points:pointsString},layer,colorMap:colorMap2}):null;return maskPolygon?!isCoveredWithSolderMask&&pour.pcb_copper_pour_id?.includes("substrate_only")?[maskPolygon]:[copperPolygon,maskPolygon]:[copperPolygon]}if(pour.shape==="brep"){let{brep_shape:brep_shape3}=pour,d4=ringToPathD(brep_shape3.outer_ring.vertices,transform6);for(let inner_ring of brep_shape3.inner_rings??[])d4+=` ${ringToPathD(inner_ring.vertices,transform6)}`;let copperPath={name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-copper-pour pcb-copper-pour-brep",d:d4,fill:color,"fill-rule":"evenodd","fill-opacity":opacity,"data-type":"pcb_copper_pour","data-pcb-layer":layer}},maskPath=showSolderMask?isCoveredWithSolderMask?createSoldermaskOverlayElement({elementType:"path",shapeAttributes:{d:d4,"fill-rule":"evenodd"},layer,fillColor:maskOverlayColor,fillOpacity:maskOverlayOpacity,className:"pcb-soldermask-covered-pour"}):createSoldermaskCutoutElement({elementType:"path",shapeAttributes:{d:d4,"fill-rule":"evenodd"},layer,colorMap:colorMap2}):null;return maskPath?!isCoveredWithSolderMask&&pour.pcb_copper_pour_id?.includes("substrate_only")?[maskPath]:[copperPath,maskPath]:[copperPath]}return[]}function createSvgObjectsForPcbGrid({grid:grid4,svgWidth,svgHeight}){if(!grid4)return{};let gridLineColor=grid4.lineColor??DEFAULT_GRID_LINE_COLOR,gridCellSize=grid4.cellSize,majorCellSize=grid4.majorCellSize,majorLineColor=grid4.majorLineColor??gridLineColor;if(majorCellSize!==void 0){if(!gridCellSize||gridCellSize<=0)throw new Error("grid.majorCellSize requires a positive grid.cellSize");if(majorCellSize<=0)throw new Error("grid.majorCellSize must be a positive multiple of grid.cellSize");let ratio=majorCellSize/gridCellSize,nearestInteger=Math.round(ratio);if(!Number.isFinite(ratio)||Math.abs(ratio-nearestInteger)>1e-6)throw new Error("grid.majorCellSize must be a positive multiple of grid.cellSize")}if(!gridCellSize||gridCellSize<=0)return{};let hasMajorGrid=majorCellSize!==void 0,patternChildren=hasMajorGrid?createMajorGridPatternChildren(gridCellSize,majorCellSize,gridLineColor,majorLineColor):[{name:"path",type:"element",value:"",attributes:{d:`M ${gridCellSize} 0 L 0 0 0 ${gridCellSize}`,fill:"none",stroke:gridLineColor,"stroke-width":"1","shape-rendering":"crispEdges"},children:[]}],defs={name:"defs",type:"element",value:"",attributes:{},children:[{name:"pattern",type:"element",value:"",attributes:{id:GRID_PATTERN_ID,width:hasMajorGrid?majorCellSize.toString():gridCellSize.toString(),height:hasMajorGrid?majorCellSize.toString():gridCellSize.toString(),patternUnits:"userSpaceOnUse"},children:patternChildren}]},rect={name:"rect",type:"element",value:"",attributes:{x:"0",y:"0",width:svgWidth.toString(),height:svgHeight.toString(),fill:`url(#${GRID_PATTERN_ID})`,"pointer-events":"none","data-type":"pcb_grid","data-pcb-layer":"global"},children:[]};return{defs,rect}}function createMajorGridPatternChildren(cellSize,majorCellSize,lineColor,majorLineColor){let children=[],steps=Math.round(majorCellSize/cellSize);for(let step=0;step<steps;step+=1){let offsetString=Number((step*cellSize).toFixed(6)).toString(),color=step===0?majorLineColor:lineColor,majorSizeString=majorCellSize.toString();children.push({name:"line",type:"element",value:"",attributes:{x1:offsetString,y1:"0",x2:offsetString,y2:majorSizeString,stroke:color,"stroke-width":"1","shape-rendering":"crispEdges"},children:[]}),children.push({name:"line",type:"element",value:"",attributes:{x1:"0",y1:offsetString,x2:majorSizeString,y2:offsetString,stroke:color,"stroke-width":"1","shape-rendering":"crispEdges"},children:[]})}return children}function createSvgObjectsFromPcbComponent(component,ctx){let{transform:transform6,circuitJson}=ctx,{center:center2,width,height,rotation:rotation5=0}=component,[x4,y4]=applyToPoint3(transform6,[center2.x,center2.y]),scaledWidth=width*Math.abs(transform6.a),scaledHeight=height*Math.abs(transform6.d),transformStr=`translate(${x4}, ${y4}) rotate(${-rotation5}) scale(1, -1)`,svgObjects=[];if(ctx.showAnchorOffsets&&circuitJson&&component.position_mode==="relative_to_group_anchor"&&(component.positioned_relative_to_pcb_group_id||component.positioned_relative_to_pcb_board_id)){let parentAnchorPosition=getParentAnchorPosition(component,circuitJson);parentAnchorPosition&&svgObjects.push(...createAnchorOffsetIndicators({groupAnchorPosition:parentAnchorPosition,componentPosition:center2,transform:transform6,componentWidth:width,componentHeight:height,displayXOffset:component.display_offset_x,displayYOffset:component.display_offset_y}))}return!ctx.colorMap.debugComponent?.fill&&!ctx.colorMap.debugComponent?.stroke||svgObjects.push({name:"g",type:"element",attributes:{transform:transformStr,"data-type":"pcb_component","data-pcb-layer":component.layer??"top"},children:[{name:"rect",type:"element",attributes:{class:"pcb-component",x:(-scaledWidth/2).toString(),y:(-scaledHeight/2).toString(),width:scaledWidth.toString(),height:scaledHeight.toString(),fill:ctx.colorMap.debugComponent.fill??"transparent",stroke:ctx.colorMap.debugComponent.stroke??"transparent","data-type":"pcb_component","data-pcb-layer":component.layer??"top"}}],value:""}),svgObjects}function getParentAnchorPosition(component,circuitJson){if(component.positioned_relative_to_pcb_group_id){let pcbGroup=circuitJson.find(elm=>elm.type==="pcb_group"&&elm.pcb_group_id===component.positioned_relative_to_pcb_group_id),point7=getPointFromElm(pcbGroup);if(point7)return point7}if(component.positioned_relative_to_pcb_board_id){let pcbBoard=circuitJson.find(elm=>elm.type==="pcb_board"&&elm.pcb_board_id===component.positioned_relative_to_pcb_board_id),point7=getPointFromElm(pcbBoard);if(point7)return point7}}function createSvgObjectsFromPcbGroup(pcbGroup,ctx){let{transform:transform6,circuitJson}=ctx,{center:center2,width,height}=pcbGroup,svgObjects=[];if(ctx.showAnchorOffsets&&pcbGroup.position_mode==="relative_to_group_anchor"&&circuitJson){let parentAnchorPosition=getParentAnchorPosition2(pcbGroup,circuitJson);parentAnchorPosition&&svgObjects.push(...createAnchorOffsetIndicators({groupAnchorPosition:parentAnchorPosition,componentPosition:pcbGroup.anchor_position??pcbGroup.center,transform:transform6,componentWidth:pcbGroup.width,componentHeight:pcbGroup.height,displayXOffset:pcbGroup.display_offset_x,displayYOffset:pcbGroup.display_offset_y}))}let outline=Array.isArray(pcbGroup.outline)?pcbGroup.outline:void 0,transformedStrokeWidth=DEFAULT_STROKE_WIDTH*Math.abs(transform6.a),dashLength=.3*Math.abs(transform6.a),gapLength=.15*Math.abs(transform6.a),baseAttributes={class:"pcb-group",fill:"none",stroke:getGroupColor(pcbGroup.pcb_group_id),"stroke-width":transformedStrokeWidth.toString(),"stroke-dasharray":`${dashLength} ${gapLength}`,"data-type":"pcb_group","data-pcb-group-id":pcbGroup.pcb_group_id,"data-pcb-layer":"overlay"};if(pcbGroup.name&&(baseAttributes["data-group-name"]=pcbGroup.name),outline&&outline.length>=3&&outline.every(point7=>point7&&typeof point7.x=="number"&&typeof point7.y=="number")){let path=outline.map((point7,index)=>{let[x4,y4]=applyToPoint3(transform6,[point7.x,point7.y]);return index===0?`M ${x4} ${y4}`:`L ${x4} ${y4}`}).join(" ");return svgObjects.push({name:"path",type:"element",value:"",children:[],attributes:{...baseAttributes,d:`${path} Z`}}),svgObjects}if(!center2||typeof center2.x!="number"||typeof center2.y!="number"||typeof width!="number"||typeof height!="number")return debugPcb(`[pcb_group] Invalid data for "${pcbGroup.pcb_group_id}"${pcbGroup.name?` (name: "${pcbGroup.name}")`:""}: expected center {x: number, y: number}, width: number, height: number, got center=${JSON.stringify(center2)}, width=${JSON.stringify(width)}, height=${JSON.stringify(height)}`),svgObjects;let halfWidth=width/2,halfHeight=height/2,[topLeftX,topLeftY]=applyToPoint3(transform6,[center2.x-halfWidth,center2.y+halfHeight]),[bottomRightX,bottomRightY]=applyToPoint3(transform6,[center2.x+halfWidth,center2.y-halfHeight]),rectX=Math.min(topLeftX,bottomRightX),rectY=Math.min(topLeftY,bottomRightY),rectWidth=Math.abs(bottomRightX-topLeftX),rectHeight=Math.abs(bottomRightY-topLeftY),svgObject={name:"rect",type:"element",value:"",attributes:{...baseAttributes,x:rectX.toString(),y:rectY.toString(),width:rectWidth.toString(),height:rectHeight.toString()},children:[]};return svgObjects.push(svgObject),svgObjects}function getGroupColor(pcbGroupId){let match2=pcbGroupId.match(/(\d+)$/),index=match2?Number.parseInt(match2[1],10):0;return GROUP_COLOR_PALETTE[index%GROUP_COLOR_PALETTE.length]}function getParentAnchorPosition2(group,circuitJson){if(group.positioned_relative_to_pcb_group_id){let pcbGroup=circuitJson.find(elm=>elm.type==="pcb_group"&&elm.pcb_group_id===group.positioned_relative_to_pcb_group_id),point7=getPointFromElm(pcbGroup);if(point7)return point7}if(group.positioned_relative_to_pcb_board_id){let pcbBoard=circuitJson.find(elm=>elm.type==="pcb_board"&&elm.pcb_board_id===group.positioned_relative_to_pcb_board_id),point7=getPointFromElm(pcbBoard);if(point7)return point7}}function getSoftwareUsedString(circuitJson){return circuitJson.find(e5=>e5.type==="project_software_metadata"||e5.type==="source_project_metadata")?.software_used_string}function sortSvgObjectsByPcbLayer(objects){return objects.map((object,index)=>({object,index,layerPriority:getLayerPriority(object.attributes?.["data-pcb-layer"]??void 0),typePriority:getTypePriority(object.attributes?.["data-type"]??void 0)})).sort((a3,b3)=>a3.layerPriority!==b3.layerPriority?a3.layerPriority-b3.layerPriority:a3.typePriority!==b3.typePriority?a3.typePriority-b3.typePriority:a3.index-b3.index).map(({object})=>object)}function getLayerPriority(layer){if(!layer)return 500;let normalized=layer.toLowerCase();if(normalized==="global")return-100;if(normalized==="bottom")return 4;if(normalized==="board")return 2;if(normalized==="soldermask-top"||normalized==="soldermask-bottom")return 3;if(normalized.startsWith("inner")){let match2=normalized.match(/\d+/);return 5+(match2?Number.parseInt(match2[0],10):0)}return normalized==="through"?18:normalized==="top"?17:normalized==="drill"?30:normalized==="overlay"?40:10}function getTypePriority(type){return type?TYPE_PRIORITY[type]??DEFAULT_TYPE_PRIORITY:DEFAULT_TYPE_PRIORITY}function createErrorTextOverlay(circuitJson,dataType="error_text_overlay"){let errorElms=circuitJson.filter(elm=>elm.type.endsWith("_error"));if(errorElms.length===0)return null;let errorMessages=errorElms.map(e5=>e5.message).filter(m4=>!!m4);return errorMessages.length===0?null:{name:"text",type:"element",value:"",attributes:{x:"10",y:"20",fill:"red","font-family":"monospace","font-size":"12px","data-type":dataType,"data-layer":"global"},children:errorMessages.map((msg,i3)=>({name:"tspan",type:"element",value:"",attributes:{x:"10",dy:i3===0?"0":"1.2em"},children:[{type:"text",value:msg,name:"",attributes:{},children:[]}]}))}}function getPcbBoundsFromCircuitJson(circuitJson){let minX=Number.POSITIVE_INFINITY,minY=Number.POSITIVE_INFINITY,maxX=Number.NEGATIVE_INFINITY,maxY=Number.NEGATIVE_INFINITY,hasBounds2=!1,boardMinX=Number.POSITIVE_INFINITY,boardMinY=Number.POSITIVE_INFINITY,boardMaxX=Number.NEGATIVE_INFINITY,boardMaxY=Number.NEGATIVE_INFINITY,hasBoardBounds=!1;for(let circuitJsonElm of circuitJson)if(circuitJsonElm.type==="pcb_panel"){let panel=circuitJsonElm,width=distance.parse(panel.width),height=distance.parse(panel.height);if(width===void 0||height===void 0)continue;let center2=panel.center??{x:width/2,y:height/2};updateBounds({center:center2,width,height})}else if(circuitJsonElm.type==="pcb_board")circuitJsonElm.outline&&Array.isArray(circuitJsonElm.outline)&&circuitJsonElm.outline.length>=3?(updateBoundsToIncludeOutline(circuitJsonElm.outline),updateBoardBoundsToIncludeOutline(circuitJsonElm.outline)):"center"in circuitJsonElm&&"width"in circuitJsonElm&&"height"in circuitJsonElm&&(updateBounds({center:circuitJsonElm.center,width:circuitJsonElm.width,height:circuitJsonElm.height}),updateBoardBounds({center:circuitJsonElm.center,width:circuitJsonElm.width,height:circuitJsonElm.height}));else if(circuitJsonElm.type==="pcb_smtpad"){let pad2=circuitJsonElm;if(pad2.shape==="rect"||pad2.shape==="rotated_rect"||pad2.shape==="pill")updateBounds({center:{x:pad2.x,y:pad2.y},width:pad2.width,height:pad2.height});else if(pad2.shape==="circle"){let radius=distance.parse(pad2.radius);radius!==void 0&&updateBounds({center:{x:pad2.x,y:pad2.y},width:radius*2,height:radius*2})}else pad2.shape==="polygon"&&updateTraceBounds(pad2.points)}else if("x"in circuitJsonElm&&"y"in circuitJsonElm)updateBounds({center:{x:circuitJsonElm.x,y:circuitJsonElm.y},width:0,height:0});else if("route"in circuitJsonElm)updateTraceBounds(circuitJsonElm.route);else if(circuitJsonElm.type==="pcb_note_rect"||circuitJsonElm.type==="pcb_fabrication_note_rect")updateBounds({center:circuitJsonElm.center,width:circuitJsonElm.width,height:circuitJsonElm.height});else if(circuitJsonElm.type==="pcb_note_dimension"||circuitJsonElm.type==="pcb_fabrication_note_dimension"){let dimension=circuitJsonElm,{from,to:to3,text,font_size=1,arrow_size,offset_distance,offset_direction}=dimension;if(!from||!to3||!arrow_size)continue;updateBounds({center:from,width:0,height:0}),updateBounds({center:to3,width:0,height:0});let normalize3=v4=>{let l4=Math.hypot(v4.x,v4.y)||1;return{x:v4.x/l4,y:v4.y/l4}},direction2=normalize3({x:to3.x-from.x,y:to3.y-from.y});if(Number.isNaN(direction2.x)||Number.isNaN(direction2.y))continue;let perpendicular={x:-direction2.y,y:direction2.x},hasOffsetDirection=offset_direction&&typeof offset_direction.x=="number"&&typeof offset_direction.y=="number",normalizedOffsetDirection=hasOffsetDirection?normalize3(offset_direction):{x:0,y:0},offsetMagnitude=typeof offset_distance=="number"?offset_distance:0,offsetVector={x:normalizedOffsetDirection.x*offsetMagnitude,y:normalizedOffsetDirection.y*offsetMagnitude},fromOffset={x:from.x+offsetVector.x,y:from.y+offsetVector.y},toOffset={x:to3.x+offsetVector.x,y:to3.y+offsetVector.y};updateBounds({center:fromOffset,width:0,height:0}),updateBounds({center:toOffset,width:0,height:0});let extensionDirection=hasOffsetDirection&&(Math.abs(normalizedOffsetDirection.x)>Number.EPSILON||Math.abs(normalizedOffsetDirection.y)>Number.EPSILON)?normalizedOffsetDirection:perpendicular,extensionLength=offsetMagnitude+arrow_size,fromExtEnd={x:from.x+extensionDirection.x*extensionLength,y:from.y+extensionDirection.y*extensionLength},toExtEnd={x:to3.x+extensionDirection.x*extensionLength,y:to3.y+extensionDirection.y*extensionLength};updateBounds({center:fromExtEnd,width:0,height:0}),updateBounds({center:toExtEnd,width:0,height:0});let arrowHalfWidth=arrow_size/2,fromBase={x:fromOffset.x+direction2.x*arrow_size,y:fromOffset.y+direction2.y*arrow_size},toBase={x:toOffset.x-direction2.x*arrow_size,y:toOffset.y-direction2.y*arrow_size},fromArrowP2={x:fromBase.x+perpendicular.x*arrowHalfWidth,y:fromBase.y+perpendicular.y*arrowHalfWidth},fromArrowP3={x:fromBase.x-perpendicular.x*arrowHalfWidth,y:fromBase.y-perpendicular.y*arrowHalfWidth};updateBounds({center:fromArrowP2,width:0,height:0}),updateBounds({center:fromArrowP3,width:0,height:0});let toArrowP2={x:toBase.x+perpendicular.x*arrowHalfWidth,y:toBase.y+perpendicular.y*arrowHalfWidth},toArrowP3={x:toBase.x-perpendicular.x*arrowHalfWidth,y:toBase.y-perpendicular.y*arrowHalfWidth};if(updateBounds({center:toArrowP2,width:0,height:0}),updateBounds({center:toArrowP3,width:0,height:0}),text){let midPoint2={x:(from.x+to3.x)/2+offsetVector.x,y:(from.y+to3.y)/2+offsetVector.y},textOffset=arrow_size*1.5,textPoint={x:midPoint2.x+perpendicular.x*textOffset,y:midPoint2.y+perpendicular.y*textOffset},textWidth=text.length*font_size*.6;updateBounds({center:textPoint,width:textWidth,height:font_size})}}else if(circuitJsonElm.type==="pcb_cutout"){let cutout=circuitJsonElm;if(cutout.shape==="rect")updateBounds({center:cutout.center,width:cutout.width,height:cutout.height});else if(cutout.shape==="circle"){let radius=distance.parse(cutout.radius);radius!==void 0&&updateBounds({center:cutout.center,width:radius*2,height:radius*2})}else if(cutout.shape==="polygon")updateTraceBounds(cutout.points);else if(cutout.shape==="path"){let cutoutPath=cutout;cutoutPath.route&&Array.isArray(cutoutPath.route)&&updateTraceBounds(cutoutPath.route)}}else if(circuitJsonElm.type==="pcb_keepout"){let keepout=circuitJsonElm;if(keepout.shape==="rect")updateBounds({center:keepout.center,width:keepout.width,height:keepout.height});else if(keepout.shape==="circle"){let radius=typeof keepout.radius=="number"?keepout.radius:distance.parse(keepout.radius)??0;radius>0&&updateBounds({center:keepout.center,width:radius*2,height:radius*2})}}else circuitJsonElm.type==="pcb_silkscreen_text"||circuitJsonElm.type==="pcb_silkscreen_rect"||circuitJsonElm.type==="pcb_silkscreen_circle"||circuitJsonElm.type==="pcb_silkscreen_line"||circuitJsonElm.type==="pcb_silkscreen_oval"?updateSilkscreenBounds(circuitJsonElm):circuitJsonElm.type==="pcb_copper_text"?updateBounds({center:circuitJsonElm.anchor_position,width:0,height:0}):circuitJsonElm.type==="pcb_copper_pour"&&(circuitJsonElm.shape==="rect"?updateBounds({center:circuitJsonElm.center,width:circuitJsonElm.width,height:circuitJsonElm.height}):circuitJsonElm.shape==="polygon"&&updateTraceBounds(circuitJsonElm.points));return{minX,minY,maxX,maxY,boardMinX,boardMinY,boardMaxX,boardMaxY,hasBounds:hasBounds2,hasBoardBounds};function updateBounds({center:center2,width,height}){if(!center2)return;let centerX=distance.parse(center2.x),centerY=distance.parse(center2.y);if(centerX===void 0||centerY===void 0)return;let numericWidth=distance.parse(width)??0,numericHeight=distance.parse(height)??0,halfWidth=numericWidth/2,halfHeight=numericHeight/2;minX=Math.min(minX,centerX-halfWidth),minY=Math.min(minY,centerY-halfHeight),maxX=Math.max(maxX,centerX+halfWidth),maxY=Math.max(maxY,centerY+halfHeight),hasBounds2=!0}function updateBoardBounds({center:center2,width,height}){if(!center2)return;let centerX=distance.parse(center2.x),centerY=distance.parse(center2.y);if(centerX===void 0||centerY===void 0)return;let numericWidth=distance.parse(width)??0,numericHeight=distance.parse(height)??0,halfWidth=numericWidth/2,halfHeight=numericHeight/2;boardMinX=Math.min(boardMinX,centerX-halfWidth),boardMinY=Math.min(boardMinY,centerY-halfHeight),boardMaxX=Math.max(boardMaxX,centerX+halfWidth),boardMaxY=Math.max(boardMaxY,centerY+halfHeight),hasBounds2=!0,hasBoardBounds=!0}function updateBoundsToIncludeOutline(outline){let updated=!1;for(let point7 of outline){let x4=distance.parse(point7.x),y4=distance.parse(point7.y);x4===void 0||y4===void 0||(minX=Math.min(minX,x4),minY=Math.min(minY,y4),maxX=Math.max(maxX,x4),maxY=Math.max(maxY,y4),updated=!0)}updated&&(hasBounds2=!0)}function updateBoardBoundsToIncludeOutline(outline){let updated=!1;for(let point7 of outline){let x4=distance.parse(point7.x),y4=distance.parse(point7.y);x4===void 0||y4===void 0||(boardMinX=Math.min(boardMinX,x4),boardMinY=Math.min(boardMinY,y4),boardMaxX=Math.max(boardMaxX,x4),boardMaxY=Math.max(boardMaxY,y4),updated=!0)}updated&&(hasBounds2=!0,hasBoardBounds=!0)}function updateTraceBounds(route){let updated=!1;for(let point7 of route)for(let anchor of getTracePoints(point7)){let x4=distance.parse(anchor.x),y4=distance.parse(anchor.y);x4===void 0||y4===void 0||(minX=Math.min(minX,x4),minY=Math.min(minY,y4),maxX=Math.max(maxX,x4),maxY=Math.max(maxY,y4),updated=!0)}updated&&(hasBounds2=!0)}function getTracePoints(point7){return"route_type"in point7?getPcbTracePoints(point7):[point7]}function updateSilkscreenBounds(item){if(item.type==="pcb_silkscreen_text")updateBounds({center:item.anchor_position,width:0,height:0});else if(item.type==="pcb_silkscreen_path")updateTraceBounds(item.route);else if(item.type==="pcb_silkscreen_rect")updateBounds({center:item.center,width:item.width,height:item.height});else if(item.type==="pcb_silkscreen_circle"){let radius=distance.parse(item.radius);radius!==void 0&&updateBounds({center:item.center,width:radius*2,height:radius*2})}else if(item.type==="pcb_silkscreen_line")updateBounds({center:{x:item.x1,y:item.y1},width:0,height:0}),updateBounds({center:{x:item.x2,y:item.y2},width:0,height:0});else if(item.type==="pcb_silkscreen_oval"){let radiusX=distance.parse(item.radius_x),radiusY=distance.parse(item.radius_y);radiusX!==void 0&&radiusY!==void 0&&updateBounds({center:item.center,width:radiusX*2,height:radiusY*2})}else if(item.type==="pcb_cutout"){let cutout=item;if(cutout.shape==="rect")updateBounds({center:cutout.center,width:cutout.width,height:cutout.height});else if(cutout.shape==="circle"){let radius=distance.parse(cutout.radius);radius!==void 0&&updateBounds({center:cutout.center,width:radius*2,height:radius*2})}else if(cutout.shape==="polygon")updateTraceBounds(cutout.points);else if(cutout.shape==="path"){let cutoutPath=cutout;cutoutPath.route&&Array.isArray(cutoutPath.route)&&updateTraceBounds(cutoutPath.route)}}}}function rectBounds(center2,width,height){if(!center2||width===void 0||height===void 0)return;let cx3=distance.parse(center2.x),cy3=distance.parse(center2.y);if(cx3===void 0||cy3===void 0)return;let numericWidth=distance.parse(width),numericHeight=distance.parse(height);if(numericWidth===void 0||numericHeight===void 0)return;let halfW=numericWidth/2,halfH=numericHeight/2;return{minX:cx3-halfW,minY:cy3-halfH,maxX:cx3+halfW,maxY:cy3+halfH}}function getOutlineBounds(outline){if(!outline||outline.length<3)return;let minX=Number.POSITIVE_INFINITY,minY=Number.POSITIVE_INFINITY,maxX=Number.NEGATIVE_INFINITY,maxY=Number.NEGATIVE_INFINITY;for(let pt3 of outline){let x4=distance.parse(pt3.x),y4=distance.parse(pt3.y);x4===void 0||y4===void 0||(minX=Math.min(minX,x4),minY=Math.min(minY,y4),maxX=Math.max(maxX,x4),maxY=Math.max(maxY,y4))}if(!(!Number.isFinite(minX)||!Number.isFinite(minY))&&!(!Number.isFinite(maxX)||!Number.isFinite(maxY)))return{minX,minY,maxX,maxY}}function convertCircuitJsonToPcbSvg(circuitJson,options){let drawPaddingOutsideBoard=options?.drawPaddingOutsideBoard??!0,layer=options?.layer,colorOverrides=options?.colorOverrides,copperColors={...DEFAULT_PCB_COLOR_MAP.copper};if(colorOverrides?.copper)for(let[layerName,color]of Object.entries(colorOverrides.copper))color!==void 0&&(copperColors[layerName]=color);let colorMap2={copper:copperColors,drill:colorOverrides?.drill??DEFAULT_PCB_COLOR_MAP.drill,silkscreen:{top:colorOverrides?.silkscreen?.top??DEFAULT_PCB_COLOR_MAP.silkscreen.top,bottom:colorOverrides?.silkscreen?.bottom??DEFAULT_PCB_COLOR_MAP.silkscreen.bottom},boardOutline:colorOverrides?.boardOutline??DEFAULT_PCB_COLOR_MAP.boardOutline,soldermask:{top:colorOverrides?.soldermask?.top??DEFAULT_PCB_COLOR_MAP.soldermask.top,bottom:colorOverrides?.soldermask?.bottom??DEFAULT_PCB_COLOR_MAP.soldermask.bottom},soldermaskOverCopper:{top:colorOverrides?.soldermaskOverCopper?.top??DEFAULT_PCB_COLOR_MAP.soldermaskOverCopper.top,bottom:colorOverrides?.soldermaskOverCopper?.bottom??DEFAULT_PCB_COLOR_MAP.soldermaskOverCopper.bottom},soldermaskWithCopperUnderneath:{top:colorOverrides?.soldermaskWithCopperUnderneath?.top??DEFAULT_PCB_COLOR_MAP.soldermaskWithCopperUnderneath.top,bottom:colorOverrides?.soldermaskWithCopperUnderneath?.bottom??DEFAULT_PCB_COLOR_MAP.soldermaskWithCopperUnderneath.bottom},substrate:colorOverrides?.substrate??DEFAULT_PCB_COLOR_MAP.substrate,courtyard:{top:colorOverrides?.courtyard?.top??DEFAULT_PCB_COLOR_MAP.courtyard.top,bottom:colorOverrides?.courtyard?.bottom??DEFAULT_PCB_COLOR_MAP.courtyard.bottom},keepout:colorOverrides?.keepout??DEFAULT_PCB_COLOR_MAP.keepout,debugComponent:{fill:colorOverrides?.debugComponent?.fill??DEFAULT_PCB_COLOR_MAP.debugComponent.fill,stroke:colorOverrides?.debugComponent?.stroke??DEFAULT_PCB_COLOR_MAP.debugComponent.stroke}},{minX,minY,maxX,maxY,boardMinX,boardMinY,boardMaxX,boardMaxY,hasBoardBounds}=getPcbBoundsFromCircuitJson(circuitJson),{boundsMinX,boundsMinY,boundsMaxX,boundsMaxY,padding}=getViewportBounds({circuitJson,drawPaddingOutsideBoard,baseBounds:{minX,minY,maxX,maxY,boardMinX,boardMinY,boardMaxX,boardMaxY,hasBoardBounds},viewportOptions:{viewport:options?.viewport,viewportTarget:options?.viewportTarget}}),circuitWidth=boundsMaxX-boundsMinX+2*padding,circuitHeight=boundsMaxY-boundsMinY+2*padding,svgWidth=options?.width??800,svgHeight=options?.height??600;if(options?.matchBoardAspectRatio){let viewportWidth=boundsMaxX-boundsMinX,viewportHeight=boundsMaxY-boundsMinY;if(viewportWidth>0&&viewportHeight>0){let aspect=viewportWidth/viewportHeight;options?.width&&!options?.height?svgHeight=options.width/aspect:options?.height&&!options?.width?svgWidth=options.height*aspect:svgHeight=svgWidth/aspect}}let paths=[];for(let circuitJsonElm of circuitJson)"route"in circuitJsonElm&&circuitJsonElm.route!==void 0&&paths.push(circuitJsonElm.route);let scaleX=svgWidth/circuitWidth,scaleY=svgHeight/circuitHeight,scaleFactor=Math.min(scaleX,scaleY),offsetX=(svgWidth-circuitWidth*scaleFactor)/2,offsetY=(svgHeight-circuitHeight*scaleFactor)/2,transform6=compose3(translate3(offsetX-boundsMinX*scaleFactor+padding*scaleFactor,svgHeight-offsetY+boundsMinY*scaleFactor-padding*scaleFactor),scale3(scaleFactor,-scaleFactor)),ctx={transform:transform6,layer,shouldDrawErrors:options?.shouldDrawErrors,showCourtyards:options?.showCourtyards,showPcbGroups:options?.showPcbGroups,drawPaddingOutsideBoard,colorMap:colorMap2,showSolderMask:options?.showSolderMask,showPcbNotes:options?.showPcbNotes??!0,showAnchorOffsets:options?.showAnchorOffsets,circuitJson},unsortedSvgObjects=circuitJson.flatMap(elm=>createSvgObjects({elm,circuitJson,ctx})),strokeWidth=String(.05*scaleFactor);for(let element of circuitJson)if("stroke_width"in element){strokeWidth=String(scaleFactor*element.stroke_width);break}if(options?.shouldDrawRatsNest){let ratsNestObjects=createSvgObjectsForRatsNest(circuitJson,ctx);unsortedSvgObjects=[...unsortedSvgObjects,...ratsNestObjects]}let svgObjects=sortSvgObjectsByPcbLayer(unsortedSvgObjects),children=[{name:"style",type:"element",value:"",attributes:{},children:[{type:"text",value:"",name:"",attributes:{},children:[]}]}],gridObjects=createSvgObjectsForPcbGrid({grid:options?.grid,svgWidth,svgHeight});if(gridObjects.defs&&children.push(gridObjects.defs),circuitJson.some(elm=>elm.type==="pcb_keepout")&&children.push(createKeepoutPatternDefs(colorMap2.keepout??DEFAULT_PCB_COLOR_MAP.keepout)),children.push({name:"rect",type:"element",value:"",attributes:{class:"boundary",x:"0",y:"0",fill:options?.backgroundColor??"#000",width:svgWidth.toString(),height:svgHeight.toString(),"data-type":"pcb_background","data-pcb-layer":"global"},children:[]}),drawPaddingOutsideBoard&&children.push(createSvgObjectFromPcbBoundary(transform6,minX,minY,maxX,maxY)),children.push(...svgObjects),gridObjects.rect&&children.push(gridObjects.rect),options?.showErrorsInTextOverlay){let errorOverlay=createErrorTextOverlay(circuitJson,"pcb_error_text_overlay");errorOverlay&&children.push(errorOverlay)}let softwareUsedString=getSoftwareUsedString(circuitJson),version2=CIRCUIT_TO_SVG_VERSION,svgObject={name:"svg",type:"element",attributes:{xmlns:"http://www.w3.org/2000/svg",width:svgWidth.toString(),height:svgHeight.toString(),...softwareUsedString&&{"data-software-used-string":softwareUsedString},...options?.includeVersion&&{"data-circuit-to-svg-version":version2}},value:"",children:children.filter(child=>child!==null)};try{return(0,import_svgson2.stringify)(svgObject)}catch(error2){throw console.error("Error stringifying SVG object:",error2),error2}}function createSvgObjects({elm,circuitJson,ctx}){switch(elm.type){case"pcb_trace_error":return createSvgObjectsFromPcbTraceError(elm,circuitJson,ctx).filter(Boolean);case"pcb_footprint_overlap_error":return createSvgObjectsFromPcbFootprintOverlapError(elm,circuitJson,ctx).filter(Boolean);case"pcb_courtyard_overlap_error":return createSvgObjectsFromPcbCourtyardOverlapError(elm,circuitJson,ctx).filter(Boolean);case"pcb_component_outside_board_error":return createSvgObjectsFromPcbComponentOutsideBoardError(elm,circuitJson,ctx).filter(Boolean);case"pcb_via_trace_clearance_error":return createSvgObjectsFromPcbViaTraceClearanceError(elm,circuitJson,ctx).filter(Boolean);case"pcb_component":return createSvgObjectsFromPcbComponent(elm,ctx).filter(Boolean);case"pcb_trace":return createSvgObjectsFromPcbTrace(elm,ctx);case"pcb_copper_pour":return createSvgObjectsFromPcbCopperPour(elm,ctx);case"pcb_plated_hole":return createSvgObjectsFromPcbPlatedHole(elm,ctx).filter(Boolean);case"pcb_hole":return createSvgObjectsFromPcbHole(elm,ctx);case"pcb_smtpad":return createSvgObjectsFromSmtPad(elm,ctx);case"pcb_silkscreen_text":return createSvgObjectsFromPcbSilkscreenText(elm,ctx);case"pcb_silkscreen_rect":return createSvgObjectsFromPcbSilkscreenRect(elm,ctx);case"pcb_silkscreen_circle":return createSvgObjectsFromPcbSilkscreenCircle(elm,ctx);case"pcb_silkscreen_line":return createSvgObjectsFromPcbSilkscreenLine(elm,ctx);case"pcb_silkscreen_pill":return createSvgObjectsFromPcbSilkscreenPill(elm,ctx);case"pcb_silkscreen_oval":return createSvgObjectsFromPcbSilkscreenOval(elm,ctx);case"pcb_copper_text":return createSvgObjectsFromPcbCopperText(elm,ctx);case"pcb_courtyard_rect":return ctx.showCourtyards?createSvgObjectsFromPcbCourtyardRect(elm,ctx):[];case"pcb_courtyard_polygon":return ctx.showCourtyards?createSvgObjectsFromPcbCourtyardPolygon(elm,ctx):[];case"pcb_courtyard_circle":return ctx.showCourtyards?createSvgObjectsFromPcbCourtyardCircle(elm,ctx):[];case"pcb_courtyard_outline":return ctx.showCourtyards?createSvgObjectsFromPcbCourtyardOutline(elm,ctx):[];case"pcb_fabrication_note_path":return createSvgObjectsFromPcbFabricationNotePath(elm,ctx);case"pcb_fabrication_note_text":return createSvgObjectsFromPcbFabricationNoteText(elm,ctx);case"pcb_fabrication_note_rect":return createSvgObjectsFromPcbFabricationNoteRect(elm,ctx);case"pcb_fabrication_note_dimension":return createSvgObjectsFromPcbFabricationNoteDimension(elm,ctx);case"pcb_note_dimension":return ctx.showPcbNotes?createSvgObjectsFromPcbNoteDimension(elm,ctx):[];case"pcb_note_text":return ctx.showPcbNotes?createSvgObjectsFromPcbNoteText(elm,ctx):[];case"pcb_note_rect":return ctx.showPcbNotes?createSvgObjectsFromPcbNoteRect(elm,ctx):[];case"pcb_note_path":return ctx.showPcbNotes?createSvgObjectsFromPcbNotePath(elm,ctx):[];case"pcb_note_line":return ctx.showPcbNotes?createSvgObjectsFromPcbNoteLine(elm,ctx):[];case"pcb_silkscreen_path":return createSvgObjectsFromPcbSilkscreenPath(elm,ctx);case"pcb_panel":return ctx.drawPaddingOutsideBoard?createSvgObjectsFromPcbPanel(elm,ctx):[];case"pcb_board":return ctx.drawPaddingOutsideBoard?createSvgObjectsFromPcbBoard(elm,ctx):[];case"pcb_via":return createSvgObjectsFromPcbVia(elm,ctx);case"pcb_cutout":let cutout=elm;return cutout.shape==="path"?createSvgObjectsFromPcbCutoutPath(cutout,ctx):createSvgObjectsFromPcbCutout(elm,ctx);case"pcb_keepout":return createSvgObjectsFromPcbKeepout(elm,ctx);case"pcb_group":return ctx.showPcbGroups?createSvgObjectsFromPcbGroup(elm,ctx):[];default:return[]}}function createSvgObjectFromPcbBoundary(transform6,minX,minY,maxX,maxY){let[x12,y12]=applyToPoint3(transform6,[minX,minY]),[x22,y22]=applyToPoint3(transform6,[maxX,maxY]),width=Math.abs(x22-x12),height=Math.abs(y22-y12),x4=Math.min(x12,x22),y4=Math.min(y12,y22);return{name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-boundary",fill:"none",stroke:"#fff","stroke-width":"0.3",x:x4.toString(),y:y4.toString(),width:width.toString(),height:height.toString(),"data-type":"pcb_boundary","data-pcb-layer":"global"}}}function createSvgObjectsFromAssemblyBoard(pcbBoard,transform6,style={}){let{width,height,center:center2,outline}=pcbBoard,path;if(outline&&Array.isArray(outline)&&outline.length>=3)path=outline.map((point7,index)=>{let[x4,y4]=applyToPoint3(transform6,[point7.x,point7.y]);return index===0?`M ${x4} ${y4}`:`L ${x4} ${y4}`}).join(" ");else{let halfWidth=width/2,halfHeight=height/2,topLeft=applyToPoint3(transform6,[center2.x-halfWidth,center2.y-halfHeight]),topRight=applyToPoint3(transform6,[center2.x+halfWidth,center2.y-halfHeight]),bottomRight=applyToPoint3(transform6,[center2.x+halfWidth,center2.y+halfHeight]),bottomLeft=applyToPoint3(transform6,[center2.x-halfWidth,center2.y+halfHeight]);path=`M ${topLeft[0]} ${topLeft[1]} L ${topRight[0]} ${topRight[1]} L ${bottomRight[0]} ${bottomRight[1]} L ${bottomLeft[0]} ${bottomLeft[1]}`}return path+=" Z",[{name:"path",type:"element",value:"",children:[],attributes:{class:"pcb-board",d:path,fill:style.fill??DEFAULT_BOARD_STYLE.fill,stroke:style.stroke??DEFAULT_BOARD_STYLE.stroke,"stroke-opacity":style.strokeOpacity??DEFAULT_BOARD_STYLE.strokeOpacity,"stroke-width":((style.strokeWidthFactor??DEFAULT_BOARD_STYLE.strokeWidthFactor)*Math.abs(transform6.a)).toString()}}]}function createSvgObjectsFromAssemblyComponent(params,ctx){let{elm,portPosition,name,arePinsInterchangeable}=params,{transform:transform6}=ctx,{center:center2,width,height,rotation:rotation5=0,layer="top"}=elm;if(!center2||typeof width!="number"||typeof height!="number")return null;let[x4,y4]=applyToPoint3(transform6,[center2.x,center2.y]),[pinX,pinY]=applyToPoint3(transform6,[portPosition.x,portPosition.y]),scaledWidth=width*Math.abs(transform6.a),scaledHeight=height*Math.abs(transform6.d),isTopLayer=layer==="top",isPinTop=pinY>y4,isPinLeft=pinX<x4,children=[createComponentPath(scaledWidth,scaledHeight,rotation5,layer),createComponentLabel(scaledWidth,scaledHeight,name??"",transform6)];return arePinsInterchangeable||children.push(createPin1Indicator(scaledWidth,scaledHeight,rotation5,layer,isPinTop,isPinLeft)),{name:"g",type:"element",value:"",attributes:{transform:`translate(${x4}, ${y4}) scale(1, -1)`},children}}function createComponentPath(scaledWidth,scaledHeight,rotation5,layer){let w4=scaledWidth/2,h6=scaledHeight/2;return{name:"path",type:"element",attributes:{class:"assembly-component",d:getRectPathData(w4,h6,rotation5),"stroke-width":.8.toFixed(2),transform:`rotate(${-rotation5})`,"stroke-dasharray":layer==="bottom"?"2,2":""},value:"",children:[]}}function createComponentLabel(scaledWidth,scaledHeight,name,transform6){let size3=Math.min(scaledWidth,scaledHeight),fontSize=Math.min(58,Math.max(3,size3*.8)),isTall=scaledHeight>scaledWidth;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":`${fontSize.toFixed(1)}px`,transform:isTall?"rotate(90) scale(1, -1)":"scale(1, -1)"},children:[{type:"text",value:name||"",name:"",attributes:{},children:[]}],value:""}}function createPin1Indicator(scaledWidth,scaledHeight,rotation5,layer,isPinTop,isPinLeft){let w4=scaledWidth/2,h6=scaledHeight/2,indicatorSize=Math.min(w4,h6)*.5,points;return isPinTop&&isPinLeft?points=[[-w4,-h6],[-w4+indicatorSize,-h6],[-w4,-h6+indicatorSize]]:isPinTop&&!isPinLeft?points=[[w4,-h6],[w4-indicatorSize,-h6],[w4,-h6+indicatorSize]]:!isPinTop&&isPinLeft?points=[[-w4,h6],[-w4+indicatorSize,h6],[-w4,h6-indicatorSize]]:points=[[w4,h6],[w4-indicatorSize,h6],[w4,h6-indicatorSize]],{name:"polygon",type:"element",attributes:{class:"assembly-pin1-indicator",points:points.map(p4=>p4.join(",")).join(" "),fill:"#333",stroke:"none",transform:`rotate(${-rotation5})`},value:"",children:[]}}function getRectPathData(w4,h6,rotation5){let rotatePoint6=(x4,y4,angle)=>{let rad=Math.PI/180*angle,cos6=Math.cos(rad),sin6=Math.sin(rad);return[x4*cos6-y4*sin6,x4*sin6+y4*cos6]};return`${[[-w4,-h6],[w4,-h6],[w4,h6],[-w4,h6]].map(([x4,y4])=>rotatePoint6(x4,y4,rotation5)).map(([x4,y4],i3)=>i3===0?`M${x4},${y4}`:`L${x4},${y4}`).join(" ")} Z`}function createSvgObjectsFromAssemblyHole(hole,ctx){let{transform:transform6}=ctx,[x4,y4]=applyToPoint3(transform6,[hole.x,hole.y]);if(hole.hole_shape==="circle"||hole.hole_shape==="square"){let scaledDiameter=hole.hole_diameter*Math.abs(transform6.a),radius=scaledDiameter/2;return hole.hole_shape==="circle"?[{name:"circle",type:"element",attributes:{class:"assembly-hole",cx:x4.toString(),cy:y4.toString(),r:radius.toString(),fill:HOLE_COLOR2},children:[],value:""}]:[{name:"rect",type:"element",attributes:{class:"assembly-hole",x:(x4-radius).toString(),y:(y4-radius).toString(),width:scaledDiameter.toString(),height:scaledDiameter.toString(),fill:HOLE_COLOR2},children:[],value:""}]}if(hole.hole_shape==="oval"){let scaledWidth=hole.hole_width*Math.abs(transform6.a),scaledHeight=hole.hole_height*Math.abs(transform6.a),rx3=scaledWidth/2,ry3=scaledHeight/2;return[{name:"ellipse",type:"element",attributes:{class:"assembly-hole",cx:x4.toString(),cy:y4.toString(),rx:rx3.toString(),ry:ry3.toString(),fill:HOLE_COLOR2},children:[],value:""}]}return[]}function createSvgObjectsFromAssemblyPlatedHole(hole,ctx){let{transform:transform6}=ctx,[x4,y4]=applyToPoint3(transform6,[hole.x,hole.y]);if(hole.shape==="pill"){let scaledOuterWidth=hole.outer_width*Math.abs(transform6.a),scaledOuterHeight=hole.outer_height*Math.abs(transform6.a),scaledHoleWidth=hole.hole_width*Math.abs(transform6.a),scaledHoleHeight=hole.hole_height*Math.abs(transform6.a),outerRadiusX=scaledOuterWidth/2,straightLength=scaledOuterHeight-scaledOuterWidth,innerRadiusX=scaledHoleWidth/2;return[{name:"g",type:"element",children:[{name:"path",type:"element",attributes:{class:"assembly-hole-outer",fill:PAD_COLOR,d:`M${x4-outerRadiusX},${y4-straightLength/2} v${straightLength} a${outerRadiusX},${outerRadiusX} 0 0 0 ${scaledOuterWidth},0 v-${straightLength} a${outerRadiusX},${outerRadiusX} 0 0 0 -${scaledOuterWidth},0 z`},value:"",children:[]},{name:"path",type:"element",attributes:{class:"assembly-hole-inner",fill:HOLE_COLOR3,d:`M${x4-innerRadiusX},${y4-(scaledHoleHeight-scaledHoleWidth)/2} v${scaledHoleHeight-scaledHoleWidth} a${innerRadiusX},${innerRadiusX} 0 0 0 ${scaledHoleWidth},0 v-${scaledHoleHeight-scaledHoleWidth} a${innerRadiusX},${innerRadiusX} 0 0 0 -${scaledHoleWidth},0 z`},value:"",children:[]}],value:"",attributes:{}}]}if(hole.shape==="circle"){let scaledOuterWidth=hole.outer_diameter*Math.abs(transform6.a),scaledOuterHeight=hole.outer_diameter*Math.abs(transform6.a),scaledHoleWidth=hole.hole_diameter*Math.abs(transform6.a),scaledHoleHeight=hole.hole_diameter*Math.abs(transform6.a),outerRadius=Math.min(scaledOuterWidth,scaledOuterHeight)/2,innerRadius=Math.min(scaledHoleWidth,scaledHoleHeight)/2;return[{name:"g",type:"element",children:[{name:"circle",type:"element",attributes:{class:"assembly-hole-outer",fill:PAD_COLOR,cx:x4.toString(),cy:y4.toString(),r:outerRadius.toString()},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"assembly-hole-inner",fill:HOLE_COLOR3,cx:x4.toString(),cy:y4.toString(),r:innerRadius.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(hole.shape==="circular_hole_with_rect_pad"){let circularHole=hole,scaledHoleDiameter=circularHole.hole_diameter*Math.abs(transform6.a),scaledRectPadWidth=circularHole.rect_pad_width*Math.abs(transform6.a),scaledRectPadHeight=circularHole.rect_pad_height*Math.abs(transform6.a),scaledRectBorderRadius=(circularHole.rect_border_radius??0)*Math.abs(transform6.a),rectCcwRotation=circularHole.rect_ccw_rotation??0,holeRadius=scaledHoleDiameter/2,[holeCx,holeCy]=applyToPoint3(transform6,[circularHole.x+circularHole.hole_offset_x,circularHole.y+circularHole.hole_offset_y]);return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"assembly-hole-outer-pad",fill:PAD_COLOR,...rectCcwRotation?{x:(-scaledRectPadWidth/2).toString(),y:(-scaledRectPadHeight/2).toString(),transform:`translate(${x4} ${y4}) rotate(${-rectCcwRotation})`}:{x:(x4-scaledRectPadWidth/2).toString(),y:(y4-scaledRectPadHeight/2).toString()},width:scaledRectPadWidth.toString(),height:scaledRectPadHeight.toString(),...scaledRectBorderRadius?{rx:scaledRectBorderRadius.toString(),ry:scaledRectBorderRadius.toString()}:{}},value:"",children:[]},{name:"circle",type:"element",attributes:{class:"assembly-hole-inner",fill:HOLE_COLOR3,cx:holeCx.toString(),cy:holeCy.toString(),r:holeRadius.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(hole.shape==="pill_hole_with_rect_pad"){let pillHole=hole,scaledRectPadWidth=pillHole.rect_pad_width*Math.abs(transform6.a),scaledRectPadHeight=pillHole.rect_pad_height*Math.abs(transform6.a),scaledRectBorderRadius=(pillHole.rect_border_radius??0)*Math.abs(transform6.a),scaledHoleHeight=pillHole.hole_height*Math.abs(transform6.a),scaledHoleWidth=pillHole.hole_width*Math.abs(transform6.a),pillHoleWithOffsets=pillHole,holeOffsetX=pillHoleWithOffsets.hole_offset_x??0,holeOffsetY=pillHoleWithOffsets.hole_offset_y??0,[holeCenterX,holeCenterY]=applyToPoint3(transform6,[pillHole.x+holeOffsetX,pillHole.y+holeOffsetY]),holeRadius=Math.min(scaledHoleHeight,scaledHoleWidth)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"assembly-hole-outer-pad",fill:PAD_COLOR,x:(x4-scaledRectPadWidth/2).toString(),y:(y4-scaledRectPadHeight/2).toString(),width:scaledRectPadWidth.toString(),height:scaledRectPadHeight.toString(),...scaledRectBorderRadius?{rx:scaledRectBorderRadius.toString(),ry:scaledRectBorderRadius.toString()}:{}},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"assembly-hole-inner",fill:HOLE_COLOR3,x:(holeCenterX-scaledHoleWidth/2).toString(),y:(holeCenterY-scaledHoleHeight/2).toString(),width:scaledHoleWidth.toString(),height:scaledHoleHeight.toString(),rx:holeRadius.toString(),ry:holeRadius.toString()},value:"",children:[]}],value:"",attributes:{}}]}if(hole.shape==="rotated_pill_hole_with_rect_pad"){let rotatedHole=hole,scaledRectPadWidth=rotatedHole.rect_pad_width*Math.abs(transform6.a),scaledRectPadHeight=rotatedHole.rect_pad_height*Math.abs(transform6.a),scaledRectBorderRadius=(rotatedHole.rect_border_radius??0)*Math.abs(transform6.a),scaledHoleHeight=rotatedHole.hole_height*Math.abs(transform6.a),scaledHoleWidth=rotatedHole.hole_width*Math.abs(transform6.a),rotatedHoleWithOffsets=rotatedHole,holeOffsetX=rotatedHoleWithOffsets.hole_offset_x??0,holeOffsetY=rotatedHoleWithOffsets.hole_offset_y??0,[holeCenterX,holeCenterY]=applyToPoint3(transform6,[rotatedHole.x+holeOffsetX,rotatedHole.y+holeOffsetY]),holeRadius=Math.min(scaledHoleHeight,scaledHoleWidth)/2;return[{name:"g",type:"element",children:[{name:"rect",type:"element",attributes:{class:"assembly-hole-outer-pad",fill:PAD_COLOR,x:(-scaledRectPadWidth/2).toString(),y:(-scaledRectPadHeight/2).toString(),width:scaledRectPadWidth.toString(),height:scaledRectPadHeight.toString(),transform:`translate(${x4} ${y4}) rotate(${-rotatedHole.rect_ccw_rotation})`,...scaledRectBorderRadius?{rx:scaledRectBorderRadius.toString(),ry:scaledRectBorderRadius.toString()}:{}},value:"",children:[]},{name:"rect",type:"element",attributes:{class:"assembly-hole-inner",fill:HOLE_COLOR3,x:(-scaledHoleWidth/2).toString(),y:(-scaledHoleHeight/2).toString(),width:scaledHoleWidth.toString(),height:scaledHoleHeight.toString(),rx:holeRadius.toString(),ry:holeRadius.toString(),transform:`translate(${holeCenterX} ${holeCenterY}) rotate(${-rotatedHole.hole_ccw_rotation})`},value:"",children:[]}],value:"",attributes:{}}]}return[]}function createSvgObjectsFromAssemblySmtPad(pad2,ctx){let{transform:transform6}=ctx;if(pad2.shape==="rect"||pad2.shape==="rotated_rect"){let width=pad2.width*Math.abs(transform6.a),height=pad2.height*Math.abs(transform6.d),[x4,y4]=applyToPoint3(transform6,[pad2.x,pad2.y]),scaledBorderRadius=(pad2.rect_border_radius??0)*Math.abs(transform6.a);return pad2.shape==="rotated_rect"&&pad2.ccw_rotation?[{name:"rect",type:"element",attributes:{class:"assembly-pad",fill:PAD_COLOR2,x:(-width/2).toString(),y:(-height/2).toString(),width:width.toString(),height:height.toString(),transform:`translate(${x4} ${y4}) rotate(${-pad2.ccw_rotation})`,"data-layer":pad2.layer,...scaledBorderRadius?{rx:scaledBorderRadius.toString(),ry:scaledBorderRadius.toString()}:{}},value:"",children:[]}]:[{name:"rect",type:"element",attributes:{class:"assembly-pad",fill:PAD_COLOR2,x:(x4-width/2).toString(),y:(y4-height/2).toString(),width:width.toString(),height:height.toString(),"data-layer":pad2.layer,...scaledBorderRadius?{rx:scaledBorderRadius.toString(),ry:scaledBorderRadius.toString()}:{}},value:"",children:[]}]}if(pad2.shape==="pill"){let width=pad2.width*Math.abs(transform6.a),height=pad2.height*Math.abs(transform6.d),radius=pad2.radius*Math.abs(transform6.a),[x4,y4]=applyToPoint3(transform6,[pad2.x,pad2.y]);return[{name:"rect",type:"element",attributes:{class:"assembly-pad",fill:PAD_COLOR2,x:(x4-width/2).toString(),y:(y4-height/2).toString(),width:width.toString(),height:height.toString(),rx:radius.toString(),ry:radius.toString(),"data-layer":pad2.layer},value:"",children:[]}]}if(pad2.shape==="circle"){let radius=pad2.radius*Math.abs(transform6.a),[x4,y4]=applyToPoint3(transform6,[pad2.x,pad2.y]);return[{name:"circle",type:"element",attributes:{class:"assembly-pad",fill:PAD_COLOR2,cx:x4.toString(),cy:y4.toString(),r:radius.toString(),"data-layer":pad2.layer},value:"",children:[]}]}if(pad2.shape==="polygon"){let points=(pad2.points??[]).map(point7=>applyToPoint3(transform6,[point7.x,point7.y]));return[{name:"polygon",type:"element",attributes:{class:"assembly-pad",fill:PAD_COLOR2,points:points.map(p4=>p4.join(",")).join(" "),"data-layer":pad2.layer},value:"",children:[]}]}return[]}function convertCircuitJsonToAssemblySvg(soup,options){let minX=Number.POSITIVE_INFINITY,minY=Number.POSITIVE_INFINITY,maxX=Number.NEGATIVE_INFINITY,maxY=Number.NEGATIVE_INFINITY;for(let item of soup)if(item.type==="pcb_board"){let center2=item.center,width=item.width||0,height=item.height||0;minX=Math.min(minX,center2.x-width/2),minY=Math.min(minY,center2.y-height/2),maxX=Math.max(maxX,center2.x+width/2),maxY=Math.max(maxY,center2.y+height/2)}let padding=1,circuitWidth=maxX-minX+2*padding,circuitHeight=maxY-minY+2*padding,svgWidth=options?.width??800,svgHeight=options?.height??600,scaleX=svgWidth/circuitWidth,scaleY=svgHeight/circuitHeight,scaleFactor=Math.min(scaleX,scaleY),offsetX=(svgWidth-circuitWidth*scaleFactor)/2,offsetY=(svgHeight-circuitHeight*scaleFactor)/2,transform6=compose3(translate3(offsetX-minX*scaleFactor+padding*scaleFactor,svgHeight-offsetY+minY*scaleFactor-padding*scaleFactor),scale3(scaleFactor,-scaleFactor)),ctx={transform:transform6},svgObjects=soup.sort((a3,b3)=>(OBJECT_ORDER.indexOf(b3.type)??9999)-(OBJECT_ORDER.indexOf(a3.type)??9999)).flatMap(item=>createSvgObjects2(item,ctx,soup)),softwareUsedString=getSoftwareUsedString(soup),version2=CIRCUIT_TO_SVG_VERSION,children=[{name:"style",type:"element",children:[{type:"text",value:`
|
|
229
229
|
.assembly-component {
|
|
230
230
|
fill: none;
|
|
231
231
|
stroke: #000;
|
|
@@ -287,7 +287,7 @@ svg { font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif; }
|
|
|
287
287
|
.simulation-line { fill: none; stroke-width: 2.5; }
|
|
288
288
|
.simulation-point { stroke-width: 0; }
|
|
289
289
|
.chart-title { fill: rgba(0, 0, 0, 0.85); font-size: 18px; font-weight: 600; }
|
|
290
|
-
`;return svgElement("style",{},[textNode(content)])}function createBackgroundRect(width,height){return svgElement("rect",{class:"background",x:"0",y:"0",width:formatNumber(width),height:formatNumber(height)})}function createDefsNode(clipPathId,plotWidth,plotHeight){return svgElement("defs",{},[svgElement("clipPath",{id:clipPathId},[svgElement("rect",{x:formatNumber(MARGIN.left),y:formatNumber(MARGIN.top),width:formatNumber(plotWidth),height:formatNumber(plotHeight)})])])}function createPlotBackground(plotWidth,plotHeight){return svgElement("rect",{class:"plot-background",x:formatNumber(MARGIN.left),y:formatNumber(MARGIN.top),width:formatNumber(plotWidth),height:formatNumber(plotHeight)})}function createGridLines({timeAxis,voltageAxis,scaleX,scaleY,plotWidth,plotHeight}){let top=MARGIN.top,bottom=MARGIN.top+plotHeight,left=MARGIN.left,right=MARGIN.left+plotWidth,children=[];for(let tick of timeAxis.ticks){let x4=formatNumber(scaleX(tick));children.push(svgElement("line",{class:"grid-line grid-line-x",x1:x4,y1:formatNumber(top),x2:x4,y2:formatNumber(bottom)}))}for(let tick of voltageAxis.ticks){let y4=formatNumber(scaleY(tick));children.push(svgElement("line",{class:"grid-line grid-line-y",x1:formatNumber(left),y1:y4,x2:formatNumber(right),y2:y4}))}return svgElement("g",{class:"grid"},children)}function createAxes({timeAxis,voltageAxis,scaleX,scaleY,plotWidth,plotHeight}){let bottom=MARGIN.top+plotHeight,left=MARGIN.left,right=MARGIN.left+plotWidth,children=[svgElement("line",{class:"axis axis-x",x1:formatNumber(left),y1:formatNumber(bottom),x2:formatNumber(right),y2:formatNumber(bottom)}),svgElement("line",{class:"axis axis-y",x1:formatNumber(left),y1:formatNumber(MARGIN.top),x2:formatNumber(left),y2:formatNumber(bottom)})];for(let tick of timeAxis.ticks){let x4=formatNumber(scaleX(tick));children.push(svgElement("line",{class:"axis-tick axis-tick-x",x1:x4,y1:formatNumber(bottom),x2:x4,y2:formatNumber(bottom+6)})),children.push(svgElement("text",{class:"axis-label axis-label-x",x:x4,y:formatNumber(bottom+22),"text-anchor":"middle"},[textNode(formatTickLabel(tick,timeAxis.ticks))]))}for(let tick of voltageAxis.ticks){let y4=formatNumber(scaleY(tick));children.push(svgElement("line",{class:"axis-tick axis-tick-y",x1:formatNumber(left-6),y1:y4,x2:formatNumber(left),y2:y4})),children.push(svgElement("text",{class:"axis-label axis-label-y",x:formatNumber(left-10),y:y4,"text-anchor":"end","dominant-baseline":"middle"},[textNode(formatTickLabel(tick,voltageAxis.ticks))]))}return children.push(svgElement("text",{class:"axis-title axis-title-x",x:formatNumber(left+plotWidth/2),y:formatNumber(bottom+48),"text-anchor":"middle"},[textNode("Time (ms)")]),svgElement("text",{class:"axis-title axis-title-y",x:formatNumber(left-64),y:formatNumber(MARGIN.top+plotHeight/2),transform:`rotate(-90 ${formatNumber(left-64)} ${formatNumber(MARGIN.top+plotHeight/2)})`,"text-anchor":"middle"},[textNode("Voltage (V)")])),svgElement("g",{class:"axes"},children)}function createLegend(graphs,width){let currentY=MARGIN.top,children=graphs.map(entry=>{let x4=width-MARGIN.right+10,lines=wrapLegendText(entry.label),legendItem=createLegendItem(entry,x4,currentY,lines),itemHeight=lines.length*LEGEND_LINE_HEIGHT;return currentY+=Math.max(itemHeight,LEGEND_MIN_SPACING),legendItem});return svgElement("g",{class:"legend"},children)}function wrapLegendText(label){let parts=label.split("_");if(parts.length<=1)return[label];let lines=[],currentLine=parts[0]??"";for(let i3=1;i3<parts.length;i3++){let part=parts[i3]??"",testLine=currentLine+"_"+part;testLine.length>MAX_LEGEND_LINE_LENGTH?(lines.push(currentLine),currentLine=part):currentLine=testLine}return currentLine&&lines.push(currentLine),lines}function createLegendItem(entry,x4,y4,lines){let textChildren=lines.map((line2,index)=>svgElement("tspan",{x:"20",dy:index===0?"0":String(LEGEND_LINE_HEIGHT)},[textNode(line2)]));return svgElement("g",{class:"legend-item",transform:`translate(${formatNumber(x4)} ${formatNumber(y4)})`},[svgElement("line",{class:"legend-line",x1:"0",y1:"0",x2:"16",y2:"0",stroke:entry.color}),svgElement("text",{class:"legend-label",x:"20",y:"0","dominant-baseline":"middle"},textChildren)])}function createDataGroup(graphs,clipPathId,scaleX,scaleY){let DASH_PATTERN=[4,8],dashArrayString=DASH_PATTERN.map(value=>formatNumber(value)).join(" "),dashOffsetStep=DASH_PATTERN.reduce((sum,value)=>sum+value,0)/3,processedGraphs=[];graphs.forEach((entry,graphIndex)=>{if(entry.points.length===0)return;let commands=[];entry.points.forEach((point7,index)=>{let x4=formatNumber(scaleX(point7.timeMs)),y4=formatNumber(scaleY(point7.voltage));commands.push(`${index===0?"M":"L"} ${x4} ${y4}`)});let baseAttributes={class:"simulation-line",d:commands.join(" "),stroke:entry.color,"clip-path":`url(#${clipPathId})`,"data-simulation-transient-voltage-graph-id":entry.graph.simulation_transient_voltage_graph_id};entry.graph.source_component_id&&(baseAttributes["data-source-component-id"]=entry.graph.source_component_id),entry.graph.subcircuit_connectivity_map_key&&(baseAttributes["data-subcircuit-connectivity-map-key"]=entry.graph.subcircuit_connectivity_map_key);let pointElements2=entry.points.map(point7=>{let cx3=formatNumber(scaleX(point7.timeMs)),cy3=formatNumber(scaleY(point7.voltage));return svgElement("circle",{class:"simulation-point",cx:cx3,cy:cy3,r:"2.5",fill:entry.color,"clip-path":`url(#${clipPathId})`})});processedGraphs.push({entry,graphIndex,pathAttributes:baseAttributes,pointElements:pointElements2})});let lineElements=[];for(let cycle=0;cycle<3;cycle++)processedGraphs.forEach(graphInfo=>{let offsetIndex=(graphInfo.graphIndex+cycle)%3,dashOffset=formatNumber(offsetIndex*dashOffsetStep);lineElements.push(svgElement("path",{...graphInfo.pathAttributes,"stroke-dasharray":dashArrayString,"stroke-dashoffset":dashOffset}))});let pointElements=processedGraphs.flatMap(graphInfo=>graphInfo.pointElements);return svgElement("g",{class:"data-series"},[...lineElements,...pointElements])}function createTitleNode(experiment,width){return experiment?.name?svgElement("text",{class:"chart-title",x:formatNumber(width/2),y:formatNumber(MARGIN.top-40),"text-anchor":"middle"},[textNode(experiment.name)]):null}function createClipPathId(simulationExperimentId){return`simulation-graph-${simulationExperimentId.replace(/[^a-zA-Z0-9_-]+/g,"-")}`}function formatNumber(value){if(!Number.isFinite(value))return"0";let rounded=Number.parseFloat(value.toFixed(6));return Number.isInteger(rounded),rounded.toString()}function formatTickLabel(value,ticks){if(ticks.length<=1)return formatNumber(value);let span=ticks[ticks.length-1]-ticks[0];if(!Number.isFinite(span)||span===0)return formatNumber(value);let precision=span>=100?0:span>=10?1:span>=1?2:3,factor=Math.pow(10,precision);return(Math.round(value*factor)/factor).toFixed(precision).replace(/\.0+$/,"").replace(/(\.\d*?)0+$/,"$1").replace(/\.$/,"")}function svgElement(name,attributes2,children=[]){return{name,type:"element",value:"",attributes:attributes2,children}}function textNode(value){return{name:"",type:"text",value,attributes:{},children:[]}}function convertCircuitJsonToSchematicSimulationSvg({circuitJson,simulation_experiment_id,simulation_transient_voltage_graph_ids,width=DEFAULT_WIDTH2,height=DEFAULT_HEIGHT2,schematicHeightRatio=DEFAULT_SCHEMATIC_RATIO,schematicOptions,includeVersion,graphAboveSchematic=!1,showErrorsInTextOverlay}){let schematicElements=circuitJson.filter(element=>!isSimulationExperiment(element)&&!isSimulationTransientVoltageGraph(element)),clampedRatio=clamp01(schematicHeightRatio),rawSchematicHeight=Math.max(1,height*clampedRatio),rawSimulationHeight=Math.max(1,height-rawSchematicHeight),totalRawHeight=rawSchematicHeight+rawSimulationHeight,scale10=totalRawHeight===0?1:height/totalRawHeight,schematicHeight=rawSchematicHeight*scale10,simulationHeight=rawSimulationHeight*scale10,schematicSvg=convertCircuitJsonToSchematicSvg(schematicElements,{...schematicOptions,width,height:schematicHeight,includeVersion:!1,showErrorsInTextOverlay}),simulationSvg=convertCircuitJsonToSimulationGraphSvg({circuitJson,simulation_experiment_id,simulation_transient_voltage_graph_ids,width,height:simulationHeight,includeVersion:!1}),schematicNode=ensureElementNode((0,import_svgson10.parseSync)(schematicSvg)),simulationNode=ensureElementNode((0,import_svgson10.parseSync)(simulationSvg)),combinedChildren=[];graphAboveSchematic?(combinedChildren.push(translateNestedSvg(simulationNode,0,0,width,simulationHeight)),combinedChildren.push(translateNestedSvg(schematicNode,0,simulationHeight,width,schematicHeight))):(combinedChildren.push(translateNestedSvg(schematicNode,0,0,width,schematicHeight)),combinedChildren.push(translateNestedSvg(simulationNode,0,schematicHeight,width,simulationHeight)));let softwareUsedString=getSoftwareUsedString(schematicElements),svgObject={name:"svg",type:"element",value:"",attributes:{xmlns:"http://www.w3.org/2000/svg",width:formatNumber2(width),height:formatNumber2(height),viewBox:`0 0 ${formatNumber2(width)} ${formatNumber2(height)}`,"data-simulation-experiment-id":simulation_experiment_id,...softwareUsedString&&{"data-software-used-string":softwareUsedString},...includeVersion&&{"data-circuit-to-svg-version":CIRCUIT_TO_SVG_VERSION}},children:combinedChildren};return(0,import_svgson10.stringify)(svgObject)}function translateNestedSvg(node,x4,y4,width,height){let clone=cloneSvgObject(node);return clone.attributes={...clone.attributes,x:formatNumber2(x4),y:formatNumber2(y4),width:formatNumber2(width),height:formatNumber2(height)},delete clone.attributes.xmlns,clone}function ensureElementNode(node){if(node.type!=="element")throw new Error("Expected SVG root element to be of type 'element'");return node}function cloneSvgObject(node){return{...node,attributes:{...node.attributes??{}},children:node.children?.map(cloneSvgObject)??[]}}function clamp01(value){return Number.isFinite(value)?value<=0?0:value>=1?1:value:DEFAULT_SCHEMATIC_RATIO}function formatNumber2(value){if(!Number.isFinite(value))return"0";let rounded=Number.parseFloat(value.toFixed(6));return Number.isInteger(rounded),rounded.toString()}function createSvgObjectsFromSolderPaste(solderPaste,ctx){let{transform:transform6,layer:layerFilter}=ctx;if(layerFilter&&solderPaste.layer!==layerFilter)return[];let[x4,y4]=applyToPoint3(transform6,[solderPaste.x,solderPaste.y]);if(solderPaste.shape==="rect"||solderPaste.shape==="rotated_rect"){let width=solderPaste.width*Math.abs(transform6.a),height=solderPaste.height*Math.abs(transform6.d);return solderPaste.shape==="rotated_rect"&&solderPaste.ccw_rotation?[{name:"rect",type:"element",attributes:{class:"pcb-solder-paste",fill:solderPasteLayerNameToColor(solderPaste.layer),x:(-width/2).toString(),y:(-height/2).toString(),width:width.toString(),height:height.toString(),transform:`translate(${x4} ${y4}) rotate(${-solderPaste.ccw_rotation})`,"data-type":"pcb_solder_paste","data-pcb-layer":solderPaste.layer}}]:[{name:"rect",type:"element",attributes:{class:"pcb-solder-paste",fill:solderPasteLayerNameToColor(solderPaste.layer),x:(x4-width/2).toString(),y:(y4-height/2).toString(),width:width.toString(),height:height.toString(),"data-type":"pcb_solder_paste","data-pcb-layer":solderPaste.layer}}]}if(solderPaste.shape==="pill"){let width=solderPaste.width*Math.abs(transform6.a),height=solderPaste.height*Math.abs(transform6.d),radius=solderPaste.radius*Math.abs(transform6.a);return[{name:"rect",type:"element",attributes:{class:"pcb-solder-paste",fill:solderPasteLayerNameToColor(solderPaste.layer),x:(x4-width/2).toString(),y:(y4-height/2).toString(),width:width.toString(),height:height.toString(),rx:radius.toString(),"data-type":"pcb_solder_paste","data-pcb-layer":solderPaste.layer}}]}if(solderPaste.shape==="circle"){let radius=solderPaste.radius*Math.abs(transform6.a);return[{name:"circle",type:"element",attributes:{class:"pcb-solder-paste",fill:solderPasteLayerNameToColor(solderPaste.layer),cx:x4.toString(),cy:y4.toString(),r:radius.toString(),"data-type":"pcb_solder_paste","data-pcb-layer":solderPaste.layer}}]}}function convertCircuitJsonToSolderPasteMask(circuitJson,options){let minX=Number.POSITIVE_INFINITY,minY=Number.POSITIVE_INFINITY,maxX=Number.NEGATIVE_INFINITY,maxY=Number.NEGATIVE_INFINITY,filteredCircuitJson=circuitJson.filter(elm=>elm.type==="pcb_board"||elm.type==="pcb_panel"||elm.type==="pcb_solder_paste"&&elm.layer===options.layer);for(let item of filteredCircuitJson)if(item.type==="pcb_board")item.outline&&Array.isArray(item.outline)&&item.outline.length>=3?updateBoundsToIncludeOutline(item.outline):"center"in item&&"width"in item&&"height"in item&&updateBounds(item.center,item.width,item.height);else if(item.type==="pcb_panel"){let panel=item,width=distance.parse(panel.width),height=distance.parse(panel.height);if(width!==void 0&&height!==void 0){let center2=panel.center??{x:width/2,y:height/2};updateBounds(center2,width,height)}}else item.type==="pcb_solder_paste"&&"x"in item&&"y"in item&&updateBounds({x:item.x,y:item.y},0,0);let padding=1,circuitWidth=maxX-minX+2*padding,circuitHeight=maxY-minY+2*padding,svgWidth=options.width??800,svgHeight=options.height??600,scaleX=svgWidth/circuitWidth,scaleY=svgHeight/circuitHeight,scaleFactor=Math.min(scaleX,scaleY),offsetX=(svgWidth-circuitWidth*scaleFactor)/2,offsetY=(svgHeight-circuitHeight*scaleFactor)/2,transform6=compose3(translate3(offsetX-minX*scaleFactor+padding*scaleFactor,svgHeight-offsetY+minY*scaleFactor-padding*scaleFactor),scale3(scaleFactor,-scaleFactor)),ctx={transform:transform6,layer:options.layer,colorMap:DEFAULT_PCB_COLOR_MAP},svgObjects=filteredCircuitJson.sort((a3,b3)=>(OBJECT_ORDER3.indexOf(b3.type)??9999)-(OBJECT_ORDER3.indexOf(a3.type)??9999)).flatMap(item=>createSvgObjects4({elm:item,ctx})),softwareUsedString=getSoftwareUsedString(circuitJson),version2=CIRCUIT_TO_SVG_VERSION,children=[{name:"style",type:"element",children:[{type:"text",value:""}]},{name:"rect",type:"element",attributes:{class:"boundary",x:"0",y:"0",fill:"#000",width:svgWidth.toString(),height:svgHeight.toString()}},createSvgObjectFromPcbBoundary2(transform6,minX,minY,maxX,maxY),...svgObjects].filter(child=>child!==null);if(options?.showErrorsInTextOverlay){let errorOverlay=createErrorTextOverlay(circuitJson);errorOverlay&&children.push(errorOverlay)}let svgObject={name:"svg",type:"element",attributes:{xmlns:"http://www.w3.org/2000/svg",width:svgWidth.toString(),height:svgHeight.toString(),...softwareUsedString&&{"data-software-used-string":softwareUsedString},...options.includeVersion&&{"data-circuit-to-svg-version":version2}},value:"",children};try{return(0,import_svgson12.stringify)(svgObject)}catch(error2){throw console.error("Error stringifying SVG object:",error2),error2}function updateBounds(center2,width,height){let halfWidth=width/2,halfHeight=height/2;minX=Math.min(minX,center2.x-halfWidth),minY=Math.min(minY,center2.y-halfHeight),maxX=Math.max(maxX,center2.x+halfWidth),maxY=Math.max(maxY,center2.y+halfHeight)}function updateBoundsToIncludeOutline(outline){for(let point7 of outline)minX=Math.min(minX,point7.x),minY=Math.min(minY,point7.y),maxX=Math.max(maxX,point7.x),maxY=Math.max(maxY,point7.y)}}function createSvgObjects4({elm,ctx}){let{transform:transform6}=ctx;switch(elm.type){case"pcb_board":return createSvgObjectsFromPcbBoard(elm,ctx);case"pcb_solder_paste":return createSvgObjectsFromSolderPaste(elm,ctx);default:return[]}}function createSvgObjectFromPcbBoundary2(transform6,minX,minY,maxX,maxY){let[x12,y12]=applyToPoint3(transform6,[minX,minY]),[x22,y22]=applyToPoint3(transform6,[maxX,maxY]),width=Math.abs(x22-x12),height=Math.abs(y22-y12),x4=Math.min(x12,x22),y4=Math.min(y12,y22);return{name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-boundary",fill:"none",stroke:"#fff","stroke-width":"0.3",x:x4.toString(),y:y4.toString(),width:width.toString(),height:height.toString()}}}var import_svgson2,import_debug5,import_svgson3,import_svgson4,import_svgson5,import_svgson6,import_svgson7,import_svgson8,import_svgson9,import_svgson10,import_svgson11,import_svgson12,debug5,debugPcb,debugSch,DEFAULT_OVERLAY_STROKE_COLOR,DEFAULT_OVERLAY_FILL_COLOR,TEXT_OFFSET_MULTIPLIER,CHARACTER_WIDTH_MULTIPLIER,TEXT_INTERSECTION_PADDING_MULTIPLIER,colorMap,DEFAULT_OVERLAY_COLOR,DEFAULT_OVERLAY_COLOR2,DEFAULT_FILL_COLOR,DEFAULT_OVERLAY_COLOR3,DEFAULT_OVERLAY_COLOR4,alphabetBounds,INTER_CHAR_SPACING_RATIO,LINE_HEIGHT_MULTIPLIER,silkscreenMaskIdCounter,DEFAULT_PCB_COLOR_MAP,HOLE_COLOR,SILKSCREEN_TOP_COLOR,SILKSCREEN_BOTTOM_COLOR,LAYER_NAME_TO_COLOR,SOLDER_PASTE_LAYER_NAME_TO_COLOR,CHAR_WIDTH,CHAR_SPACING,LINE_HEIGHT,FONT_SCALE,maskIdCounter,OFFSET_THRESHOLD_MM,TICK_SIZE_PX,LABEL_GAP_PX,LABEL_FONT_SIZE_PX,STROKE_WIDTH_PX,ANCHOR_MARKER_SIZE_PX,ANCHOR_MARKER_STROKE_WIDTH_PX,COMPONENT_ANCHOR_MARKER_RADIUS_PX,CONNECTOR_GROUP_GAP_PX,CONNECTOR_COMPONENT_GAP_PX,DIMENSION_ANCHOR_CLEARANCE_PX,COMPONENT_GAP_PX,COMPONENT_SIDE_GAP_PX,DISTANCE_MULTIPLIER,MAX_OFFSET_PX,getElementPosition,findNearestPointInNet,KEEPOUT_PATTERN_ID,KEEPOUT_PATTERN_SIZE,KEEPOUT_LINE_SPACING,KEEPOUT_BACKGROUND_COLOR,DEFAULT_GRID_LINE_COLOR,GRID_PATTERN_ID,GROUP_COLOR_PALETTE,DEFAULT_STROKE_WIDTH,package_default2,CIRCUIT_TO_SVG_VERSION,TYPE_PRIORITY,DEFAULT_TYPE_PRIORITY,getViewportBounds,circuitJsonToPcbSvg,DEFAULT_BOARD_STYLE,fontSizeMap,getSchMmFontSize,getSchScreenFontSize,HOLE_COLOR2,PAD_COLOR,HOLE_COLOR3,PAD_COLOR2,OBJECT_ORDER,BOARD_FILL_COLOR,BOARD_STROKE_COLOR,COMPONENT_FILL_COLOR,COMPONENT_LABEL_COLOR,HOLE_COLOR4,PAD_COLOR3,HOLE_COLOR5,PAD_COLOR4,LABEL_COLOR,LABEL_BACKGROUND,LINE_COLOR,PIN_NUMBER_BACKGROUND,PIN_NUMBER_COLOR,LABEL_RECT_HEIGHT_BASE_MM,FONT_HEIGHT_RATIO,CHAR_WIDTH_FACTOR,STAGGER_OFFSET_MIN,STAGGER_OFFSET_PER_PIN,STAGGER_OFFSET_STEP,ALIGNED_OFFSET_MARGIN,GROUP_SEPARATION_MM,calculateLabelPositions,OBJECT_ORDER2,arialTextMetrics,estimateTextWidth,getTableDimensions,getUnitVectorFromOutsideToEdge,ARROW_POINT_WIDTH_FSR,END_PADDING_FSR,END_PADDING_EXTRA_PER_CHARACTER_FSR,ninePointAnchorToTextAnchor,ninePointAnchorToDominantBaseline,getSchStrokeSize,getAngularDifference,matchSchPortsToSymbolPorts,createSvgSchErrorText,isSourcePortConnected,ninePointAnchorToTextAnchor2,ninePointAnchorToDominantBaseline2,createSvgObjectsFromSchematicComponentWithSymbol,PIN_CIRCLE_RADIUS_MM,createArrow,createSvgObjectsForSchPortBoxLine,createSvgObjectsForSchPortPinNumberText,LABEL_DIST_FROM_EDGE_MM,createSvgObjectsForSchPortPinLabel,createSvgObjectsFromSchPortOnBox,createSvgSchText,createSvgObjectsFromSchematicComponentWithBox,createSvgObjectsFromSchematicComponentWithPrimitives,createSvgObjectsForSchNetLabelWithSymbol,createSvgObjectsForSchNetLabel,createSvgObjectsFromSchematicBox,createSvgObjectsFromSchematicTable,PIN_CIRCLE_RADIUS_MM2,createSvgObjectsForSchPortHover,createSvgObjectsForSchComponentPortHovers,PIN_CIRCLE_RADIUS_MM3,createSvgObjectsForSchPortIndicator,circuitJsonToSchematicSvg,DEFAULT_WIDTH,DEFAULT_HEIGHT,MARGIN,FALLBACK_LINE_COLOR,MAX_LEGEND_LINE_LENGTH,LEGEND_LINE_HEIGHT,LEGEND_MIN_SPACING,DEFAULT_WIDTH2,DEFAULT_HEIGHT2,DEFAULT_SCHEMATIC_RATIO,OBJECT_ORDER3,init_dist8=__esm({"node_modules/circuit-to-svg/dist/index.js"(){"use strict";init_dist();import_svgson2=__toESM(require_svgson_umd(),1);init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();import_debug5=__toESM(require_browser(),1);init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_dist7();init_dist7();init_src2();init_src2();init_dist();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_dist3();import_svgson3=__toESM(require_svgson_umd(),1);init_src2();init_dist6();init_dist3();init_dist6();init_src2();init_src2();init_src2();init_src2();init_src2();import_svgson4=__toESM(require_svgson_umd(),1);init_src2();init_src2();init_dist();init_dist();import_svgson5=__toESM(require_svgson_umd(),1);init_dist6();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();import_svgson6=__toESM(require_svgson_umd(),1);init_src2();init_src2();init_dist6();init_dist6();init_src2();init_src2();init_src2();init_src2();init_src2();init_dist5();init_src2();init_dist6();import_svgson7=__toESM(require_svgson_umd(),1);init_src2();init_src2();init_src2();init_src2();init_dist4();init_dist6();init_dist4();import_svgson8=__toESM(require_svgson_umd(),1);init_src2();init_src2();init_src2();init_dist6();init_dist4();import_svgson9=__toESM(require_svgson_umd(),1);init_src2();init_src2();init_dist6();init_src2();init_dist6();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_dist4();init_src2();init_src2();init_dist6();init_src2();init_src2();import_svgson10=__toESM(require_svgson_umd(),1),import_svgson11=__toESM(require_svgson_umd(),1);init_dist();import_svgson12=__toESM(require_svgson_umd(),1);init_src2();init_src2();debug5=(0,import_debug5.default)("circuit-to-svg"),debugPcb=debug5.extend("pcb"),debugSch=debug5.extend("sch");DEFAULT_OVERLAY_STROKE_COLOR="rgba(255,255,255,0.5)",DEFAULT_OVERLAY_FILL_COLOR="rgba(255,255,255,0.2)";TEXT_OFFSET_MULTIPLIER=1.5,CHARACTER_WIDTH_MULTIPLIER=.6,TEXT_INTERSECTION_PADDING_MULTIPLIER=.3;colorMap={"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},simulation_palette:["#1f77b4","#d62728","#2ca02c","#ff7f0e","#9467bd","#17becf","#8c564b","#e377c2","#7f7f7f","#bcbd22"],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)"}};DEFAULT_OVERLAY_COLOR=colorMap.board.user_2;DEFAULT_OVERLAY_COLOR2=colorMap.board.user_2,DEFAULT_FILL_COLOR=colorMap.board.user_2;DEFAULT_OVERLAY_COLOR3=colorMap.board.user_2;DEFAULT_OVERLAY_COLOR4=colorMap.board.user_2;alphabetBounds=(()=>{let maxX=0,minY=1/0,maxY=-1/0;for(let segments of Object.values(lineAlphabet))for(let seg of segments)maxX=Math.max(maxX,seg.x1,seg.x2),minY=Math.min(minY,seg.y1,seg.y2),maxY=Math.max(maxY,seg.y1,seg.y2);return{width:maxX,height:maxY-minY}})(),INTER_CHAR_SPACING_RATIO=.2,LINE_HEIGHT_MULTIPLIER=1.1,silkscreenMaskIdCounter=0;DEFAULT_PCB_COLOR_MAP={copper:{top:"rgb(200, 52, 52)",inner1:"rgb(255, 140, 0)",inner2:"rgb(255, 215, 0)",inner3:"rgb(50, 205, 50)",inner4:"rgb(64, 224, 208)",inner5:"rgb(138, 43, 226)",inner6:"rgb(255, 105, 180)",bottom:"rgb(77, 127, 196)"},soldermaskWithCopperUnderneath:{top:"rgb(18, 82, 50)",bottom:"rgb(77, 127, 196)"},soldermask:{top:"rgb(12, 55, 33)",bottom:"rgb(12, 55, 33)"},soldermaskOverCopper:{top:"rgb(52, 135, 73)",bottom:"rgb(52, 135, 73)"},substrate:"rgb(201, 162, 110)",drill:"#FF26E2",silkscreen:{top:"#f2eda1",bottom:"#5da9e9"},boardOutline:"rgba(255, 255, 255, 0.5)",courtyard:{top:"#FF00FF",bottom:"rgb(38, 233, 255)"},keepout:"#FF6B6B",debugComponent:{fill:null,stroke:null}},HOLE_COLOR=DEFAULT_PCB_COLOR_MAP.drill,SILKSCREEN_TOP_COLOR=DEFAULT_PCB_COLOR_MAP.silkscreen.top,SILKSCREEN_BOTTOM_COLOR=DEFAULT_PCB_COLOR_MAP.silkscreen.bottom,LAYER_NAME_TO_COLOR={...DEFAULT_PCB_COLOR_MAP.copper};SOLDER_PASTE_LAYER_NAME_TO_COLOR={bottom:"rgb(105, 105, 105)",top:"rgb(105, 105, 105)"};CHAR_WIDTH=1,CHAR_SPACING=.2,LINE_HEIGHT=1.4,FONT_SCALE=.53,maskIdCounter=0;OFFSET_THRESHOLD_MM=.05,TICK_SIZE_PX=4,LABEL_GAP_PX=8,LABEL_FONT_SIZE_PX=11,STROKE_WIDTH_PX=1,ANCHOR_MARKER_SIZE_PX=5,ANCHOR_MARKER_STROKE_WIDTH_PX=1.5,COMPONENT_ANCHOR_MARKER_RADIUS_PX=2,CONNECTOR_GROUP_GAP_PX=ANCHOR_MARKER_SIZE_PX+2,CONNECTOR_COMPONENT_GAP_PX=COMPONENT_ANCHOR_MARKER_RADIUS_PX+2,DIMENSION_ANCHOR_CLEARANCE_PX=ANCHOR_MARKER_SIZE_PX+TICK_SIZE_PX+6,COMPONENT_GAP_PX=15,COMPONENT_SIDE_GAP_PX=10,DISTANCE_MULTIPLIER=.2,MAX_OFFSET_PX=50;getElementPosition=(id2,circuitJson)=>{let pcbSmtpad=su2(circuitJson).pcb_smtpad.get(id2);if(pcbSmtpad&&"x"in pcbSmtpad&&"y"in pcbSmtpad)return{x:pcbSmtpad.x,y:pcbSmtpad.y};let pcbPlatedHole=su2(circuitJson).pcb_plated_hole.get(id2);return pcbPlatedHole&&"x"in pcbPlatedHole&&"y"in pcbPlatedHole?{x:pcbPlatedHole.x,y:pcbPlatedHole.y}:null},findNearestPointInNet=(sourcePoint,netId,connectivity,circuitJson)=>{let connectedIds=connectivity.getIdsConnectedToNet(netId),nearestPoint=null,minDistance=1/0;for(let id2 of connectedIds){let pos=getElementPosition(id2,circuitJson);if(pos){let dx3=sourcePoint.x-pos.x,dy3=sourcePoint.y-pos.y,distance62=Math.sqrt(dx3*dx3+dy3*dy3);distance62>0&&distance62<minDistance&&(minDistance=distance62,nearestPoint=pos)}}return nearestPoint};KEEPOUT_PATTERN_ID="pcb-keepout-pattern",KEEPOUT_PATTERN_SIZE=20,KEEPOUT_LINE_SPACING=5,KEEPOUT_BACKGROUND_COLOR="rgba(255, 107, 107, 0.2)";DEFAULT_GRID_LINE_COLOR="rgba(255, 255, 255, 0.5)",GRID_PATTERN_ID="pcb-grid-pattern";GROUP_COLOR_PALETTE=["rgba(100, 200, 255, 0.6)","rgba(255, 150, 100, 0.6)","rgba(100, 255, 150, 0.6)","rgba(200, 100, 255, 0.6)","rgba(255, 220, 100, 0.6)","rgba(255, 100, 200, 0.6)","rgba(100, 255, 255, 0.6)","rgba(180, 255, 100, 0.6)"],DEFAULT_STROKE_WIDTH=.1;package_default2={name:"circuit-to-svg",type:"module",version:"0.0.347",description:"Convert Circuit JSON to SVG",main:"dist/index.js",files:["dist"],scripts:{start:"cosmos",prepublish:"npm run build",build:"tsup-node ./lib/index.ts --format esm --dts --sourcemap --external tscircuit",format:"biome format . --write","format:check":"biome format .",cosmos:"cosmos","cosmos-export":"cosmos-export"},license:"ISC",devDependencies:{"@biomejs/biome":"^1.9.4","@tscircuit/alphabet":"^0.0.25","@types/bun":"^1.2.8","@types/debug":"^4.1.12","@vitejs/plugin-react":"5.0.0",biome:"^0.3.3","bun-match-svg":"^0.0.12","circuit-json":"^0.0.424",esbuild:"^0.20.2","performance-now":"^2.1.0",react:"19.1.0","react-cosmos":"7.0.0","react-cosmos-plugin-vite":"7.0.0","react-dom":"19.1.0",tscircuit:"^0.0.1564",tsup:"^8.0.2",typescript:"^5.4.5","vite-tsconfig-paths":"^5.0.1"},peerDependencies:{"@tscircuit/alphabet":"*"},dependencies:{"@types/node":"^22.5.5","bun-types":"^1.1.40","calculate-elbow":"0.0.12",debug:"^4.4.3","svg-path-commander":"^2.1.11",svgson:"^5.3.1","transformation-matrix":"^2.16.1"}},CIRCUIT_TO_SVG_VERSION=package_default2.version,TYPE_PRIORITY={pcb_background:0,pcb_boundary:1,pcb_panel:5,pcb_board:10,pcb_cutout:15,pcb_cutout_path:15,pcb_keepout:16,pcb_hole:18,pcb_plated_hole_drill:19,pcb_plated_hole:20,pcb_trace_soldermask:25,pcb_trace:30,pcb_smtpad:30,pcb_copper_pour:35,pcb_via:36,pcb_soldermask:40,pcb_soldermask_opening:25,pcb_solder_paste:45,pcb_silkscreen_text:50,pcb_silkscreen_path:50,pcb_silkscreen_rect:50,pcb_silkscreen_circle:50,pcb_silkscreen_line:50,pcb_silkscreen_oval:50,pcb_silkscreen_pill:50,pcb_component:60,pcb_fabrication_note_text:70,pcb_fabrication_note_path:70,pcb_fabrication_note_rect:70,pcb_fabrication_note_dimension:70,pcb_note_dimension:70,pcb_note_text:70,pcb_note_rect:70,pcb_note_path:70,pcb_note_line:70,pcb_trace_error:80,pcb_footprint_overlap_error:80,pcb_component_outside_board_error:80,pcb_via_trace_clearance_error:80,pcb_rats_nest:85},DEFAULT_TYPE_PRIORITY=100;getViewportBounds=({circuitJson,drawPaddingOutsideBoard,baseBounds,viewportOptions})=>{let padding=drawPaddingOutsideBoard?1:0,boundsMinX=drawPaddingOutsideBoard||!baseBounds.hasBoardBounds?baseBounds.minX:baseBounds.boardMinX,boundsMinY=drawPaddingOutsideBoard||!baseBounds.hasBoardBounds?baseBounds.minY:baseBounds.boardMinY,boundsMaxX=drawPaddingOutsideBoard||!baseBounds.hasBoardBounds?baseBounds.maxX:baseBounds.boardMaxX,boundsMaxY=drawPaddingOutsideBoard||!baseBounds.hasBoardBounds?baseBounds.maxY:baseBounds.boardMaxY,hasPanelBounds=!1,panelMinX=Number.POSITIVE_INFINITY,panelMinY=Number.POSITIVE_INFINITY,panelMaxX=Number.NEGATIVE_INFINITY,panelMaxY=Number.NEGATIVE_INFINITY,panelBoundsById=new Map,boardBoundsById=new Map;for(let elm of circuitJson)if(elm.type==="pcb_panel"){let panel=elm,panelBounds=rectBounds(panel.center,panel.width,panel.height);if(!panelBounds)continue;panelMinX=Math.min(panelMinX,panelBounds.minX),panelMinY=Math.min(panelMinY,panelBounds.minY),panelMaxX=Math.max(panelMaxX,panelBounds.maxX),panelMaxY=Math.max(panelMaxY,panelBounds.maxY),hasPanelBounds=!0,panel.pcb_panel_id&&panelBoundsById.set(panel.pcb_panel_id,panelBounds)}else if(elm.type==="pcb_board"){let board=elm,boardBounds=getOutlineBounds(board.outline)??rectBounds(board.center,board.width,board.height);boardBounds&&board.pcb_board_id&&boardBoundsById.set(board.pcb_board_id,boardBounds)}if(viewportOptions?.viewport){let{minX,minY,maxX,maxY}=viewportOptions.viewport;boundsMinX=minX,boundsMinY=minY,boundsMaxX=maxX,boundsMaxY=maxY,padding=0}else if(viewportOptions?.viewportTarget?.pcb_panel_id){let panelBounds=panelBoundsById.get(viewportOptions.viewportTarget.pcb_panel_id);if(!panelBounds)throw new Error(`Viewport target panel '${viewportOptions.viewportTarget.pcb_panel_id}' not found`);boundsMinX=panelBounds.minX,boundsMinY=panelBounds.minY,boundsMaxX=panelBounds.maxX,boundsMaxY=panelBounds.maxY,padding=0}else if(viewportOptions?.viewportTarget?.pcb_board_id){let boardBounds=boardBoundsById.get(viewportOptions.viewportTarget.pcb_board_id);if(!boardBounds)throw new Error(`Viewport target board '${viewportOptions.viewportTarget.pcb_board_id}' not found`);boundsMinX=boardBounds.minX,boundsMinY=boardBounds.minY,boundsMaxX=boardBounds.maxX,boundsMaxY=boardBounds.maxY,padding=0}else hasPanelBounds&&(boundsMinX=panelMinX,boundsMinY=panelMinY,boundsMaxX=panelMaxX,boundsMaxY=panelMaxY);return{boundsMinX,boundsMinY,boundsMaxX,boundsMaxY,padding}};circuitJsonToPcbSvg=convertCircuitJsonToPcbSvg,DEFAULT_BOARD_STYLE={fill:"none",stroke:"rgb(0,0,0)",strokeOpacity:"0.8",strokeWidthFactor:.2};fontSizeMap={pin_number:.15,negated_pin_number:.15*.8,reference_designator:.18,manufacturer_number:.18,net_label:.18,error:.05},getSchMmFontSize=(textType,fontSize)=>fontSize??fontSizeMap[textType],getSchScreenFontSize=(transform6,textType,fontSize)=>Math.abs(transform6.a)*getSchMmFontSize(textType,fontSize);HOLE_COLOR2="rgb(190, 190, 190)";PAD_COLOR="rgb(210, 210, 210)",HOLE_COLOR3="rgb(190, 190, 190)";PAD_COLOR2="rgb(210, 210, 210)";OBJECT_ORDER=["pcb_component","pcb_smtpad","pcb_hole","pcb_plated_hole","pcb_board"];BOARD_FILL_COLOR="rgb(26, 115, 143)",BOARD_STROKE_COLOR="rgba(0,0,0,0.9)";COMPONENT_FILL_COLOR="rgba(120, 120, 120, 0.6)",COMPONENT_LABEL_COLOR="rgba(255, 255, 255, 0.9)";HOLE_COLOR4="rgb(50, 50, 50)";PAD_COLOR3="rgb(218, 165, 32)",HOLE_COLOR5="rgb(40, 40, 40)";PAD_COLOR4="rgb(218, 165, 32)";LABEL_COLOR="rgb(255, 255, 255)",LABEL_BACKGROUND="rgb(0, 0, 0)",LINE_COLOR="rgba(0, 0, 0, 0.6)",PIN_NUMBER_BACKGROUND="rgb(200, 200, 200)",PIN_NUMBER_COLOR="rgb(0, 0, 0)";LABEL_RECT_HEIGHT_BASE_MM=1.6,FONT_HEIGHT_RATIO=11/21,CHAR_WIDTH_FACTOR=.6,STAGGER_OFFSET_MIN=.1,STAGGER_OFFSET_PER_PIN=.1,STAGGER_OFFSET_STEP=3,ALIGNED_OFFSET_MARGIN=.1,GROUP_SEPARATION_MM=.8;calculateLabelPositions=({left_labels,right_labels,transform:transform6,soup,board_bounds,svgWidth,svgHeight,styleScale})=>{let label_positions=new Map,shared_params={transform:transform6,soup,board_bounds};return calculateVerticalEdgeLabels("left",left_labels,{...shared_params,svgHeight,styleScale},label_positions),calculateVerticalEdgeLabels("right",right_labels,{...shared_params,svgHeight,styleScale},label_positions),label_positions};OBJECT_ORDER2=["pcb_board","pcb_smtpad","pcb_hole","pcb_plated_hole","pcb_component","pcb_port"];arialTextMetrics={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}},estimateTextWidth=text=>{if(!text)return 0;let totalWidth=0;for(let char of text){let metrics=arialTextMetrics[char];metrics?totalWidth+=metrics.width:totalWidth+=arialTextMetrics["?"].width}return totalWidth/27},getTableDimensions=(schematicTable,circuitJson)=>{if(schematicTable.column_widths&&schematicTable.column_widths.length>0&&schematicTable.row_heights&&schematicTable.row_heights.length>0){let unitToMm4=v4=>typeof v4=="number"?v4:v4.endsWith("mm")?parseFloat(v4):v4.endsWith("in")?parseFloat(v4)*25.4:parseFloat(v4);return{column_widths:schematicTable.column_widths.map(unitToMm4),row_heights:schematicTable.row_heights.map(unitToMm4)}}let cells=circuitJson.filter(elm=>elm.type==="schematic_table_cell"&&elm.schematic_table_id===schematicTable.schematic_table_id);if(cells.length===0)return{column_widths:[],row_heights:[]};let numColumns=cells.reduce((max,c4)=>Math.max(max,c4.end_column_index),-1)+1,numRows=cells.reduce((max,c4)=>Math.max(max,c4.end_row_index),-1)+1,{cell_padding=.2}=schematicTable,column_widths=new Array(numColumns).fill(0),row_heights=new Array(numRows).fill(0),cell_widths={},cell_heights={};for(let cell of cells){let fontSizeMm=getSchMmFontSize("reference_designator",cell.font_size),requiredWidth=estimateTextWidth(cell.text??"")*fontSizeMm+2*cell_padding,requiredHeight=fontSizeMm*1.2+2*cell_padding,key=`${cell.start_row_index}-${cell.start_column_index}`;cell_widths[key]=requiredWidth,cell_heights[key]=requiredHeight}for(let i3=0;i3<numRows;i3++)for(let j4=0;j4<numColumns;j4++){let key=`${i3}-${j4}`;cell_widths[key]&&cell_widths[key]>column_widths[j4]&&(column_widths[j4]=cell_widths[key]),cell_heights[key]&&cell_heights[key]>row_heights[i3]&&(row_heights[i3]=cell_heights[key])}for(let cell of cells){if(cell.start_column_index===cell.end_column_index&&cell.start_row_index===cell.end_row_index)continue;let key=`${cell.start_row_index}-${cell.start_column_index}`,requiredWidth=cell_widths[key],requiredHeight=cell_heights[key];if(requiredWidth===void 0||requiredHeight===void 0)continue;let currentWidth=0;for(let i3=cell.start_column_index;i3<=cell.end_column_index;i3++)currentWidth+=column_widths[i3];if(requiredWidth>currentWidth){let extraPerColumn=(requiredWidth-currentWidth)/(cell.end_column_index-cell.start_column_index+1);for(let i3=cell.start_column_index;i3<=cell.end_column_index;i3++)column_widths[i3]+=extraPerColumn}let currentHeight=0;for(let i3=cell.start_row_index;i3<=cell.end_row_index;i3++)currentHeight+=row_heights[i3];if(requiredHeight>currentHeight){let extraPerRow=(requiredHeight-currentHeight)/(cell.end_row_index-cell.start_row_index+1);for(let i3=cell.start_row_index;i3<=cell.end_row_index;i3++)row_heights[i3]+=extraPerRow}}return{column_widths,row_heights}},getUnitVectorFromOutsideToEdge=side=>{switch(side){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: ${side}`)},ARROW_POINT_WIDTH_FSR=.3,END_PADDING_FSR=.3,END_PADDING_EXTRA_PER_CHARACTER_FSR=.06,ninePointAnchorToTextAnchor={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"},ninePointAnchorToDominantBaseline={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"};getSchStrokeSize=transform6=>Math.abs(transform6.a)*.02,getAngularDifference=(angle1,angle2)=>{let a12=angle1<0?angle1+2*Math.PI:angle1,a22=angle2<0?angle2+2*Math.PI:angle2,diff=Math.abs(a12-a22);return diff>Math.PI&&(diff=2*Math.PI-diff),diff},matchSchPortsToSymbolPorts=({schPorts,symbol,schComponent})=>{let schPortAngles=schPorts.map(port=>{let dx3=port.center.x-schComponent.center.x,dy3=port.center.y-schComponent.center.y;return{port,angle:Math.atan2(dy3,dx3)}}),symbolPortAngles=symbol.ports.map(port=>{let dx3=port.x-symbol.center.x,dy3=port.y-symbol.center.y;return{port,angle:Math.atan2(dy3,dx3)}});schPortAngles.sort((a3,b3)=>a3.angle-b3.angle),symbolPortAngles.sort((a3,b3)=>a3.angle-b3.angle);let matches=[],usedSymbolPorts=new Set;for(let schPortAngle of schPortAngles){let bestMatch=null;for(let symbolPortAngle of symbolPortAngles){if(usedSymbolPorts.has(symbolPortAngle.port))continue;let angleDiff=getAngularDifference(schPortAngle.angle,symbolPortAngle.angle);(bestMatch===null||angleDiff<bestMatch.angleDiff)&&(bestMatch={symbolPort:symbolPortAngle.port,angleDiff})}bestMatch&&bestMatch.angleDiff<Math.PI/4&&(matches.push({schPort:schPortAngle.port,symbolPort:bestMatch.symbolPort}),usedSymbolPorts.add(bestMatch.symbolPort))}return matches};createSvgSchErrorText=({text,realCenter,realToScreenTransform})=>{let screenCenter=applyToPoint3(realToScreenTransform,realCenter);return{type:"element",name:"text",value:"",attributes:{x:screenCenter.x.toString(),y:screenCenter.y.toString(),fill:"red","text-anchor":"middle","dominant-baseline":"middle","font-family":"sans-serif","font-size":`${getSchScreenFontSize(realToScreenTransform,"error")}px`},children:[{type:"text",value:text,name:"",attributes:{},children:[]}]}},isSourcePortConnected=(circuitJson,sourcePortId)=>{for(let elm of circuitJson){if(elm.type!=="source_trace")continue;let trace=elm;if(Array.isArray(trace.connected_source_port_ids)&&trace.connected_source_port_ids.includes(sourcePortId))return!0}return!1},ninePointAnchorToTextAnchor2={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"},ninePointAnchorToDominantBaseline2={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"},createSvgObjectsFromSchematicComponentWithSymbol=({component:schComponent,transform:realToScreenTransform,circuitJson,colorMap:colorMap2})=>{let svgObjects=[],symbol=Vf[schComponent.symbol_name];if(!symbol)return[createSvgSchErrorText({text:`Symbol not found: ${schComponent.symbol_name}`,realCenter:schComponent.center,realToScreenTransform})];let schPorts=su2(circuitJson).schematic_port.list({schematic_component_id:schComponent.schematic_component_id}),srcComponent=su2(circuitJson).source_component.get(schComponent.source_component_id),schPortsWithSymbolPorts=matchSchPortsToSymbolPorts({schPorts,symbol,schComponent});if(!schPortsWithSymbolPorts[0])return[createSvgSchErrorText({text:`Could not match ports for symbol ${schComponent.symbol_name}`,realCenter:schComponent.center,realToScreenTransform})];let transformFromSymbolToReal=pointPairsToMatrix(schPortsWithSymbolPorts[1]?.symbolPort??symbol.center,schPortsWithSymbolPorts[1]?.schPort.center??schComponent.center,schPortsWithSymbolPorts[0].symbolPort,schPortsWithSymbolPorts[0].schPort.center),paths=symbol.primitives.filter(p4=>p4.type==="path"),texts=symbol.primitives.filter(p4=>p4.type==="text"),circles=symbol.primitives.filter(p4=>p4.type==="circle"),boxes=symbol.primitives.filter(p4=>p4.type==="box"),connectedSymbolPorts=new Set;for(let match2 of schPortsWithSymbolPorts)isSourcePortConnected(circuitJson,match2.schPort.source_port_id)&&connectedSymbolPorts.add(match2.symbolPort);let bounds={minX:Math.min(...paths.flatMap(p4=>p4.points.map(pt3=>pt3.x))),maxX:Math.max(...paths.flatMap(p4=>p4.points.map(pt3=>pt3.x))),minY:Math.min(...paths.flatMap(p4=>p4.points.map(pt3=>pt3.y))),maxY:Math.max(...paths.flatMap(p4=>p4.points.map(pt3=>pt3.y)))},[screenMinX,screenMinY]=applyToPoint3(compose3(realToScreenTransform,transformFromSymbolToReal),[bounds.minX,bounds.minY]),[screenMaxX,screenMaxY]=applyToPoint3(compose3(realToScreenTransform,transformFromSymbolToReal),[bounds.maxX,bounds.maxY]),rectHeight=Math.abs(screenMaxY-screenMinY),rectY=Math.min(screenMinY,screenMaxY),rectWidth=Math.abs(screenMaxX-screenMinX),rectX=Math.min(screenMinX,screenMaxX);svgObjects.push({name:"rect",type:"element",value:"",attributes:{class:"component-overlay",x:rectX.toString(),y:rectY.toString(),width:rectWidth.toString(),height:rectHeight.toString(),fill:"transparent"},children:[]});for(let path of paths){let{points,color,closed,fill}=path;svgObjects.push({type:"element",name:"path",attributes:{d:points.map((p4,i3)=>{let[x4,y4]=applyToPoint3(compose3(realToScreenTransform,transformFromSymbolToReal),[p4.x,p4.y]);return`${i3===0?"M":"L"} ${x4} ${y4}`}).join(" ")+(closed?" Z":""),stroke:colorMap2.schematic.component_outline,fill:"none","stroke-width":`${getSchStrokeSize(realToScreenTransform)}px`,"stroke-linecap":"round"},value:"",children:[]})}for(let text of texts){let screenTextPos=applyToPoint3(compose3(realToScreenTransform,transformFromSymbolToReal),text),textValue="",isReferenceText=text.text==="{REF}";isReferenceText?textValue=srcComponent?.display_name??srcComponent?.name??"":text.text==="{VAL}"&&(textValue=schComponent.symbol_display_value??"");let dominantBaseline=ninePointAnchorToDominantBaseline2[text.anchor];svgObjects.push({name:"text",type:"element",attributes:{x:screenTextPos.x.toString(),y:screenTextPos.y.toString(),...isReferenceText?{stroke:colorMap2.schematic.background,"stroke-width":`${getSchStrokeSize(realToScreenTransform)}px`,"paint-order":"stroke"}:{},fill:colorMap2.schematic.label_local,"font-family":"sans-serif","text-anchor":ninePointAnchorToTextAnchor2[text.anchor],"dominant-baseline":dominantBaseline,"font-size":`${getSchScreenFontSize(realToScreenTransform,"reference_designator")}px`},value:"",children:[{type:"text",value:textValue,name:"",attributes:{},children:[]}]})}for(let box2 of boxes){let screenBoxPos=applyToPoint3(compose3(realToScreenTransform,transformFromSymbolToReal),box2),symbolToScreenScale=compose3(realToScreenTransform,transformFromSymbolToReal).a;svgObjects.push({name:"rect",type:"element",attributes:{x:screenBoxPos.x.toString(),y:screenBoxPos.y.toString(),width:(box2.width*symbolToScreenScale).toString(),height:(box2.height*symbolToScreenScale).toString(),fill:"red"},value:"",children:[]})}for(let port of symbol.ports){if(connectedSymbolPorts.has(port))continue;let screenPortPos=applyToPoint3(compose3(realToScreenTransform,transformFromSymbolToReal),port);svgObjects.push({type:"element",name:"circle",attributes:{cx:screenPortPos.x.toString(),cy:screenPortPos.y.toString(),r:`${Math.abs(realToScreenTransform.a)*.02}px`,"stroke-width":`${getSchStrokeSize(realToScreenTransform)}px`,fill:"none",stroke:colorMap2.schematic.component_outline},value:"",children:[]})}for(let circle2 of circles){let screenCirclePos=applyToPoint3(compose3(realToScreenTransform,transformFromSymbolToReal),circle2),screenRadius=Math.abs(circle2.radius*realToScreenTransform.a);svgObjects.push({type:"element",name:"circle",attributes:{cx:screenCirclePos.x.toString(),cy:screenCirclePos.y.toString(),r:`${screenRadius}px`,"stroke-width":`${getSchStrokeSize(realToScreenTransform)}px`,fill:"none",stroke:colorMap2.schematic.component_outline},value:"",children:[]})}return svgObjects},PIN_CIRCLE_RADIUS_MM=.02,createArrow=(tip,angle,size3,color,strokeWidth)=>{let arrowAngle=Math.PI/6,p12={x:tip.x-size3*Math.cos(angle-arrowAngle),y:tip.y-size3*Math.sin(angle-arrowAngle)},p22={x:tip.x-size3*Math.cos(angle+arrowAngle),y:tip.y-size3*Math.sin(angle+arrowAngle)};return{name:"polygon",type:"element",attributes:{points:`${tip.x},${tip.y} ${p12.x},${p12.y} ${p22.x},${p22.y}`,fill:"white",stroke:color,"stroke-width":`${strokeWidth}px`},value:"",children:[]}},createSvgObjectsForSchPortBoxLine=({schPort,schComponent,transform:transform6,circuitJson})=>{let svgObjects=[],srcPort=su2(circuitJson).source_port.get(schPort.source_port_id),realEdgePos={x:schPort.center.x,y:schPort.center.y},realPinLineLength=schPort.distance_from_component_edge??.4;switch(schPort.side_of_component){case"left":realEdgePos.x+=realPinLineLength;break;case"right":realEdgePos.x-=realPinLineLength;break;case"top":realEdgePos.y-=realPinLineLength;break;case"bottom":realEdgePos.y+=realPinLineLength;break}let screenSchPortPos=applyToPoint3(transform6,schPort.center),screenRealEdgePos=applyToPoint3(transform6,realEdgePos),isConnected=isSourcePortConnected(circuitJson,schPort.source_port_id),is_drawn_with_inversion_circle=schPort.is_drawn_with_inversion_circle??!1,BUBBLE_RADIUS_MM=.06,realLineEnd={...schPort.center};if(!isConnected)switch(schPort.side_of_component){case"left":realLineEnd.x+=PIN_CIRCLE_RADIUS_MM;break;case"right":realLineEnd.x-=PIN_CIRCLE_RADIUS_MM;break;case"top":realLineEnd.y-=PIN_CIRCLE_RADIUS_MM;break;case"bottom":realLineEnd.y+=PIN_CIRCLE_RADIUS_MM;break}let screenLineEnd=applyToPoint3(transform6,realLineEnd);if(is_drawn_with_inversion_circle){let bubbleRadiusPx=Math.abs(transform6.a)*BUBBLE_RADIUS_MM,bubbleCenter={...screenRealEdgePos};switch(schPort.side_of_component){case"left":bubbleCenter.x-=bubbleRadiusPx,screenRealEdgePos.x-=bubbleRadiusPx*2;break;case"right":bubbleCenter.x+=bubbleRadiusPx,screenRealEdgePos.x+=bubbleRadiusPx*2;break;case"top":bubbleCenter.y-=bubbleRadiusPx,screenRealEdgePos.y-=bubbleRadiusPx*2;break;case"bottom":bubbleCenter.y+=bubbleRadiusPx,screenRealEdgePos.y+=bubbleRadiusPx*2;break}svgObjects.push({name:"circle",type:"element",attributes:{class:"component-pin",cx:bubbleCenter.x.toString(),cy:bubbleCenter.y.toString(),r:bubbleRadiusPx.toString(),fill:"white",stroke:colorMap.schematic.component_outline,"stroke-width":`${getSchStrokeSize(transform6)}px`},value:"",children:[]})}svgObjects.push({name:"line",type:"element",attributes:{class:"component-pin",x1:screenRealEdgePos.x.toString(),y1:screenRealEdgePos.y.toString(),x2:screenLineEnd.x.toString(),y2:screenLineEnd.y.toString(),"stroke-width":`${getSchStrokeSize(transform6)}px`},value:"",children:[]});let pinRadiusPx=Math.abs(transform6.a)*PIN_CIRCLE_RADIUS_MM,pinChildren=[];isConnected||pinChildren.push({name:"circle",type:"element",attributes:{class:"component-pin",cx:screenSchPortPos.x.toString(),cy:screenSchPortPos.y.toString(),r:pinRadiusPx.toString(),"stroke-width":`${getSchStrokeSize(transform6)}px`},value:"",children:[]}),pinChildren.push({name:"rect",type:"element",attributes:{x:(screenSchPortPos.x-pinRadiusPx).toString(),y:(screenSchPortPos.y-pinRadiusPx).toString(),width:(pinRadiusPx*2).toString(),height:(pinRadiusPx*2).toString(),opacity:"0"},value:"",children:[]}),svgObjects.push({name:"g",type:"element",value:"",attributes:{"data-schematic-port-id":schPort.source_port_id},children:pinChildren});let{has_input_arrow,has_output_arrow}=schPort;if((has_input_arrow||has_output_arrow)&&schPort.side_of_component){let arrowSize=Math.abs(transform6.a)*.1,arrowColor=colorMap.schematic.component_outline,arrowAxialLength=arrowSize*Math.cos(Math.PI/6),strokeWidth=getSchStrokeSize(transform6)/3,inputAngleRads=0,outputAngleRads=0;schPort.side_of_component==="left"?(inputAngleRads=0,outputAngleRads=Math.PI):schPort.side_of_component==="right"?(inputAngleRads=Math.PI,outputAngleRads=0):schPort.side_of_component==="top"?(inputAngleRads=Math.PI/2,outputAngleRads=-Math.PI/2):schPort.side_of_component==="bottom"&&(inputAngleRads=-Math.PI/2,outputAngleRads=Math.PI/2);let both=has_input_arrow&&has_output_arrow,inputArrowTip={...screenRealEdgePos},outputArrowBase={...screenRealEdgePos};if(both){let offset=arrowAxialLength;schPort.side_of_component==="left"?outputArrowBase.x-=offset:schPort.side_of_component==="right"?outputArrowBase.x+=offset:schPort.side_of_component==="top"?outputArrowBase.y-=offset:schPort.side_of_component==="bottom"&&(outputArrowBase.y+=offset)}if(has_input_arrow&&svgObjects.push(createArrow(inputArrowTip,inputAngleRads,arrowSize,arrowColor,strokeWidth)),has_output_arrow){let outputArrowTip={x:outputArrowBase.x+arrowSize*Math.cos(outputAngleRads),y:outputArrowBase.y+arrowSize*Math.sin(outputAngleRads)};svgObjects.push(createArrow(outputArrowTip,outputAngleRads,arrowSize,arrowColor,strokeWidth))}}return svgObjects},createSvgObjectsForSchPortPinNumberText=params=>{let svgObjects=[],{schPort,schComponent,transform:transform6,circuitJson}=params,realPinNumberPos={x:schPort.center.x,y:schPort.center.y};if(!schPort.side_of_component)return[];let vecToEdge=getUnitVectorFromOutsideToEdge(schPort.side_of_component),realPinEdgeDistance=schPort.distance_from_component_edge??.4;realPinNumberPos.x+=vecToEdge.x*realPinEdgeDistance/2,realPinNumberPos.y+=vecToEdge.y*realPinEdgeDistance/2,schPort.side_of_component==="top"||schPort.side_of_component==="bottom"?realPinNumberPos.x-=.02:realPinNumberPos.y+=.02;let screenPinNumberTextPos=applyToPoint3(transform6,realPinNumberPos);return svgObjects.push({name:"text",type:"element",attributes:{class:"pin-number",x:screenPinNumberTextPos.x.toString(),y:screenPinNumberTextPos.y.toString(),style:"font-family: sans-serif;",fill:colorMap.schematic.pin_number,"text-anchor":"middle","dominant-baseline":"auto","font-size":`${getSchScreenFontSize(transform6,"pin_number")}px`,transform:schPort.side_of_component==="top"||schPort.side_of_component==="bottom"?`rotate(-90 ${screenPinNumberTextPos.x} ${screenPinNumberTextPos.y})`:""},children:[{type:"text",value:schPort.pin_number?.toString()||"",name:"",attributes:{},children:[]}],value:""}),svgObjects},LABEL_DIST_FROM_EDGE_MM=.1,createSvgObjectsForSchPortPinLabel=params=>{let svgObjects=[],{schPort,schComponent,transform:transform6,circuitJson}=params,realPinNumberPos={x:schPort.center.x,y:schPort.center.y};if(!schPort.side_of_component)return[];let vecToEdge=getUnitVectorFromOutsideToEdge(schPort.side_of_component),realPinEdgeDistance=schPort.distance_from_component_edge??.4;realPinNumberPos.x+=vecToEdge.x*(realPinEdgeDistance+LABEL_DIST_FROM_EDGE_MM),realPinNumberPos.y+=vecToEdge.y*(realPinEdgeDistance+LABEL_DIST_FROM_EDGE_MM);let screenPinNumberTextPos=applyToPoint3(transform6,realPinNumberPos),label=schPort.display_pin_label??schComponent.port_labels?.[`${schPort.pin_number}`];if(!label)return[];let isNegated=label.startsWith("N_"),displayLabel=isNegated?label.slice(2):label,is_drawn_with_inversion_circle=schPort.is_drawn_with_inversion_circle??!1,fontSizePx=getSchScreenFontSize(transform6,isNegated||is_drawn_with_inversion_circle?"negated_pin_number":"pin_number");return svgObjects.push({name:"text",type:"element",attributes:{class:"pin-number",x:screenPinNumberTextPos.x.toString(),y:screenPinNumberTextPos.y.toString(),style:`font-family: sans-serif;${isNegated?" text-decoration: overline;":""}`,fill:colorMap.schematic.pin_number,"text-anchor":schPort.side_of_component==="left"||schPort.side_of_component==="bottom"?"start":"end","dominant-baseline":"middle","font-size":`${fontSizePx}px`,transform:schPort.side_of_component==="top"||schPort.side_of_component==="bottom"?`rotate(-90 ${screenPinNumberTextPos.x} ${screenPinNumberTextPos.y})`:""},children:[{type:"text",value:displayLabel||"",name:"",attributes:{},children:[]}],value:""}),svgObjects},createSvgObjectsFromSchPortOnBox=params=>{let svgObjects=[],{schPort,schComponent,transform:transform6,circuitJson}=params;return svgObjects.push(...createSvgObjectsForSchPortBoxLine(params)),svgObjects.push(...createSvgObjectsForSchPortPinNumberText(params)),svgObjects.push(...createSvgObjectsForSchPortPinLabel(params)),svgObjects},createSvgSchText=({elm,transform:transform6,colorMap:colorMap2})=>{let center2=applyToPoint3(transform6,elm.position),textAnchorMap={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"},dominantBaselineMap={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"},lines=elm.text.split(`
|
|
290
|
+
`;return svgElement("style",{},[textNode(content)])}function createBackgroundRect(width,height){return svgElement("rect",{class:"background",x:"0",y:"0",width:formatNumber(width),height:formatNumber(height)})}function createDefsNode(clipPathId,plotWidth,plotHeight){return svgElement("defs",{},[svgElement("clipPath",{id:clipPathId},[svgElement("rect",{x:formatNumber(MARGIN.left),y:formatNumber(MARGIN.top),width:formatNumber(plotWidth),height:formatNumber(plotHeight)})])])}function createPlotBackground(plotWidth,plotHeight){return svgElement("rect",{class:"plot-background",x:formatNumber(MARGIN.left),y:formatNumber(MARGIN.top),width:formatNumber(plotWidth),height:formatNumber(plotHeight)})}function createGridLines({timeAxis,voltageAxis,scaleX,scaleY,plotWidth,plotHeight}){let top=MARGIN.top,bottom=MARGIN.top+plotHeight,left=MARGIN.left,right=MARGIN.left+plotWidth,children=[];for(let tick of timeAxis.ticks){let x4=formatNumber(scaleX(tick));children.push(svgElement("line",{class:"grid-line grid-line-x",x1:x4,y1:formatNumber(top),x2:x4,y2:formatNumber(bottom)}))}for(let tick of voltageAxis.ticks){let y4=formatNumber(scaleY(tick));children.push(svgElement("line",{class:"grid-line grid-line-y",x1:formatNumber(left),y1:y4,x2:formatNumber(right),y2:y4}))}return svgElement("g",{class:"grid"},children)}function createAxes({timeAxis,voltageAxis,scaleX,scaleY,plotWidth,plotHeight}){let bottom=MARGIN.top+plotHeight,left=MARGIN.left,right=MARGIN.left+plotWidth,children=[svgElement("line",{class:"axis axis-x",x1:formatNumber(left),y1:formatNumber(bottom),x2:formatNumber(right),y2:formatNumber(bottom)}),svgElement("line",{class:"axis axis-y",x1:formatNumber(left),y1:formatNumber(MARGIN.top),x2:formatNumber(left),y2:formatNumber(bottom)})];for(let tick of timeAxis.ticks){let x4=formatNumber(scaleX(tick));children.push(svgElement("line",{class:"axis-tick axis-tick-x",x1:x4,y1:formatNumber(bottom),x2:x4,y2:formatNumber(bottom+6)})),children.push(svgElement("text",{class:"axis-label axis-label-x",x:x4,y:formatNumber(bottom+22),"text-anchor":"middle"},[textNode(formatTickLabel(tick,timeAxis.ticks))]))}for(let tick of voltageAxis.ticks){let y4=formatNumber(scaleY(tick));children.push(svgElement("line",{class:"axis-tick axis-tick-y",x1:formatNumber(left-6),y1:y4,x2:formatNumber(left),y2:y4})),children.push(svgElement("text",{class:"axis-label axis-label-y",x:formatNumber(left-10),y:y4,"text-anchor":"end","dominant-baseline":"middle"},[textNode(formatTickLabel(tick,voltageAxis.ticks))]))}return children.push(svgElement("text",{class:"axis-title axis-title-x",x:formatNumber(left+plotWidth/2),y:formatNumber(bottom+48),"text-anchor":"middle"},[textNode("Time (ms)")]),svgElement("text",{class:"axis-title axis-title-y",x:formatNumber(left-64),y:formatNumber(MARGIN.top+plotHeight/2),transform:`rotate(-90 ${formatNumber(left-64)} ${formatNumber(MARGIN.top+plotHeight/2)})`,"text-anchor":"middle"},[textNode("Voltage (V)")])),svgElement("g",{class:"axes"},children)}function createLegend(graphs,width){let currentY=MARGIN.top,children=graphs.map(entry=>{let x4=width-MARGIN.right+10,lines=wrapLegendText(entry.label),legendItem=createLegendItem(entry,x4,currentY,lines),itemHeight=lines.length*LEGEND_LINE_HEIGHT;return currentY+=Math.max(itemHeight,LEGEND_MIN_SPACING),legendItem});return svgElement("g",{class:"legend"},children)}function wrapLegendText(label){let parts=label.split("_");if(parts.length<=1)return[label];let lines=[],currentLine=parts[0]??"";for(let i3=1;i3<parts.length;i3++){let part=parts[i3]??"",testLine=currentLine+"_"+part;testLine.length>MAX_LEGEND_LINE_LENGTH?(lines.push(currentLine),currentLine=part):currentLine=testLine}return currentLine&&lines.push(currentLine),lines}function createLegendItem(entry,x4,y4,lines){let textChildren=lines.map((line2,index)=>svgElement("tspan",{x:"20",dy:index===0?"0":String(LEGEND_LINE_HEIGHT)},[textNode(line2)]));return svgElement("g",{class:"legend-item",transform:`translate(${formatNumber(x4)} ${formatNumber(y4)})`},[svgElement("line",{class:"legend-line",x1:"0",y1:"0",x2:"16",y2:"0",stroke:entry.color}),svgElement("text",{class:"legend-label",x:"20",y:"0","dominant-baseline":"middle"},textChildren)])}function createDataGroup(graphs,clipPathId,scaleX,scaleY){let DASH_PATTERN=[4,8],dashArrayString=DASH_PATTERN.map(value=>formatNumber(value)).join(" "),dashOffsetStep=DASH_PATTERN.reduce((sum,value)=>sum+value,0)/3,processedGraphs=[];graphs.forEach((entry,graphIndex)=>{if(entry.points.length===0)return;let commands=[];entry.points.forEach((point7,index)=>{let x4=formatNumber(scaleX(point7.timeMs)),y4=formatNumber(scaleY(point7.voltage));commands.push(`${index===0?"M":"L"} ${x4} ${y4}`)});let baseAttributes={class:"simulation-line",d:commands.join(" "),stroke:entry.color,"clip-path":`url(#${clipPathId})`,"data-simulation-transient-voltage-graph-id":entry.graph.simulation_transient_voltage_graph_id};entry.graph.source_component_id&&(baseAttributes["data-source-component-id"]=entry.graph.source_component_id),entry.graph.subcircuit_connectivity_map_key&&(baseAttributes["data-subcircuit-connectivity-map-key"]=entry.graph.subcircuit_connectivity_map_key);let pointElements2=entry.points.map(point7=>{let cx3=formatNumber(scaleX(point7.timeMs)),cy3=formatNumber(scaleY(point7.voltage));return svgElement("circle",{class:"simulation-point",cx:cx3,cy:cy3,r:"2.5",fill:entry.color,"clip-path":`url(#${clipPathId})`})});processedGraphs.push({entry,graphIndex,pathAttributes:baseAttributes,pointElements:pointElements2})});let lineElements=[];for(let cycle=0;cycle<3;cycle++)processedGraphs.forEach(graphInfo=>{let offsetIndex=(graphInfo.graphIndex+cycle)%3,dashOffset=formatNumber(offsetIndex*dashOffsetStep);lineElements.push(svgElement("path",{...graphInfo.pathAttributes,"stroke-dasharray":dashArrayString,"stroke-dashoffset":dashOffset}))});let pointElements=processedGraphs.flatMap(graphInfo=>graphInfo.pointElements);return svgElement("g",{class:"data-series"},[...lineElements,...pointElements])}function createTitleNode(experiment,width){return experiment?.name?svgElement("text",{class:"chart-title",x:formatNumber(width/2),y:formatNumber(MARGIN.top-40),"text-anchor":"middle"},[textNode(experiment.name)]):null}function createClipPathId(simulationExperimentId){return`simulation-graph-${simulationExperimentId.replace(/[^a-zA-Z0-9_-]+/g,"-")}`}function formatNumber(value){if(!Number.isFinite(value))return"0";let rounded=Number.parseFloat(value.toFixed(6));return Number.isInteger(rounded),rounded.toString()}function formatTickLabel(value,ticks){if(ticks.length<=1)return formatNumber(value);let span=ticks[ticks.length-1]-ticks[0];if(!Number.isFinite(span)||span===0)return formatNumber(value);let precision=span>=100?0:span>=10?1:span>=1?2:3,factor=Math.pow(10,precision);return(Math.round(value*factor)/factor).toFixed(precision).replace(/\.0+$/,"").replace(/(\.\d*?)0+$/,"$1").replace(/\.$/,"")}function svgElement(name,attributes2,children=[]){return{name,type:"element",value:"",attributes:attributes2,children}}function textNode(value){return{name:"",type:"text",value,attributes:{},children:[]}}function convertCircuitJsonToSchematicSimulationSvg({circuitJson,simulation_experiment_id,simulation_transient_voltage_graph_ids,width=DEFAULT_WIDTH2,height=DEFAULT_HEIGHT2,schematicHeightRatio=DEFAULT_SCHEMATIC_RATIO,schematicOptions,includeVersion,graphAboveSchematic=!1,showErrorsInTextOverlay}){let schematicElements=circuitJson.filter(element=>!isSimulationExperiment(element)&&!isSimulationTransientVoltageGraph(element)),clampedRatio=clamp01(schematicHeightRatio),rawSchematicHeight=Math.max(1,height*clampedRatio),rawSimulationHeight=Math.max(1,height-rawSchematicHeight),totalRawHeight=rawSchematicHeight+rawSimulationHeight,scale10=totalRawHeight===0?1:height/totalRawHeight,schematicHeight=rawSchematicHeight*scale10,simulationHeight=rawSimulationHeight*scale10,schematicSvg=convertCircuitJsonToSchematicSvg(schematicElements,{...schematicOptions,width,height:schematicHeight,includeVersion:!1,showErrorsInTextOverlay}),simulationSvg=convertCircuitJsonToSimulationGraphSvg({circuitJson,simulation_experiment_id,simulation_transient_voltage_graph_ids,width,height:simulationHeight,includeVersion:!1}),schematicNode=ensureElementNode((0,import_svgson10.parseSync)(schematicSvg)),simulationNode=ensureElementNode((0,import_svgson10.parseSync)(simulationSvg)),combinedChildren=[];graphAboveSchematic?(combinedChildren.push(translateNestedSvg(simulationNode,0,0,width,simulationHeight)),combinedChildren.push(translateNestedSvg(schematicNode,0,simulationHeight,width,schematicHeight))):(combinedChildren.push(translateNestedSvg(schematicNode,0,0,width,schematicHeight)),combinedChildren.push(translateNestedSvg(simulationNode,0,schematicHeight,width,simulationHeight)));let softwareUsedString=getSoftwareUsedString(schematicElements),svgObject={name:"svg",type:"element",value:"",attributes:{xmlns:"http://www.w3.org/2000/svg",width:formatNumber2(width),height:formatNumber2(height),viewBox:`0 0 ${formatNumber2(width)} ${formatNumber2(height)}`,"data-simulation-experiment-id":simulation_experiment_id,...softwareUsedString&&{"data-software-used-string":softwareUsedString},...includeVersion&&{"data-circuit-to-svg-version":CIRCUIT_TO_SVG_VERSION}},children:combinedChildren};return(0,import_svgson10.stringify)(svgObject)}function translateNestedSvg(node,x4,y4,width,height){let clone=cloneSvgObject(node);return clone.attributes={...clone.attributes,x:formatNumber2(x4),y:formatNumber2(y4),width:formatNumber2(width),height:formatNumber2(height)},delete clone.attributes.xmlns,clone}function ensureElementNode(node){if(node.type!=="element")throw new Error("Expected SVG root element to be of type 'element'");return node}function cloneSvgObject(node){return{...node,attributes:{...node.attributes??{}},children:node.children?.map(cloneSvgObject)??[]}}function clamp01(value){return Number.isFinite(value)?value<=0?0:value>=1?1:value:DEFAULT_SCHEMATIC_RATIO}function formatNumber2(value){if(!Number.isFinite(value))return"0";let rounded=Number.parseFloat(value.toFixed(6));return Number.isInteger(rounded),rounded.toString()}function createSvgObjectsFromSolderPaste(solderPaste,ctx){let{transform:transform6,layer:layerFilter}=ctx;if(layerFilter&&solderPaste.layer!==layerFilter)return[];let[x4,y4]=applyToPoint3(transform6,[solderPaste.x,solderPaste.y]);if(solderPaste.shape==="rect"||solderPaste.shape==="rotated_rect"){let width=solderPaste.width*Math.abs(transform6.a),height=solderPaste.height*Math.abs(transform6.d);return solderPaste.shape==="rotated_rect"&&solderPaste.ccw_rotation?[{name:"rect",type:"element",attributes:{class:"pcb-solder-paste",fill:solderPasteLayerNameToColor(solderPaste.layer),x:(-width/2).toString(),y:(-height/2).toString(),width:width.toString(),height:height.toString(),transform:`translate(${x4} ${y4}) rotate(${-solderPaste.ccw_rotation})`,"data-type":"pcb_solder_paste","data-pcb-layer":solderPaste.layer}}]:[{name:"rect",type:"element",attributes:{class:"pcb-solder-paste",fill:solderPasteLayerNameToColor(solderPaste.layer),x:(x4-width/2).toString(),y:(y4-height/2).toString(),width:width.toString(),height:height.toString(),"data-type":"pcb_solder_paste","data-pcb-layer":solderPaste.layer}}]}if(solderPaste.shape==="pill"){let width=solderPaste.width*Math.abs(transform6.a),height=solderPaste.height*Math.abs(transform6.d),radius=solderPaste.radius*Math.abs(transform6.a);return[{name:"rect",type:"element",attributes:{class:"pcb-solder-paste",fill:solderPasteLayerNameToColor(solderPaste.layer),x:(x4-width/2).toString(),y:(y4-height/2).toString(),width:width.toString(),height:height.toString(),rx:radius.toString(),"data-type":"pcb_solder_paste","data-pcb-layer":solderPaste.layer}}]}if(solderPaste.shape==="circle"){let radius=solderPaste.radius*Math.abs(transform6.a);return[{name:"circle",type:"element",attributes:{class:"pcb-solder-paste",fill:solderPasteLayerNameToColor(solderPaste.layer),cx:x4.toString(),cy:y4.toString(),r:radius.toString(),"data-type":"pcb_solder_paste","data-pcb-layer":solderPaste.layer}}]}}function convertCircuitJsonToSolderPasteMask(circuitJson,options){let minX=Number.POSITIVE_INFINITY,minY=Number.POSITIVE_INFINITY,maxX=Number.NEGATIVE_INFINITY,maxY=Number.NEGATIVE_INFINITY,filteredCircuitJson=circuitJson.filter(elm=>elm.type==="pcb_board"||elm.type==="pcb_panel"||elm.type==="pcb_solder_paste"&&elm.layer===options.layer);for(let item of filteredCircuitJson)if(item.type==="pcb_board")item.outline&&Array.isArray(item.outline)&&item.outline.length>=3?updateBoundsToIncludeOutline(item.outline):"center"in item&&"width"in item&&"height"in item&&updateBounds(item.center,item.width,item.height);else if(item.type==="pcb_panel"){let panel=item,width=distance.parse(panel.width),height=distance.parse(panel.height);if(width!==void 0&&height!==void 0){let center2=panel.center??{x:width/2,y:height/2};updateBounds(center2,width,height)}}else item.type==="pcb_solder_paste"&&"x"in item&&"y"in item&&updateBounds({x:item.x,y:item.y},0,0);let padding=1,circuitWidth=maxX-minX+2*padding,circuitHeight=maxY-minY+2*padding,svgWidth=options.width??800,svgHeight=options.height??600,scaleX=svgWidth/circuitWidth,scaleY=svgHeight/circuitHeight,scaleFactor=Math.min(scaleX,scaleY),offsetX=(svgWidth-circuitWidth*scaleFactor)/2,offsetY=(svgHeight-circuitHeight*scaleFactor)/2,transform6=compose3(translate3(offsetX-minX*scaleFactor+padding*scaleFactor,svgHeight-offsetY+minY*scaleFactor-padding*scaleFactor),scale3(scaleFactor,-scaleFactor)),ctx={transform:transform6,layer:options.layer,colorMap:DEFAULT_PCB_COLOR_MAP},svgObjects=filteredCircuitJson.sort((a3,b3)=>(OBJECT_ORDER3.indexOf(b3.type)??9999)-(OBJECT_ORDER3.indexOf(a3.type)??9999)).flatMap(item=>createSvgObjects4({elm:item,ctx})),softwareUsedString=getSoftwareUsedString(circuitJson),version2=CIRCUIT_TO_SVG_VERSION,children=[{name:"style",type:"element",children:[{type:"text",value:""}]},{name:"rect",type:"element",attributes:{class:"boundary",x:"0",y:"0",fill:"#000",width:svgWidth.toString(),height:svgHeight.toString()}},createSvgObjectFromPcbBoundary2(transform6,minX,minY,maxX,maxY),...svgObjects].filter(child=>child!==null);if(options?.showErrorsInTextOverlay){let errorOverlay=createErrorTextOverlay(circuitJson);errorOverlay&&children.push(errorOverlay)}let svgObject={name:"svg",type:"element",attributes:{xmlns:"http://www.w3.org/2000/svg",width:svgWidth.toString(),height:svgHeight.toString(),...softwareUsedString&&{"data-software-used-string":softwareUsedString},...options.includeVersion&&{"data-circuit-to-svg-version":version2}},value:"",children};try{return(0,import_svgson12.stringify)(svgObject)}catch(error2){throw console.error("Error stringifying SVG object:",error2),error2}function updateBounds(center2,width,height){let halfWidth=width/2,halfHeight=height/2;minX=Math.min(minX,center2.x-halfWidth),minY=Math.min(minY,center2.y-halfHeight),maxX=Math.max(maxX,center2.x+halfWidth),maxY=Math.max(maxY,center2.y+halfHeight)}function updateBoundsToIncludeOutline(outline){for(let point7 of outline)minX=Math.min(minX,point7.x),minY=Math.min(minY,point7.y),maxX=Math.max(maxX,point7.x),maxY=Math.max(maxY,point7.y)}}function createSvgObjects4({elm,ctx}){let{transform:transform6}=ctx;switch(elm.type){case"pcb_board":return createSvgObjectsFromPcbBoard(elm,ctx);case"pcb_solder_paste":return createSvgObjectsFromSolderPaste(elm,ctx);default:return[]}}function createSvgObjectFromPcbBoundary2(transform6,minX,minY,maxX,maxY){let[x12,y12]=applyToPoint3(transform6,[minX,minY]),[x22,y22]=applyToPoint3(transform6,[maxX,maxY]),width=Math.abs(x22-x12),height=Math.abs(y22-y12),x4=Math.min(x12,x22),y4=Math.min(y12,y22);return{name:"rect",type:"element",value:"",children:[],attributes:{class:"pcb-boundary",fill:"none",stroke:"#fff","stroke-width":"0.3",x:x4.toString(),y:y4.toString(),width:width.toString(),height:height.toString()}}}var import_svgson2,import_debug5,import_svgson3,import_svgson4,import_svgson5,import_svgson6,import_svgson7,import_svgson8,import_svgson9,import_svgson10,import_svgson11,import_svgson12,debug5,debugPcb,debugSch,DEFAULT_OVERLAY_STROKE_COLOR,DEFAULT_OVERLAY_FILL_COLOR,TEXT_OFFSET_MULTIPLIER,CHARACTER_WIDTH_MULTIPLIER,TEXT_INTERSECTION_PADDING_MULTIPLIER,colorMap,DEFAULT_OVERLAY_COLOR,DEFAULT_OVERLAY_COLOR2,DEFAULT_FILL_COLOR,DEFAULT_OVERLAY_COLOR3,DEFAULT_OVERLAY_COLOR4,alphabetBounds,INTER_CHAR_SPACING_RATIO,LINE_HEIGHT_MULTIPLIER,silkscreenMaskIdCounter,DEFAULT_PCB_COLOR_MAP,HOLE_COLOR,SILKSCREEN_TOP_COLOR,SILKSCREEN_BOTTOM_COLOR,LAYER_NAME_TO_COLOR,SOLDER_PASTE_LAYER_NAME_TO_COLOR,CHAR_WIDTH,CHAR_SPACING,LINE_HEIGHT,FONT_SCALE,maskIdCounter,OFFSET_THRESHOLD_MM,TICK_SIZE_PX,LABEL_GAP_PX,LABEL_FONT_SIZE_PX,STROKE_WIDTH_PX,ANCHOR_MARKER_SIZE_PX,ANCHOR_MARKER_STROKE_WIDTH_PX,COMPONENT_ANCHOR_MARKER_RADIUS_PX,CONNECTOR_GROUP_GAP_PX,CONNECTOR_COMPONENT_GAP_PX,DIMENSION_ANCHOR_CLEARANCE_PX,COMPONENT_GAP_PX,COMPONENT_SIDE_GAP_PX,DISTANCE_MULTIPLIER,MAX_OFFSET_PX,getElementPosition,findNearestPointInNet,KEEPOUT_PATTERN_ID,KEEPOUT_PATTERN_SIZE,KEEPOUT_LINE_SPACING,KEEPOUT_BACKGROUND_COLOR,DEFAULT_GRID_LINE_COLOR,GRID_PATTERN_ID,GROUP_COLOR_PALETTE,DEFAULT_STROKE_WIDTH,package_default2,CIRCUIT_TO_SVG_VERSION,TYPE_PRIORITY,DEFAULT_TYPE_PRIORITY,getViewportBounds,circuitJsonToPcbSvg,DEFAULT_BOARD_STYLE,fontSizeMap,getSchMmFontSize,getSchScreenFontSize,HOLE_COLOR2,PAD_COLOR,HOLE_COLOR3,PAD_COLOR2,OBJECT_ORDER,BOARD_FILL_COLOR,BOARD_STROKE_COLOR,COMPONENT_FILL_COLOR,COMPONENT_LABEL_COLOR,HOLE_COLOR4,PAD_COLOR3,HOLE_COLOR5,PAD_COLOR4,LABEL_COLOR,LABEL_BACKGROUND,LINE_COLOR,PIN_NUMBER_BACKGROUND,PIN_NUMBER_COLOR,LABEL_RECT_HEIGHT_BASE_MM,FONT_HEIGHT_RATIO,CHAR_WIDTH_FACTOR,STAGGER_OFFSET_MIN,STAGGER_OFFSET_PER_PIN,STAGGER_OFFSET_STEP,ALIGNED_OFFSET_MARGIN,GROUP_SEPARATION_MM,calculateLabelPositions,OBJECT_ORDER2,arialTextMetrics,estimateTextWidth,getTableDimensions,getUnitVectorFromOutsideToEdge,ARROW_POINT_WIDTH_FSR,END_PADDING_FSR,END_PADDING_EXTRA_PER_CHARACTER_FSR,ninePointAnchorToTextAnchor,ninePointAnchorToDominantBaseline,getSchStrokeSize,getAngularDifference,matchSchPortsToSymbolPorts,createSvgSchErrorText,isSourcePortConnected,ninePointAnchorToTextAnchor2,ninePointAnchorToDominantBaseline2,createSvgObjectsFromSchematicComponentWithSymbol,PIN_CIRCLE_RADIUS_MM,createArrow,createSvgObjectsForSchPortBoxLine,createSvgObjectsForSchPortPinNumberText,LABEL_DIST_FROM_EDGE_MM,createSvgObjectsForSchPortPinLabel,createSvgObjectsFromSchPortOnBox,createSvgSchText,createSvgObjectsFromSchematicComponentWithBox,createSvgObjectsFromSchematicComponentWithPrimitives,createSvgObjectsForSchNetLabelWithSymbol,createSvgObjectsForSchNetLabel,createSvgObjectsFromSchematicBox,createSvgObjectsFromSchematicTable,PIN_CIRCLE_RADIUS_MM2,createSvgObjectsForSchPortHover,createSvgObjectsForSchComponentPortHovers,PIN_CIRCLE_RADIUS_MM3,createSvgObjectsForSchPortIndicator,circuitJsonToSchematicSvg,DEFAULT_WIDTH,DEFAULT_HEIGHT,MARGIN,FALLBACK_LINE_COLOR,MAX_LEGEND_LINE_LENGTH,LEGEND_LINE_HEIGHT,LEGEND_MIN_SPACING,DEFAULT_WIDTH2,DEFAULT_HEIGHT2,DEFAULT_SCHEMATIC_RATIO,OBJECT_ORDER3,init_dist8=__esm({"node_modules/circuit-to-svg/dist/index.js"(){"use strict";init_dist();import_svgson2=__toESM(require_svgson_umd(),1);init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();import_debug5=__toESM(require_browser(),1);init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_dist7();init_dist7();init_src2();init_src2();init_dist();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_dist3();import_svgson3=__toESM(require_svgson_umd(),1);init_src2();init_dist6();init_dist3();init_dist6();init_src2();init_src2();init_src2();init_src2();init_src2();import_svgson4=__toESM(require_svgson_umd(),1);init_src2();init_src2();init_dist();init_dist();import_svgson5=__toESM(require_svgson_umd(),1);init_dist6();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();import_svgson6=__toESM(require_svgson_umd(),1);init_src2();init_src2();init_dist6();init_dist6();init_src2();init_src2();init_src2();init_src2();init_src2();init_dist5();init_src2();init_dist6();import_svgson7=__toESM(require_svgson_umd(),1);init_src2();init_src2();init_src2();init_src2();init_dist4();init_dist6();init_dist4();import_svgson8=__toESM(require_svgson_umd(),1);init_src2();init_src2();init_src2();init_dist6();init_dist4();import_svgson9=__toESM(require_svgson_umd(),1);init_src2();init_src2();init_dist6();init_src2();init_dist6();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_src2();init_dist4();init_src2();init_src2();init_dist6();init_src2();init_src2();import_svgson10=__toESM(require_svgson_umd(),1),import_svgson11=__toESM(require_svgson_umd(),1);init_dist();import_svgson12=__toESM(require_svgson_umd(),1);init_src2();init_src2();debug5=(0,import_debug5.default)("circuit-to-svg"),debugPcb=debug5.extend("pcb"),debugSch=debug5.extend("sch");DEFAULT_OVERLAY_STROKE_COLOR="rgba(255,255,255,0.5)",DEFAULT_OVERLAY_FILL_COLOR="rgba(255,255,255,0.2)";TEXT_OFFSET_MULTIPLIER=1.5,CHARACTER_WIDTH_MULTIPLIER=.6,TEXT_INTERSECTION_PADDING_MULTIPLIER=.3;colorMap={"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},simulation_palette:["#1f77b4","#d62728","#2ca02c","#ff7f0e","#9467bd","#17becf","#8c564b","#e377c2","#7f7f7f","#bcbd22"],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)"}};DEFAULT_OVERLAY_COLOR=colorMap.board.user_2;DEFAULT_OVERLAY_COLOR2=colorMap.board.user_2,DEFAULT_FILL_COLOR=colorMap.board.user_2;DEFAULT_OVERLAY_COLOR3=colorMap.board.user_2;DEFAULT_OVERLAY_COLOR4=colorMap.board.user_2;alphabetBounds=(()=>{let maxX=0,minY=1/0,maxY=-1/0;for(let segments of Object.values(lineAlphabet))for(let seg of segments)maxX=Math.max(maxX,seg.x1,seg.x2),minY=Math.min(minY,seg.y1,seg.y2),maxY=Math.max(maxY,seg.y1,seg.y2);return{width:maxX,height:maxY-minY}})(),INTER_CHAR_SPACING_RATIO=.2,LINE_HEIGHT_MULTIPLIER=1.1,silkscreenMaskIdCounter=0;DEFAULT_PCB_COLOR_MAP={copper:{top:"rgb(200, 52, 52)",inner1:"rgb(255, 140, 0)",inner2:"rgb(255, 215, 0)",inner3:"rgb(50, 205, 50)",inner4:"rgb(64, 224, 208)",inner5:"rgb(138, 43, 226)",inner6:"rgb(255, 105, 180)",bottom:"rgb(77, 127, 196)"},soldermaskWithCopperUnderneath:{top:"rgb(18, 82, 50)",bottom:"rgb(77, 127, 196)"},soldermask:{top:"rgb(12, 55, 33)",bottom:"rgb(12, 55, 33)"},soldermaskOverCopper:{top:"rgb(52, 135, 73)",bottom:"rgb(52, 135, 73)"},substrate:"rgb(201, 162, 110)",drill:"#FF26E2",silkscreen:{top:"#f2eda1",bottom:"#5da9e9"},boardOutline:"rgba(255, 255, 255, 0.5)",courtyard:{top:"#FF00FF",bottom:"rgb(38, 233, 255)"},keepout:"#FF6B6B",debugComponent:{fill:null,stroke:null}},HOLE_COLOR=DEFAULT_PCB_COLOR_MAP.drill,SILKSCREEN_TOP_COLOR=DEFAULT_PCB_COLOR_MAP.silkscreen.top,SILKSCREEN_BOTTOM_COLOR=DEFAULT_PCB_COLOR_MAP.silkscreen.bottom,LAYER_NAME_TO_COLOR={...DEFAULT_PCB_COLOR_MAP.copper};SOLDER_PASTE_LAYER_NAME_TO_COLOR={bottom:"rgb(105, 105, 105)",top:"rgb(105, 105, 105)"};CHAR_WIDTH=1,CHAR_SPACING=.2,LINE_HEIGHT=1.4,FONT_SCALE=.53,maskIdCounter=0;OFFSET_THRESHOLD_MM=.05,TICK_SIZE_PX=4,LABEL_GAP_PX=8,LABEL_FONT_SIZE_PX=11,STROKE_WIDTH_PX=1,ANCHOR_MARKER_SIZE_PX=5,ANCHOR_MARKER_STROKE_WIDTH_PX=1.5,COMPONENT_ANCHOR_MARKER_RADIUS_PX=2,CONNECTOR_GROUP_GAP_PX=ANCHOR_MARKER_SIZE_PX+2,CONNECTOR_COMPONENT_GAP_PX=COMPONENT_ANCHOR_MARKER_RADIUS_PX+2,DIMENSION_ANCHOR_CLEARANCE_PX=ANCHOR_MARKER_SIZE_PX+TICK_SIZE_PX+6,COMPONENT_GAP_PX=15,COMPONENT_SIDE_GAP_PX=10,DISTANCE_MULTIPLIER=.2,MAX_OFFSET_PX=50;getElementPosition=(id2,circuitJson)=>{let pcbSmtpad=su2(circuitJson).pcb_smtpad.get(id2);if(pcbSmtpad&&"x"in pcbSmtpad&&"y"in pcbSmtpad)return{x:pcbSmtpad.x,y:pcbSmtpad.y};let pcbPlatedHole=su2(circuitJson).pcb_plated_hole.get(id2);return pcbPlatedHole&&"x"in pcbPlatedHole&&"y"in pcbPlatedHole?{x:pcbPlatedHole.x,y:pcbPlatedHole.y}:null},findNearestPointInNet=(sourcePoint,netId,connectivity,circuitJson)=>{let connectedIds=connectivity.getIdsConnectedToNet(netId),nearestPoint=null,minDistance=1/0;for(let id2 of connectedIds){let pos=getElementPosition(id2,circuitJson);if(pos){let dx3=sourcePoint.x-pos.x,dy3=sourcePoint.y-pos.y,distance62=Math.sqrt(dx3*dx3+dy3*dy3);distance62>0&&distance62<minDistance&&(minDistance=distance62,nearestPoint=pos)}}return nearestPoint};KEEPOUT_PATTERN_ID="pcb-keepout-pattern",KEEPOUT_PATTERN_SIZE=20,KEEPOUT_LINE_SPACING=5,KEEPOUT_BACKGROUND_COLOR="rgba(255, 107, 107, 0.2)";DEFAULT_GRID_LINE_COLOR="rgba(255, 255, 255, 0.5)",GRID_PATTERN_ID="pcb-grid-pattern";GROUP_COLOR_PALETTE=["rgba(100, 200, 255, 0.6)","rgba(255, 150, 100, 0.6)","rgba(100, 255, 150, 0.6)","rgba(200, 100, 255, 0.6)","rgba(255, 220, 100, 0.6)","rgba(255, 100, 200, 0.6)","rgba(100, 255, 255, 0.6)","rgba(180, 255, 100, 0.6)"],DEFAULT_STROKE_WIDTH=.1;package_default2={name:"circuit-to-svg",type:"module",version:"0.0.348",description:"Convert Circuit JSON to SVG",main:"dist/index.js",files:["dist"],scripts:{start:"cosmos",prepublish:"npm run build",build:"tsup-node ./lib/index.ts --format esm --dts --sourcemap --external tscircuit",format:"biome format . --write","format:check":"biome format .",cosmos:"cosmos","cosmos-export":"cosmos-export"},license:"ISC",devDependencies:{"@biomejs/biome":"^1.9.4","@tscircuit/alphabet":"^0.0.25","@types/bun":"^1.2.8","@types/debug":"^4.1.12","@vitejs/plugin-react":"5.0.0",biome:"^0.3.3","bun-match-svg":"^0.0.12","circuit-json":"^0.0.424",esbuild:"^0.20.2","performance-now":"^2.1.0",react:"19.1.0","react-cosmos":"7.0.0","react-cosmos-plugin-vite":"7.0.0","react-dom":"19.1.0",tscircuit:"^0.0.1564",tsup:"^8.0.2",typescript:"^5.4.5","vite-tsconfig-paths":"^5.0.1"},peerDependencies:{"@tscircuit/alphabet":"*"},dependencies:{"@types/node":"^22.5.5","bun-types":"^1.1.40","calculate-elbow":"0.0.12",debug:"^4.4.3","svg-path-commander":"^2.1.11",svgson:"^5.3.1","transformation-matrix":"^2.16.1"}},CIRCUIT_TO_SVG_VERSION=package_default2.version,TYPE_PRIORITY={pcb_background:0,pcb_boundary:1,pcb_panel:5,pcb_board:10,pcb_cutout:15,pcb_cutout_path:15,pcb_keepout:16,pcb_hole:18,pcb_plated_hole_drill:19,pcb_plated_hole:20,pcb_trace_soldermask:25,pcb_trace:30,pcb_smtpad:30,pcb_copper_pour:35,pcb_via:36,pcb_soldermask:40,pcb_soldermask_opening:25,pcb_solder_paste:45,pcb_silkscreen_text:50,pcb_silkscreen_path:50,pcb_silkscreen_rect:50,pcb_silkscreen_circle:50,pcb_silkscreen_line:50,pcb_silkscreen_oval:50,pcb_silkscreen_pill:50,pcb_component:60,pcb_fabrication_note_text:70,pcb_fabrication_note_path:70,pcb_fabrication_note_rect:70,pcb_fabrication_note_dimension:70,pcb_note_dimension:70,pcb_note_text:70,pcb_note_rect:70,pcb_note_path:70,pcb_note_line:70,pcb_trace_error:80,pcb_footprint_overlap_error:80,pcb_component_outside_board_error:80,pcb_via_trace_clearance_error:80,pcb_rats_nest:85},DEFAULT_TYPE_PRIORITY=100;getViewportBounds=({circuitJson,drawPaddingOutsideBoard,baseBounds,viewportOptions})=>{let padding=drawPaddingOutsideBoard?1:0,boundsMinX=drawPaddingOutsideBoard||!baseBounds.hasBoardBounds?baseBounds.minX:baseBounds.boardMinX,boundsMinY=drawPaddingOutsideBoard||!baseBounds.hasBoardBounds?baseBounds.minY:baseBounds.boardMinY,boundsMaxX=drawPaddingOutsideBoard||!baseBounds.hasBoardBounds?baseBounds.maxX:baseBounds.boardMaxX,boundsMaxY=drawPaddingOutsideBoard||!baseBounds.hasBoardBounds?baseBounds.maxY:baseBounds.boardMaxY,hasPanelBounds=!1,panelMinX=Number.POSITIVE_INFINITY,panelMinY=Number.POSITIVE_INFINITY,panelMaxX=Number.NEGATIVE_INFINITY,panelMaxY=Number.NEGATIVE_INFINITY,panelBoundsById=new Map,boardBoundsById=new Map;for(let elm of circuitJson)if(elm.type==="pcb_panel"){let panel=elm,panelBounds=rectBounds(panel.center,panel.width,panel.height);if(!panelBounds)continue;panelMinX=Math.min(panelMinX,panelBounds.minX),panelMinY=Math.min(panelMinY,panelBounds.minY),panelMaxX=Math.max(panelMaxX,panelBounds.maxX),panelMaxY=Math.max(panelMaxY,panelBounds.maxY),hasPanelBounds=!0,panel.pcb_panel_id&&panelBoundsById.set(panel.pcb_panel_id,panelBounds)}else if(elm.type==="pcb_board"){let board=elm,boardBounds=getOutlineBounds(board.outline)??rectBounds(board.center,board.width,board.height);boardBounds&&board.pcb_board_id&&boardBoundsById.set(board.pcb_board_id,boardBounds)}if(viewportOptions?.viewport){let{minX,minY,maxX,maxY}=viewportOptions.viewport;boundsMinX=minX,boundsMinY=minY,boundsMaxX=maxX,boundsMaxY=maxY,padding=0}else if(viewportOptions?.viewportTarget?.pcb_panel_id){let panelBounds=panelBoundsById.get(viewportOptions.viewportTarget.pcb_panel_id);if(!panelBounds)throw new Error(`Viewport target panel '${viewportOptions.viewportTarget.pcb_panel_id}' not found`);boundsMinX=panelBounds.minX,boundsMinY=panelBounds.minY,boundsMaxX=panelBounds.maxX,boundsMaxY=panelBounds.maxY,padding=0}else if(viewportOptions?.viewportTarget?.pcb_board_id){let boardBounds=boardBoundsById.get(viewportOptions.viewportTarget.pcb_board_id);if(!boardBounds)throw new Error(`Viewport target board '${viewportOptions.viewportTarget.pcb_board_id}' not found`);boundsMinX=boardBounds.minX,boundsMinY=boardBounds.minY,boundsMaxX=boardBounds.maxX,boundsMaxY=boardBounds.maxY,padding=0}else hasPanelBounds&&(boundsMinX=panelMinX,boundsMinY=panelMinY,boundsMaxX=panelMaxX,boundsMaxY=panelMaxY);return{boundsMinX,boundsMinY,boundsMaxX,boundsMaxY,padding}};circuitJsonToPcbSvg=convertCircuitJsonToPcbSvg,DEFAULT_BOARD_STYLE={fill:"none",stroke:"rgb(0,0,0)",strokeOpacity:"0.8",strokeWidthFactor:.2};fontSizeMap={pin_number:.15,negated_pin_number:.15*.8,reference_designator:.18,manufacturer_number:.18,net_label:.18,error:.05},getSchMmFontSize=(textType,fontSize)=>fontSize??fontSizeMap[textType],getSchScreenFontSize=(transform6,textType,fontSize)=>Math.abs(transform6.a)*getSchMmFontSize(textType,fontSize);HOLE_COLOR2="rgb(190, 190, 190)";PAD_COLOR="rgb(210, 210, 210)",HOLE_COLOR3="rgb(190, 190, 190)";PAD_COLOR2="rgb(210, 210, 210)";OBJECT_ORDER=["pcb_component","pcb_smtpad","pcb_hole","pcb_plated_hole","pcb_board"];BOARD_FILL_COLOR="rgb(26, 115, 143)",BOARD_STROKE_COLOR="rgba(0,0,0,0.9)";COMPONENT_FILL_COLOR="rgba(120, 120, 120, 0.6)",COMPONENT_LABEL_COLOR="rgba(255, 255, 255, 0.9)";HOLE_COLOR4="rgb(50, 50, 50)";PAD_COLOR3="rgb(218, 165, 32)",HOLE_COLOR5="rgb(40, 40, 40)";PAD_COLOR4="rgb(218, 165, 32)";LABEL_COLOR="rgb(255, 255, 255)",LABEL_BACKGROUND="rgb(0, 0, 0)",LINE_COLOR="rgba(0, 0, 0, 0.6)",PIN_NUMBER_BACKGROUND="rgb(200, 200, 200)",PIN_NUMBER_COLOR="rgb(0, 0, 0)";LABEL_RECT_HEIGHT_BASE_MM=1.6,FONT_HEIGHT_RATIO=11/21,CHAR_WIDTH_FACTOR=.6,STAGGER_OFFSET_MIN=.1,STAGGER_OFFSET_PER_PIN=.1,STAGGER_OFFSET_STEP=3,ALIGNED_OFFSET_MARGIN=.1,GROUP_SEPARATION_MM=.8;calculateLabelPositions=({left_labels,right_labels,transform:transform6,soup,board_bounds,svgWidth,svgHeight,styleScale})=>{let label_positions=new Map,shared_params={transform:transform6,soup,board_bounds};return calculateVerticalEdgeLabels("left",left_labels,{...shared_params,svgHeight,styleScale},label_positions),calculateVerticalEdgeLabels("right",right_labels,{...shared_params,svgHeight,styleScale},label_positions),label_positions};OBJECT_ORDER2=["pcb_board","pcb_smtpad","pcb_hole","pcb_plated_hole","pcb_component","pcb_port"];arialTextMetrics={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}},estimateTextWidth=text=>{if(!text)return 0;let totalWidth=0;for(let char of text){let metrics=arialTextMetrics[char];metrics?totalWidth+=metrics.width:totalWidth+=arialTextMetrics["?"].width}return totalWidth/27},getTableDimensions=(schematicTable,circuitJson)=>{if(schematicTable.column_widths&&schematicTable.column_widths.length>0&&schematicTable.row_heights&&schematicTable.row_heights.length>0){let unitToMm4=v4=>typeof v4=="number"?v4:v4.endsWith("mm")?parseFloat(v4):v4.endsWith("in")?parseFloat(v4)*25.4:parseFloat(v4);return{column_widths:schematicTable.column_widths.map(unitToMm4),row_heights:schematicTable.row_heights.map(unitToMm4)}}let cells=circuitJson.filter(elm=>elm.type==="schematic_table_cell"&&elm.schematic_table_id===schematicTable.schematic_table_id);if(cells.length===0)return{column_widths:[],row_heights:[]};let numColumns=cells.reduce((max,c4)=>Math.max(max,c4.end_column_index),-1)+1,numRows=cells.reduce((max,c4)=>Math.max(max,c4.end_row_index),-1)+1,{cell_padding=.2}=schematicTable,column_widths=new Array(numColumns).fill(0),row_heights=new Array(numRows).fill(0),cell_widths={},cell_heights={};for(let cell of cells){let fontSizeMm=getSchMmFontSize("reference_designator",cell.font_size),requiredWidth=estimateTextWidth(cell.text??"")*fontSizeMm+2*cell_padding,requiredHeight=fontSizeMm*1.2+2*cell_padding,key=`${cell.start_row_index}-${cell.start_column_index}`;cell_widths[key]=requiredWidth,cell_heights[key]=requiredHeight}for(let i3=0;i3<numRows;i3++)for(let j4=0;j4<numColumns;j4++){let key=`${i3}-${j4}`;cell_widths[key]&&cell_widths[key]>column_widths[j4]&&(column_widths[j4]=cell_widths[key]),cell_heights[key]&&cell_heights[key]>row_heights[i3]&&(row_heights[i3]=cell_heights[key])}for(let cell of cells){if(cell.start_column_index===cell.end_column_index&&cell.start_row_index===cell.end_row_index)continue;let key=`${cell.start_row_index}-${cell.start_column_index}`,requiredWidth=cell_widths[key],requiredHeight=cell_heights[key];if(requiredWidth===void 0||requiredHeight===void 0)continue;let currentWidth=0;for(let i3=cell.start_column_index;i3<=cell.end_column_index;i3++)currentWidth+=column_widths[i3];if(requiredWidth>currentWidth){let extraPerColumn=(requiredWidth-currentWidth)/(cell.end_column_index-cell.start_column_index+1);for(let i3=cell.start_column_index;i3<=cell.end_column_index;i3++)column_widths[i3]+=extraPerColumn}let currentHeight=0;for(let i3=cell.start_row_index;i3<=cell.end_row_index;i3++)currentHeight+=row_heights[i3];if(requiredHeight>currentHeight){let extraPerRow=(requiredHeight-currentHeight)/(cell.end_row_index-cell.start_row_index+1);for(let i3=cell.start_row_index;i3<=cell.end_row_index;i3++)row_heights[i3]+=extraPerRow}}return{column_widths,row_heights}},getUnitVectorFromOutsideToEdge=side=>{switch(side){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: ${side}`)},ARROW_POINT_WIDTH_FSR=.3,END_PADDING_FSR=.3,END_PADDING_EXTRA_PER_CHARACTER_FSR=.06,ninePointAnchorToTextAnchor={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"},ninePointAnchorToDominantBaseline={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"};getSchStrokeSize=transform6=>Math.abs(transform6.a)*.02,getAngularDifference=(angle1,angle2)=>{let a12=angle1<0?angle1+2*Math.PI:angle1,a22=angle2<0?angle2+2*Math.PI:angle2,diff=Math.abs(a12-a22);return diff>Math.PI&&(diff=2*Math.PI-diff),diff},matchSchPortsToSymbolPorts=({schPorts,symbol,schComponent})=>{let schPortAngles=schPorts.map(port=>{let dx3=port.center.x-schComponent.center.x,dy3=port.center.y-schComponent.center.y;return{port,angle:Math.atan2(dy3,dx3)}}),symbolPortAngles=symbol.ports.map(port=>{let dx3=port.x-symbol.center.x,dy3=port.y-symbol.center.y;return{port,angle:Math.atan2(dy3,dx3)}});schPortAngles.sort((a3,b3)=>a3.angle-b3.angle),symbolPortAngles.sort((a3,b3)=>a3.angle-b3.angle);let matches=[],usedSymbolPorts=new Set;for(let schPortAngle of schPortAngles){let bestMatch=null;for(let symbolPortAngle of symbolPortAngles){if(usedSymbolPorts.has(symbolPortAngle.port))continue;let angleDiff=getAngularDifference(schPortAngle.angle,symbolPortAngle.angle);(bestMatch===null||angleDiff<bestMatch.angleDiff)&&(bestMatch={symbolPort:symbolPortAngle.port,angleDiff})}bestMatch&&bestMatch.angleDiff<Math.PI/4&&(matches.push({schPort:schPortAngle.port,symbolPort:bestMatch.symbolPort}),usedSymbolPorts.add(bestMatch.symbolPort))}return matches};createSvgSchErrorText=({text,realCenter,realToScreenTransform})=>{let screenCenter=applyToPoint3(realToScreenTransform,realCenter);return{type:"element",name:"text",value:"",attributes:{x:screenCenter.x.toString(),y:screenCenter.y.toString(),fill:"red","text-anchor":"middle","dominant-baseline":"middle","font-family":"sans-serif","font-size":`${getSchScreenFontSize(realToScreenTransform,"error")}px`},children:[{type:"text",value:text,name:"",attributes:{},children:[]}]}},isSourcePortConnected=(circuitJson,sourcePortId)=>{for(let elm of circuitJson){if(elm.type!=="source_trace")continue;let trace=elm;if(Array.isArray(trace.connected_source_port_ids)&&trace.connected_source_port_ids.includes(sourcePortId))return!0}return!1},ninePointAnchorToTextAnchor2={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"},ninePointAnchorToDominantBaseline2={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"},createSvgObjectsFromSchematicComponentWithSymbol=({component:schComponent,transform:realToScreenTransform,circuitJson,colorMap:colorMap2})=>{let svgObjects=[],symbol=Vf[schComponent.symbol_name];if(!symbol)return[createSvgSchErrorText({text:`Symbol not found: ${schComponent.symbol_name}`,realCenter:schComponent.center,realToScreenTransform})];let schPorts=su2(circuitJson).schematic_port.list({schematic_component_id:schComponent.schematic_component_id}),srcComponent=su2(circuitJson).source_component.get(schComponent.source_component_id),schPortsWithSymbolPorts=matchSchPortsToSymbolPorts({schPorts,symbol,schComponent});if(!schPortsWithSymbolPorts[0])return[createSvgSchErrorText({text:`Could not match ports for symbol ${schComponent.symbol_name}`,realCenter:schComponent.center,realToScreenTransform})];let transformFromSymbolToReal=pointPairsToMatrix(schPortsWithSymbolPorts[1]?.symbolPort??symbol.center,schPortsWithSymbolPorts[1]?.schPort.center??schComponent.center,schPortsWithSymbolPorts[0].symbolPort,schPortsWithSymbolPorts[0].schPort.center),paths=symbol.primitives.filter(p4=>p4.type==="path"),texts=symbol.primitives.filter(p4=>p4.type==="text"),circles=symbol.primitives.filter(p4=>p4.type==="circle"),boxes=symbol.primitives.filter(p4=>p4.type==="box"),connectedSymbolPorts=new Set;for(let match2 of schPortsWithSymbolPorts)isSourcePortConnected(circuitJson,match2.schPort.source_port_id)&&connectedSymbolPorts.add(match2.symbolPort);let bounds={minX:Math.min(...paths.flatMap(p4=>p4.points.map(pt3=>pt3.x))),maxX:Math.max(...paths.flatMap(p4=>p4.points.map(pt3=>pt3.x))),minY:Math.min(...paths.flatMap(p4=>p4.points.map(pt3=>pt3.y))),maxY:Math.max(...paths.flatMap(p4=>p4.points.map(pt3=>pt3.y)))},[screenMinX,screenMinY]=applyToPoint3(compose3(realToScreenTransform,transformFromSymbolToReal),[bounds.minX,bounds.minY]),[screenMaxX,screenMaxY]=applyToPoint3(compose3(realToScreenTransform,transformFromSymbolToReal),[bounds.maxX,bounds.maxY]),rectHeight=Math.abs(screenMaxY-screenMinY),rectY=Math.min(screenMinY,screenMaxY),rectWidth=Math.abs(screenMaxX-screenMinX),rectX=Math.min(screenMinX,screenMaxX);svgObjects.push({name:"rect",type:"element",value:"",attributes:{class:"component-overlay",x:rectX.toString(),y:rectY.toString(),width:rectWidth.toString(),height:rectHeight.toString(),fill:"transparent"},children:[]});for(let path of paths){let{points,color,closed,fill}=path;svgObjects.push({type:"element",name:"path",attributes:{d:points.map((p4,i3)=>{let[x4,y4]=applyToPoint3(compose3(realToScreenTransform,transformFromSymbolToReal),[p4.x,p4.y]);return`${i3===0?"M":"L"} ${x4} ${y4}`}).join(" ")+(closed?" Z":""),stroke:colorMap2.schematic.component_outline,fill:"none","stroke-width":`${getSchStrokeSize(realToScreenTransform)}px`,"stroke-linecap":"round"},value:"",children:[]})}for(let text of texts){let screenTextPos=applyToPoint3(compose3(realToScreenTransform,transformFromSymbolToReal),text),textValue="",isReferenceText=text.text==="{REF}";isReferenceText?textValue=srcComponent?.display_name??srcComponent?.name??"":text.text==="{VAL}"&&(textValue=schComponent.symbol_display_value??"");let dominantBaseline=ninePointAnchorToDominantBaseline2[text.anchor];svgObjects.push({name:"text",type:"element",attributes:{x:screenTextPos.x.toString(),y:screenTextPos.y.toString(),...isReferenceText?{stroke:colorMap2.schematic.background,"stroke-width":`${getSchStrokeSize(realToScreenTransform)}px`,"paint-order":"stroke"}:{},fill:colorMap2.schematic.label_local,"font-family":"sans-serif","text-anchor":ninePointAnchorToTextAnchor2[text.anchor],"dominant-baseline":dominantBaseline,"font-size":`${getSchScreenFontSize(realToScreenTransform,"reference_designator")}px`},value:"",children:[{type:"text",value:textValue,name:"",attributes:{},children:[]}]})}for(let box2 of boxes){let screenBoxPos=applyToPoint3(compose3(realToScreenTransform,transformFromSymbolToReal),box2),symbolToScreenScale=compose3(realToScreenTransform,transformFromSymbolToReal).a;svgObjects.push({name:"rect",type:"element",attributes:{x:screenBoxPos.x.toString(),y:screenBoxPos.y.toString(),width:(box2.width*symbolToScreenScale).toString(),height:(box2.height*symbolToScreenScale).toString(),fill:"red"},value:"",children:[]})}for(let port of symbol.ports){if(connectedSymbolPorts.has(port))continue;let screenPortPos=applyToPoint3(compose3(realToScreenTransform,transformFromSymbolToReal),port);svgObjects.push({type:"element",name:"circle",attributes:{cx:screenPortPos.x.toString(),cy:screenPortPos.y.toString(),r:`${Math.abs(realToScreenTransform.a)*.02}px`,"stroke-width":`${getSchStrokeSize(realToScreenTransform)}px`,fill:"none",stroke:colorMap2.schematic.component_outline},value:"",children:[]})}for(let circle2 of circles){let screenCirclePos=applyToPoint3(compose3(realToScreenTransform,transformFromSymbolToReal),circle2),screenRadius=Math.abs(circle2.radius*realToScreenTransform.a);svgObjects.push({type:"element",name:"circle",attributes:{cx:screenCirclePos.x.toString(),cy:screenCirclePos.y.toString(),r:`${screenRadius}px`,"stroke-width":`${getSchStrokeSize(realToScreenTransform)}px`,fill:"none",stroke:colorMap2.schematic.component_outline},value:"",children:[]})}return svgObjects},PIN_CIRCLE_RADIUS_MM=.02,createArrow=(tip,angle,size3,color,strokeWidth)=>{let arrowAngle=Math.PI/6,p12={x:tip.x-size3*Math.cos(angle-arrowAngle),y:tip.y-size3*Math.sin(angle-arrowAngle)},p22={x:tip.x-size3*Math.cos(angle+arrowAngle),y:tip.y-size3*Math.sin(angle+arrowAngle)};return{name:"polygon",type:"element",attributes:{points:`${tip.x},${tip.y} ${p12.x},${p12.y} ${p22.x},${p22.y}`,fill:"white",stroke:color,"stroke-width":`${strokeWidth}px`},value:"",children:[]}},createSvgObjectsForSchPortBoxLine=({schPort,schComponent,transform:transform6,circuitJson})=>{let svgObjects=[],srcPort=su2(circuitJson).source_port.get(schPort.source_port_id),realEdgePos={x:schPort.center.x,y:schPort.center.y},realPinLineLength=schPort.distance_from_component_edge??.4;switch(schPort.side_of_component){case"left":realEdgePos.x+=realPinLineLength;break;case"right":realEdgePos.x-=realPinLineLength;break;case"top":realEdgePos.y-=realPinLineLength;break;case"bottom":realEdgePos.y+=realPinLineLength;break}let screenSchPortPos=applyToPoint3(transform6,schPort.center),screenRealEdgePos=applyToPoint3(transform6,realEdgePos),isConnected=isSourcePortConnected(circuitJson,schPort.source_port_id),is_drawn_with_inversion_circle=schPort.is_drawn_with_inversion_circle??!1,BUBBLE_RADIUS_MM=.06,realLineEnd={...schPort.center};if(!isConnected)switch(schPort.side_of_component){case"left":realLineEnd.x+=PIN_CIRCLE_RADIUS_MM;break;case"right":realLineEnd.x-=PIN_CIRCLE_RADIUS_MM;break;case"top":realLineEnd.y-=PIN_CIRCLE_RADIUS_MM;break;case"bottom":realLineEnd.y+=PIN_CIRCLE_RADIUS_MM;break}let screenLineEnd=applyToPoint3(transform6,realLineEnd);if(is_drawn_with_inversion_circle){let bubbleRadiusPx=Math.abs(transform6.a)*BUBBLE_RADIUS_MM,bubbleCenter={...screenRealEdgePos};switch(schPort.side_of_component){case"left":bubbleCenter.x-=bubbleRadiusPx,screenRealEdgePos.x-=bubbleRadiusPx*2;break;case"right":bubbleCenter.x+=bubbleRadiusPx,screenRealEdgePos.x+=bubbleRadiusPx*2;break;case"top":bubbleCenter.y-=bubbleRadiusPx,screenRealEdgePos.y-=bubbleRadiusPx*2;break;case"bottom":bubbleCenter.y+=bubbleRadiusPx,screenRealEdgePos.y+=bubbleRadiusPx*2;break}svgObjects.push({name:"circle",type:"element",attributes:{class:"component-pin",cx:bubbleCenter.x.toString(),cy:bubbleCenter.y.toString(),r:bubbleRadiusPx.toString(),fill:"white",stroke:colorMap.schematic.component_outline,"stroke-width":`${getSchStrokeSize(transform6)}px`},value:"",children:[]})}svgObjects.push({name:"line",type:"element",attributes:{class:"component-pin",x1:screenRealEdgePos.x.toString(),y1:screenRealEdgePos.y.toString(),x2:screenLineEnd.x.toString(),y2:screenLineEnd.y.toString(),"stroke-width":`${getSchStrokeSize(transform6)}px`},value:"",children:[]});let pinRadiusPx=Math.abs(transform6.a)*PIN_CIRCLE_RADIUS_MM,pinChildren=[];isConnected||pinChildren.push({name:"circle",type:"element",attributes:{class:"component-pin",cx:screenSchPortPos.x.toString(),cy:screenSchPortPos.y.toString(),r:pinRadiusPx.toString(),"stroke-width":`${getSchStrokeSize(transform6)}px`},value:"",children:[]}),pinChildren.push({name:"rect",type:"element",attributes:{x:(screenSchPortPos.x-pinRadiusPx).toString(),y:(screenSchPortPos.y-pinRadiusPx).toString(),width:(pinRadiusPx*2).toString(),height:(pinRadiusPx*2).toString(),opacity:"0"},value:"",children:[]}),svgObjects.push({name:"g",type:"element",value:"",attributes:{"data-schematic-port-id":schPort.source_port_id},children:pinChildren});let{has_input_arrow,has_output_arrow}=schPort;if((has_input_arrow||has_output_arrow)&&schPort.side_of_component){let arrowSize=Math.abs(transform6.a)*.1,arrowColor=colorMap.schematic.component_outline,arrowAxialLength=arrowSize*Math.cos(Math.PI/6),strokeWidth=getSchStrokeSize(transform6)/3,inputAngleRads=0,outputAngleRads=0;schPort.side_of_component==="left"?(inputAngleRads=0,outputAngleRads=Math.PI):schPort.side_of_component==="right"?(inputAngleRads=Math.PI,outputAngleRads=0):schPort.side_of_component==="top"?(inputAngleRads=Math.PI/2,outputAngleRads=-Math.PI/2):schPort.side_of_component==="bottom"&&(inputAngleRads=-Math.PI/2,outputAngleRads=Math.PI/2);let both=has_input_arrow&&has_output_arrow,inputArrowTip={...screenRealEdgePos},outputArrowBase={...screenRealEdgePos};if(both){let offset=arrowAxialLength;schPort.side_of_component==="left"?outputArrowBase.x-=offset:schPort.side_of_component==="right"?outputArrowBase.x+=offset:schPort.side_of_component==="top"?outputArrowBase.y-=offset:schPort.side_of_component==="bottom"&&(outputArrowBase.y+=offset)}if(has_input_arrow&&svgObjects.push(createArrow(inputArrowTip,inputAngleRads,arrowSize,arrowColor,strokeWidth)),has_output_arrow){let outputArrowTip={x:outputArrowBase.x+arrowSize*Math.cos(outputAngleRads),y:outputArrowBase.y+arrowSize*Math.sin(outputAngleRads)};svgObjects.push(createArrow(outputArrowTip,outputAngleRads,arrowSize,arrowColor,strokeWidth))}}return svgObjects},createSvgObjectsForSchPortPinNumberText=params=>{let svgObjects=[],{schPort,schComponent,transform:transform6,circuitJson}=params,realPinNumberPos={x:schPort.center.x,y:schPort.center.y};if(!schPort.side_of_component)return[];let vecToEdge=getUnitVectorFromOutsideToEdge(schPort.side_of_component),realPinEdgeDistance=schPort.distance_from_component_edge??.4;realPinNumberPos.x+=vecToEdge.x*realPinEdgeDistance/2,realPinNumberPos.y+=vecToEdge.y*realPinEdgeDistance/2,schPort.side_of_component==="top"||schPort.side_of_component==="bottom"?realPinNumberPos.x-=.02:realPinNumberPos.y+=.02;let screenPinNumberTextPos=applyToPoint3(transform6,realPinNumberPos);return svgObjects.push({name:"text",type:"element",attributes:{class:"pin-number",x:screenPinNumberTextPos.x.toString(),y:screenPinNumberTextPos.y.toString(),style:"font-family: sans-serif;",fill:colorMap.schematic.pin_number,"text-anchor":"middle","dominant-baseline":"auto","font-size":`${getSchScreenFontSize(transform6,"pin_number")}px`,transform:schPort.side_of_component==="top"||schPort.side_of_component==="bottom"?`rotate(-90 ${screenPinNumberTextPos.x} ${screenPinNumberTextPos.y})`:""},children:[{type:"text",value:schPort.pin_number?.toString()||"",name:"",attributes:{},children:[]}],value:""}),svgObjects},LABEL_DIST_FROM_EDGE_MM=.1,createSvgObjectsForSchPortPinLabel=params=>{let svgObjects=[],{schPort,schComponent,transform:transform6,circuitJson}=params,realPinNumberPos={x:schPort.center.x,y:schPort.center.y};if(!schPort.side_of_component)return[];let vecToEdge=getUnitVectorFromOutsideToEdge(schPort.side_of_component),realPinEdgeDistance=schPort.distance_from_component_edge??.4;realPinNumberPos.x+=vecToEdge.x*(realPinEdgeDistance+LABEL_DIST_FROM_EDGE_MM),realPinNumberPos.y+=vecToEdge.y*(realPinEdgeDistance+LABEL_DIST_FROM_EDGE_MM);let screenPinNumberTextPos=applyToPoint3(transform6,realPinNumberPos),label=schPort.display_pin_label??schComponent.port_labels?.[`${schPort.pin_number}`];if(!label)return[];let isNegated=label.startsWith("N_"),displayLabel=isNegated?label.slice(2):label,is_drawn_with_inversion_circle=schPort.is_drawn_with_inversion_circle??!1,fontSizePx=getSchScreenFontSize(transform6,isNegated||is_drawn_with_inversion_circle?"negated_pin_number":"pin_number");return svgObjects.push({name:"text",type:"element",attributes:{class:"pin-number",x:screenPinNumberTextPos.x.toString(),y:screenPinNumberTextPos.y.toString(),style:`font-family: sans-serif;${isNegated?" text-decoration: overline;":""}`,fill:colorMap.schematic.pin_number,"text-anchor":schPort.side_of_component==="left"||schPort.side_of_component==="bottom"?"start":"end","dominant-baseline":"middle","font-size":`${fontSizePx}px`,transform:schPort.side_of_component==="top"||schPort.side_of_component==="bottom"?`rotate(-90 ${screenPinNumberTextPos.x} ${screenPinNumberTextPos.y})`:""},children:[{type:"text",value:displayLabel||"",name:"",attributes:{},children:[]}],value:""}),svgObjects},createSvgObjectsFromSchPortOnBox=params=>{let svgObjects=[],{schPort,schComponent,transform:transform6,circuitJson}=params;return svgObjects.push(...createSvgObjectsForSchPortBoxLine(params)),svgObjects.push(...createSvgObjectsForSchPortPinNumberText(params)),svgObjects.push(...createSvgObjectsForSchPortPinLabel(params)),svgObjects},createSvgSchText=({elm,transform:transform6,colorMap:colorMap2})=>{let center2=applyToPoint3(transform6,elm.position),textAnchorMap={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"},dominantBaselineMap={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"},lines=elm.text.split(`
|
|
291
291
|
`),children=lines.length===1?[{type:"text",value:elm.text,name:elm.schematic_text_id,attributes:{},children:[]}]:lines.map((line2,idx)=>({type:"element",name:"tspan",value:"",attributes:{x:center2.x.toString(),...idx>0?{dy:"1em"}:{}},children:[{type:"text",value:line2,name:idx===0?elm.schematic_text_id:"",attributes:{},children:[]}]}));return{type:"element",name:"text",value:"",attributes:{x:center2.x.toString(),y:center2.y.toString(),fill:elm.color??colorMap2.schematic.sheet_label,"text-anchor":textAnchorMap[elm.anchor],"dominant-baseline":dominantBaselineMap[elm.anchor],"font-family":"sans-serif","font-size":`${getSchScreenFontSize(transform6,"reference_designator",elm.font_size)}px`,transform:`rotate(${elm.rotation}, ${center2.x}, ${center2.y})`},children}},createSvgObjectsFromSchematicComponentWithBox=({component:schComponent,transform:transform6,circuitJson,colorMap:colorMap2})=>{let svgObjects=[],componentScreenTopLeft=applyToPoint3(transform6,{x:schComponent.center.x-schComponent.size.width/2,y:schComponent.center.y+schComponent.size.height/2}),componentScreenBottomRight=applyToPoint3(transform6,{x:schComponent.center.x+schComponent.size.width/2,y:schComponent.center.y-schComponent.size.height/2}),componentScreenWidth=componentScreenBottomRight.x-componentScreenTopLeft.x,componentScreenHeight=componentScreenBottomRight.y-componentScreenTopLeft.y;svgObjects.push({name:"rect",type:"element",value:"",attributes:{class:"component chip",x:componentScreenTopLeft.x.toString(),y:componentScreenTopLeft.y.toString(),width:componentScreenWidth.toString(),height:componentScreenHeight.toString(),"stroke-width":`${getSchStrokeSize(transform6)}px`,fill:colorMap2.schematic.component_body,stroke:colorMap2.schematic.component_outline},children:[]}),svgObjects.push({name:"rect",type:"element",value:"",attributes:{class:"component-overlay",x:componentScreenTopLeft.x.toString(),y:componentScreenTopLeft.y.toString(),width:componentScreenWidth.toString(),height:componentScreenHeight.toString(),fill:"transparent"},children:[]});let schTexts=su2(circuitJson).schematic_text.list();for(let schText of schTexts)schText.schematic_component_id===schComponent.schematic_component_id&&svgObjects.push(createSvgSchText({elm:schText,transform:transform6,colorMap:colorMap2}));let schematicPorts=su2(circuitJson).schematic_port.list({schematic_component_id:schComponent.schematic_component_id});for(let schPort of schematicPorts)svgObjects.push(...createSvgObjectsFromSchPortOnBox({schPort,schComponent,transform:transform6,circuitJson}));return svgObjects};createSvgObjectsFromSchematicComponentWithPrimitives=({component:schComponent,transform:transform6,circuitJson,colorMap:colorMap2})=>{let svgObjects=[],compId=schComponent.schematic_component_id;for(let elm of circuitJson)!("schematic_component_id"in elm)||elm.schematic_component_id!==compId||(elm.type==="schematic_line"?svgObjects.push(...createSvgObjectsFromSchematicLine({schLine:elm,transform:transform6,colorMap:colorMap2})):elm.type==="schematic_circle"?svgObjects.push(...createSvgObjectsFromSchematicCircle({schCircle:elm,transform:transform6,colorMap:colorMap2})):elm.type==="schematic_rect"?svgObjects.push(...createSvgObjectsFromSchematicRect({schRect:elm,transform:transform6,colorMap:colorMap2})):elm.type==="schematic_arc"?svgObjects.push(...createSvgObjectsFromSchematicArc({schArc:elm,transform:transform6,colorMap:colorMap2})):elm.type==="schematic_path"&&svgObjects.push(...createSvgObjectsFromSchematicPath({schPath:elm,transform:transform6,colorMap:colorMap2})));return svgObjects};createSvgObjectsForSchNetLabelWithSymbol=({schNetLabel,realToScreenTransform,colorMap:colorMap2})=>{if(!schNetLabel.text)return[];let isNegated=schNetLabel.text.startsWith("N_"),labelText=isNegated?schNetLabel.text.slice(2):schNetLabel.text,svgObjects=[],symbol=Vf[schNetLabel.symbol_name];if(!symbol)return svgObjects.push(createSvgSchErrorText({text:`Symbol not found: ${schNetLabel.symbol_name}`,realCenter:schNetLabel.center,realToScreenTransform})),svgObjects;let symbolPaths=symbol.primitives.filter(p4=>p4.type==="path"),symbolTexts=symbol.primitives.filter(p4=>p4.type==="text"),symbolCircles=symbol.primitives.filter(p4=>p4.type==="circle"),symbolBoxes=symbol.primitives.filter(p4=>p4.type==="box"),bounds={minX:Math.min(...symbolPaths.flatMap(p4=>p4.points.map(pt3=>pt3.x))),maxX:Math.max(...symbolPaths.flatMap(p4=>p4.points.map(pt3=>pt3.x))),minY:Math.min(...symbolPaths.flatMap(p4=>p4.points.map(pt3=>pt3.y))),maxY:Math.max(...symbolPaths.flatMap(p4=>p4.points.map(pt3=>pt3.y)))},fontSizeMm=getSchMmFontSize("net_label"),fullWidthFsr=estimateTextWidth(labelText||"")+ARROW_POINT_WIDTH_FSR*2+END_PADDING_EXTRA_PER_CHARACTER_FSR*labelText.length+END_PADDING_FSR,realTextGrowthVec=getUnitVectorFromOutsideToEdge(schNetLabel.anchor_side),realAnchorPosition=schNetLabel.anchor_position??{x:schNetLabel.center.x-realTextGrowthVec.x*fullWidthFsr*fontSizeMm/2,y:schNetLabel.center.y-realTextGrowthVec.y*fullWidthFsr*fontSizeMm/2},rotationMatrix=rotate3(0/180*Math.PI),symbolBounds={minX:Math.min(...symbol.primitives.flatMap(p4=>p4.type==="path"?p4.points.map(pt3=>pt3.x):[])),maxX:Math.max(...symbol.primitives.flatMap(p4=>p4.type==="path"?p4.points.map(pt3=>pt3.x):[])),minY:Math.min(...symbol.primitives.flatMap(p4=>p4.type==="path"?p4.points.map(pt3=>pt3.y):[])),maxY:Math.max(...symbol.primitives.flatMap(p4=>p4.type==="path"?p4.points.map(pt3=>pt3.y):[]))},symbolEndPoint=symbol.ports?.[0]?{x:symbol.ports[0].x,y:symbol.ports[0].y}:{x:symbolBounds.minX,y:(symbolBounds.minY+symbolBounds.maxY)/2},rotatedSymbolEnd=applyToPoint3(rotationMatrix,symbolEndPoint),symbolToRealTransform=compose3(translate3(realAnchorPosition.x-rotatedSymbolEnd.x,realAnchorPosition.y-rotatedSymbolEnd.y),rotationMatrix,scale3(1)),[screenMinX,screenMinY]=applyToPoint3(compose3(realToScreenTransform,symbolToRealTransform),[bounds.minX,bounds.minY]),[screenMaxX,screenMaxY]=applyToPoint3(compose3(realToScreenTransform,symbolToRealTransform),[bounds.maxX,bounds.maxY]),rectHeight=Math.abs(screenMaxY-screenMinY),rectY=Math.min(screenMinY,screenMaxY),rectWidth=Math.abs(screenMaxX-screenMinX),rectX=Math.min(screenMinX,screenMaxX);svgObjects.push({name:"rect",type:"element",value:"",attributes:{class:"component-overlay",x:rectX.toString(),y:rectY.toString(),width:rectWidth.toString(),height:rectHeight.toString(),fill:"transparent"},children:[]});for(let path of symbolPaths){let symbolPath=path.points.map((p4,i3)=>{let[x4,y4]=applyToPoint3(compose3(realToScreenTransform,symbolToRealTransform),[p4.x,p4.y]);return`${i3===0?"M":"L"} ${x4} ${y4}`}).join(" ");svgObjects.push({name:"path",type:"element",attributes:{d:symbolPath+(path.closed?" Z":""),stroke:colorMap2.schematic.component_outline,fill:"none","stroke-width":`${getSchStrokeSize(realToScreenTransform)}px`,"stroke-linecap":"round"},value:"",children:[]})}for(let text of symbolTexts){let screenTextPos=applyToPoint3(compose3(realToScreenTransform,symbolToRealTransform),text),textValue=text.text;textValue==="{REF}"?textValue=labelText||"":textValue==="{VAL}"&&(textValue="");let baseOffset=Math.abs(realToScreenTransform.a)*.1,offsetScreenPos={x:screenTextPos.x,y:screenTextPos.y};svgObjects.push({name:"text",type:"element",attributes:{x:offsetScreenPos.x.toString(),y:offsetScreenPos.y.toString(),fill:colorMap2.schematic.label_local,"font-family":"sans-serif","text-anchor":ninePointAnchorToTextAnchor[text.anchor],"dominant-baseline":ninePointAnchorToDominantBaseline[text.anchor],"font-size":`${getSchScreenFontSize(realToScreenTransform,"reference_designator")}px`,...isNegated&&textValue===labelText?{style:"text-decoration: overline;"}:{}},children:[{type:"text",value:textValue,name:"",attributes:{},children:[]}],value:""})}for(let box2 of symbolBoxes){let screenBoxPos=applyToPoint3(compose3(realToScreenTransform,symbolToRealTransform),box2),symbolToScreenScale=compose3(realToScreenTransform,symbolToRealTransform).a;svgObjects.push({name:"rect",type:"element",attributes:{x:screenBoxPos.x.toString(),y:screenBoxPos.y.toString(),width:(box2.width*symbolToScreenScale).toString(),height:(box2.height*symbolToScreenScale).toString(),fill:"red"},value:"",children:[]})}for(let circle2 of symbolCircles){let screenCirclePos=applyToPoint3(compose3(realToScreenTransform,symbolToRealTransform),circle2),symbolToScreenScale=compose3(realToScreenTransform,symbolToRealTransform).a;svgObjects.push({name:"circle",type:"element",attributes:{cx:screenCirclePos.x.toString(),cy:screenCirclePos.y.toString(),r:(circle2.radius*symbolToScreenScale).toString(),fill:"none",stroke:colorMap2.schematic.component_outline,"stroke-width":`${getSchStrokeSize(realToScreenTransform)}px`},value:"",children:[]})}return svgObjects},createSvgObjectsForSchNetLabel=({schNetLabel,realToScreenTransform,colorMap:colorMap2})=>{if(!schNetLabel.text)return[];let labelText=schNetLabel.text;if(schNetLabel.symbol_name)return createSvgObjectsForSchNetLabelWithSymbol({schNetLabel,realToScreenTransform,colorMap:colorMap2});let svgObjects=[],fontSizePx=getSchScreenFontSize(realToScreenTransform,"net_label"),fontSizeMm=getSchMmFontSize("net_label"),textWidthFSR=estimateTextWidth(labelText||""),screenCenter=applyToPoint3(realToScreenTransform,schNetLabel.center),realTextGrowthVec=getUnitVectorFromOutsideToEdge(schNetLabel.anchor_side),screenTextGrowthVec={...realTextGrowthVec};screenTextGrowthVec.y*=-1;let fullWidthFsr=textWidthFSR+ARROW_POINT_WIDTH_FSR*2+END_PADDING_EXTRA_PER_CHARACTER_FSR*labelText.length+END_PADDING_FSR,screenAnchorPosition=schNetLabel.anchor_position?applyToPoint3(realToScreenTransform,schNetLabel.anchor_position):{x:screenCenter.x-screenTextGrowthVec.x*fullWidthFsr*fontSizePx/2,y:screenCenter.y-screenTextGrowthVec.y*fullWidthFsr*fontSizePx/2},realAnchorPosition=schNetLabel.anchor_position??{x:schNetLabel.center.x-realTextGrowthVec.x*fullWidthFsr*fontSizeMm/2,y:schNetLabel.center.y-realTextGrowthVec.y*fullWidthFsr*fontSizeMm/2},pathRotation={left:0,top:-90,bottom:90,right:180}[schNetLabel.anchor_side],screenOutlinePoints=[{x:0,y:0},{x:ARROW_POINT_WIDTH_FSR,y:.6},{x:ARROW_POINT_WIDTH_FSR*2+END_PADDING_FSR+END_PADDING_EXTRA_PER_CHARACTER_FSR*labelText.length+textWidthFSR,y:.6},{x:ARROW_POINT_WIDTH_FSR*2+END_PADDING_FSR+END_PADDING_EXTRA_PER_CHARACTER_FSR*labelText.length+textWidthFSR,y:-.6},{x:ARROW_POINT_WIDTH_FSR,y:-.6}].map(fontRelativePoint=>applyToPoint3(compose3(realToScreenTransform,translate3(realAnchorPosition.x,realAnchorPosition.y),scale3(fontSizeMm),rotate3(pathRotation/180*Math.PI)),fontRelativePoint)),pathD=`
|
|
292
292
|
M ${screenOutlinePoints[0].x},${screenOutlinePoints[0].y}
|
|
293
293
|
L ${screenOutlinePoints[1].x},${screenOutlinePoints[1].y}
|