tscircuit 0.0.1252 → 0.0.1253-libonly
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.min.js +4 -4
- package/package.json +3 -9
- package/cli.mjs +0 -14
package/dist/browser.min.js
CHANGED
|
@@ -4942,7 +4942,7 @@ ${o(r.vertices[c+1])}
|
|
|
4942
4942
|
${o(r.vertices[c+2])}
|
|
4943
4943
|
endloop
|
|
4944
4944
|
endfacet`;a.push(I)}}return a.join(`
|
|
4945
|
-
`)};return hhA={serializeText:A},hhA}var EhA,tzA;function NCt(){if(tzA)return EhA;tzA=1;const{geometries:t,modifiers:A}=rW(),{flatten:e,toArray:i}=GCt(),{serializeBinary:n}=RCt(),{serializeText:o}=MCt();return EhA={mimeType:"application/sla",serialize:(a,...g)=>{a=Object.assign({},{binary:!0,statusCallback:null},a),g=e(g);let I=g.filter(l=>t.geom3.isA(l));if(I.length===0)throw new Error("only 3D geometries can be serialized to STL");return g.length!==I.length&&console.warn("some objects could not be serialized to STL"),I=i(A.generalize({snap:!0,triangulate:!0},I)),a.binary?n(I,a):o(I,a)}},EhA}var vCt=NCt();const LCt=g0(vCt);var izA={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"},aD={};for(const t in izA){aD[t]=[];const A=izA[t].split("M").slice(1).map(e=>e.split("L").map(i=>i.trim().split(" ").map(parseFloat)));for(const e of A)for(let i=0;i<e.length-1;i++)aD[t].push({x1:e[i][0],y1:1-e[i][1],x2:e[i+1][0],y2:1-e[i+1][1]})}function UCt(t,A){if(!A.layers||A.layers.length===0)return!0;const e=Q1A(t);return e.length===0?!0:e.some(i=>A.layers.includes(i))}var HCt={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 Yu(t){const{ctx:A,center:e,radius:i,fill:n,realToCanvasMat:o}=t,[s,r]=Pt(o,[e.x,e.y]),a=i*Math.abs(o.a);A.beginPath(),A.arc(s,r,a,0,Math.PI*2),A.fillStyle=n,A.fill()}function Qc(t){const{ctx:A,center:e,width:i,height:n,fill:o,realToCanvasMat:s,borderRadius:r=0,rotation:a=0,stroke:g,strokeWidth:c,isStrokeDashed:I=!1}=t,[l,B]=Pt(s,[e.x,e.y]),C=i*Math.abs(s.a),Q=n*Math.abs(s.a),h=r*Math.abs(s.a),E=c?c*Math.abs(s.a):void 0;if(A.save(),A.translate(l,B),a!==0&&A.rotate(-a*(Math.PI/180)),A.beginPath(),h>0){const u=-C/2,d=-Q/2,p=Math.min(h,C/2,Q/2);A.moveTo(u+p,d),A.lineTo(u+C-p,d),A.arcTo(u+C,d,u+C,d+p,p),A.lineTo(u+C,d+Q-p),A.arcTo(u+C,d+Q,u+C-p,d+Q,p),A.lineTo(u+p,d+Q),A.arcTo(u,d+Q,u,d+Q-p,p),A.lineTo(u,d+p),A.arcTo(u,d,u+p,d,p)}else A.rect(-C/2,-Q/2,C,Q);o&&(A.fillStyle=o,A.fill()),g&&E&&(I?A.setLineDash([E*3,E*2]):A.setLineDash([]),A.strokeStyle=g,A.lineWidth=E,A.stroke()),A.restore()}function eb(t){const{ctx:A,center:e,radius_x:i,radius_y:n,fill:o,stroke:s,strokeWidth:r=.1,realToCanvasMat:a,rotation:g=0}=t,[c,I]=Pt(a,[e.x,e.y]),l=i*Math.abs(a.a),B=n*Math.abs(a.a),C=r*Math.abs(a.a);A.save(),A.translate(c,I),g!==0&&A.rotate(-g*(Math.PI/180)),A.beginPath(),A.ellipse(0,0,l,B,0,0,Math.PI*2),o&&(A.fillStyle=o,A.fill()),s&&(A.strokeStyle=s,A.lineWidth=C,A.stroke()),A.restore()}function ZB(t){const{ctx:A,center:e,width:i,height:n,fill:o,realToCanvasMat:s,rotation:r=0,stroke:a,strokeWidth:g}=t,[c,I]=Pt(s,[e.x,e.y]),l=i*Math.abs(s.a),B=n*Math.abs(s.a),C=g?g*Math.abs(s.a):void 0;if(A.save(),A.translate(c,I),r!==0&&A.rotate(-r*(Math.PI/180)),A.beginPath(),l>B){const Q=B/2,h=l-B;A.moveTo(-h/2,-Q),A.lineTo(h/2,-Q),A.arc(h/2,0,Q,-Math.PI/2,Math.PI/2),A.lineTo(-h/2,Q),A.arc(-h/2,0,Q,Math.PI/2,-Math.PI/2)}else if(B>l){const Q=l/2,h=B-l;A.moveTo(Q,-h/2),A.lineTo(Q,h/2),A.arc(0,h/2,Q,0,Math.PI),A.lineTo(-Q,-h/2),A.arc(0,-h/2,Q,Math.PI,0)}else A.arc(0,0,l/2,0,Math.PI*2);A.closePath(),o&&(A.fillStyle=o,A.fill()),a&&C&&(A.strokeStyle=a,A.lineWidth=C,A.stroke()),A.restore()}function I_(t){const{ctx:A,points:e,fill:i,realToCanvasMat:n}=t;if(e.length<3)return;A.beginPath();const o=e.map(g=>Pt(n,[g.x,g.y])),s=o[0];if(!s)return;const[r,a]=s;A.moveTo(r,a);for(let g=1;g<o.length;g++){const c=o[g];if(!c)continue;const[I,l]=c;A.lineTo(I,l)}A.closePath(),A.fillStyle=i,A.fill()}function ZF(t,A,e,i,n,o,s,r,a,g){const[c,I]=Pt(r,[A.x,A.y]),l=e*Math.abs(r.a),B=i*Math.abs(r.a),C=Math.abs(n)*Math.abs(r.a),Q=o*Math.abs(r.a);t.save(),t.translate(c,I),s!==0&&t.rotate(-s*(Math.PI/180));const h=t.globalCompositeOperation;t.globalCompositeOperation!==void 0&&(t.globalCompositeOperation="source-atop");const E=l,u=B,d=Q;if(t.beginPath(),d>0){const w=-E/2,b=-u/2,k=Math.min(d,E/2,u/2);t.moveTo(w+k,b),t.lineTo(w+E-k,b),t.arcTo(w+E,b,w+E,b+k,k),t.lineTo(w+E,b+u-k),t.arcTo(w+E,b+u,w+E-k,b+u,k),t.lineTo(w+k,b+u),t.arcTo(w,b+u,w,b+u-k,k),t.lineTo(w,b+k),t.arcTo(w,b,w+k,b,k)}else t.rect(-E/2,-u/2,E,u);t.fillStyle=a,t.fill(),t.globalCompositeOperation!==void 0&&(t.globalCompositeOperation=h||"source-over");const p=l-C*2,m=B-C*2,D=Math.max(0,Q-C);if(p>0&&m>0){if(t.beginPath(),D>0){const w=-p/2,b=-m/2,k=Math.min(D,p/2,m/2);t.moveTo(w+k,b),t.lineTo(w+p-k,b),t.arcTo(w+p,b,w+p,b+k,k),t.lineTo(w+p,b+m-k),t.arcTo(w+p,b+m,w+p-k,b+m,k),t.lineTo(w+k,b+m),t.arcTo(w,b+m,w,b+m-k,k),t.lineTo(w,b+k),t.arcTo(w,b,w+k,b,k)}else t.rect(-p/2,-m/2,p,m);t.fillStyle=g,t.fill()}t.restore()}function uhA(t,A,e,i,n,o,s){const[r,a]=Pt(n,[A.x,A.y]),g=e*Math.abs(n.a),c=Math.abs(i)*Math.abs(n.a);t.save();const I=t.globalCompositeOperation;t.globalCompositeOperation!==void 0&&(t.globalCompositeOperation="source-atop"),t.beginPath(),t.arc(r,a,g,0,Math.PI*2),t.fillStyle=o,t.fill(),t.globalCompositeOperation!==void 0&&(t.globalCompositeOperation=I||"source-over");const l=Math.max(0,g-c);l>0&&(t.beginPath(),t.arc(r,a,l,0,Math.PI*2),t.fillStyle=s,t.fill()),t.restore()}function nH(t,A,e,i,n,o,s,r,a){const[g,c]=Pt(s,[A.x,A.y]),I=e*Math.abs(s.a),l=i*Math.abs(s.a),B=Math.abs(n)*Math.abs(s.a);t.save(),t.translate(g,c),o!==0&&t.rotate(-o*(Math.PI/180));const C=t.globalCompositeOperation;t.globalCompositeOperation!==void 0&&(t.globalCompositeOperation="source-atop");const Q=I,h=l;if(t.beginPath(),Q>h){const d=h/2,p=Q-h;t.moveTo(-p/2,-d),t.lineTo(p/2,-d),t.arc(p/2,0,d,-Math.PI/2,Math.PI/2),t.lineTo(-p/2,d),t.arc(-p/2,0,d,Math.PI/2,-Math.PI/2)}else if(h>Q){const d=Q/2,p=h-Q;t.moveTo(d,-p/2),t.lineTo(d,p/2),t.arc(0,p/2,d,0,Math.PI),t.lineTo(-d,-p/2),t.arc(0,-p/2,d,Math.PI,0)}else t.arc(0,0,Q/2,0,Math.PI*2);t.fillStyle=r,t.fill(),t.globalCompositeOperation!==void 0&&(t.globalCompositeOperation=C||"source-over");const E=I-B*2,u=l-B*2;if(E>0&&u>0){if(t.beginPath(),E>u){const d=u/2,p=E-u;t.moveTo(-p/2,-d),t.lineTo(p/2,-d),t.arc(p/2,0,d,-Math.PI/2,Math.PI/2),t.lineTo(-p/2,d),t.arc(-p/2,0,d,Math.PI/2,-Math.PI/2)}else if(u>E){const d=E/2,p=u-E;t.moveTo(d,-p/2),t.lineTo(d,p/2),t.arc(0,p/2,d,0,Math.PI),t.lineTo(-d,-p/2),t.arc(0,-p/2,d,Math.PI,0)}else t.arc(0,0,E/2,0,Math.PI*2);t.fillStyle=a,t.fill()}t.restore()}function nzA(t,A,e,i,n,o,s,r,a){const[g,c]=Pt(s,[A.x,A.y]),I=e*Math.abs(s.a),l=i*Math.abs(s.a),B=Math.abs(n)*Math.abs(s.a);t.save(),t.translate(g,c),o!==0&&t.rotate(-o*(Math.PI/180));const C=t.globalCompositeOperation;t.globalCompositeOperation!==void 0&&(t.globalCompositeOperation="source-atop"),t.beginPath(),t.ellipse(0,0,I,l,0,0,Math.PI*2),t.fillStyle=r,t.fill(),t.globalCompositeOperation!==void 0&&(t.globalCompositeOperation=C||"source-over");const Q=Math.max(0,I-B),h=Math.max(0,l-B);Q>0&&h>0&&(t.beginPath(),t.ellipse(0,0,Q,h,0,0,Math.PI*2),t.fillStyle=a,t.fill()),t.restore()}function dhA(t,A){if(t.length<3||A===0)return t;let e=0,i=0;for(const o of t)e+=o.x,i+=o.y;e/=t.length,i/=t.length;const n=[];for(const o of t){const s=o.x-e,r=o.y-i,a=Math.sqrt(s*s+r*r);if(a>0){const g=s/a,c=r/a;n.push({x:o.x+g*A,y:o.y+c*A})}else n.push({x:o.x+A,y:o.y})}return n}function ozA(t,A,e,i,n,o){if(A.length<3||e>=0)return;Math.abs(e)*Math.abs(i.a);const s=t.globalCompositeOperation;t.globalCompositeOperation!==void 0&&(t.globalCompositeOperation="source-atop"),t.beginPath();const r=A.map(c=>Pt(i,[c.x,c.y])),a=r[0];if(a){const[c,I]=a;t.moveTo(c,I);for(let l=1;l<r.length;l++){const B=r[l];if(B){const[C,Q]=B;t.lineTo(C,Q)}}t.closePath(),t.fillStyle=n,t.fill()}t.globalCompositeOperation!==void 0&&(t.globalCompositeOperation=s||"source-over");const g=dhA(A,e);if(g.length>=3){t.beginPath();const c=g.map(l=>Pt(i,[l.x,l.y])),I=c[0];if(I){const[l,B]=I;t.moveTo(l,B);for(let C=1;C<c.length;C++){const Q=c[C];if(Q){const[h,E]=Q;t.lineTo(h,E)}}t.closePath(),t.fillStyle=o,t.fill()}}t.restore()}function YCt(t,A){const e=t?.includes("top")?"top":"bottom";return A.soldermaskOverCopper[e]??A.soldermaskOverCopper.top}function JCt(t){const{ctx:A,hole:e,realToCanvasMat:i,colorMap:n}=t,o=e.is_covered_with_solder_mask===!0,s=o?0:e.soldermask_margin??0,r=!o&&e.soldermask_margin!==void 0&&e.soldermask_margin!==0,a=YCt(e.layers,n),g=n.substrate,c=n.copper.top;if(e.shape==="circle"){r&&s>0&&Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.outer_diameter/2+s,fill:g,realToCanvasMat:i}),Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.outer_diameter/2,fill:c,realToCanvasMat:i}),r&&s<0&&uhA(A,{x:e.x,y:e.y},e.outer_diameter/2,s,i,a,c),o&&Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.outer_diameter/2,fill:a,realToCanvasMat:i}),o||Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.hole_diameter/2,fill:n.drill,realToCanvasMat:i});return}if(e.shape==="oval"){r&&s>0&&eb({ctx:A,center:{x:e.x,y:e.y},radius_x:e.outer_width/2+s,radius_y:e.outer_height/2+s,fill:g,realToCanvasMat:i,rotation:e.ccw_rotation}),eb({ctx:A,center:{x:e.x,y:e.y},radius_x:e.outer_width/2,radius_y:e.outer_height/2,fill:c,realToCanvasMat:i,rotation:e.ccw_rotation}),r&&s<0&&nzA(A,{x:e.x,y:e.y},e.outer_width/2,e.outer_height/2,s,e.ccw_rotation??0,i,a,c),o&&eb({ctx:A,center:{x:e.x,y:e.y},radius_x:e.outer_width/2,radius_y:e.outer_height/2,fill:a,realToCanvasMat:i,rotation:e.ccw_rotation}),o||eb({ctx:A,center:{x:e.x,y:e.y},radius_x:e.hole_width/2,radius_y:e.hole_height/2,fill:n.drill,realToCanvasMat:i,rotation:e.ccw_rotation});return}if(e.shape==="pill"){r&&s>0&&ZB({ctx:A,center:{x:e.x,y:e.y},width:e.outer_width+s*2,height:e.outer_height+s*2,fill:g,realToCanvasMat:i,rotation:e.ccw_rotation}),ZB({ctx:A,center:{x:e.x,y:e.y},width:e.outer_width,height:e.outer_height,fill:c,realToCanvasMat:i,rotation:e.ccw_rotation}),r&&s<0&&nH(A,{x:e.x,y:e.y},e.outer_width,e.outer_height,s,e.ccw_rotation??0,i,a,c),o&&ZB({ctx:A,center:{x:e.x,y:e.y},width:e.outer_width,height:e.outer_height,fill:a,realToCanvasMat:i,rotation:e.ccw_rotation}),o||ZB({ctx:A,center:{x:e.x,y:e.y},width:e.hole_width,height:e.hole_height,fill:n.drill,realToCanvasMat:i,rotation:e.ccw_rotation});return}if(e.shape==="circular_hole_with_rect_pad"){if(r&&s>0&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.rect_pad_width+s*2,height:e.rect_pad_height+s*2,fill:g,realToCanvasMat:i,borderRadius:e.rect_border_radius??0}),Qc({ctx:A,center:{x:e.x,y:e.y},width:e.rect_pad_width,height:e.rect_pad_height,fill:c,realToCanvasMat:i,borderRadius:e.rect_border_radius??0}),r&&s<0&&ZF(A,{x:e.x,y:e.y},e.rect_pad_width,e.rect_pad_height,s,e.rect_border_radius??0,0,i,a,c),o&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.rect_pad_width,height:e.rect_pad_height,fill:a,realToCanvasMat:i,borderRadius:e.rect_border_radius??0}),!o){const I=e.x+(e.hole_offset_x??0),l=e.y+(e.hole_offset_y??0);Yu({ctx:A,center:{x:I,y:l},radius:e.hole_diameter/2,fill:n.drill,realToCanvasMat:i})}return}if(e.shape==="pill_hole_with_rect_pad"){if(r&&s>0&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.rect_pad_width+s*2,height:e.rect_pad_height+s*2,fill:g,realToCanvasMat:i,borderRadius:e.rect_border_radius??0}),Qc({ctx:A,center:{x:e.x,y:e.y},width:e.rect_pad_width,height:e.rect_pad_height,fill:c,realToCanvasMat:i,borderRadius:e.rect_border_radius??0}),r&&s<0&&ZF(A,{x:e.x,y:e.y},e.rect_pad_width,e.rect_pad_height,s,e.rect_border_radius??0,0,i,a,c),o&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.rect_pad_width,height:e.rect_pad_height,fill:a,realToCanvasMat:i,borderRadius:e.rect_border_radius??0}),!o){const I=e.x+(e.hole_offset_x??0),l=e.y+(e.hole_offset_y??0);ZB({ctx:A,center:{x:I,y:l},width:e.hole_width,height:e.hole_height,fill:n.drill,realToCanvasMat:i})}return}if(e.shape==="rotated_pill_hole_with_rect_pad"){if(r&&s>0&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.rect_pad_width+s*2,height:e.rect_pad_height+s*2,fill:g,realToCanvasMat:i,borderRadius:e.rect_border_radius??0,rotation:e.rect_ccw_rotation}),Qc({ctx:A,center:{x:e.x,y:e.y},width:e.rect_pad_width,height:e.rect_pad_height,fill:c,realToCanvasMat:i,borderRadius:e.rect_border_radius??0,rotation:e.rect_ccw_rotation}),r&&s<0&&ZF(A,{x:e.x,y:e.y},e.rect_pad_width,e.rect_pad_height,s,e.rect_border_radius??0,e.rect_ccw_rotation??0,i,a,c),o&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.rect_pad_width,height:e.rect_pad_height,fill:a,realToCanvasMat:i,borderRadius:e.rect_border_radius??0,rotation:e.rect_ccw_rotation}),!o){const I=e.x+(e.hole_offset_x??0),l=e.y+(e.hole_offset_y??0);ZB({ctx:A,center:{x:I,y:l},width:e.hole_width,height:e.hole_height,fill:n.drill,realToCanvasMat:i,rotation:e.hole_ccw_rotation})}return}if(e.shape==="hole_with_polygon_pad"){const I=e.pad_outline;if(I&&I.length>=3){const l=I.map(B=>({x:e.x+B.x,y:e.y+B.y}));if(r&&s>0){const B=dhA(l,s);I_({ctx:A,points:B,fill:g,realToCanvasMat:i})}I_({ctx:A,points:l,fill:c,realToCanvasMat:i}),r&&s<0&&ozA(A,l,s,i,a,c),o&&I_({ctx:A,points:l,fill:a,realToCanvasMat:i})}if(!o){const l=e.x+(e.hole_offset_x??0),B=e.y+(e.hole_offset_y??0),C=e.hole_shape;C==="circle"?Yu({ctx:A,center:{x:l,y:B},radius:(e.hole_diameter??0)/2,fill:n.drill,realToCanvasMat:i}):C==="oval"?eb({ctx:A,center:{x:l,y:B},radius_x:(e.hole_width??0)/2,radius_y:(e.hole_height??0)/2,fill:n.drill,realToCanvasMat:i}):C==="pill"?ZB({ctx:A,center:{x:l,y:B},width:e.hole_width??0,height:e.hole_height??0,fill:n.drill,realToCanvasMat:i}):C==="rotated_pill"&&ZB({ctx:A,center:{x:l,y:B},width:e.hole_width??0,height:e.hole_height??0,fill:n.drill,realToCanvasMat:i})}return}}function TCt(t){const{ctx:A,via:e,realToCanvasMat:i,colorMap:n}=t;Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.outer_diameter/2,fill:n.copper.top,realToCanvasMat:i}),Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.hole_diameter/2,fill:n.drill,realToCanvasMat:i})}function oH(t){return"ccw_rotation"in t&&typeof t.ccw_rotation=="number"?t.ccw_rotation:0}function KCt(t){const{ctx:A,hole:e,realToCanvasMat:i,colorMap:n}=t,o=e.is_covered_with_solder_mask===!0,s=o?0:e.soldermask_margin??0,r=!o&&e.soldermask_margin!==void 0&&e.soldermask_margin!==0,a=n.substrate,g=n.soldermaskOverCopper.top,c=n.soldermaskOverCopper.top;if(e.hole_shape==="circle"){r&&s>0&&Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.hole_diameter/2+s,fill:a,realToCanvasMat:i}),o||(Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.hole_diameter/2,fill:n.drill,realToCanvasMat:i}),r&&s<0&&uhA(A,{x:e.x,y:e.y},e.hole_diameter/2,s,i,c,n.drill)),o&&Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.hole_diameter/2,fill:g,realToCanvasMat:i});return}if(e.hole_shape==="square"){const I=oH(e);r&&s>0&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.hole_diameter+s*2,height:e.hole_diameter+s*2,fill:a,realToCanvasMat:i,rotation:I}),o||(Qc({ctx:A,center:{x:e.x,y:e.y},width:e.hole_diameter,height:e.hole_diameter,fill:n.drill,realToCanvasMat:i,rotation:I}),r&&s<0&&ZF(A,{x:e.x,y:e.y},e.hole_diameter,e.hole_diameter,s,0,I,i,c,n.drill)),o&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.hole_diameter,height:e.hole_diameter,fill:g,realToCanvasMat:i,rotation:I});return}if(e.hole_shape==="oval"){const I=oH(e);r&&s>0&&eb({ctx:A,center:{x:e.x,y:e.y},radius_x:e.hole_width/2+s,radius_y:e.hole_height/2+s,fill:a,realToCanvasMat:i,rotation:I}),o||(eb({ctx:A,center:{x:e.x,y:e.y},radius_x:e.hole_width/2,radius_y:e.hole_height/2,fill:n.drill,realToCanvasMat:i,rotation:I}),r&&s<0&&nzA(A,{x:e.x,y:e.y},e.hole_width/2,e.hole_height/2,s,I,i,c,n.drill)),o&&eb({ctx:A,center:{x:e.x,y:e.y},radius_x:e.hole_width/2,radius_y:e.hole_height/2,fill:g,realToCanvasMat:i,rotation:I});return}if(e.hole_shape==="rect"){const I=oH(e);r&&s>0&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.hole_width+s*2,height:e.hole_height+s*2,fill:a,realToCanvasMat:i,rotation:I}),o||(Qc({ctx:A,center:{x:e.x,y:e.y},width:e.hole_width,height:e.hole_height,fill:n.drill,realToCanvasMat:i,rotation:I}),r&&s<0&&ZF(A,{x:e.x,y:e.y},e.hole_width,e.hole_height,s,0,I,i,c,n.drill)),o&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.hole_width,height:e.hole_height,fill:g,realToCanvasMat:i,rotation:I});return}if(e.hole_shape==="pill"){const I=oH(e);r&&s>0&&ZB({ctx:A,center:{x:e.x,y:e.y},width:e.hole_width+s*2,height:e.hole_height+s*2,fill:a,realToCanvasMat:i,rotation:I}),o||(ZB({ctx:A,center:{x:e.x,y:e.y},width:e.hole_width,height:e.hole_height,fill:n.drill,realToCanvasMat:i,rotation:I}),r&&s<0&&nH(A,{x:e.x,y:e.y},e.hole_width,e.hole_height,s,I,i,c,n.drill)),o&&ZB({ctx:A,center:{x:e.x,y:e.y},width:e.hole_width,height:e.hole_height,fill:g,realToCanvasMat:i,rotation:I});return}if(e.hole_shape==="rotated_pill"){const I=oH(e);r&&s>0&&ZB({ctx:A,center:{x:e.x,y:e.y},width:e.hole_width+s*2,height:e.hole_height+s*2,fill:a,realToCanvasMat:i,rotation:I}),o||(ZB({ctx:A,center:{x:e.x,y:e.y},width:e.hole_width,height:e.hole_height,fill:n.drill,realToCanvasMat:i,rotation:I}),r&&s<0&&nH(A,{x:e.x,y:e.y},e.hole_width,e.hole_height,s,I,i,c,n.drill)),o&&ZB({ctx:A,center:{x:e.x,y:e.y},width:e.hole_width,height:e.hole_height,fill:g,realToCanvasMat:i,rotation:I});return}}function PCt(t,A){return A.copper[t]??A.copper.top}function szA(t,A){return A.soldermaskOverCopper[t]??A.soldermaskOverCopper.top}function l_(t,A=0){return(t.corner_radius??t.rect_border_radius??0)+A}function qCt(t){const{ctx:A,pad:e,realToCanvasMat:i,colorMap:n}=t,o=PCt(e.layer,n),s=e.is_covered_with_solder_mask===!0,r=s?0:e.soldermask_margin??0,a=!s&&e.soldermask_margin!==void 0&&e.soldermask_margin!==0,g=szA(e.layer,n),c=n.substrate,I=szA(e.layer,n);if(e.shape==="rect"){a&&r>0&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.width+r*2,height:e.height+r*2,fill:c,realToCanvasMat:i,borderRadius:l_(e)}),Qc({ctx:A,center:{x:e.x,y:e.y},width:e.width,height:e.height,fill:o,realToCanvasMat:i,borderRadius:l_(e)}),a&&r<0&&ZF(A,{x:e.x,y:e.y},e.width,e.height,r,l_(e),0,i,g,o),s&&r===0&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.width,height:e.height,fill:I,realToCanvasMat:i,borderRadius:l_(e)});return}if(e.shape==="rotated_rect"){a&&r>0&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.width+r*2,height:e.height+r*2,fill:c,realToCanvasMat:i,borderRadius:l_(e),rotation:e.ccw_rotation??0}),Qc({ctx:A,center:{x:e.x,y:e.y},width:e.width,height:e.height,fill:o,realToCanvasMat:i,borderRadius:l_(e),rotation:e.ccw_rotation??0}),a&&r<0&&ZF(A,{x:e.x,y:e.y},e.width,e.height,r,l_(e),e.ccw_rotation??0,i,g,o),s&&r===0&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.width,height:e.height,fill:I,realToCanvasMat:i,borderRadius:l_(e),rotation:e.ccw_rotation??0});return}if(e.shape==="circle"){a&&r>0&&Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.radius+r,fill:c,realToCanvasMat:i}),Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.radius,fill:o,realToCanvasMat:i}),a&&r<0&&uhA(A,{x:e.x,y:e.y},e.radius,r,i,g,o),s&&r===0&&Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.radius,fill:I,realToCanvasMat:i});return}if(e.shape==="pill"){a&&r>0&&ZB({ctx:A,center:{x:e.x,y:e.y},width:e.width+r*2,height:e.height+r*2,fill:c,realToCanvasMat:i}),ZB({ctx:A,center:{x:e.x,y:e.y},width:e.width,height:e.height,fill:o,realToCanvasMat:i}),a&&r<0&&nH(A,{x:e.x,y:e.y},e.width,e.height,r,0,i,g,o),s&&r===0&&ZB({ctx:A,center:{x:e.x,y:e.y},width:e.width,height:e.height,fill:I,realToCanvasMat:i});return}if(e.shape==="rotated_pill"){a&&r>0&&ZB({ctx:A,center:{x:e.x,y:e.y},width:e.width+r*2,height:e.height+r*2,fill:c,realToCanvasMat:i,rotation:e.ccw_rotation??0}),ZB({ctx:A,center:{x:e.x,y:e.y},width:e.width,height:e.height,fill:o,realToCanvasMat:i,rotation:e.ccw_rotation??0}),a&&r<0&&nH(A,{x:e.x,y:e.y},e.width,e.height,r,e.ccw_rotation??0,i,g,o),s&&r===0&&ZB({ctx:A,center:{x:e.x,y:e.y},width:e.width,height:e.height,fill:I,realToCanvasMat:i,rotation:e.ccw_rotation??0});return}if(e.shape==="polygon"){if(e.points&&e.points.length>=3){if(a&&r>0){const l=dhA(e.points,r);I_({ctx:A,points:l,fill:c,realToCanvasMat:i})}I_({ctx:A,points:e.points,fill:o,realToCanvasMat:i}),a&&r<0&&ozA(A,e.points,r,i,g,o),s&&r===0&&I_({ctx:A,points:e.points,fill:I,realToCanvasMat:i})}return}}function sH(t){const{ctx:A,start:e,end:i,strokeWidth:n,stroke:o,realToCanvasMat:s,lineCap:r="round"}=t,[a,g]=Pt(s,[e.x,e.y]),[c,I]=Pt(s,[i.x,i.y]),l=n*Math.abs(s.a);A.beginPath(),A.moveTo(a,g),A.lineTo(c,I),A.lineWidth=l,A.strokeStyle=o,A.lineCap=r,A.stroke()}function OCt(t,A){return A.copper[t]??A.copper.top}function WCt(t){const{ctx:A,trace:e,realToCanvasMat:i,colorMap:n}=t;if(!(!e.route||!Array.isArray(e.route)||e.route.length<2))for(let o=0;o<e.route.length-1;o++){const s=e.route[o],r=e.route[o+1];if(!s||!r)continue;const a="layer"in s?s.layer:"layer"in r?r.layer:null;if(!a)continue;const g=OCt(a,n),c="width"in s?s.width:"width"in r?r.width:.1;sH({ctx:A,start:{x:s.x,y:s.y},end:{x:r.x,y:r.y},strokeWidth:c,stroke:g,realToCanvasMat:i,lineCap:"round"})}}function aW(t){const{ctx:A,points:e,fill:i,stroke:n,strokeWidth:o=1,realToCanvasMat:s,closePath:r=!1}=t;if(e.length<2)return;A.beginPath();const a=e.map(l=>Pt(s,[l.x,l.y])),g=a[0];if(!g)return;const[c,I]=g;A.moveTo(c,I);for(let l=1;l<a.length;l++){const B=a[l];if(!B)continue;const[C,Q]=B;A.lineTo(C,Q)}if(r&&A.closePath(),i&&(A.fillStyle=i,A.fill()),n){const l=o*Math.abs(s.a);A.strokeStyle=n,A.lineWidth=l,A.stroke()}}function ZCt(t){const{ctx:A,board:e,realToCanvasMat:i,colorMap:n}=t,{width:o,height:s,center:r,outline:a}=e;if(a&&Array.isArray(a)&&a.length>=3){aW({ctx:A,points:a.map(g=>({x:g.x,y:g.y})),stroke:n.boardOutline,strokeWidth:.1,realToCanvasMat:i,closePath:!0});return}if(o!==void 0&&s!==void 0&&r){Qc({ctx:A,center:r,width:o,height:s,fill:"transparent",realToCanvasMat:i});const g=o/2,c=s/2,I=[{x:r.x-g,y:r.y-c},{x:r.x+g,y:r.y-c},{x:r.x+g,y:r.y+c},{x:r.x-g,y:r.y+c}];aW({ctx:A,points:I,stroke:n.boardOutline,strokeWidth:.1,realToCanvasMat:i,closePath:!0})}}var VCt=.62,jCt=.3,zCt=1,XCt=.13;function gW(t,A){const e=A*VCt,i=e*jCt,n=e*zCt,o=Array.from(t);let s=0;o.forEach((a,g)=>{s+=a===" "?n:e,g<o.length-1&&(s+=i)});const r=Math.max(A*XCt,.35);return{width:s,height:A,glyphWidth:e,letterSpacing:i,spaceWidth:n,strokeWidth:r}}function phA(t,A){const e=A.width+A.strokeWidth,i=A.height+A.strokeWidth;let n=0,o=0;return t==="center"?n=-e/2:t==="top_left"||t==="bottom_left"||t==="center_left"?n=0:(t==="top_right"||t==="bottom_right"||t==="center_right")&&(n=-e),t==="center"?o=-i/2:t==="top_left"||t==="top_right"||t==="top_center"?o=0:t==="bottom_left"||t==="bottom_right"||t==="bottom_center"?o=-i:o=0,{x:n,y:o}}var $Ct=t=>aD[t]??aD[t.toUpperCase()];function fhA(t){const{ctx:A,text:e,fontSize:i,startX:n,startY:o}=t,s=gW(e,i),{glyphWidth:r,letterSpacing:a,spaceWidth:g,height:c,strokeWidth:I}=s,l=o,B=Array.from(e);let C=n+I/2;B.forEach((Q,h)=>{const E=$Ct(Q),u=Q===" "?g:r;if(E?.length){A.beginPath();for(const d of E){const p=C+d.x1*r,m=l+(1-d.y1)*c,D=C+d.x2*r,w=l+(1-d.y2)*c;A.moveTo(p,m),A.lineTo(D,w)}A.stroke()}C+=u,h<B.length-1&&(C+=a)})}function yhA(t){const{ctx:A,text:e,x:i,y:n,fontSize:o,color:s,realToCanvasMat:r,anchorAlignment:a,rotation:g=0}=t;if(!e)return;const[c,I]=Pt(r,[i,n]),l=Math.abs(r.a),B=o*l,C=gW(e,B),Q=phA(a,C);A.save(),A.translate(c,I),g!==0&&A.rotate(-g*(Math.PI/180)),A.lineWidth=C.strokeWidth,A.lineCap="round",A.lineJoin="round",A.strokeStyle=s,fhA({ctx:A,text:e,fontSize:B,startX:Q.x,startY:Q.y}),A.restore()}function AQt(t,A){return t==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function eQt(t){return t||"center"}function tQt(t){const{ctx:A,text:e,realToCanvasMat:i,colorMap:n}=t,o=e.text??"";if(!o)return;const s=AQt(e.layer,n),[r,a]=Pt(i,[e.anchor_position.x,e.anchor_position.y]),g=Math.abs(i.a),c=(e.font_size??1)*g,I=e.ccw_rotation??0,l=gW(o,c),B=eQt(e.anchor_alignment),C=phA(B,l);A.save(),A.translate(r,a),I!==0&&A.rotate(-I*(Math.PI/180)),e.layer==="bottom"&&A.scale(-1,1),A.lineWidth=l.strokeWidth,A.lineCap="round",A.lineJoin="round",A.strokeStyle=s,fhA({ctx:A,text:o,fontSize:c,startX:C.x,startY:C.y}),A.restore()}function iQt(t,A){return t==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function nQt(t){const{ctx:A,rect:e,realToCanvasMat:i,colorMap:n}=t,o=iQt(e.layer,n);Qc({ctx:A,center:e.center,width:e.width,height:e.height,fill:o,realToCanvasMat:i})}function oQt(t,A){return t==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function sQt(t){const{ctx:A,circle:e,realToCanvasMat:i,colorMap:n}=t,o=oQt(e.layer,n);Yu({ctx:A,center:e.center,radius:e.radius,fill:o,realToCanvasMat:i})}function rQt(t,A){return t==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function aQt(t){const{ctx:A,line:e,realToCanvasMat:i,colorMap:n}=t,o=rQt(e.layer,n);sH({ctx:A,start:{x:e.x1,y:e.y1},end:{x:e.x2,y:e.y2},strokeWidth:e.stroke_width??.1,stroke:o,realToCanvasMat:i})}function gQt(t,A){return t==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function cQt(t){const{ctx:A,path:e,realToCanvasMat:i,colorMap:n}=t,o=gQt(e.layer,n);if(!(!e.route||e.route.length<2))for(let s=0;s<e.route.length-1;s++){const r=e.route[s],a=e.route[s+1];!r||!a||sH({ctx:A,start:{x:r.x,y:r.y},end:{x:a.x,y:a.y},strokeWidth:e.stroke_width??.1,stroke:o,realToCanvasMat:i})}}function IQt(t,A){return t==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function lQt(t){const{ctx:A,oval:e,realToCanvasMat:i,colorMap:n}=t,o=IQt(e.layer,n);eb({ctx:A,center:e.center,radius_x:e.radius_x,radius_y:e.radius_y,stroke:o,strokeWidth:.1,realToCanvasMat:i,rotation:e.ccw_rotation??0})}function BQt(t,A){return t==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function CQt(t){const{ctx:A,pill:e,realToCanvasMat:i,colorMap:n}=t,o=BQt(e.layer,n);ZB({ctx:A,center:e.center,width:e.width,height:e.height,stroke:o,strokeWidth:.2,realToCanvasMat:i})}function QQt(t){const{ctx:A,cutout:e,realToCanvasMat:i,colorMap:n}=t;if(e.shape==="rect"){Qc({ctx:A,center:e.center,width:e.width,height:e.height,fill:n.drill,realToCanvasMat:i,rotation:e.rotation??0,borderRadius:e.corner_radius??0});return}if(e.shape==="circle"){Yu({ctx:A,center:e.center,radius:e.radius,fill:n.drill,realToCanvasMat:i});return}if(e.shape==="polygon"){e.points&&e.points.length>=3&&I_({ctx:A,points:e.points,fill:n.drill,realToCanvasMat:i});return}}function hQt(t,A){const e=parseInt(t.slice(1,3),16),i=parseInt(t.slice(3,5),16),n=parseInt(t.slice(5,7),16);return`rgba(${e}, ${i}, ${n}, ${A})`}function EQt(t){const{ctx:A,keepout:e,realToCanvasMat:i,colorMap:n}=t,o=n.keepout,s=hQt(n.keepout,.2),r=1;if(e.shape==="rect"){const[a,g]=Pt(i,[e.center.x,e.center.y]),c=e.width*Math.abs(i.a),I=e.height*Math.abs(i.a),l=e.rotation??0;A.save(),A.translate(a,g),l!==0&&A.rotate(-l*(Math.PI/180)),A.beginPath(),A.rect(-c/2,-I/2,c,I),A.fillStyle=s,A.fill(),A.beginPath(),A.rect(-c/2,-I/2,c,I),A.clip();const B=r*Math.abs(i.a),C=Math.sqrt(c*c+I*I),Q=c/2,h=I/2;A.strokeStyle=o,A.lineWidth=.15*Math.abs(i.a),A.setLineDash([]);for(let E=-C;E<C*2;E+=B){A.beginPath();const u=-Q+E,d=-h,p=-Q+E+C,m=-h+C;A.moveTo(u,d),A.lineTo(p,m),A.stroke()}A.restore();return}if(e.shape==="circle"){const[a,g]=Pt(i,[e.center.x,e.center.y]),c=e.radius*Math.abs(i.a),I=r*Math.abs(i.a);A.save(),A.translate(a,g),A.beginPath(),A.arc(0,0,c,0,Math.PI*2),A.fillStyle=s,A.fill(),A.beginPath(),A.arc(0,0,c,0,Math.PI*2),A.clip();const l=c*2;A.strokeStyle=o,A.lineWidth=.15*Math.abs(i.a),A.setLineDash([]);for(let B=-l;B<l*2;B+=I)A.beginPath(),A.moveTo(B-l,-l),A.lineTo(B+l,l),A.stroke();A.restore();return}}function uQt(t,A){return A.copper[t]??A.copper.top}function dQt(t,A,e,i,n){if(Math.abs(n)<1e-10)return null;const o=e-t,s=i-A,r=Math.hypot(o,s);if(r<1e-10)return null;const a=Math.abs(n)*(r/2),g=r/2,c=(a*a+g*g)/(2*a),I=c-a,l=(t+e)/2,B=(A+i)/2,C=-s/r,Q=o/r,h=n>0?-1:1,E=l+h*C*I,u=B+h*Q*I;return{centerX:E,centerY:u,radius:c}}function mhA(t,A,e,i,n,o,s){if(Math.abs(o)<1e-10){const[p,m]=Pt(s,[i,n]);t.lineTo(p,m);return}const r=dQt(A,e,i,n,o);if(!r){const[p,m]=Pt(s,[i,n]);t.lineTo(p,m);return}const[a,g]=Pt(s,[A,e]),[c,I]=Pt(s,[i,n]),[l,B]=Pt(s,[r.centerX,r.centerY]),C=Math.hypot(a-l,g-B),Q=Math.atan2(g-B,a-l),h=Math.atan2(I-B,c-l),u=s.a*s.d-s.b*s.c<0,d=o>0?!u:u;t.arc(l,B,C,Q,h,d)}function rzA(t,A,e){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]=Pt(e,[s.x,s.y]);t.moveTo(a,g),mhA(t,s.x,s.y,r.x,r.y,1,e),mhA(t,r.x,r.y,s.x,s.y,1,e);return}}const i=A.vertices[0];if(!i)return;const[n,o]=Pt(e,[i.x,i.y]);t.moveTo(n,o);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 c=r.bulge??0;if(Math.abs(c)<1e-10){const[I,l]=Pt(e,[g.x,g.y]);t.lineTo(I,l)}else mhA(t,r.x,r.y,g.x,g.y,c,e)}}function pQt(t){const{ctx:A,pour:e,realToCanvasMat:i,colorMap:n}=t,o=uQt(e.layer,n);if(A.save(),e.shape==="rect"){const[s,r]=Pt(i,[e.center.x,e.center.y]),a=e.width*Math.abs(i.a),g=e.height*Math.abs(i.a);A.translate(s,r),e.rotation&&A.rotate(-e.rotation*(Math.PI/180)),A.beginPath(),A.rect(-a/2,-g/2,a,g),A.fillStyle=o,A.globalAlpha=.5,A.fill(),A.restore();return}if(e.shape==="polygon"){if(e.points&&e.points.length>=3){const s=e.points.map(c=>Pt(i,[c.x,c.y])),r=s[0];if(!r){A.restore();return}A.beginPath();const[a,g]=r;A.moveTo(a,g);for(let c=1;c<s.length;c++){const I=s[c];if(!I)continue;const[l,B]=I;A.lineTo(l,B)}A.closePath(),A.fillStyle=o,A.globalAlpha=.5,A.fill()}A.restore();return}if(e.shape==="brep"){if(A.beginPath(),rzA(A,e.brep_shape.outer_ring,i),e.brep_shape.inner_rings)for(const s of e.brep_shape.inner_rings)rzA(A,s,i);A.fillStyle=o,A.globalAlpha=.5,A.fill("evenodd"),A.restore();return}A.restore()}var fQt={left:.2,right:.2,top:.2,bottom:.2};function yQt(t){return t?t.includes("left")?"center_left":t.includes("right")?"center_right":"center":"center"}function mQt(t){const{ctx:A,text:e,realToCanvasMat:i,colorMap:n}=t,o=e.text??"";if(!o)return;const[s,r]=Pt(i,[e.anchor_position.x,e.anchor_position.y]),a=Math.abs(i.a),g=(e.font_size??1)*a,c=e.ccw_rotation??0,I={...fQt,...e.knockout_padding},l=n.copper[e.layer]??n.copper.top,B=gW(o,g),C=B.width+B.strokeWidth,Q=yQt(e.anchor_alignment),h=phA(Q,B);if(A.save(),A.translate(s,r),e.is_mirrored&&A.scale(-1,1),c!==0&&A.rotate(-c*(Math.PI/180)),A.lineWidth=B.strokeWidth,A.lineCap="round",A.lineJoin="round",e.is_knockout){const E=I.left*a,u=I.right*a,d=I.top*a,p=I.bottom*a,m=h.x-E*4,D=h.y-d*4,w=C+E*2+u*2,b=B.height+B.strokeWidth+d*2+p*2;A.fillStyle=l,A.fillRect(m,D,w,b)}else A.strokeStyle=l;fhA({ctx:A,text:o,fontSize:g,startX:h.x,startY:h.y}),A.restore()}var wQt="rgba(255,255,255,0.5)";function DQt(t,A){return wQt}function SQt(t){const{ctx:A,text:e,realToCanvasMat:i}=t,n=DQt(e.layer),o=e.color??n,s=e.font_size;yhA({ctx:A,text:e.text,x:e.anchor_position.x,y:e.anchor_position.y,fontSize:s,color:o,realToCanvasMat:i,anchorAlignment:e.anchor_alignment})}function bQt(t){const{ctx:A,rect:e,realToCanvasMat:i}=t,o=e.color??"rgba(255,255,255,0.5)",s=e.is_filled??!1,r=e.has_stroke??!0,a=e.is_stroke_dashed??!1;Qc({ctx:A,center:e.center,width:e.width,height:e.height,fill:s?o:void 0,stroke:r?o:void 0,strokeWidth:r?e.stroke_width:void 0,borderRadius:e.corner_radius,realToCanvasMat:i,isStrokeDashed:a})}function xQt(t){const{ctx:A,rect:e,realToCanvasMat:i}=t,o=e.color??"rgb(89, 148, 220)",s=e.is_filled??!1,r=e.has_stroke??!0,a=e.is_stroke_dashed??!1;Qc({ctx:A,center:e.center,width:e.width,height:e.height,fill:s?o:void 0,stroke:r?o:void 0,strokeWidth:r?e.stroke_width:void 0,borderRadius:e.corner_radius,realToCanvasMat:i,isStrokeDashed:a})}function _Qt(t){const{ctx:A,path:e,realToCanvasMat:i}=t,o=e.color??"rgba(255,255,255,0.5)";if(!(!e.route||e.route.length<2))for(let s=0;s<e.route.length-1;s++){const r=e.route[s],a=e.route[s+1];!r||!a||sH({ctx:A,start:{x:r.x,y:r.y},end:{x:a.x,y:a.y},strokeWidth:e.stroke_width??.1,stroke:o,realToCanvasMat:i})}}function kQt(t){const{ctx:A,path:e,realToCanvasMat:i}=t,o=e.color??"rgb(89, 148, 220)";if(!(!e.route||e.route.length<2))for(let s=0;s<e.route.length-1;s++){const r=e.route[s],a=e.route[s+1];!r||!a||sH({ctx:A,start:{x:r.x,y:r.y},end:{x:a.x,y:a.y},strokeWidth:e.stroke_width??.1,stroke:o,realToCanvasMat:i})}}var FQt="rgb(89, 148, 220)";function GQt(t){const{ctx:A,text:e,realToCanvasMat:i}=t,n=FQt,o=e.color??n,s=e.font_size??1;yhA({ctx:A,text:e.text??"",x:e.anchor_position.x,y:e.anchor_position.y,fontSize:s,color:o,realToCanvasMat:i,anchorAlignment:e.anchor_alignment??"center"})}var RQt=1.5,MQt=.6,NQt=.3;function whA(t){const A=Math.hypot(t.x,t.y)||1;return{x:t.x/A,y:t.y/A}}function azA(t){const{ctx:A,from:e,to:i,realToCanvasMat:n,color:o,fontSize:s,arrowSize:r=1,strokeWidth:a,text:g,textRotation:c,offset:I}=t,l=whA({x:i.x-e.x,y:i.y-e.y}),B={x:-l.y,y:l.x},C=I?.direction&&typeof I.direction.x=="number"&&typeof I.direction.y=="number",Q=C?whA(I.direction):{x:0,y:0},h=I?.distance??0,E={x:Q.x*h,y:Q.y*h},u={x:e.x+E.x,y:e.y+E.y},d={x:i.x+E.x,y:i.y+E.y},p={x:u.x+l.x*r,y:u.y+l.y*r},m={x:d.x-l.x*r,y:d.y-l.y*r};Math.abs(n.a);const D=a??r/5,w=o||"rgba(255,255,255,0.5)",b=C&&(Math.abs(Q.x)>Number.EPSILON||Math.abs(Q.y)>Number.EPSILON)?Q:B,k=h+.5,x=[],N=Y=>{const H={x:Y.x+b.x*k,y:Y.y+b.y*k},O=D/2,Z={x:-b.y,y:b.x};return[{x:Y.x+Z.x*O,y:Y.y+Z.y*O},{x:Y.x-Z.x*O,y:Y.y-Z.y*O},{x:H.x-Z.x*O,y:H.y-Z.y*O},{x:H.x+Z.x*O,y:H.y+Z.y*O}]};x.push(u),x.push({x:p.x+B.x*(r/2),y:p.y+B.y*(r/2)}),x.push({x:p.x+B.x*(D/2),y:p.y+B.y*(D/2)}),x.push({x:m.x+B.x*(D/2),y:m.y+B.y*(D/2)}),x.push({x:m.x+B.x*(r/2),y:m.y+B.y*(r/2)}),x.push(d),x.push({x:m.x-B.x*(r/2),y:m.y-B.y*(r/2)}),x.push({x:m.x-B.x*(D/2),y:m.y-B.y*(D/2)}),x.push({x:p.x-B.x*(D/2),y:p.y-B.y*(D/2)}),x.push({x:p.x-B.x*(r/2),y:p.y-B.y*(r/2)}),x.push(u);const M=x[0],L=Y=>{const H=N(Y);x.push(M),x.push(H[0]),x.push(...H),x.push(H[0]),x.push(M)};if(L(e),L(i),I_({ctx:A,points:x,fill:w,realToCanvasMat:n}),g){const Y={x:(e.x+i.x)/2+E.x,y:(e.y+i.y)/2+E.y},[H,O]=Pt(n,[u.x,u.y]),[Z,$]=Pt(n,[d.x,d.y]),iA=whA({x:Z-H,y:$-O});let aA=Math.atan2(iA.y,iA.x)*180/Math.PI;(aA>90||aA<-90)&&(aA+=180);const eA=typeof c=="number"&&Number.isFinite(c)?aA-c:aA;let nA=0;if(g&&typeof c=="number"&&Number.isFinite(c)){const pA=g.length*s*MQt,xA=s,RA=c*Math.PI/180,YA=Math.abs(Math.sin(RA)),CA=Math.abs(Math.cos(RA)),_A=pA/2,dA=xA/2;nA=_A*YA+dA*CA+s*NQt}const rA=r*RQt+nA,lA={x:Y.x+B.x*rA,y:Y.y+B.y*rA};yhA({ctx:A,text:g,x:lA.x,y:lA.y,fontSize:s,color:w,realToCanvasMat:n,anchorAlignment:"center",rotation:-eA})}}var vQt="rgba(255,255,255,0.5)";function LQt(t){const{ctx:A,pcbNoteDimension:e,realToCanvasMat:i}=t,n=e.color??vQt;azA({ctx:A,from:e.from,to:e.to,realToCanvasMat:i,color:n,fontSize:e.font_size,arrowSize:e.arrow_size,text:e.text,textRotation:e.text_ccw_rotation,offset:e.offset_distance&&e.offset_direction?{distance:e.offset_distance,direction:e.offset_direction}:void 0})}var UQt="rgba(255,255,255,0.5)";function HQt(t){const{ctx:A,pcbFabricationNoteDimension:e,realToCanvasMat:i}=t,n=e.color??UQt;azA({ctx:A,from:e.from,to:e.to,realToCanvasMat:i,color:n,fontSize:e.font_size??1,arrowSize:e.arrow_size??1,text:e.text,textRotation:e.text_ccw_rotation,offset:e.offset_distance&&e.offset_direction?{distance:e.offset_distance,direction:e.offset_direction}:void 0})}function YQt(t){const{ctx:A,line:e,realToCanvasMat:i}=t,o=e.color??"rgb(89, 148, 220)",s=e.stroke_width??.1,r=e.is_dashed??!1,[a,g]=Pt(i,[e.x1,e.y1]),[c,I]=Pt(i,[e.x2,e.y2]),l=s*Math.abs(i.a);A.save(),r?A.setLineDash([l*2,l*2]):A.setLineDash([]),A.beginPath(),A.moveTo(a,g),A.lineTo(c,I),A.lineWidth=l,A.strokeStyle=o,A.lineCap="round",A.stroke(),A.restore()}var JQt=class{ctx;colorMap;realToCanvasMat;constructor(A){if("getContext"in A&&typeof A.getContext=="function"){const e=A.getContext("2d");if(!e)throw new Error("Failed to get 2D rendering context from canvas");this.ctx=e}else this.ctx=A;this.colorMap={...HCt},this.realToCanvasMat=Gd()}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 e=this.ctx.canvas,i=e.width,n=e.height,o=A.maxX-A.minX,s=A.maxY-A.minY,r=i/o,a=n/s,g=Math.min(r,a),c=(i-o*g)/2,I=(n-s*g)/2;this.realToCanvasMat=tB(Qr(c,I),uh(g,-g),Qr(-A.minX,-A.maxY))}drawElements(A,e={}){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,e)}drawBoardWithSoldermask(A){const{width:e,height:i,center:n,outline:o}=A,s="top";if(o&&Array.isArray(o)&&o.length>=3){const r=this.colorMap.soldermask[s]??this.colorMap.soldermask.top,a=o.map(c=>{const[I,l]=Pt(this.realToCanvasMat,[c.x,c.y]);return{x:I,y:l}});this.ctx.beginPath();const g=a[0];if(g){this.ctx.moveTo(g.x,g.y);for(let c=1;c<a.length;c++){const I=a[c];I&&this.ctx.lineTo(I.x,I.y)}this.ctx.closePath()}this.ctx.fillStyle=r,this.ctx.fill(),aW({ctx:this.ctx,points:o.map(c=>({x:c.x,y:c.y})),stroke:this.colorMap.boardOutline,strokeWidth:.1,realToCanvasMat:this.realToCanvasMat,closePath:!0});return}if(e!==void 0&&i!==void 0&&n){const r=this.colorMap.soldermask[s]??this.colorMap.soldermask.top;Qc({ctx:this.ctx,center:n,width:e,height:i,fill:r,realToCanvasMat:this.realToCanvasMat});const a=e/2,g=i/2,c=[{x:n.x-a,y:n.y-g},{x:n.x+a,y:n.y-g},{x:n.x+a,y:n.y+g},{x:n.x-a,y:n.y+g}];aW({ctx:this.ctx,points:c,stroke:this.colorMap.boardOutline,strokeWidth:.1,realToCanvasMat:this.realToCanvasMat,closePath:!0})}}drawElement(A,e){UCt(A,e)&&(A.type==="pcb_plated_hole"&&JCt({ctx:this.ctx,hole:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_via"&&TCt({ctx:this.ctx,via:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_hole"&&KCt({ctx:this.ctx,hole:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_smtpad"&&qCt({ctx:this.ctx,pad:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_trace"&&WCt({ctx:this.ctx,trace:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_board"&&ZCt({ctx:this.ctx,board:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_text"&&tQt({ctx:this.ctx,text:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_rect"&&nQt({ctx:this.ctx,rect:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_circle"&&sQt({ctx:this.ctx,circle:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_line"&&aQt({ctx:this.ctx,line:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_path"&&cQt({ctx:this.ctx,path:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_pill"&&CQt({ctx:this.ctx,pill:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_oval"&&lQt({ctx:this.ctx,oval:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_cutout"&&QQt({ctx:this.ctx,cutout:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_keepout"&&EQt({ctx:this.ctx,keepout:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_copper_pour"&&pQt({ctx:this.ctx,pour:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_copper_text"&&mQt({ctx:this.ctx,text:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_fabrication_note_text"&&SQt({ctx:this.ctx,text:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_fabrication_note_rect"&&bQt({ctx:this.ctx,rect:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_note_rect"&&xQt({realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap,ctx:this.ctx,rect:A}),A.type==="pcb_fabrication_note_path"&&_Qt({ctx:this.ctx,path:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_note_path"&&kQt({ctx:this.ctx,path:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_note_text"&&GQt({ctx:this.ctx,text:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_note_line"&&YQt({ctx:this.ctx,line:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_note_dimension"&&LQt({ctx:this.ctx,pcbNoteDimension:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_fabrication_note_dimension"&&HQt({ctx:this.ctx,pcbFabricationNoteDimension:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}))}};let TQt={data:""},KQt=t=>{if(typeof window=="object"){let A=(t?t.querySelector("#_goober"):window._goober)||Object.assign(document.createElement("style"),{innerHTML:" ",id:"_goober"});return A.nonce=window.__nonce__,A.parentNode||(t||document.head).appendChild(A),A.firstChild}return t||TQt},PQt=/(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g,qQt=/\/\*[^]*?\*\/| +/g,gzA=/\n+/g,B_=(t,A)=>{let e="",i="",n="";for(let o in t){let s=t[o];o[0]=="@"?o[1]=="i"?e=o+" "+s+";":i+=o[1]=="f"?B_(s,o):o+"{"+B_(s,o[1]=="k"?"":A)+"}":typeof s=="object"?i+=B_(s,A?A.replace(/([^,])+/g,r=>o.replace(/([^,]*:\S+\([^)]*\))|([^,])+/g,a=>/&/.test(a)?a.replace(/&/g,r):r?r+" "+a:a)):o):s!=null&&(o=/^--/.test(o)?o:o.replace(/[A-Z]/g,"-$&").toLowerCase(),n+=B_.p?B_.p(o,s):o+":"+s+";")}return e+(A&&n?A+"{"+n+"}":n)+i},tb={},czA=t=>{if(typeof t=="object"){let A="";for(let e in t)A+=e+czA(t[e]);return A}return t},OQt=(t,A,e,i,n)=>{let o=czA(t),s=tb[o]||(tb[o]=(a=>{let g=0,c=11;for(;g<a.length;)c=101*c+a.charCodeAt(g++)>>>0;return"go"+c})(o));if(!tb[s]){let a=o!==t?t:(g=>{let c,I,l=[{}];for(;c=PQt.exec(g.replace(qQt,""));)c[4]?l.shift():c[3]?(I=c[3].replace(gzA," ").trim(),l.unshift(l[0][I]=l[0][I]||{})):l[0][c[1]]=c[2].replace(gzA," ").trim();return l[0]})(t);tb[s]=B_(n?{["@keyframes "+s]:a}:a,e?"":"."+s)}let r=e&&tb.g?tb.g:null;return e&&(tb.g=tb[s]),((a,g,c,I)=>{I?g.data=g.data.replace(I,a):g.data.indexOf(a)===-1&&(g.data=c?a+g.data:g.data+a)})(tb[s],A,i,r),s},WQt=(t,A,e)=>t.reduce((i,n,o)=>{let s=A[o];if(s&&s.call){let r=s(e),a=r&&r.props&&r.props.className||/^go/.test(r)&&r;s=a?"."+a:r&&typeof r=="object"?r.props?"":B_(r,""):r===!1?"":r}return i+n+(s??"")},"");function cW(t){let A=this||{},e=t.call?t(A.p):t;return OQt(e.unshift?e.raw?WQt(e,[].slice.call(arguments,1),A.p):e.reduce((i,n)=>Object.assign(i,n&&n.call?n(A.p):n),{}):e,KQt(A.target),A.g,A.o,A.k)}let IzA,DhA,ShA;cW.bind({g:1});let ib=cW.bind({k:1});function ZQt(t,A,e,i){B_.p=A,IzA=t,DhA=e,ShA=i}function C_(t,A){let e=this||{};return function(){let i=arguments;function n(o,s){let r=Object.assign({},o),a=r.className||n.className;e.p=Object.assign({theme:DhA&&DhA()},r),e.o=/ *go\d+/.test(a),r.className=cW.apply(e,i)+(a?" "+a:"");let g=t;return t[0]&&(g=r.as||t,delete r.as),ShA&&g[0]&&ShA(r),IzA(g,r)}return n}}var VQt=t=>typeof t=="function",IW=(t,A)=>VQt(t)?t(A):t,jQt=(()=>{let t=0;return()=>(++t).toString()})(),lzA=(()=>{let t;return()=>{if(t===void 0&&typeof window<"u"){let A=matchMedia("(prefers-reduced-motion: reduce)");t=!A||A.matches}return t}})(),zQt=20,bhA="default",BzA=(t,A)=>{let{toastLimit:e}=t.settings;switch(A.type){case 0:return{...t,toasts:[A.toast,...t.toasts].slice(0,e)};case 1:return{...t,toasts:t.toasts.map(s=>s.id===A.toast.id?{...s,...A.toast}:s)};case 2:let{toast:i}=A;return BzA(t,{type:t.toasts.find(s=>s.id===i.id)?1:0,toast:i});case 3:let{toastId:n}=A;return{...t,toasts:t.toasts.map(s=>s.id===n||n===void 0?{...s,dismissed:!0,visible:!1}:s)};case 4:return A.toastId===void 0?{...t,toasts:[]}:{...t,toasts:t.toasts.filter(s=>s.id!==A.toastId)};case 5:return{...t,pausedAt:A.time};case 6:let o=A.time-(t.pausedAt||0);return{...t,pausedAt:void 0,toasts:t.toasts.map(s=>({...s,pauseDuration:s.pauseDuration+o}))}}},lW=[],CzA={toasts:[],pausedAt:void 0,settings:{toastLimit:zQt}},gD={},QzA=(t,A=bhA)=>{gD[A]=BzA(gD[A]||CzA,t),lW.forEach(([e,i])=>{e===A&&i(gD[A])})},hzA=t=>Object.keys(gD).forEach(A=>QzA(t,A)),XQt=t=>Object.keys(gD).find(A=>gD[A].toasts.some(e=>e.id===t)),BW=(t=bhA)=>A=>{QzA(A,t)},$Qt={blank:4e3,error:4e3,success:2e3,loading:1/0,custom:4e3},Aht=(t={},A=bhA)=>{let[e,i]=V.useState(gD[A]||CzA),n=V.useRef(gD[A]);V.useEffect(()=>(n.current!==gD[A]&&i(gD[A]),lW.push([A,i]),()=>{let s=lW.findIndex(([r])=>r===A);s>-1&&lW.splice(s,1)}),[A]);let o=e.toasts.map(s=>{var r,a,g;return{...t,...t[s.type],...s,removeDelay:s.removeDelay||((r=t[s.type])==null?void 0:r.removeDelay)||t?.removeDelay,duration:s.duration||((a=t[s.type])==null?void 0:a.duration)||t?.duration||$Qt[s.type],style:{...t.style,...(g=t[s.type])==null?void 0:g.style,...s.style}}});return{...e,toasts:o}},eht=(t,A="blank",e)=>({createdAt:Date.now(),visible:!0,dismissed:!1,type:A,ariaProps:{role:"status","aria-live":"polite"},message:t,pauseDuration:0,...e,id:e?.id||jQt()}),rH=t=>(A,e)=>{let i=eht(A,t,e);return BW(i.toasterId||XQt(i.id))({type:2,toast:i}),i.id},ds=(t,A)=>rH("blank")(t,A);ds.error=rH("error"),ds.success=rH("success"),ds.loading=rH("loading"),ds.custom=rH("custom"),ds.dismiss=(t,A)=>{let e={type:3,toastId:t};A?BW(A)(e):hzA(e)},ds.dismissAll=t=>ds.dismiss(void 0,t),ds.remove=(t,A)=>{let e={type:4,toastId:t};A?BW(A)(e):hzA(e)},ds.removeAll=t=>ds.remove(void 0,t),ds.promise=(t,A,e)=>{let i=ds.loading(A.loading,{...e,...e?.loading});return typeof t=="function"&&(t=t()),t.then(n=>{let o=A.success?IW(A.success,n):void 0;return o?ds.success(o,{id:i,...e,...e?.success}):ds.dismiss(i),n}).catch(n=>{let o=A.error?IW(A.error,n):void 0;o?ds.error(o,{id:i,...e,...e?.error}):ds.dismiss(i)}),t};var tht=1e3,iht=(t,A="default")=>{let{toasts:e,pausedAt:i}=Aht(t,A),n=V.useRef(new Map).current,o=V.useCallback((I,l=tht)=>{if(n.has(I))return;let B=setTimeout(()=>{n.delete(I),s({type:4,toastId:I})},l);n.set(I,B)},[]);V.useEffect(()=>{if(i)return;let I=Date.now(),l=e.map(B=>{if(B.duration===1/0)return;let C=(B.duration||0)+B.pauseDuration-(I-B.createdAt);if(C<0){B.visible&&ds.dismiss(B.id);return}return setTimeout(()=>ds.dismiss(B.id,A),C)});return()=>{l.forEach(B=>B&&clearTimeout(B))}},[e,i,A]);let s=V.useCallback(BW(A),[A]),r=V.useCallback(()=>{s({type:5,time:Date.now()})},[s]),a=V.useCallback((I,l)=>{s({type:1,toast:{id:I,height:l}})},[s]),g=V.useCallback(()=>{i&&s({type:6,time:Date.now()})},[i,s]),c=V.useCallback((I,l)=>{let{reverseOrder:B=!1,gutter:C=8,defaultPosition:Q}=l||{},h=e.filter(d=>(d.position||Q)===(I.position||Q)&&d.height),E=h.findIndex(d=>d.id===I.id),u=h.filter((d,p)=>p<E&&d.visible).length;return h.filter(d=>d.visible).slice(...B?[u+1]:[0,u]).reduce((d,p)=>d+(p.height||0)+C,0)},[e]);return V.useEffect(()=>{e.forEach(I=>{if(I.dismissed)o(I.id,I.removeDelay);else{let l=n.get(I.id);l&&(clearTimeout(l),n.delete(I.id))}})},[e,o]),{toasts:e,handlers:{updateHeight:a,startPause:r,endPause:g,calculateOffset:c}}},nht=ib`
|
|
4945
|
+
`)};return hhA={serializeText:A},hhA}var EhA,tzA;function NCt(){if(tzA)return EhA;tzA=1;const{geometries:t,modifiers:A}=rW(),{flatten:e,toArray:i}=GCt(),{serializeBinary:n}=RCt(),{serializeText:o}=MCt();return EhA={mimeType:"application/sla",serialize:(a,...g)=>{a=Object.assign({},{binary:!0,statusCallback:null},a),g=e(g);let I=g.filter(l=>t.geom3.isA(l));if(I.length===0)throw new Error("only 3D geometries can be serialized to STL");return g.length!==I.length&&console.warn("some objects could not be serialized to STL"),I=i(A.generalize({snap:!0,triangulate:!0},I)),a.binary?n(I,a):o(I,a)}},EhA}var vCt=NCt();const LCt=g0(vCt);var izA={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"},aD={};for(const t in izA){aD[t]=[];const A=izA[t].split("M").slice(1).map(e=>e.split("L").map(i=>i.trim().split(" ").map(parseFloat)));for(const e of A)for(let i=0;i<e.length-1;i++)aD[t].push({x1:e[i][0],y1:1-e[i][1],x2:e[i+1][0],y2:1-e[i+1][1]})}function UCt(t,A){if(!A.layers||A.layers.length===0)return!0;const e=Q1A(t);return e.length===0?!0:e.some(i=>A.layers.includes(i))}var HCt={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 Yu(t){const{ctx:A,center:e,radius:i,fill:n,realToCanvasMat:o}=t,[s,r]=Pt(o,[e.x,e.y]),a=i*Math.abs(o.a);A.beginPath(),A.arc(s,r,a,0,Math.PI*2),A.fillStyle=n,A.fill()}function Qc(t){const{ctx:A,center:e,width:i,height:n,fill:o,realToCanvasMat:s,borderRadius:r=0,rotation:a=0,stroke:g,strokeWidth:c,isStrokeDashed:I=!1}=t,[l,B]=Pt(s,[e.x,e.y]),C=i*Math.abs(s.a),Q=n*Math.abs(s.a),h=r*Math.abs(s.a),E=c?c*Math.abs(s.a):void 0;if(A.save(),A.translate(l,B),a!==0&&A.rotate(-a*(Math.PI/180)),A.beginPath(),h>0){const u=-C/2,d=-Q/2,p=Math.min(h,C/2,Q/2);A.moveTo(u+p,d),A.lineTo(u+C-p,d),A.arcTo(u+C,d,u+C,d+p,p),A.lineTo(u+C,d+Q-p),A.arcTo(u+C,d+Q,u+C-p,d+Q,p),A.lineTo(u+p,d+Q),A.arcTo(u,d+Q,u,d+Q-p,p),A.lineTo(u,d+p),A.arcTo(u,d,u+p,d,p)}else A.rect(-C/2,-Q/2,C,Q);o&&(A.fillStyle=o,A.fill()),g&&E&&(I?A.setLineDash([E*3,E*2]):A.setLineDash([]),A.strokeStyle=g,A.lineWidth=E,A.stroke()),A.restore()}function eb(t){const{ctx:A,center:e,radius_x:i,radius_y:n,fill:o,stroke:s,strokeWidth:r=.1,realToCanvasMat:a,rotation:g=0}=t,[c,I]=Pt(a,[e.x,e.y]),l=i*Math.abs(a.a),B=n*Math.abs(a.a),C=r*Math.abs(a.a);A.save(),A.translate(c,I),g!==0&&A.rotate(-g*(Math.PI/180)),A.beginPath(),A.ellipse(0,0,l,B,0,0,Math.PI*2),o&&(A.fillStyle=o,A.fill()),s&&(A.strokeStyle=s,A.lineWidth=C,A.stroke()),A.restore()}function ZB(t){const{ctx:A,center:e,width:i,height:n,fill:o,realToCanvasMat:s,rotation:r=0,stroke:a,strokeWidth:g}=t,[c,I]=Pt(s,[e.x,e.y]),l=i*Math.abs(s.a),B=n*Math.abs(s.a),C=g?g*Math.abs(s.a):void 0;if(A.save(),A.translate(c,I),r!==0&&A.rotate(-r*(Math.PI/180)),A.beginPath(),l>B){const Q=B/2,h=l-B;A.moveTo(-h/2,-Q),A.lineTo(h/2,-Q),A.arc(h/2,0,Q,-Math.PI/2,Math.PI/2),A.lineTo(-h/2,Q),A.arc(-h/2,0,Q,Math.PI/2,-Math.PI/2)}else if(B>l){const Q=l/2,h=B-l;A.moveTo(Q,-h/2),A.lineTo(Q,h/2),A.arc(0,h/2,Q,0,Math.PI),A.lineTo(-Q,-h/2),A.arc(0,-h/2,Q,Math.PI,0)}else A.arc(0,0,l/2,0,Math.PI*2);A.closePath(),o&&(A.fillStyle=o,A.fill()),a&&C&&(A.strokeStyle=a,A.lineWidth=C,A.stroke()),A.restore()}function I_(t){const{ctx:A,points:e,fill:i,realToCanvasMat:n}=t;if(e.length<3)return;A.beginPath();const o=e.map(g=>Pt(n,[g.x,g.y])),s=o[0];if(!s)return;const[r,a]=s;A.moveTo(r,a);for(let g=1;g<o.length;g++){const c=o[g];if(!c)continue;const[I,l]=c;A.lineTo(I,l)}A.closePath(),A.fillStyle=i,A.fill()}function ZF(t,A,e,i,n,o,s,r,a,g){const[c,I]=Pt(r,[A.x,A.y]),l=e*Math.abs(r.a),B=i*Math.abs(r.a),C=Math.abs(n)*Math.abs(r.a),Q=o*Math.abs(r.a);t.save(),t.translate(c,I),s!==0&&t.rotate(-s*(Math.PI/180));const h=t.globalCompositeOperation;t.globalCompositeOperation!==void 0&&(t.globalCompositeOperation="source-atop");const E=l,u=B,d=Q;if(t.beginPath(),d>0){const w=-E/2,b=-u/2,k=Math.min(d,E/2,u/2);t.moveTo(w+k,b),t.lineTo(w+E-k,b),t.arcTo(w+E,b,w+E,b+k,k),t.lineTo(w+E,b+u-k),t.arcTo(w+E,b+u,w+E-k,b+u,k),t.lineTo(w+k,b+u),t.arcTo(w,b+u,w,b+u-k,k),t.lineTo(w,b+k),t.arcTo(w,b,w+k,b,k)}else t.rect(-E/2,-u/2,E,u);t.fillStyle=a,t.fill(),t.globalCompositeOperation!==void 0&&(t.globalCompositeOperation=h||"source-over");const p=l-C*2,m=B-C*2,D=Math.max(0,Q-C);if(p>0&&m>0){if(t.beginPath(),D>0){const w=-p/2,b=-m/2,k=Math.min(D,p/2,m/2);t.moveTo(w+k,b),t.lineTo(w+p-k,b),t.arcTo(w+p,b,w+p,b+k,k),t.lineTo(w+p,b+m-k),t.arcTo(w+p,b+m,w+p-k,b+m,k),t.lineTo(w+k,b+m),t.arcTo(w,b+m,w,b+m-k,k),t.lineTo(w,b+k),t.arcTo(w,b,w+k,b,k)}else t.rect(-p/2,-m/2,p,m);t.fillStyle=g,t.fill()}t.restore()}function uhA(t,A,e,i,n,o,s){const[r,a]=Pt(n,[A.x,A.y]),g=e*Math.abs(n.a),c=Math.abs(i)*Math.abs(n.a);t.save();const I=t.globalCompositeOperation;t.globalCompositeOperation!==void 0&&(t.globalCompositeOperation="source-atop"),t.beginPath(),t.arc(r,a,g,0,Math.PI*2),t.fillStyle=o,t.fill(),t.globalCompositeOperation!==void 0&&(t.globalCompositeOperation=I||"source-over");const l=Math.max(0,g-c);l>0&&(t.beginPath(),t.arc(r,a,l,0,Math.PI*2),t.fillStyle=s,t.fill()),t.restore()}function nH(t,A,e,i,n,o,s,r,a){const[g,c]=Pt(s,[A.x,A.y]),I=e*Math.abs(s.a),l=i*Math.abs(s.a),B=Math.abs(n)*Math.abs(s.a);t.save(),t.translate(g,c),o!==0&&t.rotate(-o*(Math.PI/180));const C=t.globalCompositeOperation;t.globalCompositeOperation!==void 0&&(t.globalCompositeOperation="source-atop");const Q=I,h=l;if(t.beginPath(),Q>h){const d=h/2,p=Q-h;t.moveTo(-p/2,-d),t.lineTo(p/2,-d),t.arc(p/2,0,d,-Math.PI/2,Math.PI/2),t.lineTo(-p/2,d),t.arc(-p/2,0,d,Math.PI/2,-Math.PI/2)}else if(h>Q){const d=Q/2,p=h-Q;t.moveTo(d,-p/2),t.lineTo(d,p/2),t.arc(0,p/2,d,0,Math.PI),t.lineTo(-d,-p/2),t.arc(0,-p/2,d,Math.PI,0)}else t.arc(0,0,Q/2,0,Math.PI*2);t.fillStyle=r,t.fill(),t.globalCompositeOperation!==void 0&&(t.globalCompositeOperation=C||"source-over");const E=I-B*2,u=l-B*2;if(E>0&&u>0){if(t.beginPath(),E>u){const d=u/2,p=E-u;t.moveTo(-p/2,-d),t.lineTo(p/2,-d),t.arc(p/2,0,d,-Math.PI/2,Math.PI/2),t.lineTo(-p/2,d),t.arc(-p/2,0,d,Math.PI/2,-Math.PI/2)}else if(u>E){const d=E/2,p=u-E;t.moveTo(d,-p/2),t.lineTo(d,p/2),t.arc(0,p/2,d,0,Math.PI),t.lineTo(-d,-p/2),t.arc(0,-p/2,d,Math.PI,0)}else t.arc(0,0,E/2,0,Math.PI*2);t.fillStyle=a,t.fill()}t.restore()}function nzA(t,A,e,i,n,o,s,r,a){const[g,c]=Pt(s,[A.x,A.y]),I=e*Math.abs(s.a),l=i*Math.abs(s.a),B=Math.abs(n)*Math.abs(s.a);t.save(),t.translate(g,c),o!==0&&t.rotate(-o*(Math.PI/180));const C=t.globalCompositeOperation;t.globalCompositeOperation!==void 0&&(t.globalCompositeOperation="source-atop"),t.beginPath(),t.ellipse(0,0,I,l,0,0,Math.PI*2),t.fillStyle=r,t.fill(),t.globalCompositeOperation!==void 0&&(t.globalCompositeOperation=C||"source-over");const Q=Math.max(0,I-B),h=Math.max(0,l-B);Q>0&&h>0&&(t.beginPath(),t.ellipse(0,0,Q,h,0,0,Math.PI*2),t.fillStyle=a,t.fill()),t.restore()}function dhA(t,A){if(t.length<3||A===0)return t;let e=0,i=0;for(const o of t)e+=o.x,i+=o.y;e/=t.length,i/=t.length;const n=[];for(const o of t){const s=o.x-e,r=o.y-i,a=Math.sqrt(s*s+r*r);if(a>0){const g=s/a,c=r/a;n.push({x:o.x+g*A,y:o.y+c*A})}else n.push({x:o.x+A,y:o.y})}return n}function ozA(t,A,e,i,n,o){if(A.length<3||e>=0)return;Math.abs(e)*Math.abs(i.a);const s=t.globalCompositeOperation;t.globalCompositeOperation!==void 0&&(t.globalCompositeOperation="source-atop"),t.beginPath();const r=A.map(c=>Pt(i,[c.x,c.y])),a=r[0];if(a){const[c,I]=a;t.moveTo(c,I);for(let l=1;l<r.length;l++){const B=r[l];if(B){const[C,Q]=B;t.lineTo(C,Q)}}t.closePath(),t.fillStyle=n,t.fill()}t.globalCompositeOperation!==void 0&&(t.globalCompositeOperation=s||"source-over");const g=dhA(A,e);if(g.length>=3){t.beginPath();const c=g.map(l=>Pt(i,[l.x,l.y])),I=c[0];if(I){const[l,B]=I;t.moveTo(l,B);for(let C=1;C<c.length;C++){const Q=c[C];if(Q){const[h,E]=Q;t.lineTo(h,E)}}t.closePath(),t.fillStyle=o,t.fill()}}t.restore()}function YCt(t,A){const e=t?.includes("top")?"top":"bottom";return A.soldermaskOverCopper[e]??A.soldermaskOverCopper.top}function JCt(t){const{ctx:A,hole:e,realToCanvasMat:i,colorMap:n}=t,o=e.is_covered_with_solder_mask===!0,s=o?0:e.soldermask_margin??0,r=!o&&e.soldermask_margin!==void 0&&e.soldermask_margin!==0,a=YCt(e.layers,n),g=n.substrate,c=n.copper.top;if(e.shape==="circle"){r&&s>0&&Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.outer_diameter/2+s,fill:g,realToCanvasMat:i}),Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.outer_diameter/2,fill:c,realToCanvasMat:i}),r&&s<0&&uhA(A,{x:e.x,y:e.y},e.outer_diameter/2,s,i,a,c),o&&Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.outer_diameter/2,fill:a,realToCanvasMat:i}),o||Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.hole_diameter/2,fill:n.drill,realToCanvasMat:i});return}if(e.shape==="oval"){r&&s>0&&eb({ctx:A,center:{x:e.x,y:e.y},radius_x:e.outer_width/2+s,radius_y:e.outer_height/2+s,fill:g,realToCanvasMat:i,rotation:e.ccw_rotation}),eb({ctx:A,center:{x:e.x,y:e.y},radius_x:e.outer_width/2,radius_y:e.outer_height/2,fill:c,realToCanvasMat:i,rotation:e.ccw_rotation}),r&&s<0&&nzA(A,{x:e.x,y:e.y},e.outer_width/2,e.outer_height/2,s,e.ccw_rotation??0,i,a,c),o&&eb({ctx:A,center:{x:e.x,y:e.y},radius_x:e.outer_width/2,radius_y:e.outer_height/2,fill:a,realToCanvasMat:i,rotation:e.ccw_rotation}),o||eb({ctx:A,center:{x:e.x,y:e.y},radius_x:e.hole_width/2,radius_y:e.hole_height/2,fill:n.drill,realToCanvasMat:i,rotation:e.ccw_rotation});return}if(e.shape==="pill"){r&&s>0&&ZB({ctx:A,center:{x:e.x,y:e.y},width:e.outer_width+s*2,height:e.outer_height+s*2,fill:g,realToCanvasMat:i,rotation:e.ccw_rotation}),ZB({ctx:A,center:{x:e.x,y:e.y},width:e.outer_width,height:e.outer_height,fill:c,realToCanvasMat:i,rotation:e.ccw_rotation}),r&&s<0&&nH(A,{x:e.x,y:e.y},e.outer_width,e.outer_height,s,e.ccw_rotation??0,i,a,c),o&&ZB({ctx:A,center:{x:e.x,y:e.y},width:e.outer_width,height:e.outer_height,fill:a,realToCanvasMat:i,rotation:e.ccw_rotation}),o||ZB({ctx:A,center:{x:e.x,y:e.y},width:e.hole_width,height:e.hole_height,fill:n.drill,realToCanvasMat:i,rotation:e.ccw_rotation});return}if(e.shape==="circular_hole_with_rect_pad"){if(r&&s>0&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.rect_pad_width+s*2,height:e.rect_pad_height+s*2,fill:g,realToCanvasMat:i,borderRadius:e.rect_border_radius??0}),Qc({ctx:A,center:{x:e.x,y:e.y},width:e.rect_pad_width,height:e.rect_pad_height,fill:c,realToCanvasMat:i,borderRadius:e.rect_border_radius??0}),r&&s<0&&ZF(A,{x:e.x,y:e.y},e.rect_pad_width,e.rect_pad_height,s,e.rect_border_radius??0,0,i,a,c),o&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.rect_pad_width,height:e.rect_pad_height,fill:a,realToCanvasMat:i,borderRadius:e.rect_border_radius??0}),!o){const I=e.x+(e.hole_offset_x??0),l=e.y+(e.hole_offset_y??0);Yu({ctx:A,center:{x:I,y:l},radius:e.hole_diameter/2,fill:n.drill,realToCanvasMat:i})}return}if(e.shape==="pill_hole_with_rect_pad"){if(r&&s>0&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.rect_pad_width+s*2,height:e.rect_pad_height+s*2,fill:g,realToCanvasMat:i,borderRadius:e.rect_border_radius??0}),Qc({ctx:A,center:{x:e.x,y:e.y},width:e.rect_pad_width,height:e.rect_pad_height,fill:c,realToCanvasMat:i,borderRadius:e.rect_border_radius??0}),r&&s<0&&ZF(A,{x:e.x,y:e.y},e.rect_pad_width,e.rect_pad_height,s,e.rect_border_radius??0,0,i,a,c),o&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.rect_pad_width,height:e.rect_pad_height,fill:a,realToCanvasMat:i,borderRadius:e.rect_border_radius??0}),!o){const I=e.x+(e.hole_offset_x??0),l=e.y+(e.hole_offset_y??0);ZB({ctx:A,center:{x:I,y:l},width:e.hole_width,height:e.hole_height,fill:n.drill,realToCanvasMat:i})}return}if(e.shape==="rotated_pill_hole_with_rect_pad"){if(r&&s>0&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.rect_pad_width+s*2,height:e.rect_pad_height+s*2,fill:g,realToCanvasMat:i,borderRadius:e.rect_border_radius??0,rotation:e.rect_ccw_rotation}),Qc({ctx:A,center:{x:e.x,y:e.y},width:e.rect_pad_width,height:e.rect_pad_height,fill:c,realToCanvasMat:i,borderRadius:e.rect_border_radius??0,rotation:e.rect_ccw_rotation}),r&&s<0&&ZF(A,{x:e.x,y:e.y},e.rect_pad_width,e.rect_pad_height,s,e.rect_border_radius??0,e.rect_ccw_rotation??0,i,a,c),o&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.rect_pad_width,height:e.rect_pad_height,fill:a,realToCanvasMat:i,borderRadius:e.rect_border_radius??0,rotation:e.rect_ccw_rotation}),!o){const I=e.x+(e.hole_offset_x??0),l=e.y+(e.hole_offset_y??0);ZB({ctx:A,center:{x:I,y:l},width:e.hole_width,height:e.hole_height,fill:n.drill,realToCanvasMat:i,rotation:e.hole_ccw_rotation})}return}if(e.shape==="hole_with_polygon_pad"){const I=e.pad_outline;if(I&&I.length>=3){const l=I.map(B=>({x:e.x+B.x,y:e.y+B.y}));if(r&&s>0){const B=dhA(l,s);I_({ctx:A,points:B,fill:g,realToCanvasMat:i})}I_({ctx:A,points:l,fill:c,realToCanvasMat:i}),r&&s<0&&ozA(A,l,s,i,a,c),o&&I_({ctx:A,points:l,fill:a,realToCanvasMat:i})}if(!o){const l=e.x+(e.hole_offset_x??0),B=e.y+(e.hole_offset_y??0),C=e.hole_shape;C==="circle"?Yu({ctx:A,center:{x:l,y:B},radius:(e.hole_diameter??0)/2,fill:n.drill,realToCanvasMat:i}):C==="oval"?eb({ctx:A,center:{x:l,y:B},radius_x:(e.hole_width??0)/2,radius_y:(e.hole_height??0)/2,fill:n.drill,realToCanvasMat:i}):C==="pill"?ZB({ctx:A,center:{x:l,y:B},width:e.hole_width??0,height:e.hole_height??0,fill:n.drill,realToCanvasMat:i}):C==="rotated_pill"&&ZB({ctx:A,center:{x:l,y:B},width:e.hole_width??0,height:e.hole_height??0,fill:n.drill,realToCanvasMat:i})}return}}function TCt(t){const{ctx:A,via:e,realToCanvasMat:i,colorMap:n}=t;Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.outer_diameter/2,fill:n.copper.top,realToCanvasMat:i}),Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.hole_diameter/2,fill:n.drill,realToCanvasMat:i})}function oH(t){return"ccw_rotation"in t&&typeof t.ccw_rotation=="number"?t.ccw_rotation:0}function KCt(t){const{ctx:A,hole:e,realToCanvasMat:i,colorMap:n}=t,o=e.is_covered_with_solder_mask===!0,s=o?0:e.soldermask_margin??0,r=!o&&e.soldermask_margin!==void 0&&e.soldermask_margin!==0,a=n.substrate,g=n.soldermaskOverCopper.top,c=n.soldermaskOverCopper.top;if(e.hole_shape==="circle"){r&&s>0&&Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.hole_diameter/2+s,fill:a,realToCanvasMat:i}),o||(Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.hole_diameter/2,fill:n.drill,realToCanvasMat:i}),r&&s<0&&uhA(A,{x:e.x,y:e.y},e.hole_diameter/2,s,i,c,n.drill)),o&&Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.hole_diameter/2,fill:g,realToCanvasMat:i});return}if(e.hole_shape==="square"){const I=oH(e);r&&s>0&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.hole_diameter+s*2,height:e.hole_diameter+s*2,fill:a,realToCanvasMat:i,rotation:I}),o||(Qc({ctx:A,center:{x:e.x,y:e.y},width:e.hole_diameter,height:e.hole_diameter,fill:n.drill,realToCanvasMat:i,rotation:I}),r&&s<0&&ZF(A,{x:e.x,y:e.y},e.hole_diameter,e.hole_diameter,s,0,I,i,c,n.drill)),o&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.hole_diameter,height:e.hole_diameter,fill:g,realToCanvasMat:i,rotation:I});return}if(e.hole_shape==="oval"){const I=oH(e);r&&s>0&&eb({ctx:A,center:{x:e.x,y:e.y},radius_x:e.hole_width/2+s,radius_y:e.hole_height/2+s,fill:a,realToCanvasMat:i,rotation:I}),o||(eb({ctx:A,center:{x:e.x,y:e.y},radius_x:e.hole_width/2,radius_y:e.hole_height/2,fill:n.drill,realToCanvasMat:i,rotation:I}),r&&s<0&&nzA(A,{x:e.x,y:e.y},e.hole_width/2,e.hole_height/2,s,I,i,c,n.drill)),o&&eb({ctx:A,center:{x:e.x,y:e.y},radius_x:e.hole_width/2,radius_y:e.hole_height/2,fill:g,realToCanvasMat:i,rotation:I});return}if(e.hole_shape==="rect"){const I=oH(e);r&&s>0&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.hole_width+s*2,height:e.hole_height+s*2,fill:a,realToCanvasMat:i,rotation:I}),o||(Qc({ctx:A,center:{x:e.x,y:e.y},width:e.hole_width,height:e.hole_height,fill:n.drill,realToCanvasMat:i,rotation:I}),r&&s<0&&ZF(A,{x:e.x,y:e.y},e.hole_width,e.hole_height,s,0,I,i,c,n.drill)),o&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.hole_width,height:e.hole_height,fill:g,realToCanvasMat:i,rotation:I});return}if(e.hole_shape==="pill"){const I=oH(e);r&&s>0&&ZB({ctx:A,center:{x:e.x,y:e.y},width:e.hole_width+s*2,height:e.hole_height+s*2,fill:a,realToCanvasMat:i,rotation:I}),o||(ZB({ctx:A,center:{x:e.x,y:e.y},width:e.hole_width,height:e.hole_height,fill:n.drill,realToCanvasMat:i,rotation:I}),r&&s<0&&nH(A,{x:e.x,y:e.y},e.hole_width,e.hole_height,s,I,i,c,n.drill)),o&&ZB({ctx:A,center:{x:e.x,y:e.y},width:e.hole_width,height:e.hole_height,fill:g,realToCanvasMat:i,rotation:I});return}if(e.hole_shape==="rotated_pill"){const I=oH(e);r&&s>0&&ZB({ctx:A,center:{x:e.x,y:e.y},width:e.hole_width+s*2,height:e.hole_height+s*2,fill:a,realToCanvasMat:i,rotation:I}),o||(ZB({ctx:A,center:{x:e.x,y:e.y},width:e.hole_width,height:e.hole_height,fill:n.drill,realToCanvasMat:i,rotation:I}),r&&s<0&&nH(A,{x:e.x,y:e.y},e.hole_width,e.hole_height,s,I,i,c,n.drill)),o&&ZB({ctx:A,center:{x:e.x,y:e.y},width:e.hole_width,height:e.hole_height,fill:g,realToCanvasMat:i,rotation:I});return}}function PCt(t,A){return A.copper[t]??A.copper.top}function szA(t,A){return A.soldermaskOverCopper[t]??A.soldermaskOverCopper.top}function l_(t,A=0){return(t.corner_radius??t.rect_border_radius??0)+A}function qCt(t){const{ctx:A,pad:e,realToCanvasMat:i,colorMap:n}=t,o=PCt(e.layer,n),s=e.is_covered_with_solder_mask===!0,r=s?0:e.soldermask_margin??0,a=!s&&e.soldermask_margin!==void 0&&e.soldermask_margin!==0,g=szA(e.layer,n),c=n.substrate,I=szA(e.layer,n);if(e.shape==="rect"){a&&r>0&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.width+r*2,height:e.height+r*2,fill:c,realToCanvasMat:i,borderRadius:l_(e)}),Qc({ctx:A,center:{x:e.x,y:e.y},width:e.width,height:e.height,fill:o,realToCanvasMat:i,borderRadius:l_(e)}),a&&r<0&&ZF(A,{x:e.x,y:e.y},e.width,e.height,r,l_(e),0,i,g,o),s&&r===0&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.width,height:e.height,fill:I,realToCanvasMat:i,borderRadius:l_(e)});return}if(e.shape==="rotated_rect"){a&&r>0&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.width+r*2,height:e.height+r*2,fill:c,realToCanvasMat:i,borderRadius:l_(e),rotation:e.ccw_rotation??0}),Qc({ctx:A,center:{x:e.x,y:e.y},width:e.width,height:e.height,fill:o,realToCanvasMat:i,borderRadius:l_(e),rotation:e.ccw_rotation??0}),a&&r<0&&ZF(A,{x:e.x,y:e.y},e.width,e.height,r,l_(e),e.ccw_rotation??0,i,g,o),s&&r===0&&Qc({ctx:A,center:{x:e.x,y:e.y},width:e.width,height:e.height,fill:I,realToCanvasMat:i,borderRadius:l_(e),rotation:e.ccw_rotation??0});return}if(e.shape==="circle"){a&&r>0&&Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.radius+r,fill:c,realToCanvasMat:i}),Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.radius,fill:o,realToCanvasMat:i}),a&&r<0&&uhA(A,{x:e.x,y:e.y},e.radius,r,i,g,o),s&&r===0&&Yu({ctx:A,center:{x:e.x,y:e.y},radius:e.radius,fill:I,realToCanvasMat:i});return}if(e.shape==="pill"){a&&r>0&&ZB({ctx:A,center:{x:e.x,y:e.y},width:e.width+r*2,height:e.height+r*2,fill:c,realToCanvasMat:i}),ZB({ctx:A,center:{x:e.x,y:e.y},width:e.width,height:e.height,fill:o,realToCanvasMat:i}),a&&r<0&&nH(A,{x:e.x,y:e.y},e.width,e.height,r,0,i,g,o),s&&r===0&&ZB({ctx:A,center:{x:e.x,y:e.y},width:e.width,height:e.height,fill:I,realToCanvasMat:i});return}if(e.shape==="rotated_pill"){a&&r>0&&ZB({ctx:A,center:{x:e.x,y:e.y},width:e.width+r*2,height:e.height+r*2,fill:c,realToCanvasMat:i,rotation:e.ccw_rotation??0}),ZB({ctx:A,center:{x:e.x,y:e.y},width:e.width,height:e.height,fill:o,realToCanvasMat:i,rotation:e.ccw_rotation??0}),a&&r<0&&nH(A,{x:e.x,y:e.y},e.width,e.height,r,e.ccw_rotation??0,i,g,o),s&&r===0&&ZB({ctx:A,center:{x:e.x,y:e.y},width:e.width,height:e.height,fill:I,realToCanvasMat:i,rotation:e.ccw_rotation??0});return}if(e.shape==="polygon"){if(e.points&&e.points.length>=3){if(a&&r>0){const l=dhA(e.points,r);I_({ctx:A,points:l,fill:c,realToCanvasMat:i})}I_({ctx:A,points:e.points,fill:o,realToCanvasMat:i}),a&&r<0&&ozA(A,e.points,r,i,g,o),s&&r===0&&I_({ctx:A,points:e.points,fill:I,realToCanvasMat:i})}return}}function sH(t){const{ctx:A,start:e,end:i,strokeWidth:n,stroke:o,realToCanvasMat:s,lineCap:r="round"}=t,[a,g]=Pt(s,[e.x,e.y]),[c,I]=Pt(s,[i.x,i.y]),l=n*Math.abs(s.a);A.beginPath(),A.moveTo(a,g),A.lineTo(c,I),A.lineWidth=l,A.strokeStyle=o,A.lineCap=r,A.stroke()}function OCt(t,A){return A.copper[t]??A.copper.top}function WCt(t){const{ctx:A,trace:e,realToCanvasMat:i,colorMap:n}=t;if(!(!e.route||!Array.isArray(e.route)||e.route.length<2))for(let o=0;o<e.route.length-1;o++){const s=e.route[o],r=e.route[o+1];if(!s||!r)continue;const a="layer"in s?s.layer:"layer"in r?r.layer:null;if(!a)continue;const g=OCt(a,n),c="width"in s?s.width:"width"in r?r.width:.1;sH({ctx:A,start:{x:s.x,y:s.y},end:{x:r.x,y:r.y},strokeWidth:c,stroke:g,realToCanvasMat:i,lineCap:"round"})}}function aW(t){const{ctx:A,points:e,fill:i,stroke:n,strokeWidth:o=1,realToCanvasMat:s,closePath:r=!1}=t;if(e.length<2)return;A.beginPath();const a=e.map(l=>Pt(s,[l.x,l.y])),g=a[0];if(!g)return;const[c,I]=g;A.moveTo(c,I);for(let l=1;l<a.length;l++){const B=a[l];if(!B)continue;const[C,Q]=B;A.lineTo(C,Q)}if(r&&A.closePath(),i&&(A.fillStyle=i,A.fill()),n){const l=o*Math.abs(s.a);A.strokeStyle=n,A.lineWidth=l,A.stroke()}}function ZCt(t){const{ctx:A,board:e,realToCanvasMat:i,colorMap:n}=t,{width:o,height:s,center:r,outline:a}=e;if(a&&Array.isArray(a)&&a.length>=3){aW({ctx:A,points:a.map(g=>({x:g.x,y:g.y})),stroke:n.boardOutline,strokeWidth:.1,realToCanvasMat:i,closePath:!0});return}if(o!==void 0&&s!==void 0&&r){Qc({ctx:A,center:r,width:o,height:s,fill:"transparent",realToCanvasMat:i});const g=o/2,c=s/2,I=[{x:r.x-g,y:r.y-c},{x:r.x+g,y:r.y-c},{x:r.x+g,y:r.y+c},{x:r.x-g,y:r.y+c}];aW({ctx:A,points:I,stroke:n.boardOutline,strokeWidth:.1,realToCanvasMat:i,closePath:!0})}}var VCt=.62,jCt=.3,zCt=1,XCt=.13;function gW(t,A){const e=A*VCt,i=e*jCt,n=e*zCt,o=Array.from(t);let s=0;o.forEach((a,g)=>{s+=a===" "?n:e,g<o.length-1&&(s+=i)});const r=Math.max(A*XCt,.35);return{width:s,height:A,glyphWidth:e,letterSpacing:i,spaceWidth:n,strokeWidth:r}}function phA(t,A){const e=A.width+A.strokeWidth,i=A.height+A.strokeWidth;let n=0,o=0;return t==="center"?n=-e/2:t==="top_left"||t==="bottom_left"||t==="center_left"?n=0:(t==="top_right"||t==="bottom_right"||t==="center_right")&&(n=-e),t==="center"?o=-i/2:t==="top_left"||t==="top_right"||t==="top_center"?o=0:t==="bottom_left"||t==="bottom_right"||t==="bottom_center"?o=-i:o=0,{x:n,y:o}}var $Ct=t=>aD[t]??aD[t.toUpperCase()];function fhA(t){const{ctx:A,text:e,fontSize:i,startX:n,startY:o}=t,s=gW(e,i),{glyphWidth:r,letterSpacing:a,spaceWidth:g,height:c,strokeWidth:I}=s,l=o,B=Array.from(e);let C=n+I/2;B.forEach((Q,h)=>{const E=$Ct(Q),u=Q===" "?g:r;if(E?.length){A.beginPath();for(const d of E){const p=C+d.x1*r,m=l+(1-d.y1)*c,D=C+d.x2*r,w=l+(1-d.y2)*c;A.moveTo(p,m),A.lineTo(D,w)}A.stroke()}C+=u,h<B.length-1&&(C+=a)})}function yhA(t){const{ctx:A,text:e,x:i,y:n,fontSize:o,color:s,realToCanvasMat:r,anchorAlignment:a,rotation:g=0}=t;if(!e)return;const[c,I]=Pt(r,[i,n]),l=Math.abs(r.a),B=o*l,C=gW(e,B),Q=phA(a,C);A.save(),A.translate(c,I),g!==0&&A.rotate(-g*(Math.PI/180)),A.lineWidth=C.strokeWidth,A.lineCap="round",A.lineJoin="round",A.strokeStyle=s,fhA({ctx:A,text:e,fontSize:B,startX:Q.x,startY:Q.y}),A.restore()}function AQt(t,A){return t==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function eQt(t){return t||"center"}function tQt(t){const{ctx:A,text:e,realToCanvasMat:i,colorMap:n}=t,o=e.text??"";if(!o)return;const s=AQt(e.layer,n),[r,a]=Pt(i,[e.anchor_position.x,e.anchor_position.y]),g=Math.abs(i.a),c=(e.font_size??1)*g,I=e.ccw_rotation??0,l=gW(o,c),B=eQt(e.anchor_alignment),C=phA(B,l);A.save(),A.translate(r,a),I!==0&&A.rotate(-I*(Math.PI/180)),e.layer==="bottom"&&A.scale(-1,1),A.lineWidth=l.strokeWidth,A.lineCap="round",A.lineJoin="round",A.strokeStyle=s,fhA({ctx:A,text:o,fontSize:c,startX:C.x,startY:C.y}),A.restore()}function iQt(t,A){return t==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function nQt(t){const{ctx:A,rect:e,realToCanvasMat:i,colorMap:n}=t,o=iQt(e.layer,n);Qc({ctx:A,center:e.center,width:e.width,height:e.height,fill:o,realToCanvasMat:i})}function oQt(t,A){return t==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function sQt(t){const{ctx:A,circle:e,realToCanvasMat:i,colorMap:n}=t,o=oQt(e.layer,n);Yu({ctx:A,center:e.center,radius:e.radius,fill:o,realToCanvasMat:i})}function rQt(t,A){return t==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function aQt(t){const{ctx:A,line:e,realToCanvasMat:i,colorMap:n}=t,o=rQt(e.layer,n);sH({ctx:A,start:{x:e.x1,y:e.y1},end:{x:e.x2,y:e.y2},strokeWidth:e.stroke_width??.1,stroke:o,realToCanvasMat:i})}function gQt(t,A){return t==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function cQt(t){const{ctx:A,path:e,realToCanvasMat:i,colorMap:n}=t,o=gQt(e.layer,n);if(!(!e.route||e.route.length<2))for(let s=0;s<e.route.length-1;s++){const r=e.route[s],a=e.route[s+1];!r||!a||sH({ctx:A,start:{x:r.x,y:r.y},end:{x:a.x,y:a.y},strokeWidth:e.stroke_width??.1,stroke:o,realToCanvasMat:i})}}function IQt(t,A){return t==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function lQt(t){const{ctx:A,oval:e,realToCanvasMat:i,colorMap:n}=t,o=IQt(e.layer,n);eb({ctx:A,center:e.center,radius_x:e.radius_x,radius_y:e.radius_y,stroke:o,strokeWidth:.1,realToCanvasMat:i,rotation:e.ccw_rotation??0})}function BQt(t,A){return t==="bottom"?A.silkscreen.bottom:A.silkscreen.top}function CQt(t){const{ctx:A,pill:e,realToCanvasMat:i,colorMap:n}=t,o=BQt(e.layer,n);ZB({ctx:A,center:e.center,width:e.width,height:e.height,stroke:o,strokeWidth:.2,realToCanvasMat:i})}function QQt(t){const{ctx:A,cutout:e,realToCanvasMat:i,colorMap:n}=t;if(e.shape==="rect"){Qc({ctx:A,center:e.center,width:e.width,height:e.height,fill:n.drill,realToCanvasMat:i,rotation:e.rotation??0,borderRadius:e.corner_radius??0});return}if(e.shape==="circle"){Yu({ctx:A,center:e.center,radius:e.radius,fill:n.drill,realToCanvasMat:i});return}if(e.shape==="polygon"){e.points&&e.points.length>=3&&I_({ctx:A,points:e.points,fill:n.drill,realToCanvasMat:i});return}}function hQt(t,A){const e=parseInt(t.slice(1,3),16),i=parseInt(t.slice(3,5),16),n=parseInt(t.slice(5,7),16);return`rgba(${e}, ${i}, ${n}, ${A})`}function EQt(t){const{ctx:A,keepout:e,realToCanvasMat:i,colorMap:n}=t,o=n.keepout,s=hQt(n.keepout,.2),r=1;if(e.shape==="rect"){const[a,g]=Pt(i,[e.center.x,e.center.y]),c=e.width*Math.abs(i.a),I=e.height*Math.abs(i.a),l=e.rotation??0;A.save(),A.translate(a,g),l!==0&&A.rotate(-l*(Math.PI/180)),A.beginPath(),A.rect(-c/2,-I/2,c,I),A.fillStyle=s,A.fill(),A.beginPath(),A.rect(-c/2,-I/2,c,I),A.clip();const B=r*Math.abs(i.a),C=Math.sqrt(c*c+I*I),Q=c/2,h=I/2;A.strokeStyle=o,A.lineWidth=.15*Math.abs(i.a),A.setLineDash([]);for(let E=-C;E<C*2;E+=B){A.beginPath();const u=-Q+E,d=-h,p=-Q+E+C,m=-h+C;A.moveTo(u,d),A.lineTo(p,m),A.stroke()}A.restore();return}if(e.shape==="circle"){const[a,g]=Pt(i,[e.center.x,e.center.y]),c=e.radius*Math.abs(i.a),I=r*Math.abs(i.a);A.save(),A.translate(a,g),A.beginPath(),A.arc(0,0,c,0,Math.PI*2),A.fillStyle=s,A.fill(),A.beginPath(),A.arc(0,0,c,0,Math.PI*2),A.clip();const l=c*2;A.strokeStyle=o,A.lineWidth=.15*Math.abs(i.a),A.setLineDash([]);for(let B=-l;B<l*2;B+=I)A.beginPath(),A.moveTo(B-l,-l),A.lineTo(B+l,l),A.stroke();A.restore();return}}function uQt(t,A){return A.copper[t]??A.copper.top}function dQt(t,A,e,i,n){if(Math.abs(n)<1e-10)return null;const o=e-t,s=i-A,r=Math.hypot(o,s);if(r<1e-10)return null;const a=Math.abs(n)*(r/2),g=r/2,c=(a*a+g*g)/(2*a),I=c-a,l=(t+e)/2,B=(A+i)/2,C=-s/r,Q=o/r,h=n>0?-1:1,E=l+h*C*I,u=B+h*Q*I;return{centerX:E,centerY:u,radius:c}}function mhA(t,A,e,i,n,o,s){if(Math.abs(o)<1e-10){const[p,m]=Pt(s,[i,n]);t.lineTo(p,m);return}const r=dQt(A,e,i,n,o);if(!r){const[p,m]=Pt(s,[i,n]);t.lineTo(p,m);return}const[a,g]=Pt(s,[A,e]),[c,I]=Pt(s,[i,n]),[l,B]=Pt(s,[r.centerX,r.centerY]),C=Math.hypot(a-l,g-B),Q=Math.atan2(g-B,a-l),h=Math.atan2(I-B,c-l),u=s.a*s.d-s.b*s.c<0,d=o>0?!u:u;t.arc(l,B,C,Q,h,d)}function rzA(t,A,e){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]=Pt(e,[s.x,s.y]);t.moveTo(a,g),mhA(t,s.x,s.y,r.x,r.y,1,e),mhA(t,r.x,r.y,s.x,s.y,1,e);return}}const i=A.vertices[0];if(!i)return;const[n,o]=Pt(e,[i.x,i.y]);t.moveTo(n,o);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 c=r.bulge??0;if(Math.abs(c)<1e-10){const[I,l]=Pt(e,[g.x,g.y]);t.lineTo(I,l)}else mhA(t,r.x,r.y,g.x,g.y,c,e)}}function pQt(t){const{ctx:A,pour:e,realToCanvasMat:i,colorMap:n}=t,o=uQt(e.layer,n);if(A.save(),e.shape==="rect"){const[s,r]=Pt(i,[e.center.x,e.center.y]),a=e.width*Math.abs(i.a),g=e.height*Math.abs(i.a);A.translate(s,r),e.rotation&&A.rotate(-e.rotation*(Math.PI/180)),A.beginPath(),A.rect(-a/2,-g/2,a,g),A.fillStyle=o,A.globalAlpha=.5,A.fill(),A.restore();return}if(e.shape==="polygon"){if(e.points&&e.points.length>=3){const s=e.points.map(c=>Pt(i,[c.x,c.y])),r=s[0];if(!r){A.restore();return}A.beginPath();const[a,g]=r;A.moveTo(a,g);for(let c=1;c<s.length;c++){const I=s[c];if(!I)continue;const[l,B]=I;A.lineTo(l,B)}A.closePath(),A.fillStyle=o,A.globalAlpha=.5,A.fill()}A.restore();return}if(e.shape==="brep"){if(A.beginPath(),rzA(A,e.brep_shape.outer_ring,i),e.brep_shape.inner_rings)for(const s of e.brep_shape.inner_rings)rzA(A,s,i);A.fillStyle=o,A.globalAlpha=.5,A.fill("evenodd"),A.restore();return}A.restore()}var fQt={left:.2,right:.2,top:.2,bottom:.2};function yQt(t){return t?t.includes("left")?"center_left":t.includes("right")?"center_right":"center":"center"}function mQt(t){const{ctx:A,text:e,realToCanvasMat:i,colorMap:n}=t,o=e.text??"";if(!o)return;const[s,r]=Pt(i,[e.anchor_position.x,e.anchor_position.y]),a=Math.abs(i.a),g=(e.font_size??1)*a,c=e.ccw_rotation??0,I={...fQt,...e.knockout_padding},l=n.copper[e.layer]??n.copper.top,B=gW(o,g),C=B.width+B.strokeWidth,Q=yQt(e.anchor_alignment),h=phA(Q,B);if(A.save(),A.translate(s,r),e.is_mirrored&&A.scale(-1,1),c!==0&&A.rotate(-c*(Math.PI/180)),A.lineWidth=B.strokeWidth,A.lineCap="round",A.lineJoin="round",e.is_knockout){const E=I.left*a,u=I.right*a,d=I.top*a,p=I.bottom*a,m=h.x-E*4,D=h.y-d*4,w=C+E*2+u*2,b=B.height+B.strokeWidth+d*2+p*2;A.fillStyle=l,A.fillRect(m,D,w,b)}else A.strokeStyle=l;fhA({ctx:A,text:o,fontSize:g,startX:h.x,startY:h.y}),A.restore()}var wQt="rgba(255,255,255,0.5)";function DQt(t,A){return wQt}function SQt(t){const{ctx:A,text:e,realToCanvasMat:i}=t,n=DQt(e.layer),o=e.color??n,s=e.font_size;yhA({ctx:A,text:e.text,x:e.anchor_position.x,y:e.anchor_position.y,fontSize:s,color:o,realToCanvasMat:i,anchorAlignment:e.anchor_alignment})}function bQt(t){const{ctx:A,rect:e,realToCanvasMat:i}=t,o=e.color??"rgba(255,255,255,0.5)",s=e.is_filled??!1,r=e.has_stroke??!0,a=e.is_stroke_dashed??!1;Qc({ctx:A,center:e.center,width:e.width,height:e.height,fill:s?o:void 0,stroke:r?o:void 0,strokeWidth:r?e.stroke_width:void 0,borderRadius:e.corner_radius,realToCanvasMat:i,isStrokeDashed:a})}function xQt(t){const{ctx:A,rect:e,realToCanvasMat:i}=t,o=e.color??"rgb(89, 148, 220)",s=e.is_filled??!1,r=e.has_stroke??!0,a=e.is_stroke_dashed??!1;Qc({ctx:A,center:e.center,width:e.width,height:e.height,fill:s?o:void 0,stroke:r?o:void 0,strokeWidth:r?e.stroke_width:void 0,borderRadius:e.corner_radius,realToCanvasMat:i,isStrokeDashed:a})}function _Qt(t){const{ctx:A,path:e,realToCanvasMat:i}=t,o=e.color??"rgba(255,255,255,0.5)";if(!(!e.route||e.route.length<2))for(let s=0;s<e.route.length-1;s++){const r=e.route[s],a=e.route[s+1];!r||!a||sH({ctx:A,start:{x:r.x,y:r.y},end:{x:a.x,y:a.y},strokeWidth:e.stroke_width??.1,stroke:o,realToCanvasMat:i})}}function kQt(t){const{ctx:A,path:e,realToCanvasMat:i}=t,o=e.color??"rgb(89, 148, 220)";if(!(!e.route||e.route.length<2))for(let s=0;s<e.route.length-1;s++){const r=e.route[s],a=e.route[s+1];!r||!a||sH({ctx:A,start:{x:r.x,y:r.y},end:{x:a.x,y:a.y},strokeWidth:e.stroke_width??.1,stroke:o,realToCanvasMat:i})}}var FQt="rgb(89, 148, 220)";function GQt(t){const{ctx:A,text:e,realToCanvasMat:i}=t,n=FQt,o=e.color??n,s=e.font_size??1;yhA({ctx:A,text:e.text??"",x:e.anchor_position.x,y:e.anchor_position.y,fontSize:s,color:o,realToCanvasMat:i,anchorAlignment:e.anchor_alignment??"center"})}var RQt=1.5,MQt=.6,NQt=.3;function whA(t){const A=Math.hypot(t.x,t.y)||1;return{x:t.x/A,y:t.y/A}}function azA(t){const{ctx:A,from:e,to:i,realToCanvasMat:n,color:o,fontSize:s,arrowSize:r=1,strokeWidth:a,text:g,textRotation:c,offset:I}=t,l=whA({x:i.x-e.x,y:i.y-e.y}),B={x:-l.y,y:l.x},C=I?.direction&&typeof I.direction.x=="number"&&typeof I.direction.y=="number",Q=C?whA(I.direction):{x:0,y:0},h=I?.distance??0,E={x:Q.x*h,y:Q.y*h},u={x:e.x+E.x,y:e.y+E.y},d={x:i.x+E.x,y:i.y+E.y},p={x:u.x+l.x*r,y:u.y+l.y*r},m={x:d.x-l.x*r,y:d.y-l.y*r};Math.abs(n.a);const D=a??r/5,w=o||"rgba(255,255,255,0.5)",b=C&&(Math.abs(Q.x)>Number.EPSILON||Math.abs(Q.y)>Number.EPSILON)?Q:B,k=h+.5,x=[],N=Y=>{const H={x:Y.x+b.x*k,y:Y.y+b.y*k},O=D/2,Z={x:-b.y,y:b.x};return[{x:Y.x+Z.x*O,y:Y.y+Z.y*O},{x:Y.x-Z.x*O,y:Y.y-Z.y*O},{x:H.x-Z.x*O,y:H.y-Z.y*O},{x:H.x+Z.x*O,y:H.y+Z.y*O}]};x.push(u),x.push({x:p.x+B.x*(r/2),y:p.y+B.y*(r/2)}),x.push({x:p.x+B.x*(D/2),y:p.y+B.y*(D/2)}),x.push({x:m.x+B.x*(D/2),y:m.y+B.y*(D/2)}),x.push({x:m.x+B.x*(r/2),y:m.y+B.y*(r/2)}),x.push(d),x.push({x:m.x-B.x*(r/2),y:m.y-B.y*(r/2)}),x.push({x:m.x-B.x*(D/2),y:m.y-B.y*(D/2)}),x.push({x:p.x-B.x*(D/2),y:p.y-B.y*(D/2)}),x.push({x:p.x-B.x*(r/2),y:p.y-B.y*(r/2)}),x.push(u);const M=x[0],L=Y=>{const H=N(Y);x.push(M),x.push(H[0]),x.push(...H),x.push(H[0]),x.push(M)};if(L(e),L(i),I_({ctx:A,points:x,fill:w,realToCanvasMat:n}),g){const Y={x:(e.x+i.x)/2+E.x,y:(e.y+i.y)/2+E.y},[H,O]=Pt(n,[u.x,u.y]),[Z,$]=Pt(n,[d.x,d.y]),iA=whA({x:Z-H,y:$-O});let aA=Math.atan2(iA.y,iA.x)*180/Math.PI;(aA>90||aA<-90)&&(aA+=180);const eA=typeof c=="number"&&Number.isFinite(c)?aA-c:aA;let nA=0;if(g&&typeof c=="number"&&Number.isFinite(c)){const pA=g.length*s*MQt,xA=s,RA=c*Math.PI/180,YA=Math.abs(Math.sin(RA)),CA=Math.abs(Math.cos(RA)),_A=pA/2,dA=xA/2;nA=_A*YA+dA*CA+s*NQt}const rA=r*RQt+nA,lA={x:Y.x+B.x*rA,y:Y.y+B.y*rA};yhA({ctx:A,text:g,x:lA.x,y:lA.y,fontSize:s,color:w,realToCanvasMat:n,anchorAlignment:"center",rotation:-eA})}}var vQt="rgba(255,255,255,0.5)";function LQt(t){const{ctx:A,pcbNoteDimension:e,realToCanvasMat:i}=t,n=e.color??vQt;azA({ctx:A,from:e.from,to:e.to,realToCanvasMat:i,color:n,fontSize:e.font_size,arrowSize:e.arrow_size,text:e.text,textRotation:e.text_ccw_rotation,offset:e.offset_distance&&e.offset_direction?{distance:e.offset_distance,direction:e.offset_direction}:void 0})}var UQt="rgba(255,255,255,0.5)";function HQt(t){const{ctx:A,pcbFabricationNoteDimension:e,realToCanvasMat:i}=t,n=e.color??UQt;azA({ctx:A,from:e.from,to:e.to,realToCanvasMat:i,color:n,fontSize:e.font_size??1,arrowSize:e.arrow_size??1,text:e.text,textRotation:e.text_ccw_rotation,offset:e.offset_distance&&e.offset_direction?{distance:e.offset_distance,direction:e.offset_direction}:void 0})}function YQt(t){const{ctx:A,line:e,realToCanvasMat:i}=t,o=e.color??"rgb(89, 148, 220)",s=e.stroke_width??.1,r=e.is_dashed??!1,[a,g]=Pt(i,[e.x1,e.y1]),[c,I]=Pt(i,[e.x2,e.y2]),l=s*Math.abs(i.a);A.save(),r?A.setLineDash([l*2,l*2]):A.setLineDash([]),A.beginPath(),A.moveTo(a,g),A.lineTo(c,I),A.lineWidth=l,A.strokeStyle=o,A.lineCap="round",A.stroke(),A.restore()}var JQt=class{ctx;colorMap;realToCanvasMat;constructor(A){if("getContext"in A&&typeof A.getContext=="function"){const e=A.getContext("2d");if(!e)throw new Error("Failed to get 2D rendering context from canvas");this.ctx=e}else this.ctx=A;this.colorMap={...HCt},this.realToCanvasMat=Gd()}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 e=this.ctx.canvas,i=e.width,n=e.height,o=A.maxX-A.minX,s=A.maxY-A.minY,r=i/o,a=n/s,g=Math.min(r,a),c=(i-o*g)/2,I=(n-s*g)/2;this.realToCanvasMat=tB(Qr(c,I),uh(g,-g),Qr(-A.minX,-A.maxY))}drawElements(A,e={}){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,e)}drawBoardWithSoldermask(A){const{width:e,height:i,center:n,outline:o}=A,s="top";if(o&&Array.isArray(o)&&o.length>=3){const r=this.colorMap.soldermask[s]??this.colorMap.soldermask.top,a=o.map(c=>{const[I,l]=Pt(this.realToCanvasMat,[c.x,c.y]);return{x:I,y:l}});this.ctx.beginPath();const g=a[0];if(g){this.ctx.moveTo(g.x,g.y);for(let c=1;c<a.length;c++){const I=a[c];I&&this.ctx.lineTo(I.x,I.y)}this.ctx.closePath()}this.ctx.fillStyle=r,this.ctx.fill(),aW({ctx:this.ctx,points:o.map(c=>({x:c.x,y:c.y})),stroke:this.colorMap.boardOutline,strokeWidth:.1,realToCanvasMat:this.realToCanvasMat,closePath:!0});return}if(e!==void 0&&i!==void 0&&n){const r=this.colorMap.soldermask[s]??this.colorMap.soldermask.top;Qc({ctx:this.ctx,center:n,width:e,height:i,fill:r,realToCanvasMat:this.realToCanvasMat});const a=e/2,g=i/2,c=[{x:n.x-a,y:n.y-g},{x:n.x+a,y:n.y-g},{x:n.x+a,y:n.y+g},{x:n.x-a,y:n.y+g}];aW({ctx:this.ctx,points:c,stroke:this.colorMap.boardOutline,strokeWidth:.1,realToCanvasMat:this.realToCanvasMat,closePath:!0})}}drawElement(A,e){UCt(A,e)&&(A.type==="pcb_plated_hole"&&JCt({ctx:this.ctx,hole:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_via"&&TCt({ctx:this.ctx,via:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_hole"&&KCt({ctx:this.ctx,hole:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_smtpad"&&qCt({ctx:this.ctx,pad:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_trace"&&WCt({ctx:this.ctx,trace:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_board"&&ZCt({ctx:this.ctx,board:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_text"&&tQt({ctx:this.ctx,text:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_rect"&&nQt({ctx:this.ctx,rect:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_circle"&&sQt({ctx:this.ctx,circle:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_line"&&aQt({ctx:this.ctx,line:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_path"&&cQt({ctx:this.ctx,path:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_pill"&&CQt({ctx:this.ctx,pill:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_silkscreen_oval"&&lQt({ctx:this.ctx,oval:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_cutout"&&QQt({ctx:this.ctx,cutout:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_keepout"&&EQt({ctx:this.ctx,keepout:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_copper_pour"&&pQt({ctx:this.ctx,pour:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_copper_text"&&mQt({ctx:this.ctx,text:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_fabrication_note_text"&&SQt({ctx:this.ctx,text:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_fabrication_note_rect"&&bQt({ctx:this.ctx,rect:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_note_rect"&&xQt({realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap,ctx:this.ctx,rect:A}),A.type==="pcb_fabrication_note_path"&&_Qt({ctx:this.ctx,path:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_note_path"&&kQt({ctx:this.ctx,path:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_note_text"&&GQt({ctx:this.ctx,text:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_note_line"&&YQt({ctx:this.ctx,line:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_note_dimension"&&LQt({ctx:this.ctx,pcbNoteDimension:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}),A.type==="pcb_fabrication_note_dimension"&&HQt({ctx:this.ctx,pcbFabricationNoteDimension:A,realToCanvasMat:this.realToCanvasMat,colorMap:this.colorMap}))}};let TQt={data:""},KQt=t=>{if(typeof window=="object"){let A=(t?t.querySelector("#_goober"):window._goober)||Object.assign(document.createElement("style"),{innerHTML:" ",id:"_goober"});return A.nonce=window.__nonce__,A.parentNode||(t||document.head).appendChild(A),A.firstChild}return t||TQt},PQt=/(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g,qQt=/\/\*[^]*?\*\/| +/g,gzA=/\n+/g,B_=(t,A)=>{let e="",i="",n="";for(let o in t){let s=t[o];o[0]=="@"?o[1]=="i"?e=o+" "+s+";":i+=o[1]=="f"?B_(s,o):o+"{"+B_(s,o[1]=="k"?"":A)+"}":typeof s=="object"?i+=B_(s,A?A.replace(/([^,])+/g,r=>o.replace(/([^,]*:\S+\([^)]*\))|([^,])+/g,a=>/&/.test(a)?a.replace(/&/g,r):r?r+" "+a:a)):o):s!=null&&(o=/^--/.test(o)?o:o.replace(/[A-Z]/g,"-$&").toLowerCase(),n+=B_.p?B_.p(o,s):o+":"+s+";")}return e+(A&&n?A+"{"+n+"}":n)+i},tb={},czA=t=>{if(typeof t=="object"){let A="";for(let e in t)A+=e+czA(t[e]);return A}return t},OQt=(t,A,e,i,n)=>{let o=czA(t),s=tb[o]||(tb[o]=(a=>{let g=0,c=11;for(;g<a.length;)c=101*c+a.charCodeAt(g++)>>>0;return"go"+c})(o));if(!tb[s]){let a=o!==t?t:(g=>{let c,I,l=[{}];for(;c=PQt.exec(g.replace(qQt,""));)c[4]?l.shift():c[3]?(I=c[3].replace(gzA," ").trim(),l.unshift(l[0][I]=l[0][I]||{})):l[0][c[1]]=c[2].replace(gzA," ").trim();return l[0]})(t);tb[s]=B_(n?{["@keyframes "+s]:a}:a,e?"":"."+s)}let r=e&&tb.g?tb.g:null;return e&&(tb.g=tb[s]),((a,g,c,I)=>{I?g.data=g.data.replace(I,a):g.data.indexOf(a)===-1&&(g.data=c?a+g.data:g.data+a)})(tb[s],A,i,r),s},WQt=(t,A,e)=>t.reduce((i,n,o)=>{let s=A[o];if(s&&s.call){let r=s(e),a=r&&r.props&&r.props.className||/^go/.test(r)&&r;s=a?"."+a:r&&typeof r=="object"?r.props?"":B_(r,""):r===!1?"":r}return i+n+(s??"")},"");function cW(t){let A=this||{},e=t.call?t(A.p):t;return OQt(e.unshift?e.raw?WQt(e,[].slice.call(arguments,1),A.p):e.reduce((i,n)=>Object.assign(i,n&&n.call?n(A.p):n),{}):e,KQt(A.target),A.g,A.o,A.k)}let IzA,DhA,ShA;cW.bind({g:1});let ib=cW.bind({k:1});function ZQt(t,A,e,i){B_.p=A,IzA=t,DhA=e,ShA=i}function C_(t,A){let e=this||{};return function(){let i=arguments;function n(o,s){let r=Object.assign({},o),a=r.className||n.className;e.p=Object.assign({theme:DhA&&DhA()},r),e.o=/ *go\d+/.test(a),r.className=cW.apply(e,i)+(a?" "+a:"");let g=t;return t[0]&&(g=r.as||t,delete r.as),ShA&&g[0]&&ShA(r),IzA(g,r)}return n}}var VQt=t=>typeof t=="function",IW=(t,A)=>VQt(t)?t(A):t,jQt=(()=>{let t=0;return()=>(++t).toString()})(),lzA=(()=>{let t;return()=>{if(t===void 0&&typeof window<"u"){let A=matchMedia("(prefers-reduced-motion: reduce)");t=!A||A.matches}return t}})(),zQt=20,bhA="default",BzA=(t,A)=>{let{toastLimit:e}=t.settings;switch(A.type){case 0:return{...t,toasts:[A.toast,...t.toasts].slice(0,e)};case 1:return{...t,toasts:t.toasts.map(s=>s.id===A.toast.id?{...s,...A.toast}:s)};case 2:let{toast:i}=A;return BzA(t,{type:t.toasts.find(s=>s.id===i.id)?1:0,toast:i});case 3:let{toastId:n}=A;return{...t,toasts:t.toasts.map(s=>s.id===n||n===void 0?{...s,dismissed:!0,visible:!1}:s)};case 4:return A.toastId===void 0?{...t,toasts:[]}:{...t,toasts:t.toasts.filter(s=>s.id!==A.toastId)};case 5:return{...t,pausedAt:A.time};case 6:let o=A.time-(t.pausedAt||0);return{...t,pausedAt:void 0,toasts:t.toasts.map(s=>({...s,pauseDuration:s.pauseDuration+o}))}}},lW=[],CzA={toasts:[],pausedAt:void 0,settings:{toastLimit:zQt}},gD={},QzA=(t,A=bhA)=>{gD[A]=BzA(gD[A]||CzA,t),lW.forEach(([e,i])=>{e===A&&i(gD[A])})},hzA=t=>Object.keys(gD).forEach(A=>QzA(t,A)),XQt=t=>Object.keys(gD).find(A=>gD[A].toasts.some(e=>e.id===t)),BW=(t=bhA)=>A=>{QzA(A,t)},$Qt={blank:4e3,error:4e3,success:2e3,loading:1/0,custom:4e3},Aht=(t={},A=bhA)=>{let[e,i]=V.useState(gD[A]||CzA),n=V.useRef(gD[A]);V.useEffect(()=>(n.current!==gD[A]&&i(gD[A]),lW.push([A,i]),()=>{let s=lW.findIndex(([r])=>r===A);s>-1&&lW.splice(s,1)}),[A]);let o=e.toasts.map(s=>{var r,a,g;return{...t,...t[s.type],...s,removeDelay:s.removeDelay||((r=t[s.type])==null?void 0:r.removeDelay)||t?.removeDelay,duration:s.duration||((a=t[s.type])==null?void 0:a.duration)||t?.duration||$Qt[s.type],style:{...t.style,...(g=t[s.type])==null?void 0:g.style,...s.style}}});return{...e,toasts:o}},eht=(t,A="blank",e)=>({createdAt:Date.now(),visible:!0,dismissed:!1,type:A,ariaProps:{role:"status","aria-live":"polite"},message:t,pauseDuration:0,...e,id:e?.id||jQt()}),rH=t=>(A,e)=>{let i=eht(A,t,e);return BW(i.toasterId||XQt(i.id))({type:2,toast:i}),i.id},ds=(t,A)=>rH("blank")(t,A);ds.error=rH("error"),ds.success=rH("success"),ds.loading=rH("loading"),ds.custom=rH("custom"),ds.dismiss=(t,A)=>{let e={type:3,toastId:t};A?BW(A)(e):hzA(e)},ds.dismissAll=t=>ds.dismiss(void 0,t),ds.remove=(t,A)=>{let e={type:4,toastId:t};A?BW(A)(e):hzA(e)},ds.removeAll=t=>ds.remove(void 0,t),ds.promise=(t,A,e)=>{let i=ds.loading(A.loading,{...e,...e?.loading});return typeof t=="function"&&(t=t()),t.then(n=>{let o=A.success?IW(A.success,n):void 0;return o?ds.success(o,{id:i,...e,...e?.success}):ds.dismiss(i),n}).catch(n=>{let o=A.error?IW(A.error,n):void 0;o?ds.error(o,{id:i,...e,...e?.error}):ds.dismiss(i)}),t};var tht=1e3,iht=(t,A="default")=>{let{toasts:e,pausedAt:i}=Aht(t,A),n=V.useRef(new Map).current,o=V.useCallback((I,l=tht)=>{if(n.has(I))return;let B=setTimeout(()=>{n.delete(I),s({type:4,toastId:I})},l);n.set(I,B)},[]);V.useEffect(()=>{if(i)return;let I=Date.now(),l=e.map(B=>{if(B.duration===1/0)return;let C=(B.duration||0)+B.pauseDuration-(I-B.createdAt);if(C<0){B.visible&&ds.dismiss(B.id);return}return setTimeout(()=>ds.dismiss(B.id,A),C)});return()=>{l.forEach(B=>B&&clearTimeout(B))}},[e,i,A]);let s=V.useCallback(BW(A),[A]),r=V.useCallback(()=>{s({type:5,time:Date.now()})},[s]),a=V.useCallback((I,l)=>{s({type:1,toast:{id:I,height:l}})},[s]),g=V.useCallback(()=>{i&&s({type:6,time:Date.now()})},[i,s]),c=V.useCallback((I,l)=>{let{reverseOrder:B=!1,gutter:C=8,defaultPosition:Q}=l||{},h=e.filter(d=>(d.position||Q)===(I.position||Q)&&d.height),E=h.findIndex(d=>d.id===I.id),u=h.filter((d,p)=>p<E&&d.visible).length;return h.filter(d=>d.visible).slice(...B?[u+1]:[0,u]).reduce((d,p)=>d+(p.height||0)+C,0)},[e]);return V.useEffect(()=>{e.forEach(I=>{if(I.dismissed)o(I.id,I.removeDelay);else{let l=n.get(I.id);l&&(clearTimeout(l),n.delete(I.id))}})},[e,o]),{toasts:e,handlers:{updateHeight:a,startPause:r,endPause:g,calculateOffset:c}}},nht=ib`
|
|
4946
4946
|
from {
|
|
4947
4947
|
transform: scale(0) rotate(45deg);
|
|
4948
4948
|
opacity: 0;
|
|
@@ -5430,7 +5430,7 @@ You passed in: '`+this.raw_options[o]+"'");return a},e.prototype._is_valid_selec
|
|
|
5430
5430
|
`);break}}return s}}}),$5t=Ma({"node_modules/pretty/index.js"(t,A){var e=W5t(),i=X5t(),n=sce(),o={unformatted:["code","pre","em","strong","span"],indent_inner_html:!0,indent_char:" ",indent_size:2,sep:`
|
|
5431
5431
|
`};A.exports=function(a,g){var c=n({},o,g);return a=e.html(a,c),c.ocd===!0?(c.newlines&&(c.sep=c.newlines),s(a,c)):a};function s(r,a){return i(r,a).replace(/^\s+/g,"").replace(/\s+$/g,`
|
|
5432
5432
|
`).replace(/(\s*<!--)/g,`
|
|
5433
|
-
$1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function rce(t,A,e){if(!A||!e)return;let i=t.get(A);i||(i=new Set,t.set(A,i)),i.add(e);let n=t.get(e);n||(n=new Set,t.set(e,n)),n.add(A)}function A8t(t,A){if(!A.subcircuit_id&&!A.source_group_id)return[...t];const e=new Map;for(const s of t){const r=s[`${s.type}_id`];typeof r=="string"&&e.set(r,s)}const i=new Map;for(const s of t){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 c=e.get(g);rce(i,s,c)}else if(a.endsWith("_ids")&&Array.isArray(g)){for(const c of g)if(typeof c=="string"){const I=e.get(c);rce(i,s,I)}}}}const n=[],o=new Set;for(const s of t)(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)))&&(n.push(s),o.add(s));for(;n.length>0;){const s=n.shift(),r=i.get(s);if(r)for(const a of r)o.has(a)||(o.add(a),n.push(a))}return t.filter(s=>o.has(s))}var R9=(t,A={})=>{const e=t;let i=e._internal_store;if(!i){i={counts:{},editCount:0},e._internal_store=i;for(const o of e){const s=o.type,r=o[`${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:(o,s)=>{if(s==="toArray")return()=>(e.editCount=i.editCount,e);if(s==="editCount")return i.editCount;if(s==="subtree")return a=>R9(A8t(e,a),A);const r=s;return{get:a=>e.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 c=g[0],I=c.replace("_id",""),l=e.find(B=>B.type===I&&B[c]===a[c]);return l?e.find(B=>B.type===r&&B[`${r}_id`]===l[`${r}_id`]):null},getWhere:a=>{const g=Object.keys(a);return e.find(c=>c.type===r&&g.every(I=>c[I]===a[I]))},list:a=>{const g=a?Object.keys(a):[];return e.filter(c=>c.type===r&&g.every(I=>c[I]===a[I]))},insert:a=>{i.counts[r]??=-1,i.counts[r]++;const g=i.counts[r],c={type:r,[`${r}_id`]:`${r}_${g}`,...a};return A.validateInserts&&(Ige[r]??VpA).parse(c),e.push(c),i.editCount++,c},delete:a=>{const g=e.find(c=>c[`${r}_id`]===a);g&&(e.splice(e.indexOf(g),1),i.editCount++)},update:(a,g)=>{const c=e.find(I=>I.type===r&&I[`${r}_id`]===a);return c?(Object.assign(c,g),i.editCount++,c):null},select:a=>{if(r==="source_component")return e.find(g=>g.type==="source_component"&&g.name===a.replace(/\./g,""));if(r==="pcb_port"||r==="source_port"||r==="schematic_port"){const[g,c]=a.replace(/\./g,"").split(/[\s\>]+/),I=e.find(B=>B.type==="source_component"&&B.name===g);if(!I)return null;const l=e.find(B=>B.type==="source_port"&&B.source_component_id===I.source_component_id&&(B.name===c||(B.port_hints??[]).includes(c)));if(!l)return null;if(r==="source_port")return l;if(r==="pcb_port")return e.find(B=>B.type==="pcb_port"&&B.source_port_id===l.source_port_id);if(r==="schematic_port")return e.find(B=>B.type==="schematic_port"&&B.source_port_id===l.source_port_id)}}}}})};R9.unparsed=R9;var wb=R9;function xfA(t){const A=t.type;return`${A}:${t[`${A}_id`]}`}var ace=(t,A={})=>{let e=t._internal_store_indexed;if(!e){e={counts:{},editCount:0,indexes:{}};for(const s of t){const r=s.type,a=s[`${r}_id`];if(!a)continue;const g=Number.parseInt(a.split("_").pop()||"");Number.isNaN(g)||(e.counts[r]=Math.max(e.counts[r]??0,g))}const n=A.indexConfig||{},o=e.indexes;if(n.byId&&(o.byId=new Map),n.byType&&(o.byType=new Map),n.byRelation&&(o.byRelation=new Map),n.bySubcircuit&&(o.bySubcircuit=new Map),n.byCustomField&&n.byCustomField.length>0){o.byCustomField=new Map;for(const s of n.byCustomField)o.byCustomField.set(s,new Map)}for(const s of t){if(n.byId){const r=xfA(s);o.byId.set(r,s)}if(n.byType){const r=o.byType.get(s.type)||[];r.push(s),o.byType.set(s.type,r)}if(n.byRelation){const r=Object.entries(s);for(const[a,g]of r)if(a.endsWith("_id")&&a!==`${s.type}_id`&&typeof g=="string"){const c=o.byRelation.get(a)||new Map,I=c.get(g)||[];I.push(s),c.set(g,I),o.byRelation.set(a,c)}}if(n.bySubcircuit&&"subcircuit_id"in s){const r=s.subcircuit_id;if(r&&typeof r=="string"){const a=o.bySubcircuit.get(r)||[];a.push(s),o.bySubcircuit.set(r,a)}}if(n.byCustomField&&o.byCustomField){for(const r of n.byCustomField)if(r in s){const a=s[r];if(a!==void 0&&(typeof a=="string"||typeof a=="number")){const g=String(a),c=o.byCustomField.get(r),I=c.get(g)||[];I.push(s),c.set(g,I)}}}}t._internal_store_indexed=e}return new Proxy({},{get:(n,o)=>{if(o==="toArray")return()=>(t.editCount=e.editCount,t);if(o==="editCount")return e.editCount;const s=o;return{get:r=>{const a=A.indexConfig||{};return a.byId&&e.indexes.byId?e.indexes.byId.get(`${s}:${r}`)||null:a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(c=>c[`${s}_id`]===r)||null:t.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 c=g[0],I=c.replace("_id","");if(a.byRelation&&e.indexes.byRelation){const B=e.indexes.byRelation.get(c);if(B){const Q=(B.get(r[c])||[]).find(E=>E.type===I);if(!Q)return null;const h=Q[`${s}_id`];return a.byId&&e.indexes.byId?e.indexes.byId.get(`${s}:${h}`)||null:a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===h)||null:t.find(E=>E.type===s&&E[`${s}_id`]===h)||null}}const l=t.find(B=>B.type===I&&B[c]===r[c]);return l&&t.find(B=>B.type===s&&B[`${s}_id`]===l[`${s}_id`])||null},getWhere:r=>{const a=A.indexConfig||{},g=Object.keys(r);if(g.length===1&&a.byCustomField&&e.indexes.byCustomField){const c=g[0],I=e.indexes.byCustomField.get(c);if(I){const l=String(r[c]);return(I.get(l)||[]).find(C=>C.type===s)||null}}if("subcircuit_id"in r&&a.bySubcircuit&&e.indexes.bySubcircuit){const c=r.subcircuit_id;return(e.indexes.bySubcircuit.get(c)||[]).find(l=>l.type===s&&g.every(B=>l[B]===r[B]))||null}return a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(I=>g.every(l=>I[l]===r[l]))||null:t.find(c=>c.type===s&&g.every(I=>c[I]===r[I]))||null},list:r=>{const a=A.indexConfig||{},g=r?Object.keys(r):[];if(g.length===0&&a.byType&&e.indexes.byType)return e.indexes.byType.get(s)||[];if(g.length===1&&g[0]==="subcircuit_id"&&a.bySubcircuit&&e.indexes.bySubcircuit){const I=r.subcircuit_id;return(e.indexes.bySubcircuit.get(I)||[]).filter(B=>B.type===s)}let c;return a.byType&&e.indexes.byType?c=e.indexes.byType.get(s)||[]:c=t.filter(I=>I.type===s),g.length>0?c.filter(I=>g.every(l=>I[l]===r[l])):c},insert:r=>{e.counts[s]??=-1,e.counts[s]++;const a=e.counts[s],g={type:s,[`${s}_id`]:`${s}_${a}`,...r};A.validateInserts&&(Ige[s]??VpA).parse(g),t.push(g),e.editCount++;const c=A.indexConfig||{};if(c.byId&&e.indexes.byId){const I=xfA(g);e.indexes.byId.set(I,g)}if(c.byType&&e.indexes.byType){const I=e.indexes.byType.get(s)||[];I.push(g),e.indexes.byType.set(s,I)}if(c.byRelation&&e.indexes.byRelation){const I=Object.entries(g);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${g.type}_id`&&typeof B=="string"){const C=e.indexes.byRelation.get(l)||new Map,Q=C.get(B)||[];Q.push(g),C.set(B,Q),e.indexes.byRelation.set(l,C)}}if(c.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I&&typeof I=="string"){const l=e.indexes.bySubcircuit.get(I)||[];l.push(g),e.indexes.bySubcircuit.set(I,l)}}if(c.byCustomField&&e.indexes.byCustomField){for(const I of c.byCustomField)if(I in g){const l=g[I];if(l!==void 0&&(typeof l=="string"||typeof l=="number")){const B=String(l),C=e.indexes.byCustomField.get(I),Q=C.get(B)||[];Q.push(g),C.set(B,Q)}}}return g},delete:r=>{const a=A.indexConfig||{};let g;if(a.byId&&e.indexes.byId?g=e.indexes.byId.get(`${s}:${r}`):a.byType&&e.indexes.byType?g=(e.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):g=t.find(I=>I[`${s}_id`]===r),!g)return;const c=t.indexOf(g);if(c>=0&&(t.splice(c,1),e.editCount++),a.byId&&e.indexes.byId){const I=xfA(g);e.indexes.byId.delete(I)}if(a.byType&&e.indexes.byType){const l=(e.indexes.byType.get(s)||[]).filter(B=>B[`${s}_id`]!==r);e.indexes.byType.set(s,l)}if(a.byRelation&&e.indexes.byRelation)for(const[I,l]of e.indexes.byRelation.entries())for(const[B,C]of l.entries()){const Q=C.filter(h=>h!==g);Q.length===0?l.delete(B):l.set(B,Q)}if(a.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I){const B=(e.indexes.bySubcircuit.get(I)||[]).filter(C=>C!==g);B.length===0?e.indexes.bySubcircuit.delete(I):e.indexes.bySubcircuit.set(I,B)}}if(a.byCustomField&&e.indexes.byCustomField)for(const I of e.indexes.byCustomField.values())for(const[l,B]of I.entries()){const C=B.filter(Q=>Q!==g);C.length===0?I.delete(l):I.set(l,C)}},update:(r,a)=>{const g=A.indexConfig||{};let c;if(g.byId&&e.indexes.byId?c=e.indexes.byId.get(`${s}:${r}`):g.byType&&e.indexes.byType?c=(e.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):c=t.find(I=>I.type===s&&I[`${s}_id`]===r),!c)return null;if(g.byRelation&&e.indexes.byRelation){const I=Object.entries(c);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${c.type}_id`&&typeof B=="string"&&l in a&&a[l]!==B){const C=e.indexes.byRelation.get(l);if(C){const h=(C.get(B)||[]).filter(E=>E!==c);h.length===0?C.delete(B):C.set(B,h)}}}if(g.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id,l=a.subcircuit_id;if(I!==l){const C=(e.indexes.bySubcircuit.get(I)||[]).filter(Q=>Q!==c);C.length===0?e.indexes.bySubcircuit.delete(I):e.indexes.bySubcircuit.set(I,C)}}if(g.byCustomField&&e.indexes.byCustomField){for(const I of g.byCustomField)if(I in c&&I in a&&c[I]!==a[I]){const l=e.indexes.byCustomField.get(I);if(l){const B=String(c[I]),Q=(l.get(B)||[]).filter(h=>h!==c);Q.length===0?l.delete(B):l.set(B,Q)}}}if(Object.assign(c,a),e.editCount++,g.byRelation&&e.indexes.byRelation){const I=Object.entries(c);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${c.type}_id`&&typeof B=="string"&&l in a){const C=e.indexes.byRelation.get(l)||new Map,Q=C.get(B)||[];Q.includes(c)||(Q.push(c),C.set(B,Q),e.indexes.byRelation.set(l,C))}}if(g.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id;if(I&&typeof I=="string"){const l=e.indexes.bySubcircuit.get(I)||[];l.includes(c)||(l.push(c),e.indexes.bySubcircuit.set(I,l))}}if(g.byCustomField&&e.indexes.byCustomField){for(const I of g.byCustomField)if(I in c&&I in a){const l=c[I];if(l!==void 0&&(typeof l=="string"||typeof l=="number")){const B=String(l),C=e.indexes.byCustomField.get(I),Q=C.get(B)||[];Q.includes(c)||(Q.push(c),C.set(B,Q))}}}return c},select:r=>{if(s==="source_component")return t.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\>]+/),c=t.find(l=>l.type==="source_component"&&l.name===a);if(!c)return null;const I=t.find(l=>l.type==="source_port"&&l.source_component_id===c.source_component_id&&(l.name===g||(l.port_hints??[]).includes(g)));if(!I)return null;if(s==="source_port")return I;if(s==="pcb_port")return t.find(l=>l.type==="pcb_port"&&l.source_port_id===I.source_port_id)||null;if(s==="schematic_port")return t.find(l=>l.type==="schematic_port"&&l.source_port_id===I.source_port_id)||null}return null}}}})};ace.unparsed=ace;var e8t=t=>{const A=t.type;return t[`${A}_id`]},_fA=t=>{let A=Number.POSITIVE_INFINITY,e=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,n=Number.NEGATIVE_INFINITY;for(const o of t){if(!o.type.startsWith("pcb_"))continue;if(o.type==="pcb_smtpad"&&o.shape==="polygon"&&Array.isArray(o.points)){for(const c of o.points)A=Math.min(A,c.x),e=Math.min(e,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y);continue}let s,r,a,g;if("x"in o&&"y"in o&&(s=Number(o.x),r=Number(o.y)),"outer_diameter"in o&&(a=Number(o.outer_diameter),g=Number(o.outer_diameter)),"width"in o&&(a=Number(o.width)),"height"in o&&(g=Number(o.height)),"center"in o&&(s=o.center.x,r=o.center.y),s!==void 0&&r!==void 0)A=Math.min(A,s),e=Math.min(e,r),i=Math.max(i,s),n=Math.max(n,r),a!==void 0&&g!==void 0&&(A=Math.min(A,s-a/2),e=Math.min(e,r-g/2),i=Math.max(i,s+a/2),n=Math.max(n,r+g/2)),"radius"in o&&(A=Math.min(A,s-o.radius),e=Math.min(e,r-o.radius),i=Math.max(i,s+o.radius),n=Math.max(n,r+o.radius));else if(o.type==="pcb_trace")for(const c of o.route)A=Math.min(A,c.x),e=Math.min(e,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y)}return{minX:A,minY:e,maxX:i,maxY:n}};function t8t(t){let A=0;if(t.length==0)return A;for(var e=0;e<t.length;e++){var i=t.charCodeAt(e);A=(A<<5)-A+i,A=A&A}return Math.abs(A)}var gce=[["#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"]],i8t=t=>{let{x:A,y:e,width:i,height:n}={...t,...t.size,...t.center,...t.position};if(t.x1!==void 0&&t.x2!==void 0&&t.y1!==void 0&&t.y2!==void 0&&(A=(t.x1+t.x2)/2,e=(t.y1+t.y2)/2,i=Math.abs(t.x1-t.x2),n=Math.abs(t.y1-t.y2)),t.points&&Array.isArray(t.points)&&t.points.length>0){const r=t.points.map(B=>B.x),a=t.points.map(B=>B.y),g=Math.min(...r),c=Math.max(...r),I=Math.min(...a),l=Math.max(...a);A=(g+c)/2,e=(I+l)/2,i=c-g,n=l-I}const o=t.text||t.name||t.source?.text||t.source?.name||"?",s=t;return A===void 0||e===void 0?null:(i===void 0&&"outer_diameter"in t&&(i=t.outer_diameter,n=t.outer_diameter),(i===void 0||n===void 0)&&(i=.1,n=.1),{x:A,y:e,width:i,height:n,title:o,content:s,bg_color:gce[t8t(t.type||o)%gce.length]?.[4]??"#f00"})},n8t=t=>!!t,o8t=t=>{const A=t.filter(g=>g.type.startsWith("pcb_")||g.type.startsWith("schematic_")).concat(t.filter(g=>g.type==="pcb_trace"||g.type==="schematic_trace").flatMap(g=>g.route)).map(g=>i8t(g)).filter(n8t);if(A.length===0)return{center:{x:0,y:0},width:0,height:0};let e=A[0].x-A[0].width/2,i=A[0].x+A[0].width/2,n=A[0].y-A[0].height/2,o=A[0].y+A[0].height/2;for(const g of A.slice(1))e=Math.min(e,g.x-g.width/2),i=Math.max(i,g.x+g.width/2),n=Math.min(n,g.y-g.height/2),o=Math.max(o,g.y+g.height/2);const s=i-e,r=o-n;return{center:{x:e+s/2,y:n+r/2},width:s,height:r}},vD={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"},M9=(t,A)=>{if(typeof window>"u")return A;try{const e=localStorage.getItem(t);return e!==null?JSON.parse(e):A}catch{return A}},N9=(t,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(A))}catch{}},s8t=(t,A)=>{if(typeof window>"u")return A;try{const e=localStorage.getItem(t);return e!==null?JSON.parse(e):A}catch{return A}},r8t=(t,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(A))}catch{}},a8t="named_only",g8t=(t={},A=!1)=>gYA(e=>({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:M9(vD.IS_SHOWING_COPPER_POURS,!0),is_showing_pcb_groups:A?!1:M9(vD.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:M9(vD.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!0),is_showing_solder_mask:M9(vD.IS_SHOWING_SOLDER_MASK,!1),pcb_group_view_mode:A?"all":s8t(vD.PCB_GROUP_VIEW_MODE,a8t),hovered_error_id:null,...t,selectLayer:i=>e({selected_layer:i}),setEditMode:i=>e({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=>e({is_showing_rats_nest:i}),setIsMovingComponent:i=>e({is_moving_component:i}),setIsDrawingTrace:i=>e({is_drawing_trace:i}),setIsMouseOverContainer:i=>e({is_mouse_over_container:i}),setIsShowingMultipleTracesLength:i=>e({is_showing_multiple_traces_length:i}),setIsShowingAutorouting:i=>e({is_showing_autorouting:i}),setIsShowingDrcErrors:i=>e({is_showing_drc_errors:i}),setIsShowingCopperPours:i=>{N9(vD.IS_SHOWING_COPPER_POURS,i),e({is_showing_copper_pours:i})},setIsShowingPcbGroups:i=>{A||(N9(vD.IS_SHOWING_PCB_GROUPS,i),e({is_showing_pcb_groups:i}))},setIsShowingGroupAnchorOffsets:i=>{N9(vD.IS_SHOWING_GROUP_ANCHOR_OFFSETS,i),e({is_showing_group_anchor_offsets:i})},setIsShowingSolderMask:i=>{N9(vD.IS_SHOWING_SOLDER_MASK,i),e({is_showing_solder_mask:i})},setPcbGroupViewMode:i=>{A||(r8t(vD.PCB_GROUP_VIEW_MODE,i),e({pcb_group_view_mode:i}))},setHoveredErrorId:i=>e({hovered_error_id:i})})),XB=t=>{const A=V.useContext(cce);return dYA(A,t)},cce=V.createContext(null),c8t=({children:t,initialState:A,disablePcbGroups:e})=>{const i=V.useMemo(()=>g8t(A,e),[e]);return W.jsx(cce.Provider,{value:i,children:t})},I8t=()=>{const t=XB(e=>e.pcb_viewer_id),A=(e,i)=>Vg(e,{containerId:t,...i});return A.error=(e,i)=>Vg.error(e,{containerId:t,...i}),A.promise=Vg.promise,A},l8t=()=>{V.useEffect(()=>{Q3t()},[]);const t=XB(A=>A.pcb_viewer_id);return W.jsx(C3t,{position:"top-center",containerId:t})},B8t=function(){},Ice=typeof window<"u",C8t=Ice?V.useLayoutEffect:V.useEffect,Q8t=C8t,lce={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function h8t(){var t=V.useState(null),A=t[0],e=t[1],i=V.useState(lce),n=i[0],o=i[1],s=V.useMemo(function(){return new window.ResizeObserver(function(r){if(r[0]){var a=r[0].contentRect,g=a.x,c=a.y,I=a.width,l=a.height,B=a.top,C=a.left,Q=a.bottom,h=a.right;o({x:g,y:c,width:I,height:l,top:B,left:C,bottom:Q,right:h})}})},[]);return Q8t(function(){if(A)return s.observe(A),function(){s.disconnect()}},[A]),[e,n]}var EJ=Ice&&typeof window.ResizeObserver<"u"?h8t:function(){return[B8t,lce]},Bce=({initialTransform:t,initialTouch1:A,initialTouch2:e,finalTouch1:i,finalTouch2:n})=>{if(!i||!n)return t;const o={x:(A.x+e.x)/2,y:(A.y+e.y)/2},s={x:(i.x+n.x)/2,y:(i.y+n.y)/2},r=Math.hypot(e.x-A.x,e.y-A.y),a=Math.hypot(n.x-i.x,n.y-i.y),g=r===0?1:a/r,c=s.x-o.x,I=s.y-o.y;return zy(rB(c,I),rB(o.x,o.y),tJ(g,g),rB(-o.x,-o.y),t)},E8t=(t={})=>{const A=V.useRef(null),[e,i]=V.useState(0),n=t.canvasElm??A.current,[o,s]=V.useState(t.initialTransform??fb()),[r,a]=V.useState(0),[g,c]=V.useReducer(d=>d+1,0),I=V.useCallback(d=>{t.onSetTransform&&t.onSetTransform(d),t.transform||s(d)},[t.onSetTransform,s]),l=V.useCallback(d=>{I(d),c()},[I]),B=t.transform??o,C=V.useCallback(()=>{i(Date.now())},[]),Q=V.useRef("none"),h=V.useRef(null),E=V.useRef(null);V.useEffect(()=>{const d=t.canvasElm??A.current;if(d&&!n){a(r+1);return}if(!d){const Z=setTimeout(()=>{a(r+1)},100);return()=>clearTimeout(Z)}let p=t.transform??o,m={x:0,y:0},D={x:0,y:0},w=!1;const b=Z=>({x:Z.pageX-d.getBoundingClientRect().left-window.scrollX,y:Z.pageY-d.getBoundingClientRect().top-window.scrollY});function k(Z){t.enabled!==!1&&(t.shouldDrag&&!t.shouldDrag(Z)||(m=b(Z),!(Date.now()-e<100)&&(w=!0,Z.preventDefault())))}function x(Z){if(!w||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;D=b(Z);const $=zy(rB(D.x-m.x,D.y-m.y),p);I($),p=$,w=!1}function N(Z){if(b(Z),!w||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;D=b(Z);const $=zy(rB(D.x-m.x,D.y-m.y),p);I($)}function M(Z){if(t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;const $=b(Z),iA=zy(rB($.x,$.y),tJ(1-Z.deltaY/1e3,1-Z.deltaY/1e3),rB(-$.x,-$.y),p);I(iA),p=iA,Z.preventDefault()}function L(Z){if(!w||t.shouldDrag&&!t.shouldDrag(Z))return;if(d){const iA=d.getBoundingClientRect();if(Z.clientX>=iA.left+10&&Z.clientX<=iA.right-10&&Z.clientY>=iA.top+10&&Z.clientY<=iA.bottom-10)return}w=!1,D=b(Z);const $=zy(rB(D.x-m.x,D.y-m.y),p);I($),p=$}function Y(Z){if(Z.preventDefault(),t.enabled!==!1){if(Z.touches.length===1){Q.current="drag";const $=Z.touches[0];h.current={initialTransform:p,initialTouch:{x:$.clientX,y:$.clientY}}}else if(Z.touches.length===2){Q.current="pinch";const $=Z.touches[0],iA=Z.touches[1];E.current={initialTransform:p,initialTouch1:{x:$.clientX,y:$.clientY},initialTouch2:{x:iA.clientX,y:iA.clientY},finalTouch1:null,finalTouch2:null}}}}function H(Z){if(Z.preventDefault(),t.enabled!==!1){if(Q.current==="drag"&&Z.touches.length===1&&h.current){const $=Z.touches[0],iA={x:$.clientX,y:$.clientY},aA=iA.x-h.current.initialTouch.x,eA=iA.y-h.current.initialTouch.y,nA=zy(rB(aA,eA),h.current.initialTransform);I(nA)}else if(Q.current==="pinch"&&Z.touches.length===2&&E.current){const $=Z.touches[0],iA=Z.touches[1];E.current.finalTouch1={x:$.clientX,y:$.clientY},E.current.finalTouch2={x:iA.clientX,y:iA.clientY};const aA=Bce(E.current);I(aA)}}}function O(Z){Z.preventDefault();const $=Z.changedTouches[0];if(Q.current==="drag"&&h.current&&$){const iA={x:$.clientX,y:$.clientY},aA=iA.x-h.current.initialTouch.x,eA=iA.y-h.current.initialTouch.y,nA=zy(rB(aA,eA),h.current.initialTransform);I(nA),p=nA}else if(Q.current==="pinch"&&E.current){const iA=Bce(E.current);I(iA),p=iA}Q.current="none",h.current=null,E.current=null}return d.addEventListener("mousedown",k),d.addEventListener("mouseup",x),window.addEventListener("mousemove",N),d.addEventListener("mouseout",L),d.addEventListener("wheel",M),d.addEventListener("touchstart",Y,{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",L),d.removeEventListener("wheel",M),d.removeEventListener("touchstart",Y),d.removeEventListener("touchmove",H),d.removeEventListener("touchend",O),d.removeEventListener("touchcancel",O)}},[n,r,g,e,t.enabled,t.shouldDrag]);const u=V.useCallback(d=>qi(B,d),[B]);return{ref:A,transform:B,applyTransformToPoint:u,setTransform:l,cancelDrag:C}},u8t=E8t;function d8t(t){const A=new Map;let e=0;function i(n){for(const[,s]of A)if(s.has(n))return s;const o=new Set;return A.set(`connectivity_net${e++}`,o),o}for(const n of t){let o=null;for(const s of n){if(!o)o=i(s);else if(!o.has(s)){const r=i(s);if(r!==o){for(const a of r)o.add(a);A.delete(Array.from(A.entries()).find(([,a])=>a===r)[0])}}o.add(s)}}return Object.fromEntries(Array.from(A.entries()).map(([n,o])=>[n,Array.from(o)]))}var p8t=class{netMap;idToNetMap;constructor(t){this.netMap=t,this.idToNetMap={};for(const[A,e]of Object.entries(t))for(const i of e)this.idToNetMap[i]=A}addConnections(t){for(const A of t){const e=new Set;for(const n of A){const o=this.idToNetMap[n];o&&e.add(o)}let i;if(e.size===0)i=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[i]=[];else if(e.size===1)i=e.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{i=e.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const n of e)if(n!==i){this.netMap[i].push(...this.netMap[n]),this.netMap[n]=this.netMap[i];for(const o of this.netMap[i])this.idToNetMap[o]=i}}for(const n of A)this.netMap[i].includes(n)||this.netMap[i].push(n),this.idToNetMap[n]=i}}getIdsConnectedToNet(t){return this.netMap[t]||[]}getNetConnectedToId(t){return this.idToNetMap[t]}areIdsConnected(t,A){if(t===A)return!0;const e=this.getNetConnectedToId(t);if(!e)return!1;const i=this.getNetConnectedToId(A);return i?e===i||i===t||i===t:!1}areAllIdsConnected(t){const A=this.getNetConnectedToId(t[0]);for(const e of t){const i=this.getNetConnectedToId(e);if(i===void 0||i!==A)return!1}return!0}},Cce=t=>{const A=[];for(const i of t)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:n,source_port_id:o}=i;o&&n&&A.push([o,n])}else if(i.type==="pcb_smtpad"){const{pcb_smtpad_id:n,pcb_port_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="pcb_plated_hole"){const{pcb_plated_hole_id:n,pcb_port_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="pcb_trace"){const{pcb_trace_id:n,source_trace_id:o}=i,s=Array.isArray(i.route)?i.route.filter(r=>r&&r.route_type==="wire"):[];if(o&&n&&A.push([n,o]),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&&n&&a&&A.push([r,n,a])}}else if(i.type==="pcb_via"){const{pcb_via_id:n,pcb_trace_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="source_component"&&i.internally_connected_source_port_ids)for(const n of i.internally_connected_source_port_ids)A.push(n);const e=d8t(A);return new p8t(e)};function f8t({primitivesWithoutInteractionMetadata:t,drawingObjectIdsWithMouseOver:A,primitiveIdsInMousedOverNet:e}){const i=[];for(const n of t){const o={...n};n?.layer==="drill"?(o.is_in_highlighted_net=!1,o.is_mouse_over=!1):A.has(n._pcb_drawing_object_id)?o.is_mouse_over=!0:n._element&&("pcb_trace_id"in n._element&&e.includes(n._element.pcb_trace_id)||"pcb_port_id"in n._element&&e.includes(n._element.pcb_port_id))?o.is_in_highlighted_net=!0:(o.is_in_highlighted_net=!1,o.is_mouse_over=!1),i.push(o)}return i}function y8t(t,A){if(t.length<2)throw new Error("Stroke must have at least two points");const e=t.map(I=>Array.isArray(I)?{x:I[0],y:I[1]}:I),i=[],n=[];function o(I,l){const B=l.x-I.x,C=l.y-I.y,Q=Math.sqrt(B*B+C*C);return{x:-C/Q,y:B/Q}}function s(I,l,B,C){const Q=C/2,h={x:I.x+l.x*Q*B,y:I.y+l.y*Q*B};B>0?i.push(h):n.unshift(h)}const r=o(e[0],e[1]),a=e[0].trace_width??A;s(e[0],r,1,a),s(e[0],r,-1,a);for(let I=1;I<e.length-1;I++){const l=e[I-1],B=e[I],C=e[I+1],Q=o(l,B),h=o(B,C),E=Q.x+h.x,u=Q.y+h.y,d=Math.sqrt(E*E+u*u),p=B.trace_width??A;if(d/2>2*(p/2))s(B,Q,1,p),s(B,h,1,p),s(B,Q,-1,p),s(B,h,-1,p);else{const D=1/d;s(B,{x:E*D,y:u*D},1,p),s(B,{x:E*D,y:u*D},-1,p)}}const g=o(e[e.length-2],e[e.length-1]),c=e[e.length-1].trace_width??A;return s(e[e.length-1],g,1,c),s(e[e.length-1],g,-1,c),[...i,...n]}var m8t=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s,rect_border_radius:r}=t,a=t.corner_radius??r??0,g=[{_pcb_drawing_object_id:Xy("rect"),pcb_drawing_type:"rect",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...t.shape==="rotated_rect"&&t.ccw_rotation!==void 0?{ccw_rotation:t.ccw_rotation}:{}}];if(t.is_covered_with_solder_mask){const c=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",l={...{_pcb_drawing_object_id:Xy("rect"),pcb_drawing_type:"rect",x:e,y:i,w:n,h:o,layer:c,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...t.shape==="rotated_rect"&&t.ccw_rotation!==void 0?{ccw_rotation:t.ccw_rotation}:{}},..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};g.push(l)}return g},w8t=(t,A)=>{const{x:e,y:i,radius:n,layer:o}=t,s=[{_pcb_drawing_object_id:Xy("circle"),pcb_drawing_type:"circle",x:e,y:i,r:n,layer:o||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const r=o==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",a={_pcb_drawing_object_id:Xy("circle"),pcb_drawing_type:"circle",x:e,y:i,r:n,layer:r,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};s.push(a)}return s},D8t=(t,A)=>{const{layer:e,points:i}=t,n=[{_pcb_drawing_object_id:Xy("polygon"),pcb_drawing_type:"polygon",points:kfA(i),layer:e||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const o=e==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={_pcb_drawing_object_id:Xy("polygon"),pcb_drawing_type:"polygon",points:kfA(i),layer:o,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};n.push(s)}return n},S8t=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s}=t,r=[{_pcb_drawing_object_id:Xy("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const a=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",g={_pcb_drawing_object_id:Xy("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:a,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};r.push(g)}return r},b8t=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s,ccw_rotation:r}=t,a=[{_pcb_drawing_object_id:Xy("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:r}];if(t.is_covered_with_solder_mask){const g=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",c={_pcb_drawing_object_id:Xy("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:g,_element:t,_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 t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};a.push(c)}return a},x8t=(t,A)=>{const{_parent_pcb_component:e,_parent_source_component:i}=A,n=t,o=typeof n.font_size=="string"?ut.parse(n.font_size):n.font_size??.2;let s;return n.knockout_padding&&(s={left:typeof n.knockout_padding.left=="string"?ut.parse(n.knockout_padding.left):n.knockout_padding.left,top:typeof n.knockout_padding.top=="string"?ut.parse(n.knockout_padding.top):n.knockout_padding.top,bottom:typeof n.knockout_padding.bottom=="string"?ut.parse(n.knockout_padding.bottom):n.knockout_padding.bottom,right:typeof n.knockout_padding.right=="string"?ut.parse(n.knockout_padding.right):n.knockout_padding.right}),[{_pcb_drawing_object_id:Xy("text"),pcb_drawing_type:"text",x:n.anchor_position.x,y:n.anchor_position.y,layer:n.layer,align:n.anchor_alignment??"center",text:n.text,size:o,ccw_rotation:n.ccw_rotation,is_mirrored:n.is_mirrored,is_knockout:n.is_knockout,knockout_padding:s,_element:t,_parent_pcb_component:e,_parent_source_component:i}]},DI=0,Xy=t=>`${t}_${DI++}`,kfA=t=>(t??[]).map(A=>({x:ut.parse(A.x),y:ut.parse(A.y)})),_8t=(t,A)=>{const e="pcb_component_id"in t?A.find(s=>s.type==="pcb_component"&&s.pcb_component_id===t.pcb_component_id):void 0,i=e&&"source_component_id"in e?A.find(s=>s.type==="source_component"&&s.source_component_id===e.source_component_id):void 0,n="source_port_id"in t?t.source_port_id:"pcb_port_id"in t?wb(A).pcb_port.get(t.pcb_port_id)?.source_port_id:void 0,o=n?A.find(s=>s.type==="source_port"&&s.source_port_id===n):void 0;switch(t.type){case"pcb_smtpad":{const s={_parent_pcb_component:e,_parent_source_component:i,_source_port:o};return t.shape==="rect"||t.shape==="rotated_rect"?m8t(t,s):t.shape==="circle"?w8t(t,s):t.shape==="polygon"?D8t(t,s):t.shape==="pill"?S8t(t,s):t.shape==="rotated_pill"?b8t(t,s):[]}case"pcb_trace":{const s=[];if(t.route_thickness_mode==="interpolated"){const g=t.route.map(l=>({x:l.x,y:l.y,trace_width:l.route_type==="wire"?l.width:.5})),c=y8t(g,.5),I=t.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${DI++}`,_element:t,pcb_drawing_type:"polygon",points:c,layer:I}),t.route.forEach(l=>{l.route_type==="via"&&s.push({_pcb_drawing_object_id:`circle_${DI++}`,_element:t,pcb_drawing_type:"circle",x:l.x,y:l.y,r:l.outer_diameter/2,layer:l.from_layer})}),s}let r=null,a=null;for(const g of t.route)g.route_type==="wire"&&(r!==null&&a!==null&&s.push({_pcb_drawing_object_id:`line_${DI++}`,_element:t,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}=t,c=t.from_layer,I=t.to_layer,l=t.layers,B=[];c&&I?B.push(c,I):l&&Array.isArray(l)?B.push(...l):B.push("top","bottom");const C=[];for(const Q of B)C.push({_pcb_drawing_object_id:`circle_${DI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:Q,_element:t,_parent_pcb_component:e,_parent_source_component:i});return C.push({_pcb_drawing_object_id:`circle_${DI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"drill",_element:t}),C}case"pcb_plated_hole":if(t.shape==="circle"){const{x:s,y:r,hole_diameter:a,outer_diameter:g}=t;return[{_pcb_drawing_object_id:`circle_${DI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`circle_${DI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:"drill",_element:t}]}else if(t.shape==="oval"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=t;return[{_pcb_drawing_object_id:`oval_${DI++}`,pcb_drawing_type:"oval",x:s,y:r,rX:g/2,rY:a/2,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`oval_${DI++}`,_element:t,pcb_drawing_type:"oval",x:s,y:r,rX:I/2,rY:c/2,layer:"drill"}]}else if(t.shape==="pill"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=t;return[{_pcb_drawing_object_id:`pill_${DI++}`,pcb_drawing_type:"pill",x:s,y:r,w:g,h:a,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:t.ccw_rotation},{_pcb_drawing_object_id:`pill_${DI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:I,h:c,layer:"drill",ccw_rotation:t.ccw_rotation}]}else if(t.shape==="circular_hole_with_rect_pad"){const{x:s,y:r,hole_diameter:a,rect_pad_width:g,rect_pad_height:c,rect_border_radius:I,hole_offset_x:l,hole_offset_y:B}=t,C=ut.parse(l??0),Q=ut.parse(B??0);return[{_pcb_drawing_object_id:`rect_${DI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:I},{_pcb_drawing_object_id:`rect_${DI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:I},{_pcb_drawing_object_id:`circle_${DI++}`,_element:t,pcb_drawing_type:"circle",x:s+C,y:r+Q,r:a/2,layer:"drill"}]}else if(t.shape==="pill_hole_with_rect_pad"){const{x:s,y:r,hole_width:a,hole_height:g,rect_pad_width:c,rect_pad_height:I,rect_border_radius:l}=t;return[{_pcb_drawing_object_id:`rect_${DI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:l},{_pcb_drawing_object_id:`rect_${DI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:l},{_pcb_drawing_object_id:`pill_${DI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill"}]}else if(t.shape==="rotated_pill_hole_with_rect_pad"){const{x:s,y:r,hole_width:a,hole_height:g,hole_ccw_rotation:c,rect_pad_width:I,rect_pad_height:l,rect_ccw_rotation:B,rect_border_radius:C}=t;return[{_pcb_drawing_object_id:`rect_${DI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C},{_pcb_drawing_object_id:`rect_${DI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C},{_pcb_drawing_object_id:`pill_${DI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill",ccw_rotation:c}]}else if(t.shape==="hole_with_polygon_pad"){const{x:s,y:r,pad_outline:a,hole_shape:g,hole_diameter:c,hole_width:I,hole_height:l,layers:B,hole_offset_x:C,hole_offset_y:Q}=t,h=ut.parse(C??0),E=ut.parse(Q??0),u=a,d=[];if(u&&Array.isArray(u)){const D=kfA(u).map(w=>({x:w.x+s,y:w.y+r}));for(const w of B||["top","bottom"])d.push({_pcb_drawing_object_id:`polygon_${DI++}`,pcb_drawing_type:"polygon",points:D,layer:w,_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o})}const p={x:s+h,y:r+E},m=[];return g==="circle"?m.push({_pcb_drawing_object_id:`circle_${DI++}`,pcb_drawing_type:"circle",x:p.x,y:p.y,r:(c??0)/2,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i}):g==="oval"?m.push({_pcb_drawing_object_id:`oval_${DI++}`,pcb_drawing_type:"oval",x:p.x,y:p.y,rX:(I??0)/2,rY:(l??0)/2,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i}):(g==="pill"||g==="rotated_pill")&&m.push({_pcb_drawing_object_id:`pill_${DI++}`,pcb_drawing_type:"pill",x:p.x,y:p.y,w:I??0,h:l??0,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i,ccw_rotation:t.ccw_rotation}),[...d,...m]}else return[];case"pcb_copper_text":return x8t(t,{_parent_pcb_component:e,_parent_source_component:i})}return[]},wn={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)"}},yf=(t,A=1)=>{if(Math.abs(t.a)!==Math.abs(t.d))throw new Error("Cannot scale non-uniformly");return A*Math.abs(t.a)},uc={elementOverlay:40,dimensionOverlay:40,editTraceHintOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:20,clickToInteractOverlay:100},v9={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:wn.board.copper.f,inner1:wn.board.copper.in1,inner2:wn.board.copper.in2,inner3:wn.board.copper.in3,inner4:wn.board.copper.in4,inner5:wn.board.copper.in5,inner6:wn.board.copper.in6,inner7:wn.board.copper.in7,inner8:wn.board.copper.in8,bottom:wn.board.copper.b,drill:wn.board.anchor,keepout:wn.board.background,tkeepout:wn.board.b_crtyd,tplace:wn.board.b_silks,top_silkscreen:wn.board.f_silks,bottom_silkscreen:wn.board.b_silks,top_fabrication:wn.board.f_fab,bottom_fabrication:wn.board.b_fab,soldermask_top:wn.board.soldermask.top,soldermask_bottom:wn.board.soldermask.bottom,soldermask_with_copper_top:wn.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:wn.board.soldermaskWithCopper.bottom,bottom_notes:wn.board.user_2,top_notes:wn.board.user_2,...wn.board},k8t=["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"],F8t=class{canvasLayerMap;ctxLayerMap;aperture;transform;foregroundLayer="top";lastPoint;constructor(t){this.canvasLayerMap=t,this.ctxLayerMap=Object.fromEntries(Object.entries(t).map(([A,e])=>[A,e.getContext("2d")])),this.transform=fb(),this.transform.d*=-1,this.transform=zy(this.transform,rB(0,-500)),this.lastPoint={x:0,y:0},this.equip({})}clear(){for(const t of Object.values(this.ctxLayerMap))t.clearRect(0,0,t.canvas.width,t.canvas.height)}equip(t){this.aperture={fontSize:0,shape:"circle",mode:"add",size:0,color:"red",layer:"top",opacity:this.foregroundLayer===t.color?1:.5,...t}}drawMeshPattern(t,A,e,i,n,o=45){const s=this.getLayerCtx(),[r,a]=qi(this.transform,[t,A]),[g,c]=qi(this.transform,[t+e,A+i]),I=yf(this.transform,n);s.lineWidth=1,s.strokeStyle=this.aperture.color;const l=B=>{const C=Math.sin(B),Q=Math.cos(B),h=Math.sqrt((g-r)**2+(c-a)**2);for(let E=-h;E<=h;E+=I)s.beginPath(),s.moveTo(r+E*Q-h*C,a+E*C+h*Q),s.lineTo(r+E*Q+h*C,a+E*C-h*Q),s.stroke()};l(o*Math.PI/180),l((o+90)*Math.PI/180)}rect({x:t,y:A,w:e,h:i,mesh_fill:n,is_filled:o=!0,has_stroke:s,is_stroke_dashed:r,stroke_width:a,roundness:g}){const[c,I]=qi(this.transform,[t-e/2,A-i/2]),[l,B]=qi(this.transform,[t+e/2,A+i/2]);this.applyAperture();const C=this.getLayerCtx(),Q=g?yf(this.transform,g):0,h=s===void 0?o===!1:s;if(n)C.save(),C.beginPath(),Q>0&&C.roundRect?C.roundRect(c,I,l-c,B-I,Q):C.rect(c,I,l-c,B-I),C.clip(),this.drawMeshPattern(t-e/2,A-i/2,e,i,.15),C.restore(),Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.stroke()):C.strokeRect(c,I,l-c,B-I);else if(o!==!1&&(Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.fill()):C.fillRect(c,I,l-c,B-I)),h){const E=C.lineWidth;if(a!==void 0&&(C.lineWidth=yf(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)}Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.stroke()):C.strokeRect(c,I,l-c,B-I),r&&C.setLineDash([]),a!==void 0&&(C.lineWidth=E)}}rotatedRect(t,A,e,i,n,o,s){const r=this.getLayerCtx();this.applyAperture();const[a,g]=qi(this.transform,[t-e/2,A-i/2]),[c,I]=qi(this.transform,[t+e/2,A+i/2]),l=o?yf(this.transform,o):0;r.save();const[B,C]=qi(this.transform,[t,A]);r.translate(B,C);const Q=360-n;n&&r.rotate(Q*Math.PI/180),r.translate(-B,-C),s?(r.beginPath(),l>0&&r.roundRect?r.roundRect(a,g,c-a,I-g,l):r.rect(a,g,c-a,I-g),r.clip(),this.drawMeshPattern(t-e/2,A-i/2,e,i,.15),l>0&&r.roundRect?(r.beginPath(),r.roundRect(a,g,c-a,I-g,l),r.stroke()):r.strokeRect(a,g,c-a,I-g)):l>0&&r.roundRect?(r.beginPath(),r.roundRect(a,g,c-a,I-g,l),r.fill()):r.fillRect(a,g,c-a,I-g),r.restore()}rotatedPill(t,A,e,i,n){const o=this.getLayerCtx();this.applyAperture(),o.save();const[s,r]=qi(this.transform,[t,A]);o.translate(s,r);const a=360-n;n&&o.rotate(a*Math.PI/180),o.translate(-s,-r),this.pill(t,A,e,i),o.restore()}circle(t,A,e,i){const n=yf(this.transform,e),[o,s]=qi(this.transform,[t,A]);this.applyAperture();const r=this.getLayerCtx();i?(r.save(),r.beginPath(),r.arc(o,s,n,0,2*Math.PI),r.clip(),this.drawMeshPattern(t-e,A-e,e*2,e*2,.15),r.restore(),r.beginPath(),r.arc(o,s,n,0,2*Math.PI),r.stroke()):(r.beginPath(),r.arc(o,s,n,0,2*Math.PI),r.fill())}oval(t,A,e,i){const n=yf(this.transform,e),o=yf(this.transform,i),[s,r]=qi(this.transform,[t,A]);this.applyAperture();const a=this.getLayerCtx();a.beginPath(),a.ellipse(s,r,n,o,0,0,2*Math.PI),a.fill(),a.closePath()}pill(t,A,e,i){const[n,o]=qi(this.transform,[t-e/2,A+i/2]),s=yf(this.transform,e),r=yf(this.transform,i),a=Math.min(s,r)/2;this.applyAperture();const g=this.getLayerCtx();g.beginPath(),g.arc(n+a,o+a,a,Math.PI,Math.PI*1.5),g.arc(n+s-a,o+a,a,Math.PI*1.5,0),g.arc(n+s-a,o+r-a,a,0,Math.PI*.5),g.arc(n+a,o+r-a,a,Math.PI*.5,Math.PI),g.fill(),g.closePath()}polygon(t){if(t.length<3)return;this.applyAperture();const A=this.getLayerCtx(),e=t.map(n=>qi(this.transform,[n.x,n.y]));A.beginPath(),A.moveTo(e[0][0],e[0][1]);for(let n=1;n<e.length;n++)A.lineTo(e[n][0],e[n][1]);A.closePath(),A.fill("evenodd");const i=yf(this.transform,this.aperture.size);i>0&&(A.lineWidth=i,A.stroke())}debugText(t,A,e){const[i,n]=qi(this.transform,[A,e]);this.applyAperture();const o=this.getLayerCtx();o.font="10px sans-serif",o.fillText(t,i,n)}getLayerCtx(){const t=this.ctxLayerMap[this.aperture.layer];if(!t)throw new Error(`No context for layer "${this.aperture.layer}"`);return t}orderAndFadeLayers(){const{canvasLayerMap:t,foregroundLayer:A}=this,e=A==="top"?"top_silkscreen":A==="bottom"?"bottom_silkscreen":void 0,i=A==="top"?"top_notes":A==="bottom"?"bottom_notes":void 0,n=A==="top"?"soldermask_with_copper_top":A==="bottom"?"soldermask_with_copper_bottom":void 0,o=new Set([A,"drill","edge_cuts","other","board",...e?[e]:[],...i?[i]:[],...n?[n]:[]]),s=[A,"edge_cuts",...e?[e]:[],...i?[i]:[],...n?[n]:[]],r=[...k8t.filter(a=>!s.includes(a)),A,...n?[n]:[],"edge_cuts","drill",...e?[e]:[],...i?[i]:[]];r.forEach((a,g)=>{const c=t[a];c&&(c.style.zIndex=`${uc.topLayer-(r.length-g)}`,c.style.opacity=o.has(a)?"1":"0.5")})}applyAperture(){const{transform:t,aperture:A}=this;let{size:e,mode:i,color:n,fontSize:o,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(n||(n="undefined"),r.lineWidth=yf(t,e),r.lineCap="round",i==="add"){r.globalCompositeOperation="source-over";let a=v9[n.toLowerCase()];if(!a)try{a=Ra(n).rgb().toString()}catch{console.warn(`Invalid color format: '${n}'`),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=`${yf(yb(t),o)}px sans-serif`}moveTo(t,A){this.lastPoint={x:t,y:A}}lineTo(t,A){const[e,i]=qi(this.transform,[t,A]),{size:n,shape:o,mode:s}=this.aperture,r=yf(this.transform,n),{lastPoint:a}=this,g=qi(this.transform,a);this.applyAperture();const c=this.getLayerCtx();o==="square"&&c.fillRect(g.x-r/2,g.y-r/2,r,r),c.beginPath(),c.moveTo(g.x,g.y),c.lineTo(e,i),c.stroke(),c.closePath(),o==="square"&&c.fillRect(e-r/2,i-r/2,r,r),this.lastPoint={x:t,y:A}}polygonWithArcs(t){const A=this.getLayerCtx(),e=i=>{if(i.vertices.length===0)return;const n=i.vertices[0],o=qi(this.transform,[n.x,n.y]);A.moveTo(o[0],o[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,c=a.x-r.x,I=a.y-r.y,l=Math.sqrt(c*c+I*I);if(l<1e-9){const M=qi(this.transform,[a.x,a.y]);A.lineTo(M[0],M[1]);continue}const B=4*Math.atan(g),C=Math.abs(l/(2*Math.sin(B/2))),Q=(r.x+a.x)/2,h=(r.y+a.y)/2,E=c/l,d=-(I/l),p=E,m=Math.sqrt(Math.max(0,C*C-(l/2)**2)),D=Q+m*d*Math.sign(g),w=h+m*p*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=yf(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(),e(t.outer_ring),t.inner_rings)for(const i of t.inner_rings)e(i);A.fill("evenodd")}};function G8t(t){return t.type==="pcb_copper_pour"}function L9({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=A.filter(G8t);if(n.length===0)return;const o=new NQ(t);o.realToCanvasMat=i,o.drawElements(n,{layers:e})}var R8t={...pf,silkscreen:{top:wn.board.f_fab,bottom:wn.board.b_fab}};function M8t(t){return t.type.includes("pcb_fabrication_note")}function Qce({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new NQ(t);n.configure({colorOverrides:R8t}),n.realToCanvasMat=i;const o=A.filter(M8t);n.drawElements(o,{layers:e})}function N8t(t){return t.type==="pcb_hole"}function v8t({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new NQ(t);o.realToCanvasMat=i;const s=A.filter(N8t);o.drawElements(s,{layers:e,drawSoldermask:n})}function L8t(t){return t.type==="pcb_board"}function U8t({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new NQ(t);o.realToCanvasMat=i;const s=A.filter(L8t);for(const r of s)o.drawElements([r],{layers:e,drawSoldermask:n})}function H8t(t){return t.type==="pcb_cutout"}function Y8t({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new NQ(t);n.realToCanvasMat=i;const o=A.filter(H8t);n.drawElements(o,{layers:e})}function J8t(t){return t.type==="pcb_keepout"}function T8t({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=A.filter(J8t);if(n.length===0)return;const o=new NQ(t);o.realToCanvasMat=i,o.drawElements(n,{layers:[]})}function K8t(t){return t.type.startsWith("pcb_note_")}function hce({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new NQ(t);n.realToCanvasMat=i;const o=A.filter(K8t);n.drawElements(o,{layers:e})}function P8t(t){return t.type==="pcb_panel"}function q8t({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new NQ(t);o.realToCanvasMat=i;const s=A.filter(P8t);for(const r of s)o.drawElements([r],{layers:e,drawSoldermask:n})}var O8t={...pf,copper:{...pf.copper,top:Ra(wn.board.pad_front).lighten(.5).toString(),bottom:Ra(wn.board.pad_back).lighten(.5).toString(),inner1:Ra(wn.board.copper.in1).lighten(.5).toString(),inner2:Ra(wn.board.copper.in2).lighten(.5).toString(),inner3:Ra(wn.board.copper.in3).lighten(.5).toString(),inner4:Ra(wn.board.copper.in4).lighten(.5).toString(),inner5:Ra(wn.board.copper.in5).lighten(.5).toString(),inner6:Ra(wn.board.copper.in6).lighten(.5).toString()}};function W8t(t){return t.type==="pcb_smtpad"}function Z8t({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(W8t).filter(c=>{const I=c.layer;return e.some(l=>l==="top_copper"&&I==="top"||l==="bottom_copper"&&I==="bottom"||l==="inner1_copper"&&I==="inner1"||l==="inner2_copper"&&I==="inner2"||l==="inner3_copper"&&I==="inner3"||l==="inner4_copper"&&I==="inner4"||l==="inner5_copper"&&I==="inner5"||l==="inner6_copper"&&I==="inner6")});if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_smtpad"&&r.add(c._element.pcb_smtpad_id);const a=s.filter(c=>r.has(c.pcb_smtpad_id)),g=s.filter(c=>!r.has(c.pcb_smtpad_id));if(g.length>0){const c=new NQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new NQ(t);c.configure({colorOverrides:O8t}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}var V8t={...pf,copper:{...pf.copper,top:Ra(wn.board.pad_front).lighten(.5).toString(),bottom:Ra(wn.board.pad_back).lighten(.5).toString(),inner1:Ra(wn.board.copper.in1).lighten(.5).toString(),inner2:Ra(wn.board.copper.in2).lighten(.5).toString(),inner3:Ra(wn.board.copper.in3).lighten(.5).toString(),inner4:Ra(wn.board.copper.in4).lighten(.5).toString(),inner5:Ra(wn.board.copper.in5).lighten(.5).toString(),inner6:Ra(wn.board.copper.in6).lighten(.5).toString()}};function j8t(t){return t.type==="pcb_trace"}var z8t=t=>t.map(A=>A.endsWith("_copper")?A.replace("_copper",""):A);function X8t({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n}){const o=new Set(z8t(e)),s=A.filter(j8t).filter(c=>c.route.some(I=>I.route_type==="wire"&&"layer"in I&&o.has(I.layer)));if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_trace"&&r.add(c._element.pcb_trace_id);const a=s.filter(c=>r.has(c.pcb_trace_id)),g=s.filter(c=>!r.has(c.pcb_trace_id));if(g.length>0){const c=new NQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e})}if(a.length>0){const c=new NQ(t);c.configure({colorOverrides:V8t}),c.realToCanvasMat=i,c.drawElements(a,{layers:e})}}var $8t={...pf,copper:{...pf.copper,top:Ra(wn.board.pad_front).lighten(.5).toString(),bottom:Ra(wn.board.pad_back).lighten(.5).toString()}};function AWt(t){return t.type==="pcb_plated_hole"}function Ece({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(AWt);if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_plated_hole"&&r.add(c._element.pcb_plated_hole_id);const a=s.filter(c=>r.has(c.pcb_plated_hole_id)),g=s.filter(c=>!r.has(c.pcb_plated_hole_id));if(g.length>0){const c=new NQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new NQ(t);c.configure({colorOverrides:$8t}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}function uce(t){const{lines:A,anchorPoint:e,ccwRotation:i}=t;if(!i)return A;const n=i*Math.PI/180,o=e3t(n),s=zy(rB(e.x,e.y),o,rB(-e.x,-e.y));return qi(s,e),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 eWt=.6,dce=.2,pce=t=>{const A=t.size*.7,e=A*eWt,i=A*dce,n=A*dce,o=t.text.split(/\r?\n/),s=t.text.length>0&&A>0,r=s?o.length:0,a=s?o.map(I=>I.length===0?0:I.length*e+(I.length-1)*i):[],g=a.length>0?Math.max(...a):0,c=r>0?r*A+(r-1)*n:0;return{text_lines:o,line_count:r,line_widths:a,target_height:A,target_width_char:e,space_between_chars:i,space_between_lines:n,width:g,height:c}},fce=t=>{const A=pce(t);return{width:A.width,height:A.height,lineHeight:A.target_height,lineSpacing:A.space_between_lines,lineCount:A.line_count}},yce=t=>{const{text_lines:A,line_count:e,line_widths:i,target_height:n,target_width_char:o,space_between_chars:s,space_between_lines:r,width:a}=pce(t);if(n<=0||e===0)return[];const g=n/12,c=[];for(let I=0;I<e;I++){const l=-I*(n+r),B=i[I],C=(a-B)/2;let Q=t.x+C;for(let h=0;h<A[I].length;h++){const E=A[I][h],u=aD[E]??aD[E.toUpperCase()];if(!u){Q+=o+s;continue}for(const{x1:d,y1:p,x2:m,y2:D}of u)c.push({_pcb_drawing_object_id:Xy("line"),pcb_drawing_type:"line",x1:Q+o*d,y1:t.y+l+n*p,x2:Q+o*m,y2:t.y+l+n*D,width:g,layer:t.layer,unit:t.unit,color:t.color});Q+=o+s}}return c};function LD(t){const e=t.color??v9[t.layer];let i=Ra(e);return t._element?.type==="pcb_copper_pour"&&(i=i.alpha(.7)),t.is_mouse_over||t.is_in_highlighted_net?i.lighten(.5).rgb().toString():i.rgb().toString()}var mce=(t,A)=>{t.equip({size:A.zoomIndependent?A.width/t.transform.a:A.width,shape:A.squareCap?"square":"circle",color:LD(A),layer:A.layer}),t.moveTo(A.x1,A.y1),t.lineTo(A.x2,A.y2)},tWt=(t,A,e)=>{switch(e){case"top_left":return{x:0,y:-A};case"top_center":return{x:-t/2,y:-A};case"top_right":return{x:-t,y:-A};case"center_left":return{x:0,y:-A/2};case"center":return{x:-t/2,y:-A/2};case"center_right":return{x:-t,y:-A/2};case"bottom_left":return{x:0,y:0};case"bottom_center":return{x:-t/2,y:0};case"bottom_right":return{x:-t,y:0};default:return{x:0,y:0}}},wce=t=>t.layer==="bottom_silkscreen"||t.layer==="bottom"?t.is_mirrored!==!1:t.is_mirrored===!0,iWt=(t,A)=>{t.equip({fontSize:A.size,color:LD(A),layer:A.layer});const{width:e,height:i}=fce(A),n=tWt(e,i,A.align);A.x??=0,A.y??=0;const o={x:A.x,y:A.y};let s=yce({...A,x:A.x+n.x,y:A.y+n.y});if(wce(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:o,ccwRotation:A.ccw_rotation};s=uce(r)}for(const r of s)mce(t,r)},nWt=(t,A)=>{const{width:e,height:i,lineHeight:n}=fce(A);A.x??=0,A.y??=0;const o=A.knockout_padding??{left:A.size*.5,right:A.size*.5,top:A.size*.3,bottom:A.size*.3},s=e+o.left+o.right,r=i+o.top+o.bottom,a=e/2,g=n-i/2,c=A.x-a,I=A.y-g,l={x:A.x,y:A.y},B={_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?Sce(t,B):Dce(t,B);let C=yce({...A,x:c,y:I});if(wce(A)&&(C=C.map(Q=>({...Q,x1:2*A.x-Q.x1,x2:2*A.x-Q.x2}))),A.ccw_rotation){const Q={lines:C,anchorPoint:l,ccwRotation:A.ccw_rotation};C=uce(Q)}for(const Q of C)t.equip({size:Q.width,shape:"circle",color:"black",layer:A.layer,mode:"subtract"}),t.moveTo(Q.x1,Q.y1),t.lineTo(Q.x2,Q.y2);t.equip({mode:"add"})},Dce=(t,A)=>{t.equip({color:LD(A),layer:A.layer,size:A.stroke_width}),t.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})},Sce=(t,A)=>{t.equip({color:LD(A),layer:A.layer}),t.rotatedRect(A.x,A.y,A.w,A.h,A.ccw_rotation,A.roundness,A.mesh_fill)},oWt=(t,A)=>{t.equip({color:LD(A),layer:A.layer}),t.rotatedPill(A.x,A.y,A.w,A.h,A.ccw_rotation)},sWt=(t,A)=>{t.equip({color:LD(A),layer:A.layer}),t.circle(A.x,A.y,A.r,A.mesh_fill)},rWt=(t,A)=>{t.equip({color:LD(A),layer:A.layer}),t.oval(A.x,A.y,A.rX,A.rY)},aWt=(t,A)=>{t.equip({color:LD(A),layer:A.layer}),t.pill(A.x,A.y,A.w,A.h)},gWt=(t,A)=>{t.equip({color:LD(A),layer:A.layer}),t.polygon(A.points)},cWt=(t,A)=>{t.equip({color:LD(A),layer:A.layer}),t.polygonWithArcs(A.brep_shape)},IWt=(t,A)=>{switch(A.pcb_drawing_type){case"line":return mce(t,A);case"text":return A.is_knockout?nWt(t,A):iWt(t,A);case"rect":return A.ccw_rotation?Sce(t,A):Dce(t,A);case"circle":return sWt(t,A);case"oval":return rWt(t,A);case"pill":return A.ccw_rotation?oWt(t,A):aWt(t,A);case"polygon":return gWt(t,A);case"polygon_with_arcs":return cWt(t,A)}},lWt=(t,A)=>{for(const e of A)IWt(t,e)},BWt={...pf,copper:{...pf.copper,top:Ra(wn.board.pad_front).lighten(.5).toString(),bottom:Ra(wn.board.pad_back).lighten(.5).toString(),inner1:Ra(wn.board.copper.in1).lighten(.5).toString(),inner2:Ra(wn.board.copper.in2).lighten(.5).toString(),inner3:Ra(wn.board.copper.in3).lighten(.5).toString(),inner4:Ra(wn.board.copper.in4).lighten(.5).toString(),inner5:Ra(wn.board.copper.in5).lighten(.5).toString(),inner6:Ra(wn.board.copper.in6).lighten(.5).toString()},soldermask:{...pf.soldermask,top:Ra(wn.board.soldermask.top).lighten(.35).toString(),bottom:Ra(wn.board.soldermask.bottom).lighten(.35).toString()}};function U9({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n}){const o=new NQ(t);if(o.realToCanvasMat=i,o.drawElements(A,{layers:e,drawSoldermask:!0}),!n)return;const s=new Set;for(const g of n){if(!(g.is_mouse_over||g.is_in_highlighted_net))continue;const c=g._element;c?.type==="pcb_smtpad"?s.add(c.pcb_smtpad_id):c?.type==="pcb_plated_hole"?s.add(c.pcb_plated_hole_id):c?.type==="pcb_via"&&s.add(c.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 NQ(t);a.configure({colorOverrides:BWt}),a.realToCanvasMat=i,a.drawElements(r,{layers:e,drawSoldermask:!0})}var CWt={...pf,silkscreen:{top:wn.board.f_silks,bottom:wn.board.b_silks}};function QWt(t){return t.type.includes("pcb_silkscreen")}function bce({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new NQ(t);n.configure({colorOverrides:CWt}),n.realToCanvasMat=i;const o=A.filter(QWt);n.drawElements(o,{layers:e})}var hWt={...pf,copper:{...pf.copper,top:Ra(wn.board.pad_front).lighten(.5).toString(),bottom:Ra(wn.board.pad_back).lighten(.5).toString()}};function EWt(t){return t.type==="pcb_via"}function xce({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(EWt).filter(c=>e.some(I=>I.includes("copper")));if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_via"&&r.add(c._element.pcb_via_id);const a=s.filter(c=>r.has(c.pcb_via_id)),g=s.filter(c=>!r.has(c.pcb_via_id));if(g.length>0){const c=new NQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new NQ(t);c.configure({colorOverrides:hWt}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}var uWt=["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"],dWt=({primitives:t,elements:A,transform:e,grid:i,width:n=500,height:o=500})=>{const s=V.useRef({}),r=XB(g=>g.selected_layer),a=XB(g=>g.is_showing_solder_mask);return V.useEffect(()=>{if(!s.current||Object.keys(s.current).length===0)return;const g=Object.fromEntries(Object.entries(s.current).filter(([l,B])=>!(!B||!a&&l.includes("soldermask"))));if(Object.keys(g).length===0)return;const c=new F8t(g);e&&(c.transform=e),c.clear(),c.foregroundLayer=r;const I=t.filter(l=>a||!l.layer?.includes("soldermask")).filter(l=>l.layer!=="board").filter(l=>l._element?.type!=="pcb_smtpad").filter(l=>l._element?.type!=="pcb_plated_hole").filter(l=>l._element?.type!=="pcb_via").filter(l=>l._element?.type!=="pcb_trace");if(lWt(c,I),e){const l=s.current.top,B=s.current.bottom,C=s.current.inner1,Q=s.current.inner2,h=s.current.inner3,E=s.current.inner4,u=s.current.inner5,d=s.current.inner6;l&&Ece({canvas:l,elements:A,layers:["top_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),B&&Ece({canvas:B,elements:A,layers:["bottom_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),l&&L9({canvas:l,elements:A,layers:["top_copper"],realToCanvasMat:e}),B&&L9({canvas:B,elements:A,layers:["bottom_copper"],realToCanvasMat:e});const p=[{canvas:l,copperLayer:"top_copper"},{canvas:B,copperLayer:"bottom_copper"},{canvas:C,copperLayer:"inner1_copper"},{canvas:Q,copperLayer:"inner2_copper"},{canvas:h,copperLayer:"inner3_copper"},{canvas:E,copperLayer:"inner4_copper"},{canvas:u,copperLayer:"inner5_copper"},{canvas:d,copperLayer:"inner6_copper"}];for(const{canvas:H,copperLayer:O}of p)H&&X8t({canvas:H,elements:A,layers:[O],realToCanvasMat:e,primitives:t});for(const{canvas:H,copperLayer:O}of p)H&&(Z8t({canvas:H,elements:A,layers:[O],realToCanvasMat:e,primitives:t,drawSoldermask:a}),a&&U9({canvas:H,elements:A,layers:[O],realToCanvasMat:e,primitives:t}));if(l&&xce({canvas:l,elements:A,layers:["top_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),B&&xce({canvas:B,elements:A,layers:["bottom_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),a){const H=s.current.soldermask_top;H&&U9({canvas:H,elements:A,layers:["top_soldermask"],realToCanvasMat:e,primitives:t});const O=s.current.soldermask_bottom;O&&U9({canvas:O,elements:A,layers:["bottom_soldermask"],realToCanvasMat:e,primitives:t})}l&&L9({canvas:l,elements:A,layers:["top_copper"],realToCanvasMat:e}),B&&L9({canvas:B,elements:A,layers:["bottom_copper"],realToCanvasMat:e});const m=s.current.drill;m&&(v8t({canvas:m,elements:A,layers:["drill"],realToCanvasMat:e}),a&&U9({canvas:m,elements:A,layers:["drill"],realToCanvasMat:e,primitives:t}));const D=s.current.top_silkscreen;D&&bce({canvas:D,elements:A,layers:["top_silkscreen"],realToCanvasMat:e});const w=s.current.bottom_silkscreen;w&&bce({canvas:w,elements:A,layers:["bottom_silkscreen"],realToCanvasMat:e});const b=s.current.top_fabrication;b&&Qce({canvas:b,elements:A,layers:["top_fabrication_note"],realToCanvasMat:e});const k=s.current.bottom_fabrication;k&&Qce({canvas:k,elements:A,layers:["bottom_fabrication_note"],realToCanvasMat:e});const x=s.current.bottom_notes;x&&hce({canvas:x,elements:A,layers:["bottom_user_note"],realToCanvasMat:e});const N=s.current.top_notes;N&&hce({canvas:N,elements:A,layers:["top_user_note"],realToCanvasMat:e});const M=s.current.board;M&&(q8t({canvas:M,elements:A,layers:[],realToCanvasMat:e,drawSoldermask:a}),U8t({canvas:M,elements:A,layers:[],realToCanvasMat:e,drawSoldermask:a}));const L=s.current.edge_cuts;L&&Y8t({canvas:L,elements:A,layers:["edge_cuts"],realToCanvasMat:e});const Y=[{canvas:l,layer:"top"},{canvas:B,layer:"bottom"}];for(const{canvas:H,layer:O}of Y)H&&T8t({canvas:H,elements:A,layers:[O],realToCanvasMat:e})}c.orderAndFadeLayers()},[t,A,e,r,a]),W.jsxs("div",{style:{backgroundColor:"black",width:n,height:o,position:"relative"},children:[W.jsx(p9.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:n,height:o,transform:e,stringifyCoord:(g,c,I)=>`${p9.toMMSI(g,I)}, ${p9.toMMSI(c,I)}`}),uWt.filter(g=>a?!0:!g.includes("soldermask")).map(g=>g.replace(/-/g,"")).map((g,c)=>W.jsx("canvas",{className:`pcb-layer-${g}`,ref:I=>{s.current??={},I?s.current[g]=I:delete s.current[g]},style:{position:"absolute",zIndex:c,left:0,top:0,pointerEvents:"none"},width:n,height:o},g))]})},pWt=.6,fWt=1;Xge(L5t()),Xge($5t());var H9=["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 _ce(t,A,e,i={}){const n=i.padding??40,o=i.yFlip??!1;let s;if("center"in t){const c=t.width/2,I=t.height/2;s={minX:t.center.x-c,maxX:t.center.x+c,minY:t.center.y-I,maxY:t.center.y+I}}else s=t;const r=s.maxX-s.minX||1,a=s.maxY-s.minY||1,g=Math.min((A-2*n)/r,(e-2*n)/a);return zy(rB(A/2,e/2),tJ(g,o?-g:g),rB(-(s.minX+r/2),-(s.minY+a/2)))}function yWt(t){const A=[...t.points||[],...(t.lines||[]).flatMap(e=>e.points),...(t.rects||[]).flatMap(e=>{const i=e.width/2,n=e.height/2;return[{x:e.center.x-i,y:e.center.y-n},{x:e.center.x+i,y:e.center.y-n},{x:e.center.x-i,y:e.center.y+n},{x:e.center.x+i,y:e.center.y+n}]}),...(t.circles||[]).flatMap(e=>[{x:e.center.x-e.radius,y:e.center.y},{x:e.center.x+e.radius,y:e.center.y},{x:e.center.x,y:e.center.y-e.radius},{x:e.center.x,y:e.center.y+e.radius}]),...(t.texts||[]).flatMap(e=>{const i=e.fontSize??12,n=e.text.length*i*pWt,o=i*fWt,s=e.anchorSide??"center",r={top_left:{dx:0,dy:0},top_center:{dx:-n/2,dy:0},top_right:{dx:-n,dy:0},center_left:{dx:0,dy:-o/2},center:{dx:-n/2,dy:-o/2},center_right:{dx:-n,dy:-o/2},bottom_left:{dx:0,dy:-o},bottom_center:{dx:-n/2,dy:-o},bottom_right:{dx:-n,dy:-o}},{dx:a,dy:g}=r[s],c=e.x+a,I=e.y+g;return[{x:c,y:I},{x:c+n,y:I+o}]})];return A.length===0?{minX:-1,maxX:1,minY:-1,maxY:1}:A.reduce((e,i)=>({minX:Math.min(e.minX,i.x),maxX:Math.max(e.maxX,i.x),minY:Math.min(e.minY,i.y),maxY:Math.max(e.maxY,i.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function mWt(t,A,e={}){const i=A instanceof HTMLCanvasElement?A.getContext("2d"):A;if(!i)throw new Error("Could not get 2D context from canvas");const n=A instanceof HTMLCanvasElement?A.width:A.canvas.width,o=A instanceof HTMLCanvasElement?A.height:A.canvas.height;let s;if(e.transform)s=e.transform;else if(e.viewbox)s=_ce(e.viewbox,n,o,{padding:e.padding,yFlip:e.yFlip});else{const r=yWt(t),a=t.coordinateSystem==="cartesian";s=_ce(r,n,o,{padding:e.padding??40,yFlip:a})}i.clearRect(0,0,n,o),i.save(),t.rects&&t.rects.length>0&&t.rects.forEach(r=>{const a=r.width/2,g=r.height/2,c=qi(s,{x:r.center.x-a,y:r.center.y-g}),I=qi(s,{x:r.center.x+a,y:r.center.y+g}),l=Math.abs(I.x-c.x),B=Math.abs(I.y-c.y);i.beginPath(),i.rect(Math.min(c.x,I.x),Math.min(c.y,I.y),l,B),r.fill&&(i.fillStyle=r.fill,i.fill()),r.stroke&&(i.strokeStyle=r.stroke,i.stroke())}),t.circles&&t.circles.length>0&&t.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())}),t.lines&&t.lines.length>0&&t.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 c=1;c<r.points.length;c++){const I=qi(s,r.points[c]);i.lineTo(I.x,I.y)}if(i.strokeStyle=r.strokeColor||H9[a%H9.length],r.strokeWidth?i.lineWidth=r.strokeWidth*s.a:i.lineWidth=2,i.lineCap="round",r.strokeDash)if(typeof r.strokeDash=="string"){let c;if(r.strokeDash.includes(","))c=r.strokeDash.split(",").map(I=>parseFloat(I.trim())).filter(I=>!Number.isNaN(I));else{const I=parseFloat(r.strokeDash.trim());c=Number.isNaN(I)?[]:[I]}i.setLineDash(c)}else i.setLineDash(r.strokeDash.map(c=>c*Math.abs(s.a)));else i.setLineDash([]);i.stroke()}),t.points&&t.points.length>0&&t.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||H9[a%H9.length],i.fill(),r.label&&!e.disableLabels&&(i.fillStyle=r.color||"black",i.font="12px sans-serif",i.fillText(r.label,g.x+5,g.y-5))}),t.texts&&t.texts.length>0&&t.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",c={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"},I={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=c[g],i.textBaseline=I[g],i.fillText(r.text,a.x,a.y)}),i.restore()}var wWt=({children:t,transform:A,debugGraphics:e})=>{const i=V.useRef(null),[n,{width:o,height:s}]=EJ(),r=XB(a=>a.is_showing_autorouting);return V.useEffect(()=>{r&&i.current&&e&&o&&s&&(i.current.width=o,i.current.height=s,mWt(e,i.current,{transform:A,disableLabels:!0}))},[e,A,o,s,r]),r?W.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:i,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):t},DWt=({children:t,transform:A=fb(),elements:e=[]})=>{const[i,{width:n,height:o}]=EJ(),s=V.useRef(null);return V.useEffect(()=>{const r=s.current;if(!r||!n||!o)return;r.width=n,r.height=o;const a=r.getContext("2d");if(!a)return;a.clearRect(0,0,n,o);const g=e.filter(I=>I.type==="pcb_component"),c=e.filter(I=>I.type==="pcb_manual_edit_conflict_warning");a.strokeStyle=wn.board.drc_warning,a.lineWidth=2,c.forEach(I=>{const l=g.find(O=>O.pcb_component_id===I.pcb_component_id);if(!l)return;const{width:B,height:C,center:Q}=l,h=qi(A,Q),E=B*Math.abs(A.a),u=C*Math.abs(A.d),d=.1*Math.abs(A.a),p=E+d*2,m=u+d*2,D=h.x-p/2,w=h.y-m/2;a.beginPath(),a.rect(D,w,p,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,L=x+k*2,Y=D+(p-M)/2,H=w+m+5;a.fillStyle="rgba(0, 0, 0, 0.7)",a.beginPath(),a.roundRect(Y,H,M,L,3),a.fill(),a.fillStyle=wn.board.drc_warning,a.textAlign="center",a.textBaseline="middle",a.fillText(b,Y+M/2,H+L/2)})},[e,A,n,o]),W.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:s,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:uc.warnings}})]})},Y9=(t,A,e)=>e(t,A),kce=(t,A,e,i,n)=>{const o=n*Math.PI/180,s=Math.cos(o),r=Math.sin(o),a=t-e,g=A-i,c=a*s-g*r,I=a*r+g*s;return{x:c+e,y:I+i}},uJ=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].x,i=t[0].y,n=t[0].y;for(const o of t)A=Y9(A,o.x,Math.min),e=Y9(e,o.x,Math.max),i=Y9(i,o.y,Math.min),n=Y9(n,o.y,Math.max);return{minX:A,maxX:e,minY:i,maxY:n}},SWt=(t,A)=>({minX:Math.min(t.minX,A.minX),maxX:Math.max(t.maxX,A.maxX),minY:Math.min(t.minY,A.minY),maxY:Math.max(t.maxY,A.maxY)}),bWt=(t,A)=>t?SWt(t,A):A,xWt=t=>{switch(t.pcb_drawing_type){case"line":{const A=(t.width??0)/2,e=[{x:t.x1,y:t.y1},{x:t.x2,y:t.y2}],i=uJ(e);return i?{minX:i.minX-A,maxX:i.maxX+A,minY:i.minY-A,maxY:i.maxY+A}:null}case"rect":{const A=t.w/2,e=t.h/2,i=[{x:t.x-A,y:t.y-e},{x:t.x+A,y:t.y-e},{x:t.x+A,y:t.y+e},{x:t.x-A,y:t.y+e}],n=t.ccw_rotation??0,o=n===0?i:i.map(s=>kce(s.x,s.y,t.x,t.y,n));return uJ(o)}case"circle":return{minX:t.x-t.r,maxX:t.x+t.r,minY:t.y-t.r,maxY:t.y+t.r};case"oval":return{minX:t.x-t.rX,maxX:t.x+t.rX,minY:t.y-t.rY,maxY:t.y+t.rY};case"pill":{const A=t.w/2,e=t.h/2,i=[{x:t.x-A,y:t.y-e},{x:t.x+A,y:t.y-e},{x:t.x+A,y:t.y+e},{x:t.x-A,y:t.y+e}],n=t.ccw_rotation??0,o=n===0?i:i.map(s=>kce(s.x,s.y,t.x,t.y,n));return uJ(o)}case"polygon":return uJ(t.points);case"polygon_with_arcs":{const A=t.brep_shape.outer_ring.vertices.map(e=>({x:e.x,y:e.y}));return uJ(A)}case"text":{const A=t.size??0,e=t.text?t.text.length*A*.6:0,i=A;if(e===0&&i===0)return{minX:t.x,maxX:t.x,minY:t.y,maxY:t.y};const n=e/2,o=i/2;return{minX:t.x-n,maxX:t.x+n,minY:t.y-o,maxY:t.y+o}}default:return null}};function _Wt(t){const{dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=t,r=e.x-A.x,a=e.y-A.y,g=Math.sqrt(r*r+a*a),c=n.x-i.x,I=n.y-i.y,l=Math.sqrt(c*c+I*I),B=Math.atan2(I,c)*(180/Math.PI),C=Math.abs(B)%90,h=Math.min(C,90-C)>15,E=(i.x+n.x)/2,u=(i.y+n.y)/2,d=15,p=B+90;let m=Math.cos(p*Math.PI/180)*d,D=Math.sin(p*Math.PI/180)*d;const w=c>0&&I<0,b=c>0&&I>0,k=c<0&&I>0;o!==s&&!w&&(m=-m,D=-D),w&&(m+=Math.cos(p*Math.PI/180)*-45,D+=Math.sin(p*Math.PI/180)*-45),b&&(m+=Math.cos(p*Math.PI/180)+-20,D+=Math.sin(p*Math.PI/180)+-10),k&&(m+=Math.cos(p*Math.PI/180)*10,D+=Math.sin(p*Math.PI/180)*10);const x=E+m,N=u+D;return{distance:g,screenDistance:l,x,y:N,show:g>.01&&l>30&&h}}function kWt(t){const{dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=t;return V.useMemo(()=>_Wt({dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}),[A,e,i,n,o,s])}var FWt=(t,A,e)=>{const i=e*Math.PI/180,n=Math.cos(i),o=Math.sin(i),s=t.x-A.x,r=t.y-A.y,a=s*n-r*o,g=s*o+r*n;return{x:a+A.x,y:g+A.y}},Fce=(t,A,e,i)=>{const n={top_left:{x:t.x-A,y:t.y-e},top_center:{x:t.x,y:t.y-e},top_right:{x:t.x+A,y:t.y-e},center_left:{x:t.x-A,y:t.y},center:{x:t.x,y:t.y},center_right:{x:t.x+A,y:t.y},bottom_left:{x:t.x-A,y:t.y+e},bottom_center:{x:t.x,y:t.y+e},bottom_right:{x:t.x+A,y:t.y+e}};return i===0?Object.entries(n).map(([o,s])=>({anchor:o,point:s})):Object.entries(n).map(([o,s])=>({anchor:o,point:FWt(s,t,i)}))},GWt=t=>{switch(t.pcb_drawing_type){case"rect":{const A=t.ccw_rotation??0;return Fce({x:t.x,y:t.y},t.w/2,t.h/2,A)}case"pill":{const A=t.ccw_rotation??0;return Fce({x:t.x,y:t.y},t.w/2,t.h/2,A)}case"circle":return[{anchor:"circle_center",point:{x:t.x,y:t.y}},{anchor:"circle_right",point:{x:t.x+t.r,y:t.y}},{anchor:"circle_left",point:{x:t.x-t.r,y:t.y}},{anchor:"circle_top",point:{x:t.x,y:t.y-t.r}},{anchor:"circle_bottom",point:{x:t.x,y:t.y+t.r}}];case"oval":return[{anchor:"oval_center",point:{x:t.x,y:t.y}},{anchor:"oval_right",point:{x:t.x+t.rX,y:t.y}},{anchor:"oval_left",point:{x:t.x-t.rX,y:t.y}},{anchor:"oval_top",point:{x:t.x,y:t.y-t.rY}},{anchor:"oval_bottom",point:{x:t.x,y:t.y+t.rY}}];case"line":{const A={x:(t.x1+t.x2)/2,y:(t.y1+t.y2)/2};return[{anchor:"line_start",point:{x:t.x1,y:t.y1}},{anchor:"line_mid",point:A},{anchor:"line_end",point:{x:t.x2,y:t.y2}}]}case"polygon":return t.points.map((A,e)=>({anchor:`polygon_vertex_${e}`,point:A}));case"polygon_with_arcs":return t.brep_shape.outer_ring.vertices.map((A,e)=>({anchor:`polygon_with_arcs_vertex_${e}`,point:{x:A.x,y:A.y}}));default:return[]}},RWt=16,SG=5,Gce=t=>{if(t.pcb_drawing_type==="text")return!0;const A=t._element;if(!A||typeof A!="object")return!1;const e=typeof A.type=="string"?A.type:void 0;return e?!!(e.startsWith("pcb_silkscreen_")||e.startsWith("pcb_note_")||e==="pcb_text"||e.startsWith("pcb_fabrication_note_")&&e!=="pcb_fabrication_note_rect"):!1},MWt=({children:t,transform:A,focusOnHover:e=!1,primitives:i=[]})=>{A||(A=fb());const[n,o]=V.useState(!1),[s,r]=V.useState(!1),[a,g]=V.useState(!1),[c,I]=V.useState({start:null,end:null}),l=XB(H=>H.is_mouse_over_container),B=V.useCallback(()=>{a&&(g(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[a]),[C,Q]=V.useState({x:0,y:0}),[h,E]=V.useState({x:0,y:0}),u=V.useRef({x:0,y:0}),d=V.useRef(null),m=d.current?.getBoundingClientRect(),D=V.useMemo(()=>{const H=new Map;for(const O of i){if(!O._element||Gce(O)||O.pcb_drawing_type==="pill"||O.pcb_drawing_type==="rect"&&O.ccw_rotation&&O.ccw_rotation!==0)continue;const Z=xWt(O);if(!Z)continue;const $=H.get(O._element);H.set(O._element,bWt($??void 0,Z))}return H},[i]),w=V.useMemo(()=>{const H=[];for(const O of i){if(!O._element||Gce(O))continue;const Z=GWt(O);if(Z.length!==0)for(const $ of Z)H.push({anchor:$.anchor,point:$.point,element:O._element})}return H},[i]),b=V.useMemo(()=>{const H=[];D.forEach((O,Z)=>{if(!O)return;const $=(O.minX+O.maxX)/2,iA=(O.minY+O.maxY)/2,aA={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[eA,nA]of Object.entries(aA))H.push({anchor:eA,point:nA,element:Z})});for(const O of w)H.push(O);return H.push({anchor:"origin",point:{x:0,y:0},element:null}),H},[D,w]),k=V.useMemo(()=>b.map((H,O)=>({...H,id:`${O}-${H.anchor}`,screenPoint:qi(A,H.point)})),[b,A]),x=V.useCallback(H=>{if(k.length===0)return{point:H,id:null};const O=qi(A,H);let Z=null;for(const $ of k){const iA=$.screenPoint.x-O.x,aA=$.screenPoint.y-O.y,eA=Math.hypot(iA,aA);eA>RWt||(!Z||eA<Z.distance)&&(Z={distance:eA,id:$.id,point:$.point})}return Z?{point:Z.point,id:Z.id}:{point:H,id:null}},[k,A]);V.useEffect(()=>{const H=Z=>{const $=Z.target;if($.tagName==="INPUT"||$.tagName==="TEXTAREA"||$.isContentEditable)return;const iA=d.current?.contains(document.activeElement)||document.activeElement===d.current;if(!(!l&&!iA)){if(Z.key==="d"){const aA=x({x:u.current.x,y:u.current.y});Q({x:aA.point.x,y:aA.point.y}),E({x:aA.point.x,y:aA.point.y}),I({start:aA.id,end:aA.id}),n?(o(!1),r(!1),I({start:null,end:null})):(o(!0),r(!0)),B()}Z.key==="Escape"&&(o(!1),r(!1),I({start:null,end:null}),B())}},O=()=>{g(!0)};return window.addEventListener("keydown",H),window.addEventListener("arm-dimension-tool",O),()=>{window.removeEventListener("keydown",H),window.removeEventListener("arm-dimension-tool",O),B()}},[l,n,B,x]);const N=qi(A,C),M=qi(A,h),L={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};L.width=L.right-L.left,L.height=L.bottom-L.top;const Y=kWt({dimensionStart:C,dimensionEnd:h,screenDimensionStart:N,screenDimensionEnd:M,flipX:L.flipX,flipY:L.flipY});return W.jsxs("div",{ref:d,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseEnter:()=>{e&&d.current&&d.current.focus()},onMouseLeave:()=>{d.current&&d.current.blur()},onClick:()=>{d.current&&d.current.focus()},onMouseMove:H=>{const O=H.currentTarget.getBoundingClientRect(),Z=H.clientX-O.left,$=H.clientY-O.top,iA=qi(yb(A),{x:Z,y:$});if(u.current.x=iA.x,u.current.y=iA.y,s){const aA=x(iA);E({x:aA.point.x,y:aA.point.y}),I(eA=>({...eA,end:aA.id}))}},onMouseDown:H=>{const O=H.currentTarget.getBoundingClientRect(),Z=H.clientX-O.left,$=H.clientY-O.top,iA=qi(yb(A),{x:Z,y:$});if(a&&!n){const aA=x(iA);Q({x:aA.point.x,y:aA.point.y}),E({x:aA.point.x,y:aA.point.y}),I({start:aA.id,end:aA.id}),o(!0),r(!0),B()}else s?(r(!1),I(aA=>({...aA,end:null}))):n&&(o(!1),I({start:null,end:null}))},children:[t,n&&W.jsxs(W.Fragment,{children:[Y.show&&W.jsx("div",{style:{position:"absolute",left:Y.x,top:Y.y,color:"red",mixBlendMode:"difference",pointerEvents:"none",fontSize:12,fontFamily:"sans-serif",whiteSpace:"nowrap",zIndex:uc.dimensionOverlay},children:Y.distance.toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:L.left,width:L.width,textAlign:"center",top:N.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:L.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:uc.dimensionOverlay},children:Math.abs(C.x-h.x).toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:M.x,height:L.height,display:"flex",flexDirection:"column",justifyContent:"center",top:L.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:uc.dimensionOverlay},children:W.jsx("div",{style:{marginLeft:L.flipX?"-100%":4,paddingRight:4},children:Math.abs(C.y-h.y).toFixed(2)})}),W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:uc.dimensionOverlay},width:m.width,height:m.height,children:[W.jsx("defs",{children:W.jsx("marker",{id:"head",orient:"auto",markerWidth:"3",markerHeight:"4",refX:"2",refY:"2",children:W.jsx("path",{d:"M0,0 V4 L2,2 Z",fill:"red"})})}),W.jsx("line",{x1:N.x,y1:N.y,x2:M.x,y2:M.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),W.jsx("line",{x1:N.x,y1:N.y,x2:M.x,y2:N.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),W.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===c.start||H.id===c.end,Z=SG/2;return W.jsxs("svg",{width:SG,height:SG,style:{position:"absolute",left:H.screenPoint.x-Z,top:H.screenPoint.y-Z,pointerEvents:"none",zIndex:uc.dimensionOverlay},children:[W.jsx("line",{x1:0,y1:0,x2:SG,y2:SG,stroke:O?"#66ccff":"white",strokeWidth:1}),W.jsx("line",{x1:SG,y1:0,x2:0,y2:SG,stroke:O?"#66ccff":"white",strokeWidth:1})]},H.id)}),W.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),")",W.jsx("br",{}),"(",h.x.toFixed(2),",",h.y.toFixed(2),")",W.jsx("br",{}),"dist:"," ",Math.sqrt((h.x-C.x)**2+(h.y-C.y)**2).toFixed(2)]})]})]})},NWt=(t,A,e=0)=>{const i=t.width/2,n=t.height/2,o=t.center.x-i-e,s=t.center.x+i+e,r=t.center.y-n-e,a=t.center.y+n+e;return A.x>o&&A.x<s&&A.y>r&&A.y<a},vWt=({children:t,disabled:A,transform:e,soup:i,cancelPanDrag:n,onCreateEditEvent:o,onModifyEditEvent:s})=>{e||(e=fb());const r=V.useRef(null),[a,g]=V.useState(null),[c,I]=V.useState(null),l=a!==null;XB(h=>h.in_edit_mode);const B=XB(h=>h.in_move_footprint_mode),C=XB(h=>h.setIsMovingComponent),Q=A||!B;return W.jsxs("div",{ref:r,style:{position:"relative",overflow:"hidden"},onMouseDown:h=>{if(Q)return;const E=h.currentTarget.getBoundingClientRect(),u=h.clientX-E.left,d=h.clientY-E.top;if(Number.isNaN(u)||Number.isNaN(d))return;const p=qi(yb(e),{x:u,y:d});let m=!1;for(const D of i)if(D.type==="pcb_component"&&NWt(D,p,10/e.a)){n(),g(D.pcb_component_id),m=!0;const w=Math.random().toString();I({dragStart:p,originalCenter:D.center,dragEnd:p,edit_event_id:w}),o({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 h.preventDefault(),!1},onMouseMove:h=>{if(!a||!c)return;const E=h.currentTarget.getBoundingClientRect(),u=h.clientX-E.left,d=h.clientY-E.top;if(Number.isNaN(u)||Number.isNaN(d))return;const p=qi(yb(e),{x:u,y:d});I({...c,dragEnd:p}),s({edit_event_id:c.edit_event_id,new_center:{x:c.originalCenter.x+p.x-c.dragStart.x,y:c.originalCenter.y+p.y-c.dragStart.y}})},onMouseUp:h=>{a&&(g(null),C(!1),c&&(s({edit_event_id:c.edit_event_id,in_progress:!1}),I(null)))},children:[t,!Q&&i.filter(h=>h.type==="pcb_component").map(h=>{if(!h?.center)return null;const E=qi(e,h.center);return W.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:E.x,top:E.y,width:h.width*e.a+20,height:h.height*e.a+20,transform:"translate(-50%, -50%)",background:l&&a===h.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},h.pcb_component_id)})]})},LWt=({hotkeys:t})=>(V.useEffect(()=>{const A=e=>{t.forEach(i=>{e.key===i.key&&i.onUse()})};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A)}},[t]),W.jsx("div",{className:A1`
|
|
5433
|
+
$1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function rce(t,A,e){if(!A||!e)return;let i=t.get(A);i||(i=new Set,t.set(A,i)),i.add(e);let n=t.get(e);n||(n=new Set,t.set(e,n)),n.add(A)}function A8t(t,A){if(!A.subcircuit_id&&!A.source_group_id)return[...t];const e=new Map;for(const s of t){const r=s[`${s.type}_id`];typeof r=="string"&&e.set(r,s)}const i=new Map;for(const s of t){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 c=e.get(g);rce(i,s,c)}else if(a.endsWith("_ids")&&Array.isArray(g)){for(const c of g)if(typeof c=="string"){const I=e.get(c);rce(i,s,I)}}}}const n=[],o=new Set;for(const s of t)(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)))&&(n.push(s),o.add(s));for(;n.length>0;){const s=n.shift(),r=i.get(s);if(r)for(const a of r)o.has(a)||(o.add(a),n.push(a))}return t.filter(s=>o.has(s))}var R9=(t,A={})=>{const e=t;let i=e._internal_store;if(!i){i={counts:{},editCount:0},e._internal_store=i;for(const o of e){const s=o.type,r=o[`${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:(o,s)=>{if(s==="toArray")return()=>(e.editCount=i.editCount,e);if(s==="editCount")return i.editCount;if(s==="subtree")return a=>R9(A8t(e,a),A);const r=s;return{get:a=>e.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 c=g[0],I=c.replace("_id",""),l=e.find(B=>B.type===I&&B[c]===a[c]);return l?e.find(B=>B.type===r&&B[`${r}_id`]===l[`${r}_id`]):null},getWhere:a=>{const g=Object.keys(a);return e.find(c=>c.type===r&&g.every(I=>c[I]===a[I]))},list:a=>{const g=a?Object.keys(a):[];return e.filter(c=>c.type===r&&g.every(I=>c[I]===a[I]))},insert:a=>{i.counts[r]??=-1,i.counts[r]++;const g=i.counts[r],c={type:r,[`${r}_id`]:`${r}_${g}`,...a};return A.validateInserts&&(Ige[r]??VpA).parse(c),e.push(c),i.editCount++,c},delete:a=>{const g=e.find(c=>c[`${r}_id`]===a);g&&(e.splice(e.indexOf(g),1),i.editCount++)},update:(a,g)=>{const c=e.find(I=>I.type===r&&I[`${r}_id`]===a);return c?(Object.assign(c,g),i.editCount++,c):null},select:a=>{if(r==="source_component")return e.find(g=>g.type==="source_component"&&g.name===a.replace(/\./g,""));if(r==="pcb_port"||r==="source_port"||r==="schematic_port"){const[g,c]=a.replace(/\./g,"").split(/[\s\>]+/),I=e.find(B=>B.type==="source_component"&&B.name===g);if(!I)return null;const l=e.find(B=>B.type==="source_port"&&B.source_component_id===I.source_component_id&&(B.name===c||(B.port_hints??[]).includes(c)));if(!l)return null;if(r==="source_port")return l;if(r==="pcb_port")return e.find(B=>B.type==="pcb_port"&&B.source_port_id===l.source_port_id);if(r==="schematic_port")return e.find(B=>B.type==="schematic_port"&&B.source_port_id===l.source_port_id)}}}}})};R9.unparsed=R9;var wb=R9;function xfA(t){const A=t.type;return`${A}:${t[`${A}_id`]}`}var ace=(t,A={})=>{let e=t._internal_store_indexed;if(!e){e={counts:{},editCount:0,indexes:{}};for(const s of t){const r=s.type,a=s[`${r}_id`];if(!a)continue;const g=Number.parseInt(a.split("_").pop()||"");Number.isNaN(g)||(e.counts[r]=Math.max(e.counts[r]??0,g))}const n=A.indexConfig||{},o=e.indexes;if(n.byId&&(o.byId=new Map),n.byType&&(o.byType=new Map),n.byRelation&&(o.byRelation=new Map),n.bySubcircuit&&(o.bySubcircuit=new Map),n.byCustomField&&n.byCustomField.length>0){o.byCustomField=new Map;for(const s of n.byCustomField)o.byCustomField.set(s,new Map)}for(const s of t){if(n.byId){const r=xfA(s);o.byId.set(r,s)}if(n.byType){const r=o.byType.get(s.type)||[];r.push(s),o.byType.set(s.type,r)}if(n.byRelation){const r=Object.entries(s);for(const[a,g]of r)if(a.endsWith("_id")&&a!==`${s.type}_id`&&typeof g=="string"){const c=o.byRelation.get(a)||new Map,I=c.get(g)||[];I.push(s),c.set(g,I),o.byRelation.set(a,c)}}if(n.bySubcircuit&&"subcircuit_id"in s){const r=s.subcircuit_id;if(r&&typeof r=="string"){const a=o.bySubcircuit.get(r)||[];a.push(s),o.bySubcircuit.set(r,a)}}if(n.byCustomField&&o.byCustomField){for(const r of n.byCustomField)if(r in s){const a=s[r];if(a!==void 0&&(typeof a=="string"||typeof a=="number")){const g=String(a),c=o.byCustomField.get(r),I=c.get(g)||[];I.push(s),c.set(g,I)}}}}t._internal_store_indexed=e}return new Proxy({},{get:(n,o)=>{if(o==="toArray")return()=>(t.editCount=e.editCount,t);if(o==="editCount")return e.editCount;const s=o;return{get:r=>{const a=A.indexConfig||{};return a.byId&&e.indexes.byId?e.indexes.byId.get(`${s}:${r}`)||null:a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(c=>c[`${s}_id`]===r)||null:t.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 c=g[0],I=c.replace("_id","");if(a.byRelation&&e.indexes.byRelation){const B=e.indexes.byRelation.get(c);if(B){const Q=(B.get(r[c])||[]).find(E=>E.type===I);if(!Q)return null;const h=Q[`${s}_id`];return a.byId&&e.indexes.byId?e.indexes.byId.get(`${s}:${h}`)||null:a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(u=>u[`${s}_id`]===h)||null:t.find(E=>E.type===s&&E[`${s}_id`]===h)||null}}const l=t.find(B=>B.type===I&&B[c]===r[c]);return l&&t.find(B=>B.type===s&&B[`${s}_id`]===l[`${s}_id`])||null},getWhere:r=>{const a=A.indexConfig||{},g=Object.keys(r);if(g.length===1&&a.byCustomField&&e.indexes.byCustomField){const c=g[0],I=e.indexes.byCustomField.get(c);if(I){const l=String(r[c]);return(I.get(l)||[]).find(C=>C.type===s)||null}}if("subcircuit_id"in r&&a.bySubcircuit&&e.indexes.bySubcircuit){const c=r.subcircuit_id;return(e.indexes.bySubcircuit.get(c)||[]).find(l=>l.type===s&&g.every(B=>l[B]===r[B]))||null}return a.byType&&e.indexes.byType?(e.indexes.byType.get(s)||[]).find(I=>g.every(l=>I[l]===r[l]))||null:t.find(c=>c.type===s&&g.every(I=>c[I]===r[I]))||null},list:r=>{const a=A.indexConfig||{},g=r?Object.keys(r):[];if(g.length===0&&a.byType&&e.indexes.byType)return e.indexes.byType.get(s)||[];if(g.length===1&&g[0]==="subcircuit_id"&&a.bySubcircuit&&e.indexes.bySubcircuit){const I=r.subcircuit_id;return(e.indexes.bySubcircuit.get(I)||[]).filter(B=>B.type===s)}let c;return a.byType&&e.indexes.byType?c=e.indexes.byType.get(s)||[]:c=t.filter(I=>I.type===s),g.length>0?c.filter(I=>g.every(l=>I[l]===r[l])):c},insert:r=>{e.counts[s]??=-1,e.counts[s]++;const a=e.counts[s],g={type:s,[`${s}_id`]:`${s}_${a}`,...r};A.validateInserts&&(Ige[s]??VpA).parse(g),t.push(g),e.editCount++;const c=A.indexConfig||{};if(c.byId&&e.indexes.byId){const I=xfA(g);e.indexes.byId.set(I,g)}if(c.byType&&e.indexes.byType){const I=e.indexes.byType.get(s)||[];I.push(g),e.indexes.byType.set(s,I)}if(c.byRelation&&e.indexes.byRelation){const I=Object.entries(g);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${g.type}_id`&&typeof B=="string"){const C=e.indexes.byRelation.get(l)||new Map,Q=C.get(B)||[];Q.push(g),C.set(B,Q),e.indexes.byRelation.set(l,C)}}if(c.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I&&typeof I=="string"){const l=e.indexes.bySubcircuit.get(I)||[];l.push(g),e.indexes.bySubcircuit.set(I,l)}}if(c.byCustomField&&e.indexes.byCustomField){for(const I of c.byCustomField)if(I in g){const l=g[I];if(l!==void 0&&(typeof l=="string"||typeof l=="number")){const B=String(l),C=e.indexes.byCustomField.get(I),Q=C.get(B)||[];Q.push(g),C.set(B,Q)}}}return g},delete:r=>{const a=A.indexConfig||{};let g;if(a.byId&&e.indexes.byId?g=e.indexes.byId.get(`${s}:${r}`):a.byType&&e.indexes.byType?g=(e.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):g=t.find(I=>I[`${s}_id`]===r),!g)return;const c=t.indexOf(g);if(c>=0&&(t.splice(c,1),e.editCount++),a.byId&&e.indexes.byId){const I=xfA(g);e.indexes.byId.delete(I)}if(a.byType&&e.indexes.byType){const l=(e.indexes.byType.get(s)||[]).filter(B=>B[`${s}_id`]!==r);e.indexes.byType.set(s,l)}if(a.byRelation&&e.indexes.byRelation)for(const[I,l]of e.indexes.byRelation.entries())for(const[B,C]of l.entries()){const Q=C.filter(h=>h!==g);Q.length===0?l.delete(B):l.set(B,Q)}if(a.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in g){const I=g.subcircuit_id;if(I){const B=(e.indexes.bySubcircuit.get(I)||[]).filter(C=>C!==g);B.length===0?e.indexes.bySubcircuit.delete(I):e.indexes.bySubcircuit.set(I,B)}}if(a.byCustomField&&e.indexes.byCustomField)for(const I of e.indexes.byCustomField.values())for(const[l,B]of I.entries()){const C=B.filter(Q=>Q!==g);C.length===0?I.delete(l):I.set(l,C)}},update:(r,a)=>{const g=A.indexConfig||{};let c;if(g.byId&&e.indexes.byId?c=e.indexes.byId.get(`${s}:${r}`):g.byType&&e.indexes.byType?c=(e.indexes.byType.get(s)||[]).find(l=>l[`${s}_id`]===r):c=t.find(I=>I.type===s&&I[`${s}_id`]===r),!c)return null;if(g.byRelation&&e.indexes.byRelation){const I=Object.entries(c);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${c.type}_id`&&typeof B=="string"&&l in a&&a[l]!==B){const C=e.indexes.byRelation.get(l);if(C){const h=(C.get(B)||[]).filter(E=>E!==c);h.length===0?C.delete(B):C.set(B,h)}}}if(g.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id,l=a.subcircuit_id;if(I!==l){const C=(e.indexes.bySubcircuit.get(I)||[]).filter(Q=>Q!==c);C.length===0?e.indexes.bySubcircuit.delete(I):e.indexes.bySubcircuit.set(I,C)}}if(g.byCustomField&&e.indexes.byCustomField){for(const I of g.byCustomField)if(I in c&&I in a&&c[I]!==a[I]){const l=e.indexes.byCustomField.get(I);if(l){const B=String(c[I]),Q=(l.get(B)||[]).filter(h=>h!==c);Q.length===0?l.delete(B):l.set(B,Q)}}}if(Object.assign(c,a),e.editCount++,g.byRelation&&e.indexes.byRelation){const I=Object.entries(c);for(const[l,B]of I)if(l.endsWith("_id")&&l!==`${c.type}_id`&&typeof B=="string"&&l in a){const C=e.indexes.byRelation.get(l)||new Map,Q=C.get(B)||[];Q.includes(c)||(Q.push(c),C.set(B,Q),e.indexes.byRelation.set(l,C))}}if(g.bySubcircuit&&e.indexes.bySubcircuit&&"subcircuit_id"in c&&"subcircuit_id"in a){const I=c.subcircuit_id;if(I&&typeof I=="string"){const l=e.indexes.bySubcircuit.get(I)||[];l.includes(c)||(l.push(c),e.indexes.bySubcircuit.set(I,l))}}if(g.byCustomField&&e.indexes.byCustomField){for(const I of g.byCustomField)if(I in c&&I in a){const l=c[I];if(l!==void 0&&(typeof l=="string"||typeof l=="number")){const B=String(l),C=e.indexes.byCustomField.get(I),Q=C.get(B)||[];Q.includes(c)||(Q.push(c),C.set(B,Q))}}}return c},select:r=>{if(s==="source_component")return t.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\>]+/),c=t.find(l=>l.type==="source_component"&&l.name===a);if(!c)return null;const I=t.find(l=>l.type==="source_port"&&l.source_component_id===c.source_component_id&&(l.name===g||(l.port_hints??[]).includes(g)));if(!I)return null;if(s==="source_port")return I;if(s==="pcb_port")return t.find(l=>l.type==="pcb_port"&&l.source_port_id===I.source_port_id)||null;if(s==="schematic_port")return t.find(l=>l.type==="schematic_port"&&l.source_port_id===I.source_port_id)||null}return null}}}})};ace.unparsed=ace;var e8t=t=>{const A=t.type;return t[`${A}_id`]},_fA=t=>{let A=Number.POSITIVE_INFINITY,e=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,n=Number.NEGATIVE_INFINITY;for(const o of t){if(!o.type.startsWith("pcb_"))continue;if(o.type==="pcb_smtpad"&&o.shape==="polygon"&&Array.isArray(o.points)){for(const c of o.points)A=Math.min(A,c.x),e=Math.min(e,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y);continue}let s,r,a,g;if("x"in o&&"y"in o&&(s=Number(o.x),r=Number(o.y)),"outer_diameter"in o&&(a=Number(o.outer_diameter),g=Number(o.outer_diameter)),"width"in o&&(a=Number(o.width)),"height"in o&&(g=Number(o.height)),"center"in o&&(s=o.center.x,r=o.center.y),s!==void 0&&r!==void 0)A=Math.min(A,s),e=Math.min(e,r),i=Math.max(i,s),n=Math.max(n,r),a!==void 0&&g!==void 0&&(A=Math.min(A,s-a/2),e=Math.min(e,r-g/2),i=Math.max(i,s+a/2),n=Math.max(n,r+g/2)),"radius"in o&&(A=Math.min(A,s-o.radius),e=Math.min(e,r-o.radius),i=Math.max(i,s+o.radius),n=Math.max(n,r+o.radius));else if(o.type==="pcb_trace")for(const c of o.route)A=Math.min(A,c.x),e=Math.min(e,c.y),i=Math.max(i,c.x),n=Math.max(n,c.y)}return{minX:A,minY:e,maxX:i,maxY:n}};function t8t(t){let A=0;if(t.length==0)return A;for(var e=0;e<t.length;e++){var i=t.charCodeAt(e);A=(A<<5)-A+i,A=A&A}return Math.abs(A)}var gce=[["#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"]],i8t=t=>{let{x:A,y:e,width:i,height:n}={...t,...t.size,...t.center,...t.position};if(t.x1!==void 0&&t.x2!==void 0&&t.y1!==void 0&&t.y2!==void 0&&(A=(t.x1+t.x2)/2,e=(t.y1+t.y2)/2,i=Math.abs(t.x1-t.x2),n=Math.abs(t.y1-t.y2)),t.points&&Array.isArray(t.points)&&t.points.length>0){const r=t.points.map(B=>B.x),a=t.points.map(B=>B.y),g=Math.min(...r),c=Math.max(...r),I=Math.min(...a),l=Math.max(...a);A=(g+c)/2,e=(I+l)/2,i=c-g,n=l-I}const o=t.text||t.name||t.source?.text||t.source?.name||"?",s=t;return A===void 0||e===void 0?null:(i===void 0&&"outer_diameter"in t&&(i=t.outer_diameter,n=t.outer_diameter),(i===void 0||n===void 0)&&(i=.1,n=.1),{x:A,y:e,width:i,height:n,title:o,content:s,bg_color:gce[t8t(t.type||o)%gce.length]?.[4]??"#f00"})},n8t=t=>!!t,o8t=t=>{const A=t.filter(g=>g.type.startsWith("pcb_")||g.type.startsWith("schematic_")).concat(t.filter(g=>g.type==="pcb_trace"||g.type==="schematic_trace").flatMap(g=>g.route)).map(g=>i8t(g)).filter(n8t);if(A.length===0)return{center:{x:0,y:0},width:0,height:0};let e=A[0].x-A[0].width/2,i=A[0].x+A[0].width/2,n=A[0].y-A[0].height/2,o=A[0].y+A[0].height/2;for(const g of A.slice(1))e=Math.min(e,g.x-g.width/2),i=Math.max(i,g.x+g.width/2),n=Math.min(n,g.y-g.height/2),o=Math.max(o,g.y+g.height/2);const s=i-e,r=o-n;return{center:{x:e+s/2,y:n+r/2},width:s,height:r}},vD={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"},M9=(t,A)=>{if(typeof window>"u")return A;try{const e=localStorage.getItem(t);return e!==null?JSON.parse(e):A}catch{return A}},N9=(t,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(A))}catch{}},s8t=(t,A)=>{if(typeof window>"u")return A;try{const e=localStorage.getItem(t);return e!==null?JSON.parse(e):A}catch{return A}},r8t=(t,A)=>{if(!(typeof window>"u"))try{localStorage.setItem(t,JSON.stringify(A))}catch{}},a8t="named_only",g8t=(t={},A=!1)=>gYA(e=>({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:M9(vD.IS_SHOWING_COPPER_POURS,!0),is_showing_pcb_groups:A?!1:M9(vD.IS_SHOWING_PCB_GROUPS,!0),is_showing_group_anchor_offsets:M9(vD.IS_SHOWING_GROUP_ANCHOR_OFFSETS,!0),is_showing_solder_mask:M9(vD.IS_SHOWING_SOLDER_MASK,!1),pcb_group_view_mode:A?"all":s8t(vD.PCB_GROUP_VIEW_MODE,a8t),hovered_error_id:null,...t,selectLayer:i=>e({selected_layer:i}),setEditMode:i=>e({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=>e({is_showing_rats_nest:i}),setIsMovingComponent:i=>e({is_moving_component:i}),setIsDrawingTrace:i=>e({is_drawing_trace:i}),setIsMouseOverContainer:i=>e({is_mouse_over_container:i}),setIsShowingMultipleTracesLength:i=>e({is_showing_multiple_traces_length:i}),setIsShowingAutorouting:i=>e({is_showing_autorouting:i}),setIsShowingDrcErrors:i=>e({is_showing_drc_errors:i}),setIsShowingCopperPours:i=>{N9(vD.IS_SHOWING_COPPER_POURS,i),e({is_showing_copper_pours:i})},setIsShowingPcbGroups:i=>{A||(N9(vD.IS_SHOWING_PCB_GROUPS,i),e({is_showing_pcb_groups:i}))},setIsShowingGroupAnchorOffsets:i=>{N9(vD.IS_SHOWING_GROUP_ANCHOR_OFFSETS,i),e({is_showing_group_anchor_offsets:i})},setIsShowingSolderMask:i=>{N9(vD.IS_SHOWING_SOLDER_MASK,i),e({is_showing_solder_mask:i})},setPcbGroupViewMode:i=>{A||(r8t(vD.PCB_GROUP_VIEW_MODE,i),e({pcb_group_view_mode:i}))},setHoveredErrorId:i=>e({hovered_error_id:i})})),XB=t=>{const A=V.useContext(cce);return dYA(A,t)},cce=V.createContext(null),c8t=({children:t,initialState:A,disablePcbGroups:e})=>{const i=V.useMemo(()=>g8t(A,e),[e]);return W.jsx(cce.Provider,{value:i,children:t})},I8t=()=>{const t=XB(e=>e.pcb_viewer_id),A=(e,i)=>Vg(e,{containerId:t,...i});return A.error=(e,i)=>Vg.error(e,{containerId:t,...i}),A.promise=Vg.promise,A},l8t=()=>{V.useEffect(()=>{Q3t()},[]);const t=XB(A=>A.pcb_viewer_id);return W.jsx(C3t,{position:"top-center",containerId:t})},B8t=function(){},Ice=typeof window<"u",C8t=Ice?V.useLayoutEffect:V.useEffect,Q8t=C8t,lce={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function h8t(){var t=V.useState(null),A=t[0],e=t[1],i=V.useState(lce),n=i[0],o=i[1],s=V.useMemo(function(){return new window.ResizeObserver(function(r){if(r[0]){var a=r[0].contentRect,g=a.x,c=a.y,I=a.width,l=a.height,B=a.top,C=a.left,Q=a.bottom,h=a.right;o({x:g,y:c,width:I,height:l,top:B,left:C,bottom:Q,right:h})}})},[]);return Q8t(function(){if(A)return s.observe(A),function(){s.disconnect()}},[A]),[e,n]}var EJ=Ice&&typeof window.ResizeObserver<"u"?h8t:function(){return[B8t,lce]},Bce=({initialTransform:t,initialTouch1:A,initialTouch2:e,finalTouch1:i,finalTouch2:n})=>{if(!i||!n)return t;const o={x:(A.x+e.x)/2,y:(A.y+e.y)/2},s={x:(i.x+n.x)/2,y:(i.y+n.y)/2},r=Math.hypot(e.x-A.x,e.y-A.y),a=Math.hypot(n.x-i.x,n.y-i.y),g=r===0?1:a/r,c=s.x-o.x,I=s.y-o.y;return zy(rB(c,I),rB(o.x,o.y),tJ(g,g),rB(-o.x,-o.y),t)},E8t=(t={})=>{const A=V.useRef(null),[e,i]=V.useState(0),n=t.canvasElm??A.current,[o,s]=V.useState(t.initialTransform??fb()),[r,a]=V.useState(0),[g,c]=V.useReducer(d=>d+1,0),I=V.useCallback(d=>{t.onSetTransform&&t.onSetTransform(d),t.transform||s(d)},[t.onSetTransform,s]),l=V.useCallback(d=>{I(d),c()},[I]),B=t.transform??o,C=V.useCallback(()=>{i(Date.now())},[]),Q=V.useRef("none"),h=V.useRef(null),E=V.useRef(null);V.useEffect(()=>{const d=t.canvasElm??A.current;if(d&&!n){a(r+1);return}if(!d){const Z=setTimeout(()=>{a(r+1)},100);return()=>clearTimeout(Z)}let p=t.transform??o,m={x:0,y:0},D={x:0,y:0},w=!1;const b=Z=>({x:Z.pageX-d.getBoundingClientRect().left-window.scrollX,y:Z.pageY-d.getBoundingClientRect().top-window.scrollY});function k(Z){t.enabled!==!1&&(t.shouldDrag&&!t.shouldDrag(Z)||(m=b(Z),!(Date.now()-e<100)&&(w=!0,Z.preventDefault())))}function x(Z){if(!w||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;D=b(Z);const $=zy(rB(D.x-m.x,D.y-m.y),p);I($),p=$,w=!1}function N(Z){if(b(Z),!w||t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;D=b(Z);const $=zy(rB(D.x-m.x,D.y-m.y),p);I($)}function M(Z){if(t.enabled===!1||t.shouldDrag&&!t.shouldDrag(Z))return;const $=b(Z),iA=zy(rB($.x,$.y),tJ(1-Z.deltaY/1e3,1-Z.deltaY/1e3),rB(-$.x,-$.y),p);I(iA),p=iA,Z.preventDefault()}function L(Z){if(!w||t.shouldDrag&&!t.shouldDrag(Z))return;if(d){const iA=d.getBoundingClientRect();if(Z.clientX>=iA.left+10&&Z.clientX<=iA.right-10&&Z.clientY>=iA.top+10&&Z.clientY<=iA.bottom-10)return}w=!1,D=b(Z);const $=zy(rB(D.x-m.x,D.y-m.y),p);I($),p=$}function Y(Z){if(Z.preventDefault(),t.enabled!==!1){if(Z.touches.length===1){Q.current="drag";const $=Z.touches[0];h.current={initialTransform:p,initialTouch:{x:$.clientX,y:$.clientY}}}else if(Z.touches.length===2){Q.current="pinch";const $=Z.touches[0],iA=Z.touches[1];E.current={initialTransform:p,initialTouch1:{x:$.clientX,y:$.clientY},initialTouch2:{x:iA.clientX,y:iA.clientY},finalTouch1:null,finalTouch2:null}}}}function H(Z){if(Z.preventDefault(),t.enabled!==!1){if(Q.current==="drag"&&Z.touches.length===1&&h.current){const $=Z.touches[0],iA={x:$.clientX,y:$.clientY},aA=iA.x-h.current.initialTouch.x,eA=iA.y-h.current.initialTouch.y,nA=zy(rB(aA,eA),h.current.initialTransform);I(nA)}else if(Q.current==="pinch"&&Z.touches.length===2&&E.current){const $=Z.touches[0],iA=Z.touches[1];E.current.finalTouch1={x:$.clientX,y:$.clientY},E.current.finalTouch2={x:iA.clientX,y:iA.clientY};const aA=Bce(E.current);I(aA)}}}function O(Z){Z.preventDefault();const $=Z.changedTouches[0];if(Q.current==="drag"&&h.current&&$){const iA={x:$.clientX,y:$.clientY},aA=iA.x-h.current.initialTouch.x,eA=iA.y-h.current.initialTouch.y,nA=zy(rB(aA,eA),h.current.initialTransform);I(nA),p=nA}else if(Q.current==="pinch"&&E.current){const iA=Bce(E.current);I(iA),p=iA}Q.current="none",h.current=null,E.current=null}return d.addEventListener("mousedown",k),d.addEventListener("mouseup",x),window.addEventListener("mousemove",N),d.addEventListener("mouseout",L),d.addEventListener("wheel",M),d.addEventListener("touchstart",Y,{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",L),d.removeEventListener("wheel",M),d.removeEventListener("touchstart",Y),d.removeEventListener("touchmove",H),d.removeEventListener("touchend",O),d.removeEventListener("touchcancel",O)}},[n,r,g,e,t.enabled,t.shouldDrag]);const u=V.useCallback(d=>qi(B,d),[B]);return{ref:A,transform:B,applyTransformToPoint:u,setTransform:l,cancelDrag:C}},u8t=E8t;function d8t(t){const A=new Map;let e=0;function i(n){for(const[,s]of A)if(s.has(n))return s;const o=new Set;return A.set(`connectivity_net${e++}`,o),o}for(const n of t){let o=null;for(const s of n){if(!o)o=i(s);else if(!o.has(s)){const r=i(s);if(r!==o){for(const a of r)o.add(a);A.delete(Array.from(A.entries()).find(([,a])=>a===r)[0])}}o.add(s)}}return Object.fromEntries(Array.from(A.entries()).map(([n,o])=>[n,Array.from(o)]))}var p8t=class{netMap;idToNetMap;constructor(t){this.netMap=t,this.idToNetMap={};for(const[A,e]of Object.entries(t))for(const i of e)this.idToNetMap[i]=A}addConnections(t){for(const A of t){const e=new Set;for(const n of A){const o=this.idToNetMap[n];o&&e.add(o)}let i;if(e.size===0)i=`connectivity_net${Object.keys(this.netMap).length}`,this.netMap[i]=[];else if(e.size===1)i=e.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;else{i=e.values().next().value??`connectivity_net${Object.keys(this.netMap).length}`;for(const n of e)if(n!==i){this.netMap[i].push(...this.netMap[n]),this.netMap[n]=this.netMap[i];for(const o of this.netMap[i])this.idToNetMap[o]=i}}for(const n of A)this.netMap[i].includes(n)||this.netMap[i].push(n),this.idToNetMap[n]=i}}getIdsConnectedToNet(t){return this.netMap[t]||[]}getNetConnectedToId(t){return this.idToNetMap[t]}areIdsConnected(t,A){if(t===A)return!0;const e=this.getNetConnectedToId(t);if(!e)return!1;const i=this.getNetConnectedToId(A);return i?e===i||i===t||i===t:!1}areAllIdsConnected(t){const A=this.getNetConnectedToId(t[0]);for(const e of t){const i=this.getNetConnectedToId(e);if(i===void 0||i!==A)return!1}return!0}},Cce=t=>{const A=[];for(const i of t)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:n,source_port_id:o}=i;o&&n&&A.push([o,n])}else if(i.type==="pcb_smtpad"){const{pcb_smtpad_id:n,pcb_port_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="pcb_plated_hole"){const{pcb_plated_hole_id:n,pcb_port_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="pcb_trace"){const{pcb_trace_id:n,source_trace_id:o}=i,s=Array.isArray(i.route)?i.route.filter(r=>r&&r.route_type==="wire"):[];if(o&&n&&A.push([n,o]),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&&n&&a&&A.push([r,n,a])}}else if(i.type==="pcb_via"){const{pcb_via_id:n,pcb_trace_id:o}=i;o&&n&&A.push([n,o])}else if(i.type==="source_component"&&i.internally_connected_source_port_ids)for(const n of i.internally_connected_source_port_ids)A.push(n);const e=d8t(A);return new p8t(e)};function f8t({primitivesWithoutInteractionMetadata:t,drawingObjectIdsWithMouseOver:A,primitiveIdsInMousedOverNet:e}){const i=[];for(const n of t){const o={...n};n?.layer==="drill"?(o.is_in_highlighted_net=!1,o.is_mouse_over=!1):A.has(n._pcb_drawing_object_id)?o.is_mouse_over=!0:n._element&&("pcb_trace_id"in n._element&&e.includes(n._element.pcb_trace_id)||"pcb_port_id"in n._element&&e.includes(n._element.pcb_port_id))?o.is_in_highlighted_net=!0:(o.is_in_highlighted_net=!1,o.is_mouse_over=!1),i.push(o)}return i}function y8t(t,A){if(t.length<2)throw new Error("Stroke must have at least two points");const e=t.map(I=>Array.isArray(I)?{x:I[0],y:I[1]}:I),i=[],n=[];function o(I,l){const B=l.x-I.x,C=l.y-I.y,Q=Math.sqrt(B*B+C*C);return{x:-C/Q,y:B/Q}}function s(I,l,B,C){const Q=C/2,h={x:I.x+l.x*Q*B,y:I.y+l.y*Q*B};B>0?i.push(h):n.unshift(h)}const r=o(e[0],e[1]),a=e[0].trace_width??A;s(e[0],r,1,a),s(e[0],r,-1,a);for(let I=1;I<e.length-1;I++){const l=e[I-1],B=e[I],C=e[I+1],Q=o(l,B),h=o(B,C),E=Q.x+h.x,u=Q.y+h.y,d=Math.sqrt(E*E+u*u),p=B.trace_width??A;if(d/2>2*(p/2))s(B,Q,1,p),s(B,h,1,p),s(B,Q,-1,p),s(B,h,-1,p);else{const D=1/d;s(B,{x:E*D,y:u*D},1,p),s(B,{x:E*D,y:u*D},-1,p)}}const g=o(e[e.length-2],e[e.length-1]),c=e[e.length-1].trace_width??A;return s(e[e.length-1],g,1,c),s(e[e.length-1],g,-1,c),[...i,...n]}var m8t=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s,rect_border_radius:r}=t,a=t.corner_radius??r??0,g=[{_pcb_drawing_object_id:Xy("rect"),pcb_drawing_type:"rect",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...t.shape==="rotated_rect"&&t.ccw_rotation!==void 0?{ccw_rotation:t.ccw_rotation}:{}}];if(t.is_covered_with_solder_mask){const c=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",l={...{_pcb_drawing_object_id:Xy("rect"),pcb_drawing_type:"rect",x:e,y:i,w:n,h:o,layer:c,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,roundness:a,...t.shape==="rotated_rect"&&t.ccw_rotation!==void 0?{ccw_rotation:t.ccw_rotation}:{}},..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};g.push(l)}return g},w8t=(t,A)=>{const{x:e,y:i,radius:n,layer:o}=t,s=[{_pcb_drawing_object_id:Xy("circle"),pcb_drawing_type:"circle",x:e,y:i,r:n,layer:o||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const r=o==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",a={_pcb_drawing_object_id:Xy("circle"),pcb_drawing_type:"circle",x:e,y:i,r:n,layer:r,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};s.push(a)}return s},D8t=(t,A)=>{const{layer:e,points:i}=t,n=[{_pcb_drawing_object_id:Xy("polygon"),pcb_drawing_type:"polygon",points:kfA(i),layer:e||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const o=e==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",s={_pcb_drawing_object_id:Xy("polygon"),pcb_drawing_type:"polygon",points:kfA(i),layer:o,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};n.push(s)}return n},S8t=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s}=t,r=[{_pcb_drawing_object_id:Xy("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port}];if(t.is_covered_with_solder_mask){const a=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",g={_pcb_drawing_object_id:Xy("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:a,_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,..."solder_mask_color"in t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};r.push(g)}return r},b8t=(t,A)=>{const{x:e,y:i,width:n,height:o,layer:s,ccw_rotation:r}=t,a=[{_pcb_drawing_object_id:Xy("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:s||"top",_element:t,_parent_pcb_component:A._parent_pcb_component,_parent_source_component:A._parent_source_component,_source_port:A._source_port,ccw_rotation:r}];if(t.is_covered_with_solder_mask){const g=s==="bottom"?"soldermask_with_copper_bottom":"soldermask_with_copper_top",c={_pcb_drawing_object_id:Xy("pill"),pcb_drawing_type:"pill",x:e,y:i,w:n,h:o,layer:g,_element:t,_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 t&&t.solder_mask_color?{color:t.solder_mask_color}:{}};a.push(c)}return a},x8t=(t,A)=>{const{_parent_pcb_component:e,_parent_source_component:i}=A,n=t,o=typeof n.font_size=="string"?ut.parse(n.font_size):n.font_size??.2;let s;return n.knockout_padding&&(s={left:typeof n.knockout_padding.left=="string"?ut.parse(n.knockout_padding.left):n.knockout_padding.left,top:typeof n.knockout_padding.top=="string"?ut.parse(n.knockout_padding.top):n.knockout_padding.top,bottom:typeof n.knockout_padding.bottom=="string"?ut.parse(n.knockout_padding.bottom):n.knockout_padding.bottom,right:typeof n.knockout_padding.right=="string"?ut.parse(n.knockout_padding.right):n.knockout_padding.right}),[{_pcb_drawing_object_id:Xy("text"),pcb_drawing_type:"text",x:n.anchor_position.x,y:n.anchor_position.y,layer:n.layer,align:n.anchor_alignment??"center",text:n.text,size:o,ccw_rotation:n.ccw_rotation,is_mirrored:n.is_mirrored,is_knockout:n.is_knockout,knockout_padding:s,_element:t,_parent_pcb_component:e,_parent_source_component:i}]},DI=0,Xy=t=>`${t}_${DI++}`,kfA=t=>(t??[]).map(A=>({x:ut.parse(A.x),y:ut.parse(A.y)})),_8t=(t,A)=>{const e="pcb_component_id"in t?A.find(s=>s.type==="pcb_component"&&s.pcb_component_id===t.pcb_component_id):void 0,i=e&&"source_component_id"in e?A.find(s=>s.type==="source_component"&&s.source_component_id===e.source_component_id):void 0,n="source_port_id"in t?t.source_port_id:"pcb_port_id"in t?wb(A).pcb_port.get(t.pcb_port_id)?.source_port_id:void 0,o=n?A.find(s=>s.type==="source_port"&&s.source_port_id===n):void 0;switch(t.type){case"pcb_smtpad":{const s={_parent_pcb_component:e,_parent_source_component:i,_source_port:o};return t.shape==="rect"||t.shape==="rotated_rect"?m8t(t,s):t.shape==="circle"?w8t(t,s):t.shape==="polygon"?D8t(t,s):t.shape==="pill"?S8t(t,s):t.shape==="rotated_pill"?b8t(t,s):[]}case"pcb_trace":{const s=[];if(t.route_thickness_mode==="interpolated"){const g=t.route.map(l=>({x:l.x,y:l.y,trace_width:l.route_type==="wire"?l.width:.5})),c=y8t(g,.5),I=t.route[0].layer;return s.push({_pcb_drawing_object_id:`polygon_${DI++}`,_element:t,pcb_drawing_type:"polygon",points:c,layer:I}),t.route.forEach(l=>{l.route_type==="via"&&s.push({_pcb_drawing_object_id:`circle_${DI++}`,_element:t,pcb_drawing_type:"circle",x:l.x,y:l.y,r:l.outer_diameter/2,layer:l.from_layer})}),s}let r=null,a=null;for(const g of t.route)g.route_type==="wire"&&(r!==null&&a!==null&&s.push({_pcb_drawing_object_id:`line_${DI++}`,_element:t,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}=t,c=t.from_layer,I=t.to_layer,l=t.layers,B=[];c&&I?B.push(c,I):l&&Array.isArray(l)?B.push(...l):B.push("top","bottom");const C=[];for(const Q of B)C.push({_pcb_drawing_object_id:`circle_${DI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:Q,_element:t,_parent_pcb_component:e,_parent_source_component:i});return C.push({_pcb_drawing_object_id:`circle_${DI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"drill",_element:t}),C}case"pcb_plated_hole":if(t.shape==="circle"){const{x:s,y:r,hole_diameter:a,outer_diameter:g}=t;return[{_pcb_drawing_object_id:`circle_${DI++}`,pcb_drawing_type:"circle",x:s,y:r,r:g/2,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`circle_${DI++}`,pcb_drawing_type:"circle",x:s,y:r,r:a/2,layer:"drill",_element:t}]}else if(t.shape==="oval"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=t;return[{_pcb_drawing_object_id:`oval_${DI++}`,pcb_drawing_type:"oval",x:s,y:r,rX:g/2,rY:a/2,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o},{_pcb_drawing_object_id:`oval_${DI++}`,_element:t,pcb_drawing_type:"oval",x:s,y:r,rX:I/2,rY:c/2,layer:"drill"}]}else if(t.shape==="pill"){const{x:s,y:r,outer_height:a,outer_width:g,hole_height:c,hole_width:I}=t;return[{_pcb_drawing_object_id:`pill_${DI++}`,pcb_drawing_type:"pill",x:s,y:r,w:g,h:a,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:t.ccw_rotation},{_pcb_drawing_object_id:`pill_${DI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:I,h:c,layer:"drill",ccw_rotation:t.ccw_rotation}]}else if(t.shape==="circular_hole_with_rect_pad"){const{x:s,y:r,hole_diameter:a,rect_pad_width:g,rect_pad_height:c,rect_border_radius:I,hole_offset_x:l,hole_offset_y:B}=t,C=ut.parse(l??0),Q=ut.parse(B??0);return[{_pcb_drawing_object_id:`rect_${DI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:I},{_pcb_drawing_object_id:`rect_${DI++}`,pcb_drawing_type:"rect",x:s,y:r,w:g,h:c,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:I},{_pcb_drawing_object_id:`circle_${DI++}`,_element:t,pcb_drawing_type:"circle",x:s+C,y:r+Q,r:a/2,layer:"drill"}]}else if(t.shape==="pill_hole_with_rect_pad"){const{x:s,y:r,hole_width:a,hole_height:g,rect_pad_width:c,rect_pad_height:I,rect_border_radius:l}=t;return[{_pcb_drawing_object_id:`rect_${DI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:l},{_pcb_drawing_object_id:`rect_${DI++}`,pcb_drawing_type:"rect",x:s,y:r,w:c,h:I,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,roundness:l},{_pcb_drawing_object_id:`pill_${DI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill"}]}else if(t.shape==="rotated_pill_hole_with_rect_pad"){const{x:s,y:r,hole_width:a,hole_height:g,hole_ccw_rotation:c,rect_pad_width:I,rect_pad_height:l,rect_ccw_rotation:B,rect_border_radius:C}=t;return[{_pcb_drawing_object_id:`rect_${DI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"top",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C},{_pcb_drawing_object_id:`rect_${DI++}`,pcb_drawing_type:"rect",x:s,y:r,w:I,h:l,layer:"bottom",_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o,ccw_rotation:B,roundness:C},{_pcb_drawing_object_id:`pill_${DI++}`,_element:t,pcb_drawing_type:"pill",x:s,y:r,w:a,h:g,layer:"drill",ccw_rotation:c}]}else if(t.shape==="hole_with_polygon_pad"){const{x:s,y:r,pad_outline:a,hole_shape:g,hole_diameter:c,hole_width:I,hole_height:l,layers:B,hole_offset_x:C,hole_offset_y:Q}=t,h=ut.parse(C??0),E=ut.parse(Q??0),u=a,d=[];if(u&&Array.isArray(u)){const D=kfA(u).map(w=>({x:w.x+s,y:w.y+r}));for(const w of B||["top","bottom"])d.push({_pcb_drawing_object_id:`polygon_${DI++}`,pcb_drawing_type:"polygon",points:D,layer:w,_element:t,_parent_pcb_component:e,_parent_source_component:i,_source_port:o})}const p={x:s+h,y:r+E},m=[];return g==="circle"?m.push({_pcb_drawing_object_id:`circle_${DI++}`,pcb_drawing_type:"circle",x:p.x,y:p.y,r:(c??0)/2,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i}):g==="oval"?m.push({_pcb_drawing_object_id:`oval_${DI++}`,pcb_drawing_type:"oval",x:p.x,y:p.y,rX:(I??0)/2,rY:(l??0)/2,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i}):(g==="pill"||g==="rotated_pill")&&m.push({_pcb_drawing_object_id:`pill_${DI++}`,pcb_drawing_type:"pill",x:p.x,y:p.y,w:I??0,h:l??0,layer:"drill",_element:t,_parent_pcb_component:e,_parent_source_component:i,ccw_rotation:t.ccw_rotation}),[...d,...m]}else return[];case"pcb_copper_text":return x8t(t,{_parent_pcb_component:e,_parent_source_component:i})}return[]},wn={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)"}},yf=(t,A=1)=>{if(Math.abs(t.a)!==Math.abs(t.d))throw new Error("Cannot scale non-uniformly");return A*Math.abs(t.a)},uc={elementOverlay:40,dimensionOverlay:40,editTraceHintOverlay:40,errorOverlay:40,pcbGroupOverlay:35,ratsNestOverlay:30,toolbarOverlay:70,warnings:30,topLayer:20,clickToInteractOverlay:100},v9={red:"red",black:"black",green:"green",board:"rgb(255, 255, 255)",other:"#eee",top:wn.board.copper.f,inner1:wn.board.copper.in1,inner2:wn.board.copper.in2,inner3:wn.board.copper.in3,inner4:wn.board.copper.in4,inner5:wn.board.copper.in5,inner6:wn.board.copper.in6,inner7:wn.board.copper.in7,inner8:wn.board.copper.in8,bottom:wn.board.copper.b,drill:wn.board.anchor,keepout:wn.board.background,tkeepout:wn.board.b_crtyd,tplace:wn.board.b_silks,top_silkscreen:wn.board.f_silks,bottom_silkscreen:wn.board.b_silks,top_fabrication:wn.board.f_fab,bottom_fabrication:wn.board.b_fab,soldermask_top:wn.board.soldermask.top,soldermask_bottom:wn.board.soldermask.bottom,soldermask_with_copper_top:wn.board.soldermaskWithCopper.top,soldermask_with_copper_bottom:wn.board.soldermaskWithCopper.bottom,bottom_notes:wn.board.user_2,top_notes:wn.board.user_2,...wn.board},k8t=["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"],F8t=class{canvasLayerMap;ctxLayerMap;aperture;transform;foregroundLayer="top";lastPoint;constructor(t){this.canvasLayerMap=t,this.ctxLayerMap=Object.fromEntries(Object.entries(t).map(([A,e])=>[A,e.getContext("2d")])),this.transform=fb(),this.transform.d*=-1,this.transform=zy(this.transform,rB(0,-500)),this.lastPoint={x:0,y:0},this.equip({})}clear(){for(const t of Object.values(this.ctxLayerMap))t.clearRect(0,0,t.canvas.width,t.canvas.height)}equip(t){this.aperture={fontSize:0,shape:"circle",mode:"add",size:0,color:"red",layer:"top",opacity:this.foregroundLayer===t.color?1:.5,...t}}drawMeshPattern(t,A,e,i,n,o=45){const s=this.getLayerCtx(),[r,a]=qi(this.transform,[t,A]),[g,c]=qi(this.transform,[t+e,A+i]),I=yf(this.transform,n);s.lineWidth=1,s.strokeStyle=this.aperture.color;const l=B=>{const C=Math.sin(B),Q=Math.cos(B),h=Math.sqrt((g-r)**2+(c-a)**2);for(let E=-h;E<=h;E+=I)s.beginPath(),s.moveTo(r+E*Q-h*C,a+E*C+h*Q),s.lineTo(r+E*Q+h*C,a+E*C-h*Q),s.stroke()};l(o*Math.PI/180),l((o+90)*Math.PI/180)}rect({x:t,y:A,w:e,h:i,mesh_fill:n,is_filled:o=!0,has_stroke:s,is_stroke_dashed:r,stroke_width:a,roundness:g}){const[c,I]=qi(this.transform,[t-e/2,A-i/2]),[l,B]=qi(this.transform,[t+e/2,A+i/2]);this.applyAperture();const C=this.getLayerCtx(),Q=g?yf(this.transform,g):0,h=s===void 0?o===!1:s;if(n)C.save(),C.beginPath(),Q>0&&C.roundRect?C.roundRect(c,I,l-c,B-I,Q):C.rect(c,I,l-c,B-I),C.clip(),this.drawMeshPattern(t-e/2,A-i/2,e,i,.15),C.restore(),Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.stroke()):C.strokeRect(c,I,l-c,B-I);else if(o!==!1&&(Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.fill()):C.fillRect(c,I,l-c,B-I)),h){const E=C.lineWidth;if(a!==void 0&&(C.lineWidth=yf(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)}Q>0&&C.roundRect?(C.beginPath(),C.roundRect(c,I,l-c,B-I,Q),C.stroke()):C.strokeRect(c,I,l-c,B-I),r&&C.setLineDash([]),a!==void 0&&(C.lineWidth=E)}}rotatedRect(t,A,e,i,n,o,s){const r=this.getLayerCtx();this.applyAperture();const[a,g]=qi(this.transform,[t-e/2,A-i/2]),[c,I]=qi(this.transform,[t+e/2,A+i/2]),l=o?yf(this.transform,o):0;r.save();const[B,C]=qi(this.transform,[t,A]);r.translate(B,C);const Q=360-n;n&&r.rotate(Q*Math.PI/180),r.translate(-B,-C),s?(r.beginPath(),l>0&&r.roundRect?r.roundRect(a,g,c-a,I-g,l):r.rect(a,g,c-a,I-g),r.clip(),this.drawMeshPattern(t-e/2,A-i/2,e,i,.15),l>0&&r.roundRect?(r.beginPath(),r.roundRect(a,g,c-a,I-g,l),r.stroke()):r.strokeRect(a,g,c-a,I-g)):l>0&&r.roundRect?(r.beginPath(),r.roundRect(a,g,c-a,I-g,l),r.fill()):r.fillRect(a,g,c-a,I-g),r.restore()}rotatedPill(t,A,e,i,n){const o=this.getLayerCtx();this.applyAperture(),o.save();const[s,r]=qi(this.transform,[t,A]);o.translate(s,r);const a=360-n;n&&o.rotate(a*Math.PI/180),o.translate(-s,-r),this.pill(t,A,e,i),o.restore()}circle(t,A,e,i){const n=yf(this.transform,e),[o,s]=qi(this.transform,[t,A]);this.applyAperture();const r=this.getLayerCtx();i?(r.save(),r.beginPath(),r.arc(o,s,n,0,2*Math.PI),r.clip(),this.drawMeshPattern(t-e,A-e,e*2,e*2,.15),r.restore(),r.beginPath(),r.arc(o,s,n,0,2*Math.PI),r.stroke()):(r.beginPath(),r.arc(o,s,n,0,2*Math.PI),r.fill())}oval(t,A,e,i){const n=yf(this.transform,e),o=yf(this.transform,i),[s,r]=qi(this.transform,[t,A]);this.applyAperture();const a=this.getLayerCtx();a.beginPath(),a.ellipse(s,r,n,o,0,0,2*Math.PI),a.fill(),a.closePath()}pill(t,A,e,i){const[n,o]=qi(this.transform,[t-e/2,A+i/2]),s=yf(this.transform,e),r=yf(this.transform,i),a=Math.min(s,r)/2;this.applyAperture();const g=this.getLayerCtx();g.beginPath(),g.arc(n+a,o+a,a,Math.PI,Math.PI*1.5),g.arc(n+s-a,o+a,a,Math.PI*1.5,0),g.arc(n+s-a,o+r-a,a,0,Math.PI*.5),g.arc(n+a,o+r-a,a,Math.PI*.5,Math.PI),g.fill(),g.closePath()}polygon(t){if(t.length<3)return;this.applyAperture();const A=this.getLayerCtx(),e=t.map(n=>qi(this.transform,[n.x,n.y]));A.beginPath(),A.moveTo(e[0][0],e[0][1]);for(let n=1;n<e.length;n++)A.lineTo(e[n][0],e[n][1]);A.closePath(),A.fill("evenodd");const i=yf(this.transform,this.aperture.size);i>0&&(A.lineWidth=i,A.stroke())}debugText(t,A,e){const[i,n]=qi(this.transform,[A,e]);this.applyAperture();const o=this.getLayerCtx();o.font="10px sans-serif",o.fillText(t,i,n)}getLayerCtx(){const t=this.ctxLayerMap[this.aperture.layer];if(!t)throw new Error(`No context for layer "${this.aperture.layer}"`);return t}orderAndFadeLayers(){const{canvasLayerMap:t,foregroundLayer:A}=this,e=A==="top"?"top_silkscreen":A==="bottom"?"bottom_silkscreen":void 0,i=A==="top"?"top_notes":A==="bottom"?"bottom_notes":void 0,n=A==="top"?"top_fabrication":A==="bottom"?"bottom_fabrication":void 0,o=A==="top"?"soldermask_with_copper_top":A==="bottom"?"soldermask_with_copper_bottom":void 0,s=new Set([A,"drill","edge_cuts","other","board",...e?[e]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[]]),r=[A,"edge_cuts",...e?[e]:[],...i?[i]:[],...n?[n]:[],...o?[o]:[]],a=[...k8t.filter(g=>!r.includes(g)),A,...o?[o]:[],"edge_cuts","drill",...e?[e]:[],...i?[i]:[],...n?[n]:[]];a.forEach((g,c)=>{const I=t[g];I&&(I.style.zIndex=`${uc.topLayer-(a.length-c)}`,I.style.opacity=s.has(g)?"1":"0.5")})}applyAperture(){const{transform:t,aperture:A}=this;let{size:e,mode:i,color:n,fontSize:o,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(n||(n="undefined"),r.lineWidth=yf(t,e),r.lineCap="round",i==="add"){r.globalCompositeOperation="source-over";let a=v9[n.toLowerCase()];if(!a)try{a=Ra(n).rgb().toString()}catch{console.warn(`Invalid color format: '${n}'`),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=`${yf(yb(t),o)}px sans-serif`}moveTo(t,A){this.lastPoint={x:t,y:A}}lineTo(t,A){const[e,i]=qi(this.transform,[t,A]),{size:n,shape:o,mode:s}=this.aperture,r=yf(this.transform,n),{lastPoint:a}=this,g=qi(this.transform,a);this.applyAperture();const c=this.getLayerCtx();o==="square"&&c.fillRect(g.x-r/2,g.y-r/2,r,r),c.beginPath(),c.moveTo(g.x,g.y),c.lineTo(e,i),c.stroke(),c.closePath(),o==="square"&&c.fillRect(e-r/2,i-r/2,r,r),this.lastPoint={x:t,y:A}}polygonWithArcs(t){const A=this.getLayerCtx(),e=i=>{if(i.vertices.length===0)return;const n=i.vertices[0],o=qi(this.transform,[n.x,n.y]);A.moveTo(o[0],o[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,c=a.x-r.x,I=a.y-r.y,l=Math.sqrt(c*c+I*I);if(l<1e-9){const M=qi(this.transform,[a.x,a.y]);A.lineTo(M[0],M[1]);continue}const B=4*Math.atan(g),C=Math.abs(l/(2*Math.sin(B/2))),Q=(r.x+a.x)/2,h=(r.y+a.y)/2,E=c/l,d=-(I/l),p=E,m=Math.sqrt(Math.max(0,C*C-(l/2)**2)),D=Q+m*d*Math.sign(g),w=h+m*p*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=yf(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(),e(t.outer_ring),t.inner_rings)for(const i of t.inner_rings)e(i);A.fill("evenodd")}};function G8t(t){return t.type==="pcb_copper_pour"}function L9({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=A.filter(G8t);if(n.length===0)return;const o=new NQ(t);o.realToCanvasMat=i,o.drawElements(n,{layers:e})}var R8t={...pf,silkscreen:{top:wn.board.f_fab,bottom:wn.board.b_fab}};function M8t(t){return t.type.includes("pcb_fabrication_note")}function Qce({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new NQ(t);n.configure({colorOverrides:R8t}),n.realToCanvasMat=i;const o=A.filter(M8t);n.drawElements(o,{layers:e})}function N8t(t){return t.type==="pcb_hole"}function v8t({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new NQ(t);o.realToCanvasMat=i;const s=A.filter(N8t);o.drawElements(s,{layers:e,drawSoldermask:n})}function L8t(t){return t.type==="pcb_board"}function U8t({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new NQ(t);o.realToCanvasMat=i;const s=A.filter(L8t);for(const r of s)o.drawElements([r],{layers:e,drawSoldermask:n})}function H8t(t){return t.type==="pcb_cutout"}function Y8t({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new NQ(t);n.realToCanvasMat=i;const o=A.filter(H8t);n.drawElements(o,{layers:e})}function J8t(t){return t.type==="pcb_keepout"}function T8t({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=A.filter(J8t);if(n.length===0)return;const o=new NQ(t);o.realToCanvasMat=i,o.drawElements(n,{layers:[]})}function K8t(t){return t.type.startsWith("pcb_note_")}function hce({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new NQ(t);n.realToCanvasMat=i;const o=A.filter(K8t);n.drawElements(o,{layers:e})}function P8t(t){return t.type==="pcb_panel"}function q8t({canvas:t,elements:A,layers:e,realToCanvasMat:i,drawSoldermask:n}){const o=new NQ(t);o.realToCanvasMat=i;const s=A.filter(P8t);for(const r of s)o.drawElements([r],{layers:e,drawSoldermask:n})}var O8t={...pf,copper:{...pf.copper,top:Ra(wn.board.pad_front).lighten(.5).toString(),bottom:Ra(wn.board.pad_back).lighten(.5).toString(),inner1:Ra(wn.board.copper.in1).lighten(.5).toString(),inner2:Ra(wn.board.copper.in2).lighten(.5).toString(),inner3:Ra(wn.board.copper.in3).lighten(.5).toString(),inner4:Ra(wn.board.copper.in4).lighten(.5).toString(),inner5:Ra(wn.board.copper.in5).lighten(.5).toString(),inner6:Ra(wn.board.copper.in6).lighten(.5).toString()}};function W8t(t){return t.type==="pcb_smtpad"}function Z8t({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(W8t).filter(c=>{const I=c.layer;return e.some(l=>l==="top_copper"&&I==="top"||l==="bottom_copper"&&I==="bottom"||l==="inner1_copper"&&I==="inner1"||l==="inner2_copper"&&I==="inner2"||l==="inner3_copper"&&I==="inner3"||l==="inner4_copper"&&I==="inner4"||l==="inner5_copper"&&I==="inner5"||l==="inner6_copper"&&I==="inner6")});if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_smtpad"&&r.add(c._element.pcb_smtpad_id);const a=s.filter(c=>r.has(c.pcb_smtpad_id)),g=s.filter(c=>!r.has(c.pcb_smtpad_id));if(g.length>0){const c=new NQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new NQ(t);c.configure({colorOverrides:O8t}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}var V8t={...pf,copper:{...pf.copper,top:Ra(wn.board.pad_front).lighten(.5).toString(),bottom:Ra(wn.board.pad_back).lighten(.5).toString(),inner1:Ra(wn.board.copper.in1).lighten(.5).toString(),inner2:Ra(wn.board.copper.in2).lighten(.5).toString(),inner3:Ra(wn.board.copper.in3).lighten(.5).toString(),inner4:Ra(wn.board.copper.in4).lighten(.5).toString(),inner5:Ra(wn.board.copper.in5).lighten(.5).toString(),inner6:Ra(wn.board.copper.in6).lighten(.5).toString()}};function j8t(t){return t.type==="pcb_trace"}var z8t=t=>t.map(A=>A.endsWith("_copper")?A.replace("_copper",""):A);function X8t({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n}){const o=new Set(z8t(e)),s=A.filter(j8t).filter(c=>c.route.some(I=>I.route_type==="wire"&&"layer"in I&&o.has(I.layer)));if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_trace"&&r.add(c._element.pcb_trace_id);const a=s.filter(c=>r.has(c.pcb_trace_id)),g=s.filter(c=>!r.has(c.pcb_trace_id));if(g.length>0){const c=new NQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e})}if(a.length>0){const c=new NQ(t);c.configure({colorOverrides:V8t}),c.realToCanvasMat=i,c.drawElements(a,{layers:e})}}var $8t={...pf,copper:{...pf.copper,top:Ra(wn.board.pad_front).lighten(.5).toString(),bottom:Ra(wn.board.pad_back).lighten(.5).toString()}};function AWt(t){return t.type==="pcb_plated_hole"}function Ece({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(AWt);if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_plated_hole"&&r.add(c._element.pcb_plated_hole_id);const a=s.filter(c=>r.has(c.pcb_plated_hole_id)),g=s.filter(c=>!r.has(c.pcb_plated_hole_id));if(g.length>0){const c=new NQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new NQ(t);c.configure({colorOverrides:$8t}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}function uce(t){const{lines:A,anchorPoint:e,ccwRotation:i}=t;if(!i)return A;const n=i*Math.PI/180,o=e3t(n),s=zy(rB(e.x,e.y),o,rB(-e.x,-e.y));return qi(s,e),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 eWt=.6,dce=.2,pce=t=>{const A=t.size*.7,e=A*eWt,i=A*dce,n=A*dce,o=t.text.split(/\r?\n/),s=t.text.length>0&&A>0,r=s?o.length:0,a=s?o.map(I=>I.length===0?0:I.length*e+(I.length-1)*i):[],g=a.length>0?Math.max(...a):0,c=r>0?r*A+(r-1)*n:0;return{text_lines:o,line_count:r,line_widths:a,target_height:A,target_width_char:e,space_between_chars:i,space_between_lines:n,width:g,height:c}},fce=t=>{const A=pce(t);return{width:A.width,height:A.height,lineHeight:A.target_height,lineSpacing:A.space_between_lines,lineCount:A.line_count}},yce=t=>{const{text_lines:A,line_count:e,line_widths:i,target_height:n,target_width_char:o,space_between_chars:s,space_between_lines:r,width:a}=pce(t);if(n<=0||e===0)return[];const g=n/12,c=[];for(let I=0;I<e;I++){const l=-I*(n+r),B=i[I],C=(a-B)/2;let Q=t.x+C;for(let h=0;h<A[I].length;h++){const E=A[I][h],u=aD[E]??aD[E.toUpperCase()];if(!u){Q+=o+s;continue}for(const{x1:d,y1:p,x2:m,y2:D}of u)c.push({_pcb_drawing_object_id:Xy("line"),pcb_drawing_type:"line",x1:Q+o*d,y1:t.y+l+n*p,x2:Q+o*m,y2:t.y+l+n*D,width:g,layer:t.layer,unit:t.unit,color:t.color});Q+=o+s}}return c};function LD(t){const e=t.color??v9[t.layer];let i=Ra(e);return t._element?.type==="pcb_copper_pour"&&(i=i.alpha(.7)),t.is_mouse_over||t.is_in_highlighted_net?i.lighten(.5).rgb().toString():i.rgb().toString()}var mce=(t,A)=>{t.equip({size:A.zoomIndependent?A.width/t.transform.a:A.width,shape:A.squareCap?"square":"circle",color:LD(A),layer:A.layer}),t.moveTo(A.x1,A.y1),t.lineTo(A.x2,A.y2)},tWt=(t,A,e)=>{switch(e){case"top_left":return{x:0,y:-A};case"top_center":return{x:-t/2,y:-A};case"top_right":return{x:-t,y:-A};case"center_left":return{x:0,y:-A/2};case"center":return{x:-t/2,y:-A/2};case"center_right":return{x:-t,y:-A/2};case"bottom_left":return{x:0,y:0};case"bottom_center":return{x:-t/2,y:0};case"bottom_right":return{x:-t,y:0};default:return{x:0,y:0}}},wce=t=>t.layer==="bottom_silkscreen"||t.layer==="bottom"?t.is_mirrored!==!1:t.is_mirrored===!0,iWt=(t,A)=>{t.equip({fontSize:A.size,color:LD(A),layer:A.layer});const{width:e,height:i}=fce(A),n=tWt(e,i,A.align);A.x??=0,A.y??=0;const o={x:A.x,y:A.y};let s=yce({...A,x:A.x+n.x,y:A.y+n.y});if(wce(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:o,ccwRotation:A.ccw_rotation};s=uce(r)}for(const r of s)mce(t,r)},nWt=(t,A)=>{const{width:e,height:i,lineHeight:n}=fce(A);A.x??=0,A.y??=0;const o=A.knockout_padding??{left:A.size*.5,right:A.size*.5,top:A.size*.3,bottom:A.size*.3},s=e+o.left+o.right,r=i+o.top+o.bottom,a=e/2,g=n-i/2,c=A.x-a,I=A.y-g,l={x:A.x,y:A.y},B={_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?Sce(t,B):Dce(t,B);let C=yce({...A,x:c,y:I});if(wce(A)&&(C=C.map(Q=>({...Q,x1:2*A.x-Q.x1,x2:2*A.x-Q.x2}))),A.ccw_rotation){const Q={lines:C,anchorPoint:l,ccwRotation:A.ccw_rotation};C=uce(Q)}for(const Q of C)t.equip({size:Q.width,shape:"circle",color:"black",layer:A.layer,mode:"subtract"}),t.moveTo(Q.x1,Q.y1),t.lineTo(Q.x2,Q.y2);t.equip({mode:"add"})},Dce=(t,A)=>{t.equip({color:LD(A),layer:A.layer,size:A.stroke_width}),t.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})},Sce=(t,A)=>{t.equip({color:LD(A),layer:A.layer}),t.rotatedRect(A.x,A.y,A.w,A.h,A.ccw_rotation,A.roundness,A.mesh_fill)},oWt=(t,A)=>{t.equip({color:LD(A),layer:A.layer}),t.rotatedPill(A.x,A.y,A.w,A.h,A.ccw_rotation)},sWt=(t,A)=>{t.equip({color:LD(A),layer:A.layer}),t.circle(A.x,A.y,A.r,A.mesh_fill)},rWt=(t,A)=>{t.equip({color:LD(A),layer:A.layer}),t.oval(A.x,A.y,A.rX,A.rY)},aWt=(t,A)=>{t.equip({color:LD(A),layer:A.layer}),t.pill(A.x,A.y,A.w,A.h)},gWt=(t,A)=>{t.equip({color:LD(A),layer:A.layer}),t.polygon(A.points)},cWt=(t,A)=>{t.equip({color:LD(A),layer:A.layer}),t.polygonWithArcs(A.brep_shape)},IWt=(t,A)=>{switch(A.pcb_drawing_type){case"line":return mce(t,A);case"text":return A.is_knockout?nWt(t,A):iWt(t,A);case"rect":return A.ccw_rotation?Sce(t,A):Dce(t,A);case"circle":return sWt(t,A);case"oval":return rWt(t,A);case"pill":return A.ccw_rotation?oWt(t,A):aWt(t,A);case"polygon":return gWt(t,A);case"polygon_with_arcs":return cWt(t,A)}},lWt=(t,A)=>{for(const e of A)IWt(t,e)},BWt={...pf,copper:{...pf.copper,top:Ra(wn.board.pad_front).lighten(.5).toString(),bottom:Ra(wn.board.pad_back).lighten(.5).toString(),inner1:Ra(wn.board.copper.in1).lighten(.5).toString(),inner2:Ra(wn.board.copper.in2).lighten(.5).toString(),inner3:Ra(wn.board.copper.in3).lighten(.5).toString(),inner4:Ra(wn.board.copper.in4).lighten(.5).toString(),inner5:Ra(wn.board.copper.in5).lighten(.5).toString(),inner6:Ra(wn.board.copper.in6).lighten(.5).toString()},soldermask:{...pf.soldermask,top:Ra(wn.board.soldermask.top).lighten(.35).toString(),bottom:Ra(wn.board.soldermask.bottom).lighten(.35).toString()}};function U9({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n}){const o=new NQ(t);if(o.realToCanvasMat=i,o.drawElements(A,{layers:e,drawSoldermask:!0}),!n)return;const s=new Set;for(const g of n){if(!(g.is_mouse_over||g.is_in_highlighted_net))continue;const c=g._element;c?.type==="pcb_smtpad"?s.add(c.pcb_smtpad_id):c?.type==="pcb_plated_hole"?s.add(c.pcb_plated_hole_id):c?.type==="pcb_via"&&s.add(c.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 NQ(t);a.configure({colorOverrides:BWt}),a.realToCanvasMat=i,a.drawElements(r,{layers:e,drawSoldermask:!0})}var CWt={...pf,silkscreen:{top:wn.board.f_silks,bottom:wn.board.b_silks}};function QWt(t){return t.type.includes("pcb_silkscreen")}function bce({canvas:t,elements:A,layers:e,realToCanvasMat:i}){const n=new NQ(t);n.configure({colorOverrides:CWt}),n.realToCanvasMat=i;const o=A.filter(QWt);n.drawElements(o,{layers:e})}var hWt={...pf,copper:{...pf.copper,top:Ra(wn.board.pad_front).lighten(.5).toString(),bottom:Ra(wn.board.pad_back).lighten(.5).toString()}};function EWt(t){return t.type==="pcb_via"}function xce({canvas:t,elements:A,layers:e,realToCanvasMat:i,primitives:n,drawSoldermask:o}){const s=A.filter(EWt).filter(c=>e.some(I=>I.includes("copper")));if(s.length===0)return;const r=new Set;if(n)for(const c of n)(c.is_mouse_over||c.is_in_highlighted_net)&&c._element?.type==="pcb_via"&&r.add(c._element.pcb_via_id);const a=s.filter(c=>r.has(c.pcb_via_id)),g=s.filter(c=>!r.has(c.pcb_via_id));if(g.length>0){const c=new NQ(t);c.realToCanvasMat=i,c.drawElements(g,{layers:e,drawSoldermask:o})}if(a.length>0){const c=new NQ(t);c.configure({colorOverrides:hWt}),c.realToCanvasMat=i,c.drawElements(a,{layers:e,drawSoldermask:o})}}var uWt=["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"],dWt=({primitives:t,elements:A,transform:e,grid:i,width:n=500,height:o=500})=>{const s=V.useRef({}),r=XB(g=>g.selected_layer),a=XB(g=>g.is_showing_solder_mask);return V.useEffect(()=>{if(!s.current||Object.keys(s.current).length===0)return;const g=Object.fromEntries(Object.entries(s.current).filter(([l,B])=>!(!B||!a&&l.includes("soldermask"))));if(Object.keys(g).length===0)return;const c=new F8t(g);e&&(c.transform=e),c.clear(),c.foregroundLayer=r;const I=t.filter(l=>a||!l.layer?.includes("soldermask")).filter(l=>l.layer!=="board").filter(l=>l._element?.type!=="pcb_smtpad").filter(l=>l._element?.type!=="pcb_plated_hole").filter(l=>l._element?.type!=="pcb_via").filter(l=>l._element?.type!=="pcb_trace");if(lWt(c,I),e){const l=s.current.top,B=s.current.bottom,C=s.current.inner1,Q=s.current.inner2,h=s.current.inner3,E=s.current.inner4,u=s.current.inner5,d=s.current.inner6;l&&Ece({canvas:l,elements:A,layers:["top_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),B&&Ece({canvas:B,elements:A,layers:["bottom_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),l&&L9({canvas:l,elements:A,layers:["top_copper"],realToCanvasMat:e}),B&&L9({canvas:B,elements:A,layers:["bottom_copper"],realToCanvasMat:e});const p=[{canvas:l,copperLayer:"top_copper"},{canvas:B,copperLayer:"bottom_copper"},{canvas:C,copperLayer:"inner1_copper"},{canvas:Q,copperLayer:"inner2_copper"},{canvas:h,copperLayer:"inner3_copper"},{canvas:E,copperLayer:"inner4_copper"},{canvas:u,copperLayer:"inner5_copper"},{canvas:d,copperLayer:"inner6_copper"}];for(const{canvas:H,copperLayer:O}of p)H&&X8t({canvas:H,elements:A,layers:[O],realToCanvasMat:e,primitives:t});for(const{canvas:H,copperLayer:O}of p)H&&(Z8t({canvas:H,elements:A,layers:[O],realToCanvasMat:e,primitives:t,drawSoldermask:a}),a&&U9({canvas:H,elements:A,layers:[O],realToCanvasMat:e,primitives:t}));if(l&&xce({canvas:l,elements:A,layers:["top_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),B&&xce({canvas:B,elements:A,layers:["bottom_copper"],realToCanvasMat:e,primitives:t,drawSoldermask:a}),a){const H=s.current.soldermask_top;H&&U9({canvas:H,elements:A,layers:["top_soldermask"],realToCanvasMat:e,primitives:t});const O=s.current.soldermask_bottom;O&&U9({canvas:O,elements:A,layers:["bottom_soldermask"],realToCanvasMat:e,primitives:t})}l&&L9({canvas:l,elements:A,layers:["top_copper"],realToCanvasMat:e}),B&&L9({canvas:B,elements:A,layers:["bottom_copper"],realToCanvasMat:e});const m=s.current.drill;m&&(v8t({canvas:m,elements:A,layers:["drill"],realToCanvasMat:e}),a&&U9({canvas:m,elements:A,layers:["drill"],realToCanvasMat:e,primitives:t}));const D=s.current.top_silkscreen;D&&bce({canvas:D,elements:A,layers:["top_silkscreen"],realToCanvasMat:e});const w=s.current.bottom_silkscreen;w&&bce({canvas:w,elements:A,layers:["bottom_silkscreen"],realToCanvasMat:e});const b=s.current.top_fabrication;b&&Qce({canvas:b,elements:A,layers:["top_fabrication_note"],realToCanvasMat:e});const k=s.current.bottom_fabrication;k&&Qce({canvas:k,elements:A,layers:["bottom_fabrication_note"],realToCanvasMat:e});const x=s.current.bottom_notes;x&&hce({canvas:x,elements:A,layers:["bottom_user_note"],realToCanvasMat:e});const N=s.current.top_notes;N&&hce({canvas:N,elements:A,layers:["top_user_note"],realToCanvasMat:e});const M=s.current.board;M&&(q8t({canvas:M,elements:A,layers:[],realToCanvasMat:e,drawSoldermask:a}),U8t({canvas:M,elements:A,layers:[],realToCanvasMat:e,drawSoldermask:a}));const L=s.current.edge_cuts;L&&Y8t({canvas:L,elements:A,layers:["edge_cuts"],realToCanvasMat:e});const Y=[{canvas:l,layer:"top"},{canvas:B,layer:"bottom"}];for(const{canvas:H,layer:O}of Y)H&&T8t({canvas:H,elements:A,layers:[O],realToCanvasMat:e})}c.orderAndFadeLayers()},[t,A,e,r,a]),W.jsxs("div",{style:{backgroundColor:"black",width:n,height:o,position:"relative"},children:[W.jsx(p9.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:n,height:o,transform:e,stringifyCoord:(g,c,I)=>`${p9.toMMSI(g,I)}, ${p9.toMMSI(c,I)}`}),uWt.filter(g=>a?!0:!g.includes("soldermask")).map(g=>g.replace(/-/g,"")).map((g,c)=>W.jsx("canvas",{className:`pcb-layer-${g}`,ref:I=>{s.current??={},I?s.current[g]=I:delete s.current[g]},style:{position:"absolute",zIndex:c,left:0,top:0,pointerEvents:"none"},width:n,height:o},g))]})},pWt=.6,fWt=1;Xge(L5t()),Xge($5t());var H9=["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 _ce(t,A,e,i={}){const n=i.padding??40,o=i.yFlip??!1;let s;if("center"in t){const c=t.width/2,I=t.height/2;s={minX:t.center.x-c,maxX:t.center.x+c,minY:t.center.y-I,maxY:t.center.y+I}}else s=t;const r=s.maxX-s.minX||1,a=s.maxY-s.minY||1,g=Math.min((A-2*n)/r,(e-2*n)/a);return zy(rB(A/2,e/2),tJ(g,o?-g:g),rB(-(s.minX+r/2),-(s.minY+a/2)))}function yWt(t){const A=[...t.points||[],...(t.lines||[]).flatMap(e=>e.points),...(t.rects||[]).flatMap(e=>{const i=e.width/2,n=e.height/2;return[{x:e.center.x-i,y:e.center.y-n},{x:e.center.x+i,y:e.center.y-n},{x:e.center.x-i,y:e.center.y+n},{x:e.center.x+i,y:e.center.y+n}]}),...(t.circles||[]).flatMap(e=>[{x:e.center.x-e.radius,y:e.center.y},{x:e.center.x+e.radius,y:e.center.y},{x:e.center.x,y:e.center.y-e.radius},{x:e.center.x,y:e.center.y+e.radius}]),...(t.texts||[]).flatMap(e=>{const i=e.fontSize??12,n=e.text.length*i*pWt,o=i*fWt,s=e.anchorSide??"center",r={top_left:{dx:0,dy:0},top_center:{dx:-n/2,dy:0},top_right:{dx:-n,dy:0},center_left:{dx:0,dy:-o/2},center:{dx:-n/2,dy:-o/2},center_right:{dx:-n,dy:-o/2},bottom_left:{dx:0,dy:-o},bottom_center:{dx:-n/2,dy:-o},bottom_right:{dx:-n,dy:-o}},{dx:a,dy:g}=r[s],c=e.x+a,I=e.y+g;return[{x:c,y:I},{x:c+n,y:I+o}]})];return A.length===0?{minX:-1,maxX:1,minY:-1,maxY:1}:A.reduce((e,i)=>({minX:Math.min(e.minX,i.x),maxX:Math.max(e.maxX,i.x),minY:Math.min(e.minY,i.y),maxY:Math.max(e.maxY,i.y)}),{minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0})}function mWt(t,A,e={}){const i=A instanceof HTMLCanvasElement?A.getContext("2d"):A;if(!i)throw new Error("Could not get 2D context from canvas");const n=A instanceof HTMLCanvasElement?A.width:A.canvas.width,o=A instanceof HTMLCanvasElement?A.height:A.canvas.height;let s;if(e.transform)s=e.transform;else if(e.viewbox)s=_ce(e.viewbox,n,o,{padding:e.padding,yFlip:e.yFlip});else{const r=yWt(t),a=t.coordinateSystem==="cartesian";s=_ce(r,n,o,{padding:e.padding??40,yFlip:a})}i.clearRect(0,0,n,o),i.save(),t.rects&&t.rects.length>0&&t.rects.forEach(r=>{const a=r.width/2,g=r.height/2,c=qi(s,{x:r.center.x-a,y:r.center.y-g}),I=qi(s,{x:r.center.x+a,y:r.center.y+g}),l=Math.abs(I.x-c.x),B=Math.abs(I.y-c.y);i.beginPath(),i.rect(Math.min(c.x,I.x),Math.min(c.y,I.y),l,B),r.fill&&(i.fillStyle=r.fill,i.fill()),r.stroke&&(i.strokeStyle=r.stroke,i.stroke())}),t.circles&&t.circles.length>0&&t.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())}),t.lines&&t.lines.length>0&&t.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 c=1;c<r.points.length;c++){const I=qi(s,r.points[c]);i.lineTo(I.x,I.y)}if(i.strokeStyle=r.strokeColor||H9[a%H9.length],r.strokeWidth?i.lineWidth=r.strokeWidth*s.a:i.lineWidth=2,i.lineCap="round",r.strokeDash)if(typeof r.strokeDash=="string"){let c;if(r.strokeDash.includes(","))c=r.strokeDash.split(",").map(I=>parseFloat(I.trim())).filter(I=>!Number.isNaN(I));else{const I=parseFloat(r.strokeDash.trim());c=Number.isNaN(I)?[]:[I]}i.setLineDash(c)}else i.setLineDash(r.strokeDash.map(c=>c*Math.abs(s.a)));else i.setLineDash([]);i.stroke()}),t.points&&t.points.length>0&&t.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||H9[a%H9.length],i.fill(),r.label&&!e.disableLabels&&(i.fillStyle=r.color||"black",i.font="12px sans-serif",i.fillText(r.label,g.x+5,g.y-5))}),t.texts&&t.texts.length>0&&t.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",c={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"},I={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=c[g],i.textBaseline=I[g],i.fillText(r.text,a.x,a.y)}),i.restore()}var wWt=({children:t,transform:A,debugGraphics:e})=>{const i=V.useRef(null),[n,{width:o,height:s}]=EJ(),r=XB(a=>a.is_showing_autorouting);return V.useEffect(()=>{r&&i.current&&e&&o&&s&&(i.current.width=o,i.current.height=s,mWt(e,i.current,{transform:A,disableLabels:!0}))},[e,A,o,s,r]),r?W.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:i,style:{position:"absolute",top:0,left:0,opacity:.5,zIndex:100,width:"100%",height:"100%",pointerEvents:"none"}})]}):t},DWt=({children:t,transform:A=fb(),elements:e=[]})=>{const[i,{width:n,height:o}]=EJ(),s=V.useRef(null);return V.useEffect(()=>{const r=s.current;if(!r||!n||!o)return;r.width=n,r.height=o;const a=r.getContext("2d");if(!a)return;a.clearRect(0,0,n,o);const g=e.filter(I=>I.type==="pcb_component"),c=e.filter(I=>I.type==="pcb_manual_edit_conflict_warning");a.strokeStyle=wn.board.drc_warning,a.lineWidth=2,c.forEach(I=>{const l=g.find(O=>O.pcb_component_id===I.pcb_component_id);if(!l)return;const{width:B,height:C,center:Q}=l,h=qi(A,Q),E=B*Math.abs(A.a),u=C*Math.abs(A.d),d=.1*Math.abs(A.a),p=E+d*2,m=u+d*2,D=h.x-p/2,w=h.y-m/2;a.beginPath(),a.rect(D,w,p,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,L=x+k*2,Y=D+(p-M)/2,H=w+m+5;a.fillStyle="rgba(0, 0, 0, 0.7)",a.beginPath(),a.roundRect(Y,H,M,L,3),a.fill(),a.fillStyle=wn.board.drc_warning,a.textAlign="center",a.textBaseline="middle",a.fillText(b,Y+M/2,H+L/2)})},[e,A,n,o]),W.jsxs("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:s,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:uc.warnings}})]})},Y9=(t,A,e)=>e(t,A),kce=(t,A,e,i,n)=>{const o=n*Math.PI/180,s=Math.cos(o),r=Math.sin(o),a=t-e,g=A-i,c=a*s-g*r,I=a*r+g*s;return{x:c+e,y:I+i}},uJ=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].x,i=t[0].y,n=t[0].y;for(const o of t)A=Y9(A,o.x,Math.min),e=Y9(e,o.x,Math.max),i=Y9(i,o.y,Math.min),n=Y9(n,o.y,Math.max);return{minX:A,maxX:e,minY:i,maxY:n}},SWt=(t,A)=>({minX:Math.min(t.minX,A.minX),maxX:Math.max(t.maxX,A.maxX),minY:Math.min(t.minY,A.minY),maxY:Math.max(t.maxY,A.maxY)}),bWt=(t,A)=>t?SWt(t,A):A,xWt=t=>{switch(t.pcb_drawing_type){case"line":{const A=(t.width??0)/2,e=[{x:t.x1,y:t.y1},{x:t.x2,y:t.y2}],i=uJ(e);return i?{minX:i.minX-A,maxX:i.maxX+A,minY:i.minY-A,maxY:i.maxY+A}:null}case"rect":{const A=t.w/2,e=t.h/2,i=[{x:t.x-A,y:t.y-e},{x:t.x+A,y:t.y-e},{x:t.x+A,y:t.y+e},{x:t.x-A,y:t.y+e}],n=t.ccw_rotation??0,o=n===0?i:i.map(s=>kce(s.x,s.y,t.x,t.y,n));return uJ(o)}case"circle":return{minX:t.x-t.r,maxX:t.x+t.r,minY:t.y-t.r,maxY:t.y+t.r};case"oval":return{minX:t.x-t.rX,maxX:t.x+t.rX,minY:t.y-t.rY,maxY:t.y+t.rY};case"pill":{const A=t.w/2,e=t.h/2,i=[{x:t.x-A,y:t.y-e},{x:t.x+A,y:t.y-e},{x:t.x+A,y:t.y+e},{x:t.x-A,y:t.y+e}],n=t.ccw_rotation??0,o=n===0?i:i.map(s=>kce(s.x,s.y,t.x,t.y,n));return uJ(o)}case"polygon":return uJ(t.points);case"polygon_with_arcs":{const A=t.brep_shape.outer_ring.vertices.map(e=>({x:e.x,y:e.y}));return uJ(A)}case"text":{const A=t.size??0,e=t.text?t.text.length*A*.6:0,i=A;if(e===0&&i===0)return{minX:t.x,maxX:t.x,minY:t.y,maxY:t.y};const n=e/2,o=i/2;return{minX:t.x-n,maxX:t.x+n,minY:t.y-o,maxY:t.y+o}}default:return null}};function _Wt(t){const{dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=t,r=e.x-A.x,a=e.y-A.y,g=Math.sqrt(r*r+a*a),c=n.x-i.x,I=n.y-i.y,l=Math.sqrt(c*c+I*I),B=Math.atan2(I,c)*(180/Math.PI),C=Math.abs(B)%90,h=Math.min(C,90-C)>15,E=(i.x+n.x)/2,u=(i.y+n.y)/2,d=15,p=B+90;let m=Math.cos(p*Math.PI/180)*d,D=Math.sin(p*Math.PI/180)*d;const w=c>0&&I<0,b=c>0&&I>0,k=c<0&&I>0;o!==s&&!w&&(m=-m,D=-D),w&&(m+=Math.cos(p*Math.PI/180)*-45,D+=Math.sin(p*Math.PI/180)*-45),b&&(m+=Math.cos(p*Math.PI/180)+-20,D+=Math.sin(p*Math.PI/180)+-10),k&&(m+=Math.cos(p*Math.PI/180)*10,D+=Math.sin(p*Math.PI/180)*10);const x=E+m,N=u+D;return{distance:g,screenDistance:l,x,y:N,show:g>.01&&l>30&&h}}function kWt(t){const{dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}=t;return V.useMemo(()=>_Wt({dimensionStart:A,dimensionEnd:e,screenDimensionStart:i,screenDimensionEnd:n,flipX:o,flipY:s}),[A,e,i,n,o,s])}var FWt=(t,A,e)=>{const i=e*Math.PI/180,n=Math.cos(i),o=Math.sin(i),s=t.x-A.x,r=t.y-A.y,a=s*n-r*o,g=s*o+r*n;return{x:a+A.x,y:g+A.y}},Fce=(t,A,e,i)=>{const n={top_left:{x:t.x-A,y:t.y-e},top_center:{x:t.x,y:t.y-e},top_right:{x:t.x+A,y:t.y-e},center_left:{x:t.x-A,y:t.y},center:{x:t.x,y:t.y},center_right:{x:t.x+A,y:t.y},bottom_left:{x:t.x-A,y:t.y+e},bottom_center:{x:t.x,y:t.y+e},bottom_right:{x:t.x+A,y:t.y+e}};return i===0?Object.entries(n).map(([o,s])=>({anchor:o,point:s})):Object.entries(n).map(([o,s])=>({anchor:o,point:FWt(s,t,i)}))},GWt=t=>{switch(t.pcb_drawing_type){case"rect":{const A=t.ccw_rotation??0;return Fce({x:t.x,y:t.y},t.w/2,t.h/2,A)}case"pill":{const A=t.ccw_rotation??0;return Fce({x:t.x,y:t.y},t.w/2,t.h/2,A)}case"circle":return[{anchor:"circle_center",point:{x:t.x,y:t.y}},{anchor:"circle_right",point:{x:t.x+t.r,y:t.y}},{anchor:"circle_left",point:{x:t.x-t.r,y:t.y}},{anchor:"circle_top",point:{x:t.x,y:t.y-t.r}},{anchor:"circle_bottom",point:{x:t.x,y:t.y+t.r}}];case"oval":return[{anchor:"oval_center",point:{x:t.x,y:t.y}},{anchor:"oval_right",point:{x:t.x+t.rX,y:t.y}},{anchor:"oval_left",point:{x:t.x-t.rX,y:t.y}},{anchor:"oval_top",point:{x:t.x,y:t.y-t.rY}},{anchor:"oval_bottom",point:{x:t.x,y:t.y+t.rY}}];case"line":{const A={x:(t.x1+t.x2)/2,y:(t.y1+t.y2)/2};return[{anchor:"line_start",point:{x:t.x1,y:t.y1}},{anchor:"line_mid",point:A},{anchor:"line_end",point:{x:t.x2,y:t.y2}}]}case"polygon":return t.points.map((A,e)=>({anchor:`polygon_vertex_${e}`,point:A}));case"polygon_with_arcs":return t.brep_shape.outer_ring.vertices.map((A,e)=>({anchor:`polygon_with_arcs_vertex_${e}`,point:{x:A.x,y:A.y}}));default:return[]}},RWt=16,SG=5,Gce=t=>{if(t.pcb_drawing_type==="text")return!0;const A=t._element;if(!A||typeof A!="object")return!1;const e=typeof A.type=="string"?A.type:void 0;return e?!!(e.startsWith("pcb_silkscreen_")||e.startsWith("pcb_note_")||e==="pcb_text"||e.startsWith("pcb_fabrication_note_")&&e!=="pcb_fabrication_note_rect"):!1},MWt=({children:t,transform:A,focusOnHover:e=!1,primitives:i=[]})=>{A||(A=fb());const[n,o]=V.useState(!1),[s,r]=V.useState(!1),[a,g]=V.useState(!1),[c,I]=V.useState({start:null,end:null}),l=XB(H=>H.is_mouse_over_container),B=V.useCallback(()=>{a&&(g(!1),window.dispatchEvent(new Event("disarm-dimension-tool")))},[a]),[C,Q]=V.useState({x:0,y:0}),[h,E]=V.useState({x:0,y:0}),u=V.useRef({x:0,y:0}),d=V.useRef(null),m=d.current?.getBoundingClientRect(),D=V.useMemo(()=>{const H=new Map;for(const O of i){if(!O._element||Gce(O)||O.pcb_drawing_type==="pill"||O.pcb_drawing_type==="rect"&&O.ccw_rotation&&O.ccw_rotation!==0)continue;const Z=xWt(O);if(!Z)continue;const $=H.get(O._element);H.set(O._element,bWt($??void 0,Z))}return H},[i]),w=V.useMemo(()=>{const H=[];for(const O of i){if(!O._element||Gce(O))continue;const Z=GWt(O);if(Z.length!==0)for(const $ of Z)H.push({anchor:$.anchor,point:$.point,element:O._element})}return H},[i]),b=V.useMemo(()=>{const H=[];D.forEach((O,Z)=>{if(!O)return;const $=(O.minX+O.maxX)/2,iA=(O.minY+O.maxY)/2,aA={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[eA,nA]of Object.entries(aA))H.push({anchor:eA,point:nA,element:Z})});for(const O of w)H.push(O);return H.push({anchor:"origin",point:{x:0,y:0},element:null}),H},[D,w]),k=V.useMemo(()=>b.map((H,O)=>({...H,id:`${O}-${H.anchor}`,screenPoint:qi(A,H.point)})),[b,A]),x=V.useCallback(H=>{if(k.length===0)return{point:H,id:null};const O=qi(A,H);let Z=null;for(const $ of k){const iA=$.screenPoint.x-O.x,aA=$.screenPoint.y-O.y,eA=Math.hypot(iA,aA);eA>RWt||(!Z||eA<Z.distance)&&(Z={distance:eA,id:$.id,point:$.point})}return Z?{point:Z.point,id:Z.id}:{point:H,id:null}},[k,A]);V.useEffect(()=>{const H=Z=>{const $=Z.target;if($.tagName==="INPUT"||$.tagName==="TEXTAREA"||$.isContentEditable)return;const iA=d.current?.contains(document.activeElement)||document.activeElement===d.current;if(!(!l&&!iA)){if(Z.key==="d"){const aA=x({x:u.current.x,y:u.current.y});Q({x:aA.point.x,y:aA.point.y}),E({x:aA.point.x,y:aA.point.y}),I({start:aA.id,end:aA.id}),n?(o(!1),r(!1),I({start:null,end:null})):(o(!0),r(!0)),B()}Z.key==="Escape"&&(o(!1),r(!1),I({start:null,end:null}),B())}},O=()=>{g(!0)};return window.addEventListener("keydown",H),window.addEventListener("arm-dimension-tool",O),()=>{window.removeEventListener("keydown",H),window.removeEventListener("arm-dimension-tool",O),B()}},[l,n,B,x]);const N=qi(A,C),M=qi(A,h),L={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};L.width=L.right-L.left,L.height=L.bottom-L.top;const Y=kWt({dimensionStart:C,dimensionEnd:h,screenDimensionStart:N,screenDimensionEnd:M,flipX:L.flipX,flipY:L.flipY});return W.jsxs("div",{ref:d,"data-pcb-viewer":!0,tabIndex:0,style:{position:"relative",outline:"none"},onMouseEnter:()=>{e&&d.current&&d.current.focus()},onMouseLeave:()=>{d.current&&d.current.blur()},onClick:()=>{d.current&&d.current.focus()},onMouseMove:H=>{const O=H.currentTarget.getBoundingClientRect(),Z=H.clientX-O.left,$=H.clientY-O.top,iA=qi(yb(A),{x:Z,y:$});if(u.current.x=iA.x,u.current.y=iA.y,s){const aA=x(iA);E({x:aA.point.x,y:aA.point.y}),I(eA=>({...eA,end:aA.id}))}},onMouseDown:H=>{const O=H.currentTarget.getBoundingClientRect(),Z=H.clientX-O.left,$=H.clientY-O.top,iA=qi(yb(A),{x:Z,y:$});if(a&&!n){const aA=x(iA);Q({x:aA.point.x,y:aA.point.y}),E({x:aA.point.x,y:aA.point.y}),I({start:aA.id,end:aA.id}),o(!0),r(!0),B()}else s?(r(!1),I(aA=>({...aA,end:null}))):n&&(o(!1),I({start:null,end:null}))},children:[t,n&&W.jsxs(W.Fragment,{children:[Y.show&&W.jsx("div",{style:{position:"absolute",left:Y.x,top:Y.y,color:"red",mixBlendMode:"difference",pointerEvents:"none",fontSize:12,fontFamily:"sans-serif",whiteSpace:"nowrap",zIndex:uc.dimensionOverlay},children:Y.distance.toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:L.left,width:L.width,textAlign:"center",top:N.y+2,color:"red",mixBlendMode:"difference",pointerEvents:"none",marginTop:L.flipY?0:-20,fontSize:12,fontFamily:"sans-serif",zIndex:uc.dimensionOverlay},children:Math.abs(C.x-h.x).toFixed(2)}),W.jsx("div",{style:{position:"absolute",left:M.x,height:L.height,display:"flex",flexDirection:"column",justifyContent:"center",top:L.top,color:"red",pointerEvents:"none",mixBlendMode:"difference",fontSize:12,fontFamily:"sans-serif",zIndex:uc.dimensionOverlay},children:W.jsx("div",{style:{marginLeft:L.flipX?"-100%":4,paddingRight:4},children:Math.abs(C.y-h.y).toFixed(2)})}),W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:uc.dimensionOverlay},width:m.width,height:m.height,children:[W.jsx("defs",{children:W.jsx("marker",{id:"head",orient:"auto",markerWidth:"3",markerHeight:"4",refX:"2",refY:"2",children:W.jsx("path",{d:"M0,0 V4 L2,2 Z",fill:"red"})})}),W.jsx("line",{x1:N.x,y1:N.y,x2:M.x,y2:M.y,markerEnd:"url(#head)",strokeWidth:1.5,fill:"none",stroke:"red"}),W.jsx("line",{x1:N.x,y1:N.y,x2:M.x,y2:N.y,strokeWidth:1.5,fill:"none",strokeDasharray:"2,2",stroke:"red"}),W.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===c.start||H.id===c.end,Z=SG/2;return W.jsxs("svg",{width:SG,height:SG,style:{position:"absolute",left:H.screenPoint.x-Z,top:H.screenPoint.y-Z,pointerEvents:"none",zIndex:uc.dimensionOverlay},children:[W.jsx("line",{x1:0,y1:0,x2:SG,y2:SG,stroke:O?"#66ccff":"white",strokeWidth:1}),W.jsx("line",{x1:SG,y1:0,x2:0,y2:SG,stroke:O?"#66ccff":"white",strokeWidth:1})]},H.id)}),W.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),")",W.jsx("br",{}),"(",h.x.toFixed(2),",",h.y.toFixed(2),")",W.jsx("br",{}),"dist:"," ",Math.sqrt((h.x-C.x)**2+(h.y-C.y)**2).toFixed(2)]})]})]})},NWt=(t,A,e=0)=>{const i=t.width/2,n=t.height/2,o=t.center.x-i-e,s=t.center.x+i+e,r=t.center.y-n-e,a=t.center.y+n+e;return A.x>o&&A.x<s&&A.y>r&&A.y<a},vWt=({children:t,disabled:A,transform:e,soup:i,cancelPanDrag:n,onCreateEditEvent:o,onModifyEditEvent:s})=>{e||(e=fb());const r=V.useRef(null),[a,g]=V.useState(null),[c,I]=V.useState(null),l=a!==null;XB(h=>h.in_edit_mode);const B=XB(h=>h.in_move_footprint_mode),C=XB(h=>h.setIsMovingComponent),Q=A||!B;return W.jsxs("div",{ref:r,style:{position:"relative",overflow:"hidden"},onMouseDown:h=>{if(Q)return;const E=h.currentTarget.getBoundingClientRect(),u=h.clientX-E.left,d=h.clientY-E.top;if(Number.isNaN(u)||Number.isNaN(d))return;const p=qi(yb(e),{x:u,y:d});let m=!1;for(const D of i)if(D.type==="pcb_component"&&NWt(D,p,10/e.a)){n(),g(D.pcb_component_id),m=!0;const w=Math.random().toString();I({dragStart:p,originalCenter:D.center,dragEnd:p,edit_event_id:w}),o({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 h.preventDefault(),!1},onMouseMove:h=>{if(!a||!c)return;const E=h.currentTarget.getBoundingClientRect(),u=h.clientX-E.left,d=h.clientY-E.top;if(Number.isNaN(u)||Number.isNaN(d))return;const p=qi(yb(e),{x:u,y:d});I({...c,dragEnd:p}),s({edit_event_id:c.edit_event_id,new_center:{x:c.originalCenter.x+p.x-c.dragStart.x,y:c.originalCenter.y+p.y-c.dragStart.y}})},onMouseUp:h=>{a&&(g(null),C(!1),c&&(s({edit_event_id:c.edit_event_id,in_progress:!1}),I(null)))},children:[t,!Q&&i.filter(h=>h.type==="pcb_component").map(h=>{if(!h?.center)return null;const E=qi(e,h.center);return W.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:E.x,top:E.y,width:h.width*e.a+20,height:h.height*e.a+20,transform:"translate(-50%, -50%)",background:l&&a===h.pcb_component_id?"rgba(255, 0, 0, 0.2)":""}},h.pcb_component_id)})]})},LWt=({hotkeys:t})=>(V.useEffect(()=>{const A=e=>{t.forEach(i=>{e.key===i.key&&i.onUse()})};return window.addEventListener("keydown",A),()=>{window.removeEventListener("keydown",A)}},[t]),W.jsx("div",{className:A1`
|
|
5434
5434
|
display: flex;
|
|
5435
5435
|
flex-direction: column;
|
|
5436
5436
|
font-family: sans-serif;
|
|
@@ -5469,7 +5469,7 @@ $1`).replace(/>(\s*)(?=<!--\s*\/)/g,"> ")}}});function rce(t,A,e){if(!A||!e)retu
|
|
|
5469
5469
|
transition: opacity 0.2s;
|
|
5470
5470
|
margin-bottom: 10px;
|
|
5471
5471
|
color: red;
|
|
5472
|
-
`,KWt=({children:t,transform:A=fb(),elements:e})=>{const i=V.useRef(null),{isShowingDRCErrors:n,hoveredErrorId:o}=XB(g=>({isShowingDRCErrors:g.is_showing_drc_errors,hoveredErrorId:g.hovered_error_id}));if(!e)return W.jsx("div",{style:{position:"relative"},ref:i,children:t});const s=e.filter(g=>g.type==="pcb_trace_error"),r=e.filter(g=>g.type==="pcb_trace_error"&&g.message?.includes("Multiple components found with name")),a=new Map;return e.forEach(g=>{g.type==="pcb_port"&&a.set(g.pcb_port_id,g)}),W.jsxs("div",{style:{position:"relative"},ref:i,children:[t,s.map((g,c)=>{const{pcb_port_ids:I,pcb_trace_id:l}=g,B=I?.[0]?a.get(I[0]):void 0,C=I?.[1]?a.get(I[1]):void 0,Q=e?wb(e).pcb_trace.get(l):void 0,h=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,E=o===h;if(B&&C){const u=qi(A,{x:B.x,y:B.y}),d=qi(A,{x:C.x,y:C.y}),p=!(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=FfA(m,i);return W.jsxs(V.Fragment,{children:[W.jsx(JWt,{screenPort1:u,screenPort2:d,errorCenter:m,canLineBeDrawn:p,isHighlighted:E}),W.jsx("div",{style:{position:"absolute",left:m.x-15,top:m.y-15,width:30,height:30,zIndex:uc.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(!E){const b=w.currentTarget.nextElementSibling;if(b){const k=b.querySelector(".error-message");k&&(k.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:E?200:100,left:D.left,top:D.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||E?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:D.transform},children:W.jsx("div",{className:`error-message ${GfA}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}if(Q?.route&&(n||E)){const u=Q.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),p=u[d],m=FfA(p,i);return W.jsxs(V.Fragment,{children:[W.jsx(TWt,{points:u,errorCenter:p,isHighlighted:E}),W.jsx("div",{style:{position:"absolute",left:p.x-15,top:p.y-15,width:30,height:30,zIndex:uc.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(!E){const w=D.currentTarget.nextElementSibling;if(w){const b=w.querySelector(".error-message");b&&(b.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:E?uc.errorOverlay+10:uc.errorOverlay+1,left:m.left,top:m.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:m.transform},children:W.jsx("div",{className:`error-message ${GfA}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}return null}),r.map((g,c)=>{const I=g.component_name||g.message?.match(/name "([^"]+)"/)?.[1];if(!I)return null;const l=e?.filter(Q=>Q.type==="source_component"&&Q.name===I||Q.type==="pcb_component"&&e?.find(h=>h.type==="source_component"&&h.source_component_id===Q.source_component_id&&h.name===I))||[],B=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,C=o===B;return!C&&!n?null:l.map((Q,h)=>{let E={x:0,y:0};if(Q.type==="pcb_component")E=Q.center||{x:0,y:0};else if(Q.type==="source_component"){const k=e?.find(x=>x.type==="pcb_component"&&x.source_component_id===Q.source_component_id);k&&k.type==="pcb_component"&&(E=k.center||{x:0,y:0})}const u=qi(A,E);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=FfA(u,i);return W.jsxs(V.Fragment,{children:[W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:uc.errorOverlay},width:"100%",height:"100%",children:C?W.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"}):W.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})}),W.jsx("div",{style:{position:"absolute",left:u.x-(w+10),top:u.y-(w+10),width:(w+10)*2,height:(w+10)*2,zIndex:uc.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")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:C?uc.errorOverlay+20:uc.errorOverlay+10,left:b.left,top:b.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:b.transform},children:W.jsx("div",{className:`error-message ${GfA}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:g.message})})]},`${B}_${h}`)})})]})};function PWt(t,A){return t.size!==A.size?!1:Array.from(t).every(e=>A.has(e))}function qWt({primitiveElement:t,elements:A}){let e=t.trace_length?`${t.trace_length.toFixed(3)}`:"";const i=wb(A).source_trace.get(t?.source_trace_id);if(i?.display_name&&(i?.max_length?e+=` / ${i.max_length}mm `:e+=" mm ",e+=`(${i.display_name})`),!e)return null;const n=t.trace_length&&i?.max_length&&t.trace_length>i.max_length;return{text:e,isOverLength:n}}function OWt(t){const{primitives:A,is_showing_multiple_traces_length:e,elements:i}=t,n=A.filter(a=>a._element.type==="pcb_trace"),o=i.filter(a=>a.type==="source_trace"),s=A.filter(a=>a._element.type!=="pcb_trace"),r=n.filter(a=>o.some(g=>a._element.type==="pcb_trace"&&a._element.source_trace_id===g.source_trace_id&&g.max_length!==void 0));if(!e)return[...s,...r];if(n.length>1){const a=n.reduce((g,c)=>{const I=g._element.trace_length;return c._element.trace_length<I?c:g},n[0]);return[...s,a]}return A}var WWt={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},ZWt=t=>{const{_element:A,_parent_pcb_component:e,_parent_source_component:i,_source_port:n}=t;switch(A.type){case"pcb_trace":return A.trace_length?`${A.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const o=[],s=Array.from(new Set((A.port_hints??[]).concat(n?.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?o.push(...s.map(a=>`${r}.${a}`)):o.push(...s):r&&o.push(r),o.join(", ")}default:return""}},VWt={top:"red",bottom:"aqua"},jWt=({primitive:t,mousePos:A,elements:e})=>{const[i,n]=V.useState(!1),o=t._element;V.useEffect(()=>{setTimeout(()=>{n(!0)},100)},[]);const[s,r,a,g]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],c=t.same_space_index??0,I=26,l=VWt[t?._element?.layer]??"red";let B=0;if(o.type==="pcb_smtpad"&&o?.shape==="rotated_rect"?B=o?.ccw_rotation??0:(o.type==="pcb_smtpad"&&(o?.shape==="pill"||o?.shape==="rotated_pill")&&"ccw_rotation"in t||o.type==="pcb_plated_hole"&&(o?.shape==="pill"||o?.shape==="oval")&&"ccw_rotation"in t)&&(B=o.ccw_rotation??0),o.type==="pcb_trace"){const h=qWt({primitiveElement:o,elements:e});if(!h)return null;const E=A.y-35;return W.jsx("div",{style:{zIndex:uc.elementOverlay,position:"absolute",left:A.x,top:E,color:l,pointerEvents:"none",transform:"translateX(-50%)"},children:W.jsx("div",{style:{backgroundColor:"#f2efcc",color:h.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:h.text})})}const C=ZWt(t);return C.trim().length===0?null:W.jsx("div",{style:{zIndex:uc.elementOverlay,position:"absolute",left:s-a/2-8,top:r-g/2-8,width:a+16,height:g+16,color:l,transform:`rotate(${-B}deg)`,transformOrigin:"center center"},children:W.jsx("div",{style:{width:i?`calc(100% + ${I*2*c}px)`:"100%",height:i?`calc(100% + ${I*2*c}px)`:"100%",marginLeft:i?`${-I*c}px`:0,marginTop:i?`${-I*c}px`:0,border:`1px solid ${l}`,opacity:i||c===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:W.jsx("div",{style:{position:"absolute",bottom:g+20+I*c,marginRight:i?`${-I*c}px`:0,marginBottom:i?0:-I*c,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(${B}deg)`,minWidth:"45px",textAlign:"center"},children:C})})})},zWt=({highlightedPrimitives:t,mousePos:A,elements:e})=>{const[i,n]=XB(r=>[r.is_moving_component,r.is_showing_multiple_traces_length]),o=t.some(r=>r._element.type==="pcb_smtpad")&&t.some(r=>r._element.type==="pcb_trace");let s=t;return o&&(s=s.filter(r=>r._element.type==="pcb_smtpad")),s=OWt({primitives:s,is_showing_multiple_traces_length:n,elements:e}),W.jsx("div",{style:WWt,children:!i&&s.map((r,a)=>W.jsx(jWt,{primitive:r,mousePos:A,elements:e},a))})},Z_=t=>t?.type==="pcb_component",Rce=t=>t?.type==="pcb_group",XWt=t=>t?.type==="pcb_panel",RfA=t=>t?.type==="pcb_board",Zc={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},v0={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},MfA=({targets:t,transform:A,containerWidth:e,containerHeight:i})=>{if(t.length===0)return null;const n={color:v0.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:Zc.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return t.forEach(s=>{if(!o.has(s.anchor_id)){const r=qi(A,s.anchor);o.set(s.anchor_id,r)}}),W.jsx("div",{style:{position:"absolute",left:0,top:0,width:e,height:i,overflow:"hidden",pointerEvents:"none",zIndex:uc.dimensionOverlay},children:W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:e,height:i,children:[t.map(s=>{const r=s.anchor,a=s.anchor_id,g=s.target,c=o.get(a),I=qi(A,g),l=g.x-r.x,B=g.y-r.y,C=Math.abs(I.x-c.x),Q=Math.abs(I.y-c.y),h=I.y<c.y,E=I.x>c.x,u=h?Zc.LABEL_OFFSET_ABOVE:Zc.LABEL_OFFSET_BELOW,d=E?Zc.LABEL_OFFSET_RIGHT:Zc.LABEL_OFFSET_LEFT,p=C>Zc.MIN_LINE_LENGTH_FOR_LABEL,m=Q>Zc.MIN_LINE_LENGTH_FOR_LABEL,D=`${s.display_offset_x??l.toFixed(2)}mm`,w=`${s.display_offset_y??B.toFixed(2)}mm`;return W.jsxs("g",{children:[W.jsx("line",{x1:c.x,y1:c.y,x2:I.x,y2:c.y,stroke:v0.OFFSET_LINE,strokeWidth:Zc.LINE_STROKE_WIDTH,strokeDasharray:Zc.LINE_DASH_PATTERN}),W.jsx("line",{x1:I.x,y1:c.y,x2:I.x,y2:I.y,stroke:v0.OFFSET_LINE,strokeWidth:Zc.LINE_STROKE_WIDTH,strokeDasharray:Zc.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?W.jsx("circle",{cx:I.x,cy:I.y,r:Zc.COMPONENT_MARKER_RADIUS,fill:v0.COMPONENT_MARKER_FILL,stroke:v0.COMPONENT_MARKER_STROKE,strokeWidth:1}):W.jsxs(W.Fragment,{children:[W.jsx("line",{x1:I.x-Zc.ANCHOR_MARKER_SIZE,y1:I.y,x2:I.x+Zc.ANCHOR_MARKER_SIZE,y2:I.y,stroke:v0.OFFSET_LINE,strokeWidth:Zc.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:I.x,y1:I.y-Zc.ANCHOR_MARKER_SIZE,x2:I.x,y2:I.y+Zc.ANCHOR_MARKER_SIZE,stroke:v0.OFFSET_LINE,strokeWidth:Zc.ANCHOR_MARKER_STROKE_WIDTH})]}),p&&W.jsx("foreignObject",{x:Math.min(c.x,I.x),y:c.y+u,width:Math.abs(I.x-c.x),height:20,style:{overflow:"visible"},children:W.jsx("div",{style:{...n,textAlign:"center"},children:D})}),m&&W.jsx("foreignObject",{x:I.x+d,y:Math.min(c.y,I.y),width:Zc.Y_LABEL_MIN_WIDTH,height:Math.abs(I.y-c.y),style:{overflow:"visible"},children:W.jsx("div",{style:{...n,display:"flex",alignItems:"center",justifyContent:E?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:w})})]},s.id)}),Array.from(o.entries()).map(([s,r])=>W.jsxs("g",{children:[W.jsx("line",{x1:r.x-Zc.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+Zc.ANCHOR_MARKER_SIZE,y2:r.y,stroke:v0.OFFSET_LINE,strokeWidth:Zc.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:r.x,y1:r.y-Zc.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+Zc.ANCHOR_MARKER_SIZE,stroke:v0.OFFSET_LINE,strokeWidth:Zc.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},$Wt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(E=>RfA(E)),s=t.filter(E=>Z_(E)),r=t.filter(E=>Rce(E)),a=A.map(E=>Z_(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Z_(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),g=new Set;if(a.forEach(E=>{const u=s.find(d=>d.pcb_component_id===E);u?.pcb_group_id&&g.add(u.pcb_group_id)}),!XB(E=>E.is_showing_group_anchor_offsets)&&a.length===0)return null;const I=s.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u)return null;const d=o.find(p=>p.pcb_board_id===u);return d?{component:E,board:d,type:"component"}:null}).filter(E=>!!E),l=r.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u||!E.center)return null;const d=o.find(p=>p.pcb_board_id===u);return d?{group:E,board:d,type:"group"}:null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=a.length===0,Q=B.filter(E=>E.type==="component"?C||a.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>E.type==="component"?{id:`${E.board.pcb_board_id}-${E.component.pcb_component_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:{id:`${E.board.pcb_board_id}-${E.group.pcb_group_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:{x:E.group.anchor_position?.x??E.group.center.x,y:E.group.anchor_position?.y??E.group.center.y},type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}).filter(E=>!!E);return W.jsx(MfA,{targets:h,transform:e,containerWidth:i,containerHeight:n})},AZt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(E=>Rce(E)),s=t.filter(E=>Z_(E)),r=A.map(E=>Z_(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Z_(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),a=(E,u)=>{if(u.has(E))return;u.add(E);const d=o.find(p=>p.pcb_group_id===E);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(E=>{const u=s.find(d=>d.pcb_component_id===E);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))}),!XB(E=>E.is_showing_group_anchor_offsets)&&r.length===0)return null;const I=s.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}if(E.pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}return null}).filter(E=>!!E),l=o.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);if(u&&u.anchor_position&&E.anchor_position)return{group:E,parentGroup:u,type:"group"}}return null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=r.length===0,Q=B.filter(E=>E.type==="component"?C||r.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id)||g.has(E.parentGroup.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>{const u=E.parentGroup.anchor_position;return u?E.type==="component"?E.component.center?{id:`${E.parentGroup.pcb_group_id}-${E.component.pcb_component_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:null:E.group.anchor_position?{id:`${E.parentGroup.pcb_group_id}-${E.group.pcb_group_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.group.anchor_position,type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}:null:null}).filter(E=>!!E);return W.jsx(MfA,{targets:h,transform:e,containerWidth:i,containerHeight:n})},eZt=(t,A)=>{const e=t.pcb_component_id,i=A.filter(n=>(n.type==="pcb_smtpad"||n.type==="pcb_plated_hole")&&n.pcb_component_id===e||n.type==="pcb_hole"&&n.pcb_component_id===e);return i.length===0?_fA([t]):_fA(i)},tZt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=new Map;for(const r of A)Z_(r._parent_pcb_component)&&o.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),Z_(r._element)&&o.set(r._element.pcb_component_id,r._element);if(o.size===0)return null;const s=[];for(const r of o.values()){const a=eZt(r,t);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,c=g?wb(t).pcb_group.get(g):null;s.push({component:r,bbox:a,group:c})}return s.length===0?null:W.jsx("div",{style:{position:"absolute",left:0,top:0,width:i,height:n,overflow:"hidden",pointerEvents:"none",zIndex:uc.dimensionOverlay},children:W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:i,height:n,children:s.map(({component:r,bbox:a,group:g})=>{const c=qi(e,{x:a.minX,y:a.maxY}),I=qi(e,{x:a.maxX,y:a.minY}),l={x:Math.min(c.x,I.x),y:Math.min(c.y,I.y),width:Math.abs(I.x-c.x),height:Math.abs(I.y-c.y)},B=r.center??{x:(a.minX+a.maxX)/2,y:(a.minY+a.maxY)/2},C=qi(e,B);return W.jsxs("g",{children:[W.jsx("rect",{x:l.x,y:l.y,width:l.width,height:l.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),W.jsx("line",{x1:C.x-6,y1:C.y,x2:C.x+6,y2:C.y,stroke:v0.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("line",{x1:C.x,y1:C.y-6,x2:C.x,y2:C.y+6,stroke:v0.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("circle",{cx:C.x,cy:C.y,r:Zc.COMPONENT_MARKER_RADIUS,fill:v0.COMPONENT_MARKER_FILL,stroke:v0.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},iZt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(B=>XWt(B)),s=t.filter(B=>RfA(B)),r=A.map(B=>RfA(B._element)?B._element.pcb_board_id:null).filter(B=>!!B);if(!XB(B=>B.is_showing_group_anchor_offsets)&&r.length===0)return null;const g=s.map(B=>{const C=B.pcb_panel_id,Q=B.position_mode;if(!C||Q!=="relative_to_panel_anchor")return null;const h=o.find(E=>E.pcb_panel_id===C);return h?{board:B,panel:h,type:"board"}:null}).filter(B=>!!B);if(g.length===0)return null;const c=r.length===0,I=g.filter(B=>c||r.includes(B.board.pcb_board_id));if(I.length===0)return null;const l=I.map(B=>B.board.center?{id:`${B.panel.pcb_panel_id}-${B.board.pcb_board_id}-${B.type}`,anchor:B.panel.center,anchor_id:B.panel.pcb_panel_id,target:B.board.center,type:"board",display_offset_x:B.board.display_offset_x,display_offset_y:B.board.display_offset_y}:null).filter(B=>!!B);return W.jsx(MfA,{targets:l,transform:e,containerWidth:i,containerHeight:n})},J9=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].y,i=t[0].x,n=t[0].y;for(const o of t)o.x<A&&(A=o.x),o.y<e&&(e=o.y),o.x>i&&(i=o.x),o.y>n&&(n=o.y);return{center:{x:(A+i)/2,y:(e+n)/2},width:i-A,height:n-e}},Mce=(t,A)=>{if(A.length<3)return!1;let e=!1;for(let i=0,n=A.length-1;i<A.length;n=i++){const o=A[i].x,s=A[i].y,r=A[n].x,a=A[n].y;s>t.y!=a>t.y&&t.x<(r-o)*(t.y-s)/(a-s||Number.EPSILON)+o&&(e=!e)}return e},nZt=(t,A,e)=>{const i=[];for(const n of t){if(!n._element)continue;if("x1"in n&&n._element?.type==="pcb_trace"){const r=uE({x:A.x,y:A.y},{x:n.x1,y:n.y1},{x:n.x2,y:n.y2}),a=n.width||.5,g=Math.max(a*25,2)/e.a;r<g&&i.push(n);continue}if(n.pcb_drawing_type==="polygon"){const r=n.points.map(g=>({x:ut.parse(g.x),y:ut.parse(g.y)})),a=J9(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;Mce(A,r)&&i.push(n);continue}if(n.pcb_drawing_type==="polygon_with_arcs"){const r=n.brep_shape.outer_ring.vertices.map(g=>({x:ut.parse(g.x),y:ut.parse(g.y)})),a=J9(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;Mce(A,r)&&i.push(n);continue}if(!("x"in n&&"y"in n))continue;let o=0,s=0;if("w"in n&&"h"in n)o=n.w,s=n.h;else if("r"in n)o=n.r*2,s=n.r*2;else if("rX"in n&&"rY"in n)o=n.rX*2,s=n.rY*2;else continue;Math.abs(n.x-A.x)<o/2&&Math.abs(n.y-A.y)<s/2&&i.push(n)}return i},oZt=({elements:t,children:A,transform:e,primitives:i,onMouseHoverOverPrimitives:n})=>{const[o,s]=V.useState([]),[r,a]=V.useState({x:0,y:0}),[g,{width:c,height:I}]=EJ(),l=V.useMemo(()=>{const C=[];for(const Q of o){if(Q._element?.type==="pcb_via"||Q._element?.type==="pcb_component"||Q?.layer==="drill")continue;let h=null,E=0,u=0;if(Q.pcb_drawing_type==="polygon"){const D=J9(Q.points);if(!D)continue;h=D.center,E=D.width,u=D.height}else if(Q.pcb_drawing_type==="polygon_with_arcs"){const D=Q.brep_shape.outer_ring.vertices.map(b=>({x:b.x,y:b.y})),w=J9(D);if(!w)continue;h=w.center,E=w.width,u=w.height}else"x"in Q&&"y"in Q&&(h={x:Q.x,y:Q.y},E="w"in Q?Q.w:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rX*2:0,u="h"in Q?Q.h:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rY*2:0);if(!h)continue;const d=qi(e,h),p={w:E*e.a,h:u*e.a},m=C.filter(D=>d.x===D.screen_x&&d.y===D.screen_y&&p.w===D.screen_w&&p.h===D.screen_h).length;C.push({...Q,x:h.x,y:h.y,w:E,h:u,screen_x:d.x,screen_y:d.y,screen_w:p.w,screen_h:p.h,same_space_index:m})}return C},[o,e]),B=(C,Q,h,E)=>{a({x:C,y:Q});const u=qi(yb(h),{x:C,y:Q}),d=nZt(E,u,h);PWt(new Set(d.map(p=>p._pcb_drawing_object_id)),new Set(o.map(p=>p._pcb_drawing_object_id)))||(s(d),n(d))};return W.jsxs("div",{ref:g,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:C=>{if(e){const Q=C.currentTarget.getBoundingClientRect(),h=C.clientX-Q.left,E=C.clientY-Q.top;B(h,E,e,i)}},onTouchStart:C=>{if(e){const Q=C.touches[0],h=C.currentTarget.getBoundingClientRect(),E=Q.clientX-h.left,u=Q.clientY-h.top;B(E,u,e,i)}},children:[A,W.jsx(zWt,{elements:t,mousePos:r,highlightedPrimitives:l}),e&&W.jsxs(W.Fragment,{children:[W.jsx($Wt,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(AZt,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(tZt,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(iZt,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I})]})]})},Nce=["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)"],sZt=({children:t,transform:A=fb(),elements:e=[],hoveredComponentIds:i=[]})=>{const[n,{width:o,height:s}]=EJ(),r=V.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:c}=XB(I=>({is_showing_pcb_groups:I.is_showing_pcb_groups,pcb_group_view_mode:I.pcb_group_view_mode,is_showing_group_anchor_offsets:I.is_showing_group_anchor_offsets}));return V.useEffect(()=>{const I=r.current;if(!I||!o||!s)return;I.width=o,I.height=s;const l=I.getContext("2d");if(!l||(l.clearRect(0,0,o,s),!a))return;const B=e.filter(D=>D.type==="pcb_group"),C=e.filter(D=>D.type==="pcb_component"),Q=e.filter(D=>D.type==="source_group"),h=new Map(Q.map(D=>[D.source_group_id,D])),E=B.filter(D=>{if(g==="all")return!0;if(!D.source_group_id)return!1;const w=h.get(D.source_group_id);return w?w.was_automatically_named!==!0:!1}),u=new Map;Q.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},p=D=>{const w=Q.find(b=>b.source_group_id===D);return w?.parent_source_group_id?1+p(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)}E.forEach((D,w)=>{let b=C.filter(HA=>HA.pcb_group_id===D.pcb_group_id);if(D.source_group_id){const HA=d(D.source_group_id),ZA=B.filter(kA=>kA.source_group_id&&HA.includes(kA.source_group_id));for(const kA of ZA){const wA=C.filter(UA=>UA.pcb_group_id===kA.pcb_group_id);b=[...b,...wA]}}let k,x,N,M,L=!1;if(D.center&&D.width&&D.height){L=!0;const HA=D.width/2,ZA=D.height/2;k=D.center.x-HA,N=D.center.x+HA,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(HA=>{if(HA.center&&typeof HA.width=="number"&&typeof HA.height=="number"){const ZA=HA.center.x-HA.width/2,kA=HA.center.x+HA.width/2,wA=HA.center.y+HA.height/2,UA=HA.center.y-HA.height/2;k=Math.min(k,ZA),N=Math.max(N,kA),x=Math.min(x,UA),M=Math.max(M,wA)}}),k===1/0||N===-1/0))return;const Y=D.source_group_id?p(D.source_group_id):0,H=D.source_group_id?d(D.source_group_id).length>0:!1;if(!L){const kA=1+(H?.5:0);k-=kA,N+=kA,x-=kA,M+=kA}const O=qi(A,{x:k,y:M}),Z=qi(A,{x:N,y:M}),$=qi(A,{x:k,y:x}),iA=qi(A,{x:N,y:x}),aA=Nce[w%Nce.length];l.strokeStyle=aA,l.lineWidth=2;const eA=Math.max(4,Math.min(12,8*Math.abs(A.a))),nA=Math.max(2,Math.min(6,4*Math.abs(A.a))),lA=eA*(H?1.3:1),pA=nA;l.setLineDash([lA,pA]),l.beginPath(),l.moveTo(O.x,O.y),l.lineTo(Z.x,Z.y),l.lineTo(iA.x,iA.y),l.lineTo($.x,$.y),l.closePath(),l.stroke();const xA=Math.max(8,Math.min(12,10*Math.abs(A.a))),RA=Y==0||Y==1?0:Y*.11,YA=xA*(1-RA),CA=4,_A=D.name||`Group ${w+1}`;l.font=`${YA}px sans-serif`,l.setLineDash([]);const KA=l.measureText(_A).width+CA*2,TA=YA+CA*2,ie=O.x-5,fA=O.y-5,Ae=3;if(l.fillStyle="rgba(0, 0, 0, 0.8)",l.beginPath(),l.roundRect(ie,fA-TA,KA,TA,Ae),l.fill(),l.fillStyle=aA,l.textAlign="left",l.textBaseline="middle",l.fillText(_A,ie+CA,fA-TA/2),c&&m.has(D.pcb_group_id)&&!!D.anchor_position&&D.anchor_position){const HA=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,HA);l.strokeStyle="white",l.lineWidth=1.5,l.setLineDash([]);const kA=Math.max(4,Math.min(8,6*Math.abs(A.a)));l.beginPath(),l.moveTo(ZA.x-kA,ZA.y),l.lineTo(ZA.x+kA,ZA.y),l.stroke(),l.beginPath(),l.moveTo(ZA.x,ZA.y-kA),l.lineTo(ZA.x,ZA.y+kA),l.stroke()}})},[e,A,o,s,a,g,c,i]),W.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:uc.pcbGroupOverlay,display:a?"block":"none"}})]})},rZt=({transform:t,soup:A,children:e})=>{const i=XB(r=>r.is_showing_rats_nest),{netMap:n,idToNetMap:o}=V.useMemo(()=>Cce(A||[]),[A]),s=V.useMemo(()=>{if(!A||!i)return[];const r=l=>{const B=wb(A)[l.replace(/_\d+$/,"")].get(l);return B&&"x"in B&&"y"in B?{x:B.x,y:B.y}:null},a=(l,B)=>{const C=n[B]||[];let Q=null,h=1/0;return C.forEach(E=>{const u=r(E);if(u){const d=Math.sqrt((l.x-u.x)**2+(l.y-u.y)**2);d<h&&d>0&&(h=d,Q=u)}}),Q},g=wb(A).pcb_port.list(),c=wb(A).source_trace.list(),I=[];return g.forEach((l,B)=>{const C=o[l.pcb_port_id];let Q=!1;for(const u of c)u.connected_source_port_ids.includes(l.source_port_id)&&u.connected_source_net_ids.length>0&&(Q=!0);if(!C)return;const h={x:l.x,y:l.y},E=a(h,C);E&&I.push({key:`${l.pcb_port_id}-${B}`,startPoint:h,endPoint:E,isInNet:Q})}),I},[A,n,o,i]);return!A||!i?e:(t||(t=fb()),W.jsxs("div",{style:{position:"relative"},children:[e,W.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:uc.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:c})=>{const I=qi(t,a),l=qi(t,g);return W.jsx("line",{x1:I.x,y1:I.y,x2:l.x,y2:l.y,stroke:"white",strokeWidth:"1",strokeDasharray:c?"6,6":void 0},r)})})]}))},aZt={version:"1.11.327"},V_=(t,A,e)=>{const i=XB(s=>s.is_mouse_over_container),n=V.useRef(i),o=V.useRef(A);V.useEffect(()=>{n.current=i},[i]),V.useEffect(()=>{o.current=A},[A]),V.useEffect(()=>{if(!t)return;const s=r=>{const a=r.target;if(a.tagName==="INPUT"||a.tagName==="TEXTAREA"||a.isContentEditable)return;const g=t.split("+"),c=g.includes("ctrl"),I=g.includes("shift"),l=g.includes("alt"),B=g.includes("meta"),C=g[g.length-1],Q=e?.current?e.current.contains(document.activeElement)||document.activeElement===e.current:!1;(n.current||Q)&&(!c||r.ctrlKey)&&(!I||r.shiftKey)&&(!l||r.altKey)&&(!B||r.metaKey)&&r.key.toLowerCase()===C.toLowerCase()&&(r.preventDefault(),o.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[t])},gZt=()=>{const[t,A]=V.useState(!1);return V.useEffect(()=>{const e=()=>{A(window.innerWidth<=768)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),t},cZt=({name:t,selected:A,onClick:e})=>W.jsxs("div",{className:A1`
|
|
5472
|
+
`,KWt=({children:t,transform:A=fb(),elements:e})=>{const i=V.useRef(null),{isShowingDRCErrors:n,hoveredErrorId:o}=XB(g=>({isShowingDRCErrors:g.is_showing_drc_errors,hoveredErrorId:g.hovered_error_id}));if(!e)return W.jsx("div",{style:{position:"relative"},ref:i,children:t});const s=e.filter(g=>g.type==="pcb_trace_error"),r=e.filter(g=>g.type==="pcb_trace_error"&&g.message?.includes("Multiple components found with name")),a=new Map;return e.forEach(g=>{g.type==="pcb_port"&&a.set(g.pcb_port_id,g)}),W.jsxs("div",{style:{position:"relative"},ref:i,children:[t,s.map((g,c)=>{const{pcb_port_ids:I,pcb_trace_id:l}=g,B=I?.[0]?a.get(I[0]):void 0,C=I?.[1]?a.get(I[1]):void 0,Q=e?wb(e).pcb_trace.get(l):void 0,h=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,E=o===h;if(B&&C){const u=qi(A,{x:B.x,y:B.y}),d=qi(A,{x:C.x,y:C.y}),p=!(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=FfA(m,i);return W.jsxs(V.Fragment,{children:[W.jsx(JWt,{screenPort1:u,screenPort2:d,errorCenter:m,canLineBeDrawn:p,isHighlighted:E}),W.jsx("div",{style:{position:"absolute",left:m.x-15,top:m.y-15,width:30,height:30,zIndex:uc.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(!E){const b=w.currentTarget.nextElementSibling;if(b){const k=b.querySelector(".error-message");k&&(k.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:E?200:100,left:D.left,top:D.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||E?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:D.transform},children:W.jsx("div",{className:`error-message ${GfA}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}if(Q?.route&&(n||E)){const u=Q.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),p=u[d],m=FfA(p,i);return W.jsxs(V.Fragment,{children:[W.jsx(TWt,{points:u,errorCenter:p,isHighlighted:E}),W.jsx("div",{style:{position:"absolute",left:p.x-15,top:p.y-15,width:30,height:30,zIndex:uc.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(!E){const w=D.currentTarget.nextElementSibling;if(w){const b=w.querySelector(".error-message");b&&(b.style.opacity="0")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:E?uc.errorOverlay+10:uc.errorOverlay+1,left:m.left,top:m.top,color:E?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:"flex",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:m.transform},children:W.jsx("div",{className:`error-message ${GfA}`,style:{opacity:E?1:0,border:`1px solid ${E?"#ff4444":"red"}`},children:g.message})})]},h)}return null}),r.map((g,c)=>{const I=g.component_name||g.message?.match(/name "([^"]+)"/)?.[1];if(!I)return null;const l=e?.filter(Q=>Q.type==="source_component"&&Q.name===I||Q.type==="pcb_component"&&e?.find(h=>h.type==="source_component"&&h.source_component_id===Q.source_component_id&&h.name===I))||[],B=g.pcb_trace_error_id||`error_${c}_${g.error_type}_${g.message?.slice(0,20)}`,C=o===B;return!C&&!n?null:l.map((Q,h)=>{let E={x:0,y:0};if(Q.type==="pcb_component")E=Q.center||{x:0,y:0};else if(Q.type==="source_component"){const k=e?.find(x=>x.type==="pcb_component"&&x.source_component_id===Q.source_component_id);k&&k.type==="pcb_component"&&(E=k.center||{x:0,y:0})}const u=qi(A,E);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=FfA(u,i);return W.jsxs(V.Fragment,{children:[W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none",mixBlendMode:"difference",zIndex:uc.errorOverlay},width:"100%",height:"100%",children:C?W.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"}):W.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})}),W.jsx("div",{style:{position:"absolute",left:u.x-(w+10),top:u.y-(w+10),width:(w+10)*2,height:(w+10)*2,zIndex:uc.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")}}}}),W.jsx("div",{style:{position:"absolute",zIndex:C?uc.errorOverlay+20:uc.errorOverlay+10,left:b.left,top:b.top,color:C?"#ff4444":"red",textAlign:"center",fontFamily:"sans-serif",fontSize:12,display:n||C?"flex":"none",flexDirection:"column",alignItems:"center",pointerEvents:"none",transform:b.transform},children:W.jsx("div",{className:`error-message ${GfA}`,style:{opacity:C?1:0,border:`1px solid ${C?"#ff4444":"red"}`},children:g.message})})]},`${B}_${h}`)})})]})};function PWt(t,A){return t.size!==A.size?!1:Array.from(t).every(e=>A.has(e))}function qWt({primitiveElement:t,elements:A}){let e=t.trace_length?`${t.trace_length.toFixed(3)}`:"";const i=wb(A).source_trace.get(t?.source_trace_id);if(i?.display_name&&(i?.max_length?e+=` / ${i.max_length}mm `:e+=" mm ",e+=`(${i.display_name})`),!e)return null;const n=t.trace_length&&i?.max_length&&t.trace_length>i.max_length;return{text:e,isOverLength:n}}function OWt(t){const{primitives:A,is_showing_multiple_traces_length:e,elements:i}=t,n=A.filter(a=>a._element.type==="pcb_trace"),o=i.filter(a=>a.type==="source_trace"),s=A.filter(a=>a._element.type!=="pcb_trace"),r=n.filter(a=>o.some(g=>a._element.type==="pcb_trace"&&a._element.source_trace_id===g.source_trace_id&&g.max_length!==void 0));if(!e)return[...s,...r];if(n.length>1){const a=n.reduce((g,c)=>{const I=g._element.trace_length;return c._element.trace_length<I?c:g},n[0]);return[...s,a]}return A}var WWt={position:"absolute",left:0,top:0,pointerEvents:"none",color:"red",fontFamily:"sans-serif",fontSize:12,textShadow:"0 0 2px black"},ZWt=t=>{const{_element:A,_parent_pcb_component:e,_parent_source_component:i,_source_port:n}=t;switch(A.type){case"pcb_trace":return A.trace_length?`${A.trace_length.toFixed(3)}`:"";case"pcb_smtpad":case"pcb_plated_hole":{const o=[],s=Array.from(new Set((A.port_hints??[]).concat(n?.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?o.push(...s.map(a=>`${r}.${a}`)):o.push(...s):r&&o.push(r),o.join(", ")}default:return""}},VWt={top:"red",bottom:"aqua"},jWt=({primitive:t,mousePos:A,elements:e})=>{const[i,n]=V.useState(!1),o=t._element;V.useEffect(()=>{setTimeout(()=>{n(!0)},100)},[]);const[s,r,a,g]=[t.screen_x,t.screen_y,t.screen_w,t.screen_h],c=t.same_space_index??0,I=26,l=VWt[t?._element?.layer]??"red";let B=0;if(o.type==="pcb_smtpad"&&o?.shape==="rotated_rect"?B=o?.ccw_rotation??0:(o.type==="pcb_smtpad"&&(o?.shape==="pill"||o?.shape==="rotated_pill")&&"ccw_rotation"in t||o.type==="pcb_plated_hole"&&(o?.shape==="pill"||o?.shape==="oval")&&"ccw_rotation"in t)&&(B=o.ccw_rotation??0),o.type==="pcb_trace"){const h=qWt({primitiveElement:o,elements:e});if(!h)return null;const E=A.y-35;return W.jsx("div",{style:{zIndex:uc.elementOverlay,position:"absolute",left:A.x,top:E,color:l,pointerEvents:"none",transform:"translateX(-50%)"},children:W.jsx("div",{style:{backgroundColor:"#f2efcc",color:h.isOverLength?"red":"black",textShadow:"none",WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"grayscale",padding:"6px 6px",borderRadius:"6px",fontSize:"14px",minWidth:"45px",textAlign:"center",whiteSpace:"nowrap"},children:h.text})})}const C=ZWt(t);return C.trim().length===0?null:W.jsx("div",{style:{zIndex:uc.elementOverlay,position:"absolute",left:s-a/2-8,top:r-g/2-8,width:a+16,height:g+16,color:l,transform:`rotate(${-B}deg)`,transformOrigin:"center center"},children:W.jsx("div",{style:{width:i?`calc(100% + ${I*2*c}px)`:"100%",height:i?`calc(100% + ${I*2*c}px)`:"100%",marginLeft:i?`${-I*c}px`:0,marginTop:i?`${-I*c}px`:0,border:`1px solid ${l}`,opacity:i||c===0?1:0,transition:"width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"},children:W.jsx("div",{style:{position:"absolute",bottom:g+20+I*c,marginRight:i?`${-I*c}px`:0,marginBottom:i?0:-I*c,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(${B}deg)`,minWidth:"45px",textAlign:"center"},children:C})})})},zWt=({highlightedPrimitives:t,mousePos:A,elements:e})=>{const[i,n]=XB(r=>[r.is_moving_component,r.is_showing_multiple_traces_length]),o=t.some(r=>r._element.type==="pcb_smtpad")&&t.some(r=>r._element.type==="pcb_trace");let s=t;return o&&(s=s.filter(r=>r._element.type==="pcb_smtpad")),s=OWt({primitives:s,is_showing_multiple_traces_length:n,elements:e}),W.jsx("div",{style:WWt,children:!i&&s.map((r,a)=>W.jsx(jWt,{primitive:r,mousePos:A,elements:e},a))})},Z_=t=>t?.type==="pcb_component",Rce=t=>t?.type==="pcb_group",XWt=t=>t?.type==="pcb_panel",RfA=t=>t?.type==="pcb_board",Zc={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},v0={OFFSET_LINE:"white",COMPONENT_MARKER_FILL:"#66ccff",COMPONENT_MARKER_STROKE:"white",LABEL_TEXT:"white"},MfA=({targets:t,transform:A,containerWidth:e,containerHeight:i})=>{if(t.length===0)return null;const n={color:v0.LABEL_TEXT,mixBlendMode:"difference",pointerEvents:"none",fontSize:Zc.LABEL_FONT_SIZE,fontFamily:"monospace",fontWeight:"bold"},o=new Map;return t.forEach(s=>{if(!o.has(s.anchor_id)){const r=qi(A,s.anchor);o.set(s.anchor_id,r)}}),W.jsx("div",{style:{position:"absolute",left:0,top:0,width:e,height:i,overflow:"hidden",pointerEvents:"none",zIndex:uc.dimensionOverlay},children:W.jsxs("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:e,height:i,children:[t.map(s=>{const r=s.anchor,a=s.anchor_id,g=s.target,c=o.get(a),I=qi(A,g),l=g.x-r.x,B=g.y-r.y,C=Math.abs(I.x-c.x),Q=Math.abs(I.y-c.y),h=I.y<c.y,E=I.x>c.x,u=h?Zc.LABEL_OFFSET_ABOVE:Zc.LABEL_OFFSET_BELOW,d=E?Zc.LABEL_OFFSET_RIGHT:Zc.LABEL_OFFSET_LEFT,p=C>Zc.MIN_LINE_LENGTH_FOR_LABEL,m=Q>Zc.MIN_LINE_LENGTH_FOR_LABEL,D=`${s.display_offset_x??l.toFixed(2)}mm`,w=`${s.display_offset_y??B.toFixed(2)}mm`;return W.jsxs("g",{children:[W.jsx("line",{x1:c.x,y1:c.y,x2:I.x,y2:c.y,stroke:v0.OFFSET_LINE,strokeWidth:Zc.LINE_STROKE_WIDTH,strokeDasharray:Zc.LINE_DASH_PATTERN}),W.jsx("line",{x1:I.x,y1:c.y,x2:I.x,y2:I.y,stroke:v0.OFFSET_LINE,strokeWidth:Zc.LINE_STROKE_WIDTH,strokeDasharray:Zc.LINE_DASH_PATTERN}),s.type==="component"||s.type==="board"?W.jsx("circle",{cx:I.x,cy:I.y,r:Zc.COMPONENT_MARKER_RADIUS,fill:v0.COMPONENT_MARKER_FILL,stroke:v0.COMPONENT_MARKER_STROKE,strokeWidth:1}):W.jsxs(W.Fragment,{children:[W.jsx("line",{x1:I.x-Zc.ANCHOR_MARKER_SIZE,y1:I.y,x2:I.x+Zc.ANCHOR_MARKER_SIZE,y2:I.y,stroke:v0.OFFSET_LINE,strokeWidth:Zc.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:I.x,y1:I.y-Zc.ANCHOR_MARKER_SIZE,x2:I.x,y2:I.y+Zc.ANCHOR_MARKER_SIZE,stroke:v0.OFFSET_LINE,strokeWidth:Zc.ANCHOR_MARKER_STROKE_WIDTH})]}),p&&W.jsx("foreignObject",{x:Math.min(c.x,I.x),y:c.y+u,width:Math.abs(I.x-c.x),height:20,style:{overflow:"visible"},children:W.jsx("div",{style:{...n,textAlign:"center"},children:D})}),m&&W.jsx("foreignObject",{x:I.x+d,y:Math.min(c.y,I.y),width:Zc.Y_LABEL_MIN_WIDTH,height:Math.abs(I.y-c.y),style:{overflow:"visible"},children:W.jsx("div",{style:{...n,display:"flex",alignItems:"center",justifyContent:E?"flex-start":"flex-end",whiteSpace:"nowrap",padding:"0 4px",height:"100%"},children:w})})]},s.id)}),Array.from(o.entries()).map(([s,r])=>W.jsxs("g",{children:[W.jsx("line",{x1:r.x-Zc.ANCHOR_MARKER_SIZE,y1:r.y,x2:r.x+Zc.ANCHOR_MARKER_SIZE,y2:r.y,stroke:v0.OFFSET_LINE,strokeWidth:Zc.ANCHOR_MARKER_STROKE_WIDTH}),W.jsx("line",{x1:r.x,y1:r.y-Zc.ANCHOR_MARKER_SIZE,x2:r.x,y2:r.y+Zc.ANCHOR_MARKER_SIZE,stroke:v0.OFFSET_LINE,strokeWidth:Zc.ANCHOR_MARKER_STROKE_WIDTH})]},`anchor-${s}`))]})})},$Wt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(E=>RfA(E)),s=t.filter(E=>Z_(E)),r=t.filter(E=>Rce(E)),a=A.map(E=>Z_(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Z_(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),g=new Set;if(a.forEach(E=>{const u=s.find(d=>d.pcb_component_id===E);u?.pcb_group_id&&g.add(u.pcb_group_id)}),!XB(E=>E.is_showing_group_anchor_offsets)&&a.length===0)return null;const I=s.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u)return null;const d=o.find(p=>p.pcb_board_id===u);return d?{component:E,board:d,type:"component"}:null}).filter(E=>!!E),l=r.map(E=>{const u=E.positioned_relative_to_pcb_board_id;if(!u||!E.center)return null;const d=o.find(p=>p.pcb_board_id===u);return d?{group:E,board:d,type:"group"}:null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=a.length===0,Q=B.filter(E=>E.type==="component"?C||a.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>E.type==="component"?{id:`${E.board.pcb_board_id}-${E.component.pcb_component_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:{id:`${E.board.pcb_board_id}-${E.group.pcb_group_id}-${E.type}`,anchor:E.board.center,anchor_id:E.board.pcb_board_id,target:{x:E.group.anchor_position?.x??E.group.center.x,y:E.group.anchor_position?.y??E.group.center.y},type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}).filter(E=>!!E);return W.jsx(MfA,{targets:h,transform:e,containerWidth:i,containerHeight:n})},AZt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(E=>Rce(E)),s=t.filter(E=>Z_(E)),r=A.map(E=>Z_(E._parent_pcb_component)?E._parent_pcb_component.pcb_component_id:Z_(E._element)?E._element.pcb_component_id:null).filter(E=>!!E),a=(E,u)=>{if(u.has(E))return;u.add(E);const d=o.find(p=>p.pcb_group_id===E);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(E=>{const u=s.find(d=>d.pcb_component_id===E);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))}),!XB(E=>E.is_showing_group_anchor_offsets)&&r.length===0)return null;const I=s.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}if(E.pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.pcb_group_id);return u&&u.anchor_position?{component:E,parentGroup:u,type:"component"}:null}return null}).filter(E=>!!E),l=o.map(E=>{if(E.position_mode==="relative_to_group_anchor"&&E.positioned_relative_to_pcb_group_id){const u=o.find(d=>d.pcb_group_id===E.positioned_relative_to_pcb_group_id);if(u&&u.anchor_position&&E.anchor_position)return{group:E,parentGroup:u,type:"group"}}return null}).filter(E=>!!E),B=[...I,...l];if(B.length===0)return null;const C=r.length===0,Q=B.filter(E=>E.type==="component"?C||r.includes(E.component.pcb_component_id):C||g.has(E.group.pcb_group_id)||g.has(E.parentGroup.pcb_group_id));if(Q.length===0)return null;const h=Q.map(E=>{const u=E.parentGroup.anchor_position;return u?E.type==="component"?E.component.center?{id:`${E.parentGroup.pcb_group_id}-${E.component.pcb_component_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.component.center,type:"component",display_offset_x:E.component.display_offset_x,display_offset_y:E.component.display_offset_y}:null:E.group.anchor_position?{id:`${E.parentGroup.pcb_group_id}-${E.group.pcb_group_id}-${E.type}`,anchor:u,anchor_id:E.parentGroup.pcb_group_id,target:E.group.anchor_position,type:"group",display_offset_x:E.group.display_offset_x,display_offset_y:E.group.display_offset_y}:null:null}).filter(E=>!!E);return W.jsx(MfA,{targets:h,transform:e,containerWidth:i,containerHeight:n})},eZt=(t,A)=>{const e=t.pcb_component_id,i=A.filter(n=>(n.type==="pcb_smtpad"||n.type==="pcb_plated_hole")&&n.pcb_component_id===e||n.type==="pcb_hole"&&n.pcb_component_id===e);return i.length===0?_fA([t]):_fA(i)},tZt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=new Map;for(const r of A)Z_(r._parent_pcb_component)&&o.set(r._parent_pcb_component.pcb_component_id,r._parent_pcb_component),Z_(r._element)&&o.set(r._element.pcb_component_id,r._element);if(o.size===0)return null;const s=[];for(const r of o.values()){const a=eZt(r,t);if(!a)continue;const g=r.positioned_relative_to_pcb_group_id??r.pcb_group_id,c=g?wb(t).pcb_group.get(g):null;s.push({component:r,bbox:a,group:c})}return s.length===0?null:W.jsx("div",{style:{position:"absolute",left:0,top:0,width:i,height:n,overflow:"hidden",pointerEvents:"none",zIndex:uc.dimensionOverlay},children:W.jsx("svg",{style:{position:"absolute",left:0,top:0,pointerEvents:"none"},width:i,height:n,children:s.map(({component:r,bbox:a,group:g})=>{const c=qi(e,{x:a.minX,y:a.maxY}),I=qi(e,{x:a.maxX,y:a.minY}),l={x:Math.min(c.x,I.x),y:Math.min(c.y,I.y),width:Math.abs(I.x-c.x),height:Math.abs(I.y-c.y)},B=r.center??{x:(a.minX+a.maxX)/2,y:(a.minY+a.maxY)/2},C=qi(e,B);return W.jsxs("g",{children:[W.jsx("rect",{x:l.x,y:l.y,width:l.width,height:l.height,fill:"none",stroke:"white",strokeWidth:1.5,strokeDasharray:"4,4"}),W.jsx("line",{x1:C.x-6,y1:C.y,x2:C.x+6,y2:C.y,stroke:v0.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("line",{x1:C.x,y1:C.y-6,x2:C.x,y2:C.y+6,stroke:v0.COMPONENT_MARKER_STROKE,strokeWidth:1.5}),W.jsx("circle",{cx:C.x,cy:C.y,r:Zc.COMPONENT_MARKER_RADIUS,fill:v0.COMPONENT_MARKER_FILL,stroke:v0.COMPONENT_MARKER_STROKE,strokeWidth:1})]},r.pcb_component_id)})})})},iZt=({elements:t,highlightedPrimitives:A,transform:e,containerWidth:i,containerHeight:n})=>{const o=t.filter(B=>XWt(B)),s=t.filter(B=>RfA(B)),r=A.map(B=>RfA(B._element)?B._element.pcb_board_id:null).filter(B=>!!B);if(!XB(B=>B.is_showing_group_anchor_offsets)&&r.length===0)return null;const g=s.map(B=>{const C=B.pcb_panel_id,Q=B.position_mode;if(!C||Q!=="relative_to_panel_anchor")return null;const h=o.find(E=>E.pcb_panel_id===C);return h?{board:B,panel:h,type:"board"}:null}).filter(B=>!!B);if(g.length===0)return null;const c=r.length===0,I=g.filter(B=>c||r.includes(B.board.pcb_board_id));if(I.length===0)return null;const l=I.map(B=>B.board.center?{id:`${B.panel.pcb_panel_id}-${B.board.pcb_board_id}-${B.type}`,anchor:B.panel.center,anchor_id:B.panel.pcb_panel_id,target:B.board.center,type:"board",display_offset_x:B.board.display_offset_x,display_offset_y:B.board.display_offset_y}:null).filter(B=>!!B);return W.jsx(MfA,{targets:l,transform:e,containerWidth:i,containerHeight:n})},J9=t=>{if(t.length===0)return null;let A=t[0].x,e=t[0].y,i=t[0].x,n=t[0].y;for(const o of t)o.x<A&&(A=o.x),o.y<e&&(e=o.y),o.x>i&&(i=o.x),o.y>n&&(n=o.y);return{center:{x:(A+i)/2,y:(e+n)/2},width:i-A,height:n-e}},Mce=(t,A)=>{if(A.length<3)return!1;let e=!1;for(let i=0,n=A.length-1;i<A.length;n=i++){const o=A[i].x,s=A[i].y,r=A[n].x,a=A[n].y;s>t.y!=a>t.y&&t.x<(r-o)*(t.y-s)/(a-s||Number.EPSILON)+o&&(e=!e)}return e},nZt=(t,A,e)=>{const i=[];for(const n of t){if(!n._element)continue;if("x1"in n&&n._element?.type==="pcb_trace"){const r=uE({x:A.x,y:A.y},{x:n.x1,y:n.y1},{x:n.x2,y:n.y2}),a=n.width||.5,g=Math.max(a*25,2)/e.a;r<g&&i.push(n);continue}if(n.pcb_drawing_type==="polygon"){const r=n.points.map(g=>({x:ut.parse(g.x),y:ut.parse(g.y)})),a=J9(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;Mce(A,r)&&i.push(n);continue}if(n.pcb_drawing_type==="polygon_with_arcs"){const r=n.brep_shape.outer_ring.vertices.map(g=>({x:ut.parse(g.x),y:ut.parse(g.y)})),a=J9(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;Mce(A,r)&&i.push(n);continue}if(!("x"in n&&"y"in n))continue;let o=0,s=0;if("w"in n&&"h"in n)o=n.w,s=n.h;else if("r"in n)o=n.r*2,s=n.r*2;else if("rX"in n&&"rY"in n)o=n.rX*2,s=n.rY*2;else continue;Math.abs(n.x-A.x)<o/2&&Math.abs(n.y-A.y)<s/2&&i.push(n)}return i},oZt=({elements:t,children:A,transform:e,primitives:i,onMouseHoverOverPrimitives:n})=>{const[o,s]=V.useState([]),[r,a]=V.useState({x:0,y:0}),[g,{width:c,height:I}]=EJ(),l=V.useMemo(()=>{const C=[];for(const Q of o){if(Q._element?.type==="pcb_via"||Q._element?.type==="pcb_component"||Q?.layer==="drill")continue;let h=null,E=0,u=0;if(Q.pcb_drawing_type==="polygon"){const D=J9(Q.points);if(!D)continue;h=D.center,E=D.width,u=D.height}else if(Q.pcb_drawing_type==="polygon_with_arcs"){const D=Q.brep_shape.outer_ring.vertices.map(b=>({x:b.x,y:b.y})),w=J9(D);if(!w)continue;h=w.center,E=w.width,u=w.height}else"x"in Q&&"y"in Q&&(h={x:Q.x,y:Q.y},E="w"in Q?Q.w:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rX*2:0,u="h"in Q?Q.h:"r"in Q?Q.r*2:"rX"in Q&&"rY"in Q?Q.rY*2:0);if(!h)continue;const d=qi(e,h),p={w:E*e.a,h:u*e.a},m=C.filter(D=>d.x===D.screen_x&&d.y===D.screen_y&&p.w===D.screen_w&&p.h===D.screen_h).length;C.push({...Q,x:h.x,y:h.y,w:E,h:u,screen_x:d.x,screen_y:d.y,screen_w:p.w,screen_h:p.h,same_space_index:m})}return C},[o,e]),B=(C,Q,h,E)=>{a({x:C,y:Q});const u=qi(yb(h),{x:C,y:Q}),d=nZt(E,u,h);PWt(new Set(d.map(p=>p._pcb_drawing_object_id)),new Set(o.map(p=>p._pcb_drawing_object_id)))||(s(d),n(d))};return W.jsxs("div",{ref:g,style:{position:"relative",width:"100%",height:"100%"},onMouseMove:C=>{if(e){const Q=C.currentTarget.getBoundingClientRect(),h=C.clientX-Q.left,E=C.clientY-Q.top;B(h,E,e,i)}},onTouchStart:C=>{if(e){const Q=C.touches[0],h=C.currentTarget.getBoundingClientRect(),E=Q.clientX-h.left,u=Q.clientY-h.top;B(E,u,e,i)}},children:[A,W.jsx(zWt,{elements:t,mousePos:r,highlightedPrimitives:l}),e&&W.jsxs(W.Fragment,{children:[W.jsx($Wt,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(AZt,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(tZt,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I}),W.jsx(iZt,{elements:t,highlightedPrimitives:l,transform:e,containerWidth:c,containerHeight:I})]})]})},Nce=["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)"],sZt=({children:t,transform:A=fb(),elements:e=[],hoveredComponentIds:i=[]})=>{const[n,{width:o,height:s}]=EJ(),r=V.useRef(null),{is_showing_pcb_groups:a,pcb_group_view_mode:g,is_showing_group_anchor_offsets:c}=XB(I=>({is_showing_pcb_groups:I.is_showing_pcb_groups,pcb_group_view_mode:I.pcb_group_view_mode,is_showing_group_anchor_offsets:I.is_showing_group_anchor_offsets}));return V.useEffect(()=>{const I=r.current;if(!I||!o||!s)return;I.width=o,I.height=s;const l=I.getContext("2d");if(!l||(l.clearRect(0,0,o,s),!a))return;const B=e.filter(D=>D.type==="pcb_group"),C=e.filter(D=>D.type==="pcb_component"),Q=e.filter(D=>D.type==="source_group"),h=new Map(Q.map(D=>[D.source_group_id,D])),E=B.filter(D=>{if(g==="all")return!0;if(!D.source_group_id)return!1;const w=h.get(D.source_group_id);return w?w.was_automatically_named!==!0:!1}),u=new Map;Q.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},p=D=>{const w=Q.find(b=>b.source_group_id===D);return w?.parent_source_group_id?1+p(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)}E.forEach((D,w)=>{let b=C.filter(HA=>HA.pcb_group_id===D.pcb_group_id);if(D.source_group_id){const HA=d(D.source_group_id),ZA=B.filter(kA=>kA.source_group_id&&HA.includes(kA.source_group_id));for(const kA of ZA){const wA=C.filter(UA=>UA.pcb_group_id===kA.pcb_group_id);b=[...b,...wA]}}let k,x,N,M,L=!1;if(D.center&&D.width&&D.height){L=!0;const HA=D.width/2,ZA=D.height/2;k=D.center.x-HA,N=D.center.x+HA,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(HA=>{if(HA.center&&typeof HA.width=="number"&&typeof HA.height=="number"){const ZA=HA.center.x-HA.width/2,kA=HA.center.x+HA.width/2,wA=HA.center.y+HA.height/2,UA=HA.center.y-HA.height/2;k=Math.min(k,ZA),N=Math.max(N,kA),x=Math.min(x,UA),M=Math.max(M,wA)}}),k===1/0||N===-1/0))return;const Y=D.source_group_id?p(D.source_group_id):0,H=D.source_group_id?d(D.source_group_id).length>0:!1;if(!L){const kA=1+(H?.5:0);k-=kA,N+=kA,x-=kA,M+=kA}const O=qi(A,{x:k,y:M}),Z=qi(A,{x:N,y:M}),$=qi(A,{x:k,y:x}),iA=qi(A,{x:N,y:x}),aA=Nce[w%Nce.length];l.strokeStyle=aA,l.lineWidth=2;const eA=Math.max(4,Math.min(12,8*Math.abs(A.a))),nA=Math.max(2,Math.min(6,4*Math.abs(A.a))),lA=eA*(H?1.3:1),pA=nA;l.setLineDash([lA,pA]),l.beginPath(),l.moveTo(O.x,O.y),l.lineTo(Z.x,Z.y),l.lineTo(iA.x,iA.y),l.lineTo($.x,$.y),l.closePath(),l.stroke();const xA=Math.max(8,Math.min(12,10*Math.abs(A.a))),RA=Y==0||Y==1?0:Y*.11,YA=xA*(1-RA),CA=4,_A=D.name||`Group ${w+1}`;l.font=`${YA}px sans-serif`,l.setLineDash([]);const KA=l.measureText(_A).width+CA*2,TA=YA+CA*2,ie=O.x-5,fA=O.y-5,Ae=3;if(l.fillStyle="rgba(0, 0, 0, 0.8)",l.beginPath(),l.roundRect(ie,fA-TA,KA,TA,Ae),l.fill(),l.fillStyle=aA,l.textAlign="left",l.textBaseline="middle",l.fillText(_A,ie+CA,fA-TA/2),c&&m.has(D.pcb_group_id)&&!!D.anchor_position&&D.anchor_position){const HA=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,HA);l.strokeStyle="white",l.lineWidth=1.5,l.setLineDash([]);const kA=Math.max(4,Math.min(8,6*Math.abs(A.a)));l.beginPath(),l.moveTo(ZA.x-kA,ZA.y),l.lineTo(ZA.x+kA,ZA.y),l.stroke(),l.beginPath(),l.moveTo(ZA.x,ZA.y-kA),l.lineTo(ZA.x,ZA.y+kA),l.stroke()}})},[e,A,o,s,a,g,c,i]),W.jsxs("div",{ref:n,style:{position:"relative",width:"100%",height:"100%"},children:[t,W.jsx("canvas",{ref:r,style:{position:"absolute",top:0,left:0,pointerEvents:"none",zIndex:uc.pcbGroupOverlay,display:a?"block":"none"}})]})},rZt=({transform:t,soup:A,children:e})=>{const i=XB(r=>r.is_showing_rats_nest),{netMap:n,idToNetMap:o}=V.useMemo(()=>Cce(A||[]),[A]),s=V.useMemo(()=>{if(!A||!i)return[];const r=l=>{const B=wb(A)[l.replace(/_\d+$/,"")].get(l);return B&&"x"in B&&"y"in B?{x:B.x,y:B.y}:null},a=(l,B)=>{const C=n[B]||[];let Q=null,h=1/0;return C.forEach(E=>{const u=r(E);if(u){const d=Math.sqrt((l.x-u.x)**2+(l.y-u.y)**2);d<h&&d>0&&(h=d,Q=u)}}),Q},g=wb(A).pcb_port.list(),c=wb(A).source_trace.list(),I=[];return g.forEach((l,B)=>{const C=o[l.pcb_port_id];let Q=!1;for(const u of c)u.connected_source_port_ids.includes(l.source_port_id)&&u.connected_source_net_ids.length>0&&(Q=!0);if(!C)return;const h={x:l.x,y:l.y},E=a(h,C);E&&I.push({key:`${l.pcb_port_id}-${B}`,startPoint:h,endPoint:E,isInNet:Q})}),I},[A,n,o,i]);return!A||!i?e:(t||(t=fb()),W.jsxs("div",{style:{position:"relative"},children:[e,W.jsx("svg",{style:{position:"absolute",left:0,top:0,width:"100%",height:"100%",pointerEvents:"none",opacity:.5,zIndex:uc.ratsNestOverlay},children:s.map(({key:r,startPoint:a,endPoint:g,isInNet:c})=>{const I=qi(t,a),l=qi(t,g);return W.jsx("line",{x1:I.x,y1:I.y,x2:l.x,y2:l.y,stroke:"white",strokeWidth:"1",strokeDasharray:c?"6,6":void 0},r)})})]}))},aZt={version:"1.11.329"},V_=(t,A,e)=>{const i=XB(s=>s.is_mouse_over_container),n=V.useRef(i),o=V.useRef(A);V.useEffect(()=>{n.current=i},[i]),V.useEffect(()=>{o.current=A},[A]),V.useEffect(()=>{if(!t)return;const s=r=>{const a=r.target;if(a.tagName==="INPUT"||a.tagName==="TEXTAREA"||a.isContentEditable)return;const g=t.split("+"),c=g.includes("ctrl"),I=g.includes("shift"),l=g.includes("alt"),B=g.includes("meta"),C=g[g.length-1],Q=e?.current?e.current.contains(document.activeElement)||document.activeElement===e.current:!1;(n.current||Q)&&(!c||r.ctrlKey)&&(!I||r.shiftKey)&&(!l||r.altKey)&&(!B||r.metaKey)&&r.key.toLowerCase()===C.toLowerCase()&&(r.preventDefault(),o.current())};return window.addEventListener("keydown",s),()=>{window.removeEventListener("keydown",s)}},[t])},gZt=()=>{const[t,A]=V.useState(!1);return V.useEffect(()=>{const e=()=>{A(window.innerWidth<=768)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),t},cZt=({name:t,selected:A,onClick:e})=>W.jsxs("div",{className:A1`
|
|
5473
5473
|
margin-top: 2px;
|
|
5474
5474
|
padding: 4px;
|
|
5475
5475
|
padding-left: 8px;
|
|
@@ -5686,7 +5686,7 @@ test("${g} should solve problem correctly", () => {
|
|
|
5686
5686
|
// Add more specific assertions based on expected output
|
|
5687
5687
|
// expect(solver.netLabelPlacementSolver!.netLabelPlacements).toMatchInlineSnapshot()
|
|
5688
5688
|
})
|
|
5689
|
-
`,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:n,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&W.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:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},Pce=t=>t.activeSubSolver?[t,...Pce(t.activeSubSolver)]:[t],vVt=({solver:t})=>{const A=Pce(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>W.jsxs("div",{className:"flex items-center",children:[i>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(NVt,{solver:e})]},e.constructor.name))})},LVt=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=V.useReducer(Q=>!Q,!1),r=V.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),n&&n(t))},c=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&t.solved&&n(t);return}t.step(),A()},e))},I=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!t.solved&&!t.failed;)t.step();A()}},l=()=>{if(t.solved||t.failed||o)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const h=Number(Q);if(!Number.isFinite(h)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<h&&!t.solved&&!t.failed;)t.step();A(),t.solved&&n&&n(t)};V.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),V.useEffect(()=>{(t.solved||t.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,o]);const B=t.getCurrentPhase!==void 0,C=B?t.getCurrentPhase():null;return W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsx(vVt,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:a,disabled:t.solved||t.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:g,disabled:t.solved||t.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:c,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),W.jsx("button",{onClick:l,disabled:t.solved||t.failed||o,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"}),B&&W.jsx("button",{onClick:I,disabled:t.solved||t.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),C&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:C})]}),t.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},UVt=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},HVt=(t,A)=>{const i=t.pipelineDef[A].solverName,n=UVt(t,A),o=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(n==="Completed"){const l=t.pipelineDef[A+1],B=l?t.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let c=0;n==="Completed"?c=1:n==="In Progress"&&o&&(c=o.progress??0);const I=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:o??null}},YVt=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[t]}`,children:t})},JVt=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},TVt=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),KVt=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(t),e=TVt(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>W.jsxs("div",{children:[i,": ",String(n)]},i))})]})},TfA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(TfA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=TfA(i));return A},PVt=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=TfA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),n=URL.createObjectURL(i),o=document.createElement("a");o.href=n,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(n)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},qVt=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>HVt(t,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):PVt(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return W.jsxs("div",{className:"border-t border-gray-200",children:[W.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:i.map(r=>W.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.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"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(YVt,{status:r.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(JVt,{progress:r.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(KVt,{stats:r.stats})}),W.jsx("td",{className:"px-4 py-2",children:r.solverInstance?W.jsxs("button",{onClick:()=>o(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.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"})}),W.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},OVt=class extends tn.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function WVt({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],n=t.circles??[],o=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const c=(h,E)=>{typeof h=="number"&&(h<s&&(s=h),h>a&&(a=h)),typeof E=="number"&&(E<r&&(r=E),E>g&&(g=E))};for(const h of A)c(h.x,h.y);for(const h of e){const E=h.points??[];for(const u of E)c(u.x,u.y)}for(const h of i){const E=h.x??0,u=h.y??0,d=h.width??0,p=h.height??0;c(E,u),c(E+d,u+p)}for(const h of n){const E=h.x??0,u=h.y??0,d=h.radius??1;c(E-d,u-d),c(E+d,u+d)}for(const h of o)c(h.x,h.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const I=10,l=s-I,B=r-I,C=Math.max(1,a-s+2*I),Q=Math.max(1,g-r+2*I);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((h,E)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),e.map((h,E)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${E}`)),n.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${E}`)),A.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),o.map((h,E)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var ZVt=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[n,o]=V.useReducer(c=>c+1,0),s=V.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[t,n]),r=V.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);V.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=t.pipelineDef!==void 0,g=c=>{const I=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)t.step();o()}};return W.jsxs("div",{children:[W.jsx(LVt,{solver:t,triggerRender:o,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(OVt,{fallback:W.jsx(WVt,{graphics:s}),children:W.jsx(MVt,{graphics:s})}),a&&W.jsx(qVt,{solver:t,onStepUntilPhase:g})]})};const VVt=()=>{V.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},jVt=t=>t.toLowerCase().includes("pack")?gMt:t.toLowerCase().includes("rout")?CMt:ZRt,zVt=({solverEvents:t=[]})=>{const[A,e]=V.useState(null);VVt();const i=V.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),n=V.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=V.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=qnA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(qnA).join(", ")}`,classFound:!1};try{const a=o.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}}},[o]);return t.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.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."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.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:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return W.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:()=>e(r),children:(()=>{const c=jVt(a.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?W.jsx(Yy,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:W.jsx(ZVt,{solver:s.instance})}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&W.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:W.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},qce=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{V.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{v5.captureException(i)}catch{}}},[t,A]),V.useEffect(()=>{if(e&&e.length>0)for(const i of e){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{v5.captureException(n,{error_type:i.type})}catch{}}},[e])},Oce="0.0.1560",XVt={version:Oce},W9=pYA()(fYA(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),$Vt=t=>{const[A,e]=V.useState([]),[i,n]=V.useState(null),[o,s]=V.useState(""),[r,a]=e1("eval-version-selection",null),g=W9(B=>B.setLastRunEvalVersion),c=W9(B=>B.lastRunEvalVersion);return V.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(B=>B.json()).then(B=>{if(Array.isArray(B?.versions)){let C=[...B.versions];B.tags?.latest&&(n(B.tags.latest),C=C.filter(Q=>Q!==B.tags.latest)),e(C)}}).catch(()=>{})},[t]),V.useEffect(()=>{t&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[t,r,i]),{versions:V.useMemo(()=>A.filter(B=>B.includes(o)).slice(0,50),[A,o]),latestVersion:i,lastRunEvalVersion:c,search:o,setSearch:s,selectVersion:B=>{a(B),s("")}}},A9t=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[n,o]=V.useState(""),[s,r]=V.useState("");if(!i)return null;const a=t.filter(I=>I.toLowerCase().includes(s.toLowerCase())),g=s&&!t.includes(s),c=I=>{I.key==="Enter"&&(a.length===1?o(a[0]):g&&o(s))};return W.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:W.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[W.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),W.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:I=>r(I.target.value),onKeyDown:c}),W.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(I=>W.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${n===I?"bg-blue-50":""}`,onClick:()=>o(I),children:I},I)),g&&W.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${n===s?"bg-blue-50":""}`,onClick:()=>o(s),children:['Create new "',s,'"']})]}),W.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:e,children:"Cancel"}),W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>n&&A(n),disabled:!n,children:n===s?`Create "${n}"`:`Save to ${n}`})]})]})})},e9t=t=>{const A=V.useRef(null),e=qI(i=>i.recentEvents);V.useEffect(()=>{if(e.length===0)return;const i=e[0];i.event_id!==A.current&&(t(i),A.current=i.event_id)},[e,t])};function t9t(t){const A=i9t(t),e=V.forwardRef((i,n)=>{const{children:o,...s}=i,r=V.Children.toArray(o),a=r.find(o9t);if(a){const g=a.props.children,c=r.map(I=>I===a?V.Children.count(g)>1?V.Children.only(null):V.isValidElement(g)?g.props.children:null:I);return W.jsx(A,{...s,ref:n,children:V.isValidElement(g)?V.cloneElement(g,void 0,c):null})}return W.jsx(A,{...s,ref:n,children:o})});return e.displayName=`${t}.Slot`,e}function i9t(t){const A=V.forwardRef((e,i)=>{const{children:n,...o}=e;if(V.isValidElement(n)){const s=r9t(n),r=s9t(o,n.props);return n.type!==V.Fragment&&(r.ref=i?sf(i,s):s),V.cloneElement(n,r)}return V.Children.count(n)>1?V.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var n9t=Symbol("radix.slottable");function o9t(t){return V.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===n9t}function s9t(t,A){const e={...A};for(const i in A){const n=t[i],o=A[i];/^on[A-Z]/.test(i)?n&&o?e[i]=(...r)=>{const a=o(...r);return n(...r),a}:n&&(e[i]=n):i==="style"?e[i]={...n,...o}:i==="className"&&(e[i]=[n,o].filter(Boolean).join(" "))}return{...t,...e}}function r9t(t){let A=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning;return e?t.ref:(A=Object.getOwnPropertyDescriptor(t,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var Z9="Dialog",[Wce,Zce]=Lm(Z9),[a9t,Iw]=Wce(Z9),Vce=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:n,onOpenChange:o,modal:s=!0}=t,r=V.useRef(null),a=V.useRef(null),[g,c]=Ux({prop:i,defaultProp:n??!1,onChange:o,caller:Z9});return W.jsx(a9t,{scope:A,triggerRef:r,contentRef:a,contentId:mE(),titleId:mE(),descriptionId:mE(),open:g,onOpenChange:c,onOpenToggle:V.useCallback(()=>c(I=>!I),[c]),modal:s,children:e})};Vce.displayName=Z9;var jce="DialogTrigger",zce=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Iw(jce,e),o=EI(A,n.triggerRef);return W.jsx(qa.button,{type:"button","aria-haspopup":"dialog","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":qfA(n.open),...i,ref:o,onClick:Hn(t.onClick,n.onOpenToggle)})});zce.displayName=jce;var KfA="DialogPortal",[g9t,Xce]=Wce(KfA,{forceMount:void 0}),$ce=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:n}=t,o=Iw(KfA,A);return W.jsx(g9t,{scope:A,forceMount:e,children:V.Children.map(i,s=>W.jsx(E0,{present:e||o.open,children:W.jsx(PZ,{asChild:!0,container:n,children:s})}))})};$ce.displayName=KfA;var V9="DialogOverlay",AIe=V.forwardRef((t,A)=>{const e=Xce(V9,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Iw(V9,t.__scopeDialog);return o.modal?W.jsx(E0,{present:i||o.open,children:W.jsx(I9t,{...n,ref:A})}):null});AIe.displayName=V9;var c9t=t9t("DialogOverlay.RemoveScroll"),I9t=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Iw(V9,e);return W.jsx(XZ,{as:c9t,allowPinchZoom:!0,shards:[n.contentRef],children:W.jsx(qa.div,{"data-state":qfA(n.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),GG="DialogContent",eIe=V.forwardRef((t,A)=>{const e=Xce(GG,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Iw(GG,t.__scopeDialog);return W.jsx(E0,{present:i||o.open,children:o.modal?W.jsx(l9t,{...n,ref:A}):W.jsx(B9t,{...n,ref:A})})});eIe.displayName=GG;var l9t=V.forwardRef((t,A)=>{const e=Iw(GG,t.__scopeDialog),i=V.useRef(null),n=EI(A,e.contentRef,i);return V.useEffect(()=>{const o=i.current;if(o)return KuA(o)},[]),W.jsx(tIe,{...t,ref:n,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Hn(t.onCloseAutoFocus,o=>{o.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:Hn(t.onPointerDownOutside,o=>{const s=o.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&o.preventDefault()}),onFocusOutside:Hn(t.onFocusOutside,o=>o.preventDefault())})}),B9t=V.forwardRef((t,A)=>{const e=Iw(GG,t.__scopeDialog),i=V.useRef(!1),n=V.useRef(!1);return W.jsx(tIe,{...t,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{t.onCloseAutoFocus?.(o),o.defaultPrevented||(i.current||e.triggerRef.current?.focus(),o.preventDefault()),i.current=!1,n.current=!1},onInteractOutside:o=>{t.onInteractOutside?.(o),o.defaultPrevented||(i.current=!0,o.detail.originalEvent.type==="pointerdown"&&(n.current=!0));const s=o.target;e.triggerRef.current?.contains(s)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&n.current&&o.preventDefault()}})}),tIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:n,onCloseAutoFocus:o,...s}=t,r=Iw(GG,e),a=V.useRef(null),g=EI(A,a);return wuA(),W.jsxs(W.Fragment,{children:[W.jsx(FZ,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:n,onUnmountAutoFocus:o,children:W.jsx(XH,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":qfA(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),W.jsxs(W.Fragment,{children:[W.jsx(Q9t,{titleId:r.titleId}),W.jsx(E9t,{contentRef:a,descriptionId:r.descriptionId})]})]})}),PfA="DialogTitle",iIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Iw(PfA,e);return W.jsx(qa.h2,{id:n.titleId,...i,ref:A})});iIe.displayName=PfA;var nIe="DialogDescription",oIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Iw(nIe,e);return W.jsx(qa.p,{id:n.descriptionId,...i,ref:A})});oIe.displayName=nIe;var sIe="DialogClose",rIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Iw(sIe,e);return W.jsx(qa.button,{type:"button",...i,ref:A,onClick:Hn(t.onClick,()=>n.onOpenChange(!1))})});rIe.displayName=sIe;function qfA(t){return t?"open":"closed"}var aIe="DialogTitleWarning",[C9t,gIe]=LXe(aIe,{contentName:GG,titleName:PfA,docsSlug:"dialog"}),Q9t=({titleId:t})=>{const A=gIe(aIe),e=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
|
|
5689
|
+
`,I=new Blob([c],{type:"text/plain"}),l=URL.createObjectURL(I),B=document.createElement("a");B.href=l,B.download=`${g}.test.ts`,B.click(),URL.revokeObjectURL(l)}catch(a){alert(`Error generating test.ts for ${t.constructor.name}: ${a instanceof Error?a.message:String(a)}`)}i(!1)};return W.jsxs("div",{className:`relative ${A}`,ref:n,children:[W.jsx("button",{className:"px-2 py-1 rounded text-xs cursor-pointer",onClick:()=>i(!e),title:`Download options for ${t.constructor.name}`,children:t.constructor.name}),e&&W.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:[W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:o,children:"Download JSON"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:s,children:"Download page.tsx"}),W.jsx("button",{className:"w-full text-left px-3 py-2 hover:bg-gray-100 text-xs",onClick:r,children:"Download test.ts"})]})]})},Pce=t=>t.activeSubSolver?[t,...Pce(t.activeSubSolver)]:[t],vVt=({solver:t})=>{const A=Pce(t);return W.jsx("div",{className:"flex gap-1 items-center text-sm pt-1",children:A.map((e,i)=>W.jsxs("div",{className:"flex items-center",children:[i>0&&W.jsx("span",{className:"text-gray-400 mx-1",children:"→"}),W.jsx(NVt,{solver:e})]},e.constructor.name))})},LVt=({solver:t,triggerRender:A,animationSpeed:e=25,onSolverStarted:i,onSolverCompleted:n})=>{const[o,s]=V.useReducer(Q=>!Q,!1),r=V.useRef(void 0),a=()=>{!t.solved&&!t.failed&&(t.step(),A())},g=()=>{!t.solved&&!t.failed&&(i&&i(t),t.solve(),A(),n&&n(t))},c=()=>{o?(r.current&&(clearInterval(r.current),r.current=void 0),s()):(s(),r.current=setInterval(()=>{if(t.solved||t.failed){r.current&&(clearInterval(r.current),r.current=void 0),s(),A(),n&&t.solved&&n(t);return}t.step(),A()},e))},I=()=>{const Q=t;if(Q.getCurrentPhase&&!t.solved&&!t.failed){const h=Q.getCurrentPhase();for(;Q.getCurrentPhase()===h&&!t.solved&&!t.failed;)t.step();A()}},l=()=>{if(t.solved||t.failed||o)return;const Q=window.prompt("Step until which iteration?",`${t.iterations}`);if(Q===null)return;const h=Number(Q);if(!Number.isFinite(h)){window.alert("Please enter a valid number for the iteration");return}for(;t.iterations<h&&!t.solved&&!t.failed;)t.step();A(),t.solved&&n&&n(t)};V.useEffect(()=>()=>{r.current&&clearInterval(r.current)},[]),V.useEffect(()=>{(t.solved||t.failed)&&o&&(r.current&&(clearInterval(r.current),r.current=void 0),s())},[t.solved,t.failed,o]);const B=t.getCurrentPhase!==void 0,C=B?t.getCurrentPhase():null;return W.jsxs("div",{className:"space-y-2 p-2 border-b",children:[W.jsx("div",{className:"flex items-center",children:W.jsx(vVt,{solver:t})}),W.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[W.jsx("button",{onClick:a,disabled:t.solved||t.failed||o,className:"bg-blue-500 hover:bg-blue-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Step"}),W.jsx("button",{onClick:g,disabled:t.solved||t.failed||o,className:"bg-green-500 hover:bg-green-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Solve"}),W.jsx("button",{onClick:c,disabled:t.solved||t.failed,className:`px-3 py-1 rounded text-white text-sm ${o?"bg-red-500 hover:bg-red-600":"bg-yellow-500 hover:bg-yellow-600"} disabled:bg-gray-300`,children:o?"Stop":"Animate"}),W.jsx("button",{onClick:l,disabled:t.solved||t.failed||o,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"}),B&&W.jsx("button",{onClick:I,disabled:t.solved||t.failed||o,className:"bg-purple-500 hover:bg-purple-600 disabled:bg-gray-300 text-white px-3 py-1 rounded text-sm",children:"Next Stage"}),W.jsxs("div",{className:"text-sm text-gray-600",children:["Iterations: ",t.iterations]}),t.timeToSolve!==void 0&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Time: ",(t.timeToSolve/1e3).toFixed(3),"s"]}),C&&W.jsxs("div",{className:"text-sm text-gray-600",children:["Phase: ",W.jsx("span",{className:"font-medium",children:C})]}),t.solved&&W.jsx("div",{className:"px-2 py-1 bg-green-100 text-green-800 rounded text-sm",children:"Solved"}),t.failed&&W.jsx("div",{className:"px-2 py-1 bg-red-100 text-red-800 rounded text-sm",children:"Failed"})]}),t.error&&W.jsxs("div",{className:"text-red-600 text-sm",children:["Error: ",t.error]})]})},UVt=(t,A,e)=>{const i=t.currentPipelineStepIndex;return A<i?"Completed":A===i&&t.activeSubSolver?t.activeSubSolver.failed?"Failed":"In Progress":"Not Started"},HVt=(t,A)=>{const i=t.pipelineDef[A].solverName,n=UVt(t,A),o=t[i],s=t.firstIterationOfPhase?.[i]??null,r=t.iterations;let a=0;if(n==="Completed"){const l=t.pipelineDef[A+1],B=l?t.firstIterationOfPhase?.[l.solverName]:void 0;B!==void 0&&s!==null?a=B-s:s!==null&&(a=r-s)}else n==="In Progress"&&s!==null&&(a=r-s);const g=t.timeSpentOnPhase?.[i]??0;let c=0;n==="Completed"?c=1:n==="In Progress"&&o&&(c=o.progress??0);const I=o?.stats??null;return{index:A,name:i,status:n,firstIteration:s,iterations:a,progress:c,timeSpent:g,stats:I&&Object.keys(I).length>0?I:null,solverInstance:o??null}},YVt=({status:t})=>{const A={"Not Started":"text-blue-600","In Progress":"text-yellow-600",Completed:"text-green-600",Failed:"text-red-600"};return W.jsx("span",{className:`font-medium ${A[t]}`,children:t})},JVt=({progress:t})=>{if(t===0)return null;const A=Math.round(t*100);return W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("div",{className:"w-20 h-2 bg-gray-200 rounded overflow-hidden",children:W.jsx("div",{className:"h-full bg-blue-500 transition-all duration-200",style:{width:`${A}%`}})}),W.jsxs("span",{className:"text-xs text-gray-500",children:[A,"%"]})]})},TVt=t=>Object.entries(t).map(([A,e])=>`${A}: ${e}`).join(", "),KVt=({stats:t})=>{if(!t||Object.keys(t).length===0)return W.jsx("span",{children:"-"});const A=Object.entries(t),e=TVt(t);return W.jsxs("details",{className:"cursor-pointer",children:[W.jsx("summary",{className:"whitespace-nowrap overflow-hidden text-ellipsis max-w-[200px]",children:e}),W.jsx("div",{className:"mt-1 text-xs",children:A.map(([i,n])=>W.jsxs("div",{children:[i,": ",String(n)]},i))})]})},TfA=t=>{if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(TfA);const A={};for(const[e,i]of Object.entries(t))e.startsWith("_")||(A[e]=TfA(i));return A},PVt=(t,A)=>{try{if(typeof t.getConstructorParams!="function"){alert(`getConstructorParams() is not implemented for ${A}`);return}const e=TfA(t.getConstructorParams()),i=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),n=URL.createObjectURL(i),o=document.createElement("a");o.href=n,o.download=`${A}_input.json`,o.click(),URL.revokeObjectURL(n)}catch(e){alert(`Error downloading input for ${A}: ${e instanceof Error?e.message:String(e)}`)}},qVt=({solver:t,onStepUntilPhase:A,onDownloadInput:e})=>{const i=t.pipelineDef.map((r,a)=>HVt(t,a)),n=r=>{A?.(r)},o=r=>{r.solverInstance&&(e?e(r.solverInstance,r.name):PVt(r.solverInstance,r.name))},s=r=>`${(r/1e3).toFixed(2)}s`;return W.jsxs("div",{className:"border-t border-gray-200",children:[W.jsx("div",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200",children:W.jsx("h3",{className:"text-sm font-semibold text-gray-700",children:"Pipeline Steps"})}),W.jsx("div",{className:"overflow-x-auto",children:W.jsxs("table",{className:"w-full text-sm",children:[W.jsx("thead",{children:W.jsxs("tr",{className:"bg-gray-50 border-b border-gray-200",children:[W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Step"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Status"}),W.jsxs("th",{className:"px-4 py-2 text-center font-semibold text-gray-700",children:["i",W.jsx("sub",{children:"0"})]}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Iterations"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Progress"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Time"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Stats"}),W.jsx("th",{className:"px-4 py-2 text-left font-semibold text-gray-700",children:"Input"})]})}),W.jsx("tbody",{children:i.map(r=>W.jsxs("tr",{className:`border-b border-gray-100 ${r.status==="In Progress"?"bg-yellow-50":""}`,children:[W.jsx("td",{className:"px-4 py-2",children:W.jsxs("div",{className:"flex items-center gap-2",children:[W.jsx("span",{className:"text-gray-400 w-6",children:String(r.index+1).padStart(2,"0")}),W.jsx("button",{onClick:()=>n(r.name),disabled:r.status==="Completed"||t.solved||t.failed,className:"text-blue-500 hover:text-blue-700 disabled:text-gray-300 disabled:cursor-not-allowed",title:`Step until ${r.name} completes`,children:W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.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"})})}),W.jsx("span",{className:"font-medium text-gray-900",children:r.name})]})}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(YVt,{status:r.status})}),W.jsx("td",{className:"px-4 py-2 text-center text-gray-600",children:r.firstIteration!==null?r.firstIteration:""}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:r.iterations}),W.jsx("td",{className:"px-4 py-2",children:W.jsx(JVt,{progress:r.progress})}),W.jsx("td",{className:"px-4 py-2 text-gray-600",children:s(r.timeSpent)}),W.jsx("td",{className:"px-4 py-2 text-gray-500",children:W.jsx(KVt,{stats:r.stats})}),W.jsx("td",{className:"px-4 py-2",children:r.solverInstance?W.jsxs("button",{onClick:()=>o(r),className:"flex items-center gap-1 text-blue-500 hover:text-blue-700",title:`Download input for ${r.name}`,children:[W.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"w-4 h-4",children:W.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"})}),W.jsx("span",{children:"Input"})]}):null})]},r.name))})]})})]})},OVt=class extends tn.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error("InteractiveGraphics render error:",t)}render(){return this.state.hasError?this.props.fallback:this.props.children}};function WVt({graphics:t}){const A=t.points??[],e=t.lines??[],i=t.rects??[],n=t.circles??[],o=t.texts??[];let s=Number.POSITIVE_INFINITY,r=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,g=Number.NEGATIVE_INFINITY;const c=(h,E)=>{typeof h=="number"&&(h<s&&(s=h),h>a&&(a=h)),typeof E=="number"&&(E<r&&(r=E),E>g&&(g=E))};for(const h of A)c(h.x,h.y);for(const h of e){const E=h.points??[];for(const u of E)c(u.x,u.y)}for(const h of i){const E=h.x??0,u=h.y??0,d=h.width??0,p=h.height??0;c(E,u),c(E+d,u+p)}for(const h of n){const E=h.x??0,u=h.y??0,d=h.radius??1;c(E-d,u-d),c(E+d,u+d)}for(const h of o)c(h.x,h.y);(!isFinite(s)||!isFinite(r)||!isFinite(a)||!isFinite(g))&&(s=-20,r=-20,a=20,g=20);const I=10,l=s-I,B=r-I,C=Math.max(1,a-s+2*I),Q=Math.max(1,g-r+2*I);return W.jsxs("svg",{className:"w-full h-[400px] bg-white",viewBox:`${l} ${B} ${C} ${Q}`,role:"img","aria-label":"Graphics fallback",children:[i.map((h,E)=>W.jsx("rect",{x:h.x??0,y:h.y??0,width:h.width??0,height:h.height??0,fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`rect-${E}`)),e.map((h,E)=>W.jsx("polyline",{fill:"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1,points:(h.points??[]).map(u=>`${u.x??0},${u.y??0}`).join(" ")},`line-${E}`)),n.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.fillColor??"none",stroke:h.strokeColor??"black",strokeWidth:h.strokeWidth??1},`circle-${E}`)),A.map((h,E)=>W.jsx("circle",{cx:h.x??0,cy:h.y??0,r:h.radius??1.5,fill:h.color??"black"},`point-${E}`)),o.map((h,E)=>W.jsx("text",{x:h.x??0,y:h.y??0,fontSize:h.fontSize??10,fill:h.color??"black",children:h.text??""},`text-${E}`))]})}var ZVt=({solver:t,animationSpeed:A=25,onSolverStarted:e,onSolverCompleted:i})=>{const[n,o]=V.useReducer(c=>c+1,0),s=V.useMemo(()=>{try{return t.visualize()||{points:[],lines:[],rects:[],circles:[]}}catch(c){return console.error("Visualization error:",c),{points:[],lines:[],rects:[],circles:[]}}},[t,n]),r=V.useMemo(()=>(s.rects?.length||0)===0&&(s.lines?.length||0)===0&&(s.points?.length||0)===0&&(s.circles?.length||0)===0,[s]);V.useEffect(()=>{if(!(typeof document>"u")&&!document.querySelector('script[src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"]')){const c=document.createElement("script");c.src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4",document.head.appendChild(c)}},[]);const a=t.pipelineDef!==void 0,g=c=>{const I=t;if(!t.solved&&!t.failed){for(;!t.solved&&!t.failed&&I.currentPipelineStepIndex<=I.pipelineDef.findIndex(l=>l.solverName===c);)t.step();o()}};return W.jsxs("div",{children:[W.jsx(LVt,{solver:t,triggerRender:o,animationSpeed:A,onSolverStarted:e,onSolverCompleted:i}),r?W.jsx("div",{className:"p-4 text-gray-500",children:"No Graphics Yet"}):W.jsx(OVt,{fallback:W.jsx(WVt,{graphics:s}),children:W.jsx(MVt,{graphics:s})}),a&&W.jsx(qVt,{solver:t,onStepUntilPhase:g})]})};const VVt=()=>{V.useEffect(()=>{const t="tailwind-cdn-script";if(document.getElementById(t)||window.tailwind)return;const A=document.createElement("div");A.className="hidden",document.body.appendChild(A);const e=window.getComputedStyle(A).display==="none";if(document.body.removeChild(A),e)return;const i=document.createElement("script");i.id=t,i.src="https://cdn.tailwindcss.com",document.head.appendChild(i)},[])},jVt=t=>t.toLowerCase().includes("pack")?gMt:t.toLowerCase().includes("rout")?CMt:ZRt,zVt=({solverEvents:t=[]})=>{const[A,e]=V.useState(null);VVt();const i=V.useMemo(()=>{const r=new Map;for(const a of t){const g=`${a.componentName}-${a.solverName}`;r.set(g,a)}return r},[t]),n=V.useMemo(()=>Array.from(i.keys()),[i]),o=A?i.get(A):null,s=V.useMemo(()=>{if(!o)return{instance:null,error:null,classFound:!1};const r=qnA[o.solverName];if(!r)return{instance:null,error:`Solver class "${o.solverName}" not found in SOLVERS registry. Available: ${Object.keys(qnA).join(", ")}`,classFound:!1};try{const a=o.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}}},[o]);return t.length===0?W.jsx("div",{className:"rf-p-4",children:W.jsx("div",{className:"rf-bg-gray-50 rf-rounded-md rf-border rf-border-gray-200",children:W.jsxs("div",{className:"rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800 rf-mb-3",children:"No Solvers Detected"}),W.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."})]})})}):W.jsxs("div",{className:"rf-flex rf-h-full rf-overflow-hidden",children:[W.jsxs("div",{className:"rf-w-64 rf-border-r rf-border-gray-200 rf-overflow-y-auto rf-flex-shrink-0",children:[W.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:[n.length," ",n.length===1?"Solver":"Solvers"]}),n.map(r=>{const a=i.get(r),g=A===r;return W.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:()=>e(r),children:(()=>{const c=jVt(a.solverName);return W.jsxs("div",{className:"rf-flex rf-items-center rf-gap-2",children:[W.jsx(c,{className:"rf-w-4 rf-h-4 rf-text-blue-500 rf-flex-shrink-0"}),W.jsxs("div",{className:"rf-flex-1 rf-min-w-0",children:[W.jsx("div",{className:"rf-text-sm rf-font-medium rf-text-gray-800 rf-truncate",children:a.componentName}),W.jsx("div",{className:"rf-text-xs rf-text-gray-500 rf-truncate",children:a.solverName})]})]})})()},r)})]}),W.jsx("div",{className:"rf-flex-1 rf-overflow-hidden",children:o?s.instance?W.jsx(Yy,{fallback:W.jsx("div",{className:"rf-p-4",children:W.jsxs("div",{className:"rf-bg-red-50 rf-rounded-md rf-border rf-border-red-200 rf-p-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-red-800 rf-mb-2",children:"Error Loading Solver Debugger"}),W.jsxs("p",{className:"rf-text-sm rf-text-red-600",children:["Failed to render the solver debugger for"," ",o.solverName]})]})}),children:W.jsx(ZVt,{solver:s.instance})}):W.jsxs("div",{className:"rf-p-4",children:[W.jsxs("div",{className:"rf-mb-4",children:[W.jsx("h3",{className:"rf-text-lg rf-font-semibold rf-text-gray-800",children:o.solverName}),W.jsxs("p",{className:"rf-text-sm rf-text-gray-500",children:["Component: ",o.componentName]})]}),s.error&&W.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:W.jsx("p",{className:`rf-text-sm ${s.classFound?"rf-text-red-700":"rf-text-yellow-700"}`,children:s.error})}),W.jsxs("div",{className:"rf-border rf-border-gray-200 rf-rounded-md rf-overflow-hidden",children:[W.jsx("div",{className:"rf-px-3 rf-py-2 rf-bg-gray-50",children:W.jsx("span",{className:"rf-text-sm rf-font-medium rf-text-gray-700",children:"Solver Parameters"})}),W.jsx("div",{className:"rf-p-3 rf-bg-white rf-border-t rf-border-gray-200",children:W.jsx("pre",{className:"rf-text-xs rf-font-mono rf-text-gray-600 rf-whitespace-pre-wrap rf-overflow-x-auto",children:JSON.stringify(o.solverParams,null,2)})})]})]}):W.jsx("div",{className:"rf-flex rf-items-center rf-justify-center rf-h-full",children:W.jsx("p",{className:"rf-text-sm rf-text-gray-500",children:"Select a solver from the list to view details"})})})]})},qce=({errorMessage:t,errorStack:A,circuitJsonErrors:e})=>{V.useEffect(()=>{if(t){const i=new Error(t);A&&(i.stack=A);try{v5.captureException(i)}catch{}}},[t,A]),V.useEffect(()=>{if(e&&e.length>0)for(const i of e){const n=new Error(i.message||"Circuit JSON Error");i.stack&&(n.stack=i.stack);try{v5.captureException(n,{error_type:i.type})}catch{}}},[e])},Oce="0.0.1562",XVt={version:Oce},W9=pYA()(fYA(t=>({lastRunEvalVersion:void 0,setLastRunEvalVersion:A=>{t({lastRunEvalVersion:A})}}),{name:"runframe-runner-store"})),$Vt=t=>{const[A,e]=V.useState([]),[i,n]=V.useState(null),[o,s]=V.useState(""),[r,a]=e1("eval-version-selection",null),g=W9(B=>B.setLastRunEvalVersion),c=W9(B=>B.lastRunEvalVersion);return V.useEffect(()=>{t&&fetch("https://data.jsdelivr.com/v1/package/npm/@tscircuit/eval").then(B=>B.json()).then(B=>{if(Array.isArray(B?.versions)){let C=[...B.versions];B.tags?.latest&&(n(B.tags.latest),C=C.filter(Q=>Q!==B.tags.latest)),e(C)}}).catch(()=>{})},[t]),V.useEffect(()=>{t&&(r?(window.TSCIRCUIT_LATEST_EVAL_VERSION=r,g(r)):i&&(window.TSCIRCUIT_LATEST_EVAL_VERSION=i,g(i)))},[t,r,i]),{versions:V.useMemo(()=>A.filter(B=>B.includes(o)).slice(0,50),[A,o]),latestVersion:i,lastRunEvalVersion:c,search:o,setSearch:s,selectVersion:B=>{a(B),s("")}}},A9t=({snippetNames:t,onSelect:A,onCancel:e,isOpen:i})=>{const[n,o]=V.useState(""),[s,r]=V.useState("");if(!i)return null;const a=t.filter(I=>I.toLowerCase().includes(s.toLowerCase())),g=s&&!t.includes(s),c=I=>{I.key==="Enter"&&(a.length===1?o(a[0]):g&&o(s))};return W.jsx("div",{className:"rf-fixed rf-inset-0 rf-bg-black rf-bg-opacity-50 rf-flex rf-items-center rf-justify-center rf-z-[100]",children:W.jsxs("div",{className:"rf-bg-white rf-rounded-lg rf-p-6 rf-w-96",children:[W.jsx("h2",{className:"rf-text-lg rf-font-semibold rf-mb-4",children:"Select Snippet"}),W.jsx("input",{type:"text",className:"rf-w-full rf-px-4 rf-py-2 rf-border rf-rounded rf-mb-4",placeholder:"Search snippets or new snippet name...",value:s,onChange:I=>r(I.target.value),onKeyDown:c}),W.jsxs("div",{className:"rf-h-60 rf-overflow-y-auto",children:[a.map(I=>W.jsx("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 ${n===I?"bg-blue-50":""}`,onClick:()=>o(I),children:I},I)),g&&W.jsxs("button",{type:"button",className:`w-full text-left px-4 py-2 rounded hover:bg-gray-100 text-blue-500 ${n===s?"bg-blue-50":""}`,onClick:()=>o(s),children:['Create new "',s,'"']})]}),W.jsxs("div",{className:"rf-mt-4 rf-flex rf-justify-end rf-gap-2",children:[W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-text-gray-600 rf-hover:text-gray-800",onClick:e,children:"Cancel"}),W.jsx("button",{type:"button",className:"rf-px-4 rf-py-2 rf-bg-blue-500 rf-text-white rf-rounded rf-hover:bg-blue-600 rf-disabled:opacity-50",onClick:()=>n&&A(n),disabled:!n,children:n===s?`Create "${n}"`:`Save to ${n}`})]})]})})},e9t=t=>{const A=V.useRef(null),e=qI(i=>i.recentEvents);V.useEffect(()=>{if(e.length===0)return;const i=e[0];i.event_id!==A.current&&(t(i),A.current=i.event_id)},[e,t])};function t9t(t){const A=i9t(t),e=V.forwardRef((i,n)=>{const{children:o,...s}=i,r=V.Children.toArray(o),a=r.find(o9t);if(a){const g=a.props.children,c=r.map(I=>I===a?V.Children.count(g)>1?V.Children.only(null):V.isValidElement(g)?g.props.children:null:I);return W.jsx(A,{...s,ref:n,children:V.isValidElement(g)?V.cloneElement(g,void 0,c):null})}return W.jsx(A,{...s,ref:n,children:o})});return e.displayName=`${t}.Slot`,e}function i9t(t){const A=V.forwardRef((e,i)=>{const{children:n,...o}=e;if(V.isValidElement(n)){const s=r9t(n),r=s9t(o,n.props);return n.type!==V.Fragment&&(r.ref=i?sf(i,s):s),V.cloneElement(n,r)}return V.Children.count(n)>1?V.Children.only(null):null});return A.displayName=`${t}.SlotClone`,A}var n9t=Symbol("radix.slottable");function o9t(t){return V.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===n9t}function s9t(t,A){const e={...A};for(const i in A){const n=t[i],o=A[i];/^on[A-Z]/.test(i)?n&&o?e[i]=(...r)=>{const a=o(...r);return n(...r),a}:n&&(e[i]=n):i==="style"?e[i]={...n,...o}:i==="className"&&(e[i]=[n,o].filter(Boolean).join(" "))}return{...t,...e}}function r9t(t){let A=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning;return e?t.ref:(A=Object.getOwnPropertyDescriptor(t,"ref")?.get,e=A&&"isReactWarning"in A&&A.isReactWarning,e?t.props.ref:t.props.ref||t.ref)}var Z9="Dialog",[Wce,Zce]=Lm(Z9),[a9t,Iw]=Wce(Z9),Vce=t=>{const{__scopeDialog:A,children:e,open:i,defaultOpen:n,onOpenChange:o,modal:s=!0}=t,r=V.useRef(null),a=V.useRef(null),[g,c]=Ux({prop:i,defaultProp:n??!1,onChange:o,caller:Z9});return W.jsx(a9t,{scope:A,triggerRef:r,contentRef:a,contentId:mE(),titleId:mE(),descriptionId:mE(),open:g,onOpenChange:c,onOpenToggle:V.useCallback(()=>c(I=>!I),[c]),modal:s,children:e})};Vce.displayName=Z9;var jce="DialogTrigger",zce=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Iw(jce,e),o=EI(A,n.triggerRef);return W.jsx(qa.button,{type:"button","aria-haspopup":"dialog","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":qfA(n.open),...i,ref:o,onClick:Hn(t.onClick,n.onOpenToggle)})});zce.displayName=jce;var KfA="DialogPortal",[g9t,Xce]=Wce(KfA,{forceMount:void 0}),$ce=t=>{const{__scopeDialog:A,forceMount:e,children:i,container:n}=t,o=Iw(KfA,A);return W.jsx(g9t,{scope:A,forceMount:e,children:V.Children.map(i,s=>W.jsx(E0,{present:e||o.open,children:W.jsx(PZ,{asChild:!0,container:n,children:s})}))})};$ce.displayName=KfA;var V9="DialogOverlay",AIe=V.forwardRef((t,A)=>{const e=Xce(V9,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Iw(V9,t.__scopeDialog);return o.modal?W.jsx(E0,{present:i||o.open,children:W.jsx(I9t,{...n,ref:A})}):null});AIe.displayName=V9;var c9t=t9t("DialogOverlay.RemoveScroll"),I9t=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Iw(V9,e);return W.jsx(XZ,{as:c9t,allowPinchZoom:!0,shards:[n.contentRef],children:W.jsx(qa.div,{"data-state":qfA(n.open),...i,ref:A,style:{pointerEvents:"auto",...i.style}})})}),GG="DialogContent",eIe=V.forwardRef((t,A)=>{const e=Xce(GG,t.__scopeDialog),{forceMount:i=e.forceMount,...n}=t,o=Iw(GG,t.__scopeDialog);return W.jsx(E0,{present:i||o.open,children:o.modal?W.jsx(l9t,{...n,ref:A}):W.jsx(B9t,{...n,ref:A})})});eIe.displayName=GG;var l9t=V.forwardRef((t,A)=>{const e=Iw(GG,t.__scopeDialog),i=V.useRef(null),n=EI(A,e.contentRef,i);return V.useEffect(()=>{const o=i.current;if(o)return KuA(o)},[]),W.jsx(tIe,{...t,ref:n,trapFocus:e.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Hn(t.onCloseAutoFocus,o=>{o.preventDefault(),e.triggerRef.current?.focus()}),onPointerDownOutside:Hn(t.onPointerDownOutside,o=>{const s=o.detail.originalEvent,r=s.button===0&&s.ctrlKey===!0;(s.button===2||r)&&o.preventDefault()}),onFocusOutside:Hn(t.onFocusOutside,o=>o.preventDefault())})}),B9t=V.forwardRef((t,A)=>{const e=Iw(GG,t.__scopeDialog),i=V.useRef(!1),n=V.useRef(!1);return W.jsx(tIe,{...t,ref:A,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{t.onCloseAutoFocus?.(o),o.defaultPrevented||(i.current||e.triggerRef.current?.focus(),o.preventDefault()),i.current=!1,n.current=!1},onInteractOutside:o=>{t.onInteractOutside?.(o),o.defaultPrevented||(i.current=!0,o.detail.originalEvent.type==="pointerdown"&&(n.current=!0));const s=o.target;e.triggerRef.current?.contains(s)&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&n.current&&o.preventDefault()}})}),tIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,trapFocus:i,onOpenAutoFocus:n,onCloseAutoFocus:o,...s}=t,r=Iw(GG,e),a=V.useRef(null),g=EI(A,a);return wuA(),W.jsxs(W.Fragment,{children:[W.jsx(FZ,{asChild:!0,loop:!0,trapped:i,onMountAutoFocus:n,onUnmountAutoFocus:o,children:W.jsx(XH,{role:"dialog",id:r.contentId,"aria-describedby":r.descriptionId,"aria-labelledby":r.titleId,"data-state":qfA(r.open),...s,ref:g,onDismiss:()=>r.onOpenChange(!1)})}),W.jsxs(W.Fragment,{children:[W.jsx(Q9t,{titleId:r.titleId}),W.jsx(E9t,{contentRef:a,descriptionId:r.descriptionId})]})]})}),PfA="DialogTitle",iIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Iw(PfA,e);return W.jsx(qa.h2,{id:n.titleId,...i,ref:A})});iIe.displayName=PfA;var nIe="DialogDescription",oIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Iw(nIe,e);return W.jsx(qa.p,{id:n.descriptionId,...i,ref:A})});oIe.displayName=nIe;var sIe="DialogClose",rIe=V.forwardRef((t,A)=>{const{__scopeDialog:e,...i}=t,n=Iw(sIe,e);return W.jsx(qa.button,{type:"button",...i,ref:A,onClick:Hn(t.onClick,()=>n.onOpenChange(!1))})});rIe.displayName=sIe;function qfA(t){return t?"open":"closed"}var aIe="DialogTitleWarning",[C9t,gIe]=LXe(aIe,{contentName:GG,titleName:PfA,docsSlug:"dialog"}),Q9t=({titleId:t})=>{const A=gIe(aIe),e=`\`${A.contentName}\` requires a \`${A.titleName}\` for the component to be accessible for screen reader users.
|
|
5690
5690
|
|
|
5691
5691
|
If you want to hide the \`${A.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
5692
5692
|
|