(dirX: -1 | 0 | 1, dirY: -1 | 0 | 1)
| 342 | ); |
| 343 | |
| 344 | const createResizeHandler = (dirX: -1 | 0 | 1, dirY: -1 | 0 | 1) => { |
| 345 | const isCorner = dirX !== 0 && dirY !== 0; |
| 346 | |
| 347 | const handler = props.createMouseDownDrag( |
| 348 | () => { |
| 349 | if (isCorner) { |
| 350 | setIsResizing(true); |
| 351 | } |
| 352 | const seg = segment(); |
| 353 | return { |
| 354 | startPos: { ...seg.center }, |
| 355 | startSize: { ...seg.size }, |
| 356 | startFontSize: seg.fontSize, |
| 357 | }; |
| 358 | }, |
| 359 | (e, { startPos, startSize, startFontSize }, initialMouse) => { |
| 360 | const dx = (e.clientX - initialMouse.x) / props.size.width; |
| 361 | const dy = (e.clientY - initialMouse.y) / props.size.height; |
| 362 | |
| 363 | const isSide = dirX !== 0 && dirY === 0; |
| 364 | |
| 365 | const minSize = 0.03; |
| 366 | const maxSize = 0.95; |
| 367 | const minPadding = 0.02; |
| 368 | |
| 369 | props.updateSegment((s) => { |
| 370 | if (isSide) { |
| 371 | const targetWidth = startSize.x + dx * dirX; |
| 372 | const clampedWidth = props.clamp(targetWidth, minSize, maxSize); |
| 373 | const appliedDelta = clampedWidth - startSize.x; |
| 374 | |
| 375 | s.size.x = clampedWidth; |
| 376 | |
| 377 | const halfWidth = s.size.x / 2; |
| 378 | const halfHeight = s.size.y / 2; |
| 379 | s.center.x = props.clamp( |
| 380 | startPos.x + (dirX * appliedDelta) / 2, |
| 381 | halfWidth + minPadding, |
| 382 | 1 - halfWidth - minPadding, |
| 383 | ); |
| 384 | s.center.y = props.clamp( |
| 385 | s.center.y, |
| 386 | halfHeight + minPadding, |
| 387 | 1 - halfHeight - minPadding, |
| 388 | ); |
| 389 | } else if (isCorner) { |
| 390 | const currentHeightPx = startSize.y * props.size.height; |
| 391 | const deltaPxY = dy * props.size.height * dirY; |
| 392 | |
| 393 | const scaleY = (currentHeightPx + deltaPxY) / currentHeightPx; |
| 394 | const scale = scaleY; |
| 395 | |
| 396 | if (scale > 0.1 && scale < 10) { |
| 397 | const newFontSize = props.clamp(startFontSize * scale, 8, 400); |
| 398 | const newSizeX = props.clamp( |
| 399 | startSize.x * scale, |
| 400 | minSize, |
| 401 | maxSize, |
no test coverage detected