From ce76ff98fc0d232e665924377a3c339c70ddb743 Mon Sep 17 00:00:00 2001 From: bchanot Date: Mon, 23 Nov 2026 14:08:36 +0100 Subject: [PATCH] feat(editor): radius handle for circle accesses --- .../editor/annotations/AnnotationCanvas.tsx | 9 +- .../annotations/EditableAnnotations.tsx | 7 ++ .../editor/annotations/HandleLayer.tsx | 18 +++ .../editor/annotations/RadiusHandle.tsx | 75 +++++++++++ .../app/src/editor/annotations/accessShape.ts | 20 +++ apps/app/src/editor/annotations/press.ts | 6 + .../src/editor/annotations/previewCommit.ts | 19 +-- .../src/editor/annotations/useBlockDrag.ts | 48 ++++++- .../src/editor/annotations/usePointEdit.ts | 53 +++++++- .../src/editor/annotations/usePressGesture.ts | 4 + apps/app/src/i18n/en.ts | 1 + apps/app/src/i18n/fr.ts | 1 + apps/app/tests/unit/annotations.press.test.ts | 33 ++++- .../app/tests/unit/editor-point-edit.test.tsx | 117 +++++++++++++++++- 14 files changed, 394 insertions(+), 17 deletions(-) create mode 100644 apps/app/src/components/editor/annotations/RadiusHandle.tsx diff --git a/apps/app/src/components/editor/annotations/AnnotationCanvas.tsx b/apps/app/src/components/editor/annotations/AnnotationCanvas.tsx index 41b18cac..95af5102 100644 --- a/apps/app/src/components/editor/annotations/AnnotationCanvas.tsx +++ b/apps/app/src/components/editor/annotations/AnnotationCanvas.tsx @@ -41,7 +41,14 @@ type OverlayData = Omit< /** The handle layer's content: the handle and its keys (the layer measures itself). */ export type HandleData = Pick< HandleLayerProps, - 'handle' | 'onKeyDown' | 'onBlur' | 'zone' | 'zoneKeys' | 'onInsertsHidden' + | 'handle' + | 'onKeyDown' + | 'onBlur' + | 'onRadiusKey' + | 'onRadiusBlur' + | 'zone' + | 'zoneKeys' + | 'onInsertsHidden' > export interface AnnotationCanvasProps { diff --git a/apps/app/src/components/editor/annotations/EditableAnnotations.tsx b/apps/app/src/components/editor/annotations/EditableAnnotations.tsx index a887becb..236a0c62 100644 --- a/apps/app/src/components/editor/annotations/EditableAnnotations.tsx +++ b/apps/app/src/components/editor/annotations/EditableAnnotations.tsx @@ -334,10 +334,15 @@ function useHandle(target: Annotation | null, doc: AnatomicalSheetDocument) { const label = t('editor.annotations.handle.shape') .replace('{kind}', () => kind) .replace('{name}', () => name) + const radiusLabel = + target.kind === 'detail_trigger' + ? t('editor.annotations.handle.radius').replace('{name}', () => name) + : null return { annotationId: target.id, label, stored: target.geometry, + radiusLabel, } } @@ -426,6 +431,8 @@ function CanvasStage({ handle, onKeyDown: work.edit.onHandleKey, onBlur: work.edit.onHandleBlur, + onRadiusKey: work.edit.onRadiusKey, + onRadiusBlur: work.edit.onRadiusBlur, zone, zoneKeys: work.zone, onInsertsHidden: work.setInsertsHidden, diff --git a/apps/app/src/components/editor/annotations/HandleLayer.tsx b/apps/app/src/components/editor/annotations/HandleLayer.tsx index a8a892bf..3f4a7d15 100644 --- a/apps/app/src/components/editor/annotations/HandleLayer.tsx +++ b/apps/app/src/components/editor/annotations/HandleLayer.tsx @@ -16,6 +16,7 @@ import { } from '@/editor/annotations/handleSize' import { useAnnotationWork } from '@/editor/annotations/workStore' import FrameHandles from './FrameHandles' +import RadiusHandle from './RadiusHandle' import ZoneHandles, { shownInserts, type Scale, @@ -29,6 +30,8 @@ export interface PointHandle { /** Its accessible name: « Point {nom} ». */ label: string stored: Geometry + /** D21: « Rayon de {nom} », for a circle access; null for a point. */ + radiusLabel: string | null } export interface HandleLayerProps { @@ -41,6 +44,9 @@ export interface HandleLayerProps { handle: PointHandle | null onKeyDown: (event: KeyboardEvent) => void onBlur: (event: FocusEvent) => void + /** The radius handle's keys (a circle access). */ + onRadiusKey: (event: KeyboardEvent) => void + onRadiusBlur: (event: FocusEvent) => void /** The selected polygon under the cap, and its handles' keys. */ zone: ZoneHandle | null zoneKeys: ZoneKeys @@ -124,6 +130,18 @@ export default function HandleLayer(props: HandleLayerProps) { unit={unit} /> )} + {props.handle?.radiusLabel && ( + + )} {props.crop && props.cropEdit && frame && ( ) => void + onBlur: (event: FocusEvent) => void +} + +/** + * D21: the radius handle of a circle access, on the circle's edge at angle 0. A focusable + * button whose hit shape carries `data-handle` for the press machine; its key series + * commits on Enter or blur, as the point handle's. + */ +export default function RadiusHandle(props: RadiusHandleProps) { + const { annotationId, unit, sizes } = props + const preview = useAnnotationWork((s) => + s.preview?.annotationId === annotationId ? s.preview.geometry : null, + ) + const shown = props.dragged ?? preview ?? props.stored + if (shown.type !== 'circle') return null + const cx = shown.cx + shown.r + const knob = (sizes.vertex / 2) * unit + return ( + + + + + + ) +} diff --git a/apps/app/src/editor/annotations/accessShape.ts b/apps/app/src/editor/annotations/accessShape.ts index cc913297..e3ea9ea6 100644 --- a/apps/app/src/editor/annotations/accessShape.ts +++ b/apps/app/src/editor/annotations/accessShape.ts @@ -64,6 +64,26 @@ export function circleFromDrag( return circleInside({ type: 'circle', cx: centre.x, cy: centre.y, r }, bounds) } +/** D5, D21: `circle` with the radius `r`, at least `minR` and no more than the centre's room + * in `bounds` (the centre stays), then kept inside them. */ +export function withRadius( + circle: Circle, + r: number, + minR: number, + bounds: Frame, +): Circle { + const room = Math.min( + circle.cx - bounds.x, + bounds.x + bounds.w - circle.cx, + circle.cy - bounds.y, + bounds.y + bounds.h - circle.cy, + ) + return circleInside( + { ...circle, r: Math.min(Math.max(r, minR), room) }, + bounds, + ) +} + /** D5: the default circle, a twelfth of the visible width in radius, centred on `at`. */ export function defaultCircle(at: XY, visible: Frame, bounds: Frame): Circle { return circleInside( diff --git a/apps/app/src/editor/annotations/press.ts b/apps/app/src/editor/annotations/press.ts index ef098220..397a8d72 100644 --- a/apps/app/src/editor/annotations/press.ts +++ b/apps/app/src/editor/annotations/press.ts @@ -31,6 +31,7 @@ export function pastSlop(kind: PointerKind, from: XY, to: XY): boolean { export type HandleRef = | { kind: 'point' } + | { kind: 'radius' } | { kind: 'vertex'; index: number } | { kind: 'remove'; index: number } | { kind: 'insert'; after: number } @@ -43,6 +44,7 @@ export type Hit = const RANK: Record = { point: 0, + radius: -1, vertex: 0, remove: 1, insert: 2, @@ -133,6 +135,8 @@ export function clickAction( : { type: 'unchoose' } } const { handle } = target + // The radius handle only drags: a click on it neither opens nor selects. + if (handle.kind === 'radius') return { type: 'nothing' } if (handle.kind === 'vertex') return { type: 'choose_vertex', index: handle.index } if (handle.kind === 'insert') return { type: 'insert', after: handle.after } @@ -175,6 +179,7 @@ export type DragAction = | { type: 'drag_mode' } | { type: 'drag_point' } | { type: 'drag_vertex'; index: number } + | { type: 'drag_radius' } | { type: 'draw' } | { type: 'drag_frame'; part: FramePart } | { type: 'drag_shape'; id: string } @@ -198,6 +203,7 @@ export function dragAction(target: PressTarget, ctx: DragContext): DragAction { if (target.kind === 'handle') { if (!ctx.movable) return { type: 'none', futile: false } if (target.handle.kind === 'point') return { type: 'drag_point' } + if (target.handle.kind === 'radius') return { type: 'drag_radius' } if (target.handle.kind === 'vertex') return { type: 'drag_vertex', index: target.handle.index } return { type: 'none', futile: false } diff --git a/apps/app/src/editor/annotations/previewCommit.ts b/apps/app/src/editor/annotations/previewCommit.ts index 26a21577..52aca2c1 100644 --- a/apps/app/src/editor/annotations/previewCommit.ts +++ b/apps/app/src/editor/annotations/previewCommit.ts @@ -58,12 +58,17 @@ export function stepSelection( const moved = movedBy(shown, delta, inMode ? mode.vertex : vertex) if (!moved) return if (inMode) return setModePreview(moved, stored) + setSeriesPreview(annotationId, moved, 'keys') +} + +/** A keyboard series' pending shape, stamped with the current text (R-13). */ +export function setSeriesPreview( + annotationId: string, + geometry: Geometry, + source: 'keys' | 'size', +): void { const base = useEditorStore.getState().documentText - const preview: Preview = { - annotationId, - geometry: moved, - base, - source: 'keys', - } - useAnnotationWork.setState({ preview }) + useAnnotationWork.setState({ + preview: { annotationId, geometry, base, source }, + }) } diff --git a/apps/app/src/editor/annotations/useBlockDrag.ts b/apps/app/src/editor/annotations/useBlockDrag.ts index 067bbf00..707e561b 100644 --- a/apps/app/src/editor/annotations/useBlockDrag.ts +++ b/apps/app/src/editor/annotations/useBlockDrag.ts @@ -1,8 +1,11 @@ import { useEffect, useRef, useState, type RefObject } from 'react' import type { Annotation, Geometry } from '@faunosteo/core-wasm/types' import { useEditorStore } from '../state/editorStore' -import type { XY } from './frame' -import { clientToDrawing, movedBy } from './gesture' +import { withRadius } from './accessShape' +import type { Frame, XY } from './frame' +import { MIN_FRAME_PX } from './frameBox' +import { parentFrame } from './frameDraw' +import { clientToDrawing, drawingPerClientPx, movedBy } from './gesture' import { isNoOpMove } from './polygonEdit' import { shownGeometry } from './previewCommit' import type { GeometryChange } from './usePlacement' @@ -34,6 +37,8 @@ interface Drag { mode: boolean /** The vertex dragged alone (a vertex handle, or the mode's chosen vertex). */ vertex: number | null + /** The radius dragged (D21): its smallest value and the frame it stays in, in units. */ + radius: { min: number; bounds: Frame } | null } function translatedAt( @@ -43,10 +48,19 @@ function translatedAt( ): Geometry | null { const now = clientToDrawing(overlay.current, client) if (!now) return null + if (drag.radius) return resizedTo(drag, drag.radius, now) const delta = { x: now.x - drag.origin.x, y: now.y - drag.origin.y } return movedBy(drag.base, delta, drag.vertex) } +/** D21: the circle with its radius at the pointer's distance from the centre. */ +function resizedTo(drag: Drag, radius: NonNullable, to: XY) { + const { base } = drag + if (base.type !== 'circle') return null + const r = Math.hypot(to.x - base.cx, to.y - base.cy) + return withRadius(base, r, radius.min, radius.bounds) +} + /** A vertex released on itself or on a neighbour moves nothing: no commit. */ function isNoOp(drag: Drag, dropped: Geometry): boolean { const { base, vertex } = drag @@ -57,10 +71,17 @@ function isNoOp(drag: Drag, dropped: Geometry): boolean { ) } +/** D21: a radius released where it started commits nothing; else one `size` update. */ +function commitRadius(input: BlockDragInput, drag: Drag, dropped: Geometry) { + if (JSON.stringify(dropped) === JSON.stringify(drag.base)) return + input.onDrop(drag.target.id, dropped, 'size') +} + /** A drop outside the mode commits once: the shape moved, or its vertex. */ function commitDrop(input: BlockDragInput, drag: Drag, dropped: Geometry) { if (drag.mode || isNoOp(drag, dropped)) return const { id } = drag.target + if (drag.radius) return void commitRadius(input, drag, dropped) if (drag.vertex === null) return void input.onDrop(id, dropped, 'move') // The dragged vertex stays chosen on the new text (board 05 B). if (input.onDrop(id, dropped, 'vertex')) chooseVertex(id, drag.vertex) @@ -116,7 +137,21 @@ function dragActions( ? (useAnnotationWork.getState().mode?.vertex ?? null) : vertex if (!mode && vertex !== null) chooseVertex(target.id, vertex) - drag.current = { target, origin, base, mode, vertex: own } + drag.current = { target, origin, base, mode, vertex: own, radius: null } + show(translatedAt(input.overlay, drag.current, client)) + } + /** D21: the radius handle's drag; the smallest radius is half the smallest frame side. */ + const startRadius = (client: XY, byFinger: boolean) => { + const { target } = input + const bounds = parentFrame(input.overlay.current) + const perPx = drawingPerClientPx(input.overlay.current) + if (!target || target.geometry.type !== 'circle') return + if (!bounds || perPx === null) return + const min = (MIN_FRAME_PX[byFinger ? 'touch' : 'mouse'] / 2) * perPx + const { geometry: base } = target + const origin = { x: base.cx, y: base.cy } + const radius = { min, bounds } + drag.current = { target, origin, base, mode: false, vertex: null, radius } show(translatedAt(input.overlay, drag.current, client)) } const follow = (client: XY) => { @@ -132,7 +167,7 @@ function dragActions( setPreview(null) if (gesture && dropped) commitDrop(input, gesture, dropped) } - return { start, follow, drop, cancel } + return { start, startRadius, follow, drop, cancel } } type Actions = ReturnType @@ -163,6 +198,11 @@ function useFinger(drag: RefObject, actions: Actions) { touch.current = byFinger && drag.current !== null if (touch.current) setFinger(client) }, + startRadius: (client: XY, byFinger: boolean) => { + actions.startRadius(client, byFinger) + touch.current = byFinger && drag.current !== null + if (touch.current) setFinger(client) + }, follow: (client: XY) => { actions.follow(client) if (touch.current && drag.current) setFinger(client) diff --git a/apps/app/src/editor/annotations/usePointEdit.ts b/apps/app/src/editor/annotations/usePointEdit.ts index 716f1fc7..69582767 100644 --- a/apps/app/src/editor/annotations/usePointEdit.ts +++ b/apps/app/src/editor/annotations/usePointEdit.ts @@ -2,9 +2,16 @@ import type { KeyboardEvent } from 'react' import type { Annotation } from '@faunosteo/core-wasm/types' import { useEditorStore } from '../state/editorStore' import { commitFocusedSeries } from './drawingGuard' -import { moveStep, type Frame } from './frame' +import { moveStep, round2, type Frame } from './frame' +import { withRadius } from './accessShape' import type { Drop } from './usePlacement' -import { takeMove, takePreview, stepSelection } from './previewCommit' +import { + setSeriesPreview, + shownGeometry, + stepSelection, + takeMove, + takePreview, +} from './previewCommit' import { chooseVertex, freshChosen } from './zoneEdit' import { endMode, @@ -45,6 +52,46 @@ function step(input: PointEditInput, direction: Direction, big: boolean) { stepSelection(target.id, target.geometry, { x: x * size, y: y * size }) } +/** D21: the smallest radius a key series reaches; the core judges the rest. */ +const MIN_KEY_RADIUS = 0.01 + +/** One key step of the radius, as a `size` series: grown or shrunk, kept in the frame. */ +function stepRadius(input: PointEditInput, grow: boolean, big: boolean) { + const { target, frame } = input + if (target?.geometry?.type !== 'circle' || !frame) return + const shown = shownGeometry(target.id, target.geometry) + if (shown.type !== 'circle') return + const size = moveStep(frame, big) * (grow ? 1 : -1) + const circle = withRadius( + shown, + round2(shown.r + size), + MIN_KEY_RADIUS, + frame, + ) + setSeriesPreview(target.id, circle, 'size') +} + +const RADIUS_GROWS: Record = { + ArrowRight: true, + ArrowUp: true, + ArrowLeft: false, + ArrowDown: false, +} + +/** The radius handle's keys: arrows grow or shrink (Shift ×10), Enter commits the series. */ +function radiusKeys(input: PointEditInput, commit: ReturnType) { + return (event: KeyboardEvent) => { + const grow = RADIUS_GROWS[event.key] + if (grow !== undefined) { + event.preventDefault() + return stepRadius(input, grow, event.shiftKey) + } + if (event.key !== 'Enter') return + event.preventDefault() + commit.size() + } +} + /** A preview back on the stored shape (there and back, a pinned slider) is no change. */ function changed( preview: Preview | null, @@ -106,6 +153,8 @@ export function usePointEdit(input: PointEditInput) { onHandleKey: handleKeys(input, commit), // BDR-050: leaving the handle commits its series; a move mode waits for « Valider ». onHandleBlur: () => commit.keys(), + onRadiusKey: radiusKeys(input, commit), + onRadiusBlur: () => commit.size(), commitSize: commit.size, // « Déplacer le sommet » while a vertex is chosen, else the whole shape. startMove: () => { diff --git a/apps/app/src/editor/annotations/usePressGesture.ts b/apps/app/src/editor/annotations/usePressGesture.ts index 4a75af61..f4305a97 100644 --- a/apps/app/src/editor/annotations/usePressGesture.ts +++ b/apps/app/src/editor/annotations/usePressGesture.ts @@ -268,6 +268,7 @@ const BLOCK_DRAGS = new Set([ 'drag_point', 'drag_mode', 'drag_vertex', + 'drag_radius', ]) const FRAME_DRAGS = new Set(['draw', 'drag_frame']) @@ -277,6 +278,7 @@ function focusSelector(handle: HandleRef): string | null { if (handle.kind === 'vertex') return `[data-vertex="${handle.index}"]` if (handle.kind === 'point') return '[data-testid="point-handle"]' if (handle.kind === 'frame') return `[data-frame-part="${handle.part}"]` + if (handle.kind === 'radius') return '[data-testid="radius-handle"]' return null } @@ -325,6 +327,8 @@ function applyEffect(f: Feed, effect: PressEffect, event: PointerEvent | null) { const finger = pointerKindOf(event.pointerType) === 'touch' const { pressedAt } = f.machine.current focusPressed(f, f.machine.current.target) + if (action.type === 'drag_radius') + return f.drag.startRadius(clientOf(event), finger) f.drag.start(pressedAt, clientOf(event), mode, vertex, finger) } } diff --git a/apps/app/src/i18n/en.ts b/apps/app/src/i18n/en.ts index 15fcd133..9c14f7a8 100644 --- a/apps/app/src/i18n/en.ts +++ b/apps/app/src/i18n/en.ts @@ -1865,6 +1865,7 @@ export const en: Dict = { 'editor.annotations.move.confirm': 'Confirm position', 'editor.annotations.move.cancel': 'Cancel', 'editor.annotations.handle.shape': '{kind} {name}', + 'editor.annotations.handle.radius': 'Radius of {name}', 'editor.annotations.handle.group': 'Vertices of {name}', 'editor.annotations.handle.vertex': 'Vertex {n} of {name}', 'editor.annotations.handle.insert': 'Add a vertex after vertex {n} of {name}', diff --git a/apps/app/src/i18n/fr.ts b/apps/app/src/i18n/fr.ts index f40632e9..af30273c 100644 --- a/apps/app/src/i18n/fr.ts +++ b/apps/app/src/i18n/fr.ts @@ -1934,6 +1934,7 @@ export const fr: Dict = { 'editor.annotations.move.confirm': 'Valider la position', 'editor.annotations.move.cancel': 'Annuler', 'editor.annotations.handle.shape': '{kind} {name}', + 'editor.annotations.handle.radius': 'Rayon de {name}', 'editor.annotations.handle.group': 'Sommets de {name}', 'editor.annotations.handle.vertex': 'Sommet {n} de {name}', 'editor.annotations.handle.insert': diff --git a/apps/app/tests/unit/annotations.press.test.ts b/apps/app/tests/unit/annotations.press.test.ts index 1c464822..c7519d1f 100644 --- a/apps/app/tests/unit/annotations.press.test.ts +++ b/apps/app/tests/unit/annotations.press.test.ts @@ -75,7 +75,10 @@ describe('nearestHandle (R-9)', () => { it('answers null without a handle', () => { expect( - nearestHandle([{ kind: 'annotation', id: 'a', access: false }], { x: 0, y: 0 }), + nearestHandle([{ kind: 'annotation', id: 'a', access: false }], { + x: 0, + y: 0, + }), ).toBeNull() }) }) @@ -491,3 +494,31 @@ describe('the frame, adjust phase (Task 8, D8)', () => { }) }) }) + +describe('the radius handle (Task 15, D21)', () => { + const radius: PressTarget = { kind: 'handle', handle: { kind: 'radius' } } + const ctx: DragContext = { + kind: 'mouse', + movable: true, + moveMode: false, + drawing: false, + adjusting: false, + } + + it('a drag of it resizes while the selection is movable, else does nothing', () => { + expect(dragAction(radius, ctx)).toEqual({ type: 'drag_radius' }) + expect(dragAction(radius, { ...ctx, movable: false })).toEqual({ + type: 'none', + futile: false, + }) + }) + + it('a click on it does nothing, and it beats the point at equal reach', () => { + expect(clickAction(radius, ZONE)).toEqual({ type: 'nothing' }) + const hits: Hit[] = [ + { kind: 'handle', handle: { kind: 'point' }, centre: { x: 10, y: 10 } }, + { kind: 'handle', handle: { kind: 'radius' }, centre: { x: 10, y: 10 } }, + ] + expect(nearestHandle(hits, { x: 10, y: 10 })).toEqual({ kind: 'radius' }) + }) +}) diff --git a/apps/app/tests/unit/editor-point-edit.test.tsx b/apps/app/tests/unit/editor-point-edit.test.tsx index 109e652f..498c2756 100644 --- a/apps/app/tests/unit/editor-point-edit.test.tsx +++ b/apps/app/tests/unit/editor-point-edit.test.tsx @@ -92,7 +92,11 @@ afterEach(() => { }) /** A link circle on the main view, opening the detail view `view-det` it adds first. */ -const withLink = (text: string, id: string) => { +const withLink = ( + text: string, + id: string, + circle = { cx: 70, cy: 70, r: 6 }, +) => { const withView = insert(text, { kind: 'view', value: { @@ -109,7 +113,7 @@ const withLink = (text: string, id: string) => { view_id: 'view-main', category_id: 'cat-a', laterality: 'unpaired', - geometry: { type: 'circle', cx: 70, cy: 70, r: 6 }, + geometry: { type: 'circle', ...circle }, review_status: 'to_confirm', color: null, kind: 'detail_trigger', @@ -825,3 +829,112 @@ describe('Safari: the focus after a press that commits a pending change', () => expect(document.activeElement).toBe(within(list).getAllByRole('button')[0]) }) }) + +describe('the radius handle (D5, D21)', () => { + const mouse = { + pointerId: 1, + isPrimary: true, + button: 0, + buttons: 1, + pointerType: 'mouse', + } + const radius = () => screen.getByRole('button', { name: /^Rayon de / }) + const radiusHit = () => radius().querySelector('[data-handle]')! + const dragTo = (x: number, y: number) => { + const el = radiusHit() + fireEvent.pointerDown(el, { ...mouse, clientX: 76, clientY: 70 }) + fireEvent.pointerMove(el, { ...mouse, clientX: x, clientY: y }) + fireEvent.pointerUp(el, { ...mouse, buttons: 0, clientX: x, clientY: y }) + } + const linked = () => withLink(withPoints(point('a', 50, 50, 5)), 'l') + + it('shows for a selected circle access only, as a button « Rayon de … »', async () => { + await mount(linked()) + await select(0) + expect(screen.queryByRole('button', { name: /^Rayon de / })).toBeNull() + await select(1) + expect(radius()).toHaveAttribute('tabindex', '0') + expect(radius().closest('[aria-hidden="true"]')).toBeNull() + expect(radiusHit()).toHaveAttribute('data-handle', '{"kind":"radius"}') + }) + + it('a drag sets the radius to the distance from the centre, committed once', async () => { + await mount(linked()) + await select(1) + const before = depth() + dragTo(82, 70) + expect(geometryOf('l')).toEqual({ type: 'circle', cx: 70, cy: 70, r: 12 }) + expect(depth()).toBe(before + 1) + expect(message()).toHaveTextContent('Taille modifiée') + }) + + it('a drag commits nothing before the release (BDR-050)', async () => { + await mount(linked()) + await select(1) + const before = depth() + const el = radiusHit() + fireEvent.pointerDown(el, { ...mouse, clientX: 76, clientY: 70 }) + fireEvent.pointerMove(el, { ...mouse, clientX: 82, clientY: 70 }) + expect(geometryOf('l')).toMatchObject({ r: 6 }) + expect(depth()).toBe(before) + fireEvent.pointerCancel(el, { ...mouse, buttons: 0 }) + expect(geometryOf('l')).toMatchObject({ r: 6 }) + }) + + it('a radius under the smallest readable side stops at it', async () => { + await mount(linked()) + await select(1) + dragTo(71, 70) + expect(geometryOf('l')).toMatchObject({ r: 8 }) + }) + + it('a radius that leaves the frame is clamped, the centre kept', async () => { + await mount(linked()) + await select(1) + dragTo(190, 70) + expect(geometryOf('l')).toEqual({ type: 'circle', cx: 70, cy: 70, r: 30 }) + }) + + it('arrows grow and shrink a series, Shift ×10, Enter commits once', async () => { + await mount(linked()) + await select(1) + const before = depth() + radius().focus() + fireEvent.keyDown(radius(), { key: 'ArrowRight' }) + fireEvent.keyDown(radius(), { key: 'ArrowUp', shiftKey: true }) + expect(geometryOf('l')).toMatchObject({ r: 6 }) + expect(depth()).toBe(before) + fireEvent.keyDown(radius(), { key: 'ArrowLeft' }) + fireEvent.keyDown(radius(), { key: 'Enter' }) + expect(geometryOf('l')).toMatchObject({ cx: 70, cy: 70, r: 11 }) + expect(depth()).toBe(before + 1) + expect(message()).toHaveTextContent('Taille modifiée') + }) + + it('shrinking with ArrowDown, then leaving the handle, commits (BDR-050)', async () => { + await mount(linked()) + await select(1) + fireEvent.keyDown(radius(), { key: 'ArrowDown', shiftKey: true }) + fireEvent.blur(radius()) + expect(geometryOf('l')).toMatchObject({ r: 1 }) + }) + + it('a radius the core refuses keeps the old circle and shows the refusal', async () => { + await mountLarge(withLink(drawnText(), 'l', { cx: 2000, cy: 1500, r: 400 })) + await select(0) + const before = depth() + const el = radiusHit() + fireEvent.pointerDown(el, { ...mouse, clientX: 2400, clientY: 1500 }) + fireEvent.pointerMove(el, { ...mouse, clientX: 2009, clientY: 1500 }) + fireEvent.pointerUp(el, { + ...mouse, + buttons: 0, + clientX: 2009, + clientY: 1500, + }) + expect(geometryOf('l')).toMatchObject({ r: 400 }) + expect(depth()).toBe(before) + expect(message()).toHaveTextContent('Taille refusée') + expect(screen.getByTestId('overlay-refused-place')).toBeInTheDocument() + }) +})