@orbat-mapper/tactical-draw 0.4.5 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -579,6 +579,8 @@ interface InteractionStyle {
579
579
  guide?: GuideStyle;
580
580
  vertexHandle?: HandleStyle;
581
581
  midpointHandle?: HandleStyle;
582
+ /** Generator-option handle, such as a flared attack shaft's rear-width grip. */
583
+ optionHandle?: HandleStyle;
582
584
  /** Visible grab target for a draggable rendered text label. */
583
585
  labelHandle?: HandleStyle;
584
586
  scaleHandle?: HandleStyle;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { FILL_PATTERN_DEFINITIONS, NON_SOLID_FILL_PATTERNS, applyBoxTransformOptions, canonicalTextAmplifierKey, cloneControlMeasure, controlMeasureIdFromFeature, foldsBoxTransformOptions, freezeOrientationOptions, getControlMeasureMetadata, getDefaultOptions, renderControlMeasure, resolveAmplifierPlacement, resolveStyleHints, roundToFixed } from "@orbat-mapper/control-measures";
1
+ import { FILL_PATTERN_DEFINITIONS, NON_SOLID_FILL_PATTERNS, applyBoxTransformOptions, canonicalTextAmplifierKey, cloneControlMeasure, controlMeasureIdFromFeature, dragControlMeasureOptionHandle, foldsBoxTransformOptions, freezeOrientationOptions, getControlMeasureMetadata, getControlMeasureOptionHandles, getDefaultOptions, renderControlMeasure, resolveAmplifierPlacement, resolveStyleHints, roundToFixed } from "@orbat-mapper/control-measures";
2
2
  function pickPointerType(originalEvent) {
3
3
  if (typeof PointerEvent !== "undefined" && originalEvent instanceof PointerEvent) {
4
4
  if (originalEvent.pointerType === "touch") return "touch";
@@ -2686,6 +2686,7 @@ function handleFeatureId(prefix, kind, index) {
2686
2686
  switch (kind) {
2687
2687
  case "vertex": return `${prefix}:handle-vertex:${index}`;
2688
2688
  case "midpoint": return `${prefix}:handle-midpoint:${index}`;
2689
+ case "option": return `${prefix}:handle-option:${index}`;
2689
2690
  case "scale": return `${prefix}:handle-scale:${index}`;
2690
2691
  case "rotate": return `${prefix}:handle-rotate`;
2691
2692
  }
@@ -2694,6 +2695,7 @@ function handleStyleFor(kind, interactionStyle) {
2694
2695
  switch (kind) {
2695
2696
  case "vertex": return interactionStyle?.vertexHandle;
2696
2697
  case "midpoint": return interactionStyle?.midpointHandle;
2698
+ case "option": return interactionStyle?.optionHandle;
2697
2699
  case "scale": return interactionStyle?.scaleHandle;
2698
2700
  case "rotate": return interactionStyle?.rotateHandle;
2699
2701
  }
@@ -2983,6 +2985,7 @@ function beginHandleDrag(args) {
2983
2985
  return move;
2984
2986
  };
2985
2987
  if (hit.kind === "vertex") return begun("vertex", preDragPoints, dragOnePoint(preDragPoints, hit.index));
2988
+ if (hit.kind !== "midpoint") throw new TypeError(`Unsupported control-point handle kind: ${hit.kind}`);
2986
2989
  const insertIndex = hit.index + 1;
2987
2990
  const segmentEndIndex = (hit.index + 1) % preDragPoints.length;
2988
2991
  const mid = segmentMidpoint(preDragPoints[hit.index], preDragPoints[segmentEndIndex]);
@@ -4183,12 +4186,7 @@ function runEdit(opts) {
4183
4186
  }
4184
4187
  function renderHandlesLayer() {
4185
4188
  if (ctx.settled) return;
4186
- const features = toFeatures(buildHandleSet(workingPoints, modes, {
4187
- includeMidpoints: midpointHandlesEnabled,
4188
- hiddenControlPointIndices,
4189
- trailingFixedSlots,
4190
- closedRing
4191
- }), handleIdPrefix, interactionStyle);
4189
+ const features = toFeatures(buildCurrentHandleSet(), handleIdPrefix, interactionStyle);
4192
4190
  if (modes.includes("labeldrag")) features.push(...labels.handleFeatures());
4193
4191
  if (modes.includes("transform")) {
4194
4192
  const liveBox = activeBoxDrag && !activeOptionTransformInFlight() ? activeBoxDrag.lastSnapshot.box : box;
@@ -4203,6 +4201,27 @@ function runEdit(opts) {
4203
4201
  iconResources: []
4204
4202
  }]);
4205
4203
  }
4204
+ function buildCurrentHandleSet() {
4205
+ const handles = buildHandleSet(workingPoints, modes, {
4206
+ includeMidpoints: midpointHandlesEnabled,
4207
+ hiddenControlPointIndices,
4208
+ trailingFixedSlots,
4209
+ closedRing
4210
+ });
4211
+ if (modes.includes("reshape")) {
4212
+ const optionHandles = getControlMeasureOptionHandles(measure.kind, workingPoints, workingOptions);
4213
+ for (let index = 0; index < optionHandles.length; index++) {
4214
+ const handle = optionHandles[index];
4215
+ handles.push({
4216
+ kind: "option",
4217
+ index,
4218
+ optionId: handle.id,
4219
+ position: [...handle.position]
4220
+ });
4221
+ }
4222
+ }
4223
+ return handles;
4224
+ }
4206
4225
  /**
4207
4226
  * Repaint the preview and, in lockstep, the handles. `renderWorkingGraphic` re-fits
4208
4227
  * `box` (for Text, the footprint depends on options — size/rotation/
@@ -4344,7 +4363,7 @@ function runEdit(opts) {
4344
4363
  drainPendingModes();
4345
4364
  emitChange(previousRendered, previousPoints, previousOptions, previousStyle, previousNonGeometryDirty, sizeAnchor, currentRendered, previousTextAmplifiers, previousAmplifierPlacements, previousProperties, "gesture", "Edit", preGestureBoxAngle);
4346
4365
  }
4347
- function setOptions(partial) {
4366
+ function setOptions(partial, source = "programmatic", historyLabel = "Change options") {
4348
4367
  if (ctx.settled) return;
4349
4368
  const previousPoints = workingPoints.map((p) => [...p]);
4350
4369
  const previousOptions = { ...workingOptions ?? {} };
@@ -4369,7 +4388,7 @@ function runEdit(opts) {
4369
4388
  renderWorkingGraphicAndHandles();
4370
4389
  nonGeometryDirty = true;
4371
4390
  dirty = true;
4372
- emitChange(previousRendered, previousPoints, previousOptions, previousStyle, previousNonGeometryDirty, sizeAnchor, currentRendered, previousTextAmplifiers, previousAmplifierPlacements, previousProperties, "programmatic", "Change options");
4391
+ emitChange(previousRendered, previousPoints, previousOptions, previousStyle, previousNonGeometryDirty, sizeAnchor, currentRendered, previousTextAmplifiers, previousAmplifierPlacements, previousProperties, source, historyLabel);
4373
4392
  }
4374
4393
  function setStyle(partial) {
4375
4394
  if (ctx.settled) return;
@@ -4708,6 +4727,14 @@ function runEdit(opts) {
4708
4727
  }
4709
4728
  };
4710
4729
  let activeDrag = null;
4730
+ let activeOptionDrag = null;
4731
+ function optionsForOptionHandle(position, drag) {
4732
+ const patch = dragControlMeasureOptionHandle(measure.kind, workingPoints, drag.preDragOptions, drag.handleId, position);
4733
+ return patch ? {
4734
+ ...drag.preDragOptions ?? {},
4735
+ ...patch
4736
+ } : null;
4737
+ }
4711
4738
  function snappedPixel(pixel, info, interaction, controlPointIndex) {
4712
4739
  if (!snap) return pixel;
4713
4740
  return snap({
@@ -4793,12 +4820,7 @@ function runEdit(opts) {
4793
4820
  driver.setDragPanEnabled(false);
4794
4821
  return;
4795
4822
  }
4796
- const hit = pickHandle(buildHandleSet(workingPoints, modes, {
4797
- includeMidpoints: midpointHandlesEnabled,
4798
- hiddenControlPointIndices,
4799
- trailingFixedSlots,
4800
- closedRing
4801
- }), pixel, tol, (lonLat) => driver.toPixel(lonLat));
4823
+ const hit = pickHandle(buildCurrentHandleSet(), pixel, tol, (lonLat) => driver.toPixel(lonLat));
4802
4824
  if (hit) {
4803
4825
  if (modes.includes("delete")) {
4804
4826
  if (hit.kind === "vertex" && canDeleteVertex(hit.index)) {
@@ -4812,6 +4834,17 @@ function runEdit(opts) {
4812
4834
  shell.suppressNextClickAway();
4813
4835
  return;
4814
4836
  }
4837
+ if (hit.kind === "option" && hit.optionId) {
4838
+ activeOptionDrag = {
4839
+ handleId: hit.optionId,
4840
+ preDragOptions: { ...workingOptions ?? {} },
4841
+ preDragNonGeometryDirty: nonGeometryDirty
4842
+ };
4843
+ emitTransient("start", workingPoints, null);
4844
+ dragInFlight = true;
4845
+ driver.setDragPanEnabled(false);
4846
+ return;
4847
+ }
4815
4848
  const preDragPoints = workingPoints.map((p) => [...p]);
4816
4849
  const { drag: fsm, initialPoints } = beginHandleDrag({
4817
4850
  hit,
@@ -4880,6 +4913,17 @@ function runEdit(opts) {
4880
4913
  recomputeDirty();
4881
4914
  emitTransient("move", snapshot.points, activeDrag.controlPointIndex);
4882
4915
  }
4916
+ function paintOptionDragSnapshot(pixel) {
4917
+ if (!activeOptionDrag) return;
4918
+ const nextOptions = optionsForOptionHandle(driver.fromPixel(pixel), activeOptionDrag);
4919
+ if (!nextOptions) return;
4920
+ replaceWorkingOptions(nextOptions);
4921
+ nonGeometryDirty = true;
4922
+ renderWorkingGraphic();
4923
+ renderHandlesLayer();
4924
+ recomputeDirty();
4925
+ emitTransient("move", workingPoints, null);
4926
+ }
4883
4927
  /**
4884
4928
  * Fold a box gesture's delta (the box `to` relative to `from`, given the
4885
4929
  * gesture `kind`) into a graphic's option-backed rotation/size, on top of
@@ -4940,7 +4984,8 @@ function runEdit(opts) {
4940
4984
  renderWorkingGraphic();
4941
4985
  renderHandlesLayer();
4942
4986
  }
4943
- } else if (activeDrag) paintDragSnapshot(pixel, info);
4987
+ } else if (activeOptionDrag) paintOptionDragSnapshot(pixel);
4988
+ else if (activeDrag) paintDragSnapshot(pixel, info);
4944
4989
  else if (activeBoxDrag) paintBoxDragSnapshot(pixel, info, info?.shiftKey);
4945
4990
  };
4946
4991
  /** Reset drag-in-flight bookkeeping shared by every "gesture ended" path. */
@@ -4963,6 +5008,24 @@ function runEdit(opts) {
4963
5008
  shell.suppressNextClickAway();
4964
5009
  return;
4965
5010
  }
5011
+ if (activeOptionDrag) {
5012
+ const drag = activeOptionDrag;
5013
+ activeOptionDrag = null;
5014
+ driver.setDragPanEnabled(true);
5015
+ const nextOptions = optionsForOptionHandle(driver.fromPixel(pixel), drag);
5016
+ emitTransient("end", workingPoints, null);
5017
+ replaceWorkingOptions(drag.preDragOptions);
5018
+ nonGeometryDirty = drag.preDragNonGeometryDirty;
5019
+ dragInFlight = false;
5020
+ drainPendingModes();
5021
+ if (nextOptions) setOptions(nextOptions, "gesture", "Adjust option handle");
5022
+ else {
5023
+ renderWorkingGraphic();
5024
+ renderHandlesLayer();
5025
+ recomputeDirty();
5026
+ }
5027
+ return;
5028
+ }
4966
5029
  if (activeDrag) {
4967
5030
  if (ctx.settled) {
4968
5031
  emitTransient("end", workingPoints, activeDrag.controlPointIndex);
@@ -5047,10 +5110,11 @@ function runEdit(opts) {
5047
5110
  facadeOnSettled: onSettled,
5048
5111
  emitSettle: (settlement) => settleFromInteraction(settlement, commitEmitter, settleEmitter),
5049
5112
  extraTeardown: () => {
5050
- if (activeDrag !== null || activeBoxDrag !== null || labels.dragging) {
5113
+ if (activeDrag !== null || activeOptionDrag !== null || activeBoxDrag !== null || labels.dragging) {
5051
5114
  emitTransient("end", workingPoints, activeDrag?.controlPointIndex ?? null);
5052
5115
  driver.setDragPanEnabled(true);
5053
5116
  activeDrag = null;
5117
+ activeOptionDrag = null;
5054
5118
  activeBoxDrag = null;
5055
5119
  labels.endDrag();
5056
5120
  dragInFlight = false;
@@ -8123,6 +8187,12 @@ const BUILT_IN_INTERACTION_STYLE = {
8123
8187
  strokeColor: "#6b7280",
8124
8188
  strokeWidth: 1.5
8125
8189
  },
8190
+ optionHandle: {
8191
+ pointRadius: 6,
8192
+ fillColor: "#f59e0b",
8193
+ strokeColor: "#ffffff",
8194
+ strokeWidth: 2
8195
+ },
8126
8196
  labelHandle: {
8127
8197
  pointRadius: 6,
8128
8198
  fillColor: "#7c3aed",
@@ -8145,6 +8215,7 @@ const BUILT_IN_INTERACTION_STYLE = {
8145
8215
  const HANDLE_SLOTS = [
8146
8216
  "vertexHandle",
8147
8217
  "midpointHandle",
8218
+ "optionHandle",
8148
8219
  "labelHandle",
8149
8220
  "scaleHandle",
8150
8221
  "rotateHandle"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbat-mapper/tactical-draw",
3
- "version": "0.4.5",
3
+ "version": "0.5.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",
@@ -39,7 +39,7 @@
39
39
  "access": "public"
40
40
  },
41
41
  "dependencies": {
42
- "@orbat-mapper/control-measures": "^0.11.0"
42
+ "@orbat-mapper/control-measures": "^0.12.0"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "vitest": ">=4.0.0"