(excludeId, x, y, w, h)
| 524 | } |
| 525 | |
| 526 | function updateDistanceHintsForDrag(excludeId, x, y, w, h) { |
| 527 | clearDistanceHints(); |
| 528 | const scale = parseFloat(preview.dataset.scale || "1"); |
| 529 | const cap = 200; |
| 530 | let bestH = null; |
| 531 | let bestV = null; |
| 532 | |
| 533 | function considerHorizontal(other) { |
| 534 | const ox = other.x; |
| 535 | const oy = other.y; |
| 536 | const ow = other.w; |
| 537 | const oh = other.h; |
| 538 | const yOverlap = !(y + h <= oy || y >= oy + oh); |
| 539 | if (!yOverlap) return; |
| 540 | if (ox >= x + w) { |
| 541 | const g = ox - (x + w); |
| 542 | if (g >= 0 && g <= cap && (!bestH || g < bestH.g)) |
| 543 | bestH = { g, mx: (x + w + ox) / 2, my: (Math.max(y, oy) + Math.min(y + h, oy + oh)) / 2 }; |
| 544 | } |
| 545 | if (ox + ow <= x) { |
| 546 | const g = x - (ox + ow); |
| 547 | if (g >= 0 && g <= cap && (!bestH || g < bestH.g)) |
| 548 | bestH = { g, mx: (ox + ow + x) / 2, my: (Math.max(y, oy) + Math.min(y + h, oy + oh)) / 2 }; |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | function considerVertical(other) { |
| 553 | const ox = other.x; |
| 554 | const oy = other.y; |
| 555 | const ow = other.w; |
| 556 | const oh = other.h; |
| 557 | const xOverlap = !(x + w <= ox || x >= ox + ow); |
| 558 | if (!xOverlap) return; |
| 559 | if (oy >= y + h) { |
| 560 | const g = oy - (y + h); |
| 561 | if (g >= 0 && g <= cap && (!bestV || g < bestV.g)) |
| 562 | bestV = { g, mx: (Math.max(x, ox) + Math.min(x + w, ox + ow)) / 2, my: (y + h + oy) / 2 }; |
| 563 | } |
| 564 | if (oy + oh <= y) { |
| 565 | const g = y - (oy + oh); |
| 566 | if (g >= 0 && g <= cap && (!bestV || g < bestV.g)) |
| 567 | bestV = { g, mx: (Math.max(x, ox) + Math.min(x + w, ox + ow)) / 2, my: (oy + oh + y) / 2 }; |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | for (const o of elements) { |
| 572 | if (o.id === excludeId || o.hidden) continue; |
| 573 | considerHorizontal(o); |
| 574 | considerVertical(o); |
| 575 | } |
| 576 | |
| 577 | function place(val, ax, ay) { |
| 578 | const s = document.createElement("div"); |
| 579 | s.className = "distance-hint"; |
| 580 | s.textContent = String(Math.round(val)); |
| 581 | s.style.left = ax * scale + "px"; |
| 582 | s.style.top = ay * scale + "px"; |
| 583 | preview.appendChild(s); |
no test coverage detected