@tscircuit/pcb-viewer 1.11.9 → 1.11.11
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 +279 -349
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,211 +1,8 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
-
}) : x)(function(x) {
|
|
10
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
11
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
|
-
});
|
|
13
|
-
var __commonJS = (cb, mod) => function __require2() {
|
|
14
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
15
|
-
};
|
|
16
2
|
var __export = (target, all) => {
|
|
17
3
|
for (var name in all)
|
|
18
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
5
|
};
|
|
20
|
-
var __copyProps = (to, from, except, desc) => {
|
|
21
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
-
for (let key of __getOwnPropNames(from))
|
|
23
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
-
}
|
|
26
|
-
return to;
|
|
27
|
-
};
|
|
28
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
-
mod
|
|
35
|
-
));
|
|
36
|
-
|
|
37
|
-
// node_modules/use-mouse-matrix-transform/dist/index.js
|
|
38
|
-
var require_dist = __commonJS({
|
|
39
|
-
"node_modules/use-mouse-matrix-transform/dist/index.js"(exports, module) {
|
|
40
|
-
"use strict";
|
|
41
|
-
var __defProp2 = Object.defineProperty;
|
|
42
|
-
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
43
|
-
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
44
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
45
|
-
var __export2 = (target, all) => {
|
|
46
|
-
for (var name in all)
|
|
47
|
-
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
48
|
-
};
|
|
49
|
-
var __copyProps2 = (to, from, except, desc) => {
|
|
50
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
51
|
-
for (let key of __getOwnPropNames2(from))
|
|
52
|
-
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
53
|
-
__defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
|
54
|
-
}
|
|
55
|
-
return to;
|
|
56
|
-
};
|
|
57
|
-
var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
|
|
58
|
-
var src_exports = {};
|
|
59
|
-
__export2(src_exports, {
|
|
60
|
-
default: () => src_default,
|
|
61
|
-
useMouseMatrixTransform: () => useMouseMatrixTransform2
|
|
62
|
-
});
|
|
63
|
-
module.exports = __toCommonJS(src_exports);
|
|
64
|
-
var import_transformation_matrix12 = __require("transformation-matrix");
|
|
65
|
-
var import_react22 = __require("react");
|
|
66
|
-
var useMouseMatrixTransform2 = (props = {}) => {
|
|
67
|
-
const extRef = (0, import_react22.useRef)(null);
|
|
68
|
-
const [lastDragCancelTime, setLastDragCancelTime] = (0, import_react22.useState)(0);
|
|
69
|
-
const outerCanvasElm = props.canvasElm ?? extRef.current;
|
|
70
|
-
const [internalTransform, setInternalTransform] = (0, import_react22.useState)(
|
|
71
|
-
props.initialTransform ?? (0, import_transformation_matrix12.identity)()
|
|
72
|
-
);
|
|
73
|
-
const [waitCounter, setWaitCounter] = (0, import_react22.useState)(0);
|
|
74
|
-
const [extChangeCounter, incExtChangeCounter] = (0, import_react22.useReducer)((s) => s + 1, 0);
|
|
75
|
-
const setTransform = (0, import_react22.useCallback)(
|
|
76
|
-
(newTransform) => {
|
|
77
|
-
if (props.onSetTransform) {
|
|
78
|
-
props.onSetTransform(newTransform);
|
|
79
|
-
}
|
|
80
|
-
if (!props.transform) {
|
|
81
|
-
setInternalTransform(newTransform);
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
[props.onSetTransform, setInternalTransform]
|
|
85
|
-
);
|
|
86
|
-
const setTransformExt = (0, import_react22.useCallback)(
|
|
87
|
-
(newTransform) => {
|
|
88
|
-
setTransform(newTransform);
|
|
89
|
-
incExtChangeCounter();
|
|
90
|
-
},
|
|
91
|
-
[setTransform]
|
|
92
|
-
);
|
|
93
|
-
const transform = props.transform ?? internalTransform;
|
|
94
|
-
const cancelDrag = (0, import_react22.useCallback)(() => {
|
|
95
|
-
setLastDragCancelTime(Date.now());
|
|
96
|
-
}, []);
|
|
97
|
-
(0, import_react22.useEffect)(() => {
|
|
98
|
-
const canvasElm = props.canvasElm ?? extRef.current;
|
|
99
|
-
if (canvasElm && !outerCanvasElm) {
|
|
100
|
-
setWaitCounter(waitCounter + 1);
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
if (!canvasElm) {
|
|
104
|
-
const timeout = setTimeout(() => {
|
|
105
|
-
setWaitCounter(waitCounter + 1);
|
|
106
|
-
}, 100);
|
|
107
|
-
return () => clearTimeout(timeout);
|
|
108
|
-
}
|
|
109
|
-
let init_tf = props.transform ?? internalTransform;
|
|
110
|
-
let m0 = { x: 0, y: 0 }, m1 = { x: 0, y: 0 }, md = false, mlastrel = { x: 0, y: 0 };
|
|
111
|
-
const getMousePos = (e) => {
|
|
112
|
-
return {
|
|
113
|
-
x: e.pageX - canvasElm.getBoundingClientRect().left - window.scrollX,
|
|
114
|
-
y: e.pageY - canvasElm.getBoundingClientRect().top - window.scrollY
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
function handleMouseDown(e) {
|
|
118
|
-
if (props.enabled === false)
|
|
119
|
-
return;
|
|
120
|
-
if (props.shouldDrag && !props.shouldDrag(e))
|
|
121
|
-
return;
|
|
122
|
-
m0 = getMousePos(e);
|
|
123
|
-
if (Date.now() - lastDragCancelTime < 100)
|
|
124
|
-
return;
|
|
125
|
-
md = true;
|
|
126
|
-
e.preventDefault();
|
|
127
|
-
}
|
|
128
|
-
function handleMouseUp(e) {
|
|
129
|
-
if (!md || props.enabled === false)
|
|
130
|
-
return;
|
|
131
|
-
if (props.shouldDrag && !props.shouldDrag(e))
|
|
132
|
-
return;
|
|
133
|
-
m1 = getMousePos(e);
|
|
134
|
-
const new_tf = (0, import_transformation_matrix12.compose)((0, import_transformation_matrix12.translate)(m1.x - m0.x, m1.y - m0.y), init_tf);
|
|
135
|
-
setTransform(new_tf);
|
|
136
|
-
init_tf = new_tf;
|
|
137
|
-
md = false;
|
|
138
|
-
}
|
|
139
|
-
function handleMouseMove(e) {
|
|
140
|
-
mlastrel = getMousePos(e);
|
|
141
|
-
if (!md || props.enabled === false)
|
|
142
|
-
return;
|
|
143
|
-
if (props.shouldDrag && !props.shouldDrag(e))
|
|
144
|
-
return;
|
|
145
|
-
m1 = getMousePos(e);
|
|
146
|
-
setTransform((0, import_transformation_matrix12.compose)((0, import_transformation_matrix12.translate)(m1.x - m0.x, m1.y - m0.y), init_tf));
|
|
147
|
-
}
|
|
148
|
-
function handleMouseWheel(e) {
|
|
149
|
-
if (props.enabled === false)
|
|
150
|
-
return;
|
|
151
|
-
if (props.shouldDrag && !props.shouldDrag(e))
|
|
152
|
-
return;
|
|
153
|
-
const center = getMousePos(e);
|
|
154
|
-
const new_tf = (0, import_transformation_matrix12.compose)(
|
|
155
|
-
(0, import_transformation_matrix12.translate)(center.x, center.y),
|
|
156
|
-
(0, import_transformation_matrix12.scale)(1 - e.deltaY / 1e3, 1 - e.deltaY / 1e3),
|
|
157
|
-
(0, import_transformation_matrix12.translate)(-center.x, -center.y),
|
|
158
|
-
init_tf
|
|
159
|
-
);
|
|
160
|
-
setTransform(new_tf);
|
|
161
|
-
init_tf = new_tf;
|
|
162
|
-
e.preventDefault();
|
|
163
|
-
}
|
|
164
|
-
function handleMouseOut(e) {
|
|
165
|
-
if (!md)
|
|
166
|
-
return;
|
|
167
|
-
if (props.shouldDrag && !props.shouldDrag(e))
|
|
168
|
-
return;
|
|
169
|
-
if (canvasElm) {
|
|
170
|
-
const boundingBox = canvasElm.getBoundingClientRect();
|
|
171
|
-
if (e.clientX >= boundingBox.left + 10 && e.clientX <= boundingBox.right - 10 && e.clientY >= boundingBox.top + 10 && e.clientY <= boundingBox.bottom - 10) {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
md = false;
|
|
176
|
-
m1 = getMousePos(e);
|
|
177
|
-
const new_tf = (0, import_transformation_matrix12.compose)((0, import_transformation_matrix12.translate)(m1.x - m0.x, m1.y - m0.y), init_tf);
|
|
178
|
-
setTransform(new_tf);
|
|
179
|
-
init_tf = new_tf;
|
|
180
|
-
}
|
|
181
|
-
canvasElm.addEventListener("mousedown", handleMouseDown);
|
|
182
|
-
canvasElm.addEventListener("mouseup", handleMouseUp);
|
|
183
|
-
window.addEventListener("mousemove", handleMouseMove);
|
|
184
|
-
canvasElm.addEventListener("mouseout", handleMouseOut);
|
|
185
|
-
canvasElm.addEventListener("wheel", handleMouseWheel);
|
|
186
|
-
return () => {
|
|
187
|
-
canvasElm.removeEventListener("mousedown", handleMouseDown);
|
|
188
|
-
canvasElm.removeEventListener("mouseup", handleMouseUp);
|
|
189
|
-
window.removeEventListener("mousemove", handleMouseMove);
|
|
190
|
-
canvasElm.removeEventListener("mouseout", handleMouseOut);
|
|
191
|
-
canvasElm.removeEventListener("wheel", handleMouseWheel);
|
|
192
|
-
};
|
|
193
|
-
}, [outerCanvasElm, waitCounter, extChangeCounter, lastDragCancelTime, props.enabled, props.shouldDrag]);
|
|
194
|
-
const applyTransformToPoint = (0, import_react22.useCallback)(
|
|
195
|
-
(obj) => (0, import_transformation_matrix12.applyToPoint)(transform, obj),
|
|
196
|
-
[transform]
|
|
197
|
-
);
|
|
198
|
-
return {
|
|
199
|
-
ref: extRef,
|
|
200
|
-
transform,
|
|
201
|
-
applyTransformToPoint,
|
|
202
|
-
setTransform: setTransformExt,
|
|
203
|
-
cancelDrag
|
|
204
|
-
};
|
|
205
|
-
};
|
|
206
|
-
var src_default = useMouseMatrixTransform2;
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
6
|
|
|
210
7
|
// src/PCBViewer.tsx
|
|
211
8
|
import { useRenderedCircuit } from "@tscircuit/core";
|
|
@@ -683,7 +480,7 @@ var makeIssue = (params) => {
|
|
|
683
480
|
};
|
|
684
481
|
}
|
|
685
482
|
let errorMessage = "";
|
|
686
|
-
const maps = errorMaps.filter((
|
|
483
|
+
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
|
687
484
|
for (const map of maps) {
|
|
688
485
|
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
|
|
689
486
|
}
|
|
@@ -4360,35 +4157,18 @@ var z = /* @__PURE__ */ Object.freeze({
|
|
|
4360
4157
|
ZodError
|
|
4361
4158
|
});
|
|
4362
4159
|
|
|
4363
|
-
// node_modules/nanoid/index.js
|
|
4364
|
-
import { webcrypto as crypto } from "node:crypto";
|
|
4365
|
-
|
|
4366
4160
|
// node_modules/nanoid/url-alphabet/index.js
|
|
4367
4161
|
var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
4368
4162
|
|
|
4369
|
-
// node_modules/nanoid/index.js
|
|
4370
|
-
var
|
|
4371
|
-
var pool;
|
|
4372
|
-
var poolOffset;
|
|
4373
|
-
function fillPool(bytes) {
|
|
4374
|
-
if (!pool || pool.length < bytes) {
|
|
4375
|
-
pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
|
|
4376
|
-
crypto.getRandomValues(pool);
|
|
4377
|
-
poolOffset = 0;
|
|
4378
|
-
} else if (poolOffset + bytes > pool.length) {
|
|
4379
|
-
crypto.getRandomValues(pool);
|
|
4380
|
-
poolOffset = 0;
|
|
4381
|
-
}
|
|
4382
|
-
poolOffset += bytes;
|
|
4383
|
-
}
|
|
4384
|
-
function nanoid(size2 = 21) {
|
|
4385
|
-
fillPool(size2 |= 0);
|
|
4163
|
+
// node_modules/nanoid/index.browser.js
|
|
4164
|
+
var nanoid = (size2 = 21) => {
|
|
4386
4165
|
let id = "";
|
|
4387
|
-
|
|
4388
|
-
|
|
4166
|
+
let bytes = crypto.getRandomValues(new Uint8Array(size2 |= 0));
|
|
4167
|
+
while (size2--) {
|
|
4168
|
+
id += urlAlphabet[bytes[size2] & 63];
|
|
4389
4169
|
}
|
|
4390
4170
|
return id;
|
|
4391
|
-
}
|
|
4171
|
+
};
|
|
4392
4172
|
|
|
4393
4173
|
// node_modules/circuit-json/dist/index.mjs
|
|
4394
4174
|
var unitMappings = {
|
|
@@ -5633,7 +5413,7 @@ var su = (soup, options = {}) => {
|
|
|
5633
5413
|
},
|
|
5634
5414
|
update: (id, newProps) => {
|
|
5635
5415
|
const elm = soup.find(
|
|
5636
|
-
(e) => e[`${component_type}_id`] === id
|
|
5416
|
+
(e) => e.type === component_type && e[`${component_type}_id`] === id
|
|
5637
5417
|
);
|
|
5638
5418
|
if (!elm)
|
|
5639
5419
|
return;
|
|
@@ -6028,7 +5808,7 @@ var ToastContainer = () => {
|
|
|
6028
5808
|
};
|
|
6029
5809
|
|
|
6030
5810
|
// src/PCBViewer.tsx
|
|
6031
|
-
import { useEffect as
|
|
5811
|
+
import { useEffect as useEffect12, useMemo as useMemo6, useState as useState10 } from "react";
|
|
6032
5812
|
|
|
6033
5813
|
// node_modules/react-use/esm/misc/util.js
|
|
6034
5814
|
var noop = function() {
|
|
@@ -6078,23 +5858,173 @@ var useMeasure_default = isBrowser && typeof window.ResizeObserver !== "undefine
|
|
|
6078
5858
|
};
|
|
6079
5859
|
|
|
6080
5860
|
// src/PCBViewer.tsx
|
|
6081
|
-
|
|
6082
|
-
|
|
5861
|
+
import { compose as compose4, scale as scale2, translate as translate5 } from "transformation-matrix";
|
|
5862
|
+
|
|
5863
|
+
// node_modules/use-mouse-matrix-transform/dist/chunk-5TGSLHOO.js
|
|
5864
|
+
import {
|
|
5865
|
+
identity,
|
|
5866
|
+
scale,
|
|
5867
|
+
translate as translate2,
|
|
5868
|
+
compose,
|
|
5869
|
+
applyToPoint as applyToPoint2
|
|
5870
|
+
} from "transformation-matrix";
|
|
5871
|
+
import { useCallback, useEffect as useEffect3, useReducer, useRef, useState as useState2 } from "react";
|
|
5872
|
+
var useMouseMatrixTransform = (props = {}) => {
|
|
5873
|
+
const extRef = useRef(null);
|
|
5874
|
+
const [lastDragCancelTime, setLastDragCancelTime] = useState2(0);
|
|
5875
|
+
const outerCanvasElm = props.canvasElm ?? extRef.current;
|
|
5876
|
+
const [internalTransform, setInternalTransform] = useState2(
|
|
5877
|
+
props.initialTransform ?? identity()
|
|
5878
|
+
);
|
|
5879
|
+
const [waitCounter, setWaitCounter] = useState2(0);
|
|
5880
|
+
const [extChangeCounter, incExtChangeCounter] = useReducer((s) => s + 1, 0);
|
|
5881
|
+
const setTransform = useCallback(
|
|
5882
|
+
(newTransform) => {
|
|
5883
|
+
if (props.onSetTransform) {
|
|
5884
|
+
props.onSetTransform(newTransform);
|
|
5885
|
+
}
|
|
5886
|
+
if (!props.transform) {
|
|
5887
|
+
setInternalTransform(newTransform);
|
|
5888
|
+
}
|
|
5889
|
+
},
|
|
5890
|
+
[props.onSetTransform, setInternalTransform]
|
|
5891
|
+
);
|
|
5892
|
+
const setTransformExt = useCallback(
|
|
5893
|
+
(newTransform) => {
|
|
5894
|
+
setTransform(newTransform);
|
|
5895
|
+
incExtChangeCounter();
|
|
5896
|
+
},
|
|
5897
|
+
[setTransform]
|
|
5898
|
+
);
|
|
5899
|
+
const transform = props.transform ?? internalTransform;
|
|
5900
|
+
const cancelDrag = useCallback(() => {
|
|
5901
|
+
setLastDragCancelTime(Date.now());
|
|
5902
|
+
}, []);
|
|
5903
|
+
useEffect3(() => {
|
|
5904
|
+
const canvasElm = props.canvasElm ?? extRef.current;
|
|
5905
|
+
if (canvasElm && !outerCanvasElm) {
|
|
5906
|
+
setWaitCounter(waitCounter + 1);
|
|
5907
|
+
return;
|
|
5908
|
+
}
|
|
5909
|
+
if (!canvasElm) {
|
|
5910
|
+
const timeout = setTimeout(() => {
|
|
5911
|
+
setWaitCounter(waitCounter + 1);
|
|
5912
|
+
}, 100);
|
|
5913
|
+
return () => clearTimeout(timeout);
|
|
5914
|
+
}
|
|
5915
|
+
let init_tf = props.transform ?? internalTransform;
|
|
5916
|
+
let m0 = { x: 0, y: 0 }, m1 = { x: 0, y: 0 }, md = false, mlastrel = { x: 0, y: 0 };
|
|
5917
|
+
const getMousePos = (e) => {
|
|
5918
|
+
return {
|
|
5919
|
+
x: e.pageX - canvasElm.getBoundingClientRect().left - window.scrollX,
|
|
5920
|
+
y: e.pageY - canvasElm.getBoundingClientRect().top - window.scrollY
|
|
5921
|
+
};
|
|
5922
|
+
};
|
|
5923
|
+
function handleMouseDown(e) {
|
|
5924
|
+
if (props.enabled === false)
|
|
5925
|
+
return;
|
|
5926
|
+
if (props.shouldDrag && !props.shouldDrag(e))
|
|
5927
|
+
return;
|
|
5928
|
+
m0 = getMousePos(e);
|
|
5929
|
+
if (Date.now() - lastDragCancelTime < 100)
|
|
5930
|
+
return;
|
|
5931
|
+
md = true;
|
|
5932
|
+
e.preventDefault();
|
|
5933
|
+
}
|
|
5934
|
+
function handleMouseUp(e) {
|
|
5935
|
+
if (!md || props.enabled === false)
|
|
5936
|
+
return;
|
|
5937
|
+
if (props.shouldDrag && !props.shouldDrag(e))
|
|
5938
|
+
return;
|
|
5939
|
+
m1 = getMousePos(e);
|
|
5940
|
+
const new_tf = compose(translate2(m1.x - m0.x, m1.y - m0.y), init_tf);
|
|
5941
|
+
setTransform(new_tf);
|
|
5942
|
+
init_tf = new_tf;
|
|
5943
|
+
md = false;
|
|
5944
|
+
}
|
|
5945
|
+
function handleMouseMove(e) {
|
|
5946
|
+
mlastrel = getMousePos(e);
|
|
5947
|
+
if (!md || props.enabled === false)
|
|
5948
|
+
return;
|
|
5949
|
+
if (props.shouldDrag && !props.shouldDrag(e))
|
|
5950
|
+
return;
|
|
5951
|
+
m1 = getMousePos(e);
|
|
5952
|
+
setTransform(compose(translate2(m1.x - m0.x, m1.y - m0.y), init_tf));
|
|
5953
|
+
}
|
|
5954
|
+
function handleMouseWheel(e) {
|
|
5955
|
+
if (props.enabled === false)
|
|
5956
|
+
return;
|
|
5957
|
+
if (props.shouldDrag && !props.shouldDrag(e))
|
|
5958
|
+
return;
|
|
5959
|
+
const center = getMousePos(e);
|
|
5960
|
+
const new_tf = compose(
|
|
5961
|
+
translate2(center.x, center.y),
|
|
5962
|
+
scale(1 - e.deltaY / 1e3, 1 - e.deltaY / 1e3),
|
|
5963
|
+
translate2(-center.x, -center.y),
|
|
5964
|
+
init_tf
|
|
5965
|
+
);
|
|
5966
|
+
setTransform(new_tf);
|
|
5967
|
+
init_tf = new_tf;
|
|
5968
|
+
e.preventDefault();
|
|
5969
|
+
}
|
|
5970
|
+
function handleMouseOut(e) {
|
|
5971
|
+
if (!md)
|
|
5972
|
+
return;
|
|
5973
|
+
if (props.shouldDrag && !props.shouldDrag(e))
|
|
5974
|
+
return;
|
|
5975
|
+
if (canvasElm) {
|
|
5976
|
+
const boundingBox = canvasElm.getBoundingClientRect();
|
|
5977
|
+
if (e.clientX >= boundingBox.left + 10 && e.clientX <= boundingBox.right - 10 && e.clientY >= boundingBox.top + 10 && e.clientY <= boundingBox.bottom - 10) {
|
|
5978
|
+
return;
|
|
5979
|
+
}
|
|
5980
|
+
}
|
|
5981
|
+
md = false;
|
|
5982
|
+
m1 = getMousePos(e);
|
|
5983
|
+
const new_tf = compose(translate2(m1.x - m0.x, m1.y - m0.y), init_tf);
|
|
5984
|
+
setTransform(new_tf);
|
|
5985
|
+
init_tf = new_tf;
|
|
5986
|
+
}
|
|
5987
|
+
canvasElm.addEventListener("mousedown", handleMouseDown);
|
|
5988
|
+
canvasElm.addEventListener("mouseup", handleMouseUp);
|
|
5989
|
+
window.addEventListener("mousemove", handleMouseMove);
|
|
5990
|
+
canvasElm.addEventListener("mouseout", handleMouseOut);
|
|
5991
|
+
canvasElm.addEventListener("wheel", handleMouseWheel);
|
|
5992
|
+
return () => {
|
|
5993
|
+
canvasElm.removeEventListener("mousedown", handleMouseDown);
|
|
5994
|
+
canvasElm.removeEventListener("mouseup", handleMouseUp);
|
|
5995
|
+
window.removeEventListener("mousemove", handleMouseMove);
|
|
5996
|
+
canvasElm.removeEventListener("mouseout", handleMouseOut);
|
|
5997
|
+
canvasElm.removeEventListener("wheel", handleMouseWheel);
|
|
5998
|
+
};
|
|
5999
|
+
}, [outerCanvasElm, waitCounter, extChangeCounter, lastDragCancelTime, props.enabled, props.shouldDrag]);
|
|
6000
|
+
const applyTransformToPoint = useCallback(
|
|
6001
|
+
(obj) => applyToPoint2(transform, obj),
|
|
6002
|
+
[transform]
|
|
6003
|
+
);
|
|
6004
|
+
return {
|
|
6005
|
+
ref: extRef,
|
|
6006
|
+
transform,
|
|
6007
|
+
applyTransformToPoint,
|
|
6008
|
+
setTransform: setTransformExt,
|
|
6009
|
+
cancelDrag
|
|
6010
|
+
};
|
|
6011
|
+
};
|
|
6012
|
+
var src_default = useMouseMatrixTransform;
|
|
6083
6013
|
|
|
6084
6014
|
// src/components/CanvasElementsRenderer.tsx
|
|
6085
|
-
import { useState as
|
|
6015
|
+
import { useState as useState9 } from "react";
|
|
6086
6016
|
|
|
6087
6017
|
// src/components/CanvasPrimitiveRenderer.tsx
|
|
6088
6018
|
import { SuperGrid, toMMSI } from "react-supergrid";
|
|
6089
|
-
import { useEffect as
|
|
6019
|
+
import { useEffect as useEffect4, useRef as useRef2 } from "react";
|
|
6090
6020
|
|
|
6091
6021
|
// src/lib/Drawer.ts
|
|
6092
6022
|
import {
|
|
6093
|
-
applyToPoint as
|
|
6094
|
-
compose,
|
|
6095
|
-
identity,
|
|
6023
|
+
applyToPoint as applyToPoint3,
|
|
6024
|
+
compose as compose2,
|
|
6025
|
+
identity as identity2,
|
|
6096
6026
|
inverse,
|
|
6097
|
-
translate as
|
|
6027
|
+
translate as translate3
|
|
6098
6028
|
} from "transformation-matrix";
|
|
6099
6029
|
|
|
6100
6030
|
// src/lib/colors.ts
|
|
@@ -6403,9 +6333,9 @@ var Drawer = class {
|
|
|
6403
6333
|
canvas.getContext("2d")
|
|
6404
6334
|
])
|
|
6405
6335
|
);
|
|
6406
|
-
this.transform =
|
|
6336
|
+
this.transform = identity2();
|
|
6407
6337
|
this.transform.d *= -1;
|
|
6408
|
-
this.transform =
|
|
6338
|
+
this.transform = compose2(this.transform, translate3(0, -500));
|
|
6409
6339
|
this.lastPoint = { x: 0, y: 0 };
|
|
6410
6340
|
this.equip({});
|
|
6411
6341
|
}
|
|
@@ -6428,8 +6358,8 @@ var Drawer = class {
|
|
|
6428
6358
|
}
|
|
6429
6359
|
drawMeshPattern(x, y, width, height, spacing, angle = 45) {
|
|
6430
6360
|
const ctx = this.getLayerCtx();
|
|
6431
|
-
const [x1, y1] =
|
|
6432
|
-
const [x2, y2] =
|
|
6361
|
+
const [x1, y1] = applyToPoint3(this.transform, [x, y]);
|
|
6362
|
+
const [x2, y2] = applyToPoint3(this.transform, [x + width, y + height]);
|
|
6433
6363
|
const spacing$ = scaleOnly(this.transform, spacing);
|
|
6434
6364
|
ctx.lineWidth = 1;
|
|
6435
6365
|
ctx.strokeStyle = this.aperture.color;
|
|
@@ -6448,8 +6378,8 @@ var Drawer = class {
|
|
|
6448
6378
|
drawLines((angle + 90) * Math.PI / 180);
|
|
6449
6379
|
}
|
|
6450
6380
|
rect(x, y, w, h, mesh_fill) {
|
|
6451
|
-
const [x1$, y1$] =
|
|
6452
|
-
const [x2$, y2$] =
|
|
6381
|
+
const [x1$, y1$] = applyToPoint3(this.transform, [x - w / 2, y - h / 2]);
|
|
6382
|
+
const [x2$, y2$] = applyToPoint3(this.transform, [x + w / 2, y + h / 2]);
|
|
6453
6383
|
this.applyAperture();
|
|
6454
6384
|
const ctx = this.getLayerCtx();
|
|
6455
6385
|
if (mesh_fill) {
|
|
@@ -6467,10 +6397,10 @@ var Drawer = class {
|
|
|
6467
6397
|
rotatedRect(x, y, w, h, ccw_rotation, mesh_fill) {
|
|
6468
6398
|
const ctx = this.getLayerCtx();
|
|
6469
6399
|
this.applyAperture();
|
|
6470
|
-
const [x1$, y1$] =
|
|
6471
|
-
const [x2$, y2$] =
|
|
6400
|
+
const [x1$, y1$] = applyToPoint3(this.transform, [x - w / 2, y - h / 2]);
|
|
6401
|
+
const [x2$, y2$] = applyToPoint3(this.transform, [x + w / 2, y + h / 2]);
|
|
6472
6402
|
ctx.save();
|
|
6473
|
-
const [centerX, centerY] =
|
|
6403
|
+
const [centerX, centerY] = applyToPoint3(this.transform, [x, y]);
|
|
6474
6404
|
ctx.translate(centerX, centerY);
|
|
6475
6405
|
const cw_rotation = 360 - ccw_rotation;
|
|
6476
6406
|
if (ccw_rotation) ctx.rotate(cw_rotation * Math.PI / 180);
|
|
@@ -6488,7 +6418,7 @@ var Drawer = class {
|
|
|
6488
6418
|
}
|
|
6489
6419
|
circle(x, y, r, mesh_fill) {
|
|
6490
6420
|
const r$ = scaleOnly(this.transform, r);
|
|
6491
|
-
const [x$, y$] =
|
|
6421
|
+
const [x$, y$] = applyToPoint3(this.transform, [x, y]);
|
|
6492
6422
|
this.applyAperture();
|
|
6493
6423
|
const ctx = this.getLayerCtx();
|
|
6494
6424
|
if (mesh_fill) {
|
|
@@ -6510,7 +6440,7 @@ var Drawer = class {
|
|
|
6510
6440
|
oval(x, y, rx, ry) {
|
|
6511
6441
|
const rx$ = scaleOnly(this.transform, rx);
|
|
6512
6442
|
const ry$ = scaleOnly(this.transform, ry);
|
|
6513
|
-
const [x$, y$] =
|
|
6443
|
+
const [x$, y$] = applyToPoint3(this.transform, [x, y]);
|
|
6514
6444
|
this.applyAperture();
|
|
6515
6445
|
const ctx = this.getLayerCtx();
|
|
6516
6446
|
ctx.beginPath();
|
|
@@ -6519,7 +6449,7 @@ var Drawer = class {
|
|
|
6519
6449
|
ctx.closePath();
|
|
6520
6450
|
}
|
|
6521
6451
|
pill(x, y, w, h) {
|
|
6522
|
-
const [x$, y$] =
|
|
6452
|
+
const [x$, y$] = applyToPoint3(this.transform, [x - w / 2, y + h / 2]);
|
|
6523
6453
|
const width$ = scaleOnly(this.transform, w);
|
|
6524
6454
|
const height$ = scaleOnly(this.transform, h);
|
|
6525
6455
|
const radius = Math.min(width$, height$) / 2;
|
|
@@ -6546,7 +6476,7 @@ var Drawer = class {
|
|
|
6546
6476
|
this.applyAperture();
|
|
6547
6477
|
const ctx = this.getLayerCtx();
|
|
6548
6478
|
const transformedPoints = points.map(
|
|
6549
|
-
(point2) =>
|
|
6479
|
+
(point2) => applyToPoint3(this.transform, [point2.x, point2.y])
|
|
6550
6480
|
);
|
|
6551
6481
|
ctx.beginPath();
|
|
6552
6482
|
ctx.moveTo(transformedPoints[0][0], transformedPoints[0][1]);
|
|
@@ -6561,7 +6491,7 @@ var Drawer = class {
|
|
|
6561
6491
|
}
|
|
6562
6492
|
/* NOTE: This is not gerber compatible */
|
|
6563
6493
|
debugText(text, x, y) {
|
|
6564
|
-
const [x$, y$] =
|
|
6494
|
+
const [x$, y$] = applyToPoint3(this.transform, [x, y]);
|
|
6565
6495
|
this.applyAperture();
|
|
6566
6496
|
const ctx = this.getLayerCtx();
|
|
6567
6497
|
ctx.font = `10px sans-serif`;
|
|
@@ -6626,11 +6556,11 @@ var Drawer = class {
|
|
|
6626
6556
|
this.lastPoint = { x, y };
|
|
6627
6557
|
}
|
|
6628
6558
|
lineTo(x, y) {
|
|
6629
|
-
const [x$, y$] =
|
|
6559
|
+
const [x$, y$] = applyToPoint3(this.transform, [x, y]);
|
|
6630
6560
|
const { size: size2, shape, mode } = this.aperture;
|
|
6631
6561
|
const size$ = scaleOnly(this.transform, size2);
|
|
6632
6562
|
let { lastPoint } = this;
|
|
6633
|
-
const lastPoint$ =
|
|
6563
|
+
const lastPoint$ = applyToPoint3(this.transform, lastPoint);
|
|
6634
6564
|
this.applyAperture();
|
|
6635
6565
|
const ctx = this.getLayerCtx();
|
|
6636
6566
|
if (shape === "square")
|
|
@@ -6652,24 +6582,24 @@ var Drawer = class {
|
|
|
6652
6582
|
};
|
|
6653
6583
|
|
|
6654
6584
|
// src/lib/util/rotate-text.ts
|
|
6655
|
-
import { compose as
|
|
6585
|
+
import { compose as compose3, translate as translate4, rotate, applyToPoint as applyToPoint4 } from "transformation-matrix";
|
|
6656
6586
|
function rotateText(rotateTextParams) {
|
|
6657
6587
|
const { lines, anchorPoint, ccwRotation } = rotateTextParams;
|
|
6658
6588
|
if (!ccwRotation) return lines;
|
|
6659
6589
|
const rad = ccwRotation * Math.PI / 180;
|
|
6660
6590
|
const rotationMatrix = rotate(rad);
|
|
6661
|
-
const transform =
|
|
6662
|
-
|
|
6591
|
+
const transform = compose3(
|
|
6592
|
+
translate4(anchorPoint.x, anchorPoint.y),
|
|
6663
6593
|
rotationMatrix,
|
|
6664
|
-
|
|
6594
|
+
translate4(-anchorPoint.x, -anchorPoint.y)
|
|
6665
6595
|
);
|
|
6666
|
-
|
|
6596
|
+
applyToPoint4(transform, anchorPoint);
|
|
6667
6597
|
return lines.map((line) => ({
|
|
6668
6598
|
...line,
|
|
6669
|
-
x1:
|
|
6670
|
-
y1:
|
|
6671
|
-
x2:
|
|
6672
|
-
y2:
|
|
6599
|
+
x1: applyToPoint4(transform, { x: line.x1, y: line.y1 }).x,
|
|
6600
|
+
y1: applyToPoint4(transform, { x: line.x1, y: line.y1 }).y,
|
|
6601
|
+
x2: applyToPoint4(transform, { x: line.x2, y: line.y2 }).x,
|
|
6602
|
+
y2: applyToPoint4(transform, { x: line.x2, y: line.y2 }).y
|
|
6673
6603
|
}));
|
|
6674
6604
|
}
|
|
6675
6605
|
|
|
@@ -6921,9 +6851,9 @@ var CanvasPrimitiveRenderer = ({
|
|
|
6921
6851
|
width = 500,
|
|
6922
6852
|
height = 500
|
|
6923
6853
|
}) => {
|
|
6924
|
-
const canvasRefs =
|
|
6854
|
+
const canvasRefs = useRef2();
|
|
6925
6855
|
const selectedLayer = useGlobalStore((s) => s.selected_layer);
|
|
6926
|
-
|
|
6856
|
+
useEffect4(() => {
|
|
6927
6857
|
if (!canvasRefs.current) return;
|
|
6928
6858
|
if (Object.keys(canvasRefs.current).length === 0) return;
|
|
6929
6859
|
const drawer = new Drawer(canvasRefs.current);
|
|
@@ -7034,16 +6964,16 @@ function getExpandedStroke(strokeInput, defaultWidth) {
|
|
|
7034
6964
|
addPoint(current2, normalPrev, -1, currentWidth);
|
|
7035
6965
|
addPoint(current2, normalNext, -1, currentWidth);
|
|
7036
6966
|
} else {
|
|
7037
|
-
const
|
|
6967
|
+
const scale3 = 1 / miterLength;
|
|
7038
6968
|
addPoint(
|
|
7039
6969
|
current2,
|
|
7040
|
-
{ x: miterX *
|
|
6970
|
+
{ x: miterX * scale3, y: miterY * scale3 },
|
|
7041
6971
|
1,
|
|
7042
6972
|
currentWidth
|
|
7043
6973
|
);
|
|
7044
6974
|
addPoint(
|
|
7045
6975
|
current2,
|
|
7046
|
-
{ x: miterX *
|
|
6976
|
+
{ x: miterX * scale3, y: miterY * scale3 },
|
|
7047
6977
|
-1,
|
|
7048
6978
|
currentWidth
|
|
7049
6979
|
);
|
|
@@ -7561,12 +7491,12 @@ var convertElementToPrimitives = (element, allElements) => {
|
|
|
7561
7491
|
};
|
|
7562
7492
|
|
|
7563
7493
|
// src/components/MouseElementTracker.tsx
|
|
7564
|
-
import { useState as
|
|
7494
|
+
import { useState as useState4 } from "react";
|
|
7565
7495
|
import { useMemo as useMemo3 } from "react";
|
|
7566
|
-
import { applyToPoint as
|
|
7496
|
+
import { applyToPoint as applyToPoint5, inverse as inverse2 } from "transformation-matrix";
|
|
7567
7497
|
|
|
7568
7498
|
// src/components/ElementOverlayBox.tsx
|
|
7569
|
-
import { useEffect as
|
|
7499
|
+
import { useEffect as useEffect5, useState as useState3 } from "react";
|
|
7570
7500
|
|
|
7571
7501
|
// src/lib/get-trace-overlay-text.ts
|
|
7572
7502
|
function getTraceOverlayInfo({
|
|
@@ -7677,9 +7607,9 @@ var HighlightedPrimitiveBoxWithText = ({
|
|
|
7677
7607
|
mousePos,
|
|
7678
7608
|
elements
|
|
7679
7609
|
}) => {
|
|
7680
|
-
const [finalState, setFinalState] =
|
|
7610
|
+
const [finalState, setFinalState] = useState3(false);
|
|
7681
7611
|
const primitiveElement = primitive._element;
|
|
7682
|
-
|
|
7612
|
+
useEffect5(() => {
|
|
7683
7613
|
setTimeout(() => {
|
|
7684
7614
|
setFinalState(true);
|
|
7685
7615
|
}, 100);
|
|
@@ -7841,15 +7771,15 @@ var MouseElementTracker = ({
|
|
|
7841
7771
|
primitives,
|
|
7842
7772
|
onMouseHoverOverPrimitives
|
|
7843
7773
|
}) => {
|
|
7844
|
-
const [mousedPrimitives, setMousedPrimitives] =
|
|
7845
|
-
const [mousePos, setMousePos] =
|
|
7774
|
+
const [mousedPrimitives, setMousedPrimitives] = useState4([]);
|
|
7775
|
+
const [mousePos, setMousePos] = useState4({ x: 0, y: 0 });
|
|
7846
7776
|
const highlightedPrimitives = useMemo3(() => {
|
|
7847
7777
|
const highlightedPrimitives2 = [];
|
|
7848
7778
|
for (const primitive of mousedPrimitives) {
|
|
7849
7779
|
if (primitive._element?.type === "pcb_via") continue;
|
|
7850
7780
|
if (primitive._element?.type === "pcb_component") continue;
|
|
7851
7781
|
if (primitive?.layer === "drill") continue;
|
|
7852
|
-
const screenPos =
|
|
7782
|
+
const screenPos = applyToPoint5(
|
|
7853
7783
|
transform,
|
|
7854
7784
|
primitive
|
|
7855
7785
|
);
|
|
@@ -7883,7 +7813,7 @@ var MouseElementTracker = ({
|
|
|
7883
7813
|
const x = e.clientX - rect.left;
|
|
7884
7814
|
const y = e.clientY - rect.top;
|
|
7885
7815
|
setMousePos({ x, y });
|
|
7886
|
-
const rwPoint =
|
|
7816
|
+
const rwPoint = applyToPoint5(inverse2(transform), { x, y });
|
|
7887
7817
|
const newMousedPrimitives = [];
|
|
7888
7818
|
for (const primitive of primitives) {
|
|
7889
7819
|
if (!primitive._element) continue;
|
|
@@ -7941,20 +7871,20 @@ var MouseElementTracker = ({
|
|
|
7941
7871
|
};
|
|
7942
7872
|
|
|
7943
7873
|
// src/components/DimensionOverlay.tsx
|
|
7944
|
-
import { useEffect as
|
|
7945
|
-
import { applyToPoint as
|
|
7874
|
+
import { useEffect as useEffect6, useRef as useRef3, useState as useState5 } from "react";
|
|
7875
|
+
import { applyToPoint as applyToPoint6, identity as identity3, inverse as inverse3 } from "transformation-matrix";
|
|
7946
7876
|
import { Fragment, jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
7947
7877
|
var DimensionOverlay = ({ children, transform }) => {
|
|
7948
|
-
if (!transform) transform =
|
|
7949
|
-
const [dimensionToolVisible, setDimensionToolVisible] =
|
|
7950
|
-
const [dimensionToolStretching, setDimensionToolStretching] =
|
|
7951
|
-
const [dStart, setDStart] =
|
|
7952
|
-
const [dEnd, setDEnd] =
|
|
7953
|
-
const mousePosRef =
|
|
7954
|
-
const containerRef =
|
|
7878
|
+
if (!transform) transform = identity3();
|
|
7879
|
+
const [dimensionToolVisible, setDimensionToolVisible] = useState5(false);
|
|
7880
|
+
const [dimensionToolStretching, setDimensionToolStretching] = useState5(false);
|
|
7881
|
+
const [dStart, setDStart] = useState5({ x: 0, y: 0 });
|
|
7882
|
+
const [dEnd, setDEnd] = useState5({ x: 0, y: 0 });
|
|
7883
|
+
const mousePosRef = useRef3({ x: 0, y: 0 });
|
|
7884
|
+
const containerRef = useRef3(null);
|
|
7955
7885
|
const container = containerRef.current;
|
|
7956
7886
|
const containerBounds = container?.getBoundingClientRect();
|
|
7957
|
-
|
|
7887
|
+
useEffect6(() => {
|
|
7958
7888
|
const container2 = containerRef.current;
|
|
7959
7889
|
const down = (e) => {
|
|
7960
7890
|
if (e.key === "d") {
|
|
@@ -7994,8 +7924,8 @@ var DimensionOverlay = ({ children, transform }) => {
|
|
|
7994
7924
|
}
|
|
7995
7925
|
};
|
|
7996
7926
|
}, [containerRef]);
|
|
7997
|
-
const screenDStart =
|
|
7998
|
-
const screenDEnd =
|
|
7927
|
+
const screenDStart = applyToPoint6(transform, dStart);
|
|
7928
|
+
const screenDEnd = applyToPoint6(transform, dEnd);
|
|
7999
7929
|
const arrowScreenBounds = {
|
|
8000
7930
|
left: Math.min(screenDStart.x, screenDEnd.x),
|
|
8001
7931
|
right: Math.max(screenDStart.x, screenDEnd.x),
|
|
@@ -8028,7 +7958,7 @@ var DimensionOverlay = ({ children, transform }) => {
|
|
|
8028
7958
|
const rect = e.currentTarget.getBoundingClientRect();
|
|
8029
7959
|
const x = e.clientX - rect.left;
|
|
8030
7960
|
const y = e.clientY - rect.top;
|
|
8031
|
-
const rwPoint =
|
|
7961
|
+
const rwPoint = applyToPoint6(inverse3(transform), { x, y });
|
|
8032
7962
|
mousePosRef.current.x = rwPoint.x;
|
|
8033
7963
|
mousePosRef.current.y = rwPoint.y;
|
|
8034
7964
|
if (dimensionToolStretching) {
|
|
@@ -8203,20 +8133,20 @@ var DimensionOverlay = ({ children, transform }) => {
|
|
|
8203
8133
|
};
|
|
8204
8134
|
|
|
8205
8135
|
// src/components/ToolbarOverlay.tsx
|
|
8206
|
-
import { Fragment as Fragment2, useState as
|
|
8136
|
+
import { Fragment as Fragment2, useState as useState6 } from "react";
|
|
8207
8137
|
import { css } from "@emotion/css";
|
|
8208
8138
|
|
|
8209
8139
|
// package.json
|
|
8210
8140
|
var package_default = {
|
|
8211
8141
|
name: "@tscircuit/pcb-viewer",
|
|
8212
|
-
version: "1.11.
|
|
8142
|
+
version: "1.11.10",
|
|
8213
8143
|
main: "dist/index.js",
|
|
8214
8144
|
type: "module",
|
|
8215
8145
|
repository: "tscircuit/pcb-viewer",
|
|
8216
8146
|
license: "MIT",
|
|
8217
8147
|
scripts: {
|
|
8218
8148
|
start: "storybook dev -p 6006",
|
|
8219
|
-
build: "tsup ./src/index.tsx --dts --sourcemap --format esm --outDir dist",
|
|
8149
|
+
build: "tsup ./src/index.tsx --platform browser --dts --sourcemap --format esm --outDir dist",
|
|
8220
8150
|
yalc: "npm run build && yalc push",
|
|
8221
8151
|
storybook: "storybook dev -p 6006",
|
|
8222
8152
|
"build-storybook": "storybook build",
|
|
@@ -8238,7 +8168,7 @@ var package_default = {
|
|
|
8238
8168
|
"@tscircuit/core": "0.0.255",
|
|
8239
8169
|
"@tscircuit/eagle-xml-converter": "^0.0.7",
|
|
8240
8170
|
"@tscircuit/props": "^0.0.128",
|
|
8241
|
-
"@tscircuit/soup-util": "^0.0.
|
|
8171
|
+
"@tscircuit/soup-util": "^0.0.41",
|
|
8242
8172
|
"@types/color": "^3.0.6",
|
|
8243
8173
|
"@types/node": "18.7.23",
|
|
8244
8174
|
"@types/react": "^18.3.3",
|
|
@@ -8273,12 +8203,12 @@ var package_default = {
|
|
|
8273
8203
|
};
|
|
8274
8204
|
|
|
8275
8205
|
// src/hooks/useHotKey.ts
|
|
8276
|
-
import { useEffect as
|
|
8206
|
+
import { useEffect as useEffect7 } from "react";
|
|
8277
8207
|
var useHotKey = (key, onUse) => {
|
|
8278
8208
|
const isMouseOverContainer = useGlobalStore(
|
|
8279
8209
|
(s) => s.is_mouse_over_container
|
|
8280
8210
|
);
|
|
8281
|
-
|
|
8211
|
+
useEffect7(() => {
|
|
8282
8212
|
if (!key || typeof onUse !== "function") return;
|
|
8283
8213
|
const handleKeyDown = (event) => {
|
|
8284
8214
|
const keyParts = key.split("+");
|
|
@@ -8395,9 +8325,9 @@ var ToolbarOverlay = ({ children, elements }) => {
|
|
|
8395
8325
|
const [isMouseOverContainer, setIsMouseOverContainer] = useGlobalStore(
|
|
8396
8326
|
(s) => [s.is_mouse_over_container, s.setIsMouseOverContainer]
|
|
8397
8327
|
);
|
|
8398
|
-
const [isViewMenuOpen, setViewMenuOpen] =
|
|
8399
|
-
const [isLayerMenuOpen, setLayerMenuOpen] =
|
|
8400
|
-
const [isErrorsOpen, setErrorsOpen] =
|
|
8328
|
+
const [isViewMenuOpen, setViewMenuOpen] = useState6(false);
|
|
8329
|
+
const [isLayerMenuOpen, setLayerMenuOpen] = useState6(false);
|
|
8330
|
+
const [isErrorsOpen, setErrorsOpen] = useState6(false);
|
|
8401
8331
|
const [selectedLayer, selectLayer] = useGlobalStore(
|
|
8402
8332
|
(s) => [s.selected_layer, s.selectLayer]
|
|
8403
8333
|
);
|
|
@@ -8639,8 +8569,8 @@ var ToolbarOverlay = ({ children, elements }) => {
|
|
|
8639
8569
|
|
|
8640
8570
|
// src/components/ErrorOverlay.tsx
|
|
8641
8571
|
import { css as css2 } from "@emotion/css";
|
|
8642
|
-
import { useRef as
|
|
8643
|
-
import { applyToPoint as
|
|
8572
|
+
import { useRef as useRef4 } from "react";
|
|
8573
|
+
import { applyToPoint as applyToPoint7, identity as identity4 } from "transformation-matrix";
|
|
8644
8574
|
import { Fragment as Fragment3, jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
8645
8575
|
var ErrorSVG = ({
|
|
8646
8576
|
screenPort1,
|
|
@@ -8700,8 +8630,8 @@ var ErrorSVG = ({
|
|
|
8700
8630
|
}
|
|
8701
8631
|
);
|
|
8702
8632
|
var ErrorOverlay = ({ children, transform, elements }) => {
|
|
8703
|
-
if (!transform) transform =
|
|
8704
|
-
const containerRef =
|
|
8633
|
+
if (!transform) transform = identity4();
|
|
8634
|
+
const containerRef = useRef4(null);
|
|
8705
8635
|
return /* @__PURE__ */ jsxs5("div", { style: { position: "relative" }, ref: containerRef, children: [
|
|
8706
8636
|
children,
|
|
8707
8637
|
elements?.filter((el) => el.type === "pcb_trace_error").map((el) => {
|
|
@@ -8713,11 +8643,11 @@ var ErrorOverlay = ({ children, transform, elements }) => {
|
|
|
8713
8643
|
(el2) => el2.type === "pcb_port" && el2.pcb_port_id === pcb_port_ids?.[1]
|
|
8714
8644
|
);
|
|
8715
8645
|
if (!port1 || !port2) return null;
|
|
8716
|
-
const screenPort1 =
|
|
8646
|
+
const screenPort1 = applyToPoint7(transform, {
|
|
8717
8647
|
x: port1.x,
|
|
8718
8648
|
y: port1.y
|
|
8719
8649
|
});
|
|
8720
|
-
const screenPort2 =
|
|
8650
|
+
const screenPort2 = applyToPoint7(transform, {
|
|
8721
8651
|
x: port2.x,
|
|
8722
8652
|
y: port2.y
|
|
8723
8653
|
});
|
|
@@ -8793,8 +8723,8 @@ var ErrorOverlay = ({ children, transform, elements }) => {
|
|
|
8793
8723
|
};
|
|
8794
8724
|
|
|
8795
8725
|
// src/components/EditPlacementOverlay.tsx
|
|
8796
|
-
import { useRef as
|
|
8797
|
-
import { applyToPoint as
|
|
8726
|
+
import { useRef as useRef5, useState as useState7 } from "react";
|
|
8727
|
+
import { applyToPoint as applyToPoint8, identity as identity5, inverse as inverse4 } from "transformation-matrix";
|
|
8798
8728
|
import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
8799
8729
|
var isInsideOf = (pcb_component2, point2, padding = 0) => {
|
|
8800
8730
|
const halfWidth = pcb_component2.width / 2;
|
|
@@ -8814,12 +8744,12 @@ var EditPlacementOverlay = ({
|
|
|
8814
8744
|
onCreateEditEvent,
|
|
8815
8745
|
onModifyEditEvent
|
|
8816
8746
|
}) => {
|
|
8817
|
-
if (!transform) transform =
|
|
8818
|
-
const containerRef =
|
|
8819
|
-
const [activePcbComponentId, setActivePcbComponent] =
|
|
8747
|
+
if (!transform) transform = identity5();
|
|
8748
|
+
const containerRef = useRef5(null);
|
|
8749
|
+
const [activePcbComponentId, setActivePcbComponent] = useState7(
|
|
8820
8750
|
null
|
|
8821
8751
|
);
|
|
8822
|
-
const [dragState, setDragState] =
|
|
8752
|
+
const [dragState, setDragState] = useState7(null);
|
|
8823
8753
|
const isPcbComponentActive = activePcbComponentId !== null;
|
|
8824
8754
|
const in_edit_mode = useGlobalStore((s) => s.in_edit_mode);
|
|
8825
8755
|
const in_move_footprint_mode = useGlobalStore((s) => s.in_move_footprint_mode);
|
|
@@ -8839,7 +8769,7 @@ var EditPlacementOverlay = ({
|
|
|
8839
8769
|
const x = e.clientX - rect.left;
|
|
8840
8770
|
const y = e.clientY - rect.top;
|
|
8841
8771
|
if (isNaN(x) || isNaN(y)) return;
|
|
8842
|
-
const rwMousePoint =
|
|
8772
|
+
const rwMousePoint = applyToPoint8(inverse4(transform), { x, y });
|
|
8843
8773
|
let foundActiveComponent = false;
|
|
8844
8774
|
for (const e2 of soup) {
|
|
8845
8775
|
if (e2.type === "pcb_component" && isInsideOf(e2, rwMousePoint, 10 / transform.a)) {
|
|
@@ -8880,7 +8810,7 @@ var EditPlacementOverlay = ({
|
|
|
8880
8810
|
const x = e.clientX - rect.left;
|
|
8881
8811
|
const y = e.clientY - rect.top;
|
|
8882
8812
|
if (isNaN(x) || isNaN(y)) return;
|
|
8883
|
-
const rwMousePoint =
|
|
8813
|
+
const rwMousePoint = applyToPoint8(inverse4(transform), { x, y });
|
|
8884
8814
|
setDragState({
|
|
8885
8815
|
...dragState,
|
|
8886
8816
|
dragEnd: rwMousePoint
|
|
@@ -8909,7 +8839,7 @@ var EditPlacementOverlay = ({
|
|
|
8909
8839
|
children,
|
|
8910
8840
|
!disabled && soup.filter((e) => e.type === "pcb_component").map((e) => {
|
|
8911
8841
|
if (!e?.center) return null;
|
|
8912
|
-
const projectedCenter =
|
|
8842
|
+
const projectedCenter = applyToPoint8(transform, e.center);
|
|
8913
8843
|
return /* @__PURE__ */ jsx9(
|
|
8914
8844
|
"div",
|
|
8915
8845
|
{
|
|
@@ -8934,21 +8864,21 @@ var EditPlacementOverlay = ({
|
|
|
8934
8864
|
};
|
|
8935
8865
|
|
|
8936
8866
|
// src/components/EditTraceHintOverlay.tsx
|
|
8937
|
-
import { Fragment as Fragment4, useEffect as
|
|
8867
|
+
import { Fragment as Fragment4, useEffect as useEffect11, useRef as useRef6, useState as useState8 } from "react";
|
|
8938
8868
|
import {
|
|
8939
|
-
applyToPoint as
|
|
8940
|
-
identity as
|
|
8869
|
+
applyToPoint as applyToPoint9,
|
|
8870
|
+
identity as identity6,
|
|
8941
8871
|
inverse as inverse5
|
|
8942
8872
|
} from "transformation-matrix";
|
|
8943
8873
|
|
|
8944
8874
|
// src/components/HotkeyActionMenu.tsx
|
|
8945
8875
|
import { css as css3 } from "@emotion/css";
|
|
8946
|
-
import { useEffect as
|
|
8876
|
+
import { useEffect as useEffect10 } from "react";
|
|
8947
8877
|
import { jsx as jsx10, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
8948
8878
|
var HotkeyActionMenu = ({
|
|
8949
8879
|
hotkeys
|
|
8950
8880
|
}) => {
|
|
8951
|
-
|
|
8881
|
+
useEffect10(() => {
|
|
8952
8882
|
const handleKeyDown = (event) => {
|
|
8953
8883
|
hotkeys.forEach((hotkey) => {
|
|
8954
8884
|
if (event.key === hotkey.key) {
|
|
@@ -9048,22 +8978,22 @@ var EditTraceHintOverlay = ({
|
|
|
9048
8978
|
onCreateEditEvent,
|
|
9049
8979
|
onModifyEditEvent
|
|
9050
8980
|
}) => {
|
|
9051
|
-
if (!transform) transform =
|
|
9052
|
-
const containerRef =
|
|
8981
|
+
if (!transform) transform = identity6();
|
|
8982
|
+
const containerRef = useRef6(null);
|
|
9053
8983
|
const containerBounds = containerRef.current?.getBoundingClientRect();
|
|
9054
|
-
const [selectedElement, setSelectedElement] =
|
|
8984
|
+
const [selectedElement, setSelectedElement] = useState8(null);
|
|
9055
8985
|
const toast = useToast();
|
|
9056
|
-
const [dragState, setDragState] =
|
|
9057
|
-
const [shouldCreateAsVia, setShouldCreateAsVia] =
|
|
8986
|
+
const [dragState, setDragState] = useState8(null);
|
|
8987
|
+
const [shouldCreateAsVia, setShouldCreateAsVia] = useState8(false);
|
|
9058
8988
|
const isElementSelected = selectedElement !== null;
|
|
9059
8989
|
const in_edit_trace_mode = useGlobalStore((s) => s.in_draw_trace_mode);
|
|
9060
8990
|
const disabled = disabledProp || !in_edit_trace_mode;
|
|
9061
8991
|
let ogCenterScreen, dragEndScreen;
|
|
9062
8992
|
if (dragState?.originalCenter && dragState?.dragEnd) {
|
|
9063
|
-
ogCenterScreen =
|
|
9064
|
-
dragEndScreen =
|
|
8993
|
+
ogCenterScreen = applyToPoint9(transform, dragState?.originalCenter);
|
|
8994
|
+
dragEndScreen = applyToPoint9(transform, dragState?.dragEnd);
|
|
9065
8995
|
}
|
|
9066
|
-
|
|
8996
|
+
useEffect11(() => {
|
|
9067
8997
|
if (!isElementSelected) return;
|
|
9068
8998
|
function keyDown(e) {
|
|
9069
8999
|
if (e.key === "Escape") {
|
|
@@ -9088,7 +9018,7 @@ var EditTraceHintOverlay = ({
|
|
|
9088
9018
|
const x = e.clientX - rect.left;
|
|
9089
9019
|
const y = e.clientY - rect.top;
|
|
9090
9020
|
if (isNaN(x) || isNaN(y)) return;
|
|
9091
|
-
const rwMousePoint =
|
|
9021
|
+
const rwMousePoint = applyToPoint9(inverse5(transform), { x, y });
|
|
9092
9022
|
if (!isElementSelected) {
|
|
9093
9023
|
for (const e2 of soup) {
|
|
9094
9024
|
if (e2.type === "pcb_smtpad" && isInsideOfSmtpad(e2, rwMousePoint, 10 / transform.a) || e2.type === "pcb_plated_hole" && isInsideOfPlatedHole(e2, rwMousePoint, 10 / transform.a)) {
|
|
@@ -9131,7 +9061,7 @@ var EditTraceHintOverlay = ({
|
|
|
9131
9061
|
const x = e.clientX - rect.left;
|
|
9132
9062
|
const y = e.clientY - rect.top;
|
|
9133
9063
|
if (isNaN(x) || isNaN(y)) return;
|
|
9134
|
-
const rwMousePoint =
|
|
9064
|
+
const rwMousePoint = applyToPoint9(inverse5(transform), { x, y });
|
|
9135
9065
|
setDragState({
|
|
9136
9066
|
...dragState,
|
|
9137
9067
|
dragEnd: rwMousePoint
|
|
@@ -9150,10 +9080,10 @@ var EditTraceHintOverlay = ({
|
|
|
9150
9080
|
const x = e.clientX - rect.left;
|
|
9151
9081
|
const y = e.clientY - rect.top;
|
|
9152
9082
|
if (isNaN(x) || isNaN(y)) return;
|
|
9153
|
-
const rwMousePoint =
|
|
9083
|
+
const rwMousePoint = applyToPoint9(inverse5(transform), { x, y });
|
|
9154
9084
|
if (dragState) {
|
|
9155
9085
|
cancelPanDrag();
|
|
9156
|
-
const lastPointScreen =
|
|
9086
|
+
const lastPointScreen = applyToPoint9(
|
|
9157
9087
|
transform,
|
|
9158
9088
|
dragState.editEvent.route.slice(-1)[0] ?? dragState.originalCenter
|
|
9159
9089
|
);
|
|
@@ -9201,11 +9131,11 @@ var EditTraceHintOverlay = ({
|
|
|
9201
9131
|
"path",
|
|
9202
9132
|
{
|
|
9203
9133
|
stroke: "red",
|
|
9204
|
-
d: `M ${ogCenterScreen.x} ${ogCenterScreen.y} ${dragState?.editEvent.route.map((p) =>
|
|
9134
|
+
d: `M ${ogCenterScreen.x} ${ogCenterScreen.y} ${dragState?.editEvent.route.map((p) => applyToPoint9(transform, p)).map((p) => `L ${p.x} ${p.y}`).join(" ")} L ${dragEndScreen.x} ${dragEndScreen.y}`
|
|
9205
9135
|
}
|
|
9206
9136
|
),
|
|
9207
9137
|
dragState?.editEvent.route.map((r, i) => {
|
|
9208
|
-
const rScreen =
|
|
9138
|
+
const rScreen = applyToPoint9(transform, r);
|
|
9209
9139
|
return /* @__PURE__ */ jsxs8(Fragment4, { children: [
|
|
9210
9140
|
r.via && /* @__PURE__ */ jsx11("circle", { cx: rScreen.x, cy: rScreen.y, r: 16, stroke: "red" }),
|
|
9211
9141
|
/* @__PURE__ */ jsx11("circle", { cx: rScreen.x, cy: rScreen.y, r: 8, stroke: "red" })
|
|
@@ -9249,7 +9179,7 @@ var EditTraceHintOverlay = ({
|
|
|
9249
9179
|
children: soup.filter((e) => e.type === "pcb_trace_hint").map((e) => {
|
|
9250
9180
|
const { route } = e;
|
|
9251
9181
|
const pcb_port2 = su_default(soup).pcb_port.get(e.pcb_port_id);
|
|
9252
|
-
const pcb_port_screen =
|
|
9182
|
+
const pcb_port_screen = applyToPoint9(transform, pcb_port2);
|
|
9253
9183
|
return /* @__PURE__ */ jsxs8(Fragment4, { children: [
|
|
9254
9184
|
/* @__PURE__ */ jsx11(
|
|
9255
9185
|
"rect",
|
|
@@ -9266,11 +9196,11 @@ var EditTraceHintOverlay = ({
|
|
|
9266
9196
|
"path",
|
|
9267
9197
|
{
|
|
9268
9198
|
stroke: "red",
|
|
9269
|
-
d: `M ${pcb_port_screen.x} ${pcb_port_screen.y} ${route.map((r) =>
|
|
9199
|
+
d: `M ${pcb_port_screen.x} ${pcb_port_screen.y} ${route.map((r) => applyToPoint9(transform, r)).map((r) => `L ${r.x} ${r.y}`).join(" ")}`
|
|
9270
9200
|
},
|
|
9271
9201
|
`path-${e.pcb_port_id}`
|
|
9272
9202
|
),
|
|
9273
|
-
route.map((r) => ({ ...r, ...
|
|
9203
|
+
route.map((r) => ({ ...r, ...applyToPoint9(transform, r) })).map((r, i) => /* @__PURE__ */ jsxs8(Fragment4, { children: [
|
|
9274
9204
|
/* @__PURE__ */ jsx11("circle", { cx: r.x, cy: r.y, r: 8, stroke: "red" }),
|
|
9275
9205
|
r.via && /* @__PURE__ */ jsx11(
|
|
9276
9206
|
"circle",
|
|
@@ -9328,7 +9258,7 @@ var EditTraceHintOverlay = ({
|
|
|
9328
9258
|
};
|
|
9329
9259
|
|
|
9330
9260
|
// src/components/RatsNestOverlay.tsx
|
|
9331
|
-
import { applyToPoint as
|
|
9261
|
+
import { applyToPoint as applyToPoint10, identity as identity7 } from "transformation-matrix";
|
|
9332
9262
|
import { getFullConnectivityMapFromCircuitJson } from "circuit-json-to-connectivity-map";
|
|
9333
9263
|
import { useMemo as useMemo4 } from "react";
|
|
9334
9264
|
import { jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
@@ -9394,7 +9324,7 @@ var RatsNestOverlay = ({ transform, soup, children }) => {
|
|
|
9394
9324
|
return lines;
|
|
9395
9325
|
}, [soup, netMap, idToNetMap, isShowingRatsNest]);
|
|
9396
9326
|
if (!soup || !isShowingRatsNest) return children;
|
|
9397
|
-
if (!transform) transform =
|
|
9327
|
+
if (!transform) transform = identity7();
|
|
9398
9328
|
return /* @__PURE__ */ jsxs9("div", { style: { position: "relative" }, children: [
|
|
9399
9329
|
children,
|
|
9400
9330
|
/* @__PURE__ */ jsx12(
|
|
@@ -9411,8 +9341,8 @@ var RatsNestOverlay = ({ transform, soup, children }) => {
|
|
|
9411
9341
|
zIndex: zIndexMap.ratsNestOverlay
|
|
9412
9342
|
},
|
|
9413
9343
|
children: ratsNestLines.map(({ key, startPoint, endPoint, isInNet }) => {
|
|
9414
|
-
const transformedStart =
|
|
9415
|
-
const transformedEnd =
|
|
9344
|
+
const transformedStart = applyToPoint10(transform, startPoint);
|
|
9345
|
+
const transformedEnd = applyToPoint10(transform, endPoint);
|
|
9416
9346
|
return /* @__PURE__ */ jsx12(
|
|
9417
9347
|
"line",
|
|
9418
9348
|
{
|
|
@@ -9477,7 +9407,7 @@ var CanvasElementsRenderer = (props) => {
|
|
|
9477
9407
|
);
|
|
9478
9408
|
return [primitivesWithoutInteractionMetadata2, connectivityMap2];
|
|
9479
9409
|
}, [props.elements]);
|
|
9480
|
-
const [primitives, setPrimitives] =
|
|
9410
|
+
const [primitives, setPrimitives] = useState9(
|
|
9481
9411
|
primitivesWithoutInteractionMetadata
|
|
9482
9412
|
);
|
|
9483
9413
|
return /* @__PURE__ */ jsx13(
|
|
@@ -9546,7 +9476,7 @@ var CanvasElementsRenderer = (props) => {
|
|
|
9546
9476
|
|
|
9547
9477
|
// src/PCBViewer.tsx
|
|
9548
9478
|
import { jsx as jsx14, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
9549
|
-
var defaultTransform =
|
|
9479
|
+
var defaultTransform = compose4(translate5(400, 300), scale2(40, -40));
|
|
9550
9480
|
var PCBViewer = ({
|
|
9551
9481
|
children,
|
|
9552
9482
|
soup,
|
|
@@ -9565,16 +9495,16 @@ var PCBViewer = ({
|
|
|
9565
9495
|
} = useRenderedCircuit(children);
|
|
9566
9496
|
circuitJson ??= circuitJsonFromChildren ?? [];
|
|
9567
9497
|
const [ref, refDimensions] = useMeasure_default();
|
|
9568
|
-
const [transform, setTransformInternal] =
|
|
9498
|
+
const [transform, setTransformInternal] = useState10(defaultTransform);
|
|
9569
9499
|
const {
|
|
9570
9500
|
ref: transformRef,
|
|
9571
9501
|
setTransform,
|
|
9572
9502
|
cancelDrag: cancelPanDrag
|
|
9573
|
-
} = (
|
|
9503
|
+
} = src_default({
|
|
9574
9504
|
transform,
|
|
9575
9505
|
onSetTransform: setTransformInternal
|
|
9576
9506
|
});
|
|
9577
|
-
let [editEvents, setEditEvents] =
|
|
9507
|
+
let [editEvents, setEditEvents] = useState10([]);
|
|
9578
9508
|
editEvents = editEventsProp ?? editEvents;
|
|
9579
9509
|
const resetTransform = () => {
|
|
9580
9510
|
const elmBounds = refDimensions?.width > 0 ? refDimensions : { width: 500, height: 500 };
|
|
@@ -9589,14 +9519,14 @@ var PCBViewer = ({
|
|
|
9589
9519
|
100
|
|
9590
9520
|
) * 0.75;
|
|
9591
9521
|
setTransform(
|
|
9592
|
-
|
|
9593
|
-
|
|
9594
|
-
|
|
9595
|
-
|
|
9522
|
+
compose4(
|
|
9523
|
+
translate5((elmBounds.width ?? 0) / 2, (elmBounds.height ?? 0) / 2),
|
|
9524
|
+
scale2(scaleFactor, -scaleFactor, 0, 0),
|
|
9525
|
+
translate5(-center.x, -center.y)
|
|
9596
9526
|
)
|
|
9597
9527
|
);
|
|
9598
9528
|
};
|
|
9599
|
-
|
|
9529
|
+
useEffect12(() => {
|
|
9600
9530
|
if (refDimensions && refDimensions.width !== 0 && (children || soup)) {
|
|
9601
9531
|
resetTransform();
|
|
9602
9532
|
}
|