@tscircuit/pcb-viewer 1.9.2 → 1.10.0

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/index.js CHANGED
@@ -11455,20 +11455,20 @@ var require_dist3 = __commonJS({
11455
11455
  });
11456
11456
  module2.exports = __toCommonJS2(src_exports2);
11457
11457
  var import_transformation_matrix10 = require("transformation-matrix");
11458
- var import_react19 = require("react");
11458
+ var import_react20 = require("react");
11459
11459
  var useMouseMatrixTransform2 = function() {
11460
11460
  var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
11461
- var extRef = (0, import_react19.useRef)(null);
11462
- var _ref = _sliced_to_array((0, import_react19.useState)(0), 2), lastDragCancelTime = _ref[0], setLastDragCancelTime = _ref[1];
11461
+ var extRef = (0, import_react20.useRef)(null);
11462
+ var _ref = _sliced_to_array((0, import_react20.useState)(0), 2), lastDragCancelTime = _ref[0], setLastDragCancelTime = _ref[1];
11463
11463
  var _props_canvasElm;
11464
11464
  var outerCanvasElm = (_props_canvasElm = props.canvasElm) !== null && _props_canvasElm !== void 0 ? _props_canvasElm : extRef.current;
11465
11465
  var _props_initialTransform;
11466
- var _ref1 = _sliced_to_array((0, import_react19.useState)((_props_initialTransform = props.initialTransform) !== null && _props_initialTransform !== void 0 ? _props_initialTransform : (0, import_transformation_matrix10.identity)()), 2), internalTransform = _ref1[0], setInternalTransform = _ref1[1];
11467
- var _ref2 = _sliced_to_array((0, import_react19.useState)(0), 2), waitCounter = _ref2[0], setWaitCounter = _ref2[1];
11468
- var _ref3 = _sliced_to_array((0, import_react19.useReducer)(function(s) {
11466
+ var _ref1 = _sliced_to_array((0, import_react20.useState)((_props_initialTransform = props.initialTransform) !== null && _props_initialTransform !== void 0 ? _props_initialTransform : (0, import_transformation_matrix10.identity)()), 2), internalTransform = _ref1[0], setInternalTransform = _ref1[1];
11467
+ var _ref2 = _sliced_to_array((0, import_react20.useState)(0), 2), waitCounter = _ref2[0], setWaitCounter = _ref2[1];
11468
+ var _ref3 = _sliced_to_array((0, import_react20.useReducer)(function(s) {
11469
11469
  return s + 1;
11470
11470
  }, 0), 2), extChangeCounter = _ref3[0], incExtChangeCounter = _ref3[1];
11471
- var setTransform = (0, import_react19.useCallback)(function(newTransform) {
11471
+ var setTransform = (0, import_react20.useCallback)(function(newTransform) {
11472
11472
  if (props.onSetTransform) {
11473
11473
  props.onSetTransform(newTransform);
11474
11474
  }
@@ -11479,7 +11479,7 @@ var require_dist3 = __commonJS({
11479
11479
  props.onSetTransform,
11480
11480
  setInternalTransform
11481
11481
  ]);
11482
- var setTransformExt = (0, import_react19.useCallback)(function(newTransform) {
11482
+ var setTransformExt = (0, import_react20.useCallback)(function(newTransform) {
11483
11483
  setTransform(newTransform);
11484
11484
  incExtChangeCounter();
11485
11485
  }, [
@@ -11487,10 +11487,10 @@ var require_dist3 = __commonJS({
11487
11487
  ]);
11488
11488
  var _props_transform;
11489
11489
  var transform = (_props_transform = props.transform) !== null && _props_transform !== void 0 ? _props_transform : internalTransform;
11490
- var cancelDrag = (0, import_react19.useCallback)(function() {
11490
+ var cancelDrag = (0, import_react20.useCallback)(function() {
11491
11491
  setLastDragCancelTime(Date.now());
11492
11492
  }, []);
11493
- (0, import_react19.useEffect)(function() {
11493
+ (0, import_react20.useEffect)(function() {
11494
11494
  var handleMouseDown = function handleMouseDown(e) {
11495
11495
  m0 = getMousePos(e);
11496
11496
  if (Date.now() - lastDragCancelTime < 100) return;
@@ -11582,7 +11582,7 @@ var require_dist3 = __commonJS({
11582
11582
  extChangeCounter,
11583
11583
  lastDragCancelTime
11584
11584
  ]);
11585
- var applyTransformToPoint = (0, import_react19.useCallback)(function(obj) {
11585
+ var applyTransformToPoint = (0, import_react20.useCallback)(function(obj) {
11586
11586
  return (0, import_transformation_matrix10.applyToPoint)(transform, obj);
11587
11587
  }, [
11588
11588
  transform
@@ -11613,236 +11613,14 @@ __export(src_exports, {
11613
11613
  });
11614
11614
  module.exports = __toCommonJS(src_exports);
11615
11615
  // src/PCBViewer.tsx
11616
- var import_react18 = require("react");
11616
+ var import_react19 = require("react");
11617
11617
  var import_react_fiber = require("@tscircuit/react-fiber");
11618
11618
  var import_builder2 = require("@tscircuit/builder");
11619
+ // src/components/CanvasElementsRenderer.tsx
11620
+ var import_react15 = require("react");
11619
11621
  // src/components/CanvasPrimitiveRenderer.tsx
11620
11622
  var import_react_supergrid = require("react-supergrid");
11621
11623
  var import_react4 = require("react");
11622
- // src/assets/alphabet.ts
11623
- var svgAlphabet = {
11624
- "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",
11625
- "1": "M 0.198 0.272 L 0.537 0 L 0.54 1",
11626
- "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",
11627
- "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",
11628
- "4": "M0.7328897338403042 0L0 0.6684672518568535L1 0.6684672518568535M0.7243346007604563 0.4530722484807562L0.7243346007604563 1",
11629
- "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",
11630
- "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",
11631
- "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",
11632
- "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",
11633
- "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",
11634
- A: "M0 1L0.4808333333333333 0L1 1M0.24250000000000002 0.6099439775910365L0.7341666666666666 0.6099439775910365",
11635
- 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",
11636
- 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",
11637
- 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",
11638
- E: "M0 0L0 1M0 0L1 0M0 0.5L0.7 0.5M0 1L1 1",
11639
- F: "M0 0L0 1M0.011363636363636364 0.006802721088435374L1 0.006802721088435374M0.011363636363636364 0.4965986394557823L0.8409090909090909 0.4965986394557823",
11640
- 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",
11641
- H: "M0 0L0 1M0 0.4788732394366197L0.989010989010989 0.4788732394366197M1 0L1 1",
11642
- I: "M0.5 0L0.5 1",
11643
- 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",
11644
- K: "M0 0L0 1M0.8787878787878788 0.06666666666666667L0 0.6148148148148148M0.3333333333333333 0.45925925925925926L1 0.9777777777777777",
11645
- L: "M0 0L0 1L1 1",
11646
- M: "M0 1L0 0L0.5 0.6512L1 0L1 1",
11647
- N: "M0 1L0 0L1 1L0.9803729146221786 0",
11648
- 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",
11649
- 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",
11650
- 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",
11651
- 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",
11652
- 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",
11653
- T: "M0 0L1 0M0.5148514851485149 0L0.5148514851485149 1",
11654
- 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",
11655
- V: "M0 0L0.5348837209302325 1L1 0",
11656
- W: "M0 0L0.23300090661831369 0.9873417721518988L0.49954669084315495 0.30081906180193585L0.7851314596554849 1L1 0.0215934475055845",
11657
- X: "M0 0L0.9893617021276596 1M1 0L0.010638297872340425 1",
11658
- Y: "M0 0L0.4860515021459227 0.44712562100780695M1 0.0014194464158977947L0.48927038626609437 0.44996451383960256L0.5075107296137339 1",
11659
- Z: "M0 0L1 0L0 1L1 1",
11660
- ".": "M 0.49 1 L 0.41 1",
11661
- "*": "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",
11662
- "(": "M0.75 0L0.25 0.5L0.25 0.5L0.75 1",
11663
- ")": "M0.25 0L0.75 0.5L0.75 0.5L0.25 1",
11664
- "-": "M0 0.5L1 0.5",
11665
- "+": "M 0 0.5 L 1 0.5 M 0.5 0.125 L 0.5 0.875",
11666
- "=": "M0 0.25L1 0.25M0 0.75L1 0.75",
11667
- _: "M0 1 L1 1",
11668
- "[": "M0.75 0L0.25 0L0.25 1L0.75 1",
11669
- "]": "M0.25 0L0.75 0L0.75 1L0.25 1",
11670
- "<": "M0.75 0L0.25 0.5L0.25 0.5L0.75 1",
11671
- ">": "M0.25 0L0.75 0.5L0.75 0.5L0.25 1",
11672
- "'": "M 0.5 0 L 0.5 0.5",
11673
- '"': "M 0.25 0 L 0.25 0.5 M 0.75 0 L 0.75 0.5"
11674
- };
11675
- var lineAlphabet = {};
11676
- for(var letter in svgAlphabet)_loop(letter);
11677
- // src/lib/convert-text-to-lines.ts
11678
- var LETTER_HEIGHT_TO_WIDTH_RATIO = 0.6;
11679
- var LETTER_HEIGHT_TO_SPACE_RATIO = 0.2;
11680
- var getTextWidth = function(text) {
11681
- return text.text.length * text.size * LETTER_HEIGHT_TO_WIDTH_RATIO + (text.text.length - 1) * text.size * LETTER_HEIGHT_TO_SPACE_RATIO;
11682
- };
11683
- var convertTextToLines = function(text) {
11684
- var strokeWidth = text.size / 8;
11685
- var letterWidth = text.size * LETTER_HEIGHT_TO_WIDTH_RATIO;
11686
- var letterSpace = text.size * LETTER_HEIGHT_TO_SPACE_RATIO;
11687
- var lines = [];
11688
- for(var letterIndex = 0; letterIndex < text.text.length; letterIndex++){
11689
- var letter = text.text[letterIndex];
11690
- var letterLines = lineAlphabet[letter.toUpperCase()];
11691
- if (!letterLines) continue;
11692
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
11693
- try {
11694
- for(var _iterator = letterLines[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
11695
- var _step_value = _step.value, x1 = _step_value.x1, y1 = _step_value.y1, x2 = _step_value.x2, y2 = _step_value.y2;
11696
- lines.push({
11697
- pcb_drawing_type: "line",
11698
- x1: text.x + (letterWidth + letterSpace) * letterIndex + letterWidth * x1,
11699
- y1: text.y + text.size * y1,
11700
- x2: text.x + (letterWidth + letterSpace) * letterIndex + letterWidth * x2,
11701
- y2: text.y + text.size * y2,
11702
- width: strokeWidth,
11703
- layer: text.layer,
11704
- unit: text.unit
11705
- });
11706
- }
11707
- } catch (err) {
11708
- _didIteratorError = true;
11709
- _iteratorError = err;
11710
- } finally{
11711
- try {
11712
- if (!_iteratorNormalCompletion && _iterator.return != null) {
11713
- _iterator.return();
11714
- }
11715
- } finally{
11716
- if (_didIteratorError) {
11717
- throw _iteratorError;
11718
- }
11719
- }
11720
- }
11721
- }
11722
- return lines;
11723
- };
11724
- // src/lib/draw-primitives.ts
11725
- var drawLine = function(drawer, line) {
11726
- drawer.equip({
11727
- size: line.zoomIndependent ? line.width / drawer.transform.a : line.width,
11728
- shape: line.squareCap ? "square" : "circle",
11729
- color: line.layer
11730
- });
11731
- drawer.moveTo(line.x1, line.y1);
11732
- drawer.lineTo(line.x2, line.y2);
11733
- };
11734
- var drawText = function(drawer, text) {
11735
- drawer.equip({
11736
- fontSize: text.size,
11737
- color: text.layer
11738
- });
11739
- var alignOffset = {
11740
- x: 0,
11741
- y: 0
11742
- };
11743
- var textWidth = getTextWidth(text);
11744
- var textHeight = text.size;
11745
- if (text.align === "top_left") {
11746
- alignOffset.y = -textHeight;
11747
- } else if (text.align === "bottom_right") {
11748
- alignOffset.x = -textWidth;
11749
- } else if (text.align === "top_right") {
11750
- alignOffset.x = -textWidth;
11751
- alignOffset.y = -textHeight;
11752
- } else if (text.align === "center") {
11753
- alignOffset.x = -textWidth / 2;
11754
- alignOffset.y = -textHeight / 2;
11755
- }
11756
- var _text_x;
11757
- (_text_x = text.x) !== null && _text_x !== void 0 ? _text_x : text.x = 0;
11758
- var _text_y;
11759
- (_text_y = text.y) !== null && _text_y !== void 0 ? _text_y : text.y = 0;
11760
- var text_lines = convertTextToLines(_object_spread_props(_object_spread({}, text), {
11761
- x: text.x + alignOffset.x,
11762
- y: text.y + alignOffset.y
11763
- }));
11764
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
11765
- try {
11766
- for(var _iterator = text_lines[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
11767
- var line = _step.value;
11768
- drawLine(drawer, line);
11769
- }
11770
- } catch (err) {
11771
- _didIteratorError = true;
11772
- _iteratorError = err;
11773
- } finally{
11774
- try {
11775
- if (!_iteratorNormalCompletion && _iterator.return != null) {
11776
- _iterator.return();
11777
- }
11778
- } finally{
11779
- if (_didIteratorError) {
11780
- throw _iteratorError;
11781
- }
11782
- }
11783
- }
11784
- };
11785
- var drawRect = function(drawer, rect) {
11786
- drawer.equip({
11787
- color: rect.layer
11788
- });
11789
- drawer.rect(rect.x, rect.y, rect.w, rect.h, rect.mesh_fill);
11790
- };
11791
- var drawCircle = function(drawer, circle) {
11792
- drawer.equip({
11793
- color: circle.layer
11794
- });
11795
- drawer.circle(circle.x, circle.y, circle.r, circle.mesh_fill);
11796
- };
11797
- var drawOval = function(drawer, oval) {
11798
- drawer.equip({
11799
- color: oval.layer
11800
- });
11801
- drawer.oval(oval.x, oval.y, oval.rX, oval.rY);
11802
- };
11803
- var drawPill = function(drawer, pill) {
11804
- drawer.equip({
11805
- color: pill.layer
11806
- });
11807
- drawer.pill(pill.x, pill.y, pill.w, pill.h);
11808
- };
11809
- var drawPolygon = function(drawer, polygon) {
11810
- drawer.equip({
11811
- color: polygon.layer
11812
- });
11813
- drawer.polygon(polygon.points);
11814
- };
11815
- var drawPrimitive = function(drawer, primitive) {
11816
- switch(primitive.pcb_drawing_type){
11817
- case "line":
11818
- return drawLine(drawer, primitive);
11819
- case "text":
11820
- return drawText(drawer, primitive);
11821
- case "rect":
11822
- return drawRect(drawer, primitive);
11823
- case "circle":
11824
- return drawCircle(drawer, primitive);
11825
- case "oval":
11826
- return drawOval(drawer, primitive);
11827
- case "pill":
11828
- return drawPill(drawer, primitive);
11829
- case "polygon":
11830
- return drawPolygon(drawer, primitive);
11831
- }
11832
- };
11833
- var drawPrimitives = function(drawer, primitives) {
11834
- primitives.sort(function(a, b) {
11835
- var layerOrder = [
11836
- "bottom",
11837
- "top",
11838
- "drill"
11839
- ];
11840
- return layerOrder.indexOf(a.layer) - layerOrder.indexOf(b.layer);
11841
- });
11842
- primitives.forEach(function(primitive) {
11843
- return drawPrimitive(drawer, primitive);
11844
- });
11845
- };
11846
11624
  // src/lib/Drawer.ts
11847
11625
  var import_transformation_matrix = require("transformation-matrix");
11848
11626
  // src/lib/colors.ts
@@ -12088,7 +11866,7 @@ var LAYER_NAME_TO_COLOR = _object_spread({
12088
11866
  red: "red",
12089
11867
  black: "black",
12090
11868
  green: "green",
12091
- board: "white",
11869
+ board: "rgb(255, 255, 255)",
12092
11870
  other: "#eee",
12093
11871
  // TODO more builtin html colors
12094
11872
  // Common eagle names
@@ -12390,9 +12168,9 @@ var Drawer = /*#__PURE__*/ function() {
12390
12168
  key: "applyAperture",
12391
12169
  value: function applyAperture() {
12392
12170
  var _this = this, transform = _this.transform, aperture = _this.aperture;
12393
- var size = aperture.size, mode = aperture.mode, color = aperture.color, fontSize = aperture.fontSize;
12394
- if (color in this.ctxLayerMap) {
12395
- this.aperture.layer = color;
12171
+ var size = aperture.size, mode = aperture.mode, color2 = aperture.color, fontSize = aperture.fontSize;
12172
+ if (color2 in this.ctxLayerMap) {
12173
+ this.aperture.layer = color2;
12396
12174
  } else {
12397
12175
  this.aperture.layer = "other";
12398
12176
  }
@@ -12400,13 +12178,13 @@ var Drawer = /*#__PURE__*/ function() {
12400
12178
  if (!ctx) {
12401
12179
  throw new Error('No context for layer "'.concat(this.foregroundLayer, '"'));
12402
12180
  }
12403
- if (!color) color = "undefined";
12181
+ if (!color2) color2 = "undefined";
12404
12182
  ctx.lineWidth = scaleOnly(transform, size);
12405
12183
  ctx.lineCap = "round";
12406
12184
  if (mode === "add") {
12407
- var colorString = (color === null || color === void 0 ? void 0 : color[0]) === "#" || (color === null || color === void 0 ? void 0 : color.startsWith("rgb")) ? color : LAYER_NAME_TO_COLOR[color === null || color === void 0 ? void 0 : color.toLowerCase()] ? LAYER_NAME_TO_COLOR[color === null || color === void 0 ? void 0 : color.toLowerCase()] : null;
12185
+ var colorString = (color2 === null || color2 === void 0 ? void 0 : color2[0]) === "#" || (color2 === null || color2 === void 0 ? void 0 : color2.startsWith("rgb")) ? color2 : LAYER_NAME_TO_COLOR[color2 === null || color2 === void 0 ? void 0 : color2.toLowerCase()] ? LAYER_NAME_TO_COLOR[color2 === null || color2 === void 0 ? void 0 : color2.toLowerCase()] : null;
12408
12186
  if (colorString === null) {
12409
- console.warn('Color mapping for "'.concat(color, '" not found'));
12187
+ console.warn('Color mapping for "'.concat(color2, '" not found'));
12410
12188
  colorString = "white";
12411
12189
  }
12412
12190
  ctx.fillStyle = colorString;
@@ -12457,6 +12235,243 @@ var Drawer = /*#__PURE__*/ function() {
12457
12235
  ]);
12458
12236
  return Drawer;
12459
12237
  }();
12238
+ // src/assets/alphabet.ts
12239
+ var svgAlphabet = {
12240
+ "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",
12241
+ "1": "M 0.198 0.272 L 0.537 0 L 0.54 1",
12242
+ "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",
12243
+ "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",
12244
+ "4": "M0.7328897338403042 0L0 0.6684672518568535L1 0.6684672518568535M0.7243346007604563 0.4530722484807562L0.7243346007604563 1",
12245
+ "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",
12246
+ "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",
12247
+ "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",
12248
+ "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",
12249
+ "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",
12250
+ A: "M0 1L0.4808333333333333 0L1 1M0.24250000000000002 0.6099439775910365L0.7341666666666666 0.6099439775910365",
12251
+ 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",
12252
+ 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",
12253
+ 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",
12254
+ E: "M0 0L0 1M0 0L1 0M0 0.5L0.7 0.5M0 1L1 1",
12255
+ F: "M0 0L0 1M0.011363636363636364 0.006802721088435374L1 0.006802721088435374M0.011363636363636364 0.4965986394557823L0.8409090909090909 0.4965986394557823",
12256
+ 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",
12257
+ H: "M0 0L0 1M0 0.4788732394366197L0.989010989010989 0.4788732394366197M1 0L1 1",
12258
+ I: "M0.5 0L0.5 1",
12259
+ 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",
12260
+ K: "M0 0L0 1M0.8787878787878788 0.06666666666666667L0 0.6148148148148148M0.3333333333333333 0.45925925925925926L1 0.9777777777777777",
12261
+ L: "M0 0L0 1L1 1",
12262
+ M: "M0 1L0 0L0.5 0.6512L1 0L1 1",
12263
+ N: "M0 1L0 0L1 1L0.9803729146221786 0",
12264
+ 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",
12265
+ 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",
12266
+ 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",
12267
+ 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",
12268
+ 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",
12269
+ T: "M0 0L1 0M0.5148514851485149 0L0.5148514851485149 1",
12270
+ 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",
12271
+ V: "M0 0L0.5348837209302325 1L1 0",
12272
+ W: "M0 0L0.23300090661831369 0.9873417721518988L0.49954669084315495 0.30081906180193585L0.7851314596554849 1L1 0.0215934475055845",
12273
+ X: "M0 0L0.9893617021276596 1M1 0L0.010638297872340425 1",
12274
+ Y: "M0 0L0.4860515021459227 0.44712562100780695M1 0.0014194464158977947L0.48927038626609437 0.44996451383960256L0.5075107296137339 1",
12275
+ Z: "M0 0L1 0L0 1L1 1",
12276
+ ".": "M 0.49 1 L 0.41 1",
12277
+ "*": "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",
12278
+ "(": "M0.75 0L0.25 0.5L0.25 0.5L0.75 1",
12279
+ ")": "M0.25 0L0.75 0.5L0.75 0.5L0.25 1",
12280
+ "-": "M0 0.5L1 0.5",
12281
+ "+": "M 0 0.5 L 1 0.5 M 0.5 0.125 L 0.5 0.875",
12282
+ "=": "M0 0.25L1 0.25M0 0.75L1 0.75",
12283
+ _: "M0 1 L1 1",
12284
+ "[": "M0.75 0L0.25 0L0.25 1L0.75 1",
12285
+ "]": "M0.25 0L0.75 0L0.75 1L0.25 1",
12286
+ "<": "M0.75 0L0.25 0.5L0.25 0.5L0.75 1",
12287
+ ">": "M0.25 0L0.75 0.5L0.75 0.5L0.25 1",
12288
+ "'": "M 0.5 0 L 0.5 0.5",
12289
+ '"': "M 0.25 0 L 0.25 0.5 M 0.75 0 L 0.75 0.5"
12290
+ };
12291
+ var lineAlphabet = {};
12292
+ for(var letter in svgAlphabet)_loop(letter);
12293
+ // src/lib/convert-text-to-lines.ts
12294
+ var LETTER_HEIGHT_TO_WIDTH_RATIO = 0.6;
12295
+ var LETTER_HEIGHT_TO_SPACE_RATIO = 0.2;
12296
+ var getTextWidth = function(text) {
12297
+ return text.text.length * text.size * LETTER_HEIGHT_TO_WIDTH_RATIO + (text.text.length - 1) * text.size * LETTER_HEIGHT_TO_SPACE_RATIO;
12298
+ };
12299
+ var convertTextToLines = function(text) {
12300
+ var strokeWidth = text.size / 8;
12301
+ var letterWidth = text.size * LETTER_HEIGHT_TO_WIDTH_RATIO;
12302
+ var letterSpace = text.size * LETTER_HEIGHT_TO_SPACE_RATIO;
12303
+ var lines = [];
12304
+ for(var letterIndex = 0; letterIndex < text.text.length; letterIndex++){
12305
+ var letter = text.text[letterIndex];
12306
+ var letterLines = lineAlphabet[letter.toUpperCase()];
12307
+ if (!letterLines) continue;
12308
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
12309
+ try {
12310
+ for(var _iterator = letterLines[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
12311
+ var _step_value = _step.value, x1 = _step_value.x1, y1 = _step_value.y1, x2 = _step_value.x2, y2 = _step_value.y2;
12312
+ lines.push({
12313
+ pcb_drawing_type: "line",
12314
+ x1: text.x + (letterWidth + letterSpace) * letterIndex + letterWidth * x1,
12315
+ y1: text.y + text.size * y1,
12316
+ x2: text.x + (letterWidth + letterSpace) * letterIndex + letterWidth * x2,
12317
+ y2: text.y + text.size * y2,
12318
+ width: strokeWidth,
12319
+ layer: text.layer,
12320
+ unit: text.unit
12321
+ });
12322
+ }
12323
+ } catch (err) {
12324
+ _didIteratorError = true;
12325
+ _iteratorError = err;
12326
+ } finally{
12327
+ try {
12328
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
12329
+ _iterator.return();
12330
+ }
12331
+ } finally{
12332
+ if (_didIteratorError) {
12333
+ throw _iteratorError;
12334
+ }
12335
+ }
12336
+ }
12337
+ }
12338
+ return lines;
12339
+ };
12340
+ // src/lib/draw-primitives.ts
12341
+ var import_color = __toESM(require("color"));
12342
+ function getColor(primitive) {
12343
+ if (primitive.is_mouse_over || primitive.is_in_highlighted_net) {
12344
+ return (0, import_color.default)(LAYER_NAME_TO_COLOR[primitive.layer]).lighten(0.5).rgb().toString();
12345
+ }
12346
+ return LAYER_NAME_TO_COLOR[primitive.layer];
12347
+ }
12348
+ var drawLine = function(drawer, line) {
12349
+ drawer.equip({
12350
+ size: line.zoomIndependent ? line.width / drawer.transform.a : line.width,
12351
+ shape: line.squareCap ? "square" : "circle",
12352
+ color: getColor(line),
12353
+ layer: line.layer
12354
+ });
12355
+ drawer.moveTo(line.x1, line.y1);
12356
+ drawer.lineTo(line.x2, line.y2);
12357
+ };
12358
+ var drawText = function(drawer, text) {
12359
+ drawer.equip({
12360
+ fontSize: text.size,
12361
+ color: text.layer
12362
+ });
12363
+ var alignOffset = {
12364
+ x: 0,
12365
+ y: 0
12366
+ };
12367
+ var textWidth = getTextWidth(text);
12368
+ var textHeight = text.size;
12369
+ if (text.align === "top_left") {
12370
+ alignOffset.y = -textHeight;
12371
+ } else if (text.align === "bottom_right") {
12372
+ alignOffset.x = -textWidth;
12373
+ } else if (text.align === "top_right") {
12374
+ alignOffset.x = -textWidth;
12375
+ alignOffset.y = -textHeight;
12376
+ } else if (text.align === "center") {
12377
+ alignOffset.x = -textWidth / 2;
12378
+ alignOffset.y = -textHeight / 2;
12379
+ }
12380
+ var _text_x;
12381
+ (_text_x = text.x) !== null && _text_x !== void 0 ? _text_x : text.x = 0;
12382
+ var _text_y;
12383
+ (_text_y = text.y) !== null && _text_y !== void 0 ? _text_y : text.y = 0;
12384
+ var text_lines = convertTextToLines(_object_spread_props(_object_spread({}, text), {
12385
+ x: text.x + alignOffset.x,
12386
+ y: text.y + alignOffset.y
12387
+ }));
12388
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
12389
+ try {
12390
+ for(var _iterator = text_lines[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
12391
+ var line = _step.value;
12392
+ drawLine(drawer, line);
12393
+ }
12394
+ } catch (err) {
12395
+ _didIteratorError = true;
12396
+ _iteratorError = err;
12397
+ } finally{
12398
+ try {
12399
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
12400
+ _iterator.return();
12401
+ }
12402
+ } finally{
12403
+ if (_didIteratorError) {
12404
+ throw _iteratorError;
12405
+ }
12406
+ }
12407
+ }
12408
+ };
12409
+ var drawRect = function(drawer, rect) {
12410
+ drawer.equip({
12411
+ color: getColor(rect),
12412
+ layer: rect.layer
12413
+ });
12414
+ drawer.rect(rect.x, rect.y, rect.w, rect.h, rect.mesh_fill);
12415
+ };
12416
+ var drawCircle = function(drawer, circle) {
12417
+ drawer.equip({
12418
+ color: getColor(circle),
12419
+ layer: circle.layer
12420
+ });
12421
+ drawer.circle(circle.x, circle.y, circle.r, circle.mesh_fill);
12422
+ };
12423
+ var drawOval = function(drawer, oval) {
12424
+ drawer.equip({
12425
+ color: getColor(oval),
12426
+ layer: oval.layer
12427
+ });
12428
+ drawer.oval(oval.x, oval.y, oval.rX, oval.rY);
12429
+ };
12430
+ var drawPill = function(drawer, pill) {
12431
+ drawer.equip({
12432
+ color: getColor(pill),
12433
+ layer: pill.layer
12434
+ });
12435
+ drawer.pill(pill.x, pill.y, pill.w, pill.h);
12436
+ };
12437
+ var drawPolygon = function(drawer, polygon) {
12438
+ drawer.equip({
12439
+ color: getColor(polygon),
12440
+ layer: polygon.layer
12441
+ });
12442
+ drawer.polygon(polygon.points);
12443
+ };
12444
+ var drawPrimitive = function(drawer, primitive) {
12445
+ switch(primitive.pcb_drawing_type){
12446
+ case "line":
12447
+ return drawLine(drawer, primitive);
12448
+ case "text":
12449
+ return drawText(drawer, primitive);
12450
+ case "rect":
12451
+ return drawRect(drawer, primitive);
12452
+ case "circle":
12453
+ return drawCircle(drawer, primitive);
12454
+ case "oval":
12455
+ return drawOval(drawer, primitive);
12456
+ case "pill":
12457
+ return drawPill(drawer, primitive);
12458
+ case "polygon":
12459
+ return drawPolygon(drawer, primitive);
12460
+ }
12461
+ };
12462
+ var drawPrimitives = function(drawer, primitives) {
12463
+ primitives.sort(function(a, b) {
12464
+ var layerOrder = [
12465
+ "bottom",
12466
+ "top",
12467
+ "drill"
12468
+ ];
12469
+ return layerOrder.indexOf(a.layer) - layerOrder.indexOf(b.layer);
12470
+ });
12471
+ primitives.forEach(function(primitive) {
12472
+ return drawPrimitive(drawer, primitive);
12473
+ });
12474
+ };
12460
12475
  // src/global-store.ts
12461
12476
  var import_zustand = require("zustand");
12462
12477
  // src/components/ContextProviders.tsx
@@ -12594,7 +12609,7 @@ var CanvasPrimitiveRenderer = function(param) {
12594
12609
  });
12595
12610
  };
12596
12611
  // src/components/CanvasElementsRenderer.tsx
12597
- var import_react15 = require("react");
12612
+ var import_react16 = require("react");
12598
12613
  // src/lib/convert-element-to-primitive.ts
12599
12614
  var import_soup_util = __toESM(require_dist2());
12600
12615
  // src/lib/util/expand-stroke.ts
@@ -12676,6 +12691,7 @@ function getExpandedStroke(strokeInput, defaultWidth) {
12676
12691
  return _to_consumable_array(leftSide).concat(_to_consumable_array(rightSide));
12677
12692
  }
12678
12693
  // src/lib/convert-element-to-primitive.ts
12694
+ var globalPcbDrawingObjectCount = 0;
12679
12695
  var convertElementToPrimitives = function(element, allElements) {
12680
12696
  var _pcb_port_get;
12681
12697
  var _parent_pcb_component = "pcb_component_id" in element ? allElements.find(function(elm) {
@@ -12695,6 +12711,7 @@ var convertElementToPrimitives = function(element, allElements) {
12695
12711
  if (outline && outline.length > 2) {
12696
12712
  return outline.map(function(point, index, array) {
12697
12713
  return {
12714
+ _pcb_drawing_object_id: "line_".concat(globalPcbDrawingObjectCount++),
12698
12715
  pcb_drawing_type: "line",
12699
12716
  x1: point.x,
12700
12717
  y1: point.y,
@@ -12710,6 +12727,7 @@ var convertElementToPrimitives = function(element, allElements) {
12710
12727
  }
12711
12728
  return [
12712
12729
  {
12730
+ _pcb_drawing_object_id: "line_".concat(globalPcbDrawingObjectCount++),
12713
12731
  pcb_drawing_type: "line",
12714
12732
  x1: center.x - width / 2,
12715
12733
  y1: center.y - height / 2,
@@ -12722,6 +12740,7 @@ var convertElementToPrimitives = function(element, allElements) {
12722
12740
  _element: element
12723
12741
  },
12724
12742
  {
12743
+ _pcb_drawing_object_id: "line_".concat(globalPcbDrawingObjectCount++),
12725
12744
  pcb_drawing_type: "line",
12726
12745
  x1: center.x - width / 2,
12727
12746
  y1: center.y + height / 2,
@@ -12734,6 +12753,7 @@ var convertElementToPrimitives = function(element, allElements) {
12734
12753
  _element: element
12735
12754
  },
12736
12755
  {
12756
+ _pcb_drawing_object_id: "line_".concat(globalPcbDrawingObjectCount++),
12737
12757
  pcb_drawing_type: "line",
12738
12758
  x1: center.x - width / 2,
12739
12759
  y1: center.y - height / 2,
@@ -12746,6 +12766,7 @@ var convertElementToPrimitives = function(element, allElements) {
12746
12766
  _element: element
12747
12767
  },
12748
12768
  {
12769
+ _pcb_drawing_object_id: "line_".concat(globalPcbDrawingObjectCount++),
12749
12770
  pcb_drawing_type: "line",
12750
12771
  x1: center.x + width / 2,
12751
12772
  y1: center.y - height / 2,
@@ -12765,6 +12786,7 @@ var convertElementToPrimitives = function(element, allElements) {
12765
12786
  var shape = element.shape, x = element.x, y = element.y, width1 = element.width, height1 = element.height, layer = element.layer;
12766
12787
  return [
12767
12788
  {
12789
+ _pcb_drawing_object_id: "rect_".concat(globalPcbDrawingObjectCount++),
12768
12790
  pcb_drawing_type: "rect",
12769
12791
  x: x,
12770
12792
  y: y,
@@ -12781,6 +12803,7 @@ var convertElementToPrimitives = function(element, allElements) {
12781
12803
  var x1 = element.x, y1 = element.y, radius = element.radius, layer1 = element.layer;
12782
12804
  return [
12783
12805
  {
12806
+ _pcb_drawing_object_id: "circle_".concat(globalPcbDrawingObjectCount++),
12784
12807
  pcb_drawing_type: "circle",
12785
12808
  x: x1,
12786
12809
  y: y1,
@@ -12801,12 +12824,12 @@ var convertElementToPrimitives = function(element, allElements) {
12801
12824
  var x2 = element.x, y2 = element.y, hole_diameter = element.hole_diameter;
12802
12825
  return [
12803
12826
  {
12827
+ _pcb_drawing_object_id: "circle_".concat(globalPcbDrawingObjectCount++),
12804
12828
  pcb_drawing_type: "circle",
12805
12829
  x: x2,
12806
12830
  y: y2,
12807
12831
  r: hole_diameter / 2,
12808
12832
  layer: "drill",
12809
- _element: element,
12810
12833
  _parent_pcb_component: _parent_pcb_component,
12811
12834
  _parent_source_component: _parent_source_component
12812
12835
  }
@@ -12820,6 +12843,7 @@ var convertElementToPrimitives = function(element, allElements) {
12820
12843
  var x3 = element.x, y3 = element.y, hole_diameter1 = element.hole_diameter, outer_diameter = element.outer_diameter;
12821
12844
  return [
12822
12845
  {
12846
+ _pcb_drawing_object_id: "circle_".concat(globalPcbDrawingObjectCount++),
12823
12847
  pcb_drawing_type: "circle",
12824
12848
  x: x3,
12825
12849
  y: y3,
@@ -12832,6 +12856,7 @@ var convertElementToPrimitives = function(element, allElements) {
12832
12856
  _source_port: _source_port
12833
12857
  },
12834
12858
  {
12859
+ _pcb_drawing_object_id: "circle_".concat(globalPcbDrawingObjectCount++),
12835
12860
  pcb_drawing_type: "circle",
12836
12861
  x: x3,
12837
12862
  y: y3,
@@ -12844,6 +12869,7 @@ var convertElementToPrimitives = function(element, allElements) {
12844
12869
  var x4 = element.x, y4 = element.y, outer_height = element.outer_height, outer_width = element.outer_width, hole_height = element.hole_height, hole_width = element.hole_width;
12845
12870
  return [
12846
12871
  {
12872
+ _pcb_drawing_object_id: "oval_".concat(globalPcbDrawingObjectCount++),
12847
12873
  pcb_drawing_type: "oval",
12848
12874
  x: x4,
12849
12875
  y: y4,
@@ -12857,6 +12883,7 @@ var convertElementToPrimitives = function(element, allElements) {
12857
12883
  _source_port: _source_port
12858
12884
  },
12859
12885
  {
12886
+ _pcb_drawing_object_id: "oval_".concat(globalPcbDrawingObjectCount++),
12860
12887
  pcb_drawing_type: "oval",
12861
12888
  x: x4,
12862
12889
  y: y4,
@@ -12869,6 +12896,7 @@ var convertElementToPrimitives = function(element, allElements) {
12869
12896
  var x5 = element.x, y5 = element.y, outer_height1 = element.outer_height, outer_width1 = element.outer_width, hole_height1 = element.hole_height, hole_width1 = element.hole_width;
12870
12897
  return [
12871
12898
  {
12899
+ _pcb_drawing_object_id: "pill_".concat(globalPcbDrawingObjectCount++),
12872
12900
  pcb_drawing_type: "pill",
12873
12901
  x: x5,
12874
12902
  y: y5,
@@ -12882,6 +12910,7 @@ var convertElementToPrimitives = function(element, allElements) {
12882
12910
  _source_port: _source_port
12883
12911
  },
12884
12912
  {
12913
+ _pcb_drawing_object_id: "pill_".concat(globalPcbDrawingObjectCount++),
12885
12914
  pcb_drawing_type: "pill",
12886
12915
  x: x5,
12887
12916
  y: y5,
@@ -12900,6 +12929,7 @@ var convertElementToPrimitives = function(element, allElements) {
12900
12929
  var center1 = element.center, radius1 = element.radius;
12901
12930
  return [
12902
12931
  {
12932
+ _pcb_drawing_object_id: "circle_".concat(globalPcbDrawingObjectCount++),
12903
12933
  pcb_drawing_type: "circle",
12904
12934
  x: center1.x,
12905
12935
  y: center1.y,
@@ -12915,6 +12945,7 @@ var convertElementToPrimitives = function(element, allElements) {
12915
12945
  var x6 = element.x, y6 = element.y, width2 = element.width, height2 = element.height;
12916
12946
  return [
12917
12947
  {
12948
+ _pcb_drawing_object_id: "rect_".concat(globalPcbDrawingObjectCount++),
12918
12949
  pcb_drawing_type: "rect",
12919
12950
  x: x6,
12920
12951
  y: y6,
@@ -12942,6 +12973,8 @@ var convertElementToPrimitives = function(element, allElements) {
12942
12973
  });
12943
12974
  var expandedStroke = getExpandedStroke(strokeInput, 0.5);
12944
12975
  primitives.push({
12976
+ _pcb_drawing_object_id: "polygon_".concat(globalPcbDrawingObjectCount++),
12977
+ _element: element,
12945
12978
  pcb_drawing_type: "polygon",
12946
12979
  points: expandedStroke,
12947
12980
  layer: element.route[0].layer
@@ -12949,6 +12982,8 @@ var convertElementToPrimitives = function(element, allElements) {
12949
12982
  element.route.forEach(function(r) {
12950
12983
  if (r.route_type === "via") {
12951
12984
  primitives.push({
12985
+ _pcb_drawing_object_id: "circle_".concat(globalPcbDrawingObjectCount++),
12986
+ _element: element,
12952
12987
  pcb_drawing_type: "circle",
12953
12988
  x: r.x,
12954
12989
  y: r.y,
@@ -12969,6 +13004,8 @@ var convertElementToPrimitives = function(element, allElements) {
12969
13004
  if (route.route_type === "wire") {
12970
13005
  if (prevX !== null && prevY !== null) {
12971
13006
  primitives.push({
13007
+ _pcb_drawing_object_id: "line_".concat(globalPcbDrawingObjectCount++),
13008
+ _element: element,
12972
13009
  pcb_drawing_type: "line",
12973
13010
  x1: prevX,
12974
13011
  y1: prevY,
@@ -13004,6 +13041,7 @@ var convertElementToPrimitives = function(element, allElements) {
13004
13041
  var x7 = element.x, y7 = element.y, outer_diameter1 = element.outer_diameter, hole_diameter2 = element.hole_diameter, from_layer = element.from_layer, to_layer = element.to_layer;
13005
13042
  return [
13006
13043
  {
13044
+ _pcb_drawing_object_id: "circle_".concat(globalPcbDrawingObjectCount++),
13007
13045
  pcb_drawing_type: "circle",
13008
13046
  x: x7,
13009
13047
  y: y7,
@@ -13014,16 +13052,17 @@ var convertElementToPrimitives = function(element, allElements) {
13014
13052
  _parent_source_component: _parent_source_component
13015
13053
  },
13016
13054
  {
13055
+ _pcb_drawing_object_id: "circle_".concat(globalPcbDrawingObjectCount++),
13017
13056
  pcb_drawing_type: "circle",
13018
13057
  x: x7,
13019
13058
  y: y7,
13020
13059
  r: hole_diameter2 / 2,
13021
13060
  layer: "drill",
13022
- _element: element,
13023
13061
  _parent_pcb_component: _parent_pcb_component,
13024
13062
  _parent_source_component: _parent_source_component
13025
13063
  },
13026
13064
  {
13065
+ _pcb_drawing_object_id: "circle_".concat(globalPcbDrawingObjectCount++),
13027
13066
  pcb_drawing_type: "circle",
13028
13067
  x: x7,
13029
13068
  y: y7,
@@ -13039,6 +13078,7 @@ var convertElementToPrimitives = function(element, allElements) {
13039
13078
  {
13040
13079
  return [
13041
13080
  {
13081
+ _pcb_drawing_object_id: "rect_".concat(globalPcbDrawingObjectCount++),
13042
13082
  pcb_drawing_type: "rect",
13043
13083
  x: element.center.x,
13044
13084
  y: element.center.y,
@@ -13052,6 +13092,7 @@ var convertElementToPrimitives = function(element, allElements) {
13052
13092
  {
13053
13093
  return [
13054
13094
  {
13095
+ _pcb_drawing_object_id: "circle_".concat(globalPcbDrawingObjectCount++),
13055
13096
  pcb_drawing_type: "circle",
13056
13097
  x: element.center.x,
13057
13098
  y: element.center.y,
@@ -13064,6 +13105,7 @@ var convertElementToPrimitives = function(element, allElements) {
13064
13105
  {
13065
13106
  return [
13066
13107
  {
13108
+ _pcb_drawing_object_id: "oval_".concat(globalPcbDrawingObjectCount++),
13067
13109
  pcb_drawing_type: "oval",
13068
13110
  x: element.center.x,
13069
13111
  y: element.center.y,
@@ -13077,6 +13119,7 @@ var convertElementToPrimitives = function(element, allElements) {
13077
13119
  {
13078
13120
  return [
13079
13121
  {
13122
+ _pcb_drawing_object_id: "pill_".concat(globalPcbDrawingObjectCount++),
13080
13123
  pcb_drawing_type: "pill",
13081
13124
  x: element.center.x,
13082
13125
  y: element.center.y,
@@ -13090,6 +13133,7 @@ var convertElementToPrimitives = function(element, allElements) {
13090
13133
  {
13091
13134
  return [
13092
13135
  {
13136
+ _pcb_drawing_object_id: "line_".concat(globalPcbDrawingObjectCount++),
13093
13137
  pcb_drawing_type: "line",
13094
13138
  x1: element.x1,
13095
13139
  y1: element.y1,
@@ -13117,6 +13161,7 @@ var convertElementToPrimitives = function(element, allElements) {
13117
13161
  var nextPoint = route1[index + 1];
13118
13162
  var _element_stroke_width;
13119
13163
  return {
13164
+ _pcb_drawing_object_id: "line_".concat(globalPcbDrawingObjectCount++),
13120
13165
  pcb_drawing_type: "line",
13121
13166
  x1: point.x,
13122
13167
  y1: point.y,
@@ -13137,6 +13182,7 @@ var convertElementToPrimitives = function(element, allElements) {
13137
13182
  var _element_anchor_alignment;
13138
13183
  return [
13139
13184
  {
13185
+ _pcb_drawing_object_id: "text_".concat(globalPcbDrawingObjectCount++),
13140
13186
  pcb_drawing_type: "text",
13141
13187
  x: element.anchor_position.x,
13142
13188
  y: element.anchor_position.y,
@@ -13152,6 +13198,7 @@ var convertElementToPrimitives = function(element, allElements) {
13152
13198
  var _element_anchor_alignment1;
13153
13199
  return [
13154
13200
  {
13201
+ _pcb_drawing_object_id: "text_".concat(globalPcbDrawingObjectCount++),
13155
13202
  pcb_drawing_type: "text",
13156
13203
  x: element.anchor_position.x,
13157
13204
  y: element.anchor_position.y,
@@ -13230,7 +13277,7 @@ var HighlightedPrimitiveBoxWithText = function(param) {
13230
13277
  var si = (_primitive_same_space_index = primitive.same_space_index) !== null && _primitive_same_space_index !== void 0 ? _primitive_same_space_index : 0;
13231
13278
  var sip = 26;
13232
13279
  var _layerColorHightlightMap_primitive__element_layer;
13233
- var color = (_layerColorHightlightMap_primitive__element_layer = layerColorHightlightMap[primitive === null || primitive === void 0 ? void 0 : (_primitive__element = primitive._element) === null || _primitive__element === void 0 ? void 0 : _primitive__element.layer]) !== null && _layerColorHightlightMap_primitive__element_layer !== void 0 ? _layerColorHightlightMap_primitive__element_layer : "red";
13280
+ var color2 = (_layerColorHightlightMap_primitive__element_layer = layerColorHightlightMap[primitive === null || primitive === void 0 ? void 0 : (_primitive__element = primitive._element) === null || _primitive__element === void 0 ? void 0 : _primitive__element.layer]) !== null && _layerColorHightlightMap_primitive__element_layer !== void 0 ? _layerColorHightlightMap_primitive__element_layer : "red";
13234
13281
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", {
13235
13282
  style: {
13236
13283
  position: "absolute",
@@ -13238,7 +13285,7 @@ var HighlightedPrimitiveBoxWithText = function(param) {
13238
13285
  top: y - h / 2 - 8,
13239
13286
  width: w + 16,
13240
13287
  height: h + 16,
13241
- color: color
13288
+ color: color2
13242
13289
  },
13243
13290
  children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", {
13244
13291
  style: {
@@ -13250,7 +13297,7 @@ var HighlightedPrimitiveBoxWithText = function(param) {
13250
13297
  height: finalState ? "calc(100% + ".concat(sip * 2 * si, "px)") : "100%",
13251
13298
  marginLeft: finalState ? "".concat(-sip * si, "px") : 0,
13252
13299
  marginTop: finalState ? "".concat(-sip * si, "px") : 0,
13253
- border: "1px solid ".concat(color),
13300
+ border: "1px solid ".concat(color2),
13254
13301
  opacity: finalState ? 1 : si === 0 ? 1 : 0,
13255
13302
  transition: "width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"
13256
13303
  },
@@ -13283,10 +13330,17 @@ var ElementOverlayBox = function(param) {
13283
13330
  })
13284
13331
  });
13285
13332
  };
13333
+ // src/lib/util/if-sets-match-exactly.ts
13334
+ function ifSetsMatchExactly(set1, set2) {
13335
+ if (set1.size !== set2.size) return false;
13336
+ return Array.from(set1).every(function(item) {
13337
+ return set2.has(item);
13338
+ });
13339
+ }
13286
13340
  // src/components/MouseElementTracker.tsx
13287
13341
  var import_jsx_runtime4 = require("react/jsx-runtime");
13288
13342
  var MouseElementTracker = function(param) {
13289
- var children = param.children, transform = param.transform, primitives = param.primitives;
13343
+ var children = param.children, transform = param.transform, primitives = param.primitives, onMouseHoverOverPrimitives = param.onMouseHoverOverPrimitives;
13290
13344
  var _ref = _sliced_to_array((0, import_react6.useState)([]), 2), mousedPrimitives = _ref[0], setMousedPrimitives = _ref[1];
13291
13345
  var highlightedPrimitives = (0, import_react7.useMemo)(function() {
13292
13346
  var highlightedPrimitives2 = [];
@@ -13348,7 +13402,7 @@ var MouseElementTracker = function(param) {
13348
13402
  x: x,
13349
13403
  y: y
13350
13404
  });
13351
- var mousedPrimitives2 = [];
13405
+ var newMousedPrimitives = [];
13352
13406
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
13353
13407
  try {
13354
13408
  for(var _iterator = primitives[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
@@ -13358,7 +13412,7 @@ var MouseElementTracker = function(param) {
13358
13412
  var w = "w" in primitive ? primitive.w : primitive.r * 2;
13359
13413
  var h = "h" in primitive ? primitive.h : primitive.r * 2;
13360
13414
  if (Math.abs(primitive.x - rwPoint.x) < w / 2 && Math.abs(primitive.y - rwPoint.y) < h / 2) {
13361
- mousedPrimitives2.push(primitive);
13415
+ newMousedPrimitives.push(primitive);
13362
13416
  }
13363
13417
  }
13364
13418
  } catch (err) {
@@ -13375,7 +13429,15 @@ var MouseElementTracker = function(param) {
13375
13429
  }
13376
13430
  }
13377
13431
  }
13378
- setMousedPrimitives(mousedPrimitives2);
13432
+ if (ifSetsMatchExactly(new Set(newMousedPrimitives.map(function(p) {
13433
+ return p._pcb_drawing_object_id;
13434
+ })), new Set(mousedPrimitives.map(function(p) {
13435
+ return p._pcb_drawing_object_id;
13436
+ })))) {
13437
+ return;
13438
+ }
13439
+ setMousedPrimitives(newMousedPrimitives);
13440
+ onMouseHoverOverPrimitives(newMousedPrimitives);
13379
13441
  }
13380
13442
  },
13381
13443
  children: [
@@ -13657,7 +13719,7 @@ var import_soup2 = __toESM(require_dist());
13657
13719
  // package.json
13658
13720
  var package_default = {
13659
13721
  name: "@tscircuit/pcb-viewer",
13660
- version: "1.9.1",
13722
+ version: "1.9.3",
13661
13723
  main: "dist/index.js",
13662
13724
  repository: "tscircuit/pcb-viewer",
13663
13725
  license: "MIT",
@@ -13687,6 +13749,7 @@ var package_default = {
13687
13749
  "@tscircuit/react-fiber": "^1.1.25",
13688
13750
  "@tscircuit/soup": "^0.0.61",
13689
13751
  "@tscircuit/soup-util": "^0.0.13",
13752
+ "@types/color": "^3.0.6",
13690
13753
  "@types/node": "18.7.23",
13691
13754
  "@types/react": "^18.3.3",
13692
13755
  next: "^14.1.4",
@@ -13707,6 +13770,7 @@ var package_default = {
13707
13770
  },
13708
13771
  dependencies: {
13709
13772
  "@emotion/css": "^11.11.2",
13773
+ "circuit-json-to-connectivity-map": "^0.0.8",
13710
13774
  color: "^4.2.3",
13711
13775
  "react-supergrid": "^1.0.10",
13712
13776
  "react-toastify": "^10.0.5",
@@ -14704,20 +14768,87 @@ var RatsNestOverlay = function(param) {
14704
14768
  });
14705
14769
  };
14706
14770
  // src/components/CanvasElementsRenderer.tsx
14771
+ var import_circuit_json_to_connectivity_map = require("circuit-json-to-connectivity-map");
14707
14772
  var import_jsx_runtime13 = require("react/jsx-runtime");
14708
14773
  var CanvasElementsRenderer = function(props) {
14709
14774
  var transform = props.transform, elements = props.elements;
14710
- var primitives = (0, import_react15.useMemo)(function() {
14711
- var primitives2 = props.elements.flatMap(function(elm) {
14775
+ var _ref = _sliced_to_array((0, import_react16.useMemo)(function() {
14776
+ var primitivesWithoutInteractionMetadata2 = props.elements.flatMap(function(elm) {
14712
14777
  return convertElementToPrimitives(elm, props.elements);
14713
14778
  });
14714
- return primitives2;
14779
+ var connectivityMap2 = (0, import_circuit_json_to_connectivity_map.getFullConnectivityMapFromCircuitJson)(props.elements);
14780
+ return [
14781
+ primitivesWithoutInteractionMetadata2,
14782
+ connectivityMap2
14783
+ ];
14715
14784
  }, [
14716
14785
  props.elements
14717
- ]);
14786
+ ]), 2), primitivesWithoutInteractionMetadata = _ref[0], connectivityMap = _ref[1];
14787
+ var _ref1 = _sliced_to_array((0, import_react15.useState)(primitivesWithoutInteractionMetadata), 2), primitives = _ref1[0], setPrimitives = _ref1[1];
14718
14788
  return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(MouseElementTracker, {
14719
14789
  transform: transform,
14720
- primitives: primitives,
14790
+ primitives: primitivesWithoutInteractionMetadata,
14791
+ onMouseHoverOverPrimitives: function(primitivesHoveredOver) {
14792
+ var connectedPrimitiveIds = [];
14793
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
14794
+ try {
14795
+ for(var _iterator = primitivesHoveredOver[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
14796
+ var primitive = _step.value;
14797
+ if (primitive._element && "pcb_port_id" in primitive._element) {
14798
+ var _connectedPrimitiveIds;
14799
+ var connectedPrimitivesList = connectivityMap.getNetConnectedToId(primitive._element.pcb_port_id);
14800
+ (_connectedPrimitiveIds = connectedPrimitiveIds).push.apply(_connectedPrimitiveIds, _to_consumable_array(connectivityMap.getIdsConnectedToNet(connectedPrimitivesList)));
14801
+ }
14802
+ }
14803
+ } catch (err) {
14804
+ _didIteratorError = true;
14805
+ _iteratorError = err;
14806
+ } finally{
14807
+ try {
14808
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
14809
+ _iterator.return();
14810
+ }
14811
+ } finally{
14812
+ if (_didIteratorError) {
14813
+ throw _iteratorError;
14814
+ }
14815
+ }
14816
+ }
14817
+ var primitiveIdsWithMouseOver = new Set(primitivesHoveredOver.map(function(p) {
14818
+ return p._pcb_drawing_object_id;
14819
+ }));
14820
+ var newPrimitives = [];
14821
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
14822
+ try {
14823
+ for(var _iterator1 = primitivesWithoutInteractionMetadata[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
14824
+ var primitive1 = _step1.value;
14825
+ var newPrimitive = _object_spread({}, primitive1);
14826
+ if (primitiveIdsWithMouseOver.has(primitive1._pcb_drawing_object_id)) {
14827
+ newPrimitive.is_mouse_over = true;
14828
+ } else if (primitive1._element && ("pcb_trace_id" in primitive1._element && connectedPrimitiveIds.includes(primitive1._element.pcb_trace_id) || "pcb_port_id" in primitive1._element && connectedPrimitiveIds.includes(primitive1._element.pcb_port_id))) {
14829
+ newPrimitive.is_in_highlighted_net = true;
14830
+ } else {
14831
+ newPrimitive.is_in_highlighted_net = false;
14832
+ newPrimitive.is_mouse_over = false;
14833
+ }
14834
+ newPrimitives.push(newPrimitive);
14835
+ }
14836
+ } catch (err) {
14837
+ _didIteratorError1 = true;
14838
+ _iteratorError1 = err;
14839
+ } finally{
14840
+ try {
14841
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
14842
+ _iterator1.return();
14843
+ }
14844
+ } finally{
14845
+ if (_didIteratorError1) {
14846
+ throw _iteratorError1;
14847
+ }
14848
+ }
14849
+ }
14850
+ setPrimitives(newPrimitives);
14851
+ },
14721
14852
  children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(EditPlacementOverlay, {
14722
14853
  disabled: !props.allowEditing,
14723
14854
  transform: transform,
@@ -14763,11 +14894,11 @@ var import_use_mouse_matrix_transform = __toESM(require_dist3());
14763
14894
  var noop = function noop() {};
14764
14895
  var isBrowser = typeof window !== "undefined";
14765
14896
  // node_modules/react-use/esm/useIsomorphicLayoutEffect.js
14766
- var import_react16 = require("react");
14767
- var useIsomorphicLayoutEffect = isBrowser ? import_react16.useLayoutEffect : import_react16.useEffect;
14897
+ var import_react17 = require("react");
14898
+ var useIsomorphicLayoutEffect = isBrowser ? import_react17.useLayoutEffect : import_react17.useEffect;
14768
14899
  var useIsomorphicLayoutEffect_default = useIsomorphicLayoutEffect;
14769
14900
  // node_modules/react-use/esm/useMeasure.js
14770
- var import_react17 = require("react");
14901
+ var import_react18 = require("react");
14771
14902
  var defaultState = {
14772
14903
  x: 0,
14773
14904
  y: 0,
@@ -14779,9 +14910,9 @@ var defaultState = {
14779
14910
  right: 0
14780
14911
  };
14781
14912
  function useMeasure() {
14782
- var _a = (0, import_react17.useState)(null), element = _a[0], ref = _a[1];
14783
- var _b = (0, import_react17.useState)(defaultState), rect = _b[0], setRect = _b[1];
14784
- var observer = (0, import_react17.useMemo)(function() {
14913
+ var _a = (0, import_react18.useState)(null), element = _a[0], ref = _a[1];
14914
+ var _b = (0, import_react18.useState)(defaultState), rect = _b[0], setRect = _b[1];
14915
+ var observer = (0, import_react18.useMemo)(function() {
14785
14916
  return new window.ResizeObserver(function(entries) {
14786
14917
  if (entries[0]) {
14787
14918
  var _a2 = entries[0].contentRect, x = _a2.x, y = _a2.y, width = _a2.width, height = _a2.height, top_1 = _a2.top, left = _a2.left, bottom = _a2.bottom, right = _a2.right;
@@ -14890,16 +15021,16 @@ var import_jsx_runtime14 = require("react/jsx-runtime");
14890
15021
  var defaultTransform = (0, import_transformation_matrix9.compose)((0, import_transformation_matrix9.translate)(400, 300), (0, import_transformation_matrix9.scale)(40, -40));
14891
15022
  var PCBViewer = function(param) {
14892
15023
  var children = param.children, soup = param.soup, _param_height = param.height, height = _param_height === void 0 ? 600 : _param_height, initialState = param.initialState, _param_allowEditing = param.allowEditing, allowEditing = _param_allowEditing === void 0 ? true : _param_allowEditing, editEventsProp = param.editEvents, onEditEventsChanged = param.onEditEventsChanged;
14893
- var _ref = _sliced_to_array((0, import_react18.useState)([]), 2), stateElements = _ref[0], setStateElements = _ref[1];
15024
+ var _ref = _sliced_to_array((0, import_react19.useState)([]), 2), stateElements = _ref[0], setStateElements = _ref[1];
14894
15025
  var _useMeasure_default = _sliced_to_array(useMeasure_default(), 2), ref = _useMeasure_default[0], refDimensions = _useMeasure_default[1];
14895
- var _ref1 = _sliced_to_array((0, import_react18.useState)(defaultTransform), 2), transform = _ref1[0], setTransformInternal = _ref1[1];
15026
+ var _ref1 = _sliced_to_array((0, import_react19.useState)(defaultTransform), 2), transform = _ref1[0], setTransformInternal = _ref1[1];
14896
15027
  var _ref2 = (0, import_use_mouse_matrix_transform.default)({
14897
15028
  transform: transform,
14898
15029
  onSetTransform: setTransformInternal
14899
15030
  }), transformRef = _ref2.ref, setTransform = _ref2.setTransform, cancelPanDrag = _ref2.cancelDrag;
14900
- var _ref3 = _sliced_to_array((0, import_react18.useState)([]), 2), editEvents = _ref3[0], setEditEvents = _ref3[1];
15031
+ var _ref3 = _sliced_to_array((0, import_react19.useState)([]), 2), editEvents = _ref3[0], setEditEvents = _ref3[1];
14901
15032
  editEvents = editEventsProp !== null && editEventsProp !== void 0 ? editEventsProp : editEvents;
14902
- var _ref4 = _sliced_to_array((0, import_react18.useState)(null), 2), error = _ref4[0], setError = _ref4[1];
15033
+ var _ref4 = _sliced_to_array((0, import_react19.useState)(null), 2), error = _ref4[0], setError = _ref4[1];
14903
15034
  var resetTransform = function() {
14904
15035
  var elmBounds = (refDimensions === null || refDimensions === void 0 ? void 0 : refDimensions.width) > 0 ? refDimensions : {
14905
15036
  width: 500,
@@ -14923,7 +15054,7 @@ var PCBViewer = function(param) {
14923
15054
  setTransform((0, import_transformation_matrix9.compose)((0, import_transformation_matrix9.translate)(((_elmBounds_width1 = elmBounds.width) !== null && _elmBounds_width1 !== void 0 ? _elmBounds_width1 : 0) / 2, ((_elmBounds_height1 = elmBounds.height) !== null && _elmBounds_height1 !== void 0 ? _elmBounds_height1 : 0) / 2), // translate(100, 0),
14924
15055
  (0, import_transformation_matrix9.scale)(scaleFactor, -scaleFactor, 0, 0), (0, import_transformation_matrix9.translate)(-center.x, -center.y)));
14925
15056
  };
14926
- (0, import_react18.useEffect)(function() {
15057
+ (0, import_react19.useEffect)(function() {
14927
15058
  var doRender = function doRender() {
14928
15059
  return _doRender.apply(this, arguments);
14929
15060
  };
@@ -14959,7 +15090,7 @@ var PCBViewer = function(param) {
14959
15090
  }, [
14960
15091
  children
14961
15092
  ]);
14962
- (0, import_react18.useEffect)(function() {
15093
+ (0, import_react19.useEffect)(function() {
14963
15094
  if (refDimensions && refDimensions.width !== 0 && (children || soup)) {
14964
15095
  resetTransform();
14965
15096
  }
@@ -14980,7 +15111,7 @@ var PCBViewer = function(param) {
14980
15111
  var pcbElmsPreEdit = (soup !== null && soup !== void 0 ? soup : stateElements).filter(function(e) {
14981
15112
  return e.type.startsWith("pcb_") || e.type.startsWith("source_");
14982
15113
  });
14983
- var elements = (0, import_react18.useMemo)(function() {
15114
+ var elements = (0, import_react19.useMemo)(function() {
14984
15115
  return applyEditEvents(pcbElmsPreEdit, editEvents);
14985
15116
  }, [
14986
15117
  pcbElmsPreEdit,