@orbat-mapper/tactical-draw 0.15.1 → 0.17.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 +30 -1
- package/dist/index.mjs +307 -124
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1111,6 +1111,17 @@ interface GraphicEditSession<G extends Graphic = Graphic> {
|
|
|
1111
1111
|
onChange(listener: (event: GraphicEditChangeEvent<G>) => void): () => void;
|
|
1112
1112
|
onCommit(handler: (snapshot: GraphicSnapshot<G>) => void): () => void;
|
|
1113
1113
|
onSettled(handler: (reason: SettleReason) => void): () => void;
|
|
1114
|
+
/**
|
|
1115
|
+
* Present on point-symbol sessions: the continuous stream of a drag, for a
|
|
1116
|
+
* host that follows the symbol while it moves (a range ring, a viewshed).
|
|
1117
|
+
* `start` fires on the first move of a gesture, `move` on each one after,
|
|
1118
|
+
* and `end` exactly once per started gesture, before that gesture's
|
|
1119
|
+
* [[onChange]], or when the session settles mid-gesture. `points` holds the
|
|
1120
|
+
* one live position; `pointIndex` is `null`. A body, location or pin drag
|
|
1121
|
+
* moves it; a rotate or scale streams it unchanged. Returns an unsubscribe
|
|
1122
|
+
* function; registering after the session has settled returns a no-op.
|
|
1123
|
+
*/
|
|
1124
|
+
onTransientChange?(listener: (event: TransientChangeEvent) => void): () => void;
|
|
1114
1125
|
}
|
|
1115
1126
|
//#endregion
|
|
1116
1127
|
//#region src/tactical-draw/transform-session.d.ts
|
|
@@ -1444,6 +1455,22 @@ interface SnapCandidate {
|
|
|
1444
1455
|
priority?: number;
|
|
1445
1456
|
}
|
|
1446
1457
|
type SnapCandidateProvider = (request: SnapCandidateRequest) => readonly SnapCandidate[];
|
|
1458
|
+
/**
|
|
1459
|
+
* A snap the host answers later, such as one to terrain it has to sample
|
|
1460
|
+
* first. Asked on every reshape and translate move of a control-measure edit,
|
|
1461
|
+
* at the position the other sources snapped it to (for a translate, the moved
|
|
1462
|
+
* first control point). Return `null` to have no say in this move, and the
|
|
1463
|
+
* drag follows the pointer at once; otherwise the drag holds where it was
|
|
1464
|
+
* until the promise settles, then lands at the position it resolves to, or at
|
|
1465
|
+
* the pointer for `null`. An answer lands unless a later move's landed first,
|
|
1466
|
+
* so a drag keeps up while answers are slow. A release waits for the answer
|
|
1467
|
+
* to where it was let go before committing, so the gesture is still one
|
|
1468
|
+
* change. `signal` aborts once the drag is over or the edit settles.
|
|
1469
|
+
*
|
|
1470
|
+
* The host decides how far it reaches: neither `enabled` nor
|
|
1471
|
+
* `tolerancePixels` applies. `bypass` does.
|
|
1472
|
+
*/
|
|
1473
|
+
type DeferredSnapProvider = (request: SnapCandidateRequest, signal: AbortSignal) => Promise<Position | null> | null;
|
|
1447
1474
|
interface SnapResult {
|
|
1448
1475
|
coordinate: Position;
|
|
1449
1476
|
pixel: PixelCoordinate;
|
|
@@ -1468,6 +1495,7 @@ interface SnappingOptions {
|
|
|
1468
1495
|
*/
|
|
1469
1496
|
graphicGeometry?: boolean | GraphicGeometrySnappingOptions;
|
|
1470
1497
|
external?: SnapCandidateProvider;
|
|
1498
|
+
deferred?: DeferredSnapProvider;
|
|
1471
1499
|
};
|
|
1472
1500
|
bypass?: (originalEvent: unknown) => boolean;
|
|
1473
1501
|
/** Called for each resolution attempt; `null` clears a host-rendered indicator. */
|
|
@@ -1716,6 +1744,7 @@ declare class TacticalDraw {
|
|
|
1716
1744
|
private readonly markers;
|
|
1717
1745
|
private snappingOptions;
|
|
1718
1746
|
private readonly resolveSnap;
|
|
1747
|
+
private readonly resolveDeferredSnap;
|
|
1719
1748
|
private readonly graphicStack;
|
|
1720
1749
|
private destroyed;
|
|
1721
1750
|
private hasRendered;
|
|
@@ -2344,4 +2373,4 @@ declare function nearestWorldCopyLng(lng: number, refLng: number): number;
|
|
|
2344
2373
|
/** `nearestWorldCopyLng` applied to a lon/lat position. */
|
|
2345
2374
|
declare function nearestWorldCopyPosition(position: Position, refLng: number): Position;
|
|
2346
2375
|
//#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 };
|
|
2376
|
+
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
|
@@ -1085,6 +1085,37 @@ function createCommitEmitter(listenerErrorsMessage) {
|
|
|
1085
1085
|
}
|
|
1086
1086
|
};
|
|
1087
1087
|
}
|
|
1088
|
+
/**
|
|
1089
|
+
* A session's `onTransientChange` stream, with the latch its contract needs:
|
|
1090
|
+
* `start` opens a gesture's stream and no-ops while one is open, `end` closes
|
|
1091
|
+
* it and no-ops when none is, so `end` fires exactly once per started
|
|
1092
|
+
* gesture. `move` always passes through. `points` is copied per emission, so
|
|
1093
|
+
* a listener can't observe (or corrupt) the live working points.
|
|
1094
|
+
*/
|
|
1095
|
+
function createTransientStream(listenerErrorsMessage) {
|
|
1096
|
+
const emitter = createCommitEmitter(listenerErrorsMessage);
|
|
1097
|
+
let active = false;
|
|
1098
|
+
return {
|
|
1099
|
+
get active() {
|
|
1100
|
+
return active;
|
|
1101
|
+
},
|
|
1102
|
+
emit(phase, points, pointIndex) {
|
|
1103
|
+
if (phase === "start") {
|
|
1104
|
+
if (active) return;
|
|
1105
|
+
active = true;
|
|
1106
|
+
} else if (phase === "end") {
|
|
1107
|
+
if (!active) return;
|
|
1108
|
+
active = false;
|
|
1109
|
+
}
|
|
1110
|
+
emitter.emit({
|
|
1111
|
+
phase,
|
|
1112
|
+
points: points.map((p) => [...p]),
|
|
1113
|
+
pointIndex
|
|
1114
|
+
});
|
|
1115
|
+
},
|
|
1116
|
+
register: emitter.register
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1088
1119
|
//#endregion
|
|
1089
1120
|
//#region src/pin-presentation.ts
|
|
1090
1121
|
/** Nested settings, merged key by key rather than replaced by a patch. */
|
|
@@ -2272,6 +2303,89 @@ function buildGuideFeatures(points, isAreaKind, trailingFixedSlots = 0) {
|
|
|
2272
2303
|
}
|
|
2273
2304
|
//#endregion
|
|
2274
2305
|
//#region src/tactical-draw/snapping.ts
|
|
2306
|
+
/** Internal controller seam for `sources.deferred`, with `bypass` applied. */
|
|
2307
|
+
function createDeferredSnapResolver(getOptions) {
|
|
2308
|
+
return (request, signal) => {
|
|
2309
|
+
const options = getOptions();
|
|
2310
|
+
const deferred = options?.sources?.deferred;
|
|
2311
|
+
if (!deferred || options.bypass?.(request.originalEvent)) return null;
|
|
2312
|
+
return deferred(request, signal);
|
|
2313
|
+
};
|
|
2314
|
+
}
|
|
2315
|
+
/** Internal controller seam: the deferred snaps of the drags of one edit. */
|
|
2316
|
+
function createDeferredDragSnap(provider, isSettled) {
|
|
2317
|
+
/** The drag's moves, numbered, and the newest whose answer landed. */
|
|
2318
|
+
let moves = 0;
|
|
2319
|
+
let landedMove = 0;
|
|
2320
|
+
/** Aborted once the drag is over or the edit settles. */
|
|
2321
|
+
let abort = null;
|
|
2322
|
+
/** The newest move's answer, and the pixel it was asked at, for a release
|
|
2323
|
+
* there to reuse; `settled` holds the answer once it has arrived. */
|
|
2324
|
+
let last = null;
|
|
2325
|
+
let releasing = false;
|
|
2326
|
+
/** Asks the host under the drag's signal, or null when it has no say. A
|
|
2327
|
+
* rejected answer counts as finding nothing. */
|
|
2328
|
+
function ask(request) {
|
|
2329
|
+
if (!request || !provider) return null;
|
|
2330
|
+
const { signal } = abort ??= new AbortController();
|
|
2331
|
+
const answer = provider(request, signal);
|
|
2332
|
+
return answer && {
|
|
2333
|
+
answer: answer.catch(() => null),
|
|
2334
|
+
signal
|
|
2335
|
+
};
|
|
2336
|
+
}
|
|
2337
|
+
function end() {
|
|
2338
|
+
abort?.abort();
|
|
2339
|
+
abort = null;
|
|
2340
|
+
last = null;
|
|
2341
|
+
}
|
|
2342
|
+
return {
|
|
2343
|
+
get releasing() {
|
|
2344
|
+
return releasing;
|
|
2345
|
+
},
|
|
2346
|
+
move(pixel, request, land) {
|
|
2347
|
+
const move = ++moves;
|
|
2348
|
+
const asked = ask(request);
|
|
2349
|
+
if (!asked) {
|
|
2350
|
+
landedMove = move;
|
|
2351
|
+
last = null;
|
|
2352
|
+
land(null);
|
|
2353
|
+
return;
|
|
2354
|
+
}
|
|
2355
|
+
const { answer, signal } = asked;
|
|
2356
|
+
const entry = {
|
|
2357
|
+
pixel: [...pixel],
|
|
2358
|
+
answer
|
|
2359
|
+
};
|
|
2360
|
+
last = entry;
|
|
2361
|
+
answer.then((position) => {
|
|
2362
|
+
entry.settled = { position };
|
|
2363
|
+
if (isSettled() || signal.aborted || move < landedMove) return;
|
|
2364
|
+
landedMove = move;
|
|
2365
|
+
land(position);
|
|
2366
|
+
});
|
|
2367
|
+
},
|
|
2368
|
+
release(pixel, request) {
|
|
2369
|
+
if (last && last.pixel[0] === pixel[0] && last.pixel[1] === pixel[1]) return last.settled ? last.settled.position : last.answer;
|
|
2370
|
+
return ask(request)?.answer ?? null;
|
|
2371
|
+
},
|
|
2372
|
+
finish(released, finish) {
|
|
2373
|
+
if (!(released instanceof Promise)) {
|
|
2374
|
+
end();
|
|
2375
|
+
finish(released);
|
|
2376
|
+
return;
|
|
2377
|
+
}
|
|
2378
|
+
releasing = true;
|
|
2379
|
+
released.then((value) => {
|
|
2380
|
+
releasing = false;
|
|
2381
|
+
if (isSettled()) return;
|
|
2382
|
+
end();
|
|
2383
|
+
finish(value);
|
|
2384
|
+
});
|
|
2385
|
+
},
|
|
2386
|
+
end
|
|
2387
|
+
};
|
|
2388
|
+
}
|
|
2275
2389
|
/** Resolve a draw-interaction map event through `snap`, falling back to the event coordinate. */
|
|
2276
2390
|
function snappedDrawPosition(snap, event) {
|
|
2277
2391
|
return snap?.({
|
|
@@ -4411,7 +4525,7 @@ const ALLOWED_EDIT_MODES = new Set([
|
|
|
4411
4525
|
* - close / abort / signal / preempt / destroy paths
|
|
4412
4526
|
*/
|
|
4413
4527
|
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;
|
|
4528
|
+
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
4529
|
const renderOpts = {
|
|
4416
4530
|
graphicsStyle,
|
|
4417
4531
|
symbolColors
|
|
@@ -4484,35 +4598,7 @@ function runEdit(opts) {
|
|
|
4484
4598
|
});
|
|
4485
4599
|
const commitEmitter = createCommitEmitter("EditSession.onCommit listener errors");
|
|
4486
4600
|
const settleEmitter = createSettleEmitter("EditSession.onSettled listener errors");
|
|
4487
|
-
const
|
|
4488
|
-
/**
|
|
4489
|
-
* Latch for the "start"/"end" pairing `emitTransient` enforces: `start`
|
|
4490
|
-
* no-ops (and doesn't re-latch) while a gesture is already open; `end`
|
|
4491
|
-
* no-ops when there is no open gesture. `move` always passes through — the
|
|
4492
|
-
* latch only guards against a duplicate/missing bookend, per the
|
|
4493
|
-
* `onTransientChange` contract (`end` fires exactly once per started
|
|
4494
|
-
* gesture).
|
|
4495
|
-
*/
|
|
4496
|
-
let transientGestureActive = false;
|
|
4497
|
-
/**
|
|
4498
|
-
* Emit one tick of the `EditSession.onTransientChange` stream. `points` is
|
|
4499
|
-
* defensively copied so a listener can't observe (or corrupt) the live
|
|
4500
|
-
* working-point array.
|
|
4501
|
-
*/
|
|
4502
|
-
function emitTransient(phase, points, pointIndex) {
|
|
4503
|
-
if (phase === "start") {
|
|
4504
|
-
if (transientGestureActive) return;
|
|
4505
|
-
transientGestureActive = true;
|
|
4506
|
-
} else if (phase === "end") {
|
|
4507
|
-
if (!transientGestureActive) return;
|
|
4508
|
-
transientGestureActive = false;
|
|
4509
|
-
}
|
|
4510
|
-
transientEmitter.emit({
|
|
4511
|
-
phase,
|
|
4512
|
-
points: points.map((p) => [...p]),
|
|
4513
|
-
pointIndex
|
|
4514
|
-
});
|
|
4515
|
-
}
|
|
4601
|
+
const transient = createTransientStream("EditSession.onTransientChange listener errors");
|
|
4516
4602
|
/**
|
|
4517
4603
|
* The transform box's rotation, in radians, session-scoped (ADR-0017 decision
|
|
4518
4604
|
* #2): starts at `0` (axis-aligned) and accumulates every committed rotate
|
|
@@ -5219,7 +5305,7 @@ function runEdit(opts) {
|
|
|
5219
5305
|
},
|
|
5220
5306
|
onTransientChange(listener) {
|
|
5221
5307
|
if (ctx.settled) return () => {};
|
|
5222
|
-
return
|
|
5308
|
+
return transient.register(listener);
|
|
5223
5309
|
}
|
|
5224
5310
|
};
|
|
5225
5311
|
let activeDrag = null;
|
|
@@ -5231,37 +5317,82 @@ function runEdit(opts) {
|
|
|
5231
5317
|
...patch
|
|
5232
5318
|
} : null;
|
|
5233
5319
|
}
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
return
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
|
|
5320
|
+
/** A reshape drag snaps the dragged control point itself. */
|
|
5321
|
+
function reshapeTarget(pixel, info, controlPointIndex) {
|
|
5322
|
+
return {
|
|
5323
|
+
request: {
|
|
5324
|
+
coordinate: driver.fromPixel(pixel),
|
|
5325
|
+
pixel,
|
|
5326
|
+
interaction: "reshape",
|
|
5327
|
+
graphicId: measure.id,
|
|
5328
|
+
controlPointIndex: controlPointIndex ?? void 0,
|
|
5329
|
+
originalEvent: info?.native
|
|
5330
|
+
},
|
|
5331
|
+
toDragPixel: (landed) => landed
|
|
5332
|
+
};
|
|
5333
|
+
}
|
|
5334
|
+
/** A body drag snaps its moved first control point; null when it can't be placed. */
|
|
5335
|
+
function translateTarget(pixel, info, drag) {
|
|
5336
|
+
if (drag.fsm.kind !== "body") return null;
|
|
5247
5337
|
const first = drag.preDragPoints[0];
|
|
5248
|
-
if (!first) return
|
|
5338
|
+
if (!first) return null;
|
|
5249
5339
|
const cursor = driver.fromPixel(pixel);
|
|
5250
5340
|
const origin = driver.fromPixel(drag.downPixel);
|
|
5251
5341
|
const anchor = [...first];
|
|
5252
5342
|
anchor[0] = first[0] + cursor[0] - origin[0];
|
|
5253
5343
|
anchor[1] = first[1] + cursor[1] - origin[1];
|
|
5254
5344
|
const anchorPixel = driver.toPixel(anchor);
|
|
5255
|
-
if (!anchorPixel) return
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
5345
|
+
if (!anchorPixel) return null;
|
|
5346
|
+
return {
|
|
5347
|
+
request: {
|
|
5348
|
+
coordinate: anchor,
|
|
5349
|
+
pixel: anchorPixel,
|
|
5350
|
+
interaction: "translate",
|
|
5351
|
+
graphicId: measure.id,
|
|
5352
|
+
originalEvent: info?.native
|
|
5353
|
+
},
|
|
5354
|
+
toDragPixel: (landed) => [pixel[0] + landed[0] - anchorPixel[0], pixel[1] + landed[1] - anchorPixel[1]]
|
|
5355
|
+
};
|
|
5356
|
+
}
|
|
5357
|
+
/**
|
|
5358
|
+
* Runs a drag at `pixel` through the immediate snap sources: the drag pixel
|
|
5359
|
+
* they put it at, and the target there for `sources.deferred` to answer.
|
|
5360
|
+
*/
|
|
5361
|
+
function snapDrag(pixel, targetAt) {
|
|
5362
|
+
const target = targetAt(pixel);
|
|
5363
|
+
const result = target && snap?.(target.request);
|
|
5364
|
+
if (!result) return {
|
|
5365
|
+
pixel,
|
|
5366
|
+
target
|
|
5367
|
+
};
|
|
5368
|
+
const snapped = target.toDragPixel(result.pixel);
|
|
5369
|
+
return {
|
|
5370
|
+
pixel: snapped,
|
|
5371
|
+
target: targetAt(snapped)
|
|
5372
|
+
};
|
|
5373
|
+
}
|
|
5374
|
+
const deferred = createDeferredDragSnap(deferredSnap, () => ctx.settled);
|
|
5375
|
+
/** The drag pixel an answer for `target` puts a drag at `pixel` at:
|
|
5376
|
+
* `pixel` itself when the host found nothing. */
|
|
5377
|
+
function landedDragPixel(pixel, target, position) {
|
|
5378
|
+
const landed = position && driver.toPixel(position);
|
|
5379
|
+
return landed ? target.toDragPixel(landed) : pixel;
|
|
5380
|
+
}
|
|
5381
|
+
/**
|
|
5382
|
+
* A drag move at `pixel`: painted at once with `paint` when the host has no
|
|
5383
|
+
* say in `target`, otherwise when its answer lands.
|
|
5384
|
+
*/
|
|
5385
|
+
function moveDeferred(pixel, target, paint) {
|
|
5386
|
+
deferred.move(pixel, target?.request ?? null, (position) => paint(target ? landedDragPixel(pixel, target, position) : pixel));
|
|
5387
|
+
}
|
|
5388
|
+
/**
|
|
5389
|
+
* What a release at `pixel` waits for: a drag pixel when it is known now,
|
|
5390
|
+
* a promise of one while the host's answer is on its way.
|
|
5391
|
+
*/
|
|
5392
|
+
function releaseDeferred(pixel, target) {
|
|
5393
|
+
if (!target) return pixel;
|
|
5394
|
+
const released = deferred.release(pixel, target.request);
|
|
5395
|
+
return released instanceof Promise ? released.then((position) => landedDragPixel(pixel, target, position)) : landedDragPixel(pixel, target, released);
|
|
5265
5396
|
}
|
|
5266
5397
|
/**
|
|
5267
5398
|
* A live transform-box gesture (corner scale, box rotate, or body
|
|
@@ -5363,7 +5494,7 @@ function runEdit(opts) {
|
|
|
5363
5494
|
preDragOptions: workingOptions,
|
|
5364
5495
|
preDragNonGeometryDirty: nonGeometryDirty
|
|
5365
5496
|
};
|
|
5366
|
-
|
|
5497
|
+
transient.emit("start", workingPoints, null);
|
|
5367
5498
|
dragInFlight = true;
|
|
5368
5499
|
driver.setDragPanEnabled(false);
|
|
5369
5500
|
return;
|
|
@@ -5382,7 +5513,7 @@ function runEdit(opts) {
|
|
|
5382
5513
|
preDragOptions: workingOptions,
|
|
5383
5514
|
controlPointIndex: hit.kind === "geometry" ? null : hit.kind === "midpoint" ? hit.index + 1 : hit.index
|
|
5384
5515
|
};
|
|
5385
|
-
|
|
5516
|
+
transient.emit("start", fsm.kind === "midpoint" ? initialPoints : preDragPoints, activeDrag.controlPointIndex);
|
|
5386
5517
|
if (fsm.kind === "midpoint") {
|
|
5387
5518
|
followVertexChange({
|
|
5388
5519
|
type: "insert",
|
|
@@ -5425,7 +5556,7 @@ function runEdit(opts) {
|
|
|
5425
5556
|
},
|
|
5426
5557
|
preDragOptions
|
|
5427
5558
|
};
|
|
5428
|
-
|
|
5559
|
+
transient.emit("start", preDragPoints, null);
|
|
5429
5560
|
dragInFlight = true;
|
|
5430
5561
|
driver.setDragPanEnabled(false);
|
|
5431
5562
|
}
|
|
@@ -5433,13 +5564,18 @@ function runEdit(opts) {
|
|
|
5433
5564
|
};
|
|
5434
5565
|
function paintDragSnapshot(pixel, info) {
|
|
5435
5566
|
if (!activeDrag) return;
|
|
5436
|
-
const
|
|
5567
|
+
const { controlPointIndex } = activeDrag;
|
|
5568
|
+
const snapped = snapDrag(pixel, (at) => reshapeTarget(at, info, controlPointIndex));
|
|
5569
|
+
moveDeferred(snapped.pixel, snapped.target, (at) => paintDragAt(at, info));
|
|
5570
|
+
}
|
|
5571
|
+
function paintDragAt(resolvedPixel, info) {
|
|
5572
|
+
if (!activeDrag) return;
|
|
5437
5573
|
const snapshot = activeDrag.fsm.move(resolvedPixel, { constrainAngles: info?.shiftKey });
|
|
5438
5574
|
workingPoints.splice(0, workingPoints.length, ...snapshot.points);
|
|
5439
5575
|
renderWorkingGraphic();
|
|
5440
5576
|
renderHandlesLayer();
|
|
5441
5577
|
recomputeDirty();
|
|
5442
|
-
|
|
5578
|
+
transient.emit("move", snapshot.points, activeDrag.controlPointIndex);
|
|
5443
5579
|
}
|
|
5444
5580
|
function paintOptionDragSnapshot(pixel) {
|
|
5445
5581
|
if (!activeOptionDrag) return;
|
|
@@ -5450,7 +5586,7 @@ function runEdit(opts) {
|
|
|
5450
5586
|
renderWorkingGraphic();
|
|
5451
5587
|
renderHandlesLayer();
|
|
5452
5588
|
recomputeDirty();
|
|
5453
|
-
|
|
5589
|
+
transient.emit("move", workingPoints, null);
|
|
5454
5590
|
}
|
|
5455
5591
|
/**
|
|
5456
5592
|
* Fold a box gesture's delta (the box `to` relative to `from`, given the
|
|
@@ -5482,7 +5618,12 @@ function runEdit(opts) {
|
|
|
5482
5618
|
}
|
|
5483
5619
|
function paintBoxDragSnapshot(pixel, info, constrainRotation = false) {
|
|
5484
5620
|
if (!activeBoxDrag) return;
|
|
5485
|
-
const
|
|
5621
|
+
const drag = activeBoxDrag;
|
|
5622
|
+
const snapped = snapDrag(pixel, (at) => translateTarget(at, info, drag));
|
|
5623
|
+
moveDeferred(snapped.pixel, snapped.target, (at) => paintBoxDragAt(at, constrainRotation));
|
|
5624
|
+
}
|
|
5625
|
+
function paintBoxDragAt(resolvedPixel, constrainRotation) {
|
|
5626
|
+
if (!activeBoxDrag) return;
|
|
5486
5627
|
const snapshot = activeBoxDrag.fsm.move(resolvedPixel, { constrainRotation });
|
|
5487
5628
|
activeBoxDrag.lastSnapshot = snapshot;
|
|
5488
5629
|
if (activeOptionTransformInFlight()) {
|
|
@@ -5495,7 +5636,7 @@ function runEdit(opts) {
|
|
|
5495
5636
|
renderWorkingGraphic();
|
|
5496
5637
|
renderHandlesLayer();
|
|
5497
5638
|
recomputeDirty();
|
|
5498
|
-
|
|
5639
|
+
transient.emit("move", activeBoxDrag.preDragPoints, null);
|
|
5499
5640
|
return;
|
|
5500
5641
|
}
|
|
5501
5642
|
workingPoints.splice(0, workingPoints.length, ...snapshot.points);
|
|
@@ -5503,7 +5644,7 @@ function runEdit(opts) {
|
|
|
5503
5644
|
renderWorkingGraphic();
|
|
5504
5645
|
renderHandlesLayer();
|
|
5505
5646
|
recomputeDirty();
|
|
5506
|
-
|
|
5647
|
+
transient.emit("move", snapshot.points, null);
|
|
5507
5648
|
}
|
|
5508
5649
|
const onDriverMove = (pixel, info) => {
|
|
5509
5650
|
if (ctx.settled) return;
|
|
@@ -5547,7 +5688,7 @@ function runEdit(opts) {
|
|
|
5547
5688
|
activeOptionDrag = null;
|
|
5548
5689
|
driver.setDragPanEnabled(true);
|
|
5549
5690
|
const nextOptions = optionsForOptionHandle(driver.fromPixel(pixel), drag);
|
|
5550
|
-
|
|
5691
|
+
transient.emit("end", workingPoints, null);
|
|
5551
5692
|
replaceWorkingOptions(drag.preDragOptions);
|
|
5552
5693
|
nonGeometryDirty = drag.preDragNonGeometryDirty;
|
|
5553
5694
|
dragInFlight = false;
|
|
@@ -5562,7 +5703,7 @@ function runEdit(opts) {
|
|
|
5562
5703
|
}
|
|
5563
5704
|
if (activeDrag) {
|
|
5564
5705
|
if (ctx.settled) {
|
|
5565
|
-
|
|
5706
|
+
transient.emit("end", workingPoints, activeDrag.controlPointIndex);
|
|
5566
5707
|
activeDrag = null;
|
|
5567
5708
|
dragInFlight = false;
|
|
5568
5709
|
driver.setDragPanEnabled(true);
|
|
@@ -5571,15 +5712,18 @@ function runEdit(opts) {
|
|
|
5571
5712
|
const { fsm, preDragPoints, preDragOptions, controlPointIndex } = activeDrag;
|
|
5572
5713
|
activeDrag = null;
|
|
5573
5714
|
driver.setDragPanEnabled(true);
|
|
5574
|
-
const
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5715
|
+
const snapped = snapDrag(pixel, (at) => reshapeTarget(at, info, controlPointIndex));
|
|
5716
|
+
deferred.finish(releaseDeferred(snapped.pixel, snapped.target), (finalPixel) => {
|
|
5717
|
+
const next = fsm.end(finalPixel, { constrainAngles: info?.shiftKey });
|
|
5718
|
+
transient.emit("end", next, controlPointIndex);
|
|
5719
|
+
replaceWorkingPoints(preDragPoints);
|
|
5720
|
+
commitGesture(next, preDragOptions);
|
|
5721
|
+
});
|
|
5578
5722
|
return;
|
|
5579
5723
|
}
|
|
5580
5724
|
if (activeBoxDrag) {
|
|
5581
5725
|
if (ctx.settled) {
|
|
5582
|
-
|
|
5726
|
+
transient.emit("end", workingPoints, null);
|
|
5583
5727
|
activeBoxDrag = null;
|
|
5584
5728
|
dragInFlight = false;
|
|
5585
5729
|
driver.setDragPanEnabled(true);
|
|
@@ -5589,9 +5733,10 @@ function runEdit(opts) {
|
|
|
5589
5733
|
activeBoxDrag = null;
|
|
5590
5734
|
driver.setDragPanEnabled(true);
|
|
5591
5735
|
if (fsm.kind === "body" && withinClickSlop(pixel, downPixel)) {
|
|
5736
|
+
deferred.end();
|
|
5592
5737
|
replaceWorkingPoints(preDragPoints);
|
|
5593
5738
|
workingAmplifierPlacements = preDragAmplifierPlacements;
|
|
5594
|
-
|
|
5739
|
+
transient.emit("end", preDragPoints, null);
|
|
5595
5740
|
renderWorkingGraphic();
|
|
5596
5741
|
renderHandlesLayer();
|
|
5597
5742
|
recomputeDirty();
|
|
@@ -5599,24 +5744,27 @@ function runEdit(opts) {
|
|
|
5599
5744
|
shell.noteBodyClick();
|
|
5600
5745
|
return;
|
|
5601
5746
|
}
|
|
5602
|
-
const
|
|
5747
|
+
const drag = {
|
|
5603
5748
|
fsm,
|
|
5604
5749
|
preDragPoints,
|
|
5605
5750
|
downPixel
|
|
5751
|
+
};
|
|
5752
|
+
const snapped = snapDrag(pixel, (at) => translateTarget(at, info, drag));
|
|
5753
|
+
deferred.finish(releaseDeferred(snapped.pixel, snapped.target), (finalPixel) => {
|
|
5754
|
+
const finalSnapshot = fsm.move(finalPixel, { constrainRotation: info?.shiftKey });
|
|
5755
|
+
replaceWorkingPoints(preDragPoints);
|
|
5756
|
+
workingAmplifierPlacements = preDragAmplifierPlacements;
|
|
5757
|
+
const optionFold = foldsTransformIntoOptions && (fsm.kind === "rotate" || fsm.kind === "scale");
|
|
5758
|
+
if (fsm.kind === "rotate" && !isTextGraphic) boxAngle += finalSnapshot.box.angle - preDragBox.angle;
|
|
5759
|
+
if (optionFold) {
|
|
5760
|
+
const foldedOptions = foldOptionTransform(preDragBox, finalSnapshot.box, fsm.kind, preDragOptions);
|
|
5761
|
+
if (foldedOptions) workingOptions = foldedOptions;
|
|
5762
|
+
nonGeometryDirty = true;
|
|
5763
|
+
}
|
|
5764
|
+
const committedPoints = optionFold && holdsAnchorOnFold ? preDragPoints : finalSnapshot.points;
|
|
5765
|
+
transient.emit("end", committedPoints, null);
|
|
5766
|
+
commitGesture(committedPoints, preDragOptions, transformAmplifierPlacements(preDragAmplifierPlacements, preDragBox, finalSnapshot.box, driver), preDragBox.angle);
|
|
5606
5767
|
});
|
|
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
5768
|
return;
|
|
5621
5769
|
}
|
|
5622
5770
|
};
|
|
@@ -5629,6 +5777,7 @@ function runEdit(opts) {
|
|
|
5629
5777
|
handlesLayer,
|
|
5630
5778
|
closeOnClickAway,
|
|
5631
5779
|
onBeforeTeardown: (settlement) => {
|
|
5780
|
+
deferred.end();
|
|
5632
5781
|
settleToGraphics(settlement.status === "committed" ? settlement.value.graphic : void 0);
|
|
5633
5782
|
},
|
|
5634
5783
|
onViewChange: rescaleOnViewChange,
|
|
@@ -5645,7 +5794,7 @@ function runEdit(opts) {
|
|
|
5645
5794
|
emitSettle: (settlement) => settleFromInteraction(settlement, commitEmitter, settleEmitter),
|
|
5646
5795
|
extraTeardown: () => {
|
|
5647
5796
|
if (activeDrag !== null || activeOptionDrag !== null || activeBoxDrag !== null || labels.dragging) {
|
|
5648
|
-
|
|
5797
|
+
transient.emit("end", workingPoints, activeDrag?.controlPointIndex ?? null);
|
|
5649
5798
|
driver.setDragPanEnabled(true);
|
|
5650
5799
|
activeDrag = null;
|
|
5651
5800
|
activeOptionDrag = null;
|
|
@@ -7181,7 +7330,7 @@ function symbolBox(adapter, symbol, rendered, padding = 0) {
|
|
|
7181
7330
|
};
|
|
7182
7331
|
}
|
|
7183
7332
|
function runPointSymbolEdit(opts) {
|
|
7184
|
-
const { adapter, capability, symbol, graphicsLayer, previewLayer, handlesLayer, signal, closeOnClickAway = true, interactionStyle, onSession, handleIdPrefix, settleToGraphics, publishWorkingGraphic, wasOnGraphicsLayer, onSettled, onClickAwayGraphicsPick, snap } = opts;
|
|
7333
|
+
const { adapter, capability, symbol, graphicsLayer, previewLayer, handlesLayer, signal, closeOnClickAway = true, interactionStyle, onSession, handleIdPrefix, settleToGraphics, publishWorkingGraphic, wasOnGraphicsLayer, onSettled, onClickAwayGraphicsPick, snap, deferredSnap } = opts;
|
|
7185
7334
|
let modes = normalisePointModes(opts.modes ?? (symbol.offset ? ["transform", "offset"] : ["transform"]));
|
|
7186
7335
|
let usesGraphicStack = wasOnGraphicsLayer;
|
|
7187
7336
|
let pinEditing = !!opts.renderPin && opts.modes === void 0;
|
|
@@ -7202,6 +7351,9 @@ function runPointSymbolEdit(opts) {
|
|
|
7202
7351
|
});
|
|
7203
7352
|
const commitEmitter = createCommitEmitter("GraphicEditSession.onCommit listener errors");
|
|
7204
7353
|
const settleEmitter = createSettleEmitter("GraphicEditSession.onSettled listener errors");
|
|
7354
|
+
const transient = createTransientStream("GraphicEditSession.onTransientChange listener errors");
|
|
7355
|
+
/** Emit one tick of the `onTransientChange` stream, at `position`. */
|
|
7356
|
+
const emitTransient = (phase, position) => transient.emit(phase, [position], null);
|
|
7205
7357
|
const captureHistory = () => ({ working: clonePointSymbol(working) });
|
|
7206
7358
|
const cloneHistory = (value) => ({ working: clonePointSymbol(value.working) });
|
|
7207
7359
|
const snapshot = () => ({
|
|
@@ -7389,16 +7541,22 @@ function runPointSymbolEdit(opts) {
|
|
|
7389
7541
|
},
|
|
7390
7542
|
onSettled(listener) {
|
|
7391
7543
|
return settleEmitter.register(listener);
|
|
7544
|
+
},
|
|
7545
|
+
onTransientChange(listener) {
|
|
7546
|
+
if (ctx.settled) return () => {};
|
|
7547
|
+
return transient.register(listener);
|
|
7392
7548
|
}
|
|
7393
7549
|
};
|
|
7394
|
-
const
|
|
7550
|
+
const translateRequest = (position, fallbackPixel, info) => ({
|
|
7395
7551
|
coordinate: position,
|
|
7396
7552
|
pixel: driver.toPixel(position) ?? fallbackPixel,
|
|
7397
7553
|
interaction: "translate",
|
|
7398
7554
|
graphicId: symbol.id,
|
|
7399
7555
|
originalEvent: info?.native
|
|
7400
|
-
})
|
|
7556
|
+
});
|
|
7557
|
+
const snapTranslate = (position, fallbackPixel, info) => snap?.(translateRequest(position, fallbackPixel, info))?.coordinate ?? position;
|
|
7401
7558
|
const onDown = (pixel, info) => {
|
|
7559
|
+
if (deferred.releasing) return;
|
|
7402
7560
|
if (pinEditing && opts.canRenderPin?.() && !ctx.settled) {
|
|
7403
7561
|
const footprint = adapter.getPinFootprint?.(working.id);
|
|
7404
7562
|
if (footprint && adapter.pickPin?.(working.id, pixel, info?.hitTolerance ?? 12)) {
|
|
@@ -7444,16 +7602,24 @@ function runPointSymbolEdit(opts) {
|
|
|
7444
7602
|
};
|
|
7445
7603
|
driver.setDragPanEnabled(false);
|
|
7446
7604
|
};
|
|
7447
|
-
|
|
7605
|
+
/** Where a translate or pin drag at `pixel` moves the symbol's position,
|
|
7606
|
+
* snapped at once; null for any other drag. */
|
|
7607
|
+
const translatedPosition = (pixel, info) => {
|
|
7448
7608
|
if (pinDrag) {
|
|
7449
7609
|
const attachment = [pinDrag.attachment[0] + pixel[0] - pinDrag.down[0], pinDrag.attachment[1] + pixel[1] - pinDrag.down[1]];
|
|
7450
7610
|
const position = adapter.movePinFromPixel?.(working.id, attachment);
|
|
7451
|
-
|
|
7452
|
-
return {
|
|
7453
|
-
...clonePointSymbol(pinDrag.start),
|
|
7454
|
-
position: snapTranslate(position, attachment, info)
|
|
7455
|
-
};
|
|
7611
|
+
return position ? snapTranslate(position, attachment, info) : null;
|
|
7456
7612
|
}
|
|
7613
|
+
if (!drag || !(drag.kind === "location" || drag.kind === "body" && !drag.offsetMode)) return null;
|
|
7614
|
+
return snapTranslate(driver.fromPixel([drag.anchor[0] + pixel[0] - drag.down[0], drag.anchor[1] + pixel[1] - drag.down[1]]), pixel, info);
|
|
7615
|
+
};
|
|
7616
|
+
/** The symbol as the drag at `pixel` leaves it; `position`, where a
|
|
7617
|
+
* translate or pin drag put it, when already known. */
|
|
7618
|
+
const transformed = (pixel, info, position = translatedPosition(pixel, info)) => {
|
|
7619
|
+
if (pinDrag) return position && {
|
|
7620
|
+
...clonePointSymbol(pinDrag.start),
|
|
7621
|
+
position
|
|
7622
|
+
};
|
|
7457
7623
|
if (!drag) return null;
|
|
7458
7624
|
let next = clonePointSymbol(drag.start);
|
|
7459
7625
|
const intrinsic = drag.render;
|
|
@@ -7478,7 +7644,7 @@ function runPointSymbolEdit(opts) {
|
|
|
7478
7644
|
return next;
|
|
7479
7645
|
}
|
|
7480
7646
|
if (drag.kind === "body" || drag.kind === "location") {
|
|
7481
|
-
|
|
7647
|
+
if (!position) return null;
|
|
7482
7648
|
if (drag.kind === "location") return movePointSymbolLocation(next, intrinsic, adapter, position);
|
|
7483
7649
|
next.position = position;
|
|
7484
7650
|
if (next.offset?.placement.mode === "ground") {
|
|
@@ -7495,37 +7661,48 @@ function runPointSymbolEdit(opts) {
|
|
|
7495
7661
|
if (drag.kind === "rotate" || drag.kind === "scale") next = preserveDisplayPlacement(next, capability.render(next), adapter, drag.layout);
|
|
7496
7662
|
return next;
|
|
7497
7663
|
};
|
|
7498
|
-
const
|
|
7499
|
-
|
|
7500
|
-
if (!next) return;
|
|
7664
|
+
const deferred = createDeferredDragSnap(deferredSnap, () => ctx.settled);
|
|
7665
|
+
const paint = (next) => {
|
|
7501
7666
|
working = next;
|
|
7502
7667
|
render();
|
|
7668
|
+
emitTransient(transient.active ? "move" : "start", working.position);
|
|
7669
|
+
};
|
|
7670
|
+
const onMove = (pixel, info) => {
|
|
7671
|
+
if (deferred.releasing) return;
|
|
7672
|
+
const position = translatedPosition(pixel, info);
|
|
7673
|
+
const next = position ? null : transformed(pixel, info, null);
|
|
7674
|
+
if (!position && !next) return;
|
|
7675
|
+
const request = position && translateRequest(position, pixel, info);
|
|
7676
|
+
deferred.move(pixel, request, (landed) => {
|
|
7677
|
+
const moved = next ?? transformed(pixel, void 0, landed ?? position);
|
|
7678
|
+
if (moved) paint(moved);
|
|
7679
|
+
});
|
|
7503
7680
|
};
|
|
7504
7681
|
const onUp = (pixel, info) => {
|
|
7505
|
-
|
|
7506
|
-
|
|
7507
|
-
pinDrag = null;
|
|
7508
|
-
driver.setDragPanEnabled(true);
|
|
7509
|
-
shell.suppressNextClickAway();
|
|
7510
|
-
working = clonePointSymbol(start);
|
|
7511
|
-
if (next && !withinClickSlop(pixel, down)) apply(next, "gesture", "Move unit");
|
|
7512
|
-
else render();
|
|
7513
|
-
return;
|
|
7514
|
-
}
|
|
7515
|
-
if (!drag) return;
|
|
7516
|
-
const currentDrag = drag;
|
|
7517
|
-
const next = transformed(pixel, info);
|
|
7518
|
-
drag = null;
|
|
7682
|
+
const gesture = pinDrag ?? drag;
|
|
7683
|
+
if (deferred.releasing || !gesture) return;
|
|
7519
7684
|
shell.suppressNextClickAway();
|
|
7685
|
+
const position = withinClickSlop(pixel, gesture.down) ? null : translatedPosition(pixel, info);
|
|
7686
|
+
const landed = position && deferred.release(pixel, translateRequest(position, pixel, info));
|
|
7687
|
+
deferred.finish(landed, (at) => finishRelease(pixel, info, at ?? position));
|
|
7688
|
+
};
|
|
7689
|
+
/** Ends a released drag at `pixel`, where a translate or pin drag put the
|
|
7690
|
+
* symbol's `position` when it moved. */
|
|
7691
|
+
function finishRelease(pixel, info, position) {
|
|
7692
|
+
const pin = pinDrag;
|
|
7693
|
+
const gesture = pin ?? drag;
|
|
7694
|
+
if (!gesture) return;
|
|
7695
|
+
const { start, down } = gesture;
|
|
7696
|
+
const next = (!!pin || drag.kind === "body") && withinClickSlop(pixel, down) ? null : transformed(pixel, info, position ?? void 0);
|
|
7697
|
+
const label = pin ? "Move unit" : `${drag.kind[0].toUpperCase()}${drag.kind.slice(1)}`;
|
|
7698
|
+
pinDrag = null;
|
|
7699
|
+
drag = null;
|
|
7520
7700
|
driver.setDragPanEnabled(true);
|
|
7521
|
-
working = clonePointSymbol(
|
|
7522
|
-
|
|
7523
|
-
if (
|
|
7524
|
-
|
|
7525
|
-
|
|
7526
|
-
}
|
|
7527
|
-
apply(next, "gesture", `${currentDrag.kind[0].toUpperCase()}${currentDrag.kind.slice(1)}`);
|
|
7528
|
-
};
|
|
7701
|
+
working = clonePointSymbol(start);
|
|
7702
|
+
emitTransient("end", (next ?? start).position);
|
|
7703
|
+
if (next) apply(next, "gesture", label);
|
|
7704
|
+
else render();
|
|
7705
|
+
}
|
|
7529
7706
|
const handle = runEditInteraction({
|
|
7530
7707
|
adapter,
|
|
7531
7708
|
signal,
|
|
@@ -7538,6 +7715,8 @@ function runPointSymbolEdit(opts) {
|
|
|
7538
7715
|
if (!pinEditing || !opts.canRenderPin?.()) render();
|
|
7539
7716
|
},
|
|
7540
7717
|
onBeforeTeardown: (settlement) => {
|
|
7718
|
+
deferred.end();
|
|
7719
|
+
emitTransient("end", settlement.status === "committed" ? settlement.value.graphic.position : symbol.position);
|
|
7541
7720
|
settleToGraphics(settlement.status === "committed" ? settlement.value.graphic : void 0);
|
|
7542
7721
|
},
|
|
7543
7722
|
onDown,
|
|
@@ -8359,6 +8538,7 @@ var TacticalDraw = class {
|
|
|
8359
8538
|
markers;
|
|
8360
8539
|
snappingOptions;
|
|
8361
8540
|
resolveSnap;
|
|
8541
|
+
resolveDeferredSnap;
|
|
8362
8542
|
graphicStack = new GraphicStackCoordinator();
|
|
8363
8543
|
destroyed = false;
|
|
8364
8544
|
hasRendered = false;
|
|
@@ -8480,6 +8660,7 @@ var TacticalDraw = class {
|
|
|
8480
8660
|
this.lastSeenMarkerGeneration = this.markers?.generation;
|
|
8481
8661
|
this.snappingOptions = options?.snapping;
|
|
8482
8662
|
this.resolveSnap = createSnapResolver(adapter, () => this.lastRenderedMeasures, () => this.snapGeometryFeatures, () => this.snappingOptions);
|
|
8663
|
+
this.resolveDeferredSnap = createDeferredSnapResolver(() => this.snappingOptions);
|
|
8483
8664
|
const owned = /* @__PURE__ */ new Set();
|
|
8484
8665
|
const provided = options?.layers ?? {};
|
|
8485
8666
|
this.graphicsLayer = resolveSlot(adapter, provided.graphics, owned);
|
|
@@ -9287,7 +9468,8 @@ var TacticalDraw = class {
|
|
|
9287
9468
|
wasOnGraphicsLayer,
|
|
9288
9469
|
onSettled,
|
|
9289
9470
|
onClickAwayGraphicsPick: (event) => this.dispatchHostPick(this.graphicsLayer, event),
|
|
9290
|
-
snap: this.resolveSnap
|
|
9471
|
+
snap: this.resolveSnap,
|
|
9472
|
+
deferredSnap: this.resolveDeferredSnap
|
|
9291
9473
|
}), (handle) => {
|
|
9292
9474
|
handle.syncHostMembership(this.lastRenderedMeasures.some((graphic) => graphic.id === handle.measureId && isPointSymbol(graphic)));
|
|
9293
9475
|
this.activeEdit = handle;
|
|
@@ -9337,7 +9519,8 @@ var TacticalDraw = class {
|
|
|
9337
9519
|
}]),
|
|
9338
9520
|
onSettled,
|
|
9339
9521
|
onClickAwayGraphicsPick,
|
|
9340
|
-
snap: this.resolveSnap
|
|
9522
|
+
snap: this.resolveSnap,
|
|
9523
|
+
deferredSnap: this.resolveDeferredSnap
|
|
9341
9524
|
}), (handle) => {
|
|
9342
9525
|
this.activeEdit = handle;
|
|
9343
9526
|
return () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orbat-mapper/tactical-draw",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.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",
|