@tscircuit/pcb-viewer 1.10.10 → 1.10.12

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
@@ -3175,944 +3175,18 @@ __export(src_exports, {
3175
3175
  });
3176
3176
  module.exports = __toCommonJS(src_exports);
3177
3177
  // src/PCBViewer.tsx
3178
- var import_react20 = require("react");
3179
- // src/components/CanvasElementsRenderer.tsx
3180
- var import_react16 = require("react");
3181
- // src/components/CanvasPrimitiveRenderer.tsx
3182
- var import_react_supergrid = require("react-supergrid");
3183
- var import_react4 = require("react");
3184
- // src/lib/Drawer.ts
3185
- var import_transformation_matrix = require("transformation-matrix");
3186
- // src/lib/colors.ts
3187
- var colors_default = {
3188
- "3d_viewer": {
3189
- background_bottom: "rgb(102, 102, 128)",
3190
- background_top: "rgb(204, 204, 230)",
3191
- board: "rgb(51, 43, 23)",
3192
- copper: "rgb(179, 156, 0)",
3193
- silkscreen_bottom: "rgb(230, 230, 230)",
3194
- silkscreen_top: "rgb(230, 230, 230)",
3195
- soldermask: "rgb(20, 51, 36)",
3196
- solderpaste: "rgb(128, 128, 128)"
3178
+ var import_core = require("@tscircuit/core");
3179
+ // node_modules/circuit-json/dist/index.mjs
3180
+ var dist_exports = {};
3181
+ __export(dist_exports, {
3182
+ all_layers: function() {
3183
+ return all_layers;
3197
3184
  },
3198
- board: {
3199
- anchor: "rgb(255, 38, 226)",
3200
- aux_items: "rgb(255, 255, 255)",
3201
- b_adhes: "rgb(0, 0, 132)",
3202
- b_crtyd: "rgb(255, 38, 226)",
3203
- b_fab: "rgb(88, 93, 132)",
3204
- b_mask: "rgba(2, 255, 238, 0.400)",
3205
- b_paste: "rgb(0, 194, 194)",
3206
- b_silks: "rgb(232, 178, 167)",
3207
- background: "rgb(0, 16, 35)",
3208
- cmts_user: "rgb(89, 148, 220)",
3209
- copper: {
3210
- b: "rgb(77, 127, 196)",
3211
- f: "rgb(200, 52, 52)",
3212
- in1: "rgb(127, 200, 127)",
3213
- in10: "rgb(237, 124, 51)",
3214
- in11: "rgb(91, 195, 235)",
3215
- in12: "rgb(247, 111, 142)",
3216
- in13: "rgb(167, 165, 198)",
3217
- in14: "rgb(40, 204, 217)",
3218
- in15: "rgb(232, 178, 167)",
3219
- in16: "rgb(242, 237, 161)",
3220
- in17: "rgb(237, 124, 51)",
3221
- in18: "rgb(91, 195, 235)",
3222
- in19: "rgb(247, 111, 142)",
3223
- in2: "rgb(206, 125, 44)",
3224
- in20: "rgb(167, 165, 198)",
3225
- in21: "rgb(40, 204, 217)",
3226
- in22: "rgb(232, 178, 167)",
3227
- in23: "rgb(242, 237, 161)",
3228
- in24: "rgb(237, 124, 51)",
3229
- in25: "rgb(91, 195, 235)",
3230
- in26: "rgb(247, 111, 142)",
3231
- in27: "rgb(167, 165, 198)",
3232
- in28: "rgb(40, 204, 217)",
3233
- in29: "rgb(232, 178, 167)",
3234
- in3: "rgb(79, 203, 203)",
3235
- in30: "rgb(242, 237, 161)",
3236
- in4: "rgb(219, 98, 139)",
3237
- in5: "rgb(167, 165, 198)",
3238
- in6: "rgb(40, 204, 217)",
3239
- in7: "rgb(232, 178, 167)",
3240
- in8: "rgb(242, 237, 161)",
3241
- in9: "rgb(141, 203, 129)"
3242
- },
3243
- cursor: "rgb(255, 255, 255)",
3244
- drc: "rgb(194, 194, 194)",
3245
- drc_error: "rgba(215, 91, 107, 0.800)",
3246
- drc_exclusion: "rgb(255, 255, 255)",
3247
- drc_warning: "rgba(255, 208, 66, 0.902)",
3248
- dwgs_user: "rgb(194, 194, 194)",
3249
- eco1_user: "rgb(180, 219, 210)",
3250
- eco2_user: "rgb(216, 200, 82)",
3251
- edge_cuts: "rgb(208, 210, 205)",
3252
- f_adhes: "rgb(132, 0, 132)",
3253
- f_crtyd: "rgb(255, 0, 245)",
3254
- f_fab: "rgb(175, 175, 175)",
3255
- f_mask: "rgba(216, 100, 255, 0.400)",
3256
- f_paste: "rgba(180, 160, 154, 0.902)",
3257
- f_silks: "rgb(242, 237, 161)",
3258
- footprint_text_back: "rgb(0, 0, 132)",
3259
- footprint_text_front: "rgb(194, 194, 194)",
3260
- footprint_text_invisible: "rgb(132, 132, 132)",
3261
- grid: "rgb(132, 132, 132)",
3262
- grid_axes: "rgb(194, 194, 194)",
3263
- margin: "rgb(255, 38, 226)",
3264
- microvia: "rgb(0, 132, 132)",
3265
- no_connect: "rgb(0, 0, 132)",
3266
- pad_back: "rgb(77, 127, 196)",
3267
- pad_front: "rgb(200, 52, 52)",
3268
- pad_plated_hole: "rgb(194, 194, 0)",
3269
- pad_through_hole: "rgb(227, 183, 46)",
3270
- plated_hole: "rgb(26, 196, 210)",
3271
- ratsnest: "rgba(245, 255, 213, 0.702)",
3272
- select_overlay: "rgb(4, 255, 67)",
3273
- through_via: "rgb(236, 236, 236)",
3274
- user_1: "rgb(194, 194, 194)",
3275
- user_2: "rgb(89, 148, 220)",
3276
- user_3: "rgb(180, 219, 210)",
3277
- user_4: "rgb(216, 200, 82)",
3278
- user_5: "rgb(194, 194, 194)",
3279
- user_6: "rgb(89, 148, 220)",
3280
- user_7: "rgb(180, 219, 210)",
3281
- user_8: "rgb(216, 200, 82)",
3282
- user_9: "rgb(232, 178, 167)",
3283
- via_blind_buried: "rgb(187, 151, 38)",
3284
- via_hole: "rgb(227, 183, 46)",
3285
- via_micro: "rgb(0, 132, 132)",
3286
- via_through: "rgb(236, 236, 236)",
3287
- worksheet: "rgb(200, 114, 171)"
3185
+ any_circuit_element: function() {
3186
+ return any_circuit_element;
3288
3187
  },
3289
- gerbview: {
3290
- axes: "rgb(0, 0, 132)",
3291
- background: "rgb(0, 0, 0)",
3292
- dcodes: "rgb(255, 255, 255)",
3293
- grid: "rgb(132, 132, 132)",
3294
- layers: [
3295
- "rgb(132, 0, 0)",
3296
- "rgb(194, 194, 0)",
3297
- "rgb(194, 0, 194)",
3298
- "rgb(194, 0, 0)",
3299
- "rgb(0, 132, 132)",
3300
- "rgb(0, 132, 0)",
3301
- "rgb(0, 0, 132)",
3302
- "rgb(132, 132, 132)",
3303
- "rgb(132, 0, 132)",
3304
- "rgb(194, 194, 194)",
3305
- "rgb(132, 0, 132)",
3306
- "rgb(132, 0, 0)",
3307
- "rgb(132, 132, 0)",
3308
- "rgb(194, 194, 194)",
3309
- "rgb(0, 0, 132)",
3310
- "rgb(0, 132, 0)",
3311
- "rgb(132, 0, 0)",
3312
- "rgb(194, 194, 0)",
3313
- "rgb(194, 0, 194)",
3314
- "rgb(194, 0, 0)",
3315
- "rgb(0, 132, 132)",
3316
- "rgb(0, 132, 0)",
3317
- "rgb(0, 0, 132)",
3318
- "rgb(132, 132, 132)",
3319
- "rgb(132, 0, 132)",
3320
- "rgb(194, 194, 194)",
3321
- "rgb(132, 0, 132)",
3322
- "rgb(132, 0, 0)",
3323
- "rgb(132, 132, 0)",
3324
- "rgb(194, 194, 194)",
3325
- "rgb(0, 0, 132)",
3326
- "rgb(0, 132, 0)",
3327
- "rgb(132, 0, 0)",
3328
- "rgb(194, 194, 0)",
3329
- "rgb(194, 0, 194)",
3330
- "rgb(194, 0, 0)",
3331
- "rgb(0, 132, 132)",
3332
- "rgb(0, 132, 0)",
3333
- "rgb(0, 0, 132)",
3334
- "rgb(132, 132, 132)",
3335
- "rgb(132, 0, 132)",
3336
- "rgb(194, 194, 194)",
3337
- "rgb(132, 0, 132)",
3338
- "rgb(132, 0, 0)",
3339
- "rgb(132, 132, 0)",
3340
- "rgb(194, 194, 194)",
3341
- "rgb(0, 0, 132)",
3342
- "rgb(0, 132, 0)",
3343
- "rgb(132, 0, 0)",
3344
- "rgb(194, 194, 0)",
3345
- "rgb(194, 0, 194)",
3346
- "rgb(194, 0, 0)",
3347
- "rgb(0, 132, 132)",
3348
- "rgb(0, 132, 0)",
3349
- "rgb(0, 0, 132)",
3350
- "rgb(132, 132, 132)",
3351
- "rgb(132, 0, 132)",
3352
- "rgb(194, 194, 194)",
3353
- "rgb(132, 0, 132)",
3354
- "rgb(132, 0, 0)"
3355
- ],
3356
- negative_objects: "rgb(132, 132, 132)",
3357
- worksheet: "rgb(0, 0, 132)"
3358
- },
3359
- palette: [
3360
- "rgb(132, 0, 0)",
3361
- "rgb(194, 194, 0)",
3362
- "rgb(194, 0, 194)",
3363
- "rgb(194, 0, 0)",
3364
- "rgb(0, 132, 132)",
3365
- "rgb(0, 132, 0)",
3366
- "rgb(0, 0, 132)",
3367
- "rgb(132, 132, 132)",
3368
- "rgb(132, 0, 132)",
3369
- "rgb(194, 194, 194)",
3370
- "rgb(132, 0, 132)",
3371
- "rgb(132, 0, 0)",
3372
- "rgb(132, 132, 0)",
3373
- "rgb(194, 194, 194)",
3374
- "rgb(0, 0, 132)",
3375
- "rgb(0, 132, 0)"
3376
- ],
3377
- schematic: {
3378
- anchor: "rgb(0, 0, 255)",
3379
- aux_items: "rgb(0, 0, 0)",
3380
- background: "rgb(33, 33, 33)",
3381
- brightened: "rgb(204, 204, 204)",
3382
- bus: "rgb(0, 96, 192)",
3383
- bus_junction: "rgb(0, 96, 192)",
3384
- component_body: "rgb(44, 44, 44)",
3385
- component_outline: "rgb(192, 0, 0)",
3386
- cursor: "rgb(224, 224, 224)",
3387
- erc_error: "rgba(192, 48, 48, 0.800)",
3388
- erc_warning: "rgba(192, 140, 0, 0.800)",
3389
- fields: "rgb(128, 0, 160)",
3390
- grid: "rgb(60, 60, 60)",
3391
- grid_axes: "rgb(60, 60, 60)",
3392
- hidden: "rgb(194, 194, 194)",
3393
- junction: "rgb(0, 160, 0)",
3394
- label_global: "rgb(0, 160, 224)",
3395
- label_hier: "rgb(160, 160, 0)",
3396
- label_local: "rgb(192, 192, 192)",
3397
- net_name: "rgb(224, 224, 224)",
3398
- no_connect: "rgb(97, 43, 224)",
3399
- note: "rgb(192, 192, 0)",
3400
- override_item_colors: false,
3401
- pin: "rgb(192, 0, 0)",
3402
- pin_name: "rgb(192, 192, 192)",
3403
- pin_number: "rgb(192, 0, 0)",
3404
- reference: "rgb(192, 192, 192)",
3405
- shadow: "rgba(102, 179, 255, 0.800)",
3406
- sheet: "rgb(128, 0, 160)",
3407
- sheet_background: "rgba(255, 255, 255, 0.000)",
3408
- sheet_fields: "rgb(160, 160, 0)",
3409
- sheet_filename: "rgb(160, 160, 0)",
3410
- sheet_label: "rgb(160, 160, 0)",
3411
- sheet_name: "rgb(0, 160, 204)",
3412
- value: "rgb(192, 192, 192)",
3413
- wire: "rgb(0, 160, 0)",
3414
- worksheet: "rgb(192, 0, 0)"
3415
- }
3416
- };
3417
- // src/lib/util/scale-only.ts
3418
- var scaleOnly = function(mat) {
3419
- var value = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
3420
- if (Math.abs(mat.a) !== Math.abs(mat.d)) throw new Error("Cannot scale non-uniformly");
3421
- return value * Math.abs(mat.a);
3422
- };
3423
- // src/lib/Drawer.ts
3424
- var LAYER_NAME_TO_COLOR = _object_spread({
3425
- // Standard colors, you shouldn't use these except for testing
3426
- red: "red",
3427
- black: "black",
3428
- green: "green",
3429
- board: "rgb(255, 255, 255)",
3430
- other: "#eee",
3431
- // TODO more builtin html colors
3432
- // Common eagle names
3433
- top: colors_default.board.copper.f,
3434
- inner1: colors_default.board.copper.in1,
3435
- inner2: colors_default.board.copper.in2,
3436
- inner3: colors_default.board.copper.in3,
3437
- inner4: colors_default.board.copper.in4,
3438
- inner5: colors_default.board.copper.in5,
3439
- inner6: colors_default.board.copper.in6,
3440
- inner7: colors_default.board.copper.in7,
3441
- inner8: colors_default.board.copper.in8,
3442
- bottom: colors_default.board.copper.b,
3443
- drill: colors_default.board.anchor,
3444
- keepout: colors_default.board.background,
3445
- tkeepout: colors_default.board.b_crtyd,
3446
- tplace: colors_default.board.b_silks,
3447
- top_silkscreen: colors_default.board.f_silks,
3448
- bottom_silkscreen: colors_default.board.b_silks,
3449
- top_fabrication: colors_default.board.f_fab,
3450
- bottom_fabrication: colors_default.board.b_fab
3451
- }, colors_default.board);
3452
- var DEFAULT_DRAW_ORDER = [
3453
- "top",
3454
- "inner1",
3455
- "inner2",
3456
- "inner3",
3457
- "inner4",
3458
- "inner5",
3459
- "inner6",
3460
- "bottom"
3461
- ];
3462
- var Drawer = /*#__PURE__*/ function() {
3463
- "use strict";
3464
- function Drawer(canvasLayerMap) {
3465
- _class_call_check(this, Drawer);
3466
- this.foregroundLayer = "top";
3467
- this.canvasLayerMap = canvasLayerMap;
3468
- this.ctxLayerMap = Object.fromEntries(Object.entries(canvasLayerMap).map(function(param) {
3469
- var _param = _sliced_to_array(param, 2), name = _param[0], canvas = _param[1];
3470
- return [
3471
- name,
3472
- canvas.getContext("2d")
3473
- ];
3474
- }));
3475
- this.transform = (0, import_transformation_matrix.identity)();
3476
- this.transform.d *= -1;
3477
- this.transform = (0, import_transformation_matrix.compose)(this.transform, (0, import_transformation_matrix.translate)(0, -500));
3478
- this.lastPoint = {
3479
- x: 0,
3480
- y: 0
3481
- };
3482
- this.equip({});
3483
- }
3484
- _create_class(Drawer, [
3485
- {
3486
- key: "clear",
3487
- value: function clear() {
3488
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
3489
- try {
3490
- for(var _iterator = Object.values(this.ctxLayerMap)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3491
- var ctx = _step.value;
3492
- ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
3493
- }
3494
- } catch (err) {
3495
- _didIteratorError = true;
3496
- _iteratorError = err;
3497
- } finally{
3498
- try {
3499
- if (!_iteratorNormalCompletion && _iterator.return != null) {
3500
- _iterator.return();
3501
- }
3502
- } finally{
3503
- if (_didIteratorError) {
3504
- throw _iteratorError;
3505
- }
3506
- }
3507
- }
3508
- }
3509
- },
3510
- {
3511
- key: "equip",
3512
- value: function equip(aperture) {
3513
- this.aperture = _object_spread({
3514
- fontSize: 0,
3515
- shape: "circle",
3516
- mode: "add",
3517
- size: 0,
3518
- color: "red",
3519
- layer: "top",
3520
- opacity: this.foregroundLayer === aperture.color ? 1 : 0.5
3521
- }, aperture);
3522
- }
3523
- },
3524
- {
3525
- key: "drawMeshPattern",
3526
- value: function drawMeshPattern(x, y, width, height, spacing) {
3527
- var angle = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : 45;
3528
- var ctx = this.getLayerCtx();
3529
- var _ref = _sliced_to_array((0, import_transformation_matrix.applyToPoint)(this.transform, [
3530
- x,
3531
- y
3532
- ]), 2), x1 = _ref[0], y1 = _ref[1];
3533
- var _ref1 = _sliced_to_array((0, import_transformation_matrix.applyToPoint)(this.transform, [
3534
- x + width,
3535
- y + height
3536
- ]), 2), x2 = _ref1[0], y2 = _ref1[1];
3537
- var spacing$ = scaleOnly(this.transform, spacing);
3538
- ctx.lineWidth = 1;
3539
- ctx.strokeStyle = this.aperture.color;
3540
- var drawLines = function(angle2) {
3541
- var sin = Math.sin(angle2);
3542
- var cos = Math.cos(angle2);
3543
- var diag = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
3544
- for(var i = -diag; i <= diag; i += spacing$){
3545
- ctx.beginPath();
3546
- ctx.moveTo(x1 + i * cos - diag * sin, y1 + i * sin + diag * cos);
3547
- ctx.lineTo(x1 + i * cos + diag * sin, y1 + i * sin - diag * cos);
3548
- ctx.stroke();
3549
- }
3550
- };
3551
- drawLines(angle * Math.PI / 180);
3552
- drawLines((angle + 90) * Math.PI / 180);
3553
- }
3554
- },
3555
- {
3556
- key: "rect",
3557
- value: function rect(x, y, w, h, mesh_fill) {
3558
- var _ref = _sliced_to_array((0, import_transformation_matrix.applyToPoint)(this.transform, [
3559
- x - w / 2,
3560
- y - h / 2
3561
- ]), 2), x1$ = _ref[0], y1$ = _ref[1];
3562
- var _ref1 = _sliced_to_array((0, import_transformation_matrix.applyToPoint)(this.transform, [
3563
- x + w / 2,
3564
- y + h / 2
3565
- ]), 2), x2$ = _ref1[0], y2$ = _ref1[1];
3566
- this.applyAperture();
3567
- var ctx = this.getLayerCtx();
3568
- if (mesh_fill) {
3569
- ctx.save();
3570
- ctx.beginPath();
3571
- ctx.rect(x1$, y1$, x2$ - x1$, y2$ - y1$);
3572
- ctx.clip();
3573
- this.drawMeshPattern(x - w / 2, y - h / 2, w, h, 0.15);
3574
- ctx.restore();
3575
- ctx.strokeRect(x1$, y1$, x2$ - x1$, y2$ - y1$);
3576
- } else {
3577
- ctx.fillRect(x1$, y1$, x2$ - x1$, y2$ - y1$);
3578
- }
3579
- }
3580
- },
3581
- {
3582
- key: "circle",
3583
- value: function circle(x, y, r, mesh_fill) {
3584
- var r$ = scaleOnly(this.transform, r);
3585
- var _ref = _sliced_to_array((0, import_transformation_matrix.applyToPoint)(this.transform, [
3586
- x,
3587
- y
3588
- ]), 2), x$ = _ref[0], y$ = _ref[1];
3589
- this.applyAperture();
3590
- var ctx = this.getLayerCtx();
3591
- if (mesh_fill) {
3592
- ctx.save();
3593
- ctx.beginPath();
3594
- ctx.arc(x$, y$, r$, 0, 2 * Math.PI);
3595
- ctx.clip();
3596
- this.drawMeshPattern(x - r, y - r, r * 2, r * 2, 0.15);
3597
- ctx.restore();
3598
- ctx.beginPath();
3599
- ctx.arc(x$, y$, r$, 0, 2 * Math.PI);
3600
- ctx.stroke();
3601
- } else {
3602
- ctx.beginPath();
3603
- ctx.arc(x$, y$, r$, 0, 2 * Math.PI);
3604
- ctx.fill();
3605
- }
3606
- }
3607
- },
3608
- {
3609
- key: "oval",
3610
- value: function oval(x, y, rx, ry) {
3611
- var rx$ = scaleOnly(this.transform, rx);
3612
- var ry$ = scaleOnly(this.transform, ry);
3613
- var _ref = _sliced_to_array((0, import_transformation_matrix.applyToPoint)(this.transform, [
3614
- x,
3615
- y
3616
- ]), 2), x$ = _ref[0], y$ = _ref[1];
3617
- this.applyAperture();
3618
- var ctx = this.getLayerCtx();
3619
- ctx.beginPath();
3620
- ctx.ellipse(x$, y$, rx$, ry$, 0, 0, 2 * Math.PI);
3621
- ctx.fill();
3622
- ctx.closePath();
3623
- }
3624
- },
3625
- {
3626
- key: "pill",
3627
- value: function pill(x, y, w, h) {
3628
- var _ref = _sliced_to_array((0, import_transformation_matrix.applyToPoint)(this.transform, [
3629
- x - w / 2,
3630
- y + h / 2
3631
- ]), 2), x$ = _ref[0], y$ = _ref[1];
3632
- var width$ = scaleOnly(this.transform, w);
3633
- var height$ = scaleOnly(this.transform, h);
3634
- var radius = Math.min(width$, height$) / 2;
3635
- this.applyAperture();
3636
- var ctx = this.getLayerCtx();
3637
- ctx.beginPath();
3638
- ctx.arc(x$ + radius, y$ + radius, radius, Math.PI, Math.PI * 1.5);
3639
- ctx.arc(x$ + width$ - radius, y$ + radius, radius, Math.PI * 1.5, 0);
3640
- ctx.arc(x$ + width$ - radius, y$ + height$ - radius, radius, 0, Math.PI * 0.5);
3641
- ctx.arc(x$ + radius, y$ + height$ - radius, radius, Math.PI * 0.5, Math.PI);
3642
- ctx.fill();
3643
- ctx.closePath();
3644
- }
3645
- },
3646
- {
3647
- key: "polygon",
3648
- value: function polygon(points) {
3649
- var _this = this;
3650
- if (points.length < 3) {
3651
- console.warn("Polygon must have at least 3 points");
3652
- return;
3653
- }
3654
- this.applyAperture();
3655
- var ctx = this.getLayerCtx();
3656
- var transformedPoints = points.map(function(point2) {
3657
- return (0, import_transformation_matrix.applyToPoint)(_this.transform, [
3658
- point2.x,
3659
- point2.y
3660
- ]);
3661
- });
3662
- ctx.beginPath();
3663
- ctx.moveTo(transformedPoints[0][0], transformedPoints[0][1]);
3664
- for(var i = 1; i < transformedPoints.length; i++){
3665
- ctx.lineTo(transformedPoints[i][0], transformedPoints[i][1]);
3666
- }
3667
- ctx.closePath();
3668
- ctx.fill();
3669
- var lineWidth = scaleOnly(this.transform, this.aperture.size);
3670
- ctx.lineWidth = lineWidth;
3671
- ctx.stroke();
3672
- }
3673
- },
3674
- {
3675
- /* NOTE: This is not gerber compatible */ key: "debugText",
3676
- value: function debugText(text, x, y) {
3677
- var _ref = _sliced_to_array((0, import_transformation_matrix.applyToPoint)(this.transform, [
3678
- x,
3679
- y
3680
- ]), 2), x$ = _ref[0], y$ = _ref[1];
3681
- this.applyAperture();
3682
- var ctx = this.getLayerCtx();
3683
- ctx.font = "10px sans-serif";
3684
- ctx.fillText(text, x$, y$);
3685
- }
3686
- },
3687
- {
3688
- key: "getLayerCtx",
3689
- value: function getLayerCtx() {
3690
- var ctx = this.ctxLayerMap[this.aperture.layer];
3691
- if (!ctx) {
3692
- throw new Error('No context for layer "'.concat(this.aperture.layer, '"'));
3693
- }
3694
- return ctx;
3695
- }
3696
- },
3697
- {
3698
- /**
3699
- * Iterate over each canvas and set the z index based on the layer order, but
3700
- * always render the foreground layer on top.
3701
- *
3702
- * Also: Set the opacity of every non-foreground layer to 0.5
3703
- */ key: "orderAndFadeLayers",
3704
- value: function orderAndFadeLayers() {
3705
- var _this = this, canvasLayerMap = _this.canvasLayerMap, foregroundLayer = _this.foregroundLayer;
3706
- var opaqueLayers = /* @__PURE__ */ new Set([
3707
- foregroundLayer,
3708
- "drill",
3709
- "other",
3710
- "board"
3711
- ]);
3712
- var order = [
3713
- "drill",
3714
- "board",
3715
- foregroundLayer
3716
- ].concat(_to_consumable_array(DEFAULT_DRAW_ORDER.filter(function(l) {
3717
- return l !== foregroundLayer;
3718
- })));
3719
- order.forEach(function(layer, i) {
3720
- var canvas = canvasLayerMap[layer];
3721
- if (!canvas) return;
3722
- canvas.style.zIndex = "".concat(100 - i);
3723
- canvas.style.opacity = opaqueLayers.has(layer) ? "1" : "0.5";
3724
- });
3725
- }
3726
- },
3727
- {
3728
- key: "applyAperture",
3729
- value: function applyAperture() {
3730
- var _this = this, transform = _this.transform, aperture = _this.aperture;
3731
- var size2 = aperture.size, mode = aperture.mode, color2 = aperture.color, fontSize = aperture.fontSize, layer = aperture.layer;
3732
- if (!(layer in this.ctxLayerMap)) this.aperture.layer = "other";
3733
- var ctx = this.getLayerCtx();
3734
- if (!ctx) {
3735
- throw new Error('No context for layer "'.concat(this.foregroundLayer, '"'));
3736
- }
3737
- if (!color2) color2 = "undefined";
3738
- ctx.lineWidth = scaleOnly(transform, size2);
3739
- ctx.lineCap = "round";
3740
- if (mode === "add") {
3741
- 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;
3742
- if (colorString === null) {
3743
- console.warn('Color mapping for "'.concat(color2, '" not found'));
3744
- colorString = "white";
3745
- }
3746
- ctx.fillStyle = colorString;
3747
- ctx.strokeStyle = colorString;
3748
- } else {
3749
- ctx.globalCompositeOperation = "destination-out";
3750
- ctx.fillStyle = "rgba(0,0,0,1)";
3751
- ctx.strokeStyle = "rgba(0,0,0,1)";
3752
- }
3753
- ctx.font = "".concat(scaleOnly((0, import_transformation_matrix.inverse)(transform), fontSize), "px sans-serif");
3754
- }
3755
- },
3756
- {
3757
- key: "moveTo",
3758
- value: function moveTo(x, y) {
3759
- this.lastPoint = {
3760
- x: x,
3761
- y: y
3762
- };
3763
- }
3764
- },
3765
- {
3766
- key: "lineTo",
3767
- value: function lineTo(x, y) {
3768
- var _ref = _sliced_to_array((0, import_transformation_matrix.applyToPoint)(this.transform, [
3769
- x,
3770
- y
3771
- ]), 2), x$ = _ref[0], y$ = _ref[1];
3772
- var _this_aperture = this.aperture, size2 = _this_aperture.size, shape = _this_aperture.shape, mode = _this_aperture.mode;
3773
- var size$ = scaleOnly(this.transform, size2);
3774
- var lastPoint = this.lastPoint;
3775
- var lastPoint$ = (0, import_transformation_matrix.applyToPoint)(this.transform, lastPoint);
3776
- this.applyAperture();
3777
- var ctx = this.getLayerCtx();
3778
- if (shape === "square") ctx.fillRect(lastPoint$.x - size$ / 2, lastPoint$.y - size$ / 2, size$, size$);
3779
- ctx.beginPath();
3780
- ctx.moveTo(lastPoint$.x, lastPoint$.y);
3781
- ctx.lineTo(x$, y$);
3782
- ctx.stroke();
3783
- ctx.closePath();
3784
- if (shape === "square") ctx.fillRect(x$ - size$ / 2, y$ - size$ / 2, size$, size$);
3785
- this.lastPoint = {
3786
- x: x,
3787
- y: y
3788
- };
3789
- }
3790
- }
3791
- ]);
3792
- return Drawer;
3793
- }();
3794
- // src/assets/alphabet.ts
3795
- var svgAlphabet = {
3796
- "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",
3797
- "1": "M 0.198 0.272 L 0.537 0 L 0.54 1",
3798
- "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",
3799
- "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",
3800
- "4": "M0.7328897338403042 0L0 0.6684672518568535L1 0.6684672518568535M0.7243346007604563 0.4530722484807562L0.7243346007604563 1",
3801
- "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",
3802
- "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",
3803
- "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",
3804
- "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",
3805
- "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",
3806
- A: "M0 1L0.4808333333333333 0L1 1M0.24250000000000002 0.6099439775910365L0.7341666666666666 0.6099439775910365",
3807
- 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",
3808
- 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",
3809
- 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",
3810
- E: "M0 0L0 1M0 0L1 0M0 0.5L0.7 0.5M0 1L1 1",
3811
- F: "M0 0L0 1M0.011363636363636364 0.006802721088435374L1 0.006802721088435374M0.011363636363636364 0.4965986394557823L0.8409090909090909 0.4965986394557823",
3812
- 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",
3813
- H: "M0 0L0 1M0 0.4788732394366197L0.989010989010989 0.4788732394366197M1 0L1 1",
3814
- I: "M0.5 0L0.5 1",
3815
- 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",
3816
- K: "M0 0L0 1M0.8787878787878788 0.06666666666666667L0 0.6148148148148148M0.3333333333333333 0.45925925925925926L1 0.9777777777777777",
3817
- L: "M0 0L0 1L1 1",
3818
- M: "M0 1L0 0L0.5 0.6512L1 0L1 1",
3819
- N: "M0 1L0 0L1 1L0.9803729146221786 0",
3820
- 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",
3821
- 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",
3822
- 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",
3823
- 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",
3824
- 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",
3825
- T: "M0 0L1 0M0.5148514851485149 0L0.5148514851485149 1",
3826
- 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",
3827
- V: "M0 0L0.5348837209302325 1L1 0",
3828
- W: "M0 0L0.23300090661831369 0.9873417721518988L0.49954669084315495 0.30081906180193585L0.7851314596554849 1L1 0.0215934475055845",
3829
- X: "M0 0L0.9893617021276596 1M1 0L0.010638297872340425 1",
3830
- Y: "M0 0L0.4860515021459227 0.44712562100780695M1 0.0014194464158977947L0.48927038626609437 0.44996451383960256L0.5075107296137339 1",
3831
- Z: "M0 0L1 0L0 1L1 1",
3832
- ".": "M 0.49 1 L 0.41 1",
3833
- "*": "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",
3834
- "(": "M0.75 0L0.25 0.5L0.25 0.5L0.75 1",
3835
- ")": "M0.25 0L0.75 0.5L0.75 0.5L0.25 1",
3836
- "-": "M0 0.5L1 0.5",
3837
- "+": "M 0 0.5 L 1 0.5 M 0.5 0.125 L 0.5 0.875",
3838
- "=": "M0 0.25L1 0.25M0 0.75L1 0.75",
3839
- _: "M0 1 L1 1",
3840
- "[": "M0.75 0L0.25 0L0.25 1L0.75 1",
3841
- "]": "M0.25 0L0.75 0L0.75 1L0.25 1",
3842
- "<": "M0.75 0L0.25 0.5L0.25 0.5L0.75 1",
3843
- ">": "M0.25 0L0.75 0.5L0.75 0.5L0.25 1",
3844
- "'": "M 0.5 0 L 0.5 0.5",
3845
- '"': "M 0.25 0 L 0.25 0.5 M 0.75 0 L 0.75 0.5"
3846
- };
3847
- var lineAlphabet = {};
3848
- for(var letter in svgAlphabet)_loop(letter);
3849
- // src/lib/convert-text-to-lines.ts
3850
- var LETTER_HEIGHT_TO_WIDTH_RATIO = 0.6;
3851
- var LETTER_HEIGHT_TO_SPACE_RATIO = 0.2;
3852
- var getTextWidth = function(text) {
3853
- return text.text.length * text.size * LETTER_HEIGHT_TO_WIDTH_RATIO + (text.text.length - 1) * text.size * LETTER_HEIGHT_TO_SPACE_RATIO;
3854
- };
3855
- var convertTextToLines = function(text) {
3856
- var strokeWidth = text.size / 8;
3857
- var letterWidth = text.size * LETTER_HEIGHT_TO_WIDTH_RATIO;
3858
- var letterSpace = text.size * LETTER_HEIGHT_TO_SPACE_RATIO;
3859
- var lines = [];
3860
- for(var letterIndex = 0; letterIndex < text.text.length; letterIndex++){
3861
- var letter = text.text[letterIndex];
3862
- var letterLines = lineAlphabet[letter.toUpperCase()];
3863
- if (!letterLines) continue;
3864
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
3865
- try {
3866
- for(var _iterator = letterLines[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3867
- var _step_value = _step.value, x1 = _step_value.x1, y1 = _step_value.y1, x2 = _step_value.x2, y2 = _step_value.y2;
3868
- lines.push({
3869
- pcb_drawing_type: "line",
3870
- x1: text.x + (letterWidth + letterSpace) * letterIndex + letterWidth * x1,
3871
- y1: text.y + text.size * y1,
3872
- x2: text.x + (letterWidth + letterSpace) * letterIndex + letterWidth * x2,
3873
- y2: text.y + text.size * y2,
3874
- width: strokeWidth,
3875
- layer: text.layer,
3876
- unit: text.unit
3877
- });
3878
- }
3879
- } catch (err) {
3880
- _didIteratorError = true;
3881
- _iteratorError = err;
3882
- } finally{
3883
- try {
3884
- if (!_iteratorNormalCompletion && _iterator.return != null) {
3885
- _iterator.return();
3886
- }
3887
- } finally{
3888
- if (_didIteratorError) {
3889
- throw _iteratorError;
3890
- }
3891
- }
3892
- }
3893
- }
3894
- return lines;
3895
- };
3896
- // src/lib/draw-primitives.ts
3897
- var import_color = __toESM(require("color"));
3898
- function getColor(primitive) {
3899
- if (primitive.is_mouse_over || primitive.is_in_highlighted_net) {
3900
- return (0, import_color.default)(LAYER_NAME_TO_COLOR[primitive.layer]).lighten(0.5).rgb().toString();
3901
- }
3902
- return LAYER_NAME_TO_COLOR[primitive.layer];
3903
- }
3904
- var drawLine = function(drawer, line) {
3905
- drawer.equip({
3906
- size: line.zoomIndependent ? line.width / drawer.transform.a : line.width,
3907
- shape: line.squareCap ? "square" : "circle",
3908
- color: getColor(line),
3909
- layer: line.layer
3910
- });
3911
- drawer.moveTo(line.x1, line.y1);
3912
- drawer.lineTo(line.x2, line.y2);
3913
- };
3914
- var drawText = function(drawer, text) {
3915
- drawer.equip({
3916
- fontSize: text.size,
3917
- color: text.layer
3918
- });
3919
- var alignOffset = {
3920
- x: 0,
3921
- y: 0
3922
- };
3923
- var textWidth = getTextWidth(text);
3924
- var textHeight = text.size;
3925
- if (text.align === "top_left") {
3926
- alignOffset.y = -textHeight;
3927
- } else if (text.align === "bottom_right") {
3928
- alignOffset.x = -textWidth;
3929
- } else if (text.align === "top_right") {
3930
- alignOffset.x = -textWidth;
3931
- alignOffset.y = -textHeight;
3932
- } else if (text.align === "center") {
3933
- alignOffset.x = -textWidth / 2;
3934
- alignOffset.y = -textHeight / 2;
3935
- }
3936
- var _text_x;
3937
- (_text_x = text.x) !== null && _text_x !== void 0 ? _text_x : text.x = 0;
3938
- var _text_y;
3939
- (_text_y = text.y) !== null && _text_y !== void 0 ? _text_y : text.y = 0;
3940
- var text_lines = convertTextToLines(_object_spread_props(_object_spread({}, text), {
3941
- x: text.x + alignOffset.x,
3942
- y: text.y + alignOffset.y
3943
- }));
3944
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
3945
- try {
3946
- for(var _iterator = text_lines[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3947
- var line = _step.value;
3948
- drawLine(drawer, line);
3949
- }
3950
- } catch (err) {
3951
- _didIteratorError = true;
3952
- _iteratorError = err;
3953
- } finally{
3954
- try {
3955
- if (!_iteratorNormalCompletion && _iterator.return != null) {
3956
- _iterator.return();
3957
- }
3958
- } finally{
3959
- if (_didIteratorError) {
3960
- throw _iteratorError;
3961
- }
3962
- }
3963
- }
3964
- };
3965
- var drawRect = function(drawer, rect) {
3966
- drawer.equip({
3967
- color: getColor(rect),
3968
- layer: rect.layer
3969
- });
3970
- drawer.rect(rect.x, rect.y, rect.w, rect.h, rect.mesh_fill);
3971
- };
3972
- var drawCircle = function(drawer, circle) {
3973
- drawer.equip({
3974
- color: getColor(circle),
3975
- layer: circle.layer
3976
- });
3977
- drawer.circle(circle.x, circle.y, circle.r, circle.mesh_fill);
3978
- };
3979
- var drawOval = function(drawer, oval) {
3980
- drawer.equip({
3981
- color: getColor(oval),
3982
- layer: oval.layer
3983
- });
3984
- drawer.oval(oval.x, oval.y, oval.rX, oval.rY);
3985
- };
3986
- var drawPill = function(drawer, pill) {
3987
- drawer.equip({
3988
- color: getColor(pill),
3989
- layer: pill.layer
3990
- });
3991
- drawer.pill(pill.x, pill.y, pill.w, pill.h);
3992
- };
3993
- var drawPolygon = function(drawer, polygon) {
3994
- drawer.equip({
3995
- color: getColor(polygon),
3996
- layer: polygon.layer
3997
- });
3998
- drawer.polygon(polygon.points);
3999
- };
4000
- var drawPrimitive = function(drawer, primitive) {
4001
- switch(primitive.pcb_drawing_type){
4002
- case "line":
4003
- return drawLine(drawer, primitive);
4004
- case "text":
4005
- return drawText(drawer, primitive);
4006
- case "rect":
4007
- return drawRect(drawer, primitive);
4008
- case "circle":
4009
- return drawCircle(drawer, primitive);
4010
- case "oval":
4011
- return drawOval(drawer, primitive);
4012
- case "pill":
4013
- return drawPill(drawer, primitive);
4014
- case "polygon":
4015
- return drawPolygon(drawer, primitive);
4016
- }
4017
- };
4018
- var drawPrimitives = function(drawer, primitives) {
4019
- primitives.sort(function(a, b) {
4020
- var layerOrder = [
4021
- "bottom",
4022
- "top",
4023
- "drill"
4024
- ];
4025
- return layerOrder.indexOf(a.layer) - layerOrder.indexOf(b.layer);
4026
- });
4027
- primitives.forEach(function(primitive) {
4028
- return drawPrimitive(drawer, primitive);
4029
- });
4030
- };
4031
- // src/global-store.ts
4032
- var import_zustand = require("zustand");
4033
- // src/components/ContextProviders.tsx
4034
- var import_react = require("react");
4035
- var import_react2 = require("react");
4036
- var import_jsx_runtime = require("react/jsx-runtime");
4037
- var StoreContext = (0, import_react2.createContext)(null);
4038
- var ContextProviders = function(param) {
4039
- var children = param.children, initialState = param.initialState;
4040
- var store = (0, import_react.useMemo)(function() {
4041
- return createStore(initialState);
4042
- }, []);
4043
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StoreContext.Provider, {
4044
- value: store,
4045
- children: children
4046
- });
4047
- };
4048
- // src/global-store.ts
4049
- var import_react3 = require("react");
4050
- var createStore = function() {
4051
- var initialState = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
4052
- return (0, import_zustand.createStore)(function(set) {
4053
- return _object_spread_props(_object_spread({
4054
- selected_layer: "top",
4055
- pcb_viewer_id: "pcb_viewer_".concat(Math.random().toString().slice(2, 10)),
4056
- in_edit_mode: false,
4057
- in_move_footprint_mode: false,
4058
- in_draw_trace_mode: false,
4059
- is_moving_component: false,
4060
- is_drawing_trace: false,
4061
- is_mouse_over_container: false,
4062
- is_showing_rats_nest: false
4063
- }, initialState), {
4064
- selectLayer: function(layer) {
4065
- return set({
4066
- selected_layer: layer
4067
- });
4068
- },
4069
- setEditMode: function(mode) {
4070
- return set({
4071
- in_edit_mode: mode !== "off",
4072
- in_move_footprint_mode: mode === "move_footprint",
4073
- in_draw_trace_mode: mode === "draw_trace",
4074
- is_moving_component: false,
4075
- is_drawing_trace: false
4076
- });
4077
- },
4078
- setIsShowingRatsNest: function(is_showing) {
4079
- return set({
4080
- is_showing_rats_nest: is_showing
4081
- });
4082
- },
4083
- setIsMovingComponent: function(is_moving) {
4084
- return set({
4085
- is_moving_component: is_moving
4086
- });
4087
- },
4088
- setIsDrawingTrace: function(is_drawing) {
4089
- return set({
4090
- is_drawing_trace: is_drawing
4091
- });
4092
- },
4093
- setIsMouseOverContainer: function(is_focused) {
4094
- return set({
4095
- is_mouse_over_container: is_focused
4096
- });
4097
- }
4098
- });
4099
- });
4100
- };
4101
- var useGlobalStore = function(s) {
4102
- var store = (0, import_react3.useContext)(StoreContext);
4103
- return (0, import_zustand.useStore)(store, s);
4104
- };
4105
- // node_modules/circuit-json/dist/index.mjs
4106
- var dist_exports = {};
4107
- __export(dist_exports, {
4108
- all_layers: function() {
4109
- return all_layers;
4110
- },
4111
- any_circuit_element: function() {
4112
- return any_circuit_element;
4113
- },
4114
- any_soup_element: function() {
4115
- return any_soup_element;
3188
+ any_soup_element: function() {
3189
+ return any_soup_element;
4116
3190
  },
4117
3191
  any_source_component: function() {
4118
3192
  return any_source_component;
@@ -11286,124 +10360,2210 @@ var pcb_fabrication_note_text = z.object({
11286
10360
  font: z.literal("tscircuit2024").default("tscircuit2024"),
11287
10361
  font_size: distance.default("1mm"),
11288
10362
  pcb_component_id: z.string(),
11289
- text: z.string(),
11290
- layer: visible_layer,
11291
- anchor_position: point.default({
10363
+ text: z.string(),
10364
+ layer: visible_layer,
10365
+ anchor_position: point.default({
10366
+ x: 0,
10367
+ y: 0
10368
+ }),
10369
+ anchor_alignment: z.enum([
10370
+ "center",
10371
+ "top_left",
10372
+ "top_right",
10373
+ "bottom_left",
10374
+ "bottom_right"
10375
+ ]).default("center"),
10376
+ color: z.string().optional()
10377
+ }).describe("Defines a fabrication note in text on the PCB, useful for leaving notes for assemblers or fabricators");
10378
+ expectTypesMatch(true);
10379
+ var pcb_fabrication_note_path = z.object({
10380
+ type: z.literal("pcb_fabrication_note_path"),
10381
+ pcb_fabrication_note_path_id: getZodPrefixedIdWithDefault("pcb_fabrication_note_path"),
10382
+ pcb_component_id: z.string(),
10383
+ layer: layer_ref,
10384
+ route: z.array(point),
10385
+ stroke_width: length,
10386
+ color: z.string().optional()
10387
+ }).describe("Defines a fabrication path on the PCB for fabricators or assemblers");
10388
+ expectTypesMatch(true);
10389
+ var pcb_keepout = z.object({
10390
+ type: z.literal("pcb_keepout"),
10391
+ shape: z.literal("rect"),
10392
+ center: point,
10393
+ width: distance,
10394
+ height: distance,
10395
+ pcb_keepout_id: z.string(),
10396
+ layers: z.array(z.string()),
10397
+ // Specify layers where the keepout applies
10398
+ description: z.string().optional()
10399
+ }).or(z.object({
10400
+ type: z.literal("pcb_keepout"),
10401
+ shape: z.literal("circle"),
10402
+ center: point,
10403
+ radius: distance,
10404
+ pcb_keepout_id: z.string(),
10405
+ layers: z.array(z.string()),
10406
+ // Specify layers where the keepout applies
10407
+ description: z.string().optional()
10408
+ }));
10409
+ var cad_component = z.object({
10410
+ type: z.literal("cad_component"),
10411
+ cad_component_id: z.string(),
10412
+ pcb_component_id: z.string(),
10413
+ source_component_id: z.string(),
10414
+ position: point3,
10415
+ rotation: point3.optional(),
10416
+ size: point3.optional(),
10417
+ layer: layer_ref.optional(),
10418
+ // These are all ways to generate/load the 3d model
10419
+ footprinter_string: z.string().optional(),
10420
+ model_obj_url: z.string().optional(),
10421
+ model_stl_url: z.string().optional(),
10422
+ model_3mf_url: z.string().optional(),
10423
+ model_jscad: z.any().optional()
10424
+ }).describe("Defines a component on the PCB");
10425
+ var any_circuit_element = z.union([
10426
+ source_trace,
10427
+ source_port,
10428
+ any_source_component,
10429
+ source_led,
10430
+ source_net,
10431
+ source_group,
10432
+ source_simple_bug,
10433
+ source_simple_chip,
10434
+ source_simple_capacitor,
10435
+ source_simple_diode,
10436
+ source_simple_resistor,
10437
+ source_simple_power_source,
10438
+ pcb_component,
10439
+ pcb_hole,
10440
+ pcb_plated_hole,
10441
+ pcb_keepout,
10442
+ pcb_port,
10443
+ pcb_text,
10444
+ pcb_trace,
10445
+ pcb_via,
10446
+ pcb_smtpad,
10447
+ pcb_board,
10448
+ pcb_trace_hint,
10449
+ pcb_silkscreen_line,
10450
+ pcb_silkscreen_path,
10451
+ pcb_silkscreen_text,
10452
+ pcb_silkscreen_rect,
10453
+ pcb_silkscreen_circle,
10454
+ pcb_silkscreen_oval,
10455
+ pcb_trace_error,
10456
+ pcb_placement_error,
10457
+ pcb_port_not_matched_error,
10458
+ pcb_fabrication_note_path,
10459
+ pcb_fabrication_note_text,
10460
+ schematic_box,
10461
+ schematic_text,
10462
+ schematic_line,
10463
+ schematic_component,
10464
+ schematic_port,
10465
+ schematic_trace,
10466
+ schematic_path,
10467
+ schematic_error,
10468
+ schematic_net_label,
10469
+ cad_component
10470
+ ]);
10471
+ var any_soup_element = any_circuit_element;
10472
+ // node_modules/@tscircuit/soup-util/dist/index.js
10473
+ var import_transformation_matrix = require("transformation-matrix");
10474
+ var su = function(soup) {
10475
+ var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
10476
+ var internalStore = soup._internal_store;
10477
+ if (!internalStore) {
10478
+ internalStore = {
10479
+ counts: {}
10480
+ };
10481
+ soup._internal_store = internalStore;
10482
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
10483
+ try {
10484
+ for(var _iterator = soup[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
10485
+ var elm = _step.value;
10486
+ var type = elm.type;
10487
+ var idVal = elm["".concat(type, "_id")];
10488
+ if (!idVal) continue;
10489
+ var idNum = Number.parseInt(idVal.split("_").pop());
10490
+ if (!Number.isNaN(idNum)) {
10491
+ var _internalStore_counts_type;
10492
+ internalStore.counts[type] = Math.max((_internalStore_counts_type = internalStore.counts[type]) !== null && _internalStore_counts_type !== void 0 ? _internalStore_counts_type : 0, idNum);
10493
+ }
10494
+ }
10495
+ } catch (err) {
10496
+ _didIteratorError = true;
10497
+ _iteratorError = err;
10498
+ } finally{
10499
+ try {
10500
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
10501
+ _iterator.return();
10502
+ }
10503
+ } finally{
10504
+ if (_didIteratorError) {
10505
+ throw _iteratorError;
10506
+ }
10507
+ }
10508
+ }
10509
+ }
10510
+ var su2 = new Proxy({}, {
10511
+ get: function(proxy_target, component_type) {
10512
+ if (component_type === "toArray") {
10513
+ return function() {
10514
+ return soup;
10515
+ };
10516
+ }
10517
+ return {
10518
+ get: function(id) {
10519
+ return soup.find(function(e) {
10520
+ return e.type === component_type && e["".concat(component_type, "_id")] === id;
10521
+ });
10522
+ },
10523
+ getUsing: function(using) {
10524
+ var keys = Object.keys(using);
10525
+ if (keys.length !== 1) {
10526
+ throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");
10527
+ }
10528
+ var join_key = keys[0];
10529
+ var join_type = join_key.replace("_id", "");
10530
+ var joiner = soup.find(function(e) {
10531
+ return e.type === join_type && e[join_key] === using[join_key];
10532
+ });
10533
+ if (!joiner) return null;
10534
+ return soup.find(function(e) {
10535
+ return e.type === component_type && e["".concat(component_type, "_id")] === joiner["".concat(component_type, "_id")];
10536
+ });
10537
+ },
10538
+ getWhere: function(where) {
10539
+ var keys = Object.keys(where);
10540
+ return soup.find(function(e) {
10541
+ return e.type === component_type && keys.every(function(key) {
10542
+ return e[key] === where[key];
10543
+ });
10544
+ });
10545
+ },
10546
+ list: function(where) {
10547
+ var keys = !where ? [] : Object.keys(where);
10548
+ return soup.filter(function(e) {
10549
+ return e.type === component_type && keys.every(function(key) {
10550
+ return e[key] === where[key];
10551
+ });
10552
+ });
10553
+ },
10554
+ insert: function(elm) {
10555
+ var _a;
10556
+ var _component_type;
10557
+ (_component_type = (_a = internalStore.counts)[component_type]) !== null && _component_type !== void 0 ? _component_type : _a[component_type] = -1;
10558
+ internalStore.counts[component_type]++;
10559
+ var index = internalStore.counts[component_type];
10560
+ var newElm = _object_spread(_define_property({
10561
+ type: component_type
10562
+ }, "".concat(component_type, "_id"), "".concat(component_type, "_").concat(index)), elm);
10563
+ if (options.validateInserts) {
10564
+ var _dist_exports_component_type;
10565
+ var parser = (_dist_exports_component_type = dist_exports[component_type]) !== null && _dist_exports_component_type !== void 0 ? _dist_exports_component_type : any_soup_element;
10566
+ parser.parse(newElm);
10567
+ }
10568
+ soup.push(newElm);
10569
+ return newElm;
10570
+ },
10571
+ delete: function(id) {
10572
+ var elm = soup.find(function(e) {
10573
+ return e["".concat(component_type, "_id")] === id;
10574
+ });
10575
+ if (!elm) return;
10576
+ soup.splice(soup.indexOf(elm), 1);
10577
+ },
10578
+ update: function(id, newProps) {
10579
+ var elm = soup.find(function(e) {
10580
+ return e["".concat(component_type, "_id")] === id;
10581
+ });
10582
+ if (!elm) return;
10583
+ Object.assign(elm, newProps);
10584
+ return elm;
10585
+ },
10586
+ select: function(selector) {
10587
+ if (component_type === "source_component") {
10588
+ return soup.find(function(e) {
10589
+ return e.type === "source_component" && e.name === selector.replace(/\./g, "");
10590
+ });
10591
+ } else if (component_type === "pcb_port" || component_type === "source_port" || component_type === "schematic_port") {
10592
+ var _selector_replace_split = _sliced_to_array(selector.replace(/\./g, "").split(/[\s\>]+/), 2), component_name = _selector_replace_split[0], port_selector = _selector_replace_split[1];
10593
+ var source_component = soup.find(function(e) {
10594
+ return e.type === "source_component" && e.name === component_name;
10595
+ });
10596
+ if (!source_component) return null;
10597
+ var source_port2 = soup.find(function(e) {
10598
+ var _e_port_hints;
10599
+ return e.type === "source_port" && e.source_component_id === source_component.source_component_id && (e.name === port_selector || ((_e_port_hints = e.port_hints) !== null && _e_port_hints !== void 0 ? _e_port_hints : []).includes(port_selector));
10600
+ });
10601
+ if (!source_port2) return null;
10602
+ if (component_type === "source_port") return source_port2;
10603
+ if (component_type === "pcb_port") {
10604
+ return soup.find(function(e) {
10605
+ return e.type === "pcb_port" && e.source_port_id === source_port2.source_port_id;
10606
+ });
10607
+ } else if (component_type === "schematic_port") {
10608
+ return soup.find(function(e) {
10609
+ return e.type === "schematic_port" && e.source_port_id === source_port2.source_port_id;
10610
+ });
10611
+ }
10612
+ }
10613
+ }
10614
+ };
10615
+ }
10616
+ });
10617
+ return su2;
10618
+ };
10619
+ su.unparsed = su;
10620
+ var su_default = su;
10621
+ var transformPCBElement = function(elm, matrix) {
10622
+ if (elm.type === "pcb_plated_hole" || elm.type === "pcb_hole" || elm.type === "pcb_via" || elm.type === "pcb_smtpad" || elm.type === "pcb_port") {
10623
+ var _ref = (0, import_transformation_matrix.applyToPoint)(matrix, {
10624
+ x: elm.x,
10625
+ y: elm.y
10626
+ }), x = _ref.x, y = _ref.y;
10627
+ elm.x = x;
10628
+ elm.y = y;
10629
+ } else if (elm.type === "pcb_keepout" || elm.type === "pcb_board") {
10630
+ elm.center = (0, import_transformation_matrix.applyToPoint)(matrix, elm.center);
10631
+ } else if (elm.type === "pcb_silkscreen_text" || elm.type === "pcb_fabrication_note_text") {
10632
+ elm.anchor_position = (0, import_transformation_matrix.applyToPoint)(matrix, elm.anchor_position);
10633
+ } else if (elm.type === "pcb_silkscreen_circle" || elm.type === "pcb_silkscreen_rect" || elm.type === "pcb_component") {
10634
+ elm.center = (0, import_transformation_matrix.applyToPoint)(matrix, elm.center);
10635
+ } else if (elm.type === "pcb_silkscreen_path" || elm.type === "pcb_trace" || elm.type === "pcb_fabrication_note_path") {
10636
+ elm.route = elm.route.map(function(rp) {
10637
+ var tp = (0, import_transformation_matrix.applyToPoint)(matrix, rp);
10638
+ rp.x = tp.x;
10639
+ rp.y = tp.y;
10640
+ return rp;
10641
+ });
10642
+ } else if (elm.type === "pcb_silkscreen_line") {
10643
+ var p1 = {
10644
+ x: elm.x1,
10645
+ y: elm.y1
10646
+ };
10647
+ var p2 = {
10648
+ x: elm.x2,
10649
+ y: elm.y2
10650
+ };
10651
+ var p1t = (0, import_transformation_matrix.applyToPoint)(matrix, p1);
10652
+ var p2t = (0, import_transformation_matrix.applyToPoint)(matrix, p2);
10653
+ elm.x1 = p1t.x;
10654
+ elm.y1 = p1t.y;
10655
+ elm.x2 = p2t.x;
10656
+ elm.y2 = p2t.y;
10657
+ } else if (elm.type === "cad_component") {
10658
+ var newPos = (0, import_transformation_matrix.applyToPoint)(matrix, {
10659
+ x: elm.position.x,
10660
+ y: elm.position.y
10661
+ });
10662
+ elm.position.x = newPos.x;
10663
+ elm.position.y = newPos.y;
10664
+ }
10665
+ return elm;
10666
+ };
10667
+ function stringHash(str) {
10668
+ var hash = 0;
10669
+ if (str.length == 0) return hash;
10670
+ for(var i = 0; i < str.length; i++){
10671
+ var char = str.charCodeAt(i);
10672
+ hash = (hash << 5) - hash + char;
10673
+ hash = hash & hash;
10674
+ }
10675
+ return Math.abs(hash);
10676
+ }
10677
+ var nice_color_palettes = [
10678
+ [
10679
+ "#69d2e7",
10680
+ "#a7dbd8",
10681
+ "#e0e4cc",
10682
+ "#f38630",
10683
+ "#fa6900"
10684
+ ],
10685
+ [
10686
+ "#fe4365",
10687
+ "#fc9d9a",
10688
+ "#f9cdad",
10689
+ "#c8c8a9",
10690
+ "#83af9b"
10691
+ ],
10692
+ [
10693
+ "#ecd078",
10694
+ "#d95b43",
10695
+ "#c02942",
10696
+ "#542437",
10697
+ "#53777a"
10698
+ ],
10699
+ [
10700
+ "#556270",
10701
+ "#4ecdc4",
10702
+ "#c7f464",
10703
+ "#ff6b6b",
10704
+ "#c44d58"
10705
+ ],
10706
+ [
10707
+ "#774f38",
10708
+ "#e08e79",
10709
+ "#f1d4af",
10710
+ "#ece5ce",
10711
+ "#c5e0dc"
10712
+ ],
10713
+ [
10714
+ "#e8ddcb",
10715
+ "#cdb380",
10716
+ "#036564",
10717
+ "#033649",
10718
+ "#031634"
10719
+ ],
10720
+ [
10721
+ "#490a3d",
10722
+ "#bd1550",
10723
+ "#e97f02",
10724
+ "#f8ca00",
10725
+ "#8a9b0f"
10726
+ ],
10727
+ [
10728
+ "#594f4f",
10729
+ "#547980",
10730
+ "#45ada8",
10731
+ "#9de0ad",
10732
+ "#e5fcc2"
10733
+ ],
10734
+ [
10735
+ "#00a0b0",
10736
+ "#6a4a3c",
10737
+ "#cc333f",
10738
+ "#eb6841",
10739
+ "#edc951"
10740
+ ],
10741
+ [
10742
+ "#e94e77",
10743
+ "#d68189",
10744
+ "#c6a49a",
10745
+ "#c6e5d9",
10746
+ "#f4ead5"
10747
+ ],
10748
+ [
10749
+ "#3fb8af",
10750
+ "#7fc7af",
10751
+ "#dad8a7",
10752
+ "#ff9e9d",
10753
+ "#ff3d7f"
10754
+ ],
10755
+ [
10756
+ "#d9ceb2",
10757
+ "#948c75",
10758
+ "#d5ded9",
10759
+ "#7a6a53",
10760
+ "#99b2b7"
10761
+ ],
10762
+ [
10763
+ "#ffffff",
10764
+ "#cbe86b",
10765
+ "#f2e9e1",
10766
+ "#1c140d",
10767
+ "#cbe86b"
10768
+ ],
10769
+ [
10770
+ "#efffcd",
10771
+ "#dce9be",
10772
+ "#555152",
10773
+ "#2e2633",
10774
+ "#99173c"
10775
+ ],
10776
+ [
10777
+ "#343838",
10778
+ "#005f6b",
10779
+ "#008c9e",
10780
+ "#00b4cc",
10781
+ "#00dffc"
10782
+ ],
10783
+ [
10784
+ "#413e4a",
10785
+ "#73626e",
10786
+ "#b38184",
10787
+ "#f0b49e",
10788
+ "#f7e4be"
10789
+ ],
10790
+ [
10791
+ "#ff4e50",
10792
+ "#fc913a",
10793
+ "#f9d423",
10794
+ "#ede574",
10795
+ "#e1f5c4"
10796
+ ],
10797
+ [
10798
+ "#99b898",
10799
+ "#fecea8",
10800
+ "#ff847c",
10801
+ "#e84a5f",
10802
+ "#2a363b"
10803
+ ],
10804
+ [
10805
+ "#655643",
10806
+ "#80bca3",
10807
+ "#f6f7bd",
10808
+ "#e6ac27",
10809
+ "#bf4d28"
10810
+ ],
10811
+ [
10812
+ "#00a8c6",
10813
+ "#40c0cb",
10814
+ "#f9f2e7",
10815
+ "#aee239",
10816
+ "#8fbe00"
10817
+ ],
10818
+ [
10819
+ "#351330",
10820
+ "#424254",
10821
+ "#64908a",
10822
+ "#e8caa4",
10823
+ "#cc2a41"
10824
+ ],
10825
+ [
10826
+ "#554236",
10827
+ "#f77825",
10828
+ "#d3ce3d",
10829
+ "#f1efa5",
10830
+ "#60b99a"
10831
+ ],
10832
+ [
10833
+ "#5d4157",
10834
+ "#838689",
10835
+ "#a8caba",
10836
+ "#cad7b2",
10837
+ "#ebe3aa"
10838
+ ],
10839
+ [
10840
+ "#8c2318",
10841
+ "#5e8c6a",
10842
+ "#88a65e",
10843
+ "#bfb35a",
10844
+ "#f2c45a"
10845
+ ],
10846
+ [
10847
+ "#fad089",
10848
+ "#ff9c5b",
10849
+ "#f5634a",
10850
+ "#ed303c",
10851
+ "#3b8183"
10852
+ ],
10853
+ [
10854
+ "#ff4242",
10855
+ "#f4fad2",
10856
+ "#d4ee5e",
10857
+ "#e1edb9",
10858
+ "#f0f2eb"
10859
+ ],
10860
+ [
10861
+ "#f8b195",
10862
+ "#f67280",
10863
+ "#c06c84",
10864
+ "#6c5b7b",
10865
+ "#355c7d"
10866
+ ],
10867
+ [
10868
+ "#d1e751",
10869
+ "#ffffff",
10870
+ "#000000",
10871
+ "#4dbce9",
10872
+ "#26ade4"
10873
+ ],
10874
+ [
10875
+ "#1b676b",
10876
+ "#519548",
10877
+ "#88c425",
10878
+ "#bef202",
10879
+ "#eafde6"
10880
+ ],
10881
+ [
10882
+ "#5e412f",
10883
+ "#fcebb6",
10884
+ "#78c0a8",
10885
+ "#f07818",
10886
+ "#f0a830"
10887
+ ],
10888
+ [
10889
+ "#bcbdac",
10890
+ "#cfbe27",
10891
+ "#f27435",
10892
+ "#f02475",
10893
+ "#3b2d38"
10894
+ ],
10895
+ [
10896
+ "#452632",
10897
+ "#91204d",
10898
+ "#e4844a",
10899
+ "#e8bf56",
10900
+ "#e2f7ce"
10901
+ ],
10902
+ [
10903
+ "#eee6ab",
10904
+ "#c5bc8e",
10905
+ "#696758",
10906
+ "#45484b",
10907
+ "#36393b"
10908
+ ],
10909
+ [
10910
+ "#f0d8a8",
10911
+ "#3d1c00",
10912
+ "#86b8b1",
10913
+ "#f2d694",
10914
+ "#fa2a00"
10915
+ ],
10916
+ [
10917
+ "#2a044a",
10918
+ "#0b2e59",
10919
+ "#0d6759",
10920
+ "#7ab317",
10921
+ "#a0c55f"
10922
+ ],
10923
+ [
10924
+ "#f04155",
10925
+ "#ff823a",
10926
+ "#f2f26f",
10927
+ "#fff7bd",
10928
+ "#95cfb7"
10929
+ ],
10930
+ [
10931
+ "#b9d7d9",
10932
+ "#668284",
10933
+ "#2a2829",
10934
+ "#493736",
10935
+ "#7b3b3b"
10936
+ ],
10937
+ [
10938
+ "#bbbb88",
10939
+ "#ccc68d",
10940
+ "#eedd99",
10941
+ "#eec290",
10942
+ "#eeaa88"
10943
+ ],
10944
+ [
10945
+ "#b3cc57",
10946
+ "#ecf081",
10947
+ "#ffbe40",
10948
+ "#ef746f",
10949
+ "#ab3e5b"
10950
+ ],
10951
+ [
10952
+ "#a3a948",
10953
+ "#edb92e",
10954
+ "#f85931",
10955
+ "#ce1836",
10956
+ "#009989"
10957
+ ],
10958
+ [
10959
+ "#300030",
10960
+ "#480048",
10961
+ "#601848",
10962
+ "#c04848",
10963
+ "#f07241"
10964
+ ],
10965
+ [
10966
+ "#67917a",
10967
+ "#170409",
10968
+ "#b8af03",
10969
+ "#ccbf82",
10970
+ "#e33258"
10971
+ ],
10972
+ [
10973
+ "#aab3ab",
10974
+ "#c4cbb7",
10975
+ "#ebefc9",
10976
+ "#eee0b7",
10977
+ "#e8caaf"
10978
+ ],
10979
+ [
10980
+ "#e8d5b7",
10981
+ "#0e2430",
10982
+ "#fc3a51",
10983
+ "#f5b349",
10984
+ "#e8d5b9"
10985
+ ],
10986
+ [
10987
+ "#ab526b",
10988
+ "#bca297",
10989
+ "#c5ceae",
10990
+ "#f0e2a4",
10991
+ "#f4ebc3"
10992
+ ],
10993
+ [
10994
+ "#607848",
10995
+ "#789048",
10996
+ "#c0d860",
10997
+ "#f0f0d8",
10998
+ "#604848"
10999
+ ],
11000
+ [
11001
+ "#b6d8c0",
11002
+ "#c8d9bf",
11003
+ "#dadabd",
11004
+ "#ecdbbc",
11005
+ "#fedcba"
11006
+ ],
11007
+ [
11008
+ "#a8e6ce",
11009
+ "#dcedc2",
11010
+ "#ffd3b5",
11011
+ "#ffaaa6",
11012
+ "#ff8c94"
11013
+ ],
11014
+ [
11015
+ "#3e4147",
11016
+ "#fffedf",
11017
+ "#dfba69",
11018
+ "#5a2e2e",
11019
+ "#2a2c31"
11020
+ ],
11021
+ [
11022
+ "#fc354c",
11023
+ "#29221f",
11024
+ "#13747d",
11025
+ "#0abfbc",
11026
+ "#fcf7c5"
11027
+ ],
11028
+ [
11029
+ "#cc0c39",
11030
+ "#e6781e",
11031
+ "#c8cf02",
11032
+ "#f8fcc1",
11033
+ "#1693a7"
11034
+ ],
11035
+ [
11036
+ "#1c2130",
11037
+ "#028f76",
11038
+ "#b3e099",
11039
+ "#ffeaad",
11040
+ "#d14334"
11041
+ ],
11042
+ [
11043
+ "#a7c5bd",
11044
+ "#e5ddcb",
11045
+ "#eb7b59",
11046
+ "#cf4647",
11047
+ "#524656"
11048
+ ],
11049
+ [
11050
+ "#dad6ca",
11051
+ "#1bb0ce",
11052
+ "#4f8699",
11053
+ "#6a5e72",
11054
+ "#563444"
11055
+ ],
11056
+ [
11057
+ "#5c323e",
11058
+ "#a82743",
11059
+ "#e15e32",
11060
+ "#c0d23e",
11061
+ "#e5f04c"
11062
+ ],
11063
+ [
11064
+ "#edebe6",
11065
+ "#d6e1c7",
11066
+ "#94c7b6",
11067
+ "#403b33",
11068
+ "#d3643b"
11069
+ ],
11070
+ [
11071
+ "#fdf1cc",
11072
+ "#c6d6b8",
11073
+ "#987f69",
11074
+ "#e3ad40",
11075
+ "#fcd036"
11076
+ ],
11077
+ [
11078
+ "#230f2b",
11079
+ "#f21d41",
11080
+ "#ebebbc",
11081
+ "#bce3c5",
11082
+ "#82b3ae"
11083
+ ],
11084
+ [
11085
+ "#b9d3b0",
11086
+ "#81bda4",
11087
+ "#b28774",
11088
+ "#f88f79",
11089
+ "#f6aa93"
11090
+ ],
11091
+ [
11092
+ "#3a111c",
11093
+ "#574951",
11094
+ "#83988e",
11095
+ "#bcdea5",
11096
+ "#e6f9bc"
11097
+ ],
11098
+ [
11099
+ "#5e3929",
11100
+ "#cd8c52",
11101
+ "#b7d1a3",
11102
+ "#dee8be",
11103
+ "#fcf7d3"
11104
+ ],
11105
+ [
11106
+ "#1c0113",
11107
+ "#6b0103",
11108
+ "#a30006",
11109
+ "#c21a01",
11110
+ "#f03c02"
11111
+ ],
11112
+ [
11113
+ "#000000",
11114
+ "#9f111b",
11115
+ "#b11623",
11116
+ "#292c37",
11117
+ "#cccccc"
11118
+ ],
11119
+ [
11120
+ "#382f32",
11121
+ "#ffeaf2",
11122
+ "#fcd9e5",
11123
+ "#fbc5d8",
11124
+ "#f1396d"
11125
+ ],
11126
+ [
11127
+ "#e3dfba",
11128
+ "#c8d6bf",
11129
+ "#93ccc6",
11130
+ "#6cbdb5",
11131
+ "#1a1f1e"
11132
+ ],
11133
+ [
11134
+ "#f6f6f6",
11135
+ "#e8e8e8",
11136
+ "#333333",
11137
+ "#990100",
11138
+ "#b90504"
11139
+ ],
11140
+ [
11141
+ "#1b325f",
11142
+ "#9cc4e4",
11143
+ "#e9f2f9",
11144
+ "#3a89c9",
11145
+ "#f26c4f"
11146
+ ],
11147
+ [
11148
+ "#a1dbb2",
11149
+ "#fee5ad",
11150
+ "#faca66",
11151
+ "#f7a541",
11152
+ "#f45d4c"
11153
+ ],
11154
+ [
11155
+ "#c1b398",
11156
+ "#605951",
11157
+ "#fbeec2",
11158
+ "#61a6ab",
11159
+ "#accec0"
11160
+ ],
11161
+ [
11162
+ "#5e9fa3",
11163
+ "#dcd1b4",
11164
+ "#fab87f",
11165
+ "#f87e7b",
11166
+ "#b05574"
11167
+ ],
11168
+ [
11169
+ "#951f2b",
11170
+ "#f5f4d7",
11171
+ "#e0dfb1",
11172
+ "#a5a36c",
11173
+ "#535233"
11174
+ ],
11175
+ [
11176
+ "#8dccad",
11177
+ "#988864",
11178
+ "#fea6a2",
11179
+ "#f9d6ac",
11180
+ "#ffe9af"
11181
+ ],
11182
+ [
11183
+ "#2d2d29",
11184
+ "#215a6d",
11185
+ "#3ca2a2",
11186
+ "#92c7a3",
11187
+ "#dfece6"
11188
+ ],
11189
+ [
11190
+ "#413d3d",
11191
+ "#040004",
11192
+ "#c8ff00",
11193
+ "#fa023c",
11194
+ "#4b000f"
11195
+ ],
11196
+ [
11197
+ "#eff3cd",
11198
+ "#b2d5ba",
11199
+ "#61ada0",
11200
+ "#248f8d",
11201
+ "#605063"
11202
+ ],
11203
+ [
11204
+ "#ffefd3",
11205
+ "#fffee4",
11206
+ "#d0ecea",
11207
+ "#9fd6d2",
11208
+ "#8b7a5e"
11209
+ ],
11210
+ [
11211
+ "#cfffdd",
11212
+ "#b4dec1",
11213
+ "#5c5863",
11214
+ "#a85163",
11215
+ "#ff1f4c"
11216
+ ],
11217
+ [
11218
+ "#9dc9ac",
11219
+ "#fffec7",
11220
+ "#f56218",
11221
+ "#ff9d2e",
11222
+ "#919167"
11223
+ ],
11224
+ [
11225
+ "#4e395d",
11226
+ "#827085",
11227
+ "#8ebe94",
11228
+ "#ccfc8e",
11229
+ "#dc5b3e"
11230
+ ],
11231
+ [
11232
+ "#a8a7a7",
11233
+ "#cc527a",
11234
+ "#e8175d",
11235
+ "#474747",
11236
+ "#363636"
11237
+ ],
11238
+ [
11239
+ "#f8edd1",
11240
+ "#d88a8a",
11241
+ "#474843",
11242
+ "#9d9d93",
11243
+ "#c5cfc6"
11244
+ ],
11245
+ [
11246
+ "#046d8b",
11247
+ "#309292",
11248
+ "#2fb8ac",
11249
+ "#93a42a",
11250
+ "#ecbe13"
11251
+ ],
11252
+ [
11253
+ "#f38a8a",
11254
+ "#55443d",
11255
+ "#a0cab5",
11256
+ "#cde9ca",
11257
+ "#f1edd0"
11258
+ ],
11259
+ [
11260
+ "#a70267",
11261
+ "#f10c49",
11262
+ "#fb6b41",
11263
+ "#f6d86b",
11264
+ "#339194"
11265
+ ],
11266
+ [
11267
+ "#ff003c",
11268
+ "#ff8a00",
11269
+ "#fabe28",
11270
+ "#88c100",
11271
+ "#00c176"
11272
+ ],
11273
+ [
11274
+ "#ffedbf",
11275
+ "#f7803c",
11276
+ "#f54828",
11277
+ "#2e0d23",
11278
+ "#f8e4c1"
11279
+ ],
11280
+ [
11281
+ "#4e4d4a",
11282
+ "#353432",
11283
+ "#94ba65",
11284
+ "#2790b0",
11285
+ "#2b4e72"
11286
+ ],
11287
+ [
11288
+ "#0ca5b0",
11289
+ "#4e3f30",
11290
+ "#fefeeb",
11291
+ "#f8f4e4",
11292
+ "#a5b3aa"
11293
+ ],
11294
+ [
11295
+ "#4d3b3b",
11296
+ "#de6262",
11297
+ "#ffb88c",
11298
+ "#ffd0b3",
11299
+ "#f5e0d3"
11300
+ ],
11301
+ [
11302
+ "#fffbb7",
11303
+ "#a6f6af",
11304
+ "#66b6ab",
11305
+ "#5b7c8d",
11306
+ "#4f2958"
11307
+ ],
11308
+ [
11309
+ "#edf6ee",
11310
+ "#d1c089",
11311
+ "#b3204d",
11312
+ "#412e28",
11313
+ "#151101"
11314
+ ],
11315
+ [
11316
+ "#9d7e79",
11317
+ "#ccac95",
11318
+ "#9a947c",
11319
+ "#748b83",
11320
+ "#5b756c"
11321
+ ],
11322
+ [
11323
+ "#fcfef5",
11324
+ "#e9ffe1",
11325
+ "#cdcfb7",
11326
+ "#d6e6c3",
11327
+ "#fafbe3"
11328
+ ],
11329
+ [
11330
+ "#9cddc8",
11331
+ "#bfd8ad",
11332
+ "#ddd9ab",
11333
+ "#f7af63",
11334
+ "#633d2e"
11335
+ ],
11336
+ [
11337
+ "#30261c",
11338
+ "#403831",
11339
+ "#36544f",
11340
+ "#1f5f61",
11341
+ "#0b8185"
11342
+ ],
11343
+ [
11344
+ "#aaff00",
11345
+ "#ffaa00",
11346
+ "#ff00aa",
11347
+ "#aa00ff",
11348
+ "#00aaff"
11349
+ ],
11350
+ [
11351
+ "#d1313d",
11352
+ "#e5625c",
11353
+ "#f9bf76",
11354
+ "#8eb2c5",
11355
+ "#615375"
11356
+ ],
11357
+ [
11358
+ "#ffe181",
11359
+ "#eee9e5",
11360
+ "#fad3b2",
11361
+ "#ffba7f",
11362
+ "#ff9c97"
11363
+ ],
11364
+ [
11365
+ "#73c8a9",
11366
+ "#dee1b6",
11367
+ "#e1b866",
11368
+ "#bd5532",
11369
+ "#373b44"
11370
+ ],
11371
+ [
11372
+ "#805841",
11373
+ "#dcf7f3",
11374
+ "#fffcdd",
11375
+ "#ffd8d8",
11376
+ "#f5a2a2"
11377
+ ]
11378
+ ];
11379
+ var getDebugLayoutObject = function(lo) {
11380
+ var _lo_source, _lo_source1, _nice_color_palettes_;
11381
+ var _$_object_spread = _object_spread({}, lo, lo.size, lo.center, lo.position), x = _$_object_spread.x, y = _$_object_spread.y, width = _$_object_spread.width, height = _$_object_spread.height;
11382
+ if (lo.x1 !== void 0 && lo.x2 !== void 0 && lo.y1 !== void 0 && lo.y2 !== void 0) {
11383
+ x = (lo.x1 + lo.x2) / 2;
11384
+ y = (lo.y1 + lo.y2) / 2;
11385
+ width = Math.abs(lo.x1 - lo.x2);
11386
+ height = Math.abs(lo.y1 - lo.y2);
11387
+ }
11388
+ var title = lo.text || lo.name || ((_lo_source = lo.source) === null || _lo_source === void 0 ? void 0 : _lo_source.text) || ((_lo_source1 = lo.source) === null || _lo_source1 === void 0 ? void 0 : _lo_source1.name) || "?";
11389
+ var content = lo;
11390
+ if (x === void 0 || y === void 0) return null;
11391
+ if (width === void 0) {
11392
+ if ("outer_diameter" in lo) {
11393
+ width = lo.outer_diameter;
11394
+ height = lo.outer_diameter;
11395
+ }
11396
+ }
11397
+ if (width === void 0 || height === void 0) {
11398
+ width = 0.1;
11399
+ height = 0.1;
11400
+ }
11401
+ var _nice_color_palettes__;
11402
+ return {
11403
+ x: x,
11404
+ y: y,
11405
+ width: width,
11406
+ height: height,
11407
+ title: title,
11408
+ content: content,
11409
+ bg_color: (_nice_color_palettes__ = (_nice_color_palettes_ = nice_color_palettes[stringHash(lo.type || title) % nice_color_palettes.length]) === null || _nice_color_palettes_ === void 0 ? void 0 : _nice_color_palettes_[4]) !== null && _nice_color_palettes__ !== void 0 ? _nice_color_palettes__ : "#f00"
11410
+ };
11411
+ };
11412
+ var isTruthy = function(value) {
11413
+ return Boolean(value);
11414
+ };
11415
+ var findBoundsAndCenter = function(elements) {
11416
+ var debugObjects = elements.filter(function(elm) {
11417
+ return elm.type.startsWith("pcb_");
11418
+ }).concat(elements.filter(function(elm) {
11419
+ return elm.type === "pcb_trace";
11420
+ }).flatMap(function(elm) {
11421
+ return elm.route;
11422
+ })).map(function(elm) {
11423
+ return getDebugLayoutObject(elm);
11424
+ }).filter(isTruthy);
11425
+ if (debugObjects.length === 0) return {
11426
+ center: {
11427
+ x: 0,
11428
+ y: 0
11429
+ },
11430
+ width: 0,
11431
+ height: 0
11432
+ };
11433
+ var minX = debugObjects[0].x - debugObjects[0].width / 2;
11434
+ var maxX = debugObjects[0].x + debugObjects[0].width / 2;
11435
+ var minY = debugObjects[0].y - debugObjects[0].height / 2;
11436
+ var maxY = debugObjects[0].y + debugObjects[0].height / 2;
11437
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
11438
+ try {
11439
+ for(var _iterator = debugObjects.slice(1)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
11440
+ var obj = _step.value;
11441
+ minX = Math.min(minX, obj.x - obj.width / 2);
11442
+ maxX = Math.max(maxX, obj.x + obj.width / 2);
11443
+ minY = Math.min(minY, obj.y - obj.height / 2);
11444
+ maxY = Math.max(maxY, obj.y + obj.height / 2);
11445
+ }
11446
+ } catch (err) {
11447
+ _didIteratorError = true;
11448
+ _iteratorError = err;
11449
+ } finally{
11450
+ try {
11451
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
11452
+ _iterator.return();
11453
+ }
11454
+ } finally{
11455
+ if (_didIteratorError) {
11456
+ throw _iteratorError;
11457
+ }
11458
+ }
11459
+ }
11460
+ var width = maxX - minX;
11461
+ var height = maxY - minY;
11462
+ var center = {
11463
+ x: minX + width / 2,
11464
+ y: minY + height / 2
11465
+ };
11466
+ return {
11467
+ center: center,
11468
+ width: width,
11469
+ height: height
11470
+ };
11471
+ };
11472
+ // src/components/ContextProviders.tsx
11473
+ var import_react2 = require("react");
11474
+ var import_react3 = require("react");
11475
+ // src/global-store.ts
11476
+ var import_zustand = require("zustand");
11477
+ var import_react = require("react");
11478
+ var createStore = function() {
11479
+ var initialState = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
11480
+ return (0, import_zustand.createStore)(function(set) {
11481
+ return _object_spread_props(_object_spread({
11482
+ selected_layer: "top",
11483
+ pcb_viewer_id: "pcb_viewer_".concat(Math.random().toString().slice(2, 10)),
11484
+ in_edit_mode: false,
11485
+ in_move_footprint_mode: false,
11486
+ in_draw_trace_mode: false,
11487
+ is_moving_component: false,
11488
+ is_drawing_trace: false,
11489
+ is_mouse_over_container: false,
11490
+ is_showing_rats_nest: false
11491
+ }, initialState), {
11492
+ selectLayer: function(layer) {
11493
+ return set({
11494
+ selected_layer: layer
11495
+ });
11496
+ },
11497
+ setEditMode: function(mode) {
11498
+ return set({
11499
+ in_edit_mode: mode !== "off",
11500
+ in_move_footprint_mode: mode === "move_footprint",
11501
+ in_draw_trace_mode: mode === "draw_trace",
11502
+ is_moving_component: false,
11503
+ is_drawing_trace: false
11504
+ });
11505
+ },
11506
+ setIsShowingRatsNest: function(is_showing) {
11507
+ return set({
11508
+ is_showing_rats_nest: is_showing
11509
+ });
11510
+ },
11511
+ setIsMovingComponent: function(is_moving) {
11512
+ return set({
11513
+ is_moving_component: is_moving
11514
+ });
11515
+ },
11516
+ setIsDrawingTrace: function(is_drawing) {
11517
+ return set({
11518
+ is_drawing_trace: is_drawing
11519
+ });
11520
+ },
11521
+ setIsMouseOverContainer: function(is_focused) {
11522
+ return set({
11523
+ is_mouse_over_container: is_focused
11524
+ });
11525
+ }
11526
+ });
11527
+ });
11528
+ };
11529
+ var useGlobalStore = function(s) {
11530
+ var store = (0, import_react.useContext)(StoreContext);
11531
+ return (0, import_zustand.useStore)(store, s);
11532
+ };
11533
+ // src/components/ContextProviders.tsx
11534
+ var import_jsx_runtime = require("react/jsx-runtime");
11535
+ var StoreContext = (0, import_react3.createContext)(null);
11536
+ var ContextProviders = function(param) {
11537
+ var children = param.children, initialState = param.initialState;
11538
+ var store = (0, import_react2.useMemo)(function() {
11539
+ return createStore(initialState);
11540
+ }, []);
11541
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StoreContext.Provider, {
11542
+ value: store,
11543
+ children: children
11544
+ });
11545
+ };
11546
+ // src/lib/apply-edit-events.ts
11547
+ var import_transformation_matrix2 = require("transformation-matrix");
11548
+ // src/lib/apply-edit-events/apply-edit-trace-hint-event.ts
11549
+ var applyTraceHintEditEvent = function(soup, edit_event) {
11550
+ var existing_trace_hint = soup.find(function(th) {
11551
+ return th.type === "pcb_trace_hint" && th.pcb_trace_hint_id === edit_event.pcb_trace_hint_id;
11552
+ });
11553
+ if (existing_trace_hint) {
11554
+ soup = soup.map(function(e) {
11555
+ return e.pcb_trace_hint_id === edit_event.pcb_trace_hint_id ? _object_spread_props(_object_spread({}, e), {
11556
+ route: edit_event.route
11557
+ }) : e;
11558
+ });
11559
+ } else {
11560
+ var pcb_port2 = su_default(soup).pcb_port.get(edit_event.pcb_port_id);
11561
+ soup = soup.filter(function(e) {
11562
+ return !(e.type === "pcb_trace_hint" && e.pcb_port_id === edit_event.pcb_port_id);
11563
+ }).concat([
11564
+ {
11565
+ type: "pcb_trace_hint",
11566
+ pcb_trace_hint_id: edit_event.pcb_trace_hint_id,
11567
+ route: edit_event.route,
11568
+ pcb_port_id: edit_event.pcb_port_id,
11569
+ pcb_component_id: pcb_port2 === null || pcb_port2 === void 0 ? void 0 : pcb_port2.pcb_component_id
11570
+ }
11571
+ ]);
11572
+ }
11573
+ return soup;
11574
+ };
11575
+ // src/lib/apply-edit-events.ts
11576
+ var applyEditEvents = function(soup, edit_events) {
11577
+ soup = JSON.parse(JSON.stringify(soup));
11578
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
11579
+ try {
11580
+ var _loop = function() {
11581
+ var edit_event = _step.value;
11582
+ if (edit_event.pcb_edit_event_type === "edit_component_location") {
11583
+ var mat = (0, import_transformation_matrix2.translate)(edit_event.new_center.x - edit_event.original_center.x, edit_event.new_center.y - edit_event.original_center.y);
11584
+ soup = soup.map(function(e) {
11585
+ return e.pcb_component_id !== edit_event.pcb_component_id ? e : transformPCBElement(e, mat);
11586
+ });
11587
+ } else if (edit_event.pcb_edit_event_type === "edit_trace_hint") {
11588
+ soup = applyTraceHintEditEvent(soup, edit_event);
11589
+ }
11590
+ };
11591
+ for(var _iterator = edit_events[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
11592
+ } catch (err) {
11593
+ _didIteratorError = true;
11594
+ _iteratorError = err;
11595
+ } finally{
11596
+ try {
11597
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
11598
+ _iterator.return();
11599
+ }
11600
+ } finally{
11601
+ if (_didIteratorError) {
11602
+ throw _iteratorError;
11603
+ }
11604
+ }
11605
+ }
11606
+ return soup;
11607
+ };
11608
+ // src/lib/toast.tsx
11609
+ var import_react4 = require("react");
11610
+ var import_react_toastify = require("react-toastify");
11611
+ var import_inject_style = require("react-toastify/dist/inject-style");
11612
+ var import_jsx_runtime2 = require("react/jsx-runtime");
11613
+ var useToast = function() {
11614
+ var pcb_viewer_id = useGlobalStore(function(s) {
11615
+ return s.pcb_viewer_id;
11616
+ });
11617
+ var toast = function(message, opts) {
11618
+ return (0, import_react_toastify.toast)(message, _object_spread({
11619
+ containerId: pcb_viewer_id
11620
+ }, opts));
11621
+ };
11622
+ toast.error = function(message, opts) {
11623
+ return import_react_toastify.toast.error(message, _object_spread({
11624
+ containerId: pcb_viewer_id
11625
+ }, opts));
11626
+ };
11627
+ toast.promise = import_react_toastify.toast.promise;
11628
+ return toast;
11629
+ };
11630
+ var ToastContainer = function() {
11631
+ (0, import_react4.useEffect)(function() {
11632
+ (0, import_inject_style.injectStyle)();
11633
+ }, []);
11634
+ var pcb_viewer_id = useGlobalStore(function(s) {
11635
+ return s.pcb_viewer_id;
11636
+ });
11637
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_toastify.ToastContainer, {
11638
+ position: "top-center",
11639
+ containerId: pcb_viewer_id
11640
+ });
11641
+ };
11642
+ // src/PCBViewer.tsx
11643
+ var import_react20 = require("react");
11644
+ // node_modules/react-use/esm/misc/util.js
11645
+ var noop = function noop() {};
11646
+ var isBrowser = typeof window !== "undefined";
11647
+ // node_modules/react-use/esm/useIsomorphicLayoutEffect.js
11648
+ var import_react5 = require("react");
11649
+ var useIsomorphicLayoutEffect = isBrowser ? import_react5.useLayoutEffect : import_react5.useEffect;
11650
+ var useIsomorphicLayoutEffect_default = useIsomorphicLayoutEffect;
11651
+ // node_modules/react-use/esm/useMeasure.js
11652
+ var import_react6 = require("react");
11653
+ var defaultState = {
11654
+ x: 0,
11655
+ y: 0,
11656
+ width: 0,
11657
+ height: 0,
11658
+ top: 0,
11659
+ left: 0,
11660
+ bottom: 0,
11661
+ right: 0
11662
+ };
11663
+ function useMeasure() {
11664
+ var _a = (0, import_react6.useState)(null), element = _a[0], ref = _a[1];
11665
+ var _b = (0, import_react6.useState)(defaultState), rect = _b[0], setRect = _b[1];
11666
+ var observer = (0, import_react6.useMemo)(function() {
11667
+ return new window.ResizeObserver(function(entries) {
11668
+ if (entries[0]) {
11669
+ 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;
11670
+ setRect({
11671
+ x: x,
11672
+ y: y,
11673
+ width: width,
11674
+ height: height,
11675
+ top: top_1,
11676
+ left: left,
11677
+ bottom: bottom,
11678
+ right: right
11679
+ });
11680
+ }
11681
+ });
11682
+ }, []);
11683
+ useIsomorphicLayoutEffect_default(function() {
11684
+ if (!element) return;
11685
+ observer.observe(element);
11686
+ return function() {
11687
+ observer.disconnect();
11688
+ };
11689
+ }, [
11690
+ element
11691
+ ]);
11692
+ return [
11693
+ ref,
11694
+ rect
11695
+ ];
11696
+ }
11697
+ var useMeasure_default = isBrowser && typeof window.ResizeObserver !== "undefined" ? useMeasure : function useMeasure_default() {
11698
+ return [
11699
+ noop,
11700
+ defaultState
11701
+ ];
11702
+ };
11703
+ // src/PCBViewer.tsx
11704
+ var import_transformation_matrix10 = require("transformation-matrix");
11705
+ var import_use_mouse_matrix_transform = __toESM(require_dist());
11706
+ // src/components/CanvasElementsRenderer.tsx
11707
+ var import_react18 = require("react");
11708
+ // src/components/CanvasPrimitiveRenderer.tsx
11709
+ var import_react_supergrid = require("react-supergrid");
11710
+ var import_react7 = require("react");
11711
+ // src/lib/Drawer.ts
11712
+ var import_transformation_matrix3 = require("transformation-matrix");
11713
+ // src/lib/colors.ts
11714
+ var colors_default = {
11715
+ "3d_viewer": {
11716
+ background_bottom: "rgb(102, 102, 128)",
11717
+ background_top: "rgb(204, 204, 230)",
11718
+ board: "rgb(51, 43, 23)",
11719
+ copper: "rgb(179, 156, 0)",
11720
+ silkscreen_bottom: "rgb(230, 230, 230)",
11721
+ silkscreen_top: "rgb(230, 230, 230)",
11722
+ soldermask: "rgb(20, 51, 36)",
11723
+ solderpaste: "rgb(128, 128, 128)"
11724
+ },
11725
+ board: {
11726
+ anchor: "rgb(255, 38, 226)",
11727
+ aux_items: "rgb(255, 255, 255)",
11728
+ b_adhes: "rgb(0, 0, 132)",
11729
+ b_crtyd: "rgb(255, 38, 226)",
11730
+ b_fab: "rgb(88, 93, 132)",
11731
+ b_mask: "rgba(2, 255, 238, 0.400)",
11732
+ b_paste: "rgb(0, 194, 194)",
11733
+ b_silks: "rgb(232, 178, 167)",
11734
+ background: "rgb(0, 16, 35)",
11735
+ cmts_user: "rgb(89, 148, 220)",
11736
+ copper: {
11737
+ b: "rgb(77, 127, 196)",
11738
+ f: "rgb(200, 52, 52)",
11739
+ in1: "rgb(127, 200, 127)",
11740
+ in10: "rgb(237, 124, 51)",
11741
+ in11: "rgb(91, 195, 235)",
11742
+ in12: "rgb(247, 111, 142)",
11743
+ in13: "rgb(167, 165, 198)",
11744
+ in14: "rgb(40, 204, 217)",
11745
+ in15: "rgb(232, 178, 167)",
11746
+ in16: "rgb(242, 237, 161)",
11747
+ in17: "rgb(237, 124, 51)",
11748
+ in18: "rgb(91, 195, 235)",
11749
+ in19: "rgb(247, 111, 142)",
11750
+ in2: "rgb(206, 125, 44)",
11751
+ in20: "rgb(167, 165, 198)",
11752
+ in21: "rgb(40, 204, 217)",
11753
+ in22: "rgb(232, 178, 167)",
11754
+ in23: "rgb(242, 237, 161)",
11755
+ in24: "rgb(237, 124, 51)",
11756
+ in25: "rgb(91, 195, 235)",
11757
+ in26: "rgb(247, 111, 142)",
11758
+ in27: "rgb(167, 165, 198)",
11759
+ in28: "rgb(40, 204, 217)",
11760
+ in29: "rgb(232, 178, 167)",
11761
+ in3: "rgb(79, 203, 203)",
11762
+ in30: "rgb(242, 237, 161)",
11763
+ in4: "rgb(219, 98, 139)",
11764
+ in5: "rgb(167, 165, 198)",
11765
+ in6: "rgb(40, 204, 217)",
11766
+ in7: "rgb(232, 178, 167)",
11767
+ in8: "rgb(242, 237, 161)",
11768
+ in9: "rgb(141, 203, 129)"
11769
+ },
11770
+ cursor: "rgb(255, 255, 255)",
11771
+ drc: "rgb(194, 194, 194)",
11772
+ drc_error: "rgba(215, 91, 107, 0.800)",
11773
+ drc_exclusion: "rgb(255, 255, 255)",
11774
+ drc_warning: "rgba(255, 208, 66, 0.902)",
11775
+ dwgs_user: "rgb(194, 194, 194)",
11776
+ eco1_user: "rgb(180, 219, 210)",
11777
+ eco2_user: "rgb(216, 200, 82)",
11778
+ edge_cuts: "rgb(208, 210, 205)",
11779
+ f_adhes: "rgb(132, 0, 132)",
11780
+ f_crtyd: "rgb(255, 0, 245)",
11781
+ f_fab: "rgb(175, 175, 175)",
11782
+ f_mask: "rgba(216, 100, 255, 0.400)",
11783
+ f_paste: "rgba(180, 160, 154, 0.902)",
11784
+ f_silks: "rgb(242, 237, 161)",
11785
+ footprint_text_back: "rgb(0, 0, 132)",
11786
+ footprint_text_front: "rgb(194, 194, 194)",
11787
+ footprint_text_invisible: "rgb(132, 132, 132)",
11788
+ grid: "rgb(132, 132, 132)",
11789
+ grid_axes: "rgb(194, 194, 194)",
11790
+ margin: "rgb(255, 38, 226)",
11791
+ microvia: "rgb(0, 132, 132)",
11792
+ no_connect: "rgb(0, 0, 132)",
11793
+ pad_back: "rgb(77, 127, 196)",
11794
+ pad_front: "rgb(200, 52, 52)",
11795
+ pad_plated_hole: "rgb(194, 194, 0)",
11796
+ pad_through_hole: "rgb(227, 183, 46)",
11797
+ plated_hole: "rgb(26, 196, 210)",
11798
+ ratsnest: "rgba(245, 255, 213, 0.702)",
11799
+ select_overlay: "rgb(4, 255, 67)",
11800
+ through_via: "rgb(236, 236, 236)",
11801
+ user_1: "rgb(194, 194, 194)",
11802
+ user_2: "rgb(89, 148, 220)",
11803
+ user_3: "rgb(180, 219, 210)",
11804
+ user_4: "rgb(216, 200, 82)",
11805
+ user_5: "rgb(194, 194, 194)",
11806
+ user_6: "rgb(89, 148, 220)",
11807
+ user_7: "rgb(180, 219, 210)",
11808
+ user_8: "rgb(216, 200, 82)",
11809
+ user_9: "rgb(232, 178, 167)",
11810
+ via_blind_buried: "rgb(187, 151, 38)",
11811
+ via_hole: "rgb(227, 183, 46)",
11812
+ via_micro: "rgb(0, 132, 132)",
11813
+ via_through: "rgb(236, 236, 236)",
11814
+ worksheet: "rgb(200, 114, 171)"
11815
+ },
11816
+ gerbview: {
11817
+ axes: "rgb(0, 0, 132)",
11818
+ background: "rgb(0, 0, 0)",
11819
+ dcodes: "rgb(255, 255, 255)",
11820
+ grid: "rgb(132, 132, 132)",
11821
+ layers: [
11822
+ "rgb(132, 0, 0)",
11823
+ "rgb(194, 194, 0)",
11824
+ "rgb(194, 0, 194)",
11825
+ "rgb(194, 0, 0)",
11826
+ "rgb(0, 132, 132)",
11827
+ "rgb(0, 132, 0)",
11828
+ "rgb(0, 0, 132)",
11829
+ "rgb(132, 132, 132)",
11830
+ "rgb(132, 0, 132)",
11831
+ "rgb(194, 194, 194)",
11832
+ "rgb(132, 0, 132)",
11833
+ "rgb(132, 0, 0)",
11834
+ "rgb(132, 132, 0)",
11835
+ "rgb(194, 194, 194)",
11836
+ "rgb(0, 0, 132)",
11837
+ "rgb(0, 132, 0)",
11838
+ "rgb(132, 0, 0)",
11839
+ "rgb(194, 194, 0)",
11840
+ "rgb(194, 0, 194)",
11841
+ "rgb(194, 0, 0)",
11842
+ "rgb(0, 132, 132)",
11843
+ "rgb(0, 132, 0)",
11844
+ "rgb(0, 0, 132)",
11845
+ "rgb(132, 132, 132)",
11846
+ "rgb(132, 0, 132)",
11847
+ "rgb(194, 194, 194)",
11848
+ "rgb(132, 0, 132)",
11849
+ "rgb(132, 0, 0)",
11850
+ "rgb(132, 132, 0)",
11851
+ "rgb(194, 194, 194)",
11852
+ "rgb(0, 0, 132)",
11853
+ "rgb(0, 132, 0)",
11854
+ "rgb(132, 0, 0)",
11855
+ "rgb(194, 194, 0)",
11856
+ "rgb(194, 0, 194)",
11857
+ "rgb(194, 0, 0)",
11858
+ "rgb(0, 132, 132)",
11859
+ "rgb(0, 132, 0)",
11860
+ "rgb(0, 0, 132)",
11861
+ "rgb(132, 132, 132)",
11862
+ "rgb(132, 0, 132)",
11863
+ "rgb(194, 194, 194)",
11864
+ "rgb(132, 0, 132)",
11865
+ "rgb(132, 0, 0)",
11866
+ "rgb(132, 132, 0)",
11867
+ "rgb(194, 194, 194)",
11868
+ "rgb(0, 0, 132)",
11869
+ "rgb(0, 132, 0)",
11870
+ "rgb(132, 0, 0)",
11871
+ "rgb(194, 194, 0)",
11872
+ "rgb(194, 0, 194)",
11873
+ "rgb(194, 0, 0)",
11874
+ "rgb(0, 132, 132)",
11875
+ "rgb(0, 132, 0)",
11876
+ "rgb(0, 0, 132)",
11877
+ "rgb(132, 132, 132)",
11878
+ "rgb(132, 0, 132)",
11879
+ "rgb(194, 194, 194)",
11880
+ "rgb(132, 0, 132)",
11881
+ "rgb(132, 0, 0)"
11882
+ ],
11883
+ negative_objects: "rgb(132, 132, 132)",
11884
+ worksheet: "rgb(0, 0, 132)"
11885
+ },
11886
+ palette: [
11887
+ "rgb(132, 0, 0)",
11888
+ "rgb(194, 194, 0)",
11889
+ "rgb(194, 0, 194)",
11890
+ "rgb(194, 0, 0)",
11891
+ "rgb(0, 132, 132)",
11892
+ "rgb(0, 132, 0)",
11893
+ "rgb(0, 0, 132)",
11894
+ "rgb(132, 132, 132)",
11895
+ "rgb(132, 0, 132)",
11896
+ "rgb(194, 194, 194)",
11897
+ "rgb(132, 0, 132)",
11898
+ "rgb(132, 0, 0)",
11899
+ "rgb(132, 132, 0)",
11900
+ "rgb(194, 194, 194)",
11901
+ "rgb(0, 0, 132)",
11902
+ "rgb(0, 132, 0)"
11903
+ ],
11904
+ schematic: {
11905
+ anchor: "rgb(0, 0, 255)",
11906
+ aux_items: "rgb(0, 0, 0)",
11907
+ background: "rgb(33, 33, 33)",
11908
+ brightened: "rgb(204, 204, 204)",
11909
+ bus: "rgb(0, 96, 192)",
11910
+ bus_junction: "rgb(0, 96, 192)",
11911
+ component_body: "rgb(44, 44, 44)",
11912
+ component_outline: "rgb(192, 0, 0)",
11913
+ cursor: "rgb(224, 224, 224)",
11914
+ erc_error: "rgba(192, 48, 48, 0.800)",
11915
+ erc_warning: "rgba(192, 140, 0, 0.800)",
11916
+ fields: "rgb(128, 0, 160)",
11917
+ grid: "rgb(60, 60, 60)",
11918
+ grid_axes: "rgb(60, 60, 60)",
11919
+ hidden: "rgb(194, 194, 194)",
11920
+ junction: "rgb(0, 160, 0)",
11921
+ label_global: "rgb(0, 160, 224)",
11922
+ label_hier: "rgb(160, 160, 0)",
11923
+ label_local: "rgb(192, 192, 192)",
11924
+ net_name: "rgb(224, 224, 224)",
11925
+ no_connect: "rgb(97, 43, 224)",
11926
+ note: "rgb(192, 192, 0)",
11927
+ override_item_colors: false,
11928
+ pin: "rgb(192, 0, 0)",
11929
+ pin_name: "rgb(192, 192, 192)",
11930
+ pin_number: "rgb(192, 0, 0)",
11931
+ reference: "rgb(192, 192, 192)",
11932
+ shadow: "rgba(102, 179, 255, 0.800)",
11933
+ sheet: "rgb(128, 0, 160)",
11934
+ sheet_background: "rgba(255, 255, 255, 0.000)",
11935
+ sheet_fields: "rgb(160, 160, 0)",
11936
+ sheet_filename: "rgb(160, 160, 0)",
11937
+ sheet_label: "rgb(160, 160, 0)",
11938
+ sheet_name: "rgb(0, 160, 204)",
11939
+ value: "rgb(192, 192, 192)",
11940
+ wire: "rgb(0, 160, 0)",
11941
+ worksheet: "rgb(192, 0, 0)"
11942
+ }
11943
+ };
11944
+ // src/lib/util/scale-only.ts
11945
+ var scaleOnly = function(mat) {
11946
+ var value = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
11947
+ if (Math.abs(mat.a) !== Math.abs(mat.d)) throw new Error("Cannot scale non-uniformly");
11948
+ return value * Math.abs(mat.a);
11949
+ };
11950
+ // src/lib/Drawer.ts
11951
+ var LAYER_NAME_TO_COLOR = _object_spread({
11952
+ // Standard colors, you shouldn't use these except for testing
11953
+ red: "red",
11954
+ black: "black",
11955
+ green: "green",
11956
+ board: "rgb(255, 255, 255)",
11957
+ other: "#eee",
11958
+ // TODO more builtin html colors
11959
+ // Common eagle names
11960
+ top: colors_default.board.copper.f,
11961
+ inner1: colors_default.board.copper.in1,
11962
+ inner2: colors_default.board.copper.in2,
11963
+ inner3: colors_default.board.copper.in3,
11964
+ inner4: colors_default.board.copper.in4,
11965
+ inner5: colors_default.board.copper.in5,
11966
+ inner6: colors_default.board.copper.in6,
11967
+ inner7: colors_default.board.copper.in7,
11968
+ inner8: colors_default.board.copper.in8,
11969
+ bottom: colors_default.board.copper.b,
11970
+ drill: colors_default.board.anchor,
11971
+ keepout: colors_default.board.background,
11972
+ tkeepout: colors_default.board.b_crtyd,
11973
+ tplace: colors_default.board.b_silks,
11974
+ top_silkscreen: colors_default.board.f_silks,
11975
+ bottom_silkscreen: colors_default.board.b_silks,
11976
+ top_fabrication: colors_default.board.f_fab,
11977
+ bottom_fabrication: colors_default.board.b_fab
11978
+ }, colors_default.board);
11979
+ var DEFAULT_DRAW_ORDER = [
11980
+ "top",
11981
+ "inner1",
11982
+ "inner2",
11983
+ "inner3",
11984
+ "inner4",
11985
+ "inner5",
11986
+ "inner6",
11987
+ "bottom"
11988
+ ];
11989
+ var Drawer = /*#__PURE__*/ function() {
11990
+ "use strict";
11991
+ function Drawer(canvasLayerMap) {
11992
+ _class_call_check(this, Drawer);
11993
+ this.foregroundLayer = "top";
11994
+ this.canvasLayerMap = canvasLayerMap;
11995
+ this.ctxLayerMap = Object.fromEntries(Object.entries(canvasLayerMap).map(function(param) {
11996
+ var _param = _sliced_to_array(param, 2), name = _param[0], canvas = _param[1];
11997
+ return [
11998
+ name,
11999
+ canvas.getContext("2d")
12000
+ ];
12001
+ }));
12002
+ this.transform = (0, import_transformation_matrix3.identity)();
12003
+ this.transform.d *= -1;
12004
+ this.transform = (0, import_transformation_matrix3.compose)(this.transform, (0, import_transformation_matrix3.translate)(0, -500));
12005
+ this.lastPoint = {
12006
+ x: 0,
12007
+ y: 0
12008
+ };
12009
+ this.equip({});
12010
+ }
12011
+ _create_class(Drawer, [
12012
+ {
12013
+ key: "clear",
12014
+ value: function clear() {
12015
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
12016
+ try {
12017
+ for(var _iterator = Object.values(this.ctxLayerMap)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
12018
+ var ctx = _step.value;
12019
+ ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
12020
+ }
12021
+ } catch (err) {
12022
+ _didIteratorError = true;
12023
+ _iteratorError = err;
12024
+ } finally{
12025
+ try {
12026
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
12027
+ _iterator.return();
12028
+ }
12029
+ } finally{
12030
+ if (_didIteratorError) {
12031
+ throw _iteratorError;
12032
+ }
12033
+ }
12034
+ }
12035
+ }
12036
+ },
12037
+ {
12038
+ key: "equip",
12039
+ value: function equip(aperture) {
12040
+ this.aperture = _object_spread({
12041
+ fontSize: 0,
12042
+ shape: "circle",
12043
+ mode: "add",
12044
+ size: 0,
12045
+ color: "red",
12046
+ layer: "top",
12047
+ opacity: this.foregroundLayer === aperture.color ? 1 : 0.5
12048
+ }, aperture);
12049
+ }
12050
+ },
12051
+ {
12052
+ key: "drawMeshPattern",
12053
+ value: function drawMeshPattern(x, y, width, height, spacing) {
12054
+ var angle = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : 45;
12055
+ var ctx = this.getLayerCtx();
12056
+ var _ref = _sliced_to_array((0, import_transformation_matrix3.applyToPoint)(this.transform, [
12057
+ x,
12058
+ y
12059
+ ]), 2), x1 = _ref[0], y1 = _ref[1];
12060
+ var _ref1 = _sliced_to_array((0, import_transformation_matrix3.applyToPoint)(this.transform, [
12061
+ x + width,
12062
+ y + height
12063
+ ]), 2), x2 = _ref1[0], y2 = _ref1[1];
12064
+ var spacing$ = scaleOnly(this.transform, spacing);
12065
+ ctx.lineWidth = 1;
12066
+ ctx.strokeStyle = this.aperture.color;
12067
+ var drawLines = function(angle2) {
12068
+ var sin = Math.sin(angle2);
12069
+ var cos = Math.cos(angle2);
12070
+ var diag = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
12071
+ for(var i = -diag; i <= diag; i += spacing$){
12072
+ ctx.beginPath();
12073
+ ctx.moveTo(x1 + i * cos - diag * sin, y1 + i * sin + diag * cos);
12074
+ ctx.lineTo(x1 + i * cos + diag * sin, y1 + i * sin - diag * cos);
12075
+ ctx.stroke();
12076
+ }
12077
+ };
12078
+ drawLines(angle * Math.PI / 180);
12079
+ drawLines((angle + 90) * Math.PI / 180);
12080
+ }
12081
+ },
12082
+ {
12083
+ key: "rect",
12084
+ value: function rect(x, y, w, h, mesh_fill) {
12085
+ var _ref = _sliced_to_array((0, import_transformation_matrix3.applyToPoint)(this.transform, [
12086
+ x - w / 2,
12087
+ y - h / 2
12088
+ ]), 2), x1$ = _ref[0], y1$ = _ref[1];
12089
+ var _ref1 = _sliced_to_array((0, import_transformation_matrix3.applyToPoint)(this.transform, [
12090
+ x + w / 2,
12091
+ y + h / 2
12092
+ ]), 2), x2$ = _ref1[0], y2$ = _ref1[1];
12093
+ this.applyAperture();
12094
+ var ctx = this.getLayerCtx();
12095
+ if (mesh_fill) {
12096
+ ctx.save();
12097
+ ctx.beginPath();
12098
+ ctx.rect(x1$, y1$, x2$ - x1$, y2$ - y1$);
12099
+ ctx.clip();
12100
+ this.drawMeshPattern(x - w / 2, y - h / 2, w, h, 0.15);
12101
+ ctx.restore();
12102
+ ctx.strokeRect(x1$, y1$, x2$ - x1$, y2$ - y1$);
12103
+ } else {
12104
+ ctx.fillRect(x1$, y1$, x2$ - x1$, y2$ - y1$);
12105
+ }
12106
+ }
12107
+ },
12108
+ {
12109
+ key: "circle",
12110
+ value: function circle(x, y, r, mesh_fill) {
12111
+ var r$ = scaleOnly(this.transform, r);
12112
+ var _ref = _sliced_to_array((0, import_transformation_matrix3.applyToPoint)(this.transform, [
12113
+ x,
12114
+ y
12115
+ ]), 2), x$ = _ref[0], y$ = _ref[1];
12116
+ this.applyAperture();
12117
+ var ctx = this.getLayerCtx();
12118
+ if (mesh_fill) {
12119
+ ctx.save();
12120
+ ctx.beginPath();
12121
+ ctx.arc(x$, y$, r$, 0, 2 * Math.PI);
12122
+ ctx.clip();
12123
+ this.drawMeshPattern(x - r, y - r, r * 2, r * 2, 0.15);
12124
+ ctx.restore();
12125
+ ctx.beginPath();
12126
+ ctx.arc(x$, y$, r$, 0, 2 * Math.PI);
12127
+ ctx.stroke();
12128
+ } else {
12129
+ ctx.beginPath();
12130
+ ctx.arc(x$, y$, r$, 0, 2 * Math.PI);
12131
+ ctx.fill();
12132
+ }
12133
+ }
12134
+ },
12135
+ {
12136
+ key: "oval",
12137
+ value: function oval(x, y, rx, ry) {
12138
+ var rx$ = scaleOnly(this.transform, rx);
12139
+ var ry$ = scaleOnly(this.transform, ry);
12140
+ var _ref = _sliced_to_array((0, import_transformation_matrix3.applyToPoint)(this.transform, [
12141
+ x,
12142
+ y
12143
+ ]), 2), x$ = _ref[0], y$ = _ref[1];
12144
+ this.applyAperture();
12145
+ var ctx = this.getLayerCtx();
12146
+ ctx.beginPath();
12147
+ ctx.ellipse(x$, y$, rx$, ry$, 0, 0, 2 * Math.PI);
12148
+ ctx.fill();
12149
+ ctx.closePath();
12150
+ }
12151
+ },
12152
+ {
12153
+ key: "pill",
12154
+ value: function pill(x, y, w, h) {
12155
+ var _ref = _sliced_to_array((0, import_transformation_matrix3.applyToPoint)(this.transform, [
12156
+ x - w / 2,
12157
+ y + h / 2
12158
+ ]), 2), x$ = _ref[0], y$ = _ref[1];
12159
+ var width$ = scaleOnly(this.transform, w);
12160
+ var height$ = scaleOnly(this.transform, h);
12161
+ var radius = Math.min(width$, height$) / 2;
12162
+ this.applyAperture();
12163
+ var ctx = this.getLayerCtx();
12164
+ ctx.beginPath();
12165
+ ctx.arc(x$ + radius, y$ + radius, radius, Math.PI, Math.PI * 1.5);
12166
+ ctx.arc(x$ + width$ - radius, y$ + radius, radius, Math.PI * 1.5, 0);
12167
+ ctx.arc(x$ + width$ - radius, y$ + height$ - radius, radius, 0, Math.PI * 0.5);
12168
+ ctx.arc(x$ + radius, y$ + height$ - radius, radius, Math.PI * 0.5, Math.PI);
12169
+ ctx.fill();
12170
+ ctx.closePath();
12171
+ }
12172
+ },
12173
+ {
12174
+ key: "polygon",
12175
+ value: function polygon(points) {
12176
+ var _this = this;
12177
+ if (points.length < 3) {
12178
+ console.warn("Polygon must have at least 3 points");
12179
+ return;
12180
+ }
12181
+ this.applyAperture();
12182
+ var ctx = this.getLayerCtx();
12183
+ var transformedPoints = points.map(function(point2) {
12184
+ return (0, import_transformation_matrix3.applyToPoint)(_this.transform, [
12185
+ point2.x,
12186
+ point2.y
12187
+ ]);
12188
+ });
12189
+ ctx.beginPath();
12190
+ ctx.moveTo(transformedPoints[0][0], transformedPoints[0][1]);
12191
+ for(var i = 1; i < transformedPoints.length; i++){
12192
+ ctx.lineTo(transformedPoints[i][0], transformedPoints[i][1]);
12193
+ }
12194
+ ctx.closePath();
12195
+ ctx.fill();
12196
+ var lineWidth = scaleOnly(this.transform, this.aperture.size);
12197
+ ctx.lineWidth = lineWidth;
12198
+ ctx.stroke();
12199
+ }
12200
+ },
12201
+ {
12202
+ /* NOTE: This is not gerber compatible */ key: "debugText",
12203
+ value: function debugText(text, x, y) {
12204
+ var _ref = _sliced_to_array((0, import_transformation_matrix3.applyToPoint)(this.transform, [
12205
+ x,
12206
+ y
12207
+ ]), 2), x$ = _ref[0], y$ = _ref[1];
12208
+ this.applyAperture();
12209
+ var ctx = this.getLayerCtx();
12210
+ ctx.font = "10px sans-serif";
12211
+ ctx.fillText(text, x$, y$);
12212
+ }
12213
+ },
12214
+ {
12215
+ key: "getLayerCtx",
12216
+ value: function getLayerCtx() {
12217
+ var ctx = this.ctxLayerMap[this.aperture.layer];
12218
+ if (!ctx) {
12219
+ throw new Error('No context for layer "'.concat(this.aperture.layer, '"'));
12220
+ }
12221
+ return ctx;
12222
+ }
12223
+ },
12224
+ {
12225
+ /**
12226
+ * Iterate over each canvas and set the z index based on the layer order, but
12227
+ * always render the foreground layer on top.
12228
+ *
12229
+ * Also: Set the opacity of every non-foreground layer to 0.5
12230
+ */ key: "orderAndFadeLayers",
12231
+ value: function orderAndFadeLayers() {
12232
+ var _this = this, canvasLayerMap = _this.canvasLayerMap, foregroundLayer = _this.foregroundLayer;
12233
+ var opaqueLayers = /* @__PURE__ */ new Set([
12234
+ foregroundLayer,
12235
+ "drill",
12236
+ "other",
12237
+ "board"
12238
+ ]);
12239
+ var order = [
12240
+ "drill",
12241
+ "board",
12242
+ foregroundLayer
12243
+ ].concat(_to_consumable_array(DEFAULT_DRAW_ORDER.filter(function(l) {
12244
+ return l !== foregroundLayer;
12245
+ })));
12246
+ order.forEach(function(layer, i) {
12247
+ var canvas = canvasLayerMap[layer];
12248
+ if (!canvas) return;
12249
+ canvas.style.zIndex = "".concat(100 - i);
12250
+ canvas.style.opacity = opaqueLayers.has(layer) ? "1" : "0.5";
12251
+ });
12252
+ }
12253
+ },
12254
+ {
12255
+ key: "applyAperture",
12256
+ value: function applyAperture() {
12257
+ var _this = this, transform = _this.transform, aperture = _this.aperture;
12258
+ var size2 = aperture.size, mode = aperture.mode, color2 = aperture.color, fontSize = aperture.fontSize, layer = aperture.layer;
12259
+ if (!(layer in this.ctxLayerMap)) this.aperture.layer = "other";
12260
+ var ctx = this.getLayerCtx();
12261
+ if (!ctx) {
12262
+ throw new Error('No context for layer "'.concat(this.foregroundLayer, '"'));
12263
+ }
12264
+ if (!color2) color2 = "undefined";
12265
+ ctx.lineWidth = scaleOnly(transform, size2);
12266
+ ctx.lineCap = "round";
12267
+ if (mode === "add") {
12268
+ 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;
12269
+ if (colorString === null) {
12270
+ console.warn('Color mapping for "'.concat(color2, '" not found'));
12271
+ colorString = "white";
12272
+ }
12273
+ ctx.fillStyle = colorString;
12274
+ ctx.strokeStyle = colorString;
12275
+ } else {
12276
+ ctx.globalCompositeOperation = "destination-out";
12277
+ ctx.fillStyle = "rgba(0,0,0,1)";
12278
+ ctx.strokeStyle = "rgba(0,0,0,1)";
12279
+ }
12280
+ ctx.font = "".concat(scaleOnly((0, import_transformation_matrix3.inverse)(transform), fontSize), "px sans-serif");
12281
+ }
12282
+ },
12283
+ {
12284
+ key: "moveTo",
12285
+ value: function moveTo(x, y) {
12286
+ this.lastPoint = {
12287
+ x: x,
12288
+ y: y
12289
+ };
12290
+ }
12291
+ },
12292
+ {
12293
+ key: "lineTo",
12294
+ value: function lineTo(x, y) {
12295
+ var _ref = _sliced_to_array((0, import_transformation_matrix3.applyToPoint)(this.transform, [
12296
+ x,
12297
+ y
12298
+ ]), 2), x$ = _ref[0], y$ = _ref[1];
12299
+ var _this_aperture = this.aperture, size2 = _this_aperture.size, shape = _this_aperture.shape, mode = _this_aperture.mode;
12300
+ var size$ = scaleOnly(this.transform, size2);
12301
+ var lastPoint = this.lastPoint;
12302
+ var lastPoint$ = (0, import_transformation_matrix3.applyToPoint)(this.transform, lastPoint);
12303
+ this.applyAperture();
12304
+ var ctx = this.getLayerCtx();
12305
+ if (shape === "square") ctx.fillRect(lastPoint$.x - size$ / 2, lastPoint$.y - size$ / 2, size$, size$);
12306
+ ctx.beginPath();
12307
+ ctx.moveTo(lastPoint$.x, lastPoint$.y);
12308
+ ctx.lineTo(x$, y$);
12309
+ ctx.stroke();
12310
+ ctx.closePath();
12311
+ if (shape === "square") ctx.fillRect(x$ - size$ / 2, y$ - size$ / 2, size$, size$);
12312
+ this.lastPoint = {
12313
+ x: x,
12314
+ y: y
12315
+ };
12316
+ }
12317
+ }
12318
+ ]);
12319
+ return Drawer;
12320
+ }();
12321
+ // src/assets/alphabet.ts
12322
+ var svgAlphabet = {
12323
+ "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",
12324
+ "1": "M 0.198 0.272 L 0.537 0 L 0.54 1",
12325
+ "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",
12326
+ "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",
12327
+ "4": "M0.7328897338403042 0L0 0.6684672518568535L1 0.6684672518568535M0.7243346007604563 0.4530722484807562L0.7243346007604563 1",
12328
+ "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",
12329
+ "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",
12330
+ "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",
12331
+ "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",
12332
+ "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",
12333
+ A: "M0 1L0.4808333333333333 0L1 1M0.24250000000000002 0.6099439775910365L0.7341666666666666 0.6099439775910365",
12334
+ 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",
12335
+ 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",
12336
+ 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",
12337
+ E: "M0 0L0 1M0 0L1 0M0 0.5L0.7 0.5M0 1L1 1",
12338
+ F: "M0 0L0 1M0.011363636363636364 0.006802721088435374L1 0.006802721088435374M0.011363636363636364 0.4965986394557823L0.8409090909090909 0.4965986394557823",
12339
+ 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",
12340
+ H: "M0 0L0 1M0 0.4788732394366197L0.989010989010989 0.4788732394366197M1 0L1 1",
12341
+ I: "M0.5 0L0.5 1",
12342
+ 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",
12343
+ K: "M0 0L0 1M0.8787878787878788 0.06666666666666667L0 0.6148148148148148M0.3333333333333333 0.45925925925925926L1 0.9777777777777777",
12344
+ L: "M0 0L0 1L1 1",
12345
+ M: "M0 1L0 0L0.5 0.6512L1 0L1 1",
12346
+ N: "M0 1L0 0L1 1L0.9803729146221786 0",
12347
+ 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",
12348
+ 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",
12349
+ 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",
12350
+ 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",
12351
+ 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",
12352
+ T: "M0 0L1 0M0.5148514851485149 0L0.5148514851485149 1",
12353
+ 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",
12354
+ V: "M0 0L0.5348837209302325 1L1 0",
12355
+ W: "M0 0L0.23300090661831369 0.9873417721518988L0.49954669084315495 0.30081906180193585L0.7851314596554849 1L1 0.0215934475055845",
12356
+ X: "M0 0L0.9893617021276596 1M1 0L0.010638297872340425 1",
12357
+ Y: "M0 0L0.4860515021459227 0.44712562100780695M1 0.0014194464158977947L0.48927038626609437 0.44996451383960256L0.5075107296137339 1",
12358
+ Z: "M0 0L1 0L0 1L1 1",
12359
+ ".": "M 0.49 1 L 0.41 1",
12360
+ "*": "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",
12361
+ "(": "M0.75 0L0.25 0.5L0.25 0.5L0.75 1",
12362
+ ")": "M0.25 0L0.75 0.5L0.75 0.5L0.25 1",
12363
+ "-": "M0 0.5L1 0.5",
12364
+ "+": "M 0 0.5 L 1 0.5 M 0.5 0.125 L 0.5 0.875",
12365
+ "=": "M0 0.25L1 0.25M0 0.75L1 0.75",
12366
+ _: "M0 1 L1 1",
12367
+ "[": "M0.75 0L0.25 0L0.25 1L0.75 1",
12368
+ "]": "M0.25 0L0.75 0L0.75 1L0.25 1",
12369
+ "<": "M0.75 0L0.25 0.5L0.25 0.5L0.75 1",
12370
+ ">": "M0.25 0L0.75 0.5L0.75 0.5L0.25 1",
12371
+ "'": "M 0.5 0 L 0.5 0.5",
12372
+ '"': "M 0.25 0 L 0.25 0.5 M 0.75 0 L 0.75 0.5"
12373
+ };
12374
+ var lineAlphabet = {};
12375
+ for(var letter in svgAlphabet)_loop(letter);
12376
+ // src/lib/convert-text-to-lines.ts
12377
+ var LETTER_HEIGHT_TO_WIDTH_RATIO = 0.6;
12378
+ var LETTER_HEIGHT_TO_SPACE_RATIO = 0.2;
12379
+ var getTextWidth = function(text) {
12380
+ return text.text.length * text.size * LETTER_HEIGHT_TO_WIDTH_RATIO + (text.text.length - 1) * text.size * LETTER_HEIGHT_TO_SPACE_RATIO;
12381
+ };
12382
+ var convertTextToLines = function(text) {
12383
+ var strokeWidth = text.size / 8;
12384
+ var letterWidth = text.size * LETTER_HEIGHT_TO_WIDTH_RATIO;
12385
+ var letterSpace = text.size * LETTER_HEIGHT_TO_SPACE_RATIO;
12386
+ var lines = [];
12387
+ for(var letterIndex = 0; letterIndex < text.text.length; letterIndex++){
12388
+ var letter = text.text[letterIndex];
12389
+ var letterLines = lineAlphabet[letter.toUpperCase()];
12390
+ if (!letterLines) continue;
12391
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
12392
+ try {
12393
+ for(var _iterator = letterLines[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
12394
+ var _step_value = _step.value, x1 = _step_value.x1, y1 = _step_value.y1, x2 = _step_value.x2, y2 = _step_value.y2;
12395
+ lines.push({
12396
+ pcb_drawing_type: "line",
12397
+ x1: text.x + (letterWidth + letterSpace) * letterIndex + letterWidth * x1,
12398
+ y1: text.y + text.size * y1,
12399
+ x2: text.x + (letterWidth + letterSpace) * letterIndex + letterWidth * x2,
12400
+ y2: text.y + text.size * y2,
12401
+ width: strokeWidth,
12402
+ layer: text.layer,
12403
+ unit: text.unit
12404
+ });
12405
+ }
12406
+ } catch (err) {
12407
+ _didIteratorError = true;
12408
+ _iteratorError = err;
12409
+ } finally{
12410
+ try {
12411
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
12412
+ _iterator.return();
12413
+ }
12414
+ } finally{
12415
+ if (_didIteratorError) {
12416
+ throw _iteratorError;
12417
+ }
12418
+ }
12419
+ }
12420
+ }
12421
+ return lines;
12422
+ };
12423
+ // src/lib/draw-primitives.ts
12424
+ var import_color = __toESM(require("color"));
12425
+ function getColor(primitive) {
12426
+ if (primitive.is_mouse_over || primitive.is_in_highlighted_net) {
12427
+ return (0, import_color.default)(LAYER_NAME_TO_COLOR[primitive.layer]).lighten(0.5).rgb().toString();
12428
+ }
12429
+ return LAYER_NAME_TO_COLOR[primitive.layer];
12430
+ }
12431
+ var drawLine = function(drawer, line) {
12432
+ drawer.equip({
12433
+ size: line.zoomIndependent ? line.width / drawer.transform.a : line.width,
12434
+ shape: line.squareCap ? "square" : "circle",
12435
+ color: getColor(line),
12436
+ layer: line.layer
12437
+ });
12438
+ drawer.moveTo(line.x1, line.y1);
12439
+ drawer.lineTo(line.x2, line.y2);
12440
+ };
12441
+ var drawText = function(drawer, text) {
12442
+ drawer.equip({
12443
+ fontSize: text.size,
12444
+ color: text.layer
12445
+ });
12446
+ var alignOffset = {
11292
12447
  x: 0,
11293
12448
  y: 0
11294
- }),
11295
- anchor_alignment: z.enum([
11296
- "center",
11297
- "top_left",
11298
- "top_right",
11299
- "bottom_left",
11300
- "bottom_right"
11301
- ]).default("center"),
11302
- color: z.string().optional()
11303
- }).describe("Defines a fabrication note in text on the PCB, useful for leaving notes for assemblers or fabricators");
11304
- expectTypesMatch(true);
11305
- var pcb_fabrication_note_path = z.object({
11306
- type: z.literal("pcb_fabrication_note_path"),
11307
- pcb_fabrication_note_path_id: getZodPrefixedIdWithDefault("pcb_fabrication_note_path"),
11308
- pcb_component_id: z.string(),
11309
- layer: layer_ref,
11310
- route: z.array(point),
11311
- stroke_width: length,
11312
- color: z.string().optional()
11313
- }).describe("Defines a fabrication path on the PCB for fabricators or assemblers");
11314
- expectTypesMatch(true);
11315
- var pcb_keepout = z.object({
11316
- type: z.literal("pcb_keepout"),
11317
- shape: z.literal("rect"),
11318
- center: point,
11319
- width: distance,
11320
- height: distance,
11321
- pcb_keepout_id: z.string(),
11322
- layers: z.array(z.string()),
11323
- // Specify layers where the keepout applies
11324
- description: z.string().optional()
11325
- }).or(z.object({
11326
- type: z.literal("pcb_keepout"),
11327
- shape: z.literal("circle"),
11328
- center: point,
11329
- radius: distance,
11330
- pcb_keepout_id: z.string(),
11331
- layers: z.array(z.string()),
11332
- // Specify layers where the keepout applies
11333
- description: z.string().optional()
11334
- }));
11335
- var cad_component = z.object({
11336
- type: z.literal("cad_component"),
11337
- cad_component_id: z.string(),
11338
- pcb_component_id: z.string(),
11339
- source_component_id: z.string(),
11340
- position: point3,
11341
- rotation: point3.optional(),
11342
- size: point3.optional(),
11343
- layer: layer_ref.optional(),
11344
- // These are all ways to generate/load the 3d model
11345
- footprinter_string: z.string().optional(),
11346
- model_obj_url: z.string().optional(),
11347
- model_stl_url: z.string().optional(),
11348
- model_3mf_url: z.string().optional(),
11349
- model_jscad: z.any().optional()
11350
- }).describe("Defines a component on the PCB");
11351
- var any_circuit_element = z.union([
11352
- source_trace,
11353
- source_port,
11354
- any_source_component,
11355
- source_led,
11356
- source_net,
11357
- source_group,
11358
- source_simple_bug,
11359
- source_simple_chip,
11360
- source_simple_capacitor,
11361
- source_simple_diode,
11362
- source_simple_resistor,
11363
- source_simple_power_source,
11364
- pcb_component,
11365
- pcb_hole,
11366
- pcb_plated_hole,
11367
- pcb_keepout,
11368
- pcb_port,
11369
- pcb_text,
11370
- pcb_trace,
11371
- pcb_via,
11372
- pcb_smtpad,
11373
- pcb_board,
11374
- pcb_trace_hint,
11375
- pcb_silkscreen_line,
11376
- pcb_silkscreen_path,
11377
- pcb_silkscreen_text,
11378
- pcb_silkscreen_rect,
11379
- pcb_silkscreen_circle,
11380
- pcb_silkscreen_oval,
11381
- pcb_trace_error,
11382
- pcb_placement_error,
11383
- pcb_port_not_matched_error,
11384
- pcb_fabrication_note_path,
11385
- pcb_fabrication_note_text,
11386
- schematic_box,
11387
- schematic_text,
11388
- schematic_line,
11389
- schematic_component,
11390
- schematic_port,
11391
- schematic_trace,
11392
- schematic_path,
11393
- schematic_error,
11394
- schematic_net_label,
11395
- cad_component
11396
- ]);
11397
- var any_soup_element = any_circuit_element;
12449
+ };
12450
+ var textWidth = getTextWidth(text);
12451
+ var textHeight = text.size;
12452
+ if (text.align === "top_left") {
12453
+ alignOffset.y = -textHeight;
12454
+ } else if (text.align === "bottom_right") {
12455
+ alignOffset.x = -textWidth;
12456
+ } else if (text.align === "top_right") {
12457
+ alignOffset.x = -textWidth;
12458
+ alignOffset.y = -textHeight;
12459
+ } else if (text.align === "center") {
12460
+ alignOffset.x = -textWidth / 2;
12461
+ alignOffset.y = -textHeight / 2;
12462
+ }
12463
+ var _text_x;
12464
+ (_text_x = text.x) !== null && _text_x !== void 0 ? _text_x : text.x = 0;
12465
+ var _text_y;
12466
+ (_text_y = text.y) !== null && _text_y !== void 0 ? _text_y : text.y = 0;
12467
+ var text_lines = convertTextToLines(_object_spread_props(_object_spread({}, text), {
12468
+ x: text.x + alignOffset.x,
12469
+ y: text.y + alignOffset.y
12470
+ }));
12471
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
12472
+ try {
12473
+ for(var _iterator = text_lines[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
12474
+ var line = _step.value;
12475
+ drawLine(drawer, line);
12476
+ }
12477
+ } catch (err) {
12478
+ _didIteratorError = true;
12479
+ _iteratorError = err;
12480
+ } finally{
12481
+ try {
12482
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
12483
+ _iterator.return();
12484
+ }
12485
+ } finally{
12486
+ if (_didIteratorError) {
12487
+ throw _iteratorError;
12488
+ }
12489
+ }
12490
+ }
12491
+ };
12492
+ var drawRect = function(drawer, rect) {
12493
+ drawer.equip({
12494
+ color: getColor(rect),
12495
+ layer: rect.layer
12496
+ });
12497
+ drawer.rect(rect.x, rect.y, rect.w, rect.h, rect.mesh_fill);
12498
+ };
12499
+ var drawCircle = function(drawer, circle) {
12500
+ drawer.equip({
12501
+ color: getColor(circle),
12502
+ layer: circle.layer
12503
+ });
12504
+ drawer.circle(circle.x, circle.y, circle.r, circle.mesh_fill);
12505
+ };
12506
+ var drawOval = function(drawer, oval) {
12507
+ drawer.equip({
12508
+ color: getColor(oval),
12509
+ layer: oval.layer
12510
+ });
12511
+ drawer.oval(oval.x, oval.y, oval.rX, oval.rY);
12512
+ };
12513
+ var drawPill = function(drawer, pill) {
12514
+ drawer.equip({
12515
+ color: getColor(pill),
12516
+ layer: pill.layer
12517
+ });
12518
+ drawer.pill(pill.x, pill.y, pill.w, pill.h);
12519
+ };
12520
+ var drawPolygon = function(drawer, polygon) {
12521
+ drawer.equip({
12522
+ color: getColor(polygon),
12523
+ layer: polygon.layer
12524
+ });
12525
+ drawer.polygon(polygon.points);
12526
+ };
12527
+ var drawPrimitive = function(drawer, primitive) {
12528
+ switch(primitive.pcb_drawing_type){
12529
+ case "line":
12530
+ return drawLine(drawer, primitive);
12531
+ case "text":
12532
+ return drawText(drawer, primitive);
12533
+ case "rect":
12534
+ return drawRect(drawer, primitive);
12535
+ case "circle":
12536
+ return drawCircle(drawer, primitive);
12537
+ case "oval":
12538
+ return drawOval(drawer, primitive);
12539
+ case "pill":
12540
+ return drawPill(drawer, primitive);
12541
+ case "polygon":
12542
+ return drawPolygon(drawer, primitive);
12543
+ }
12544
+ };
12545
+ var drawPrimitives = function(drawer, primitives) {
12546
+ primitives.sort(function(a, b) {
12547
+ var layerOrder = [
12548
+ "bottom",
12549
+ "top",
12550
+ "drill"
12551
+ ];
12552
+ return layerOrder.indexOf(a.layer) - layerOrder.indexOf(b.layer);
12553
+ });
12554
+ primitives.forEach(function(primitive) {
12555
+ return drawPrimitive(drawer, primitive);
12556
+ });
12557
+ };
11398
12558
  // src/components/CanvasPrimitiveRenderer.tsx
11399
- var import_jsx_runtime2 = require("react/jsx-runtime");
12559
+ var import_jsx_runtime3 = require("react/jsx-runtime");
11400
12560
  var CanvasPrimitiveRenderer = function(param) {
11401
12561
  var primitives = param.primitives, transform = param.transform, grid = param.grid, _param_width = param.width, width = _param_width === void 0 ? 500 : _param_width, _param_height = param.height, height = _param_height === void 0 ? 500 : _param_height;
11402
- var canvasRefs = (0, import_react4.useRef)();
12562
+ var canvasRefs = (0, import_react7.useRef)();
11403
12563
  var selectedLayer = useGlobalStore(function(s) {
11404
12564
  return s.selected_layer;
11405
12565
  });
11406
- (0, import_react4.useEffect)(function() {
12566
+ (0, import_react7.useEffect)(function() {
11407
12567
  if (!canvasRefs.current) return;
11408
12568
  if (Object.keys(canvasRefs.current).length === 0) return;
11409
12569
  var drawer = new Drawer(canvasRefs.current);
@@ -11417,7 +12577,7 @@ var CanvasPrimitiveRenderer = function(param) {
11417
12577
  transform,
11418
12578
  selectedLayer
11419
12579
  ]);
11420
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", {
12580
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", {
11421
12581
  style: {
11422
12582
  backgroundColor: "black",
11423
12583
  width: width,
@@ -11425,7 +12585,7 @@ var CanvasPrimitiveRenderer = function(param) {
11425
12585
  position: "relative"
11426
12586
  },
11427
12587
  children: [
11428
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_supergrid.SuperGrid, {
12588
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_supergrid.SuperGrid, {
11429
12589
  textColor: "rgba(0,255,0,0.8)",
11430
12590
  majorColor: "rgba(0,255,0,0.4)",
11431
12591
  minorColor: "rgba(0,255,0,0.2)",
@@ -11443,296 +12603,27 @@ var CanvasPrimitiveRenderer = function(param) {
11443
12603
  "drill",
11444
12604
  "other"
11445
12605
  ]).map(function(layer, i) {
11446
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("canvas", {
12606
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("canvas", {
11447
12607
  ref: function(el) {
11448
12608
  var _canvasRefs_current;
11449
12609
  (_canvasRefs_current = canvasRefs.current) !== null && _canvasRefs_current !== void 0 ? _canvasRefs_current : canvasRefs.current = {};
11450
- canvasRefs.current[layer] = el;
11451
- },
11452
- style: {
11453
- position: "absolute",
11454
- left: 0,
11455
- top: 0,
11456
- pointerEvents: "none"
11457
- },
11458
- width: width,
11459
- height: height
11460
- }, layer);
11461
- })
11462
- ]
11463
- });
11464
- };
11465
- // src/components/CanvasElementsRenderer.tsx
11466
- var import_react17 = require("react");
11467
- // node_modules/@tscircuit/soup-util/dist/index.js
11468
- var import_transformation_matrix2 = require("transformation-matrix");
11469
- var su = function(soup) {
11470
- var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
11471
- var internalStore = soup._internal_store;
11472
- if (!internalStore) {
11473
- internalStore = {
11474
- counts: {}
11475
- };
11476
- soup._internal_store = internalStore;
11477
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
11478
- try {
11479
- for(var _iterator = soup[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
11480
- var elm = _step.value;
11481
- var type = elm.type;
11482
- var idVal = elm["".concat(type, "_id")];
11483
- if (!idVal) continue;
11484
- var idNum = Number.parseInt(idVal.split("_").pop());
11485
- if (!Number.isNaN(idNum)) {
11486
- var _internalStore_counts_type;
11487
- internalStore.counts[type] = Math.max((_internalStore_counts_type = internalStore.counts[type]) !== null && _internalStore_counts_type !== void 0 ? _internalStore_counts_type : 0, idNum);
11488
- }
11489
- }
11490
- } catch (err) {
11491
- _didIteratorError = true;
11492
- _iteratorError = err;
11493
- } finally{
11494
- try {
11495
- if (!_iteratorNormalCompletion && _iterator.return != null) {
11496
- _iterator.return();
11497
- }
11498
- } finally{
11499
- if (_didIteratorError) {
11500
- throw _iteratorError;
11501
- }
11502
- }
11503
- }
11504
- }
11505
- var su2 = new Proxy({}, {
11506
- get: function(proxy_target, component_type) {
11507
- if (component_type === "toArray") {
11508
- return function() {
11509
- return soup;
11510
- };
11511
- }
11512
- return {
11513
- get: function(id) {
11514
- return soup.find(function(e) {
11515
- return e.type === component_type && e["".concat(component_type, "_id")] === id;
11516
- });
11517
- },
11518
- getUsing: function(using) {
11519
- var keys = Object.keys(using);
11520
- if (keys.length !== 1) {
11521
- throw new Error("getUsing requires exactly one key, e.g. { pcb_component_id }");
11522
- }
11523
- var join_key = keys[0];
11524
- var join_type = join_key.replace("_id", "");
11525
- var joiner = soup.find(function(e) {
11526
- return e.type === join_type && e[join_key] === using[join_key];
11527
- });
11528
- if (!joiner) return null;
11529
- return soup.find(function(e) {
11530
- return e.type === component_type && e["".concat(component_type, "_id")] === joiner["".concat(component_type, "_id")];
11531
- });
11532
- },
11533
- getWhere: function(where) {
11534
- var keys = Object.keys(where);
11535
- return soup.find(function(e) {
11536
- return e.type === component_type && keys.every(function(key) {
11537
- return e[key] === where[key];
11538
- });
11539
- });
11540
- },
11541
- list: function(where) {
11542
- var keys = !where ? [] : Object.keys(where);
11543
- return soup.filter(function(e) {
11544
- return e.type === component_type && keys.every(function(key) {
11545
- return e[key] === where[key];
11546
- });
11547
- });
11548
- },
11549
- insert: function(elm) {
11550
- var _a;
11551
- var _component_type;
11552
- (_component_type = (_a = internalStore.counts)[component_type]) !== null && _component_type !== void 0 ? _component_type : _a[component_type] = -1;
11553
- internalStore.counts[component_type]++;
11554
- var index = internalStore.counts[component_type];
11555
- var newElm = _object_spread(_define_property({
11556
- type: component_type
11557
- }, "".concat(component_type, "_id"), "".concat(component_type, "_").concat(index)), elm);
11558
- if (options.validateInserts) {
11559
- var _dist_exports_component_type;
11560
- var parser = (_dist_exports_component_type = dist_exports[component_type]) !== null && _dist_exports_component_type !== void 0 ? _dist_exports_component_type : any_soup_element;
11561
- parser.parse(newElm);
11562
- }
11563
- soup.push(newElm);
11564
- return newElm;
11565
- },
11566
- delete: function(id) {
11567
- var elm = soup.find(function(e) {
11568
- return e["".concat(component_type, "_id")] === id;
11569
- });
11570
- if (!elm) return;
11571
- soup.splice(soup.indexOf(elm), 1);
11572
- },
11573
- update: function(id, newProps) {
11574
- var elm = soup.find(function(e) {
11575
- return e["".concat(component_type, "_id")] === id;
11576
- });
11577
- if (!elm) return;
11578
- Object.assign(elm, newProps);
11579
- return elm;
11580
- },
11581
- select: function(selector) {
11582
- if (component_type === "source_component") {
11583
- return soup.find(function(e) {
11584
- return e.type === "source_component" && e.name === selector.replace(/\./g, "");
11585
- });
11586
- } else if (component_type === "pcb_port" || component_type === "source_port" || component_type === "schematic_port") {
11587
- var _selector_replace_split = _sliced_to_array(selector.replace(/\./g, "").split(/[\s\>]+/), 2), component_name = _selector_replace_split[0], port_selector = _selector_replace_split[1];
11588
- var source_component = soup.find(function(e) {
11589
- return e.type === "source_component" && e.name === component_name;
11590
- });
11591
- if (!source_component) return null;
11592
- var source_port2 = soup.find(function(e) {
11593
- var _e_port_hints;
11594
- return e.type === "source_port" && e.source_component_id === source_component.source_component_id && (e.name === port_selector || ((_e_port_hints = e.port_hints) !== null && _e_port_hints !== void 0 ? _e_port_hints : []).includes(port_selector));
11595
- });
11596
- if (!source_port2) return null;
11597
- if (component_type === "source_port") return source_port2;
11598
- if (component_type === "pcb_port") {
11599
- return soup.find(function(e) {
11600
- return e.type === "pcb_port" && e.source_port_id === source_port2.source_port_id;
11601
- });
11602
- } else if (component_type === "schematic_port") {
11603
- return soup.find(function(e) {
11604
- return e.type === "schematic_port" && e.source_port_id === source_port2.source_port_id;
11605
- });
11606
- }
11607
- }
11608
- }
11609
- };
11610
- }
11611
- });
11612
- return su2;
11613
- };
11614
- su.unparsed = su;
11615
- var su_default = su;
11616
- var transformPCBElement = function(elm, matrix) {
11617
- if (elm.type === "pcb_plated_hole" || elm.type === "pcb_hole" || elm.type === "pcb_via" || elm.type === "pcb_smtpad" || elm.type === "pcb_port") {
11618
- var _ref = (0, import_transformation_matrix2.applyToPoint)(matrix, {
11619
- x: elm.x,
11620
- y: elm.y
11621
- }), x = _ref.x, y = _ref.y;
11622
- elm.x = x;
11623
- elm.y = y;
11624
- } else if (elm.type === "pcb_keepout" || elm.type === "pcb_board") {
11625
- elm.center = (0, import_transformation_matrix2.applyToPoint)(matrix, elm.center);
11626
- } else if (elm.type === "pcb_silkscreen_text" || elm.type === "pcb_fabrication_note_text") {
11627
- elm.anchor_position = (0, import_transformation_matrix2.applyToPoint)(matrix, elm.anchor_position);
11628
- } else if (elm.type === "pcb_silkscreen_circle" || elm.type === "pcb_silkscreen_rect" || elm.type === "pcb_component") {
11629
- elm.center = (0, import_transformation_matrix2.applyToPoint)(matrix, elm.center);
11630
- } else if (elm.type === "pcb_silkscreen_path" || elm.type === "pcb_trace" || elm.type === "pcb_fabrication_note_path") {
11631
- elm.route = elm.route.map(function(rp) {
11632
- var tp = (0, import_transformation_matrix2.applyToPoint)(matrix, rp);
11633
- rp.x = tp.x;
11634
- rp.y = tp.y;
11635
- return rp;
11636
- });
11637
- } else if (elm.type === "pcb_silkscreen_line") {
11638
- var p1 = {
11639
- x: elm.x1,
11640
- y: elm.y1
11641
- };
11642
- var p2 = {
11643
- x: elm.x2,
11644
- y: elm.y2
11645
- };
11646
- var p1t = (0, import_transformation_matrix2.applyToPoint)(matrix, p1);
11647
- var p2t = (0, import_transformation_matrix2.applyToPoint)(matrix, p2);
11648
- elm.x1 = p1t.x;
11649
- elm.y1 = p1t.y;
11650
- elm.x2 = p2t.x;
11651
- elm.y2 = p2t.y;
11652
- } else if (elm.type === "cad_component") {
11653
- var newPos = (0, import_transformation_matrix2.applyToPoint)(matrix, {
11654
- x: elm.position.x,
11655
- y: elm.position.y
11656
- });
11657
- elm.position.x = newPos.x;
11658
- elm.position.y = newPos.y;
11659
- }
11660
- return elm;
11661
- };
11662
- var getBoundsOfPcbElements = function(elements) {
11663
- var minX = Number.POSITIVE_INFINITY;
11664
- var minY = Number.POSITIVE_INFINITY;
11665
- var maxX = Number.NEGATIVE_INFINITY;
11666
- var maxY = Number.NEGATIVE_INFINITY;
11667
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
11668
- try {
11669
- for(var _iterator = elements[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
11670
- var elm = _step.value;
11671
- if (!elm.type.startsWith("pcb_")) continue;
11672
- if ("x" in elm && "y" in elm) {
11673
- minX = Math.min(minX, elm.x);
11674
- minY = Math.min(minY, elm.y);
11675
- maxX = Math.max(maxX, elm.x);
11676
- maxY = Math.max(maxY, elm.y);
11677
- if ("width" in elm) {
11678
- maxX = Math.max(maxX, elm.x + elm.width);
11679
- }
11680
- if ("height" in elm) {
11681
- maxY = Math.max(maxY, elm.y + elm.height);
11682
- }
11683
- if ("radius" in elm) {
11684
- minX = Math.min(minX, elm.x - elm.radius);
11685
- minY = Math.min(minY, elm.y - elm.radius);
11686
- maxX = Math.max(maxX, elm.x + elm.radius);
11687
- maxY = Math.max(maxY, elm.y + elm.radius);
11688
- }
11689
- } else if (elm.type === "pcb_trace") {
11690
- var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
11691
- try {
11692
- for(var _iterator1 = elm.route[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
11693
- var point2 = _step1.value;
11694
- minX = Math.min(minX, point2.x);
11695
- minY = Math.min(minY, point2.y);
11696
- maxX = Math.max(maxX, point2.x);
11697
- maxY = Math.max(maxY, point2.y);
11698
- }
11699
- } catch (err) {
11700
- _didIteratorError1 = true;
11701
- _iteratorError1 = err;
11702
- } finally{
11703
- try {
11704
- if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
11705
- _iterator1.return();
11706
- }
11707
- } finally{
11708
- if (_didIteratorError1) {
11709
- throw _iteratorError1;
11710
- }
11711
- }
11712
- }
11713
- }
11714
- }
11715
- } catch (err) {
11716
- _didIteratorError = true;
11717
- _iteratorError = err;
11718
- } finally{
11719
- try {
11720
- if (!_iteratorNormalCompletion && _iterator.return != null) {
11721
- _iterator.return();
11722
- }
11723
- } finally{
11724
- if (_didIteratorError) {
11725
- throw _iteratorError;
11726
- }
11727
- }
11728
- }
11729
- return {
11730
- minX: minX,
11731
- minY: minY,
11732
- maxX: maxX,
11733
- maxY: maxY
11734
- };
12610
+ canvasRefs.current[layer] = el;
12611
+ },
12612
+ style: {
12613
+ position: "absolute",
12614
+ left: 0,
12615
+ top: 0,
12616
+ pointerEvents: "none"
12617
+ },
12618
+ width: width,
12619
+ height: height
12620
+ }, layer);
12621
+ })
12622
+ ]
12623
+ });
11735
12624
  };
12625
+ // src/components/CanvasElementsRenderer.tsx
12626
+ var import_react19 = require("react");
11736
12627
  // src/lib/util/expand-stroke.ts
11737
12628
  function getExpandedStroke(strokeInput, defaultWidth) {
11738
12629
  if (strokeInput.length < 2) {
@@ -12339,12 +13230,12 @@ var convertElementToPrimitives = function(element, allElements) {
12339
13230
  return [];
12340
13231
  };
12341
13232
  // src/components/MouseElementTracker.tsx
12342
- var import_react6 = require("react");
12343
- var import_react7 = require("react");
12344
- var import_transformation_matrix3 = require("transformation-matrix");
13233
+ var import_react9 = require("react");
13234
+ var import_react10 = require("react");
13235
+ var import_transformation_matrix4 = require("transformation-matrix");
12345
13236
  // src/components/ElementOverlayBox.tsx
12346
- var import_react5 = require("react");
12347
- var import_jsx_runtime3 = require("react/jsx-runtime");
13237
+ var import_react8 = require("react");
13238
+ var import_jsx_runtime4 = require("react/jsx-runtime");
12348
13239
  var containerStyle = {
12349
13240
  position: "absolute",
12350
13241
  left: 0,
@@ -12387,8 +13278,8 @@ var layerColorHightlightMap = {
12387
13278
  var HighlightedPrimitiveBoxWithText = function(param) {
12388
13279
  var primitive = param.primitive;
12389
13280
  var _primitive__element;
12390
- var _ref = _sliced_to_array((0, import_react5.useState)(false), 2), finalState = _ref[0], setFinalState = _ref[1];
12391
- (0, import_react5.useEffect)(function() {
13281
+ var _ref = _sliced_to_array((0, import_react8.useState)(false), 2), finalState = _ref[0], setFinalState = _ref[1];
13282
+ (0, import_react8.useEffect)(function() {
12392
13283
  setTimeout(function() {
12393
13284
  setFinalState(true);
12394
13285
  }, 100);
@@ -12404,7 +13295,7 @@ var HighlightedPrimitiveBoxWithText = function(param) {
12404
13295
  var sip = 26;
12405
13296
  var _layerColorHightlightMap_primitive__element_layer;
12406
13297
  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";
12407
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", {
13298
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", {
12408
13299
  style: {
12409
13300
  zIndex: 98,
12410
13301
  position: "absolute",
@@ -12414,7 +13305,7 @@ var HighlightedPrimitiveBoxWithText = function(param) {
12414
13305
  height: h + 16,
12415
13306
  color: color2
12416
13307
  },
12417
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", {
13308
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", {
12418
13309
  style: {
12419
13310
  // width: finalState ? `${100 + 20 * si}%` : "100%",
12420
13311
  // height: finalState ? `${100 + 20 * si}%` : "100%",
@@ -12428,7 +13319,7 @@ var HighlightedPrimitiveBoxWithText = function(param) {
12428
13319
  opacity: finalState ? 1 : si === 0 ? 1 : 0,
12429
13320
  transition: "width 0.2s, height 0.2s, margin-left 0.2s, margin-top 0.2s, opacity 0.2s"
12430
13321
  },
12431
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", {
13322
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", {
12432
13323
  style: {
12433
13324
  position: "absolute",
12434
13325
  left: 0,
@@ -12448,10 +13339,10 @@ var ElementOverlayBox = function(param) {
12448
13339
  var is_moving_component = useGlobalStore(function(s) {
12449
13340
  return s.is_moving_component;
12450
13341
  });
12451
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", {
13342
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", {
12452
13343
  style: containerStyle,
12453
13344
  children: !is_moving_component && highlightedPrimitives.map(function(primitive, i) {
12454
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(HighlightedPrimitiveBoxWithText, {
13345
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(HighlightedPrimitiveBoxWithText, {
12455
13346
  primitive: primitive
12456
13347
  }, i);
12457
13348
  })
@@ -12465,11 +13356,11 @@ function ifSetsMatchExactly(set1, set2) {
12465
13356
  });
12466
13357
  }
12467
13358
  // src/components/MouseElementTracker.tsx
12468
- var import_jsx_runtime4 = require("react/jsx-runtime");
13359
+ var import_jsx_runtime5 = require("react/jsx-runtime");
12469
13360
  var MouseElementTracker = function(param) {
12470
13361
  var children = param.children, transform = param.transform, primitives = param.primitives, onMouseHoverOverPrimitives = param.onMouseHoverOverPrimitives;
12471
- var _ref = _sliced_to_array((0, import_react6.useState)([]), 2), mousedPrimitives = _ref[0], setMousedPrimitives = _ref[1];
12472
- var highlightedPrimitives = (0, import_react7.useMemo)(function() {
13362
+ var _ref = _sliced_to_array((0, import_react9.useState)([]), 2), mousedPrimitives = _ref[0], setMousedPrimitives = _ref[1];
13363
+ var highlightedPrimitives = (0, import_react10.useMemo)(function() {
12473
13364
  var highlightedPrimitives2 = [];
12474
13365
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
12475
13366
  try {
@@ -12479,7 +13370,7 @@ var MouseElementTracker = function(param) {
12479
13370
  if (((_primitive__element = primitive._element) === null || _primitive__element === void 0 ? void 0 : _primitive__element.type) === "pcb_via") return "continue";
12480
13371
  if (((_primitive__element1 = primitive._element) === null || _primitive__element1 === void 0 ? void 0 : _primitive__element1.type) === "pcb_component") return "continue";
12481
13372
  if ((primitive === null || primitive === void 0 ? void 0 : primitive.layer) === "drill") return "continue";
12482
- var screenPos = (0, import_transformation_matrix3.applyToPoint)(transform, primitive);
13373
+ var screenPos = (0, import_transformation_matrix4.applyToPoint)(transform, primitive);
12483
13374
  var w = "w" in primitive ? primitive.w : "r" in primitive ? primitive.r * 2 : 0;
12484
13375
  var h = "h" in primitive ? primitive.h : "r" in primitive ? primitive.r * 2 : 0;
12485
13376
  var screenSize = {
@@ -12517,7 +13408,7 @@ var MouseElementTracker = function(param) {
12517
13408
  mousedPrimitives,
12518
13409
  transform
12519
13410
  ]);
12520
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", {
13411
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", {
12521
13412
  style: {
12522
13413
  position: "relative"
12523
13414
  },
@@ -12526,7 +13417,7 @@ var MouseElementTracker = function(param) {
12526
13417
  var rect = e.currentTarget.getBoundingClientRect();
12527
13418
  var x = e.clientX - rect.left;
12528
13419
  var y = e.clientY - rect.top;
12529
- var rwPoint = (0, import_transformation_matrix3.applyToPoint)((0, import_transformation_matrix3.inverse)(transform), {
13420
+ var rwPoint = (0, import_transformation_matrix4.applyToPoint)((0, import_transformation_matrix4.inverse)(transform), {
12530
13421
  x: x,
12531
13422
  y: y
12532
13423
  });
@@ -12570,37 +13461,37 @@ var MouseElementTracker = function(param) {
12570
13461
  },
12571
13462
  children: [
12572
13463
  children,
12573
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ElementOverlayBox, {
13464
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ElementOverlayBox, {
12574
13465
  highlightedPrimitives: highlightedPrimitives
12575
13466
  })
12576
13467
  ]
12577
13468
  });
12578
13469
  };
12579
13470
  // src/components/DimensionOverlay.tsx
12580
- var import_react8 = require("react");
12581
- var import_transformation_matrix4 = require("transformation-matrix");
12582
- var import_jsx_runtime5 = require("react/jsx-runtime");
13471
+ var import_react11 = require("react");
13472
+ var import_transformation_matrix5 = require("transformation-matrix");
13473
+ var import_jsx_runtime6 = require("react/jsx-runtime");
12583
13474
  var DimensionOverlay = function(param) {
12584
13475
  var children = param.children, transform = param.transform;
12585
- if (!transform) transform = (0, import_transformation_matrix4.identity)();
12586
- var _ref = _sliced_to_array((0, import_react8.useState)(false), 2), dimensionToolVisible = _ref[0], setDimensionToolVisible = _ref[1];
12587
- var _ref1 = _sliced_to_array((0, import_react8.useState)(false), 2), dimensionToolStretching = _ref1[0], setDimensionToolStretching = _ref1[1];
12588
- var _ref2 = _sliced_to_array((0, import_react8.useState)({
13476
+ if (!transform) transform = (0, import_transformation_matrix5.identity)();
13477
+ var _ref = _sliced_to_array((0, import_react11.useState)(false), 2), dimensionToolVisible = _ref[0], setDimensionToolVisible = _ref[1];
13478
+ var _ref1 = _sliced_to_array((0, import_react11.useState)(false), 2), dimensionToolStretching = _ref1[0], setDimensionToolStretching = _ref1[1];
13479
+ var _ref2 = _sliced_to_array((0, import_react11.useState)({
12589
13480
  x: 0,
12590
13481
  y: 0
12591
13482
  }), 2), dStart = _ref2[0], setDStart = _ref2[1];
12592
- var _ref3 = _sliced_to_array((0, import_react8.useState)({
13483
+ var _ref3 = _sliced_to_array((0, import_react11.useState)({
12593
13484
  x: 0,
12594
13485
  y: 0
12595
13486
  }), 2), dEnd = _ref3[0], setDEnd = _ref3[1];
12596
- var mousePosRef = (0, import_react8.useRef)({
13487
+ var mousePosRef = (0, import_react11.useRef)({
12597
13488
  x: 0,
12598
13489
  y: 0
12599
13490
  });
12600
- var containerRef = (0, import_react8.useRef)(null);
13491
+ var containerRef = (0, import_react11.useRef)(null);
12601
13492
  var container = containerRef.current;
12602
13493
  var containerBounds = container === null || container === void 0 ? void 0 : container.getBoundingClientRect();
12603
- (0, import_react8.useEffect)(function() {
13494
+ (0, import_react11.useEffect)(function() {
12604
13495
  var container2 = containerRef.current;
12605
13496
  var down = function(e) {
12606
13497
  if (e.key === "d") {
@@ -12650,8 +13541,8 @@ var DimensionOverlay = function(param) {
12650
13541
  }, [
12651
13542
  containerRef
12652
13543
  ]);
12653
- var screenDStart = (0, import_transformation_matrix4.applyToPoint)(transform, dStart);
12654
- var screenDEnd = (0, import_transformation_matrix4.applyToPoint)(transform, dEnd);
13544
+ var screenDStart = (0, import_transformation_matrix5.applyToPoint)(transform, dStart);
13545
+ var screenDEnd = (0, import_transformation_matrix5.applyToPoint)(transform, dEnd);
12655
13546
  var arrowScreenBounds = {
12656
13547
  left: Math.min(screenDStart.x, screenDEnd.x),
12657
13548
  right: Math.max(screenDStart.x, screenDEnd.x),
@@ -12664,7 +13555,7 @@ var DimensionOverlay = function(param) {
12664
13555
  };
12665
13556
  arrowScreenBounds.width = arrowScreenBounds.right - arrowScreenBounds.left;
12666
13557
  arrowScreenBounds.height = arrowScreenBounds.bottom - arrowScreenBounds.top;
12667
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", {
13558
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", {
12668
13559
  ref: containerRef,
12669
13560
  tabIndex: 0,
12670
13561
  style: {
@@ -12684,7 +13575,7 @@ var DimensionOverlay = function(param) {
12684
13575
  var rect = e.currentTarget.getBoundingClientRect();
12685
13576
  var x = e.clientX - rect.left;
12686
13577
  var y = e.clientY - rect.top;
12687
- var rwPoint = (0, import_transformation_matrix4.applyToPoint)((0, import_transformation_matrix4.inverse)(transform), {
13578
+ var rwPoint = (0, import_transformation_matrix5.applyToPoint)((0, import_transformation_matrix5.inverse)(transform), {
12688
13579
  x: x,
12689
13580
  y: y
12690
13581
  });
@@ -12706,9 +13597,9 @@ var DimensionOverlay = function(param) {
12706
13597
  },
12707
13598
  children: [
12708
13599
  children,
12709
- dimensionToolVisible && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, {
13600
+ dimensionToolVisible && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, {
12710
13601
  children: [
12711
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", {
13602
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", {
12712
13603
  style: {
12713
13604
  position: "absolute",
12714
13605
  left: arrowScreenBounds.left,
@@ -12725,7 +13616,7 @@ var DimensionOverlay = function(param) {
12725
13616
  },
12726
13617
  children: Math.abs(dStart.x - dEnd.x).toFixed(2)
12727
13618
  }),
12728
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", {
13619
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", {
12729
13620
  style: {
12730
13621
  position: "absolute",
12731
13622
  left: screenDEnd.x,
@@ -12741,7 +13632,7 @@ var DimensionOverlay = function(param) {
12741
13632
  fontFamily: "sans-serif",
12742
13633
  zIndex: 1e3
12743
13634
  },
12744
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", {
13635
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", {
12745
13636
  style: {
12746
13637
  marginLeft: arrowScreenBounds.flipX ? "-100%" : 4,
12747
13638
  paddingRight: 4
@@ -12749,7 +13640,7 @@ var DimensionOverlay = function(param) {
12749
13640
  children: Math.abs(dStart.y - dEnd.y).toFixed(2)
12750
13641
  })
12751
13642
  }),
12752
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("svg", {
13643
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("svg", {
12753
13644
  style: {
12754
13645
  position: "absolute",
12755
13646
  left: 0,
@@ -12761,21 +13652,21 @@ var DimensionOverlay = function(param) {
12761
13652
  width: containerBounds.width,
12762
13653
  height: containerBounds.height,
12763
13654
  children: [
12764
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("defs", {
12765
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("marker", {
13655
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("defs", {
13656
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("marker", {
12766
13657
  id: "head",
12767
13658
  orient: "auto",
12768
13659
  markerWidth: "3",
12769
13660
  markerHeight: "4",
12770
13661
  refX: "2",
12771
13662
  refY: "2",
12772
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", {
13663
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("path", {
12773
13664
  d: "M0,0 V4 L2,2 Z",
12774
13665
  fill: "red"
12775
13666
  })
12776
13667
  })
12777
13668
  }),
12778
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("line", {
13669
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("line", {
12779
13670
  x1: screenDStart.x,
12780
13671
  y1: screenDStart.y,
12781
13672
  x2: screenDEnd.x,
@@ -12785,7 +13676,7 @@ var DimensionOverlay = function(param) {
12785
13676
  fill: "none",
12786
13677
  stroke: "red"
12787
13678
  }),
12788
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("line", {
13679
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("line", {
12789
13680
  x1: screenDStart.x,
12790
13681
  y1: screenDStart.y,
12791
13682
  x2: screenDEnd.x,
@@ -12795,7 +13686,7 @@ var DimensionOverlay = function(param) {
12795
13686
  strokeDasharray: "2,2",
12796
13687
  stroke: "red"
12797
13688
  }),
12798
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("line", {
13689
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("line", {
12799
13690
  x1: screenDEnd.x,
12800
13691
  y1: screenDStart.y,
12801
13692
  x2: screenDEnd.x,
@@ -12807,7 +13698,7 @@ var DimensionOverlay = function(param) {
12807
13698
  })
12808
13699
  ]
12809
13700
  }),
12810
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", {
13701
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", {
12811
13702
  style: {
12812
13703
  right: 0,
12813
13704
  bottom: 0,
@@ -12823,13 +13714,13 @@ var DimensionOverlay = function(param) {
12823
13714
  ",",
12824
13715
  dStart.y.toFixed(2),
12825
13716
  ")",
12826
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("br", {}),
13717
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("br", {}),
12827
13718
  "(",
12828
13719
  dEnd.x.toFixed(2),
12829
13720
  ",",
12830
13721
  dEnd.y.toFixed(2),
12831
13722
  ")",
12832
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("br", {}),
13723
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("br", {}),
12833
13724
  "dist:",
12834
13725
  " ",
12835
13726
  Math.sqrt(Math.pow(dEnd.x - dStart.x, 2) + Math.pow(dEnd.y - dStart.y, 2)).toFixed(2)
@@ -12841,12 +13732,12 @@ var DimensionOverlay = function(param) {
12841
13732
  });
12842
13733
  };
12843
13734
  // src/components/ToolbarOverlay.tsx
12844
- var import_react10 = require("react");
13735
+ var import_react13 = require("react");
12845
13736
  var import_css = require("@emotion/css");
12846
13737
  // package.json
12847
13738
  var package_default = {
12848
13739
  name: "@tscircuit/pcb-viewer",
12849
- version: "1.10.9",
13740
+ version: "1.10.11",
12850
13741
  main: "dist/index.js",
12851
13742
  repository: "tscircuit/pcb-viewer",
12852
13743
  license: "MIT",
@@ -12869,10 +13760,10 @@ var package_default = {
12869
13760
  "@storybook/nextjs": "^8.0.6",
12870
13761
  "@storybook/react": "^8.0.6",
12871
13762
  "@swc/core": "^1.4.12",
12872
- "@tscircuit/core": "^0.0.106",
13763
+ "@tscircuit/core": "^0.0.108",
12873
13764
  "@tscircuit/eagle-xml-converter": "^0.0.6",
12874
13765
  "@tscircuit/props": "^0.0.46",
12875
- "@tscircuit/soup-util": "^0.0.32",
13766
+ "@tscircuit/soup-util": "^0.0.38",
12876
13767
  "@types/color": "^3.0.6",
12877
13768
  "@types/node": "18.7.23",
12878
13769
  "@types/react": "^18.3.3",
@@ -12904,12 +13795,12 @@ var package_default = {
12904
13795
  }
12905
13796
  };
12906
13797
  // src/hooks/useHotKey.ts
12907
- var import_react9 = require("react");
13798
+ var import_react12 = require("react");
12908
13799
  var useHotKey = function(key, onUse) {
12909
13800
  var isMouseOverContainer = useGlobalStore(function(s) {
12910
13801
  return s.is_mouse_over_container;
12911
13802
  });
12912
- (0, import_react9.useEffect)(function() {
13803
+ (0, import_react12.useEffect)(function() {
12913
13804
  if (!key || typeof onUse !== "function") return;
12914
13805
  var handleKeyDown = function(event) {
12915
13806
  var keyParts = key.split("+");
@@ -12933,21 +13824,21 @@ var useHotKey = function(key, onUse) {
12933
13824
  ]);
12934
13825
  };
12935
13826
  // src/components/ToolbarOverlay.tsx
12936
- var import_jsx_runtime6 = require("react/jsx-runtime");
13827
+ var import_jsx_runtime7 = require("react/jsx-runtime");
12937
13828
  var LayerButton = function(param) {
12938
13829
  var name = param.name, selected = param.selected, onClick = param.onClick;
12939
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", {
13830
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", {
12940
13831
  className: import_css.css(_templateObject()),
12941
13832
  onClick: onClick,
12942
13833
  children: [
12943
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", {
13834
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", {
12944
13835
  style: {
12945
13836
  marginRight: 2,
12946
13837
  opacity: selected ? 1 : 0
12947
13838
  },
12948
13839
  children: "•"
12949
13840
  }),
12950
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", {
13841
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", {
12951
13842
  style: {
12952
13843
  marginLeft: 2,
12953
13844
  fontWeight: 500,
@@ -12962,7 +13853,7 @@ var ToolbarButton = function(_param) {
12962
13853
  var children = _param.children, props = _object_without_properties(_param, [
12963
13854
  "children"
12964
13855
  ]);
12965
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", _object_spread_props(_object_spread({}, props), {
13856
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", _object_spread_props(_object_spread({}, props), {
12966
13857
  style: _object_spread({
12967
13858
  backgroundColor: "#1F1F1F",
12968
13859
  border: "1px solid #666",
@@ -12986,8 +13877,8 @@ var ToolbarOverlay = function(param) {
12986
13877
  s.setIsMouseOverContainer
12987
13878
  ];
12988
13879
  }), 2), isMouseOverContainer = _useGlobalStore[0], setIsMouseOverContainer = _useGlobalStore[1];
12989
- var _ref = _sliced_to_array((0, import_react10.useState)(false), 2), isLayerMenuOpen = _ref[0], setLayerMenuOpen = _ref[1];
12990
- var _ref1 = _sliced_to_array((0, import_react10.useState)(false), 2), isErrorsOpen = _ref1[0], setErrorsOpen = _ref1[1];
13880
+ var _ref = _sliced_to_array((0, import_react13.useState)(false), 2), isLayerMenuOpen = _ref[0], setLayerMenuOpen = _ref[1];
13881
+ var _ref1 = _sliced_to_array((0, import_react13.useState)(false), 2), isErrorsOpen = _ref1[0], setErrorsOpen = _ref1[1];
12991
13882
  var _useGlobalStore1 = _sliced_to_array(useGlobalStore(function(s) {
12992
13883
  return [
12993
13884
  s.selected_layer,
@@ -13035,7 +13926,7 @@ var ToolbarOverlay = function(param) {
13035
13926
  var errorCount = (_elements_filter_length = elements === null || elements === void 0 ? void 0 : elements.filter(function(e) {
13036
13927
  return e.type.includes("error");
13037
13928
  }).length) !== null && _elements_filter_length !== void 0 ? _elements_filter_length : 0;
13038
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", {
13929
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", {
13039
13930
  style: {
13040
13931
  position: "relative"
13041
13932
  },
@@ -13048,7 +13939,7 @@ var ToolbarOverlay = function(param) {
13048
13939
  },
13049
13940
  children: [
13050
13941
  children,
13051
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", {
13942
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", {
13052
13943
  style: {
13053
13944
  position: "absolute",
13054
13945
  bottom: 4,
@@ -13066,7 +13957,7 @@ var ToolbarOverlay = function(param) {
13066
13957
  package_default.version
13067
13958
  ]
13068
13959
  }),
13069
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", {
13960
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", {
13070
13961
  style: {
13071
13962
  position: "absolute",
13072
13963
  opacity: isMouseOverContainer ? 1 : 0,
@@ -13081,7 +13972,7 @@ var ToolbarOverlay = function(param) {
13081
13972
  fontFamily: "sans-serif"
13082
13973
  },
13083
13974
  children: [
13084
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(ToolbarButton, {
13975
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(ToolbarButton, {
13085
13976
  onClick: function() {
13086
13977
  setLayerMenuOpen(!isLayerMenuOpen);
13087
13978
  },
@@ -13091,11 +13982,11 @@ var ToolbarOverlay = function(param) {
13091
13982
  }
13092
13983
  },
13093
13984
  children: [
13094
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", {
13985
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", {
13095
13986
  children: [
13096
13987
  "layer:",
13097
13988
  " ",
13098
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", {
13989
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", {
13099
13990
  style: {
13100
13991
  marginLeft: 2,
13101
13992
  fontWeight: 500,
@@ -13105,7 +13996,7 @@ var ToolbarOverlay = function(param) {
13105
13996
  })
13106
13997
  ]
13107
13998
  }),
13108
- isLayerMenuOpen && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", {
13999
+ isLayerMenuOpen && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", {
13109
14000
  style: {
13110
14001
  marginTop: 4,
13111
14002
  minWidth: 120
@@ -13113,7 +14004,7 @@ var ToolbarOverlay = function(param) {
13113
14004
  children: all_layers.map(function(l) {
13114
14005
  return l.replace(/-/g, "");
13115
14006
  }).map(function(layer) {
13116
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(LayerButton, {
14007
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(LayerButton, {
13117
14008
  name: layer,
13118
14009
  selected: layer === selectedLayer,
13119
14010
  onClick: function() {
@@ -13124,7 +14015,7 @@ var ToolbarOverlay = function(param) {
13124
14015
  })
13125
14016
  ]
13126
14017
  }),
13127
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(ToolbarButton, {
14018
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(ToolbarButton, {
13128
14019
  style: errorCount > 0 ? {
13129
14020
  color: "red"
13130
14021
  } : {},
@@ -13135,13 +14026,13 @@ var ToolbarOverlay = function(param) {
13135
14026
  return setErrorsOpen(false);
13136
14027
  },
13137
14028
  children: [
13138
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", {
14029
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", {
13139
14030
  children: [
13140
14031
  errorCount,
13141
14032
  " errors"
13142
14033
  ]
13143
14034
  }),
13144
- isErrorsOpen && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", {
14035
+ isErrorsOpen && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", {
13145
14036
  style: {
13146
14037
  display: "grid",
13147
14038
  gridTemplateColumns: "100px 300px"
@@ -13149,12 +14040,12 @@ var ToolbarOverlay = function(param) {
13149
14040
  children: elements === null || elements === void 0 ? void 0 : elements.filter(function(e) {
13150
14041
  return e.type.includes("error");
13151
14042
  }).map(function(e, i) {
13152
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_react10.Fragment, {
14043
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_react13.Fragment, {
13153
14044
  children: [
13154
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", {
14045
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", {
13155
14046
  children: e.error_type
13156
14047
  }),
13157
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", {
14048
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", {
13158
14049
  children: e.message
13159
14050
  })
13160
14051
  ]
@@ -13163,36 +14054,36 @@ var ToolbarOverlay = function(param) {
13163
14054
  })
13164
14055
  ]
13165
14056
  }),
13166
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ToolbarButton, {
14057
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ToolbarButton, {
13167
14058
  style: {},
13168
14059
  onClick: function() {
13169
14060
  setEditMode(in_draw_trace_mode ? "off" : "draw_trace");
13170
14061
  },
13171
- children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", {
14062
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", {
13172
14063
  children: [
13173
14064
  in_draw_trace_mode ? "✖ " : "",
13174
14065
  "Edit Traces"
13175
14066
  ]
13176
14067
  })
13177
14068
  }),
13178
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ToolbarButton, {
14069
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ToolbarButton, {
13179
14070
  style: {},
13180
14071
  onClick: function() {
13181
14072
  setEditMode(in_move_footprint_mode ? "off" : "move_footprint");
13182
14073
  },
13183
- children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", {
14074
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", {
13184
14075
  children: [
13185
14076
  in_move_footprint_mode ? "✖ " : "",
13186
14077
  "Move Components"
13187
14078
  ]
13188
14079
  })
13189
14080
  }),
13190
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ToolbarButton, {
14081
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ToolbarButton, {
13191
14082
  style: {},
13192
14083
  onClick: function() {
13193
14084
  setIsShowingRatsNest(!is_showing_rats_nest);
13194
14085
  },
13195
- children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", {
14086
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", {
13196
14087
  children: [
13197
14088
  is_showing_rats_nest ? "✖ " : "",
13198
14089
  "Rats Nest"
@@ -13206,12 +14097,12 @@ var ToolbarOverlay = function(param) {
13206
14097
  };
13207
14098
  // src/components/ErrorOverlay.tsx
13208
14099
  var import_css2 = require("@emotion/css");
13209
- var import_react11 = require("react");
13210
- var import_transformation_matrix5 = require("transformation-matrix");
13211
- var import_jsx_runtime7 = require("react/jsx-runtime");
14100
+ var import_react14 = require("react");
14101
+ var import_transformation_matrix6 = require("transformation-matrix");
14102
+ var import_jsx_runtime8 = require("react/jsx-runtime");
13212
14103
  var ErrorSVG = function(param) {
13213
14104
  var screenPort1 = param.screenPort1, screenPort2 = param.screenPort2, errorCenter = param.errorCenter, canLineBeDrawn = param.canLineBeDrawn;
13214
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("svg", {
14105
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("svg", {
13215
14106
  style: {
13216
14107
  position: "absolute",
13217
14108
  left: 0,
@@ -13222,9 +14113,9 @@ var ErrorSVG = function(param) {
13222
14113
  },
13223
14114
  width: "100%",
13224
14115
  height: "100%",
13225
- children: canLineBeDrawn && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, {
14116
+ children: canLineBeDrawn && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, {
13226
14117
  children: [
13227
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("line", {
14118
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("line", {
13228
14119
  x1: screenPort1.x,
13229
14120
  y1: screenPort1.y,
13230
14121
  x2: errorCenter.x,
@@ -13233,7 +14124,7 @@ var ErrorSVG = function(param) {
13233
14124
  strokeDasharray: "2,2",
13234
14125
  stroke: "red"
13235
14126
  }),
13236
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("line", {
14127
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("line", {
13237
14128
  x1: errorCenter.x,
13238
14129
  y1: errorCenter.y,
13239
14130
  x2: screenPort2.x,
@@ -13242,7 +14133,7 @@ var ErrorSVG = function(param) {
13242
14133
  strokeDasharray: "2,2",
13243
14134
  stroke: "red"
13244
14135
  }),
13245
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("rect", {
14136
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("rect", {
13246
14137
  x: errorCenter.x - 5,
13247
14138
  y: errorCenter.y - 5,
13248
14139
  width: 10,
@@ -13256,9 +14147,9 @@ var ErrorSVG = function(param) {
13256
14147
  };
13257
14148
  var ErrorOverlay = function(param) {
13258
14149
  var children = param.children, transform = param.transform, elements = param.elements;
13259
- if (!transform) transform = (0, import_transformation_matrix5.identity)();
13260
- var containerRef = (0, import_react11.useRef)(null);
13261
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", {
14150
+ if (!transform) transform = (0, import_transformation_matrix6.identity)();
14151
+ var containerRef = (0, import_react14.useRef)(null);
14152
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", {
13262
14153
  style: {
13263
14154
  position: "relative"
13264
14155
  },
@@ -13276,11 +14167,11 @@ var ErrorOverlay = function(param) {
13276
14167
  return el2.type === "pcb_port" && el2.pcb_port_id === (pcb_port_ids === null || pcb_port_ids === void 0 ? void 0 : pcb_port_ids[1]);
13277
14168
  });
13278
14169
  if (!port1 || !port2) return null;
13279
- var screenPort1 = (0, import_transformation_matrix5.applyToPoint)(transform, {
14170
+ var screenPort1 = (0, import_transformation_matrix6.applyToPoint)(transform, {
13280
14171
  x: port1.x,
13281
14172
  y: port1.y
13282
14173
  });
13283
- var screenPort2 = (0, import_transformation_matrix5.applyToPoint)(transform, {
14174
+ var screenPort2 = (0, import_transformation_matrix6.applyToPoint)(transform, {
13284
14175
  x: port2.x,
13285
14176
  y: port2.y
13286
14177
  });
@@ -13292,22 +14183,22 @@ var ErrorOverlay = function(param) {
13292
14183
  if (isNaN(errorCenter.x) || isNaN(errorCenter.y)) {
13293
14184
  return null;
13294
14185
  }
13295
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, {
14186
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, {
13296
14187
  children: [
13297
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ErrorSVG, {
14188
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ErrorSVG, {
13298
14189
  screenPort1: screenPort1,
13299
14190
  screenPort2: screenPort2,
13300
14191
  errorCenter: errorCenter,
13301
14192
  canLineBeDrawn: canLineBeDrawn
13302
14193
  }),
13303
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", {
14194
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", {
13304
14195
  className: import_css2.css(_templateObject1(), errorCenter.x, errorCenter.y),
13305
14196
  children: [
13306
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", {
14197
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", {
13307
14198
  className: "error-message",
13308
14199
  children: el.message
13309
14200
  }),
13310
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", {
14201
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", {
13311
14202
  className: import_css2.css(_templateObject2())
13312
14203
  })
13313
14204
  ]
@@ -13319,9 +14210,9 @@ var ErrorOverlay = function(param) {
13319
14210
  });
13320
14211
  };
13321
14212
  // src/components/EditPlacementOverlay.tsx
13322
- var import_react12 = require("react");
13323
- var import_transformation_matrix6 = require("transformation-matrix");
13324
- var import_jsx_runtime8 = require("react/jsx-runtime");
14213
+ var import_react15 = require("react");
14214
+ var import_transformation_matrix7 = require("transformation-matrix");
14215
+ var import_jsx_runtime9 = require("react/jsx-runtime");
13325
14216
  var isInsideOf = function(pcb_component2, point2) {
13326
14217
  var padding = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 0;
13327
14218
  var halfWidth = pcb_component2.width / 2;
@@ -13334,10 +14225,10 @@ var isInsideOf = function(pcb_component2, point2) {
13334
14225
  };
13335
14226
  var EditPlacementOverlay = function(param) {
13336
14227
  var children = param.children, disabledProp = param.disabled, transform = param.transform, soup = param.soup, cancelPanDrag = param.cancelPanDrag, onCreateEditEvent = param.onCreateEditEvent, onModifyEditEvent = param.onModifyEditEvent;
13337
- if (!transform) transform = (0, import_transformation_matrix6.identity)();
13338
- var containerRef = (0, import_react12.useRef)(null);
13339
- var _ref = _sliced_to_array((0, import_react12.useState)(null), 2), activePcbComponentId = _ref[0], setActivePcbComponent = _ref[1];
13340
- var _ref1 = _sliced_to_array((0, import_react12.useState)(null), 2), dragState = _ref1[0], setDragState = _ref1[1];
14228
+ if (!transform) transform = (0, import_transformation_matrix7.identity)();
14229
+ var containerRef = (0, import_react15.useRef)(null);
14230
+ var _ref = _sliced_to_array((0, import_react15.useState)(null), 2), activePcbComponentId = _ref[0], setActivePcbComponent = _ref[1];
14231
+ var _ref1 = _sliced_to_array((0, import_react15.useState)(null), 2), dragState = _ref1[0], setDragState = _ref1[1];
13341
14232
  var isPcbComponentActive = activePcbComponentId !== null;
13342
14233
  var in_edit_mode = useGlobalStore(function(s) {
13343
14234
  return s.in_edit_mode;
@@ -13349,7 +14240,7 @@ var EditPlacementOverlay = function(param) {
13349
14240
  return s.setIsMovingComponent;
13350
14241
  });
13351
14242
  var disabled = disabledProp || !in_move_footprint_mode;
13352
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", {
14243
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", {
13353
14244
  ref: containerRef,
13354
14245
  style: {
13355
14246
  position: "relative",
@@ -13361,7 +14252,7 @@ var EditPlacementOverlay = function(param) {
13361
14252
  var x = e.clientX - rect.left;
13362
14253
  var y = e.clientY - rect.top;
13363
14254
  if (isNaN(x) || isNaN(y)) return;
13364
- var rwMousePoint = (0, import_transformation_matrix6.applyToPoint)((0, import_transformation_matrix6.inverse)(transform), {
14255
+ var rwMousePoint = (0, import_transformation_matrix7.applyToPoint)((0, import_transformation_matrix7.inverse)(transform), {
13365
14256
  x: x,
13366
14257
  y: y
13367
14258
  });
@@ -13422,7 +14313,7 @@ var EditPlacementOverlay = function(param) {
13422
14313
  var x = e.clientX - rect.left;
13423
14314
  var y = e.clientY - rect.top;
13424
14315
  if (isNaN(x) || isNaN(y)) return;
13425
- var rwMousePoint = (0, import_transformation_matrix6.applyToPoint)((0, import_transformation_matrix6.inverse)(transform), {
14316
+ var rwMousePoint = (0, import_transformation_matrix7.applyToPoint)((0, import_transformation_matrix7.inverse)(transform), {
13426
14317
  x: x,
13427
14318
  y: y
13428
14319
  });
@@ -13455,8 +14346,8 @@ var EditPlacementOverlay = function(param) {
13455
14346
  return e.type === "pcb_component";
13456
14347
  }).map(function(e) {
13457
14348
  if (!(e === null || e === void 0 ? void 0 : e.center)) return null;
13458
- var projectedCenter = (0, import_transformation_matrix6.applyToPoint)(transform, e.center);
13459
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", {
14349
+ var projectedCenter = (0, import_transformation_matrix7.applyToPoint)(transform, e.center);
14350
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", {
13460
14351
  style: {
13461
14352
  position: "absolute",
13462
14353
  pointerEvents: "none",
@@ -13474,15 +14365,15 @@ var EditPlacementOverlay = function(param) {
13474
14365
  });
13475
14366
  };
13476
14367
  // src/components/EditTraceHintOverlay.tsx
13477
- var import_react15 = require("react");
13478
- var import_transformation_matrix7 = require("transformation-matrix");
14368
+ var import_react17 = require("react");
14369
+ var import_transformation_matrix8 = require("transformation-matrix");
13479
14370
  // src/components/HotkeyActionMenu.tsx
13480
14371
  var import_css3 = require("@emotion/css");
13481
- var import_react13 = require("react");
13482
- var import_jsx_runtime9 = require("react/jsx-runtime");
14372
+ var import_react16 = require("react");
14373
+ var import_jsx_runtime10 = require("react/jsx-runtime");
13483
14374
  var HotkeyActionMenu = function(param) {
13484
14375
  var hotkeys = param.hotkeys;
13485
- (0, import_react13.useEffect)(function() {
14376
+ (0, import_react16.useEffect)(function() {
13486
14377
  var handleKeyDown = function(event) {
13487
14378
  hotkeys.forEach(function(hotkey) {
13488
14379
  if (event.key === hotkey.key) {
@@ -13497,18 +14388,18 @@ var HotkeyActionMenu = function(param) {
13497
14388
  }, [
13498
14389
  hotkeys
13499
14390
  ]);
13500
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", {
14391
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", {
13501
14392
  className: import_css3.css(_templateObject3()),
13502
14393
  children: hotkeys.map(function(hotkey) {
13503
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", {
14394
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", {
13504
14395
  className: import_css3.css(_templateObject4()),
13505
14396
  children: [
13506
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", {
14397
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", {
13507
14398
  className: "key",
13508
14399
  children: hotkey.key
13509
14400
  }),
13510
14401
  " ",
13511
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", {
14402
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", {
13512
14403
  className: "name",
13513
14404
  children: hotkey.name
13514
14405
  })
@@ -13517,40 +14408,6 @@ var HotkeyActionMenu = function(param) {
13517
14408
  })
13518
14409
  });
13519
14410
  };
13520
- // src/lib/toast.tsx
13521
- var import_react14 = require("react");
13522
- var import_react_toastify = require("react-toastify");
13523
- var import_inject_style = require("react-toastify/dist/inject-style");
13524
- var import_jsx_runtime10 = require("react/jsx-runtime");
13525
- var useToast = function() {
13526
- var pcb_viewer_id = useGlobalStore(function(s) {
13527
- return s.pcb_viewer_id;
13528
- });
13529
- var toast = function(message, opts) {
13530
- return (0, import_react_toastify.toast)(message, _object_spread({
13531
- containerId: pcb_viewer_id
13532
- }, opts));
13533
- };
13534
- toast.error = function(message, opts) {
13535
- return import_react_toastify.toast.error(message, _object_spread({
13536
- containerId: pcb_viewer_id
13537
- }, opts));
13538
- };
13539
- toast.promise = import_react_toastify.toast.promise;
13540
- return toast;
13541
- };
13542
- var ToastContainer = function() {
13543
- (0, import_react14.useEffect)(function() {
13544
- (0, import_inject_style.injectStyle)();
13545
- }, []);
13546
- var pcb_viewer_id = useGlobalStore(function(s) {
13547
- return s.pcb_viewer_id;
13548
- });
13549
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_react_toastify.ToastContainer, {
13550
- position: "top-center",
13551
- containerId: pcb_viewer_id
13552
- });
13553
- };
13554
14411
  // src/components/EditTraceHintOverlay.tsx
13555
14412
  var import_jsx_runtime11 = require("react/jsx-runtime");
13556
14413
  var isInsideOfSmtpad = function(elm, point2) {
@@ -13584,13 +14441,13 @@ var isInsideOfPlatedHole = function(hole, point2) {
13584
14441
  var EditTraceHintOverlay = function(param) {
13585
14442
  var children = param.children, disabledProp = param.disabled, transform = param.transform, soup = param.soup, cancelPanDrag = param.cancelPanDrag, onCreateEditEvent = param.onCreateEditEvent, onModifyEditEvent = param.onModifyEditEvent;
13586
14443
  var _containerRef_current;
13587
- if (!transform) transform = (0, import_transformation_matrix7.identity)();
13588
- var containerRef = (0, import_react15.useRef)(null);
14444
+ if (!transform) transform = (0, import_transformation_matrix8.identity)();
14445
+ var containerRef = (0, import_react17.useRef)(null);
13589
14446
  var containerBounds = (_containerRef_current = containerRef.current) === null || _containerRef_current === void 0 ? void 0 : _containerRef_current.getBoundingClientRect();
13590
- var _ref = _sliced_to_array((0, import_react15.useState)(null), 2), selectedElement = _ref[0], setSelectedElement = _ref[1];
14447
+ var _ref = _sliced_to_array((0, import_react17.useState)(null), 2), selectedElement = _ref[0], setSelectedElement = _ref[1];
13591
14448
  var toast = useToast();
13592
- var _ref1 = _sliced_to_array((0, import_react15.useState)(null), 2), dragState = _ref1[0], setDragState = _ref1[1];
13593
- var _ref2 = _sliced_to_array((0, import_react15.useState)(false), 2), shouldCreateAsVia = _ref2[0], setShouldCreateAsVia = _ref2[1];
14449
+ var _ref1 = _sliced_to_array((0, import_react17.useState)(null), 2), dragState = _ref1[0], setDragState = _ref1[1];
14450
+ var _ref2 = _sliced_to_array((0, import_react17.useState)(false), 2), shouldCreateAsVia = _ref2[0], setShouldCreateAsVia = _ref2[1];
13594
14451
  var isElementSelected = selectedElement !== null;
13595
14452
  var in_edit_trace_mode = useGlobalStore(function(s) {
13596
14453
  return s.in_draw_trace_mode;
@@ -13598,10 +14455,10 @@ var EditTraceHintOverlay = function(param) {
13598
14455
  var disabled = disabledProp || !in_edit_trace_mode;
13599
14456
  var ogCenterScreen, dragEndScreen;
13600
14457
  if ((dragState === null || dragState === void 0 ? void 0 : dragState.originalCenter) && (dragState === null || dragState === void 0 ? void 0 : dragState.dragEnd)) {
13601
- ogCenterScreen = (0, import_transformation_matrix7.applyToPoint)(transform, dragState === null || dragState === void 0 ? void 0 : dragState.originalCenter);
13602
- dragEndScreen = (0, import_transformation_matrix7.applyToPoint)(transform, dragState === null || dragState === void 0 ? void 0 : dragState.dragEnd);
14458
+ ogCenterScreen = (0, import_transformation_matrix8.applyToPoint)(transform, dragState === null || dragState === void 0 ? void 0 : dragState.originalCenter);
14459
+ dragEndScreen = (0, import_transformation_matrix8.applyToPoint)(transform, dragState === null || dragState === void 0 ? void 0 : dragState.dragEnd);
13603
14460
  }
13604
- (0, import_react15.useEffect)(function() {
14461
+ (0, import_react17.useEffect)(function() {
13605
14462
  var keyDown = function keyDown(e) {
13606
14463
  if (e.key === "Escape") {
13607
14464
  setSelectedElement(null);
@@ -13628,7 +14485,7 @@ var EditTraceHintOverlay = function(param) {
13628
14485
  var x = e.clientX - rect.left;
13629
14486
  var y = e.clientY - rect.top;
13630
14487
  if (isNaN(x) || isNaN(y)) return;
13631
- var rwMousePoint = (0, import_transformation_matrix7.applyToPoint)((0, import_transformation_matrix7.inverse)(transform), {
14488
+ var rwMousePoint = (0, import_transformation_matrix8.applyToPoint)((0, import_transformation_matrix8.inverse)(transform), {
13632
14489
  x: x,
13633
14490
  y: y
13634
14491
  });
@@ -13693,7 +14550,7 @@ var EditTraceHintOverlay = function(param) {
13693
14550
  var x = e.clientX - rect.left;
13694
14551
  var y = e.clientY - rect.top;
13695
14552
  if (isNaN(x) || isNaN(y)) return;
13696
- var rwMousePoint = (0, import_transformation_matrix7.applyToPoint)((0, import_transformation_matrix7.inverse)(transform), {
14553
+ var rwMousePoint = (0, import_transformation_matrix8.applyToPoint)((0, import_transformation_matrix8.inverse)(transform), {
13697
14554
  x: x,
13698
14555
  y: y
13699
14556
  });
@@ -13712,14 +14569,14 @@ var EditTraceHintOverlay = function(param) {
13712
14569
  var x = e.clientX - rect.left;
13713
14570
  var y = e.clientY - rect.top;
13714
14571
  if (isNaN(x) || isNaN(y)) return;
13715
- var rwMousePoint = (0, import_transformation_matrix7.applyToPoint)((0, import_transformation_matrix7.inverse)(transform), {
14572
+ var rwMousePoint = (0, import_transformation_matrix8.applyToPoint)((0, import_transformation_matrix8.inverse)(transform), {
13716
14573
  x: x,
13717
14574
  y: y
13718
14575
  });
13719
14576
  if (dragState) {
13720
14577
  cancelPanDrag();
13721
14578
  var _dragState_editEvent_route_slice_;
13722
- var lastPointScreen = (0, import_transformation_matrix7.applyToPoint)(transform, (_dragState_editEvent_route_slice_ = dragState.editEvent.route.slice(-1)[0]) !== null && _dragState_editEvent_route_slice_ !== void 0 ? _dragState_editEvent_route_slice_ : dragState.originalCenter);
14579
+ var lastPointScreen = (0, import_transformation_matrix8.applyToPoint)(transform, (_dragState_editEvent_route_slice_ = dragState.editEvent.route.slice(-1)[0]) !== null && _dragState_editEvent_route_slice_ !== void 0 ? _dragState_editEvent_route_slice_ : dragState.originalCenter);
13723
14580
  var distanceFromLastPoint = Math.sqrt(Math.pow(x - lastPointScreen.x, 2) + Math.pow(y - lastPointScreen.y, 2));
13724
14581
  if (distanceFromLastPoint < 20) {
13725
14582
  onCreateEditEvent(_object_spread_props(_object_spread({}, dragState.editEvent), {
@@ -13757,14 +14614,14 @@ var EditTraceHintOverlay = function(param) {
13757
14614
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("path", {
13758
14615
  stroke: "red",
13759
14616
  d: "M ".concat(ogCenterScreen.x, " ").concat(ogCenterScreen.y, " ").concat(dragState === null || dragState === void 0 ? void 0 : dragState.editEvent.route.map(function(p) {
13760
- return (0, import_transformation_matrix7.applyToPoint)(transform, p);
14617
+ return (0, import_transformation_matrix8.applyToPoint)(transform, p);
13761
14618
  }).map(function(p) {
13762
14619
  return "L ".concat(p.x, " ").concat(p.y);
13763
14620
  }).join(" "), " L ").concat(dragEndScreen.x, " ").concat(dragEndScreen.y)
13764
14621
  }),
13765
14622
  dragState === null || dragState === void 0 ? void 0 : dragState.editEvent.route.map(function(r, i) {
13766
- var rScreen = (0, import_transformation_matrix7.applyToPoint)(transform, r);
13767
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_react15.Fragment, {
14623
+ var rScreen = (0, import_transformation_matrix8.applyToPoint)(transform, r);
14624
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_react17.Fragment, {
13768
14625
  children: [
13769
14626
  r.via && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("circle", {
13770
14627
  cx: rScreen.x,
@@ -13811,8 +14668,8 @@ var EditTraceHintOverlay = function(param) {
13811
14668
  }).map(function(e) {
13812
14669
  var route = e.route;
13813
14670
  var pcb_port2 = su_default(soup).pcb_port.get(e.pcb_port_id);
13814
- var pcb_port_screen = (0, import_transformation_matrix7.applyToPoint)(transform, pcb_port2);
13815
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_react15.Fragment, {
14671
+ var pcb_port_screen = (0, import_transformation_matrix8.applyToPoint)(transform, pcb_port2);
14672
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_react17.Fragment, {
13816
14673
  children: [
13817
14674
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("rect", {
13818
14675
  x: pcb_port_screen.x - 10,
@@ -13824,15 +14681,15 @@ var EditTraceHintOverlay = function(param) {
13824
14681
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("path", {
13825
14682
  stroke: "red",
13826
14683
  d: "M ".concat(pcb_port_screen.x, " ").concat(pcb_port_screen.y, " ").concat(route.map(function(r) {
13827
- return (0, import_transformation_matrix7.applyToPoint)(transform, r);
14684
+ return (0, import_transformation_matrix8.applyToPoint)(transform, r);
13828
14685
  }).map(function(r) {
13829
14686
  return "L ".concat(r.x, " ").concat(r.y);
13830
14687
  }).join(" "))
13831
14688
  }, "path-".concat(e.pcb_port_id)),
13832
14689
  route.map(function(r) {
13833
- return _object_spread({}, r, (0, import_transformation_matrix7.applyToPoint)(transform, r));
14690
+ return _object_spread({}, r, (0, import_transformation_matrix8.applyToPoint)(transform, r));
13834
14691
  }).map(function(r, i) {
13835
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_react15.Fragment, {
14692
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_react17.Fragment, {
13836
14693
  children: [
13837
14694
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("circle", {
13838
14695
  cx: r.x,
@@ -13876,7 +14733,7 @@ var EditTraceHintOverlay = function(param) {
13876
14733
  });
13877
14734
  };
13878
14735
  // src/components/RatsNestOverlay.tsx
13879
- var import_transformation_matrix8 = require("transformation-matrix");
14736
+ var import_transformation_matrix9 = require("transformation-matrix");
13880
14737
  var import_jsx_runtime12 = require("react/jsx-runtime");
13881
14738
  var RatsNestOverlay = function(param) {
13882
14739
  var transform = param.transform, soup = param.soup, children = param.children;
@@ -13884,7 +14741,7 @@ var RatsNestOverlay = function(param) {
13884
14741
  return s.is_showing_rats_nest;
13885
14742
  });
13886
14743
  if (!soup || !isShowingRatsNest) return children;
13887
- if (!transform) transform = (0, import_transformation_matrix8.identity)();
14744
+ if (!transform) transform = (0, import_transformation_matrix9.identity)();
13888
14745
  var sourceTraces = su_default(soup).source_trace.list();
13889
14746
  var groups = [];
13890
14747
  sourceTraces.forEach(function(sourceTrace) {
@@ -13918,7 +14775,7 @@ var RatsNestOverlay = function(param) {
13918
14775
  },
13919
14776
  children: groups.map(function(group, index) {
13920
14777
  var points = group.map(function(port) {
13921
- return (0, import_transformation_matrix8.applyToPoint)(transform, {
14778
+ return (0, import_transformation_matrix9.applyToPoint)(transform, {
13922
14779
  x: port.x,
13923
14780
  y: port.y
13924
14781
  });
@@ -13992,7 +14849,7 @@ function addInteractionMetadataToPrimitives(param) {
13992
14849
  var import_jsx_runtime13 = require("react/jsx-runtime");
13993
14850
  var CanvasElementsRenderer = function(props) {
13994
14851
  var transform = props.transform, elements = props.elements;
13995
- var _ref = _sliced_to_array((0, import_react17.useMemo)(function() {
14852
+ var _ref = _sliced_to_array((0, import_react19.useMemo)(function() {
13996
14853
  var primitivesWithoutInteractionMetadata2 = props.elements.flatMap(function(elm) {
13997
14854
  return convertElementToPrimitives(elm, props.elements);
13998
14855
  });
@@ -14004,7 +14861,7 @@ var CanvasElementsRenderer = function(props) {
14004
14861
  }, [
14005
14862
  props.elements
14006
14863
  ]), 2), primitivesWithoutInteractionMetadata = _ref[0], connectivityMap = _ref[1];
14007
- var _ref1 = _sliced_to_array((0, import_react16.useState)(primitivesWithoutInteractionMetadata), 2), primitives = _ref1[0], setPrimitives = _ref1[1];
14864
+ var _ref1 = _sliced_to_array((0, import_react18.useState)(primitivesWithoutInteractionMetadata), 2), primitives = _ref1[0], setPrimitives = _ref1[1];
14008
14865
  return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(MouseElementTracker, {
14009
14866
  transform: transform,
14010
14867
  primitives: primitivesWithoutInteractionMetadata,
@@ -14085,153 +14942,21 @@ var CanvasElementsRenderer = function(props) {
14085
14942
  });
14086
14943
  };
14087
14944
  // src/PCBViewer.tsx
14088
- var import_use_mouse_matrix_transform = __toESM(require_dist());
14089
- // node_modules/react-use/esm/misc/util.js
14090
- var noop = function noop() {};
14091
- var isBrowser = typeof window !== "undefined";
14092
- // node_modules/react-use/esm/useIsomorphicLayoutEffect.js
14093
- var import_react18 = require("react");
14094
- var useIsomorphicLayoutEffect = isBrowser ? import_react18.useLayoutEffect : import_react18.useEffect;
14095
- var useIsomorphicLayoutEffect_default = useIsomorphicLayoutEffect;
14096
- // node_modules/react-use/esm/useMeasure.js
14097
- var import_react19 = require("react");
14098
- var defaultState = {
14099
- x: 0,
14100
- y: 0,
14101
- width: 0,
14102
- height: 0,
14103
- top: 0,
14104
- left: 0,
14105
- bottom: 0,
14106
- right: 0
14107
- };
14108
- function useMeasure() {
14109
- var _a = (0, import_react19.useState)(null), element = _a[0], ref = _a[1];
14110
- var _b = (0, import_react19.useState)(defaultState), rect = _b[0], setRect = _b[1];
14111
- var observer = (0, import_react19.useMemo)(function() {
14112
- return new window.ResizeObserver(function(entries) {
14113
- if (entries[0]) {
14114
- 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;
14115
- setRect({
14116
- x: x,
14117
- y: y,
14118
- width: width,
14119
- height: height,
14120
- top: top_1,
14121
- left: left,
14122
- bottom: bottom,
14123
- right: right
14124
- });
14125
- }
14126
- });
14127
- }, []);
14128
- useIsomorphicLayoutEffect_default(function() {
14129
- if (!element) return;
14130
- observer.observe(element);
14131
- return function() {
14132
- observer.disconnect();
14133
- };
14134
- }, [
14135
- element
14136
- ]);
14137
- return [
14138
- ref,
14139
- rect
14140
- ];
14141
- }
14142
- var useMeasure_default = isBrowser && typeof window.ResizeObserver !== "undefined" ? useMeasure : function useMeasure_default() {
14143
- return [
14144
- noop,
14145
- defaultState
14146
- ];
14147
- };
14148
- // src/PCBViewer.tsx
14149
- var import_transformation_matrix10 = require("transformation-matrix");
14150
- // src/lib/apply-edit-events.ts
14151
- var import_transformation_matrix9 = require("transformation-matrix");
14152
- // src/lib/apply-edit-events/apply-edit-trace-hint-event.ts
14153
- var applyTraceHintEditEvent = function(soup, edit_event) {
14154
- var existing_trace_hint = soup.find(function(th) {
14155
- return th.type === "pcb_trace_hint" && th.pcb_trace_hint_id === edit_event.pcb_trace_hint_id;
14156
- });
14157
- if (existing_trace_hint) {
14158
- soup = soup.map(function(e) {
14159
- return e.pcb_trace_hint_id === edit_event.pcb_trace_hint_id ? _object_spread_props(_object_spread({}, e), {
14160
- route: edit_event.route
14161
- }) : e;
14162
- });
14163
- } else {
14164
- var pcb_port2 = su_default(soup).pcb_port.get(edit_event.pcb_port_id);
14165
- soup = soup.filter(function(e) {
14166
- return !(e.type === "pcb_trace_hint" && e.pcb_port_id === edit_event.pcb_port_id);
14167
- }).concat([
14168
- {
14169
- type: "pcb_trace_hint",
14170
- pcb_trace_hint_id: edit_event.pcb_trace_hint_id,
14171
- route: edit_event.route,
14172
- pcb_port_id: edit_event.pcb_port_id,
14173
- pcb_component_id: pcb_port2 === null || pcb_port2 === void 0 ? void 0 : pcb_port2.pcb_component_id
14174
- }
14175
- ]);
14176
- }
14177
- return soup;
14178
- };
14179
- // src/lib/apply-edit-events.ts
14180
- var applyEditEvents = function(soup, edit_events) {
14181
- soup = JSON.parse(JSON.stringify(soup));
14182
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
14183
- try {
14184
- var _loop = function() {
14185
- var edit_event = _step.value;
14186
- if (edit_event.pcb_edit_event_type === "edit_component_location") {
14187
- var mat = (0, import_transformation_matrix9.translate)(edit_event.new_center.x - edit_event.original_center.x, edit_event.new_center.y - edit_event.original_center.y);
14188
- soup = soup.map(function(e) {
14189
- return e.pcb_component_id !== edit_event.pcb_component_id ? e : transformPCBElement(e, mat);
14190
- });
14191
- } else if (edit_event.pcb_edit_event_type === "edit_trace_hint") {
14192
- soup = applyTraceHintEditEvent(soup, edit_event);
14193
- }
14194
- };
14195
- for(var _iterator = edit_events[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
14196
- } catch (err) {
14197
- _didIteratorError = true;
14198
- _iteratorError = err;
14199
- } finally{
14200
- try {
14201
- if (!_iteratorNormalCompletion && _iterator.return != null) {
14202
- _iterator.return();
14203
- }
14204
- } finally{
14205
- if (_didIteratorError) {
14206
- throw _iteratorError;
14207
- }
14208
- }
14209
- }
14210
- return soup;
14211
- };
14212
- // src/PCBViewer.tsx
14213
- var import_core = require("@tscircuit/core");
14214
14945
  var import_jsx_runtime14 = require("react/jsx-runtime");
14215
14946
  var defaultTransform = (0, import_transformation_matrix10.compose)((0, import_transformation_matrix10.translate)(400, 300), (0, import_transformation_matrix10.scale)(40, -40));
14216
14947
  var PCBViewer = function(param) {
14217
14948
  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;
14218
- var _ref = (0, import_core.useRenderedCircuit)(children), circuitJsonFromChildren = _ref.circuitJson, errorFromChildren = _ref.error;
14219
- var _ref1;
14220
- var stateElements = (_ref1 = circuitJsonFromChildren !== null && circuitJsonFromChildren !== void 0 ? circuitJsonFromChildren : soup) !== null && _ref1 !== void 0 ? _ref1 : [];
14949
+ var _ref = (0, import_core.useRenderedCircuit)(children), circuitJsonFromChildren = _ref.circuitJson, errorFromChildren = _ref.error, isLoading = _ref.isLoading;
14221
14950
  var _useMeasure_default = _sliced_to_array(useMeasure_default(), 2), ref = _useMeasure_default[0], refDimensions = _useMeasure_default[1];
14222
- var _ref2 = _sliced_to_array((0, import_react20.useState)(defaultTransform), 2), transform = _ref2[0], setTransformInternal = _ref2[1];
14223
- var _ref3 = (0, import_use_mouse_matrix_transform.default)({
14951
+ var _ref1 = _sliced_to_array((0, import_react20.useState)(defaultTransform), 2), transform = _ref1[0], setTransformInternal = _ref1[1];
14952
+ var _ref2 = (0, import_use_mouse_matrix_transform.default)({
14224
14953
  transform: transform,
14225
14954
  onSetTransform: setTransformInternal
14226
- }), transformRef = _ref3.ref, setTransform = _ref3.setTransform, cancelPanDrag = _ref3.cancelDrag;
14227
- var _ref4 = _sliced_to_array((0, import_react20.useState)([]), 2), editEvents = _ref4[0], setEditEvents = _ref4[1];
14955
+ }), transformRef = _ref2.ref, setTransform = _ref2.setTransform, cancelPanDrag = _ref2.cancelDrag;
14956
+ var _ref3 = _sliced_to_array((0, import_react20.useState)([]), 2), editEvents = _ref3[0], setEditEvents = _ref3[1];
14228
14957
  editEvents = editEventsProp !== null && editEventsProp !== void 0 ? editEventsProp : editEvents;
14229
- var _ref5 = _sliced_to_array((0, import_react20.useState)(null), 2), error = _ref5[0], setError = _ref5[1];
14230
- (0, import_react20.useEffect)(function() {
14231
- setError(errorFromChildren ? errorFromChildren.toString() : null);
14232
- }, [
14233
- errorFromChildren
14234
- ]);
14958
+ var _ref4;
14959
+ var stateElements = (_ref4 = circuitJsonFromChildren !== null && circuitJsonFromChildren !== void 0 ? circuitJsonFromChildren : soup) !== null && _ref4 !== void 0 ? _ref4 : [];
14235
14960
  var resetTransform = function() {
14236
14961
  var elmBounds = (refDimensions === null || refDimensions === void 0 ? void 0 : refDimensions.width) > 0 ? refDimensions : {
14237
14962
  width: 500,
@@ -14239,25 +14964,20 @@ var PCBViewer = function(param) {
14239
14964
  };
14240
14965
  var _ref = elements.some(function(e) {
14241
14966
  return e.type.startsWith("pcb_");
14242
- }) ? getBoundsOfPcbElements(elements.filter(function(e) {
14967
+ }) ? findBoundsAndCenter(elements.filter(function(e) {
14243
14968
  return e.type.startsWith("pcb_");
14244
14969
  })) : {
14245
- minX: -1e-3,
14246
- minY: -1e-3,
14247
- maxX: 1e-3,
14248
- maxY: 1e-3
14249
- }, minX = _ref.minX, minY = _ref.minY, maxX = _ref.maxX, maxY = _ref.maxY;
14250
- var width = maxX - minX;
14251
- var height2 = maxY - minY;
14252
- var center = {
14253
- x: (minX + maxX) / 2,
14254
- y: (minY + maxY) / 2
14255
- };
14970
+ center: {
14971
+ x: 0,
14972
+ y: 0
14973
+ },
14974
+ width: 1e-3,
14975
+ height: 1e-3
14976
+ }, center = _ref.center, width = _ref.width, height2 = _ref.height;
14256
14977
  var _elmBounds_width, _elmBounds_height;
14257
14978
  var scaleFactor = Math.min(((_elmBounds_width = elmBounds.width) !== null && _elmBounds_width !== void 0 ? _elmBounds_width : 0) / width, ((_elmBounds_height = elmBounds.height) !== null && _elmBounds_height !== void 0 ? _elmBounds_height : 0) / height2, 100) * 0.75;
14258
14979
  var _elmBounds_width1, _elmBounds_height1;
14259
- setTransform((0, import_transformation_matrix10.compose)((0, import_transformation_matrix10.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),
14260
- (0, import_transformation_matrix10.scale)(scaleFactor, -scaleFactor, 0, 0), (0, import_transformation_matrix10.translate)(-center.x, -center.y)));
14980
+ setTransform((0, import_transformation_matrix10.compose)((0, import_transformation_matrix10.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), (0, import_transformation_matrix10.scale)(scaleFactor, -scaleFactor, 0, 0), (0, import_transformation_matrix10.translate)(-center.x, -center.y)));
14261
14981
  };
14262
14982
  (0, import_react20.useEffect)(function() {
14263
14983
  if (refDimensions && refDimensions.width !== 0 && (children || soup)) {
@@ -14267,16 +14987,6 @@ var PCBViewer = function(param) {
14267
14987
  children,
14268
14988
  refDimensions
14269
14989
  ]);
14270
- if (error) return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", {
14271
- style: {
14272
- color: "red"
14273
- },
14274
- children: [
14275
- " ",
14276
- error,
14277
- " "
14278
- ]
14279
- });
14280
14990
  var pcbElmsPreEdit = (soup !== null && soup !== void 0 ? soup : stateElements).filter(function(e) {
14281
14991
  return e.type.startsWith("pcb_") || e.type.startsWith("source_");
14282
14992
  });