@orbat-mapper/tactical-draw 0.32.0 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1446,6 +1446,18 @@ interface TransformSession {
1446
1446
  * members are unaffected.
1447
1447
  */
1448
1448
  setSizeAnchor(anchor: SizeAnchor): void;
1449
+ /**
1450
+ * Whether each member is outlined inside the group box. Initialised from
1451
+ * `EditManyOptions.memberOutlines` (default `true`) and mutated by
1452
+ * [[setMemberOutlines]].
1453
+ */
1454
+ readonly memberOutlines: boolean;
1455
+ /**
1456
+ * Show or hide the per-member outlines inside the group box, leaving the box
1457
+ * and its handles as they are. A host turns them off when the members read
1458
+ * as one object (a group selected whole) rather than as separate picks.
1459
+ */
1460
+ setMemberOutlines(visible: boolean): void;
1449
1461
  /**
1450
1462
  * Replace the member set in place — the primitive behind shift-click toggle,
1451
1463
  * marquee replace, and single-edit → group folding, without tearing the
@@ -1700,6 +1712,11 @@ interface SnapCandidateRequest {
1700
1712
  pixel: PixelCoordinate;
1701
1713
  interaction: SnapInteraction;
1702
1714
  graphicId?: string;
1715
+ /**
1716
+ * Every graphic a multi-selection moves together; candidates of any of them
1717
+ * are skipped, so the group never snaps onto itself. Set instead of `graphicId`.
1718
+ */
1719
+ graphicIds?: readonly string[];
1703
1720
  controlPointIndex?: number;
1704
1721
  originalEvent?: unknown;
1705
1722
  }
@@ -1711,6 +1728,14 @@ interface SnapCandidate {
1711
1728
  controlPointIndex?: number;
1712
1729
  priority?: number;
1713
1730
  }
1731
+ /**
1732
+ * Host snap candidates near `request`. A provider that leaves out the moving
1733
+ * graphic's own candidates should check `request.graphicIds` (a multi-selection)
1734
+ * as well as `request.graphicId`. A move or scale that tests several
1735
+ * points of a graphic (a control measure's control points, a Note's or an
1736
+ * Image's corners and centre) asks once per tested point on each pointer move,
1737
+ * so keep it cheap: return only candidates near `request.pixel`.
1738
+ */
1714
1739
  type SnapCandidateProvider = (request: SnapCandidateRequest) => readonly SnapCandidate[];
1715
1740
  /**
1716
1741
  * A snap the host answers later, such as one to terrain it has to sample
@@ -1968,6 +1993,22 @@ interface EditManyOptions {
1968
1993
  interactionStyle?: InteractionStyle;
1969
1994
  /** Size anchor for ordinary control measures in the group. Uniform symbols retain their own unit. Default `"ground"`. */
1970
1995
  sizeAnchor?: SizeAnchor;
1996
+ /**
1997
+ * Whether each member gets its own outline inside the group box. Default
1998
+ * `true`; see `TransformSession.setMemberOutlines`. On
1999
+ * {@link TacticalDraw.syncTransformGraphics} it also applies to a live
2000
+ * session, where the other options are ignored.
2001
+ */
2002
+ memberOutlines?: boolean;
2003
+ }
2004
+ /**
2005
+ * A host-defined set of graphics outlined together as one passive box
2006
+ * ({@link TacticalDraw.setHighlightedGroups}), such as a group the pointer is
2007
+ * over. `id` keys the outline; `graphicIds` are the graphics it encloses.
2008
+ */
2009
+ interface HighlightedGroup {
2010
+ id: string;
2011
+ graphicIds: readonly string[];
1971
2012
  }
1972
2013
  /**
1973
2014
  * Draft control measure handed to `TacticalDraw.draw`. `kind` is required up
@@ -2148,6 +2189,8 @@ declare class TacticalDraw {
2148
2189
  * `render()` so outlines track geometry, style, and dropped graphics.
2149
2190
  */
2150
2191
  private highlightedIds;
2192
+ /** Graphic sets outlined as one box each ({@link setHighlightedGroups}). */
2193
+ private highlightedGroups;
2151
2194
  private pinBodies;
2152
2195
  /** Resolved marker icons, so pin, highlight and view rebuilds don't re-ask the host. */
2153
2196
  private markerRenders;
