@skillpet/circuit 0.6.1 → 0.6.3
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 +106 -42
- package/dist/circuit.bundle.min.js +20 -20
- package/dist/circuit.esm.js +106 -42
- package/dist/drawing-transition.d.ts +11 -8
- package/dist/index.cjs +106 -42
- package/package.json +1 -1
package/dist/circuit.bundle.js
CHANGED
|
@@ -17738,29 +17738,56 @@ var Circuit = (() => {
|
|
|
17738
17738
|
const p = mergeParamsFirstWins(el.userParams, el.elmParams, el.defaults, el.dwgParams);
|
|
17739
17739
|
return p.color ?? "black";
|
|
17740
17740
|
}
|
|
17741
|
+
var EXCLUDED_ANCHORS = /* @__PURE__ */ new Set([
|
|
17742
|
+
"xy",
|
|
17743
|
+
"center",
|
|
17744
|
+
"istart",
|
|
17745
|
+
"iend",
|
|
17746
|
+
"mid",
|
|
17747
|
+
"label",
|
|
17748
|
+
"vd",
|
|
17749
|
+
"vs",
|
|
17750
|
+
"n1",
|
|
17751
|
+
"n2",
|
|
17752
|
+
"n1a",
|
|
17753
|
+
"n2a"
|
|
17754
|
+
]);
|
|
17755
|
+
function isConnectionAnchor(name) {
|
|
17756
|
+
return !EXCLUDED_ANCHORS.has(name);
|
|
17757
|
+
}
|
|
17758
|
+
function getConnectionAnchors(el) {
|
|
17759
|
+
const pts = [];
|
|
17760
|
+
for (const [name, pt] of Object.entries(el.absanchors)) {
|
|
17761
|
+
if (isConnectionAnchor(name)) pts.push(pt);
|
|
17762
|
+
}
|
|
17763
|
+
return pts;
|
|
17764
|
+
}
|
|
17741
17765
|
function buildConnectionGraph(elements) {
|
|
17742
17766
|
const edges = [];
|
|
17743
17767
|
const seen = /* @__PURE__ */ new Set();
|
|
17744
17768
|
const tol = 0.5;
|
|
17745
17769
|
for (let i = 0; i < elements.length; i++) {
|
|
17746
|
-
const
|
|
17747
|
-
const
|
|
17748
|
-
|
|
17749
|
-
|
|
17750
|
-
|
|
17751
|
-
const
|
|
17752
|
-
const
|
|
17753
|
-
if (
|
|
17754
|
-
const
|
|
17755
|
-
|
|
17756
|
-
|
|
17757
|
-
|
|
17758
|
-
|
|
17759
|
-
|
|
17760
|
-
|
|
17761
|
-
|
|
17762
|
-
|
|
17763
|
-
|
|
17770
|
+
const elA = elements[i];
|
|
17771
|
+
const colorA = resolveElementColor(elA);
|
|
17772
|
+
const anchorsA = getConnectionAnchors(elA);
|
|
17773
|
+
if (anchorsA.length === 0) continue;
|
|
17774
|
+
for (let j = i + 1; j < elements.length; j++) {
|
|
17775
|
+
const elB = elements[j];
|
|
17776
|
+
const colorB = resolveElementColor(elB);
|
|
17777
|
+
if (colorsEqual(colorA, colorB)) continue;
|
|
17778
|
+
const anchorsB = getConnectionAnchors(elB);
|
|
17779
|
+
if (anchorsB.length === 0) continue;
|
|
17780
|
+
for (const pa of anchorsA) {
|
|
17781
|
+
for (const pb of anchorsB) {
|
|
17782
|
+
if (Math.hypot(pa.x - pb.x, pa.y - pb.y) > tol) continue;
|
|
17783
|
+
const key = `${i}|${j}`;
|
|
17784
|
+
if (seen.has(key)) continue;
|
|
17785
|
+
seen.add(key);
|
|
17786
|
+
edges.push({ elA, elB, colorA, colorB, junctionPt: pa });
|
|
17787
|
+
break;
|
|
17788
|
+
}
|
|
17789
|
+
if (seen.has(`${i}|${j}`)) break;
|
|
17790
|
+
}
|
|
17764
17791
|
}
|
|
17765
17792
|
}
|
|
17766
17793
|
return edges;
|
|
@@ -17775,26 +17802,28 @@ var Circuit = (() => {
|
|
|
17775
17802
|
const cleanups = [];
|
|
17776
17803
|
let n = 0;
|
|
17777
17804
|
for (const edge of edges) {
|
|
17778
|
-
const
|
|
17779
|
-
const
|
|
17780
|
-
if (!
|
|
17781
|
-
if (
|
|
17805
|
+
const segA = findSegAtJunction(edge.elA, edge.junctionPt);
|
|
17806
|
+
const segB = findSegAtJunction(edge.elB, edge.junctionPt);
|
|
17807
|
+
if (!segA && !segB) continue;
|
|
17808
|
+
if (segA?.gradientStrokeId && segB?.gradientStrokeId) continue;
|
|
17782
17809
|
let gx1, gy1, gx2, gy2;
|
|
17783
|
-
if (
|
|
17784
|
-
const
|
|
17785
|
-
const
|
|
17786
|
-
|
|
17787
|
-
|
|
17788
|
-
|
|
17789
|
-
|
|
17790
|
-
|
|
17791
|
-
|
|
17810
|
+
if (segA && segB) {
|
|
17811
|
+
const a = segEndpointsSvg(edge.elA, segA, scale);
|
|
17812
|
+
const b = segEndpointsSvg(edge.elB, segB, scale);
|
|
17813
|
+
const aNear = nearFarSvg(edge.elA, segA, edge.junctionPt, scale);
|
|
17814
|
+
const bNear = nearFarSvg(edge.elB, segB, edge.junctionPt, scale);
|
|
17815
|
+
gx1 = aNear.farX;
|
|
17816
|
+
gy1 = aNear.farY;
|
|
17817
|
+
gx2 = bNear.farX;
|
|
17818
|
+
gy2 = bNear.farY;
|
|
17819
|
+
} else if (segA) {
|
|
17820
|
+
const c = segEndpointsSvg(edge.elA, segA, scale);
|
|
17792
17821
|
gx1 = c.x1;
|
|
17793
17822
|
gy1 = c.y1;
|
|
17794
17823
|
gx2 = c.x2;
|
|
17795
17824
|
gy2 = c.y2;
|
|
17796
17825
|
} else {
|
|
17797
|
-
const c = segEndpointsSvg(edge.
|
|
17826
|
+
const c = segEndpointsSvg(edge.elB, segB, scale);
|
|
17798
17827
|
gx1 = c.x1;
|
|
17799
17828
|
gy1 = c.y1;
|
|
17800
17829
|
gx2 = c.x2;
|
|
@@ -17802,17 +17831,17 @@ var Circuit = (() => {
|
|
|
17802
17831
|
}
|
|
17803
17832
|
if (gradientVectorLength({ x1: gx1, y1: gy1, x2: gx2, y2: gy2 }) < 1e-6) continue;
|
|
17804
17833
|
const id = `sd-trans-${n++}`;
|
|
17805
|
-
parts.push(gradientXml(id, gx1, gy1, gx2, gy2, edge.
|
|
17806
|
-
if (
|
|
17807
|
-
|
|
17834
|
+
parts.push(gradientXml(id, gx1, gy1, gx2, gy2, edge.colorA, edge.colorB));
|
|
17835
|
+
if (segA && !segA.gradientStrokeId) {
|
|
17836
|
+
segA.gradientStrokeId = id;
|
|
17808
17837
|
cleanups.push(() => {
|
|
17809
|
-
|
|
17838
|
+
segA.gradientStrokeId = void 0;
|
|
17810
17839
|
});
|
|
17811
17840
|
}
|
|
17812
|
-
if (
|
|
17813
|
-
|
|
17841
|
+
if (segB && !segB.gradientStrokeId) {
|
|
17842
|
+
segB.gradientStrokeId = id;
|
|
17814
17843
|
cleanups.push(() => {
|
|
17815
|
-
|
|
17844
|
+
segB.gradientStrokeId = void 0;
|
|
17816
17845
|
});
|
|
17817
17846
|
}
|
|
17818
17847
|
}
|
|
@@ -17823,11 +17852,46 @@ var Circuit = (() => {
|
|
|
17823
17852
|
}
|
|
17824
17853
|
};
|
|
17825
17854
|
}
|
|
17826
|
-
function
|
|
17855
|
+
function findSegAtJunction(el, junctionPt) {
|
|
17856
|
+
const tol = 0.6;
|
|
17827
17857
|
for (const s of el.segments) {
|
|
17828
|
-
if (s instanceof Segment
|
|
17858
|
+
if (!(s instanceof Segment)) continue;
|
|
17859
|
+
if (s.role !== "lead1" && s.role !== "lead2") continue;
|
|
17860
|
+
if (segTouchesPoint(el, s, junctionPt, tol)) return s;
|
|
17829
17861
|
}
|
|
17830
|
-
|
|
17862
|
+
let best;
|
|
17863
|
+
let bestDist = Infinity;
|
|
17864
|
+
for (const s of el.segments) {
|
|
17865
|
+
if (!(s instanceof Segment)) continue;
|
|
17866
|
+
if (s.path.length < 2) continue;
|
|
17867
|
+
if (s.role === "body") continue;
|
|
17868
|
+
if (s.path.length > 6) continue;
|
|
17869
|
+
const d = segDistToPoint(el, s, junctionPt);
|
|
17870
|
+
if (d < bestDist && d < tol) {
|
|
17871
|
+
bestDist = d;
|
|
17872
|
+
best = s;
|
|
17873
|
+
}
|
|
17874
|
+
}
|
|
17875
|
+
return best;
|
|
17876
|
+
}
|
|
17877
|
+
function segTouchesPoint(el, seg, absPt, tol) {
|
|
17878
|
+
return segDistToPoint(el, seg, absPt) < tol;
|
|
17879
|
+
}
|
|
17880
|
+
function segDistToPoint(el, seg, absPt) {
|
|
17881
|
+
const p0 = el.transform.transform(seg.path[0]);
|
|
17882
|
+
const pN = el.transform.transform(seg.path[seg.path.length - 1]);
|
|
17883
|
+
return Math.min(
|
|
17884
|
+
Math.hypot(p0.x - absPt.x, p0.y - absPt.y),
|
|
17885
|
+
Math.hypot(pN.x - absPt.x, pN.y - absPt.y)
|
|
17886
|
+
);
|
|
17887
|
+
}
|
|
17888
|
+
function nearFarSvg(el, seg, junctionPt, scale) {
|
|
17889
|
+
const p0 = el.transform.transform(seg.path[0]);
|
|
17890
|
+
const pN = el.transform.transform(seg.path[seg.path.length - 1]);
|
|
17891
|
+
const d0 = Math.hypot(p0.x - junctionPt.x, p0.y - junctionPt.y);
|
|
17892
|
+
const dN = Math.hypot(pN.x - junctionPt.x, pN.y - junctionPt.y);
|
|
17893
|
+
const far = d0 > dN ? p0 : pN;
|
|
17894
|
+
return { farX: far.x * scale, farY: -far.y * scale };
|
|
17831
17895
|
}
|
|
17832
17896
|
function segEndpointsSvg(el, seg, scale) {
|
|
17833
17897
|
const p0 = el.transform.transform(seg.path[0]);
|