@orbat-mapper/tactical-draw 0.5.8 → 0.6.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
@@ -544,13 +544,14 @@ declare const DEFAULT_LABEL_SIZE_PIXELS = 14;
544
544
  * on zoom. `screen` means a pixel size held constant on screen — re-rendered
545
545
  * against the live `metersPerPixel` on every view change. A draw/edit drawn in
546
546
  * pixels resolves (`bakes`) to a `ground` anchor on commit unless the caller
547
- * asks to stay `screen`.
547
+ * asks to stay `screen`. Edits of uniformly sized symbols retain their authored
548
+ * unit by default (ADR-0052).
548
549
  */
549
550
  type SizeAnchor = "ground" | "screen";
550
551
  /**
551
552
  * The [[SizeAnchor]] a measure currently encodes (ADR-0020): `screen` when it
552
553
  * carries its kind's pixel-denominated size option, `ground` otherwise. Keys off
553
- * the same `PIXEL_SIZE_OPTIONS` table as the bake, so a consumer deciding how to
554
+ * the same metadata size pairs as the bake, so a consumer deciding how to
554
555
  * re-edit a graphic never has to re-derive the per-kind pixel-option knowledge
555
556
  * (e.g. via a fragile key-name heuristic). Accepts the minimal `{ kind, options }`
556
557
  * shape, mirroring [[measureUsesAdapterResolution]].
@@ -1394,7 +1395,7 @@ interface EditOptions {
1394
1395
  * `DrawOptions.sizeAnchor`: editing a screen-anchored graphic as `"ground"`
1395
1396
  * bakes/freezes it to meters; editing a ground graphic whose working options
1396
1397
  * have been switched to pixels as `"screen"` keeps the pixel size. Default
1397
- * `"ground"`. Applied to the resolved snapshot only — the in-flight preview
1398
+ * `"ground"`, except uniformly sized symbols retain their authored unit. Applied to the resolved snapshot only — the in-flight preview
1398
1399
  * stays screen-anchored throughout the edit.
1399
1400
  */
1400
1401
  sizeAnchor?: SizeAnchor;
@@ -1422,7 +1423,7 @@ interface EditManyOptions {
1422
1423
  closeOnClickAway?: boolean;
1423
1424
  /** Per-call interaction style override scoped to this transform. See ADR-0006. */
1424
1425
  interactionStyle?: InteractionStyle;
1425
- /** Size anchor for the committed measures (ADR-0020), applied group-wide. Default `"ground"`. */
1426
+ /** Size anchor for ordinary control measures in the group. Uniform symbols retain their own unit. Default `"ground"`. */
1426
1427
  sizeAnchor?: SizeAnchor;
1427
1428
  }
