@orbat-mapper/tactical-draw 0.16.0 → 0.17.1

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
@@ -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
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. */
@@ -1462,15 +1493,22 @@ function pixelDistance$1(a, b) {
1462
1493
  * grip use `tolerance` pixels; body containment is exact (`pointInBox`), so a
1463
1494
  * click just outside the box never starts a body drag. Returns `null` when
1464
1495
  * nothing matches.
1496
+ *
1497
+ * Inside the box a corner reaches no further than half the shorter
1498
+ * half-extent, so a box smaller than the corners' reach — a small symbol
1499
+ * under a touch tolerance — keeps its middle for the body. Outward a corner
1500
+ * keeps the full tolerance.
1465
1501
  */
1466
1502
  function pickBoxHandle(box, pixel, tolerance) {
1467
1503
  const corners = boxCorners(box);
1468
- for (let i = 0; i < corners.length; i++) if (pixelDistance$1(corners[i], pixel) <= tolerance) return {
1504
+ const inside = pointInBox(box, pixel);
1505
+ const reach = inside ? Math.min(tolerance, Math.min(box.halfWidth, box.halfHeight) / 2) : tolerance;
1506
+ for (let i = 0; i < corners.length; i++) if (pixelDistance$1(corners[i], pixel) <= reach) return {
1469
1507
  kind: "scale",
1470
1508
  index: i
1471
1509
  };
1472
1510
  if (pixelDistance$1(rotateGripPixel(box), pixel) <= tolerance) return { kind: "rotate" };
1473
- if (pointInBox(box, pixel)) return { kind: "body" };
1511
+ if (inside) return { kind: "body" };
1474
1512
  return null;
1475
1513
  }
1476
1514
  //#endregion
@@ -2281,6 +2319,80 @@ function createDeferredSnapResolver(getOptions) {
2281
2319
  return deferred(request, signal);
2282
2320
  };
2283
2321
  }
2322
+ /** Internal controller seam: the deferred snaps of the drags of one edit. */
2323
+ function createDeferredDragSnap(provider, isSettled) {
2324
+ /** The drag's moves, numbered, and the newest whose answer landed. */
2325
+ let moves = 0;
2326
+ let landedMove = 0;
2327
+ /** Aborted once the drag is over or the edit settles. */
2328
+ let abort = null;
2329
+ /** The newest move's answer, and the pixel it was asked at, for a release
2330
+ * there to reuse; `settled` holds the answer once it has arrived. */
2331
+ let last = null;
2332
+ let releasing = false;
2333
+ /** Asks the host under the drag's signal, or null when it has no say. A
2334
+ * rejected answer counts as finding nothing. */
2335
+ function ask(request) {
2336
+ if (!request || !provider) return null;
2337
+ const { signal } = abort ??= new AbortController();
2338
+ const answer = provider(request, signal);
2339
+ return answer && {
2340
+ answer: answer.catch(() => null),
2341
+ signal
2342
+ };
2343
+ }
2344
+ function end() {
2345
+ abort?.abort();
2346
+ abort = null;
2347
+ last = null;
2348
+ }
2349
+ return {
2350
+ get releasing() {
2351
+ return releasing;
2352
+ },
2353
+ move(pixel, request, land) {
2354
+ const move = ++moves;
2355
+ const asked = ask(request);
2356
+ if (!asked) {
2357
+ landedMove = move;
2358
+ last = null;
2359
+ land(null);
2360
+ return;
2361
+ }
2362
+ const { answer, signal } = asked;
2363
+ const entry = {
2364
+ pixel: [...pixel],
2365
+ answer
2366
+ };
2367
+ last = entry;
2368
+ answer.then((position) => {
2369
+ entry.settled = { position };
2370
+ if (isSettled() || signal.aborted || move < landedMove) return;
2371
+ landedMove = move;
2372
+ land(position);
2373
+ });
2374
+ },
2375
+ release(pixel, request) {
2376
+ if (last && last.pixel[0] === pixel[0] && last.pixel[1] === pixel[1]) return last.settled ? last.settled.position : last.answer;
2377
+ return ask(request)?.answer ?? null;
2378
+ },
2379
+ finish(released, finish) {
2380
+ if (!(released instanceof Promise)) {
2381
+ end();
2382
+ finish(released);
2383
+ return;
2384
+ }
2385
+ releasing = true;
2386
+ released.then((value) => {
2387
+ releasing = false;
2388
+ if (isSettled()) return;
2389
+ end();
2390
+ finish(value);
2391
+ });
2392
+ },
2393
+ end
2394
+ };
2395
+ }
2284
2396
  /** Resolve a draw-interaction map event through `snap`, falling back to the event coordinate. */
2285
2397
  function snappedDrawPosition(snap, event) {
2286
2398
  return snap?.({
@@ -4493,35 +4605,7 @@ function runEdit(opts) {
4493
4605
  });
4494
4606
  const commitEmitter = createCommitEmitter("EditSession.onCommit listener errors");
4495
4607
  const settleEmitter = createSettleEmitter("EditSession.onSettled listener errors");
4496
- const transientEmitter = createCommitEmitter("EditSession.onTransientChange listener errors");
4497
- /**
4498
- * Latch for the "start"/"end" pairing `emitTransient` enforces: `start`
4499
- * no-ops (and doesn't re-latch) while a gesture is already open; `end`
4500
- * no-ops when there is no open gesture. `move` always passes through — the
4501
- * latch only guards against a duplicate/missing bookend, per the
4502
- * `onTransientChange` contract (`end` fires exactly once per started
4503
- * gesture).
4504
- */
4505
- let transientGestureActive = false;
4506
- /**
4507
- * Emit one tick of the `EditSession.onTransientChange` stream. `points` is
4508
- * defensively copied so a listener can't observe (or corrupt) the live
4509
- * working-point array.
4510
- */
4511
- function emitTransient(phase, points, pointIndex) {
4512
- if (phase === "start") {
4513
- if (transientGestureActive) return;
4514
- transientGestureActive = true;
4515
- } else if (phase === "end") {
4516
- if (!transientGestureActive) return;
4517
- transientGestureActive = false;
4518
- }
4519
- transientEmitter.emit({
4520
- phase,
4521
- points: points.map((p) => [...p]),
4522
- pointIndex
4523
- });
4524
- }
4608
+ const transient = createTransientStream("EditSession.onTransientChange listener errors");
4525
4609
  /**
4526
4610
  * The transform box's rotation, in radians, session-scoped (ADR-0017 decision
4527
4611
  * #2): starts at `0` (axis-aligned) and accumulates every committed rotate
@@ -5228,7 +5312,7 @@ function runEdit(opts) {
5228
5312
  },
5229
5313
  onTransientChange(listener) {
5230
5314
  if (ctx.settled) return () => {};
5231
- return transientEmitter.register(listener);
5315
+ return transient.register(listener);
5232
5316
  }
5233
5317
  };
5234
5318
  let activeDrag = null;
@@ -5294,27 +5378,7 @@ function runEdit(opts) {
5294
5378
  target: targetAt(snapped)
5295
5379
  };
5296
5380
  }
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
- }
5381
+ const deferred = createDeferredDragSnap(deferredSnap, () => ctx.settled);
5318
5382
  /** The drag pixel an answer for `target` puts a drag at `pixel` at:
5319
5383
  * `pixel` itself when the host found nothing. */
5320
5384
  function landedDragPixel(pixel, target, position) {
@@ -5326,65 +5390,16 @@ function runEdit(opts) {
5326
5390
  * say in `target`, otherwise when its answer lands.
5327
5391
  */
5328
5392
  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
- });
5393
+ deferred.move(pixel, target?.request ?? null, (position) => paint(target ? landedDragPixel(pixel, target, position) : pixel));
5349
5394
  }
5350
5395
  /**
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.
5396
+ * What a release at `pixel` waits for: a drag pixel when it is known now,
5397
+ * a promise of one while the host's answer is on its way.
5354
5398
  */
5355
5399
  function releaseDeferred(pixel, target) {
5356
5400
  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);
5387
- });
5401
+ const released = deferred.release(pixel, target.request);
5402
+ return released instanceof Promise ? released.then((position) => landedDragPixel(pixel, target, position)) : landedDragPixel(pixel, target, released);
5388
5403
  }
