@orbat-mapper/tactical-draw 0.3.0 → 0.3.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.
Files changed (2) hide show
  1. package/dist/index.mjs +53 -21
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { applyBoxTransformOptions, canonicalTextAmplifierKey, cloneControlMeasure, controlMeasureIdFromFeature, freezeOrientationOptions, getControlMeasureMetadata, getDefaultOptions, renderControlMeasure, resolveAmplifierPlacement, resolveStyleHints, roundToFixed } from "@orbat-mapper/control-measures";
1
+ import { applyBoxTransformOptions, canonicalTextAmplifierKey, cloneControlMeasure, controlMeasureIdFromFeature, foldsBoxTransformOptions, freezeOrientationOptions, getControlMeasureMetadata, 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";
@@ -1102,6 +1102,10 @@ const PIXEL_SIZE_OPTIONS = {
1102
1102
  pixels: "toothHeightPixels",
1103
1103
  meters: "toothHeight"
1104
1104
  },
1105
+ minefield: {
1106
+ pixels: "sizePixels",
1107
+ meters: "sizeMeters"
1108
+ },
1105
1109
  text: {
1106
1110
  pixels: "sizePixels",
1107
1111
  meters: "sizeMeters"
@@ -1126,6 +1130,22 @@ function sizeOptionSpecs(kind) {
1126
1130
  return specs;
1127
1131
  }
1128
1132
  /**
1133
+ * Whether `kind` authors `spec` in pixels — its defaults declare the pixel key
1134
+ * with no meter counterpart. A static property of the definition, but
1135
+ * `getDefaultOptions` deep-clones on every call, so it is memoised: the gate
1136
+ * below runs per measure per view-change frame.
1137
+ */
1138
+ const pixelAuthoredCache = /* @__PURE__ */ new Map();
1139
+ function isPixelAuthored(kind, spec) {
1140
+ const cacheKey = `${kind}:${spec.pixels}`;
1141
+ const cached = pixelAuthoredCache.get(cacheKey);
1142
+ if (cached !== void 0) return cached;
1143
+ const defaults = getDefaultOptions(kind);
1144
+ const authored = defaults[spec.pixels] !== void 0 && defaults[spec.meters] === void 0;
1145
+ pixelAuthoredCache.set(cacheKey, authored);
1146
+ return authored;
1147
+ }
1148
+ /**
1129
1149
  * Whether `measure` carries a pixel-denominated size option whose resolution
1130
1150
  * to meters depends on the live map (`metersPerPixel`) — i.e. it is
1131
1151
  * *screen-anchored*. Used both to inject the override
@@ -1136,7 +1156,11 @@ function sizeOptionSpecs(kind) {
1136
1156
  */
1137
1157
  function measureUsesAdapterResolution(measure) {
1138
1158
  const options = measure.options;
1139
- return sizeOptionSpecs(measure.kind).some((spec) => options?.[spec.pixels] !== void 0);
1159
+ return sizeOptionSpecs(measure.kind).some((spec) => {
1160
+ if (options?.[spec.pixels] !== void 0) return true;
1161
+ if (options?.[spec.meters] !== void 0) return false;
1162
+ return isPixelAuthored(measure.kind, spec);
1163
+ });
1140
1164
  }
1141
1165
  /**
1142
1166
  * Whether rendering `measure` through [[renderMeasureForAdapter]] reads live
@@ -3866,6 +3890,7 @@ function runEdit(opts) {
3866
3890
  const guideEnabled = (guideOpt ?? true) && !shouldSuppressGuide(metadata);
3867
3891
  const isAreaKind = metadata.geometry === "area";
3868
3892
  const isTextGraphic = measure.kind === "text";
3893
+ const foldsTransformIntoOptions = foldsBoxTransformOptions(measure.kind);
3869
3894
  const requestedModes = normaliseModes(initialModes);
3870
3895
  const editStartPoints = measure.controlPoints.map((p) => [...p]);
3871
3896
  const workingPoints = editStartPoints.map((p) => [...p]);
@@ -4024,7 +4049,7 @@ function runEdit(opts) {
4024
4049
  const px = driver.toPixel(p);
4025
4050
  if (px) pixels.push(px);
4026
4051
  }
4027
- return fitTransformBox(pixels, boxAngle, interactionStyle?.boxPadding ?? 0);
4052
+ return fitTransformBox(pixels, activeOptionTransformInFlight() ? activeBoxDrag.lastSnapshot.box.angle : boxAngle, interactionStyle?.boxPadding ?? 0);
4028
4053
  }
4029
4054
  /**
4030
4055
  * The Text footprint box (rotated rectangle hugging the rendered text),
@@ -4043,12 +4068,12 @@ function runEdit(opts) {
4043
4068
  * Re-fit `box` from `lastWorkingFeatures`. A no-op while a box gesture is
4044
4069
  * in flight — that drag paints the box rigidly from its own snapshot
4045
4070
  * (`BoxDragSnapshot.box`) instead of a re-fit, so a corner/rotate/body drag
4046
- * doesn't fight its own paint. Text is the exception: its box follows the
4047
- * rendered footprint live (a rotate/scale gesture changes the rendered text),
4048
- * so it re-fits every frame, drag included.
4071
+ * doesn't fight its own paint. Option-backed transforms are the exception:
4072
+ * their anchor points stay fixed while their rendered footprint changes, so
4073
+ * the box must re-fit from that live render on every tick.
4049
4074
  */
4050
4075
  function refitBox() {
4051
- if (activeBoxDrag && !isTextGraphic) return;
4076
+ if (activeBoxDrag && !activeOptionTransformInFlight()) return;
4052
4077
  box = fitBoxFromFeatures(lastWorkingFeatures);
4053
4078
  }
4054
4079
  function renderWorkingGraphic() {
@@ -4100,7 +4125,7 @@ function runEdit(opts) {
4100
4125
  }), handleIdPrefix, interactionStyle);
4101
4126
  if (modes.includes("labeldrag")) features.push(...labels.handleFeatures());
4102
4127
  if (modes.includes("transform")) {
4103
- const liveBox = activeBoxDrag && !isTextGraphic ? activeBoxDrag.lastSnapshot.box : box;
4128
+ const liveBox = activeBoxDrag && !activeOptionTransformInFlight() ? activeBoxDrag.lastSnapshot.box : box;
4104
4129
  if (liveBox) {
4105
4130
  features.push(boxOutlineFeature(liveBox, dragProjection.fromPixel, `${handleIdPrefix}:box-outline`, interactionStyle?.boxOutline));
4106
4131
  features.push(...toFeatures(boxToHandles(liveBox, dragProjection.fromPixel), handleIdPrefix, interactionStyle));
@@ -4754,13 +4779,12 @@ function runEdit(opts) {
4754
4779
  }
4755
4780
  /**
4756
4781
  * Fold a box gesture's delta (the box `to` relative to `from`, given the
4757
- * gesture `kind`) into a Text graphic's `rotation`/size options, on top of
4758
- * `base`. A `scale` grows the active size anchor; a `rotate` adds to the
4759
- * rotation. Returns `base` unchanged when the kind produces no patch. The
4760
- * delta (uniform scale ratio, angle difference) is pivot-independent, so
4761
- * folding it keeps the anchor point fixed while the glyph turns/grows.
4782
+ * gesture `kind`) into a graphic's option-backed rotation/size, on top of
4783
+ * `base`. Returns `null` when the definition produces no patch. The delta is
4784
+ * pivot-independent, so folding it keeps single-anchor geometry fixed while
4785
+ * the rendered graphic turns or grows.
4762
4786
  */
4763
- function foldTextTransform(from, to, kind, base) {
4787
+ function foldOptionTransform(from, to, kind, base) {
4764
4788
  const { scale, rotation } = boxScaleRotation(kind, to, from);
4765
4789
  const patch = applyBoxTransformOptions(measure.kind, base ?? {}, {
4766
4790
  scale,
@@ -4769,16 +4793,23 @@ function runEdit(opts) {
4769
4793
  return patch ? {
4770
4794
  ...base ?? {},
4771
4795
  ...patch
4772
- } : base;
4796
+ } : null;
4797
+ }
4798
+ /** Whether the current live box gesture changes rendered options rather than control points. */
4799
+ function activeOptionTransformInFlight() {
4800
+ if (!activeBoxDrag || !foldsTransformIntoOptions) return false;
4801
+ const kind = activeBoxDrag.fsm.kind;
4802
+ return kind === "rotate" || kind === "scale";
4773
4803
  }
4774
4804
  function paintBoxDragSnapshot(pixel, info, constrainRotation = false) {
4775
4805
  if (!activeBoxDrag) return;
4776
4806
  const resolvedPixel = translatedBoxPixel(pixel, info, activeBoxDrag);
4777
4807
  const snapshot = activeBoxDrag.fsm.move(resolvedPixel, { constrainRotation });
4778
4808
  activeBoxDrag.lastSnapshot = snapshot;
4779
- if (isTextGraphic && (activeBoxDrag.fsm.kind === "rotate" || activeBoxDrag.fsm.kind === "scale")) {
4809
+ if (activeOptionTransformInFlight()) {
4810
+ const foldedOptions = foldOptionTransform(activeBoxDrag.preDragBox, snapshot.box, activeBoxDrag.fsm.kind, activeBoxDrag.preDragOptions);
4780
4811
  workingPoints.splice(0, workingPoints.length, ...activeBoxDrag.preDragPoints);
4781
- workingOptions = foldTextTransform(activeBoxDrag.preDragBox, snapshot.box, activeBoxDrag.fsm.kind, activeBoxDrag.preDragOptions);
4812
+ if (foldedOptions) workingOptions = foldedOptions;
4782
4813
  nonGeometryDirty = true;
4783
4814
  renderWorkingGraphic();
4784
4815
  renderHandlesLayer();
@@ -4876,13 +4907,14 @@ function runEdit(opts) {
4876
4907
  const finalSnapshot = fsm.move(finalPixel, { constrainRotation: info?.shiftKey });
4877
4908
  replaceWorkingPoints(preDragPoints);
4878
4909
  workingAmplifierPlacements = preDragAmplifierPlacements;
4879
- const textOptionFold = isTextGraphic && (fsm.kind === "rotate" || fsm.kind === "scale");
4910
+ const optionFold = foldsTransformIntoOptions && (fsm.kind === "rotate" || fsm.kind === "scale");
4880
4911
  if (fsm.kind === "rotate" && !isTextGraphic) boxAngle += finalSnapshot.box.angle - preDragBox.angle;
4881
- if (textOptionFold) {
4882
- workingOptions = foldTextTransform(preDragBox, finalSnapshot.box, fsm.kind, preDragOptions);
4912
+ if (optionFold) {
4913
+ const foldedOptions = foldOptionTransform(preDragBox, finalSnapshot.box, fsm.kind, preDragOptions);
4914
+ if (foldedOptions) workingOptions = foldedOptions;
4883
4915
  nonGeometryDirty = true;
4884
4916
  }
4885
- const committedPoints = textOptionFold ? preDragPoints : finalSnapshot.points;
4917
+ const committedPoints = optionFold ? preDragPoints : finalSnapshot.points;
4886
4918
  emitTransient("end", committedPoints, null);
4887
4919
  commitGesture(committedPoints, preDragOptions, transformAmplifierPlacements(preDragAmplifierPlacements, preDragBox, finalSnapshot.box, driver), preDragBox.angle);
4888
4920
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbat-mapper/tactical-draw",
3
- "version": "0.3.0",
3
+ "version": "0.3.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",
@@ -39,7 +39,7 @@
39
39
  "access": "public"
40
40
  },
41
41
  "dependencies": {
42
- "@orbat-mapper/control-measures": "^0.3.1"
42
+ "@orbat-mapper/control-measures": "^0.4.0"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "vitest": ">=4.0.0"