@skillpet/circuit 0.6.1 → 0.6.2
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/circuit.bundle.js +60 -16
- package/dist/circuit.bundle.min.js +19 -19
- package/dist/circuit.esm.js +60 -16
- package/dist/drawing-transition.d.ts +7 -4
- package/dist/index.cjs +60 -16
- package/package.json +1 -1
package/dist/circuit.bundle.js
CHANGED
|
@@ -17738,29 +17738,52 @@ var Circuit = (() => {
|
|
|
17738
17738
|
const p = mergeParamsFirstWins(el.userParams, el.elmParams, el.defaults, el.dwgParams);
|
|
17739
17739
|
return p.color ?? "black";
|
|
17740
17740
|
}
|
|
17741
|
+
function getOutputAnchors(el) {
|
|
17742
|
+
const pts = [];
|
|
17743
|
+
const aa = el.absanchors;
|
|
17744
|
+
if (aa.end) pts.push(aa.end);
|
|
17745
|
+
if (aa.out && (!aa.end || !pointsClose(aa.out, aa.end, 0.01))) pts.push(aa.out);
|
|
17746
|
+
return pts;
|
|
17747
|
+
}
|
|
17748
|
+
function getInputAnchors(el) {
|
|
17749
|
+
const pts = [];
|
|
17750
|
+
const aa = el.absanchors;
|
|
17751
|
+
if (aa.start) pts.push(aa.start);
|
|
17752
|
+
for (const [name, pt] of Object.entries(aa)) {
|
|
17753
|
+
if (name.startsWith("in") && /^in\d+$/.test(name)) {
|
|
17754
|
+
if (!aa.start || !pointsClose(pt, aa.start, 0.01)) pts.push(pt);
|
|
17755
|
+
}
|
|
17756
|
+
}
|
|
17757
|
+
return pts;
|
|
17758
|
+
}
|
|
17759
|
+
function pointsClose(a, b, tol) {
|
|
17760
|
+
return Math.hypot(a.x - b.x, a.y - b.y) <= tol;
|
|
17761
|
+
}
|
|
17741
17762
|
function buildConnectionGraph(elements) {
|
|
17742
17763
|
const edges = [];
|
|
17743
17764
|
const seen = /* @__PURE__ */ new Set();
|
|
17744
17765
|
const tol = 0.5;
|
|
17745
17766
|
for (let i = 0; i < elements.length; i++) {
|
|
17746
17767
|
const fromEl = elements[i];
|
|
17747
|
-
const
|
|
17748
|
-
if (
|
|
17768
|
+
const fromPts = getOutputAnchors(fromEl);
|
|
17769
|
+
if (fromPts.length === 0) continue;
|
|
17770
|
+
const fromColor = resolveElementColor(fromEl);
|
|
17749
17771
|
for (let j = 0; j < elements.length; j++) {
|
|
17750
17772
|
if (i === j) continue;
|
|
17751
17773
|
const toEl = elements[j];
|
|
17752
|
-
const
|
|
17753
|
-
if (
|
|
17754
|
-
const dx = fromEnd.x - toStart.x;
|
|
17755
|
-
const dy = fromEnd.y - toStart.y;
|
|
17756
|
-
if (Math.hypot(dx, dy) > tol) continue;
|
|
17757
|
-
const fromColor = resolveElementColor(fromEl);
|
|
17774
|
+
const toPts = getInputAnchors(toEl);
|
|
17775
|
+
if (toPts.length === 0) continue;
|
|
17758
17776
|
const toColor = resolveElementColor(toEl);
|
|
17759
17777
|
if (colorsEqual(fromColor, toColor)) continue;
|
|
17760
|
-
const
|
|
17761
|
-
|
|
17762
|
-
|
|
17763
|
-
|
|
17778
|
+
for (const fp of fromPts) {
|
|
17779
|
+
for (const tp of toPts) {
|
|
17780
|
+
if (!pointsClose(fp, tp, tol)) continue;
|
|
17781
|
+
const key = `${i}|${j}`;
|
|
17782
|
+
if (seen.has(key)) continue;
|
|
17783
|
+
seen.add(key);
|
|
17784
|
+
edges.push({ fromEl, toEl, fromColor, toColor, junctionPt: fp });
|
|
17785
|
+
}
|
|
17786
|
+
}
|
|
17764
17787
|
}
|
|
17765
17788
|
}
|
|
17766
17789
|
return edges;
|
|
@@ -17775,8 +17798,8 @@ var Circuit = (() => {
|
|
|
17775
17798
|
const cleanups = [];
|
|
17776
17799
|
let n = 0;
|
|
17777
17800
|
for (const edge of edges) {
|
|
17778
|
-
const lead2Seg =
|
|
17779
|
-
const lead1Seg =
|
|
17801
|
+
const lead2Seg = findLeadSegmentFor(edge.fromEl, "out", edge.junctionPt);
|
|
17802
|
+
const lead1Seg = findLeadSegmentFor(edge.toEl, "in", edge.junctionPt);
|
|
17780
17803
|
if (!lead2Seg && !lead1Seg) continue;
|
|
17781
17804
|
if (lead2Seg?.gradientStrokeId && lead1Seg?.gradientStrokeId) continue;
|
|
17782
17805
|
let gx1, gy1, gx2, gy2;
|
|
@@ -17823,11 +17846,32 @@ var Circuit = (() => {
|
|
|
17823
17846
|
}
|
|
17824
17847
|
};
|
|
17825
17848
|
}
|
|
17826
|
-
function
|
|
17849
|
+
function findLeadSegmentFor(el, side, junctionPt) {
|
|
17850
|
+
const role = side === "in" ? "lead1" : "lead2";
|
|
17827
17851
|
for (const s of el.segments) {
|
|
17828
17852
|
if (s instanceof Segment && s.role === role) return s;
|
|
17829
17853
|
}
|
|
17830
|
-
return
|
|
17854
|
+
return findSegmentNearPoint(el, junctionPt);
|
|
17855
|
+
}
|
|
17856
|
+
function findSegmentNearPoint(el, absPt) {
|
|
17857
|
+
let best;
|
|
17858
|
+
let bestDist = Infinity;
|
|
17859
|
+
const tol = 0.6;
|
|
17860
|
+
for (const s of el.segments) {
|
|
17861
|
+
if (!(s instanceof Segment)) continue;
|
|
17862
|
+
if (s.path.length < 2) continue;
|
|
17863
|
+
if (s.role === "body") continue;
|
|
17864
|
+
const p0 = el.transform.transform(s.path[0]);
|
|
17865
|
+
const pN = el.transform.transform(s.path[s.path.length - 1]);
|
|
17866
|
+
const d0 = Math.hypot(p0.x - absPt.x, p0.y - absPt.y);
|
|
17867
|
+
const dN = Math.hypot(pN.x - absPt.x, pN.y - absPt.y);
|
|
17868
|
+
const d = Math.min(d0, dN);
|
|
17869
|
+
if (d < bestDist && d < tol) {
|
|
17870
|
+
bestDist = d;
|
|
17871
|
+
best = s;
|
|
17872
|
+
}
|
|
17873
|
+
}
|
|
17874
|
+
return best;
|
|
17831
17875
|
}
|
|
17832
17876
|
function segEndpointsSvg(el, seg, scale) {
|
|
17833
17877
|
const p0 = el.transform.transform(seg.path[0]);
|