From c469b474cc6eaf6bc8c14af43eb95e6b09d06f2f Mon Sep 17 00:00:00 2001 From: bchanot Date: Fri, 20 Nov 2026 14:48:43 +0100 Subject: [PATCH] =?UTF-8?q?feat(editor):=20the=20=C2=AB=20=E2=88=92=20?= =?UTF-8?q?=C2=BB=20bubble=20follows=20the=20open=20side,=20on=20screen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../editor/annotations/AnnotationCanvas.tsx | 10 ++++++++- .../editor/annotations/HandleLayer.tsx | 22 ++++++++++++++----- .../editor/annotations/ZoneHandles.tsx | 22 +++++++++++++------ apps/app/tests/unit/editor-zone-edit.test.tsx | 14 ++++++++++++ 4 files changed, 54 insertions(+), 14 deletions(-) diff --git a/apps/app/src/components/editor/annotations/AnnotationCanvas.tsx b/apps/app/src/components/editor/annotations/AnnotationCanvas.tsx index ee5df696..52338165 100644 --- a/apps/app/src/components/editor/annotations/AnnotationCanvas.tsx +++ b/apps/app/src/components/editor/annotations/AnnotationCanvas.tsx @@ -114,6 +114,10 @@ export default function AnnotationCanvas(props: AnnotationCanvasProps) { handles: { ...props.handles, scale: gestures.framing.framing.scale, + pan: { + x: gestures.framing.framing.x, + y: gestures.framing.framing.y, + }, dragged: gestures.drag, }, }} @@ -223,7 +227,11 @@ interface LayerProps { root: RootAttributes | null transform: string overlay: Omit - handles: HandleData & { scale: number; dragged: Geometry | null } + handles: HandleData & { + scale: number + pan: { x: number; y: number } + dragged: Geometry | null + } } /** diff --git a/apps/app/src/components/editor/annotations/HandleLayer.tsx b/apps/app/src/components/editor/annotations/HandleLayer.tsx index 5109a0d9..5c8f6904 100644 --- a/apps/app/src/components/editor/annotations/HandleLayer.tsx +++ b/apps/app/src/components/editor/annotations/HandleLayer.tsx @@ -9,6 +9,7 @@ import { } from 'react' import type { Geometry } from '@faunosteo/core-wasm/types' import { parseFrame } from '@/editor/annotations/frame' +import { visibleBounds } from '@/editor/annotations/removeBubble' import { useHandleSizes, type HandleSizes, @@ -16,6 +17,7 @@ import { import { useAnnotationWork } from '@/editor/annotations/workStore' import ZoneHandles, { shownInserts, + type Scale, type ZoneHandle, type ZoneKeys, } from './ZoneHandles' @@ -33,6 +35,8 @@ export interface HandleLayerProps { ratio: string /** The framing's zoom: handles keep their CSS px size under it. */ scale: number + /** The framing's offset in CSS px: with the zoom, the part of the drawing on screen. */ + pan: { x: number; y: number } handle: PointHandle | null onKeyDown: (event: KeyboardEvent) => void onBlur: (event: FocusEvent) => void @@ -69,8 +73,9 @@ function useBoxSize(svg: RefObject) { /** * Drawing units per CSS px: the box over the frame (`meet`), times the zoom. Unknown * before layout (0 px), one unit per px. - * shortcut: assumes a `meet` ratio (the core's default); a `none` ratio would need one - * factor per axis. Upgrade: read both factors when a drawing ships `none`. + * shortcut: assumes a `meet` ratio (the core's default), here and in `visibleBounds`; a + * `none` ratio would need one factor per axis. Upgrade: read both factors when a drawing + * ships `none`. */ function unitsPerPx( viewBox: string, @@ -90,10 +95,15 @@ function unitsPerPx( */ export default function HandleLayer(props: HandleLayerProps) { const svg = useRef(null) - const unit = unitsPerPx(props.viewBox, useBoxSize(svg), props.scale) + const size = useBoxSize(svg) + const unit = unitsPerPx(props.viewBox, size, props.scale) const sizes = useHandleSizes() + const frame = parseFrame(props.viewBox) + const bounds = + frame && visibleBounds(frame, size, { ...props.pan, scale: props.scale }) + const scale: Scale = { unit, sizes, bounds, frame } const zone = useShownZone(props.zone, props.dragged) - useReportHidden(zone, { unit, sizes }, props.onInsertsHidden) + useReportHidden(zone, scale, props.onInsertsHidden) return ( )} @@ -139,7 +149,7 @@ function useShownZone( function useReportHidden( zone: ZoneHandle | null, - scale: Parameters[1], + scale: Pick, report: (hidden: boolean) => void, ) { const hidden = zone ? shownInserts(zone.points, scale).includes(false) : false diff --git a/apps/app/src/components/editor/annotations/ZoneHandles.tsx b/apps/app/src/components/editor/annotations/ZoneHandles.tsx index f43ed0a3..42f696e6 100644 --- a/apps/app/src/components/editor/annotations/ZoneHandles.tsx +++ b/apps/app/src/components/editor/annotations/ZoneHandles.tsx @@ -7,7 +7,9 @@ import { } from 'react' import type { Point } from '@faunosteo/core-wasm/types' import type { HandleSizes } from '@/editor/annotations/handleSize' +import type { Frame } from '@/editor/annotations/frame' import { MIN_VERTICES, showsInsert } from '@/editor/annotations/polygonEdit' +import { removeBubbleCentre } from '@/editor/annotations/removeBubble' import type { ZoneEdit } from '@/editor/annotations/useZoneEdit' import { useAnnotationWork } from '@/editor/annotations/workStore' import { useT } from '@/i18n/useT' @@ -29,17 +31,24 @@ export type ZoneKeys = Pick< | 'onRemoveKey' > -interface Scale { +export interface Scale { /** Drawing units per CSS px. */ unit: number sizes: HandleSizes + /** Where the « − » bubble may lie: the frame ∩ the part on screen; null: no bound. */ + bounds: Frame | null + /** The whole frame; null: none. */ + frame: Frame | null } const segmentPx = (a: Point, b: Point, unit: number) => Math.hypot(b[0] - a[0], b[1] - a[1]) / unit /** R-9: the « + » of segment `i` (vertex i to the next) shows at the current zoom. */ -export function shownInserts(points: readonly Point[], { unit, sizes }: Scale) { +export function shownInserts( + points: readonly Point[], + { unit, sizes }: Pick, +) { return points.map((p, i) => showsInsert(segmentPx(p, points[(i + 1) % points.length], unit), sizes.hit), ) @@ -184,14 +193,14 @@ function Vertex({ /** The « − » bubble over the chosen vertex (board 05), greyed at three vertices (12 B). */ function Remove({ - at, + centre, index, disabled, label, scale, onKeyDown, }: { - at: Point + centre: Point index: number disabled: boolean label: string @@ -203,8 +212,7 @@ function Remove({ const hitH = sizes.bubble.h * unit const w = sizes.bubbleMark.w * unit const h = sizes.bubbleMark.h * unit - const cx = at[0] - const cy = at[1] - (sizes.vertex / 2 + 6) * unit - hitH / 2 + const [cx, cy] = centre const fill = disabled ? 'var(--color-ink-muted)' : 'var(--color-danger-strong)' @@ -390,7 +398,7 @@ export default function ZoneHandles({ ))} {chosen !== null && ( { expect(chosen()).toMatchObject({ vertex: 1 }) }) + it('the « − » bubble of a bottom vertex opens below it, inside the frame', async () => { + await mount( + squareText([ + [20, 20], + [80, 20], + [50, 60], + ]), + ) + await select() + clickHandle('Sommet 3 de N', [50, 60]) + const rect = hitOf('Retirer le sommet 3 de N') + expect(Number(rect.getAttribute('y'))).toBeGreaterThan(60) + }) + it('on « − »: one removal, never a second', async () => { await mount(squareText([...SQUARE, [10, 50]])) await select()