@orbat-mapper/tactical-draw 0.15.1 → 0.16.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 +19 -1
- package/dist/index.mjs +189 -45
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1444,6 +1444,22 @@ interface SnapCandidate {
|
|
|
1444
1444
|
priority?: number;
|
|
1445
1445
|
}
|
|
1446
1446
|
type SnapCandidateProvider = (request: SnapCandidateRequest) => readonly SnapCandidate[];
|
|
1447
|
+
/**
|
|
1448
|
+
* A snap the host answers later, such as one to terrain it has to sample
|
|
1449
|
+
* first. Asked on every reshape and translate move of a control-measure edit,
|
|
1450
|
+
* at the position the other sources snapped it to (for a translate, the moved
|
|
1451
|
+
* first control point). Return `null` to have no say in this move, and the
|
|
1452
|
+
* drag follows the pointer at once; otherwise the drag holds where it was
|
|
1453
|
+
* until the promise settles, then lands at the position it resolves to, or at
|
|
1454
|
+
* the pointer for `null`. An answer lands unless a later move's landed first,
|
|
1455
|
+
* so a drag keeps up while answers are slow. A release waits for the answer
|
|
1456
|
+
* to where it was let go before committing, so the gesture is still one
|
|
1457
|
+
* change. `signal` aborts once the drag is over or the edit settles.
|
|
1458
|
+
*
|
|
1459
|
+
* The host decides how far it reaches: neither `enabled` nor
|
|
1460
|
+
* `tolerancePixels` applies. `bypass` does.
|
|
1461
|
+
*/
|
|
1462
|
+
type DeferredSnapProvider = (request: SnapCandidateRequest, signal: AbortSignal) => Promise<Position | null> | null;
|
|
1447
1463
|
interface SnapResult {
|
|
1448
1464
|
coordinate: Position;
|
|
1449
1465
|
pixel: PixelCoordinate;
|
|
@@ -1468,6 +1484,7 @@ interface SnappingOptions {
|
|
|
1468
1484
|
*/
|
|
1469
1485
|
graphicGeometry?: boolean | GraphicGeometrySnappingOptions;
|
|
1470
1486
|
external?: SnapCandidateProvider;
|
|
1487
|
+
deferred?: DeferredSnapProvider;
|
|
1471
1488
|
};
|
|
1472
1489
|
bypass?: (originalEvent: unknown) => boolean;
|
|
1473
1490
|
/** Called for each resolution attempt; `null` clears a host-rendered indicator. */
|
|
@@ -1716,6 +1733,7 @@ declare class TacticalDraw {
|
|
|
1716
1733
|
private readonly markers;
|
|
1717
1734
|
private snappingOptions;
|
|
1718
1735
|
private readonly resolveSnap;
|
|
1736
|
+
private readonly resolveDeferredSnap;
|
|
1719
1737
|
private readonly graphicStack;
|
|
1720
1738
|
private destroyed;
|
|
1721
1739
|
private hasRendered;
|
|
@@ -2344,4 +2362,4 @@ declare function nearestWorldCopyLng(lng: number, refLng: number): number;
|
|
|
2344
2362
|
/** `nearestWorldCopyLng` applied to a lon/lat position. */
|
|
2345
2363
|
declare function nearestWorldCopyPosition(position: Position, refLng: number): Position;
|
|
2346
2364
|
//#endregion
|
|
2347
|
-
export { type AnchoredGraphic, BaseMapAdapter, type CombinedAbort, DEFAULT_LABEL_SIZE_PIXELS, DEFAULT_MARKER_SIZE, DEFAULT_PIN_PRESENTATION, DEFAULT_TEXT_SIZE_MAX_PIXELS, DEFAULT_TEXT_SIZE_MIN_PIXELS, type DrawImageDraft, type DrawMarkerDraft, type DrawMeasureDraft, type DrawOptions, type DrawPointSymbolDraft, type DrawSession, type EditChangeEvent, type EditManyOptions, type EditMode, type EditOptions, type EditPointerDriver, type EditSession, type FeatureGroup, type Graphic, type GraphicEditChangeEvent, type GraphicEditSession, type GraphicGeometrySnappingOptions, type GraphicRender, type GraphicSnapshot, type GuideStyle, HATCH_PATTERNS, type HandleStyle, type HatchPattern, 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 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 NativeEventEntry, 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 PointSymbolRender, type PointSymbolSize, type PointSymbolStyle, type PointSymbolView, type PointerCallback, PointerCallbackHub, type PointerEventInfo, 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_HALO_COLOR, TOUCH_HIT_TOLERANCE_PX, TacticalDraw, TacticalDrawAbortError, type TacticalDrawAbortReason, TacticalDrawDestroyedError, type TacticalDrawLayerOptions, type TacticalDrawOptions, type TextSizeProps, type TextStyleOptions, type ToPixel, type TransformBox, type TransformChangeEvent, type TransformSession, type TransientChangeEvent, type TransientPhase, alignPointSymbolIndicator, bindAbortable, cloneImageGraphic, cloneMarker, clonePointSymbol, coerceHandleStyle, combinePinScale, combineWithHostSignal, convertPointSymbolPlacement, effectivePointSymbolPixelSize, evaluatePickCandidates, fillPatternImageDimension, fillPatternImageId, getSizeAnchor, hitTestFeature, hitTestIconFeature, ignoreAbort, imageFootprint, imageOpacity, isAnchoredGraphic, isImageGraphic, isMarker, isMinePattern, isPinnableGraphic, isPointSymbol, isTacticalDrawAbortError, isValidPinNumber, makeFillPatternImage, markerFootprint, markerOpacity, mergeNativeAndCachedPickFeatures, movePointSymbolLocation, nearestWorldCopyLng, nearestWorldCopyPosition, normalizeImageGraphic, normalizeMarker, parseColor, pickHitTolerance, pickPointerType, pinDistanceScale, pinZoomScale, placePointSymbol, pointSymbolFootprint, pointSymbolResource, renderOrderToVisualOrder, resizePointSymbolSize, resolveGroundTextSizePixels, resolveMarkerRender, resolvePickPresentation, resolvePinPresentation, resolvePointSymbolOffset, resolveTextHaloWidth, resolveTextSizePixels, scalePointSymbolLayout, tryControlMeasureIdFromFeature, validateImageGraphic, validateMarker };
|
|
2365
|
+
export { type AnchoredGraphic, BaseMapAdapter, type CombinedAbort, 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 DrawOptions, type DrawPointSymbolDraft, type DrawSession, type EditChangeEvent, type EditManyOptions, type EditMode, type EditOptions, type EditPointerDriver, type EditSession, type FeatureGroup, type Graphic, type GraphicEditChangeEvent, type GraphicEditSession, type GraphicGeometrySnappingOptions, type GraphicRender, type GraphicSnapshot, type GuideStyle, HATCH_PATTERNS, type HandleStyle, type HatchPattern, 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 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 NativeEventEntry, 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 PointSymbolRender, type PointSymbolSize, type PointSymbolStyle, type PointSymbolView, type PointerCallback, PointerCallbackHub, type PointerEventInfo, 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_HALO_COLOR, TOUCH_HIT_TOLERANCE_PX, TacticalDraw, TacticalDrawAbortError, type TacticalDrawAbortReason, TacticalDrawDestroyedError, type TacticalDrawLayerOptions, type TacticalDrawOptions, type TextSizeProps, type TextStyleOptions, type ToPixel, type TransformBox, type TransformChangeEvent, type TransformSession, type TransientChangeEvent, type TransientPhase, alignPointSymbolIndicator, bindAbortable, cloneImageGraphic, cloneMarker, clonePointSymbol, coerceHandleStyle, combinePinScale, combineWithHostSignal, convertPointSymbolPlacement, effectivePointSymbolPixelSize, evaluatePickCandidates, fillPatternImageDimension, fillPatternImageId, getSizeAnchor, hitTestFeature, hitTestIconFeature, ignoreAbort, imageFootprint, imageOpacity, isAnchoredGraphic, isImageGraphic, isMarker, isMinePattern, isPinnableGraphic, isPointSymbol, isTacticalDrawAbortError, isValidPinNumber, makeFillPatternImage, markerFootprint, markerOpacity, mergeNativeAndCachedPickFeatures, movePointSymbolLocation, nearestWorldCopyLng, nearestWorldCopyPosition, normalizeImageGraphic, normalizeMarker, parseColor, pickHitTolerance, pickPointerType, pinDistanceScale, pinZoomScale, placePointSymbol, pointSymbolFootprint, pointSymbolResource, renderOrderToVisualOrder, resizePointSymbolSize, resolveGroundTextSizePixels, resolveMarkerRender, resolvePickPresentation, resolvePinPresentation, resolvePointSymbolOffset, resolveTextHaloWidth, resolveTextSizePixels, scalePointSymbolLayout, tryControlMeasureIdFromFeature, validateImageGraphic, validateMarker };
|
package/dist/index.mjs
CHANGED
|
@@ -2272,6 +2272,15 @@ function buildGuideFeatures(points, isAreaKind, trailingFixedSlots = 0) {
|
|
|
2272
2272
|
}
|
|
2273
2273
|
//#endregion
|
|
2274
2274
|
//#region src/tactical-draw/snapping.ts
|
|
2275
|
+
/** Internal controller seam for `sources.deferred`, with `bypass` applied. */
|
|
2276
|
+
function createDeferredSnapResolver(getOptions) {
|
|
2277
|
+
return (request, signal) => {
|
|
2278
|
+
const options = getOptions();
|
|
2279
|
+
const deferred = options?.sources?.deferred;
|
|
2280
|
+
if (!deferred || options.bypass?.(request.originalEvent)) return null;
|
|
2281
|
+
return deferred(request, signal);
|
|
2282
|
+
};
|
|
2283
|
+
}
|
|
2275
2284
|
/** Resolve a draw-interaction map event through `snap`, falling back to the event coordinate. */
|
|
2276
2285
|
function snappedDrawPosition(snap, event) {
|
|
2277
2286
|
return snap?.({
|
|
@@ -4411,7 +4420,7 @@ const ALLOWED_EDIT_MODES = new Set([
|
|
|
4411
4420
|
* - close / abort / signal / preempt / destroy paths
|
|
4412
4421
|
*/
|
|
4413
4422
|
function runEdit(opts) {
|
|
4414
|
-
const { adapter, measure, graphicsLayer, previewLayer, guideLayer, handlesLayer, graphicsStyle, symbolColors, signal, closeOnClickAway = true, modes: initialModes, interactionStyle, onSession, handleIdPrefix, guide: guideOpt, settleToGraphics, publishWorkingGraphic, onSettled, onClickAwayGraphicsPick, snap } = opts;
|
|
4423
|
+
const { adapter, measure, graphicsLayer, previewLayer, guideLayer, handlesLayer, graphicsStyle, symbolColors, signal, closeOnClickAway = true, modes: initialModes, interactionStyle, onSession, handleIdPrefix, guide: guideOpt, settleToGraphics, publishWorkingGraphic, onSettled, onClickAwayGraphicsPick, snap, deferredSnap } = opts;
|
|
4415
4424
|
const renderOpts = {
|
|
4416
4425
|
graphicsStyle,
|
|
4417
4426
|
symbolColors
|
|
@@ -5231,37 +5240,151 @@ function runEdit(opts) {
|
|
|
5231
5240
|
...patch
|
|
5232
5241
|
} : null;
|
|
5233
5242
|
}
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
return
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
|
|
5243
|
+
/** A reshape drag snaps the dragged control point itself. */
|
|
5244
|
+
function reshapeTarget(pixel, info, controlPointIndex) {
|
|
5245
|
+
return {
|
|
5246
|
+
request: {
|
|
5247
|
+
coordinate: driver.fromPixel(pixel),
|
|
5248
|
+
pixel,
|
|
5249
|
+
interaction: "reshape",
|
|
5250
|
+
graphicId: measure.id,
|
|
5251
|
+
controlPointIndex: controlPointIndex ?? void 0,
|
|
5252
|
+
originalEvent: info?.native
|
|
5253
|
+
},
|
|
5254
|
+
toDragPixel: (landed) => landed
|
|
5255
|
+
};
|
|
5256
|
+
}
|
|
5257
|
+
/** A body drag snaps its moved first control point; null when it can't be placed. */
|
|
5258
|
+
function translateTarget(pixel, info, drag) {
|
|
5259
|
+
if (drag.fsm.kind !== "body") return null;
|
|
5247
5260
|
const first = drag.preDragPoints[0];
|
|
5248
|
-
if (!first) return
|
|
5261
|
+
if (!first) return null;
|
|
5249
5262
|
const cursor = driver.fromPixel(pixel);
|
|
5250
5263
|
const origin = driver.fromPixel(drag.downPixel);
|
|
5251
5264
|
const anchor = [...first];
|
|
5252
5265
|
anchor[0] = first[0] + cursor[0] - origin[0];
|
|
5253
5266
|
anchor[1] = first[1] + cursor[1] - origin[1];
|
|
5254
5267
|
const anchorPixel = driver.toPixel(anchor);
|
|
5255
|
-
if (!anchorPixel) return
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5268
|
+
if (!anchorPixel) return null;
|
|
5269
|
+
return {
|
|
5270
|
+
request: {
|
|
5271
|
+
coordinate: anchor,
|
|
5272
|
+
pixel: anchorPixel,
|
|
5273
|
+
interaction: "translate",
|
|
5274
|
+
graphicId: measure.id,
|
|
5275
|
+
originalEvent: info?.native
|
|
5276
|
+
},
|
|
5277
|
+
toDragPixel: (landed) => [pixel[0] + landed[0] - anchorPixel[0], pixel[1] + landed[1] - anchorPixel[1]]
|
|
5278
|
+
};
|
|
5279
|
+
}
|
|
5280
|
+
/**
|
|
5281
|
+
* Runs a drag at `pixel` through the immediate snap sources: the drag pixel
|
|
5282
|
+
* they put it at, and the target there for `sources.deferred` to answer.
|
|
5283
|
+
*/
|
|
5284
|
+
function snapDrag(pixel, targetAt) {
|
|
5285
|
+
const target = targetAt(pixel);
|
|
5286
|
+
const result = target && snap?.(target.request);
|
|
5287
|
+
if (!result) return {
|
|
5288
|
+
pixel,
|
|
5289
|
+
target
|
|
5290
|
+
};
|
|
5291
|
+
const snapped = target.toDragPixel(result.pixel);
|
|
5292
|
+
return {
|
|
5293
|
+
pixel: snapped,
|
|
5294
|
+
target: targetAt(snapped)
|
|
5295
|
+
};
|
|
5296
|
+
}
|
|
5297
|
+
/** The drag's moves, numbered, and the newest whose answer landed. */
|
|
5298
|
+
let deferredMoves = 0;
|
|
5299
|
+
let landedMove = 0;
|
|
5300
|
+
/** Aborted once the drag is over or the edit settles. */
|
|
5301
|
+
let deferredAbort = null;
|
|
5302
|
+
/** The newest move's answer, and the pixel it was asked at, for a release
|
|
5303
|
+
* there to reuse; `settled` holds the answer once it has arrived. */
|
|
5304
|
+
let lastDeferred = null;
|
|
5305
|
+
/**
|
|
5306
|
+
* Asks `sources.deferred` where `target` lands, under the drag's signal, or
|
|
5307
|
+
* null when the host has no say. A rejected answer counts as finding nothing.
|
|
5308
|
+
*/
|
|
5309
|
+
function askDeferred(target) {
|
|
5310
|
+
if (!target || !deferredSnap) return null;
|
|
5311
|
+
const { signal } = deferredAbort ??= new AbortController();
|
|
5312
|
+
const answer = deferredSnap(target.request, signal);
|
|
5313
|
+
return answer && {
|
|
5314
|
+
answer: answer.catch(() => null),
|
|
5315
|
+
signal
|
|
5316
|
+
};
|
|
5317
|
+
}
|
|
5318
|
+
/** The drag pixel an answer for `target` puts a drag at `pixel` at:
|
|
5319
|
+
* `pixel` itself when the host found nothing. */
|
|
5320
|
+
function landedDragPixel(pixel, target, position) {
|
|
5321
|
+
const landed = position && driver.toPixel(position);
|
|
5322
|
+
return landed ? target.toDragPixel(landed) : pixel;
|
|
5323
|
+
}
|
|
5324
|
+
/**
|
|
5325
|
+
* A drag move at `pixel`: painted at once with `paint` when the host has no
|
|
5326
|
+
* say in `target`, otherwise when its answer lands.
|
|
5327
|
+
*/
|
|
5328
|
+
function moveDeferred(pixel, target, paint) {
|
|
5329
|
+
const move = ++deferredMoves;
|
|
5330
|
+
const asked = askDeferred(target);
|
|
5331
|
+
if (!asked) {
|
|
5332
|
+
landedMove = move;
|
|
5333
|
+
lastDeferred = null;
|
|
5334
|
+
paint(pixel);
|
|
5335
|
+
return;
|
|
5336
|
+
}
|
|
5337
|
+
const { answer, signal } = asked;
|
|
5338
|
+
const last = {
|
|
5339
|
+
pixel,
|
|
5340
|
+
answer
|
|
5341
|
+
};
|
|
5342
|
+
lastDeferred = last;
|
|
5343
|
+
answer.then((position) => {
|
|
5344
|
+
last.settled = { position };
|
|
5345
|
+
if (ctx.settled || signal.aborted || move < landedMove) return;
|
|
5346
|
+
landedMove = move;
|
|
5347
|
+
paint(landedDragPixel(pixel, target, position));
|
|
5348
|
+
});
|
|
5349
|
+
}
|
|
5350
|
+
/**
|
|
5351
|
+
* What a release at `pixel` waits for: the last move's answer when let go
|
|
5352
|
+
* where it was asked, else a fresh one. A drag pixel when it is known now,
|
|
5353
|
+
* a promise of one while it is on its way.
|
|
5354
|
+
*/
|
|
5355
|
+
function releaseDeferred(pixel, target) {
|
|
5356
|
+
if (!target) return pixel;
|
|
5357
|
+
const last = lastDeferred;
|
|
5358
|
+
if (last && last.pixel[0] === pixel[0] && last.pixel[1] === pixel[1]) {
|
|
5359
|
+
if (last.settled) return landedDragPixel(pixel, target, last.settled.position);
|
|
5360
|
+
return last.answer.then((position) => landedDragPixel(pixel, target, position));
|
|
5361
|
+
}
|
|
5362
|
+
const asked = askDeferred(target);
|
|
5363
|
+
if (!asked) return pixel;
|
|
5364
|
+
return asked.answer.then((position) => landedDragPixel(pixel, target, position));
|
|
5365
|
+
}
|
|
5366
|
+
/** Done with the drag's deferred snaps: aborts any still on their way. */
|
|
5367
|
+
function endDeferred() {
|
|
5368
|
+
deferredAbort?.abort();
|
|
5369
|
+
deferredAbort = null;
|
|
5370
|
+
lastDeferred = null;
|
|
5371
|
+
}
|
|
5372
|
+
/**
|
|
5373
|
+
* Finishes a released drag at the pixel `released` gives, at once or once
|
|
5374
|
+
* its answer arrives; the drag stays in flight meanwhile, so no other
|
|
5375
|
+
* gesture starts. An edit settled in between drops it.
|
|
5376
|
+
*/
|
|
5377
|
+
function finishRelease(released, finish) {
|
|
5378
|
+
if (!(released instanceof Promise)) {
|
|
5379
|
+
endDeferred();
|
|
5380
|
+
finish(released);
|
|
5381
|
+
return;
|
|
5382
|
+
}
|
|
5383
|
+
released.then((pixel) => {
|
|
5384
|
+
if (ctx.settled) return;
|
|
5385
|
+
endDeferred();
|
|
5386
|
+
finish(pixel);
|
|
5262
5387
|
});
|
|
5263
|
-
if (!result) return pixel;
|
|
5264
|
-
return [pixel[0] + result.pixel[0] - anchorPixel[0], pixel[1] + result.pixel[1] - anchorPixel[1]];
|
|
5265
5388
|
}
|
|
5266
5389
|
/**
|
|
5267
5390
|
* A live transform-box gesture (corner scale, box rotate, or body
|
|
@@ -5433,7 +5556,12 @@ function runEdit(opts) {
|
|
|
5433
5556
|
};
|
|
5434
5557
|
function paintDragSnapshot(pixel, info) {
|
|
5435
5558
|
if (!activeDrag) return;
|
|
5436
|
-
const
|
|
5559
|
+
const { controlPointIndex } = activeDrag;
|
|
5560
|
+
const snapped = snapDrag(pixel, (at) => reshapeTarget(at, info, controlPointIndex));
|
|
5561
|
+
moveDeferred(snapped.pixel, snapped.target, (at) => paintDragAt(at, info));
|
|
5562
|
+
}
|
|
5563
|
+
function paintDragAt(resolvedPixel, info) {
|
|
5564
|
+
if (!activeDrag) return;
|
|
5437
5565
|
const snapshot = activeDrag.fsm.move(resolvedPixel, { constrainAngles: info?.shiftKey });
|
|
5438
5566
|
workingPoints.splice(0, workingPoints.length, ...snapshot.points);
|
|
5439
5567
|
renderWorkingGraphic();
|
|
@@ -5482,7 +5610,12 @@ function runEdit(opts) {
|
|
|
5482
5610
|
}
|
|
5483
5611
|
function paintBoxDragSnapshot(pixel, info, constrainRotation = false) {
|
|
5484
5612
|
if (!activeBoxDrag) return;
|
|
5485
|
-
const
|
|
5613
|
+
const drag = activeBoxDrag;
|
|
5614
|
+
const snapped = snapDrag(pixel, (at) => translateTarget(at, info, drag));
|
|
5615
|
+
moveDeferred(snapped.pixel, snapped.target, (at) => paintBoxDragAt(at, constrainRotation));
|
|
5616
|
+
}
|
|
5617
|
+
function paintBoxDragAt(resolvedPixel, constrainRotation) {
|
|
5618
|
+
if (!activeBoxDrag) return;
|
|
5486
5619
|
const snapshot = activeBoxDrag.fsm.move(resolvedPixel, { constrainRotation });
|
|
5487
5620
|
activeBoxDrag.lastSnapshot = snapshot;
|
|
5488
5621
|
if (activeOptionTransformInFlight()) {
|
|
@@ -5571,10 +5704,13 @@ function runEdit(opts) {
|
|
|
5571
5704
|
const { fsm, preDragPoints, preDragOptions, controlPointIndex } = activeDrag;
|
|
5572
5705
|
activeDrag = null;
|
|
5573
5706
|
driver.setDragPanEnabled(true);
|
|
5574
|
-
const
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5707
|
+
const snapped = snapDrag(pixel, (at) => reshapeTarget(at, info, controlPointIndex));
|
|
5708
|
+
finishRelease(releaseDeferred(snapped.pixel, snapped.target), (finalPixel) => {
|
|
5709
|
+
const next = fsm.end(finalPixel, { constrainAngles: info?.shiftKey });
|
|
5710
|
+
emitTransient("end", next, controlPointIndex);
|
|
5711
|
+
replaceWorkingPoints(preDragPoints);
|
|
5712
|
+
commitGesture(next, preDragOptions);
|
|
5713
|
+
});
|
|
5578
5714
|
return;
|
|
5579
5715
|
}
|
|
5580
5716
|
if (activeBoxDrag) {
|
|
@@ -5589,6 +5725,7 @@ function runEdit(opts) {
|
|
|
5589
5725
|
activeBoxDrag = null;
|
|
5590
5726
|
driver.setDragPanEnabled(true);
|
|
5591
5727
|
if (fsm.kind === "body" && withinClickSlop(pixel, downPixel)) {
|
|
5728
|
+
endDeferred();
|
|
5592
5729
|
replaceWorkingPoints(preDragPoints);
|
|
5593
5730
|
workingAmplifierPlacements = preDragAmplifierPlacements;
|
|
5594
5731
|
emitTransient("end", preDragPoints, null);
|
|
@@ -5599,24 +5736,27 @@ function runEdit(opts) {
|
|
|
5599
5736
|
shell.noteBodyClick();
|
|
5600
5737
|
return;
|
|
5601
5738
|
}
|
|
5602
|
-
const
|
|
5739
|
+
const drag = {
|
|
5603
5740
|
fsm,
|
|
5604
5741
|
preDragPoints,
|
|
5605
5742
|
downPixel
|
|
5743
|
+
};
|
|
5744
|
+
const snapped = snapDrag(pixel, (at) => translateTarget(at, info, drag));
|
|
5745
|
+
finishRelease(releaseDeferred(snapped.pixel, snapped.target), (finalPixel) => {
|
|
5746
|
+
const finalSnapshot = fsm.move(finalPixel, { constrainRotation: info?.shiftKey });
|
|
5747
|
+
replaceWorkingPoints(preDragPoints);
|
|
5748
|
+
workingAmplifierPlacements = preDragAmplifierPlacements;
|
|
5749
|
+
const optionFold = foldsTransformIntoOptions && (fsm.kind === "rotate" || fsm.kind === "scale");
|
|
5750
|
+
if (fsm.kind === "rotate" && !isTextGraphic) boxAngle += finalSnapshot.box.angle - preDragBox.angle;
|
|
5751
|
+
if (optionFold) {
|
|
5752
|
+
const foldedOptions = foldOptionTransform(preDragBox, finalSnapshot.box, fsm.kind, preDragOptions);
|
|
5753
|
+
if (foldedOptions) workingOptions = foldedOptions;
|
|
5754
|
+
nonGeometryDirty = true;
|
|
5755
|
+
}
|
|
5756
|
+
const committedPoints = optionFold && holdsAnchorOnFold ? preDragPoints : finalSnapshot.points;
|
|
5757
|
+
emitTransient("end", committedPoints, null);
|
|
5758
|
+
commitGesture(committedPoints, preDragOptions, transformAmplifierPlacements(preDragAmplifierPlacements, preDragBox, finalSnapshot.box, driver), preDragBox.angle);
|
|
5606
5759
|
});
|
|
5607
|
-
const finalSnapshot = fsm.move(finalPixel, { constrainRotation: info?.shiftKey });
|
|
5608
|
-
replaceWorkingPoints(preDragPoints);
|
|
5609
|
-
workingAmplifierPlacements = preDragAmplifierPlacements;
|
|
5610
|
-
const optionFold = foldsTransformIntoOptions && (fsm.kind === "rotate" || fsm.kind === "scale");
|
|
5611
|
-
if (fsm.kind === "rotate" && !isTextGraphic) boxAngle += finalSnapshot.box.angle - preDragBox.angle;
|
|
5612
|
-
if (optionFold) {
|
|
5613
|
-
const foldedOptions = foldOptionTransform(preDragBox, finalSnapshot.box, fsm.kind, preDragOptions);
|
|
5614
|
-
if (foldedOptions) workingOptions = foldedOptions;
|
|
5615
|
-
nonGeometryDirty = true;
|
|
5616
|
-
}
|
|
5617
|
-
const committedPoints = optionFold && holdsAnchorOnFold ? preDragPoints : finalSnapshot.points;
|
|
5618
|
-
emitTransient("end", committedPoints, null);
|
|
5619
|
-
commitGesture(committedPoints, preDragOptions, transformAmplifierPlacements(preDragAmplifierPlacements, preDragBox, finalSnapshot.box, driver), preDragBox.angle);
|
|
5620
5760
|
return;
|
|
5621
5761
|
}
|
|
5622
5762
|
};
|
|
@@ -5629,6 +5769,7 @@ function runEdit(opts) {
|
|
|
5629
5769
|
handlesLayer,
|
|
5630
5770
|
closeOnClickAway,
|
|
5631
5771
|
onBeforeTeardown: (settlement) => {
|
|
5772
|
+
endDeferred();
|
|
5632
5773
|
settleToGraphics(settlement.status === "committed" ? settlement.value.graphic : void 0);
|
|
5633
5774
|
},
|
|
5634
5775
|
onViewChange: rescaleOnViewChange,
|
|
@@ -8359,6 +8500,7 @@ var TacticalDraw = class {
|
|
|
8359
8500
|
markers;
|
|
8360
8501
|
snappingOptions;
|
|
8361
8502
|
resolveSnap;
|
|
8503
|
+
resolveDeferredSnap;
|
|
8362
8504
|
graphicStack = new GraphicStackCoordinator();
|
|
8363
8505
|
destroyed = false;
|
|
8364
8506
|
hasRendered = false;
|
|
@@ -8480,6 +8622,7 @@ var TacticalDraw = class {
|
|
|
8480
8622
|
this.lastSeenMarkerGeneration = this.markers?.generation;
|
|
8481
8623
|
this.snappingOptions = options?.snapping;
|
|
8482
8624
|
this.resolveSnap = createSnapResolver(adapter, () => this.lastRenderedMeasures, () => this.snapGeometryFeatures, () => this.snappingOptions);
|
|
8625
|
+
this.resolveDeferredSnap = createDeferredSnapResolver(() => this.snappingOptions);
|
|
8483
8626
|
const owned = /* @__PURE__ */ new Set();
|
|
8484
8627
|
const provided = options?.layers ?? {};
|
|
8485
8628
|
this.graphicsLayer = resolveSlot(adapter, provided.graphics, owned);
|
|
@@ -9337,7 +9480,8 @@ var TacticalDraw = class {
|
|
|
9337
9480
|
}]),
|
|
9338
9481
|
onSettled,
|
|
9339
9482
|
onClickAwayGraphicsPick,
|
|
9340
|
-
snap: this.resolveSnap
|
|
9483
|
+
snap: this.resolveSnap,
|
|
9484
|
+
deferredSnap: this.resolveDeferredSnap
|
|
9341
9485
|
}), (handle) => {
|
|
9342
9486
|
this.activeEdit = handle;
|
|
9343
9487
|
return () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orbat-mapper/tactical-draw",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.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",
|