@skillpet/circuit 0.6.0 → 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.
@@ -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 fromEnd = fromEl.absanchors.end;
17748
- if (!fromEnd) continue;
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 toStart = toEl.absanchors.start;
17753
- if (!toStart) continue;
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 key = `${i}|${j}`;
17761
- if (seen.has(key)) continue;
17762
- seen.add(key);
17763
- edges.push({ fromEl, toEl, fromColor, toColor });
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 = findLeadSegment(edge.fromEl, "lead2");
17779
- const lead1Seg = findLeadSegment(edge.toEl, "lead1");
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 findLeadSegment(el, role) {
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 void 0;
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]);
@@ -30920,13 +30964,28 @@ var Circuit = (() => {
30920
30964
  }
30921
30965
  _initTooltip() {
30922
30966
  const tip = document.createElement("div");
30923
- tip.style.cssText = "position:fixed;z-index:99999;pointer-events:none;opacity:0;transition:opacity .12s ease;background:rgba(30,30,30,.92);color:#fff;font-size:12px;line-height:1.4;padding:5px 10px;border-radius:4px;max-width:260px;white-space:pre-wrap;box-shadow:0 2px 8px rgba(0,0,0,.25)";
30967
+ tip.className = "schemdraw-tooltip";
30968
+ tip.style.cssText = "position:fixed;z-index:99999;pointer-events:none;opacity:0;transition:opacity .15s ease;font-size:12px;line-height:1.4;padding:6px 12px;border-radius:6px;max-width:260px;white-space:pre-wrap;";
30969
+ this._applyTooltipTheme(tip);
30924
30970
  document.body.appendChild(tip);
30925
30971
  this._tooltipEl = tip;
30926
30972
  }
30973
+ _applyTooltipTheme(tip) {
30974
+ const isDark = document.documentElement.classList.contains("dark") || document.documentElement.getAttribute("data-theme") === "dark" || typeof window !== "undefined" && window.matchMedia?.("(prefers-color-scheme: dark)").matches && !document.documentElement.classList.contains("light");
30975
+ if (isDark) {
30976
+ tip.style.background = "rgba(250,250,250,.95)";
30977
+ tip.style.color = "#1a1a1a";
30978
+ tip.style.boxShadow = "0 2px 12px rgba(0,0,0,.4)";
30979
+ } else {
30980
+ tip.style.background = "rgba(15,15,15,.92)";
30981
+ tip.style.color = "#fff";
30982
+ tip.style.boxShadow = "0 2px 8px rgba(0,0,0,.2)";
30983
+ }
30984
+ }
30927
30985
  _showTooltip(text2, clientX, clientY) {
30928
30986
  const tip = this._tooltipEl;
30929
30987
  if (!tip) return;
30988
+ this._applyTooltipTheme(tip);
30930
30989
  tip.textContent = text2;
30931
30990
  tip.style.opacity = "1";
30932
30991
  const gap2 = 10;