1428
1429
  /**
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { FILL_PATTERN_DEFINITIONS, NON_SOLID_FILL_PATTERNS, applyBoxTransformOptions, canonicalTextAmplifierKey, cloneControlMeasure, controlMeasureIdFromFeature, dragControlMeasureOptionHandle, foldsBoxTransformOptions, freezeOrientationOptions, getControlMeasureMetadata, getControlMeasureOptionHandles, getDefaultOptions, normalizeTextAmplifiers, renderControlMeasure, resolveAmplifierPlacement, resolveStyleHints, roundToFixed } from "@orbat-mapper/control-measures";
1
+ import { DEFAULT_LABEL_HEIGHT_CSS_PIXELS, FILL_PATTERN_DEFINITIONS, NON_SOLID_FILL_PATTERNS, applyBoxTransformOptions, canonicalTextAmplifierKey, cloneControlMeasure, controlMeasureIdFromFeature, dragControlMeasureOptionHandle, foldsBoxTransformOptions, freezeOrientationOptions, getControlMeasureMetadata, getControlMeasureOptionHandles, getDefaultOptions, normalizeTextAmplifiers, renderControlMeasure, resolveAmplifierPlacement, resolveSizePair, resolveStyleHints, roundToFixed, switchSizePairUnit } 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";
@@ -1046,98 +1046,23 @@ function combineWithHostSignal(hostSignal) {
1046
1046
  }
1047
1047
  //#endregion
1048
1048
  //#region src/tactical-draw/measure-options.ts
1049
- const DEFAULT_LABEL_SIZE_PIXELS = 14;
1050
- /**
1051
- * Per-kind pixel-denominated *geometry* size option and the meter option it
1052
- * bakes into — the single source of which geometry option makes a measure
1053
- * screen-anchored. Label sizing is not listed here: every `capturesLabelSize`
1054
- * kind carries the shared `labelSizePixels` → `labelSize` pair implicitly
1055
- * (ADR-0028) — see [[sizeOptionSpecs]]. Both the resolution gate
1056
- * ([[measureUsesAdapterResolution]]) and the bake ([[bakePixelSizeToGround]])
1057
- * derive from this table, so a new pixel-sized kind is one entry here
1058
- * (ADR-0020).
1059
- */
1060
- const PIXEL_SIZE_OPTIONS = {
1061
- boundary: {
1062
- pixels: "echelonSizePixels",
1063
- meters: "echelonSize"
1064
- },
1065
- "battle-position": {
1066
- pixels: "echelonSizePixels",
1067
- meters: "echelonSize"
1068
- },
1069
- "strong-point": {
1070
- pixels: "echelonSizePixels",
1071
- meters: "echelonSize"
1072
- },
1073
- "base-camp": {
1074
- pixels: "echelonSizePixels",
1075
- meters: "echelonSize"
1076
- },
1077
- "guerrilla-base": {
1078
- pixels: "echelonSizePixels",
1079
- meters: "echelonSize"
1080
- },
1081
- flot: {
1082
- pixels: "radiusPixels",
1083
- meters: "radius"
1084
- },
1085
- "fortified-line": {
1086
- pixels: "toothSizePixels",
1087
- meters: "toothSize"
1088
- },
1089
- "fortified-area": {
1090
- pixels: "toothSizePixels",
1091
- meters: "toothSize"
1092
- },
1093
- "antitank-ditch-under-construction": {
1094
- pixels: "toothHeightPixels",
1095
- meters: "toothHeight"
1096
- },
1097
- "antitank-ditch-completed": {
1098
- pixels: "toothHeightPixels",
1099
- meters: "toothHeight"
1100
- },
1101
- "antitank-wall": {
1102
- pixels: "toothHeightPixels",
1103
- meters: "toothHeight"
1104
- },
1105
- minefield: {
1106
- pixels: "sizePixels",
1107
- meters: "sizeMeters"
1108
- },
1109
- text: {
1110
- pixels: "sizePixels",
1111
- meters: "sizeMeters"
1112
- }
1113
- };
1114
- /** The shared label-size pair every `capturesLabelSize` kind carries (ADR-0028). */
1115
- const LABEL_SIZE_SPEC = {
1116
- pixels: "labelSizePixels",
1117
- meters: "labelSize"
1118
- };
1119
- /**
1120
- * Every pixel/meter size-option pair `kind` can carry: its geometry entry from
1121
- * [[PIXEL_SIZE_OPTIONS]] (if any) plus the shared label pair when the kind
1122
- * captures a label size — a kind like Boundary can carry both anchor-bearing
1123
- * dimensions at once (echelon glyph + labels).
1124
- */
1049
+ const DEFAULT_LABEL_SIZE_PIXELS = DEFAULT_LABEL_HEIGHT_CSS_PIXELS;
1050
+ /** An adapter resolution usable for pixel<->meter conversion. */
1051
+ function hasUsableResolution(mpp) {
1052
+ return mpp !== void 0 && Number.isFinite(mpp) && mpp > 0;
1053
+ }
1054
+ /** Every supported dimension, including captured labels, comes from core metadata. */
1125
1055
  function sizeOptionSpecs(kind) {
1126
- const specs = [];
1127
- const geometry = PIXEL_SIZE_OPTIONS[kind];
1128
- if (geometry) specs.push(geometry);
1129
- if (getControlMeasureMetadata(kind).capturesLabelSize) specs.push(LABEL_SIZE_SPEC);
1130
- return specs;
1056
+ return getControlMeasureMetadata(kind).sizePairs ?? [];
1131
1057
  }
1132
1058
  /**
1133
1059
  * Whether `kind` has at least one size that can be restored to its normal
1134
1060
  * pixel-authored appearance at the adapter's current resolution. Kept inside
1135
- * tactical-draw with the private size-pair catalog so hosts never need to
1061
+ * tactical-draw using the core metadata catalog so hosts never need to
1136
1062
  * infer option names or special-case captured labels.
1137
1063
  */
1138
1064
  function canResetGroundSizes(measure, adapter) {
1139
- const mpp = adapter.getResolution();
1140
- return mpp !== void 0 && mpp > 0 && sizeOptionSpecs(measure.kind).length > 0;
1065
+ return hasUsableResolution(adapter.getResolution()) && sizeOptionSpecs(measure.kind).length > 0;
1141
1066
  }