@@ -2330,6 +2373,17 @@ declare class TacticalDraw {
2330
2373
  * "locked selection" chrome.
2331
2374
  */
2332
2375
  setHighlightedGraphics(ids: readonly string[]): void;
2376
+ /**
2377
+ * Replace the passive group outlines with `groups`: one outline box around
2378
+ * the joint bounds of each group's still-rendered graphics, drawn with the
2379
+ * same style and on the same layer as {@link setHighlightedGraphics}, which
2380
+ * it sits beside. Declarative like that set: `[]` clears every group
2381
+ * outline. A graphic in an active edit or transform session still counts
2382
+ * toward its group's bounds (at its last rendered geometry), so a host can
2383
+ * frame the group around a member being edited on its own. A group with no
2384
+ * rendered graphic draws nothing.
2385
+ */
2386
+ setHighlightedGroups(groups: readonly HighlightedGroup[]): void;
2333
2387
  /**
2334
2388
  * Cancel any pending coalesced highlight frame and re-project highlights
2335
2389
  * immediately. Used by every caller other than `setHighlightedGraphics`
@@ -2800,4 +2854,4 @@ declare function nearestWorldCopyLng(lng: number, refLng: number): number;
2800
2854
  /** `nearestWorldCopyLng` applied to a lon/lat position. */
2801
2855
  declare function nearestWorldCopyPosition(position: Position, refLng: number): Position;
2802
2856
  //#endregion
2803
- export { type AnchoredGraphic, BaseMapAdapter, type CombinedAbort, DEFAULT_EDIT_MODIFIERS, DEFAULT_LABEL_SIZE_PIXELS, DEFAULT_MARKER_SIZE, DEFAULT_PIN_PRESENTATION, DEFAULT_TEXT_SIZE_MAX_PIXELS, DEFAULT_TEXT_SIZE_MIN_PIXELS, type DeferredSnapProvider, type DrawImageDraft, type DrawMarkerDraft, type DrawMeasureDraft, type DrawNoteDraft, type DrawOptions, type DrawPointSymbolDraft, type DrawSession, type EditChangeEvent, type EditManyOptions, type EditMode, type EditModifiers, type EditOptions, type EditPointerDriver, type EditSession, type FeatureGroup, type FeatureHighlightBand, type Graphic, type GraphicEditChangeEvent, type GraphicEditSession, type GraphicGeometrySnappingOptions, type GraphicRender, type GraphicSnapshot, type GuideStyle, HATCH_PATTERNS, HIGHLIGHT_BAND_SLOTS, HIGHLIGHT_CASING_OUTSET_CSS_PIXELS, HIGHLIGHT_GLOW_BANDS, type HandleStyle, type HatchPattern, type HighlightBand, type HighlightBandSlot, type HighlightCasing, type IconResource, type ImageCapability, ImageCapabilityRequiredError, type ImageFootprint, type ImageGraphic, type ImageGraphicStyle, type ImageIntrinsicSize, type ImageOverlayResource, type ImageRender, type ImageResource, type ImageSize, type InteractionHit, type InteractionStyle, type LabelExtent, type LabelSizeBand, type LayerId, MINE_PATTERN_TILE_SIZE, type MapAdapter, type MapCursor, type MapEvent, type MapEventHandler, type Marker, type MarkerAnchor, type MarkerCapability, MarkerCapabilityRequiredError, type MarkerFootprint, type MarkerIcon, type MarkerRender, type MarkerSize, type MarkerStyle, type MergedPickFeature, type ModifierKey, NOTE_MAX_RASTER_PIXELS, NOTE_MAX_WIDTH, NOTE_MIN_WIDTH, type NativeEventEntry, type NoteBodyAlign, type NoteBodyStyle, type NoteCapability, NoteCapabilityRequiredError, type NoteEmSize, type NoteFadeThresholds, type NoteFontRoles, type NoteFootprint, type NoteFrame, type NoteFramePresetId, type NoteFrameTokenOverrides, type NoteGraphic, type NoteGraphicStyle, type NoteHeadingAlign, type NoteRaster, type NoteRender, type NoteStroke, type OffsetDragModifier, type PickCandidate, type PickCandidateHit, type PickCandidateHitKind, type PickCandidateInput, type PickEvaluationContext, type PickEvent, type PickHandler, type PickOptions, type PickPointerType, PinFootprint, PinOverridePatch, PinPresentation, PinPresentationCapability, PinPresentationPatch, PinPresentationState, PinPresentationStatus, PinPresentationStatusEvent, PinPresentationStore, PinRender, type PinnableGraphic, type PixelCoordinate, type PointSymbol, type PointSymbolAnchor, type PointSymbolCapability, PointSymbolCapabilityRequiredError, type PointSymbolColors, type PointSymbolConnector, type PointSymbolFootprint, type PointSymbolGraphicModifiers, type PointSymbolOffset, type PointSymbolOffsetControls, type PointSymbolOffsetLayout, type PointSymbolOffsetStyle, type PointSymbolPlacement, type PointSymbolProjection, type PointSymbolRect, type PointSymbolRender, type PointSymbolSize, type PointSymbolStyle, type PointSymbolView, type PointerCallback, PointerCallbackHub, type PointerEventInfo, type ResolvedEditModifiers, type ResolvedPickPresentation, type Rgba, type RotatedScreenBounds, type ScreenBounds, type SessionChangeSource, type SessionHistory, type SessionHistoryState, type SettleReason, type SizeAnchor, type SnapCandidate, type SnapCandidateProvider, type SnapCandidateRequest, type SnapInteraction, type SnapResult, type SnappingOptions, type StyleOptions, TEXT_FADE_END_RATIO, TEXT_HALO_BREAKPOINT_PIXELS, TEXT_HALO_COLOR, TOUCH_HIT_TOLERANCE_PX, TacticalDraw, TacticalDrawAbortError, type TacticalDrawAbortReason, TacticalDrawDestroyedError, type TacticalDrawLayerOptions, type TacticalDrawOptions, type TextAppearance, type TextSizeProps, type TextStyleOptions, type ToPixel, type TransformBox, type TransformChangeEvent, type TransformSession, type TransientChangeEvent, type TransientPhase, alignPointSymbolIndicator, bindAbortable, canResetGroundSizes, cloneImageGraphic, cloneMarker, cloneNoteGraphic, clonePointSymbol, coerceHandleStyle, combinePinScale, combineWithHostSignal, composeMarkerCapabilities, convertPointSymbolPlacement, effectivePointSymbolPixelSize, evaluatePickCandidates, fillPatternImageDimension, fillPatternImageId, getSizeAnchor, hasHighlightCasing, highlightBandsForStyle, highlightBandsInPaintOrder, highlightCasingWidth, hitTestFeature, hitTestIconFeature, ignoreAbort, imageFootprint, imageOpacity, isAnchoredGraphic, isImageGraphic, isMarker, isMinePattern, isNoteGraphic, isPinnableGraphic, isPointSymbol, isTacticalDrawAbortError, isValidPinNumber, makeFillPatternImage, markerFootprint, markerOpacity, mergeNativeAndCachedPickFeatures, movePointSymbolLocation, nearestWorldCopyLng, nearestWorldCopyPosition, normalizeImageGraphic, normalizeMarker, normalizeNoteGraphic, noteFootprint, noteOpacity, parseColor, pickHitTolerance, pickPointerType, pinDistanceScale, pinZoomScale, placePointSymbol, pointSymbolFootprint, pointSymbolResource, renderNoteForAdapter, renderOrderToVisualOrder, resetGroundSizeOptions, resizePointSymbolSize, resolveGroundTextSizePixels, resolveHighlightBands, resolveHighlightCasing, resolveMarkerRender, resolvePickPresentation, resolvePinPresentation, resolvePointSymbolOffset, resolveTextAppearance, resolveTextHaloWidth, resolveTextSizePixels, scalePointSymbolLayout, tryControlMeasureIdFromFeature, validateImageGraphic, validateMarker, validateNoteGraphic };
2857
+ export { type AnchoredGraphic, BaseMapAdapter, type CombinedAbort, DEFAULT_EDIT_MODIFIERS, DEFAULT_LABEL_SIZE_PIXELS, DEFAULT_MARKER_SIZE, DEFAULT_PIN_PRESENTATION, DEFAULT_TEXT_SIZE_MAX_PIXELS, DEFAULT_TEXT_SIZE_MIN_PIXELS, type DeferredSnapProvider, type DrawImageDraft, type DrawMarkerDraft, type DrawMeasureDraft, type DrawNoteDraft, type DrawOptions, type DrawPointSymbolDraft, type DrawSession, type EditChangeEvent, type EditManyOptions, type EditMode, type EditModifiers, type EditOptions, type EditPointerDriver, type EditSession, type FeatureGroup, type FeatureHighlightBand, type Graphic, type GraphicEditChangeEvent, type GraphicEditSession, type GraphicGeometrySnappingOptions, type GraphicRender, type GraphicSnapshot, type GuideStyle, HATCH_PATTERNS, HIGHLIGHT_BAND_SLOTS, HIGHLIGHT_CASING_OUTSET_CSS_PIXELS, HIGHLIGHT_GLOW_BANDS, type HandleStyle, type HatchPattern, type HighlightBand, type HighlightBandSlot, type HighlightCasing, type HighlightedGroup, type IconResource, type ImageCapability, ImageCapabilityRequiredError, type ImageFootprint, type ImageGraphic, type ImageGraphicStyle, type ImageIntrinsicSize, type ImageOverlayResource, type ImageRender, type ImageResource, type ImageSize, type InteractionHit, type InteractionStyle, type LabelExtent, type LabelSizeBand, type LayerId, MINE_PATTERN_TILE_SIZE, type MapAdapter, type MapCursor, type MapEvent, type MapEventHandler, type Marker, type MarkerAnchor, type MarkerCapability, MarkerCapabilityRequiredError, type MarkerFootprint, type MarkerIcon, type MarkerRender, type MarkerSize, type MarkerStyle, type MergedPickFeature, type ModifierKey, NOTE_MAX_RASTER_PIXELS, NOTE_MAX_WIDTH, NOTE_MIN_WIDTH, type NativeEventEntry, type NoteBodyAlign, type NoteBodyStyle, type NoteCapability, NoteCapabilityRequiredError, type NoteEmSize, type NoteFadeThresholds, type NoteFontRoles, type NoteFootprint, type NoteFrame, type NoteFramePresetId, type NoteFrameTokenOverrides, type NoteGraphic, type NoteGraphicStyle, type NoteHeadingAlign, type NoteRaster, type NoteRender, type NoteStroke, type OffsetDragModifier, type PickCandidate, type PickCandidateHit, type PickCandidateHitKind, type PickCandidateInput, type PickEvaluationContext, type PickEvent, type PickHandler, type PickOptions, type PickPointerType, PinFootprint, PinOverridePatch, PinPresentation, PinPresentationCapability, PinPresentationPatch, PinPresentationState, PinPresentationStatus, PinPresentationStatusEvent, PinPresentationStore, PinRender, type PinnableGraphic, type PixelCoordinate, type PointSymbol, type PointSymbolAnchor, type PointSymbolCapability, PointSymbolCapabilityRequiredError, type PointSymbolColors, type PointSymbolConnector, type PointSymbolFootprint, type PointSymbolGraphicModifiers, type PointSymbolOffset, type PointSymbolOffsetControls, type PointSymbolOffsetLayout, type PointSymbolOffsetStyle, type PointSymbolPlacement, type PointSymbolProjection, type PointSymbolRect, type PointSymbolRender, type PointSymbolSize, type PointSymbolStyle, type PointSymbolView, type PointerCallback, PointerCallbackHub, type PointerEventInfo, type ResolvedEditModifiers, type ResolvedPickPresentation, type Rgba, type RotatedScreenBounds, type ScreenBounds, type SessionChangeSource, type SessionHistory, type SessionHistoryState, type SettleReason, type SizeAnchor, type SnapCandidate, type SnapCandidateProvider, type SnapCandidateRequest, type SnapInteraction, type SnapResult, type SnappingOptions, type StyleOptions, TEXT_FADE_END_RATIO, TEXT_HALO_BREAKPOINT_PIXELS, TEXT_HALO_COLOR, TOUCH_HIT_TOLERANCE_PX, TacticalDraw, TacticalDrawAbortError, type TacticalDrawAbortReason, TacticalDrawDestroyedError, type TacticalDrawLayerOptions, type TacticalDrawOptions, type TextAppearance, type TextSizeProps, type TextStyleOptions, type ToPixel, type TransformBox, type TransformChangeEvent, type TransformSession, type TransientChangeEvent, type TransientPhase, alignPointSymbolIndicator, bindAbortable, canResetGroundSizes, cloneImageGraphic, cloneMarker, cloneNoteGraphic, clonePointSymbol, coerceHandleStyle, combinePinScale, combineWithHostSignal, composeMarkerCapabilities, convertPointSymbolPlacement, effectivePointSymbolPixelSize, evaluatePickCandidates, fillPatternImageDimension, fillPatternImageId, getSizeAnchor, hasHighlightCasing, highlightBandsForStyle, highlightBandsInPaintOrder, highlightCasingWidth, hitTestFeature, hitTestIconFeature, ignoreAbort, imageFootprint, imageOpacity, isAnchoredGraphic, isImageGraphic, isMarker, isMinePattern, isNoteGraphic, isPinnableGraphic, isPointSymbol, isTacticalDrawAbortError, isValidPinNumber, makeFillPatternImage, markerFootprint, markerOpacity, mergeNativeAndCachedPickFeatures, movePointSymbolLocation, nearestWorldCopyLng, nearestWorldCopyPosition, normalizeImageGraphic, normalizeMarker, normalizeNoteGraphic, noteFootprint, noteOpacity, parseColor, pickHitTolerance, pickPointerType, pinDistanceScale, pinZoomScale, placePointSymbol, pointSymbolFootprint, pointSymbolResource, renderNoteForAdapter, renderOrderToVisualOrder, resetGroundSizeOptions, resizePointSymbolSize, resolveGroundTextSizePixels, resolveHighlightBands, resolveHighlightCasing, resolveMarkerRender, resolvePickPresentation, resolvePinPresentation, resolvePointSymbolOffset, resolveTextAppearance, resolveTextHaloWidth, resolveTextSizePixels, scalePointSymbolLayout, tryControlMeasureIdFromFeature, validateImageGraphic, validateMarker, validateNoteGraphic };
package/dist/index.mjs CHANGED
@@ -3106,6 +3106,7 @@ function graphicCandidates(graphics) {
3106
3106
  return candidates;
3107
3107
  }
3108
3108
  function isSelfCandidate(candidate, request) {
3109
+ if (candidate.graphicId !== void 0 && request.graphicIds?.includes(candidate.graphicId)) return true;
3109
3110
  if (request.graphicId === void 0 || candidate.graphicId !== request.graphicId) return false;
3110
3111
  if (request.interaction === "reshape" && request.controlPointIndex !== void 0) return candidate.controlPointIndex === void 0 || candidate.controlPointIndex === request.controlPointIndex;
3111
3112
  return true;
@@ -3159,7 +3160,7 @@ function interpolatePosition(a, b, t) {
3159
3160
  for (let index = 0; index < dimensions; index += 1) position.push(a[index] + (b[index] - a[index]) * t);
3160
3161
  return position;
3161
3162
  }
3162
- function generatedGeometryCandidates(adapter, paths, request, options) {
3163
+ function generatedGeometryCandidates(project, paths, request, options) {
3163
3164
  const resolved = options === true ? {} : options;
3164
3165
  const edges = resolved.edges ?? true;
3165
3166
  const vertices = resolved.vertices ?? false;
@@ -3177,8 +3178,8 @@ function generatedGeometryCandidates(adapter, paths, request, options) {
3177
3178
  for (let index = 1; index < path.positions.length; index += 1) {
3178
3179
  const a = path.positions[index - 1];
3179
3180
  const b = path.positions[index];
3180
- const aPixel = adapter.getPixelFromCoordinate(a);
3181
- const bPixel = adapter.getPixelFromCoordinate(b);
3181
+ const aPixel = project(a);
3182
+ const bPixel = project(b);
3182
3183
  if (!aPixel || !bPixel) continue;
3183
3184
  const t = clampedSegmentParameter(request.pixel, aPixel, bPixel) ?? 0;
3184
3185
  candidates.push({
@@ -3212,30 +3213,23 @@ function createSnapResolver(adapter, getGraphics, getGeometryFeatures, getOption
3212
3213
  }
3213
3214
  return indexedGeometryPaths;
3214
3215
  };
3215
- return (request) => {
3216
- const options = getOptions();
3217
- const clear = () => options?.onSnap?.(null);
3218
- if (!options?.enabled || options.bypass?.(request.originalEvent)) {
3219
- clear();
3220
- return null;
3221
- }
3216
+ /** The snap for `request` under `options`, without reporting it. */
3217
+ const resolve = (request, options, project) => {
3218
+ if (!options?.enabled || options.bypass?.(request.originalEvent)) return null;
3222
3219
  const tolerance = options.tolerancePixels ?? DEFAULT_TOLERANCE_PIXELS;
3223
- if (!Number.isFinite(tolerance) || tolerance < 0) {
3224
- clear();
3225
- return null;
3226
- }
3220
+ if (!Number.isFinite(tolerance) || tolerance < 0) return null;
3227
3221
  const candidateLists = [];
3228
3222
  if (options.sources?.graphics !== false) candidateLists.push(builtInCandidates());
3229
3223
  const graphicGeometry = options.sources?.graphicGeometry;
3230
- if (graphicGeometry) candidateLists.push(generatedGeometryCandidates(adapter, geometryPaths(), request, graphicGeometry));
3224
+ if (graphicGeometry) candidateLists.push(generatedGeometryCandidates(project, geometryPaths(), request, graphicGeometry));
3231
3225
  const external = options.sources?.external?.(request);
3232
3226
  if (external) candidateLists.push(external);
3233
3227
  let best = null;
3234
3228
  for (const list of candidateLists) for (const candidate of list) {
3235
3229
  if (isSelfCandidate(candidate, request)) continue;
3236
- const pixel = adapter.getPixelFromCoordinate(candidate.coordinate);
3230
+ const pixel = project(candidate.coordinate);
3237
3231
  if (!pixel) continue;
3238
- const distancePixels = Math.hypot(pixel[0] - request.pixel[0], pixel[1] - request.pixel[1]);
3232
+ const distancePixels = pixelDistance$1(pixel, request.pixel);
3239
3233
  if (distancePixels > tolerance) continue;
3240
3234
  const priority = candidate.priority ?? 0;
3241
3235
  const bestPriority = best?.candidate.priority ?? 0;
@@ -3247,9 +3241,33 @@ function createSnapResolver(adapter, getGraphics, getGeometryFeatures, getOption
3247
3241
  distancePixels
3248
3242
  };
3249
3243
  }
3250
- options.onSnap?.(best);
3251
3244
  return best;
3252
3245
  };
3246
+ const closest = (requests, cursor) => {
3247
+ const options = getOptions();
3248
+ const pixels = /* @__PURE__ */ new Map();
3249
+ const project = (position) => {
3250
+ if (!pixels.has(position)) pixels.set(position, adapter.getPixelFromCoordinate(position));
3251
+ return pixels.get(position);
3252
+ };
3253
+ let best = null;
3254
+ for (const request of requests) {
3255
+ const result = resolve(request, options, project);
3256
+ if (!result) continue;
3257
+ const rank = cursor ? pixelDistance$1(result.pixel, cursor) : result.distancePixels;
3258
+ if (!best || rank < best.rank || rank === best.rank && result.distancePixels < best.result.distancePixels) best = {
3259
+ request,
3260
+ result,
3261
+ rank
3262
+ };
3263
+ }
3264
+ options?.onSnap?.(best?.result ?? null);
3265
+ return best && {
3266
+ request: best.request,
3267
+ result: best.result
3268
+ };
3269
+ };
3270
+ return Object.assign((request) => closest([request])?.result ?? null, { closest });
3253
3271
  }
3254
3272
  //#endregion
3255
3273
  //#region src/tactical-draw/draw-controller.ts
@@ -6227,47 +6245,58 @@ function runEdit(opts) {
6227
6245
  toDragPixel: (landed) => landed
6228
6246
  };
6229
6247
  }
6230
- /** A body drag snaps its moved first control point; null when it can't be placed. */
6231
- function translateTarget(pixel, info, drag) {
6232
- if (drag.fsm.kind !== "body") return null;
6233
- const first = drag.preDragPoints[0];
6234
- if (!first) return null;
6248
+ /**
6249
+ * Every moved control point of a body drag as a snap target, in order, null
6250
+ * where one can't be placed: the first is what `sources.deferred` is asked
6251
+ * about. Empty for any other box drag.
6252
+ */
6253
+ function translateTargets(pixel, info, drag) {
6254
+ if (drag.fsm.kind !== "body") return [];
6235
6255
  const cursor = driver.fromPixel(pixel);
6236
6256
  const origin = driver.fromPixel(drag.downPixel);
6237
- const anchor = [...first];
6238
- anchor[0] = first[0] + cursor[0] - origin[0];
6239
- anchor[1] = first[1] + cursor[1] - origin[1];
6240
- const anchorPixel = driver.toPixel(anchor);
6241
- if (!anchorPixel) return null;
6242
- return {
6243
- request: {
6244
- coordinate: anchor,
6245
- pixel: anchorPixel,
6246
- interaction: "translate",
6247
- graphicId: measure.id,
6248
- originalEvent: info?.native
6249
- },
6250
- toDragPixel: (landed) => {
6251
- const at = driver.fromPixel(landed);
6252
- return driver.toPixel([origin[0] + at[0] - first[0], origin[1] + at[1] - first[1]]) ?? [pixel[0] + landed[0] - anchorPixel[0], pixel[1] + landed[1] - anchorPixel[1]];
6253
- }
6254
- };
6257
+ const dx = cursor[0] - origin[0];
6258
+ const dy = cursor[1] - origin[1];
6259
+ return drag.preDragPoints.map((point) => {
6260
+ const moved = [...point];
6261
+ moved[0] = point[0] + dx;
6262
+ moved[1] = point[1] + dy;
6263
+ const movedPixel = driver.toPixel(moved);
6264
+ if (!movedPixel) return null;
6265
+ return {
6266
+ request: {
6267
+ coordinate: moved,
6268
+ pixel: movedPixel,
6269
+ interaction: "translate",
6270
+ graphicId: measure.id,
6271
+ originalEvent: info?.native
6272
+ },
6273
+ toDragPixel: (landed) => {
6274
+ const at = driver.fromPixel(landed);
6275
+ return driver.toPixel([origin[0] + at[0] - point[0], origin[1] + at[1] - point[1]]) ?? [pixel[0] + landed[0] - movedPixel[0], pixel[1] + landed[1] - movedPixel[1]];
6276
+ }
6277
+ };
6278
+ });
6255
6279
  }
6256
6280
  /**
6257
6281
  * Runs a drag at `pixel` through the immediate snap sources: the drag pixel
6258
6282
  * they put it at, and the target there for `sources.deferred` to answer.
6283
+ * `targetsAt` lists the points the immediate sources test, null where one
6284
+ * can't be placed; the first is the deferred target. The snap nearest the
6285
+ * cursor wins and is reported once.
6259
6286
  */
6260
- function snapDrag(pixel, targetAt) {
6261
- const target = targetAt(pixel);
6262
- const result = target && snap?.(target.request);
6263
- if (!result) return {
6287
+ function snapDrag(pixel, targetsAt) {
6288
+ const targets = targetsAt(pixel);
6289
+ const candidates = targets.filter((target) => target !== null);
6290
+ const hit = snap?.closest(candidates.map((candidate) => candidate.request), pixel);
6291
+ const winner = hit && candidates.find((candidate) => candidate.request === hit.request);
6292
+ if (!winner) return {
6264
6293
  pixel,
6265
- target
6294
+ target: targets[0] ?? null
6266
6295
  };
6267
- const snapped = target.toDragPixel(result.pixel);
6296
+ const snapped = winner.toDragPixel(hit.result.pixel);
6268
6297
  return {
6269
6298
  pixel: snapped,
6270
- target: targetAt(snapped)
6299
+ target: targetsAt(snapped)[0] ?? null
6271
6300
  };
6272
6301
  }
6273
6302
  const deferred = createDeferredDragSnap(deferredSnap, () => ctx.settled);
@@ -6483,7 +6512,7 @@ function runEdit(opts) {
6483
6512
  function paintDragSnapshot(pixel, info) {
6484
6513
  if (!activeDrag) return;
6485
6514
  const { controlPointIndex } = activeDrag;
6486
- const snapped = snapDrag(pixel, (at) => reshapeTarget(at, info, controlPointIndex));
6515
+ const snapped = snapDrag(pixel, (at) => [reshapeTarget(at, info, controlPointIndex)]);
6487
6516
  moveDeferred(snapped.pixel, snapped.target, (at) => paintDragAt(at, info));
6488
6517
  }
6489
6518
  function paintDragAt(resolvedPixel, info) {
@@ -6537,7 +6566,7 @@ function runEdit(opts) {
6537
6566
  function paintBoxDragSnapshot(pixel, info, constrainRotation = false) {
6538
6567
  if (!activeBoxDrag) return;
6539
6568
  const drag = activeBoxDrag;
6540
- const snapped = snapDrag(pixel, (at) => translateTarget(at, info, drag));
6569
+ const snapped = snapDrag(pixel, (at) => translateTargets(at, info, drag));
6541
6570
  moveDeferred(snapped.pixel, snapped.target, (at) => paintBoxDragAt(at, constrainRotation));
6542
6571
  }
6543
6572
  function paintBoxDragAt(resolvedPixel, constrainRotation) {
@@ -6684,7 +6713,7 @@ function runEdit(opts) {
6684
6713
  renderHandlesLayer();
6685
6714
  return;
6686
6715
  }
6687
- const snapped = snapDrag(pixel, (at) => reshapeTarget(at, info, controlPointIndex));
6716
+ const snapped = snapDrag(pixel, (at) => [reshapeTarget(at, info, controlPointIndex)]);
6688
6717
  deferred.finish(releaseDeferred(snapped.pixel, snapped.target), (finalPixel) => {
6689
6718
  const next = fsm.end(finalPixel, { constrainAngles: constrainHeld(info) });
6690
6719
  transient.emit("end", next, controlPointIndex);
@@ -6721,7 +6750,7 @@ function runEdit(opts) {
6721
6750
  preDragPoints,
6722
6751
  downPixel
6723
6752
  };
6724
- const snapped = snapDrag(pixel, (at) => translateTarget(at, info, drag));
6753
+ const snapped = snapDrag(pixel, (at) => translateTargets(at, info, drag));
6725
6754
  deferred.finish(releaseDeferred(snapped.pixel, snapped.target), (finalPixel) => {
6726
6755
  const finalSnapshot = fsm.move(finalPixel, { constrainRotation: constrainHeld(info) });
6727
6756
  replaceWorkingPoints(preDragPoints);
@@ -7490,6 +7519,55 @@ function createFrameCoalescer(run) {
7490
7519
  };
7491
7520
  }
7492
7521
  //#endregion
7522
+ //#region src/tactical-draw/box-snap.ts
7523
+ /**
7524
+ * The closest snap of `points`, tested as one request each and reported once.
7525
+ * With `cursor`, the snap nearest the cursor wins, so the part of the box being
7526
+ * dragged near snaps before a far one. Null with no resolver or no snap.
7527
+ */
7528
+ function closestBoxSnap(context, points, interaction, originalEvent, cursor) {
7529
+ if (!context.snap) return null;
7530
+ const { graphicId, graphicIds } = context;
7531
+ const requests = points.flatMap((coordinate) => {
7532
+ const pixel = context.toPixel(coordinate);
7533
+ return pixel ? [{
7534
+ coordinate,
7535
+ pixel,
7536
+ interaction,
7537
+ graphicId,
7538
+ graphicIds,
7539
+ originalEvent
7540
+ }] : [];
7541
+ });
7542
+ return context.snap.closest(requests, cursor);
7543
+ }
7544
+ /** How far `hit` moves the point it tested on the ground, in Web Mercator metres. */
7545
+ function groundSnapOffset(adapter, { request, result }) {
7546
+ const [fromX, fromY] = adapter.fromLonLat(request.coordinate);
7547
+ const [toX, toY] = adapter.fromLonLat(result.coordinate);
7548
+ return [toX - fromX, toY - fromY];
7549
+ }
7550
+ /**
7551
+ * A corner scale snapped to `target`: the factor that puts the dragged corner
7552
+ * of `startCorners` (TL, TR, BR, BL) at `target` projected on to its diagonal,
7553
+ * with the opposite corner fixed, and where `center` goes for a given factor.
7554
+ * Null for a degenerate box.
7555
+ */
7556
+ function snappedCornerScale(adapter, startCorners, cornerIndex, center, target) {
7557
+ const [anchorX, anchorY] = adapter.fromLonLat(startCorners[(cornerIndex + 2) % 4]);
7558
+ const [cornerX, cornerY] = adapter.fromLonLat(startCorners[cornerIndex]);
7559
+ const [toX, toY] = adapter.fromLonLat(target);
7560
+ const [centerX, centerY] = adapter.fromLonLat(center);
7561
+ const dx = cornerX - anchorX;
7562
+ const dy = cornerY - anchorY;
7563
+ const lengthSquared = dx * dx + dy * dy;
7564
+ if (lengthSquared === 0) return null;
7565
+ return {
7566
+ factor: ((toX - anchorX) * dx + (toY - anchorY) * dy) / lengthSquared,
7567
+ centerAt: (factor) => adapter.toLonLat([anchorX + (centerX - anchorX) * factor, anchorY + (centerY - anchorY) * factor])
7568
+ };
7569
+ }
7570
+ //#endregion
7493
7571
  //#region src/tactical-draw/transform-controller.ts
7494
7572
  /** No point symbol may scale below this factor of its own size — mirrors the box-drag floor. */
7495
7573
  const MIN_POINT_SYMBOL_SIZE = .1;
@@ -7535,11 +7613,12 @@ function defaultGroupSizeAnchor(graphics) {
7535
7613
  */
7536
7614
  function runGroupTransform(opts) {
7537
7615
  const constrainKey = () => opts.editModifiers().constrain;
7538
- const { adapter, capability, imageCapability, noteCapability, markerCapability, graphics, graphicsLayer, previewLayer, handlesLayer, renderOptions: renderOpts, signal, closeOnClickAway = true, interactionStyle, onSession, handleIdPrefix, publishWorkingGraphics, settleWorkingGraphics, isOnGraphicsLayer, onSettled, onClickAwayGraphicsPick } = opts;
7616
+ const { adapter, capability, imageCapability, noteCapability, markerCapability, graphics, graphicsLayer, previewLayer, handlesLayer, renderOptions: renderOpts, signal, closeOnClickAway = true, interactionStyle, onSession, handleIdPrefix, publishWorkingGraphics, settleWorkingGraphics, isOnGraphicsLayer, onSettled, onClickAwayGraphicsPick, snap } = opts;
7539
7617
  const { noteResolveCache } = opts;
7540
7618
  assertCapabilityFor(graphics);
7541
7619
  validateHostResources(graphics);
7542
7620
  let sizeAnchor = opts.sizeAnchor ?? defaultGroupSizeAnchor(graphics);
7621
+ let memberOutlines = opts.memberOutlines ?? true;
7543
7622
  /** Throw synchronously if any graphic in `list` is a point symbol and no capability was supplied. */
7544
7623
  function assertCapabilityFor(list) {
7545
7624
  if (!capability && list.some(isPointSymbol)) throw new PointSymbolCapabilityRequiredError();
@@ -7960,7 +8039,7 @@ function runGroupTransform(opts) {
7960
8039
  features.push(boxOutlineFeature(liveGroupBox, dragProjection.fromPixel, `${handleIdPrefix}:box-outline`, groupOutlineStyle(interactionStyle?.boxOutline)));
7961
8040
  features.push(...toFeatures(boxToHandles(liveGroupBox, dragProjection.fromPixel), handleIdPrefix, interactionStyle));
7962
8041
  }
7963
- features.push(...memberOutlineFeatures(members.flatMap((member) => member.box ? [[member.graphic.id, member.box]] : []), dragProjection.fromPixel, handleIdPrefix, interactionStyle?.boxOutline));
8042
+ if (memberOutlines) features.push(...memberOutlineFeatures(members.flatMap((member) => member.box ? [[member.graphic.id, member.box]] : []), dragProjection.fromPixel, handleIdPrefix, interactionStyle?.boxOutline));
7964
8043
  ctx.writeLayer(handlesLayer, [{
7965
8044
  id: "__td_transform_handles__",
7966
8045
  features,
@@ -8286,6 +8365,14 @@ function runGroupTransform(opts) {
8286
8365
  setSizeAnchor(next) {
8287
8366
  setSizeAnchor(next);
8288
8367
  },
8368
+ get memberOutlines() {
8369
+ return memberOutlines;
8370
+ },
8371
+ setMemberOutlines(visible) {
8372
+ if (ctx.settled || memberOutlines === visible) return;
8373
+ memberOutlines = visible;
8374
+ renderHandlesLayer();
8375
+ },
8289
8376
  setGraphics,
8290
8377
  syncHostGraphics,
8291
8378
  close,
@@ -8339,6 +8426,7 @@ function runGroupTransform(opts) {
8339
8426
  preDragPoints,
8340
8427
  preDragBox: groupBox,
8341
8428
  downPixel: pixel,
8429
+ bodySnap: boxHit.kind === "body" ? groupBodySnap(pixel) : null,
8342
8430
  lastSnapshot: {
8343
8431
  points: preDragPoints,
8344
8432
  box: groupBox
@@ -8350,8 +8438,48 @@ function runGroupTransform(opts) {
8350
8438
  dragInFlight = true;
8351
8439
  driver.setDragPanEnabled(false);
8352
8440
  };
8353
- function paintBoxDragSnapshot(pixel, constrainRotation = false) {
8441
+ /**
8442
+ * A body drag's snapping, from pointer-down at `downPixel`: the corners and
8443
+ * centre of the box around every member's footprint, without the edit
8444
+ * padding, in lon/lat. A corner near an intersection lines up two sides of
8445
+ * the group, an edge near a line that side. Null without a resolver.
8446
+ */
8447
+ function groupBodySnap(downPixel) {
8448
+ if (!snap) return null;
8449
+ const box = fitTransformBox(members.flatMap((member) => member.lastBoxPixels), boxAngle, 0);
8450
+ if (!box) return null;
8451
+ return {
8452
+ points: [...boxCorners(box), box.center].map((corner) => driver.fromPixel(corner)),
8453
+ origin: driver.fromPixel(downPixel),
8454
+ context: {
8455
+ adapter,
8456
+ snap,
8457
+ toPixel: (position) => driver.toPixel(position),
8458
+ graphicIds: members.map((member) => member.graphic.id)
8459
+ }
8460
+ };
8461
+ }
8462
+ /**
8463
+ * The drag pixel that puts a body drag at `pixel` on the snap nearest the
8464
+ * cursor: every snap point moves by the pointer's lon/lat delta (as
8465
+ * `beginBoxDrag` moves the members), and the winner's offset to its target is
8466
+ * added to the pointer. `pixel` itself with no snap.
8467
+ */
8468
+ function snappedDragPixel(bodySnap, pixel, info) {
8469
+ const { points, origin, context } = bodySnap;
8470
+ const cursor = driver.fromPixel(pixel);
8471
+ const dx = cursor[0] - origin[0];
8472
+ const dy = cursor[1] - origin[1];
8473
+ const hit = closestBoxSnap(context, points.map((point) => [point[0] + dx, point[1] + dy]), "translate", info?.native, pixel);
8474
+ if (!hit) return pixel;
8475
+ const { coordinate: from } = hit.request;
8476
+ const { coordinate: to } = hit.result;
8477
+ return driver.toPixel([cursor[0] + to[0] - from[0], cursor[1] + to[1] - from[1]]) ?? pixel;
8478
+ }
8479
+ function paintBoxDragSnapshot(rawPixel, constrainRotation = false, info) {
8354
8480
  if (!activeBoxDrag) return;
8481
+ const { bodySnap } = activeBoxDrag;
8482
+ const pixel = bodySnap ? snappedDragPixel(bodySnap, rawPixel, info) : rawPixel;
8355
8483
  const snapshot = activeBoxDrag.fsm.move(pixel, { constrainRotation });
8356
8484
  activeBoxDrag.lastSnapshot = snapshot;
8357
8485
  applyConcatenatedPoints(snapshot.points);
@@ -8365,7 +8493,7 @@ function runGroupTransform(opts) {
8365
8493
  const boxDragPaintCoalescer = createFrameCoalescer(paintBoxDragSnapshot);
8366
8494
  const onDriverMove = (pixel, info) => {
8367
8495
  if (ctx.settled) return;
8368
- if (activeBoxDrag) boxDragPaintCoalescer.schedule(pixel, modifierHeld(info, constrainKey()));
8496
+ if (activeBoxDrag) boxDragPaintCoalescer.schedule(pixel, modifierHeld(info, constrainKey()), info);
8369
8497
  };
8370
8498
  const onDriverUp = (pixel, info) => {
8371
8499
  if (!activeBoxDrag) return;
@@ -8376,7 +8504,7 @@ function runGroupTransform(opts) {
8376
8504
  driver.setDragPanEnabled(true);
8377
8505
  return;
8378
8506
  }
8379
- const { fsm, preDragPoints, preDragBox, downPixel, preDragOptionsOverrideByMember, preDragAmplifierPlacementsByMember, preDragPointSymbolStateByMember } = activeBoxDrag;
8507
+ const { fsm, preDragPoints, preDragBox, downPixel, preDragOptionsOverrideByMember, preDragAmplifierPlacementsByMember, preDragPointSymbolStateByMember, bodySnap } = activeBoxDrag;
8380
8508
  activeBoxDrag = null;
8381
8509
  driver.setDragPanEnabled(true);
8382
8510
  if (fsm.kind === "body" && withinClickSlop(pixel, downPixel)) {
@@ -8390,7 +8518,7 @@ function runGroupTransform(opts) {
8390
8518
  shell.noteBodyClick();
8391
8519
  return;
8392
8520
  }
8393
- const finalSnapshot = fsm.move(pixel, { constrainRotation: modifierHeld(info, constrainKey()) });
8521
+ const finalSnapshot = fsm.move(bodySnap ? snappedDragPixel(bodySnap, pixel, info) : pixel, { constrainRotation: modifierHeld(info, constrainKey()) });
8394
8522
  const { scale, rotation } = boxScaleRotation(fsm.kind, finalSnapshot.box, preDragBox);
8395
8523
  const nextPointSymbolStateByMember = scalePointSymbolStates(preDragPointSymbolStateByMember, scale, rotation);
8396
8524
  applyConcatenatedPoints(preDragPoints);
@@ -9210,24 +9338,52 @@ function runImageEdit(opts) {
9210
9338
  const result = drag.fsm.move(pixel, { constrainRotation: modifierHeld(info, constrainKey()) });
9211
9339
  next.position = [...result.points[0]];
9212
9340
  const delta = boxScaleRotation(drag.kind, result.box, drag.startBox);
9213
- if (drag.kind === "scale") next.size = {
9214
- value: Math.max(.1, next.size.value * delta.scale),
9215
- unit: "meters"
9216
- };
9217
- else if (drag.kind === "rotate") next.rotation = normalizeRotation(next.rotation + delta.rotation);
9341
+ if (drag.kind === "scale") {
9342
+ next.size = {
9343
+ value: Math.max(.1, next.size.value * delta.scale),
9344
+ unit: "meters"
9345
+ };
9346
+ return snappedScale(drag, next, info) ?? next;
9347
+ } else if (drag.kind === "rotate") next.rotation = normalizeRotation(next.rotation + delta.rotation);
9218
9348
  else {
9219
- const anchorPixel = driver.toPixel(next.position) ?? pixel;
9220
- const snapped = snap?.({
9221
- coordinate: next.position,
9222
- pixel: anchorPixel,
9223
- interaction: "translate",
9224
- graphicId: image.id,
9225
- originalEvent: info?.native
9226
- });
9227
- if (snapped) next.position = snapped.coordinate;
9349
+ const hit = closestBoxSnap(boxSnap, [next.position, ...cornersOf(next)], "translate", info?.native, pixel);
9350
+ if (hit) next.position = offsetGroundPosition(adapter, next.position, 0, ...groundSnapOffset(adapter, hit));
9228
9351
  }
9229
9352
  return next;
9230
9353
  };
9354
+ const boxSnap = {
9355
+ adapter,
9356
+ snap,
9357
+ toPixel: (position) => driver.toPixel(position),
9358
+ graphicId: image.id
9359
+ };
9360
+ /** `value`'s footprint corners TL, TR, BR, BL on the ground, without the edit padding. */
9361
+ const cornersOf = (value) => {
9362
+ const { width, height } = value.intrinsicSize;
9363
+ return groundBoxCoordinates(adapter, value.position, value.rotation, value.size.value, value.size.value * height / width);
9364
+ };
9365
+ /**
9366
+ * A corner scale whose dragged corner snaps: the snapped point projected on
9367
+ * to the diagonal from the fixed opposite corner gives the factor. Null when
9368
+ * nothing snaps.
9369
+ */
9370
+ const snappedScale = (current, scaled, info) => {
9371
+ const { start, cornerIndex } = current;
9372
+ if (cornerIndex === void 0) return null;
9373
+ const corner = cornersOf(scaled)[cornerIndex];
9374
+ const hit = closestBoxSnap(boxSnap, [corner], "reshape", info?.native);
9375
+ if (!hit) return null;
9376
+ const scale = snappedCornerScale(adapter, cornersOf(start), cornerIndex, start.position, hit.result.coordinate);
9377
+ if (!scale) return null;
9378
+ const value = Math.max(.1, start.size.value * scale.factor);
9379
+ const next = cloneImageGraphic(start);
9380
+ next.size = {
9381
+ value,
9382
+ unit: "meters"
9383
+ };
9384
+ next.position = scale.centerAt(value / start.size.value);
9385
+ return next;
9386
+ };
9231
9387
  const onDown = (pixel, info) => {
9232
9388
  if (ctx.settled || !box || !modes.includes("transform")) return;
9233
9389
  const hit = pickBoxHandle(box, pixel, info?.hitTolerance ?? 12);
@@ -9247,7 +9403,8 @@ function runImageEdit(opts) {
9247
9403
  kind: hit.kind,
9248
9404
  down: [...pixel],
9249
9405
  start: cloneImageGraphic(working),
9250
- startBox: box
9406
+ startBox: box,
9407
+ ...hit.kind === "scale" ? { cornerIndex: hit.index } : {}
9251
9408
  };
9252
9409
  driver.setDragPanEnabled(false);
9253
9410
  };
@@ -9566,13 +9723,24 @@ function runNoteEdit(opts) {
9566
9723
  * opposite edge keeps its ground position. The height follows the new layout,
9567
9724
  * growing or shrinking at the bottom.
9568
9725
  */
9569
- const widened = (current, pixel) => {
9726
+ const widened = (current, pixel, info) => {
9727
+ const pointer = groundAt(pixel);
9728
+ const side = current.index === 1 ? 1 : -1;
9729
+ const next = widenedUnsnapped(current, side, pointer);
9730
+ const corners = cornersOf(next);
9731
+ const edge = side === 1 ? [corners[1], corners[2]] : [corners[0], corners[3]];
9732
+ const midpoint = offsetGroundPosition(adapter, next.position, next.rotation, side * next.width * next.emSize.value / 2, 0);
9733
+ const hit = closestSnap([...edge, midpoint], "reshape", info, pixel);
9734
+ if (!hit) return next;
9735
+ const [dx, dy] = groundSnapOffset(adapter, hit);
9736
+ return widenedUnsnapped(current, side, [pointer[0] + dx, pointer[1] + dy]);
9737
+ };
9738
+ /** {@link widened} for a pointer at `pointer` in Web Mercator metres, without snapping. */
9739
+ const widenedUnsnapped = (current, side, pointer) => {
9570
9740
  const next = cloneNoteGraphic(current.start);
9571
9741
  const { start } = current;
9572
9742
  const em = start.emSize.value;
9573
- const side = current.index === 1 ? 1 : -1;
9574
9743
  const axis = [Math.cos(start.rotation) * side, -Math.sin(start.rotation) * side];
9575
- const pointer = groundAt(pixel);
9576
9744
  const pulled = (pointer[0] - current.downGround[0]) * axis[0] + (pointer[1] - current.downGround[1]) * axis[1];
9577
9745
  const width = Math.min(60, Math.max(2, start.width + pulled / em));
9578
9746
  next.width = width;
@@ -9580,8 +9748,8 @@ function runNoteEdit(opts) {
9580
9748
  };
9581
9749
  const transformed = (pixel, info) => {
9582
9750
  if (!drag) return null;
9583
- if (drag.kind === "width") return widened(drag, pixel);
9584
- const next = cloneNoteGraphic(drag.start);
9751
+ if (drag.kind === "width") return widened(drag, pixel, info);
9752
+ let next = cloneNoteGraphic(drag.start);
9585
9753
  const result = drag.fsm.move(pixel, { constrainRotation: modifierHeld(info, constrainKey()) });
9586
9754
  next.position = [...result.points[0]];
9587
9755
  const delta = boxScaleRotation(drag.kind, result.box, drag.startBox);
@@ -9595,25 +9763,58 @@ function runNoteEdit(opts) {
9595
9763
  };
9596
9764
  if (value !== startEm * delta.scale) {
9597
9765
  const factor = value / startEm;
9598
- const { anchor } = drag;
9766
+ const anchor = boxCorners(drag.startBox)[(drag.cornerIndex + 2) % 4];
9599
9767
  const center = driver.toPixel(drag.start.position);
9600
9768
  if (center) next.position = driver.fromPixel([anchor[0] + (center[0] - anchor[0]) * factor, anchor[1] + (center[1] - anchor[1]) * factor]);
9601
9769
  }
9770
+ next = snappedScale(drag, next, info) ?? next;
9602
9771
  } else if (drag.kind === "rotate") next.rotation = normalizeRotation(next.rotation + delta.rotation);
9603
9772
  else {
9604
- const anchorPixel = driver.toPixel(next.position) ?? pixel;
9605
- const snapped = snap?.({
9606
- coordinate: next.position,
9607
- pixel: anchorPixel,
9608
- interaction: "translate",
9609
- graphicId: note.id,
9610
- originalEvent: info?.native
9611
- });
9612
- if (snapped) next.position = snapped.coordinate;
9773
+ const corners = cornersOf(next, drag.startHeight);
9774
+ const hit = closestSnap([next.position, ...corners], "translate", info, pixel);
9775
+ if (hit) next.position = offsetGroundPosition(adapter, next.position, 0, ...groundSnapOffset(adapter, hit));
9613
9776
  }
9614
9777
  return next;
9615
9778
  };
9616
9779
  /**
9780
+ * A corner scale whose dragged corner snaps: the snapped point projected on
9781
+ * to the diagonal from the fixed opposite corner gives the factor, clamped to
9782
+ * the edit's `emSize` range. Null when nothing snaps.
9783
+ */
9784
+ const snappedScale = (current, scaled, info) => {
9785
+ const { start, startHeight, cornerIndex } = current;
9786
+ const corner = cornersOf(scaled, startHeight)[cornerIndex];
9787
+ const hit = closestSnap([corner], "reshape", info);
9788
+ if (!hit) return null;
9789
+ const scale = snappedCornerScale(adapter, cornersOf(start, startHeight), cornerIndex, start.position, hit.result.coordinate);
9790
+ if (!scale) return null;
9791
+ const [min, max] = current.emSizeRange;
9792
+ const value = Math.min(max, Math.max(min, start.emSize.value * scale.factor));
9793
+ const next = cloneNoteGraphic(start);
9794
+ next.emSize = {
9795
+ value,
9796
+ unit: "meters"
9797
+ };
9798
+ next.position = scale.centerAt(value / start.emSize.value);
9799
+ return next;
9800
+ };
9801
+ /**
9802
+ * `value`'s box corners TL, TR, BR, BL on the ground, without the edit
9803
+ * padding. Pass `height` in em when it is known, to skip measuring the layout.
9804
+ */
9805
+ const cornersOf = (value, height = heightOf(value)) => {
9806
+ const em = value.emSize.value;
9807
+ return groundBoxCoordinates(adapter, value.position, value.rotation, value.width * em, height * em);
9808
+ };
9809
+ const boxSnap = {
9810
+ adapter,
9811
+ snap,
9812
+ toPixel: (position) => driver.toPixel(position),
9813
+ graphicId: note.id
9814
+ };
9815
+ /** {@link closestBoxSnap} of the Note's `points`. */
9816
+ const closestSnap = (points, interaction, info, cursor) => closestBoxSnap(boxSnap, points, interaction, info?.native, cursor);
9817
+ /**
9617
9818
  * The `emSize` range a scale drag may reach: the limits around the size this
9618
9819
  * edit started with. `updateGraphic` can set a size outside them, so a drag
9619
9820
  * from there includes its start value rather than jumping to the limit.
@@ -9647,12 +9848,13 @@ function runNoteEdit(opts) {
9647
9848
  }),
9648
9849
  down: [...pixel],
9649
9850
  start: cloneNoteGraphic(working),
9650
- startBox: box
9851
+ startBox: box,
9852
+ startHeight: heightOf(working)
9651
9853
  };
9652
9854
  drag = hit.kind === "scale" ? {
9653
9855
  ...shared,
9654
9856
  kind: "scale",
9655
- anchor: boxCorners(box)[(hit.index + 2) % 4],
9857
+ cornerIndex: hit.index,
9656
9858
  emSizeRange: emSizeRange(working.emSize.value)
9657
9859
  } : {
9658
9860
  ...shared,
@@ -10286,6 +10488,8 @@ var TacticalDraw = class {
10286
10488
  * `render()` so outlines track geometry, style, and dropped graphics.
10287
10489
  */
10288
10490
  highlightedIds = [];
10491
+ /** Graphic sets outlined as one box each ({@link setHighlightedGroups}). */
10492
+ highlightedGroups = [];
10289
10493
  pinBodies = /* @__PURE__ */ new WeakMap();
10290
10494
  /** Resolved marker icons, so pin, highlight and view rebuilds don't re-ask the host. */
10291
10495
  markerRenders = /* @__PURE__ */ new WeakMap();
@@ -10821,6 +11025,24 @@ var TacticalDraw = class {
10821
11025
  this.highlightCoalescer.schedule();
10822
11026
  }
10823
11027
  /**
11028
+ * Replace the passive group outlines with `groups`: one outline box around
11029
+ * the joint bounds of each group's still-rendered graphics, drawn with the
11030
+ * same style and on the same layer as {@link setHighlightedGraphics}, which
11031
+ * it sits beside. Declarative like that set: `[]` clears every group
11032
+ * outline. A graphic in an active edit or transform session still counts
11033
+ * toward its group's bounds (at its last rendered geometry), so a host can
11034
+ * frame the group around a member being edited on its own. A group with no
11035
+ * rendered graphic draws nothing.
11036
+ */
11037
+ setHighlightedGroups(groups) {
11038
+ this.assertAlive();
11039
+ this.highlightedGroups = groups.map((group) => ({
11040
+ id: group.id,
11041
+ graphicIds: group.graphicIds.slice()
11042
+ }));
11043
+ this.highlightCoalescer.schedule();
11044
+ }
11045
+ /**
10824
11046
  * Cancel any pending coalesced highlight frame and re-project highlights
10825
11047
  * immediately. Used by every caller other than `setHighlightedGraphics`
10826
11048
  * (`render()`, view-change, session start / settle) so their own
@@ -10842,7 +11064,7 @@ var TacticalDraw = class {
10842
11064
  */
10843
11065
  renderHighlights() {
10844
11066
  if (this.destroyed) return;
10845
- if (this.highlightedIds.length === 0 && !this.hasHighlightOutlines) return;
11067
+ if (this.highlightedIds.length === 0 && this.highlightedGroups.length === 0 && !this.hasHighlightOutlines) return;
10846
11068
  const fromPixel = this.adapter.getCoordinateFromPixel?.bind(this.adapter);
10847
11069
  if (!fromPixel) return;
10848
11070
  const resolved = this.resolveInteractionStyle(void 0);
@@ -10852,6 +11074,28 @@ var TacticalDraw = class {
10852
11074
  const bearing = this.adapter.getBearing();
10853
11075
  const features = [];
10854
11076
  const pinGroups = [];
11077
+ const pushOutline = (box, featureId) => {
11078
+ let invertFailed = false;
11079
+ const invert = (pixel) => {
11080
+ const coord = fromPixel(pixel);
11081
+ if (!coord) {
11082
+ invertFailed = true;
11083
+ return [pixel[0], pixel[1]];
11084
+ }
11085
+ return coord;
11086
+ };
11087
+ const feature = boxOutlineFeature(box, invert, featureId, style);
11088
+ if (!invertFailed) features.push(feature);
11089
+ };
11090
+ const boxes = /* @__PURE__ */ new Map();
11091
+ const boxFor = (graphic) => {
11092
+ let box = boxes.get(graphic.id);
11093
+ if (box === void 0) {
11094
+ box = this.highlightBoxForGraphic(graphic, bearing, padding);
11095
+ boxes.set(graphic.id, box);
11096
+ }
11097
+ return box;
11098
+ };
10855
11099
  for (const id of this.highlightedIds) {
10856
11100
  if (excluded.has(id)) continue;
10857
11101
  const graphic = this.lastRenderedMeasuresById.get(id);
@@ -10871,19 +11115,18 @@ var TacticalDraw = class {
10871
11115
  continue;
10872
11116
  }
10873
11117
  }
10874
- const box = this.highlightBoxForGraphic(graphic, bearing, padding);
10875
- if (!box) continue;
10876
- let invertFailed = false;
10877
- const invert = (pixel) => {
10878
- const coord = fromPixel(pixel);
10879
- if (!coord) {
10880
- invertFailed = true;
10881
- return [pixel[0], pixel[1]];
10882
- }
10883
- return coord;
10884
- };
10885
- const feature = boxOutlineFeature(box, invert, `__td_highlight__:${id}`, style);
10886
- if (!invertFailed) features.push(feature);
11118
+ const box = boxFor(graphic);
11119
+ if (box) pushOutline(box, `__td_highlight__:${id}`);
11120
+ }
11121
+ for (const group of this.highlightedGroups) {
11122
+ const corners = [];
11123
+ for (const id of group.graphicIds) {
11124
+ const graphic = this.lastRenderedMeasuresById.get(id);
11125
+ const box = graphic && boxFor(graphic);
11126
+ if (box) corners.push(...boxCorners(box));
11127
+ }
11128
+ const box = fitTransformBox(corners, bearing);
11129
+ if (box) pushOutline(box, `__td_highlight_group__:${group.id}`);
10887
11130
  }
10888
11131
  this.adapter.setLayerFeatureGroups(this.highlightLayer, [...pinGroups, ...features.map((feature) => ({
10889
11132
  id: String(feature.id),
@@ -11409,7 +11652,9 @@ var TacticalDraw = class {
11409
11652
  isOnGraphicsLayer,
11410
11653
  onSettled,
11411
11654
  onClickAwayGraphicsPick,
11412
- editModifiers: this.currentEditModifiers
11655
+ editModifiers: this.currentEditModifiers,
11656
+ snap: this.resolveSnap,
11657
+ memberOutlines: options?.memberOutlines
11413
11658
  }), (handle) => {
11414
11659
  this.activeTransform = handle;
11415
11660
  return () => {
@@ -11456,6 +11701,7 @@ var TacticalDraw = class {
11456
11701
  this.assertAlive();
11457
11702
  const session = this.activeTransformSessionRef;
11458
11703
  if (session) {
11704
+ if (options?.memberOutlines !== void 0) session.setMemberOutlines(options.memberOutlines);
11459
11705
  if (session.setGraphics(graphics) !== void 0) return;
11460
11706
  }
11461
11707
  if (graphics.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbat-mapper/tactical-draw",
3
- "version": "0.32.0",
3
+ "version": "0.34.0",
4
4
  "description": "Engine-agnostic draw/edit core for tactical control measures (MIL-STD-2525 / APP-6). The MapAdapter ABI and bring-your-own-engine entry point for the tactical-draw package family.",
5
5
  "license": "MIT",
6
6
  "author": "Orbat Mapper",