5389
5404
  /**
5390
5405
  * A live transform-box gesture (corner scale, box rotate, or body
@@ -5486,7 +5501,7 @@ function runEdit(opts) {
5486
5501
  preDragOptions: workingOptions,
5487
5502
  preDragNonGeometryDirty: nonGeometryDirty
5488
5503
  };
5489
- emitTransient("start", workingPoints, null);
5504
+ transient.emit("start", workingPoints, null);
5490
5505
  dragInFlight = true;
5491
5506
  driver.setDragPanEnabled(false);
5492
5507
  return;
@@ -5505,7 +5520,7 @@ function runEdit(opts) {
5505
5520
  preDragOptions: workingOptions,
5506
5521
  controlPointIndex: hit.kind === "geometry" ? null : hit.kind === "midpoint" ? hit.index + 1 : hit.index
5507
5522
  };
5508
- emitTransient("start", fsm.kind === "midpoint" ? initialPoints : preDragPoints, activeDrag.controlPointIndex);
5523
+ transient.emit("start", fsm.kind === "midpoint" ? initialPoints : preDragPoints, activeDrag.controlPointIndex);
5509
5524
  if (fsm.kind === "midpoint") {
5510
5525
  followVertexChange({
5511
5526
  type: "insert",
@@ -5548,7 +5563,7 @@ function runEdit(opts) {
5548
5563
  },
5549
5564
  preDragOptions
5550
5565
  };
5551
- emitTransient("start", preDragPoints, null);
5566
+ transient.emit("start", preDragPoints, null);
5552
5567
  dragInFlight = true;
5553
5568
  driver.setDragPanEnabled(false);
5554
5569
  }
@@ -5567,7 +5582,7 @@ function runEdit(opts) {
5567
5582
  renderWorkingGraphic();
5568
5583
  renderHandlesLayer();
5569
5584
  recomputeDirty();
5570
- emitTransient("move", snapshot.points, activeDrag.controlPointIndex);
5585
+ transient.emit("move", snapshot.points, activeDrag.controlPointIndex);
5571
5586
  }
5572
5587
  function paintOptionDragSnapshot(pixel) {
5573
5588
  if (!activeOptionDrag) return;
@@ -5578,7 +5593,7 @@ function runEdit(opts) {
5578
5593
  renderWorkingGraphic();
5579
5594
  renderHandlesLayer();
5580
5595
  recomputeDirty();
5581
- emitTransient("move", workingPoints, null);
5596
+ transient.emit("move", workingPoints, null);
5582
5597
  }
5583
5598
  /**
5584
5599
  * Fold a box gesture's delta (the box `to` relative to `from`, given the
@@ -5628,7 +5643,7 @@ function runEdit(opts) {
5628
5643
  renderWorkingGraphic();
5629
5644
  renderHandlesLayer();
5630
5645
  recomputeDirty();
5631
- emitTransient("move", activeBoxDrag.preDragPoints, null);
5646
+ transient.emit("move", activeBoxDrag.preDragPoints, null);
5632
5647
  return;
5633
5648
  }
5634
5649
  workingPoints.splice(0, workingPoints.length, ...snapshot.points);
@@ -5636,7 +5651,7 @@ function runEdit(opts) {
5636
5651
  renderWorkingGraphic();
5637
5652
  renderHandlesLayer();
5638
5653
  recomputeDirty();
5639
- emitTransient("move", snapshot.points, null);
5654
+ transient.emit("move", snapshot.points, null);
5640
5655
  }
5641
5656
  const onDriverMove = (pixel, info) => {
5642
5657
  if (ctx.settled) return;
@@ -5680,7 +5695,7 @@ function runEdit(opts) {
5680
5695
  activeOptionDrag = null;
5681
5696
  driver.setDragPanEnabled(true);
5682
5697
  const nextOptions = optionsForOptionHandle(driver.fromPixel(pixel), drag);
5683
- emitTransient("end", workingPoints, null);
5698
+ transient.emit("end", workingPoints, null);
5684
5699
  replaceWorkingOptions(drag.preDragOptions);
5685
5700
  nonGeometryDirty = drag.preDragNonGeometryDirty;
5686
5701
  dragInFlight = false;
@@ -5695,7 +5710,7 @@ function runEdit(opts) {
5695
5710
  }
5696
5711
  if (activeDrag) {
5697
5712
  if (ctx.settled) {
5698
- emitTransient("end", workingPoints, activeDrag.controlPointIndex);
5713
+ transient.emit("end", workingPoints, activeDrag.controlPointIndex);
5699
5714
  activeDrag = null;
5700
5715
  dragInFlight = false;
5701
5716
  driver.setDragPanEnabled(true);
@@ -5705,9 +5720,9 @@ function runEdit(opts) {
5705
5720
  activeDrag = null;
5706
5721
  driver.setDragPanEnabled(true);
5707
5722
  const snapped = snapDrag(pixel, (at) => reshapeTarget(at, info, controlPointIndex));
5708
- finishRelease(releaseDeferred(snapped.pixel, snapped.target), (finalPixel) => {
5723
+ deferred.finish(releaseDeferred(snapped.pixel, snapped.target), (finalPixel) => {
5709
5724
  const next = fsm.end(finalPixel, { constrainAngles: info?.shiftKey });
5710
- emitTransient("end", next, controlPointIndex);
5725
+ transient.emit("end", next, controlPointIndex);
5711
5726
  replaceWorkingPoints(preDragPoints);
5712
5727
  commitGesture(next, preDragOptions);
5713
5728
  });
@@ -5715,7 +5730,7 @@ function runEdit(opts) {
5715
5730
  }
5716
5731
  if (activeBoxDrag) {
5717
5732
  if (ctx.settled) {
5718
- emitTransient("end", workingPoints, null);
5733
+ transient.emit("end", workingPoints, null);
5719
5734
  activeBoxDrag = null;
5720
5735
  dragInFlight = false;
5721
5736
  driver.setDragPanEnabled(true);
@@ -5725,10 +5740,10 @@ function runEdit(opts) {
5725
5740
  activeBoxDrag = null;
5726
5741
  driver.setDragPanEnabled(true);
5727
5742
  if (fsm.kind === "body" && withinClickSlop(pixel, downPixel)) {
5728
- endDeferred();
5743
+ deferred.end();
5729
5744
  replaceWorkingPoints(preDragPoints);
5730
5745
  workingAmplifierPlacements = preDragAmplifierPlacements;
5731
- emitTransient("end", preDragPoints, null);
5746
+ transient.emit("end", preDragPoints, null);
5732
5747
  renderWorkingGraphic();
5733
5748
  renderHandlesLayer();
5734
5749
  recomputeDirty();
@@ -5742,7 +5757,7 @@ function runEdit(opts) {
5742
5757
  downPixel
5743
5758
  };
5744
5759
  const snapped = snapDrag(pixel, (at) => translateTarget(at, info, drag));
5745
- finishRelease(releaseDeferred(snapped.pixel, snapped.target), (finalPixel) => {
5760
+ deferred.finish(releaseDeferred(snapped.pixel, snapped.target), (finalPixel) => {
5746
5761
  const finalSnapshot = fsm.move(finalPixel, { constrainRotation: info?.shiftKey });
5747
5762
  replaceWorkingPoints(preDragPoints);
5748
5763
  workingAmplifierPlacements = preDragAmplifierPlacements;
@@ -5754,7 +5769,7 @@ function runEdit(opts) {
5754
5769
  nonGeometryDirty = true;
5755
5770
  }
5756
5771
  const committedPoints = optionFold && holdsAnchorOnFold ? preDragPoints : finalSnapshot.points;
5757
- emitTransient("end", committedPoints, null);
5772
+ transient.emit("end", committedPoints, null);
5758
5773
  commitGesture(committedPoints, preDragOptions, transformAmplifierPlacements(preDragAmplifierPlacements, preDragBox, finalSnapshot.box, driver), preDragBox.angle);
5759
5774
  });
5760
5775
  return;
@@ -5769,7 +5784,7 @@ function runEdit(opts) {
5769
5784
  handlesLayer,
5770
5785
  closeOnClickAway,
5771
5786
  onBeforeTeardown: (settlement) => {
5772
- endDeferred();
5787
+ deferred.end();
5773
5788
  settleToGraphics(settlement.status === "committed" ? settlement.value.graphic : void 0);
5774
5789
  },
5775
5790
  onViewChange: rescaleOnViewChange,
@@ -5786,7 +5801,7 @@ function runEdit(opts) {
5786
5801
  emitSettle: (settlement) => settleFromInteraction(settlement, commitEmitter, settleEmitter),
5787
5802
  extraTeardown: () => {
5788
5803
  if (activeDrag !== null || activeOptionDrag !== null || activeBoxDrag !== null || labels.dragging) {
5789
- emitTransient("end", workingPoints, activeDrag?.controlPointIndex ?? null);
5804
+ transient.emit("end", workingPoints, activeDrag?.controlPointIndex ?? null);
5790
5805
  driver.setDragPanEnabled(true);
5791
5806
  activeDrag = null;
5792
5807
  activeOptionDrag = null;
@@ -7322,7 +7337,7 @@ function symbolBox(adapter, symbol, rendered, padding = 0) {
7322
7337
  };
7323
7338
  }
7324
7339
  function runPointSymbolEdit(opts) {
7325
- const { adapter, capability, symbol, graphicsLayer, previewLayer, handlesLayer, signal, closeOnClickAway = true, interactionStyle, onSession, handleIdPrefix, settleToGraphics, publishWorkingGraphic, wasOnGraphicsLayer, onSettled, onClickAwayGraphicsPick, snap } = opts;
7340
+ const { adapter, capability, symbol, graphicsLayer, previewLayer, handlesLayer, signal, closeOnClickAway = true, interactionStyle, onSession, handleIdPrefix, settleToGraphics, publishWorkingGraphic, wasOnGraphicsLayer, onSettled, onClickAwayGraphicsPick, snap, deferredSnap } = opts;
7326
7341
  let modes = normalisePointModes(opts.modes ?? (symbol.offset ? ["transform", "offset"] : ["transform"]));
7327
7342
  let usesGraphicStack = wasOnGraphicsLayer;
7328
7343
  let pinEditing = !!opts.renderPin && opts.modes === void 0;
@@ -7343,6 +7358,9 @@ function runPointSymbolEdit(opts) {
7343
7358
  });
7344
7359
  const commitEmitter = createCommitEmitter("GraphicEditSession.onCommit listener errors");
7345
7360
  const settleEmitter = createSettleEmitter("GraphicEditSession.onSettled listener errors");
7361
+ const transient = createTransientStream("GraphicEditSession.onTransientChange listener errors");
7362
+ /** Emit one tick of the `onTransientChange` stream, at `position`. */
7363
+ const emitTransient = (phase, position) => transient.emit(phase, [position], null);
7346
7364
  const captureHistory = () => ({ working: clonePointSymbol(working) });
