(e)
| 2614 | |
| 2615 | // 拖拽调整大小 |
| 2616 | const resizeHandler = (e) => { |
| 2617 | e.preventDefault(); |
| 2618 | e.stopPropagation(); |
| 2619 | |
| 2620 | handle._isDragging = true; |
| 2621 | const startX = e.clientX; |
| 2622 | const startY = e.clientY; |
| 2623 | const startWidth = img.offsetWidth; |
| 2624 | const startHeight = img.offsetHeight; |
| 2625 | const aspectRatio = startWidth / startHeight; |
| 2626 | |
| 2627 | const onMouseMove = (moveEvent) => { |
| 2628 | const deltaX = moveEvent.clientX - startX; |
| 2629 | const deltaY = moveEvent.clientY - startY; |
| 2630 | |
| 2631 | // 根据x方向的变化计算新尺寸,保持宽高比 |
| 2632 | let newWidth = Math.max(50, startWidth + deltaX); |
| 2633 | let newHeight = newWidth / aspectRatio; |
| 2634 | |
| 2635 | // 计算可用的最大尺寸,避免遮挡底部按钮 |
| 2636 | const maxWidth = editor.offsetWidth - 40; |
| 2637 | const bottomBar = editor.parentElement.querySelector('.nsn-bottom'); |
| 2638 | const bottomBarHeight = bottomBar ? bottomBar.offsetHeight + 20 : 60; |
| 2639 | const maxHeight = editor.offsetHeight - bottomBarHeight; |
| 2640 | |
| 2641 | // 限制最大宽度 |
| 2642 | if (newWidth > maxWidth) { |
| 2643 | newWidth = maxWidth; |
| 2644 | newHeight = newWidth / aspectRatio; |
| 2645 | } |
| 2646 | |
| 2647 | // 限制最大高度,避免遮挡底部按钮 |
| 2648 | if (newHeight > maxHeight) { |
| 2649 | newHeight = maxHeight; |
| 2650 | newWidth = newHeight * aspectRatio; |
| 2651 | if (newWidth > maxWidth) { |
| 2652 | newWidth = maxWidth; |
| 2653 | newHeight = newWidth / aspectRatio; |
| 2654 | } |
| 2655 | } |
| 2656 | |
| 2657 | img.style.width = newWidth + 'px'; |
| 2658 | img.style.height = newHeight + 'px'; |
| 2659 | img.style.maxWidth = 'none'; |
| 2660 | }; |
| 2661 | |
| 2662 | const onMouseUp = (upEvent) => { |
| 2663 | handle._isDragging = false; |
| 2664 | document.removeEventListener('mousemove', onMouseMove); |
| 2665 | document.removeEventListener('mouseup', onMouseUp); |
| 2666 | |
| 2667 | // 检查是否仍在容器内,如果不在则隐藏手柄 |
| 2668 | const rect = container.getBoundingClientRect(); |
| 2669 | const mouseX = upEvent.clientX; |
| 2670 | const mouseY = upEvent.clientY; |
| 2671 | if (mouseX < rect.left || mouseX > rect.right || mouseY < rect.top || mouseY > rect.bottom) { |
| 2672 | handle.style.display = 'none'; |
| 2673 | container.style.border = '1px dashed transparent'; |
nothing calls this directly
no outgoing calls
no test coverage detected