@tscircuit/runframe 0.0.1562 → 0.0.1563

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.
@@ -4938,7 +4938,7 @@ ${n(r.vertices[I+1])}
4938
4938
  ${n(r.vertices[I+2])}
4939
4939
  endloop
4940
4940
  endfacet`;a.push(c)}}return a.join(`
4941
- `)};return aQA={serializeText:A},aQA}var gQA,E9A;function Gce(){if(E9A)return gQA;E9A=1;const{geometries:e,modifiers:A}=w8(),{flatten:t,toArray:i}=xce(),{serializeBinary:o}=_ce(),{serializeText:n}=kce();return gQA={mimeType:"application/sla",serialize:(a,...g)=>{a=Object.assign({},{binary:!0,statusCallback:null},a),g=t(g);let c=g.filter(B=>e.geom3.isA(B));if(c.length===0)throw new Error("only 3D geometries can be serialized to STL");return g.length!==c.length&&console.warn("some objects could not be serialized to STL"),c=i(A.generalize({snap:!0,triangulate:!0},c)),a.binary?o(c,a):n(c,a)}},gQA}var Fce=Gce();const Rce=t0(Fce);var h9A={0:"M0.4544564813877358 0L0.2723441540828736 0.03592830447352719L0.1086847233315459 0.14528754990019965L0.020630545837255005 0.3040632652221331L0 0.5395277421960205L0.049259221760993496 0.7369487828466779L0.18080513776237842 0.9005494166306564L0.37036887043974215 0.9872116270037247L0.5864663759301132 1L0.8148695622827444 0.9332890276148733L0.9326583645506394 0.8113052246023419L1 0.4031281830668562L0.833288960385582 0.09886798567812842L0.6801767918233781 0.02483708485091681L0.4544564813877358 0",1:"M 0.16 0.27 L 0.5 0 L 0.5 1",2:"M0.069593147751606 0.19461498231706575L0.1039380353319058 0.1224291500164194L0.20543361884368308 0.05510832064153169L0.3717712794432549 0.009452970962689482L0.4785344452623127 0L0.663238590738758 0.008714098643339864L0.8017933618843684 0.04769189395915288L0.8775637379550322 0.10746757678258442L0.9047778372591005 0.17693069668193287L0.9029710920770878 0.2231347105796246L0.8704496788008566 0.30047744598157516L0.7292906538577354 0.4508486051631194L0.3737955032119913 0.7369006417749693L0 1L1 1",3:"M0.03917438899874637 0.19855364635107545L0.15510940508963084 0.06745632622133718L0.37598645522339846 0L0.8486391893813088 0.0652271323161611L0.9782182415054349 0.21747394183735683L0.9213133780517754 0.3547560290117714L0.6504271515903481 0.4543436297681271L0.22975249764129613 0.48476611625264143L0.7659038682744629 0.5411919558122493L0.9258712987734741 0.6203185665660985L1 0.7458360609169667L0.8938813281118737 0.9059190913045964L0.6166890258875837 1L0.261528440153542 0.9874861530507921L0 0.8837289530851273",4:"M0.7328897338403042 0L0 0.6684672518568535L1 0.6684672518568535M0.7243346007604563 0.4530722484807562L0.7243346007604563 1",5:"M 0 0 L 0 0.4973 L 0.4262 0.4319 L 0.7305 0.4565 L 0.8516 0.5009 L 0.9357 0.5639 L 1 0.7356 L 0.9696 0.8248 L 0.8898 0.895 L 0.733 0.9602 L 0.5518 0.9945 L 0.3814 1 L 0.2379 0.9821 L 0.1219 0.947 L 0 0.8748 M 0 0 L 1 0",6:"M0.6964601700926856 0L0.3639239026215478 0.0743562375769351L0.1415931962925719 0.21735490179786915L0.009977939399608712 0.46336322325406004L0.00029622007592593224 0.7083131475173043L0.09408885043224748 0.8746809149767036L0.3379247445101846 0.9876686500961888L0.7109203869569624 1L0.9260852957913362 0.9103558029693921L1 0.7716571969091733L0.9824294723385016 0.6390635485705886L0.7446504992867332 0.4733643097729175L0.31028858071607296 0.47578021640899115L0.1208702146816024 0.5481452483973847L0 0.6616669755788906",7:"M0 0L1 0L0.9246479649697582 0.030539772727272752L0.8850302419354837 0.05075757575757579L0.7922946068548385 0.11079545454545457L0.7419268208165322 0.15213068181818185L0.6907258064516127 0.20202020202020204L0.6400666267641127 0.26122159090909086L0.5913243447580644 0.33049242424242414L0.5458740234374998 0.4105902777777778L0.5050907258064514 0.5022727272727272L0.4703495148689514 0.6062973484848484L0.43257456133442534 0.787133049242424L0.41612903225806447 1",8:"M0.5143001078924863 0L0.16007477667923162 0.10731570786949331L0.14924628550868277 0.3146018498698755L0.2939585848842112 0.41617921794558677L0.8648302624811545 0.5385163833653317L1 0.7775820770511038L0.8180842915260376 0.9505845566922285L0.41968938540525413 1L0.08062381919779889 0.882831681184498L0 0.6936376947135333L0.17150171673893433 0.5188652309607817L0.6529263782780712 0.4242818653203618L0.8650205888491803 0.29644027376796367L0.8702067371119496 0.09910067291661573L0.5143001078924863 0",9:"M1 0.25379591792994305L0.9514789771111742 0.11679361536614272L0.8702482473521467 0.05711741614054847L0.7327445265851579 0.015213872471965633L0.525248180711544 0L0.3292056884418538 0.012928195113745608L0.15997632037247655 0.058762870026191856L0.05266940041228321 0.12882439350476L0 0.2562067822770946L0.11316462894512366 0.4121335905917837L0.2403060136479954 0.4603365890068938L0.4097241967586011 0.4745978388276783L0.8642414300184816 0.420815170259988L0.9732054796346318 0.34537434075898393L1 0.25379591792994305M0.9647426784191072 0.35488595400360495L0.4756895081034974 1",A:"M0 1L0.4808333333333333 0L1 1M0.24250000000000002 0.6099439775910365L0.7341666666666666 0.6099439775910365",B:"M0 1L0 0.0117369978777208L0.30665717153513444 0L0.5874522807082946 0.03451403469442413L0.7766202217193218 0.15033936404895643L0.7471969743588041 0.31967962568332936L0.5246013359741988 0.4102978954282461L0.04378745314885416 0.44918617613783574L0.5112949594180156 0.469692928091109L0.8540266515643348 0.5552749498651879L1 0.6868463175009967L0.9880091196159324 0.8570018204672155L0.922301719975498 0.9321708046604659L0.7584266951758925 0.9932594737131338L0 1",C:"M1 0.23038928858890784L0.9328355511865092 0.12426412616785204L0.8096380839483327 0.04912601676267708L0.5763225801788256 0L0.4039037709527492 0.015028068281399815L0.2519579390951737 0.06533979308999706L0.10359458463139784 0.18146243506591617L0 0.4862728453971315L0.08129580872733055 0.792689266886982L0.20257034847159672 0.9160822255736587L0.3286572892798542 0.9738230826074175L0.5742878414421707 1L0.7883510303801312 0.9665431511195721L0.946851033994232 0.8689071500976585L1 0.7311049027121912",D:"M0 1L0.015604366822624637 0.020770988281483303L0.22564758265176144 0L0.3865476147957666 0.0024153386496795644L0.6479126635475078 0.051745644338731314L0.841191887805517 0.15827717679529366L0.9517008345536152 0.30172260586872185L0.9957536578687336 0.4504541551987709L1 0.5624359222498485L0.9798483279164735 0.6584121775234548L0.9386273319285215 0.7395945263504481L0.806292129480815 0.8624239259880274L0.6296239151398265 0.9406169638094516L0.3397492767598845 0.9954164354263132L0 1",E:"M0 0L0 1M0 0L1 0M0 0.5L0.7 0.5M0 1L1 1",F:"M0 0L0 1M0.011363636363636364 0.006802721088435374L1 0.006802721088435374M0.011363636363636364 0.4965986394557823L0.8409090909090909 0.4965986394557823",G:"M0.902666857540557 0.03860785012651126L0.6504261864675637 0L0.3838947267237336 0.015442305268228053L0.21293332876776194 0.07706794377239819L0.07799659974941617 0.1994951236187481L0 0.46380381528937314L0.04159964421546915 0.7502491408002389L0.13176692977834842 0.8535497868383203L0.2709176262273927 0.936767572377719L0.4386472596876406 0.9891638569283179L0.6145513562841309 1L0.7782254421419019 0.9585373611026471L0.9092650433859927 0.8540372997461425L1 0.5556012645283437L0.5583959277303046 0.55491741080559",H:"M0 0L0 1M0 0.4788732394366197L0.989010989010989 0.4788732394366197M1 0L1 1",I:"M0.5 0L0.5 1",J:"M0.9976457238788704 0L1 0.7396412315872798L0.9773931362096968 0.8322033314977973L0.9345115952458736 0.882296255506608L0.8743862896259549 0.9221331222466961L0.8024024079884948 0.9526431718061675L0.6443996712151668 0.9893997797356828L0.5035848940343224 1L0.3127211130319937 0.9877004749449337L0.17201910858386513 0.9539509911894274L0.10357419806379677 0.9212555066079295L0.053656568662899015 0.8816079295154184L0.020759483663648916 0.8360407488986785L0.003376206348523566 0.7855864537444934L0 0.7312775330396476",K:"M0 0L0 1M0.8787878787878788 0.06666666666666667L0 0.6148148148148148M0.3333333333333333 0.45925925925925926L1 0.9777777777777777",L:"M0 0L0 1L1 1",M:"M0 1L0 0L0.5 0.6512L1 0L1 1",N:"M0 1L0 0L1 1L0.9803729146221786 0",O:"M0.4718499217948183 1L0.2896765846490613 0.9606979309189402L0.12315162147934663 0.8411184486080473L0 0.4352399966492615L0.11730398524516283 0.13145645436014852L0.2612197451988078 0.04493357858878059L0.5104071592772554 0L0.7450113425917159 0.05393013710105273L0.882367950645524 0.15242300282020502L1 0.5224527406249126L0.9414597290654386 0.7560662329321755L0.8371289514446183 0.8910800547287298L0.6518259868433511 0.9830452628933628L0.4718499217948183 1",P:"M0 1L0 0.018871774228013626L0.29609603495819875 0L0.5609840637427541 0.011794858892508529L0.7332142696692472 0.04353904702296349L0.8102258645858864 0.0691965055027166L0.9330504315465442 0.14445061754775845L0.9876391714147118 0.22527816445836535L1 0.3434414070631638L0.9510549958116356 0.41772808046663146L0.8746646891596713 0.45879131862541683L0.7528523813396283 0.49171525113425024L0.5766919939969619 0.5153253033973054L0.33725744877712827 0.5284469008187558L0.025622667325582785 0.529905468802775",Q:"M0.4618887943546369 0.9755918167206952L0.28356128136544534 0.9372490397450218L0.12055179272160406 0.8205882753548176L0 0.4246165790405623L0.1148276047430244 0.12824784112887844L0.25570518844754375 0.043836831567190586L0.49963205786237674 0L0.7292835601228574 0.0526138004304122L0.8637404608452104 0.14870263423138746L0.9788892040030622 0.5097006183769648L0.9215847647858059 0.7376120297474734L0.8194564929275405 0.869330409436378L0.6380654214095985 0.9590509139448092L0.4618887943546369 0.9755918167206952M0.5824181120212351 0.6861805006946525L1 1",R:"M0 0.9928375167236815L0 0.02590227442068435L0.3611517274211098 0L0.6146286724700761 0.008660554424468435L0.7675462459194776 0.035269459580494614L0.831839975516866 0.056961676692569484L0.8847592491838954 0.08519560521497332L0.9238557535364527 0.120683646438422L0.9583303225312839 0.21691797435320384L0.955092470586235 0.3022616904894429L0.9198097669001631 0.3640573439322699L0.8564862239866702 0.40639258627024005L0.7691258543593579 0.43335506909190874L0.601775027203482 0.4539166070813109L0.023939064200217658 0.46997623755243123M0.5038084874863982 0.5108023922274467L1 1",S:"M0.8886929689221953 0.15146982162688968L0.7276173683050475 0.013780286031594946L0.34582323121005076 0L0.1318235250900008 0.09920162734298861L0.0444543935052531 0.2811287071349243L0.08064065829108809 0.3709571405906485L0.21603115127470426 0.4485505768228281L0.7525409135992945 0.5111160926769565L0.9330263665417677 0.5850732219351329L1 0.7129938124702524L0.9117772389978691 0.9130572743138187L0.6423187128058188 1L0.29586019579751677 0.9935291584506244L0.10638454191462794 0.9229845198431584L0 0.7570771288048773",T:"M0 0L1 0M0.5148514851485149 0L0.5148514851485149 1",U:"M0 0L0.0023103778751369115 0.5467447428390111L0.01823032542100219 0.6954785891481812L0.05895528135268338 0.8056480226151669L0.13703402031421133 0.8894445726483398L0.23918400876232196 0.9448524533417946L0.3917887458926616 0.9848674531975652L0.584341627875137 1L0.7194816196604602 0.9848501456716763L0.8303268115073934 0.9449411544119768L0.8966613970084885 0.898186315516197L0.9251437568455642 0.867453197565408L0.9687114937020809 0.7890904895145239L0.9890470974808324 0.6852857184065537L1 0.0014769088758762145",V:"M0 0L0.5348837209302325 1L1 0",W:"M0 0L0.23300090661831369 0.9873417721518988L0.49954669084315495 0.30081906180193585L0.7851314596554849 1L1 0.0215934475055845",X:"M0 0L0.9893617021276596 1M1 0L0.010638297872340425 1",Y:"M0 0L0.4860515021459227 0.44712562100780695M1 0.0014194464158977947L0.48927038626609437 0.44996451383960256L0.5075107296137339 1",Z:"M0 0L1 0L0 1L1 1",a:"M0.900 0.517L0.900 1.000M0.900 0.620L0.766 0.551L0.634 0.517L0.434 0.517L0.300 0.551L0.166 0.620L0.100 0.724L0.100 0.793L0.166 0.896L0.300 0.965L0.434 1.000L0.634 1.000L0.766 0.965L0.900 0.896",b:"M0.100 0.275L0.100 1.000M0.100 0.620L0.234 0.551L0.366 0.517L0.566 0.517L0.700 0.551L0.834 0.620L0.900 0.724L0.900 0.793L0.834 0.896L0.700 0.965L0.566 1.000L0.366 1.000L0.234 0.965L0.100 0.896",c:"M0.900 0.620L0.766 0.551L0.634 0.517L0.434 0.517L0.300 0.551L0.166 0.620L0.100 0.724L0.100 0.793L0.166 0.896L0.300 0.965L0.434 1.000L0.634 1.000L0.766 0.965L0.900 0.896",d:"M0.900 0.275L0.900 1.000M0.900 0.620L0.766 0.551L0.634 0.517L0.434 0.517L0.300 0.551L0.166 0.620L0.100 0.724L0.100 0.793L0.166 0.896L0.300 0.965L0.434 1.000L0.634 1.000L0.766 0.965L0.900 0.896",e:"M0.100 0.724L0.900 0.724M0.900 0.655L0.834 0.586L0.766 0.551L0.634 0.517L0.434 0.517L0.300 0.551L0.166 0.620L0.100 0.724L0.100 0.793L0.166 0.896L0.300 0.965L0.434 1.000L0.634 1.000L0.766 0.965L0.900 0.896",f:"M0.900 0.275L0.700 0.275L0.500 0.310L0.400 0.413L0.400 1.000M0.100 0.517L0.800 0.517",g:"M0.900 0.516L0.900 1.068L0.834 1.171L0.766 1.206L0.634 1.240L0.434 1.240L0.300 1.206L0.166 1.137L0.100 1.033M0.900 0.619L0.766 0.550L0.634 0.516L0.434 0.516L0.300 0.550L0.166 0.619L0.100 0.723L0.100 0.792L0.166 0.895L0.300 0.964L0.434 0.999L0.634 0.999L0.766 0.964L0.900 0.895",h:"M0.100 0.275L0.100 1.000M0.100 0.655L0.318 0.551L0.464 0.517L0.682 0.517L0.827 0.551L0.900 0.655L0.900 1.000",i:"M0.466 0.275L0.534 0.275M0.500 0.517L0.500 1.000",j:"M0.634 0.274L0.766 0.274M0.700 0.516L0.700 1.102L0.634 1.206L0.366 1.240L0.166 1.206",k:"M0.100 0.275L0.100 1.000M0.827 0.517L0.100 0.862M0.391 0.724L0.900 1.000",l:"M0.5 0.275L0.5 1.000",m:"M0.100 0.517L0.100 1.000M0.100 0.655L0.209 0.551L0.282 0.517L0.418 0.517L0.491 0.551L0.564 0.655L0.564 1.000M0.564 0.655L0.673 0.551L0.745 0.517L0.882 0.517L0.955 0.551L0.955 1.000",n:"M0.100 0.517L0.100 1.000M0.100 0.655L0.318 0.551L0.464 0.517L0.682 0.517L0.827 0.551L0.900 0.655L0.900 1.000",o:"M0.408 0.517L0.285 0.551L0.162 0.620L0.100 0.724L0.100 0.793L0.162 0.896L0.285 0.965L0.408 1.000L0.592 1.000L0.715 0.965L0.838 0.896L0.900 0.793L0.900 0.724L0.838 0.620L0.715 0.551L0.592 0.517L0.408 0.517",p:"M0.100 0.516L0.100 1.240M0.100 0.619L0.234 0.550L0.366 0.516L0.566 0.516L0.700 0.550L0.834 0.619L0.900 0.723L0.900 0.792L0.834 0.895L0.700 0.964L0.566 0.999L0.366 0.999L0.234 0.964L0.100 0.895",q:"M0.900 0.516L0.900 1.240M0.900 0.619L0.766 0.550L0.634 0.516L0.434 0.516L0.300 0.550L0.166 0.619L0.100 0.723L0.100 0.792L0.166 0.895L0.300 0.964L0.434 0.999L0.634 0.999L0.766 0.964L0.900 0.895",r:"M0.100 0.517L0.100 1.000M0.100 0.724L0.200 0.620L0.400 0.551L0.600 0.517L0.900 0.517",s:"M0.850 0.551L0.700 0.517L0.450 0.517L0.250 0.551L0.100 0.620L0.100 0.689L0.250 0.724L0.500 0.724L0.750 0.793L0.900 0.862L0.900 0.931L0.750 0.965L0.550 1.000L0.300 1.000L0.150 0.965L0.100 0.896",t:"M0.400 0.275L0.400 0.862L0.500 0.965L0.700 1.000L0.900 1.000M0.100 0.517L0.800 0.517",u:"M0.100 0.517L0.100 0.862L0.173 0.965L0.318 1.000L0.536 1.000L0.682 0.965L0.900 0.862M0.900 0.517L0.900 1.000",v:"M0.100 0.517L0.500 1.000M0.900 0.517L0.500 1.000",w:"M0.100 0.517L0.300 1.000M0.500 0.517L0.300 1.000M0.500 0.517L0.700 1.000M0.900 0.517L0.700 1.000",x:"M0.100 0.517L0.900 1.000M0.900 0.517L0.100 1.000",y:"M0.162 0.516L0.530 0.999M0.900 0.516L0.530 0.999L0.408 1.137L0.285 1.206L0.162 1.240L0.100 1.240",z:"M0.900 0.517L0.100 1.000M0.100 0.517L0.900 0.517M0.100 1.000L0.900 1.000",".":"M 0.49 1 L 0.41 1","!":"M0.5 0L0.5 0.6M0.49 0.85L0.51 0.85",",":"M0.55 0.85L0.45 0.95L0.5 1","*":"M 0.5 0.25 L 0.8 0.25 M 0.5 0.25 L 0.5927 0.4402 M 0.5 0.25 L 0.2573 0.3676 M 0.5 0.25 L 0.2573 0.1324 M 0.5 0.25 L 0.599 0.055","(":"M0.75 0L0.25 0.5L0.25 0.5L0.75 1",")":"M0.25 0L0.75 0.5L0.75 0.5L0.25 1","-":"M0 0.5L1 0.5","+":"M 0 0.5 L 1 0.5 M 0.5 0.125 L 0.5 0.875","=":"M0 0.25L1 0.25M0 0.75L1 0.75",_:"M0 1 L1 1","[":"M0.75 0L0.25 0L0.25 1L0.75 1","]":"M0.25 0L0.75 0L0.75 1L0.25 1","<":"M0.75 0L0.25 0.5L0.25 0.5L0.75 1",">":"M0.25 0L0.75 0.5L0.75 0.5L0.25 1","'":"M 0.5 0 L 0.5 0.5",'"':"M 0.25 0 L 0.25 0.5 M 0.75 0 L 0.75 0.5","/":"M0 1L1 0","\\":"M0 0L1 1"},jw={};for(const e in h9A){jw[e]=[];const A=h9A[e].split("M").slice(1).map(t=>t.split("L").map(i=>i.trim().split(" ").map(parseFloat)));for(const t of A)for(let i=0;i<t.length-1;i++)jw[e].push({x1:t[i][0],y1:1-t[i][1],x2:t[i+1][0],y2:1-t[i+1][1]})}function Mce(e,A){if(!A.layers||A.layers.length===0)return!0;const t=sNA(e);return t.length===0?!0:t.some(i=>A.layers.includes(i))}var Nce={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:"#FF00FF",keepout:"#FF6B6B"};function Lu(e){const{ctx:A,center:t,radius:i,fill:o,realToCanvasMat:n}=e,[s,r]=Pe(n,[t.x,t.y]),a=i*Math.abs(n.a);A.beginPath(),A.arc(s,r,a,0,Math.PI*2),A.fillStyle=o,A.fill()}function lI(e){const{ctx:A,center:t,width:i,height:o,fill:n,realToCanvasMat:s,borderRadius:r=0,rotation:a=0,stroke:g,strokeWidth:I,isStrokeDashed:c=!1}=e,[B,l]=Pe(s,[t.x,t.y]),C=i*Math.abs(s.a),E=o*Math.abs(s.a),Q=r*Math.abs(s.a),h=I?I*Math.abs(s.a):void 0;if(A.save(),A.translate(B,l),a!==0&&A.rotate(-a*(Math.PI/180)),A.beginPath(),Q>0){const u=-C/2,d=-E/2,f=Math.min(Q,C/2,E/2);A.moveTo(u+f,d),A.lineTo(u+C-f,d),A.arcTo(u+C,d,u+C,d+f,f),A.lineTo(u+C,d+E-f),A.arcTo(u+C,d+E,u+C-f,d+E,f),A.lineTo(u+f,d+E),A.arcTo(u,d+E,u,d+E-f,f),A.lineTo(u,d+f),A.arcTo(u,d,u+f,d,f)}else A.rect(-C/2,-E/2,C,E);n&&(A.fillStyle=n,A.fill()),g&&h&&(c?A.setLineDash([h*3,h*2]):A.setLineDash([]),A.strokeStyle=g,A.lineWidth=h,A.stroke()),A.restore()}function WS(e){const{ctx:A,center:t,radius_x:i,radius_y:o,fill:n,stroke:s,strokeWidth:r=.1,realToCanvasMat:a,rotation:g=0}=e,[I,c]=Pe(a,[t.x,t.y]),B=i*Math.abs(a.a),l=o*Math.abs(a.a),C=r*Math.abs(a.a);A.save(),A.translate(I,c),g!==0&&A.rotate(-g*(Math.PI/180)),A.beginPath(),A.ellipse(0,0,B,l,0,0,Math.PI*2),n&&(A.fillStyle=n,A.fill()),s&&(A.strokeStyle=s,A.lineWidth=C,A.stroke()),A.restore()}function Wl(e){const{ctx:A,center:t,width:i,height:o,fill:n,realToCanvasMat:s,rotation:r=0,stroke:a,strokeWidth:g}=e,[I,c]=Pe(s,[t.x,t.y]),B=i*Math.abs(s.a),l=o*Math.abs(s.a),C=g?g*Math.abs(s.a):void 0;if(A.save(),A.translate(I,c),r!==0&&A.rotate(-r*(Math.PI/180)),A.beginPath(),B>l){const E=l/2,Q=B-l;A.moveTo(-Q/2,-E),A.lineTo(Q/2,-E),A.arc(Q/2,0,E,-Math.PI/2,Math.PI/2),A.lineTo(-Q/2,E),A.arc(-Q/2,0,E,Math.PI/2,-Math.PI/2)}else if(l>B){const E=B/2,Q=l-B;A.moveTo(E,-Q/2),A.lineTo(E,Q/2),A.arc(0,Q/2,E,0,Math.PI),A.lineTo(-E,-Q/2),A.arc(0,-Q/2,E,Math.PI,0)}else A.arc(0,0,B/2,0,Math.PI*2);A.closePath(),n&&(A.fillStyle=n,A.fill()),a&&C&&(A.strokeStyle=a,A.lineWidth=C,A.stroke()),A.restore()}function i_(e){const{ctx:A,points:t,fill:i,realToCanvasMat:o}=e;if(t.length<3)return;A.beginPath();const n=t.map(g=>Pe(o,[g.x,g.y])),s=n[0];if(!s)return;const[r,a]=s;A.moveTo(r,a);for(let g=1;g<n.length;g++){const I=n[g];if(!I)continue;const[c,B]=I;A.lineTo(c,B)}A.closePath(),A.fillStyle=i,A.fill()}function vG(e,A,t,i,o,n,s,r,a,g){const[I,c]=Pe(r,[A.x,A.y]),B=t*Math.abs(r.a),l=i*Math.abs(r.a),C=Math.abs(o)*Math.abs(r.a),E=n*Math.abs(r.a);e.save(),e.translate(I,c),s!==0&&e.rotate(-s*(Math.PI/180));const Q=e.globalCompositeOperation;e.globalCompositeOperation!==void 0&&(e.globalCompositeOperation="source-atop");const h=B,u=l,d=E;if(e.beginPath(),d>0){const w=-h/2,b=-u/2,k=Math.min(d,h/2,u/2);e.moveTo(w+k,b),e.lineTo(w+h-k,b),e.arcTo(w+h,b,w+h,b+k,k),e.lineTo(w+h,b+u-k),e.arcTo(w+h,b+u,w+h-k,b+u,k),e.lineTo(w+k,b+u),e.arcTo(w,b+u,w,b+u-k,k),e.lineTo(w,b+k),e.arcTo(w,b,w+k,b,k)}else e.rect(-h/2,-u/2,h,u);e.fillStyle=a,e.fill(),e.globalCompositeOperation!==void 0&&(e.globalCompositeOperation=Q||"source-over");const f=B-C*2,m=l-C*2,D=Math.max(0,E-C);if(f>0&&m>0){if(e.beginPath(),D>0){const w=-f/2,b=-m/2,k=Math.min(D,f/2,m/2);e.moveTo(w+k,b),e.lineTo(w+f-k,b),e.arcTo(w+f,b,w+f,b+k,k),e.lineTo(w+f,b+m-k),e.arcTo(w+f,b+m,w+f-k,b+m,k),e.lineTo(w+k,b+m),e.arcTo(w,b+m,w,b+m-k,k),e.lineTo(w,b+k),e.arcTo(w,b,w+k,b,k)}else e.rect(-f/2,-m/2,f,m);e.fillStyle=g,e.fill()}e.restore()}function IQA(e,A,t,i,o,n,s){const[r,a]=Pe(o,[A.x,A.y]),g=t*Math.abs(o.a),I=Math.abs(i)*Math.abs(o.a);e.save();const c=e.globalCompositeOperation;e.globalCompositeOperation!==void 0&&(e.globalCompositeOperation="source-atop"),e.beginPath(),e.arc(r,a,g,0,Math.PI*2),e.fillStyle=n,e.fill(),e.globalCompositeOperation!==void 0&&(e.globalCompositeOperation=c||"source-over");const B=Math.max(0,g-I);B>0&&(e.beginPath(),e.arc(r,a,B,0,Math.PI*2),e.fillStyle=s,e.fill()),e.restore()}function NU(e,A,t,i,o,n,s,r,a){const[g,I]=Pe(s,[A.x,A.y]),c=t*Math.abs(s.a),B=i*Math.abs(s.a),l=Math.abs(o)*Math.abs(s.a);e.save(),e.translate(g,I),n!==0&&e.rotate(-n*(Math.PI/180));const C=e.globalCompositeOperation;e.globalCompositeOperation!==void 0&&(e.globalCompositeOperation="source-atop");const E=c,Q=B;if(e.beginPath(),E>Q){const d=Q/2,f=E-Q;e.moveTo(-f/2,-d),e.lineTo(f/2,-d),e.arc(f/2,0,d,-Math.PI/2,Math.PI/2),e.lineTo(-f/2,d),e.arc(-f/2,0,d,Math.PI/2,-Math.PI/2)}else if(Q>E){const d=E/2,f=Q-E;e.moveTo(d,-f/2),e.lineTo(d,f/2),e.arc(0,f/2,d,0,Math.PI),e.lineTo(-d,-f/2),e.arc(0,-f/2,d,Math.PI,0)}else e.arc(0,0,E/2,0,Math.PI*2);e.fillStyle=r,e.fill(),e.globalCompositeOperation!==void 0&&(e.globalCompositeOperation=C||"source-over");const h=c-l*2,u=B-l*2;if(h>0&&u>0){if(e.beginPath(),h>u){const d=u/2,f=h-u;e.moveTo(-f/2,-d),e.lineTo(f/2,-d),e.arc(f/2,0,d,-Math.PI/2,Math.PI/2),e.lineTo(-f/2,d),e.arc(-f/2,0,d,Math.PI/2,-Math.PI/2)}else if(u>h){const d=h/2,f=u-h;e.moveTo(d,-f/2),e.lineTo(d,f/2),e.arc(0,f/2,d,0,Math.PI),e.lineTo(-d,-f/2),e.arc(0,-f/2,d,Math.PI,0)}else e.arc(0,0,h/2,0,Math.PI*2);e.fillStyle=a,e.fill()}e.restore()}function u9A(e,A,t,i,o,n,s,r,a){const[g,I]=Pe(s,[A.x,A.y]),c=t*Math.abs(s.a),B=i*Math.abs(s.a),l=Math.abs(o)*Math.abs(s.a);e.save(),e.translate(g,I),n!==0&&e.rotate(-n*(Math.PI/180));const C=e.globalCompositeOperation;e.globalCompositeOperation!==void 0&&(e.globalCompositeOperation="source-atop"),e.beginPath(),e.ellipse(0,0,c,B,0,0,Math.PI*2),e.fillStyle=r,e.fill(),e.globalCompositeOperation!==void 0&&(e.globalCompositeOperation=C||"source-over");const E=Math.max(0,c-l),Q=Math.max(0,B-l);E>0&&Q>0&&(e.beginPath(),e.ellipse(0,0,E,Q,0,0,Math.PI*2),e.fillStyle=a,e.fill()),e.restore()}function cQA(e,A){if(e.length<3||A===0)return e;let t=0,i=0;for(const n of e)t+=n.x,i+=n.y;t/=e.length,i/=e.length;const o=[];for(const n of e){const s=n.x-t,r=n.y-i,a=Math.sqrt(s*s+r*r);if(a>0){const g=s/a,I=r/a;o.push({x:n.x+g*A,y:n.y+I*A})}else o.push({x:n.x+A,y:n.y})}return o}function d9A(e,A,t,i,o,n){if(A.length<3||t>=0)return;Math.abs(t)*Math.abs(i.a);const s=e.globalCompositeOperation;e.globalCompositeOperation!==void 0&&(e.globalCompositeOperation="source-atop"),e.beginPath();const r=A.map(I=>Pe(i,[I.x,I.y])),a=r[0];if(a){const[I,c]=a;e.moveTo(I,c);for(let B=1;B<r.length;B++){const l=r[B];if(l){const[C,E]=l;e.lineTo(C,E)}}e.closePath(),e.fillStyle=o,e.fill()}e.globalCompositeOperation!==void 0&&(e.globalCompositeOperation=s||"source-over");const g=cQA(A,t);if(g.length>=3){e.beginPath();const I=g.map(B=>Pe(i,[B.x,B.y])),c=I[0];if(c){const[B,l]=c;e.moveTo(B,l);for(let C=1;C<I.length;C++){const E=I[C];if(E){const[Q,h]=E;e.lineTo(Q,h)}}e.closePath(),e.fillStyle=n,e.fill()}}e.restore()}function vce(e,A){const t=e?.includes("top")?"top":"bottom";return A.soldermaskOverCopper[t]??A.soldermaskOverCopper.top}function Lce(e){const{ctx:A,hole:t,realToCanvasMat:i,colorMap:o}=e,n=t.is_covered_with_solder_mask===!0,s=n?0:t.soldermask_margin??0,r=!n&&t.soldermask_margin!==void 0&&t.soldermask_margin!==0,a=vce(t.layers,o),g=o.substrate,I=o.copper.top;if(t.shape==="circle"){r&&s>0&&Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.outer_diameter/2+s,fill:g,realToCanvasMat:i}),Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.outer_diameter/2,fill:I,realToCanvasMat:i}),r&&s<0&&IQA(A,{x:t.x,y:t.y},t.outer_diameter/2,s,i,a,I),n&&Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.outer_diameter/2,fill:a,realToCanvasMat:i}),n||Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.hole_diameter/2,fill:o.drill,realToCanvasMat:i});return}if(t.shape==="oval"){r&&s>0&&WS({ctx:A,center:{x:t.x,y:t.y},radius_x:t.outer_width/2+s,radius_y:t.outer_height/2+s,fill:g,realToCanvasMat:i,rotation:t.ccw_rotation}),WS({ctx:A,center:{x:t.x,y:t.y},radius_x:t.outer_width/2,radius_y:t.outer_height/2,fill:I,realToCanvasMat:i,rotation:t.ccw_rotation}),r&&s<0&&u9A(A,{x:t.x,y:t.y},t.outer_width/2,t.outer_height/2,s,t.ccw_rotation??0,i,a,I),n&&WS({ctx:A,center:{x:t.x,y:t.y},radius_x:t.outer_width/2,radius_y:t.outer_height/2,fill:a,realToCanvasMat:i,rotation:t.ccw_rotation}),n||WS({ctx:A,center:{x:t.x,y:t.y},radius_x:t.hole_width/2,radius_y:t.hole_height/2,fill:o.drill,realToCanvasMat:i,rotation:t.ccw_rotation});return}if(t.shape==="pill"){r&&s>0&&Wl({ctx:A,center:{x:t.x,y:t.y},width:t.outer_width+s*2,height:t.outer_height+s*2,fill:g,realToCanvasMat:i,rotation:t.ccw_rotation}),Wl({ctx:A,center:{x:t.x,y:t.y},width:t.outer_width,height:t.outer_height,fill:I,realToCanvasMat:i,rotation:t.ccw_rotation}),r&&s<0&&NU(A,{x:t.x,y:t.y},t.outer_width,t.outer_height,s,t.ccw_rotation??0,i,a,I),n&&Wl({ctx:A,center:{x:t.x,y:t.y},width:t.outer_width,height:t.outer_height,fill:a,realToCanvasMat:i,rotation:t.ccw_rotation}),n||Wl({ctx:A,center:{x:t.x,y:t.y},width:t.hole_width,height:t.hole_height,fill:o.drill,realToCanvasMat:i,rotation:t.ccw_rotation});return}if(t.shape==="circular_hole_with_rect_pad"){if(r&&s>0&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.rect_pad_width+s*2,height:t.rect_pad_height+s*2,fill:g,realToCanvasMat:i,borderRadius:t.rect_border_radius??0}),lI({ctx:A,center:{x:t.x,y:t.y},width:t.rect_pad_width,height:t.rect_pad_height,fill:I,realToCanvasMat:i,borderRadius:t.rect_border_radius??0}),r&&s<0&&vG(A,{x:t.x,y:t.y},t.rect_pad_width,t.rect_pad_height,s,t.rect_border_radius??0,0,i,a,I),n&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.rect_pad_width,height:t.rect_pad_height,fill:a,realToCanvasMat:i,borderRadius:t.rect_border_radius??0}),!n){const c=t.x+(t.hole_offset_x??0),B=t.y+(t.hole_offset_y??0);Lu({ctx:A,center:{x:c,y:B},radius:t.hole_diameter/2,fill:o.drill,realToCanvasMat:i})}return}if(t.shape==="pill_hole_with_rect_pad"){if(r&&s>0&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.rect_pad_width+s*2,height:t.rect_pad_height+s*2,fill:g,realToCanvasMat:i,borderRadius:t.rect_border_radius??0}),lI({ctx:A,center:{x:t.x,y:t.y},width:t.rect_pad_width,height:t.rect_pad_height,fill:I,realToCanvasMat:i,borderRadius:t.rect_border_radius??0}),r&&s<0&&vG(A,{x:t.x,y:t.y},t.rect_pad_width,t.rect_pad_height,s,t.rect_border_radius??0,0,i,a,I),n&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.rect_pad_width,height:t.rect_pad_height,fill:a,realToCanvasMat:i,borderRadius:t.rect_border_radius??0}),!n){const c=t.x+(t.hole_offset_x??0),B=t.y+(t.hole_offset_y??0);Wl({ctx:A,center:{x:c,y:B},width:t.hole_width,height:t.hole_height,fill:o.drill,realToCanvasMat:i})}return}if(t.shape==="rotated_pill_hole_with_rect_pad"){if(r&&s>0&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.rect_pad_width+s*2,height:t.rect_pad_height+s*2,fill:g,realToCanvasMat:i,borderRadius:t.rect_border_radius??0,rotation:t.rect_ccw_rotation}),lI({ctx:A,center:{x:t.x,y:t.y},width:t.rect_pad_width,height:t.rect_pad_height,fill:I,realToCanvasMat:i,borderRadius:t.rect_border_radius??0,rotation:t.rect_ccw_rotation}),r&&s<0&&vG(A,{x:t.x,y:t.y},t.rect_pad_width,t.rect_pad_height,s,t.rect_border_radius??0,t.rect_ccw_rotation??0,i,a,I),n&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.rect_pad_width,height:t.rect_pad_height,fill:a,realToCanvasMat:i,borderRadius:t.rect_border_radius??0,rotation:t.rect_ccw_rotation}),!n){const c=t.x+(t.hole_offset_x??0),B=t.y+(t.hole_offset_y??0);Wl({ctx:A,center:{x:c,y:B},width:t.hole_width,height:t.hole_height,fill:o.drill,realToCanvasMat:i,rotation:t.hole_ccw_rotation})}return}if(t.shape==="hole_with_polygon_pad"){const c=t.pad_outline;if(c&&c.length>=3){const B=c.map(l=>({x:t.x+l.x,y:t.y+l.y}));if(r&&s>0){const l=cQA(B,s);i_({ctx:A,points:l,fill:g,realToCanvasMat:i})}i_({ctx:A,points:B,fill:I,realToCanvasMat:i}),r&&s<0&&d9A(A,B,s,i,a,I),n&&i_({ctx:A,points:B,fill:a,realToCanvasMat:i})}if(!n){const B=t.x+(t.hole_offset_x??0),l=t.y+(t.hole_offset_y??0),C=t.hole_shape;C==="circle"?Lu({ctx:A,center:{x:B,y:l},radius:(t.hole_diameter??0)/2,fill:o.drill,realToCanvasMat:i}):C==="oval"?WS({ctx:A,center:{x:B,y:l},radius_x:(t.hole_width??0)/2,radius_y:(t.hole_height??0)/2,fill:o.drill,realToCanvasMat:i}):C==="pill"?Wl({ctx:A,center:{x:B,y:l},width:t.hole_width??0,height:t.hole_height??0,fill:o.drill,realToCanvasMat:i}):C==="rotated_pill"&&Wl({ctx:A,center:{x:B,y:l},width:t.hole_width??0,height:t.hole_height??0,fill:o.drill,realToCanvasMat:i})}return}}function Uce(e){const{ctx:A,via:t,realToCanvasMat:i,colorMap:o}=e;Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.outer_diameter/2,fill:o.copper.top,realToCanvasMat:i}),Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.hole_diameter/2,fill:o.drill,realToCanvasMat:i})}function vU(e){return"ccw_rotation"in e&&typeof e.ccw_rotation=="number"?e.ccw_rotation:0}function Hce(e){const{ctx:A,hole:t,realToCanvasMat:i,colorMap:o}=e,n=t.is_covered_with_solder_mask===!0,s=n?0:t.soldermask_margin??0,r=!n&&t.soldermask_margin!==void 0&&t.soldermask_margin!==0,a=o.substrate,g=o.soldermaskOverCopper.top,I=o.soldermaskOverCopper.top;if(t.hole_shape==="circle"){r&&s>0&&Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.hole_diameter/2+s,fill:a,realToCanvasMat:i}),n||(Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.hole_diameter/2,fill:o.drill,realToCanvasMat:i}),r&&s<0&&IQA(A,{x:t.x,y:t.y},t.hole_diameter/2,s,i,I,o.drill)),n&&Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.hole_diameter/2,fill:g,realToCanvasMat:i});return}if(t.hole_shape==="square"){const c=vU(t);r&&s>0&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.hole_diameter+s*2,height:t.hole_diameter+s*2,fill:a,realToCanvasMat:i,rotation:c}),n||(lI({ctx:A,center:{x:t.x,y:t.y},width:t.hole_diameter,height:t.hole_diameter,fill:o.drill,realToCanvasMat:i,rotation:c}),r&&s<0&&vG(A,{x:t.x,y:t.y},t.hole_diameter,t.hole_diameter,s,0,c,i,I,o.drill)),n&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.hole_diameter,height:t.hole_diameter,fill:g,realToCanvasMat:i,rotation:c});return}if(t.hole_shape==="oval"){const c=vU(t);r&&s>0&&WS({ctx:A,center:{x:t.x,y:t.y},radius_x:t.hole_width/2+s,radius_y:t.hole_height/2+s,fill:a,realToCanvasMat:i,rotation:c}),n||(WS({ctx:A,center:{x:t.x,y:t.y},radius_x:t.hole_width/2,radius_y:t.hole_height/2,fill:o.drill,realToCanvasMat:i,rotation:c}),r&&s<0&&u9A(A,{x:t.x,y:t.y},t.hole_width/2,t.hole_height/2,s,c,i,I,o.drill)),n&&WS({ctx:A,center:{x:t.x,y:t.y},radius_x:t.hole_width/2,radius_y:t.hole_height/2,fill:g,realToCanvasMat:i,rotation:c});return}if(t.hole_shape==="rect"){const c=vU(t);r&&s>0&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.hole_width+s*2,height:t.hole_height+s*2,fill:a,realToCanvasMat:i,rotation:c}),n||(lI({ctx:A,center:{x:t.x,y:t.y},width:t.hole_width,height:t.hole_height,fill:o.drill,realToCanvasMat:i,rotation:c}),r&&s<0&&vG(A,{x:t.x,y:t.y},t.hole_width,t.hole_height,s,0,c,i,I,o.drill)),n&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.hole_width,height:t.hole_height,fill:g,realToCanvasMat:i,rotation:c});return}if(t.hole_shape==="pill"){const c=vU(t);r&&s>0&&Wl({ctx:A,center:{x:t.x,y:t.y},width:t.hole_width+s*2,height:t.hole_height+s*2,fill:a,realToCanvasMat:i,rotation:c}),n||(Wl({ctx:A,center:{x:t.x,y:t.y},width:t.hole_width,height:t.hole_height,fill:o.drill,realToCanvasMat:i,rotation:c}),r&&s<0&&NU(A,{x:t.x,y:t.y},t.hole_width,t.hole_height,s,c,i,I,o.drill)),n&&Wl({ctx:A,center:{x:t.x,y:t.y},width:t.hole_width,height:t.hole_height,fill:g,realToCanvasMat:i,rotation:c});return}if(t.hole_shape==="rotated_pill"){const c=vU(t);r&&s>0&&Wl({ctx:A,center:{x:t.x,y:t.y},width:t.hole_width+s*2,height:t.hole_height+s*2,fill:a,realToCanvasMat:i,rotation:c}),n||(Wl({ctx:A,center:{x:t.x,y:t.y},width:t.hole_width,height:t.hole_height,fill:o.drill,realToCanvasMat:i,rotation:c}),r&&s<0&&NU(A,{x:t.x,y:t.y},t.hole_width,t.hole_height,s,c,i,I,o.drill)),n&&Wl({ctx:A,center:{x:t.x,y:t.y},width:t.hole_width,height:t.hole_height,fill:g,realToCanvasMat:i,rotation:c});return}}function Yce(e,A){return A.copper[e]??A.copper.top}function p9A(e,A){return A.soldermaskOverCopper[e]??A.soldermaskOverCopper.top}function o_(e,A=0){return(e.corner_radius??e.rect_border_radius??0)+A}function Jce(e){const{ctx:A,pad:t,realToCanvasMat:i,colorMap:o}=e,n=Yce(t.layer,o),s=t.is_covered_with_solder_mask===!0,r=s?0:t.soldermask_margin??0,a=!s&&t.soldermask_margin!==void 0&&t.soldermask_margin!==0,g=p9A(t.layer,o),I=o.substrate,c=p9A(t.layer,o);if(t.shape==="rect"){a&&r>0&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.width+r*2,height:t.height+r*2,fill:I,realToCanvasMat:i,borderRadius:o_(t)}),lI({ctx:A,center:{x:t.x,y:t.y},width:t.width,height:t.height,fill:n,realToCanvasMat:i,borderRadius:o_(t)}),a&&r<0&&vG(A,{x:t.x,y:t.y},t.width,t.height,r,o_(t),0,i,g,n),s&&r===0&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.width,height:t.height,fill:c,realToCanvasMat:i,borderRadius:o_(t)});return}if(t.shape==="rotated_rect"){a&&r>0&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.width+r*2,height:t.height+r*2,fill:I,realToCanvasMat:i,borderRadius:o_(t),rotation:t.ccw_rotation??0}),lI({ctx:A,center:{x:t.x,y:t.y},width:t.width,height:t.height,fill:n,realToCanvasMat:i,borderRadius:o_(t),rotation:t.ccw_rotation??0}),a&&r<0&&vG(A,{x:t.x,y:t.y},t.width,t.height,r,o_(t),t.ccw_rotation??0,i,g,n),s&&r===0&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.width,height:t.height,fill:c,realToCanvasMat:i,borderRadius:o_(t),rotation:t.ccw_rotation??0});return}if(t.shape==="circle"){a&&r>0&&Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.radius+r,fill:I,realToCanvasMat:i}),Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.radius,fill:n,realToCanvasMat:i}),a&&r<0&&IQA(A,{x:t.x,y:t.y},t.radius,r,i,g,n),s&&r===0&&Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.radius,fill:c,realToCanvasMat:i});return}if(t.shape==="pill"){a&&r>0&&Wl({ctx:A,center:{x:t.x,y:t.y},width:t.width+r*2,height:t.height+r*2,fill:I,realToCanvasMat:i}),Wl({ctx:A,center:{x:t.x,y:t.y},width:t.width,height:t.height,fill:n,realToCanvasMat:i}),a&&r<0&&NU(A,{x:t.x,y:t.y},t.width,t.height,r,0,i,g,n),s&&r===0&&Wl({ctx:A,center:{x:t.x,y:t.y},width:t.width,height:t.height,fill:c,realToCanvasMat:i});return}if(t.shape==="rotated_pill"){a&&r>0&&Wl({ctx:A,center:{x:t.x,y:t.y},width:t.width+r*2,height:t.height+r*2,fill:I,realToCanvasMat:i,rotation:t.ccw_rotation??0}),Wl({ctx:A,center:{x:t.x,y:t.y},width:t.width,height:t.height,fill:n,realToCanvasMat:i,rotation:t.ccw_rotation??0}),a&&r<0&&NU(A,{x:t.x,y:t.y},t.width,t.height,r,t.ccw_rotation??0,i,g,n),s&&r===0&&Wl({ctx:A,center:{x:t.x,y:t.y},width:t.width,height:t.height,fill:c,realToCanvasMat:i,rotation:t.ccw_rotation??0});return}if(t.shape==="polygon"){if(t.points&&t.points.length>=3){if(a&&r>0){const B=cQA(t.points,r);i_({ctx:A,points:B,fill:I,realToCanvasMat:i})}i_({ctx:A,points:t.points,fill:n,realToCanvasMat:i}),a&&r<0&&d9A(A,t.points,r,i,g,n),s&&r===0&&i_({ctx:A,points:t.points,fill:c,realToCanvasMat:i})}return}}function LU(e){const{ctx:A,start:t,end:i,strokeWidth:o,stroke:n,realToCanvasMat:s,lineCap:r="round"}=e,[a,g]=Pe(s,[t.x,t.y]),[I,c]=Pe(s,[i.x,i.y]),B=o*Math.abs(s.a);A.beginPath(),A.moveTo(a,g),A.lineTo(I,c),A.lineWidth=B,A.strokeStyle=n,A.lineCap=r,A.stroke()}function Tce(e,A){return A.copper[e]??A.copper.top}function Kce(e){const{ctx:A,trace:t,realToCanvasMat:i,colorMap:o}=e;if(!(!t.route||!Array.isArray(t.route)||t.route.length<2))for(let n=0;n<t.route.length-1;n++){const s=t.route[n],r=t.route[n+1];if(!s||!r)continue;const a="layer"in s?s.layer:"layer"in r?r.layer:null;if(!a)continue;const g=Tce(a,o),I="width"in s?s.width:"width"in r?r.width:.1;LU({ctx:A,start:{x:s.x,y:s.y},end:{x:r.x,y:r.y},strokeWidth:I,stroke:g,realToCanvasMat:i,lineCap:"round"})}}function D8(e){const{ctx:A,points:t,fill:i,stroke:o,strokeWidth:n=1,realToCanvasMat:s,closePath:r=!1}=e;if(t.length<2)return;A.beginPath();const a=t.map(B=>Pe(s,[B.x,B.y])),g=a[0];if(!g)return;const[I,c]=g;A.moveTo(I,c);for(let B=1;B<a.length;B++){const l=a[B];if(!l)continue;const[C,E]=l;A.lineTo(C,E)}if(r&&A.closePath(),i&&(A.fillStyle=i,A.fill()),o){const B=n*Math.abs(s.a);A.strokeStyle=o,A.lineWidth=B,A.stroke()}}function Pce(e){const{ctx:A,board:t,realToCanvasMat:i,colorMap:o}=e,{width:n,height:s,center:r,outline:a}=t;if(a&&Array.isArray(a)&&a.length>=3){D8({ctx:A,points:a.map(g=>({x:g.x,y:g.y})),stroke:o.boardOutline,strokeWidth:.1,realToCanvasMat:i,closePath:!0});return}if(n!==void 0&&s!==void 0&&r){lI({ctx:A,center:r,width:n,height:s,fill:"transparent",realToCanvasMat:i});const g=n/2,I=s/2,c=[{x:r.x-g,y:r.y-I},{x:r.x+g,y:r.y-I},{x:r.x+g,y:r.y+I},{x:r.x-g,y:r.y+I}];D8({ctx:A,points:c,stroke:o.boardOutline,strokeWidth:.1,realToCanvasMat:i,closePath:!0})}}var qce=.62,Oce=.3,Wce=1,Zce=.13;function S8(e,A){const t=A*qce,i=t*Oce,o=t*Wce,n=Array.from(e);let s=0;n.forEach((a,g)=>{s+=a===" "?o:t,g<n.length-1&&(s+=i)});const r=Math.max(A*Zce,.35);return{width:s,height:A,glyphWidth:t,letterSpacing:i,spaceWidth:o,strokeWidth:r}}function BQA(e,A){const t=A.width+A.strokeWidth,i=A.height+A.strokeWidth;let o=0,n=0;return e==="center"?o=-t/2:e==="top_left"||e==="bottom_left"||e==="center_left"?o=0:(e==="top_right"||e==="bottom_right"||e==="center_right")&&(o=-t),e==="center"?n=-i/2:e==="top_left"||e==="top_right"||e==="top_center"?n=0:e==="bottom_left"||e==="bottom_right"||e==="bottom_center"?n=-i:n=0,{x:o,y:n}}var Vce=e=>jw[e]??jw[e.toUpperCase()];function lQA(e){const{ctx:A,text:t,fontSize:i,startX:o,startY:n}=e,s=S8(t,i),{glyphWidth:r,letterSpacing:a,spaceWidth:g,height:I,strokeWidth:c}=s,B=n,l=Array.from(t);let C=o+c/2;l.forEach((E,Q)=>{const h=Vce(E),u=E===" "?g:r;if(h?.length){A.beginPath();for(const d of h){const f=C+d.x1*r,m=B+(1-d.y1)*I,D=C+d.x2*r,w=B+(1-d.y2)*I;A.moveTo(f,m),A.lineTo(D,w)}A.stroke()}C+=u,Q<l.length-1&&(C+=a)})}function CQA(e){const{ctx:A,text:t,x:i,y:o,fontSize:n,color:s,realToCanvasMat:r,anchorAlignment:a,rotation:g=0}=e;if(!t)return;const[I,c]=Pe(r,[i,o]),B=Math.abs(r.a),l=n*B,C=S8(t,l),E=BQA(a,C);A.save(),A.translate(I,c),g!==0&&A.rotate(-g*(Math.PI/180)),A.lineWidth=C.strokeWidth,A.lineCap="round",A.lineJoin="round",A.strokeStyle=s,lQA({ctx:A,text:t,fontSize:l,startX:E.x,startY:E.y}),A.restore()}function jce(e,A){return e==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function zce(e){return e||"center"}function Xce(e){const{ctx:A,text:t,realToCanvasMat:i,colorMap:o}=e,n=t.text??"";if(!n)return;const s=jce(t.layer,o),[r,a]=Pe(i,[t.anchor_position.x,t.anchor_position.y]),g=Math.abs(i.a),I=(t.font_size??1)*g,c=t.ccw_rotation??0,B=S8(n,I),l=zce(t.anchor_alignment),C=BQA(l,B);A.save(),A.translate(r,a),c!==0&&A.rotate(-c*(Math.PI/180)),t.layer==="bottom"&&A.scale(-1,1),A.lineWidth=B.strokeWidth,A.lineCap="round",A.lineJoin="round",A.strokeStyle=s,lQA({ctx:A,text:n,fontSize:I,startX:C.x,startY:C.y}),A.restore()}function $ce(e,A){return e==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function ABe(e){const{ctx:A,rect:t,realToCanvasMat:i,colorMap:o}=e,n=$ce(t.layer,o);lI({ctx:A,center:t.center,width:t.width,height:t.height,fill:n,realToCanvasMat:i})}function tBe(e,A){return e==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function eBe(e){const{ctx:A,circle:t,realToCanvasMat:i,colorMap:o}=e,n=tBe(t.layer,o);Lu({ctx:A,center:t.center,radius:t.radius,fill:n,realToCanvasMat:i})}function iBe(e,A){return e==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function oBe(e){const{ctx:A,line:t,realToCanvasMat:i,colorMap:o}=e,n=iBe(t.layer,o);LU({ctx:A,start:{x:t.x1,y:t.y1},end:{x:t.x2,y:t.y2},strokeWidth:t.stroke_width??.1,stroke:n,realToCanvasMat:i})}function nBe(e,A){return e==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function sBe(e){const{ctx:A,path:t,realToCanvasMat:i,colorMap:o}=e,n=nBe(t.layer,o);if(!(!t.route||t.route.length<2))for(let s=0;s<t.route.length-1;s++){const r=t.route[s],a=t.route[s+1];!r||!a||LU({ctx:A,start:{x:r.x,y:r.y},end:{x:a.x,y:a.y},strokeWidth:t.stroke_width??.1,stroke:n,realToCanvasMat:i})}}function rBe(e,A){return e==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function aBe(e){const{ctx:A,oval:t,realToCanvasMat:i,colorMap:o}=e,n=rBe(t.layer,o);WS({ctx:A,center:t.center,radius_x:t.radius_x,radius_y:t.radius_y,stroke:n,strokeWidth:.1,realToCanvasMat:i,rotation:t.ccw_rotation??0})}function gBe(e,A){return e==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function IBe(e){const{ctx:A,pill:t,realToCanvasMat:i,colorMap:o}=e,n=gBe(t.layer,o);Wl({ctx:A,center:t.center,width:t.width,height:t.height,stroke:n,strokeWidth:.2,realToCanvasMat:i})}function cBe(e){const{ctx:A,cutout:t,realToCanvasMat:i,colorMap:o}=e;if(t.shape==="rect"){lI({ctx:A,center:t.center,width:t.width,height:t.height,fill:o.drill,realToCanvasMat:i,rotation:t.rotation??0,borderRadius:t.corner_radius??0});return}if(t.shape==="circle"){Lu({ctx:A,center:t.center,radius:t.radius,fill:o.drill,realToCanvasMat:i});return}if(t.shape==="polygon"){t.points&&t.points.length>=3&&i_({ctx:A,points:t.points,fill:o.drill,realToCanvasMat:i});return}}function BBe(e,A){const t=parseInt(e.slice(1,3),16),i=parseInt(e.slice(3,5),16),o=parseInt(e.slice(5,7),16);return`rgba(${t}, ${i}, ${o}, ${A})`}function lBe(e){const{ctx:A,keepout:t,realToCanvasMat:i,colorMap:o}=e,n=o.keepout,s=BBe(o.keepout,.2),r=1;if(t.shape==="rect"){const[a,g]=Pe(i,[t.center.x,t.center.y]),I=t.width*Math.abs(i.a),c=t.height*Math.abs(i.a),B=t.rotation??0;A.save(),A.translate(a,g),B!==0&&A.rotate(-B*(Math.PI/180)),A.beginPath(),A.rect(-I/2,-c/2,I,c),A.fillStyle=s,A.fill(),A.beginPath(),A.rect(-I/2,-c/2,I,c),A.clip();const l=r*Math.abs(i.a),C=Math.sqrt(I*I+c*c),E=I/2,Q=c/2;A.strokeStyle=n,A.lineWidth=.15*Math.abs(i.a),A.setLineDash([]);for(let h=-C;h<C*2;h+=l){A.beginPath();const u=-E+h,d=-Q,f=-E+h+C,m=-Q+C;A.moveTo(u,d),A.lineTo(f,m),A.stroke()}A.restore();return}if(t.shape==="circle"){const[a,g]=Pe(i,[t.center.x,t.center.y]),I=t.radius*Math.abs(i.a),c=r*Math.abs(i.a);A.save(),A.translate(a,g),A.beginPath(),A.arc(0,0,I,0,Math.PI*2),A.fillStyle=s,A.fill(),A.beginPath(),A.arc(0,0,I,0,Math.PI*2),A.clip();const B=I*2;A.strokeStyle=n,A.lineWidth=.15*Math.abs(i.a),A.setLineDash([]);for(let l=-B;l<B*2;l+=c)A.beginPath(),A.moveTo(l-B,-B),A.lineTo(l+B,B),A.stroke();A.restore();return}}function CBe(e,A){return A.copper[e]??A.copper.top}function QBe(e,A,t,i,o){if(Math.abs(o)<1e-10)return null;const n=t-e,s=i-A,r=Math.hypot(n,s);if(r<1e-10)return null;const a=Math.abs(o)*(r/2),g=r/2,I=(a*a+g*g)/(2*a),c=I-a,B=(e+t)/2,l=(A+i)/2,C=-s/r,E=n/r,Q=o>0?-1:1,h=B+Q*C*c,u=l+Q*E*c;return{centerX:h,centerY:u,radius:I}}function QQA(e,A,t,i,o,n,s){if(Math.abs(n)<1e-10){const[f,m]=Pe(s,[i,o]);e.lineTo(f,m);return}const r=QBe(A,t,i,o,n);if(!r){const[f,m]=Pe(s,[i,o]);e.lineTo(f,m);return}const[a,g]=Pe(s,[A,t]),[I,c]=Pe(s,[i,o]),[B,l]=Pe(s,[r.centerX,r.centerY]),C=Math.hypot(a-B,g-l),E=Math.atan2(g-l,a-B),Q=Math.atan2(c-l,I-B),u=s.a*s.d-s.b*s.c<0,d=n>0?!u:u;e.arc(B,l,C,E,Q,d)}function f9A(e,A,t){if(A.vertices.length<2)return;if(A.vertices.length===2){const s=A.vertices[0],r=A.vertices[1];if(s&&r&&Math.abs((s.bulge??0)-1)<1e-10&&Math.abs((r.bulge??0)-1)<1e-10){const[a,g]=Pe(t,[s.x,s.y]);e.moveTo(a,g),QQA(e,s.x,s.y,r.x,r.y,1,t),QQA(e,r.x,r.y,s.x,s.y,1,t);return}}const i=A.vertices[0];if(!i)return;const[o,n]=Pe(t,[i.x,i.y]);e.moveTo(o,n);for(let s=0;s<A.vertices.length;s++){const r=A.vertices[s],a=(s+1)%A.vertices.length,g=A.vertices[a];if(!r||!g)continue;const I=r.bulge??0;if(Math.abs(I)<1e-10){const[c,B]=Pe(t,[g.x,g.y]);e.lineTo(c,B)}else QQA(e,r.x,r.y,g.x,g.y,I,t)}}function EBe(e){const{ctx:A,pour:t,realToCanvasMat:i,colorMap:o}=e,n=CBe(t.layer,o);if(A.save(),t.shape==="rect"){const[s,r]=Pe(i,[t.center.x,t.center.y]),a=t.width*Math.abs(i.a),g=t.height*Math.abs(i.a);A.translate(s,r),t.rotation&&A.rotate(-t.rotation*(Math.PI/180)),A.beginPath(),A.rect(-a/2,-g/2,a,g),A.fillStyle=n,A.globalAlpha=.5,A.fill(),A.restore();return}if(t.shape==="polygon"){if(t.points&&t.points.length>=3){const s=t.points.map(I=>Pe(i,[I.x,I.y])),r=s[0];if(!r){A.restore();return}A.beginPath();const[a,g]=r;A.moveTo(a,g);for(let I=1;I<s.length;I++){const c=s[I];if(!c)continue;const[B,l]=c;A.lineTo(B,l)}A.closePath(),A.fillStyle=n,A.globalAlpha=.5,A.fill()}A.restore();return}if(t.shape==="brep"){if(A.beginPath(),f9A(A,t.brep_shape.outer_ring,i),t.brep_shape.inner_rings)for(const s of t.brep_shape.inner_rings)f9A(A,s,i);A.fillStyle=n,A.globalAlpha=.5,A.fill("evenodd"),A.restore();return}A.restore()}var hBe={left:.2,right:.2,top:.2,bottom:.2};function uBe(e){return e?e.includes("left")?"center_left":e.includes("right")?"center_right":"center":"center"}function dBe(e){const{ctx:A,text:t,realToCanvasMat:i,colorMap:o}=e,n=t.text??"";if(!n)return;const[s,r]=Pe(i,[t.anchor_position.x,t.anchor_position.y]),a=Math.abs(i.a),g=(t.font_size??1)*a,I=t.ccw_rotation??0,c={...hBe,...t.knockout_padding},B=o.copper[t.layer]??o.copper.top,l=S8(n,g),C=l.width+l.strokeWidth,E=uBe(t.anchor_alignment),Q=BQA(E,l);if(A.save(),A.translate(s,r),t.is_mirrored&&A.scale(-1,1),I!==0&&A.rotate(-I*(Math.PI/180)),A.lineWidth=l.strokeWidth,A.lineCap="round",A.lineJoin="round",t.is_knockout){const h=c.left*a,u=c.right*a,d=c.top*a,f=c.bottom*a,m=Q.x-h*4,D=Q.y-d*4,w=C+h*2+u*2,b=l.height+l.strokeWidth+d*2+f*2;A.fillStyle=B,A.fillRect(m,D,w,b)}else A.strokeStyle=B;lQA({ctx:A,text:n,fontSize:g,startX:Q.x,startY:Q.y}),A.restore()}var pBe="rgba(255,255,255,0.5)";function fBe(e,A){return pBe}function yBe(e){const{ctx:A,text:t,realToCanvasMat:i}=e,o=fBe(t.layer),n=t.color??o,s=t.font_size;CQA({ctx:A,text:t.text,x:t.anchor_position.x,y:t.anchor_position.y,fontSize:s,color:n,realToCanvasMat:i,anchorAlignment:t.anchor_alignment})}function mBe(e){const{ctx:A,rect:t,realToCanvasMat:i}=e,n=t.color??"rgba(255,255,255,0.5)",s=t.is_filled??!1,r=t.has_stroke??!0,a=t.is_stroke_dashed??!1;lI({ctx:A,center:t.center,width:t.width,height:t.height,fill:s?n:void 0,stroke:r?n:void 0,strokeWidth:r?t.stroke_width:void 0,borderRadius:t.corner_radius,realToCanvasMat:i,isStrokeDashed:a})}function wBe(e){const{ctx:A,rect:t,realToCanvasMat:i}=e,n=t.color??"rgb(89, 148, 220)",s=t.is_filled??!1,r=t.has_stroke??!0,a=t.is_stroke_dashed??!1;lI({ctx:A,center:t.center,width:t.width,height:t.height,fill:s?n:void 0,stroke:r?n:void 0,strokeWidth:r?t.stroke_width:void 0,borderRadius:t.corner_radius,realToCanvasMat:i,isStrokeDashed:a})}function DBe(e){const{ctx:A,path:t,realToCanvasMat:i}=e,n=t.color??"rgba(255,255,255,0.5)";if(!(!t.route||t.route.length<2))for(let s=0;s<t.route.length-1;s++){const r=t.route[s],a=t.route[s+1];!r||!a||LU({ctx:A,start:{x:r.x,y:r.y},end:{x:a.x,y:a.y},strokeWidth:t.stroke_width??.1,stroke:n,realToCanvasMat:i})}}function SBe(e){const{ctx:A,path:t,realToCanvasMat:i}=e,n=t.color??"rgb(89, 148, 220)";if(!(!t.route||t.route.length<2))for(let s=0;s<t.route.length-1;s++){const r=t.route[s],a=t.route[s+1];!r||!a||LU({ctx:A,start:{x:r.x,y:r.y},end:{x:a.x,y:a.y},strokeWidth:t.stroke_width??.1,stroke:n,realToCanvasMat:i})}}var bBe="rgb(89, 148, 220)";function xBe(e){const{ctx:A,text:t,realToCanvasMat:i}=e,o=bBe,n=t.color??o,s=t.font_size??1;CQA({ctx:A,text:t.text??"",x:t.anchor_position.x,y:t.anchor_position.y,fontSize:s,color:n,realToCanvasMat:i,anchorAlignment:t.anchor_alignment??"center"})}var _Be=1.5,kBe=.6,GBe=.3;function EQA(e){const A=Math.hypot(e.x,e.y)||1;return{x:e.x/A,y:e.y/A}}function y9A(e){const{ctx:A,from:t,to:i,realToCanvasMat:o,color:n,fontSize:s,arrowSize:r=1,strokeWidth:a,text:g,textRotation:I,offset:c}=e,B=EQA({x:i.x-t.x,y:i.y-t.y}),l={x:-B.y,y:B.x},C=c?.direction&&typeof c.direction.x=="number"&&typeof c.direction.y=="number",E=C?EQA(c.direction):{x:0,y:0},Q=c?.distance??0,h={x:E.x*Q,y:E.y*Q},u={x:t.x+h.x,y:t.y+h.y},d={x:i.x+h.x,y:i.y+h.y},f={x:u.x+B.x*r,y:u.y+B.y*r},m={x:d.x-B.x*r,y:d.y-B.y*r};Math.abs(o.a);const D=a??r/5,w=n||"rgba(255,255,255,0.5)",b=C&&(Math.abs(E.x)>Number.EPSILON||Math.abs(E.y)>Number.EPSILON)?E:l,k=Q+.5,x=[],N=J=>{const H={x:J.x+b.x*k,y:J.y+b.y*k},O=D/2,W={x:-b.y,y:b.x};return[{x:J.x+W.x*O,y:J.y+W.y*O},{x:J.x-W.x*O,y:J.y-W.y*O},{x:H.x-W.x*O,y:H.y-W.y*O},{x:H.x+W.x*O,y:H.y+W.y*O}]};x.push(u),x.push({x:f.x+l.x*(r/2),y:f.y+l.y*(r/2)}),x.push({x:f.x+l.x*(D/2),y:f.y+l.y*(D/2)}),x.push({x:m.x+l.x*(D/2),y:m.y+l.y*(D/2)}),x.push({x:m.x+l.x*(r/2),y:m.y+l.y*(r/2)}),x.push(d),x.push({x:m.x-l.x*(r/2),y:m.y-l.y*(r/2)}),x.push({x:m.x-l.x*(D/2),y:m.y-l.y*(D/2)}),x.push({x:f.x-l.x*(D/2),y:f.y-l.y*(D/2)}),x.push({x:f.x-l.x*(r/2),y:f.y-l.y*(r/2)}),x.push(u);const M=x[0],U=J=>{const H=N(J);x.push(M),x.push(H[0]),x.push(...H),x.push(H[0]),x.push(M)};if(U(t),U(i),i_({ctx:A,points:x,fill:w,realToCanvasMat:o}),g){const J={x:(t.x+i.x)/2+h.x,y:(t.y+i.y)/2+h.y},[H,O]=Pe(o,[u.x,u.y]),[W,$]=Pe(o,[d.x,d.y]),iA=EQA({x:W-H,y:$-O});let rA=Math.atan2(iA.y,iA.x)*180/Math.PI;(rA>90||rA<-90)&&(rA+=180);const tA=typeof I=="number"&&Number.isFinite(I)?rA-I:rA;let nA=0;if(g&&typeof I=="number"&&Number.isFinite(I)){const SA=g.length*s*kBe,FA=s,MA=I*Math.PI/180,TA=Math.abs(Math.sin(MA)),EA=Math.abs(Math.cos(MA)),GA=SA/2,dA=FA/2;nA=GA*TA+dA*EA+s*GBe}const aA=r*_Be+nA,QA={x:J.x+l.x*aA,y:J.y+l.y*aA};CQA({ctx:A,text:g,x:QA.x,y:QA.y,fontSize:s,color:w,realToCanvasMat:o,anchorAlignment:"center",rotation:-tA})}}var FBe="rgba(255,255,255,0.5)";function RBe(e){const{ctx:A,pcbNoteDimension:t,realToCanvasMat:i}=e,o=t.color??FBe;y9A({ctx:A,from:t.from,to:t.to,realToCanvasMat:i,color:o,fontSize:t.font_size,arrowSize:t.arrow_size,text:t.text,textRotation:t.text_ccw_rotation,offset:t.offset_distance&&t.offset_direction?{distance:t.offset_distance,direction:t.offset_direction}:void 0})}var MBe="rgba(255,255,255,0.5)";function NBe(e){const{ctx:A,pcbFabricationNoteDimension:t,realToCanvasMat:i}=e,o=t.color??MBe;y9A({ctx:A,from:t.from,to:t.to,realToCanvasMat:i,color:o,fontSize:t.font_size??1,arrowSize:t.arrow_size??1,text:t.text,textRotation:t.text_ccw_rotation,offset:t.offset_distance&&t.offset_direction?{distance:t.offset_distance,direction:t.offset_direction}:void 0})}function vBe(e){const{ctx:A,line:t,realToCanvasMat:i}=e,n=t.color??"rgb(89, 148, 220)",s=t.stroke_width??.1,r=t.is_dashed??!1,[a,g]=Pe(i,[t.x1,t.y1]),[I,c]=Pe(i,[t.x2,t.y2]),B=s*Math.abs(i.a);A.save(),r?A.setLineDash([B*2,B*2]):A.setLineDash([]),A.beginPath(),A.moveTo(a,g),A.lineTo(I,c),A.lineWidth=B,A.strokeStyle=n,A.lineCap="round",A.stroke(),A.restore()}var LBe=class{ctx;colorMap;realToCanvasMat;constructor(A){if("getContext"in A&&typeof A.getContext=="function"){const t=A.getContext("2d");if(!t)throw new Error("Failed to get 2D rendering context from canvas");this.ctx=t}else this.ctx=A;this.colorMap={...Nce},this.realToCanvasMat=Md()}configure(A){A.colorOverrides&&(this.colorMap={...this.colorMap,...A.colorOverrides,copper:{...this.colorMap.copper,...A.colorOverrides.copper},silkscreen:{...this.colorMap.silkscreen,...A.colorOverrides.silkscreen},soldermask:{...this.colorMap.soldermask,...A.colorOverrides.soldermask},soldermaskWithCopperUnderneath:{...this.colorMap.soldermaskWithCopperUnderneath,...A.colorOverrides.soldermaskWithCopperUnderneath},soldermaskOverCopper:{...this.colorMap.soldermaskOverCopper,...A.colorOverrides.soldermaskOverCopper}})}setCameraBounds(A){const t=this.ctx.canvas,i=t.width,o=t.height,n=A.maxX-A.minX,s=A.maxY-A.minY,r=i/n,a=o/s,g=Math.min(r,a),I=(i-n*g)/2,c=(o-s*g)/2;this.realToCanvasMat=el(Er(I,c),dE(g,-g),Er(-A.minX,-A.maxY))}drawElements(A,t={}){A.some(i=>i.type==="pcb_smtpad"&&i.is_covered_with_solder_mask===!0),A.some(i=>i.type==="pcb_hole"&&i.is_covered_with_solder_mask===!0),A.some(i=>i.type==="pcb_plated_hole"&&i.is_covered_with_solder_mask===!0);for(const i of A)i.type==="pcb_board"?this.drawBoardWithSoldermask(i):this.drawElement(i,t)}drawBoardWithSoldermask(A){const{width:t,height:i,center:o,outline:n}=A,s="top";if(n&&Array.isArray(n)&&n.length>=3){const r=this.colorMap.soldermask[s]??this.colorMap.soldermask.top,a=n.map(I=>{const[c,B]=Pe(this.realToCanvasMat,[I.x,I.y]);return{x:c,y:B}});this.ctx.beginPath();const g=a[0];if(g){this.ctx.moveTo(g.x,g.y);for(let I=1;I<a.length;I++){const c=a[I];c&&this.ctx.lineTo(c.x,c.y)}this.ctx.closePath()}this.ctx.fillStyle=r,this.ctx.fill(),D8({ctx:this.ctx,points:n.map(I=>({x:I.x,y:I.y})),stroke:this.colorMap.boardOutline,strokeWidth:.1,realToCanvasMat:this.realToCanvasMat,closePath:!0});return}if(t!==void 0&&i!==void 0&&o){const r=this.colorMap.soldermask[s]??this.colorMap.soldermask.top;lI({ctx:this.ctx,center:o,width:t,height:i,fill:r,realToCanvasMat:this.realToCanvasMat});const a=t/2,g=i/2,I=[{x:o.x-a,y:o.y-g},{x:o.x+a,y:o.y-g},{x:o.x+a,y:o.y+g},{x:o.x-a,y:o.y+g}];D8({ctx:this.ctx,points:I,stroke:this.colorMap.boardOutline,strokeWidth:.1,realToCanvasMat:this.realToCanvasMat,closePath:!0})}}drawElement(A,t){Mce(A,t)&&(A.type==="pcb_plated_hole"&&Lce({ctx:this.ctx,hole:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_via"&&Uce({ctx:this.ctx,via:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_hole"&&Hce({ctx:this.ctx,hole:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_smtpad"&&Jce({ctx:this.ctx,pad:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_trace"&&Kce({ctx:this.ctx,trace:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_board"&&Pce({ctx:this.ctx,board:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_text"&&Xce({ctx:this.ctx,text:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_rect"&&ABe({ctx:this.ctx,rect:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_circle"&&eBe({ctx:this.ctx,circle:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_line"&&oBe({ctx:this.ctx,line:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_path"&&sBe({ctx:this.ctx,path:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_pill"&&IBe({ctx:this.ctx,pill:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_oval"&&aBe({ctx:this.ctx,oval:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_cutout"&&cBe({ctx:this.ctx,cutout:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_keepout"&&lBe({ctx:this.ctx,keepout:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_copper_pour"&&EBe({ctx:this.ctx,pour:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_copper_text"&&dBe({ctx:this.ctx,text:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_fabrication_note_text"&&yBe({ctx:this.ctx,text:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_fabrication_note_rect"&&mBe({ctx:this.ctx,rect:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_note_rect"&&wBe({realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap,ctx:this.ctx,rect:A}),A.type==="pcb_fabrication_note_path"&&DBe({ctx:this.ctx,path:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_note_path"&&SBe({ctx:this.ctx,path:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_note_text"&&xBe({ctx:this.ctx,text:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_note_line"&&vBe({ctx:this.ctx,line:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_note_dimension"&&RBe({ctx:this.ctx,pcbNoteDimension:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_fabrication_note_dimension"&&NBe({ctx:this.ctx,pcbFabricationNoteDimension:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}))}};let UBe={data:""},HBe=e=>{if(typeof window=="object"){let A=(e?e.querySelector("#_goober"):window._goober)||Object.assign(document.createElement("style"),{innerHTML:" ",id:"_goober"});return A.nonce=window.__nonce__,A.parentNode||(e||document.head).appendChild(A),A.firstChild}return e||UBe},YBe=/(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g,JBe=/\/\*[^]*?\*\/| +/g,m9A=/\n+/g,n_=(e,A)=>{let t="",i="",o="";for(let n in e){let s=e[n];n[0]=="@"?n[1]=="i"?t=n+" "+s+";":i+=n[1]=="f"?n_(s,n):n+"{"+n_(s,n[1]=="k"?"":A)+"}":typeof s=="object"?i+=n_(s,A?A.replace(/([^,])+/g,r=>n.replace(/([^,]*:\S+\([^)]*\))|([^,])+/g,a=>/&/.test(a)?a.replace(/&/g,r):r?r+" "+a:a)):n):s!=null&&(n=/^--/.test(n)?n:n.replace(/[A-Z]/g,"-$&").toLowerCase(),o+=n_.p?n_.p(n,s):n+":"+s+";")}return t+(A&&o?A+"{"+o+"}":o)+i},ZS={},w9A=e=>{if(typeof e=="object"){let A="";for(let t in e)A+=t+w9A(e[t]);return A}return e},TBe=(e,A,t,i,o)=>{let n=w9A(e),s=ZS[n]||(ZS[n]=(a=>{let g=0,I=11;for(;g<a.length;)I=101*I+a.charCodeAt(g++)>>>0;return"go"+I})(n));if(!ZS[s]){let a=n!==e?e:(g=>{let I,c,B=[{}];for(;I=YBe.exec(g.replace(JBe,""));)I[4]?B.shift():I[3]?(c=I[3].replace(m9A," ").trim(),B.unshift(B[0][c]=B[0][c]||{})):B[0][I[1]]=I[2].replace(m9A," ").trim();return B[0]})(e);ZS[s]=n_(o?{["@keyframes "+s]:a}:a,t?"":"."+s)}let r=t&&ZS.g?ZS.g:null;return t&&(ZS.g=ZS[s]),((a,g,I,c)=>{c?g.data=g.data.replace(c,a):g.data.indexOf(a)===-1&&(g.data=I?a+g.data:g.data+a)})(ZS[s],A,i,r),s},KBe=(e,A,t)=>e.reduce((i,o,n)=>{let s=A[n];if(s&&s.call){let r=s(t),a=r&&r.props&&r.props.className||/^go/.test(r)&&r;s=a?"."+a:r&&typeof r=="object"?r.props?"":n_(r,""):r===!1?"":r}return i+o+(s??"")},"");function b8(e){let A=this||{},t=e.call?e(A.p):e;return TBe(t.unshift?t.raw?KBe(t,[].slice.call(arguments,1),A.p):t.reduce((i,o)=>Object.assign(i,o&&o.call?o(A.p):o),{}):t,HBe(A.target),A.g,A.o,A.k)}let D9A,hQA,uQA;b8.bind({g:1});let VS=b8.bind({k:1});function PBe(e,A,t,i){n_.p=A,D9A=e,hQA=t,uQA=i}function s_(e,A){let t=this||{};return function(){let i=arguments;function o(n,s){let r=Object.assign({},n),a=r.className||o.className;t.p=Object.assign({theme:hQA&&hQA()},r),t.o=/ *go\d+/.test(a),r.className=b8.apply(t,i)+(a?" "+a:"");let g=e;return e[0]&&(g=r.as||e,delete r.as),uQA&&g[0]&&uQA(r),D9A(g,r)}return o}}var qBe=e=>typeof e=="function",x8=(e,A)=>qBe(e)?e(A):e,OBe=(()=>{let e=0;return()=>(++e).toString()})(),S9A=(()=>{let e;return()=>{if(e===void 0&&typeof window<"u"){let A=matchMedia("(prefers-reduced-motion: reduce)");e=!A||A.matches}return e}})(),WBe=20,dQA="default",b9A=(e,A)=>{let{toastLimit:t}=e.settings;switch(A.type){case 0:return{...e,toasts:[A.toast,...e.toasts].slice(0,t)};case 1:return{...e,toasts:e.toasts.map(s=>s.id===A.toast.id?{...s,...A.toast}:s)};case 2:let{toast:i}=A;return b9A(e,{type:e.toasts.find(s=>s.id===i.id)?1:0,toast:i});case 3:let{toastId:o}=A;return{...e,toasts:e.toasts.map(s=>s.id===o||o===void 0?{...s,dismissed:!0,visible:!1}:s)};case 4:return A.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(s=>s.id!==A.toastId)};case 5:return{...e,pausedAt:A.time};case 6:let n=A.time-(e.pausedAt||0);return{...e,pausedAt:void 0,toasts:e.toasts.map(s=>({...s,pauseDuration:s.pauseDuration+n}))}}},_8=[],x9A={toasts:[],pausedAt:void 0,settings:{toastLimit:WBe}},zw={},_9A=(e,A=dQA)=>{zw[A]=b9A(zw[A]||x9A,e),_8.forEach(([t,i])=>{t===A&&i(zw[A])})},k9A=e=>Object.keys(zw).forEach(A=>_9A(e,A)),ZBe=e=>Object.keys(zw).find(A=>zw[A].toasts.some(t=>t.id===e)),k8=(e=dQA)=>A=>{_9A(A,e)},VBe={blank:4e3,error:4e3,success:2e3,loading:1/0,custom:4e3},jBe=(e={},A=dQA)=>{let[t,i]=AA.useState(zw[A]||x9A),o=AA.useRef(zw[A]);AA.useEffect(()=>(o.current!==zw[A]&&i(zw[A]),_8.push([A,i]),()=>{let s=_8.findIndex(([r])=>r===A);s>-1&&_8.splice(s,1)}),[A]);let n=t.toasts.map(s=>{var r,a,g;return{...e,...e[s.type],...s,removeDelay:s.removeDelay||((r=e[s.type])==null?void 0:r.removeDelay)||e?.removeDelay,duration:s.duration||((a=e[s.type])==null?void 0:a.duration)||e?.duration||VBe[s.type],style:{...e.style,...(g=e[s.type])==null?void 0:g.style,...s.style}}});return{...t,toasts:n}},zBe=(e,A="blank",t)=>({createdAt:Date.now(),visible:!0,dismissed:!1,type:A,ariaProps:{role:"status","aria-live":"polite"},message:e,pauseDuration:0,...t,id:t?.id||OBe()}),UU=e=>(A,t)=>{let i=zBe(A,e,t);return k8(i.toasterId||ZBe(i.id))({type:2,toast:i}),i.id},Us=(e,A)=>UU("blank")(e,A);Us.error=UU("error"),Us.success=UU("success"),Us.loading=UU("loading"),Us.custom=UU("custom"),Us.dismiss=(e,A)=>{let t={type:3,toastId:e};A?k8(A)(t):k9A(t)},Us.dismissAll=e=>Us.dismiss(void 0,e),Us.remove=(e,A)=>{let t={type:4,toastId:e};A?k8(A)(t):k9A(t)},Us.removeAll=e=>Us.remove(void 0,e),Us.promise=(e,A,t)=>{let i=Us.loading(A.loading,{...t,...t?.loading});return typeof e=="function"&&(e=e()),e.then(o=>{let n=A.success?x8(A.success,o):void 0;return n?Us.success(n,{id:i,...t,...t?.success}):Us.dismiss(i),o}).catch(o=>{let n=A.error?x8(A.error,o):void 0;n?Us.error(n,{id:i,...t,...t?.error}):Us.dismiss(i)}),e};var XBe=1e3,$Be=(e,A="default")=>{let{toasts:t,pausedAt:i}=jBe(e,A),o=AA.useRef(new Map).current,n=AA.useCallback((c,B=XBe)=>{if(o.has(c))return;let l=setTimeout(()=>{o.delete(c),s({type:4,toastId:c})},B);o.set(c,l)},[]);AA.useEffect(()=>{if(i)return;let c=Date.now(),B=t.map(l=>{if(l.duration===1/0)return;let C=(l.duration||0)+l.pauseDuration-(c-l.createdAt);if(C<0){l.visible&&Us.dismiss(l.id);return}return setTimeout(()=>Us.dismiss(l.id,A),C)});return()=>{B.forEach(l=>l&&clearTimeout(l))}},[t,i,A]);let s=AA.useCallback(k8(A),[A]),r=AA.useCallback(()=>{s({type:5,time:Date.now()})},[s]),a=AA.useCallback((c,B)=>{s({type:1,toast:{id:c,height:B}})},[s]),g=AA.useCallback(()=>{i&&s({type:6,time:Date.now()})},[i,s]),I=AA.useCallback((c,B)=>{let{reverseOrder:l=!1,gutter:C=8,defaultPosition:E}=B||{},Q=t.filter(d=>(d.position||E)===(c.position||E)&&d.height),h=Q.findIndex(d=>d.id===c.id),u=Q.filter((d,f)=>f<h&&d.visible).length;return Q.filter(d=>d.visible).slice(...l?[u+1]:[0,u]).reduce((d,f)=>d+(f.height||0)+C,0)},[t]);return AA.useEffect(()=>{t.forEach(c=>{if(c.dismissed)n(c.id,c.removeDelay);else{let B=o.get(c.id);B&&(clearTimeout(B),o.delete(c.id))}})},[t,n]),{toasts:t,handlers:{updateHeight:a,startPause:r,endPause:g,calculateOffset:I}}},Ale=VS`
4941
+ `)};return aQA={serializeText:A},aQA}var gQA,E9A;function Gce(){if(E9A)return gQA;E9A=1;const{geometries:e,modifiers:A}=w8(),{flatten:t,toArray:i}=xce(),{serializeBinary:o}=_ce(),{serializeText:n}=kce();return gQA={mimeType:"application/sla",serialize:(a,...g)=>{a=Object.assign({},{binary:!0,statusCallback:null},a),g=t(g);let c=g.filter(B=>e.geom3.isA(B));if(c.length===0)throw new Error("only 3D geometries can be serialized to STL");return g.length!==c.length&&console.warn("some objects could not be serialized to STL"),c=i(A.generalize({snap:!0,triangulate:!0},c)),a.binary?o(c,a):n(c,a)}},gQA}var Fce=Gce();const Rce=t0(Fce);var h9A={0:"M0.169711 0.28125 L0.101703 0.305674 L0.040587 0.380015 L0.007704 0.487949 L0 0.648016 L0.018395 0.78222 L0.067519 0.893435 L0.13831 0.952347 L0.219008 0.96104 L0.304303 0.915691 L0.34829 0.832767 L0.373438 0.555293 L0.311181 0.348459 L0.254003 0.298134 L0.169711 0.28125",1:"M0 0.461728 L0.210938 0.28125 L0.210938 0.949688",2:"M0.026346 0.411338 L0.039348 0.363086 L0.077772 0.318086 L0.140743 0.287569 L0.181161 0.28125 L0.251086 0.287075 L0.30354 0.313129 L0.332224 0.353085 L0.342527 0.399517 L0.341843 0.430402 L0.329531 0.4821 L0.276092 0.582614 L0.14151 0.773822 L0 0.949688 L0.378576 0.949688",3:"M0.014691 0.416315 L0.058166 0.327137 L0.140995 0.28125 L0.31824 0.32562 L0.366832 0.429185 L0.345493 0.522571 L0.24391 0.590315 L0.086157 0.611009 L0.287214 0.649393 L0.347202 0.703218 L0.375 0.788601 L0.335206 0.897496 L0.231259 0.961494 L0.098073 0.952982 L0 0.882401",4:"M0.290293 0.28418 L0 0.729187 L0.396094 0.729187 M0.286905 0.585796 L0.286905 0.949893",5:"M0 0.293945 L0 0.626133 L0.161823 0.582447 L0.277362 0.59888 L0.323342 0.628538 L0.355274 0.670621 L0.379688 0.785314 L0.368145 0.844898 L0.337846 0.89179 L0.278311 0.935343 L0.209511 0.958255 L0.144813 0.961929 L0.090328 0.949972 L0.046284 0.926526 L0 0.878297 M0 0.293945 L0.379688 0.293945",6:"M0.263349 0.28125 L0.137608 0.331797 L0.05354 0.429006 L0.003773 0.59624 L0.000112 0.762754 L0.035577 0.875849 L0.127777 0.952657 L0.268816 0.96104 L0.350176 0.900101 L0.378125 0.805815 L0.371481 0.715679 L0.281571 0.603038 L0.117328 0.604681 L0.045704 0.653874 L0 0.731045",7:"M0 0.293457 L0.370703 0.293457 L0.34277 0.313524 L0.328084 0.326809 L0.293706 0.366259 L0.275035 0.39342 L0.256054 0.426201 L0.237275 0.465102 L0.219206 0.510619 L0.202357 0.56325 L0.187239 0.623493 L0.17436 0.691846 L0.160357 0.81067 L0.154261 0.950542",8:"M0.194068 0.28125 L0.060404 0.354202 L0.056317 0.495113 L0.110924 0.564164 L0.326339 0.647328 L0.377344 0.809843 L0.308699 0.927448 L0.158368 0.96104 L0.030423 0.88139 L0 0.752778 L0.064715 0.633969 L0.246378 0.569673 L0.32641 0.482767 L0.328367 0.348618 L0.194068 0.28125",9:"M0.376563 0.453778 L0.358291 0.360645 L0.327703 0.320078 L0.275924 0.291592 L0.197789 0.28125 L0.123966 0.290038 L0.060241 0.321196 L0.019833 0.368824 L0 0.455417 L0.042613 0.561414 L0.09049 0.594182 L0.154287 0.603877 L0.325441 0.567316 L0.366473 0.516032 L0.376563 0.453778 M0.363286 0.522498 L0.179127 0.96104","!":"M0.043554 0.28418 L0.043554 0.754095 M0 0.949893 L0.087109 0.949893",'"':"M0 0.28418 L0 0.519858 M0.209766 0.28418 L0.209766 0.519858","#":"M0.148174 0.271973 L0.103273 0.960391 M0.32778 0.271973 L0.282878 0.960391 M0.022451 0.524393 L0.426562 0.447902 M0 0.830356 L0.404112 0.753865",$:"M0.194573 0.218262 L0.194573 1.041094 M0.348184 0.389685 L0.276499 0.303973 L0.133129 0.286831 L0.051203 0.372543 L0.020481 0.492539 L0.040962 0.561108 L0.102407 0.612535 L0.29698 0.663962 L0.358424 0.715389 L0.378906 0.801101 L0.337943 0.921097 L0.235536 0.972524 L0.102407 0.955382 L0.030722 0.903955 L0 0.801101","'":"M0 0.28418 L0 0.519858","(":"M0.189062 0.271973 L0.154687 0.316502 L0.120312 0.369938 L0.085937 0.43228 L0.051562 0.503527 L0.025781 0.574775 L0.008594 0.646023 L0 0.708364 L0.008594 0.770706 L0.025781 0.841954 L0.051562 0.913201 L0.085937 0.984449 L0.120312 1.04679 L0.154687 1.100226 L0.189062 1.144756",")":"M0 0.271973 L0.034375 0.316502 L0.06875 0.369938 L0.103125 0.43228 L0.1375 0.503527 L0.163281 0.574775 L0.180469 0.646023 L0.189062 0.708364 L0.180469 0.770706 L0.163281 0.841954 L0.1375 0.913201 L0.103125 0.984449 L0.06875 1.04679 L0.034375 1.100226 L0 1.144756","*":"M0.129102 0.406196 L0.129102 0.555332 M0.129102 0.406196 L0.258203 0.458393 M0.129102 0.406196 L0.210639 0.271973 M0.129102 0.406196 L0.047564 0.271973 M0.129102 0.406196 L0 0.458393","+":"M0 0.631145 L0.378125 0.631145 M0.189063 0.411133 L0.189063 0.851157",",":"M0.084766 0.899902 L0 1.049756 L0.042383 1.124683","-":"M0 0.696777 L0.216016 0.696777",".":"M0.080078 0.899902 L0 0.899902","/":"M0 0.960391 L0.222266 0.271973","<":"M0.379297 0.404785 L0 0.630247 L0 0.630247 L0.379297 0.855708","=":"M0 0.49707 L0.378125 0.49707 M0 0.775435 L0.378125 0.775435",">":"M0 0.404785 L0.379297 0.630247 L0.379297 0.630247 L0 0.855708",A:"M0 0.949893 L0.257697 0.28418 L0.535938 0.949893 M0.129965 0.690227 L0.393468 0.690227",B:"M0 0.949893 L0 0.291993 L0.132605 0.28418 L0.254027 0.307156 L0.335828 0.384263 L0.323105 0.496995 L0.226849 0.55732 L0.018935 0.583209 L0.221095 0.59686 L0.3693 0.653833 L0.432422 0.741422 L0.427237 0.854697 L0.398824 0.904738 L0.32796 0.945405 L0 0.949893",C:"M0.50625 0.430577 L0.472248 0.357518 L0.409879 0.305792 L0.291763 0.271973 L0.204476 0.282318 L0.127553 0.316954 L0.052444 0.396895 L0 0.606732 L0.041156 0.817674 L0.102551 0.90262 L0.166382 0.94237 L0.290733 0.960391 L0.399102 0.937358 L0.479343 0.870144 L0.50625 0.775278",D:"M0 0.949893 L0.007388 0.298007 L0.10683 0.28418 L0.183007 0.285788 L0.306747 0.318627 L0.398252 0.389547 L0.450571 0.48504 L0.471428 0.584053 L0.473438 0.658601 L0.463897 0.722493 L0.444382 0.776537 L0.381729 0.858306 L0.298088 0.910361 L0.16085 0.946841 L0 0.949893",E:"M0 0.28418 L0 0.949893 M0 0.28418 L0.427344 0.28418 M0 0.617036 L0.299141 0.617036 M0 0.949893 L0.427344 0.949893",F:"M0 0.28418 L0 0.949893 M0.00439 0.288708 L0.386328 0.288708 M0.00439 0.614772 L0.324867 0.614772",G:"M0.478131 0.298551 L0.344522 0.271973 L0.203344 0.282603 L0.112788 0.325028 L0.041313 0.409309 L0 0.591264 L0.022034 0.788458 L0.069795 0.859572 L0.143501 0.91686 L0.232346 0.952931 L0.32552 0.960391 L0.412216 0.931847 L0.481626 0.859907 L0.529687 0.654459 L0.295775 0.653988",H:"M0 0.28418 L0 0.949893 M0 0.602972 L0.444282 0.602972 M0.449219 0.28418 L0.449219 0.949893",I:"M0 0.28418 L0 0.949893",J:"M0.314103 0.28418 L0.314844 0.784965 L0.307727 0.847636 L0.294226 0.881552 L0.275296 0.908524 L0.252632 0.929181 L0.202885 0.954068 L0.15855 0.961245 L0.098458 0.952918 L0.054159 0.930067 L0.032609 0.90793 L0.016893 0.881086 L0.006536 0.850234 L0.001063 0.816073 L0 0.779302",K:"M0 0.28418 L0 0.949893 M0.416051 0.328561 L0 0.69347 M0.157813 0.589914 L0.473438 0.935099",L:"M0 0.28418 L0 0.949893 L0.357812 0.949893",M:"M0 0.949893 L0 0.28418 L0.273242 0.717692 L0.546484 0.28418 L0.546484 0.949893",N:"M0 0.949893 L0 0.28418 L0.451172 0.949893 L0.442317 0.28418",O:"M0.258411 0.960356 L0.158643 0.933282 L0.067445 0.850907 L0 0.571309 L0.064242 0.362041 L0.143058 0.302438 L0.279528 0.271484 L0.40801 0.308635 L0.483234 0.376484 L0.547656 0.631387 L0.515596 0.792317 L0.458459 0.885325 L0.356976 0.948677 L0.258411 0.960356",P:"M0 0.949893 L0 0.296743 L0.129427 0.28418 L0.245212 0.292032 L0.320495 0.313164 L0.354157 0.330245 L0.407845 0.380342 L0.431706 0.43415 L0.437109 0.512813 L0.415714 0.562267 L0.382324 0.589603 L0.329079 0.611521 L0.252078 0.627238 L0.147419 0.635974 L0.0112 0.636945",Q:"M0.258008 0.982971 L0.158395 0.955008 L0.067339 0.869929 L0 0.581152 L0.064142 0.365014 L0.142835 0.303454 L0.279091 0.271484 L0.407373 0.309855 L0.48248 0.379931 L0.546801 0.643202 L0.514791 0.809415 L0.457743 0.905476 L0.356419 0.970908 L0.258008 0.982971 M0.325335 0.771907 L0.558594 1.000771",R:"M0 0.945124 L0 0.301423 L0.182269 0.28418 L0.310196 0.289945 L0.387371 0.307659 L0.41982 0.3221 L0.446527 0.340896 L0.466259 0.36452 L0.483658 0.428585 L0.482024 0.485399 L0.464217 0.526537 L0.432258 0.55472 L0.388168 0.57267 L0.303709 0.586358 L0.012082 0.597049 M0.254266 0.624227 L0.504687 0.949893",S:"M0.405119 0.376247 L0.331691 0.281459 L0.157647 0.271973 L0.060093 0.340265 L0.020265 0.465507 L0.036761 0.527346 L0.09848 0.580763 L0.343053 0.623834 L0.425329 0.674748 L0.455859 0.76281 L0.415642 0.900538 L0.292807 0.960391 L0.134871 0.955936 L0.048496 0.907372 L0 0.793158",T:"M0 0.28418 L0.453906 0.28418 M0.233694 0.28418 L0.233694 0.949893",U:"M0 0.28418 L0.001041 0.654362 L0.008211 0.755064 L0.026553 0.829656 L0.061719 0.886392 L0.107727 0.923907 L0.176458 0.950999 L0.263182 0.961245 L0.324048 0.950988 L0.373972 0.923967 L0.403848 0.892311 L0.416676 0.871502 L0.436299 0.818446 L0.445458 0.748163 L0.450391 0.28518",V:"M0 0.28418 L0.280187 0.949893 L0.523828 0.28418",W:"M0 0.28418 L0.171565 0.941466 L0.36783 0.484439 L0.578114 0.949893 L0.736328 0.298555",X:"M0 0.28418 L0.519414 0.949893 M0.525 0.28418 L0.005585 0.949893",Y:"M0 0.28418 L0.255177 0.581837 M0.525 0.285125 L0.256867 0.583727 L0.266443 0.949893",Z:"M0 0.28418 L0.452734 0.28418 L0 0.949893 L0.452734 0.949893","[":"M0.155078 0.28418 L0 0.28418 L0 1.134712 L0.155078 1.134712","\\":"M0 0.271973 L0.222266 0.960391","]":"M0 0.28418 L0.155078 0.28418 L0.155078 1.134712 L0 1.134712","^":"M0 0.635708 L0.166602 0.271973 L0.333203 0.635708",_:"M0 1.135254 L0.466016 1.135254",a:"M0.382031 0.469727 L0.382031 0.973779 M0.382031 0.577216 L0.318041 0.505209 L0.255006 0.469727 L0.159498 0.469727 L0.095508 0.505209 L0.031517 0.577216 L0 0.685749 L0 0.757757 L0.031517 0.865246 L0.095508 0.937254 L0.159498 0.973779 L0.255006 0.973779 L0.318041 0.937254 L0.382031 0.865246",b:"M0 0.28418 L0 0.960791 M0 0.606153 L0.06026 0.541759 L0.119622 0.510028 L0.209563 0.510028 L0.269824 0.541759 L0.330086 0.606153 L0.359766 0.703212 L0.359766 0.767607 L0.330086 0.863732 L0.269824 0.928127 L0.209563 0.960791 L0.119622 0.960791 L0.06026 0.928127 L0 0.863732",c:"M0.361328 0.577216 L0.300805 0.505209 L0.241186 0.469727 L0.150854 0.469727 L0.090332 0.505209 L0.029809 0.577216 L0 0.685749 L0 0.757757 L0.029809 0.865246 L0.090332 0.937254 L0.150854 0.973779 L0.241186 0.973779 L0.300805 0.937254 L0.361328 0.865246",d:"M0.359766 0.28418 L0.359766 0.960791 M0.359766 0.606153 L0.299506 0.541759 L0.240143 0.510028 L0.150202 0.510028 L0.089941 0.541759 L0.02968 0.606153 L0 0.703212 L0 0.767607 L0.02968 0.863732 L0.089941 0.928127 L0.150202 0.960791 L0.240143 0.960791 L0.299506 0.928127 L0.359766 0.863732",e:"M0 0.685749 L0.382422 0.685749 M0.382422 0.613742 L0.350872 0.541734 L0.318366 0.505209 L0.255267 0.469727 L0.159661 0.469727 L0.095606 0.505209 L0.03155 0.577216 L0 0.685749 L0 0.757757 L0.03155 0.865246 L0.095606 0.937254 L0.159661 0.973779 L0.255267 0.973779 L0.318366 0.937254 L0.382422 0.865246",f:"M0.242578 0.271973 L0.181934 0.271973 L0.121289 0.304659 L0.090967 0.400849 L0.090967 0.949038 M0 0.497972 L0.212256 0.497972",g:"M0.365625 0.469727 L0.365625 0.994944 L0.33546 1.092946 L0.304382 1.126248 L0.244054 1.158599 L0.152648 1.158599 L0.091406 1.126248 L0.030164 1.060596 L0 0.961642 M0.365625 0.567729 L0.304382 0.502077 L0.244054 0.469727 L0.152648 0.469727 L0.091406 0.502077 L0.030164 0.567729 L0 0.666683 L0 0.732335 L0.030164 0.830338 L0.091406 0.89599 L0.152648 0.929292 L0.244054 0.929292 L0.304382 0.89599 L0.365625 0.830338",h:"M0 0.28418 L0 0.949893 M0 0.633105 L0.092075 0.53761 L0.15374 0.50639 L0.245815 0.50639 L0.307058 0.53761 L0.337891 0.633105 L0.337891 0.949893",i:"M0 0.28418 L0.070313 0.28418 M0.035156 0.50639 L0.035156 0.949893",j:"M0.124312 0.28418 L0.159375 0.28418 M0.141843 0.499983 L0.141843 1.022549 L0.124312 1.115291 L0.053125 1.14561 L0 1.115291",k:"M0 0.28418 L0 0.949893 M0.312383 0.50639 L0 0.823178 M0.125039 0.696463 L0.34375 0.949893",l:"M0 0.28418 L0 0.949893",m:"M0 0.469727 L0 0.962881 M0 0.610628 L0.071661 0.504441 L0.119654 0.469727 L0.209065 0.469727 L0.257058 0.504441 L0.305051 0.610628 L0.305051 0.962881 M0.305051 0.610628 L0.376712 0.504441 L0.424047 0.469727 L0.514116 0.469727 L0.562109 0.504441 L0.562109 0.962881",n:"M0 0.469727 L0 0.962881 M0 0.610628 L0.091862 0.504441 L0.153385 0.469727 L0.245247 0.469727 L0.306348 0.504441 L0.337109 0.610628 L0.337109 0.962881",o:"M0.149639 0.469727 L0.08988 0.505209 L0.030122 0.577216 L0 0.685749 L0 0.757757 L0.030122 0.865246 L0.08988 0.937254 L0.149639 0.973779 L0.239033 0.973779 L0.298792 0.937254 L0.35855 0.865246 L0.388672 0.757757 L0.388672 0.685749 L0.35855 0.577216 L0.298792 0.505209 L0.239033 0.469727 L0.149639 0.469727",p:"M0 0.469727 L0 1.1477 M0 0.566179 L0.060326 0.501565 L0.119752 0.469727 L0.209791 0.469727 L0.270117 0.501565 L0.330443 0.566179 L0.360156 0.663567 L0.360156 0.728181 L0.330443 0.824633 L0.270117 0.889246 L0.209791 0.922021 L0.119752 0.922021 L0.060326 0.889246 L0 0.824633",q:"M0.359375 0.469727 L0.359375 1.1477 M0.359375 0.566179 L0.29918 0.501565 L0.239883 0.469727 L0.150039 0.469727 L0.089844 0.501565 L0.029649 0.566179 L0 0.663567 L0 0.728181 L0.029649 0.824633 L0.089844 0.889246 L0.150039 0.922021 L0.239883 0.922021 L0.29918 0.889246 L0.359375 0.824633",r:"M0 0.469727 L0 0.962881 M0 0.681078 L0.028174 0.574892 L0.084522 0.504441 L0.14087 0.469727 L0.225391 0.469727",s:"M0.322998 0.505209 L0.258398 0.469727 L0.150732 0.469727 L0.064599 0.505209 L0 0.577216 L0 0.649224 L0.064599 0.685749 L0.172265 0.685749 L0.279931 0.757757 L0.344531 0.829764 L0.344531 0.901772 L0.279931 0.937254 L0.193799 0.973779 L0.086133 0.973779 L0.021533 0.937254 L0 0.865246",t:"M0.075879 0.300293 L0.075879 0.832305 L0.101172 0.925657 L0.151758 0.957378 L0.202344 0.957378 M0 0.519623 L0.177051 0.519623",u:"M0 0.481445 L0 0.833698 L0.03069 0.938864 L0.091649 0.9746 L0.183299 0.9746 L0.244679 0.938864 L0.336328 0.833698 M0.336328 0.481445 L0.336328 0.9746",v:"M0 0.481445 L0.190235 0.963701 M0.380469 0.481445 L0.190235 0.963701",w:"M0 0.481445 L0.142285 0.963701 M0.28457 0.481445 L0.142285 0.963701 M0.28457 0.481445 L0.426855 0.963701 M0.569141 0.481445 L0.426855 0.963701",x:"M0 0.481445 L0.388281 0.963701 M0.388281 0.481445 L0 0.963701",y:"M0.029456 0.481445 L0.204292 0.93374 M0.380078 0.481445 L0.204292 0.93374 L0.14633 1.062967 L0.087893 1.12758 L0.029456 1.159419 L0 1.159419",z:"M0.367188 0.481445 L0 0.963701 M0 0.481445 L0.367188 0.481445 M0 0.963701 L0.367188 0.963701"},jw={};for(const e in h9A){jw[e]=[];const A=h9A[e].split("M").slice(1).map(t=>t.split("L").map(i=>i.trim().split(" ").map(parseFloat)));for(const t of A)for(let i=0;i<t.length-1;i++)jw[e].push({x1:t[i][0],y1:1-t[i][1],x2:t[i+1][0],y2:1-t[i+1][1]})}function Mce(e,A){if(!A.layers||A.layers.length===0)return!0;const t=sNA(e);return t.length===0?!0:t.some(i=>A.layers.includes(i))}var Nce={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:"#FF00FF",keepout:"#FF6B6B"};function Lu(e){const{ctx:A,center:t,radius:i,fill:o,realToCanvasMat:n}=e,[s,r]=Pe(n,[t.x,t.y]),a=i*Math.abs(n.a);A.beginPath(),A.arc(s,r,a,0,Math.PI*2),A.fillStyle=o,A.fill()}function lI(e){const{ctx:A,center:t,width:i,height:o,fill:n,realToCanvasMat:s,borderRadius:r=0,rotation:a=0,stroke:g,strokeWidth:I,isStrokeDashed:c=!1}=e,[B,l]=Pe(s,[t.x,t.y]),C=i*Math.abs(s.a),E=o*Math.abs(s.a),Q=r*Math.abs(s.a),h=I?I*Math.abs(s.a):void 0;if(A.save(),A.translate(B,l),a!==0&&A.rotate(-a*(Math.PI/180)),A.beginPath(),Q>0){const u=-C/2,d=-E/2,f=Math.min(Q,C/2,E/2);A.moveTo(u+f,d),A.lineTo(u+C-f,d),A.arcTo(u+C,d,u+C,d+f,f),A.lineTo(u+C,d+E-f),A.arcTo(u+C,d+E,u+C-f,d+E,f),A.lineTo(u+f,d+E),A.arcTo(u,d+E,u,d+E-f,f),A.lineTo(u,d+f),A.arcTo(u,d,u+f,d,f)}else A.rect(-C/2,-E/2,C,E);n&&(A.fillStyle=n,A.fill()),g&&h&&(c?A.setLineDash([h*3,h*2]):A.setLineDash([]),A.strokeStyle=g,A.lineWidth=h,A.stroke()),A.restore()}function WS(e){const{ctx:A,center:t,radius_x:i,radius_y:o,fill:n,stroke:s,strokeWidth:r=.1,realToCanvasMat:a,rotation:g=0}=e,[I,c]=Pe(a,[t.x,t.y]),B=i*Math.abs(a.a),l=o*Math.abs(a.a),C=r*Math.abs(a.a);A.save(),A.translate(I,c),g!==0&&A.rotate(-g*(Math.PI/180)),A.beginPath(),A.ellipse(0,0,B,l,0,0,Math.PI*2),n&&(A.fillStyle=n,A.fill()),s&&(A.strokeStyle=s,A.lineWidth=C,A.stroke()),A.restore()}function Wl(e){const{ctx:A,center:t,width:i,height:o,fill:n,realToCanvasMat:s,rotation:r=0,stroke:a,strokeWidth:g}=e,[I,c]=Pe(s,[t.x,t.y]),B=i*Math.abs(s.a),l=o*Math.abs(s.a),C=g?g*Math.abs(s.a):void 0;if(A.save(),A.translate(I,c),r!==0&&A.rotate(-r*(Math.PI/180)),A.beginPath(),B>l){const E=l/2,Q=B-l;A.moveTo(-Q/2,-E),A.lineTo(Q/2,-E),A.arc(Q/2,0,E,-Math.PI/2,Math.PI/2),A.lineTo(-Q/2,E),A.arc(-Q/2,0,E,Math.PI/2,-Math.PI/2)}else if(l>B){const E=B/2,Q=l-B;A.moveTo(E,-Q/2),A.lineTo(E,Q/2),A.arc(0,Q/2,E,0,Math.PI),A.lineTo(-E,-Q/2),A.arc(0,-Q/2,E,Math.PI,0)}else A.arc(0,0,B/2,0,Math.PI*2);A.closePath(),n&&(A.fillStyle=n,A.fill()),a&&C&&(A.strokeStyle=a,A.lineWidth=C,A.stroke()),A.restore()}function i_(e){const{ctx:A,points:t,fill:i,realToCanvasMat:o}=e;if(t.length<3)return;A.beginPath();const n=t.map(g=>Pe(o,[g.x,g.y])),s=n[0];if(!s)return;const[r,a]=s;A.moveTo(r,a);for(let g=1;g<n.length;g++){const I=n[g];if(!I)continue;const[c,B]=I;A.lineTo(c,B)}A.closePath(),A.fillStyle=i,A.fill()}function vG(e,A,t,i,o,n,s,r,a,g){const[I,c]=Pe(r,[A.x,A.y]),B=t*Math.abs(r.a),l=i*Math.abs(r.a),C=Math.abs(o)*Math.abs(r.a),E=n*Math.abs(r.a);e.save(),e.translate(I,c),s!==0&&e.rotate(-s*(Math.PI/180));const Q=e.globalCompositeOperation;e.globalCompositeOperation!==void 0&&(e.globalCompositeOperation="source-atop");const h=B,u=l,d=E;if(e.beginPath(),d>0){const w=-h/2,b=-u/2,k=Math.min(d,h/2,u/2);e.moveTo(w+k,b),e.lineTo(w+h-k,b),e.arcTo(w+h,b,w+h,b+k,k),e.lineTo(w+h,b+u-k),e.arcTo(w+h,b+u,w+h-k,b+u,k),e.lineTo(w+k,b+u),e.arcTo(w,b+u,w,b+u-k,k),e.lineTo(w,b+k),e.arcTo(w,b,w+k,b,k)}else e.rect(-h/2,-u/2,h,u);e.fillStyle=a,e.fill(),e.globalCompositeOperation!==void 0&&(e.globalCompositeOperation=Q||"source-over");const f=B-C*2,m=l-C*2,D=Math.max(0,E-C);if(f>0&&m>0){if(e.beginPath(),D>0){const w=-f/2,b=-m/2,k=Math.min(D,f/2,m/2);e.moveTo(w+k,b),e.lineTo(w+f-k,b),e.arcTo(w+f,b,w+f,b+k,k),e.lineTo(w+f,b+m-k),e.arcTo(w+f,b+m,w+f-k,b+m,k),e.lineTo(w+k,b+m),e.arcTo(w,b+m,w,b+m-k,k),e.lineTo(w,b+k),e.arcTo(w,b,w+k,b,k)}else e.rect(-f/2,-m/2,f,m);e.fillStyle=g,e.fill()}e.restore()}function IQA(e,A,t,i,o,n,s){const[r,a]=Pe(o,[A.x,A.y]),g=t*Math.abs(o.a),I=Math.abs(i)*Math.abs(o.a);e.save();const c=e.globalCompositeOperation;e.globalCompositeOperation!==void 0&&(e.globalCompositeOperation="source-atop"),e.beginPath(),e.arc(r,a,g,0,Math.PI*2),e.fillStyle=n,e.fill(),e.globalCompositeOperation!==void 0&&(e.globalCompositeOperation=c||"source-over");const B=Math.max(0,g-I);B>0&&(e.beginPath(),e.arc(r,a,B,0,Math.PI*2),e.fillStyle=s,e.fill()),e.restore()}function NU(e,A,t,i,o,n,s,r,a){const[g,I]=Pe(s,[A.x,A.y]),c=t*Math.abs(s.a),B=i*Math.abs(s.a),l=Math.abs(o)*Math.abs(s.a);e.save(),e.translate(g,I),n!==0&&e.rotate(-n*(Math.PI/180));const C=e.globalCompositeOperation;e.globalCompositeOperation!==void 0&&(e.globalCompositeOperation="source-atop");const E=c,Q=B;if(e.beginPath(),E>Q){const d=Q/2,f=E-Q;e.moveTo(-f/2,-d),e.lineTo(f/2,-d),e.arc(f/2,0,d,-Math.PI/2,Math.PI/2),e.lineTo(-f/2,d),e.arc(-f/2,0,d,Math.PI/2,-Math.PI/2)}else if(Q>E){const d=E/2,f=Q-E;e.moveTo(d,-f/2),e.lineTo(d,f/2),e.arc(0,f/2,d,0,Math.PI),e.lineTo(-d,-f/2),e.arc(0,-f/2,d,Math.PI,0)}else e.arc(0,0,E/2,0,Math.PI*2);e.fillStyle=r,e.fill(),e.globalCompositeOperation!==void 0&&(e.globalCompositeOperation=C||"source-over");const h=c-l*2,u=B-l*2;if(h>0&&u>0){if(e.beginPath(),h>u){const d=u/2,f=h-u;e.moveTo(-f/2,-d),e.lineTo(f/2,-d),e.arc(f/2,0,d,-Math.PI/2,Math.PI/2),e.lineTo(-f/2,d),e.arc(-f/2,0,d,Math.PI/2,-Math.PI/2)}else if(u>h){const d=h/2,f=u-h;e.moveTo(d,-f/2),e.lineTo(d,f/2),e.arc(0,f/2,d,0,Math.PI),e.lineTo(-d,-f/2),e.arc(0,-f/2,d,Math.PI,0)}else e.arc(0,0,h/2,0,Math.PI*2);e.fillStyle=a,e.fill()}e.restore()}function u9A(e,A,t,i,o,n,s,r,a){const[g,I]=Pe(s,[A.x,A.y]),c=t*Math.abs(s.a),B=i*Math.abs(s.a),l=Math.abs(o)*Math.abs(s.a);e.save(),e.translate(g,I),n!==0&&e.rotate(-n*(Math.PI/180));const C=e.globalCompositeOperation;e.globalCompositeOperation!==void 0&&(e.globalCompositeOperation="source-atop"),e.beginPath(),e.ellipse(0,0,c,B,0,0,Math.PI*2),e.fillStyle=r,e.fill(),e.globalCompositeOperation!==void 0&&(e.globalCompositeOperation=C||"source-over");const E=Math.max(0,c-l),Q=Math.max(0,B-l);E>0&&Q>0&&(e.beginPath(),e.ellipse(0,0,E,Q,0,0,Math.PI*2),e.fillStyle=a,e.fill()),e.restore()}function cQA(e,A){if(e.length<3||A===0)return e;let t=0,i=0;for(const n of e)t+=n.x,i+=n.y;t/=e.length,i/=e.length;const o=[];for(const n of e){const s=n.x-t,r=n.y-i,a=Math.sqrt(s*s+r*r);if(a>0){const g=s/a,I=r/a;o.push({x:n.x+g*A,y:n.y+I*A})}else o.push({x:n.x+A,y:n.y})}return o}function d9A(e,A,t,i,o,n){if(A.length<3||t>=0)return;Math.abs(t)*Math.abs(i.a);const s=e.globalCompositeOperation;e.globalCompositeOperation!==void 0&&(e.globalCompositeOperation="source-atop"),e.beginPath();const r=A.map(I=>Pe(i,[I.x,I.y])),a=r[0];if(a){const[I,c]=a;e.moveTo(I,c);for(let B=1;B<r.length;B++){const l=r[B];if(l){const[C,E]=l;e.lineTo(C,E)}}e.closePath(),e.fillStyle=o,e.fill()}e.globalCompositeOperation!==void 0&&(e.globalCompositeOperation=s||"source-over");const g=cQA(A,t);if(g.length>=3){e.beginPath();const I=g.map(B=>Pe(i,[B.x,B.y])),c=I[0];if(c){const[B,l]=c;e.moveTo(B,l);for(let C=1;C<I.length;C++){const E=I[C];if(E){const[Q,h]=E;e.lineTo(Q,h)}}e.closePath(),e.fillStyle=n,e.fill()}}e.restore()}function vce(e,A){const t=e?.includes("top")?"top":"bottom";return A.soldermaskOverCopper[t]??A.soldermaskOverCopper.top}function Lce(e){const{ctx:A,hole:t,realToCanvasMat:i,colorMap:o}=e,n=t.is_covered_with_solder_mask===!0,s=n?0:t.soldermask_margin??0,r=!n&&t.soldermask_margin!==void 0&&t.soldermask_margin!==0,a=vce(t.layers,o),g=o.substrate,I=o.copper.top;if(t.shape==="circle"){r&&s>0&&Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.outer_diameter/2+s,fill:g,realToCanvasMat:i}),Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.outer_diameter/2,fill:I,realToCanvasMat:i}),r&&s<0&&IQA(A,{x:t.x,y:t.y},t.outer_diameter/2,s,i,a,I),n&&Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.outer_diameter/2,fill:a,realToCanvasMat:i}),n||Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.hole_diameter/2,fill:o.drill,realToCanvasMat:i});return}if(t.shape==="oval"){r&&s>0&&WS({ctx:A,center:{x:t.x,y:t.y},radius_x:t.outer_width/2+s,radius_y:t.outer_height/2+s,fill:g,realToCanvasMat:i,rotation:t.ccw_rotation}),WS({ctx:A,center:{x:t.x,y:t.y},radius_x:t.outer_width/2,radius_y:t.outer_height/2,fill:I,realToCanvasMat:i,rotation:t.ccw_rotation}),r&&s<0&&u9A(A,{x:t.x,y:t.y},t.outer_width/2,t.outer_height/2,s,t.ccw_rotation??0,i,a,I),n&&WS({ctx:A,center:{x:t.x,y:t.y},radius_x:t.outer_width/2,radius_y:t.outer_height/2,fill:a,realToCanvasMat:i,rotation:t.ccw_rotation}),n||WS({ctx:A,center:{x:t.x,y:t.y},radius_x:t.hole_width/2,radius_y:t.hole_height/2,fill:o.drill,realToCanvasMat:i,rotation:t.ccw_rotation});return}if(t.shape==="pill"){r&&s>0&&Wl({ctx:A,center:{x:t.x,y:t.y},width:t.outer_width+s*2,height:t.outer_height+s*2,fill:g,realToCanvasMat:i,rotation:t.ccw_rotation}),Wl({ctx:A,center:{x:t.x,y:t.y},width:t.outer_width,height:t.outer_height,fill:I,realToCanvasMat:i,rotation:t.ccw_rotation}),r&&s<0&&NU(A,{x:t.x,y:t.y},t.outer_width,t.outer_height,s,t.ccw_rotation??0,i,a,I),n&&Wl({ctx:A,center:{x:t.x,y:t.y},width:t.outer_width,height:t.outer_height,fill:a,realToCanvasMat:i,rotation:t.ccw_rotation}),n||Wl({ctx:A,center:{x:t.x,y:t.y},width:t.hole_width,height:t.hole_height,fill:o.drill,realToCanvasMat:i,rotation:t.ccw_rotation});return}if(t.shape==="circular_hole_with_rect_pad"){if(r&&s>0&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.rect_pad_width+s*2,height:t.rect_pad_height+s*2,fill:g,realToCanvasMat:i,borderRadius:t.rect_border_radius??0}),lI({ctx:A,center:{x:t.x,y:t.y},width:t.rect_pad_width,height:t.rect_pad_height,fill:I,realToCanvasMat:i,borderRadius:t.rect_border_radius??0}),r&&s<0&&vG(A,{x:t.x,y:t.y},t.rect_pad_width,t.rect_pad_height,s,t.rect_border_radius??0,0,i,a,I),n&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.rect_pad_width,height:t.rect_pad_height,fill:a,realToCanvasMat:i,borderRadius:t.rect_border_radius??0}),!n){const c=t.x+(t.hole_offset_x??0),B=t.y+(t.hole_offset_y??0);Lu({ctx:A,center:{x:c,y:B},radius:t.hole_diameter/2,fill:o.drill,realToCanvasMat:i})}return}if(t.shape==="pill_hole_with_rect_pad"){if(r&&s>0&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.rect_pad_width+s*2,height:t.rect_pad_height+s*2,fill:g,realToCanvasMat:i,borderRadius:t.rect_border_radius??0}),lI({ctx:A,center:{x:t.x,y:t.y},width:t.rect_pad_width,height:t.rect_pad_height,fill:I,realToCanvasMat:i,borderRadius:t.rect_border_radius??0}),r&&s<0&&vG(A,{x:t.x,y:t.y},t.rect_pad_width,t.rect_pad_height,s,t.rect_border_radius??0,0,i,a,I),n&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.rect_pad_width,height:t.rect_pad_height,fill:a,realToCanvasMat:i,borderRadius:t.rect_border_radius??0}),!n){const c=t.x+(t.hole_offset_x??0),B=t.y+(t.hole_offset_y??0);Wl({ctx:A,center:{x:c,y:B},width:t.hole_width,height:t.hole_height,fill:o.drill,realToCanvasMat:i})}return}if(t.shape==="rotated_pill_hole_with_rect_pad"){if(r&&s>0&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.rect_pad_width+s*2,height:t.rect_pad_height+s*2,fill:g,realToCanvasMat:i,borderRadius:t.rect_border_radius??0,rotation:t.rect_ccw_rotation}),lI({ctx:A,center:{x:t.x,y:t.y},width:t.rect_pad_width,height:t.rect_pad_height,fill:I,realToCanvasMat:i,borderRadius:t.rect_border_radius??0,rotation:t.rect_ccw_rotation}),r&&s<0&&vG(A,{x:t.x,y:t.y},t.rect_pad_width,t.rect_pad_height,s,t.rect_border_radius??0,t.rect_ccw_rotation??0,i,a,I),n&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.rect_pad_width,height:t.rect_pad_height,fill:a,realToCanvasMat:i,borderRadius:t.rect_border_radius??0,rotation:t.rect_ccw_rotation}),!n){const c=t.x+(t.hole_offset_x??0),B=t.y+(t.hole_offset_y??0);Wl({ctx:A,center:{x:c,y:B},width:t.hole_width,height:t.hole_height,fill:o.drill,realToCanvasMat:i,rotation:t.hole_ccw_rotation})}return}if(t.shape==="hole_with_polygon_pad"){const c=t.pad_outline;if(c&&c.length>=3){const B=c.map(l=>({x:t.x+l.x,y:t.y+l.y}));if(r&&s>0){const l=cQA(B,s);i_({ctx:A,points:l,fill:g,realToCanvasMat:i})}i_({ctx:A,points:B,fill:I,realToCanvasMat:i}),r&&s<0&&d9A(A,B,s,i,a,I),n&&i_({ctx:A,points:B,fill:a,realToCanvasMat:i})}if(!n){const B=t.x+(t.hole_offset_x??0),l=t.y+(t.hole_offset_y??0),C=t.hole_shape;C==="circle"?Lu({ctx:A,center:{x:B,y:l},radius:(t.hole_diameter??0)/2,fill:o.drill,realToCanvasMat:i}):C==="oval"?WS({ctx:A,center:{x:B,y:l},radius_x:(t.hole_width??0)/2,radius_y:(t.hole_height??0)/2,fill:o.drill,realToCanvasMat:i}):C==="pill"?Wl({ctx:A,center:{x:B,y:l},width:t.hole_width??0,height:t.hole_height??0,fill:o.drill,realToCanvasMat:i}):C==="rotated_pill"&&Wl({ctx:A,center:{x:B,y:l},width:t.hole_width??0,height:t.hole_height??0,fill:o.drill,realToCanvasMat:i})}return}}function Uce(e){const{ctx:A,via:t,realToCanvasMat:i,colorMap:o}=e;Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.outer_diameter/2,fill:o.copper.top,realToCanvasMat:i}),Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.hole_diameter/2,fill:o.drill,realToCanvasMat:i})}function vU(e){return"ccw_rotation"in e&&typeof e.ccw_rotation=="number"?e.ccw_rotation:0}function Hce(e){const{ctx:A,hole:t,realToCanvasMat:i,colorMap:o}=e,n=t.is_covered_with_solder_mask===!0,s=n?0:t.soldermask_margin??0,r=!n&&t.soldermask_margin!==void 0&&t.soldermask_margin!==0,a=o.substrate,g=o.soldermaskOverCopper.top,I=o.soldermaskOverCopper.top;if(t.hole_shape==="circle"){r&&s>0&&Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.hole_diameter/2+s,fill:a,realToCanvasMat:i}),n||(Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.hole_diameter/2,fill:o.drill,realToCanvasMat:i}),r&&s<0&&IQA(A,{x:t.x,y:t.y},t.hole_diameter/2,s,i,I,o.drill)),n&&Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.hole_diameter/2,fill:g,realToCanvasMat:i});return}if(t.hole_shape==="square"){const c=vU(t);r&&s>0&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.hole_diameter+s*2,height:t.hole_diameter+s*2,fill:a,realToCanvasMat:i,rotation:c}),n||(lI({ctx:A,center:{x:t.x,y:t.y},width:t.hole_diameter,height:t.hole_diameter,fill:o.drill,realToCanvasMat:i,rotation:c}),r&&s<0&&vG(A,{x:t.x,y:t.y},t.hole_diameter,t.hole_diameter,s,0,c,i,I,o.drill)),n&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.hole_diameter,height:t.hole_diameter,fill:g,realToCanvasMat:i,rotation:c});return}if(t.hole_shape==="oval"){const c=vU(t);r&&s>0&&WS({ctx:A,center:{x:t.x,y:t.y},radius_x:t.hole_width/2+s,radius_y:t.hole_height/2+s,fill:a,realToCanvasMat:i,rotation:c}),n||(WS({ctx:A,center:{x:t.x,y:t.y},radius_x:t.hole_width/2,radius_y:t.hole_height/2,fill:o.drill,realToCanvasMat:i,rotation:c}),r&&s<0&&u9A(A,{x:t.x,y:t.y},t.hole_width/2,t.hole_height/2,s,c,i,I,o.drill)),n&&WS({ctx:A,center:{x:t.x,y:t.y},radius_x:t.hole_width/2,radius_y:t.hole_height/2,fill:g,realToCanvasMat:i,rotation:c});return}if(t.hole_shape==="rect"){const c=vU(t);r&&s>0&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.hole_width+s*2,height:t.hole_height+s*2,fill:a,realToCanvasMat:i,rotation:c}),n||(lI({ctx:A,center:{x:t.x,y:t.y},width:t.hole_width,height:t.hole_height,fill:o.drill,realToCanvasMat:i,rotation:c}),r&&s<0&&vG(A,{x:t.x,y:t.y},t.hole_width,t.hole_height,s,0,c,i,I,o.drill)),n&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.hole_width,height:t.hole_height,fill:g,realToCanvasMat:i,rotation:c});return}if(t.hole_shape==="pill"){const c=vU(t);r&&s>0&&Wl({ctx:A,center:{x:t.x,y:t.y},width:t.hole_width+s*2,height:t.hole_height+s*2,fill:a,realToCanvasMat:i,rotation:c}),n||(Wl({ctx:A,center:{x:t.x,y:t.y},width:t.hole_width,height:t.hole_height,fill:o.drill,realToCanvasMat:i,rotation:c}),r&&s<0&&NU(A,{x:t.x,y:t.y},t.hole_width,t.hole_height,s,c,i,I,o.drill)),n&&Wl({ctx:A,center:{x:t.x,y:t.y},width:t.hole_width,height:t.hole_height,fill:g,realToCanvasMat:i,rotation:c});return}if(t.hole_shape==="rotated_pill"){const c=vU(t);r&&s>0&&Wl({ctx:A,center:{x:t.x,y:t.y},width:t.hole_width+s*2,height:t.hole_height+s*2,fill:a,realToCanvasMat:i,rotation:c}),n||(Wl({ctx:A,center:{x:t.x,y:t.y},width:t.hole_width,height:t.hole_height,fill:o.drill,realToCanvasMat:i,rotation:c}),r&&s<0&&NU(A,{x:t.x,y:t.y},t.hole_width,t.hole_height,s,c,i,I,o.drill)),n&&Wl({ctx:A,center:{x:t.x,y:t.y},width:t.hole_width,height:t.hole_height,fill:g,realToCanvasMat:i,rotation:c});return}}function Yce(e,A){return A.copper[e]??A.copper.top}function p9A(e,A){return A.soldermaskOverCopper[e]??A.soldermaskOverCopper.top}function o_(e,A=0){return(e.corner_radius??e.rect_border_radius??0)+A}function Jce(e){const{ctx:A,pad:t,realToCanvasMat:i,colorMap:o}=e,n=Yce(t.layer,o),s=t.is_covered_with_solder_mask===!0,r=s?0:t.soldermask_margin??0,a=!s&&t.soldermask_margin!==void 0&&t.soldermask_margin!==0,g=p9A(t.layer,o),I=o.substrate,c=p9A(t.layer,o);if(t.shape==="rect"){a&&r>0&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.width+r*2,height:t.height+r*2,fill:I,realToCanvasMat:i,borderRadius:o_(t)}),lI({ctx:A,center:{x:t.x,y:t.y},width:t.width,height:t.height,fill:n,realToCanvasMat:i,borderRadius:o_(t)}),a&&r<0&&vG(A,{x:t.x,y:t.y},t.width,t.height,r,o_(t),0,i,g,n),s&&r===0&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.width,height:t.height,fill:c,realToCanvasMat:i,borderRadius:o_(t)});return}if(t.shape==="rotated_rect"){a&&r>0&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.width+r*2,height:t.height+r*2,fill:I,realToCanvasMat:i,borderRadius:o_(t),rotation:t.ccw_rotation??0}),lI({ctx:A,center:{x:t.x,y:t.y},width:t.width,height:t.height,fill:n,realToCanvasMat:i,borderRadius:o_(t),rotation:t.ccw_rotation??0}),a&&r<0&&vG(A,{x:t.x,y:t.y},t.width,t.height,r,o_(t),t.ccw_rotation??0,i,g,n),s&&r===0&&lI({ctx:A,center:{x:t.x,y:t.y},width:t.width,height:t.height,fill:c,realToCanvasMat:i,borderRadius:o_(t),rotation:t.ccw_rotation??0});return}if(t.shape==="circle"){a&&r>0&&Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.radius+r,fill:I,realToCanvasMat:i}),Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.radius,fill:n,realToCanvasMat:i}),a&&r<0&&IQA(A,{x:t.x,y:t.y},t.radius,r,i,g,n),s&&r===0&&Lu({ctx:A,center:{x:t.x,y:t.y},radius:t.radius,fill:c,realToCanvasMat:i});return}if(t.shape==="pill"){a&&r>0&&Wl({ctx:A,center:{x:t.x,y:t.y},width:t.width+r*2,height:t.height+r*2,fill:I,realToCanvasMat:i}),Wl({ctx:A,center:{x:t.x,y:t.y},width:t.width,height:t.height,fill:n,realToCanvasMat:i}),a&&r<0&&NU(A,{x:t.x,y:t.y},t.width,t.height,r,0,i,g,n),s&&r===0&&Wl({ctx:A,center:{x:t.x,y:t.y},width:t.width,height:t.height,fill:c,realToCanvasMat:i});return}if(t.shape==="rotated_pill"){a&&r>0&&Wl({ctx:A,center:{x:t.x,y:t.y},width:t.width+r*2,height:t.height+r*2,fill:I,realToCanvasMat:i,rotation:t.ccw_rotation??0}),Wl({ctx:A,center:{x:t.x,y:t.y},width:t.width,height:t.height,fill:n,realToCanvasMat:i,rotation:t.ccw_rotation??0}),a&&r<0&&NU(A,{x:t.x,y:t.y},t.width,t.height,r,t.ccw_rotation??0,i,g,n),s&&r===0&&Wl({ctx:A,center:{x:t.x,y:t.y},width:t.width,height:t.height,fill:c,realToCanvasMat:i,rotation:t.ccw_rotation??0});return}if(t.shape==="polygon"){if(t.points&&t.points.length>=3){if(a&&r>0){const B=cQA(t.points,r);i_({ctx:A,points:B,fill:I,realToCanvasMat:i})}i_({ctx:A,points:t.points,fill:n,realToCanvasMat:i}),a&&r<0&&d9A(A,t.points,r,i,g,n),s&&r===0&&i_({ctx:A,points:t.points,fill:c,realToCanvasMat:i})}return}}function LU(e){const{ctx:A,start:t,end:i,strokeWidth:o,stroke:n,realToCanvasMat:s,lineCap:r="round"}=e,[a,g]=Pe(s,[t.x,t.y]),[I,c]=Pe(s,[i.x,i.y]),B=o*Math.abs(s.a);A.beginPath(),A.moveTo(a,g),A.lineTo(I,c),A.lineWidth=B,A.strokeStyle=n,A.lineCap=r,A.stroke()}function Tce(e,A){return A.copper[e]??A.copper.top}function Kce(e){const{ctx:A,trace:t,realToCanvasMat:i,colorMap:o}=e;if(!(!t.route||!Array.isArray(t.route)||t.route.length<2))for(let n=0;n<t.route.length-1;n++){const s=t.route[n],r=t.route[n+1];if(!s||!r)continue;const a="layer"in s?s.layer:"layer"in r?r.layer:null;if(!a)continue;const g=Tce(a,o),I="width"in s?s.width:"width"in r?r.width:.1;LU({ctx:A,start:{x:s.x,y:s.y},end:{x:r.x,y:r.y},strokeWidth:I,stroke:g,realToCanvasMat:i,lineCap:"round"})}}function D8(e){const{ctx:A,points:t,fill:i,stroke:o,strokeWidth:n=1,realToCanvasMat:s,closePath:r=!1}=e;if(t.length<2)return;A.beginPath();const a=t.map(B=>Pe(s,[B.x,B.y])),g=a[0];if(!g)return;const[I,c]=g;A.moveTo(I,c);for(let B=1;B<a.length;B++){const l=a[B];if(!l)continue;const[C,E]=l;A.lineTo(C,E)}if(r&&A.closePath(),i&&(A.fillStyle=i,A.fill()),o){const B=n*Math.abs(s.a);A.strokeStyle=o,A.lineWidth=B,A.stroke()}}function Pce(e){const{ctx:A,board:t,realToCanvasMat:i,colorMap:o}=e,{width:n,height:s,center:r,outline:a}=t;if(a&&Array.isArray(a)&&a.length>=3){D8({ctx:A,points:a.map(g=>({x:g.x,y:g.y})),stroke:o.boardOutline,strokeWidth:.1,realToCanvasMat:i,closePath:!0});return}if(n!==void 0&&s!==void 0&&r){lI({ctx:A,center:r,width:n,height:s,fill:"transparent",realToCanvasMat:i});const g=n/2,I=s/2,c=[{x:r.x-g,y:r.y-I},{x:r.x+g,y:r.y-I},{x:r.x+g,y:r.y+I},{x:r.x-g,y:r.y+I}];D8({ctx:A,points:c,stroke:o.boardOutline,strokeWidth:.1,realToCanvasMat:i,closePath:!0})}}var qce=.62,Oce=.3,Wce=1,Zce=.13;function S8(e,A){const t=A*qce,i=t*Oce,o=t*Wce,n=Array.from(e);let s=0;n.forEach((a,g)=>{s+=a===" "?o:t,g<n.length-1&&(s+=i)});const r=Math.max(A*Zce,.35);return{width:s,height:A,glyphWidth:t,letterSpacing:i,spaceWidth:o,strokeWidth:r}}function BQA(e,A){const t=A.width+A.strokeWidth,i=A.height+A.strokeWidth;let o=0,n=0;return e==="center"?o=-t/2:e==="top_left"||e==="bottom_left"||e==="center_left"?o=0:(e==="top_right"||e==="bottom_right"||e==="center_right")&&(o=-t),e==="center"?n=-i/2:e==="top_left"||e==="top_right"||e==="top_center"?n=0:e==="bottom_left"||e==="bottom_right"||e==="bottom_center"?n=-i:n=0,{x:o,y:n}}var Vce=e=>jw[e]??jw[e.toUpperCase()];function lQA(e){const{ctx:A,text:t,fontSize:i,startX:o,startY:n}=e,s=S8(t,i),{glyphWidth:r,letterSpacing:a,spaceWidth:g,height:I,strokeWidth:c}=s,B=n,l=Array.from(t);let C=o+c/2;l.forEach((E,Q)=>{const h=Vce(E),u=E===" "?g:r;if(h?.length){A.beginPath();for(const d of h){const f=C+d.x1*r,m=B+(1-d.y1)*I,D=C+d.x2*r,w=B+(1-d.y2)*I;A.moveTo(f,m),A.lineTo(D,w)}A.stroke()}C+=u,Q<l.length-1&&(C+=a)})}function CQA(e){const{ctx:A,text:t,x:i,y:o,fontSize:n,color:s,realToCanvasMat:r,anchorAlignment:a,rotation:g=0}=e;if(!t)return;const[I,c]=Pe(r,[i,o]),B=Math.abs(r.a),l=n*B,C=S8(t,l),E=BQA(a,C);A.save(),A.translate(I,c),g!==0&&A.rotate(-g*(Math.PI/180)),A.lineWidth=C.strokeWidth,A.lineCap="round",A.lineJoin="round",A.strokeStyle=s,lQA({ctx:A,text:t,fontSize:l,startX:E.x,startY:E.y}),A.restore()}function jce(e,A){return e==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function zce(e){return e||"center"}function Xce(e){const{ctx:A,text:t,realToCanvasMat:i,colorMap:o}=e,n=t.text??"";if(!n)return;const s=jce(t.layer,o),[r,a]=Pe(i,[t.anchor_position.x,t.anchor_position.y]),g=Math.abs(i.a),I=(t.font_size??1)*g,c=t.ccw_rotation??0,B=S8(n,I),l=zce(t.anchor_alignment),C=BQA(l,B);A.save(),A.translate(r,a),c!==0&&A.rotate(-c*(Math.PI/180)),t.layer==="bottom"&&A.scale(-1,1),A.lineWidth=B.strokeWidth,A.lineCap="round",A.lineJoin="round",A.strokeStyle=s,lQA({ctx:A,text:n,fontSize:I,startX:C.x,startY:C.y}),A.restore()}function $ce(e,A){return e==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function ABe(e){const{ctx:A,rect:t,realToCanvasMat:i,colorMap:o}=e,n=$ce(t.layer,o);lI({ctx:A,center:t.center,width:t.width,height:t.height,fill:n,realToCanvasMat:i})}function tBe(e,A){return e==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function eBe(e){const{ctx:A,circle:t,realToCanvasMat:i,colorMap:o}=e,n=tBe(t.layer,o);Lu({ctx:A,center:t.center,radius:t.radius,fill:n,realToCanvasMat:i})}function iBe(e,A){return e==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function oBe(e){const{ctx:A,line:t,realToCanvasMat:i,colorMap:o}=e,n=iBe(t.layer,o);LU({ctx:A,start:{x:t.x1,y:t.y1},end:{x:t.x2,y:t.y2},strokeWidth:t.stroke_width??.1,stroke:n,realToCanvasMat:i})}function nBe(e,A){return e==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function sBe(e){const{ctx:A,path:t,realToCanvasMat:i,colorMap:o}=e,n=nBe(t.layer,o);if(!(!t.route||t.route.length<2))for(let s=0;s<t.route.length-1;s++){const r=t.route[s],a=t.route[s+1];!r||!a||LU({ctx:A,start:{x:r.x,y:r.y},end:{x:a.x,y:a.y},strokeWidth:t.stroke_width??.1,stroke:n,realToCanvasMat:i})}}function rBe(e,A){return e==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function aBe(e){const{ctx:A,oval:t,realToCanvasMat:i,colorMap:o}=e,n=rBe(t.layer,o);WS({ctx:A,center:t.center,radius_x:t.radius_x,radius_y:t.radius_y,stroke:n,strokeWidth:.1,realToCanvasMat:i,rotation:t.ccw_rotation??0})}function gBe(e,A){return e==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function IBe(e){const{ctx:A,pill:t,realToCanvasMat:i,colorMap:o}=e,n=gBe(t.layer,o);Wl({ctx:A,center:t.center,width:t.width,height:t.height,stroke:n,strokeWidth:.2,realToCanvasMat:i})}function cBe(e){const{ctx:A,cutout:t,realToCanvasMat:i,colorMap:o}=e;if(t.shape==="rect"){lI({ctx:A,center:t.center,width:t.width,height:t.height,fill:o.drill,realToCanvasMat:i,rotation:t.rotation??0,borderRadius:t.corner_radius??0});return}if(t.shape==="circle"){Lu({ctx:A,center:t.center,radius:t.radius,fill:o.drill,realToCanvasMat:i});return}if(t.shape==="polygon"){t.points&&t.points.length>=3&&i_({ctx:A,points:t.points,fill:o.drill,realToCanvasMat:i});return}}function BBe(e,A){const t=parseInt(e.slice(1,3),16),i=parseInt(e.slice(3,5),16),o=parseInt(e.slice(5,7),16);return`rgba(${t}, ${i}, ${o}, ${A})`}function lBe(e){const{ctx:A,keepout:t,realToCanvasMat:i,colorMap:o}=e,n=o.keepout,s=BBe(o.keepout,.2),r=1;if(t.shape==="rect"){const[a,g]=Pe(i,[t.center.x,t.center.y]),I=t.width*Math.abs(i.a),c=t.height*Math.abs(i.a),B=t.rotation??0;A.save(),A.translate(a,g),B!==0&&A.rotate(-B*(Math.PI/180)),A.beginPath(),A.rect(-I/2,-c/2,I,c),A.fillStyle=s,A.fill(),A.beginPath(),A.rect(-I/2,-c/2,I,c),A.clip();const l=r*Math.abs(i.a),C=Math.sqrt(I*I+c*c),E=I/2,Q=c/2;A.strokeStyle=n,A.lineWidth=.15*Math.abs(i.a),A.setLineDash([]);for(let h=-C;h<C*2;h+=l){A.beginPath();const u=-E+h,d=-Q,f=-E+h+C,m=-Q+C;A.moveTo(u,d),A.lineTo(f,m),A.stroke()}A.restore();return}if(t.shape==="circle"){const[a,g]=Pe(i,[t.center.x,t.center.y]),I=t.radius*Math.abs(i.a),c=r*Math.abs(i.a);A.save(),A.translate(a,g),A.beginPath(),A.arc(0,0,I,0,Math.PI*2),A.fillStyle=s,A.fill(),A.beginPath(),A.arc(0,0,I,0,Math.PI*2),A.clip();const B=I*2;A.strokeStyle=n,A.lineWidth=.15*Math.abs(i.a),A.setLineDash([]);for(let l=-B;l<B*2;l+=c)A.beginPath(),A.moveTo(l-B,-B),A.lineTo(l+B,B),A.stroke();A.restore();return}}function CBe(e,A){return A.copper[e]??A.copper.top}function QBe(e,A,t,i,o){if(Math.abs(o)<1e-10)return null;const n=t-e,s=i-A,r=Math.hypot(n,s);if(r<1e-10)return null;const a=Math.abs(o)*(r/2),g=r/2,I=(a*a+g*g)/(2*a),c=I-a,B=(e+t)/2,l=(A+i)/2,C=-s/r,E=n/r,Q=o>0?-1:1,h=B+Q*C*c,u=l+Q*E*c;return{centerX:h,centerY:u,radius:I}}function QQA(e,A,t,i,o,n,s){if(Math.abs(n)<1e-10){const[f,m]=Pe(s,[i,o]);e.lineTo(f,m);return}const r=QBe(A,t,i,o,n);if(!r){const[f,m]=Pe(s,[i,o]);e.lineTo(f,m);return}const[a,g]=Pe(s,[A,t]),[I,c]=Pe(s,[i,o]),[B,l]=Pe(s,[r.centerX,r.centerY]),C=Math.hypot(a-B,g-l),E=Math.atan2(g-l,a-B),Q=Math.atan2(c-l,I-B),u=s.a*s.d-s.b*s.c<0,d=n>0?!u:u;e.arc(B,l,C,E,Q,d)}function f9A(e,A,t){if(A.vertices.length<2)return;if(A.vertices.length===2){const s=A.vertices[0],r=A.vertices[1];if(s&&r&&Math.abs((s.bulge??0)-1)<1e-10&&Math.abs((r.bulge??0)-1)<1e-10){const[a,g]=Pe(t,[s.x,s.y]);e.moveTo(a,g),QQA(e,s.x,s.y,r.x,r.y,1,t),QQA(e,r.x,r.y,s.x,s.y,1,t);return}}const i=A.vertices[0];if(!i)return;const[o,n]=Pe(t,[i.x,i.y]);e.moveTo(o,n);for(let s=0;s<A.vertices.length;s++){const r=A.vertices[s],a=(s+1)%A.vertices.length,g=A.vertices[a];if(!r||!g)continue;const I=r.bulge??0;if(Math.abs(I)<1e-10){const[c,B]=Pe(t,[g.x,g.y]);e.lineTo(c,B)}else QQA(e,r.x,r.y,g.x,g.y,I,t)}}function EBe(e){const{ctx:A,pour:t,realToCanvasMat:i,colorMap:o}=e,n=CBe(t.layer,o);if(A.save(),t.shape==="rect"){const[s,r]=Pe(i,[t.center.x,t.center.y]),a=t.width*Math.abs(i.a),g=t.height*Math.abs(i.a);A.translate(s,r),t.rotation&&A.rotate(-t.rotation*(Math.PI/180)),A.beginPath(),A.rect(-a/2,-g/2,a,g),A.fillStyle=n,A.globalAlpha=.5,A.fill(),A.restore();return}if(t.shape==="polygon"){if(t.points&&t.points.length>=3){const s=t.points.map(I=>Pe(i,[I.x,I.y])),r=s[0];if(!r){A.restore();return}A.beginPath();const[a,g]=r;A.moveTo(a,g);for(let I=1;I<s.length;I++){const c=s[I];if(!c)continue;const[B,l]=c;A.lineTo(B,l)}A.closePath(),A.fillStyle=n,A.globalAlpha=.5,A.fill()}A.restore();return}if(t.shape==="brep"){if(A.beginPath(),f9A(A,t.brep_shape.outer_ring,i),t.brep_shape.inner_rings)for(const s of t.brep_shape.inner_rings)f9A(A,s,i);A.fillStyle=n,A.globalAlpha=.5,A.fill("evenodd"),A.restore();return}A.restore()}var hBe={left:.2,right:.2,top:.2,bottom:.2};function uBe(e){return e?e.includes("left")?"center_left":e.includes("right")?"center_right":"center":"center"}function dBe(e){const{ctx:A,text:t,realToCanvasMat:i,colorMap:o}=e,n=t.text??"";if(!n)return;const[s,r]=Pe(i,[t.anchor_position.x,t.anchor_position.y]),a=Math.abs(i.a),g=(t.font_size??1)*a,I=t.ccw_rotation??0,c={...hBe,...t.knockout_padding},B=o.copper[t.layer]??o.copper.top,l=S8(n,g),C=l.width+l.strokeWidth,E=uBe(t.anchor_alignment),Q=BQA(E,l);if(A.save(),A.translate(s,r),t.is_mirrored&&A.scale(-1,1),I!==0&&A.rotate(-I*(Math.PI/180)),A.lineWidth=l.strokeWidth,A.lineCap="round",A.lineJoin="round",t.is_knockout){const h=c.left*a,u=c.right*a,d=c.top*a,f=c.bottom*a,m=Q.x-h*4,D=Q.y-d*4,w=C+h*2+u*2,b=l.height+l.strokeWidth+d*2+f*2;A.fillStyle=B,A.fillRect(m,D,w,b)}else A.strokeStyle=B;lQA({ctx:A,text:n,fontSize:g,startX:Q.x,startY:Q.y}),A.restore()}var pBe="rgba(255,255,255,0.5)";function fBe(e,A){return pBe}function yBe(e){const{ctx:A,text:t,realToCanvasMat:i}=e,o=fBe(t.layer),n=t.color??o,s=t.font_size;CQA({ctx:A,text:t.text,x:t.anchor_position.x,y:t.anchor_position.y,fontSize:s,color:n,realToCanvasMat:i,anchorAlignment:t.anchor_alignment})}function mBe(e){const{ctx:A,rect:t,realToCanvasMat:i}=e,n=t.color??"rgba(255,255,255,0.5)",s=t.is_filled??!1,r=t.has_stroke??!0,a=t.is_stroke_dashed??!1;lI({ctx:A,center:t.center,width:t.width,height:t.height,fill:s?n:void 0,stroke:r?n:void 0,strokeWidth:r?t.stroke_width:void 0,borderRadius:t.corner_radius,realToCanvasMat:i,isStrokeDashed:a})}function wBe(e){const{ctx:A,rect:t,realToCanvasMat:i}=e,n=t.color??"rgb(89, 148, 220)",s=t.is_filled??!1,r=t.has_stroke??!0,a=t.is_stroke_dashed??!1;lI({ctx:A,center:t.center,width:t.width,height:t.height,fill:s?n:void 0,stroke:r?n:void 0,strokeWidth:r?t.stroke_width:void 0,borderRadius:t.corner_radius,realToCanvasMat:i,isStrokeDashed:a})}function DBe(e){const{ctx:A,path:t,realToCanvasMat:i}=e,n=t.color??"rgba(255,255,255,0.5)";if(!(!t.route||t.route.length<2))for(let s=0;s<t.route.length-1;s++){const r=t.route[s],a=t.route[s+1];!r||!a||LU({ctx:A,start:{x:r.x,y:r.y},end:{x:a.x,y:a.y},strokeWidth:t.stroke_width??.1,stroke:n,realToCanvasMat:i})}}function SBe(e){const{ctx:A,path:t,realToCanvasMat:i}=e,n=t.color??"rgb(89, 148, 220)";if(!(!t.route||t.route.length<2))for(let s=0;s<t.route.length-1;s++){const r=t.route[s],a=t.route[s+1];!r||!a||LU({ctx:A,start:{x:r.x,y:r.y},end:{x:a.x,y:a.y},strokeWidth:t.stroke_width??.1,stroke:n,realToCanvasMat:i})}}var bBe="rgb(89, 148, 220)";function xBe(e){const{ctx:A,text:t,realToCanvasMat:i}=e,o=bBe,n=t.color??o,s=t.font_size??1;CQA({ctx:A,text:t.text??"",x:t.anchor_position.x,y:t.anchor_position.y,fontSize:s,color:n,realToCanvasMat:i,anchorAlignment:t.anchor_alignment??"center"})}var _Be=1.5,kBe=.6,GBe=.3;function EQA(e){const A=Math.hypot(e.x,e.y)||1;return{x:e.x/A,y:e.y/A}}function y9A(e){const{ctx:A,from:t,to:i,realToCanvasMat:o,color:n,fontSize:s,arrowSize:r=1,strokeWidth:a,text:g,textRotation:I,offset:c}=e,B=EQA({x:i.x-t.x,y:i.y-t.y}),l={x:-B.y,y:B.x},C=c?.direction&&typeof c.direction.x=="number"&&typeof c.direction.y=="number",E=C?EQA(c.direction):{x:0,y:0},Q=c?.distance??0,h={x:E.x*Q,y:E.y*Q},u={x:t.x+h.x,y:t.y+h.y},d={x:i.x+h.x,y:i.y+h.y},f={x:u.x+B.x*r,y:u.y+B.y*r},m={x:d.x-B.x*r,y:d.y-B.y*r};Math.abs(o.a);const D=a??r/5,w=n||"rgba(255,255,255,0.5)",b=C&&(Math.abs(E.x)>Number.EPSILON||Math.abs(E.y)>Number.EPSILON)?E:l,k=Q+.5,x=[],N=J=>{const H={x:J.x+b.x*k,y:J.y+b.y*k},O=D/2,W={x:-b.y,y:b.x};return[{x:J.x+W.x*O,y:J.y+W.y*O},{x:J.x-W.x*O,y:J.y-W.y*O},{x:H.x-W.x*O,y:H.y-W.y*O},{x:H.x+W.x*O,y:H.y+W.y*O}]};x.push(u),x.push({x:f.x+l.x*(r/2),y:f.y+l.y*(r/2)}),x.push({x:f.x+l.x*(D/2),y:f.y+l.y*(D/2)}),x.push({x:m.x+l.x*(D/2),y:m.y+l.y*(D/2)}),x.push({x:m.x+l.x*(r/2),y:m.y+l.y*(r/2)}),x.push(d),x.push({x:m.x-l.x*(r/2),y:m.y-l.y*(r/2)}),x.push({x:m.x-l.x*(D/2),y:m.y-l.y*(D/2)}),x.push({x:f.x-l.x*(D/2),y:f.y-l.y*(D/2)}),x.push({x:f.x-l.x*(r/2),y:f.y-l.y*(r/2)}),x.push(u);const M=x[0],U=J=>{const H=N(J);x.push(M),x.push(H[0]),x.push(...H),x.push(H[0]),x.push(M)};if(U(t),U(i),i_({ctx:A,points:x,fill:w,realToCanvasMat:o}),g){const J={x:(t.x+i.x)/2+h.x,y:(t.y+i.y)/2+h.y},[H,O]=Pe(o,[u.x,u.y]),[W,$]=Pe(o,[d.x,d.y]),iA=EQA({x:W-H,y:$-O});let rA=Math.atan2(iA.y,iA.x)*180/Math.PI;(rA>90||rA<-90)&&(rA+=180);const tA=typeof I=="number"&&Number.isFinite(I)?rA-I:rA;let nA=0;if(g&&typeof I=="number"&&Number.isFinite(I)){const SA=g.length*s*kBe,FA=s,MA=I*Math.PI/180,TA=Math.abs(Math.sin(MA)),EA=Math.abs(Math.cos(MA)),GA=SA/2,dA=FA/2;nA=GA*TA+dA*EA+s*GBe}const aA=r*_Be+nA,QA={x:J.x+l.x*aA,y:J.y+l.y*aA};CQA({ctx:A,text:g,x:QA.x,y:QA.y,fontSize:s,color:w,realToCanvasMat:o,anchorAlignment:"center",rotation:-tA})}}var FBe="rgba(255,255,255,0.5)";function RBe(e){const{ctx:A,pcbNoteDimension:t,realToCanvasMat:i}=e,o=t.color??FBe;y9A({ctx:A,from:t.from,to:t.to,realToCanvasMat:i,color:o,fontSize:t.font_size,arrowSize:t.arrow_size,text:t.text,textRotation:t.text_ccw_rotation,offset:t.offset_distance&&t.offset_direction?{distance:t.offset_distance,direction:t.offset_direction}:void 0})}var MBe="rgba(255,255,255,0.5)";function NBe(e){const{ctx:A,pcbFabricationNoteDimension:t,realToCanvasMat:i}=e,o=t.color??MBe;y9A({ctx:A,from:t.from,to:t.to,realToCanvasMat:i,color:o,fontSize:t.font_size??1,arrowSize:t.arrow_size??1,text:t.text,textRotation:t.text_ccw_rotation,offset:t.offset_distance&&t.offset_direction?{distance:t.offset_distance,direction:t.offset_direction}:void 0})}function vBe(e){const{ctx:A,line:t,realToCanvasMat:i}=e,n=t.color??"rgb(89, 148, 220)",s=t.stroke_width??.1,r=t.is_dashed??!1,[a,g]=Pe(i,[t.x1,t.y1]),[I,c]=Pe(i,[t.x2,t.y2]),B=s*Math.abs(i.a);A.save(),r?A.setLineDash([B*2,B*2]):A.setLineDash([]),A.beginPath(),A.moveTo(a,g),A.lineTo(I,c),A.lineWidth=B,A.strokeStyle=n,A.lineCap="round",A.stroke(),A.restore()}var LBe=class{ctx;colorMap;realToCanvasMat;constructor(A){if("getContext"in A&&typeof A.getContext=="function"){const t=A.getContext("2d");if(!t)throw new Error("Failed to get 2D rendering context from canvas");this.ctx=t}else this.ctx=A;this.colorMap={...Nce},this.realToCanvasMat=Md()}configure(A){A.colorOverrides&&(this.colorMap={...this.colorMap,...A.colorOverrides,copper:{...this.colorMap.copper,...A.colorOverrides.copper},silkscreen:{...this.colorMap.silkscreen,...A.colorOverrides.silkscreen},soldermask:{...this.colorMap.soldermask,...A.colorOverrides.soldermask},soldermaskWithCopperUnderneath:{...this.colorMap.soldermaskWithCopperUnderneath,...A.colorOverrides.soldermaskWithCopperUnderneath},soldermaskOverCopper:{...this.colorMap.soldermaskOverCopper,...A.colorOverrides.soldermaskOverCopper}})}setCameraBounds(A){const t=this.ctx.canvas,i=t.width,o=t.height,n=A.maxX-A.minX,s=A.maxY-A.minY,r=i/n,a=o/s,g=Math.min(r,a),I=(i-n*g)/2,c=(o-s*g)/2;this.realToCanvasMat=el(Er(I,c),dE(g,-g),Er(-A.minX,-A.maxY))}drawElements(A,t={}){A.some(i=>i.type==="pcb_smtpad"&&i.is_covered_with_solder_mask===!0),A.some(i=>i.type==="pcb_hole"&&i.is_covered_with_solder_mask===!0),A.some(i=>i.type==="pcb_plated_hole"&&i.is_covered_with_solder_mask===!0);for(const i of A)i.type==="pcb_board"?this.drawBoardWithSoldermask(i):this.drawElement(i,t)}drawBoardWithSoldermask(A){const{width:t,height:i,center:o,outline:n}=A,s="top";if(n&&Array.isArray(n)&&n.length>=3){const r=this.colorMap.soldermask[s]??this.colorMap.soldermask.top,a=n.map(I=>{const[c,B]=Pe(this.realToCanvasMat,[I.x,I.y]);return{x:c,y:B}});this.ctx.beginPath();const g=a[0];if(g){this.ctx.moveTo(g.x,g.y);for(let I=1;I<a.length;I++){const c=a[I];c&&this.ctx.lineTo(c.x,c.y)}this.ctx.closePath()}this.ctx.fillStyle=r,this.ctx.fill(),D8({ctx:this.ctx,points:n.map(I=>({x:I.x,y:I.y})),stroke:this.colorMap.boardOutline,strokeWidth:.1,realToCanvasMat:this.realToCanvasMat,closePath:!0});return}if(t!==void 0&&i!==void 0&&o){const r=this.colorMap.soldermask[s]??this.colorMap.soldermask.top;lI({ctx:this.ctx,center:o,width:t,height:i,fill:r,realToCanvasMat:this.realToCanvasMat});const a=t/2,g=i/2,I=[{x:o.x-a,y:o.y-g},{x:o.x+a,y:o.y-g},{x:o.x+a,y:o.y+g},{x:o.x-a,y:o.y+g}];D8({ctx:this.ctx,points:I,stroke:this.colorMap.boardOutline,strokeWidth:.1,realToCanvasMat:this.realToCanvasMat,closePath:!0})}}drawElement(A,t){Mce(A,t)&&(A.type==="pcb_plated_hole"&&Lce({ctx:this.ctx,hole:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_via"&&Uce({ctx:this.ctx,via:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_hole"&&Hce({ctx:this.ctx,hole:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_smtpad"&&Jce({ctx:this.ctx,pad:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_trace"&&Kce({ctx:this.ctx,trace:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_board"&&Pce({ctx:this.ctx,board:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_text"&&Xce({ctx:this.ctx,text:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_rect"&&ABe({ctx:this.ctx,rect:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_circle"&&eBe({ctx:this.ctx,circle:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_line"&&oBe({ctx:this.ctx,line:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_path"&&sBe({ctx:this.ctx,path:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_pill"&&IBe({ctx:this.ctx,pill:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_oval"&&aBe({ctx:this.ctx,oval:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_cutout"&&cBe({ctx:this.ctx,cutout:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_keepout"&&lBe({ctx:this.ctx,keepout:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_copper_pour"&&EBe({ctx:this.ctx,pour:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_copper_text"&&dBe({ctx:this.ctx,text:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_fabrication_note_text"&&yBe({ctx:this.ctx,text:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_fabrication_note_rect"&&mBe({ctx:this.ctx,rect:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_note_rect"&&wBe({realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap,ctx:this.ctx,rect:A}),A.type==="pcb_fabrication_note_path"&&DBe({ctx:this.ctx,path:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_note_path"&&SBe({ctx:this.ctx,path:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_note_text"&&xBe({ctx:this.ctx,text:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_note_line"&&vBe({ctx:this.ctx,line:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_note_dimension"&&RBe({ctx:this.ctx,pcbNoteDimension:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_fabrication_note_dimension"&&NBe({ctx:this.ctx,pcbFabricationNoteDimension:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}))}};let UBe={data:""},HBe=e=>{if(typeof window=="object"){let A=(e?e.querySelector("#_goober"):window._goober)||Object.assign(document.createElement("style"),{innerHTML:" ",id:"_goober"});return A.nonce=window.__nonce__,A.parentNode||(e||document.head).appendChild(A),A.firstChild}return e||UBe},YBe=/(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g,JBe=/\/\*[^]*?\*\/| +/g,m9A=/\n+/g,n_=(e,A)=>{let t="",i="",o="";for(let n in e){let s=e[n];n[0]=="@"?n[1]=="i"?t=n+" "+s+";":i+=n[1]=="f"?n_(s,n):n+"{"+n_(s,n[1]=="k"?"":A)+"}":typeof s=="object"?i+=n_(s,A?A.replace(/([^,])+/g,r=>n.replace(/([^,]*:\S+\([^)]*\))|([^,])+/g,a=>/&/.test(a)?a.replace(/&/g,r):r?r+" "+a:a)):n):s!=null&&(n=/^--/.test(n)?n:n.replace(/[A-Z]/g,"-$&").toLowerCase(),o+=n_.p?n_.p(n,s):n+":"+s+";")}return t+(A&&o?A+"{"+o+"}":o)+i},ZS={},w9A=e=>{if(typeof e=="object"){let A="";for(let t in e)A+=t+w9A(e[t]);return A}return e},TBe=(e,A,t,i,o)=>{let n=w9A(e),s=ZS[n]||(ZS[n]=(a=>{let g=0,I=11;for(;g<a.length;)I=101*I+a.charCodeAt(g++)>>>0;return"go"+I})(n));if(!ZS[s]){let a=n!==e?e:(g=>{let I,c,B=[{}];for(;I=YBe.exec(g.replace(JBe,""));)I[4]?B.shift():I[3]?(c=I[3].replace(m9A," ").trim(),B.unshift(B[0][c]=B[0][c]||{})):B[0][I[1]]=I[2].replace(m9A," ").trim();return B[0]})(e);ZS[s]=n_(o?{["@keyframes "+s]:a}:a,t?"":"."+s)}let r=t&&ZS.g?ZS.g:null;return t&&(ZS.g=ZS[s]),((a,g,I,c)=>{c?g.data=g.data.replace(c,a):g.data.indexOf(a)===-1&&(g.data=I?a+g.data:g.data+a)})(ZS[s],A,i,r),s},KBe=(e,A,t)=>e.reduce((i,o,n)=>{let s=A[n];if(s&&s.call){let r=s(t),a=r&&r.props&&r.props.className||/^go/.test(r)&&r;s=a?"."+a:r&&typeof r=="object"?r.props?"":n_(r,""):r===!1?"":r}return i+o+(s??"")},"");function b8(e){let A=this||{},t=e.call?e(A.p):e;return TBe(t.unshift?t.raw?KBe(t,[].slice.call(arguments,1),A.p):t.reduce((i,o)=>Object.assign(i,o&&o.call?o(A.p):o),{}):t,HBe(A.target),A.g,A.o,A.k)}let D9A,hQA,uQA;b8.bind({g:1});let VS=b8.bind({k:1});function PBe(e,A,t,i){n_.p=A,D9A=e,hQA=t,uQA=i}function s_(e,A){let t=this||{};return function(){let i=arguments;function o(n,s){let r=Object.assign({},n),a=r.className||o.className;t.p=Object.assign({theme:hQA&&hQA()},r),t.o=/ *go\d+/.test(a),r.className=b8.apply(t,i)+(a?" "+a:"");let g=e;return e[0]&&(g=r.as||e,delete r.as),uQA&&g[0]&&uQA(r),D9A(g,r)}return o}}var qBe=e=>typeof e=="function",x8=(e,A)=>qBe(e)?e(A):e,OBe=(()=>{let e=0;return()=>(++e).toString()})(),S9A=(()=>{let e;return()=>{if(e===void 0&&typeof window<"u"){let A=matchMedia("(prefers-reduced-motion: reduce)");e=!A||A.matches}return e}})(),WBe=20,dQA="default",b9A=(e,A)=>{let{toastLimit:t}=e.settings;switch(A.type){case 0:return{...e,toasts:[A.toast,...e.toasts].slice(0,t)};case 1:return{...e,toasts:e.toasts.map(s=>s.id===A.toast.id?{...s,...A.toast}:s)};case 2:let{toast:i}=A;return b9A(e,{type:e.toasts.find(s=>s.id===i.id)?1:0,toast:i});case 3:let{toastId:o}=A;return{...e,toasts:e.toasts.map(s=>s.id===o||o===void 0?{...s,dismissed:!0,visible:!1}:s)};case 4:return A.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(s=>s.id!==A.toastId)};case 5:return{...e,pausedAt:A.time};case 6:let n=A.time-(e.pausedAt||0);return{...e,pausedAt:void 0,toasts:e.toasts.map(s=>({...s,pauseDuration:s.pauseDuration+n}))}}},_8=[],x9A={toasts:[],pausedAt:void 0,settings:{toastLimit:WBe}},zw={},_9A=(e,A=dQA)=>{zw[A]=b9A(zw[A]||x9A,e),_8.forEach(([t,i])=>{t===A&&i(zw[A])})},k9A=e=>Object.keys(zw).forEach(A=>_9A(e,A)),ZBe=e=>Object.keys(zw).find(A=>zw[A].toasts.some(t=>t.id===e)),k8=(e=dQA)=>A=>{_9A(A,e)},VBe={blank:4e3,error:4e3,success:2e3,loading:1/0,custom:4e3},jBe=(e={},A=dQA)=>{let[t,i]=AA.useState(zw[A]||x9A),o=AA.useRef(zw[A]);AA.useEffect(()=>(o.current!==zw[A]&&i(zw[A]),_8.push([A,i]),()=>{let s=_8.findIndex(([r])=>r===A);s>-1&&_8.splice(s,1)}),[A]);let n=t.toasts.map(s=>{var r,a,g;return{...e,...e[s.type],...s,removeDelay:s.removeDelay||((r=e[s.type])==null?void 0:r.removeDelay)||e?.removeDelay,duration:s.duration||((a=e[s.type])==null?void 0:a.duration)||e?.duration||VBe[s.type],style:{...e.style,...(g=e[s.type])==null?void 0:g.style,...s.style}}});return{...t,toasts:n}},zBe=(e,A="blank",t)=>({createdAt:Date.now(),visible:!0,dismissed:!1,type:A,ariaProps:{role:"status","aria-live":"polite"},message:e,pauseDuration:0,...t,id:t?.id||OBe()}),UU=e=>(A,t)=>{let i=zBe(A,e,t);return k8(i.toasterId||ZBe(i.id))({type:2,toast:i}),i.id},Us=(e,A)=>UU("blank")(e,A);Us.error=UU("error"),Us.success=UU("success"),Us.loading=UU("loading"),Us.custom=UU("custom"),Us.dismiss=(e,A)=>{let t={type:3,toastId:e};A?k8(A)(t):k9A(t)},Us.dismissAll=e=>Us.dismiss(void 0,e),Us.remove=(e,A)=>{let t={type:4,toastId:e};A?k8(A)(t):k9A(t)},Us.removeAll=e=>Us.remove(void 0,e),Us.promise=(e,A,t)=>{let i=Us.loading(A.loading,{...t,...t?.loading});return typeof e=="function"&&(e=e()),e.then(o=>{let n=A.success?x8(A.success,o):void 0;return n?Us.success(n,{id:i,...t,...t?.success}):Us.dismiss(i),o}).catch(o=>{let n=A.error?x8(A.error,o):void 0;n?Us.error(n,{id:i,...t,...t?.error}):Us.dismiss(i)}),e};var XBe=1e3,$Be=(e,A="default")=>{let{toasts:t,pausedAt:i}=jBe(e,A),o=AA.useRef(new Map).current,n=AA.useCallback((c,B=XBe)=>{if(o.has(c))return;let l=setTimeout(()=>{o.delete(c),s({type:4,toastId:c})},B);o.set(c,l)},[]);AA.useEffect(()=>{if(i)return;let c=Date.now(),B=t.map(l=>{if(l.duration===1/0)return;let C=(l.duration||0)+l.pauseDuration-(c-l.createdAt);if(C<0){l.visible&&Us.dismiss(l.id);return}return setTimeout(()=>Us.dismiss(l.id,A),C)});return()=>{B.forEach(l=>l&&clearTimeout(l))}},[t,i,A]);let s=AA.useCallback(k8(A),[A]),r=AA.useCallback(()=>{s({type:5,time:Date.now()})},[s]),a=AA.useCallback((c,B)=>{s({type:1,toast:{id:c,height:B}})},[s]),g=AA.useCallback(()=>{i&&s({type:6,time:Date.now()})},[i,s]),I=AA.useCallback((c,B)=>{let{reverseOrder:l=!1,gutter:C=8,defaultPosition:E}=B||{},Q=t.filter(d=>(d.position||E)===(c.position||E)&&d.height),h=Q.findIndex(d=>d.id===c.id),u=Q.filter((d,f)=>f<h&&d.visible).length;return Q.filter(d=>d.visible).slice(...l?[u+1]:[0,u]).reduce((d,f)=>d+(f.height||0)+C,0)},[t]);return AA.useEffect(()=>{t.forEach(c=>{if(c.dismissed)n(c.id,c.removeDelay);else{let B=o.get(c.id);B&&(clearTimeout(B),o.delete(c.id))}})},[t,n]),{toasts:t,handlers:{updateHeight:a,startPause:r,endPause:g,calculateOffset:I}}},Ale=VS`
4942
4942
  from {
4943
4943
  transform: scale(0) rotate(45deg);
4944
4944
  opacity: 0;
@@ -5426,7 +5426,7 @@ You passed in: '`+this.raw_options[n]+"'");return a},t.prototype._is_valid_selec
5426
5426
  `);break}}return s}}}),e3e=Ga({"node_modules/pretty/index.js"(e,A){var t=j4e(),i=t3e(),o=Hat(),n={unformatted:["code","pre","em","strong","span"],indent_inner_html:!0,indent_char:" ",indent_size:2,sep:`
5427
5427
  `};A.exports=function(a,g){var I=o({},n,g);return a=t.html(a,I),I.ocd===!0?(I.newlines&&(I.sep=I.newlines),s(a,I)):a};function s(r,a){return i(r,a).replace(/^\s+/g,"").replace(/\s+$/g,`
5428
5428
  `).replace(/(\s*<!--)/g,`
5429
- $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function Yat(e,A,t){if(!A||!t)return;let i=e.get(A);i||(i=new Set,e.set(A,i)),i.add(t);let o=e.get(t);o||(o=new Set,e.set(t,o)),o.add(A)}function i3e(e,A){if(!A.subcircuit_id&&!A.source_group_id)return[...e];const t=new Map;for(const s of e){const r=s[`${s.type}_id`];typeof r=="string"&&t.set(r,s)}const i=new Map;for(const s of e){const r=Object.entries(s);for(const[a,g]of r)if(a!=="parent_source_group_id"){if(a.endsWith("_id")&&typeof g=="string"){const I=t.get(g);Yat(i,s,I)}else if(a.endsWith("_ids")&&Array.isArray(g)){for(const I of g)if(typeof I=="string"){const c=t.get(I);Yat(i,s,c)}}}}const o=[],n=new Set;for(const s of e)(A.subcircuit_id&&s.subcircuit_id===A.subcircuit_id||A.source_group_id&&(s.source_group_id===A.source_group_id||Array.isArray(s.member_source_group_ids)&&s.member_source_group_ids.includes(A.source_group_id)))&&(o.push(s),n.add(s));for(;o.length>0;){const s=o.shift(),r=i.get(s);if(r)for(const a of r)n.has(a)||(n.add(a),o.push(a))}return e.filter(s=>n.has(s))}var WV=(e,A={})=>{const t=e;let i=t._internal_store;if(!i){i={counts:{},editCount:0},t._internal_store=i;for(const n of t){const s=n.type,r=n[`${s}_id`];if(!r)continue;const a=Number.parseInt(r.split("_").pop());Number.isNaN(a)||(i.counts[s]=Math.max(i.counts[s]??0,a))}}return new Proxy({},{get:(n,s)=>{if(s==="toArray")return()=>(t.editCount=i.editCount,t);if(s==="editCount")return i.editCount;if(s==="subtree")return a=>WV(i3e(t,a),A);const r=s;return{get:a=>t.find(g=>g.type===r&&g[`${r}_id`]===a),getUsing:a=>{const g=Object.keys(a);if(g.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const I=g[0],c=I.replace("_id",""),B=t.find(l=>l.type===c&&l[I]===a[I]);return B?t.find(l=>l.type===r&&l[`${r}_id`]===B[`${r}_id`]):null},getWhere:a=>{const g=Object.keys(a);return t.find(I=>I.type===r&&g.every(c=>I[c]===a[c]))},list:a=>{const g=a?Object.keys(a):[];return t.filter(I=>I.type===r&&g.every(c=>I[c]===a[c]))},insert:a=>{i.counts[r]??=-1,i.counts[r]++;const g=i.counts[r],I={type:r,[`${r}_id`]:`${r}_${g}`,...a};return A.validateInserts&&(Grt[r]??YdA).parse(I),t.push(I),i.editCount++,I},delete:a=>{const g=t.find(I=>I[`${r}_id`]===a);g&&(t.splice(t.indexOf(g),1),i.editCount++)},update:(a,g)=>{const I=t.find(c=>c.type===r&&c[`${r}_id`]===a);return I?(Object.assign(I,g),i.editCount++,I):null},select:a=>{if(r==="source_component")return t.find(g=>g.type==="source_component"&&g.name===a.replace(/\./g,""));if(r==="pcb_port"||r==="source_port"||r==="schematic_port"){const[g,I]=a.replace(/\./g,"").split(/[\s\>]+/),c=t.find(l=>l.type==="source_component"&&l.name===g);if(!c)return null;const B=t.find(l=>l.type==="source_port"&&l.source_component_id===c.source_component_id&&(l.name===I||(l.port_hints??[]).includes(I)));if(!B)return null;if(r==="source_port")return B;if(r==="pcb_port")return t.find(l=>l.type==="pcb_port"&&l.source_port_id===B.source_port_id);if(r==="schematic_port")return t.find(l=>l.type==="schematic_port"&&l.source_port_id===B.source_port_id)}}}}})};WV.unparsed=WV;var Qb=WV;function mpA(e){const A=e.type;return`${A}:${e[`${A}_id`]}`}var Jat=(e,A={})=>{let t=e._internal_store_indexed;if(!t){t={counts:{},editCount:0,indexes:{}};for(const s of e){const r=s.type,a=s[`${r}_id`];if(!a)continue;const g=Number.parseInt(a.split("_").pop()||"");Number.isNaN(g)||(t.counts[r]=Math.max(t.counts[r]??0,g))}const o=A.indexConfig||{},n=t.indexes;if(o.byId&&(n.byId=new Map),o.byType&&(n.byType=new Map),o.byRelation&&(n.byRelation=new Map),o.bySubcircuit&&(n.bySubcircuit=new Map),o.byCustomField&&o.byCustomField.length>0){n.byCustomField=new Map;for(const s of o.byCustomField)n.byCustomField.set(s,new Map)}for(const s of e){if(o.byId){const r=mpA(s);n.byId.set(r,s)}if(o.byType){const r=n.byType.get(s.type)||[];r.push(s),n.byType.set(s.type,r)}if(o.byRelation){const r=Object.entries(s);for(const[a,g]of r)if(a.endsWith("_id")&&a!==`${s.type}_id`&&typeof g=="string"){const I=n.byRelation.get(a)||new Map,c=I.get(g)||[];c.push(s),I.set(g,c),n.byRelation.set(a,I)}}if(o.bySubcircuit&&"subcircuit_id"in s){const r=s.subcircuit_id;if(r&&typeof r=="string"){const a=n.bySubcircuit.get(r)||[];a.push(s),n.bySubcircuit.set(r,a)}}if(o.byCustomField&&n.byCustomField){for(const r of o.byCustomField)if(r in s){const a=s[r];if(a!==void 0&&(typeof a=="string"||typeof a=="number")){const g=String(a),I=n.byCustomField.get(r),c=I.get(g)||[];c.push(s),I.set(g,c)}}}}e._internal_store_indexed=t}return new Proxy({},{get:(o,n)=>{if(n==="toArray")return()=>(e.editCount=t.editCount,e);if(n==="editCount")return t.editCount;const s=n;return{get:r=>{const a=A.indexConfig||{};return a.byId&&t.indexes.byId?t.indexes.byId.get(`${s}:${r}`)||null:a.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(I=>I[`${s}_id`]===r)||null:e.find(g=>g.type===s&&g[`${s}_id`]===r)||null},getUsing:r=>{const a=A.indexConfig||{},g=Object.keys(r);if(g.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const I=g[0],c=I.replace("_id","");if(a.byRelation&&t.indexes.byRelation){const l=t.indexes.byRelation.get(I);if(l){const E=(l.get(r[I])||[]).find(h=>h.type===c);if(!E)return null;const Q=E[`${s}_id`];return a.byId&&t.indexes.byId?t.indexes.byId.get(`${s}:${Q}`)||null:a.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===Q)||null:e.find(h=>h.type===s&&h[`${s}_id`]===Q)||null}}const B=e.find(l=>l.type===c&&l[I]===r[I]);return B&&e.find(l=>l.type===s&&l[`${s}_id`]===B[`${s}_id`])||null},getWhere:r=>{const a=A.indexConfig||{},g=Object.keys(r);if(g.length===1&&a.byCustomField&&t.indexes.byCustomField){const I=g[0],c=t.indexes.byCustomField.get(I);if(c){const B=String(r[I]);return(c.get(B)||[]).find(C=>C.type===s)||null}}if("subcircuit_id"in r&&a.bySubcircuit&&t.indexes.bySubcircuit){const I=r.subcircuit_id;return(t.indexes.bySubcircuit.get(I)||[]).find(B=>B.type===s&&g.every(l=>B[l]===r[l]))||null}return a.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(c=>g.every(B=>c[B]===r[B]))||null:e.find(I=>I.type===s&&g.every(c=>I[c]===r[c]))||null},list:r=>{const a=A.indexConfig||{},g=r?Object.keys(r):[];if(g.length===0&&a.byType&&t.indexes.byType)return t.indexes.byType.get(s)||[];if(g.length===1&&g[0]==="subcircuit_id"&&a.bySubcircuit&&t.indexes.bySubcircuit){const c=r.subcircuit_id;return(t.indexes.bySubcircuit.get(c)||[]).filter(l=>l.type===s)}let I;return a.byType&&t.indexes.byType?I=t.indexes.byType.get(s)||[]:I=e.filter(c=>c.type===s),g.length>0?I.filter(c=>g.every(B=>c[B]===r[B])):I},insert:r=>{t.counts[s]??=-1,t.counts[s]++;const a=t.counts[s],g={type:s,[`${s}_id`]:`${s}_${a}`,...r};A.validateInserts&&(Grt[s]??YdA).parse(g),e.push(g),t.editCount++;const I=A.indexConfig||{};if(I.byId&&t.indexes.byId){const c=mpA(g);t.indexes.byId.set(c,g)}if(I.byType&&t.indexes.byType){const c=t.indexes.byType.get(s)||[];c.push(g),t.indexes.byType.set(s,c)}if(I.byRelation&&t.indexes.byRelation){const c=Object.entries(g);for(const[B,l]of c)if(B.endsWith("_id")&&B!==`${g.type}_id`&&typeof l=="string"){const C=t.indexes.byRelation.get(B)||new Map,E=C.get(l)||[];E.push(g),C.set(l,E),t.indexes.byRelation.set(B,C)}}if(I.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in g){const c=g.subcircuit_id;if(c&&typeof c=="string"){const B=t.indexes.bySubcircuit.get(c)||[];B.push(g),t.indexes.bySubcircuit.set(c,B)}}if(I.byCustomField&&t.indexes.byCustomField){for(const c of I.byCustomField)if(c in g){const B=g[c];if(B!==void 0&&(typeof B=="string"||typeof B=="number")){const l=String(B),C=t.indexes.byCustomField.get(c),E=C.get(l)||[];E.push(g),C.set(l,E)}}}return g},delete:r=>{const a=A.indexConfig||{};let g;if(a.byId&&t.indexes.byId?g=t.indexes.byId.get(`${s}:${r}`):a.byType&&t.indexes.byType?g=(t.indexes.byType.get(s)||[]).find(B=>B[`${s}_id`]===r):g=e.find(c=>c[`${s}_id`]===r),!g)return;const I=e.indexOf(g);if(I>=0&&(e.splice(I,1),t.editCount++),a.byId&&t.indexes.byId){const c=mpA(g);t.indexes.byId.delete(c)}if(a.byType&&t.indexes.byType){const B=(t.indexes.byType.get(s)||[]).filter(l=>l[`${s}_id`]!==r);t.indexes.byType.set(s,B)}if(a.byRelation&&t.indexes.byRelation)for(const[c,B]of t.indexes.byRelation.entries())for(const[l,C]of B.entries()){const E=C.filter(Q=>Q!==g);E.length===0?B.delete(l):B.set(l,E)}if(a.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in g){const c=g.subcircuit_id;if(c){const l=(t.indexes.bySubcircuit.get(c)||[]).filter(C=>C!==g);l.length===0?t.indexes.bySubcircuit.delete(c):t.indexes.bySubcircuit.set(c,l)}}if(a.byCustomField&&t.indexes.byCustomField)for(const c of t.indexes.byCustomField.values())for(const[B,l]of c.entries()){const C=l.filter(E=>E!==g);C.length===0?c.delete(B):c.set(B,C)}},update:(r,a)=>{const g=A.indexConfig||{};let I;if(g.byId&&t.indexes.byId?I=t.indexes.byId.get(`${s}:${r}`):g.byType&&t.indexes.byType?I=(t.indexes.byType.get(s)||[]).find(B=>B[`${s}_id`]===r):I=e.find(c=>c.type===s&&c[`${s}_id`]===r),!I)return null;if(g.byRelation&&t.indexes.byRelation){const c=Object.entries(I);for(const[B,l]of c)if(B.endsWith("_id")&&B!==`${I.type}_id`&&typeof l=="string"&&B in a&&a[B]!==l){const C=t.indexes.byRelation.get(B);if(C){const Q=(C.get(l)||[]).filter(h=>h!==I);Q.length===0?C.delete(l):C.set(l,Q)}}}if(g.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in I&&"subcircuit_id"in a){const c=I.subcircuit_id,B=a.subcircuit_id;if(c!==B){const C=(t.indexes.bySubcircuit.get(c)||[]).filter(E=>E!==I);C.length===0?t.indexes.bySubcircuit.delete(c):t.indexes.bySubcircuit.set(c,C)}}if(g.byCustomField&&t.indexes.byCustomField){for(const c of g.byCustomField)if(c in I&&c in a&&I[c]!==a[c]){const B=t.indexes.byCustomField.get(c);if(B){const l=String(I[c]),E=(B.get(l)||[]).filter(Q=>Q!==I);E.length===0?B.delete(l):B.set(l,E)}}}if(Object.assign(I,a),t.editCount++,g.byRelation&&t.indexes.byRelation){const c=Object.entries(I);for(const[B,l]of c)if(B.endsWith("_id")&&B!==`${I.type}_id`&&typeof l=="string"&&B in a){const C=t.indexes.byRelation.get(B)||new Map,E=C.get(l)||[];E.includes(I)||(E.push(I),C.set(l,E),t.indexes.byRelation.set(B,C))}}if(g.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in I&&"subcircuit_id"in a){const c=I.subcircuit_id;if(c&&typeof c=="string"){const B=t.indexes.bySubcircuit.get(c)||[];B.includes(I)||(B.push(I),t.indexes.bySubcircuit.set(c,B))}}if(g.byCustomField&&t.indexes.byCustomField){for(const c of g.byCustomField)if(c in I&&c in a){const B=I[c];if(B!==void 0&&(typeof B=="string"||typeof B=="number")){const l=String(B),C=t.indexes.byCustomField.get(c),E=C.get(l)||[];E.includes(I)||(E.push(I),C.set(l,E))}}}return I},select:r=>{if(s==="source_component")return e.find(a=>a.type==="source_component"&&a.name===r.replace(/\./g,""))||null;if(s==="pcb_port"||s==="source_port"||s==="schematic_port"){const[a,g]=r.replace(/\./g,"").split(/[\s\>]+/),I=e.find(B=>B.type==="source_component"&&B.name===a);if(!I)return null;const c=e.find(B=>B.type==="source_port"&&B.source_component_id===I.source_component_id&&(B.name===g||(B.port_hints??[]).includes(g)));if(!c)return null;if(s==="source_port")return c;if(s==="pcb_port")return e.find(B=>B.type==="pcb_port"&&B.source_port_id===c.source_port_id)||null;if(s==="schematic_port")return e.find(B=>B.type==="schematic_port"&&B.source_port_id===c.source_port_id)||null}return null}}}})};Jat.unparsed=Jat;var o3e=e=>{const A=e.type;return e[`${A}_id`]},wpA=e=>{let A=Number.POSITIVE_INFINITY,t=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY;for(const n of e){if(!n.type.startsWith("pcb_"))continue;if(n.type==="pcb_smtpad"&&n.shape==="polygon"&&Array.isArray(n.points)){for(const I of n.points)A=Math.min(A,I.x),t=Math.min(t,I.y),i=Math.max(i,I.x),o=Math.max(o,I.y);continue}let s,r,a,g;if("x"in n&&"y"in n&&(s=Number(n.x),r=Number(n.y)),"outer_diameter"in n&&(a=Number(n.outer_diameter),g=Number(n.outer_diameter)),"width"in n&&(a=Number(n.width)),"height"in n&&(g=Number(n.height)),"center"in n&&(s=n.center.x,r=n.center.y),s!==void 0&&r!==void 0)A=Math.min(A,s),t=Math.min(t,r),i=Math.max(i,s),o=Math.max(o,r),a!==void 0&&g!==void 0&&(A=Math.min(A,s-a/2),t=Math.min(t,r-g/2),i=Math.max(i,s+a/2),o=Math.max(o,r+g/2)),"radius"in n&&(A=Math.min(A,s-n.radius),t=Math.min(t,r-n.radius),i=Math.max(i,s+n.radius),o=Math.max(o,r+n.radius));else if(n.type==="pcb_trace")for(const I of n.route)A=Math.min(A,I.x),t=Math.min(t,I.y),i=Math.max(i,I.x),o=Math.max(o,I.y)}return{minX:A,minY:t,maxX:i,maxY:o}};function n3e(e){let A=0;if(e.length==0)return A;for(var t=0;t<e.length;t++){var i=e.charCodeAt(t);A=(A<<5)-A+i,A=A&A}return Math.abs(A)}var Tat=[["#69d2e7","#a7dbd8","#e0e4cc","#f38630","#fa6900"],["#fe4365","#fc9d9a","#f9cdad","#c8c8a9","#83af9b"],["#ecd078","#d95b43","#c02942","#542437","#53777a"],["#556270","#4ecdc4","#c7f464","#ff6b6b","#c44d58"],["#774f38","#e08e79","#f1d4af","#ece5ce","#c5e0dc"],["#e8ddcb","#cdb380","#036564","#033649","#031634"],["#490a3d","#bd1550","#e97f02","#f8ca00","#8a9b0f"],["#594f4f","#547980","#45ada8","#9de0ad","#e5fcc2"],["#00a0b0","#6a4a3c","#cc333f","#eb6841","#edc951"],["#e94e77","#d68189","#c6a49a","#c6e5d9","#f4ead5"],["#3fb8af","#7fc7af","#dad8a7","#ff9e9d","#ff3d7f"],["#d9ceb2","#948c75","#d5ded9","#7a6a53","#99b2b7"],["#ffffff","#cbe86b","#f2e9e1","#1c140d","#cbe86b"],["#efffcd","#dce9be","#555152","#2e2633","#99173c"],["#343838","#005f6b","#008c9e","#00b4cc","#00dffc"],["#413e4a","#73626e","#b38184","#f0b49e","#f7e4be"],["#ff4e50","#fc913a","#f9d423","#ede574","#e1f5c4"],["#99b898","#fecea8","#ff847c","#e84a5f","#2a363b"],["#655643","#80bca3","#f6f7bd","#e6ac27","#bf4d28"],["#00a8c6","#40c0cb","#f9f2e7","#aee239","#8fbe00"],["#351330","#424254","#64908a","#e8caa4","#cc2a41"],["#554236","#f77825","#d3ce3d","#f1efa5","#60b99a"],["#5d4157","#838689","#a8caba","#cad7b2","#ebe3aa"],["#8c2318","#5e8c6a","#88a65e","#bfb35a","#f2c45a"],["#fad089","#ff9c5b","#f5634a","#ed303c","#3b8183"],["#ff4242","#f4fad2","#d4ee5e","#e1edb9","#f0f2eb"],["#f8b195","#f67280","#c06c84","#6c5b7b","#355c7d"],["#d1e751","#ffffff","#000000","#4dbce9","#26ade4"],["#1b676b","#519548","#88c425","#bef202","#eafde6"],["#5e412f","#fcebb6","#78c0a8","#f07818","#f0a830"],["#bcbdac","#cfbe27","#f27435","#f02475","#3b2d38"],["#452632","#91204d","#e4844a","#e8bf56","#e2f7ce"],["#eee6ab","#c5bc8e","#696758","#45484b","#36393b"],["#f0d8a8","#3d1c00","#86b8b1","#f2d694","#fa2a00"],["#2a044a","#0b2e59","#0d6759","#7ab317","#a0c55f"],["#f04155","#ff823a","#f2f26f","#fff7bd","#95cfb7"],["#b9d7d9","#668284","#2a2829","#493736","#7b3b3b"],["#bbbb88","#ccc68d","#eedd99","#eec290","#eeaa88"],["#b3cc57","#ecf081","#ffbe40","#ef746f","#ab3e5b"],["#a3a948","#edb92e","#f85931","#ce1836","#009989"],["#300030","#480048","#601848","#c04848","#f07241"],["#67917a","#170409","#b8af03","#ccbf82","#e33258"],["#aab3ab","#c4cbb7","#ebefc9","#eee0b7","#e8caaf"],["#e8d5b7","#0e2430","#fc3a51","#f5b349","#e8d5b9"],["#ab526b","#bca297","#c5ceae","#f0e2a4","#f4ebc3"],["#607848","#789048","#c0d860","#f0f0d8","#604848"],["#b6d8c0","#c8d9bf","#dadabd","#ecdbbc","#fedcba"],["#a8e6ce","#dcedc2","#ffd3b5","#ffaaa6","#ff8c94"],["#3e4147","#fffedf","#dfba69","#5a2e2e","#2a2c31"],["#fc354c","#29221f","#13747d","#0abfbc","#fcf7c5"],["#cc0c39","#e6781e","#c8cf02","#f8fcc1","#1693a7"],["#1c2130","#028f76","#b3e099","#ffeaad","#d14334"],["#a7c5bd","#e5ddcb","#eb7b59","#cf4647","#524656"],["#dad6ca","#1bb0ce","#4f8699","#6a5e72","#563444"],["#5c323e","#a82743","#e15e32","#c0d23e","#e5f04c"],["#edebe6","#d6e1c7","#94c7b6","#403b33","#d3643b"],["#fdf1cc","#c6d6b8","#987f69","#e3ad40","#fcd036"],["#230f2b","#f21d41","#ebebbc","#bce3c5","#82b3ae"],["#b9d3b0","#81bda4","#b28774","#f88f79","#f6aa93"],["#3a111c","#574951","#83988e","#bcdea5","#e6f9bc"],["#5e3929","#cd8c52","#b7d1a3","#dee8be","#fcf7d3"],["#1c0113","#6b0103","#a30006","#c21a01","#f03c02"],["#000000","#9f111b","#b11623","#292c37","#cccccc"],["#382f32","#ffeaf2","#fcd9e5","#fbc5d8","#f1396d"],["#e3dfba","#c8d6bf","#93ccc6","#6cbdb5","#1a1f1e"],["#f6f6f6","#e8e8e8","#333333","#990100","#b90504"],["#1b325f","#9cc4e4","#e9f2f9","#3a89c9","#f26c4f"],["#a1dbb2","#fee5ad","#faca66","#f7a541","#f45d4c"],["#c1b398","#605951","#fbeec2","#61a6ab","#accec0"],["#5e9fa3","#dcd1b4","#fab87f","#f87e7b","#b05574"],["#951f2b","#f5f4d7","#e0dfb1","#a5a36c","#535233"],["#8dccad","#988864","#fea6a2","#f9d6ac","#ffe9af"],["#2d2d29","#215a6d","#3ca2a2","#92c7a3","#dfece6"],["#413d3d","#040004","#c8ff00","#fa023c","#4b000f"],["#eff3cd","#b2d5ba","#61ada0","#248f8d","#605063"],["#ffefd3","#fffee4","#d0ecea","#9fd6d2","#8b7a5e"],["#cfffdd","#b4dec1","#5c5863","#a85163","#ff1f4c"],["#9dc9ac","#fffec7","#f56218","#ff9d2e","#919167"],["#4e395d","#827085","#8ebe94","#ccfc8e","#dc5b3e"],["#a8a7a7","#cc527a","#e8175d","#474747","#363636"],["#f8edd1","#d88a8a","#474843","#9d9d93","#c5cfc6"],["#046d8b","#309292","#2fb8ac","#93a42a","#ecbe13"],["#f38a8a","#55443d","#a0cab5","#cde9ca","#f1edd0"],["#a70267","#f10c49","#fb6b41","#f6d86b","#339194"],["#ff003c","#ff8a00","#fabe28","#88c100","#00c176"],["#ffedbf","#f7803c","#f54828","#2e0d23","#f8e4c1"],["#4e4d4a","#353432","#94ba65","#2790b0","#2b4e72"],["#0ca5b0","#4e3f30","#fefeeb","#f8f4e4","#a5b3aa"],["#4d3b3b","#de6262","#ffb88c","#ffd0b3","#f5e0d3"],["#fffbb7","#a6f6af","#66b6ab","#5b7c8d","#4f2958"],["#edf6ee","#d1c089","#b3204d","#412e28","#151101"],["#9d7e79","#ccac95","#9a947c","#748b83","#5b756c"],["#fcfef5","#e9ffe1","#cdcfb7","#d6e6c3","#fafbe3"],["#9cddc8","#bfd8ad","#ddd9ab","#f7af63","#633d2e"],["#30261c","#403831","#36544f","#1f5f61","#0b8185"],["#aaff00","#ffaa00","#ff00aa","#aa00ff","#00aaff"],["#d1313d","#e5625c","#f9bf76","#8eb2c5","#615375"],["#ffe181","#eee9e5","#fad3b2","#ffba7f","#ff9c97"],["#73c8a9","#dee1b6","#e1b866","#bd5532","#373b44"],["#805841","#dcf7f3","#fffcdd","#ffd8d8","#f5a2a2"]],s3e=e=>{let{x:A,y:t,width:i,height:o}={...e,...e.size,...e.center,...e.position};if(e.x1!==void 0&&e.x2!==void 0&&e.y1!==void 0&&e.y2!==void 0&&(A=(e.x1+e.x2)/2,t=(e.y1+e.y2)/2,i=Math.abs(e.x1-e.x2),o=Math.abs(e.y1-e.y2)),e.points&&Array.isArray(e.points)&&e.points.length>0){const r=e.points.map(l=>l.x),a=e.points.map(l=>l.y),g=Math.min(...r),I=Math.max(...r),c=Math.min(...a),B=Math.max(...a);A=(g+I)/2,t=(c+B)/2,i=I-g,o=B-c}const n=e.text||e.name||e.source?.text||e.source?.name||"?",s=e;return A===void 0||t===void 0?null:(i===void 0&&"outer_diameter"in e&&(i=e.outer_diameter,o=e.outer_diameter),(i===void 0||o===void 0)&&(i=.1,o=.1),{x:A,y:t,width:i,height:o,title:n,content:s,bg_color:Tat[n3e(e.type||n)%Tat.length]?.[4]??"#f00"})},r3e=e=>!!e,a3e=e=>{const A=e.filter(g=>g.type.startsWith("pcb_")||g.type.startsWith("schematic_")).concat(e.filter(g=>g.type==="pcb_trace"||g.type==="schematic_trace").flatMap(g=>g.route)).map(g=>s3e(g)).filter(r3e);if(A.length===0)return{center:{x:0,y:0},width:0,height:0};let t=A[0].x-A[0].width/2,i=A[0].x+A[0].width/2,o=A[0].y-A[0].height/2,n=A[0].y+A[0].height/2;for(const g of A.slice(1))t=Math.min(t,g.x-g.width/2),i=Math.max(i,g.x+g.width/2),o=Math.min(o,g.y-g.height/2),n=Math.max(n,g.y+g.height/2);const s=i-t,r=n-o;return{center:{x:t+s/2,y:o+r/2},width:s,height:r}},DD={IS_SHOWING_PCB_GROUPS:"pcb_viewer_is_showing_pcb_groups",PCB_GROUP_VIEW_MODE:"pcb_viewer_group_view_mode",IS_SHOWING_COPPER_POURS:"pcb_viewer_is_showing_copper_pours",IS_SHOWING_GROUP_ANCHOR_OFFSETS:"pcb_viewer_is_showing_group_anchor_offsets",IS_SHOWING_SOLDER_MASK:"pcb_viewer_is_showing_solder_mask"},ZV=(e,A)=>{if(typeof window>"u")return A;try{const t=localStorage.getItem(e);return t!==null?JSON.parse(t):A}catch{return A}},VV=(e,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(e,JSON.stringify(A))}catch{}},g3e=(e,A)=>{if(typeof window>"u")return A;try{const t=localStorage.getItem(e);return t!==null?JSON.parse(t):A}catch{return A}},I3e=(e,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(e,JSON.stringify(A))}catch{}},c3e="named_only",B3e=(e={},A=!1)=>Rrt(t=>({selected_layer:"top",pcb_viewer_id:`pcb_viewer_${Math.random().toString().slice(2,10)}`,in_edit_mode:!1,in_move_footprint_mode:!1,in_draw_trace_mode:!1,is_moving_component:!1,is_drawing_trace:!1,is_mouse_over_container:!1,is_showing_multiple_traces_length:!1,is_showing_rats_nest:!1,is_showing_autorouting:!0,is_showing_drc_errors:!0,is_showing_copper_pours:ZV(DD.IS_SHOWING_COPPER_POURS,!0),is_showing_pcb_groups:A?!1:ZV(DD.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:ZV(DD.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!0),is_showing_solder_mask:ZV(DD.IS_SHOWING_SOLDER_MASK,!1),pcb_group_view_mode:A?"all":g3e(DD.PCB_GROUP_VIEW_MODE,c3e),hovered_error_id:null,...e,selectLayer:i=>t({selected_layer:i}),setEditMode:i=>t({in_edit_mode:i!=="off",in_move_footprint_mode:i==="move_footprint",in_draw_trace_mode:i==="draw_trace",is_moving_component:!1,is_drawing_trace:!1}),setIsShowingRatsNest:i=>t({is_showing_rats_nest:i}),setIsMovingComponent:i=>t({is_moving_component:i}),setIsDrawingTrace:i=>t({is_drawing_trace:i}),setIsMouseOverContainer:i=>t({is_mouse_over_container:i}),setIsShowingMultipleTracesLength:i=>t({is_showing_multiple_traces_length:i}),setIsShowingAutorouting:i=>t({is_showing_autorouting:i}),setIsShowingDrcErrors:i=>t({is_showing_drc_errors:i}),setIsShowingCopperPours:i=>{VV(DD.IS_SHOWING_COPPER_POURS,i),t({is_showing_copper_pours:i})},setIsShowingPcbGroups:i=>{A||(VV(DD.IS_SHOWING_PCB_GROUPS,i),t({is_showing_pcb_groups:i}))},setIsShowingGroupAnchorOffsets:i=>{VV(DD.IS_SHOWING_GROUP_ANCHOR_OFFSETS,i),t({is_showing_group_anchor_offsets:i})},setIsShowingSolderMask:i=>{VV(DD.IS_SHOWING_SOLDER_MASK,i),t({is_showing_solder_mask:i})},setPcbGroupViewMode:i=>{A||(I3e(DD.PCB_GROUP_VIEW_MODE,i),t({pcb_group_view_mode:i}))},setHoveredErrorId:i=>t({hovered_error_id:i})})),zl=e=>{const A=AA.useContext(Kat);return Krt(A,e)},Kat=AA.createContext(null),l3e=({children:e,initialState:A,disablePcbGroups:t})=>{const i=AA.useMemo(()=>B3e(A,t),[t]);return Z.jsx(Kat.Provider,{value:i,children:e})},C3e=()=>{const e=zl(t=>t.pcb_viewer_id),A=(t,i)=>qg(t,{containerId:e,...i});return A.error=(t,i)=>qg.error(t,{containerId:e,...i}),A.promise=qg.promise,A},Q3e=()=>{AA.useEffect(()=>{uPe()},[]);const e=zl(A=>A.pcb_viewer_id);return Z.jsx(hPe,{position:"top-center",containerId:e})},E3e=function(){},Pat=typeof window<"u",h3e=Pat?AA.useLayoutEffect:AA.useEffect,u3e=h3e,qat={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function d3e(){var e=AA.useState(null),A=e[0],t=e[1],i=AA.useState(qat),o=i[0],n=i[1],s=AA.useMemo(function(){return new window.ResizeObserver(function(r){if(r[0]){var a=r[0].contentRect,g=a.x,I=a.y,c=a.width,B=a.height,l=a.top,C=a.left,E=a.bottom,Q=a.right;n({x:g,y:I,width:c,height:B,top:l,left:C,bottom:E,right:Q})}})},[]);return u3e(function(){if(A)return s.observe(A),function(){s.disconnect()}},[A]),[t,o]}var ZY=Pat&&typeof window.ResizeObserver<"u"?d3e:function(){return[E3e,qat]},Oat=({initialTransform:e,initialTouch1:A,initialTouch2:t,finalTouch1:i,finalTouch2:o})=>{if(!i||!o)return e;const n={x:(A.x+t.x)/2,y:(A.y+t.y)/2},s={x:(i.x+o.x)/2,y:(i.y+o.y)/2},r=Math.hypot(t.x-A.x,t.y-A.y),a=Math.hypot(o.x-i.x,o.y-i.y),g=r===0?1:a/r,I=s.x-n.x,c=s.y-n.y;return Yy(nl(I,c),nl(n.x,n.y),RY(g,g),nl(-n.x,-n.y),e)},p3e=(e={})=>{const A=AA.useRef(null),[t,i]=AA.useState(0),o=e.canvasElm??A.current,[n,s]=AA.useState(e.initialTransform??Bb()),[r,a]=AA.useState(0),[g,I]=AA.useReducer(d=>d+1,0),c=AA.useCallback(d=>{e.onSetTransform&&e.onSetTransform(d),e.transform||s(d)},[e.onSetTransform,s]),B=AA.useCallback(d=>{c(d),I()},[c]),l=e.transform??n,C=AA.useCallback(()=>{i(Date.now())},[]),E=AA.useRef("none"),Q=AA.useRef(null),h=AA.useRef(null);AA.useEffect(()=>{const d=e.canvasElm??A.current;if(d&&!o){a(r+1);return}if(!d){const W=setTimeout(()=>{a(r+1)},100);return()=>clearTimeout(W)}let f=e.transform??n,m={x:0,y:0},D={x:0,y:0},w=!1;const b=W=>({x:W.pageX-d.getBoundingClientRect().left-window.scrollX,y:W.pageY-d.getBoundingClientRect().top-window.scrollY});function k(W){e.enabled!==!1&&(e.shouldDrag&&!e.shouldDrag(W)||(m=b(W),!(Date.now()-t<100)&&(w=!0,W.preventDefault())))}function x(W){if(!w||e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;D=b(W);const $=Yy(nl(D.x-m.x,D.y-m.y),f);c($),f=$,w=!1}function N(W){if(b(W),!w||e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;D=b(W);const $=Yy(nl(D.x-m.x,D.y-m.y),f);c($)}function M(W){if(e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;const $=b(W),iA=Yy(nl($.x,$.y),RY(1-W.deltaY/1e3,1-W.deltaY/1e3),nl(-$.x,-$.y),f);c(iA),f=iA,W.preventDefault()}function U(W){if(!w||e.shouldDrag&&!e.shouldDrag(W))return;if(d){const iA=d.getBoundingClientRect();if(W.clientX>=iA.left+10&&W.clientX<=iA.right-10&&W.clientY>=iA.top+10&&W.clientY<=iA.bottom-10)return}w=!1,D=b(W);const $=Yy(nl(D.x-m.x,D.y-m.y),f);c($),f=$}function J(W){if(W.preventDefault(),e.enabled!==!1){if(W.touches.length===1){E.current="drag";const $=W.touches[0];Q.current={initialTransform:f,initialTouch:{x:$.clientX,y:$.clientY}}}else if(W.touches.length===2){E.current="pinch";const $=W.touches[0],iA=W.touches[1];h.current={initialTransform:f,initialTouch1:{x:$.clientX,y:$.clientY},initialTouch2:{x:iA.clientX,y:iA.clientY},finalTouch1:null,finalTouch2:null}}}}function H(W){if(W.preventDefault(),e.enabled!==!1){if(E.current==="drag"&&W.touches.length===1&&Q.current){const $=W.touches[0],iA={x:$.clientX,y:$.clientY},rA=iA.x-Q.current.initialTouch.x,tA=iA.y-Q.current.initialTouch.y,nA=Yy(nl(rA,tA),Q.current.initialTransform);c(nA)}else if(E.current==="pinch"&&W.touches.length===2&&h.current){const $=W.touches[0],iA=W.touches[1];h.current.finalTouch1={x:$.clientX,y:$.clientY},h.current.finalTouch2={x:iA.clientX,y:iA.clientY};const rA=Oat(h.current);c(rA)}}}function O(W){W.preventDefault();const $=W.changedTouches[0];if(E.current==="drag"&&Q.current&&$){const iA={x:$.clientX,y:$.clientY},rA=iA.x-Q.current.initialTouch.x,tA=iA.y-Q.current.initialTouch.y,nA=Yy(nl(rA,tA),Q.current.initialTransform);c(nA),f=nA}else if(E.current==="pinch"&&h.current){const iA=Oat(h.current);c(iA),f=iA}E.current="none",Q.current=null,h.current=null}return d.addEventListener("mousedown",k),d.addEventListener("mouseup",x),window.addEventListener("mousemove",N),d.addEventListener("mouseout",U),d.addEventListener("wheel",M),d.addEventListener("touchstart",J,{passive:!1}),d.addEventListener("touchmove",H,{passive:!1}),d.addEventListener("touchend",O,{passive:!1}),d.addEventListener("touchcancel",O,{passive:!1}),()=>{d.removeEventListener("mousedown",k),d.removeEventListener("mouseup",x),window.removeEventListener("mousemove",N),d.removeEventListener("mouseout",U),d.removeEventListener("wheel",M),d.removeEventListener("touchstart",J),d.removeEventListener("touchmove",H),d.removeEventListener("touchend",O),d.removeEventListener("touchcancel",O)}},[o,r,g,t,e.enabled,e.shouldDrag]);const u=AA.useCallback(d=>qi(l,d),[l]);return{ref:A,transform:l,applyTransformToPoint:u,setTransform:B,cancelDrag:C}},f3e=p3e;function y3e(e){const A=new Map;let t=0;function i(o){for(const[,s]of A)if(s.has(o))return s;const n=new Set;return A.set(`connectivity_net${t++}`,n),n}for(const o of e){let n=null;for(const s of o){if(!n)n=i(s);else if(!n.has(s)){const r=i(s);if(r!==n){for(const a of r)n.add(a);A.delete(Array.from(A.entries()).find(([,a])=>a===r)[0])}}n.add(s)}}return Object.fromEntries(Array.from(A.entries()).map(([o,n])=>[o,Array.from(n)]))}var m3e=class{netMap;idToNetMap;constructor(e){this.netMap=e,this.idToNetMap={};for(const[A,t]of Object.entries(e))for(const i of t)this.idToNetMap[i]=A}addConnections(e){for(const A of e){const t=new Set;for(const o of A){const n=this.idToNetMap[o];n&&t.add(n)}let i;if(t.size===0)i=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[i]=[];else if(t.size===1)i=t.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{i=t.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const o of t)if(o!==i){this.netMap[i].push(...this.netMap[o]),this.netMap[o]=this.netMap[i];for(const n of this.netMap[i])this.idToNetMap[n]=i}}for(const o of A)this.netMap[i].includes(o)||this.netMap[i].push(o),this.idToNetMap[o]=i}}getIdsConnectedToNet(e){return this.netMap[e]||[]}getNetConnectedToId(e){return this.idToNetMap[e]}areIdsConnected(e,A){if(e===A)return!0;const t=this.getNetConnectedToId(e);if(!t)return!1;const i=this.getNetConnectedToId(A);return i?t===i||i===e||i===e:!1}areAllIdsConnected(e){const A=this.getNetConnectedToId(e[0]);for(const t of e){const i=this.getNetConnectedToId(t);if(i===void 0||i!==A)return!1}return!0}},Wat=e=>{const A=[];for(const i of e)if(i.type==="source_trace")A.push([i.source_trace_id,...i.connected_source_port_ids??[],...i.connected_source_net_ids??[]].filter(Boolean));else if(i.type==="pcb_port"){const{pcb_port_id:o,source_port_id:n}=i;n&&o&&A.push([n,o])}else if(i.type==="pcb_smtpad"){const{pcb_smtpad_id:o,pcb_port_id:n}=i;n&&o&&A.push([o,n])}else if(i.type==="pcb_plated_hole"){const{pcb_plated_hole_id:o,pcb_port_id:n}=i;n&&o&&A.push([o,n])}else if(i.type==="pcb_trace"){const{pcb_trace_id:o,source_trace_id:n}=i,s=Array.isArray(i.route)?i.route.filter(r=>r&&r.route_type==="wire"):[];if(n&&o&&A.push([o,n]),Array.isArray(s)){const r=s.find(g=>g?.start_pcb_port_id)?.start_pcb_port_id,a=s.find(g=>g?.end_pcb_port_id)?.end_pcb_port_id;r&&o&&a&&A.push([r,o,a])}}else if(i.type==="pcb_via"){const{pcb_via_id:o,pcb_trace_id:n}=i;n&&o&&A.push([o,n])}else if(i.type==="source_component"&&i.internally_connected_source_port_ids)for(const o of i.internally_connected_source_port_ids)A.push(o);const t=y3e(A);return new m3e(t)};function w3e({primitivesWithoutInteractionMetadata:e,drawingObjectIdsWithMouseOver:A,primitiveIdsInMousedOverNet:t}){const i=[];for(const o of e){const n={...o};o?.layer==="drill"?(n.is_in_highlighted_net=!1,n.is_mouse_over=!1):A.has(o._pcb_drawing_object_id)?n.is_mouse_over=!0:o._element&&("pcb_trace_id"in o._element&&t.includes(o._element.pcb_trace_id)||"pcb_port_id"in o._element&&t.includes(o._element.pcb_port_id))?n.is_in_highlighted_net=!0:(n.is_in_highlighted_net=!1,n.is_mouse_over=!1),i.push(n)}return i}function D3e(e,A){if(e.length<2)throw new Error("Stroke must have at least two points");const t=e.map(c=>Array.isArray(c)?{x:c[0],y:c[1]}:c),i=[],o=[];function n(c,B){const l=B.x-c.x,C=B.y-c.y,E=Math.sqrt(l*l+C*C);return{x:-C/E,y:l/E}}function s(c,B,l,C){const E=C/2,Q={x:c.x+B.x*E*l,y:c.y+B.y*E*l};l>0?i.push(Q):o.unshift(Q)}const r=n(t[0],t[1]),a=t[0].trace_width??A;s(t[0],r,1,a),s(t[0],r,-1,a);for(let c=1;c<t.length-1;c++){const B=t[c-1],l=t[c],C=t[c+1],E=n(B,l),Q=n(l,C),h=E.x+Q.x,u=E.y+Q.y,d=Math.sqrt(h*h+u*u),f=l.trace_width??A;if(d/2>2*(f/2))s(l,E,1,f),s(l,Q,1,f),s(l,E,-1,f),s(l,Q,-1,f);else{const D=1/d;s(l,{x:h*D,y:u*D},1,f),s(l,{x:h*D,y:u*D},-1,f)}}const g=n(t[t.length-2],t[t.length-1]),I=t[t.length-1].trace_width??A;return s(t[t.length-1],g,1,I),s(t[t.length-1],g,-1,I),[...i,...o]}var S3e=(e,A)=>{const{x:t,y:i,width:o,height:n,layer:s,rect_border_radius:r}=e,a=e.corner_radius??r??0,g=[{_pcb_drawing_object_id:Jy("rect"),pcb_drawing_type:"rect",x:t,y:i,w:o,h:n,layer:s||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...e.shape==="rotated_rect"&&e.ccw_rotation!==void 0?{ccw_rotation:e.ccw_rotation}:{}}];if(e.is_covered_with_solder_mask){const I=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",B={...{_pcb_drawing_object_id:Jy("rect"),pcb_drawing_type:"rect",x:t,y:i,w:o,h:n,layer:I,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...e.shape==="rotated_rect"&&e.ccw_rotation!==void 0?{ccw_rotation:e.ccw_rotation}:{}},..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};g.push(B)}return g},b3e=(e,A)=>{const{x:t,y:i,radius:o,layer:n}=e,s=[{_pcb_drawing_object_id:Jy("circle"),pcb_drawing_type:"circle",x:t,y:i,r:o,layer:n||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(e.is_covered_with_solder_mask){const r=n==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",a={_pcb_drawing_object_id:Jy("circle"),pcb_drawing_type:"circle",x:t,y:i,r:o,layer:r,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};s.push(a)}return s},x3e=(e,A)=>{const{layer:t,points:i}=e,o=[{_pcb_drawing_object_id:Jy("polygon"),pcb_drawing_type:"polygon",points:DpA(i),layer:t||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(e.is_covered_with_solder_mask){const n=t==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={_pcb_drawing_object_id:Jy("polygon"),pcb_drawing_type:"polygon",points:DpA(i),layer:n,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};o.push(s)}return o},_3e=(e,A)=>{const{x:t,y:i,width:o,height:n,layer:s}=e,r=[{_pcb_drawing_object_id:Jy("pill"),pcb_drawing_type:"pill",x:t,y:i,w:o,h:n,layer:s||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(e.is_covered_with_solder_mask){const a=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",g={_pcb_drawing_object_id:Jy("pill"),pcb_drawing_type:"pill",x:t,y:i,w:o,h:n,layer:a,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};r.push(g)}return r},k3e=(e,A)=>{const{x:t,y:i,width:o,height:n,layer:s,ccw_rotation:r}=e,a=[{_pcb_drawing_object_id:Jy("pill"),pcb_drawing_type:"pill",x:t,y:i,w:o,h:n,layer:s||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:r}];if(e.is_covered_with_solder_mask){const g=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",I={_pcb_drawing_object_id:Jy("pill"),pcb_drawing_type:"pill",x:t,y:i,w:o,h:n,layer:g,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:r,..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};a.push(I)}return a},G3e=(e,A)=>{const{_parent_pcb_component:t,_parent_source_component:i}=A,o=e,n=typeof o.font_size=="string"?ue.parse(o.font_size):o.font_size??.2;let s;return o.knockout_padding&&(s={left:typeof o.knockout_padding.left=="string"?ue.parse(o.knockout_padding.left):o.knockout_padding.left,top:typeof o.knockout_padding.top=="string"?ue.parse(o.knockout_padding.top):o.knockout_padding.top,bottom:typeof o.knockout_padding.bottom=="string"?ue.parse(o.knockout_padding.bottom):o.knockout_padding.bottom,right:typeof o.knockout_padding.right=="string"?ue.parse(o.knockout_padding.right):o.knockout_padding.right}),[{_pcb_drawing_object_id:Jy("text"),pcb_drawing_type:"text",x:o.anchor_position.x,y:o.anchor_position.y,layer:o.layer,align:o.anchor_alignment??"center",text:o.text,size:n,ccw_rotation:o.ccw_rotation,is_mirrored:o.is_mirrored,is_knockout:o.is_knockout,knockout_padding:s,_element:e,_parent_pcb_component:t,_parent_source_component:i}]},mc=0,Jy=e=>`${e}_${mc++}`,DpA=e=>(e??[]).map(A=>({x:ue.parse(A.x),y:ue.parse(A.y)})),F3e=(e,A)=>{const t="pcb_component_id"in e?A.find(s=>s.type==="pcb_component"&&s.pcb_component_id===e.pcb_component_id):void 0,i=t&&"source_component_id"in t?A.find(s=>s.type==="source_component"&&s.source_component_id===t.source_component_id):void 0,o="source_port_id"in e?e.source_port_id:"pcb_port_id"in e?Qb(A).pcb_port.get(e.pcb_port_id)?.source_port_id:void 0,n=o?A.find(s=>s.type==="source_port"&&s.source_port_id===o):void 0;switch(e.type){case"pcb_smtpad":{const s={_parent_pcb_component:t,_parent_source_component:i,_source_port:n};return e.shape==="rect"||e.shape==="rotated_rect"?S3e(e,s):e.shape==="circle"?b3e(e,s):e.shape==="polygon"?x3e(e,s):e.shape==="pill"?_3e(e,s):e.shape==="rotated_pill"?k3e(e,s):[]}case"pcb_trace":{const s=[];if(e.route_thickness_mode==="interpolated"){const g=e.route.map(B=>({x:B.x,y:B.y,trace_width:B.route_type==="wire"?B.width:.5})),I=D3e(g,.5),c=e.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${mc++}`,_element:e,pcb_drawing_type:"polygon",points:I,layer:c}),e.route.forEach(B=>{B.route_type==="via"&&s.push({_pcb_drawing_object_id:`circle_${mc++}`,_element:e,pcb_drawing_type:"circle",x:B.x,y:B.y,r:B.outer_diameter/2,layer:B.from_layer})}),s}let r=null,a=null;for(const g of e.route)g.route_type==="wire"&&(r!==null&&a!==null&&s.push({_pcb_drawing_object_id:`line_${mc++}`,_element:e,pcb_drawing_type:"line",x1:r,y1:a,x2:g.x,y2:g.y,width:g.width,squareCap:!1,layer:g.layer}),r=g.x,a=g.y);return s}case"pcb_via":{const{x:s,y:r,outer_diameter:a,hole_diameter:g}=e,I=e.from_layer,c=e.to_layer,B=e.layers,l=[];I&&c?l.push(I,c):B&&Array.isArray(B)?l.push(...B):l.push("top","bottom");const C=[];for(const E of l)C.push({_pcb_drawing_object_id:`circle_${mc++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:E,_element:e,_parent_pcb_component:t,_parent_source_component:i});return C.push({_pcb_drawing_object_id:`circle_${mc++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"drill",_element:e}),C}case"pcb_plated_hole":if(e.shape==="circle"){const{x:s,y:r,hole_diameter:a,outer_diameter:g}=e;return[{_pcb_drawing_object_id:`circle_${mc++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:n},{_pcb_drawing_object_id:`circle_${mc++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:"drill",_element:e}]}else if(e.shape==="oval"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:I,hole_width:c}=e;return[{_pcb_drawing_object_id:`oval_${mc++}`,pcb_drawing_type:"oval",x:s,y:r,rX:g/2,rY:a/2,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:n},{_pcb_drawing_object_id:`oval_${mc++}`,_element:e,pcb_drawing_type:"oval",x:s,y:r,rX:c/2,rY:I/2,layer:"drill"}]}else if(e.shape==="pill"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:I,hole_width:c}=e;return[{_pcb_drawing_object_id:`pill_${mc++}`,pcb_drawing_type:"pill",x:s,y:r,w:g,h:a,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:n,ccw_rotation:e.ccw_rotation},{_pcb_drawing_object_id:`pill_${mc++}`,_element:e,pcb_drawing_type:"pill",x:s,y:r,w:c,h:I,layer:"drill",ccw_rotation:e.ccw_rotation}]}else if(e.shape==="circular_hole_with_rect_pad"){const{x:s,y:r,hole_diameter:a,rect_pad_width:g,rect_pad_height:I,rect_border_radius:c,hole_offset_x:B,hole_offset_y:l}=e,C=ue.parse(B??0),E=ue.parse(l??0);return[{_pcb_drawing_object_id:`rect_${mc++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:I,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:n,roundness:c},{_pcb_drawing_object_id:`rect_${mc++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:I,layer:"bottom",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:n,roundness:c},{_pcb_drawing_object_id:`circle_${mc++}`,_element:e,pcb_drawing_type:"circle",x:s+C,y:r+E,r:a/2,layer:"drill"}]}else if(e.shape==="pill_hole_with_rect_pad"){const{x:s,y:r,hole_width:a,hole_height:g,rect_pad_width:I,rect_pad_height:c,rect_border_radius:B}=e;return[{_pcb_drawing_object_id:`rect_${mc++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:c,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:n,roundness:B},{_pcb_drawing_object_id:`rect_${mc++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:c,layer:"bottom",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:n,roundness:B},{_pcb_drawing_object_id:`pill_${mc++}`,_element:e,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill"}]}else if(e.shape==="rotated_pill_hole_with_rect_pad"){const{x:s,y:r,hole_width:a,hole_height:g,hole_ccw_rotation:I,rect_pad_width:c,rect_pad_height:B,rect_ccw_rotation:l,rect_border_radius:C}=e;return[{_pcb_drawing_object_id:`rect_${mc++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:B,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:n,ccw_rotation:l,roundness:C},{_pcb_drawing_object_id:`rect_${mc++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:B,layer:"bottom",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:n,ccw_rotation:l,roundness:C},{_pcb_drawing_object_id:`pill_${mc++}`,_element:e,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill",ccw_rotation:I}]}else if(e.shape==="hole_with_polygon_pad"){const{x:s,y:r,pad_outline:a,hole_shape:g,hole_diameter:I,hole_width:c,hole_height:B,layers:l,hole_offset_x:C,hole_offset_y:E}=e,Q=ue.parse(C??0),h=ue.parse(E??0),u=a,d=[];if(u&&Array.isArray(u)){const D=DpA(u).map(w=>({x:w.x+s,y:w.y+r}));for(const w of l||["top","bottom"])d.push({_pcb_drawing_object_id:`polygon_${mc++}`,pcb_drawing_type:"polygon",points:D,layer:w,_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:n})}const f={x:s+Q,y:r+h},m=[];return g==="circle"?m.push({_pcb_drawing_object_id:`circle_${mc++}`,pcb_drawing_type:"circle",x:f.x,y:f.y,r:(I??0)/2,layer:"drill",_element:e,_parent_pcb_component:t,_parent_source_component:i}):g==="oval"?m.push({_pcb_drawing_object_id:`oval_${mc++}`,pcb_drawing_type:"oval",x:f.x,y:f.y,rX:(c??0)/2,rY:(B??0)/2,layer:"drill",_element:e,_parent_pcb_component:t,_parent_source_component:i}):(g==="pill"||g==="rotated_pill")&&m.push({_pcb_drawing_object_id:`pill_${mc++}`,pcb_drawing_type:"pill",x:f.x,y:f.y,w:c??0,h:B??0,layer:"drill",_element:e,_parent_pcb_component:t,_parent_source_component:i,ccw_rotation:e.ccw_rotation}),[...d,...m]}else return[];case"pcb_copper_text":return G3e(e,{_parent_pcb_component:t,_parent_source_component:i})}return[]},mo={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(242, 237, 161)",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)",soldermaskWithCopper:{top:"rgb(18, 82, 50)",bottom:"rgb(77, 127, 196)"},soldermask:{top:"rgb(12, 55, 33)",bottom:"rgb(12, 55, 33)"},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)"}},Ef=(e,A=1)=>{if(Math.abs(e.a)!==Math.abs(e.d))throw new Error("Cannot scale non-uniformly");return A*Math.abs(e.a)},EI={elementOverlay:40,dimensionOverlay:40,editTraceHintOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:20,clickToInteractOverlay:100},jV={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:mo.board.copper.f,inner1:mo.board.copper.in1,inner2:mo.board.copper.in2,inner3:mo.board.copper.in3,inner4:mo.board.copper.in4,inner5:mo.board.copper.in5,inner6:mo.board.copper.in6,inner7:mo.board.copper.in7,inner8:mo.board.copper.in8,bottom:mo.board.copper.b,drill:mo.board.anchor,keepout:mo.board.background,tkeepout:mo.board.b_crtyd,tplace:mo.board.b_silks,top_silkscreen:mo.board.f_silks,bottom_silkscreen:mo.board.b_silks,top_fabrication:mo.board.f_fab,bottom_fabrication:mo.board.b_fab,soldermask_top:mo.board.soldermask.top,soldermask_bottom:mo.board.soldermask.bottom,soldermask_with_copper_top:mo.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:mo.board.soldermaskWithCopper.bottom,bottom_notes:mo.board.user_2,top_notes:mo.board.user_2,...mo.board},R3e=["inner6","inner5","inner4","inner3","inner2","inner1","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","soldermask_with_copper_bottom","soldermask_with_copper_top","edge_cuts","top_silkscreen","board"],M3e=class{canvasLayerMap;ctxLayerMap;aperture;transform;foregroundLayer="top";lastPoint;constructor(e){this.canvasLayerMap=e,this.ctxLayerMap=Object.fromEntries(Object.entries(e).map(([A,t])=>[A,t.getContext("2d")])),this.transform=Bb(),this.transform.d*=-1,this.transform=Yy(this.transform,nl(0,-500)),this.lastPoint={x:0,y:0},this.equip({})}clear(){for(const e of Object.values(this.ctxLayerMap))e.clearRect(0,0,e.canvas.width,e.canvas.height)}equip(e){this.aperture={fontSize:0,shape:"circle",mode:"add",size:0,color:"red",layer:"top",opacity:this.foregroundLayer===e.color?1:.5,...e}}drawMeshPattern(e,A,t,i,o,n=45){const s=this.getLayerCtx(),[r,a]=qi(this.transform,[e,A]),[g,I]=qi(this.transform,[e+t,A+i]),c=Ef(this.transform,o);s.lineWidth=1,s.strokeStyle=this.aperture.color;const B=l=>{const C=Math.sin(l),E=Math.cos(l),Q=Math.sqrt((g-r)**2+(I-a)**2);for(let h=-Q;h<=Q;h+=c)s.beginPath(),s.moveTo(r+h*E-Q*C,a+h*C+Q*E),s.lineTo(r+h*E+Q*C,a+h*C-Q*E),s.stroke()};B(n*Math.PI/180),B((n+90)*Math.PI/180)}rect({x:e,y:A,w:t,h:i,mesh_fill:o,is_filled:n=!0,has_stroke:s,is_stroke_dashed:r,stroke_width:a,roundness:g}){const[I,c]=qi(this.transform,[e-t/2,A-i/2]),[B,l]=qi(this.transform,[e+t/2,A+i/2]);this.applyAperture();const C=this.getLayerCtx(),E=g?Ef(this.transform,g):0,Q=s===void 0?n===!1:s;if(o)C.save(),C.beginPath(),E>0&&C.roundRect?C.roundRect(I,c,B-I,l-c,E):C.rect(I,c,B-I,l-c),C.clip(),this.drawMeshPattern(e-t/2,A-i/2,t,i,.15),C.restore(),E>0&&C.roundRect?(C.beginPath(),C.roundRect(I,c,B-I,l-c,E),C.stroke()):C.strokeRect(I,c,B-I,l-c);else if(n!==!1&&(E>0&&C.roundRect?(C.beginPath(),C.roundRect(I,c,B-I,l-c,E),C.fill()):C.fillRect(I,c,B-I,l-c)),Q){const h=C.lineWidth;if(a!==void 0&&(C.lineWidth=Ef(this.transform,a)),r){let u=[];const d=Math.abs(this.transform.a);if(d>0){const m=.1*d,D=m*1.3;m>.5&&(u=[m,D])}C.setLineDash(u)}E>0&&C.roundRect?(C.beginPath(),C.roundRect(I,c,B-I,l-c,E),C.stroke()):C.strokeRect(I,c,B-I,l-c),r&&C.setLineDash([]),a!==void 0&&(C.lineWidth=h)}}rotatedRect(e,A,t,i,o,n,s){const r=this.getLayerCtx();this.applyAperture();const[a,g]=qi(this.transform,[e-t/2,A-i/2]),[I,c]=qi(this.transform,[e+t/2,A+i/2]),B=n?Ef(this.transform,n):0;r.save();const[l,C]=qi(this.transform,[e,A]);r.translate(l,C);const E=360-o;o&&r.rotate(E*Math.PI/180),r.translate(-l,-C),s?(r.beginPath(),B>0&&r.roundRect?r.roundRect(a,g,I-a,c-g,B):r.rect(a,g,I-a,c-g),r.clip(),this.drawMeshPattern(e-t/2,A-i/2,t,i,.15),B>0&&r.roundRect?(r.beginPath(),r.roundRect(a,g,I-a,c-g,B),r.stroke()):r.strokeRect(a,g,I-a,c-g)):B>0&&r.roundRect?(r.beginPath(),r.roundRect(a,g,I-a,c-g,B),r.fill()):r.fillRect(a,g,I-a,c-g),r.restore()}rotatedPill(e,A,t,i,o){const n=this.getLayerCtx();this.applyAperture(),n.save();const[s,r]=qi(this.transform,[e,A]);n.translate(s,r);const a=360-o;o&&n.rotate(a*Math.PI/180),n.translate(-s,-r),this.pill(e,A,t,i),n.restore()}circle(e,A,t,i){const o=Ef(this.transform,t),[n,s]=qi(this.transform,[e,A]);this.applyAperture();const r=this.getLayerCtx();i?(r.save(),r.beginPath(),r.arc(n,s,o,0,2*Math.PI),r.clip(),this.drawMeshPattern(e-t,A-t,t*2,t*2,.15),r.restore(),r.beginPath(),r.arc(n,s,o,0,2*Math.PI),r.stroke()):(r.beginPath(),r.arc(n,s,o,0,2*Math.PI),r.fill())}oval(e,A,t,i){const o=Ef(this.transform,t),n=Ef(this.transform,i),[s,r]=qi(this.transform,[e,A]);this.applyAperture();const a=this.getLayerCtx();a.beginPath(),a.ellipse(s,r,o,n,0,0,2*Math.PI),a.fill(),a.closePath()}pill(e,A,t,i){const[o,n]=qi(this.transform,[e-t/2,A+i/2]),s=Ef(this.transform,t),r=Ef(this.transform,i),a=Math.min(s,r)/2;this.applyAperture();const g=this.getLayerCtx();g.beginPath(),g.arc(o+a,n+a,a,Math.PI,Math.PI*1.5),g.arc(o+s-a,n+a,a,Math.PI*1.5,0),g.arc(o+s-a,n+r-a,a,0,Math.PI*.5),g.arc(o+a,n+r-a,a,Math.PI*.5,Math.PI),g.fill(),g.closePath()}polygon(e){if(e.length<3)return;this.applyAperture();const A=this.getLayerCtx(),t=e.map(o=>qi(this.transform,[o.x,o.y]));A.beginPath(),A.moveTo(t[0][0],t[0][1]);for(let o=1;o<t.length;o++)A.lineTo(t[o][0],t[o][1]);A.closePath(),A.fill("evenodd");const i=Ef(this.transform,this.aperture.size);i>0&&(A.lineWidth=i,A.stroke())}debugText(e,A,t){const[i,o]=qi(this.transform,[A,t]);this.applyAperture();const n=this.getLayerCtx();n.font="10px sans-serif",n.fillText(e,i,o)}getLayerCtx(){const e=this.ctxLayerMap[this.aperture.layer];if(!e)throw new Error(`No context for layer "${this.aperture.layer}"`);return e}orderAndFadeLayers(){const{canvasLayerMap:e,foregroundLayer:A}=this,t=A==="top"?"top_silkscreen":A==="bottom"?"bottom_silkscreen":void 0,i=A==="top"?"top_notes":A==="bottom"?"bottom_notes":void 0,o=A==="top"?"soldermask_with_copper_top":A==="bottom"?"soldermask_with_copper_bottom":void 0,n=new Set([A,"drill","edge_cuts","other","board",...t?[t]:[],...i?[i]:[],...o?[o]:[]]),s=[A,"edge_cuts",...t?[t]:[],...i?[i]:[],...o?[o]:[]],r=[...R3e.filter(a=>!s.includes(a)),A,...o?[o]:[],"edge_cuts","drill",...t?[t]:[],...i?[i]:[]];r.forEach((a,g)=>{const I=e[a];I&&(I.style.zIndex=`${EI.topLayer-(r.length-g)}`,I.style.opacity=n.has(a)?"1":"0.5")})}applyAperture(){const{transform:e,aperture:A}=this;let{size:t,mode:i,color:o,fontSize:n,layer:s}=A;s in this.ctxLayerMap||(this.aperture.layer="other");const r=this.getLayerCtx();if(!r)throw new Error(`No context for layer "${this.foregroundLayer}"`);if(o||(o="undefined"),r.lineWidth=Ef(e,t),r.lineCap="round",i==="add"){r.globalCompositeOperation="source-over";let a=jV[o.toLowerCase()];if(!a)try{a=ka(o).rgb().toString()}catch{console.warn(`Invalid color format: '${o}'`),a="white"}r.fillStyle=a,r.strokeStyle=a}else r.globalCompositeOperation="destination-out",r.fillStyle="rgba(0,0,0,1)",r.strokeStyle="rgba(0,0,0,1)";r.font=`${Ef(lb(e),n)}px sans-serif`}moveTo(e,A){this.lastPoint={x:e,y:A}}lineTo(e,A){const[t,i]=qi(this.transform,[e,A]),{size:o,shape:n,mode:s}=this.aperture,r=Ef(this.transform,o),{lastPoint:a}=this,g=qi(this.transform,a);this.applyAperture();const I=this.getLayerCtx();n==="square"&&I.fillRect(g.x-r/2,g.y-r/2,r,r),I.beginPath(),I.moveTo(g.x,g.y),I.lineTo(t,i),I.stroke(),I.closePath(),n==="square"&&I.fillRect(t-r/2,i-r/2,r,r),this.lastPoint={x:e,y:A}}polygonWithArcs(e){const A=this.getLayerCtx(),t=i=>{if(i.vertices.length===0)return;const o=i.vertices[0],n=qi(this.transform,[o.x,o.y]);A.moveTo(n[0],n[1]);for(let s=0;s<i.vertices.length;s++){const r=i.vertices[s],a=i.vertices[(s+1)%i.vertices.length];if(r.bulge&&r.bulge!==0){const g=r.bulge,I=a.x-r.x,c=a.y-r.y,B=Math.sqrt(I*I+c*c);if(B<1e-9){const M=qi(this.transform,[a.x,a.y]);A.lineTo(M[0],M[1]);continue}const l=4*Math.atan(g),C=Math.abs(B/(2*Math.sin(l/2))),E=(r.x+a.x)/2,Q=(r.y+a.y)/2,h=I/B,d=-(c/B),f=h,m=Math.sqrt(Math.max(0,C*C-(B/2)**2)),D=E+m*d*Math.sign(g),w=Q+m*f*Math.sign(g),b=Math.atan2(r.y-w,r.x-D);let k=Math.atan2(a.y-w,a.x-D);g>0&&k<b?k+=2*Math.PI:g<0&&k>b&&(k-=2*Math.PI);const x=qi(this.transform,[D,w]),N=Ef(this.transform,C);A.arc(x[0],x[1],N,-b,-k,g>0)}else{const g=qi(this.transform,[a.x,a.y]);A.lineTo(g[0],g[1])}}A.closePath()};if(A.beginPath(),t(e.outer_ring),e.inner_rings)for(const i of e.inner_rings)t(i);A.fill("evenodd")}};function N3e(e){return e.type==="pcb_copper_pour"}function zV({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const o=A.filter(N3e);if(o.length===0)return;const n=new MQ(e);n.realToCanvasMat=i,n.drawElements(o,{layers:t})}var v3e={...Cf,silkscreen:{top:mo.board.f_fab,bottom:mo.board.b_fab}};function L3e(e){return e.type.includes("pcb_fabrication_note")}function Zat({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const o=new MQ(e);o.configure({colorOverrides:v3e}),o.realToCanvasMat=i;const n=A.filter(L3e);o.drawElements(n,{layers:t})}function U3e(e){return e.type==="pcb_hole"}function H3e({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:o}){const n=new MQ(e);n.realToCanvasMat=i;const s=A.filter(U3e);n.drawElements(s,{layers:t,drawSoldermask:o})}function Y3e(e){return e.type==="pcb_board"}function J3e({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:o}){const n=new MQ(e);n.realToCanvasMat=i;const s=A.filter(Y3e);for(const r of s)n.drawElements([r],{layers:t,drawSoldermask:o})}function T3e(e){return e.type==="pcb_cutout"}function K3e({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const o=new MQ(e);o.realToCanvasMat=i;const n=A.filter(T3e);o.drawElements(n,{layers:t})}function P3e(e){return e.type==="pcb_keepout"}function q3e({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const o=A.filter(P3e);if(o.length===0)return;const n=new MQ(e);n.realToCanvasMat=i,n.drawElements(o,{layers:[]})}function O3e(e){return e.type.startsWith("pcb_note_")}function Vat({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const o=new MQ(e);o.realToCanvasMat=i;const n=A.filter(O3e);o.drawElements(n,{layers:t})}function W3e(e){return e.type==="pcb_panel"}function Z3e({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:o}){const n=new MQ(e);n.realToCanvasMat=i;const s=A.filter(W3e);for(const r of s)n.drawElements([r],{layers:t,drawSoldermask:o})}var V3e={...Cf,copper:{...Cf.copper,top:ka(mo.board.pad_front).lighten(.5).toString(),bottom:ka(mo.board.pad_back).lighten(.5).toString(),inner1:ka(mo.board.copper.in1).lighten(.5).toString(),inner2:ka(mo.board.copper.in2).lighten(.5).toString(),inner3:ka(mo.board.copper.in3).lighten(.5).toString(),inner4:ka(mo.board.copper.in4).lighten(.5).toString(),inner5:ka(mo.board.copper.in5).lighten(.5).toString(),inner6:ka(mo.board.copper.in6).lighten(.5).toString()}};function j3e(e){return e.type==="pcb_smtpad"}function z3e({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:o,drawSoldermask:n}){const s=A.filter(j3e).filter(I=>{const c=I.layer;return t.some(B=>B==="top_copper"&&c==="top"||B==="bottom_copper"&&c==="bottom"||B==="inner1_copper"&&c==="inner1"||B==="inner2_copper"&&c==="inner2"||B==="inner3_copper"&&c==="inner3"||B==="inner4_copper"&&c==="inner4"||B==="inner5_copper"&&c==="inner5"||B==="inner6_copper"&&c==="inner6")});if(s.length===0)return;const r=new Set;if(o)for(const I of o)(I.is_mouse_over||I.is_in_highlighted_net)&&I._element?.type==="pcb_smtpad"&&r.add(I._element.pcb_smtpad_id);const a=s.filter(I=>r.has(I.pcb_smtpad_id)),g=s.filter(I=>!r.has(I.pcb_smtpad_id));if(g.length>0){const I=new MQ(e);I.realToCanvasMat=i,I.drawElements(g,{layers:t,drawSoldermask:n})}if(a.length>0){const I=new MQ(e);I.configure({colorOverrides:V3e}),I.realToCanvasMat=i,I.drawElements(a,{layers:t,drawSoldermask:n})}}var X3e={...Cf,copper:{...Cf.copper,top:ka(mo.board.pad_front).lighten(.5).toString(),bottom:ka(mo.board.pad_back).lighten(.5).toString(),inner1:ka(mo.board.copper.in1).lighten(.5).toString(),inner2:ka(mo.board.copper.in2).lighten(.5).toString(),inner3:ka(mo.board.copper.in3).lighten(.5).toString(),inner4:ka(mo.board.copper.in4).lighten(.5).toString(),inner5:ka(mo.board.copper.in5).lighten(.5).toString(),inner6:ka(mo.board.copper.in6).lighten(.5).toString()}};function $3e(e){return e.type==="pcb_trace"}var AOe=e=>e.map(A=>A.endsWith("_copper")?A.replace("_copper",""):A);function tOe({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:o}){const n=new Set(AOe(t)),s=A.filter($3e).filter(I=>I.route.some(c=>c.route_type==="wire"&&"layer"in c&&n.has(c.layer)));if(s.length===0)return;const r=new Set;if(o)for(const I of o)(I.is_mouse_over||I.is_in_highlighted_net)&&I._element?.type==="pcb_trace"&&r.add(I._element.pcb_trace_id);const a=s.filter(I=>r.has(I.pcb_trace_id)),g=s.filter(I=>!r.has(I.pcb_trace_id));if(g.length>0){const I=new MQ(e);I.realToCanvasMat=i,I.drawElements(g,{layers:t})}if(a.length>0){const I=new MQ(e);I.configure({colorOverrides:X3e}),I.realToCanvasMat=i,I.drawElements(a,{layers:t})}}var eOe={...Cf,copper:{...Cf.copper,top:ka(mo.board.pad_front).lighten(.5).toString(),bottom:ka(mo.board.pad_back).lighten(.5).toString()}};function iOe(e){return e.type==="pcb_plated_hole"}function jat({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:o,drawSoldermask:n}){const s=A.filter(iOe);if(s.length===0)return;const r=new Set;if(o)for(const I of o)(I.is_mouse_over||I.is_in_highlighted_net)&&I._element?.type==="pcb_plated_hole"&&r.add(I._element.pcb_plated_hole_id);const a=s.filter(I=>r.has(I.pcb_plated_hole_id)),g=s.filter(I=>!r.has(I.pcb_plated_hole_id));if(g.length>0){const I=new MQ(e);I.realToCanvasMat=i,I.drawElements(g,{layers:t,drawSoldermask:n})}if(a.length>0){const I=new MQ(e);I.configure({colorOverrides:eOe}),I.realToCanvasMat=i,I.drawElements(a,{layers:t,drawSoldermask:n})}}function zat(e){const{lines:A,anchorPoint:t,ccwRotation:i}=e;if(!i)return A;const o=i*Math.PI/180,n=OKe(o),s=Yy(nl(t.x,t.y),n,nl(-t.x,-t.y));return qi(s,t),A.map(r=>({...r,x1:qi(s,{x:r.x1,y:r.y1}).x,y1:qi(s,{x:r.x1,y:r.y1}).y,x2:qi(s,{x:r.x2,y:r.y2}).x,y2:qi(s,{x:r.x2,y:r.y2}).y}))}var oOe=.6,Xat=.2,$at=e=>{const A=e.size*.7,t=A*oOe,i=A*Xat,o=A*Xat,n=e.text.split(/\r?\n/),s=e.text.length>0&&A>0,r=s?n.length:0,a=s?n.map(c=>c.length===0?0:c.length*t+(c.length-1)*i):[],g=a.length>0?Math.max(...a):0,I=r>0?r*A+(r-1)*o:0;return{text_lines:n,line_count:r,line_widths:a,target_height:A,target_width_char:t,space_between_chars:i,space_between_lines:o,width:g,height:I}},Agt=e=>{const A=$at(e);return{width:A.width,height:A.height,lineHeight:A.target_height,lineSpacing:A.space_between_lines,lineCount:A.line_count}},tgt=e=>{const{text_lines:A,line_count:t,line_widths:i,target_height:o,target_width_char:n,space_between_chars:s,space_between_lines:r,width:a}=$at(e);if(o<=0||t===0)return[];const g=o/12,I=[];for(let c=0;c<t;c++){const B=-c*(o+r),l=i[c],C=(a-l)/2;let E=e.x+C;for(let Q=0;Q<A[c].length;Q++){const h=A[c][Q],u=jw[h]??jw[h.toUpperCase()];if(!u){E+=n+s;continue}for(const{x1:d,y1:f,x2:m,y2:D}of u)I.push({_pcb_drawing_object_id:Jy("line"),pcb_drawing_type:"line",x1:E+n*d,y1:e.y+B+o*f,x2:E+n*m,y2:e.y+B+o*D,width:g,layer:e.layer,unit:e.unit,color:e.color});E+=n+s}}return I};function SD(e){const t=e.color??jV[e.layer];let i=ka(t);return e._element?.type==="pcb_copper_pour"&&(i=i.alpha(.7)),e.is_mouse_over||e.is_in_highlighted_net?i.lighten(.5).rgb().toString():i.rgb().toString()}var egt=(e,A)=>{e.equip({size:A.zoomIndependent?A.width/e.transform.a:A.width,shape:A.squareCap?"square":"circle",color:SD(A),layer:A.layer}),e.moveTo(A.x1,A.y1),e.lineTo(A.x2,A.y2)},nOe=(e,A,t)=>{switch(t){case"top_left":return{x:0,y:-A};case"top_center":return{x:-e/2,y:-A};case"top_right":return{x:-e,y:-A};case"center_left":return{x:0,y:-A/2};case"center":return{x:-e/2,y:-A/2};case"center_right":return{x:-e,y:-A/2};case"bottom_left":return{x:0,y:0};case"bottom_center":return{x:-e/2,y:0};case"bottom_right":return{x:-e,y:0};default:return{x:0,y:0}}},igt=e=>e.layer==="bottom_silkscreen"||e.layer==="bottom"?e.is_mirrored!==!1:e.is_mirrored===!0,sOe=(e,A)=>{e.equip({fontSize:A.size,color:SD(A),layer:A.layer});const{width:t,height:i}=Agt(A),o=nOe(t,i,A.align);A.x??=0,A.y??=0;const n={x:A.x,y:A.y};let s=tgt({...A,x:A.x+o.x,y:A.y+o.y});if(igt(A)&&(s=s.map(r=>({...r,x1:2*A.x-r.x1,x2:2*A.x-r.x2}))),A.ccw_rotation){const r={lines:s,anchorPoint:n,ccwRotation:A.ccw_rotation};s=zat(r)}for(const r of s)egt(e,r)},rOe=(e,A)=>{const{width:t,height:i,lineHeight:o}=Agt(A);A.x??=0,A.y??=0;const n=A.knockout_padding??{left:A.size*.5,right:A.size*.5,top:A.size*.3,bottom:A.size*.3},s=t+n.left+n.right,r=i+n.top+n.bottom,a=t/2,g=o-i/2,I=A.x-a,c=A.y-g,B={x:A.x,y:A.y},l={_pcb_drawing_object_id:`knockout_rect_${A._pcb_drawing_object_id}`,x:A.x,y:A.y,w:s,h:r,layer:A.layer,ccw_rotation:A.ccw_rotation};A.ccw_rotation?ngt(e,l):ogt(e,l);let C=tgt({...A,x:I,y:c});if(igt(A)&&(C=C.map(E=>({...E,x1:2*A.x-E.x1,x2:2*A.x-E.x2}))),A.ccw_rotation){const E={lines:C,anchorPoint:B,ccwRotation:A.ccw_rotation};C=zat(E)}for(const E of C)e.equip({size:E.width,shape:"circle",color:"black",layer:A.layer,mode:"subtract"}),e.moveTo(E.x1,E.y1),e.lineTo(E.x2,E.y2);e.equip({mode:"add"})},ogt=(e,A)=>{e.equip({color:SD(A),layer:A.layer,size:A.stroke_width}),e.rect({x:A.x,y:A.y,w:A.w,h:A.h,mesh_fill:A.mesh_fill,is_filled:A.is_filled,has_stroke:A.has_stroke,is_stroke_dashed:A.is_stroke_dashed,stroke_width:A.stroke_width,roundness:A.roundness})},ngt=(e,A)=>{e.equip({color:SD(A),layer:A.layer}),e.rotatedRect(A.x,A.y,A.w,A.h,A.ccw_rotation,A.roundness,A.mesh_fill)},aOe=(e,A)=>{e.equip({color:SD(A),layer:A.layer}),e.rotatedPill(A.x,A.y,A.w,A.h,A.ccw_rotation)},gOe=(e,A)=>{e.equip({color:SD(A),layer:A.layer}),e.circle(A.x,A.y,A.r,A.mesh_fill)},IOe=(e,A)=>{e.equip({color:SD(A),layer:A.layer}),e.oval(A.x,A.y,A.rX,A.rY)},cOe=(e,A)=>{e.equip({color:SD(A),layer:A.layer}),e.pill(A.x,A.y,A.w,A.h)},BOe=(e,A)=>{e.equip({color:SD(A),layer:A.layer}),e.polygon(A.points)},lOe=(e,A)=>{e.equip({color:SD(A),layer:A.layer}),e.polygonWithArcs(A.brep_shape)},COe=(e,A)=>{switch(A.pcb_drawing_type){case"line":return egt(e,A);case"text":return A.is_knockout?rOe(e,A):sOe(e,A);case"rect":return A.ccw_rotation?ngt(e,A):ogt(e,A);case"circle":return gOe(e,A);case"oval":return IOe(e,A);case"pill":return A.ccw_rotation?aOe(e,A):cOe(e,A);case"polygon":return BOe(e,A);case"polygon_with_arcs":return lOe(e,A)}},QOe=(e,A)=>{for(const t of A)COe(e,t)},EOe={...Cf,copper:{...Cf.copper,top:ka(mo.board.pad_front).lighten(.5).toString(),bottom:ka(mo.board.pad_back).lighten(.5).toString(),inner1:ka(mo.board.copper.in1).lighten(.5).toString(),inner2:ka(mo.board.copper.in2).lighten(.5).toString(),inner3:ka(mo.board.copper.in3).lighten(.5).toString(),inner4:ka(mo.board.copper.in4).lighten(.5).toString(),inner5:ka(mo.board.copper.in5).lighten(.5).toString(),inner6:ka(mo.board.copper.in6).lighten(.5).toString()},soldermask:{...Cf.soldermask,top:ka(mo.board.soldermask.top).lighten(.35).toString(),bottom:ka(mo.board.soldermask.bottom).lighten(.35).toString()}};function XV({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:o}){const n=new MQ(e);if(n.realToCanvasMat=i,n.drawElements(A,{layers:t,drawSoldermask:!0}),!o)return;const s=new Set;for(const g of o){if(!(g.is_mouse_over||g.is_in_highlighted_net))continue;const I=g._element;I?.type==="pcb_smtpad"?s.add(I.pcb_smtpad_id):I?.type==="pcb_plated_hole"?s.add(I.pcb_plated_hole_id):I?.type==="pcb_via"&&s.add(I.pcb_via_id)}if(s.size===0)return;const r=A.filter(g=>g.type==="pcb_smtpad"?s.has(g.pcb_smtpad_id):g.type==="pcb_plated_hole"?s.has(g.pcb_plated_hole_id):g.type==="pcb_via"?s.has(g.pcb_via_id):!1);if(r.length===0)return;const a=new MQ(e);a.configure({colorOverrides:EOe}),a.realToCanvasMat=i,a.drawElements(r,{layers:t,drawSoldermask:!0})}var hOe={...Cf,silkscreen:{top:mo.board.f_silks,bottom:mo.board.b_silks}};function uOe(e){return e.type.includes("pcb_silkscreen")}function sgt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const o=new MQ(e);o.configure({colorOverrides:hOe}),o.realToCanvasMat=i;const n=A.filter(uOe);o.drawElements(n,{layers:t})}var dOe={...Cf,copper:{...Cf.copper,top:ka(mo.board.pad_front).lighten(.5).toString(),bottom:ka(mo.board.pad_back).lighten(.5).toString()}};function pOe(e){return e.type==="pcb_via"}function rgt({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:o,drawSoldermask:n}){const s=A.filter(pOe).filter(I=>t.some(c=>c.includes("copper")));if(s.length===0)return;const r=new Set;if(o)for(const I of o)(I.is_mouse_over||I.is_in_highlighted_net)&&I._element?.type==="pcb_via"&&r.add(I._element.pcb_via_id);const a=s.filter(I=>r.has(I.pcb_via_id)),g=s.filter(I=>!r.has(I.pcb_via_id));if(g.length>0){const I=new MQ(e);I.realToCanvasMat=i,I.drawElements(g,{layers:t,drawSoldermask:n})}if(a.length>0){const I=new MQ(e);I.configure({colorOverrides:dOe}),I.realToCanvasMat=i,I.drawElements(a,{layers:t,drawSoldermask:n})}}var fOe=["board","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","soldermask_with_copper_bottom","soldermask_with_copper_top","top_fabrication","bottom_fabrication","inner1","inner2","inner3","inner4","inner5","inner6","drill","edge_cuts","bottom_notes","top_notes","top_silkscreen","bottom_silkscreen","other"],yOe=({primitives:e,elements:A,transform:t,grid:i,width:o=500,height:n=500})=>{const s=AA.useRef({}),r=zl(g=>g.selected_layer),a=zl(g=>g.is_showing_solder_mask);return AA.useEffect(()=>{if(!s.current||Object.keys(s.current).length===0)return;const g=Object.fromEntries(Object.entries(s.current).filter(([B,l])=>!(!l||!a&&B.includes("soldermask"))));if(Object.keys(g).length===0)return;const I=new M3e(g);t&&(I.transform=t),I.clear(),I.foregroundLayer=r;const c=e.filter(B=>a||!B.layer?.includes("soldermask")).filter(B=>B.layer!=="board").filter(B=>B._element?.type!=="pcb_smtpad").filter(B=>B._element?.type!=="pcb_plated_hole").filter(B=>B._element?.type!=="pcb_via").filter(B=>B._element?.type!=="pcb_trace");if(QOe(I,c),t){const B=s.current.top,l=s.current.bottom,C=s.current.inner1,E=s.current.inner2,Q=s.current.inner3,h=s.current.inner4,u=s.current.inner5,d=s.current.inner6;B&&jat({canvas:B,elements:A,layers:["top_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),l&&jat({canvas:l,elements:A,layers:["bottom_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),B&&zV({canvas:B,elements:A,layers:["top_copper"],realToCanvasMat:t}),l&&zV({canvas:l,elements:A,layers:["bottom_copper"],realToCanvasMat:t});const f=[{canvas:B,copperLayer:"top_copper"},{canvas:l,copperLayer:"bottom_copper"},{canvas:C,copperLayer:"inner1_copper"},{canvas:E,copperLayer:"inner2_copper"},{canvas:Q,copperLayer:"inner3_copper"},{canvas:h,copperLayer:"inner4_copper"},{canvas:u,copperLayer:"inner5_copper"},{canvas:d,copperLayer:"inner6_copper"}];for(const{canvas:H,copperLayer:O}of f)H&&tOe({canvas:H,elements:A,layers:[O],realToCanvasMat:t,primitives:e});for(const{canvas:H,copperLayer:O}of f)H&&(z3e({canvas:H,elements:A,layers:[O],realToCanvasMat:t,primitives:e,drawSoldermask:a}),a&&XV({canvas:H,elements:A,layers:[O],realToCanvasMat:t,primitives:e}));if(B&&rgt({canvas:B,elements:A,layers:["top_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),l&&rgt({canvas:l,elements:A,layers:["bottom_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),a){const H=s.current.soldermask_top;H&&XV({canvas:H,elements:A,layers:["top_soldermask"],realToCanvasMat:t,primitives:e});const O=s.current.soldermask_bottom;O&&XV({canvas:O,elements:A,layers:["bottom_soldermask"],realToCanvasMat:t,primitives:e})}B&&zV({canvas:B,elements:A,layers:["top_copper"],realToCanvasMat:t}),l&&zV({canvas:l,elements:A,layers:["bottom_copper"],realToCanvasMat:t});const m=s.current.drill;m&&(H3e({canvas:m,elements:A,layers:["drill"],realToCanvasMat:t}),a&&XV({canvas:m,elements:A,layers:["drill"],realToCanvasMat:t,primitives:e}));const D=s.current.top_silkscreen;D&&sgt({canvas:D,elements:A,layers:["top_silkscreen"],realToCanvasMat:t});const w=s.current.bottom_silkscreen;w&&sgt({canvas:w,elements:A,layers:["bottom_silkscreen"],realToCanvasMat:t});const b=s.current.top_fabrication;b&&Zat({canvas:b,elements:A,layers:["top_fabrication_note"],realToCanvasMat:t});const k=s.current.bottom_fabrication;k&&Zat({canvas:k,elements:A,layers:["bottom_fabrication_note"],realToCanvasMat:t});const x=s.current.bottom_notes;x&&Vat({canvas:x,elements:A,layers:["bottom_user_note"],realToCanvasMat:t});const N=s.current.top_notes;N&&Vat({canvas:N,elements:A,layers:["top_user_note"],realToCanvasMat:t});const M=s.current.board;M&&(Z3e({canvas:M,elements:A,layers:[],realToCanvasMat:t,drawSoldermask:a}),J3e({canvas:M,elements:A,layers:[],realToCanvasMat:t,drawSoldermask:a}));const U=s.current.edge_cuts;U&&K3e({canvas:U,elements:A,layers:["edge_cuts"],realToCanvasMat:t});const J=[{canvas:B,layer:"top"},{canvas:l,layer:"bottom"}];for(const{canvas:H,layer:O}of J)H&&q3e({canvas:H,elements:A,layers:[O],realToCanvasMat:t})}I.orderAndFadeLayers()},[e,A,t,r,a]),Z.jsxs("div",{style:{backgroundColor:"black",width:o,height:n,position:"relative"},children:[Z.jsx(MV.SuperGrid,{textColor:"rgba(0,255,0,0.8)",majorColor:"rgba(0,255,0,0.4)",minorColor:"rgba(0,255,0,0.2)",screenSpaceCellSize:200,width:o,height:n,transform:t,stringifyCoord:(g,I,c)=>`${MV.toMMSI(g,c)}, ${MV.toMMSI(I,c)}`}),fOe.filter(g=>a?!0:!g.includes("soldermask")).map(g=>g.replace(/-/g,"")).map((g,I)=>Z.jsx("canvas",{className:`pcb-layer-${g}`,ref:c=>{s.current??={},c?s.current[g]=c:delete s.current[g]},style:{position:"absolute",zIndex:I,left:0,top:0,pointerEvents:"none"},width:o,height:n},g))]})},mOe=.6,wOe=1;Gat(Y4e()),Gat(e3e());var $V=["rgba(239, 68, 68, 0.8)","rgba(249, 115, 22, 0.8)","rgba(245, 158, 11, 0.8)","rgba(234, 179, 8, 0.8)","rgba(132, 204, 22, 0.8)","rgba(34, 197, 94, 0.8)","rgba(16, 185, 129, 0.8)","rgba(20, 184, 166, 0.8)","rgba(6, 182, 212, 0.8)","rgba(14, 165, 233, 0.8)","rgba(59, 130, 246, 0.8)","rgba(99, 102, 241, 0.8)","rgba(139, 92, 246, 0.8)","rgba(168, 85, 247, 0.8)","rgba(217, 70, 239, 0.8)","rgba(236, 72, 153, 0.8)","rgba(249, 168, 212, 0.8)","rgba(161, 161, 170, 0.8)"];function agt(e,A,t,i={}){const o=i.padding??40,n=i.yFlip??!1;let s;if("center"in e){const I=e.width/2,c=e.height/2;s={minX:e.center.x-I,maxX:e.center.x+I,minY:e.center.y-c,maxY:e.center.y+c}}else s=e;const r=s.maxX-s.minX||1,a=s.maxY-s.minY||1,g=Math.min((A-2*o)/r,(t-2*o)/a);return Yy(nl(A/2,t/2),RY(g,n?-g:g),nl(-(s.minX+r/2),-(s.minY+a/2)))}function DOe(e){const A=[...e.points||[],...(e.lines||[]).flatMap(t=>t.points),...(e.rects||[]).flatMap(t=>{const i=t.width/2,o=t.height/2;return[{x:t.center.x-i,y:t.center.y-o},{x:t.center.x+i,y:t.center.y-o},{x:t.center.x-i,y:t.center.y+o},{x:t.center.x+i,y:t.center.y+o}]}),...(e.circles||[]).flatMap(t=>[{x:t.center.x-t.radius,y:t.center.y},{x:t.center.x+t.radius,y:t.center.y},{x:t.center.x,y:t.center.y-t.radius},{x:t.center.x,y:t.center.y+t.radius}]),...(e.texts||[]).flatMap(t=>{const i=t.fontSize??12,o=t.text.length*i*mOe,n=i*wOe,s=t.anchorSide??"center",r={top_left:{dx:0,dy:0},top_center:{dx:-o/2,dy:0},top_right:{dx:-o,dy:0},center_left:{dx:0,dy:-n/2},center:{dx:-o/2,dy:-n/2},center_right:{dx:-o,dy:-n/2},bottom_left:{dx:0,dy:-n},bottom_center:{dx:-o/2,dy:-n},bottom_right:{dx:-o,dy:-n}},{dx:a,dy:g}=r[s],I=t.x+a,c=t.y+g;return[{x:I,y:c},{x:I+o,y:c+n}]})];return A.length===0?{minX:-1,maxX:1,minY:-1,maxY:1}:A.reduce((t,i)=>({minX:Math.min(t.minX,i.x),maxX:Math.max(t.maxX,i.x),minY:Math.min(t.minY,i.y),maxY:Math.max(t.maxY,i.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function SOe(e,A,t={}){const i=A instanceof HTMLCanvasElement?A.getContext("2d"):A;if(!i)throw new Error("Could not get 2D context from canvas");const o=A instanceof HTMLCanvasElement?A.width:A.canvas.width,n=A instanceof HTMLCanvasElement?A.height:A.canvas.height;let s;if(t.transform)s=t.transform;else if(t.viewbox)s=agt(t.viewbox,o,n,{padding:t.padding,yFlip:t.yFlip});else{const r=DOe(e),a=e.coordinateSystem==="cartesian";s=agt(r,o,n,{padding:t.padding??40,yFlip:a})}i.clearRect(0,0,o,n),i.save(),e.rects&&e.rects.length>0&&e.rects.forEach(r=>{const a=r.width/2,g=r.height/2,I=qi(s,{x:r.center.x-a,y:r.center.y-g}),c=qi(s,{x:r.center.x+a,y:r.center.y+g}),B=Math.abs(c.x-I.x),l=Math.abs(c.y-I.y);i.beginPath(),i.rect(Math.min(I.x,c.x),Math.min(I.y,c.y),B,l),r.fill&&(i.fillStyle=r.fill,i.fill()),r.stroke&&(i.strokeStyle=r.stroke,i.stroke())}),e.circles&&e.circles.length>0&&e.circles.forEach(r=>{const a=qi(s,r.center),g=r.radius*Math.abs(s.a);i.beginPath(),i.arc(a.x,a.y,g,0,2*Math.PI),r.fill&&(i.fillStyle=r.fill,i.fill()),r.stroke&&(i.strokeStyle=r.stroke??"transparent",i.stroke())}),e.lines&&e.lines.length>0&&e.lines.forEach((r,a)=>{if(r.points.length===0)return;i.beginPath();const g=qi(s,r.points[0]);i.moveTo(g.x,g.y);for(let I=1;I<r.points.length;I++){const c=qi(s,r.points[I]);i.lineTo(c.x,c.y)}if(i.strokeStyle=r.strokeColor||$V[a%$V.length],r.strokeWidth?i.lineWidth=r.strokeWidth*s.a:i.lineWidth=2,i.lineCap="round",r.strokeDash)if(typeof r.strokeDash=="string"){let I;if(r.strokeDash.includes(","))I=r.strokeDash.split(",").map(c=>parseFloat(c.trim())).filter(c=>!Number.isNaN(c));else{const c=parseFloat(r.strokeDash.trim());I=Number.isNaN(c)?[]:[c]}i.setLineDash(I)}else i.setLineDash(r.strokeDash.map(I=>I*Math.abs(s.a)));else i.setLineDash([]);i.stroke()}),e.points&&e.points.length>0&&e.points.forEach((r,a)=>{const g=qi(s,r);i.beginPath(),i.arc(g.x,g.y,3,0,2*Math.PI),i.fillStyle=r.color||$V[a%$V.length],i.fill(),r.label&&!t.disableLabels&&(i.fillStyle=r.color||"black",i.font="12px sans-serif",i.fillText(r.label,g.x+5,g.y-5))}),e.texts&&e.texts.length>0&&e.texts.forEach(r=>{const a=qi(s,{x:r.x,y:r.y});i.fillStyle=r.color||"black",i.font=`${(r.fontSize??12)*Math.abs(s.a)}px sans-serif`;const g=r.anchorSide??"center",I={top_left:"left",center_left:"left",bottom_left:"left",top_center:"center",center:"center",bottom_center:"center",top_right:"right",center_right:"right",bottom_right:"right"},c={top_left:"top",top_center:"top",top_right:"top",center_left:"middle",center:"middle",center_right:"middle",bottom_left:"bottom",bottom_center:"bottom",bottom_right:"bottom"};i.textAlign=I[g],i.textBaseline=c[g],i.fillText(r.text,a.x,a.y)}),i.restore()}var bOe=({children:e,transform:A,debugGraphics:t})=>{const i=AA.useRef(null),[o,{width:n,height:s}]=ZY(),r=zl(a=>a.is_showing_autorouting);return AA.useEffect(()=>{r&&i.current&&t&&n&&s&&(i.current.width=n,i.current.height=s,SOe(t,i.current,{transform:A,disableLabels:!0}))},[t,A,n,s,r]),r?Z.jsxs("div",{ref:o,style:{position:"relative",width:"100%",height:"100%"},children:[e,Z.jsx("canvas",{ref:i,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):e},xOe=({children:e,transform:A=Bb(),elements:t=[]})=>{const[i,{width:o,height:n}]=ZY(),s=AA.useRef(null);return AA.useEffect(()=>{const r=s.current;if(!r||!o||!n)return;r.width=o,r.height=n;const a=r.getContext("2d");if(!a)return;a.clearRect(0,0,o,n);const g=t.filter(c=>c.type==="pcb_component"),I=t.filter(c=>c.type==="pcb_manual_edit_conflict_warning");a.strokeStyle=mo.board.drc_warning,a.lineWidth=2,I.forEach(c=>{const B=g.find(O=>O.pcb_component_id===c.pcb_component_id);if(!B)return;const{width:l,height:C,center:E}=B,Q=qi(A,E),h=l*Math.abs(A.a),u=C*Math.abs(A.d),d=.1*Math.abs(A.a),f=h+d*2,m=u+d*2,D=Q.x-f/2,w=Q.y-m/2;a.beginPath(),a.rect(D,w,f,m),a.stroke();const b="Manual Edit Conflict",k=4,x=Math.max(8,Math.min(12,10*Math.abs(A.a)));a.font=`${x}px sans-serif`;const M=a.measureText(b).width+k*2,U=x+k*2,J=D+(f-M)/2,H=w+m+5;a.fillStyle="rgba(0, 0, 0, 0.7)",a.beginPath(),a.roundRect(J,H,M,U,3),a.fill(),a.fillStyle=mo.board.drc_warning,a.textAlign="center",a.textBaseline="middle",a.fillText(b,J+M/2,H+U/2)})},[t,A,o,n]),Z.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[e,Z.jsx("canvas",{ref:s,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:EI.warnings}})]})},A9=(e,A,t)=>t(e,A),ggt=(e,A,t,i,o)=>{const n=o*Math.PI/180,s=Math.cos(n),r=Math.sin(n),a=e-t,g=A-i,I=a*s-g*r,c=a*r+g*s;return{x:I+t,y:c+i}},VY=e=>{if(e.length===0)return null;let A=e[0].x,t=e[0].x,i=e[0].y,o=e[0].y;for(const n of e)A=A9(A,n.x,Math.min),t=A9(t,n.x,Math.max),i=A9(i,n.y,Math.min),o=A9(o,n.y,Math.max);return{minX:A,maxX:t,minY:i,maxY:o}},_Oe=(e,A)=>({minX:Math.min(e.minX,A.minX),maxX:Math.max(e.maxX,A.maxX),minY:Math.min(e.minY,A.minY),maxY:Math.max(e.maxY,A.maxY)}),kOe=(e,A)=>e?_Oe(e,A):A,GOe=e=>{switch(e.pcb_drawing_type){case"line":{const A=(e.width??0)/2,t=[{x:e.x1,y:e.y1},{x:e.x2,y:e.y2}],i=VY(t);return i?{minX:i.minX-A,maxX:i.maxX+A,minY:i.minY-A,maxY:i.maxY+A}:null}case"rect":{const A=e.w/2,t=e.h/2,i=[{x:e.x-A,y:e.y-t},{x:e.x+A,y:e.y-t},{x:e.x+A,y:e.y+t},{x:e.x-A,y:e.y+t}],o=e.ccw_rotation??0,n=o===0?i:i.map(s=>ggt(s.x,s.y,e.x,e.y,o));return VY(n)}case"circle":return{minX:e.x-e.r,maxX:e.x+e.r,minY:e.y-e.r,maxY:e.y+e.r};case"oval":return{minX:e.x-e.rX,maxX:e.x+e.rX,minY:e.y-e.rY,maxY:e.y+e.rY};case"pill":{const A=e.w/2,t=e.h/2,i=[{x:e.x-A,y:e.y-t},{x:e.x+A,y:e.y-t},{x:e.x+A,y:e.y+t},{x:e.x-A,y:e.y+t}],o=e.ccw_rotation??0,n=o===0?i:i.map(s=>ggt(s.x,s.y,e.x,e.y,o));return VY(n)}case"polygon":return VY(e.points);case"polygon_with_arcs":{const A=e.brep_shape.outer_ring.vertices.map(t=>({x:t.x,y:t.y}));return VY(A)}case"text":{const A=e.size??0,t=e.text?e.text.length*A*.6:0,i=A;if(t===0&&i===0)return{minX:e.x,maxX:e.x,minY:e.y,maxY:e.y};const o=t/2,n=i/2;return{minX:e.x-o,maxX:e.x+o,minY:e.y-n,maxY:e.y+n}}default:return null}};function FOe(e){const{dimensionStart:A,dimensionEnd:t,screenDimensionStart:i,screenDimensionEnd:o,flipX:n,flipY:s}=e,r=t.x-A.x,a=t.y-A.y,g=Math.sqrt(r*r+a*a),I=o.x-i.x,c=o.y-i.y,B=Math.sqrt(I*I+c*c),l=Math.atan2(c,I)*(180/Math.PI),C=Math.abs(l)%90,Q=Math.min(C,90-C)>15,h=(i.x+o.x)/2,u=(i.y+o.y)/2,d=15,f=l+90;let m=Math.cos(f*Math.PI/180)*d,D=Math.sin(f*Math.PI/180)*d;const w=I>0&&c<0,b=I>0&&c>0,k=I<0&&c>0;n!==s&&!w&&(m=-m,D=-D),w&&(m+=Math.cos(f*Math.PI/180)*-45,D+=Math.sin(f*Math.PI/180)*-45),b&&(m+=Math.cos(f*Math.PI/180)+-20,D+=Math.sin(f*Math.PI/180)+-10),k&&(m+=Math.cos(f*Math.PI/180)*10,D+=Math.sin(f*Math.PI/180)*10);const x=h+m,N=u+D;return{distance:g,screenDistance:B,x,y:N,show:g>.01&&B>30&&Q}}function ROe(e){const{dimensionStart:A,dimensionEnd:t,screenDimensionStart:i,screenDimensionEnd:o,flipX:n,flipY:s}=e;return AA.useMemo(()=>FOe({dimensionStart:A,dimensionEnd:t,screenDimensionStart:i,screenDimensionEnd:o,flipX:n,flipY:s}),[A,t,i,o,n,s])}var MOe=(e,A,t)=>{const i=t*Math.PI/180,o=Math.cos(i),n=Math.sin(i),s=e.x-A.x,r=e.y-A.y,a=s*o-r*n,g=s*n+r*o;return{x:a+A.x,y:g+A.y}},Igt=(e,A,t,i)=>{const o={top_left:{x:e.x-A,y:e.y-t},top_center:{x:e.x,y:e.y-t},top_right:{x:e.x+A,y:e.y-t},center_left:{x:e.x-A,y:e.y},center:{x:e.x,y:e.y},center_right:{x:e.x+A,y:e.y},bottom_left:{x:e.x-A,y:e.y+t},bottom_center:{x:e.x,y:e.y+t},bottom_right:{x:e.x+A,y:e.y+t}};return i===0?Object.entries(o).map(([n,s])=>({anchor:n,point:s})):Object.entries(o).map(([n,s])=>({anchor:n,point:MOe(s,e,i)}))},NOe=e=>{switch(e.pcb_drawing_type){case"rect":{const A=e.ccw_rotation??0;return Igt({x:e.x,y:e.y},e.w/2,e.h/2,A)}case"pill":{const A=e.ccw_rotation??0;return Igt({x:e.x,y:e.y},e.w/2,e.h/2,A)}case"circle":return[{anchor:"circle_center",point:{x:e.x,y:e.y}},{anchor:"circle_right",point:{x:e.x+e.r,y:e.y}},{anchor:"circle_left",point:{x:e.x-e.r,y:e.y}},{anchor:"circle_top",point:{x:e.x,y:e.y-e.r}},{anchor:"circle_bottom",point:{x:e.x,y:e.y+e.r}}];case"oval":return[{anchor:"oval_center",point:{x:e.x,y:e.y}},{anchor:"oval_right",point:{x:e.x+e.rX,y:e.y}},{anchor:"oval_left",point:{x:e.x-e.rX,y:e.y}},{anchor:"oval_top",point:{x:e.x,y:e.y-e.rY}},{anchor:"oval_bottom",point:{x:e.x,y:e.y+e.rY}}];case"line":{const A={x:(e.x1+e.x2)/2,y:(e.y1+e.y2)/2};return[{anchor:"line_start",point:{x:e.x1,y:e.y1}},{anchor:"line_mid",point:A},{anchor:"line_end",point:{x:e.x2,y:e.y2}}]}case"polygon":return e.points.map((A,t)=>({anchor:`polygon_vertex_${t}`,point:A}));case"polygon_with_arcs":return e.brep_shape.outer_ring.vertices.map((A,t)=>({anchor:`polygon_with_arcs_vertex_${t}`,point:{x:A.x,y:A.y}}));default:return[]}},vOe=16,lF=5,cgt=e=>{if(e.pcb_drawing_type==="text")return!0;const A=e._element;if(!A||typeof A!="object")return!1;const t=typeof A.type=="string"?A.type:void 0;return t?!!(t.startsWith("pcb_silkscreen_")||t.startsWith("pcb_note_")||t==="pcb_text"||t.startsWith("pcb_fabrication_note_")&&t!=="pcb_fabrication_note_rect"):!1},LOe=({children:e,transform:A,focusOnHover:t=!1,primitives:i=[]})=>{A||(A=Bb());const[o,n]=AA.useState(!1),[s,r]=AA.useState(!1),[a,g]=AA.useState(!1),[I,c]=AA.useState({start:null,end:null}),B=zl(H=>H.is_mouse_over_container),l=AA.useCallback(()=>{a&&(g(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[a]),[C,E]=AA.useState({x:0,y:0}),[Q,h]=AA.useState({x:0,y:0}),u=AA.useRef({x:0,y:0}),d=AA.useRef(null),m=d.current?.getBoundingClientRect(),D=AA.useMemo(()=>{const H=new Map;for(const O of i){if(!O._element||cgt(O)||O.pcb_drawing_type==="pill"||O.pcb_drawing_type==="rect"&&O.ccw_rotation&&O.ccw_rotation!==0)continue;const W=GOe(O);if(!W)continue;const $=H.get(O._element);H.set(O._element,kOe($??void 0,W))}return H},[i]),w=AA.useMemo(()=>{const H=[];for(const O of i){if(!O._element||cgt(O))continue;const W=NOe(O);if(W.length!==0)for(const $ of W)H.push({anchor:$.anchor,point:$.point,element:O._element})}return H},[i]),b=AA.useMemo(()=>{const H=[];D.forEach((O,W)=>{if(!O)return;const $=(O.minX+O.maxX)/2,iA=(O.minY+O.maxY)/2,rA={top_left:{x:O.minX,y:O.minY},top_center:{x:$,y:O.minY},top_right:{x:O.maxX,y:O.minY},center_left:{x:O.minX,y:iA},center:{x:$,y:iA},center_right:{x:O.maxX,y:iA},bottom_left:{x:O.minX,y:O.maxY},bottom_center:{x:$,y:O.maxY},bottom_right:{x:O.maxX,y:O.maxY}};for(const[tA,nA]of Object.entries(rA))H.push({anchor:tA,point:nA,element:W})});for(const O of w)H.push(O);return H.push({anchor:"origin",point:{x:0,y:0},element:null}),H},[D,w]),k=AA.useMemo(()=>b.map((H,O)=>({...H,id:`${O}-${H.anchor}`,screenPoint:qi(A,H.point)})),[b,A]),x=AA.useCallback(H=>{if(k.length===0)return{point:H,id:null};const O=qi(A,H);let W=null;for(const $ of k){const iA=$.screenPoint.x-O.x,rA=$.screenPoint.y-O.y,tA=Math.hypot(iA,rA);tA>vOe||(!W||tA<W.distance)&&(W={distance:tA,id:$.id,point:$.point})}return W?{point:W.point,id:W.id}:{point:H,id:null}},[k,A]);AA.useEffect(()=>{const H=W=>{const $=W.target;if($.tagName==="INPUT"||$.tagName==="TEXTAREA"||$.isContentEditable)return;const iA=d.current?.contains(document.activeElement)||document.activeElement===d.current;if(!(!B&&!iA)){if(W.key==="d"){const rA=x({x:u.current.x,y:u.current.y});E({x:rA.point.x,y:rA.point.y}),h({x:rA.point.x,y:rA.point.y}),c({start:rA.id,end:rA.id}),o?(n(!1),r(!1),c({start:null,end:null})):(n(!0),r(!0)),l()}W.key==="Escape"&&(n(!1),r(!1),c({start:null,end:null}),l())}},O=()=>{g(!0)};return window.addEventListener("keydown",H),window.addEventListener("arm-dimension-tool",O),()=>{window.removeEventListener("keydown",H),window.removeEventListener("arm-dimension-tool",O),l()}},[B,o,l,x]);const N=qi(A,C),M=qi(A,Q),U={left:Math.min(N.x,M.x),right:Math.max(N.x,M.x),top:Math.min(N.y,M.y),bottom:Math.max(N.y,M.y),flipX:N.x>M.x,flipY:N.y>M.y,width:0,height:0};U.width=U.right-U.left,U.height=U.bottom-U.top;const J=ROe({dimensionStart:C,dimensionEnd:Q,screenDimensionStart:N,screenDimensionEnd:M,flipX:U.flipX,flipY:U.flipY});return Z.jsxs("div",{ref:d,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseEnter:()=>{t&&d.current&&d.current.focus()},onMouseLeave:()=>{d.current&&d.current.blur()},onClick:()=>{d.current&&d.current.focus()},onMouseMove:H=>{const O=H.currentTarget.getBoundingClientRect(),W=H.clientX-O.left,$=H.clientY-O.top,iA=qi(lb(A),{x:W,y:$});if(u.current.x=iA.x,u.current.y=iA.y,s){const rA=x(iA);h({x:rA.point.x,y:rA.point.y}),c(tA=>({...tA,end:rA.id}))}},onMouseDown:H=>{const O=H.currentTarget.getBoundingClientRect(),W=H.clientX-O.left,$=H.clientY-O.top,iA=qi(lb(A),{x:W,y:$});if(a&&!o){const rA=x(iA);E({x:rA.point.x,y:rA.point.y}),h({x:rA.point.x,y:rA.point.y}),c({start:rA.id,end:rA.id}),n(!0),r(!0),l()}else s?(r(!1),c(rA=>({...rA,end:null}))):o&&(n(!1),c({start:null,end:null}))},children:[e,o&&Z.jsxs(Z.Fragment,{children:[J.show&&Z.jsx("div",{style:{position:"absolute",left:J.x,top:J.y,color:"red",mixBlendMode:"difference",pointerEvents:"none",fontSize:12,fontFamily:"sans-serif",whiteSpace:"nowrap",zIndex:EI.dimensionOverlay},children:J.distance.toFixed(2)}),Z.jsx("div",{style:{position:"absolute",left:U.left,width:U.width,textAlign:"center",top:N.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:U.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:EI.dimensionOverlay},children:Math.abs(C.x-Q.x).toFixed(2)}),Z.jsx("div",{style:{position:"absolute",left:M.x,height:U.height,display:"flex",flexDirection:"column",justifyContent:"center",top:U.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:EI.dimensionOverlay},children:Z.jsx("div",{style:{marginLeft:U.flipX?"-100%":4,paddingRight:4},children:Math.abs(C.y-Q.y).toFixed(2)})}),Z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:EI.dimensionOverlay},width:m.width,height:m.height,children:[Z.jsx("defs",{children:Z.jsx("marker",{id:"head",orient:"auto",markerWidth:"3",markerHeight:"4",refX:"2",refY:"2",children:Z.jsx("path",{d:"M0,0 V4 L2,2 Z",fill:"red"})})}),Z.jsx("line",{x1:N.x,y1:N.y,x2:M.x,y2:M.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),Z.jsx("line",{x1:N.x,y1:N.y,x2:M.x,y2:N.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),Z.jsx("line",{x1:M.x,y1:N.y,x2:M.x,y2:M.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"})]}),s&&k.map(H=>{const O=H.id===I.start||H.id===I.end,W=lF/2;return Z.jsxs("svg",{width:lF,height:lF,style:{position:"absolute",left:H.screenPoint.x-W,top:H.screenPoint.y-W,pointerEvents:"none",zIndex:EI.dimensionOverlay},children:[Z.jsx("line",{x1:0,y1:0,x2:lF,y2:lF,stroke:O?"#66ccff":"white",strokeWidth:1}),Z.jsx("line",{x1:lF,y1:0,x2:0,y2:lF,stroke:O?"#66ccff":"white",strokeWidth:1})]},H.id)}),Z.jsxs("div",{style:{right:0,bottom:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4},children:["(",C.x.toFixed(2),",",C.y.toFixed(2),")",Z.jsx("br",{}),"(",Q.x.toFixed(2),",",Q.y.toFixed(2),")",Z.jsx("br",{}),"dist:"," ",Math.sqrt((Q.x-C.x)**2+(Q.y-C.y)**2).toFixed(2)]})]})]})},UOe=(e,A,t=0)=>{const i=e.width/2,o=e.height/2,n=e.center.x-i-t,s=e.center.x+i+t,r=e.center.y-o-t,a=e.center.y+o+t;return A.x>n&&A.x<s&&A.y>r&&A.y<a},HOe=({children:e,disabled:A,transform:t,soup:i,cancelPanDrag:o,onCreateEditEvent:n,onModifyEditEvent:s})=>{t||(t=Bb());const r=AA.useRef(null),[a,g]=AA.useState(null),[I,c]=AA.useState(null),B=a!==null;zl(Q=>Q.in_edit_mode);const l=zl(Q=>Q.in_move_footprint_mode),C=zl(Q=>Q.setIsMovingComponent),E=A||!l;return Z.jsxs("div",{ref:r,style:{position:"relative",overflow:"hidden"},onMouseDown:Q=>{if(E)return;const h=Q.currentTarget.getBoundingClientRect(),u=Q.clientX-h.left,d=Q.clientY-h.top;if(Number.isNaN(u)||Number.isNaN(d))return;const f=qi(lb(t),{x:u,y:d});let m=!1;for(const D of i)if(D.type==="pcb_component"&&UOe(D,f,10/t.a)){o(),g(D.pcb_component_id),m=!0;const w=Math.random().toString();c({dragStart:f,originalCenter:D.center,dragEnd:f,edit_event_id:w}),n({edit_event_id:w,edit_event_type:"edit_pcb_component_location",pcb_edit_event_type:"edit_component_location",pcb_component_id:D.pcb_component_id,original_center:D.center,new_center:D.center,in_progress:!0,created_at:Date.now()}),C(!0);break}if(m||g(null),m)return Q.preventDefault(),!1},onMouseMove:Q=>{if(!a||!I)return;const h=Q.currentTarget.getBoundingClientRect(),u=Q.clientX-h.left,d=Q.clientY-h.top;if(Number.isNaN(u)||Number.isNaN(d))return;const f=qi(lb(t),{x:u,y:d});c({...I,dragEnd:f}),s({edit_event_id:I.edit_event_id,new_center:{x:I.originalCenter.x+f.x-I.dragStart.x,y:I.originalCenter.y+f.y-I.dragStart.y}})},onMouseUp:Q=>{a&&(g(null),C(!1),I&&(s({edit_event_id:I.edit_event_id,in_progress:!1}),c(null)))},children:[e,!E&&i.filter(Q=>Q.type==="pcb_component").map(Q=>{if(!Q?.center)return null;const h=qi(t,Q.center);return Z.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:h.x,top:h.y,width:Q.width*t.a+20,height:Q.height*t.a+20,transform:"translate(-50%, -50%)",background:B&&a===Q.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},Q.pcb_component_id)})]})},YOe=({hotkeys:e})=>(AA.useEffect(()=>{const A=t=>{e.forEach(i=>{t.key===i.key&&i.onUse()})};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A)}},[e]),Z.jsx("div",{className:Uv`
5429
+ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function Yat(e,A,t){if(!A||!t)return;let i=e.get(A);i||(i=new Set,e.set(A,i)),i.add(t);let o=e.get(t);o||(o=new Set,e.set(t,o)),o.add(A)}function i3e(e,A){if(!A.subcircuit_id&&!A.source_group_id)return[...e];const t=new Map;for(const s of e){const r=s[`${s.type}_id`];typeof r=="string"&&t.set(r,s)}const i=new Map;for(const s of e){const r=Object.entries(s);for(const[a,g]of r)if(a!=="parent_source_group_id"){if(a.endsWith("_id")&&typeof g=="string"){const I=t.get(g);Yat(i,s,I)}else if(a.endsWith("_ids")&&Array.isArray(g)){for(const I of g)if(typeof I=="string"){const c=t.get(I);Yat(i,s,c)}}}}const o=[],n=new Set;for(const s of e)(A.subcircuit_id&&s.subcircuit_id===A.subcircuit_id||A.source_group_id&&(s.source_group_id===A.source_group_id||Array.isArray(s.member_source_group_ids)&&s.member_source_group_ids.includes(A.source_group_id)))&&(o.push(s),n.add(s));for(;o.length>0;){const s=o.shift(),r=i.get(s);if(r)for(const a of r)n.has(a)||(n.add(a),o.push(a))}return e.filter(s=>n.has(s))}var WV=(e,A={})=>{const t=e;let i=t._internal_store;if(!i){i={counts:{},editCount:0},t._internal_store=i;for(const n of t){const s=n.type,r=n[`${s}_id`];if(!r)continue;const a=Number.parseInt(r.split("_").pop());Number.isNaN(a)||(i.counts[s]=Math.max(i.counts[s]??0,a))}}return new Proxy({},{get:(n,s)=>{if(s==="toArray")return()=>(t.editCount=i.editCount,t);if(s==="editCount")return i.editCount;if(s==="subtree")return a=>WV(i3e(t,a),A);const r=s;return{get:a=>t.find(g=>g.type===r&&g[`${r}_id`]===a),getUsing:a=>{const g=Object.keys(a);if(g.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const I=g[0],c=I.replace("_id",""),B=t.find(l=>l.type===c&&l[I]===a[I]);return B?t.find(l=>l.type===r&&l[`${r}_id`]===B[`${r}_id`]):null},getWhere:a=>{const g=Object.keys(a);return t.find(I=>I.type===r&&g.every(c=>I[c]===a[c]))},list:a=>{const g=a?Object.keys(a):[];return t.filter(I=>I.type===r&&g.every(c=>I[c]===a[c]))},insert:a=>{i.counts[r]??=-1,i.counts[r]++;const g=i.counts[r],I={type:r,[`${r}_id`]:`${r}_${g}`,...a};return A.validateInserts&&(Grt[r]??YdA).parse(I),t.push(I),i.editCount++,I},delete:a=>{const g=t.find(I=>I[`${r}_id`]===a);g&&(t.splice(t.indexOf(g),1),i.editCount++)},update:(a,g)=>{const I=t.find(c=>c.type===r&&c[`${r}_id`]===a);return I?(Object.assign(I,g),i.editCount++,I):null},select:a=>{if(r==="source_component")return t.find(g=>g.type==="source_component"&&g.name===a.replace(/\./g,""));if(r==="pcb_port"||r==="source_port"||r==="schematic_port"){const[g,I]=a.replace(/\./g,"").split(/[\s\>]+/),c=t.find(l=>l.type==="source_component"&&l.name===g);if(!c)return null;const B=t.find(l=>l.type==="source_port"&&l.source_component_id===c.source_component_id&&(l.name===I||(l.port_hints??[]).includes(I)));if(!B)return null;if(r==="source_port")return B;if(r==="pcb_port")return t.find(l=>l.type==="pcb_port"&&l.source_port_id===B.source_port_id);if(r==="schematic_port")return t.find(l=>l.type==="schematic_port"&&l.source_port_id===B.source_port_id)}}}}})};WV.unparsed=WV;var Qb=WV;function mpA(e){const A=e.type;return`${A}:${e[`${A}_id`]}`}var Jat=(e,A={})=>{let t=e._internal_store_indexed;if(!t){t={counts:{},editCount:0,indexes:{}};for(const s of e){const r=s.type,a=s[`${r}_id`];if(!a)continue;const g=Number.parseInt(a.split("_").pop()||"");Number.isNaN(g)||(t.counts[r]=Math.max(t.counts[r]??0,g))}const o=A.indexConfig||{},n=t.indexes;if(o.byId&&(n.byId=new Map),o.byType&&(n.byType=new Map),o.byRelation&&(n.byRelation=new Map),o.bySubcircuit&&(n.bySubcircuit=new Map),o.byCustomField&&o.byCustomField.length>0){n.byCustomField=new Map;for(const s of o.byCustomField)n.byCustomField.set(s,new Map)}for(const s of e){if(o.byId){const r=mpA(s);n.byId.set(r,s)}if(o.byType){const r=n.byType.get(s.type)||[];r.push(s),n.byType.set(s.type,r)}if(o.byRelation){const r=Object.entries(s);for(const[a,g]of r)if(a.endsWith("_id")&&a!==`${s.type}_id`&&typeof g=="string"){const I=n.byRelation.get(a)||new Map,c=I.get(g)||[];c.push(s),I.set(g,c),n.byRelation.set(a,I)}}if(o.bySubcircuit&&"subcircuit_id"in s){const r=s.subcircuit_id;if(r&&typeof r=="string"){const a=n.bySubcircuit.get(r)||[];a.push(s),n.bySubcircuit.set(r,a)}}if(o.byCustomField&&n.byCustomField){for(const r of o.byCustomField)if(r in s){const a=s[r];if(a!==void 0&&(typeof a=="string"||typeof a=="number")){const g=String(a),I=n.byCustomField.get(r),c=I.get(g)||[];c.push(s),I.set(g,c)}}}}e._internal_store_indexed=t}return new Proxy({},{get:(o,n)=>{if(n==="toArray")return()=>(e.editCount=t.editCount,e);if(n==="editCount")return t.editCount;const s=n;return{get:r=>{const a=A.indexConfig||{};return a.byId&&t.indexes.byId?t.indexes.byId.get(`${s}:${r}`)||null:a.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(I=>I[`${s}_id`]===r)||null:e.find(g=>g.type===s&&g[`${s}_id`]===r)||null},getUsing:r=>{const a=A.indexConfig||{},g=Object.keys(r);if(g.length!==1)throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");const I=g[0],c=I.replace("_id","");if(a.byRelation&&t.indexes.byRelation){const l=t.indexes.byRelation.get(I);if(l){const E=(l.get(r[I])||[]).find(h=>h.type===c);if(!E)return null;const Q=E[`${s}_id`];return a.byId&&t.indexes.byId?t.indexes.byId.get(`${s}:${Q}`)||null:a.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===Q)||null:e.find(h=>h.type===s&&h[`${s}_id`]===Q)||null}}const B=e.find(l=>l.type===c&&l[I]===r[I]);return B&&e.find(l=>l.type===s&&l[`${s}_id`]===B[`${s}_id`])||null},getWhere:r=>{const a=A.indexConfig||{},g=Object.keys(r);if(g.length===1&&a.byCustomField&&t.indexes.byCustomField){const I=g[0],c=t.indexes.byCustomField.get(I);if(c){const B=String(r[I]);return(c.get(B)||[]).find(C=>C.type===s)||null}}if("subcircuit_id"in r&&a.bySubcircuit&&t.indexes.bySubcircuit){const I=r.subcircuit_id;return(t.indexes.bySubcircuit.get(I)||[]).find(B=>B.type===s&&g.every(l=>B[l]===r[l]))||null}return a.byType&&t.indexes.byType?(t.indexes.byType.get(s)||[]).find(c=>g.every(B=>c[B]===r[B]))||null:e.find(I=>I.type===s&&g.every(c=>I[c]===r[c]))||null},list:r=>{const a=A.indexConfig||{},g=r?Object.keys(r):[];if(g.length===0&&a.byType&&t.indexes.byType)return t.indexes.byType.get(s)||[];if(g.length===1&&g[0]==="subcircuit_id"&&a.bySubcircuit&&t.indexes.bySubcircuit){const c=r.subcircuit_id;return(t.indexes.bySubcircuit.get(c)||[]).filter(l=>l.type===s)}let I;return a.byType&&t.indexes.byType?I=t.indexes.byType.get(s)||[]:I=e.filter(c=>c.type===s),g.length>0?I.filter(c=>g.every(B=>c[B]===r[B])):I},insert:r=>{t.counts[s]??=-1,t.counts[s]++;const a=t.counts[s],g={type:s,[`${s}_id`]:`${s}_${a}`,...r};A.validateInserts&&(Grt[s]??YdA).parse(g),e.push(g),t.editCount++;const I=A.indexConfig||{};if(I.byId&&t.indexes.byId){const c=mpA(g);t.indexes.byId.set(c,g)}if(I.byType&&t.indexes.byType){const c=t.indexes.byType.get(s)||[];c.push(g),t.indexes.byType.set(s,c)}if(I.byRelation&&t.indexes.byRelation){const c=Object.entries(g);for(const[B,l]of c)if(B.endsWith("_id")&&B!==`${g.type}_id`&&typeof l=="string"){const C=t.indexes.byRelation.get(B)||new Map,E=C.get(l)||[];E.push(g),C.set(l,E),t.indexes.byRelation.set(B,C)}}if(I.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in g){const c=g.subcircuit_id;if(c&&typeof c=="string"){const B=t.indexes.bySubcircuit.get(c)||[];B.push(g),t.indexes.bySubcircuit.set(c,B)}}if(I.byCustomField&&t.indexes.byCustomField){for(const c of I.byCustomField)if(c in g){const B=g[c];if(B!==void 0&&(typeof B=="string"||typeof B=="number")){const l=String(B),C=t.indexes.byCustomField.get(c),E=C.get(l)||[];E.push(g),C.set(l,E)}}}return g},delete:r=>{const a=A.indexConfig||{};let g;if(a.byId&&t.indexes.byId?g=t.indexes.byId.get(`${s}:${r}`):a.byType&&t.indexes.byType?g=(t.indexes.byType.get(s)||[]).find(B=>B[`${s}_id`]===r):g=e.find(c=>c[`${s}_id`]===r),!g)return;const I=e.indexOf(g);if(I>=0&&(e.splice(I,1),t.editCount++),a.byId&&t.indexes.byId){const c=mpA(g);t.indexes.byId.delete(c)}if(a.byType&&t.indexes.byType){const B=(t.indexes.byType.get(s)||[]).filter(l=>l[`${s}_id`]!==r);t.indexes.byType.set(s,B)}if(a.byRelation&&t.indexes.byRelation)for(const[c,B]of t.indexes.byRelation.entries())for(const[l,C]of B.entries()){const E=C.filter(Q=>Q!==g);E.length===0?B.delete(l):B.set(l,E)}if(a.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in g){const c=g.subcircuit_id;if(c){const l=(t.indexes.bySubcircuit.get(c)||[]).filter(C=>C!==g);l.length===0?t.indexes.bySubcircuit.delete(c):t.indexes.bySubcircuit.set(c,l)}}if(a.byCustomField&&t.indexes.byCustomField)for(const c of t.indexes.byCustomField.values())for(const[B,l]of c.entries()){const C=l.filter(E=>E!==g);C.length===0?c.delete(B):c.set(B,C)}},update:(r,a)=>{const g=A.indexConfig||{};let I;if(g.byId&&t.indexes.byId?I=t.indexes.byId.get(`${s}:${r}`):g.byType&&t.indexes.byType?I=(t.indexes.byType.get(s)||[]).find(B=>B[`${s}_id`]===r):I=e.find(c=>c.type===s&&c[`${s}_id`]===r),!I)return null;if(g.byRelation&&t.indexes.byRelation){const c=Object.entries(I);for(const[B,l]of c)if(B.endsWith("_id")&&B!==`${I.type}_id`&&typeof l=="string"&&B in a&&a[B]!==l){const C=t.indexes.byRelation.get(B);if(C){const Q=(C.get(l)||[]).filter(h=>h!==I);Q.length===0?C.delete(l):C.set(l,Q)}}}if(g.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in I&&"subcircuit_id"in a){const c=I.subcircuit_id,B=a.subcircuit_id;if(c!==B){const C=(t.indexes.bySubcircuit.get(c)||[]).filter(E=>E!==I);C.length===0?t.indexes.bySubcircuit.delete(c):t.indexes.bySubcircuit.set(c,C)}}if(g.byCustomField&&t.indexes.byCustomField){for(const c of g.byCustomField)if(c in I&&c in a&&I[c]!==a[c]){const B=t.indexes.byCustomField.get(c);if(B){const l=String(I[c]),E=(B.get(l)||[]).filter(Q=>Q!==I);E.length===0?B.delete(l):B.set(l,E)}}}if(Object.assign(I,a),t.editCount++,g.byRelation&&t.indexes.byRelation){const c=Object.entries(I);for(const[B,l]of c)if(B.endsWith("_id")&&B!==`${I.type}_id`&&typeof l=="string"&&B in a){const C=t.indexes.byRelation.get(B)||new Map,E=C.get(l)||[];E.includes(I)||(E.push(I),C.set(l,E),t.indexes.byRelation.set(B,C))}}if(g.bySubcircuit&&t.indexes.bySubcircuit&&"subcircuit_id"in I&&"subcircuit_id"in a){const c=I.subcircuit_id;if(c&&typeof c=="string"){const B=t.indexes.bySubcircuit.get(c)||[];B.includes(I)||(B.push(I),t.indexes.bySubcircuit.set(c,B))}}if(g.byCustomField&&t.indexes.byCustomField){for(const c of g.byCustomField)if(c in I&&c in a){const B=I[c];if(B!==void 0&&(typeof B=="string"||typeof B=="number")){const l=String(B),C=t.indexes.byCustomField.get(c),E=C.get(l)||[];E.includes(I)||(E.push(I),C.set(l,E))}}}return I},select:r=>{if(s==="source_component")return e.find(a=>a.type==="source_component"&&a.name===r.replace(/\./g,""))||null;if(s==="pcb_port"||s==="source_port"||s==="schematic_port"){const[a,g]=r.replace(/\./g,"").split(/[\s\>]+/),I=e.find(B=>B.type==="source_component"&&B.name===a);if(!I)return null;const c=e.find(B=>B.type==="source_port"&&B.source_component_id===I.source_component_id&&(B.name===g||(B.port_hints??[]).includes(g)));if(!c)return null;if(s==="source_port")return c;if(s==="pcb_port")return e.find(B=>B.type==="pcb_port"&&B.source_port_id===c.source_port_id)||null;if(s==="schematic_port")return e.find(B=>B.type==="schematic_port"&&B.source_port_id===c.source_port_id)||null}return null}}}})};Jat.unparsed=Jat;var o3e=e=>{const A=e.type;return e[`${A}_id`]},wpA=e=>{let A=Number.POSITIVE_INFINITY,t=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,o=Number.NEGATIVE_INFINITY;for(const n of e){if(!n.type.startsWith("pcb_"))continue;if(n.type==="pcb_smtpad"&&n.shape==="polygon"&&Array.isArray(n.points)){for(const I of n.points)A=Math.min(A,I.x),t=Math.min(t,I.y),i=Math.max(i,I.x),o=Math.max(o,I.y);continue}let s,r,a,g;if("x"in n&&"y"in n&&(s=Number(n.x),r=Number(n.y)),"outer_diameter"in n&&(a=Number(n.outer_diameter),g=Number(n.outer_diameter)),"width"in n&&(a=Number(n.width)),"height"in n&&(g=Number(n.height)),"center"in n&&(s=n.center.x,r=n.center.y),s!==void 0&&r!==void 0)A=Math.min(A,s),t=Math.min(t,r),i=Math.max(i,s),o=Math.max(o,r),a!==void 0&&g!==void 0&&(A=Math.min(A,s-a/2),t=Math.min(t,r-g/2),i=Math.max(i,s+a/2),o=Math.max(o,r+g/2)),"radius"in n&&(A=Math.min(A,s-n.radius),t=Math.min(t,r-n.radius),i=Math.max(i,s+n.radius),o=Math.max(o,r+n.radius));else if(n.type==="pcb_trace")for(const I of n.route)A=Math.min(A,I.x),t=Math.min(t,I.y),i=Math.max(i,I.x),o=Math.max(o,I.y)}return{minX:A,minY:t,maxX:i,maxY:o}};function n3e(e){let A=0;if(e.length==0)return A;for(var t=0;t<e.length;t++){var i=e.charCodeAt(t);A=(A<<5)-A+i,A=A&A}return Math.abs(A)}var Tat=[["#69d2e7","#a7dbd8","#e0e4cc","#f38630","#fa6900"],["#fe4365","#fc9d9a","#f9cdad","#c8c8a9","#83af9b"],["#ecd078","#d95b43","#c02942","#542437","#53777a"],["#556270","#4ecdc4","#c7f464","#ff6b6b","#c44d58"],["#774f38","#e08e79","#f1d4af","#ece5ce","#c5e0dc"],["#e8ddcb","#cdb380","#036564","#033649","#031634"],["#490a3d","#bd1550","#e97f02","#f8ca00","#8a9b0f"],["#594f4f","#547980","#45ada8","#9de0ad","#e5fcc2"],["#00a0b0","#6a4a3c","#cc333f","#eb6841","#edc951"],["#e94e77","#d68189","#c6a49a","#c6e5d9","#f4ead5"],["#3fb8af","#7fc7af","#dad8a7","#ff9e9d","#ff3d7f"],["#d9ceb2","#948c75","#d5ded9","#7a6a53","#99b2b7"],["#ffffff","#cbe86b","#f2e9e1","#1c140d","#cbe86b"],["#efffcd","#dce9be","#555152","#2e2633","#99173c"],["#343838","#005f6b","#008c9e","#00b4cc","#00dffc"],["#413e4a","#73626e","#b38184","#f0b49e","#f7e4be"],["#ff4e50","#fc913a","#f9d423","#ede574","#e1f5c4"],["#99b898","#fecea8","#ff847c","#e84a5f","#2a363b"],["#655643","#80bca3","#f6f7bd","#e6ac27","#bf4d28"],["#00a8c6","#40c0cb","#f9f2e7","#aee239","#8fbe00"],["#351330","#424254","#64908a","#e8caa4","#cc2a41"],["#554236","#f77825","#d3ce3d","#f1efa5","#60b99a"],["#5d4157","#838689","#a8caba","#cad7b2","#ebe3aa"],["#8c2318","#5e8c6a","#88a65e","#bfb35a","#f2c45a"],["#fad089","#ff9c5b","#f5634a","#ed303c","#3b8183"],["#ff4242","#f4fad2","#d4ee5e","#e1edb9","#f0f2eb"],["#f8b195","#f67280","#c06c84","#6c5b7b","#355c7d"],["#d1e751","#ffffff","#000000","#4dbce9","#26ade4"],["#1b676b","#519548","#88c425","#bef202","#eafde6"],["#5e412f","#fcebb6","#78c0a8","#f07818","#f0a830"],["#bcbdac","#cfbe27","#f27435","#f02475","#3b2d38"],["#452632","#91204d","#e4844a","#e8bf56","#e2f7ce"],["#eee6ab","#c5bc8e","#696758","#45484b","#36393b"],["#f0d8a8","#3d1c00","#86b8b1","#f2d694","#fa2a00"],["#2a044a","#0b2e59","#0d6759","#7ab317","#a0c55f"],["#f04155","#ff823a","#f2f26f","#fff7bd","#95cfb7"],["#b9d7d9","#668284","#2a2829","#493736","#7b3b3b"],["#bbbb88","#ccc68d","#eedd99","#eec290","#eeaa88"],["#b3cc57","#ecf081","#ffbe40","#ef746f","#ab3e5b"],["#a3a948","#edb92e","#f85931","#ce1836","#009989"],["#300030","#480048","#601848","#c04848","#f07241"],["#67917a","#170409","#b8af03","#ccbf82","#e33258"],["#aab3ab","#c4cbb7","#ebefc9","#eee0b7","#e8caaf"],["#e8d5b7","#0e2430","#fc3a51","#f5b349","#e8d5b9"],["#ab526b","#bca297","#c5ceae","#f0e2a4","#f4ebc3"],["#607848","#789048","#c0d860","#f0f0d8","#604848"],["#b6d8c0","#c8d9bf","#dadabd","#ecdbbc","#fedcba"],["#a8e6ce","#dcedc2","#ffd3b5","#ffaaa6","#ff8c94"],["#3e4147","#fffedf","#dfba69","#5a2e2e","#2a2c31"],["#fc354c","#29221f","#13747d","#0abfbc","#fcf7c5"],["#cc0c39","#e6781e","#c8cf02","#f8fcc1","#1693a7"],["#1c2130","#028f76","#b3e099","#ffeaad","#d14334"],["#a7c5bd","#e5ddcb","#eb7b59","#cf4647","#524656"],["#dad6ca","#1bb0ce","#4f8699","#6a5e72","#563444"],["#5c323e","#a82743","#e15e32","#c0d23e","#e5f04c"],["#edebe6","#d6e1c7","#94c7b6","#403b33","#d3643b"],["#fdf1cc","#c6d6b8","#987f69","#e3ad40","#fcd036"],["#230f2b","#f21d41","#ebebbc","#bce3c5","#82b3ae"],["#b9d3b0","#81bda4","#b28774","#f88f79","#f6aa93"],["#3a111c","#574951","#83988e","#bcdea5","#e6f9bc"],["#5e3929","#cd8c52","#b7d1a3","#dee8be","#fcf7d3"],["#1c0113","#6b0103","#a30006","#c21a01","#f03c02"],["#000000","#9f111b","#b11623","#292c37","#cccccc"],["#382f32","#ffeaf2","#fcd9e5","#fbc5d8","#f1396d"],["#e3dfba","#c8d6bf","#93ccc6","#6cbdb5","#1a1f1e"],["#f6f6f6","#e8e8e8","#333333","#990100","#b90504"],["#1b325f","#9cc4e4","#e9f2f9","#3a89c9","#f26c4f"],["#a1dbb2","#fee5ad","#faca66","#f7a541","#f45d4c"],["#c1b398","#605951","#fbeec2","#61a6ab","#accec0"],["#5e9fa3","#dcd1b4","#fab87f","#f87e7b","#b05574"],["#951f2b","#f5f4d7","#e0dfb1","#a5a36c","#535233"],["#8dccad","#988864","#fea6a2","#f9d6ac","#ffe9af"],["#2d2d29","#215a6d","#3ca2a2","#92c7a3","#dfece6"],["#413d3d","#040004","#c8ff00","#fa023c","#4b000f"],["#eff3cd","#b2d5ba","#61ada0","#248f8d","#605063"],["#ffefd3","#fffee4","#d0ecea","#9fd6d2","#8b7a5e"],["#cfffdd","#b4dec1","#5c5863","#a85163","#ff1f4c"],["#9dc9ac","#fffec7","#f56218","#ff9d2e","#919167"],["#4e395d","#827085","#8ebe94","#ccfc8e","#dc5b3e"],["#a8a7a7","#cc527a","#e8175d","#474747","#363636"],["#f8edd1","#d88a8a","#474843","#9d9d93","#c5cfc6"],["#046d8b","#309292","#2fb8ac","#93a42a","#ecbe13"],["#f38a8a","#55443d","#a0cab5","#cde9ca","#f1edd0"],["#a70267","#f10c49","#fb6b41","#f6d86b","#339194"],["#ff003c","#ff8a00","#fabe28","#88c100","#00c176"],["#ffedbf","#f7803c","#f54828","#2e0d23","#f8e4c1"],["#4e4d4a","#353432","#94ba65","#2790b0","#2b4e72"],["#0ca5b0","#4e3f30","#fefeeb","#f8f4e4","#a5b3aa"],["#4d3b3b","#de6262","#ffb88c","#ffd0b3","#f5e0d3"],["#fffbb7","#a6f6af","#66b6ab","#5b7c8d","#4f2958"],["#edf6ee","#d1c089","#b3204d","#412e28","#151101"],["#9d7e79","#ccac95","#9a947c","#748b83","#5b756c"],["#fcfef5","#e9ffe1","#cdcfb7","#d6e6c3","#fafbe3"],["#9cddc8","#bfd8ad","#ddd9ab","#f7af63","#633d2e"],["#30261c","#403831","#36544f","#1f5f61","#0b8185"],["#aaff00","#ffaa00","#ff00aa","#aa00ff","#00aaff"],["#d1313d","#e5625c","#f9bf76","#8eb2c5","#615375"],["#ffe181","#eee9e5","#fad3b2","#ffba7f","#ff9c97"],["#73c8a9","#dee1b6","#e1b866","#bd5532","#373b44"],["#805841","#dcf7f3","#fffcdd","#ffd8d8","#f5a2a2"]],s3e=e=>{let{x:A,y:t,width:i,height:o}={...e,...e.size,...e.center,...e.position};if(e.x1!==void 0&&e.x2!==void 0&&e.y1!==void 0&&e.y2!==void 0&&(A=(e.x1+e.x2)/2,t=(e.y1+e.y2)/2,i=Math.abs(e.x1-e.x2),o=Math.abs(e.y1-e.y2)),e.points&&Array.isArray(e.points)&&e.points.length>0){const r=e.points.map(l=>l.x),a=e.points.map(l=>l.y),g=Math.min(...r),I=Math.max(...r),c=Math.min(...a),B=Math.max(...a);A=(g+I)/2,t=(c+B)/2,i=I-g,o=B-c}const n=e.text||e.name||e.source?.text||e.source?.name||"?",s=e;return A===void 0||t===void 0?null:(i===void 0&&"outer_diameter"in e&&(i=e.outer_diameter,o=e.outer_diameter),(i===void 0||o===void 0)&&(i=.1,o=.1),{x:A,y:t,width:i,height:o,title:n,content:s,bg_color:Tat[n3e(e.type||n)%Tat.length]?.[4]??"#f00"})},r3e=e=>!!e,a3e=e=>{const A=e.filter(g=>g.type.startsWith("pcb_")||g.type.startsWith("schematic_")).concat(e.filter(g=>g.type==="pcb_trace"||g.type==="schematic_trace").flatMap(g=>g.route)).map(g=>s3e(g)).filter(r3e);if(A.length===0)return{center:{x:0,y:0},width:0,height:0};let t=A[0].x-A[0].width/2,i=A[0].x+A[0].width/2,o=A[0].y-A[0].height/2,n=A[0].y+A[0].height/2;for(const g of A.slice(1))t=Math.min(t,g.x-g.width/2),i=Math.max(i,g.x+g.width/2),o=Math.min(o,g.y-g.height/2),n=Math.max(n,g.y+g.height/2);const s=i-t,r=n-o;return{center:{x:t+s/2,y:o+r/2},width:s,height:r}},DD={IS_SHOWING_PCB_GROUPS:"pcb_viewer_is_showing_pcb_groups",PCB_GROUP_VIEW_MODE:"pcb_viewer_group_view_mode",IS_SHOWING_COPPER_POURS:"pcb_viewer_is_showing_copper_pours",IS_SHOWING_GROUP_ANCHOR_OFFSETS:"pcb_viewer_is_showing_group_anchor_offsets",IS_SHOWING_SOLDER_MASK:"pcb_viewer_is_showing_solder_mask"},ZV=(e,A)=>{if(typeof window>"u")return A;try{const t=localStorage.getItem(e);return t!==null?JSON.parse(t):A}catch{return A}},VV=(e,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(e,JSON.stringify(A))}catch{}},g3e=(e,A)=>{if(typeof window>"u")return A;try{const t=localStorage.getItem(e);return t!==null?JSON.parse(t):A}catch{return A}},I3e=(e,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(e,JSON.stringify(A))}catch{}},c3e="named_only",B3e=(e={},A=!1)=>Rrt(t=>({selected_layer:"top",pcb_viewer_id:`pcb_viewer_${Math.random().toString().slice(2,10)}`,in_edit_mode:!1,in_move_footprint_mode:!1,in_draw_trace_mode:!1,is_moving_component:!1,is_drawing_trace:!1,is_mouse_over_container:!1,is_showing_multiple_traces_length:!1,is_showing_rats_nest:!1,is_showing_autorouting:!0,is_showing_drc_errors:!0,is_showing_copper_pours:ZV(DD.IS_SHOWING_COPPER_POURS,!0),is_showing_pcb_groups:A?!1:ZV(DD.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:ZV(DD.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!0),is_showing_solder_mask:ZV(DD.IS_SHOWING_SOLDER_MASK,!1),pcb_group_view_mode:A?"all":g3e(DD.PCB_GROUP_VIEW_MODE,c3e),hovered_error_id:null,...e,selectLayer:i=>t({selected_layer:i}),setEditMode:i=>t({in_edit_mode:i!=="off",in_move_footprint_mode:i==="move_footprint",in_draw_trace_mode:i==="draw_trace",is_moving_component:!1,is_drawing_trace:!1}),setIsShowingRatsNest:i=>t({is_showing_rats_nest:i}),setIsMovingComponent:i=>t({is_moving_component:i}),setIsDrawingTrace:i=>t({is_drawing_trace:i}),setIsMouseOverContainer:i=>t({is_mouse_over_container:i}),setIsShowingMultipleTracesLength:i=>t({is_showing_multiple_traces_length:i}),setIsShowingAutorouting:i=>t({is_showing_autorouting:i}),setIsShowingDrcErrors:i=>t({is_showing_drc_errors:i}),setIsShowingCopperPours:i=>{VV(DD.IS_SHOWING_COPPER_POURS,i),t({is_showing_copper_pours:i})},setIsShowingPcbGroups:i=>{A||(VV(DD.IS_SHOWING_PCB_GROUPS,i),t({is_showing_pcb_groups:i}))},setIsShowingGroupAnchorOffsets:i=>{VV(DD.IS_SHOWING_GROUP_ANCHOR_OFFSETS,i),t({is_showing_group_anchor_offsets:i})},setIsShowingSolderMask:i=>{VV(DD.IS_SHOWING_SOLDER_MASK,i),t({is_showing_solder_mask:i})},setPcbGroupViewMode:i=>{A||(I3e(DD.PCB_GROUP_VIEW_MODE,i),t({pcb_group_view_mode:i}))},setHoveredErrorId:i=>t({hovered_error_id:i})})),zl=e=>{const A=AA.useContext(Kat);return Krt(A,e)},Kat=AA.createContext(null),l3e=({children:e,initialState:A,disablePcbGroups:t})=>{const i=AA.useMemo(()=>B3e(A,t),[t]);return Z.jsx(Kat.Provider,{value:i,children:e})},C3e=()=>{const e=zl(t=>t.pcb_viewer_id),A=(t,i)=>qg(t,{containerId:e,...i});return A.error=(t,i)=>qg.error(t,{containerId:e,...i}),A.promise=qg.promise,A},Q3e=()=>{AA.useEffect(()=>{uPe()},[]);const e=zl(A=>A.pcb_viewer_id);return Z.jsx(hPe,{position:"top-center",containerId:e})},E3e=function(){},Pat=typeof window<"u",h3e=Pat?AA.useLayoutEffect:AA.useEffect,u3e=h3e,qat={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function d3e(){var e=AA.useState(null),A=e[0],t=e[1],i=AA.useState(qat),o=i[0],n=i[1],s=AA.useMemo(function(){return new window.ResizeObserver(function(r){if(r[0]){var a=r[0].contentRect,g=a.x,I=a.y,c=a.width,B=a.height,l=a.top,C=a.left,E=a.bottom,Q=a.right;n({x:g,y:I,width:c,height:B,top:l,left:C,bottom:E,right:Q})}})},[]);return u3e(function(){if(A)return s.observe(A),function(){s.disconnect()}},[A]),[t,o]}var ZY=Pat&&typeof window.ResizeObserver<"u"?d3e:function(){return[E3e,qat]},Oat=({initialTransform:e,initialTouch1:A,initialTouch2:t,finalTouch1:i,finalTouch2:o})=>{if(!i||!o)return e;const n={x:(A.x+t.x)/2,y:(A.y+t.y)/2},s={x:(i.x+o.x)/2,y:(i.y+o.y)/2},r=Math.hypot(t.x-A.x,t.y-A.y),a=Math.hypot(o.x-i.x,o.y-i.y),g=r===0?1:a/r,I=s.x-n.x,c=s.y-n.y;return Yy(nl(I,c),nl(n.x,n.y),RY(g,g),nl(-n.x,-n.y),e)},p3e=(e={})=>{const A=AA.useRef(null),[t,i]=AA.useState(0),o=e.canvasElm??A.current,[n,s]=AA.useState(e.initialTransform??Bb()),[r,a]=AA.useState(0),[g,I]=AA.useReducer(d=>d+1,0),c=AA.useCallback(d=>{e.onSetTransform&&e.onSetTransform(d),e.transform||s(d)},[e.onSetTransform,s]),B=AA.useCallback(d=>{c(d),I()},[c]),l=e.transform??n,C=AA.useCallback(()=>{i(Date.now())},[]),E=AA.useRef("none"),Q=AA.useRef(null),h=AA.useRef(null);AA.useEffect(()=>{const d=e.canvasElm??A.current;if(d&&!o){a(r+1);return}if(!d){const W=setTimeout(()=>{a(r+1)},100);return()=>clearTimeout(W)}let f=e.transform??n,m={x:0,y:0},D={x:0,y:0},w=!1;const b=W=>({x:W.pageX-d.getBoundingClientRect().left-window.scrollX,y:W.pageY-d.getBoundingClientRect().top-window.scrollY});function k(W){e.enabled!==!1&&(e.shouldDrag&&!e.shouldDrag(W)||(m=b(W),!(Date.now()-t<100)&&(w=!0,W.preventDefault())))}function x(W){if(!w||e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;D=b(W);const $=Yy(nl(D.x-m.x,D.y-m.y),f);c($),f=$,w=!1}function N(W){if(b(W),!w||e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;D=b(W);const $=Yy(nl(D.x-m.x,D.y-m.y),f);c($)}function M(W){if(e.enabled===!1||e.shouldDrag&&!e.shouldDrag(W))return;const $=b(W),iA=Yy(nl($.x,$.y),RY(1-W.deltaY/1e3,1-W.deltaY/1e3),nl(-$.x,-$.y),f);c(iA),f=iA,W.preventDefault()}function U(W){if(!w||e.shouldDrag&&!e.shouldDrag(W))return;if(d){const iA=d.getBoundingClientRect();if(W.clientX>=iA.left+10&&W.clientX<=iA.right-10&&W.clientY>=iA.top+10&&W.clientY<=iA.bottom-10)return}w=!1,D=b(W);const $=Yy(nl(D.x-m.x,D.y-m.y),f);c($),f=$}function J(W){if(W.preventDefault(),e.enabled!==!1){if(W.touches.length===1){E.current="drag";const $=W.touches[0];Q.current={initialTransform:f,initialTouch:{x:$.clientX,y:$.clientY}}}else if(W.touches.length===2){E.current="pinch";const $=W.touches[0],iA=W.touches[1];h.current={initialTransform:f,initialTouch1:{x:$.clientX,y:$.clientY},initialTouch2:{x:iA.clientX,y:iA.clientY},finalTouch1:null,finalTouch2:null}}}}function H(W){if(W.preventDefault(),e.enabled!==!1){if(E.current==="drag"&&W.touches.length===1&&Q.current){const $=W.touches[0],iA={x:$.clientX,y:$.clientY},rA=iA.x-Q.current.initialTouch.x,tA=iA.y-Q.current.initialTouch.y,nA=Yy(nl(rA,tA),Q.current.initialTransform);c(nA)}else if(E.current==="pinch"&&W.touches.length===2&&h.current){const $=W.touches[0],iA=W.touches[1];h.current.finalTouch1={x:$.clientX,y:$.clientY},h.current.finalTouch2={x:iA.clientX,y:iA.clientY};const rA=Oat(h.current);c(rA)}}}function O(W){W.preventDefault();const $=W.changedTouches[0];if(E.current==="drag"&&Q.current&&$){const iA={x:$.clientX,y:$.clientY},rA=iA.x-Q.current.initialTouch.x,tA=iA.y-Q.current.initialTouch.y,nA=Yy(nl(rA,tA),Q.current.initialTransform);c(nA),f=nA}else if(E.current==="pinch"&&h.current){const iA=Oat(h.current);c(iA),f=iA}E.current="none",Q.current=null,h.current=null}return d.addEventListener("mousedown",k),d.addEventListener("mouseup",x),window.addEventListener("mousemove",N),d.addEventListener("mouseout",U),d.addEventListener("wheel",M),d.addEventListener("touchstart",J,{passive:!1}),d.addEventListener("touchmove",H,{passive:!1}),d.addEventListener("touchend",O,{passive:!1}),d.addEventListener("touchcancel",O,{passive:!1}),()=>{d.removeEventListener("mousedown",k),d.removeEventListener("mouseup",x),window.removeEventListener("mousemove",N),d.removeEventListener("mouseout",U),d.removeEventListener("wheel",M),d.removeEventListener("touchstart",J),d.removeEventListener("touchmove",H),d.removeEventListener("touchend",O),d.removeEventListener("touchcancel",O)}},[o,r,g,t,e.enabled,e.shouldDrag]);const u=AA.useCallback(d=>qi(l,d),[l]);return{ref:A,transform:l,applyTransformToPoint:u,setTransform:B,cancelDrag:C}},f3e=p3e;function y3e(e){const A=new Map;let t=0;function i(o){for(const[,s]of A)if(s.has(o))return s;const n=new Set;return A.set(`connectivity_net${t++}`,n),n}for(const o of e){let n=null;for(const s of o){if(!n)n=i(s);else if(!n.has(s)){const r=i(s);if(r!==n){for(const a of r)n.add(a);A.delete(Array.from(A.entries()).find(([,a])=>a===r)[0])}}n.add(s)}}return Object.fromEntries(Array.from(A.entries()).map(([o,n])=>[o,Array.from(n)]))}var m3e=class{netMap;idToNetMap;constructor(e){this.netMap=e,this.idToNetMap={};for(const[A,t]of Object.entries(e))for(const i of t)this.idToNetMap[i]=A}addConnections(e){for(const A of e){const t=new Set;for(const o of A){const n=this.idToNetMap[o];n&&t.add(n)}let i;if(t.size===0)i=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[i]=[];else if(t.size===1)i=t.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{i=t.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const o of t)if(o!==i){this.netMap[i].push(...this.netMap[o]),this.netMap[o]=this.netMap[i];for(const n of this.netMap[i])this.idToNetMap[n]=i}}for(const o of A)this.netMap[i].includes(o)||this.netMap[i].push(o),this.idToNetMap[o]=i}}getIdsConnectedToNet(e){return this.netMap[e]||[]}getNetConnectedToId(e){return this.idToNetMap[e]}areIdsConnected(e,A){if(e===A)return!0;const t=this.getNetConnectedToId(e);if(!t)return!1;const i=this.getNetConnectedToId(A);return i?t===i||i===e||i===e:!1}areAllIdsConnected(e){const A=this.getNetConnectedToId(e[0]);for(const t of e){const i=this.getNetConnectedToId(t);if(i===void 0||i!==A)return!1}return!0}},Wat=e=>{const A=[];for(const i of e)if(i.type==="source_trace")A.push([i.source_trace_id,...i.connected_source_port_ids??[],...i.connected_source_net_ids??[]].filter(Boolean));else if(i.type==="pcb_port"){const{pcb_port_id:o,source_port_id:n}=i;n&&o&&A.push([n,o])}else if(i.type==="pcb_smtpad"){const{pcb_smtpad_id:o,pcb_port_id:n}=i;n&&o&&A.push([o,n])}else if(i.type==="pcb_plated_hole"){const{pcb_plated_hole_id:o,pcb_port_id:n}=i;n&&o&&A.push([o,n])}else if(i.type==="pcb_trace"){const{pcb_trace_id:o,source_trace_id:n}=i,s=Array.isArray(i.route)?i.route.filter(r=>r&&r.route_type==="wire"):[];if(n&&o&&A.push([o,n]),Array.isArray(s)){const r=s.find(g=>g?.start_pcb_port_id)?.start_pcb_port_id,a=s.find(g=>g?.end_pcb_port_id)?.end_pcb_port_id;r&&o&&a&&A.push([r,o,a])}}else if(i.type==="pcb_via"){const{pcb_via_id:o,pcb_trace_id:n}=i;n&&o&&A.push([o,n])}else if(i.type==="source_component"&&i.internally_connected_source_port_ids)for(const o of i.internally_connected_source_port_ids)A.push(o);const t=y3e(A);return new m3e(t)};function w3e({primitivesWithoutInteractionMetadata:e,drawingObjectIdsWithMouseOver:A,primitiveIdsInMousedOverNet:t}){const i=[];for(const o of e){const n={...o};o?.layer==="drill"?(n.is_in_highlighted_net=!1,n.is_mouse_over=!1):A.has(o._pcb_drawing_object_id)?n.is_mouse_over=!0:o._element&&("pcb_trace_id"in o._element&&t.includes(o._element.pcb_trace_id)||"pcb_port_id"in o._element&&t.includes(o._element.pcb_port_id))?n.is_in_highlighted_net=!0:(n.is_in_highlighted_net=!1,n.is_mouse_over=!1),i.push(n)}return i}function D3e(e,A){if(e.length<2)throw new Error("Stroke must have at least two points");const t=e.map(c=>Array.isArray(c)?{x:c[0],y:c[1]}:c),i=[],o=[];function n(c,B){const l=B.x-c.x,C=B.y-c.y,E=Math.sqrt(l*l+C*C);return{x:-C/E,y:l/E}}function s(c,B,l,C){const E=C/2,Q={x:c.x+B.x*E*l,y:c.y+B.y*E*l};l>0?i.push(Q):o.unshift(Q)}const r=n(t[0],t[1]),a=t[0].trace_width??A;s(t[0],r,1,a),s(t[0],r,-1,a);for(let c=1;c<t.length-1;c++){const B=t[c-1],l=t[c],C=t[c+1],E=n(B,l),Q=n(l,C),h=E.x+Q.x,u=E.y+Q.y,d=Math.sqrt(h*h+u*u),f=l.trace_width??A;if(d/2>2*(f/2))s(l,E,1,f),s(l,Q,1,f),s(l,E,-1,f),s(l,Q,-1,f);else{const D=1/d;s(l,{x:h*D,y:u*D},1,f),s(l,{x:h*D,y:u*D},-1,f)}}const g=n(t[t.length-2],t[t.length-1]),I=t[t.length-1].trace_width??A;return s(t[t.length-1],g,1,I),s(t[t.length-1],g,-1,I),[...i,...o]}var S3e=(e,A)=>{const{x:t,y:i,width:o,height:n,layer:s,rect_border_radius:r}=e,a=e.corner_radius??r??0,g=[{_pcb_drawing_object_id:Jy("rect"),pcb_drawing_type:"rect",x:t,y:i,w:o,h:n,layer:s||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...e.shape==="rotated_rect"&&e.ccw_rotation!==void 0?{ccw_rotation:e.ccw_rotation}:{}}];if(e.is_covered_with_solder_mask){const I=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",B={...{_pcb_drawing_object_id:Jy("rect"),pcb_drawing_type:"rect",x:t,y:i,w:o,h:n,layer:I,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...e.shape==="rotated_rect"&&e.ccw_rotation!==void 0?{ccw_rotation:e.ccw_rotation}:{}},..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};g.push(B)}return g},b3e=(e,A)=>{const{x:t,y:i,radius:o,layer:n}=e,s=[{_pcb_drawing_object_id:Jy("circle"),pcb_drawing_type:"circle",x:t,y:i,r:o,layer:n||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(e.is_covered_with_solder_mask){const r=n==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",a={_pcb_drawing_object_id:Jy("circle"),pcb_drawing_type:"circle",x:t,y:i,r:o,layer:r,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};s.push(a)}return s},x3e=(e,A)=>{const{layer:t,points:i}=e,o=[{_pcb_drawing_object_id:Jy("polygon"),pcb_drawing_type:"polygon",points:DpA(i),layer:t||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(e.is_covered_with_solder_mask){const n=t==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={_pcb_drawing_object_id:Jy("polygon"),pcb_drawing_type:"polygon",points:DpA(i),layer:n,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};o.push(s)}return o},_3e=(e,A)=>{const{x:t,y:i,width:o,height:n,layer:s}=e,r=[{_pcb_drawing_object_id:Jy("pill"),pcb_drawing_type:"pill",x:t,y:i,w:o,h:n,layer:s||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(e.is_covered_with_solder_mask){const a=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",g={_pcb_drawing_object_id:Jy("pill"),pcb_drawing_type:"pill",x:t,y:i,w:o,h:n,layer:a,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};r.push(g)}return r},k3e=(e,A)=>{const{x:t,y:i,width:o,height:n,layer:s,ccw_rotation:r}=e,a=[{_pcb_drawing_object_id:Jy("pill"),pcb_drawing_type:"pill",x:t,y:i,w:o,h:n,layer:s||"top",_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:r}];if(e.is_covered_with_solder_mask){const g=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",I={_pcb_drawing_object_id:Jy("pill"),pcb_drawing_type:"pill",x:t,y:i,w:o,h:n,layer:g,_element:e,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:r,..."solder_mask_color"in e&&e.solder_mask_color?{color:e.solder_mask_color}:{}};a.push(I)}return a},G3e=(e,A)=>{const{_parent_pcb_component:t,_parent_source_component:i}=A,o=e,n=typeof o.font_size=="string"?ue.parse(o.font_size):o.font_size??.2;let s;return o.knockout_padding&&(s={left:typeof o.knockout_padding.left=="string"?ue.parse(o.knockout_padding.left):o.knockout_padding.left,top:typeof o.knockout_padding.top=="string"?ue.parse(o.knockout_padding.top):o.knockout_padding.top,bottom:typeof o.knockout_padding.bottom=="string"?ue.parse(o.knockout_padding.bottom):o.knockout_padding.bottom,right:typeof o.knockout_padding.right=="string"?ue.parse(o.knockout_padding.right):o.knockout_padding.right}),[{_pcb_drawing_object_id:Jy("text"),pcb_drawing_type:"text",x:o.anchor_position.x,y:o.anchor_position.y,layer:o.layer,align:o.anchor_alignment??"center",text:o.text,size:n,ccw_rotation:o.ccw_rotation,is_mirrored:o.is_mirrored,is_knockout:o.is_knockout,knockout_padding:s,_element:e,_parent_pcb_component:t,_parent_source_component:i}]},mc=0,Jy=e=>`${e}_${mc++}`,DpA=e=>(e??[]).map(A=>({x:ue.parse(A.x),y:ue.parse(A.y)})),F3e=(e,A)=>{const t="pcb_component_id"in e?A.find(s=>s.type==="pcb_component"&&s.pcb_component_id===e.pcb_component_id):void 0,i=t&&"source_component_id"in t?A.find(s=>s.type==="source_component"&&s.source_component_id===t.source_component_id):void 0,o="source_port_id"in e?e.source_port_id:"pcb_port_id"in e?Qb(A).pcb_port.get(e.pcb_port_id)?.source_port_id:void 0,n=o?A.find(s=>s.type==="source_port"&&s.source_port_id===o):void 0;switch(e.type){case"pcb_smtpad":{const s={_parent_pcb_component:t,_parent_source_component:i,_source_port:n};return e.shape==="rect"||e.shape==="rotated_rect"?S3e(e,s):e.shape==="circle"?b3e(e,s):e.shape==="polygon"?x3e(e,s):e.shape==="pill"?_3e(e,s):e.shape==="rotated_pill"?k3e(e,s):[]}case"pcb_trace":{const s=[];if(e.route_thickness_mode==="interpolated"){const g=e.route.map(B=>({x:B.x,y:B.y,trace_width:B.route_type==="wire"?B.width:.5})),I=D3e(g,.5),c=e.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${mc++}`,_element:e,pcb_drawing_type:"polygon",points:I,layer:c}),e.route.forEach(B=>{B.route_type==="via"&&s.push({_pcb_drawing_object_id:`circle_${mc++}`,_element:e,pcb_drawing_type:"circle",x:B.x,y:B.y,r:B.outer_diameter/2,layer:B.from_layer})}),s}let r=null,a=null;for(const g of e.route)g.route_type==="wire"&&(r!==null&&a!==null&&s.push({_pcb_drawing_object_id:`line_${mc++}`,_element:e,pcb_drawing_type:"line",x1:r,y1:a,x2:g.x,y2:g.y,width:g.width,squareCap:!1,layer:g.layer}),r=g.x,a=g.y);return s}case"pcb_via":{const{x:s,y:r,outer_diameter:a,hole_diameter:g}=e,I=e.from_layer,c=e.to_layer,B=e.layers,l=[];I&&c?l.push(I,c):B&&Array.isArray(B)?l.push(...B):l.push("top","bottom");const C=[];for(const E of l)C.push({_pcb_drawing_object_id:`circle_${mc++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:E,_element:e,_parent_pcb_component:t,_parent_source_component:i});return C.push({_pcb_drawing_object_id:`circle_${mc++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"drill",_element:e}),C}case"pcb_plated_hole":if(e.shape==="circle"){const{x:s,y:r,hole_diameter:a,outer_diameter:g}=e;return[{_pcb_drawing_object_id:`circle_${mc++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:n},{_pcb_drawing_object_id:`circle_${mc++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:"drill",_element:e}]}else if(e.shape==="oval"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:I,hole_width:c}=e;return[{_pcb_drawing_object_id:`oval_${mc++}`,pcb_drawing_type:"oval",x:s,y:r,rX:g/2,rY:a/2,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:n},{_pcb_drawing_object_id:`oval_${mc++}`,_element:e,pcb_drawing_type:"oval",x:s,y:r,rX:c/2,rY:I/2,layer:"drill"}]}else if(e.shape==="pill"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:I,hole_width:c}=e;return[{_pcb_drawing_object_id:`pill_${mc++}`,pcb_drawing_type:"pill",x:s,y:r,w:g,h:a,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:n,ccw_rotation:e.ccw_rotation},{_pcb_drawing_object_id:`pill_${mc++}`,_element:e,pcb_drawing_type:"pill",x:s,y:r,w:c,h:I,layer:"drill",ccw_rotation:e.ccw_rotation}]}else if(e.shape==="circular_hole_with_rect_pad"){const{x:s,y:r,hole_diameter:a,rect_pad_width:g,rect_pad_height:I,rect_border_radius:c,hole_offset_x:B,hole_offset_y:l}=e,C=ue.parse(B??0),E=ue.parse(l??0);return[{_pcb_drawing_object_id:`rect_${mc++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:I,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:n,roundness:c},{_pcb_drawing_object_id:`rect_${mc++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:I,layer:"bottom",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:n,roundness:c},{_pcb_drawing_object_id:`circle_${mc++}`,_element:e,pcb_drawing_type:"circle",x:s+C,y:r+E,r:a/2,layer:"drill"}]}else if(e.shape==="pill_hole_with_rect_pad"){const{x:s,y:r,hole_width:a,hole_height:g,rect_pad_width:I,rect_pad_height:c,rect_border_radius:B}=e;return[{_pcb_drawing_object_id:`rect_${mc++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:c,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:n,roundness:B},{_pcb_drawing_object_id:`rect_${mc++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:c,layer:"bottom",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:n,roundness:B},{_pcb_drawing_object_id:`pill_${mc++}`,_element:e,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill"}]}else if(e.shape==="rotated_pill_hole_with_rect_pad"){const{x:s,y:r,hole_width:a,hole_height:g,hole_ccw_rotation:I,rect_pad_width:c,rect_pad_height:B,rect_ccw_rotation:l,rect_border_radius:C}=e;return[{_pcb_drawing_object_id:`rect_${mc++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:B,layer:"top",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:n,ccw_rotation:l,roundness:C},{_pcb_drawing_object_id:`rect_${mc++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:B,layer:"bottom",_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:n,ccw_rotation:l,roundness:C},{_pcb_drawing_object_id:`pill_${mc++}`,_element:e,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill",ccw_rotation:I}]}else if(e.shape==="hole_with_polygon_pad"){const{x:s,y:r,pad_outline:a,hole_shape:g,hole_diameter:I,hole_width:c,hole_height:B,layers:l,hole_offset_x:C,hole_offset_y:E}=e,Q=ue.parse(C??0),h=ue.parse(E??0),u=a,d=[];if(u&&Array.isArray(u)){const D=DpA(u).map(w=>({x:w.x+s,y:w.y+r}));for(const w of l||["top","bottom"])d.push({_pcb_drawing_object_id:`polygon_${mc++}`,pcb_drawing_type:"polygon",points:D,layer:w,_element:e,_parent_pcb_component:t,_parent_source_component:i,_source_port:n})}const f={x:s+Q,y:r+h},m=[];return g==="circle"?m.push({_pcb_drawing_object_id:`circle_${mc++}`,pcb_drawing_type:"circle",x:f.x,y:f.y,r:(I??0)/2,layer:"drill",_element:e,_parent_pcb_component:t,_parent_source_component:i}):g==="oval"?m.push({_pcb_drawing_object_id:`oval_${mc++}`,pcb_drawing_type:"oval",x:f.x,y:f.y,rX:(c??0)/2,rY:(B??0)/2,layer:"drill",_element:e,_parent_pcb_component:t,_parent_source_component:i}):(g==="pill"||g==="rotated_pill")&&m.push({_pcb_drawing_object_id:`pill_${mc++}`,pcb_drawing_type:"pill",x:f.x,y:f.y,w:c??0,h:B??0,layer:"drill",_element:e,_parent_pcb_component:t,_parent_source_component:i,ccw_rotation:e.ccw_rotation}),[...d,...m]}else return[];case"pcb_copper_text":return G3e(e,{_parent_pcb_component:t,_parent_source_component:i})}return[]},mo={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(242, 237, 161)",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)",soldermaskWithCopper:{top:"rgb(18, 82, 50)",bottom:"rgb(77, 127, 196)"},soldermask:{top:"rgb(12, 55, 33)",bottom:"rgb(12, 55, 33)"},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)"}},Ef=(e,A=1)=>{if(Math.abs(e.a)!==Math.abs(e.d))throw new Error("Cannot scale non-uniformly");return A*Math.abs(e.a)},EI={elementOverlay:40,dimensionOverlay:40,editTraceHintOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:20,clickToInteractOverlay:100},jV={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:mo.board.copper.f,inner1:mo.board.copper.in1,inner2:mo.board.copper.in2,inner3:mo.board.copper.in3,inner4:mo.board.copper.in4,inner5:mo.board.copper.in5,inner6:mo.board.copper.in6,inner7:mo.board.copper.in7,inner8:mo.board.copper.in8,bottom:mo.board.copper.b,drill:mo.board.anchor,keepout:mo.board.background,tkeepout:mo.board.b_crtyd,tplace:mo.board.b_silks,top_silkscreen:mo.board.f_silks,bottom_silkscreen:mo.board.b_silks,top_fabrication:mo.board.f_fab,bottom_fabrication:mo.board.b_fab,soldermask_top:mo.board.soldermask.top,soldermask_bottom:mo.board.soldermask.bottom,soldermask_with_copper_top:mo.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:mo.board.soldermaskWithCopper.bottom,bottom_notes:mo.board.user_2,top_notes:mo.board.user_2,...mo.board},R3e=["inner6","inner5","inner4","inner3","inner2","inner1","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","soldermask_with_copper_bottom","soldermask_with_copper_top","bottom_fabrication","top_fabrication","edge_cuts","top_silkscreen","board"],M3e=class{canvasLayerMap;ctxLayerMap;aperture;transform;foregroundLayer="top";lastPoint;constructor(e){this.canvasLayerMap=e,this.ctxLayerMap=Object.fromEntries(Object.entries(e).map(([A,t])=>[A,t.getContext("2d")])),this.transform=Bb(),this.transform.d*=-1,this.transform=Yy(this.transform,nl(0,-500)),this.lastPoint={x:0,y:0},this.equip({})}clear(){for(const e of Object.values(this.ctxLayerMap))e.clearRect(0,0,e.canvas.width,e.canvas.height)}equip(e){this.aperture={fontSize:0,shape:"circle",mode:"add",size:0,color:"red",layer:"top",opacity:this.foregroundLayer===e.color?1:.5,...e}}drawMeshPattern(e,A,t,i,o,n=45){const s=this.getLayerCtx(),[r,a]=qi(this.transform,[e,A]),[g,I]=qi(this.transform,[e+t,A+i]),c=Ef(this.transform,o);s.lineWidth=1,s.strokeStyle=this.aperture.color;const B=l=>{const C=Math.sin(l),E=Math.cos(l),Q=Math.sqrt((g-r)**2+(I-a)**2);for(let h=-Q;h<=Q;h+=c)s.beginPath(),s.moveTo(r+h*E-Q*C,a+h*C+Q*E),s.lineTo(r+h*E+Q*C,a+h*C-Q*E),s.stroke()};B(n*Math.PI/180),B((n+90)*Math.PI/180)}rect({x:e,y:A,w:t,h:i,mesh_fill:o,is_filled:n=!0,has_stroke:s,is_stroke_dashed:r,stroke_width:a,roundness:g}){const[I,c]=qi(this.transform,[e-t/2,A-i/2]),[B,l]=qi(this.transform,[e+t/2,A+i/2]);this.applyAperture();const C=this.getLayerCtx(),E=g?Ef(this.transform,g):0,Q=s===void 0?n===!1:s;if(o)C.save(),C.beginPath(),E>0&&C.roundRect?C.roundRect(I,c,B-I,l-c,E):C.rect(I,c,B-I,l-c),C.clip(),this.drawMeshPattern(e-t/2,A-i/2,t,i,.15),C.restore(),E>0&&C.roundRect?(C.beginPath(),C.roundRect(I,c,B-I,l-c,E),C.stroke()):C.strokeRect(I,c,B-I,l-c);else if(n!==!1&&(E>0&&C.roundRect?(C.beginPath(),C.roundRect(I,c,B-I,l-c,E),C.fill()):C.fillRect(I,c,B-I,l-c)),Q){const h=C.lineWidth;if(a!==void 0&&(C.lineWidth=Ef(this.transform,a)),r){let u=[];const d=Math.abs(this.transform.a);if(d>0){const m=.1*d,D=m*1.3;m>.5&&(u=[m,D])}C.setLineDash(u)}E>0&&C.roundRect?(C.beginPath(),C.roundRect(I,c,B-I,l-c,E),C.stroke()):C.strokeRect(I,c,B-I,l-c),r&&C.setLineDash([]),a!==void 0&&(C.lineWidth=h)}}rotatedRect(e,A,t,i,o,n,s){const r=this.getLayerCtx();this.applyAperture();const[a,g]=qi(this.transform,[e-t/2,A-i/2]),[I,c]=qi(this.transform,[e+t/2,A+i/2]),B=n?Ef(this.transform,n):0;r.save();const[l,C]=qi(this.transform,[e,A]);r.translate(l,C);const E=360-o;o&&r.rotate(E*Math.PI/180),r.translate(-l,-C),s?(r.beginPath(),B>0&&r.roundRect?r.roundRect(a,g,I-a,c-g,B):r.rect(a,g,I-a,c-g),r.clip(),this.drawMeshPattern(e-t/2,A-i/2,t,i,.15),B>0&&r.roundRect?(r.beginPath(),r.roundRect(a,g,I-a,c-g,B),r.stroke()):r.strokeRect(a,g,I-a,c-g)):B>0&&r.roundRect?(r.beginPath(),r.roundRect(a,g,I-a,c-g,B),r.fill()):r.fillRect(a,g,I-a,c-g),r.restore()}rotatedPill(e,A,t,i,o){const n=this.getLayerCtx();this.applyAperture(),n.save();const[s,r]=qi(this.transform,[e,A]);n.translate(s,r);const a=360-o;o&&n.rotate(a*Math.PI/180),n.translate(-s,-r),this.pill(e,A,t,i),n.restore()}circle(e,A,t,i){const o=Ef(this.transform,t),[n,s]=qi(this.transform,[e,A]);this.applyAperture();const r=this.getLayerCtx();i?(r.save(),r.beginPath(),r.arc(n,s,o,0,2*Math.PI),r.clip(),this.drawMeshPattern(e-t,A-t,t*2,t*2,.15),r.restore(),r.beginPath(),r.arc(n,s,o,0,2*Math.PI),r.stroke()):(r.beginPath(),r.arc(n,s,o,0,2*Math.PI),r.fill())}oval(e,A,t,i){const o=Ef(this.transform,t),n=Ef(this.transform,i),[s,r]=qi(this.transform,[e,A]);this.applyAperture();const a=this.getLayerCtx();a.beginPath(),a.ellipse(s,r,o,n,0,0,2*Math.PI),a.fill(),a.closePath()}pill(e,A,t,i){const[o,n]=qi(this.transform,[e-t/2,A+i/2]),s=Ef(this.transform,t),r=Ef(this.transform,i),a=Math.min(s,r)/2;this.applyAperture();const g=this.getLayerCtx();g.beginPath(),g.arc(o+a,n+a,a,Math.PI,Math.PI*1.5),g.arc(o+s-a,n+a,a,Math.PI*1.5,0),g.arc(o+s-a,n+r-a,a,0,Math.PI*.5),g.arc(o+a,n+r-a,a,Math.PI*.5,Math.PI),g.fill(),g.closePath()}polygon(e){if(e.length<3)return;this.applyAperture();const A=this.getLayerCtx(),t=e.map(o=>qi(this.transform,[o.x,o.y]));A.beginPath(),A.moveTo(t[0][0],t[0][1]);for(let o=1;o<t.length;o++)A.lineTo(t[o][0],t[o][1]);A.closePath(),A.fill("evenodd");const i=Ef(this.transform,this.aperture.size);i>0&&(A.lineWidth=i,A.stroke())}debugText(e,A,t){const[i,o]=qi(this.transform,[A,t]);this.applyAperture();const n=this.getLayerCtx();n.font="10px sans-serif",n.fillText(e,i,o)}getLayerCtx(){const e=this.ctxLayerMap[this.aperture.layer];if(!e)throw new Error(`No context for layer "${this.aperture.layer}"`);return e}orderAndFadeLayers(){const{canvasLayerMap:e,foregroundLayer:A}=this,t=A==="top"?"top_silkscreen":A==="bottom"?"bottom_silkscreen":void 0,i=A==="top"?"top_notes":A==="bottom"?"bottom_notes":void 0,o=A==="top"?"top_fabrication":A==="bottom"?"bottom_fabrication":void 0,n=A==="top"?"soldermask_with_copper_top":A==="bottom"?"soldermask_with_copper_bottom":void 0,s=new Set([A,"drill","edge_cuts","other","board",...t?[t]:[],...i?[i]:[],...o?[o]:[],...n?[n]:[]]),r=[A,"edge_cuts",...t?[t]:[],...i?[i]:[],...o?[o]:[],...n?[n]:[]],a=[...R3e.filter(g=>!r.includes(g)),A,...n?[n]:[],"edge_cuts","drill",...t?[t]:[],...i?[i]:[],...o?[o]:[]];a.forEach((g,I)=>{const c=e[g];c&&(c.style.zIndex=`${EI.topLayer-(a.length-I)}`,c.style.opacity=s.has(g)?"1":"0.5")})}applyAperture(){const{transform:e,aperture:A}=this;let{size:t,mode:i,color:o,fontSize:n,layer:s}=A;s in this.ctxLayerMap||(this.aperture.layer="other");const r=this.getLayerCtx();if(!r)throw new Error(`No context for layer "${this.foregroundLayer}"`);if(o||(o="undefined"),r.lineWidth=Ef(e,t),r.lineCap="round",i==="add"){r.globalCompositeOperation="source-over";let a=jV[o.toLowerCase()];if(!a)try{a=ka(o).rgb().toString()}catch{console.warn(`Invalid color format: '${o}'`),a="white"}r.fillStyle=a,r.strokeStyle=a}else r.globalCompositeOperation="destination-out",r.fillStyle="rgba(0,0,0,1)",r.strokeStyle="rgba(0,0,0,1)";r.font=`${Ef(lb(e),n)}px sans-serif`}moveTo(e,A){this.lastPoint={x:e,y:A}}lineTo(e,A){const[t,i]=qi(this.transform,[e,A]),{size:o,shape:n,mode:s}=this.aperture,r=Ef(this.transform,o),{lastPoint:a}=this,g=qi(this.transform,a);this.applyAperture();const I=this.getLayerCtx();n==="square"&&I.fillRect(g.x-r/2,g.y-r/2,r,r),I.beginPath(),I.moveTo(g.x,g.y),I.lineTo(t,i),I.stroke(),I.closePath(),n==="square"&&I.fillRect(t-r/2,i-r/2,r,r),this.lastPoint={x:e,y:A}}polygonWithArcs(e){const A=this.getLayerCtx(),t=i=>{if(i.vertices.length===0)return;const o=i.vertices[0],n=qi(this.transform,[o.x,o.y]);A.moveTo(n[0],n[1]);for(let s=0;s<i.vertices.length;s++){const r=i.vertices[s],a=i.vertices[(s+1)%i.vertices.length];if(r.bulge&&r.bulge!==0){const g=r.bulge,I=a.x-r.x,c=a.y-r.y,B=Math.sqrt(I*I+c*c);if(B<1e-9){const M=qi(this.transform,[a.x,a.y]);A.lineTo(M[0],M[1]);continue}const l=4*Math.atan(g),C=Math.abs(B/(2*Math.sin(l/2))),E=(r.x+a.x)/2,Q=(r.y+a.y)/2,h=I/B,d=-(c/B),f=h,m=Math.sqrt(Math.max(0,C*C-(B/2)**2)),D=E+m*d*Math.sign(g),w=Q+m*f*Math.sign(g),b=Math.atan2(r.y-w,r.x-D);let k=Math.atan2(a.y-w,a.x-D);g>0&&k<b?k+=2*Math.PI:g<0&&k>b&&(k-=2*Math.PI);const x=qi(this.transform,[D,w]),N=Ef(this.transform,C);A.arc(x[0],x[1],N,-b,-k,g>0)}else{const g=qi(this.transform,[a.x,a.y]);A.lineTo(g[0],g[1])}}A.closePath()};if(A.beginPath(),t(e.outer_ring),e.inner_rings)for(const i of e.inner_rings)t(i);A.fill("evenodd")}};function N3e(e){return e.type==="pcb_copper_pour"}function zV({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const o=A.filter(N3e);if(o.length===0)return;const n=new MQ(e);n.realToCanvasMat=i,n.drawElements(o,{layers:t})}var v3e={...Cf,silkscreen:{top:mo.board.f_fab,bottom:mo.board.b_fab}};function L3e(e){return e.type.includes("pcb_fabrication_note")}function Zat({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const o=new MQ(e);o.configure({colorOverrides:v3e}),o.realToCanvasMat=i;const n=A.filter(L3e);o.drawElements(n,{layers:t})}function U3e(e){return e.type==="pcb_hole"}function H3e({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:o}){const n=new MQ(e);n.realToCanvasMat=i;const s=A.filter(U3e);n.drawElements(s,{layers:t,drawSoldermask:o})}function Y3e(e){return e.type==="pcb_board"}function J3e({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:o}){const n=new MQ(e);n.realToCanvasMat=i;const s=A.filter(Y3e);for(const r of s)n.drawElements([r],{layers:t,drawSoldermask:o})}function T3e(e){return e.type==="pcb_cutout"}function K3e({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const o=new MQ(e);o.realToCanvasMat=i;const n=A.filter(T3e);o.drawElements(n,{layers:t})}function P3e(e){return e.type==="pcb_keepout"}function q3e({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const o=A.filter(P3e);if(o.length===0)return;const n=new MQ(e);n.realToCanvasMat=i,n.drawElements(o,{layers:[]})}function O3e(e){return e.type.startsWith("pcb_note_")}function Vat({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const o=new MQ(e);o.realToCanvasMat=i;const n=A.filter(O3e);o.drawElements(n,{layers:t})}function W3e(e){return e.type==="pcb_panel"}function Z3e({canvas:e,elements:A,layers:t,realToCanvasMat:i,drawSoldermask:o}){const n=new MQ(e);n.realToCanvasMat=i;const s=A.filter(W3e);for(const r of s)n.drawElements([r],{layers:t,drawSoldermask:o})}var V3e={...Cf,copper:{...Cf.copper,top:ka(mo.board.pad_front).lighten(.5).toString(),bottom:ka(mo.board.pad_back).lighten(.5).toString(),inner1:ka(mo.board.copper.in1).lighten(.5).toString(),inner2:ka(mo.board.copper.in2).lighten(.5).toString(),inner3:ka(mo.board.copper.in3).lighten(.5).toString(),inner4:ka(mo.board.copper.in4).lighten(.5).toString(),inner5:ka(mo.board.copper.in5).lighten(.5).toString(),inner6:ka(mo.board.copper.in6).lighten(.5).toString()}};function j3e(e){return e.type==="pcb_smtpad"}function z3e({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:o,drawSoldermask:n}){const s=A.filter(j3e).filter(I=>{const c=I.layer;return t.some(B=>B==="top_copper"&&c==="top"||B==="bottom_copper"&&c==="bottom"||B==="inner1_copper"&&c==="inner1"||B==="inner2_copper"&&c==="inner2"||B==="inner3_copper"&&c==="inner3"||B==="inner4_copper"&&c==="inner4"||B==="inner5_copper"&&c==="inner5"||B==="inner6_copper"&&c==="inner6")});if(s.length===0)return;const r=new Set;if(o)for(const I of o)(I.is_mouse_over||I.is_in_highlighted_net)&&I._element?.type==="pcb_smtpad"&&r.add(I._element.pcb_smtpad_id);const a=s.filter(I=>r.has(I.pcb_smtpad_id)),g=s.filter(I=>!r.has(I.pcb_smtpad_id));if(g.length>0){const I=new MQ(e);I.realToCanvasMat=i,I.drawElements(g,{layers:t,drawSoldermask:n})}if(a.length>0){const I=new MQ(e);I.configure({colorOverrides:V3e}),I.realToCanvasMat=i,I.drawElements(a,{layers:t,drawSoldermask:n})}}var X3e={...Cf,copper:{...Cf.copper,top:ka(mo.board.pad_front).lighten(.5).toString(),bottom:ka(mo.board.pad_back).lighten(.5).toString(),inner1:ka(mo.board.copper.in1).lighten(.5).toString(),inner2:ka(mo.board.copper.in2).lighten(.5).toString(),inner3:ka(mo.board.copper.in3).lighten(.5).toString(),inner4:ka(mo.board.copper.in4).lighten(.5).toString(),inner5:ka(mo.board.copper.in5).lighten(.5).toString(),inner6:ka(mo.board.copper.in6).lighten(.5).toString()}};function $3e(e){return e.type==="pcb_trace"}var AOe=e=>e.map(A=>A.endsWith("_copper")?A.replace("_copper",""):A);function tOe({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:o}){const n=new Set(AOe(t)),s=A.filter($3e).filter(I=>I.route.some(c=>c.route_type==="wire"&&"layer"in c&&n.has(c.layer)));if(s.length===0)return;const r=new Set;if(o)for(const I of o)(I.is_mouse_over||I.is_in_highlighted_net)&&I._element?.type==="pcb_trace"&&r.add(I._element.pcb_trace_id);const a=s.filter(I=>r.has(I.pcb_trace_id)),g=s.filter(I=>!r.has(I.pcb_trace_id));if(g.length>0){const I=new MQ(e);I.realToCanvasMat=i,I.drawElements(g,{layers:t})}if(a.length>0){const I=new MQ(e);I.configure({colorOverrides:X3e}),I.realToCanvasMat=i,I.drawElements(a,{layers:t})}}var eOe={...Cf,copper:{...Cf.copper,top:ka(mo.board.pad_front).lighten(.5).toString(),bottom:ka(mo.board.pad_back).lighten(.5).toString()}};function iOe(e){return e.type==="pcb_plated_hole"}function jat({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:o,drawSoldermask:n}){const s=A.filter(iOe);if(s.length===0)return;const r=new Set;if(o)for(const I of o)(I.is_mouse_over||I.is_in_highlighted_net)&&I._element?.type==="pcb_plated_hole"&&r.add(I._element.pcb_plated_hole_id);const a=s.filter(I=>r.has(I.pcb_plated_hole_id)),g=s.filter(I=>!r.has(I.pcb_plated_hole_id));if(g.length>0){const I=new MQ(e);I.realToCanvasMat=i,I.drawElements(g,{layers:t,drawSoldermask:n})}if(a.length>0){const I=new MQ(e);I.configure({colorOverrides:eOe}),I.realToCanvasMat=i,I.drawElements(a,{layers:t,drawSoldermask:n})}}function zat(e){const{lines:A,anchorPoint:t,ccwRotation:i}=e;if(!i)return A;const o=i*Math.PI/180,n=OKe(o),s=Yy(nl(t.x,t.y),n,nl(-t.x,-t.y));return qi(s,t),A.map(r=>({...r,x1:qi(s,{x:r.x1,y:r.y1}).x,y1:qi(s,{x:r.x1,y:r.y1}).y,x2:qi(s,{x:r.x2,y:r.y2}).x,y2:qi(s,{x:r.x2,y:r.y2}).y}))}var oOe=.6,Xat=.2,$at=e=>{const A=e.size*.7,t=A*oOe,i=A*Xat,o=A*Xat,n=e.text.split(/\r?\n/),s=e.text.length>0&&A>0,r=s?n.length:0,a=s?n.map(c=>c.length===0?0:c.length*t+(c.length-1)*i):[],g=a.length>0?Math.max(...a):0,I=r>0?r*A+(r-1)*o:0;return{text_lines:n,line_count:r,line_widths:a,target_height:A,target_width_char:t,space_between_chars:i,space_between_lines:o,width:g,height:I}},Agt=e=>{const A=$at(e);return{width:A.width,height:A.height,lineHeight:A.target_height,lineSpacing:A.space_between_lines,lineCount:A.line_count}},tgt=e=>{const{text_lines:A,line_count:t,line_widths:i,target_height:o,target_width_char:n,space_between_chars:s,space_between_lines:r,width:a}=$at(e);if(o<=0||t===0)return[];const g=o/12,I=[];for(let c=0;c<t;c++){const B=-c*(o+r),l=i[c],C=(a-l)/2;let E=e.x+C;for(let Q=0;Q<A[c].length;Q++){const h=A[c][Q],u=jw[h]??jw[h.toUpperCase()];if(!u){E+=n+s;continue}for(const{x1:d,y1:f,x2:m,y2:D}of u)I.push({_pcb_drawing_object_id:Jy("line"),pcb_drawing_type:"line",x1:E+n*d,y1:e.y+B+o*f,x2:E+n*m,y2:e.y+B+o*D,width:g,layer:e.layer,unit:e.unit,color:e.color});E+=n+s}}return I};function SD(e){const t=e.color??jV[e.layer];let i=ka(t);return e._element?.type==="pcb_copper_pour"&&(i=i.alpha(.7)),e.is_mouse_over||e.is_in_highlighted_net?i.lighten(.5).rgb().toString():i.rgb().toString()}var egt=(e,A)=>{e.equip({size:A.zoomIndependent?A.width/e.transform.a:A.width,shape:A.squareCap?"square":"circle",color:SD(A),layer:A.layer}),e.moveTo(A.x1,A.y1),e.lineTo(A.x2,A.y2)},nOe=(e,A,t)=>{switch(t){case"top_left":return{x:0,y:-A};case"top_center":return{x:-e/2,y:-A};case"top_right":return{x:-e,y:-A};case"center_left":return{x:0,y:-A/2};case"center":return{x:-e/2,y:-A/2};case"center_right":return{x:-e,y:-A/2};case"bottom_left":return{x:0,y:0};case"bottom_center":return{x:-e/2,y:0};case"bottom_right":return{x:-e,y:0};default:return{x:0,y:0}}},igt=e=>e.layer==="bottom_silkscreen"||e.layer==="bottom"?e.is_mirrored!==!1:e.is_mirrored===!0,sOe=(e,A)=>{e.equip({fontSize:A.size,color:SD(A),layer:A.layer});const{width:t,height:i}=Agt(A),o=nOe(t,i,A.align);A.x??=0,A.y??=0;const n={x:A.x,y:A.y};let s=tgt({...A,x:A.x+o.x,y:A.y+o.y});if(igt(A)&&(s=s.map(r=>({...r,x1:2*A.x-r.x1,x2:2*A.x-r.x2}))),A.ccw_rotation){const r={lines:s,anchorPoint:n,ccwRotation:A.ccw_rotation};s=zat(r)}for(const r of s)egt(e,r)},rOe=(e,A)=>{const{width:t,height:i,lineHeight:o}=Agt(A);A.x??=0,A.y??=0;const n=A.knockout_padding??{left:A.size*.5,right:A.size*.5,top:A.size*.3,bottom:A.size*.3},s=t+n.left+n.right,r=i+n.top+n.bottom,a=t/2,g=o-i/2,I=A.x-a,c=A.y-g,B={x:A.x,y:A.y},l={_pcb_drawing_object_id:`knockout_rect_${A._pcb_drawing_object_id}`,x:A.x,y:A.y,w:s,h:r,layer:A.layer,ccw_rotation:A.ccw_rotation};A.ccw_rotation?ngt(e,l):ogt(e,l);let C=tgt({...A,x:I,y:c});if(igt(A)&&(C=C.map(E=>({...E,x1:2*A.x-E.x1,x2:2*A.x-E.x2}))),A.ccw_rotation){const E={lines:C,anchorPoint:B,ccwRotation:A.ccw_rotation};C=zat(E)}for(const E of C)e.equip({size:E.width,shape:"circle",color:"black",layer:A.layer,mode:"subtract"}),e.moveTo(E.x1,E.y1),e.lineTo(E.x2,E.y2);e.equip({mode:"add"})},ogt=(e,A)=>{e.equip({color:SD(A),layer:A.layer,size:A.stroke_width}),e.rect({x:A.x,y:A.y,w:A.w,h:A.h,mesh_fill:A.mesh_fill,is_filled:A.is_filled,has_stroke:A.has_stroke,is_stroke_dashed:A.is_stroke_dashed,stroke_width:A.stroke_width,roundness:A.roundness})},ngt=(e,A)=>{e.equip({color:SD(A),layer:A.layer}),e.rotatedRect(A.x,A.y,A.w,A.h,A.ccw_rotation,A.roundness,A.mesh_fill)},aOe=(e,A)=>{e.equip({color:SD(A),layer:A.layer}),e.rotatedPill(A.x,A.y,A.w,A.h,A.ccw_rotation)},gOe=(e,A)=>{e.equip({color:SD(A),layer:A.layer}),e.circle(A.x,A.y,A.r,A.mesh_fill)},IOe=(e,A)=>{e.equip({color:SD(A),layer:A.layer}),e.oval(A.x,A.y,A.rX,A.rY)},cOe=(e,A)=>{e.equip({color:SD(A),layer:A.layer}),e.pill(A.x,A.y,A.w,A.h)},BOe=(e,A)=>{e.equip({color:SD(A),layer:A.layer}),e.polygon(A.points)},lOe=(e,A)=>{e.equip({color:SD(A),layer:A.layer}),e.polygonWithArcs(A.brep_shape)},COe=(e,A)=>{switch(A.pcb_drawing_type){case"line":return egt(e,A);case"text":return A.is_knockout?rOe(e,A):sOe(e,A);case"rect":return A.ccw_rotation?ngt(e,A):ogt(e,A);case"circle":return gOe(e,A);case"oval":return IOe(e,A);case"pill":return A.ccw_rotation?aOe(e,A):cOe(e,A);case"polygon":return BOe(e,A);case"polygon_with_arcs":return lOe(e,A)}},QOe=(e,A)=>{for(const t of A)COe(e,t)},EOe={...Cf,copper:{...Cf.copper,top:ka(mo.board.pad_front).lighten(.5).toString(),bottom:ka(mo.board.pad_back).lighten(.5).toString(),inner1:ka(mo.board.copper.in1).lighten(.5).toString(),inner2:ka(mo.board.copper.in2).lighten(.5).toString(),inner3:ka(mo.board.copper.in3).lighten(.5).toString(),inner4:ka(mo.board.copper.in4).lighten(.5).toString(),inner5:ka(mo.board.copper.in5).lighten(.5).toString(),inner6:ka(mo.board.copper.in6).lighten(.5).toString()},soldermask:{...Cf.soldermask,top:ka(mo.board.soldermask.top).lighten(.35).toString(),bottom:ka(mo.board.soldermask.bottom).lighten(.35).toString()}};function XV({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:o}){const n=new MQ(e);if(n.realToCanvasMat=i,n.drawElements(A,{layers:t,drawSoldermask:!0}),!o)return;const s=new Set;for(const g of o){if(!(g.is_mouse_over||g.is_in_highlighted_net))continue;const I=g._element;I?.type==="pcb_smtpad"?s.add(I.pcb_smtpad_id):I?.type==="pcb_plated_hole"?s.add(I.pcb_plated_hole_id):I?.type==="pcb_via"&&s.add(I.pcb_via_id)}if(s.size===0)return;const r=A.filter(g=>g.type==="pcb_smtpad"?s.has(g.pcb_smtpad_id):g.type==="pcb_plated_hole"?s.has(g.pcb_plated_hole_id):g.type==="pcb_via"?s.has(g.pcb_via_id):!1);if(r.length===0)return;const a=new MQ(e);a.configure({colorOverrides:EOe}),a.realToCanvasMat=i,a.drawElements(r,{layers:t,drawSoldermask:!0})}var hOe={...Cf,silkscreen:{top:mo.board.f_silks,bottom:mo.board.b_silks}};function uOe(e){return e.type.includes("pcb_silkscreen")}function sgt({canvas:e,elements:A,layers:t,realToCanvasMat:i}){const o=new MQ(e);o.configure({colorOverrides:hOe}),o.realToCanvasMat=i;const n=A.filter(uOe);o.drawElements(n,{layers:t})}var dOe={...Cf,copper:{...Cf.copper,top:ka(mo.board.pad_front).lighten(.5).toString(),bottom:ka(mo.board.pad_back).lighten(.5).toString()}};function pOe(e){return e.type==="pcb_via"}function rgt({canvas:e,elements:A,layers:t,realToCanvasMat:i,primitives:o,drawSoldermask:n}){const s=A.filter(pOe).filter(I=>t.some(c=>c.includes("copper")));if(s.length===0)return;const r=new Set;if(o)for(const I of o)(I.is_mouse_over||I.is_in_highlighted_net)&&I._element?.type==="pcb_via"&&r.add(I._element.pcb_via_id);const a=s.filter(I=>r.has(I.pcb_via_id)),g=s.filter(I=>!r.has(I.pcb_via_id));if(g.length>0){const I=new MQ(e);I.realToCanvasMat=i,I.drawElements(g,{layers:t,drawSoldermask:n})}if(a.length>0){const I=new MQ(e);I.configure({colorOverrides:dOe}),I.realToCanvasMat=i,I.drawElements(a,{layers:t,drawSoldermask:n})}}var fOe=["board","bottom","soldermask_bottom","bottom_silkscreen","top","soldermask_top","soldermask_with_copper_bottom","soldermask_with_copper_top","top_fabrication","bottom_fabrication","inner1","inner2","inner3","inner4","inner5","inner6","drill","edge_cuts","bottom_notes","top_notes","top_silkscreen","bottom_silkscreen","other"],yOe=({primitives:e,elements:A,transform:t,grid:i,width:o=500,height:n=500})=>{const s=AA.useRef({}),r=zl(g=>g.selected_layer),a=zl(g=>g.is_showing_solder_mask);return AA.useEffect(()=>{if(!s.current||Object.keys(s.current).length===0)return;const g=Object.fromEntries(Object.entries(s.current).filter(([B,l])=>!(!l||!a&&B.includes("soldermask"))));if(Object.keys(g).length===0)return;const I=new M3e(g);t&&(I.transform=t),I.clear(),I.foregroundLayer=r;const c=e.filter(B=>a||!B.layer?.includes("soldermask")).filter(B=>B.layer!=="board").filter(B=>B._element?.type!=="pcb_smtpad").filter(B=>B._element?.type!=="pcb_plated_hole").filter(B=>B._element?.type!=="pcb_via").filter(B=>B._element?.type!=="pcb_trace");if(QOe(I,c),t){const B=s.current.top,l=s.current.bottom,C=s.current.inner1,E=s.current.inner2,Q=s.current.inner3,h=s.current.inner4,u=s.current.inner5,d=s.current.inner6;B&&jat({canvas:B,elements:A,layers:["top_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),l&&jat({canvas:l,elements:A,layers:["bottom_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),B&&zV({canvas:B,elements:A,layers:["top_copper"],realToCanvasMat:t}),l&&zV({canvas:l,elements:A,layers:["bottom_copper"],realToCanvasMat:t});const f=[{canvas:B,copperLayer:"top_copper"},{canvas:l,copperLayer:"bottom_copper"},{canvas:C,copperLayer:"inner1_copper"},{canvas:E,copperLayer:"inner2_copper"},{canvas:Q,copperLayer:"inner3_copper"},{canvas:h,copperLayer:"inner4_copper"},{canvas:u,copperLayer:"inner5_copper"},{canvas:d,copperLayer:"inner6_copper"}];for(const{canvas:H,copperLayer:O}of f)H&&tOe({canvas:H,elements:A,layers:[O],realToCanvasMat:t,primitives:e});for(const{canvas:H,copperLayer:O}of f)H&&(z3e({canvas:H,elements:A,layers:[O],realToCanvasMat:t,primitives:e,drawSoldermask:a}),a&&XV({canvas:H,elements:A,layers:[O],realToCanvasMat:t,primitives:e}));if(B&&rgt({canvas:B,elements:A,layers:["top_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),l&&rgt({canvas:l,elements:A,layers:["bottom_copper"],realToCanvasMat:t,primitives:e,drawSoldermask:a}),a){const H=s.current.soldermask_top;H&&XV({canvas:H,elements:A,layers:["top_soldermask"],realToCanvasMat:t,primitives:e});const O=s.current.soldermask_bottom;O&&XV({canvas:O,elements:A,layers:["bottom_soldermask"],realToCanvasMat:t,primitives:e})}B&&zV({canvas:B,elements:A,layers:["top_copper"],realToCanvasMat:t}),l&&zV({canvas:l,elements:A,layers:["bottom_copper"],realToCanvasMat:t});const m=s.current.drill;m&&(H3e({canvas:m,elements:A,layers:["drill"],realToCanvasMat:t}),a&&XV({canvas:m,elements:A,layers:["drill"],realToCanvasMat:t,primitives:e}));const D=s.current.top_silkscreen;D&&sgt({canvas:D,elements:A,layers:["top_silkscreen"],realToCanvasMat:t});const w=s.current.bottom_silkscreen;w&&sgt({canvas:w,elements:A,layers:["bottom_silkscreen"],realToCanvasMat:t});const b=s.current.top_fabrication;b&&Zat({canvas:b,elements:A,layers:["top_fabrication_note"],realToCanvasMat:t});const k=s.current.bottom_fabrication;k&&Zat({canvas:k,elements:A,layers:["bottom_fabrication_note"],realToCanvasMat:t});const x=s.current.bottom_notes;x&&Vat({canvas:x,elements:A,layers:["bottom_user_note"],realToCanvasMat:t});const N=s.current.top_notes;N&&Vat({canvas:N,elements:A,layers:["top_user_note"],realToCanvasMat:t});const M=s.current.board;M&&(Z3e({canvas:M,elements:A,layers:[],realToCanvasMat:t,drawSoldermask:a}),J3e({canvas:M,elements:A,layers:[],realToCanvasMat:t,drawSoldermask:a}));const U=s.current.edge_cuts;U&&K3e({canvas:U,elements:A,layers:["edge_cuts"],realToCanvasMat:t});const J=[{canvas:B,layer:"top"},{canvas:l,layer:"bottom"}];for(const{canvas:H,layer:O}of J)H&&q3e({canvas:H,elements:A,layers:[O],realToCanvasMat:t})}I.orderAndFadeLayers()},[e,A,t,r,a]),Z.jsxs("div",{style:{backgroundColor:"black",width:o,height:n,position:"relative"},children:[Z.jsx(MV.SuperGrid,{textColor:"rgba(0,255,0,0.8)",majorColor:"rgba(0,255,0,0.4)",minorColor:"rgba(0,255,0,0.2)",screenSpaceCellSize:200,width:o,height:n,transform:t,stringifyCoord:(g,I,c)=>`${MV.toMMSI(g,c)}, ${MV.toMMSI(I,c)}`}),fOe.filter(g=>a?!0:!g.includes("soldermask")).map(g=>g.replace(/-/g,"")).map((g,I)=>Z.jsx("canvas",{className:`pcb-layer-${g}`,ref:c=>{s.current??={},c?s.current[g]=c:delete s.current[g]},style:{position:"absolute",zIndex:I,left:0,top:0,pointerEvents:"none"},width:o,height:n},g))]})},mOe=.6,wOe=1;Gat(Y4e()),Gat(e3e());var $V=["rgba(239, 68, 68, 0.8)","rgba(249, 115, 22, 0.8)","rgba(245, 158, 11, 0.8)","rgba(234, 179, 8, 0.8)","rgba(132, 204, 22, 0.8)","rgba(34, 197, 94, 0.8)","rgba(16, 185, 129, 0.8)","rgba(20, 184, 166, 0.8)","rgba(6, 182, 212, 0.8)","rgba(14, 165, 233, 0.8)","rgba(59, 130, 246, 0.8)","rgba(99, 102, 241, 0.8)","rgba(139, 92, 246, 0.8)","rgba(168, 85, 247, 0.8)","rgba(217, 70, 239, 0.8)","rgba(236, 72, 153, 0.8)","rgba(249, 168, 212, 0.8)","rgba(161, 161, 170, 0.8)"];function agt(e,A,t,i={}){const o=i.padding??40,n=i.yFlip??!1;let s;if("center"in e){const I=e.width/2,c=e.height/2;s={minX:e.center.x-I,maxX:e.center.x+I,minY:e.center.y-c,maxY:e.center.y+c}}else s=e;const r=s.maxX-s.minX||1,a=s.maxY-s.minY||1,g=Math.min((A-2*o)/r,(t-2*o)/a);return Yy(nl(A/2,t/2),RY(g,n?-g:g),nl(-(s.minX+r/2),-(s.minY+a/2)))}function DOe(e){const A=[...e.points||[],...(e.lines||[]).flatMap(t=>t.points),...(e.rects||[]).flatMap(t=>{const i=t.width/2,o=t.height/2;return[{x:t.center.x-i,y:t.center.y-o},{x:t.center.x+i,y:t.center.y-o},{x:t.center.x-i,y:t.center.y+o},{x:t.center.x+i,y:t.center.y+o}]}),...(e.circles||[]).flatMap(t=>[{x:t.center.x-t.radius,y:t.center.y},{x:t.center.x+t.radius,y:t.center.y},{x:t.center.x,y:t.center.y-t.radius},{x:t.center.x,y:t.center.y+t.radius}]),...(e.texts||[]).flatMap(t=>{const i=t.fontSize??12,o=t.text.length*i*mOe,n=i*wOe,s=t.anchorSide??"center",r={top_left:{dx:0,dy:0},top_center:{dx:-o/2,dy:0},top_right:{dx:-o,dy:0},center_left:{dx:0,dy:-n/2},center:{dx:-o/2,dy:-n/2},center_right:{dx:-o,dy:-n/2},bottom_left:{dx:0,dy:-n},bottom_center:{dx:-o/2,dy:-n},bottom_right:{dx:-o,dy:-n}},{dx:a,dy:g}=r[s],I=t.x+a,c=t.y+g;return[{x:I,y:c},{x:I+o,y:c+n}]})];return A.length===0?{minX:-1,maxX:1,minY:-1,maxY:1}:A.reduce((t,i)=>({minX:Math.min(t.minX,i.x),maxX:Math.max(t.maxX,i.x),minY:Math.min(t.minY,i.y),maxY:Math.max(t.maxY,i.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function SOe(e,A,t={}){const i=A instanceof HTMLCanvasElement?A.getContext("2d"):A;if(!i)throw new Error("Could not get 2D context from canvas");const o=A instanceof HTMLCanvasElement?A.width:A.canvas.width,n=A instanceof HTMLCanvasElement?A.height:A.canvas.height;let s;if(t.transform)s=t.transform;else if(t.viewbox)s=agt(t.viewbox,o,n,{padding:t.padding,yFlip:t.yFlip});else{const r=DOe(e),a=e.coordinateSystem==="cartesian";s=agt(r,o,n,{padding:t.padding??40,yFlip:a})}i.clearRect(0,0,o,n),i.save(),e.rects&&e.rects.length>0&&e.rects.forEach(r=>{const a=r.width/2,g=r.height/2,I=qi(s,{x:r.center.x-a,y:r.center.y-g}),c=qi(s,{x:r.center.x+a,y:r.center.y+g}),B=Math.abs(c.x-I.x),l=Math.abs(c.y-I.y);i.beginPath(),i.rect(Math.min(I.x,c.x),Math.min(I.y,c.y),B,l),r.fill&&(i.fillStyle=r.fill,i.fill()),r.stroke&&(i.strokeStyle=r.stroke,i.stroke())}),e.circles&&e.circles.length>0&&e.circles.forEach(r=>{const a=qi(s,r.center),g=r.radius*Math.abs(s.a);i.beginPath(),i.arc(a.x,a.y,g,0,2*Math.PI),r.fill&&(i.fillStyle=r.fill,i.fill()),r.stroke&&(i.strokeStyle=r.stroke??"transparent",i.stroke())}),e.lines&&e.lines.length>0&&e.lines.forEach((r,a)=>{if(r.points.length===0)return;i.beginPath();const g=qi(s,r.points[0]);i.moveTo(g.x,g.y);for(let I=1;I<r.points.length;I++){const c=qi(s,r.points[I]);i.lineTo(c.x,c.y)}if(i.strokeStyle=r.strokeColor||$V[a%$V.length],r.strokeWidth?i.lineWidth=r.strokeWidth*s.a:i.lineWidth=2,i.lineCap="round",r.strokeDash)if(typeof r.strokeDash=="string"){let I;if(r.strokeDash.includes(","))I=r.strokeDash.split(",").map(c=>parseFloat(c.trim())).filter(c=>!Number.isNaN(c));else{const c=parseFloat(r.strokeDash.trim());I=Number.isNaN(c)?[]:[c]}i.setLineDash(I)}else i.setLineDash(r.strokeDash.map(I=>I*Math.abs(s.a)));else i.setLineDash([]);i.stroke()}),e.points&&e.points.length>0&&e.points.forEach((r,a)=>{const g=qi(s,r);i.beginPath(),i.arc(g.x,g.y,3,0,2*Math.PI),i.fillStyle=r.color||$V[a%$V.length],i.fill(),r.label&&!t.disableLabels&&(i.fillStyle=r.color||"black",i.font="12px sans-serif",i.fillText(r.label,g.x+5,g.y-5))}),e.texts&&e.texts.length>0&&e.texts.forEach(r=>{const a=qi(s,{x:r.x,y:r.y});i.fillStyle=r.color||"black",i.font=`${(r.fontSize??12)*Math.abs(s.a)}px sans-serif`;const g=r.anchorSide??"center",I={top_left:"left",center_left:"left",bottom_left:"left",top_center:"center",center:"center",bottom_center:"center",top_right:"right",center_right:"right",bottom_right:"right"},c={top_left:"top",top_center:"top",top_right:"top",center_left:"middle",center:"middle",center_right:"middle",bottom_left:"bottom",bottom_center:"bottom",bottom_right:"bottom"};i.textAlign=I[g],i.textBaseline=c[g],i.fillText(r.text,a.x,a.y)}),i.restore()}var bOe=({children:e,transform:A,debugGraphics:t})=>{const i=AA.useRef(null),[o,{width:n,height:s}]=ZY(),r=zl(a=>a.is_showing_autorouting);return AA.useEffect(()=>{r&&i.current&&t&&n&&s&&(i.current.width=n,i.current.height=s,SOe(t,i.current,{transform:A,disableLabels:!0}))},[t,A,n,s,r]),r?Z.jsxs("div",{ref:o,style:{position:"relative",width:"100%",height:"100%"},children:[e,Z.jsx("canvas",{ref:i,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):e},xOe=({children:e,transform:A=Bb(),elements:t=[]})=>{const[i,{width:o,height:n}]=ZY(),s=AA.useRef(null);return AA.useEffect(()=>{const r=s.current;if(!r||!o||!n)return;r.width=o,r.height=n;const a=r.getContext("2d");if(!a)return;a.clearRect(0,0,o,n);const g=t.filter(c=>c.type==="pcb_component"),I=t.filter(c=>c.type==="pcb_manual_edit_conflict_warning");a.strokeStyle=mo.board.drc_warning,a.lineWidth=2,I.forEach(c=>{const B=g.find(O=>O.pcb_component_id===c.pcb_component_id);if(!B)return;const{width:l,height:C,center:E}=B,Q=qi(A,E),h=l*Math.abs(A.a),u=C*Math.abs(A.d),d=.1*Math.abs(A.a),f=h+d*2,m=u+d*2,D=Q.x-f/2,w=Q.y-m/2;a.beginPath(),a.rect(D,w,f,m),a.stroke();const b="Manual Edit Conflict",k=4,x=Math.max(8,Math.min(12,10*Math.abs(A.a)));a.font=`${x}px sans-serif`;const M=a.measureText(b).width+k*2,U=x+k*2,J=D+(f-M)/2,H=w+m+5;a.fillStyle="rgba(0, 0, 0, 0.7)",a.beginPath(),a.roundRect(J,H,M,U,3),a.fill(),a.fillStyle=mo.board.drc_warning,a.textAlign="center",a.textBaseline="middle",a.fillText(b,J+M/2,H+U/2)})},[t,A,o,n]),Z.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[e,Z.jsx("canvas",{ref:s,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:EI.warnings}})]})},A9=(e,A,t)=>t(e,A),ggt=(e,A,t,i,o)=>{const n=o*Math.PI/180,s=Math.cos(n),r=Math.sin(n),a=e-t,g=A-i,I=a*s-g*r,c=a*r+g*s;return{x:I+t,y:c+i}},VY=e=>{if(e.length===0)return null;let A=e[0].x,t=e[0].x,i=e[0].y,o=e[0].y;for(const n of e)A=A9(A,n.x,Math.min),t=A9(t,n.x,Math.max),i=A9(i,n.y,Math.min),o=A9(o,n.y,Math.max);return{minX:A,maxX:t,minY:i,maxY:o}},_Oe=(e,A)=>({minX:Math.min(e.minX,A.minX),maxX:Math.max(e.maxX,A.maxX),minY:Math.min(e.minY,A.minY),maxY:Math.max(e.maxY,A.maxY)}),kOe=(e,A)=>e?_Oe(e,A):A,GOe=e=>{switch(e.pcb_drawing_type){case"line":{const A=(e.width??0)/2,t=[{x:e.x1,y:e.y1},{x:e.x2,y:e.y2}],i=VY(t);return i?{minX:i.minX-A,maxX:i.maxX+A,minY:i.minY-A,maxY:i.maxY+A}:null}case"rect":{const A=e.w/2,t=e.h/2,i=[{x:e.x-A,y:e.y-t},{x:e.x+A,y:e.y-t},{x:e.x+A,y:e.y+t},{x:e.x-A,y:e.y+t}],o=e.ccw_rotation??0,n=o===0?i:i.map(s=>ggt(s.x,s.y,e.x,e.y,o));return VY(n)}case"circle":return{minX:e.x-e.r,maxX:e.x+e.r,minY:e.y-e.r,maxY:e.y+e.r};case"oval":return{minX:e.x-e.rX,maxX:e.x+e.rX,minY:e.y-e.rY,maxY:e.y+e.rY};case"pill":{const A=e.w/2,t=e.h/2,i=[{x:e.x-A,y:e.y-t},{x:e.x+A,y:e.y-t},{x:e.x+A,y:e.y+t},{x:e.x-A,y:e.y+t}],o=e.ccw_rotation??0,n=o===0?i:i.map(s=>ggt(s.x,s.y,e.x,e.y,o));return VY(n)}case"polygon":return VY(e.points);case"polygon_with_arcs":{const A=e.brep_shape.outer_ring.vertices.map(t=>({x:t.x,y:t.y}));return VY(A)}case"text":{const A=e.size??0,t=e.text?e.text.length*A*.6:0,i=A;if(t===0&&i===0)return{minX:e.x,maxX:e.x,minY:e.y,maxY:e.y};const o=t/2,n=i/2;return{minX:e.x-o,maxX:e.x+o,minY:e.y-n,maxY:e.y+n}}default:return null}};function FOe(e){const{dimensionStart:A,dimensionEnd:t,screenDimensionStart:i,screenDimensionEnd:o,flipX:n,flipY:s}=e,r=t.x-A.x,a=t.y-A.y,g=Math.sqrt(r*r+a*a),I=o.x-i.x,c=o.y-i.y,B=Math.sqrt(I*I+c*c),l=Math.atan2(c,I)*(180/Math.PI),C=Math.abs(l)%90,Q=Math.min(C,90-C)>15,h=(i.x+o.x)/2,u=(i.y+o.y)/2,d=15,f=l+90;let m=Math.cos(f*Math.PI/180)*d,D=Math.sin(f*Math.PI/180)*d;const w=I>0&&c<0,b=I>0&&c>0,k=I<0&&c>0;n!==s&&!w&&(m=-m,D=-D),w&&(m+=Math.cos(f*Math.PI/180)*-45,D+=Math.sin(f*Math.PI/180)*-45),b&&(m+=Math.cos(f*Math.PI/180)+-20,D+=Math.sin(f*Math.PI/180)+-10),k&&(m+=Math.cos(f*Math.PI/180)*10,D+=Math.sin(f*Math.PI/180)*10);const x=h+m,N=u+D;return{distance:g,screenDistance:B,x,y:N,show:g>.01&&B>30&&Q}}function ROe(e){const{dimensionStart:A,dimensionEnd:t,screenDimensionStart:i,screenDimensionEnd:o,flipX:n,flipY:s}=e;return AA.useMemo(()=>FOe({dimensionStart:A,dimensionEnd:t,screenDimensionStart:i,screenDimensionEnd:o,flipX:n,flipY:s}),[A,t,i,o,n,s])}var MOe=(e,A,t)=>{const i=t*Math.PI/180,o=Math.cos(i),n=Math.sin(i),s=e.x-A.x,r=e.y-A.y,a=s*o-r*n,g=s*n+r*o;return{x:a+A.x,y:g+A.y}},Igt=(e,A,t,i)=>{const o={top_left:{x:e.x-A,y:e.y-t},top_center:{x:e.x,y:e.y-t},top_right:{x:e.x+A,y:e.y-t},center_left:{x:e.x-A,y:e.y},center:{x:e.x,y:e.y},center_right:{x:e.x+A,y:e.y},bottom_left:{x:e.x-A,y:e.y+t},bottom_center:{x:e.x,y:e.y+t},bottom_right:{x:e.x+A,y:e.y+t}};return i===0?Object.entries(o).map(([n,s])=>({anchor:n,point:s})):Object.entries(o).map(([n,s])=>({anchor:n,point:MOe(s,e,i)}))},NOe=e=>{switch(e.pcb_drawing_type){case"rect":{const A=e.ccw_rotation??0;return Igt({x:e.x,y:e.y},e.w/2,e.h/2,A)}case"pill":{const A=e.ccw_rotation??0;return Igt({x:e.x,y:e.y},e.w/2,e.h/2,A)}case"circle":return[{anchor:"circle_center",point:{x:e.x,y:e.y}},{anchor:"circle_right",point:{x:e.x+e.r,y:e.y}},{anchor:"circle_left",point:{x:e.x-e.r,y:e.y}},{anchor:"circle_top",point:{x:e.x,y:e.y-e.r}},{anchor:"circle_bottom",point:{x:e.x,y:e.y+e.r}}];case"oval":return[{anchor:"oval_center",point:{x:e.x,y:e.y}},{anchor:"oval_right",point:{x:e.x+e.rX,y:e.y}},{anchor:"oval_left",point:{x:e.x-e.rX,y:e.y}},{anchor:"oval_top",point:{x:e.x,y:e.y-e.rY}},{anchor:"oval_bottom",point:{x:e.x,y:e.y+e.rY}}];case"line":{const A={x:(e.x1+e.x2)/2,y:(e.y1+e.y2)/2};return[{anchor:"line_start",point:{x:e.x1,y:e.y1}},{anchor:"line_mid",point:A},{anchor:"line_end",point:{x:e.x2,y:e.y2}}]}case"polygon":return e.points.map((A,t)=>({anchor:`polygon_vertex_${t}`,point:A}));case"polygon_with_arcs":return e.brep_shape.outer_ring.vertices.map((A,t)=>({anchor:`polygon_with_arcs_vertex_${t}`,point:{x:A.x,y:A.y}}));default:return[]}},vOe=16,lF=5,cgt=e=>{if(e.pcb_drawing_type==="text")return!0;const A=e._element;if(!A||typeof A!="object")return!1;const t=typeof A.type=="string"?A.type:void 0;return t?!!(t.startsWith("pcb_silkscreen_")||t.startsWith("pcb_note_")||t==="pcb_text"||t.startsWith("pcb_fabrication_note_")&&t!=="pcb_fabrication_note_rect"):!1},LOe=({children:e,transform:A,focusOnHover:t=!1,primitives:i=[]})=>{A||(A=Bb());const[o,n]=AA.useState(!1),[s,r]=AA.useState(!1),[a,g]=AA.useState(!1),[I,c]=AA.useState({start:null,end:null}),B=zl(H=>H.is_mouse_over_container),l=AA.useCallback(()=>{a&&(g(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[a]),[C,E]=AA.useState({x:0,y:0}),[Q,h]=AA.useState({x:0,y:0}),u=AA.useRef({x:0,y:0}),d=AA.useRef(null),m=d.current?.getBoundingClientRect(),D=AA.useMemo(()=>{const H=new Map;for(const O of i){if(!O._element||cgt(O)||O.pcb_drawing_type==="pill"||O.pcb_drawing_type==="rect"&&O.ccw_rotation&&O.ccw_rotation!==0)continue;const W=GOe(O);if(!W)continue;const $=H.get(O._element);H.set(O._element,kOe($??void 0,W))}return H},[i]),w=AA.useMemo(()=>{const H=[];for(const O of i){if(!O._element||cgt(O))continue;const W=NOe(O);if(W.length!==0)for(const $ of W)H.push({anchor:$.anchor,point:$.point,element:O._element})}return H},[i]),b=AA.useMemo(()=>{const H=[];D.forEach((O,W)=>{if(!O)return;const $=(O.minX+O.maxX)/2,iA=(O.minY+O.maxY)/2,rA={top_left:{x:O.minX,y:O.minY},top_center:{x:$,y:O.minY},top_right:{x:O.maxX,y:O.minY},center_left:{x:O.minX,y:iA},center:{x:$,y:iA},center_right:{x:O.maxX,y:iA},bottom_left:{x:O.minX,y:O.maxY},bottom_center:{x:$,y:O.maxY},bottom_right:{x:O.maxX,y:O.maxY}};for(const[tA,nA]of Object.entries(rA))H.push({anchor:tA,point:nA,element:W})});for(const O of w)H.push(O);return H.push({anchor:"origin",point:{x:0,y:0},element:null}),H},[D,w]),k=AA.useMemo(()=>b.map((H,O)=>({...H,id:`${O}-${H.anchor}`,screenPoint:qi(A,H.point)})),[b,A]),x=AA.useCallback(H=>{if(k.length===0)return{point:H,id:null};const O=qi(A,H);let W=null;for(const $ of k){const iA=$.screenPoint.x-O.x,rA=$.screenPoint.y-O.y,tA=Math.hypot(iA,rA);tA>vOe||(!W||tA<W.distance)&&(W={distance:tA,id:$.id,point:$.point})}return W?{point:W.point,id:W.id}:{point:H,id:null}},[k,A]);AA.useEffect(()=>{const H=W=>{const $=W.target;if($.tagName==="INPUT"||$.tagName==="TEXTAREA"||$.isContentEditable)return;const iA=d.current?.contains(document.activeElement)||document.activeElement===d.current;if(!(!B&&!iA)){if(W.key==="d"){const rA=x({x:u.current.x,y:u.current.y});E({x:rA.point.x,y:rA.point.y}),h({x:rA.point.x,y:rA.point.y}),c({start:rA.id,end:rA.id}),o?(n(!1),r(!1),c({start:null,end:null})):(n(!0),r(!0)),l()}W.key==="Escape"&&(n(!1),r(!1),c({start:null,end:null}),l())}},O=()=>{g(!0)};return window.addEventListener("keydown",H),window.addEventListener("arm-dimension-tool",O),()=>{window.removeEventListener("keydown",H),window.removeEventListener("arm-dimension-tool",O),l()}},[B,o,l,x]);const N=qi(A,C),M=qi(A,Q),U={left:Math.min(N.x,M.x),right:Math.max(N.x,M.x),top:Math.min(N.y,M.y),bottom:Math.max(N.y,M.y),flipX:N.x>M.x,flipY:N.y>M.y,width:0,height:0};U.width=U.right-U.left,U.height=U.bottom-U.top;const J=ROe({dimensionStart:C,dimensionEnd:Q,screenDimensionStart:N,screenDimensionEnd:M,flipX:U.flipX,flipY:U.flipY});return Z.jsxs("div",{ref:d,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseEnter:()=>{t&&d.current&&d.current.focus()},onMouseLeave:()=>{d.current&&d.current.blur()},onClick:()=>{d.current&&d.current.focus()},onMouseMove:H=>{const O=H.currentTarget.getBoundingClientRect(),W=H.clientX-O.left,$=H.clientY-O.top,iA=qi(lb(A),{x:W,y:$});if(u.current.x=iA.x,u.current.y=iA.y,s){const rA=x(iA);h({x:rA.point.x,y:rA.point.y}),c(tA=>({...tA,end:rA.id}))}},onMouseDown:H=>{const O=H.currentTarget.getBoundingClientRect(),W=H.clientX-O.left,$=H.clientY-O.top,iA=qi(lb(A),{x:W,y:$});if(a&&!o){const rA=x(iA);E({x:rA.point.x,y:rA.point.y}),h({x:rA.point.x,y:rA.point.y}),c({start:rA.id,end:rA.id}),n(!0),r(!0),l()}else s?(r(!1),c(rA=>({...rA,end:null}))):o&&(n(!1),c({start:null,end:null}))},children:[e,o&&Z.jsxs(Z.Fragment,{children:[J.show&&Z.jsx("div",{style:{position:"absolute",left:J.x,top:J.y,color:"red",mixBlendMode:"difference",pointerEvents:"none",fontSize:12,fontFamily:"sans-serif",whiteSpace:"nowrap",zIndex:EI.dimensionOverlay},children:J.distance.toFixed(2)}),Z.jsx("div",{style:{position:"absolute",left:U.left,width:U.width,textAlign:"center",top:N.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:U.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:EI.dimensionOverlay},children:Math.abs(C.x-Q.x).toFixed(2)}),Z.jsx("div",{style:{position:"absolute",left:M.x,height:U.height,display:"flex",flexDirection:"column",justifyContent:"center",top:U.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:EI.dimensionOverlay},children:Z.jsx("div",{style:{marginLeft:U.flipX?"-100%":4,paddingRight:4},children:Math.abs(C.y-Q.y).toFixed(2)})}),Z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:EI.dimensionOverlay},width:m.width,height:m.height,children:[Z.jsx("defs",{children:Z.jsx("marker",{id:"head",orient:"auto",markerWidth:"3",markerHeight:"4",refX:"2",refY:"2",children:Z.jsx("path",{d:"M0,0 V4 L2,2 Z",fill:"red"})})}),Z.jsx("line",{x1:N.x,y1:N.y,x2:M.x,y2:M.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),Z.jsx("line",{x1:N.x,y1:N.y,x2:M.x,y2:N.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),Z.jsx("line",{x1:M.x,y1:N.y,x2:M.x,y2:M.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"})]}),s&&k.map(H=>{const O=H.id===I.start||H.id===I.end,W=lF/2;return Z.jsxs("svg",{width:lF,height:lF,style:{position:"absolute",left:H.screenPoint.x-W,top:H.screenPoint.y-W,pointerEvents:"none",zIndex:EI.dimensionOverlay},children:[Z.jsx("line",{x1:0,y1:0,x2:lF,y2:lF,stroke:O?"#66ccff":"white",strokeWidth:1}),Z.jsx("line",{x1:lF,y1:0,x2:0,y2:lF,stroke:O?"#66ccff":"white",strokeWidth:1})]},H.id)}),Z.jsxs("div",{style:{right:0,bottom:0,position:"absolute",color:"red",fontFamily:"sans-serif",fontSize:12,margin:4},children:["(",C.x.toFixed(2),",",C.y.toFixed(2),")",Z.jsx("br",{}),"(",Q.x.toFixed(2),",",Q.y.toFixed(2),")",Z.jsx("br",{}),"dist:"," ",Math.sqrt((Q.x-C.x)**2+(Q.y-C.y)**2).toFixed(2)]})]})]})},UOe=(e,A,t=0)=>{const i=e.width/2,o=e.height/2,n=e.center.x-i-t,s=e.center.x+i+t,r=e.center.y-o-t,a=e.center.y+o+t;return A.x>n&&A.x<s&&A.y>r&&A.y<a},HOe=({children:e,disabled:A,transform:t,soup:i,cancelPanDrag:o,onCreateEditEvent:n,onModifyEditEvent:s})=>{t||(t=Bb());const r=AA.useRef(null),[a,g]=AA.useState(null),[I,c]=AA.useState(null),B=a!==null;zl(Q=>Q.in_edit_mode);const l=zl(Q=>Q.in_move_footprint_mode),C=zl(Q=>Q.setIsMovingComponent),E=A||!l;return Z.jsxs("div",{ref:r,style:{position:"relative",overflow:"hidden"},onMouseDown:Q=>{if(E)return;const h=Q.currentTarget.getBoundingClientRect(),u=Q.clientX-h.left,d=Q.clientY-h.top;if(Number.isNaN(u)||Number.isNaN(d))return;const f=qi(lb(t),{x:u,y:d});let m=!1;for(const D of i)if(D.type==="pcb_component"&&UOe(D,f,10/t.a)){o(),g(D.pcb_component_id),m=!0;const w=Math.random().toString();c({dragStart:f,originalCenter:D.center,dragEnd:f,edit_event_id:w}),n({edit_event_id:w,edit_event_type:"edit_pcb_component_location",pcb_edit_event_type:"edit_component_location",pcb_component_id:D.pcb_component_id,original_center:D.center,new_center:D.center,in_progress:!0,created_at:Date.now()}),C(!0);break}if(m||g(null),m)return Q.preventDefault(),!1},onMouseMove:Q=>{if(!a||!I)return;const h=Q.currentTarget.getBoundingClientRect(),u=Q.clientX-h.left,d=Q.clientY-h.top;if(Number.isNaN(u)||Number.isNaN(d))return;const f=qi(lb(t),{x:u,y:d});c({...I,dragEnd:f}),s({edit_event_id:I.edit_event_id,new_center:{x:I.originalCenter.x+f.x-I.dragStart.x,y:I.originalCenter.y+f.y-I.dragStart.y}})},onMouseUp:Q=>{a&&(g(null),C(!1),I&&(s({edit_event_id:I.edit_event_id,in_progress:!1}),c(null)))},children:[e,!E&&i.filter(Q=>Q.type==="pcb_component").map(Q=>{if(!Q?.center)return null;const h=qi(t,Q.center);return Z.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:h.x,top:h.y,width:Q.width*t.a+20,height:Q.height*t.a+20,transform:"translate(-50%, -50%)",background:B&&a===Q.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},Q.pcb_component_id)})]})},YOe=({hotkeys:e})=>(AA.useEffect(()=>{const A=t=>{e.forEach(i=>{t.key===i.key&&i.onUse()})};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A)}},[e]),Z.jsx("div",{className:Uv`
5430
5430
  display: flex;
5431
5431
  flex-direction: column;
5432
5432
  font-family: sans-serif;
@@ -5465,7 +5465,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function Yat(e,A,t){if(!A||!t)retu
5465
5465
  transition: opacity 0.2s;
5466
5466
  margin-bottom: 10px;
5467
5467
  color: red;
5468
- `,OOe=({children:e,transform:A=Bb(),elements:t})=>{const i=AA.useRef(null),{isShowingDRCErrors:o,hoveredErrorId:n}=zl(g=>({isShowingDRCErrors:g.is_showing_drc_errors,hoveredErrorId:g.hovered_error_id}));if(!t)return Z.jsx("div",{style:{position:"relative"},ref:i,children:e});const s=t.filter(g=>g.type==="pcb_trace_error"),r=t.filter(g=>g.type==="pcb_trace_error"&&g.message?.includes("Multiple components found with name")),a=new Map;return t.forEach(g=>{g.type==="pcb_port"&&a.set(g.pcb_port_id,g)}),Z.jsxs("div",{style:{position:"relative"},ref:i,children:[e,s.map((g,I)=>{const{pcb_port_ids:c,pcb_trace_id:B}=g,l=c?.[0]?a.get(c[0]):void 0,C=c?.[1]?a.get(c[1]):void 0,E=t?Qb(t).pcb_trace.get(B):void 0,Q=g.pcb_trace_error_id||`error_${I}_${g.error_type}_${g.message?.slice(0,20)}`,h=n===Q;if(l&&C){const u=qi(A,{x:l.x,y:l.y}),d=qi(A,{x:C.x,y:C.y}),f=!(isNaN(u.x)||isNaN(u.y)||isNaN(d.x)||isNaN(d.y)),m={x:(u.x+d.x)/2,y:(u.y+d.y)/2};if(isNaN(m.x)||isNaN(m.y))return null;const D=SpA(m,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx(POe,{screenPort1:u,screenPort2:d,errorCenter:m,canLineBeDrawn:f,isHighlighted:h}),Z.jsx("div",{style:{position:"absolute",left:m.x-15,top:m.y-15,width:30,height:30,zIndex:EI.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:w=>{const b=w.currentTarget.nextElementSibling;if(b){const k=b.querySelector(".error-message");k&&(k.style.opacity="1")}},onMouseLeave:w=>{if(!h){const b=w.currentTarget.nextElementSibling;if(b){const k=b.querySelector(".error-message");k&&(k.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:h?200:100,left:D.left,top:D.top,color:h?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:o||h?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:D.transform},children:Z.jsx("div",{className:`error-message ${bpA}`,style:{opacity:h?1:0,border:`1px solid ${h?"#ff4444":"red"}`},children:g.message})})]},Q)}if(E?.route&&(o||h)){const u=E.route.map(D=>qi(A,{x:D.x,y:D.y}));if(u.some(D=>isNaN(D.x)||isNaN(D.y)))return null;const d=Math.floor(u.length/2),f=u[d],m=SpA(f,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx(qOe,{points:u,errorCenter:f,isHighlighted:h}),Z.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:EI.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:D=>{const w=D.currentTarget.nextElementSibling;if(w){const b=w.querySelector(".error-message");b&&(b.style.opacity="1")}},onMouseLeave:D=>{if(!h){const w=D.currentTarget.nextElementSibling;if(w){const b=w.querySelector(".error-message");b&&(b.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:h?EI.errorOverlay+10:EI.errorOverlay+1,left:m.left,top:m.top,color:h?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:m.transform},children:Z.jsx("div",{className:`error-message ${bpA}`,style:{opacity:h?1:0,border:`1px solid ${h?"#ff4444":"red"}`},children:g.message})})]},Q)}return null}),r.map((g,I)=>{const c=g.component_name||g.message?.match(/name "([^"]+)"/)?.[1];if(!c)return null;const B=t?.filter(E=>E.type==="source_component"&&E.name===c||E.type==="pcb_component"&&t?.find(Q=>Q.type==="source_component"&&Q.source_component_id===E.source_component_id&&Q.name===c))||[],l=g.pcb_trace_error_id||`error_${I}_${g.error_type}_${g.message?.slice(0,20)}`,C=n===l;return!C&&!o?null:B.map((E,Q)=>{let h={x:0,y:0};if(E.type==="pcb_component")h=E.center||{x:0,y:0};else if(E.type==="source_component"){const k=t?.find(x=>x.type==="pcb_component"&&x.source_component_id===E.source_component_id);k&&k.type==="pcb_component"&&(h=k.center||{x:0,y:0})}const u=qi(A,h);if(isNaN(u.x)||isNaN(u.y))return null;const d=Math.abs(A.a),w=Math.max(8,Math.min(30,.5*d)),b=SpA(u,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:EI.errorOverlay},width:"100%",height:"100%",children:C?Z.jsx("polygon",{points:`${u.x},${u.y-w*1.25} ${u.x+w},${u.y} ${u.x},${u.y+w*1.25} ${u.x-w},${u.y}`,fill:"#ff4444"}):Z.jsx("circle",{cx:u.x,cy:u.y,r:w,fill:"none",stroke:C?"#ff4444":"red",strokeWidth:C?Math.max(2,w*.15):Math.max(1,w*.1),opacity:1})}),Z.jsx("div",{style:{position:"absolute",left:u.x-(w+10),top:u.y-(w+10),width:(w+10)*2,height:(w+10)*2,zIndex:EI.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:k=>{const x=k.currentTarget.nextElementSibling;if(x){const N=x.querySelector(".error-message");N&&(N.style.opacity="1")}},onMouseLeave:k=>{if(!C){const x=k.currentTarget.nextElementSibling;if(x){const N=x.querySelector(".error-message");N&&(N.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:C?EI.errorOverlay+20:EI.errorOverlay+10,left:b.left,top:b.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:o||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:b.transform},children:Z.jsx("div",{className:`error-message ${bpA}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:g.message})})]},`${l}_${Q}`)})})]})};function WOe(e,A){return e.size!==A.size?!1:Array.from(e).every(t=>A.has(t))}function ZOe({primitiveElement:e,elements:A}){let t=e.trace_length?`${e.trace_length.toFixed(3)}`:"";const i=Qb(A).source_trace.get(e?.source_trace_id);if(i?.display_name&&(i?.max_length?t+=` / ${i.max_length}mm `:t+=" mm ",t+=`(${i.display_name})`),!t)return null;const o=e.trace_length&&i?.max_length&&e.trace_length>i.max_length;return{text:t,isOverLength:o}}function VOe(e){const{primitives:A,is_showing_multiple_traces_length:t,elements:i}=e,o=A.filter(a=>a._element.type==="pcb_trace"),n=i.filter(a=>a.type==="source_trace"),s=A.filter(a=>a._element.type!=="pcb_trace"),r=o.filter(a=>n.some(g=>a._element.type==="pcb_trace"&&a._element.source_trace_id===g.source_trace_id&&g.max_length!==void 0));if(!t)return[...s,...r];if(o.length>1){const a=o.reduce((g,I)=>{const c=g._element.trace_length;return I._element.trace_length<c?I:g},o[0]);return[...s,a]}return A}var jOe={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},zOe=e=>{const{_element:A,_parent_pcb_component:t,_parent_source_component:i,_source_port:o}=e;switch(A.type){case"pcb_trace":return A.trace_length?`${A.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const n=[],s=Array.from(new Set((A.port_hints??[]).concat(o?.port_hints??[]))).filter(a=>!/^[0-9]+$/.test(a)).filter(a=>!a.includes("unnamed_")).sort((a,g)=>g.localeCompare(a)),r=i&&"name"in i&&i.name&&!i.name.includes("unnamed_")?i.name:null;return s.length>0?r?n.push(...s.map(a=>`${r}.${a}`)):n.push(...s):r&&n.push(r),n.join(", ")}default:return""}},XOe={top:"red",bottom:"aqua"},$Oe=({primitive:e,mousePos:A,elements:t})=>{const[i,o]=AA.useState(!1),n=e._element;AA.useEffect(()=>{setTimeout(()=>{o(!0)},100)},[]);const[s,r,a,g]=[e.screen_x,e.screen_y,e.screen_w,e.screen_h],I=e.same_space_index??0,c=26,B=XOe[e?._element?.layer]??"red";let l=0;if(n.type==="pcb_smtpad"&&n?.shape==="rotated_rect"?l=n?.ccw_rotation??0:(n.type==="pcb_smtpad"&&(n?.shape==="pill"||n?.shape==="rotated_pill")&&"ccw_rotation"in e||n.type==="pcb_plated_hole"&&(n?.shape==="pill"||n?.shape==="oval")&&"ccw_rotation"in e)&&(l=n.ccw_rotation??0),n.type==="pcb_trace"){const Q=ZOe({primitiveElement:n,elements:t});if(!Q)return null;const h=A.y-35;return Z.jsx("div",{style:{zIndex:EI.elementOverlay,position:"absolute",left:A.x,top:h,color:B,pointerEvents:"none",transform:"translateX(-50%)"},children:Z.jsx("div",{style:{backgroundColor:"#f2efcc",color:Q.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:Q.text})})}const C=zOe(e);return C.trim().length===0?null:Z.jsx("div",{style:{zIndex:EI.elementOverlay,position:"absolute",left:s-a/2-8,top:r-g/2-8,width:a+16,height:g+16,color:B,transform:`rotate(${-l}deg)`,transformOrigin:"center center"},children:Z.jsx("div",{style:{width:i?`calc(100% + ${c*2*I}px)`:"100%",height:i?`calc(100% + ${c*2*I}px)`:"100%",marginLeft:i?`${-c*I}px`:0,marginTop:i?`${-c*I}px`:0,border:`1px solid ${B}`,opacity:i||I===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:Z.jsx("div",{style:{position:"absolute",bottom:g+20+c*I,marginRight:i?`${-c*I}px`:0,marginBottom:i?0:-c*I,transition:"margin-right 0.2s, margin-bottom 0.2s",backgroundColor:"#f2efcc",color:"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",transform:`rotate(${l}deg)`,minWidth:"45px",textAlign:"center"},children:C})})})},A5e=({highlightedPrimitives:e,mousePos:A,elements:t})=>{const[i,o]=zl(r=>[r.is_moving_component,r.is_showing_multiple_traces_length]),n=e.some(r=>r._element.type==="pcb_smtpad")&&e.some(r=>r._element.type==="pcb_trace");let s=e;return n&&(s=s.filter(r=>r._element.type==="pcb_smtpad")),s=VOe({primitives:s,is_showing_multiple_traces_length:o,elements:t}),Z.jsx("div",{style:jOe,children:!i&&s.map((r,a)=>Z.jsx($Oe,{primitive:r,mousePos:A,elements:t},a))})},J_=e=>e?.type==="pcb_component",Bgt=e=>e?.type==="pcb_group",t5e=e=>e?.type==="pcb_panel",xpA=e=>e?.type==="pcb_board",WI={MIN_LINE_LENGTH_FOR_LABEL:40,LABEL_OFFSET_ABOVE:2,LABEL_OFFSET_BELOW:-18,LABEL_OFFSET_RIGHT:8,LABEL_OFFSET_LEFT:-120,Y_LABEL_MIN_WIDTH:110,LINE_STROKE_WIDTH:1.5,LINE_DASH_PATTERN:"4,4",COMPONENT_MARKER_RADIUS:3,LABEL_FONT_SIZE:11,ANCHOR_MARKER_SIZE:6,ANCHOR_MARKER_STROKE_WIDTH:1.5},S0={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},_pA=({targets:e,transform:A,containerWidth:t,containerHeight:i})=>{if(e.length===0)return null;const o={color:S0.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:WI.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},n=new Map;return e.forEach(s=>{if(!n.has(s.anchor_id)){const r=qi(A,s.anchor);n.set(s.anchor_id,r)}}),Z.jsx("div",{style:{position:"absolute",left:0,top:0,width:t,height:i,overflow:"hidden",pointerEvents:"none",zIndex:EI.dimensionOverlay},children:Z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:t,height:i,children:[e.map(s=>{const r=s.anchor,a=s.anchor_id,g=s.target,I=n.get(a),c=qi(A,g),B=g.x-r.x,l=g.y-r.y,C=Math.abs(c.x-I.x),E=Math.abs(c.y-I.y),Q=c.y<I.y,h=c.x>I.x,u=Q?WI.LABEL_OFFSET_ABOVE:WI.LABEL_OFFSET_BELOW,d=h?WI.LABEL_OFFSET_RIGHT:WI.LABEL_OFFSET_LEFT,f=C>WI.MIN_LINE_LENGTH_FOR_LABEL,m=E>WI.MIN_LINE_LENGTH_FOR_LABEL,D=`${s.display_offset_x??B.toFixed(2)}mm`,w=`${s.display_offset_y??l.toFixed(2)}mm`;return Z.jsxs("g",{children:[Z.jsx("line",{x1:I.x,y1:I.y,x2:c.x,y2:I.y,stroke:S0.OFFSET_LINE,strokeWidth:WI.LINE_STROKE_WIDTH,strokeDasharray:WI.LINE_DASH_PATTERN}),Z.jsx("line",{x1:c.x,y1:I.y,x2:c.x,y2:c.y,stroke:S0.OFFSET_LINE,strokeWidth:WI.LINE_STROKE_WIDTH,strokeDasharray:WI.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?Z.jsx("circle",{cx:c.x,cy:c.y,r:WI.COMPONENT_MARKER_RADIUS,fill:S0.COMPONENT_MARKER_FILL,stroke:S0.COMPONENT_MARKER_STROKE,strokeWidth:1}):Z.jsxs(Z.Fragment,{children:[Z.jsx("line",{x1:c.x-WI.ANCHOR_MARKER_SIZE,y1:c.y,x2:c.x+WI.ANCHOR_MARKER_SIZE,y2:c.y,stroke:S0.OFFSET_LINE,strokeWidth:WI.ANCHOR_MARKER_STROKE_WIDTH}),Z.jsx("line",{x1:c.x,y1:c.y-WI.ANCHOR_MARKER_SIZE,x2:c.x,y2:c.y+WI.ANCHOR_MARKER_SIZE,stroke:S0.OFFSET_LINE,strokeWidth:WI.ANCHOR_MARKER_STROKE_WIDTH})]}),f&&Z.jsx("foreignObject",{x:Math.min(I.x,c.x),y:I.y+u,width:Math.abs(c.x-I.x),height:20,style:{overflow:"visible"},children:Z.jsx("div",{style:{...o,textAlign:"center"},children:D})}),m&&Z.jsx("foreignObject",{x:c.x+d,y:Math.min(I.y,c.y),width:WI.Y_LABEL_MIN_WIDTH,height:Math.abs(c.y-I.y),style:{overflow:"visible"},children:Z.jsx("div",{style:{...o,display:"flex",alignItems:"center",justifyContent:h?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:w})})]},s.id)}),Array.from(n.entries()).map(([s,r])=>Z.jsxs("g",{children:[Z.jsx("line",{x1:r.x-WI.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+WI.ANCHOR_MARKER_SIZE,y2:r.y,stroke:S0.OFFSET_LINE,strokeWidth:WI.ANCHOR_MARKER_STROKE_WIDTH}),Z.jsx("line",{x1:r.x,y1:r.y-WI.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+WI.ANCHOR_MARKER_SIZE,stroke:S0.OFFSET_LINE,strokeWidth:WI.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},e5e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:o})=>{const n=e.filter(h=>xpA(h)),s=e.filter(h=>J_(h)),r=e.filter(h=>Bgt(h)),a=A.map(h=>J_(h._parent_pcb_component)?h._parent_pcb_component.pcb_component_id:J_(h._element)?h._element.pcb_component_id:null).filter(h=>!!h),g=new Set;if(a.forEach(h=>{const u=s.find(d=>d.pcb_component_id===h);u?.pcb_group_id&&g.add(u.pcb_group_id)}),!zl(h=>h.is_showing_group_anchor_offsets)&&a.length===0)return null;const c=s.map(h=>{const u=h.positioned_relative_to_pcb_board_id;if(!u)return null;const d=n.find(f=>f.pcb_board_id===u);return d?{component:h,board:d,type:"component"}:null}).filter(h=>!!h),B=r.map(h=>{const u=h.positioned_relative_to_pcb_board_id;if(!u||!h.center)return null;const d=n.find(f=>f.pcb_board_id===u);return d?{group:h,board:d,type:"group"}:null}).filter(h=>!!h),l=[...c,...B];if(l.length===0)return null;const C=a.length===0,E=l.filter(h=>h.type==="component"?C||a.includes(h.component.pcb_component_id):C||g.has(h.group.pcb_group_id));if(E.length===0)return null;const Q=E.map(h=>h.type==="component"?{id:`${h.board.pcb_board_id}-${h.component.pcb_component_id}-${h.type}`,anchor:h.board.center,anchor_id:h.board.pcb_board_id,target:h.component.center,type:"component",display_offset_x:h.component.display_offset_x,display_offset_y:h.component.display_offset_y}:{id:`${h.board.pcb_board_id}-${h.group.pcb_group_id}-${h.type}`,anchor:h.board.center,anchor_id:h.board.pcb_board_id,target:{x:h.group.anchor_position?.x??h.group.center.x,y:h.group.anchor_position?.y??h.group.center.y},type:"group",display_offset_x:h.group.display_offset_x,display_offset_y:h.group.display_offset_y}).filter(h=>!!h);return Z.jsx(_pA,{targets:Q,transform:t,containerWidth:i,containerHeight:o})},i5e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:o})=>{const n=e.filter(h=>Bgt(h)),s=e.filter(h=>J_(h)),r=A.map(h=>J_(h._parent_pcb_component)?h._parent_pcb_component.pcb_component_id:J_(h._element)?h._element.pcb_component_id:null).filter(h=>!!h),a=(h,u)=>{if(u.has(h))return;u.add(h);const d=n.find(f=>f.pcb_group_id===h);d?.position_mode==="relative_to_group_anchor"&&d.positioned_relative_to_pcb_group_id&&a(d.positioned_relative_to_pcb_group_id,u)},g=new Set;if(r.forEach(h=>{const u=s.find(d=>d.pcb_component_id===h);u&&(u.position_mode==="relative_to_group_anchor"&&u.positioned_relative_to_pcb_group_id&&a(u.positioned_relative_to_pcb_group_id,g),u.pcb_group_id&&a(u.pcb_group_id,g))}),!zl(h=>h.is_showing_group_anchor_offsets)&&r.length===0)return null;const c=s.map(h=>{if(h.position_mode==="relative_to_group_anchor"&&h.positioned_relative_to_pcb_group_id){const u=n.find(d=>d.pcb_group_id===h.positioned_relative_to_pcb_group_id);return u&&u.anchor_position?{component:h,parentGroup:u,type:"component"}:null}if(h.pcb_group_id){const u=n.find(d=>d.pcb_group_id===h.pcb_group_id);return u&&u.anchor_position?{component:h,parentGroup:u,type:"component"}:null}return null}).filter(h=>!!h),B=n.map(h=>{if(h.position_mode==="relative_to_group_anchor"&&h.positioned_relative_to_pcb_group_id){const u=n.find(d=>d.pcb_group_id===h.positioned_relative_to_pcb_group_id);if(u&&u.anchor_position&&h.anchor_position)return{group:h,parentGroup:u,type:"group"}}return null}).filter(h=>!!h),l=[...c,...B];if(l.length===0)return null;const C=r.length===0,E=l.filter(h=>h.type==="component"?C||r.includes(h.component.pcb_component_id):C||g.has(h.group.pcb_group_id)||g.has(h.parentGroup.pcb_group_id));if(E.length===0)return null;const Q=E.map(h=>{const u=h.parentGroup.anchor_position;return u?h.type==="component"?h.component.center?{id:`${h.parentGroup.pcb_group_id}-${h.component.pcb_component_id}-${h.type}`,anchor:u,anchor_id:h.parentGroup.pcb_group_id,target:h.component.center,type:"component",display_offset_x:h.component.display_offset_x,display_offset_y:h.component.display_offset_y}:null:h.group.anchor_position?{id:`${h.parentGroup.pcb_group_id}-${h.group.pcb_group_id}-${h.type}`,anchor:u,anchor_id:h.parentGroup.pcb_group_id,target:h.group.anchor_position,type:"group",display_offset_x:h.group.display_offset_x,display_offset_y:h.group.display_offset_y}:null:null}).filter(h=>!!h);return Z.jsx(_pA,{targets:Q,transform:t,containerWidth:i,containerHeight:o})},o5e=(e,A)=>{const t=e.pcb_component_id,i=A.filter(o=>(o.type==="pcb_smtpad"||o.type==="pcb_plated_hole")&&o.pcb_component_id===t||o.type==="pcb_hole"&&o.pcb_component_id===t);return i.length===0?wpA([e]):wpA(i)},n5e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:o})=>{const n=new Map;for(const r of A)J_(r._parent_pcb_component)&&n.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),J_(r._element)&&n.set(r._element.pcb_component_id,r._element);if(n.size===0)return null;const s=[];for(const r of n.values()){const a=o5e(r,e);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,I=g?Qb(e).pcb_group.get(g):null;s.push({component:r,bbox:a,group:I})}return s.length===0?null:Z.jsx("div",{style:{position:"absolute",left:0,top:0,width:i,height:o,overflow:"hidden",pointerEvents:"none",zIndex:EI.dimensionOverlay},children:Z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:i,height:o,children:s.map(({component:r,bbox:a,group:g})=>{const I=qi(t,{x:a.minX,y:a.maxY}),c=qi(t,{x:a.maxX,y:a.minY}),B={x:Math.min(I.x,c.x),y:Math.min(I.y,c.y),width:Math.abs(c.x-I.x),height:Math.abs(c.y-I.y)},l=r.center??{x:(a.minX+a.maxX)/2,y:(a.minY+a.maxY)/2},C=qi(t,l);return Z.jsxs("g",{children:[Z.jsx("rect",{x:B.x,y:B.y,width:B.width,height:B.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),Z.jsx("line",{x1:C.x-6,y1:C.y,x2:C.x+6,y2:C.y,stroke:S0.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),Z.jsx("line",{x1:C.x,y1:C.y-6,x2:C.x,y2:C.y+6,stroke:S0.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),Z.jsx("circle",{cx:C.x,cy:C.y,r:WI.COMPONENT_MARKER_RADIUS,fill:S0.COMPONENT_MARKER_FILL,stroke:S0.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},s5e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:o})=>{const n=e.filter(l=>t5e(l)),s=e.filter(l=>xpA(l)),r=A.map(l=>xpA(l._element)?l._element.pcb_board_id:null).filter(l=>!!l);if(!zl(l=>l.is_showing_group_anchor_offsets)&&r.length===0)return null;const g=s.map(l=>{const C=l.pcb_panel_id,E=l.position_mode;if(!C||E!=="relative_to_panel_anchor")return null;const Q=n.find(h=>h.pcb_panel_id===C);return Q?{board:l,panel:Q,type:"board"}:null}).filter(l=>!!l);if(g.length===0)return null;const I=r.length===0,c=g.filter(l=>I||r.includes(l.board.pcb_board_id));if(c.length===0)return null;const B=c.map(l=>l.board.center?{id:`${l.panel.pcb_panel_id}-${l.board.pcb_board_id}-${l.type}`,anchor:l.panel.center,anchor_id:l.panel.pcb_panel_id,target:l.board.center,type:"board",display_offset_x:l.board.display_offset_x,display_offset_y:l.board.display_offset_y}:null).filter(l=>!!l);return Z.jsx(_pA,{targets:B,transform:t,containerWidth:i,containerHeight:o})},t9=e=>{if(e.length===0)return null;let A=e[0].x,t=e[0].y,i=e[0].x,o=e[0].y;for(const n of e)n.x<A&&(A=n.x),n.y<t&&(t=n.y),n.x>i&&(i=n.x),n.y>o&&(o=n.y);return{center:{x:(A+i)/2,y:(t+o)/2},width:i-A,height:o-t}},lgt=(e,A)=>{if(A.length<3)return!1;let t=!1;for(let i=0,o=A.length-1;i<A.length;o=i++){const n=A[i].x,s=A[i].y,r=A[o].x,a=A[o].y;s>e.y!=a>e.y&&e.x<(r-n)*(e.y-s)/(a-s||Number.EPSILON)+n&&(t=!t)}return t},r5e=(e,A,t)=>{const i=[];for(const o of e){if(!o._element)continue;if("x1"in o&&o._element?.type==="pcb_trace"){const r=mh({x:A.x,y:A.y},{x:o.x1,y:o.y1},{x:o.x2,y:o.y2}),a=o.width||.5,g=Math.max(a*25,2)/t.a;r<g&&i.push(o);continue}if(o.pcb_drawing_type==="polygon"){const r=o.points.map(g=>({x:ue.parse(g.x),y:ue.parse(g.y)})),a=t9(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;lgt(A,r)&&i.push(o);continue}if(o.pcb_drawing_type==="polygon_with_arcs"){const r=o.brep_shape.outer_ring.vertices.map(g=>({x:ue.parse(g.x),y:ue.parse(g.y)})),a=t9(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;lgt(A,r)&&i.push(o);continue}if(!("x"in o&&"y"in o))continue;let n=0,s=0;if("w"in o&&"h"in o)n=o.w,s=o.h;else if("r"in o)n=o.r*2,s=o.r*2;else if("rX"in o&&"rY"in o)n=o.rX*2,s=o.rY*2;else continue;Math.abs(o.x-A.x)<n/2&&Math.abs(o.y-A.y)<s/2&&i.push(o)}return i},a5e=({elements:e,children:A,transform:t,primitives:i,onMouseHoverOverPrimitives:o})=>{const[n,s]=AA.useState([]),[r,a]=AA.useState({x:0,y:0}),[g,{width:I,height:c}]=ZY(),B=AA.useMemo(()=>{const C=[];for(const E of n){if(E._element?.type==="pcb_via"||E._element?.type==="pcb_component"||E?.layer==="drill")continue;let Q=null,h=0,u=0;if(E.pcb_drawing_type==="polygon"){const D=t9(E.points);if(!D)continue;Q=D.center,h=D.width,u=D.height}else if(E.pcb_drawing_type==="polygon_with_arcs"){const D=E.brep_shape.outer_ring.vertices.map(b=>({x:b.x,y:b.y})),w=t9(D);if(!w)continue;Q=w.center,h=w.width,u=w.height}else"x"in E&&"y"in E&&(Q={x:E.x,y:E.y},h="w"in E?E.w:"r"in E?E.r*2:"rX"in E&&"rY"in E?E.rX*2:0,u="h"in E?E.h:"r"in E?E.r*2:"rX"in E&&"rY"in E?E.rY*2:0);if(!Q)continue;const d=qi(t,Q),f={w:h*t.a,h:u*t.a},m=C.filter(D=>d.x===D.screen_x&&d.y===D.screen_y&&f.w===D.screen_w&&f.h===D.screen_h).length;C.push({...E,x:Q.x,y:Q.y,w:h,h:u,screen_x:d.x,screen_y:d.y,screen_w:f.w,screen_h:f.h,same_space_index:m})}return C},[n,t]),l=(C,E,Q,h)=>{a({x:C,y:E});const u=qi(lb(Q),{x:C,y:E}),d=r5e(h,u,Q);WOe(new Set(d.map(f=>f._pcb_drawing_object_id)),new Set(n.map(f=>f._pcb_drawing_object_id)))||(s(d),o(d))};return Z.jsxs("div",{ref:g,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:C=>{if(t){const E=C.currentTarget.getBoundingClientRect(),Q=C.clientX-E.left,h=C.clientY-E.top;l(Q,h,t,i)}},onTouchStart:C=>{if(t){const E=C.touches[0],Q=C.currentTarget.getBoundingClientRect(),h=E.clientX-Q.left,u=E.clientY-Q.top;l(h,u,t,i)}},children:[A,Z.jsx(A5e,{elements:e,mousePos:r,highlightedPrimitives:B}),t&&Z.jsxs(Z.Fragment,{children:[Z.jsx(e5e,{elements:e,highlightedPrimitives:B,transform:t,containerWidth:I,containerHeight:c}),Z.jsx(i5e,{elements:e,highlightedPrimitives:B,transform:t,containerWidth:I,containerHeight:c}),Z.jsx(n5e,{elements:e,highlightedPrimitives:B,transform:t,containerWidth:I,containerHeight:c}),Z.jsx(s5e,{elements:e,highlightedPrimitives:B,transform:t,containerWidth:I,containerHeight:c})]})]})},Cgt=["rgb(255, 100, 100)","rgb(100, 255, 100)","rgb(100, 100, 255)","rgb(255, 255, 100)","rgb(255, 100, 255)","rgb(100, 255, 255)","rgb(255, 150, 100)","rgb(150, 100, 255)","rgb(100, 255, 150)","rgb(255, 100, 150)"],g5e=({children:e,transform:A=Bb(),elements:t=[],hoveredComponentIds:i=[]})=>{const[o,{width:n,height:s}]=ZY(),r=AA.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:I}=zl(c=>({is_showing_pcb_groups:c.is_showing_pcb_groups,pcb_group_view_mode:c.pcb_group_view_mode,is_showing_group_anchor_offsets:c.is_showing_group_anchor_offsets}));return AA.useEffect(()=>{const c=r.current;if(!c||!n||!s)return;c.width=n,c.height=s;const B=c.getContext("2d");if(!B||(B.clearRect(0,0,n,s),!a))return;const l=t.filter(D=>D.type==="pcb_group"),C=t.filter(D=>D.type==="pcb_component"),E=t.filter(D=>D.type==="source_group"),Q=new Map(E.map(D=>[D.source_group_id,D])),h=l.filter(D=>{if(g==="all")return!0;if(!D.source_group_id)return!1;const w=Q.get(D.source_group_id);return w?w.was_automatically_named!==!0:!1}),u=new Map;E.forEach(D=>{const w=D;if(w.parent_source_group_id){const b=u.get(w.parent_source_group_id)||[];b.push(D.source_group_id),u.set(w.parent_source_group_id,b)}});const d=D=>{const w=[],b=u.get(D)||[];for(const k of b)w.push(k),w.push(...d(k));return w},f=D=>{const w=E.find(b=>b.source_group_id===D);return w?.parent_source_group_id?1+f(w.parent_source_group_id):0},m=new Set;if(i.length>0)for(const D of C){if(!i.includes(D.pcb_component_id))continue;const w=D.positioned_relative_to_pcb_group_id??D.pcb_group_id;w&&m.add(w)}h.forEach((D,w)=>{let b=C.filter(UA=>UA.pcb_group_id===D.pcb_group_id);if(D.source_group_id){const UA=d(D.source_group_id),ZA=l.filter(kA=>kA.source_group_id&&UA.includes(kA.source_group_id));for(const kA of ZA){const DA=C.filter(HA=>HA.pcb_group_id===kA.pcb_group_id);b=[...b,...DA]}}let k,x,N,M,U=!1;if(D.center&&D.width&&D.height){U=!0;const UA=D.width/2,ZA=D.height/2;k=D.center.x-UA,N=D.center.x+UA,x=D.center.y-ZA,M=D.center.y+ZA}else if(b.length===0||(k=1/0,x=1/0,N=-1/0,M=-1/0,b.forEach(UA=>{if(UA.center&&typeof UA.width=="number"&&typeof UA.height=="number"){const ZA=UA.center.x-UA.width/2,kA=UA.center.x+UA.width/2,DA=UA.center.y+UA.height/2,HA=UA.center.y-UA.height/2;k=Math.min(k,ZA),N=Math.max(N,kA),x=Math.min(x,HA),M=Math.max(M,DA)}}),k===1/0||N===-1/0))return;const J=D.source_group_id?f(D.source_group_id):0,H=D.source_group_id?d(D.source_group_id).length>0:!1;if(!U){const kA=1+(H?.5:0);k-=kA,N+=kA,x-=kA,M+=kA}const O=qi(A,{x:k,y:M}),W=qi(A,{x:N,y:M}),$=qi(A,{x:k,y:x}),iA=qi(A,{x:N,y:x}),rA=Cgt[w%Cgt.length];B.strokeStyle=rA,B.lineWidth=2;const tA=Math.max(4,Math.min(12,8*Math.abs(A.a))),nA=Math.max(2,Math.min(6,4*Math.abs(A.a))),QA=tA*(H?1.3:1),SA=nA;B.setLineDash([QA,SA]),B.beginPath(),B.moveTo(O.x,O.y),B.lineTo(W.x,W.y),B.lineTo(iA.x,iA.y),B.lineTo($.x,$.y),B.closePath(),B.stroke();const FA=Math.max(8,Math.min(12,10*Math.abs(A.a))),MA=J==0||J==1?0:J*.11,TA=FA*(1-MA),EA=4,GA=D.name||`Group ${w+1}`;B.font=`${TA}px sans-serif`,B.setLineDash([]);const PA=B.measureText(GA).width+EA*2,JA=TA+EA*2,it=O.x-5,yA=O.y-5,tt=3;if(B.fillStyle="rgba(0, 0, 0, 0.8)",B.beginPath(),B.roundRect(it,yA-JA,PA,JA,tt),B.fill(),B.fillStyle=rA,B.textAlign="left",B.textBaseline="middle",B.fillText(GA,it+EA,yA-JA/2),I&&m.has(D.pcb_group_id)&&!!D.anchor_position&&D.anchor_position){const UA=Array.isArray(D.anchor_position)?{x:D.anchor_position[0]??0,y:D.anchor_position[1]??0}:{x:D.anchor_position.x,y:D.anchor_position.y},ZA=qi(A,UA);B.strokeStyle="white",B.lineWidth=1.5,B.setLineDash([]);const kA=Math.max(4,Math.min(8,6*Math.abs(A.a)));B.beginPath(),B.moveTo(ZA.x-kA,ZA.y),B.lineTo(ZA.x+kA,ZA.y),B.stroke(),B.beginPath(),B.moveTo(ZA.x,ZA.y-kA),B.lineTo(ZA.x,ZA.y+kA),B.stroke()}})},[t,A,n,s,a,g,I,i]),Z.jsxs("div",{ref:o,style:{position:"relative",width:"100%",height:"100%"},children:[e,Z.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:EI.pcbGroupOverlay,display:a?"block":"none"}})]})},I5e=({transform:e,soup:A,children:t})=>{const i=zl(r=>r.is_showing_rats_nest),{netMap:o,idToNetMap:n}=AA.useMemo(()=>Wat(A||[]),[A]),s=AA.useMemo(()=>{if(!A||!i)return[];const r=B=>{const l=Qb(A)[B.replace(/_\d+$/,"")].get(B);return l&&"x"in l&&"y"in l?{x:l.x,y:l.y}:null},a=(B,l)=>{const C=o[l]||[];let E=null,Q=1/0;return C.forEach(h=>{const u=r(h);if(u){const d=Math.sqrt((B.x-u.x)**2+(B.y-u.y)**2);d<Q&&d>0&&(Q=d,E=u)}}),E},g=Qb(A).pcb_port.list(),I=Qb(A).source_trace.list(),c=[];return g.forEach((B,l)=>{const C=n[B.pcb_port_id];let E=!1;for(const u of I)u.connected_source_port_ids.includes(B.source_port_id)&&u.connected_source_net_ids.length>0&&(E=!0);if(!C)return;const Q={x:B.x,y:B.y},h=a(Q,C);h&&c.push({key:`${B.pcb_port_id}-${l}`,startPoint:Q,endPoint:h,isInNet:E})}),c},[A,o,n,i]);return!A||!i?t:(e||(e=Bb()),Z.jsxs("div",{style:{position:"relative"},children:[t,Z.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:EI.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:I})=>{const c=qi(e,a),B=qi(e,g);return Z.jsx("line",{x1:c.x,y1:c.y,x2:B.x,y2:B.y,stroke:"white",strokeWidth:"1",strokeDasharray:I?"6,6":void 0},r)})})]}))},c5e={version:"1.11.327"},T_=(e,A,t)=>{const i=zl(s=>s.is_mouse_over_container),o=AA.useRef(i),n=AA.useRef(A);AA.useEffect(()=>{o.current=i},[i]),AA.useEffect(()=>{n.current=A},[A]),AA.useEffect(()=>{if(!e)return;const s=r=>{const a=r.target;if(a.tagName==="INPUT"||a.tagName==="TEXTAREA"||a.isContentEditable)return;const g=e.split("+"),I=g.includes("ctrl"),c=g.includes("shift"),B=g.includes("alt"),l=g.includes("meta"),C=g[g.length-1],E=t?.current?t.current.contains(document.activeElement)||document.activeElement===t.current:!1;(o.current||E)&&(!I||r.ctrlKey)&&(!c||r.shiftKey)&&(!B||r.altKey)&&(!l||r.metaKey)&&r.key.toLowerCase()===C.toLowerCase()&&(r.preventDefault(),n.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[e])},B5e=()=>{const[e,A]=AA.useState(!1);return AA.useEffect(()=>{const t=()=>{A(window.innerWidth<=768)};return t(),window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[]),e},l5e=({name:e,selected:A,onClick:t})=>Z.jsxs("div",{className:Uv`
5468
+ `,OOe=({children:e,transform:A=Bb(),elements:t})=>{const i=AA.useRef(null),{isShowingDRCErrors:o,hoveredErrorId:n}=zl(g=>({isShowingDRCErrors:g.is_showing_drc_errors,hoveredErrorId:g.hovered_error_id}));if(!t)return Z.jsx("div",{style:{position:"relative"},ref:i,children:e});const s=t.filter(g=>g.type==="pcb_trace_error"),r=t.filter(g=>g.type==="pcb_trace_error"&&g.message?.includes("Multiple components found with name")),a=new Map;return t.forEach(g=>{g.type==="pcb_port"&&a.set(g.pcb_port_id,g)}),Z.jsxs("div",{style:{position:"relative"},ref:i,children:[e,s.map((g,I)=>{const{pcb_port_ids:c,pcb_trace_id:B}=g,l=c?.[0]?a.get(c[0]):void 0,C=c?.[1]?a.get(c[1]):void 0,E=t?Qb(t).pcb_trace.get(B):void 0,Q=g.pcb_trace_error_id||`error_${I}_${g.error_type}_${g.message?.slice(0,20)}`,h=n===Q;if(l&&C){const u=qi(A,{x:l.x,y:l.y}),d=qi(A,{x:C.x,y:C.y}),f=!(isNaN(u.x)||isNaN(u.y)||isNaN(d.x)||isNaN(d.y)),m={x:(u.x+d.x)/2,y:(u.y+d.y)/2};if(isNaN(m.x)||isNaN(m.y))return null;const D=SpA(m,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx(POe,{screenPort1:u,screenPort2:d,errorCenter:m,canLineBeDrawn:f,isHighlighted:h}),Z.jsx("div",{style:{position:"absolute",left:m.x-15,top:m.y-15,width:30,height:30,zIndex:EI.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:w=>{const b=w.currentTarget.nextElementSibling;if(b){const k=b.querySelector(".error-message");k&&(k.style.opacity="1")}},onMouseLeave:w=>{if(!h){const b=w.currentTarget.nextElementSibling;if(b){const k=b.querySelector(".error-message");k&&(k.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:h?200:100,left:D.left,top:D.top,color:h?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:o||h?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:D.transform},children:Z.jsx("div",{className:`error-message ${bpA}`,style:{opacity:h?1:0,border:`1px solid ${h?"#ff4444":"red"}`},children:g.message})})]},Q)}if(E?.route&&(o||h)){const u=E.route.map(D=>qi(A,{x:D.x,y:D.y}));if(u.some(D=>isNaN(D.x)||isNaN(D.y)))return null;const d=Math.floor(u.length/2),f=u[d],m=SpA(f,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx(qOe,{points:u,errorCenter:f,isHighlighted:h}),Z.jsx("div",{style:{position:"absolute",left:f.x-15,top:f.y-15,width:30,height:30,zIndex:EI.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:D=>{const w=D.currentTarget.nextElementSibling;if(w){const b=w.querySelector(".error-message");b&&(b.style.opacity="1")}},onMouseLeave:D=>{if(!h){const w=D.currentTarget.nextElementSibling;if(w){const b=w.querySelector(".error-message");b&&(b.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:h?EI.errorOverlay+10:EI.errorOverlay+1,left:m.left,top:m.top,color:h?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:m.transform},children:Z.jsx("div",{className:`error-message ${bpA}`,style:{opacity:h?1:0,border:`1px solid ${h?"#ff4444":"red"}`},children:g.message})})]},Q)}return null}),r.map((g,I)=>{const c=g.component_name||g.message?.match(/name "([^"]+)"/)?.[1];if(!c)return null;const B=t?.filter(E=>E.type==="source_component"&&E.name===c||E.type==="pcb_component"&&t?.find(Q=>Q.type==="source_component"&&Q.source_component_id===E.source_component_id&&Q.name===c))||[],l=g.pcb_trace_error_id||`error_${I}_${g.error_type}_${g.message?.slice(0,20)}`,C=n===l;return!C&&!o?null:B.map((E,Q)=>{let h={x:0,y:0};if(E.type==="pcb_component")h=E.center||{x:0,y:0};else if(E.type==="source_component"){const k=t?.find(x=>x.type==="pcb_component"&&x.source_component_id===E.source_component_id);k&&k.type==="pcb_component"&&(h=k.center||{x:0,y:0})}const u=qi(A,h);if(isNaN(u.x)||isNaN(u.y))return null;const d=Math.abs(A.a),w=Math.max(8,Math.min(30,.5*d)),b=SpA(u,i);return Z.jsxs(AA.Fragment,{children:[Z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:EI.errorOverlay},width:"100%",height:"100%",children:C?Z.jsx("polygon",{points:`${u.x},${u.y-w*1.25} ${u.x+w},${u.y} ${u.x},${u.y+w*1.25} ${u.x-w},${u.y}`,fill:"#ff4444"}):Z.jsx("circle",{cx:u.x,cy:u.y,r:w,fill:"none",stroke:C?"#ff4444":"red",strokeWidth:C?Math.max(2,w*.15):Math.max(1,w*.1),opacity:1})}),Z.jsx("div",{style:{position:"absolute",left:u.x-(w+10),top:u.y-(w+10),width:(w+10)*2,height:(w+10)*2,zIndex:EI.errorOverlay+5,cursor:"pointer",borderRadius:"50%"},onMouseEnter:k=>{const x=k.currentTarget.nextElementSibling;if(x){const N=x.querySelector(".error-message");N&&(N.style.opacity="1")}},onMouseLeave:k=>{if(!C){const x=k.currentTarget.nextElementSibling;if(x){const N=x.querySelector(".error-message");N&&(N.style.opacity="0")}}}}),Z.jsx("div",{style:{position:"absolute",zIndex:C?EI.errorOverlay+20:EI.errorOverlay+10,left:b.left,top:b.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:o||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:b.transform},children:Z.jsx("div",{className:`error-message ${bpA}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:g.message})})]},`${l}_${Q}`)})})]})};function WOe(e,A){return e.size!==A.size?!1:Array.from(e).every(t=>A.has(t))}function ZOe({primitiveElement:e,elements:A}){let t=e.trace_length?`${e.trace_length.toFixed(3)}`:"";const i=Qb(A).source_trace.get(e?.source_trace_id);if(i?.display_name&&(i?.max_length?t+=` / ${i.max_length}mm `:t+=" mm ",t+=`(${i.display_name})`),!t)return null;const o=e.trace_length&&i?.max_length&&e.trace_length>i.max_length;return{text:t,isOverLength:o}}function VOe(e){const{primitives:A,is_showing_multiple_traces_length:t,elements:i}=e,o=A.filter(a=>a._element.type==="pcb_trace"),n=i.filter(a=>a.type==="source_trace"),s=A.filter(a=>a._element.type!=="pcb_trace"),r=o.filter(a=>n.some(g=>a._element.type==="pcb_trace"&&a._element.source_trace_id===g.source_trace_id&&g.max_length!==void 0));if(!t)return[...s,...r];if(o.length>1){const a=o.reduce((g,I)=>{const c=g._element.trace_length;return I._element.trace_length<c?I:g},o[0]);return[...s,a]}return A}var jOe={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},zOe=e=>{const{_element:A,_parent_pcb_component:t,_parent_source_component:i,_source_port:o}=e;switch(A.type){case"pcb_trace":return A.trace_length?`${A.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const n=[],s=Array.from(new Set((A.port_hints??[]).concat(o?.port_hints??[]))).filter(a=>!/^[0-9]+$/.test(a)).filter(a=>!a.includes("unnamed_")).sort((a,g)=>g.localeCompare(a)),r=i&&"name"in i&&i.name&&!i.name.includes("unnamed_")?i.name:null;return s.length>0?r?n.push(...s.map(a=>`${r}.${a}`)):n.push(...s):r&&n.push(r),n.join(", ")}default:return""}},XOe={top:"red",bottom:"aqua"},$Oe=({primitive:e,mousePos:A,elements:t})=>{const[i,o]=AA.useState(!1),n=e._element;AA.useEffect(()=>{setTimeout(()=>{o(!0)},100)},[]);const[s,r,a,g]=[e.screen_x,e.screen_y,e.screen_w,e.screen_h],I=e.same_space_index??0,c=26,B=XOe[e?._element?.layer]??"red";let l=0;if(n.type==="pcb_smtpad"&&n?.shape==="rotated_rect"?l=n?.ccw_rotation??0:(n.type==="pcb_smtpad"&&(n?.shape==="pill"||n?.shape==="rotated_pill")&&"ccw_rotation"in e||n.type==="pcb_plated_hole"&&(n?.shape==="pill"||n?.shape==="oval")&&"ccw_rotation"in e)&&(l=n.ccw_rotation??0),n.type==="pcb_trace"){const Q=ZOe({primitiveElement:n,elements:t});if(!Q)return null;const h=A.y-35;return Z.jsx("div",{style:{zIndex:EI.elementOverlay,position:"absolute",left:A.x,top:h,color:B,pointerEvents:"none",transform:"translateX(-50%)"},children:Z.jsx("div",{style:{backgroundColor:"#f2efcc",color:Q.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:Q.text})})}const C=zOe(e);return C.trim().length===0?null:Z.jsx("div",{style:{zIndex:EI.elementOverlay,position:"absolute",left:s-a/2-8,top:r-g/2-8,width:a+16,height:g+16,color:B,transform:`rotate(${-l}deg)`,transformOrigin:"center center"},children:Z.jsx("div",{style:{width:i?`calc(100% + ${c*2*I}px)`:"100%",height:i?`calc(100% + ${c*2*I}px)`:"100%",marginLeft:i?`${-c*I}px`:0,marginTop:i?`${-c*I}px`:0,border:`1px solid ${B}`,opacity:i||I===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:Z.jsx("div",{style:{position:"absolute",bottom:g+20+c*I,marginRight:i?`${-c*I}px`:0,marginBottom:i?0:-c*I,transition:"margin-right 0.2s, margin-bottom 0.2s",backgroundColor:"#f2efcc",color:"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",transform:`rotate(${l}deg)`,minWidth:"45px",textAlign:"center"},children:C})})})},A5e=({highlightedPrimitives:e,mousePos:A,elements:t})=>{const[i,o]=zl(r=>[r.is_moving_component,r.is_showing_multiple_traces_length]),n=e.some(r=>r._element.type==="pcb_smtpad")&&e.some(r=>r._element.type==="pcb_trace");let s=e;return n&&(s=s.filter(r=>r._element.type==="pcb_smtpad")),s=VOe({primitives:s,is_showing_multiple_traces_length:o,elements:t}),Z.jsx("div",{style:jOe,children:!i&&s.map((r,a)=>Z.jsx($Oe,{primitive:r,mousePos:A,elements:t},a))})},J_=e=>e?.type==="pcb_component",Bgt=e=>e?.type==="pcb_group",t5e=e=>e?.type==="pcb_panel",xpA=e=>e?.type==="pcb_board",WI={MIN_LINE_LENGTH_FOR_LABEL:40,LABEL_OFFSET_ABOVE:2,LABEL_OFFSET_BELOW:-18,LABEL_OFFSET_RIGHT:8,LABEL_OFFSET_LEFT:-120,Y_LABEL_MIN_WIDTH:110,LINE_STROKE_WIDTH:1.5,LINE_DASH_PATTERN:"4,4",COMPONENT_MARKER_RADIUS:3,LABEL_FONT_SIZE:11,ANCHOR_MARKER_SIZE:6,ANCHOR_MARKER_STROKE_WIDTH:1.5},S0={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},_pA=({targets:e,transform:A,containerWidth:t,containerHeight:i})=>{if(e.length===0)return null;const o={color:S0.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:WI.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},n=new Map;return e.forEach(s=>{if(!n.has(s.anchor_id)){const r=qi(A,s.anchor);n.set(s.anchor_id,r)}}),Z.jsx("div",{style:{position:"absolute",left:0,top:0,width:t,height:i,overflow:"hidden",pointerEvents:"none",zIndex:EI.dimensionOverlay},children:Z.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:t,height:i,children:[e.map(s=>{const r=s.anchor,a=s.anchor_id,g=s.target,I=n.get(a),c=qi(A,g),B=g.x-r.x,l=g.y-r.y,C=Math.abs(c.x-I.x),E=Math.abs(c.y-I.y),Q=c.y<I.y,h=c.x>I.x,u=Q?WI.LABEL_OFFSET_ABOVE:WI.LABEL_OFFSET_BELOW,d=h?WI.LABEL_OFFSET_RIGHT:WI.LABEL_OFFSET_LEFT,f=C>WI.MIN_LINE_LENGTH_FOR_LABEL,m=E>WI.MIN_LINE_LENGTH_FOR_LABEL,D=`${s.display_offset_x??B.toFixed(2)}mm`,w=`${s.display_offset_y??l.toFixed(2)}mm`;return Z.jsxs("g",{children:[Z.jsx("line",{x1:I.x,y1:I.y,x2:c.x,y2:I.y,stroke:S0.OFFSET_LINE,strokeWidth:WI.LINE_STROKE_WIDTH,strokeDasharray:WI.LINE_DASH_PATTERN}),Z.jsx("line",{x1:c.x,y1:I.y,x2:c.x,y2:c.y,stroke:S0.OFFSET_LINE,strokeWidth:WI.LINE_STROKE_WIDTH,strokeDasharray:WI.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?Z.jsx("circle",{cx:c.x,cy:c.y,r:WI.COMPONENT_MARKER_RADIUS,fill:S0.COMPONENT_MARKER_FILL,stroke:S0.COMPONENT_MARKER_STROKE,strokeWidth:1}):Z.jsxs(Z.Fragment,{children:[Z.jsx("line",{x1:c.x-WI.ANCHOR_MARKER_SIZE,y1:c.y,x2:c.x+WI.ANCHOR_MARKER_SIZE,y2:c.y,stroke:S0.OFFSET_LINE,strokeWidth:WI.ANCHOR_MARKER_STROKE_WIDTH}),Z.jsx("line",{x1:c.x,y1:c.y-WI.ANCHOR_MARKER_SIZE,x2:c.x,y2:c.y+WI.ANCHOR_MARKER_SIZE,stroke:S0.OFFSET_LINE,strokeWidth:WI.ANCHOR_MARKER_STROKE_WIDTH})]}),f&&Z.jsx("foreignObject",{x:Math.min(I.x,c.x),y:I.y+u,width:Math.abs(c.x-I.x),height:20,style:{overflow:"visible"},children:Z.jsx("div",{style:{...o,textAlign:"center"},children:D})}),m&&Z.jsx("foreignObject",{x:c.x+d,y:Math.min(I.y,c.y),width:WI.Y_LABEL_MIN_WIDTH,height:Math.abs(c.y-I.y),style:{overflow:"visible"},children:Z.jsx("div",{style:{...o,display:"flex",alignItems:"center",justifyContent:h?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:w})})]},s.id)}),Array.from(n.entries()).map(([s,r])=>Z.jsxs("g",{children:[Z.jsx("line",{x1:r.x-WI.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+WI.ANCHOR_MARKER_SIZE,y2:r.y,stroke:S0.OFFSET_LINE,strokeWidth:WI.ANCHOR_MARKER_STROKE_WIDTH}),Z.jsx("line",{x1:r.x,y1:r.y-WI.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+WI.ANCHOR_MARKER_SIZE,stroke:S0.OFFSET_LINE,strokeWidth:WI.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},e5e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:o})=>{const n=e.filter(h=>xpA(h)),s=e.filter(h=>J_(h)),r=e.filter(h=>Bgt(h)),a=A.map(h=>J_(h._parent_pcb_component)?h._parent_pcb_component.pcb_component_id:J_(h._element)?h._element.pcb_component_id:null).filter(h=>!!h),g=new Set;if(a.forEach(h=>{const u=s.find(d=>d.pcb_component_id===h);u?.pcb_group_id&&g.add(u.pcb_group_id)}),!zl(h=>h.is_showing_group_anchor_offsets)&&a.length===0)return null;const c=s.map(h=>{const u=h.positioned_relative_to_pcb_board_id;if(!u)return null;const d=n.find(f=>f.pcb_board_id===u);return d?{component:h,board:d,type:"component"}:null}).filter(h=>!!h),B=r.map(h=>{const u=h.positioned_relative_to_pcb_board_id;if(!u||!h.center)return null;const d=n.find(f=>f.pcb_board_id===u);return d?{group:h,board:d,type:"group"}:null}).filter(h=>!!h),l=[...c,...B];if(l.length===0)return null;const C=a.length===0,E=l.filter(h=>h.type==="component"?C||a.includes(h.component.pcb_component_id):C||g.has(h.group.pcb_group_id));if(E.length===0)return null;const Q=E.map(h=>h.type==="component"?{id:`${h.board.pcb_board_id}-${h.component.pcb_component_id}-${h.type}`,anchor:h.board.center,anchor_id:h.board.pcb_board_id,target:h.component.center,type:"component",display_offset_x:h.component.display_offset_x,display_offset_y:h.component.display_offset_y}:{id:`${h.board.pcb_board_id}-${h.group.pcb_group_id}-${h.type}`,anchor:h.board.center,anchor_id:h.board.pcb_board_id,target:{x:h.group.anchor_position?.x??h.group.center.x,y:h.group.anchor_position?.y??h.group.center.y},type:"group",display_offset_x:h.group.display_offset_x,display_offset_y:h.group.display_offset_y}).filter(h=>!!h);return Z.jsx(_pA,{targets:Q,transform:t,containerWidth:i,containerHeight:o})},i5e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:o})=>{const n=e.filter(h=>Bgt(h)),s=e.filter(h=>J_(h)),r=A.map(h=>J_(h._parent_pcb_component)?h._parent_pcb_component.pcb_component_id:J_(h._element)?h._element.pcb_component_id:null).filter(h=>!!h),a=(h,u)=>{if(u.has(h))return;u.add(h);const d=n.find(f=>f.pcb_group_id===h);d?.position_mode==="relative_to_group_anchor"&&d.positioned_relative_to_pcb_group_id&&a(d.positioned_relative_to_pcb_group_id,u)},g=new Set;if(r.forEach(h=>{const u=s.find(d=>d.pcb_component_id===h);u&&(u.position_mode==="relative_to_group_anchor"&&u.positioned_relative_to_pcb_group_id&&a(u.positioned_relative_to_pcb_group_id,g),u.pcb_group_id&&a(u.pcb_group_id,g))}),!zl(h=>h.is_showing_group_anchor_offsets)&&r.length===0)return null;const c=s.map(h=>{if(h.position_mode==="relative_to_group_anchor"&&h.positioned_relative_to_pcb_group_id){const u=n.find(d=>d.pcb_group_id===h.positioned_relative_to_pcb_group_id);return u&&u.anchor_position?{component:h,parentGroup:u,type:"component"}:null}if(h.pcb_group_id){const u=n.find(d=>d.pcb_group_id===h.pcb_group_id);return u&&u.anchor_position?{component:h,parentGroup:u,type:"component"}:null}return null}).filter(h=>!!h),B=n.map(h=>{if(h.position_mode==="relative_to_group_anchor"&&h.positioned_relative_to_pcb_group_id){const u=n.find(d=>d.pcb_group_id===h.positioned_relative_to_pcb_group_id);if(u&&u.anchor_position&&h.anchor_position)return{group:h,parentGroup:u,type:"group"}}return null}).filter(h=>!!h),l=[...c,...B];if(l.length===0)return null;const C=r.length===0,E=l.filter(h=>h.type==="component"?C||r.includes(h.component.pcb_component_id):C||g.has(h.group.pcb_group_id)||g.has(h.parentGroup.pcb_group_id));if(E.length===0)return null;const Q=E.map(h=>{const u=h.parentGroup.anchor_position;return u?h.type==="component"?h.component.center?{id:`${h.parentGroup.pcb_group_id}-${h.component.pcb_component_id}-${h.type}`,anchor:u,anchor_id:h.parentGroup.pcb_group_id,target:h.component.center,type:"component",display_offset_x:h.component.display_offset_x,display_offset_y:h.component.display_offset_y}:null:h.group.anchor_position?{id:`${h.parentGroup.pcb_group_id}-${h.group.pcb_group_id}-${h.type}`,anchor:u,anchor_id:h.parentGroup.pcb_group_id,target:h.group.anchor_position,type:"group",display_offset_x:h.group.display_offset_x,display_offset_y:h.group.display_offset_y}:null:null}).filter(h=>!!h);return Z.jsx(_pA,{targets:Q,transform:t,containerWidth:i,containerHeight:o})},o5e=(e,A)=>{const t=e.pcb_component_id,i=A.filter(o=>(o.type==="pcb_smtpad"||o.type==="pcb_plated_hole")&&o.pcb_component_id===t||o.type==="pcb_hole"&&o.pcb_component_id===t);return i.length===0?wpA([e]):wpA(i)},n5e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:o})=>{const n=new Map;for(const r of A)J_(r._parent_pcb_component)&&n.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),J_(r._element)&&n.set(r._element.pcb_component_id,r._element);if(n.size===0)return null;const s=[];for(const r of n.values()){const a=o5e(r,e);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,I=g?Qb(e).pcb_group.get(g):null;s.push({component:r,bbox:a,group:I})}return s.length===0?null:Z.jsx("div",{style:{position:"absolute",left:0,top:0,width:i,height:o,overflow:"hidden",pointerEvents:"none",zIndex:EI.dimensionOverlay},children:Z.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:i,height:o,children:s.map(({component:r,bbox:a,group:g})=>{const I=qi(t,{x:a.minX,y:a.maxY}),c=qi(t,{x:a.maxX,y:a.minY}),B={x:Math.min(I.x,c.x),y:Math.min(I.y,c.y),width:Math.abs(c.x-I.x),height:Math.abs(c.y-I.y)},l=r.center??{x:(a.minX+a.maxX)/2,y:(a.minY+a.maxY)/2},C=qi(t,l);return Z.jsxs("g",{children:[Z.jsx("rect",{x:B.x,y:B.y,width:B.width,height:B.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),Z.jsx("line",{x1:C.x-6,y1:C.y,x2:C.x+6,y2:C.y,stroke:S0.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),Z.jsx("line",{x1:C.x,y1:C.y-6,x2:C.x,y2:C.y+6,stroke:S0.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),Z.jsx("circle",{cx:C.x,cy:C.y,r:WI.COMPONENT_MARKER_RADIUS,fill:S0.COMPONENT_MARKER_FILL,stroke:S0.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},s5e=({elements:e,highlightedPrimitives:A,transform:t,containerWidth:i,containerHeight:o})=>{const n=e.filter(l=>t5e(l)),s=e.filter(l=>xpA(l)),r=A.map(l=>xpA(l._element)?l._element.pcb_board_id:null).filter(l=>!!l);if(!zl(l=>l.is_showing_group_anchor_offsets)&&r.length===0)return null;const g=s.map(l=>{const C=l.pcb_panel_id,E=l.position_mode;if(!C||E!=="relative_to_panel_anchor")return null;const Q=n.find(h=>h.pcb_panel_id===C);return Q?{board:l,panel:Q,type:"board"}:null}).filter(l=>!!l);if(g.length===0)return null;const I=r.length===0,c=g.filter(l=>I||r.includes(l.board.pcb_board_id));if(c.length===0)return null;const B=c.map(l=>l.board.center?{id:`${l.panel.pcb_panel_id}-${l.board.pcb_board_id}-${l.type}`,anchor:l.panel.center,anchor_id:l.panel.pcb_panel_id,target:l.board.center,type:"board",display_offset_x:l.board.display_offset_x,display_offset_y:l.board.display_offset_y}:null).filter(l=>!!l);return Z.jsx(_pA,{targets:B,transform:t,containerWidth:i,containerHeight:o})},t9=e=>{if(e.length===0)return null;let A=e[0].x,t=e[0].y,i=e[0].x,o=e[0].y;for(const n of e)n.x<A&&(A=n.x),n.y<t&&(t=n.y),n.x>i&&(i=n.x),n.y>o&&(o=n.y);return{center:{x:(A+i)/2,y:(t+o)/2},width:i-A,height:o-t}},lgt=(e,A)=>{if(A.length<3)return!1;let t=!1;for(let i=0,o=A.length-1;i<A.length;o=i++){const n=A[i].x,s=A[i].y,r=A[o].x,a=A[o].y;s>e.y!=a>e.y&&e.x<(r-n)*(e.y-s)/(a-s||Number.EPSILON)+n&&(t=!t)}return t},r5e=(e,A,t)=>{const i=[];for(const o of e){if(!o._element)continue;if("x1"in o&&o._element?.type==="pcb_trace"){const r=mh({x:A.x,y:A.y},{x:o.x1,y:o.y1},{x:o.x2,y:o.y2}),a=o.width||.5,g=Math.max(a*25,2)/t.a;r<g&&i.push(o);continue}if(o.pcb_drawing_type==="polygon"){const r=o.points.map(g=>({x:ue.parse(g.x),y:ue.parse(g.y)})),a=t9(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;lgt(A,r)&&i.push(o);continue}if(o.pcb_drawing_type==="polygon_with_arcs"){const r=o.brep_shape.outer_ring.vertices.map(g=>({x:ue.parse(g.x),y:ue.parse(g.y)})),a=t9(r);if(!a||A.x<a.center.x-a.width/2||A.x>a.center.x+a.width/2||A.y<a.center.y-a.height/2||A.y>a.center.y+a.height/2)continue;lgt(A,r)&&i.push(o);continue}if(!("x"in o&&"y"in o))continue;let n=0,s=0;if("w"in o&&"h"in o)n=o.w,s=o.h;else if("r"in o)n=o.r*2,s=o.r*2;else if("rX"in o&&"rY"in o)n=o.rX*2,s=o.rY*2;else continue;Math.abs(o.x-A.x)<n/2&&Math.abs(o.y-A.y)<s/2&&i.push(o)}return i},a5e=({elements:e,children:A,transform:t,primitives:i,onMouseHoverOverPrimitives:o})=>{const[n,s]=AA.useState([]),[r,a]=AA.useState({x:0,y:0}),[g,{width:I,height:c}]=ZY(),B=AA.useMemo(()=>{const C=[];for(const E of n){if(E._element?.type==="pcb_via"||E._element?.type==="pcb_component"||E?.layer==="drill")continue;let Q=null,h=0,u=0;if(E.pcb_drawing_type==="polygon"){const D=t9(E.points);if(!D)continue;Q=D.center,h=D.width,u=D.height}else if(E.pcb_drawing_type==="polygon_with_arcs"){const D=E.brep_shape.outer_ring.vertices.map(b=>({x:b.x,y:b.y})),w=t9(D);if(!w)continue;Q=w.center,h=w.width,u=w.height}else"x"in E&&"y"in E&&(Q={x:E.x,y:E.y},h="w"in E?E.w:"r"in E?E.r*2:"rX"in E&&"rY"in E?E.rX*2:0,u="h"in E?E.h:"r"in E?E.r*2:"rX"in E&&"rY"in E?E.rY*2:0);if(!Q)continue;const d=qi(t,Q),f={w:h*t.a,h:u*t.a},m=C.filter(D=>d.x===D.screen_x&&d.y===D.screen_y&&f.w===D.screen_w&&f.h===D.screen_h).length;C.push({...E,x:Q.x,y:Q.y,w:h,h:u,screen_x:d.x,screen_y:d.y,screen_w:f.w,screen_h:f.h,same_space_index:m})}return C},[n,t]),l=(C,E,Q,h)=>{a({x:C,y:E});const u=qi(lb(Q),{x:C,y:E}),d=r5e(h,u,Q);WOe(new Set(d.map(f=>f._pcb_drawing_object_id)),new Set(n.map(f=>f._pcb_drawing_object_id)))||(s(d),o(d))};return Z.jsxs("div",{ref:g,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:C=>{if(t){const E=C.currentTarget.getBoundingClientRect(),Q=C.clientX-E.left,h=C.clientY-E.top;l(Q,h,t,i)}},onTouchStart:C=>{if(t){const E=C.touches[0],Q=C.currentTarget.getBoundingClientRect(),h=E.clientX-Q.left,u=E.clientY-Q.top;l(h,u,t,i)}},children:[A,Z.jsx(A5e,{elements:e,mousePos:r,highlightedPrimitives:B}),t&&Z.jsxs(Z.Fragment,{children:[Z.jsx(e5e,{elements:e,highlightedPrimitives:B,transform:t,containerWidth:I,containerHeight:c}),Z.jsx(i5e,{elements:e,highlightedPrimitives:B,transform:t,containerWidth:I,containerHeight:c}),Z.jsx(n5e,{elements:e,highlightedPrimitives:B,transform:t,containerWidth:I,containerHeight:c}),Z.jsx(s5e,{elements:e,highlightedPrimitives:B,transform:t,containerWidth:I,containerHeight:c})]})]})},Cgt=["rgb(255, 100, 100)","rgb(100, 255, 100)","rgb(100, 100, 255)","rgb(255, 255, 100)","rgb(255, 100, 255)","rgb(100, 255, 255)","rgb(255, 150, 100)","rgb(150, 100, 255)","rgb(100, 255, 150)","rgb(255, 100, 150)"],g5e=({children:e,transform:A=Bb(),elements:t=[],hoveredComponentIds:i=[]})=>{const[o,{width:n,height:s}]=ZY(),r=AA.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:I}=zl(c=>({is_showing_pcb_groups:c.is_showing_pcb_groups,pcb_group_view_mode:c.pcb_group_view_mode,is_showing_group_anchor_offsets:c.is_showing_group_anchor_offsets}));return AA.useEffect(()=>{const c=r.current;if(!c||!n||!s)return;c.width=n,c.height=s;const B=c.getContext("2d");if(!B||(B.clearRect(0,0,n,s),!a))return;const l=t.filter(D=>D.type==="pcb_group"),C=t.filter(D=>D.type==="pcb_component"),E=t.filter(D=>D.type==="source_group"),Q=new Map(E.map(D=>[D.source_group_id,D])),h=l.filter(D=>{if(g==="all")return!0;if(!D.source_group_id)return!1;const w=Q.get(D.source_group_id);return w?w.was_automatically_named!==!0:!1}),u=new Map;E.forEach(D=>{const w=D;if(w.parent_source_group_id){const b=u.get(w.parent_source_group_id)||[];b.push(D.source_group_id),u.set(w.parent_source_group_id,b)}});const d=D=>{const w=[],b=u.get(D)||[];for(const k of b)w.push(k),w.push(...d(k));return w},f=D=>{const w=E.find(b=>b.source_group_id===D);return w?.parent_source_group_id?1+f(w.parent_source_group_id):0},m=new Set;if(i.length>0)for(const D of C){if(!i.includes(D.pcb_component_id))continue;const w=D.positioned_relative_to_pcb_group_id??D.pcb_group_id;w&&m.add(w)}h.forEach((D,w)=>{let b=C.filter(UA=>UA.pcb_group_id===D.pcb_group_id);if(D.source_group_id){const UA=d(D.source_group_id),ZA=l.filter(kA=>kA.source_group_id&&UA.includes(kA.source_group_id));for(const kA of ZA){const DA=C.filter(HA=>HA.pcb_group_id===kA.pcb_group_id);b=[...b,...DA]}}let k,x,N,M,U=!1;if(D.center&&D.width&&D.height){U=!0;const UA=D.width/2,ZA=D.height/2;k=D.center.x-UA,N=D.center.x+UA,x=D.center.y-ZA,M=D.center.y+ZA}else if(b.length===0||(k=1/0,x=1/0,N=-1/0,M=-1/0,b.forEach(UA=>{if(UA.center&&typeof UA.width=="number"&&typeof UA.height=="number"){const ZA=UA.center.x-UA.width/2,kA=UA.center.x+UA.width/2,DA=UA.center.y+UA.height/2,HA=UA.center.y-UA.height/2;k=Math.min(k,ZA),N=Math.max(N,kA),x=Math.min(x,HA),M=Math.max(M,DA)}}),k===1/0||N===-1/0))return;const J=D.source_group_id?f(D.source_group_id):0,H=D.source_group_id?d(D.source_group_id).length>0:!1;if(!U){const kA=1+(H?.5:0);k-=kA,N+=kA,x-=kA,M+=kA}const O=qi(A,{x:k,y:M}),W=qi(A,{x:N,y:M}),$=qi(A,{x:k,y:x}),iA=qi(A,{x:N,y:x}),rA=Cgt[w%Cgt.length];B.strokeStyle=rA,B.lineWidth=2;const tA=Math.max(4,Math.min(12,8*Math.abs(A.a))),nA=Math.max(2,Math.min(6,4*Math.abs(A.a))),QA=tA*(H?1.3:1),SA=nA;B.setLineDash([QA,SA]),B.beginPath(),B.moveTo(O.x,O.y),B.lineTo(W.x,W.y),B.lineTo(iA.x,iA.y),B.lineTo($.x,$.y),B.closePath(),B.stroke();const FA=Math.max(8,Math.min(12,10*Math.abs(A.a))),MA=J==0||J==1?0:J*.11,TA=FA*(1-MA),EA=4,GA=D.name||`Group ${w+1}`;B.font=`${TA}px sans-serif`,B.setLineDash([]);const PA=B.measureText(GA).width+EA*2,JA=TA+EA*2,it=O.x-5,yA=O.y-5,tt=3;if(B.fillStyle="rgba(0, 0, 0, 0.8)",B.beginPath(),B.roundRect(it,yA-JA,PA,JA,tt),B.fill(),B.fillStyle=rA,B.textAlign="left",B.textBaseline="middle",B.fillText(GA,it+EA,yA-JA/2),I&&m.has(D.pcb_group_id)&&!!D.anchor_position&&D.anchor_position){const UA=Array.isArray(D.anchor_position)?{x:D.anchor_position[0]??0,y:D.anchor_position[1]??0}:{x:D.anchor_position.x,y:D.anchor_position.y},ZA=qi(A,UA);B.strokeStyle="white",B.lineWidth=1.5,B.setLineDash([]);const kA=Math.max(4,Math.min(8,6*Math.abs(A.a)));B.beginPath(),B.moveTo(ZA.x-kA,ZA.y),B.lineTo(ZA.x+kA,ZA.y),B.stroke(),B.beginPath(),B.moveTo(ZA.x,ZA.y-kA),B.lineTo(ZA.x,ZA.y+kA),B.stroke()}})},[t,A,n,s,a,g,I,i]),Z.jsxs("div",{ref:o,style:{position:"relative",width:"100%",height:"100%"},children:[e,Z.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:EI.pcbGroupOverlay,display:a?"block":"none"}})]})},I5e=({transform:e,soup:A,children:t})=>{const i=zl(r=>r.is_showing_rats_nest),{netMap:o,idToNetMap:n}=AA.useMemo(()=>Wat(A||[]),[A]),s=AA.useMemo(()=>{if(!A||!i)return[];const r=B=>{const l=Qb(A)[B.replace(/_\d+$/,"")].get(B);return l&&"x"in l&&"y"in l?{x:l.x,y:l.y}:null},a=(B,l)=>{const C=o[l]||[];let E=null,Q=1/0;return C.forEach(h=>{const u=r(h);if(u){const d=Math.sqrt((B.x-u.x)**2+(B.y-u.y)**2);d<Q&&d>0&&(Q=d,E=u)}}),E},g=Qb(A).pcb_port.list(),I=Qb(A).source_trace.list(),c=[];return g.forEach((B,l)=>{const C=n[B.pcb_port_id];let E=!1;for(const u of I)u.connected_source_port_ids.includes(B.source_port_id)&&u.connected_source_net_ids.length>0&&(E=!0);if(!C)return;const Q={x:B.x,y:B.y},h=a(Q,C);h&&c.push({key:`${B.pcb_port_id}-${l}`,startPoint:Q,endPoint:h,isInNet:E})}),c},[A,o,n,i]);return!A||!i?t:(e||(e=Bb()),Z.jsxs("div",{style:{position:"relative"},children:[t,Z.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:EI.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:I})=>{const c=qi(e,a),B=qi(e,g);return Z.jsx("line",{x1:c.x,y1:c.y,x2:B.x,y2:B.y,stroke:"white",strokeWidth:"1",strokeDasharray:I?"6,6":void 0},r)})})]}))},c5e={version:"1.11.329"},T_=(e,A,t)=>{const i=zl(s=>s.is_mouse_over_container),o=AA.useRef(i),n=AA.useRef(A);AA.useEffect(()=>{o.current=i},[i]),AA.useEffect(()=>{n.current=A},[A]),AA.useEffect(()=>{if(!e)return;const s=r=>{const a=r.target;if(a.tagName==="INPUT"||a.tagName==="TEXTAREA"||a.isContentEditable)return;const g=e.split("+"),I=g.includes("ctrl"),c=g.includes("shift"),B=g.includes("alt"),l=g.includes("meta"),C=g[g.length-1],E=t?.current?t.current.contains(document.activeElement)||document.activeElement===t.current:!1;(o.current||E)&&(!I||r.ctrlKey)&&(!c||r.shiftKey)&&(!B||r.altKey)&&(!l||r.metaKey)&&r.key.toLowerCase()===C.toLowerCase()&&(r.preventDefault(),n.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[e])},B5e=()=>{const[e,A]=AA.useState(!1);return AA.useEffect(()=>{const t=()=>{A(window.innerWidth<=768)};return t(),window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[]),e},l5e=({name:e,selected:A,onClick:t})=>Z.jsxs("div",{className:Uv`
5469
5469
  margin-top: 2px;
5470
5470
  padding: 4px;
5471
5471
  padding-left: 8px;
@@ -5682,7 +5682,7 @@ test("${g} should solve problem correctly", () => {
5682
5682
  // Add more specific assertions based on expected output
5683
5683
  // expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
5684
5684
  })
5685
- `,c=new Blob([I],{type:"text/plain"}),B=URL.createObjectURL(c),l=document.createElement("a");l.href=B,l.download=`${g}.test.ts`,l.click(),URL.revokeObjectURL(B)}catch(a){alert(`Error generating test.ts for ${e.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return Z.jsxs("div",{className:`relative ${A}`,ref:o,children:[Z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!t),title:`Download options for ${e.constructor.name}`,children:e.constructor.name}),t&&Z.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:n,children:"Download JSON"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},Dgt=e=>e.activeSubSolver?[e,...Dgt(e.activeSubSolver)]:[e],H8e=({solver:e})=>{const A=Dgt(e);return Z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((t,i)=>Z.jsxs("div",{className:"flex items-center",children:[i>0&&Z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),Z.jsx(U8e,{solver:t})]},t.constructor.name))})},Y8e=({solver:e,triggerRender:A,animationSpeed:t=25,onSolverStarted:i,onSolverCompleted:o})=>{const[n,s]=AA.useReducer(E=>!E,!1),r=AA.useRef(void 0),a=()=>{!e.solved&&!e.failed&&(e.step(),A())},g=()=>{!e.solved&&!e.failed&&(i&&i(e),e.solve(),A(),o&&o(e))},I=()=>{n?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(e.solved||e.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),o&&e.solved&&o(e);return}e.step(),A()},t))},c=()=>{const E=e;if(E.getCurrentPhase&&!e.solved&&!e.failed){const Q=E.getCurrentPhase();for(;E.getCurrentPhase()===Q&&!e.solved&&!e.failed;)e.step();A()}},B=()=>{if(e.solved||e.failed||n)return;const E=window.prompt("Step until which iteration?",`${e.iterations}`);if(E===null)return;const Q=Number(E);if(!Number.isFinite(Q)){window.alert("Please enter a valid number for the iteration");return}for(;e.iterations<Q&&!e.solved&&!e.failed;)e.step();A(),e.solved&&o&&o(e)};AA.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),AA.useEffect(()=>{(e.solved||e.failed)&&n&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[e.solved,e.failed,n]);const l=e.getCurrentPhase!==void 0,C=l?e.getCurrentPhase():null;return Z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[Z.jsx("div",{className:"flex items-center",children:Z.jsx(H8e,{solver:e})}),Z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[Z.jsx("button",{onClick:a,disabled:e.solved||e.failed||n,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),Z.jsx("button",{onClick:g,disabled:e.solved||e.failed||n,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),Z.jsx("button",{onClick:I,disabled:e.solved||e.failed,className:`px-3 py-1 rounded text-white text-sm ${n?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:n?"Stop":"Animate"}),Z.jsx("button",{onClick:B,disabled:e.solved||e.failed||n,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),l&&Z.jsx("button",{onClick:c,disabled:e.solved||e.failed||n,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),Z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",e.iterations]}),e.timeToSolve!==void 0&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(e.timeToSolve/1e3).toFixed(3),"s"]}),C&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",Z.jsx("span",{className:"font-medium",children:C})]}),e.solved&&Z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),e.failed&&Z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),e.error&&Z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",e.error]})]})},J8e=(e,A,t)=>{const i=e.currentPipelineStepIndex;return A<i?"Completed":A===i&&e.activeSubSolver?e.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},T8e=(e,A)=>{const i=e.pipelineDef[A].solverName,o=J8e(e,A),n=e[i],s=e.firstIterationOfPhase?.[i]??null,r=e.iterations;let a=0;if(o==="Completed"){const B=e.pipelineDef[A+1],l=B?e.firstIterationOfPhase?.[B.solverName]:void 0;l!==void 0&&s!==null?a=l-s:s!==null&&(a=r-s)}else o==="In Progress"&&s!==null&&(a=r-s);const g=e.timeSpentOnPhase?.[i]??0;let I=0;o==="Completed"?I=1:o==="In Progress"&&n&&(I=n.progress??0);const c=n?.stats??null;return{index:A,name:i,status:o,firstIteration:s,iterations:a,progress:I,timeSpent:g,stats:c&&Object.keys(c).length>0?c:null,solverInstance:n??null}},K8e=({status:e})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return Z.jsx("span",{className:`font-medium ${A[e]}`,children:e})},P8e=({progress:e})=>{if(e===0)return null;const A=Math.round(e*100);return Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:Z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),Z.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},q8e=e=>Object.entries(e).map(([A,t])=>`${A}: ${t}`).join(", "),O8e=({stats:e})=>{if(!e||Object.keys(e).length===0)return Z.jsx("span",{children:"-"});const A=Object.entries(e),t=q8e(e);return Z.jsxs("details",{className:"cursor-pointer",children:[Z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:t}),Z.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,o])=>Z.jsxs("div",{children:[i,": ",String(o)]},i))})]})},LpA=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(LpA);const A={};for(const[t,i]of Object.entries(e))t.startsWith("_")||(A[t]=LpA(i));return A},W8e=(e,A)=>{try{if(typeof e.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const t=LpA(e.getConstructorParams()),i=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),o=URL.createObjectURL(i),n=document.createElement("a");n.href=o,n.download=`${A}_input.json`,n.click(),URL.revokeObjectURL(o)}catch(t){alert(`Error downloading input for ${A}: ${t instanceof Error?t.message:String(t)}`)}},Z8e=({solver:e,onStepUntilPhase:A,onDownloadInput:t})=>{const i=e.pipelineDef.map((r,a)=>T8e(e,a)),o=r=>{A?.(r)},n=r=>{r.solverInstance&&(t?t(r.solverInstance,r.name):W8e(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return Z.jsxs("div",{className:"border-t border-gray-200",children:[Z.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:Z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),Z.jsx("div",{className:"overflow-x-auto",children:Z.jsxs("table",{className:"w-full text-sm",children:[Z.jsx("thead",{children:Z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),Z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",Z.jsx("sub",{children:"0"})]}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),Z.jsx("tbody",{children:i.map(r=>Z.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[Z.jsx("td",{className:"px-4 py-2",children:Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),Z.jsx("button",{onClick:()=>o(r.name),disabled:r.status==="Completed"||e.solved||e.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),Z.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(K8e,{status:r.status})}),Z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(P8e,{progress:r.progress})}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),Z.jsx("td",{className:"px-4 py-2 text-gray-500",children:Z.jsx(O8e,{stats:r.stats})}),Z.jsx("td",{className:"px-4 py-2",children:r.solverInstance?Z.jsxs("button",{onClick:()=>n(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),Z.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},V8e=class extends eo.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){console.error("InteractiveGraphics render error:",e)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function j8e({graphics:e}){const A=e.points??[],t=e.lines??[],i=e.rects??[],o=e.circles??[],n=e.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const I=(Q,h)=>{typeof Q=="number"&&(Q<s&&(s=Q),Q>a&&(a=Q)),typeof h=="number"&&(h<r&&(r=h),h>g&&(g=h))};for(const Q of A)I(Q.x,Q.y);for(const Q of t){const h=Q.points??[];for(const u of h)I(u.x,u.y)}for(const Q of i){const h=Q.x??0,u=Q.y??0,d=Q.width??0,f=Q.height??0;I(h,u),I(h+d,u+f)}for(const Q of o){const h=Q.x??0,u=Q.y??0,d=Q.radius??1;I(h-d,u-d),I(h+d,u+d)}for(const Q of n)I(Q.x,Q.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const c=10,B=s-c,l=r-c,C=Math.max(1,a-s+2*c),E=Math.max(1,g-r+2*c);return Z.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${B} ${l} ${C} ${E}`,role:"img","aria-label":"Graphics fallback",children:[i.map((Q,h)=>Z.jsx("rect",{x:Q.x??0,y:Q.y??0,width:Q.width??0,height:Q.height??0,fill:"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1},`rect-${h}`)),t.map((Q,h)=>Z.jsx("polyline",{fill:"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1,points:(Q.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${h}`)),o.map((Q,h)=>Z.jsx("circle",{cx:Q.x??0,cy:Q.y??0,r:Q.radius??1.5,fill:Q.fillColor??"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1},`circle-${h}`)),A.map((Q,h)=>Z.jsx("circle",{cx:Q.x??0,cy:Q.y??0,r:Q.radius??1.5,fill:Q.color??"black"},`point-${h}`)),n.map((Q,h)=>Z.jsx("text",{x:Q.x??0,y:Q.y??0,fontSize:Q.fontSize??10,fill:Q.color??"black",children:Q.text??""},`text-${h}`))]})}var z8e=({solver:e,animationSpeed:A=25,onSolverStarted:t,onSolverCompleted:i})=>{const[o,n]=AA.useReducer(I=>I+1,0),s=AA.useMemo(()=>{try{return e.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(I){return console.error("Visualization error:",I),{points:[],lines:[],rects:[],circles:[]}}},[e,o]),r=AA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);AA.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const I=document.createElement("script");I.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(I)}},[]);const a=e.pipelineDef!==void 0,g=I=>{const c=e;if(!e.solved&&!e.failed){for(;!e.solved&&!e.failed&&c.currentPipelineStepIndex<=c.pipelineDef.findIndex(B=>B.solverName===I);)e.step();n()}};return Z.jsxs("div",{children:[Z.jsx(Y8e,{solver:e,triggerRender:n,animationSpeed:A,onSolverStarted:t,onSolverCompleted:i}),r?Z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):Z.jsx(V8e,{fallback:Z.jsx(j8e,{graphics:s}),children:Z.jsx(L8e,{graphics:s})}),a&&Z.jsx(Z8e,{solver:e,onStepUntilPhase:g})]})};const X8e=()=>{AA.useEffect(()=>{const e="tailwind-cdn-script";if(document.getElementById(e)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const t=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),t)return;const i=document.createElement("script");i.id=e,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},$8e=e=>e.toLowerCase().includes("pack")?$ke:e.toLowerCase().includes("rout")?nGe:Pke,AWe=({solverEvents:e=[]})=>{const[A,t]=AA.useState(null);X8e();const i=AA.useMemo(()=>{const r=new Map;for(const a of e){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[e]),o=AA.useMemo(()=>Array.from(i.keys()),[i]),n=A?i.get(A):null,s=AA.useMemo(()=>{if(!n)return{instance:null,error:null,classFound:!1};const r=ZsA[n.solverName];if(!r)return{instance:null,error:`Solver class "${n.solverName}" not found in SOLVERS registry. Available: ${Object.keys(ZsA).join(", ")}`,classFound:!1};try{const a=n.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[n]);return e.length===0?Z.jsx("div",{className:"rf-p-4",children:Z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:Z.jsxs("div",{className:"rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),Z.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):Z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[Z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[Z.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[o.length," ",o.length===1?"Solver":"Solvers"]}),o.map(r=>{const a=i.get(r),g=A===r;return Z.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>t(r),children:(()=>{const I=$8e(a.solverName);return Z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[Z.jsx(I,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),Z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[Z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),Z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),Z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:n?s.instance?Z.jsx(gD,{fallback:Z.jsx("div",{className:"rf-p-4",children:Z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),Z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",n.solverName]})]})}),children:Z.jsx(z8e,{solver:s.instance})}):Z.jsxs("div",{className:"rf-p-4",children:[Z.jsxs("div",{className:"rf-mb-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:n.solverName}),Z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",n.componentName]})]}),s.error&&Z.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:Z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),Z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[Z.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:Z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),Z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:Z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(n.solverParams,null,2)})})]})]}):Z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:Z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Sgt=({errorMessage:e,errorStack:A,circuitJsonErrors:t})=>{AA.useEffect(()=>{if(e){const i=new Error(e);A&&(i.stack=A);try{RK.captureException(i)}catch{}}},[e,A]),AA.useEffect(()=>{if(t&&t.length>0)for(const i of t){const o=new Error(i.message||"Circuit JSON Error");i.stack&&(o.stack=i.stack);try{RK.captureException(o,{error_type:i.type})}catch{}}},[t])},bgt="0.0.1561",tWe={version:bgt},UpA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},HpA=new Map,s9=e=>{const A=HpA.get(e);return A?Object.fromEntries(Object.entries(A.stores).map(([t,i])=>[t,i.getState()])):{}},eWe=(e,A,t)=>{if(e===void 0)return{type:"untracked",connection:A.connect(t)};const i=HpA.get(t.name);if(i)return{type:"tracked",store:e,...i};const o={connection:A.connect(t),stores:{}};return HpA.set(t.name,o),{type:"tracked",store:e,...o}},xgt=(e,A={})=>(t,i,o)=>{const{enabled:n,anonymousActionType:s,store:r,...a}=A;let g;try{g=(n??(UpA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(UpA?"production":void 0)!=="production"&&n&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),e(t,i,o);const{connection:I,...c}=eWe(r,g,a);let B=!0;o.setState=(E,Q,h)=>{const u=t(E,Q);if(!B)return u;const d=h===void 0?{type:s||"anonymous"}:typeof h=="string"?{type:h}:h;return r===void 0?(I?.send(d,i()),u):(I?.send({...d,type:`${r}/${d.type}`},{...s9(a.name),[r]:o.getState()}),u)};const l=(...E)=>{const Q=B;B=!1,t(...E),B=Q},C=e(o.setState,i,o);if(c.type==="untracked"?I?.init(C):(c.stores[c.store]=o,I?.init(Object.fromEntries(Object.entries(c.stores).map(([E,Q])=>[E,E===c.store?C:Q.getState()])))),o.dispatchFromDevtools&&typeof o.dispatch=="function"){let E=!1;const Q=o.dispatch;o.dispatch=(...h)=>{(UpA?"production":void 0)!=="production"&&h[0].type==="__setState"&&!E&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),E=!0),Q(...h)}}return I.subscribe(E=>{var Q;switch(E.type){case"ACTION":if(typeof E.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return YpA(E.payload,h=>{if(h.type==="__setState"){if(r===void 0){l(h.state);return}Object.keys(h.state).length!==1&&console.error(`
5685
+ `,c=new Blob([I],{type:"text/plain"}),B=URL.createObjectURL(c),l=document.createElement("a");l.href=B,l.download=`${g}.test.ts`,l.click(),URL.revokeObjectURL(B)}catch(a){alert(`Error generating test.ts for ${e.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return Z.jsxs("div",{className:`relative ${A}`,ref:o,children:[Z.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!t),title:`Download options for ${e.constructor.name}`,children:e.constructor.name}),t&&Z.jsxs("div",{className:"absolute top-full left-0 mt-1 bg-white border border-gray-300 rounded shadow-lg z-10 min-w-[150px]",children:[Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:n,children:"Download JSON"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),Z.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},Dgt=e=>e.activeSubSolver?[e,...Dgt(e.activeSubSolver)]:[e],H8e=({solver:e})=>{const A=Dgt(e);return Z.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((t,i)=>Z.jsxs("div",{className:"flex items-center",children:[i>0&&Z.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),Z.jsx(U8e,{solver:t})]},t.constructor.name))})},Y8e=({solver:e,triggerRender:A,animationSpeed:t=25,onSolverStarted:i,onSolverCompleted:o})=>{const[n,s]=AA.useReducer(E=>!E,!1),r=AA.useRef(void 0),a=()=>{!e.solved&&!e.failed&&(e.step(),A())},g=()=>{!e.solved&&!e.failed&&(i&&i(e),e.solve(),A(),o&&o(e))},I=()=>{n?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(e.solved||e.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),o&&e.solved&&o(e);return}e.step(),A()},t))},c=()=>{const E=e;if(E.getCurrentPhase&&!e.solved&&!e.failed){const Q=E.getCurrentPhase();for(;E.getCurrentPhase()===Q&&!e.solved&&!e.failed;)e.step();A()}},B=()=>{if(e.solved||e.failed||n)return;const E=window.prompt("Step until which iteration?",`${e.iterations}`);if(E===null)return;const Q=Number(E);if(!Number.isFinite(Q)){window.alert("Please enter a valid number for the iteration");return}for(;e.iterations<Q&&!e.solved&&!e.failed;)e.step();A(),e.solved&&o&&o(e)};AA.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),AA.useEffect(()=>{(e.solved||e.failed)&&n&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[e.solved,e.failed,n]);const l=e.getCurrentPhase!==void 0,C=l?e.getCurrentPhase():null;return Z.jsxs("div",{className:"space-y-2 p-2 border-b",children:[Z.jsx("div",{className:"flex items-center",children:Z.jsx(H8e,{solver:e})}),Z.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[Z.jsx("button",{onClick:a,disabled:e.solved||e.failed||n,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),Z.jsx("button",{onClick:g,disabled:e.solved||e.failed||n,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),Z.jsx("button",{onClick:I,disabled:e.solved||e.failed,className:`px-3 py-1 rounded text-white text-sm ${n?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:n?"Stop":"Animate"}),Z.jsx("button",{onClick:B,disabled:e.solved||e.failed||n,className:"bg-orange-500 hover:bg-orange-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step Until Iteration"}),l&&Z.jsx("button",{onClick:c,disabled:e.solved||e.failed||n,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),Z.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",e.iterations]}),e.timeToSolve!==void 0&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(e.timeToSolve/1e3).toFixed(3),"s"]}),C&&Z.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",Z.jsx("span",{className:"font-medium",children:C})]}),e.solved&&Z.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),e.failed&&Z.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),e.error&&Z.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",e.error]})]})},J8e=(e,A,t)=>{const i=e.currentPipelineStepIndex;return A<i?"Completed":A===i&&e.activeSubSolver?e.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},T8e=(e,A)=>{const i=e.pipelineDef[A].solverName,o=J8e(e,A),n=e[i],s=e.firstIterationOfPhase?.[i]??null,r=e.iterations;let a=0;if(o==="Completed"){const B=e.pipelineDef[A+1],l=B?e.firstIterationOfPhase?.[B.solverName]:void 0;l!==void 0&&s!==null?a=l-s:s!==null&&(a=r-s)}else o==="In Progress"&&s!==null&&(a=r-s);const g=e.timeSpentOnPhase?.[i]??0;let I=0;o==="Completed"?I=1:o==="In Progress"&&n&&(I=n.progress??0);const c=n?.stats??null;return{index:A,name:i,status:o,firstIteration:s,iterations:a,progress:I,timeSpent:g,stats:c&&Object.keys(c).length>0?c:null,solverInstance:n??null}},K8e=({status:e})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return Z.jsx("span",{className:`font-medium ${A[e]}`,children:e})},P8e=({progress:e})=>{if(e===0)return null;const A=Math.round(e*100);return Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:Z.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),Z.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},q8e=e=>Object.entries(e).map(([A,t])=>`${A}: ${t}`).join(", "),O8e=({stats:e})=>{if(!e||Object.keys(e).length===0)return Z.jsx("span",{children:"-"});const A=Object.entries(e),t=q8e(e);return Z.jsxs("details",{className:"cursor-pointer",children:[Z.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:t}),Z.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,o])=>Z.jsxs("div",{children:[i,": ",String(o)]},i))})]})},LpA=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(LpA);const A={};for(const[t,i]of Object.entries(e))t.startsWith("_")||(A[t]=LpA(i));return A},W8e=(e,A)=>{try{if(typeof e.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const t=LpA(e.getConstructorParams()),i=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),o=URL.createObjectURL(i),n=document.createElement("a");n.href=o,n.download=`${A}_input.json`,n.click(),URL.revokeObjectURL(o)}catch(t){alert(`Error downloading input for ${A}: ${t instanceof Error?t.message:String(t)}`)}},Z8e=({solver:e,onStepUntilPhase:A,onDownloadInput:t})=>{const i=e.pipelineDef.map((r,a)=>T8e(e,a)),o=r=>{A?.(r)},n=r=>{r.solverInstance&&(t?t(r.solverInstance,r.name):W8e(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return Z.jsxs("div",{className:"border-t border-gray-200",children:[Z.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:Z.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),Z.jsx("div",{className:"overflow-x-auto",children:Z.jsxs("table",{className:"w-full text-sm",children:[Z.jsx("thead",{children:Z.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),Z.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",Z.jsx("sub",{children:"0"})]}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),Z.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),Z.jsx("tbody",{children:i.map(r=>Z.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[Z.jsx("td",{className:"px-4 py-2",children:Z.jsxs("div",{className:"flex items-center gap-2",children:[Z.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),Z.jsx("button",{onClick:()=>o(r.name),disabled:r.status==="Completed"||e.solved||e.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M4.5 5.653c0-1.426 1.529-2.33 2.779-1.643l11.54 6.348c1.295.712 1.295 2.573 0 3.285L7.28 19.991c-1.25.687-2.779-.217-2.779-1.643V5.653z",clipRule:"evenodd"})})}),Z.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(K8e,{status:r.status})}),Z.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),Z.jsx("td",{className:"px-4 py-2",children:Z.jsx(P8e,{progress:r.progress})}),Z.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),Z.jsx("td",{className:"px-4 py-2 text-gray-500",children:Z.jsx(O8e,{stats:r.stats})}),Z.jsx("td",{className:"px-4 py-2",children:r.solverInstance?Z.jsxs("button",{onClick:()=>n(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[Z.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:Z.jsx("path",{fillRule:"evenodd",d:"M12 2.25a.75.75 0 01.75.75v11.69l3.22-3.22a.75.75 0 111.06 1.06l-4.5 4.5a.75.75 0 01-1.06 0l-4.5-4.5a.75.75 0 111.06-1.06l3.22 3.22V3a.75.75 0 01.75-.75zm-9 13.5a.75.75 0 01.75.75v2.25a1.5 1.5 0 001.5 1.5h13.5a1.5 1.5 0 001.5-1.5V16.5a.75.75 0 011.5 0v2.25a3 3 0 01-3 3H5.25a3 3 0 01-3-3V16.5a.75.75 0 01.75-.75z",clipRule:"evenodd"})}),Z.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},V8e=class extends eo.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e){console.error("InteractiveGraphics render error:",e)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function j8e({graphics:e}){const A=e.points??[],t=e.lines??[],i=e.rects??[],o=e.circles??[],n=e.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const I=(Q,h)=>{typeof Q=="number"&&(Q<s&&(s=Q),Q>a&&(a=Q)),typeof h=="number"&&(h<r&&(r=h),h>g&&(g=h))};for(const Q of A)I(Q.x,Q.y);for(const Q of t){const h=Q.points??[];for(const u of h)I(u.x,u.y)}for(const Q of i){const h=Q.x??0,u=Q.y??0,d=Q.width??0,f=Q.height??0;I(h,u),I(h+d,u+f)}for(const Q of o){const h=Q.x??0,u=Q.y??0,d=Q.radius??1;I(h-d,u-d),I(h+d,u+d)}for(const Q of n)I(Q.x,Q.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const c=10,B=s-c,l=r-c,C=Math.max(1,a-s+2*c),E=Math.max(1,g-r+2*c);return Z.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${B} ${l} ${C} ${E}`,role:"img","aria-label":"Graphics fallback",children:[i.map((Q,h)=>Z.jsx("rect",{x:Q.x??0,y:Q.y??0,width:Q.width??0,height:Q.height??0,fill:"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1},`rect-${h}`)),t.map((Q,h)=>Z.jsx("polyline",{fill:"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1,points:(Q.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${h}`)),o.map((Q,h)=>Z.jsx("circle",{cx:Q.x??0,cy:Q.y??0,r:Q.radius??1.5,fill:Q.fillColor??"none",stroke:Q.strokeColor??"black",strokeWidth:Q.strokeWidth??1},`circle-${h}`)),A.map((Q,h)=>Z.jsx("circle",{cx:Q.x??0,cy:Q.y??0,r:Q.radius??1.5,fill:Q.color??"black"},`point-${h}`)),n.map((Q,h)=>Z.jsx("text",{x:Q.x??0,y:Q.y??0,fontSize:Q.fontSize??10,fill:Q.color??"black",children:Q.text??""},`text-${h}`))]})}var z8e=({solver:e,animationSpeed:A=25,onSolverStarted:t,onSolverCompleted:i})=>{const[o,n]=AA.useReducer(I=>I+1,0),s=AA.useMemo(()=>{try{return e.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(I){return console.error("Visualization error:",I),{points:[],lines:[],rects:[],circles:[]}}},[e,o]),r=AA.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);AA.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const I=document.createElement("script");I.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(I)}},[]);const a=e.pipelineDef!==void 0,g=I=>{const c=e;if(!e.solved&&!e.failed){for(;!e.solved&&!e.failed&&c.currentPipelineStepIndex<=c.pipelineDef.findIndex(B=>B.solverName===I);)e.step();n()}};return Z.jsxs("div",{children:[Z.jsx(Y8e,{solver:e,triggerRender:n,animationSpeed:A,onSolverStarted:t,onSolverCompleted:i}),r?Z.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):Z.jsx(V8e,{fallback:Z.jsx(j8e,{graphics:s}),children:Z.jsx(L8e,{graphics:s})}),a&&Z.jsx(Z8e,{solver:e,onStepUntilPhase:g})]})};const X8e=()=>{AA.useEffect(()=>{const e="tailwind-cdn-script";if(document.getElementById(e)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const t=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),t)return;const i=document.createElement("script");i.id=e,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},$8e=e=>e.toLowerCase().includes("pack")?$ke:e.toLowerCase().includes("rout")?nGe:Pke,AWe=({solverEvents:e=[]})=>{const[A,t]=AA.useState(null);X8e();const i=AA.useMemo(()=>{const r=new Map;for(const a of e){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[e]),o=AA.useMemo(()=>Array.from(i.keys()),[i]),n=A?i.get(A):null,s=AA.useMemo(()=>{if(!n)return{instance:null,error:null,classFound:!1};const r=ZsA[n.solverName];if(!r)return{instance:null,error:`Solver class "${n.solverName}" not found in SOLVERS registry. Available: ${Object.keys(ZsA).join(", ")}`,classFound:!1};try{const a=n.solverParams,g=a?.input!==void 0?a.input:a;return{instance:new r(g),error:null,classFound:!0}}catch(a){const g=a instanceof Error?a.message:String(a);return console.error("Failed to reconstruct solver:",a),{instance:null,error:`Failed to instantiate solver: ${g}`,classFound:!0}}},[n]);return e.length===0?Z.jsx("div",{className:"rf-p-4",children:Z.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:Z.jsxs("div",{className:"rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),Z.jsx("p",{className:"rf-text-sm rf-text-gray-600",children:"Solvers will appear here when the circuit runs. Solvers are used for tasks like component packing and autorouting."})]})})}):Z.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[Z.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[Z.jsxs("div",{className:"rf-text-xs rf-font-semibold rf-text-gray-500 rf-px-3 rf-py-2 rf-bg-gray-50 rf-border-b rf-border-gray-200",children:[o.length," ",o.length===1?"Solver":"Solvers"]}),o.map(r=>{const a=i.get(r),g=A===r;return Z.jsx("div",{className:`rf-px-3 rf-py-2 rf-cursor-pointer rf-border-b rf-border-gray-100 ${g?"rf-bg-blue-50 rf-border-l-2 rf-border-l-blue-500":"hover:rf-bg-gray-50"}`,onClick:()=>t(r),children:(()=>{const I=$8e(a.solverName);return Z.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[Z.jsx(I,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),Z.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[Z.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),Z.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),Z.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:n?s.instance?Z.jsx(gD,{fallback:Z.jsx("div",{className:"rf-p-4",children:Z.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),Z.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",n.solverName]})]})}),children:Z.jsx(z8e,{solver:s.instance})}):Z.jsxs("div",{className:"rf-p-4",children:[Z.jsxs("div",{className:"rf-mb-4",children:[Z.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:n.solverName}),Z.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",n.componentName]})]}),s.error&&Z.jsx("div",{className:`rf-rounded-md rf-border rf-p-4 rf-mb-4 ${s.classFound?"rf-bg-red-50 rf-border-red-200":"rf-bg-yellow-50 rf-border-yellow-200"}`,children:Z.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),Z.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[Z.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:Z.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),Z.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:Z.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(n.solverParams,null,2)})})]})]}):Z.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:Z.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},Sgt=({errorMessage:e,errorStack:A,circuitJsonErrors:t})=>{AA.useEffect(()=>{if(e){const i=new Error(e);A&&(i.stack=A);try{RK.captureException(i)}catch{}}},[e,A]),AA.useEffect(()=>{if(t&&t.length>0)for(const i of t){const o=new Error(i.message||"Circuit JSON Error");i.stack&&(o.stack=i.stack);try{RK.captureException(o,{error_type:i.type})}catch{}}},[t])},bgt="0.0.1562",tWe={version:bgt},UpA={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},HpA=new Map,s9=e=>{const A=HpA.get(e);return A?Object.fromEntries(Object.entries(A.stores).map(([t,i])=>[t,i.getState()])):{}},eWe=(e,A,t)=>{if(e===void 0)return{type:"untracked",connection:A.connect(t)};const i=HpA.get(t.name);if(i)return{type:"tracked",store:e,...i};const o={connection:A.connect(t),stores:{}};return HpA.set(t.name,o),{type:"tracked",store:e,...o}},xgt=(e,A={})=>(t,i,o)=>{const{enabled:n,anonymousActionType:s,store:r,...a}=A;let g;try{g=(n??(UpA?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!g)return(UpA?"production":void 0)!=="production"&&n&&console.warn("[zustand devtools middleware] Please install/enable Redux devtools extension"),e(t,i,o);const{connection:I,...c}=eWe(r,g,a);let B=!0;o.setState=(E,Q,h)=>{const u=t(E,Q);if(!B)return u;const d=h===void 0?{type:s||"anonymous"}:typeof h=="string"?{type:h}:h;return r===void 0?(I?.send(d,i()),u):(I?.send({...d,type:`${r}/${d.type}`},{...s9(a.name),[r]:o.getState()}),u)};const l=(...E)=>{const Q=B;B=!1,t(...E),B=Q},C=e(o.setState,i,o);if(c.type==="untracked"?I?.init(C):(c.stores[c.store]=o,I?.init(Object.fromEntries(Object.entries(c.stores).map(([E,Q])=>[E,E===c.store?C:Q.getState()])))),o.dispatchFromDevtools&&typeof o.dispatch=="function"){let E=!1;const Q=o.dispatch;o.dispatch=(...h)=>{(UpA?"production":void 0)!=="production"&&h[0].type==="__setState"&&!E&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),E=!0),Q(...h)}}return I.subscribe(E=>{var Q;switch(E.type){case"ACTION":if(typeof E.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return YpA(E.payload,h=>{if(h.type==="__setState"){if(r===void 0){l(h.state);return}Object.keys(h.state).length!==1&&console.error(`
5686
5686
  [zustand devtools middleware] Unsupported __setState action format.
5687
5687
  When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
5688
5688
  and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }