@tscircuit/pcb-viewer 1.2.13 → 1.2.15
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.d.ts +2 -2
- package/dist/index.js +1436 -952
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -1,1038 +1,1522 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function _array_like_to_array(arr, len) {
|
|
3
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
4
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
5
|
+
return arr2;
|
|
6
|
+
}
|
|
7
|
+
function _array_with_holes(arr) {
|
|
8
|
+
if (Array.isArray(arr)) return arr;
|
|
9
|
+
}
|
|
10
|
+
function _class_call_check(instance, Constructor) {
|
|
11
|
+
if (!(instance instanceof Constructor)) {
|
|
12
|
+
throw new TypeError("Cannot call a class as a function");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _defineProperties(target, props) {
|
|
16
|
+
for(var i = 0; i < props.length; i++){
|
|
17
|
+
var descriptor = props[i];
|
|
18
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
19
|
+
descriptor.configurable = true;
|
|
20
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
21
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
25
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
26
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
27
|
+
return Constructor;
|
|
28
|
+
}
|
|
29
|
+
function _define_property(obj, key, value) {
|
|
30
|
+
if (key in obj) {
|
|
31
|
+
Object.defineProperty(obj, key, {
|
|
32
|
+
value: value,
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
writable: true
|
|
36
|
+
});
|
|
37
|
+
} else {
|
|
38
|
+
obj[key] = value;
|
|
39
|
+
}
|
|
40
|
+
return obj;
|
|
41
|
+
}
|
|
42
|
+
function _iterable_to_array_limit(arr, i) {
|
|
43
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
44
|
+
if (_i == null) return;
|
|
45
|
+
var _arr = [];
|
|
46
|
+
var _n = true;
|
|
47
|
+
var _d = false;
|
|
48
|
+
var _s, _e;
|
|
49
|
+
try {
|
|
50
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
51
|
+
_arr.push(_s.value);
|
|
52
|
+
if (i && _arr.length === i) break;
|
|
53
|
+
}
|
|
54
|
+
} catch (err) {
|
|
55
|
+
_d = true;
|
|
56
|
+
_e = err;
|
|
57
|
+
} finally{
|
|
58
|
+
try {
|
|
59
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
60
|
+
} finally{
|
|
61
|
+
if (_d) throw _e;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return _arr;
|
|
65
|
+
}
|
|
66
|
+
function _non_iterable_rest() {
|
|
67
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
68
|
+
}
|
|
69
|
+
function _object_spread(target) {
|
|
70
|
+
for(var i = 1; i < arguments.length; i++){
|
|
71
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
72
|
+
var ownKeys = Object.keys(source);
|
|
73
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
74
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
75
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
ownKeys.forEach(function(key) {
|
|
79
|
+
_define_property(target, key, source[key]);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return target;
|
|
83
|
+
}
|
|
84
|
+
function ownKeys(object, enumerableOnly) {
|
|
85
|
+
var keys = Object.keys(object);
|
|
86
|
+
if (Object.getOwnPropertySymbols) {
|
|
87
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
88
|
+
if (enumerableOnly) {
|
|
89
|
+
symbols = symbols.filter(function(sym) {
|
|
90
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
keys.push.apply(keys, symbols);
|
|
94
|
+
}
|
|
95
|
+
return keys;
|
|
96
|
+
}
|
|
97
|
+
function _object_spread_props(target, source) {
|
|
98
|
+
source = source != null ? source : {};
|
|
99
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
100
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
101
|
+
} else {
|
|
102
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
103
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return target;
|
|
107
|
+
}
|
|
108
|
+
function _sliced_to_array(arr, i) {
|
|
109
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
110
|
+
}
|
|
111
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
112
|
+
if (!o) return;
|
|
113
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
114
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
115
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
116
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
117
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
118
|
+
}
|
|
119
|
+
var _loop = function(letter) {
|
|
120
|
+
lineAlphabet[letter] = [];
|
|
121
|
+
var segs = svgAlphabet[letter].split("M").slice(1).map(function(seg) {
|
|
122
|
+
return seg.split("L").map(function(pr) {
|
|
123
|
+
return pr.trim().split(" ").map(parseFloat);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
127
|
+
try {
|
|
128
|
+
for(var _iterator = segs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
129
|
+
var seg = _step.value;
|
|
130
|
+
for(var i = 0; i < seg.length - 1; i++){
|
|
131
|
+
lineAlphabet[letter].push({
|
|
132
|
+
x1: seg[i][0],
|
|
133
|
+
y1: 1 - seg[i][1],
|
|
134
|
+
x2: seg[i + 1][0],
|
|
135
|
+
y2: 1 - seg[i + 1][1]
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
} catch (err) {
|
|
140
|
+
_didIteratorError = true;
|
|
141
|
+
_iteratorError = err;
|
|
142
|
+
} finally{
|
|
143
|
+
try {
|
|
144
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
145
|
+
_iterator.return();
|
|
146
|
+
}
|
|
147
|
+
} finally{
|
|
148
|
+
if (_didIteratorError) {
|
|
149
|
+
throw _iteratorError;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
};
|
|
1
154
|
var __create = Object.create;
|
|
2
155
|
var __defProp = Object.defineProperty;
|
|
3
156
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
157
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
158
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
159
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __commonJS = (cb, mod)
|
|
8
|
-
|
|
160
|
+
var __commonJS = function(cb, mod) {
|
|
161
|
+
return function __require() {
|
|
162
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = {
|
|
163
|
+
exports: {}
|
|
164
|
+
}).exports, mod), mod.exports;
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
var __export = function(target, all) {
|
|
168
|
+
for(var name in all)__defProp(target, name, {
|
|
169
|
+
get: all[name],
|
|
170
|
+
enumerable: true
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
var __copyProps = function(to, from, except, desc) {
|
|
174
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
175
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
176
|
+
try {
|
|
177
|
+
var _loop = function() {
|
|
178
|
+
var key = _step.value;
|
|
179
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
180
|
+
get: function() {
|
|
181
|
+
return from[key];
|
|
182
|
+
},
|
|
183
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
187
|
+
} catch (err) {
|
|
188
|
+
_didIteratorError = true;
|
|
189
|
+
_iteratorError = err;
|
|
190
|
+
} finally{
|
|
191
|
+
try {
|
|
192
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
193
|
+
_iterator.return();
|
|
194
|
+
}
|
|
195
|
+
} finally{
|
|
196
|
+
if (_didIteratorError) {
|
|
197
|
+
throw _iteratorError;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return to;
|
|
9
203
|
};
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
204
|
+
var __toESM = function(mod, isNodeMode, target) {
|
|
205
|
+
return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
|
|
206
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
207
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
208
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
209
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
210
|
+
value: mod,
|
|
211
|
+
enumerable: true
|
|
212
|
+
}) : target, mod);
|
|
13
213
|
};
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
214
|
+
var __toCommonJS = function(mod) {
|
|
215
|
+
return __copyProps(__defProp({}, "__esModule", {
|
|
216
|
+
value: true
|
|
217
|
+
}), mod);
|
|
21
218
|
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
-
mod
|
|
25
|
-
));
|
|
26
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
-
|
|
28
219
|
// node_modules/use-mouse-matrix-transform/dist/index.js
|
|
29
220
|
var require_dist = __commonJS({
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
42
|
-
for (let key of __getOwnPropNames2(from))
|
|
43
|
-
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
44
|
-
__defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
|
45
|
-
}
|
|
46
|
-
return to;
|
|
47
|
-
};
|
|
48
|
-
var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
|
|
49
|
-
var src_exports2 = {};
|
|
50
|
-
__export2(src_exports2, {
|
|
51
|
-
default: () => src_default,
|
|
52
|
-
useMouseMatrixTransform: () => useMouseMatrixTransform2
|
|
53
|
-
});
|
|
54
|
-
module2.exports = __toCommonJS2(src_exports2);
|
|
55
|
-
var import_transformation_matrix4 = require("transformation-matrix");
|
|
56
|
-
var import_react7 = require("react");
|
|
57
|
-
var useMouseMatrixTransform2 = (props = {}) => {
|
|
58
|
-
const extRef = (0, import_react7.useRef)(null);
|
|
59
|
-
const outerCanvasElm = props.canvasElm ?? extRef.current;
|
|
60
|
-
const [internalTransform, setInternalTransform] = (0, import_react7.useState)(
|
|
61
|
-
props.initialTransform ?? (0, import_transformation_matrix4.identity)()
|
|
62
|
-
);
|
|
63
|
-
const [waitCounter, setWaitCounter] = (0, import_react7.useState)(0);
|
|
64
|
-
const [extChangeCounter, incExtChangeCounter] = (0, import_react7.useReducer)((s) => s + 1, 0);
|
|
65
|
-
const setTransform = (0, import_react7.useCallback)(
|
|
66
|
-
(newTransform) => {
|
|
67
|
-
if (props.onSetTransform) {
|
|
68
|
-
props.onSetTransform(newTransform);
|
|
69
|
-
}
|
|
70
|
-
if (!props.transform) {
|
|
71
|
-
setInternalTransform(newTransform);
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
[props.onSetTransform, setInternalTransform]
|
|
75
|
-
);
|
|
76
|
-
const setTransformExt = (0, import_react7.useCallback)(
|
|
77
|
-
(newTransform) => {
|
|
78
|
-
setTransform(newTransform);
|
|
79
|
-
incExtChangeCounter();
|
|
80
|
-
},
|
|
81
|
-
[setTransform]
|
|
82
|
-
);
|
|
83
|
-
const transform = props.transform ?? internalTransform;
|
|
84
|
-
(0, import_react7.useEffect)(() => {
|
|
85
|
-
const canvasElm = props.canvasElm ?? extRef.current;
|
|
86
|
-
if (canvasElm && !outerCanvasElm) {
|
|
87
|
-
setWaitCounter(waitCounter + 1);
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
if (!canvasElm) {
|
|
91
|
-
const timeout = setTimeout(() => {
|
|
92
|
-
setWaitCounter(waitCounter + 1);
|
|
93
|
-
}, 100);
|
|
94
|
-
return () => clearTimeout(timeout);
|
|
95
|
-
}
|
|
96
|
-
let init_tf = props.transform ?? internalTransform;
|
|
97
|
-
let m0 = { x: 0, y: 0 }, m1 = { x: 0, y: 0 }, md = false, mlastrel = { x: 0, y: 0 };
|
|
98
|
-
const getMousePos = (e) => {
|
|
99
|
-
return {
|
|
100
|
-
x: e.pageX - canvasElm.getBoundingClientRect().left - window.scrollX,
|
|
101
|
-
y: e.pageY - canvasElm.getBoundingClientRect().top - window.scrollY
|
|
102
|
-
};
|
|
221
|
+
"node_modules/use-mouse-matrix-transform/dist/index.js": function(exports2, module2) {
|
|
222
|
+
"use strict";
|
|
223
|
+
var __defProp2 = Object.defineProperty;
|
|
224
|
+
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
225
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
226
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
227
|
+
var __export2 = function(target, all) {
|
|
228
|
+
for(var name in all)__defProp2(target, name, {
|
|
229
|
+
get: all[name],
|
|
230
|
+
enumerable: true
|
|
231
|
+
});
|
|
103
232
|
};
|
|
104
|
-
function
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
function handleMouseOut(e) {
|
|
136
|
-
if (!md)
|
|
137
|
-
return;
|
|
138
|
-
md = false;
|
|
139
|
-
m1 = getMousePos(e);
|
|
140
|
-
const new_tf = (0, import_transformation_matrix4.compose)((0, import_transformation_matrix4.translate)(m1.x - m0.x, m1.y - m0.y), init_tf);
|
|
141
|
-
setTransform(new_tf);
|
|
142
|
-
init_tf = new_tf;
|
|
143
|
-
}
|
|
144
|
-
canvasElm.addEventListener("mousedown", handleMouseDown);
|
|
145
|
-
canvasElm.addEventListener("mouseup", handleMouseUp);
|
|
146
|
-
canvasElm.addEventListener("mousemove", handleMouseMove);
|
|
147
|
-
canvasElm.addEventListener("mouseout", handleMouseOut);
|
|
148
|
-
canvasElm.addEventListener("wheel", handleMouseWheel);
|
|
149
|
-
return () => {
|
|
150
|
-
canvasElm.removeEventListener("mousedown", handleMouseDown);
|
|
151
|
-
canvasElm.removeEventListener("mouseup", handleMouseUp);
|
|
152
|
-
canvasElm.removeEventListener("mousemove", handleMouseMove);
|
|
153
|
-
canvasElm.removeEventListener("mouseout", handleMouseOut);
|
|
154
|
-
canvasElm.removeEventListener("wheel", handleMouseWheel);
|
|
233
|
+
var __copyProps2 = function(to, from, except, desc) {
|
|
234
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
235
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
236
|
+
try {
|
|
237
|
+
var _loop = function() {
|
|
238
|
+
var key = _step.value;
|
|
239
|
+
if (!__hasOwnProp2.call(to, key) && key !== except) __defProp2(to, key, {
|
|
240
|
+
get: function() {
|
|
241
|
+
return from[key];
|
|
242
|
+
},
|
|
243
|
+
enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
for(var _iterator = __getOwnPropNames2(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
247
|
+
} catch (err) {
|
|
248
|
+
_didIteratorError = true;
|
|
249
|
+
_iteratorError = err;
|
|
250
|
+
} finally{
|
|
251
|
+
try {
|
|
252
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
253
|
+
_iterator.return();
|
|
254
|
+
}
|
|
255
|
+
} finally{
|
|
256
|
+
if (_didIteratorError) {
|
|
257
|
+
throw _iteratorError;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return to;
|
|
155
263
|
};
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
264
|
+
var __toCommonJS2 = function(mod) {
|
|
265
|
+
return __copyProps2(__defProp2({}, "__esModule", {
|
|
266
|
+
value: true
|
|
267
|
+
}), mod);
|
|
268
|
+
};
|
|
269
|
+
var src_exports2 = {};
|
|
270
|
+
__export2(src_exports2, {
|
|
271
|
+
default: function() {
|
|
272
|
+
return src_default;
|
|
273
|
+
},
|
|
274
|
+
useMouseMatrixTransform: function() {
|
|
275
|
+
return useMouseMatrixTransform2;
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
module2.exports = __toCommonJS2(src_exports2);
|
|
279
|
+
var import_transformation_matrix4 = require("transformation-matrix");
|
|
280
|
+
var import_react10 = require("react");
|
|
281
|
+
var useMouseMatrixTransform2 = function() {
|
|
282
|
+
var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
283
|
+
var extRef = (0, import_react10.useRef)(null);
|
|
284
|
+
var _props_canvasElm;
|
|
285
|
+
var outerCanvasElm = (_props_canvasElm = props.canvasElm) !== null && _props_canvasElm !== void 0 ? _props_canvasElm : extRef.current;
|
|
286
|
+
var _props_initialTransform;
|
|
287
|
+
var _ref = _sliced_to_array((0, import_react10.useState)((_props_initialTransform = props.initialTransform) !== null && _props_initialTransform !== void 0 ? _props_initialTransform : (0, import_transformation_matrix4.identity)()), 2), internalTransform = _ref[0], setInternalTransform = _ref[1];
|
|
288
|
+
var _ref1 = _sliced_to_array((0, import_react10.useState)(0), 2), waitCounter = _ref1[0], setWaitCounter = _ref1[1];
|
|
289
|
+
var _ref2 = _sliced_to_array((0, import_react10.useReducer)(function(s) {
|
|
290
|
+
return s + 1;
|
|
291
|
+
}, 0), 2), extChangeCounter = _ref2[0], incExtChangeCounter = _ref2[1];
|
|
292
|
+
var setTransform = (0, import_react10.useCallback)(function(newTransform) {
|
|
293
|
+
if (props.onSetTransform) {
|
|
294
|
+
props.onSetTransform(newTransform);
|
|
295
|
+
}
|
|
296
|
+
if (!props.transform) {
|
|
297
|
+
setInternalTransform(newTransform);
|
|
298
|
+
}
|
|
299
|
+
}, [
|
|
300
|
+
props.onSetTransform,
|
|
301
|
+
setInternalTransform
|
|
302
|
+
]);
|
|
303
|
+
var setTransformExt = (0, import_react10.useCallback)(function(newTransform) {
|
|
304
|
+
setTransform(newTransform);
|
|
305
|
+
incExtChangeCounter();
|
|
306
|
+
}, [
|
|
307
|
+
setTransform
|
|
308
|
+
]);
|
|
309
|
+
var _props_transform;
|
|
310
|
+
var transform = (_props_transform = props.transform) !== null && _props_transform !== void 0 ? _props_transform : internalTransform;
|
|
311
|
+
(0, import_react10.useEffect)(function() {
|
|
312
|
+
var handleMouseDown = function handleMouseDown(e) {
|
|
313
|
+
m0 = getMousePos(e);
|
|
314
|
+
md = true;
|
|
315
|
+
e.preventDefault();
|
|
316
|
+
};
|
|
317
|
+
var handleMouseUp = function handleMouseUp(e) {
|
|
318
|
+
m1 = getMousePos(e);
|
|
319
|
+
var new_tf = (0, import_transformation_matrix4.compose)((0, import_transformation_matrix4.translate)(m1.x - m0.x, m1.y - m0.y), init_tf);
|
|
320
|
+
setTransform(new_tf);
|
|
321
|
+
init_tf = new_tf;
|
|
322
|
+
md = false;
|
|
323
|
+
};
|
|
324
|
+
var handleMouseMove = function handleMouseMove(e) {
|
|
325
|
+
mlastrel = getMousePos(e);
|
|
326
|
+
if (!md) return;
|
|
327
|
+
m1 = getMousePos(e);
|
|
328
|
+
setTransform((0, import_transformation_matrix4.compose)((0, import_transformation_matrix4.translate)(m1.x - m0.x, m1.y - m0.y), init_tf));
|
|
329
|
+
};
|
|
330
|
+
var handleMouseWheel = function handleMouseWheel(e) {
|
|
331
|
+
var center = getMousePos(e);
|
|
332
|
+
var new_tf = (0, import_transformation_matrix4.compose)((0, import_transformation_matrix4.translate)(center.x, center.y), (0, import_transformation_matrix4.scale)(1 - e.deltaY / 1e3, 1 - e.deltaY / 1e3), (0, import_transformation_matrix4.translate)(-center.x, -center.y), init_tf);
|
|
333
|
+
setTransform(new_tf);
|
|
334
|
+
init_tf = new_tf;
|
|
335
|
+
e.preventDefault();
|
|
336
|
+
};
|
|
337
|
+
var handleMouseOut = function handleMouseOut(e) {
|
|
338
|
+
if (!md) return;
|
|
339
|
+
md = false;
|
|
340
|
+
m1 = getMousePos(e);
|
|
341
|
+
var new_tf = (0, import_transformation_matrix4.compose)((0, import_transformation_matrix4.translate)(m1.x - m0.x, m1.y - m0.y), init_tf);
|
|
342
|
+
setTransform(new_tf);
|
|
343
|
+
init_tf = new_tf;
|
|
344
|
+
};
|
|
345
|
+
var _props_canvasElm;
|
|
346
|
+
var canvasElm = (_props_canvasElm = props.canvasElm) !== null && _props_canvasElm !== void 0 ? _props_canvasElm : extRef.current;
|
|
347
|
+
if (canvasElm && !outerCanvasElm) {
|
|
348
|
+
setWaitCounter(waitCounter + 1);
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
if (!canvasElm) {
|
|
352
|
+
var timeout = setTimeout(function() {
|
|
353
|
+
setWaitCounter(waitCounter + 1);
|
|
354
|
+
}, 100);
|
|
355
|
+
return function() {
|
|
356
|
+
return clearTimeout(timeout);
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
var _props_transform;
|
|
360
|
+
var init_tf = (_props_transform = props.transform) !== null && _props_transform !== void 0 ? _props_transform : internalTransform;
|
|
361
|
+
var m0 = {
|
|
362
|
+
x: 0,
|
|
363
|
+
y: 0
|
|
364
|
+
}, m1 = {
|
|
365
|
+
x: 0,
|
|
366
|
+
y: 0
|
|
367
|
+
}, md = false, mlastrel = {
|
|
368
|
+
x: 0,
|
|
369
|
+
y: 0
|
|
370
|
+
};
|
|
371
|
+
var getMousePos = function(e) {
|
|
372
|
+
return {
|
|
373
|
+
x: e.pageX - canvasElm.getBoundingClientRect().left - window.scrollX,
|
|
374
|
+
y: e.pageY - canvasElm.getBoundingClientRect().top - window.scrollY
|
|
375
|
+
};
|
|
376
|
+
};
|
|
377
|
+
canvasElm.addEventListener("mousedown", handleMouseDown);
|
|
378
|
+
canvasElm.addEventListener("mouseup", handleMouseUp);
|
|
379
|
+
canvasElm.addEventListener("mousemove", handleMouseMove);
|
|
380
|
+
canvasElm.addEventListener("mouseout", handleMouseOut);
|
|
381
|
+
canvasElm.addEventListener("wheel", handleMouseWheel);
|
|
382
|
+
return function() {
|
|
383
|
+
canvasElm.removeEventListener("mousedown", handleMouseDown);
|
|
384
|
+
canvasElm.removeEventListener("mouseup", handleMouseUp);
|
|
385
|
+
canvasElm.removeEventListener("mousemove", handleMouseMove);
|
|
386
|
+
canvasElm.removeEventListener("mouseout", handleMouseOut);
|
|
387
|
+
canvasElm.removeEventListener("wheel", handleMouseWheel);
|
|
388
|
+
};
|
|
389
|
+
}, [
|
|
390
|
+
outerCanvasElm,
|
|
391
|
+
waitCounter,
|
|
392
|
+
extChangeCounter
|
|
393
|
+
]);
|
|
394
|
+
var applyTransformToPoint = (0, import_react10.useCallback)(function(obj) {
|
|
395
|
+
return (0, import_transformation_matrix4.applyToPoint)(transform, obj);
|
|
396
|
+
}, [
|
|
397
|
+
transform
|
|
398
|
+
]);
|
|
399
|
+
return {
|
|
400
|
+
ref: extRef,
|
|
401
|
+
transform: transform,
|
|
402
|
+
applyTransformToPoint: applyTransformToPoint,
|
|
403
|
+
setTransform: setTransformExt
|
|
404
|
+
};
|
|
405
|
+
};
|
|
406
|
+
var src_default = useMouseMatrixTransform2;
|
|
407
|
+
}
|
|
170
408
|
});
|
|
171
|
-
|
|
172
409
|
// src/index.tsx
|
|
173
410
|
var src_exports = {};
|
|
174
411
|
__export(src_exports, {
|
|
175
|
-
|
|
176
|
-
|
|
412
|
+
CanvasElementsRenderer: function() {
|
|
413
|
+
return CanvasElementsRenderer;
|
|
414
|
+
},
|
|
415
|
+
PCBViewer: function() {
|
|
416
|
+
return PCBViewer;
|
|
417
|
+
}
|
|
177
418
|
});
|
|
178
419
|
module.exports = __toCommonJS(src_exports);
|
|
179
|
-
|
|
180
420
|
// src/PCBViewer.tsx
|
|
181
|
-
var
|
|
421
|
+
var import_react9 = __toESM(require("react"));
|
|
182
422
|
var import_react_fiber = require("@tscircuit/react-fiber");
|
|
183
423
|
var import_builder = require("@tscircuit/builder");
|
|
184
|
-
|
|
185
424
|
// src/components/CanvasElementsRenderer.tsx
|
|
186
|
-
var
|
|
187
|
-
|
|
425
|
+
var import_react5 = __toESM(require("react"));
|
|
188
426
|
// src/components/CanvasPrimitiveRenderer.tsx
|
|
189
427
|
var import_react_supergrid = require("react-supergrid");
|
|
190
428
|
var import_react = __toESM(require("react"));
|
|
191
|
-
|
|
192
429
|
// src/assets/alphabet.ts
|
|
193
430
|
var svgAlphabet = {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
431
|
+
"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",
|
|
432
|
+
"1": "M 0.198 0.272 L 0.537 0 L 0.54 1",
|
|
433
|
+
"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",
|
|
434
|
+
"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",
|
|
435
|
+
"4": "M0.7328897338403042 0L0 0.6684672518568535L1 0.6684672518568535M0.7243346007604563 0.4530722484807562L0.7243346007604563 1",
|
|
436
|
+
"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",
|
|
437
|
+
"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",
|
|
438
|
+
"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",
|
|
439
|
+
"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",
|
|
440
|
+
"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",
|
|
441
|
+
A: "M0 1L0.4808333333333333 0L1 1M0.24250000000000002 0.6099439775910365L0.7341666666666666 0.6099439775910365",
|
|
442
|
+
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",
|
|
443
|
+
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",
|
|
444
|
+
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",
|
|
445
|
+
E: "M0 0L0 1M0 0L1 0M0 0.5L0.7 0.5M0 1L1 1",
|
|
446
|
+
F: "M0 0L0 1M0.011363636363636364 0.006802721088435374L1 0.006802721088435374M0.011363636363636364 0.4965986394557823L0.8409090909090909 0.4965986394557823",
|
|
447
|
+
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",
|
|
448
|
+
H: "M0 0L0 1M0 0.4788732394366197L0.989010989010989 0.4788732394366197M1 0L1 1",
|
|
449
|
+
I: "MNaN 0LNaN 1",
|
|
450
|
+
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",
|
|
451
|
+
K: "M0 0L0 1M0.8787878787878788 0.06666666666666667L0 0.6148148148148148M0.3333333333333333 0.45925925925925926L1 0.9777777777777777",
|
|
452
|
+
L: "M0 0L0 1L1 1",
|
|
453
|
+
M: "M0 1L0 0L0.5 0.6512L1 0L1 1",
|
|
454
|
+
N: "M0 1L0 0L1 1L0.9803729146221786 0",
|
|
455
|
+
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",
|
|
456
|
+
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",
|
|
457
|
+
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",
|
|
458
|
+
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",
|
|
459
|
+
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",
|
|
460
|
+
T: "M0 0L1 0M0.5148514851485149 0L0.5148514851485149 1",
|
|
461
|
+
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",
|
|
462
|
+
V: "M0 0L0.5348837209302325 1L1 0",
|
|
463
|
+
W: "M0 0L0.23300090661831369 0.9873417721518988L0.49954669084315495 0.30081906180193585L0.7851314596554849 1L1 0.0215934475055845",
|
|
464
|
+
X: "M0 0L0.9893617021276596 1M1 0L0.010638297872340425 1",
|
|
465
|
+
Y: "M0 0L0.4860515021459227 0.44712562100780695M1 0.0014194464158977947L0.48927038626609437 0.44996451383960256L0.5075107296137339 1",
|
|
466
|
+
Z: "M0 0L1 0L0 1L1 1",
|
|
467
|
+
".": "M 0.49 1 L 0.41 1"
|
|
231
468
|
};
|
|
232
469
|
var lineAlphabet = {};
|
|
233
|
-
for
|
|
234
|
-
lineAlphabet[letter] = [];
|
|
235
|
-
const segs = svgAlphabet[letter].split("M").slice(1).map(
|
|
236
|
-
(seg) => seg.split("L").map((pr) => pr.trim().split(" ").map(parseFloat))
|
|
237
|
-
);
|
|
238
|
-
for (const seg of segs) {
|
|
239
|
-
for (let i = 0; i < seg.length - 1; i++) {
|
|
240
|
-
lineAlphabet[letter].push({
|
|
241
|
-
x1: seg[i][0],
|
|
242
|
-
y1: 1 - seg[i][1],
|
|
243
|
-
x2: seg[i + 1][0],
|
|
244
|
-
y2: 1 - seg[i + 1][1]
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
470
|
+
for(var letter in svgAlphabet)_loop(letter);
|
|
250
471
|
// src/lib/convert-text-to-lines.ts
|
|
251
|
-
var convertTextToLines = (text)
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
472
|
+
var convertTextToLines = function(text) {
|
|
473
|
+
var strokeWidth = text.size / 8;
|
|
474
|
+
var letterWidth = text.size * 0.6;
|
|
475
|
+
var letterSpace = text.size * 0.2;
|
|
476
|
+
var lines = [];
|
|
477
|
+
for(var letterIndex = 0; letterIndex < text.text.length; letterIndex++){
|
|
478
|
+
var letter = text.text[letterIndex];
|
|
479
|
+
var letterLines = lineAlphabet[letter.toUpperCase()];
|
|
480
|
+
if (!letterLines) continue;
|
|
481
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
482
|
+
try {
|
|
483
|
+
for(var _iterator = letterLines[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
484
|
+
var _step_value = _step.value, x1 = _step_value.x1, y1 = _step_value.y1, x2 = _step_value.x2, y2 = _step_value.y2;
|
|
485
|
+
lines.push({
|
|
486
|
+
pcb_drawing_type: "line",
|
|
487
|
+
x1: text.x + (letterWidth + letterSpace) * letterIndex + letterWidth * x1,
|
|
488
|
+
y1: text.y + text.size * y1,
|
|
489
|
+
x2: text.x + (letterWidth + letterSpace) * letterIndex + letterWidth * x2,
|
|
490
|
+
y2: text.y + text.size * y2,
|
|
491
|
+
width: strokeWidth,
|
|
492
|
+
layer: text.layer,
|
|
493
|
+
unit: text.unit
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
} catch (err) {
|
|
497
|
+
_didIteratorError = true;
|
|
498
|
+
_iteratorError = err;
|
|
499
|
+
} finally{
|
|
500
|
+
try {
|
|
501
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
502
|
+
_iterator.return();
|
|
503
|
+
}
|
|
504
|
+
} finally{
|
|
505
|
+
if (_didIteratorError) {
|
|
506
|
+
throw _iteratorError;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
272
510
|
}
|
|
273
|
-
|
|
274
|
-
return lines;
|
|
511
|
+
return lines;
|
|
275
512
|
};
|
|
276
|
-
|
|
277
513
|
// src/lib/draw-primitives.ts
|
|
278
|
-
var drawLine = (drawer, line)
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
514
|
+
var drawLine = function(drawer, line) {
|
|
515
|
+
drawer.equip({
|
|
516
|
+
size: line.width,
|
|
517
|
+
shape: line.squareCap ? "square" : "circle",
|
|
518
|
+
color: line.layer
|
|
519
|
+
});
|
|
520
|
+
drawer.moveTo(line.x1, line.y1);
|
|
521
|
+
drawer.lineTo(line.x2, line.y2);
|
|
286
522
|
};
|
|
287
|
-
var drawText = (drawer, text)
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
523
|
+
var drawText = function(drawer, text) {
|
|
524
|
+
drawer.equip({
|
|
525
|
+
fontSize: text.size,
|
|
526
|
+
color: text.layer
|
|
527
|
+
});
|
|
528
|
+
if (text.align && text.align !== "top-left") {
|
|
529
|
+
console.warn("Unhandled text align", text.align);
|
|
530
|
+
}
|
|
531
|
+
var lines = convertTextToLines(text);
|
|
532
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
533
|
+
try {
|
|
534
|
+
for(var _iterator = lines[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
535
|
+
var line = _step.value;
|
|
536
|
+
drawLine(drawer, line);
|
|
537
|
+
}
|
|
538
|
+
} catch (err) {
|
|
539
|
+
_didIteratorError = true;
|
|
540
|
+
_iteratorError = err;
|
|
541
|
+
} finally{
|
|
542
|
+
try {
|
|
543
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
544
|
+
_iterator.return();
|
|
545
|
+
}
|
|
546
|
+
} finally{
|
|
547
|
+
if (_didIteratorError) {
|
|
548
|
+
throw _iteratorError;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
299
552
|
};
|
|
300
|
-
var drawRect = (drawer, rect)
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
553
|
+
var drawRect = function(drawer, rect) {
|
|
554
|
+
drawer.equip({
|
|
555
|
+
color: rect.layer
|
|
556
|
+
});
|
|
557
|
+
if (rect.align && rect.align !== "center") {
|
|
558
|
+
console.warn("Unhandled rect align", rect.align);
|
|
559
|
+
}
|
|
560
|
+
drawer.rect(rect.x, rect.y, rect.w, rect.h);
|
|
308
561
|
};
|
|
309
|
-
var drawCircle = (drawer, circle)
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
562
|
+
var drawCircle = function(drawer, circle) {
|
|
563
|
+
drawer.equip({
|
|
564
|
+
color: circle.layer
|
|
565
|
+
});
|
|
566
|
+
drawer.circle(circle.x, circle.y, circle.r);
|
|
314
567
|
};
|
|
315
|
-
var drawPrimitive = (drawer, primitive)
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
`Unknown primitive type: ${primitive.pcb_drawing_type}`
|
|
328
|
-
);
|
|
568
|
+
var drawPrimitive = function(drawer, primitive) {
|
|
569
|
+
switch(primitive.pcb_drawing_type){
|
|
570
|
+
case "line":
|
|
571
|
+
return drawLine(drawer, primitive);
|
|
572
|
+
case "text":
|
|
573
|
+
return drawText(drawer, primitive);
|
|
574
|
+
case "rect":
|
|
575
|
+
return drawRect(drawer, primitive);
|
|
576
|
+
case "circle":
|
|
577
|
+
return drawCircle(drawer, primitive);
|
|
578
|
+
}
|
|
579
|
+
throw new Error("Unknown primitive type: ".concat(primitive.pcb_drawing_type));
|
|
329
580
|
};
|
|
330
|
-
var drawPrimitives = (drawer, primitives)
|
|
331
|
-
|
|
581
|
+
var drawPrimitives = function(drawer, primitives) {
|
|
582
|
+
primitives.sort(function(a, b) {
|
|
583
|
+
var layerOrder = [
|
|
584
|
+
"bottom",
|
|
585
|
+
"top",
|
|
586
|
+
"drill"
|
|
587
|
+
];
|
|
588
|
+
return layerOrder.indexOf(a.layer) - layerOrder.indexOf(b.layer);
|
|
589
|
+
});
|
|
590
|
+
primitives.forEach(function(primitive) {
|
|
591
|
+
return drawPrimitive(drawer, primitive);
|
|
592
|
+
});
|
|
332
593
|
};
|
|
333
|
-
|
|
334
594
|
// src/lib/util/scale-only.ts
|
|
335
|
-
var scaleOnly = (mat
|
|
336
|
-
|
|
337
|
-
throw new Error("Cannot scale non-uniformly");
|
|
338
|
-
|
|
595
|
+
var scaleOnly = function(mat) {
|
|
596
|
+
var value = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
|
|
597
|
+
if (Math.abs(mat.a) !== Math.abs(mat.d)) throw new Error("Cannot scale non-uniformly");
|
|
598
|
+
return value * Math.abs(mat.a);
|
|
339
599
|
};
|
|
340
|
-
|
|
341
600
|
// src/lib/Drawer.ts
|
|
342
601
|
var import_transformation_matrix = require("transformation-matrix");
|
|
343
|
-
|
|
344
602
|
// src/lib/colors.ts
|
|
345
603
|
var colors_default = {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
},
|
|
356
|
-
board: {
|
|
357
|
-
anchor: "rgb(255, 38, 226)",
|
|
358
|
-
aux_items: "rgb(255, 255, 255)",
|
|
359
|
-
b_adhes: "rgb(0, 0, 132)",
|
|
360
|
-
b_crtyd: "rgb(255, 38, 226)",
|
|
361
|
-
b_fab: "rgb(88, 93, 132)",
|
|
362
|
-
b_mask: "rgba(2, 255, 238, 0.400)",
|
|
363
|
-
b_paste: "rgb(0, 194, 194)",
|
|
364
|
-
b_silks: "rgb(232, 178, 167)",
|
|
365
|
-
background: "rgb(0, 16, 35)",
|
|
366
|
-
cmts_user: "rgb(89, 148, 220)",
|
|
367
|
-
copper: {
|
|
368
|
-
b: "rgb(77, 127, 196)",
|
|
369
|
-
f: "rgb(200, 52, 52)",
|
|
370
|
-
in1: "rgb(127, 200, 127)",
|
|
371
|
-
in10: "rgb(237, 124, 51)",
|
|
372
|
-
in11: "rgb(91, 195, 235)",
|
|
373
|
-
in12: "rgb(247, 111, 142)",
|
|
374
|
-
in13: "rgb(167, 165, 198)",
|
|
375
|
-
in14: "rgb(40, 204, 217)",
|
|
376
|
-
in15: "rgb(232, 178, 167)",
|
|
377
|
-
in16: "rgb(242, 237, 161)",
|
|
378
|
-
in17: "rgb(237, 124, 51)",
|
|
379
|
-
in18: "rgb(91, 195, 235)",
|
|
380
|
-
in19: "rgb(247, 111, 142)",
|
|
381
|
-
in2: "rgb(206, 125, 44)",
|
|
382
|
-
in20: "rgb(167, 165, 198)",
|
|
383
|
-
in21: "rgb(40, 204, 217)",
|
|
384
|
-
in22: "rgb(232, 178, 167)",
|
|
385
|
-
in23: "rgb(242, 237, 161)",
|
|
386
|
-
in24: "rgb(237, 124, 51)",
|
|
387
|
-
in25: "rgb(91, 195, 235)",
|
|
388
|
-
in26: "rgb(247, 111, 142)",
|
|
389
|
-
in27: "rgb(167, 165, 198)",
|
|
390
|
-
in28: "rgb(40, 204, 217)",
|
|
391
|
-
in29: "rgb(232, 178, 167)",
|
|
392
|
-
in3: "rgb(79, 203, 203)",
|
|
393
|
-
in30: "rgb(242, 237, 161)",
|
|
394
|
-
in4: "rgb(219, 98, 139)",
|
|
395
|
-
in5: "rgb(167, 165, 198)",
|
|
396
|
-
in6: "rgb(40, 204, 217)",
|
|
397
|
-
in7: "rgb(232, 178, 167)",
|
|
398
|
-
in8: "rgb(242, 237, 161)",
|
|
399
|
-
in9: "rgb(141, 203, 129)"
|
|
604
|
+
"3d_viewer": {
|
|
605
|
+
background_bottom: "rgb(102, 102, 128)",
|
|
606
|
+
background_top: "rgb(204, 204, 230)",
|
|
607
|
+
board: "rgb(51, 43, 23)",
|
|
608
|
+
copper: "rgb(179, 156, 0)",
|
|
609
|
+
silkscreen_bottom: "rgb(230, 230, 230)",
|
|
610
|
+
silkscreen_top: "rgb(230, 230, 230)",
|
|
611
|
+
soldermask: "rgb(20, 51, 36)",
|
|
612
|
+
solderpaste: "rgb(128, 128, 128)"
|
|
400
613
|
},
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
614
|
+
board: {
|
|
615
|
+
anchor: "rgb(255, 38, 226)",
|
|
616
|
+
aux_items: "rgb(255, 255, 255)",
|
|
617
|
+
b_adhes: "rgb(0, 0, 132)",
|
|
618
|
+
b_crtyd: "rgb(255, 38, 226)",
|
|
619
|
+
b_fab: "rgb(88, 93, 132)",
|
|
620
|
+
b_mask: "rgba(2, 255, 238, 0.400)",
|
|
621
|
+
b_paste: "rgb(0, 194, 194)",
|
|
622
|
+
b_silks: "rgb(232, 178, 167)",
|
|
623
|
+
background: "rgb(0, 16, 35)",
|
|
624
|
+
cmts_user: "rgb(89, 148, 220)",
|
|
625
|
+
copper: {
|
|
626
|
+
b: "rgb(77, 127, 196)",
|
|
627
|
+
f: "rgb(200, 52, 52)",
|
|
628
|
+
in1: "rgb(127, 200, 127)",
|
|
629
|
+
in10: "rgb(237, 124, 51)",
|
|
630
|
+
in11: "rgb(91, 195, 235)",
|
|
631
|
+
in12: "rgb(247, 111, 142)",
|
|
632
|
+
in13: "rgb(167, 165, 198)",
|
|
633
|
+
in14: "rgb(40, 204, 217)",
|
|
634
|
+
in15: "rgb(232, 178, 167)",
|
|
635
|
+
in16: "rgb(242, 237, 161)",
|
|
636
|
+
in17: "rgb(237, 124, 51)",
|
|
637
|
+
in18: "rgb(91, 195, 235)",
|
|
638
|
+
in19: "rgb(247, 111, 142)",
|
|
639
|
+
in2: "rgb(206, 125, 44)",
|
|
640
|
+
in20: "rgb(167, 165, 198)",
|
|
641
|
+
in21: "rgb(40, 204, 217)",
|
|
642
|
+
in22: "rgb(232, 178, 167)",
|
|
643
|
+
in23: "rgb(242, 237, 161)",
|
|
644
|
+
in24: "rgb(237, 124, 51)",
|
|
645
|
+
in25: "rgb(91, 195, 235)",
|
|
646
|
+
in26: "rgb(247, 111, 142)",
|
|
647
|
+
in27: "rgb(167, 165, 198)",
|
|
648
|
+
in28: "rgb(40, 204, 217)",
|
|
649
|
+
in29: "rgb(232, 178, 167)",
|
|
650
|
+
in3: "rgb(79, 203, 203)",
|
|
651
|
+
in30: "rgb(242, 237, 161)",
|
|
652
|
+
in4: "rgb(219, 98, 139)",
|
|
653
|
+
in5: "rgb(167, 165, 198)",
|
|
654
|
+
in6: "rgb(40, 204, 217)",
|
|
655
|
+
in7: "rgb(232, 178, 167)",
|
|
656
|
+
in8: "rgb(242, 237, 161)",
|
|
657
|
+
in9: "rgb(141, 203, 129)"
|
|
658
|
+
},
|
|
659
|
+
cursor: "rgb(255, 255, 255)",
|
|
660
|
+
drc: "rgb(194, 194, 194)",
|
|
661
|
+
drc_error: "rgba(215, 91, 107, 0.800)",
|
|
662
|
+
drc_exclusion: "rgb(255, 255, 255)",
|
|
663
|
+
drc_warning: "rgba(255, 208, 66, 0.902)",
|
|
664
|
+
dwgs_user: "rgb(194, 194, 194)",
|
|
665
|
+
eco1_user: "rgb(180, 219, 210)",
|
|
666
|
+
eco2_user: "rgb(216, 200, 82)",
|
|
667
|
+
edge_cuts: "rgb(208, 210, 205)",
|
|
668
|
+
f_adhes: "rgb(132, 0, 132)",
|
|
669
|
+
f_crtyd: "rgb(255, 0, 245)",
|
|
670
|
+
f_fab: "rgb(175, 175, 175)",
|
|
671
|
+
f_mask: "rgba(216, 100, 255, 0.400)",
|
|
672
|
+
f_paste: "rgba(180, 160, 154, 0.902)",
|
|
673
|
+
f_silks: "rgb(242, 237, 161)",
|
|
674
|
+
footprint_text_back: "rgb(0, 0, 132)",
|
|
675
|
+
footprint_text_front: "rgb(194, 194, 194)",
|
|
676
|
+
footprint_text_invisible: "rgb(132, 132, 132)",
|
|
677
|
+
grid: "rgb(132, 132, 132)",
|
|
678
|
+
grid_axes: "rgb(194, 194, 194)",
|
|
679
|
+
margin: "rgb(255, 38, 226)",
|
|
680
|
+
microvia: "rgb(0, 132, 132)",
|
|
681
|
+
no_connect: "rgb(0, 0, 132)",
|
|
682
|
+
pad_back: "rgb(77, 127, 196)",
|
|
683
|
+
pad_front: "rgb(200, 52, 52)",
|
|
684
|
+
pad_plated_hole: "rgb(194, 194, 0)",
|
|
685
|
+
pad_through_hole: "rgb(227, 183, 46)",
|
|
686
|
+
plated_hole: "rgb(26, 196, 210)",
|
|
687
|
+
ratsnest: "rgba(245, 255, 213, 0.702)",
|
|
688
|
+
select_overlay: "rgb(4, 255, 67)",
|
|
689
|
+
through_via: "rgb(236, 236, 236)",
|
|
690
|
+
user_1: "rgb(194, 194, 194)",
|
|
691
|
+
user_2: "rgb(89, 148, 220)",
|
|
692
|
+
user_3: "rgb(180, 219, 210)",
|
|
693
|
+
user_4: "rgb(216, 200, 82)",
|
|
694
|
+
user_5: "rgb(194, 194, 194)",
|
|
695
|
+
user_6: "rgb(89, 148, 220)",
|
|
696
|
+
user_7: "rgb(180, 219, 210)",
|
|
697
|
+
user_8: "rgb(216, 200, 82)",
|
|
698
|
+
user_9: "rgb(232, 178, 167)",
|
|
699
|
+
via_blind_buried: "rgb(187, 151, 38)",
|
|
700
|
+
via_hole: "rgb(227, 183, 46)",
|
|
701
|
+
via_micro: "rgb(0, 132, 132)",
|
|
702
|
+
via_through: "rgb(236, 236, 236)",
|
|
703
|
+
worksheet: "rgb(200, 114, 171)"
|
|
704
|
+
},
|
|
705
|
+
gerbview: {
|
|
706
|
+
axes: "rgb(0, 0, 132)",
|
|
707
|
+
background: "rgb(0, 0, 0)",
|
|
708
|
+
dcodes: "rgb(255, 255, 255)",
|
|
709
|
+
grid: "rgb(132, 132, 132)",
|
|
710
|
+
layers: [
|
|
711
|
+
"rgb(132, 0, 0)",
|
|
712
|
+
"rgb(194, 194, 0)",
|
|
713
|
+
"rgb(194, 0, 194)",
|
|
714
|
+
"rgb(194, 0, 0)",
|
|
715
|
+
"rgb(0, 132, 132)",
|
|
716
|
+
"rgb(0, 132, 0)",
|
|
717
|
+
"rgb(0, 0, 132)",
|
|
718
|
+
"rgb(132, 132, 132)",
|
|
719
|
+
"rgb(132, 0, 132)",
|
|
720
|
+
"rgb(194, 194, 194)",
|
|
721
|
+
"rgb(132, 0, 132)",
|
|
722
|
+
"rgb(132, 0, 0)",
|
|
723
|
+
"rgb(132, 132, 0)",
|
|
724
|
+
"rgb(194, 194, 194)",
|
|
725
|
+
"rgb(0, 0, 132)",
|
|
726
|
+
"rgb(0, 132, 0)",
|
|
727
|
+
"rgb(132, 0, 0)",
|
|
728
|
+
"rgb(194, 194, 0)",
|
|
729
|
+
"rgb(194, 0, 194)",
|
|
730
|
+
"rgb(194, 0, 0)",
|
|
731
|
+
"rgb(0, 132, 132)",
|
|
732
|
+
"rgb(0, 132, 0)",
|
|
733
|
+
"rgb(0, 0, 132)",
|
|
734
|
+
"rgb(132, 132, 132)",
|
|
735
|
+
"rgb(132, 0, 132)",
|
|
736
|
+
"rgb(194, 194, 194)",
|
|
737
|
+
"rgb(132, 0, 132)",
|
|
738
|
+
"rgb(132, 0, 0)",
|
|
739
|
+
"rgb(132, 132, 0)",
|
|
740
|
+
"rgb(194, 194, 194)",
|
|
741
|
+
"rgb(0, 0, 132)",
|
|
742
|
+
"rgb(0, 132, 0)",
|
|
743
|
+
"rgb(132, 0, 0)",
|
|
744
|
+
"rgb(194, 194, 0)",
|
|
745
|
+
"rgb(194, 0, 194)",
|
|
746
|
+
"rgb(194, 0, 0)",
|
|
747
|
+
"rgb(0, 132, 132)",
|
|
748
|
+
"rgb(0, 132, 0)",
|
|
749
|
+
"rgb(0, 0, 132)",
|
|
750
|
+
"rgb(132, 132, 132)",
|
|
751
|
+
"rgb(132, 0, 132)",
|
|
752
|
+
"rgb(194, 194, 194)",
|
|
753
|
+
"rgb(132, 0, 132)",
|
|
754
|
+
"rgb(132, 0, 0)",
|
|
755
|
+
"rgb(132, 132, 0)",
|
|
756
|
+
"rgb(194, 194, 194)",
|
|
757
|
+
"rgb(0, 0, 132)",
|
|
758
|
+
"rgb(0, 132, 0)",
|
|
759
|
+
"rgb(132, 0, 0)",
|
|
760
|
+
"rgb(194, 194, 0)",
|
|
761
|
+
"rgb(194, 0, 194)",
|
|
762
|
+
"rgb(194, 0, 0)",
|
|
763
|
+
"rgb(0, 132, 132)",
|
|
764
|
+
"rgb(0, 132, 0)",
|
|
765
|
+
"rgb(0, 0, 132)",
|
|
766
|
+
"rgb(132, 132, 132)",
|
|
767
|
+
"rgb(132, 0, 132)",
|
|
768
|
+
"rgb(194, 194, 194)",
|
|
769
|
+
"rgb(132, 0, 132)",
|
|
770
|
+
"rgb(132, 0, 0)"
|
|
771
|
+
],
|
|
772
|
+
negative_objects: "rgb(132, 132, 132)",
|
|
773
|
+
worksheet: "rgb(0, 0, 132)"
|
|
774
|
+
},
|
|
775
|
+
palette: [
|
|
776
|
+
"rgb(132, 0, 0)",
|
|
777
|
+
"rgb(194, 194, 0)",
|
|
778
|
+
"rgb(194, 0, 194)",
|
|
779
|
+
"rgb(194, 0, 0)",
|
|
780
|
+
"rgb(0, 132, 132)",
|
|
781
|
+
"rgb(0, 132, 0)",
|
|
782
|
+
"rgb(0, 0, 132)",
|
|
783
|
+
"rgb(132, 132, 132)",
|
|
784
|
+
"rgb(132, 0, 132)",
|
|
785
|
+
"rgb(194, 194, 194)",
|
|
786
|
+
"rgb(132, 0, 132)",
|
|
787
|
+
"rgb(132, 0, 0)",
|
|
788
|
+
"rgb(132, 132, 0)",
|
|
789
|
+
"rgb(194, 194, 194)",
|
|
790
|
+
"rgb(0, 0, 132)",
|
|
791
|
+
"rgb(0, 132, 0)"
|
|
513
792
|
],
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
label_global: "rgb(0, 160, 224)",
|
|
553
|
-
label_hier: "rgb(160, 160, 0)",
|
|
554
|
-
label_local: "rgb(192, 192, 192)",
|
|
555
|
-
net_name: "rgb(224, 224, 224)",
|
|
556
|
-
no_connect: "rgb(97, 43, 224)",
|
|
557
|
-
note: "rgb(192, 192, 0)",
|
|
558
|
-
override_item_colors: false,
|
|
559
|
-
pin: "rgb(192, 0, 0)",
|
|
560
|
-
pin_name: "rgb(192, 192, 192)",
|
|
561
|
-
pin_number: "rgb(192, 0, 0)",
|
|
562
|
-
reference: "rgb(192, 192, 192)",
|
|
563
|
-
shadow: "rgba(102, 179, 255, 0.800)",
|
|
564
|
-
sheet: "rgb(128, 0, 160)",
|
|
565
|
-
sheet_background: "rgba(255, 255, 255, 0.000)",
|
|
566
|
-
sheet_fields: "rgb(160, 160, 0)",
|
|
567
|
-
sheet_filename: "rgb(160, 160, 0)",
|
|
568
|
-
sheet_label: "rgb(160, 160, 0)",
|
|
569
|
-
sheet_name: "rgb(0, 160, 204)",
|
|
570
|
-
value: "rgb(192, 192, 192)",
|
|
571
|
-
wire: "rgb(0, 160, 0)",
|
|
572
|
-
worksheet: "rgb(192, 0, 0)"
|
|
573
|
-
}
|
|
574
|
-
};
|
|
575
|
-
|
|
576
|
-
// src/lib/Drawer.ts
|
|
577
|
-
var LAYER_NAME_TO_COLOR = {
|
|
578
|
-
red: "red",
|
|
579
|
-
black: "black",
|
|
580
|
-
green: "green",
|
|
581
|
-
top: colors_default.board.copper.f,
|
|
582
|
-
keepout: colors_default.board.background,
|
|
583
|
-
tkeepout: colors_default.board.b_crtyd,
|
|
584
|
-
tplace: colors_default.board.b_silks,
|
|
585
|
-
...colors_default.board
|
|
586
|
-
};
|
|
587
|
-
var Drawer = class {
|
|
588
|
-
constructor(canvas) {
|
|
589
|
-
this.canvas = canvas;
|
|
590
|
-
this.canvas = canvas;
|
|
591
|
-
this.ctx = canvas.getContext("2d");
|
|
592
|
-
this.transform = (0, import_transformation_matrix.identity)();
|
|
593
|
-
this.transform.d *= -1;
|
|
594
|
-
this.transform = (0, import_transformation_matrix.compose)(this.transform, (0, import_transformation_matrix.translate)(0, -500));
|
|
595
|
-
}
|
|
596
|
-
clear() {
|
|
597
|
-
const { ctx, canvas } = this;
|
|
598
|
-
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
599
|
-
}
|
|
600
|
-
equip(aperature) {
|
|
601
|
-
this.aperture = {
|
|
602
|
-
fontSize: 0,
|
|
603
|
-
shape: "circle",
|
|
604
|
-
mode: "add",
|
|
605
|
-
size: 0,
|
|
606
|
-
color: "red",
|
|
607
|
-
...aperature
|
|
608
|
-
};
|
|
609
|
-
}
|
|
610
|
-
rect(x, y, w, h) {
|
|
611
|
-
const [x1$, y1$] = (0, import_transformation_matrix.applyToPoint)(this.transform, [x - w / 2, y - h / 2]);
|
|
612
|
-
const [x2$, y2$] = (0, import_transformation_matrix.applyToPoint)(this.transform, [x + w / 2, y + h / 2]);
|
|
613
|
-
this.applyAperture();
|
|
614
|
-
this.ctx.fillRect(x1$, y1$, x2$ - x1$, y2$ - y1$);
|
|
615
|
-
}
|
|
616
|
-
circle(x, y, r) {
|
|
617
|
-
const r$ = scaleOnly(this.transform, r);
|
|
618
|
-
const [x$, y$] = (0, import_transformation_matrix.applyToPoint)(this.transform, [x, y]);
|
|
619
|
-
this.applyAperture();
|
|
620
|
-
this.ctx.beginPath();
|
|
621
|
-
this.ctx.arc(x$, y$, r$, 0, 2 * Math.PI);
|
|
622
|
-
this.ctx.fill();
|
|
623
|
-
this.ctx.closePath();
|
|
624
|
-
}
|
|
625
|
-
debugText(text, x, y) {
|
|
626
|
-
const [x$, y$] = (0, import_transformation_matrix.applyToPoint)(this.transform, [x, y]);
|
|
627
|
-
this.applyAperture();
|
|
628
|
-
this.ctx.font = `10px sans-serif`;
|
|
629
|
-
this.ctx.fillText(text, x$, y$);
|
|
630
|
-
}
|
|
631
|
-
applyAperture() {
|
|
632
|
-
const { ctx, transform, aperture } = this;
|
|
633
|
-
const { size, mode, color, fontSize } = aperture;
|
|
634
|
-
ctx.lineWidth = scaleOnly(transform, size);
|
|
635
|
-
ctx.lineCap = "round";
|
|
636
|
-
if (mode === "add") {
|
|
637
|
-
let colorString = color[0] === "#" || color.startsWith("rgb") ? color : LAYER_NAME_TO_COLOR[color.toLowerCase()] ? LAYER_NAME_TO_COLOR[color.toLowerCase()] : null;
|
|
638
|
-
if (colorString === null) {
|
|
639
|
-
console.warn(`Color mapping for "${color}" not found`);
|
|
640
|
-
colorString = "white";
|
|
641
|
-
}
|
|
642
|
-
ctx.fillStyle = colorString;
|
|
643
|
-
ctx.strokeStyle = colorString;
|
|
644
|
-
} else {
|
|
645
|
-
ctx.globalCompositeOperation = "destination-out";
|
|
646
|
-
ctx.fillStyle = "rgba(0,0,0,1)";
|
|
647
|
-
ctx.strokeStyle = "rgba(0,0,0,1)";
|
|
793
|
+
schematic: {
|
|
794
|
+
anchor: "rgb(0, 0, 255)",
|
|
795
|
+
aux_items: "rgb(0, 0, 0)",
|
|
796
|
+
background: "rgb(33, 33, 33)",
|
|
797
|
+
brightened: "rgb(204, 204, 204)",
|
|
798
|
+
bus: "rgb(0, 96, 192)",
|
|
799
|
+
bus_junction: "rgb(0, 96, 192)",
|
|
800
|
+
component_body: "rgb(44, 44, 44)",
|
|
801
|
+
component_outline: "rgb(192, 0, 0)",
|
|
802
|
+
cursor: "rgb(224, 224, 224)",
|
|
803
|
+
erc_error: "rgba(192, 48, 48, 0.800)",
|
|
804
|
+
erc_warning: "rgba(192, 140, 0, 0.800)",
|
|
805
|
+
fields: "rgb(128, 0, 160)",
|
|
806
|
+
grid: "rgb(60, 60, 60)",
|
|
807
|
+
grid_axes: "rgb(60, 60, 60)",
|
|
808
|
+
hidden: "rgb(194, 194, 194)",
|
|
809
|
+
junction: "rgb(0, 160, 0)",
|
|
810
|
+
label_global: "rgb(0, 160, 224)",
|
|
811
|
+
label_hier: "rgb(160, 160, 0)",
|
|
812
|
+
label_local: "rgb(192, 192, 192)",
|
|
813
|
+
net_name: "rgb(224, 224, 224)",
|
|
814
|
+
no_connect: "rgb(97, 43, 224)",
|
|
815
|
+
note: "rgb(192, 192, 0)",
|
|
816
|
+
override_item_colors: false,
|
|
817
|
+
pin: "rgb(192, 0, 0)",
|
|
818
|
+
pin_name: "rgb(192, 192, 192)",
|
|
819
|
+
pin_number: "rgb(192, 0, 0)",
|
|
820
|
+
reference: "rgb(192, 192, 192)",
|
|
821
|
+
shadow: "rgba(102, 179, 255, 0.800)",
|
|
822
|
+
sheet: "rgb(128, 0, 160)",
|
|
823
|
+
sheet_background: "rgba(255, 255, 255, 0.000)",
|
|
824
|
+
sheet_fields: "rgb(160, 160, 0)",
|
|
825
|
+
sheet_filename: "rgb(160, 160, 0)",
|
|
826
|
+
sheet_label: "rgb(160, 160, 0)",
|
|
827
|
+
sheet_name: "rgb(0, 160, 204)",
|
|
828
|
+
value: "rgb(192, 192, 192)",
|
|
829
|
+
wire: "rgb(0, 160, 0)",
|
|
830
|
+
worksheet: "rgb(192, 0, 0)"
|
|
648
831
|
}
|
|
649
|
-
ctx.font = `${scaleOnly((0, import_transformation_matrix.inverse)(transform), fontSize)}px sans-serif`;
|
|
650
|
-
}
|
|
651
|
-
moveTo(x, y) {
|
|
652
|
-
this.lastPoint = { x, y };
|
|
653
|
-
}
|
|
654
|
-
lineTo(x, y) {
|
|
655
|
-
const [x$, y$] = (0, import_transformation_matrix.applyToPoint)(this.transform, [x, y]);
|
|
656
|
-
const { size, shape, mode } = this.aperture;
|
|
657
|
-
const size$ = scaleOnly(this.transform, size);
|
|
658
|
-
let { lastPoint, ctx } = this;
|
|
659
|
-
const lastPoint$ = (0, import_transformation_matrix.applyToPoint)(this.transform, lastPoint);
|
|
660
|
-
this.applyAperture();
|
|
661
|
-
if (shape === "square")
|
|
662
|
-
ctx.fillRect(
|
|
663
|
-
lastPoint$.x - size$ / 2,
|
|
664
|
-
lastPoint$.y - size$ / 2,
|
|
665
|
-
size$,
|
|
666
|
-
size$
|
|
667
|
-
);
|
|
668
|
-
ctx.beginPath();
|
|
669
|
-
ctx.moveTo(lastPoint$.x, lastPoint$.y);
|
|
670
|
-
ctx.lineTo(x$, y$);
|
|
671
|
-
ctx.stroke();
|
|
672
|
-
ctx.closePath();
|
|
673
|
-
if (shape === "square")
|
|
674
|
-
ctx.fillRect(x$ - size$ / 2, y$ - size$ / 2, size$, size$);
|
|
675
|
-
this.lastPoint = { x, y };
|
|
676
|
-
}
|
|
677
832
|
};
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
screenSpaceCellSize: 200,
|
|
709
|
-
width,
|
|
710
|
-
height,
|
|
711
|
-
transform,
|
|
712
|
-
stringifyCoord: (x, y, z) => `${(0, import_react_supergrid.toMMSI)(x, z)}, ${(0, import_react_supergrid.toMMSI)(y, z)}`
|
|
713
|
-
}), /* @__PURE__ */ import_react.default.createElement("canvas", {
|
|
714
|
-
ref,
|
|
715
|
-
style: { position: "absolute", left: 0, top: 0, pointerEvents: "none" },
|
|
716
|
-
width,
|
|
717
|
-
height
|
|
718
|
-
}));
|
|
719
|
-
};
|
|
720
|
-
|
|
721
|
-
// src/components/CanvasElementsRenderer.tsx
|
|
722
|
-
var import_react3 = require("react");
|
|
723
|
-
|
|
724
|
-
// src/lib/convert-element-to-primitive.ts
|
|
725
|
-
var convertElementToPrimitives = (element) => {
|
|
726
|
-
switch (element.type) {
|
|
727
|
-
case "pcb_smtpad": {
|
|
728
|
-
if (element.shape === "rect") {
|
|
729
|
-
const { shape, x, y, width, height, layer } = element;
|
|
730
|
-
return [
|
|
731
|
-
{
|
|
732
|
-
pcb_drawing_type: "rect",
|
|
733
|
-
x,
|
|
734
|
-
y,
|
|
735
|
-
w: width,
|
|
736
|
-
h: height,
|
|
737
|
-
layer: layer || { name: "top" },
|
|
738
|
-
_element: element
|
|
739
|
-
}
|
|
740
|
-
];
|
|
741
|
-
} else if (element.shape === "circle") {
|
|
742
|
-
console.warn(`Unsupported shape: ${element.shape} for pcb_smtpad`);
|
|
743
|
-
return [];
|
|
744
|
-
}
|
|
833
|
+
// src/lib/Drawer.ts
|
|
834
|
+
var LAYER_NAME_TO_COLOR = _object_spread({
|
|
835
|
+
// Standard colors, you shouldn't use these except for testing
|
|
836
|
+
red: "red",
|
|
837
|
+
black: "black",
|
|
838
|
+
green: "green",
|
|
839
|
+
// TODO more builtin html colors
|
|
840
|
+
// Common eagle names
|
|
841
|
+
top: colors_default.board.copper.f,
|
|
842
|
+
bottom: colors_default.board.copper.b,
|
|
843
|
+
drill: colors_default.board.anchor,
|
|
844
|
+
keepout: colors_default.board.background,
|
|
845
|
+
tkeepout: colors_default.board.b_crtyd,
|
|
846
|
+
tplace: colors_default.board.b_silks
|
|
847
|
+
}, colors_default.board);
|
|
848
|
+
var Drawer = /*#__PURE__*/ function() {
|
|
849
|
+
"use strict";
|
|
850
|
+
function Drawer(canvas) {
|
|
851
|
+
_class_call_check(this, Drawer);
|
|
852
|
+
this.canvas = canvas;
|
|
853
|
+
this.canvas = canvas;
|
|
854
|
+
this.ctx = canvas.getContext("2d");
|
|
855
|
+
this.transform = (0, import_transformation_matrix.identity)();
|
|
856
|
+
this.transform.d *= -1;
|
|
857
|
+
this.transform = (0, import_transformation_matrix.compose)(this.transform, (0, import_transformation_matrix.translate)(0, -500));
|
|
858
|
+
this.lastPoint = {
|
|
859
|
+
x: 0,
|
|
860
|
+
y: 0
|
|
861
|
+
};
|
|
862
|
+
this.equip({});
|
|
745
863
|
}
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
864
|
+
_create_class(Drawer, [
|
|
865
|
+
{
|
|
866
|
+
key: "clear",
|
|
867
|
+
value: function clear() {
|
|
868
|
+
var _this = this, ctx = _this.ctx, canvas = _this.canvas;
|
|
869
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
870
|
+
}
|
|
871
|
+
},
|
|
872
|
+
{
|
|
873
|
+
key: "equip",
|
|
874
|
+
value: function equip(aperature) {
|
|
875
|
+
this.aperture = _object_spread({
|
|
876
|
+
fontSize: 0,
|
|
877
|
+
shape: "circle",
|
|
878
|
+
mode: "add",
|
|
879
|
+
size: 0,
|
|
880
|
+
color: "red"
|
|
881
|
+
}, aperature);
|
|
882
|
+
}
|
|
883
|
+
},
|
|
884
|
+
{
|
|
885
|
+
key: "rect",
|
|
886
|
+
value: function rect(x, y, w, h) {
|
|
887
|
+
var _ref = _sliced_to_array((0, import_transformation_matrix.applyToPoint)(this.transform, [
|
|
888
|
+
x - w / 2,
|
|
889
|
+
y - h / 2
|
|
890
|
+
]), 2), x1$ = _ref[0], y1$ = _ref[1];
|
|
891
|
+
var _ref1 = _sliced_to_array((0, import_transformation_matrix.applyToPoint)(this.transform, [
|
|
892
|
+
x + w / 2,
|
|
893
|
+
y + h / 2
|
|
894
|
+
]), 2), x2$ = _ref1[0], y2$ = _ref1[1];
|
|
895
|
+
this.applyAperture();
|
|
896
|
+
this.ctx.fillRect(x1$, y1$, x2$ - x1$, y2$ - y1$);
|
|
897
|
+
}
|
|
898
|
+
},
|
|
899
|
+
{
|
|
900
|
+
key: "circle",
|
|
901
|
+
value: function circle(x, y, r) {
|
|
902
|
+
var r$ = scaleOnly(this.transform, r);
|
|
903
|
+
var _ref = _sliced_to_array((0, import_transformation_matrix.applyToPoint)(this.transform, [
|
|
904
|
+
x,
|
|
905
|
+
y
|
|
906
|
+
]), 2), x$ = _ref[0], y$ = _ref[1];
|
|
907
|
+
this.applyAperture();
|
|
908
|
+
this.ctx.beginPath();
|
|
909
|
+
this.ctx.arc(x$, y$, r$, 0, 2 * Math.PI);
|
|
910
|
+
this.ctx.fill();
|
|
911
|
+
this.ctx.closePath();
|
|
912
|
+
}
|
|
913
|
+
},
|
|
914
|
+
{
|
|
915
|
+
/* NOTE: This is not gerber compatible */ key: "debugText",
|
|
916
|
+
value: function debugText(text, x, y) {
|
|
917
|
+
var _ref = _sliced_to_array((0, import_transformation_matrix.applyToPoint)(this.transform, [
|
|
918
|
+
x,
|
|
919
|
+
y
|
|
920
|
+
]), 2), x$ = _ref[0], y$ = _ref[1];
|
|
921
|
+
this.applyAperture();
|
|
922
|
+
this.ctx.font = "10px sans-serif";
|
|
923
|
+
this.ctx.fillText(text, x$, y$);
|
|
924
|
+
}
|
|
925
|
+
},
|
|
749
926
|
{
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
927
|
+
key: "applyAperture",
|
|
928
|
+
value: function applyAperture() {
|
|
929
|
+
var _this = this, ctx = _this.ctx, transform = _this.transform, aperture = _this.aperture;
|
|
930
|
+
var size = aperture.size, mode = aperture.mode, color = aperture.color, fontSize = aperture.fontSize;
|
|
931
|
+
ctx.lineWidth = scaleOnly(transform, size);
|
|
932
|
+
ctx.lineCap = "round";
|
|
933
|
+
if (mode === "add") {
|
|
934
|
+
var colorString = color[0] === "#" || color.startsWith("rgb") ? color : LAYER_NAME_TO_COLOR[color.toLowerCase()] ? LAYER_NAME_TO_COLOR[color.toLowerCase()] : null;
|
|
935
|
+
if (colorString === null) {
|
|
936
|
+
console.warn('Color mapping for "'.concat(color, '" not found'));
|
|
937
|
+
colorString = "white";
|
|
938
|
+
}
|
|
939
|
+
ctx.fillStyle = colorString;
|
|
940
|
+
ctx.strokeStyle = colorString;
|
|
941
|
+
} else {
|
|
942
|
+
ctx.globalCompositeOperation = "destination-out";
|
|
943
|
+
ctx.fillStyle = "rgba(0,0,0,1)";
|
|
944
|
+
ctx.strokeStyle = "rgba(0,0,0,1)";
|
|
945
|
+
}
|
|
946
|
+
ctx.font = "".concat(scaleOnly((0, import_transformation_matrix.inverse)(transform), fontSize), "px sans-serif");
|
|
947
|
+
}
|
|
756
948
|
},
|
|
757
949
|
{
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
950
|
+
key: "moveTo",
|
|
951
|
+
value: function moveTo(x, y) {
|
|
952
|
+
this.lastPoint = {
|
|
953
|
+
x: x,
|
|
954
|
+
y: y
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
},
|
|
958
|
+
{
|
|
959
|
+
key: "lineTo",
|
|
960
|
+
value: function lineTo(x, y) {
|
|
961
|
+
var _ref = _sliced_to_array((0, import_transformation_matrix.applyToPoint)(this.transform, [
|
|
962
|
+
x,
|
|
963
|
+
y
|
|
964
|
+
]), 2), x$ = _ref[0], y$ = _ref[1];
|
|
965
|
+
var _this_aperture = this.aperture, size = _this_aperture.size, shape = _this_aperture.shape, mode = _this_aperture.mode;
|
|
966
|
+
var size$ = scaleOnly(this.transform, size);
|
|
967
|
+
var _this = this, lastPoint = _this.lastPoint, ctx = _this.ctx;
|
|
968
|
+
var lastPoint$ = (0, import_transformation_matrix.applyToPoint)(this.transform, lastPoint);
|
|
969
|
+
this.applyAperture();
|
|
970
|
+
if (shape === "square") ctx.fillRect(lastPoint$.x - size$ / 2, lastPoint$.y - size$ / 2, size$, size$);
|
|
971
|
+
ctx.beginPath();
|
|
972
|
+
ctx.moveTo(lastPoint$.x, lastPoint$.y);
|
|
973
|
+
ctx.lineTo(x$, y$);
|
|
974
|
+
ctx.stroke();
|
|
975
|
+
ctx.closePath();
|
|
976
|
+
if (shape === "square") ctx.fillRect(x$ - size$ / 2, y$ - size$ / 2, size$, size$);
|
|
977
|
+
this.lastPoint = {
|
|
978
|
+
x: x,
|
|
979
|
+
y: y
|
|
980
|
+
};
|
|
981
|
+
}
|
|
763
982
|
}
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
983
|
+
]);
|
|
984
|
+
return Drawer;
|
|
985
|
+
}();
|
|
986
|
+
// src/components/CanvasPrimitiveRenderer.tsx
|
|
987
|
+
var CanvasPrimitiveRenderer = function(param) {
|
|
988
|
+
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;
|
|
989
|
+
var ref = (0, import_react.useRef)();
|
|
990
|
+
(0, import_react.useEffect)(function() {
|
|
991
|
+
if (!ref.current) return;
|
|
992
|
+
var drawer = new Drawer(ref.current);
|
|
993
|
+
if (transform) drawer.transform = transform;
|
|
994
|
+
drawer.clear();
|
|
995
|
+
drawPrimitives(drawer, primitives);
|
|
996
|
+
}, [
|
|
997
|
+
primitives,
|
|
998
|
+
transform
|
|
999
|
+
]);
|
|
1000
|
+
return /* @__PURE__ */ import_react.default.createElement("div", {
|
|
1001
|
+
style: {
|
|
1002
|
+
backgroundColor: "black",
|
|
1003
|
+
width: width,
|
|
1004
|
+
height: height,
|
|
1005
|
+
position: "relative"
|
|
786
1006
|
}
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
1007
|
+
}, /* @__PURE__ */ import_react.default.createElement(import_react_supergrid.SuperGrid, {
|
|
1008
|
+
textColor: "rgba(0,255,0,0.8)",
|
|
1009
|
+
majorColor: "rgba(0,255,0,0.4)",
|
|
1010
|
+
minorColor: "rgba(0,255,0,0.2)",
|
|
1011
|
+
screenSpaceCellSize: 200,
|
|
1012
|
+
width: width,
|
|
1013
|
+
height: height,
|
|
1014
|
+
transform: transform,
|
|
1015
|
+
stringifyCoord: function(x, y, z) {
|
|
1016
|
+
return "".concat((0, import_react_supergrid.toMMSI)(x, z), ", ").concat((0, import_react_supergrid.toMMSI)(y, z));
|
|
1017
|
+
}
|
|
1018
|
+
}), /* @__PURE__ */ import_react.default.createElement("canvas", {
|
|
1019
|
+
ref: ref,
|
|
1020
|
+
style: {
|
|
1021
|
+
position: "absolute",
|
|
1022
|
+
left: 0,
|
|
1023
|
+
top: 0,
|
|
1024
|
+
pointerEvents: "none"
|
|
1025
|
+
},
|
|
1026
|
+
width: width,
|
|
1027
|
+
height: height
|
|
1028
|
+
}));
|
|
792
1029
|
};
|
|
793
|
-
|
|
794
1030
|
// src/components/CanvasElementsRenderer.tsx
|
|
795
|
-
var
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
|
|
1031
|
+
var import_react6 = require("react");
|
|
1032
|
+
// src/lib/convert-element-to-primitive.ts
|
|
1033
|
+
var convertElementToPrimitives = function(element, allElements) {
|
|
1034
|
+
var _parent_pcb_component = "pcb_component_id" in element ? allElements.find(function(elm) {
|
|
1035
|
+
return elm.type === "pcb_component" && elm.pcb_component_id === element.pcb_component_id;
|
|
1036
|
+
}) : void 0;
|
|
1037
|
+
var _parent_source_component = _parent_pcb_component && "source_component_id" in _parent_pcb_component ? allElements.find(function(elm) {
|
|
1038
|
+
return elm.type === "source_component" && elm.source_component_id === _parent_pcb_component.source_component_id;
|
|
1039
|
+
}) : void 0;
|
|
1040
|
+
switch(element.type){
|
|
1041
|
+
case "pcb_smtpad":
|
|
1042
|
+
{
|
|
1043
|
+
if (element.shape === "rect") {
|
|
1044
|
+
var shape = element.shape, x = element.x, y = element.y, width = element.width, height = element.height, layer = element.layer;
|
|
1045
|
+
return [
|
|
1046
|
+
{
|
|
1047
|
+
pcb_drawing_type: "rect",
|
|
1048
|
+
x: x,
|
|
1049
|
+
y: y,
|
|
1050
|
+
w: width,
|
|
1051
|
+
h: height,
|
|
1052
|
+
layer: layer || "top",
|
|
1053
|
+
_element: element,
|
|
1054
|
+
_parent_pcb_component: _parent_pcb_component,
|
|
1055
|
+
_parent_source_component: _parent_source_component
|
|
1056
|
+
}
|
|
1057
|
+
];
|
|
1058
|
+
} else if (element.shape === "circle") {
|
|
1059
|
+
var x1 = element.x, y1 = element.y, radius = element.radius, layer1 = element.layer;
|
|
1060
|
+
return [
|
|
1061
|
+
{
|
|
1062
|
+
pcb_drawing_type: "circle",
|
|
1063
|
+
x: x1,
|
|
1064
|
+
y: y1,
|
|
1065
|
+
r: radius,
|
|
1066
|
+
layer: layer1 || "top",
|
|
1067
|
+
_element: element,
|
|
1068
|
+
_parent_pcb_component: _parent_pcb_component,
|
|
1069
|
+
_parent_source_component: _parent_source_component
|
|
1070
|
+
}
|
|
1071
|
+
];
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
case "pcb_hole":
|
|
1075
|
+
{
|
|
1076
|
+
var x2 = element.x, y2 = element.y, hole_diameter = element.hole_diameter;
|
|
1077
|
+
console.log("hole", element);
|
|
1078
|
+
return [
|
|
1079
|
+
{
|
|
1080
|
+
pcb_drawing_type: "circle",
|
|
1081
|
+
x: x2,
|
|
1082
|
+
y: y2,
|
|
1083
|
+
r: hole_diameter / 2,
|
|
1084
|
+
layer: "drill",
|
|
1085
|
+
_element: element,
|
|
1086
|
+
_parent_pcb_component: _parent_pcb_component,
|
|
1087
|
+
_parent_source_component: _parent_source_component
|
|
1088
|
+
}
|
|
1089
|
+
];
|
|
1090
|
+
}
|
|
1091
|
+
case "pcb_plated_hole":
|
|
1092
|
+
{
|
|
1093
|
+
var x3 = element.x, y3 = element.y, hole_diameter1 = element.hole_diameter, outer_diameter = element.outer_diameter;
|
|
1094
|
+
return [
|
|
1095
|
+
{
|
|
1096
|
+
pcb_drawing_type: "circle",
|
|
1097
|
+
x: x3,
|
|
1098
|
+
y: y3,
|
|
1099
|
+
r: outer_diameter / 2,
|
|
1100
|
+
// TODO support layer on pcb_plated_hole
|
|
1101
|
+
layer: "top",
|
|
1102
|
+
_element: element,
|
|
1103
|
+
_parent_pcb_component: _parent_pcb_component,
|
|
1104
|
+
_parent_source_component: _parent_source_component
|
|
1105
|
+
},
|
|
1106
|
+
{
|
|
1107
|
+
pcb_drawing_type: "circle",
|
|
1108
|
+
x: x3,
|
|
1109
|
+
y: y3,
|
|
1110
|
+
r: hole_diameter1 / 2,
|
|
1111
|
+
// TODO support layer on pcb_plated_hole
|
|
1112
|
+
layer: "drill"
|
|
1113
|
+
}
|
|
1114
|
+
];
|
|
1115
|
+
}
|
|
1116
|
+
case "pcb_trace":
|
|
1117
|
+
{
|
|
1118
|
+
var primitives = [];
|
|
1119
|
+
var prevX = null;
|
|
1120
|
+
var prevY = null;
|
|
1121
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1122
|
+
try {
|
|
1123
|
+
for(var _iterator = element.route[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1124
|
+
var route = _step.value;
|
|
1125
|
+
if (route.route_type === "wire") {
|
|
1126
|
+
if (prevX !== null && prevY !== null) {
|
|
1127
|
+
primitives.push({
|
|
1128
|
+
pcb_drawing_type: "line",
|
|
1129
|
+
x1: prevX,
|
|
1130
|
+
y1: prevY,
|
|
1131
|
+
x2: route.x,
|
|
1132
|
+
y2: route.y,
|
|
1133
|
+
width: route.width,
|
|
1134
|
+
squareCap: false,
|
|
1135
|
+
layer: route.layer
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
prevX = route.x;
|
|
1139
|
+
prevY = route.y;
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
} catch (err) {
|
|
1143
|
+
_didIteratorError = true;
|
|
1144
|
+
_iteratorError = err;
|
|
1145
|
+
} finally{
|
|
1146
|
+
try {
|
|
1147
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1148
|
+
_iterator.return();
|
|
1149
|
+
}
|
|
1150
|
+
} finally{
|
|
1151
|
+
if (_didIteratorError) {
|
|
1152
|
+
throw _iteratorError;
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
return primitives;
|
|
1157
|
+
}
|
|
1158
|
+
case "pcb_via":
|
|
1159
|
+
{
|
|
1160
|
+
var x4 = element.x, y4 = element.y, outer_diameter1 = element.outer_diameter, hole_diameter2 = element.hole_diameter, from_layer = element.from_layer, to_layer = element.to_layer;
|
|
1161
|
+
return [
|
|
1162
|
+
{
|
|
1163
|
+
pcb_drawing_type: "circle",
|
|
1164
|
+
x: x4,
|
|
1165
|
+
y: y4,
|
|
1166
|
+
r: outer_diameter1 / 2,
|
|
1167
|
+
layer: from_layer,
|
|
1168
|
+
_element: element,
|
|
1169
|
+
_parent_pcb_component: _parent_pcb_component,
|
|
1170
|
+
_parent_source_component: _parent_source_component
|
|
1171
|
+
},
|
|
1172
|
+
{
|
|
1173
|
+
pcb_drawing_type: "circle",
|
|
1174
|
+
x: x4,
|
|
1175
|
+
y: y4,
|
|
1176
|
+
r: hole_diameter2 / 2,
|
|
1177
|
+
layer: to_layer
|
|
1178
|
+
}
|
|
1179
|
+
];
|
|
1180
|
+
}
|
|
806
1181
|
}
|
|
807
|
-
|
|
1182
|
+
return [];
|
|
808
1183
|
};
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
for (const primitive of primitives) {
|
|
825
|
-
if (!("x" in primitive && "y" in primitive && ("w" in primitive && "h" in primitive || "r" in primitive)))
|
|
826
|
-
continue;
|
|
827
|
-
if (!primitive._element)
|
|
828
|
-
continue;
|
|
829
|
-
const w = "w" in primitive ? primitive.w : primitive.r * 2;
|
|
830
|
-
const h = "h" in primitive ? primitive.h : primitive.r * 2;
|
|
831
|
-
if (Math.abs(primitive.x - rwPoint.x) < w / 2 && Math.abs(primitive.y - rwPoint.y) < h / 2) {
|
|
832
|
-
const screenPos = (0, import_transformation_matrix2.applyToPoint)(transform, primitive);
|
|
833
|
-
const screenSize = {
|
|
834
|
-
w: w * transform.d,
|
|
835
|
-
h: h * transform.d
|
|
836
|
-
};
|
|
837
|
-
highlightedPrimitives2.push({
|
|
838
|
-
...primitive,
|
|
839
|
-
screen_x: screenPos.x,
|
|
840
|
-
screen_y: screenPos.y,
|
|
841
|
-
screen_w: screenSize.w,
|
|
842
|
-
screen_h: screenSize.h
|
|
843
|
-
});
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
setHighlightedPrimitives(highlightedPrimitives2);
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
}, children, /* @__PURE__ */ import_react2.default.createElement(ElementMouseOverlay, {
|
|
850
|
-
highlightedPrimitives
|
|
851
|
-
}));
|
|
1184
|
+
// src/components/MouseElementTracker.tsx
|
|
1185
|
+
var import_react3 = __toESM(require("react"));
|
|
1186
|
+
var import_react4 = require("react");
|
|
1187
|
+
var import_transformation_matrix2 = require("transformation-matrix");
|
|
1188
|
+
// src/components/ElementOverlayBox.tsx
|
|
1189
|
+
var import_react2 = __toESM(require("react"));
|
|
1190
|
+
var containerStyle = {
|
|
1191
|
+
position: "absolute",
|
|
1192
|
+
left: 0,
|
|
1193
|
+
top: 0,
|
|
1194
|
+
pointerEvents: "none",
|
|
1195
|
+
color: "red",
|
|
1196
|
+
fontFamily: "sans-serif",
|
|
1197
|
+
fontSize: 12,
|
|
1198
|
+
textShadow: "0 0 2px black"
|
|
852
1199
|
};
|
|
853
|
-
var
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
top: primitive.screen_y - primitive.screen_h / 2 - 8,
|
|
873
|
-
width: primitive.screen_w + 16,
|
|
874
|
-
height: primitive.screen_h + 16,
|
|
875
|
-
border: "1px solid red"
|
|
1200
|
+
var getTextForHighlightedPrimitive = function(prim) {
|
|
1201
|
+
var element = prim._element, _parent_pcb_component = prim._parent_pcb_component, _parent_source_component = prim._parent_source_component;
|
|
1202
|
+
switch(element.type){
|
|
1203
|
+
case "pcb_smtpad":
|
|
1204
|
+
case "pcb_plated_hole":
|
|
1205
|
+
{
|
|
1206
|
+
var s = "";
|
|
1207
|
+
if (_parent_source_component && "name" in _parent_source_component && _parent_source_component.name) {
|
|
1208
|
+
s += ".".concat(_parent_source_component.name, " > ");
|
|
1209
|
+
}
|
|
1210
|
+
s += element.port_hints.map(function(ph) {
|
|
1211
|
+
return "port.".concat(ph);
|
|
1212
|
+
}).join(", ");
|
|
1213
|
+
return s;
|
|
1214
|
+
}
|
|
1215
|
+
default:
|
|
1216
|
+
{
|
|
1217
|
+
return "";
|
|
1218
|
+
}
|
|
876
1219
|
}
|
|
877
|
-
})), highlightedPrimitives.map((primitive, i) => /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
878
|
-
key: `${i}-text`,
|
|
879
|
-
style: {
|
|
880
|
-
position: "absolute",
|
|
881
|
-
left: primitive.screen_x - primitive.screen_w / 2 - 8,
|
|
882
|
-
top: primitive.screen_y - primitive.screen_h / 2 - 8
|
|
883
|
-
}
|
|
884
|
-
}, /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
885
|
-
style: { position: "absolute", left: 0, bottom: 0 }
|
|
886
|
-
}, getTextForElement(primitive._element)))));
|
|
887
1220
|
};
|
|
888
|
-
var
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
)
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
1221
|
+
var ElementOverlayBox = function(param) {
|
|
1222
|
+
var highlightedPrimitives = param.highlightedPrimitives;
|
|
1223
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
1224
|
+
style: containerStyle
|
|
1225
|
+
}, highlightedPrimitives.map(function(primitive, i) {
|
|
1226
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
1227
|
+
key: "".concat(i, "-box"),
|
|
1228
|
+
style: {
|
|
1229
|
+
position: "absolute",
|
|
1230
|
+
left: primitive.screen_x - primitive.screen_w / 2 - 8,
|
|
1231
|
+
top: primitive.screen_y - primitive.screen_h / 2 - 8,
|
|
1232
|
+
width: primitive.screen_w + 16,
|
|
1233
|
+
height: primitive.screen_h + 16,
|
|
1234
|
+
border: "1px solid red"
|
|
1235
|
+
}
|
|
1236
|
+
});
|
|
1237
|
+
}), highlightedPrimitives.map(function(primitive, i) {
|
|
1238
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
1239
|
+
key: "".concat(i, "-text"),
|
|
1240
|
+
style: {
|
|
1241
|
+
position: "absolute",
|
|
1242
|
+
left: primitive.screen_x - primitive.screen_w / 2 - 8,
|
|
1243
|
+
top: primitive.screen_y - primitive.screen_h / 2 - 8,
|
|
1244
|
+
whiteSpace: "pre-line",
|
|
1245
|
+
width: Math.max(100, primitive.screen_w + 16)
|
|
1246
|
+
}
|
|
1247
|
+
}, /* @__PURE__ */ import_react2.default.createElement("div", {
|
|
1248
|
+
style: {
|
|
1249
|
+
position: "absolute",
|
|
1250
|
+
left: 0,
|
|
1251
|
+
bottom: 0
|
|
1252
|
+
}
|
|
1253
|
+
}, getTextForHighlightedPrimitive(primitive)));
|
|
1254
|
+
}));
|
|
1255
|
+
};
|
|
1256
|
+
// src/components/MouseElementTracker.tsx
|
|
1257
|
+
var MouseElementTracker = function(param) {
|
|
1258
|
+
var children = param.children, transform = param.transform, primitives = param.primitives;
|
|
1259
|
+
var _ref = _sliced_to_array((0, import_react3.useState)([]), 2), mousedPrimitives = _ref[0], setMousedPrimitives = _ref[1];
|
|
1260
|
+
var highlightedPrimitives = (0, import_react4.useMemo)(function() {
|
|
1261
|
+
var highlightedPrimitives2 = [];
|
|
1262
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1263
|
+
try {
|
|
1264
|
+
for(var _iterator = mousedPrimitives[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1265
|
+
var primitive = _step.value;
|
|
1266
|
+
var screenPos = (0, import_transformation_matrix2.applyToPoint)(transform, primitive);
|
|
1267
|
+
var w = "w" in primitive ? primitive.w : "r" in primitive ? primitive.r * 2 : 0;
|
|
1268
|
+
var h = "h" in primitive ? primitive.h : "r" in primitive ? primitive.r * 2 : 0;
|
|
1269
|
+
var screenSize = {
|
|
1270
|
+
w: w * transform.d,
|
|
1271
|
+
h: h * transform.d
|
|
1272
|
+
};
|
|
1273
|
+
highlightedPrimitives2.push(_object_spread_props(_object_spread({}, primitive), {
|
|
1274
|
+
screen_x: screenPos.x,
|
|
1275
|
+
screen_y: screenPos.y,
|
|
1276
|
+
screen_w: screenSize.w,
|
|
1277
|
+
screen_h: screenSize.h
|
|
1278
|
+
}));
|
|
1279
|
+
}
|
|
1280
|
+
} catch (err) {
|
|
1281
|
+
_didIteratorError = true;
|
|
1282
|
+
_iteratorError = err;
|
|
1283
|
+
} finally{
|
|
1284
|
+
try {
|
|
1285
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1286
|
+
_iterator.return();
|
|
1287
|
+
}
|
|
1288
|
+
} finally{
|
|
1289
|
+
if (_didIteratorError) {
|
|
1290
|
+
throw _iteratorError;
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
return highlightedPrimitives2;
|
|
1295
|
+
}, [
|
|
1296
|
+
mousedPrimitives,
|
|
1297
|
+
transform
|
|
1298
|
+
]);
|
|
1299
|
+
return /* @__PURE__ */ import_react3.default.createElement("div", {
|
|
1300
|
+
style: {
|
|
1301
|
+
position: "relative"
|
|
1302
|
+
},
|
|
1303
|
+
onMouseMove: function(e) {
|
|
1304
|
+
if (transform) {
|
|
1305
|
+
var rect = e.currentTarget.getBoundingClientRect();
|
|
1306
|
+
var x = e.clientX - rect.left;
|
|
1307
|
+
var y = e.clientY - rect.top;
|
|
1308
|
+
var rwPoint = (0, import_transformation_matrix2.applyToPoint)((0, import_transformation_matrix2.inverse)(transform), {
|
|
1309
|
+
x: x,
|
|
1310
|
+
y: y
|
|
1311
|
+
});
|
|
1312
|
+
var mousedPrimitives2 = [];
|
|
1313
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1314
|
+
try {
|
|
1315
|
+
for(var _iterator = primitives[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1316
|
+
var primitive = _step.value;
|
|
1317
|
+
if (!("x" in primitive && "y" in primitive && ("w" in primitive && "h" in primitive || "r" in primitive))) continue;
|
|
1318
|
+
if (!primitive._element) continue;
|
|
1319
|
+
var w = "w" in primitive ? primitive.w : primitive.r * 2;
|
|
1320
|
+
var h = "h" in primitive ? primitive.h : primitive.r * 2;
|
|
1321
|
+
if (Math.abs(primitive.x - rwPoint.x) < w / 2 && Math.abs(primitive.y - rwPoint.y) < h / 2) {
|
|
1322
|
+
mousedPrimitives2.push(primitive);
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
} catch (err) {
|
|
1326
|
+
_didIteratorError = true;
|
|
1327
|
+
_iteratorError = err;
|
|
1328
|
+
} finally{
|
|
1329
|
+
try {
|
|
1330
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1331
|
+
_iterator.return();
|
|
1332
|
+
}
|
|
1333
|
+
} finally{
|
|
1334
|
+
if (_didIteratorError) {
|
|
1335
|
+
throw _iteratorError;
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
setMousedPrimitives(mousedPrimitives2);
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
}, children, /* @__PURE__ */ import_react3.default.createElement(ElementOverlayBox, {
|
|
1343
|
+
highlightedPrimitives: highlightedPrimitives
|
|
1344
|
+
}));
|
|
1345
|
+
};
|
|
1346
|
+
// src/components/CanvasElementsRenderer.tsx
|
|
1347
|
+
var CanvasElementsRenderer = function(props) {
|
|
1348
|
+
var primitives = (0, import_react6.useMemo)(function() {
|
|
1349
|
+
var primitives2 = props.elements.flatMap(function(elm) {
|
|
1350
|
+
return convertElementToPrimitives(elm, props.elements);
|
|
1351
|
+
});
|
|
1352
|
+
console.log(primitives2);
|
|
1353
|
+
return primitives2;
|
|
1354
|
+
}, [
|
|
1355
|
+
props.elements
|
|
1356
|
+
]);
|
|
1357
|
+
return /* @__PURE__ */ import_react5.default.createElement(MouseElementTracker, {
|
|
1358
|
+
transform: props.transform,
|
|
1359
|
+
primitives: primitives
|
|
1360
|
+
}, /* @__PURE__ */ import_react5.default.createElement(CanvasPrimitiveRenderer, {
|
|
1361
|
+
transform: props.transform,
|
|
1362
|
+
primitives: primitives,
|
|
1363
|
+
width: props.width,
|
|
1364
|
+
height: props.height,
|
|
1365
|
+
grid: props.grid
|
|
1366
|
+
}));
|
|
905
1367
|
};
|
|
906
|
-
|
|
907
1368
|
// src/PCBViewer.tsx
|
|
908
1369
|
var import_use_mouse_matrix_transform = __toESM(require_dist());
|
|
909
|
-
|
|
910
1370
|
// node_modules/react-use/esm/misc/util.js
|
|
911
|
-
var noop = function() {
|
|
912
|
-
};
|
|
1371
|
+
var noop = function noop() {};
|
|
913
1372
|
var isBrowser = typeof window !== "undefined";
|
|
914
|
-
|
|
915
1373
|
// node_modules/react-use/esm/useIsomorphicLayoutEffect.js
|
|
916
|
-
var
|
|
917
|
-
var useIsomorphicLayoutEffect = isBrowser ?
|
|
1374
|
+
var import_react7 = require("react");
|
|
1375
|
+
var useIsomorphicLayoutEffect = isBrowser ? import_react7.useLayoutEffect : import_react7.useEffect;
|
|
918
1376
|
var useIsomorphicLayoutEffect_default = useIsomorphicLayoutEffect;
|
|
919
|
-
|
|
920
1377
|
// node_modules/react-use/esm/useMeasure.js
|
|
921
|
-
var
|
|
1378
|
+
var import_react8 = require("react");
|
|
922
1379
|
var defaultState = {
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
1380
|
+
x: 0,
|
|
1381
|
+
y: 0,
|
|
1382
|
+
width: 0,
|
|
1383
|
+
height: 0,
|
|
1384
|
+
top: 0,
|
|
1385
|
+
left: 0,
|
|
1386
|
+
bottom: 0,
|
|
1387
|
+
right: 0
|
|
931
1388
|
};
|
|
932
1389
|
function useMeasure() {
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
1390
|
+
var _a = (0, import_react8.useState)(null), element = _a[0], ref = _a[1];
|
|
1391
|
+
var _b = (0, import_react8.useState)(defaultState), rect = _b[0], setRect = _b[1];
|
|
1392
|
+
var observer = (0, import_react8.useMemo)(function() {
|
|
1393
|
+
return new window.ResizeObserver(function(entries) {
|
|
1394
|
+
if (entries[0]) {
|
|
1395
|
+
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;
|
|
1396
|
+
setRect({
|
|
1397
|
+
x: x,
|
|
1398
|
+
y: y,
|
|
1399
|
+
width: width,
|
|
1400
|
+
height: height,
|
|
1401
|
+
top: top_1,
|
|
1402
|
+
left: left,
|
|
1403
|
+
bottom: bottom,
|
|
1404
|
+
right: right
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1407
|
+
});
|
|
1408
|
+
}, []);
|
|
1409
|
+
useIsomorphicLayoutEffect_default(function() {
|
|
1410
|
+
if (!element) return;
|
|
1411
|
+
observer.observe(element);
|
|
1412
|
+
return function() {
|
|
1413
|
+
observer.disconnect();
|
|
1414
|
+
};
|
|
1415
|
+
}, [
|
|
1416
|
+
element
|
|
1417
|
+
]);
|
|
1418
|
+
return [
|
|
1419
|
+
ref,
|
|
1420
|
+
rect
|
|
1421
|
+
];
|
|
952
1422
|
}
|
|
953
|
-
var useMeasure_default = isBrowser && typeof window.ResizeObserver !== "undefined" ? useMeasure : function() {
|
|
954
|
-
|
|
1423
|
+
var useMeasure_default = isBrowser && typeof window.ResizeObserver !== "undefined" ? useMeasure : function useMeasure_default() {
|
|
1424
|
+
return [
|
|
1425
|
+
noop,
|
|
1426
|
+
defaultState
|
|
1427
|
+
];
|
|
955
1428
|
};
|
|
956
|
-
|
|
957
1429
|
// src/PCBViewer.tsx
|
|
958
1430
|
var import_transformation_matrix3 = require("transformation-matrix");
|
|
959
1431
|
var import_builder2 = require("@tscircuit/builder");
|
|
960
1432
|
var defaultTransform = (0, import_transformation_matrix3.compose)((0, import_transformation_matrix3.translate)(400, 300), (0, import_transformation_matrix3.scale)(40, 40));
|
|
961
|
-
var PCBViewer = (
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1433
|
+
var PCBViewer = function(param) {
|
|
1434
|
+
var children = param.children, soup = param.soup, _param_height = param.height, height = _param_height === void 0 ? 600 : _param_height;
|
|
1435
|
+
var _ref = _sliced_to_array((0, import_react9.useState)([]), 2), stateElements = _ref[0], setStateElements = _ref[1];
|
|
1436
|
+
var _useMeasure_default = _sliced_to_array(useMeasure_default(), 2), ref = _useMeasure_default[0], refDimensions = _useMeasure_default[1];
|
|
1437
|
+
var _ref1 = _sliced_to_array((0, import_react9.useState)(defaultTransform), 2), transform = _ref1[0], setTransformInternal = _ref1[1];
|
|
1438
|
+
var _ref2 = (0, import_use_mouse_matrix_transform.default)({
|
|
1439
|
+
transform: transform,
|
|
1440
|
+
onSetTransform: setTransformInternal
|
|
1441
|
+
}), transformRef = _ref2.ref, setTransform = _ref2.setTransform;
|
|
1442
|
+
var _ref3 = _sliced_to_array((0, import_react9.useState)(null), 2), error = _ref3[0], setError = _ref3[1];
|
|
1443
|
+
var resetTransform = function() {
|
|
1444
|
+
var elmBounds = (refDimensions === null || refDimensions === void 0 ? void 0 : refDimensions.width) > 0 ? refDimensions : {
|
|
1445
|
+
width: 500,
|
|
1446
|
+
height: 500
|
|
1447
|
+
};
|
|
1448
|
+
var _ref = elements.some(function(e) {
|
|
1449
|
+
return e.type.startsWith("pcb_");
|
|
1450
|
+
}) ? (0, import_builder2.findBoundsAndCenter)(elements.filter(function(e) {
|
|
1451
|
+
return e.type.startsWith("pcb_");
|
|
1452
|
+
})) : {
|
|
1453
|
+
center: {
|
|
1454
|
+
x: 0,
|
|
1455
|
+
y: 0
|
|
1456
|
+
},
|
|
1457
|
+
width: 1e-3,
|
|
1458
|
+
height: 1e-3
|
|
1459
|
+
}, center = _ref.center, width = _ref.width, height2 = _ref.height;
|
|
1460
|
+
var _elmBounds_width, _elmBounds_height;
|
|
1461
|
+
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);
|
|
1462
|
+
var _elmBounds_width1, _elmBounds_height1;
|
|
1463
|
+
setTransform((0, import_transformation_matrix3.compose)((0, import_transformation_matrix3.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),
|
|
1464
|
+
(0, import_transformation_matrix3.scale)(scaleFactor, scaleFactor, 0, 0), (0, import_transformation_matrix3.translate)(-center.x, -center.y)));
|
|
1465
|
+
};
|
|
1466
|
+
(0, import_react9.useEffect)(function() {
|
|
1467
|
+
if (!children || (children === null || children === void 0 ? void 0 : children.length) === 0) return;
|
|
1468
|
+
var projectBuilder = (0, import_builder.createProjectBuilder)();
|
|
1469
|
+
(0, import_react_fiber.createRoot)().render(children, projectBuilder).then(function(elements2) {
|
|
1470
|
+
setStateElements(elements2);
|
|
1471
|
+
setError(null);
|
|
1472
|
+
}).catch(function(e) {
|
|
1473
|
+
setError(e.toString());
|
|
1474
|
+
console.log(e.toString());
|
|
1475
|
+
});
|
|
1476
|
+
}, [
|
|
1477
|
+
children
|
|
1478
|
+
]);
|
|
1479
|
+
(0, import_react9.useEffect)(function() {
|
|
1480
|
+
if (refDimensions && refDimensions.width !== 0 && children) {
|
|
1481
|
+
resetTransform();
|
|
1482
|
+
}
|
|
1483
|
+
}, [
|
|
1484
|
+
children,
|
|
1485
|
+
refDimensions
|
|
1486
|
+
]);
|
|
1487
|
+
if (error) return /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
1488
|
+
style: {
|
|
1489
|
+
color: "red"
|
|
1490
|
+
}
|
|
1008
1491
|
}, " ", error, " ");
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
return
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1492
|
+
var elements = soup !== null && soup !== void 0 ? soup : stateElements;
|
|
1493
|
+
if (elements.length === 0) return null;
|
|
1494
|
+
return /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
1495
|
+
ref: transformRef
|
|
1496
|
+
}, /* @__PURE__ */ import_react9.default.createElement("div", {
|
|
1497
|
+
ref: ref
|
|
1498
|
+
}, /* @__PURE__ */ import_react9.default.createElement(CanvasElementsRenderer, {
|
|
1499
|
+
key: refDimensions.width,
|
|
1500
|
+
transform: transform,
|
|
1501
|
+
height: height,
|
|
1502
|
+
width: refDimensions.width,
|
|
1503
|
+
grid: {
|
|
1504
|
+
spacing: 1,
|
|
1505
|
+
view_window: {
|
|
1506
|
+
left: 0,
|
|
1507
|
+
right: refDimensions.width || 500,
|
|
1508
|
+
top: height,
|
|
1509
|
+
bottom: 0
|
|
1510
|
+
}
|
|
1511
|
+
},
|
|
1512
|
+
elements: elements.filter(function(elm) {
|
|
1513
|
+
return elm.type.startsWith("pcb_") || elm.type.startsWith("source_");
|
|
1514
|
+
})
|
|
1515
|
+
})));
|
|
1032
1516
|
};
|
|
1033
1517
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1034
1518
|
0 && (module.exports = {
|
|
1035
|
-
|
|
1036
|
-
|
|
1519
|
+
CanvasElementsRenderer: CanvasElementsRenderer,
|
|
1520
|
+
PCBViewer: PCBViewer
|
|
1037
1521
|
});
|
|
1038
1522
|
//# sourceMappingURL=index.js.map
|