1142
1067
  /**
1143
1068
  * Return the complete option record produced by resetting every known size
@@ -1151,35 +1076,30 @@ function canResetGroundSizes(measure, adapter) {
1151
1076
  function resetGroundSizeOptions(measure, adapter) {
1152
1077
  const mpp = adapter.getResolution();
1153
1078
  const specs = sizeOptionSpecs(measure.kind);
1154
- if (mpp === void 0 || mpp <= 0 || specs.length === 0) return void 0;
1079
+ if (!hasUsableResolution(mpp) || specs.length === 0) return void 0;
1155
1080
  const defaults = getDefaultOptions(measure.kind);
1156
1081
  const next = { ...measure.options ?? {} };
1157
1082
  for (const spec of specs) {
1158
- const defaultPixels = spec === LABEL_SIZE_SPEC ? 14 : defaults[spec.pixels];
1083
+ const defaultPixels = spec.defaultUnit === "px" && spec.defaultValue !== void 0 ? spec.defaultValue : defaults[spec.pixels];
1159
1084
  if (typeof defaultPixels !== "number") continue;
1085
+ const result = switchSizePairUnit({
1086
+ kind: measure.kind,
1087
+ dimension: spec.id,
1088
+ options: {
1089
+ ...next,
1090
+ [spec.pixels]: defaultPixels
1091
+ },
1092
+ unit: "m",
1093
+ constructionMetersPerCssPixel: mpp
1094
+ });
1095
+ if (result.status !== "converted") return void 0;
1160
1096
  delete next[spec.pixels];
1161
- next[spec.meters] = defaultPixels * mpp;
1097
+ next[spec.meters] = result.value;
1162
1098
  }
1163
1099
  delete next.metersPerPixel;
1164
1100
  return next;
1165
1101
  }
1166
1102
  /**
1167
- * Whether `kind` authors `spec` in pixels — its defaults declare the pixel key
1168
- * with no meter counterpart. A static property of the definition, but
1169
- * `getDefaultOptions` deep-clones on every call, so it is memoised: the gate
1170
- * below runs per measure per view-change frame.
1171
- */
1172
- const pixelAuthoredCache = /* @__PURE__ */ new Map();
1173
- function isPixelAuthored(kind, spec) {
1174
- const cacheKey = `${kind}:${spec.pixels}`;
1175
- const cached = pixelAuthoredCache.get(cacheKey);
1176
- if (cached !== void 0) return cached;
1177
- const defaults = getDefaultOptions(kind);
1178
- const authored = defaults[spec.pixels] !== void 0 && defaults[spec.meters] === void 0;
1179
- pixelAuthoredCache.set(cacheKey, authored);
1180
- return authored;
1181
- }
1182
- /**
1183
1103
  * Whether `measure` carries a pixel-denominated size option whose resolution
1184
1104
  * to meters depends on the live map (`metersPerPixel`) — i.e. it is
1185
1105
  * *screen-anchored*. Used both to inject the override
@@ -1193,7 +1113,7 @@ function measureUsesAdapterResolution(measure) {
1193
1113
  return sizeOptionSpecs(measure.kind).some((spec) => {
1194
1114
  if (options?.[spec.pixels] !== void 0) return true;
1195
1115
  if (options?.[spec.meters] !== void 0) return false;
1196
- return isPixelAuthored(measure.kind, spec);
1116
+ return !spec.captureOnDraw && spec.defaultUnit === "px";
1197
1117
  });
1198
1118
  }
1199
1119
  /**
@@ -1225,7 +1145,7 @@ function measureRendersFromViewState(measure) {
1225
1145
  /**
1226
1146
  * The [[SizeAnchor]] a measure currently encodes (ADR-0020): `screen` when it
1227
1147
  * carries its kind's pixel-denominated size option, `ground` otherwise. Keys off
1228
- * the same `PIXEL_SIZE_OPTIONS` table as the bake, so a consumer deciding how to
1148
+ * the same metadata size pairs as the bake, so a consumer deciding how to
1229
1149
  * re-edit a graphic never has to re-derive the per-kind pixel-option knowledge
1230
1150
  * (e.g. via a fragile key-name heuristic). Accepts the minimal `{ kind, options }`
1231
1151
  * shape, mirroring [[measureUsesAdapterResolution]].
@@ -1233,33 +1153,37 @@ function measureRendersFromViewState(measure) {
1233
1153
  function getSizeAnchor(measure) {
1234
1154
  return measureUsesAdapterResolution(measure) ? "screen" : "ground";
1235
1155
  }
1156
+ /** Uniform symbols retain their authored unit unless a caller explicitly changes it. */
1157
+ function defaultSizeAnchor(measure) {
1158
+ return getControlMeasureMetadata(measure.kind).uniformSizing ? getSizeAnchor(measure) : "ground";
1159
+ }
1236
1160
  /**
1237
- * Materialise a *pixel-authored* kind's default pixel size onto a measure that
1238
- * carries neither size key, so the ADR-0020 ground bake has a pixel value to
1239
- * resolve to meters at commit. A kind is pixel-authored when its default
1240
- * options declare the pixel-size option but no meter counterpart (e.g. Text's
1241
- * `sizePixels: 24` with no `sizeMeters`) — such a fresh draw is authored in
1242
- * pixels and must bake to meters, but a default draw commits with no options,
1243
- * so the pixel size would otherwise never land and the graphic would persist
1244
- * screen-anchored forever. No-op when the measure already carries a size key,
1245
- * the kind has no pixel-size option, or the kind's default is meter-denominated
1246
- * (e.g. FLOT, whose meter default governs a default draw without any bake) —
1247
- * so this never changes the committed size of the pre-existing pixel kinds.
1161
+ * Materialize uncaptured pixel authoring defaults before commit, so the ground
1162
+ * bake sees an explicit value. Meter-default dimensions and authored values
1163
+ * remain unchanged; captured labels have their separate render/commit seam.
1248
1164
  */