7347
7365
  const cloneHistory = (value) => ({ working: clonePointSymbol(value.working) });
7348
7366
  const snapshot = () => ({
@@ -7530,16 +7548,22 @@ function runPointSymbolEdit(opts) {
7530
7548
  },
7531
7549
  onSettled(listener) {
7532
7550
  return settleEmitter.register(listener);
7551
+ },
7552
+ onTransientChange(listener) {
7553
+ if (ctx.settled) return () => {};
7554
+ return transient.register(listener);
7533
7555
  }
7534
7556
  };
7535
- const snapTranslate = (position, fallbackPixel, info) => snap?.({
7557
+ const translateRequest = (position, fallbackPixel, info) => ({
7536
7558
  coordinate: position,
7537
7559
  pixel: driver.toPixel(position) ?? fallbackPixel,
7538
7560
  interaction: "translate",
7539
7561
  graphicId: symbol.id,
7540
7562
  originalEvent: info?.native
7541
- })?.coordinate ?? position;
7563
+ });
7564
+ const snapTranslate = (position, fallbackPixel, info) => snap?.(translateRequest(position, fallbackPixel, info))?.coordinate ?? position;
7542
7565
  const onDown = (pixel, info) => {
7566
+ if (deferred.releasing) return;
7543
7567
  if (pinEditing && opts.canRenderPin?.() && !ctx.settled) {
7544
7568
  const footprint = adapter.getPinFootprint?.(working.id);
7545
7569
  if (footprint && adapter.pickPin?.(working.id, pixel, info?.hitTolerance ?? 12)) {
@@ -7585,16 +7609,24 @@ function runPointSymbolEdit(opts) {
7585
7609
  };
7586
7610
  driver.setDragPanEnabled(false);
7587
7611
  };
7588
- const transformed = (pixel, info) => {
7612
+ /** Where a translate or pin drag at `pixel` moves the symbol's position,
7613
+ * snapped at once; null for any other drag. */
7614
+ const translatedPosition = (pixel, info) => {
7589
7615
  if (pinDrag) {
7590
7616
  const attachment = [pinDrag.attachment[0] + pixel[0] - pinDrag.down[0], pinDrag.attachment[1] + pixel[1] - pinDrag.down[1]];
7591
7617
  const position = adapter.movePinFromPixel?.(working.id, attachment);
7592
- if (!position) return null;
7593
- return {
7594
- ...clonePointSymbol(pinDrag.start),
7595
- position: snapTranslate(position, attachment, info)
7596
- };
7618
+ return position ? snapTranslate(position, attachment, info) : null;
7597
7619
  }
7620
+ if (!drag || !(drag.kind === "location" || drag.kind === "body" && !drag.offsetMode)) return null;
7621
+ return snapTranslate(driver.fromPixel([drag.anchor[0] + pixel[0] - drag.down[0], drag.anchor[1] + pixel[1] - drag.down[1]]), pixel, info);
7622
+ };
7623
+ /** The symbol as the drag at `pixel` leaves it; `position`, where a
7624
+ * translate or pin drag put it, when already known. */
7625
+ const transformed = (pixel, info, position = translatedPosition(pixel, info)) => {
7626
+ if (pinDrag) return position && {
7627
+ ...clonePointSymbol(pinDrag.start),
7628
+ position
7629
+ };
7598
7630
  if (!drag) return null;
7599
7631
  let next = clonePointSymbol(drag.start);
7600
7632
  const intrinsic = drag.render;
@@ -7619,7 +7651,7 @@ function runPointSymbolEdit(opts) {
7619
7651
  return next;
7620
7652
  }
7621
7653
  if (drag.kind === "body" || drag.kind === "location") {
7622
- const position = snapTranslate(driver.fromPixel([drag.anchor[0] + pixel[0] - drag.down[0], drag.anchor[1] + pixel[1] - drag.down[1]]), pixel, info);
7654
+ if (!position) return null;
7623
7655
  if (drag.kind === "location") return movePointSymbolLocation(next, intrinsic, adapter, position);
7624
7656
  next.position = position;
7625
7657
  if (next.offset?.placement.mode === "ground") {
@@ -7636,37 +7668,48 @@ function runPointSymbolEdit(opts) {
7636
7668
  if (drag.kind === "rotate" || drag.kind === "scale") next = preserveDisplayPlacement(next, capability.render(next), adapter, drag.layout);
7637
7669
  return next;
7638
7670
  };
7639
- const onMove = (pixel, info) => {
7640
- const next = transformed(pixel, info);
7641
- if (!next) return;
7671
+ const deferred = createDeferredDragSnap(deferredSnap, () => ctx.settled);
7672
+ const paint = (next) => {
7642
7673
  working = next;
7643
7674
  render();
7675
+ emitTransient(transient.active ? "move" : "start", working.position);
7676
+ };
7677
+ const onMove = (pixel, info) => {
7678
+ if (deferred.releasing) return;
7679
+ const position = translatedPosition(pixel, info);
7680
+ const next = position ? null : transformed(pixel, info, null);
7681
+ if (!position && !next) return;
7682
+ const request = position && translateRequest(position, pixel, info);
7683
+ deferred.move(pixel, request, (landed) => {
7684
+ const moved = next ?? transformed(pixel, void 0, landed ?? position);
7685
+ if (moved) paint(moved);
7686
+ });
7644
7687
  };
7645
7688
  const onUp = (pixel, info) => {
7646
- if (pinDrag) {
7647
- const next = transformed(pixel, info), start = pinDrag.start, down = pinDrag.down;
7648
- pinDrag = null;
7649
- driver.setDragPanEnabled(true);
7650
- shell.suppressNextClickAway();
7651
- working = clonePointSymbol(start);
7652
- if (next && !withinClickSlop(pixel, down)) apply(next, "gesture", "Move unit");
7653
- else render();
7654
- return;
7655
- }
7656
- if (!drag) return;
7657
- const currentDrag = drag;
7658
- const next = transformed(pixel, info);
7659
- drag = null;
7689
+ const gesture = pinDrag ?? drag;
7690
+ if (deferred.releasing || !gesture) return;
7660
7691
  shell.suppressNextClickAway();
7692
+ const position = withinClickSlop(pixel, gesture.down) ? null : translatedPosition(pixel, info);
7693
+ const landed = position && deferred.release(pixel, translateRequest(position, pixel, info));
7694
+ deferred.finish(landed, (at) => finishRelease(pixel, info, at ?? position));
7695
+ };
7696
+ /** Ends a released drag at `pixel`, where a translate or pin drag put the
7697
+ * symbol's `position` when it moved. */
7698
+ function finishRelease(pixel, info, position) {
7699
+ const pin = pinDrag;
7700
+ const gesture = pin ?? drag;
7701
+ if (!gesture) return;
7702
+ const { start, down } = gesture;
7703
+ const next = (!!pin || drag.kind === "body") && withinClickSlop(pixel, down) ? null : transformed(pixel, info, position ?? void 0);
7704
+ const label = pin ? "Move unit" : `${drag.kind[0].toUpperCase()}${drag.kind.slice(1)}`;
7705
+ pinDrag = null;
7706
+ drag = null;
7661
7707
  driver.setDragPanEnabled(true);
7662
- working = clonePointSymbol(currentDrag.start);
7663
- if (!next) return;
7664
- if (currentDrag.kind === "body" && withinClickSlop(pixel, currentDrag.down)) {
7665
- render();
7666
- return;
7667
- }
7668
- apply(next, "gesture", `${currentDrag.kind[0].toUpperCase()}${currentDrag.kind.slice(1)}`);
7669
- };
7708
+ working = clonePointSymbol(start);
7709
+ emitTransient("end", (next ?? start).position);
7710
+ if (next) apply(next, "gesture", label);
7711
+ else render();
7712
+ }
7670
7713
  const handle = runEditInteraction({
7671
7714
  adapter,
7672
7715
  signal,
@@ -7679,6 +7722,8 @@ function runPointSymbolEdit(opts) {
7679
7722
  if (!pinEditing || !opts.canRenderPin?.()) render();
7680
7723
  },
7681
7724
  onBeforeTeardown: (settlement) => {
7725
+ deferred.end();
7726
+ emitTransient("end", settlement.status === "committed" ? settlement.value.graphic.position : symbol.position);
7682
7727
  settleToGraphics(settlement.status === "committed" ? settlement.value.graphic : void 0);
7683
7728
  },
7684
7729
  onDown,
@@ -9430,7 +9475,8 @@ var TacticalDraw = class {
9430
9475
  wasOnGraphicsLayer,
9431
9476
  onSettled,
9432
9477
  onClickAwayGraphicsPick: (event) => this.dispatchHostPick(this.graphicsLayer, event),
9433
- snap: this.resolveSnap
9478
+ snap: this.resolveSnap,
9479
+ deferredSnap: this.resolveDeferredSnap
9434
9480
  }), (handle) => {
9435
9481
  handle.syncHostMembership(this.lastRenderedMeasures.some((graphic) => graphic.id === handle.measureId && isPointSymbol(graphic)));
9436
9482
  this.activeEdit = handle;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbat-mapper/tactical-draw",
3
- "version": "0.16.0",
3
+ "version": "0.17.1",
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",