1249
1165
  function withDefaultAuthoringSize(measure) {
1250
- const spec = PIXEL_SIZE_OPTIONS[measure.kind];
1251
- if (!spec) return measure;
1252
- const options = measure.options ?? {};
1253
- if (options[spec.pixels] !== void 0 || options[spec.meters] !== void 0) return measure;
1254
- const defaults = getDefaultOptions(measure.kind);
1255
- if (defaults[spec.meters] !== void 0 || defaults[spec.pixels] === void 0) return measure;
1256
- return {
1257
- ...measure,
1258
- options: {
1166
+ let options = measure.options ?? {};
1167
+ let changed = false;
1168
+ for (const spec of sizeOptionSpecs(measure.kind)) {
1169
+ if (spec.captureOnDraw || spec.defaultUnit !== "px") continue;
1170
+ if (options[spec.pixels] !== void 0 || options[spec.meters] !== void 0) continue;
1171
+ const resolved = resolveSizePair({
1172
+ kind: measure.kind,
1173
+ dimension: spec.id,
1174
+ options
1175
+ });
1176
+ if (resolved.status !== "resolved") continue;
1177
+ options = {
1259
1178
  ...options,
1260
- [spec.pixels]: defaults[spec.pixels]
1261
- }
1262
- };
1179
+ [spec.pixels]: resolved.value
1180
+ };
1181
+ changed = true;
1182
+ }
1183
+ return changed ? {
1184
+ ...measure,
1185
+ options
1186
+ } : measure;
1263
1187
  }
1264
1188
  /**
1265
1189
  * Bake a screen-anchored (pixel) size to a ground-anchored (meter) size at the
@@ -1271,17 +1195,26 @@ function withDefaultAuthoringSize(measure) {
1271
1195
  */
1272
1196
  function bakePixelSizeToGround(measure, adapter) {
1273
1197
  const options = measure.options ?? {};
1274
- const specs = sizeOptionSpecs(measure.kind).filter((spec) => typeof options[spec.pixels] === "number");
1198
+ const specs = sizeOptionSpecs(measure.kind).filter((spec) => options[spec.pixels] !== void 0);
1275
1199
  if (specs.length === 0) return measure;
1276
1200
  const mpp = adapter.getResolution();
1277
- if (mpp === void 0 || mpp <= 0) return measure;
1278
- const pixelKeys = new Set(specs.map((spec) => spec.pixels));
1279
- const rest = {};
1280
- for (const [key, value] of Object.entries(options)) if (!pixelKeys.has(key) && key !== "metersPerPixel") rest[key] = value;
1281
- for (const spec of specs) rest[spec.meters] = options[spec.pixels] * mpp;
1201
+ if (!hasUsableResolution(mpp)) return measure;
1202
+ let next = options;
1203
+ for (const spec of specs) {
1204
+ const result = switchSizePairUnit({
1205
+ kind: measure.kind,
1206
+ dimension: spec.id,
1207
+ options: next,
1208
+ unit: "m",
1209
+ constructionMetersPerCssPixel: mpp
1210
+ });
1211
+ if (result.status !== "converted") return measure;
1212
+ next = result.options;
1213
+ }
1214
+ delete next.metersPerPixel;
1282
1215
  return {
1283
1216
  ...measure,
1284
- options: rest
1217
+ options: next
1285
1218
  };
1286
1219
  }
1287
1220
  /**
@@ -1302,7 +1235,7 @@ function withCommittedAdapterMeasureOptions(measure) {
1302
1235
  ...measure,
1303
1236
  options: {
1304
1237
  ...measure.options,
1305
- labelSizePixels: 14
1238
+ labelSizePixels: DEFAULT_LABEL_SIZE_PIXELS
1306
1239
  }
1307
1240
  };
1308
1241
  }
@@ -3983,7 +3916,7 @@ const ALLOWED_EDIT_MODES = new Set([
3983
3916
  function runEdit(opts) {
3984
3917
  const { adapter, measure, graphicsLayer, previewLayer, guideLayer, handlesLayer, graphicsStyle, signal, closeOnClickAway = true, modes: initialModes, interactionStyle, onSession, handleIdPrefix, guide: guideOpt, settleToGraphics, publishWorkingGraphic, onSettled, onClickAwayGraphicsPick, snap } = opts;
3985
3918
  const renderOpts = graphicsStyle ? { graphicsStyle } : void 0;
3986
- let sizeAnchor = opts.sizeAnchor ?? "ground";
3919
+ let sizeAnchor = opts.sizeAnchor ?? defaultSizeAnchor(measure);
3987
3920
  const metadata = getControlMeasureMetadata(measure.kind);
3988
3921
  const rule = metadata.rule;
3989
3922
  const midpointHandlesEnabled = rule?.canonicalPointCount === void 0;
@@ -5489,6 +5422,17 @@ function scalePointSymbolStates(pre, scale, rotation) {
5489
5422
  } : null);
5490
5423
  }
5491
5424
  /**
5425
+ * Seed the group's single `sizeAnchor` scalar, which the session exposes and the
5426
+ * UI reflects. Only a lone control measure has an unambiguous authored unit to
5427
+ * honour (ADR-0052); a mixed or multi-member group falls back to `"ground"`.
5428
+ * Per-member commits consult `uniformSizing` directly, so this only decides the
5429
+ * starting state of the exposed toggle.
5430
+ */
5431
+ function defaultGroupSizeAnchor(graphics) {
5432
+ const only = graphics.length === 1 ? graphics[0] : void 0;
5433
+ return only && !isAnchoredGraphic(only) ? defaultSizeAnchor(only) : "ground";
5434
+ }
5435
+ /**
5492
5436
  * Drive an interactive group transform against a `MapAdapter` — the leaner,
5493
5437
  * multi-select sibling of `runEdit` (ADR-0017 "Multi-select" slice). No
5494
5438
  * reshape, no per-vertex handles, no guide layer, no per-measure
@@ -5515,7 +5459,7 @@ function runGroupTransform(opts) {
5515
5459
  assertCapabilityFor(graphics);
5516
5460
  validateImageResources(graphics);
5517
5461
  const renderOpts = graphicsStyle ? { graphicsStyle } : void 0;
5518
- let sizeAnchor = opts.sizeAnchor ?? "ground";
5462
+ let sizeAnchor = opts.sizeAnchor ?? defaultGroupSizeAnchor(graphics);
5519
5463
  /** Throw synchronously if any graphic in `list` is a point symbol and no capability was supplied. */
5520
5464
  function assertCapabilityFor(list) {
5521
5465
  if (!capability && list.some(isPointSymbol)) throw new PointSymbolCapabilityRequiredError();
@@ -5630,7 +5574,7 @@ function runGroupTransform(opts) {
5630
5574
  };
5631
5575
  }
5632
5576
  const working = buildWorkingMeasureWith(member, override);
5633
- const committed = sizeAnchor === "screen" ? working : bakePixelSizeToGround(working, adapter);
5577
+ const committed = getControlMeasureMetadata(working.kind).uniformSizing || sizeAnchor === "screen" ? working : bakePixelSizeToGround(working, adapter);
5634
5578
  return {
5635
5579
  graphic: cloneControlMeasure(committed),
5636
5580
  render: renderMeasureForAdapter(adapter, committed, renderOpts)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbat-mapper/tactical-draw",
3
- "version": "0.5.8",
3
+ "version": "0.6.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.19.0"
42
+ "@orbat-mapper/control-measures": "^0.21.0"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "vitest": ">=4.0.0"