@orbat-mapper/tactical-draw 0.5.6 → 0.5.7

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
@@ -1551,11 +1551,14 @@ declare class TacticalDraw {
1551
1551
  private lastRenderedMeasures;
1552
1552
  private snapGeometryFeatures;
1553
1553
  /**
1554
- * Rendered graphics-layer groups, keyed on Graphic snapshot identity. See
1555
- * {@link renderGraphicGroup} for the invalidation contract; swapped for a
1556
- * fresh map (not cleared entry-by-entry) so stale entries are collectable.
1554
+ * Rendered graphics-layer groups, keyed on Graphic snapshot identity. Each
1555
+ * entry records whether and at which adapter resolution it was generated, so
1556
+ * a zoom rebuild replaces only view-dependent groups and preserves every
1557
+ * unrelated cached render.
1557
1558
  */
1558
1559
  private graphicGroupCache;
1560
+ /** Last adapter resolution observed by the shared graphics-stack view handler. */
1561
+ private lastViewResolution;
1559
1562
  /**
1560
1563
  * Last {@link PointSymbolCapability.generation} observed from `pointSymbols`,
1561
1564
  * initialised from the capability at construction. Compared at the top of
@@ -1597,8 +1600,10 @@ declare class TacticalDraw {
1597
1600
  * re-renders the same reference is outside the contract — `render()` has
1598
1601
  * always been documented as taking snapshots.) Rendered output also depends
1599
1602
  * on live view state and on the resolved graphics style; the style is fixed
1600
- * at construction, and every view change drops the whole cache. Crucially,
1601
- * the view cannot change during a box drag (drag-pan is disabled), so every
1603
+ * at construction, while a resolution-dependent entry is reused only at the
1604
+ * resolution that produced it. This keeps zoom work proportional to the
1605
+ * affected graphics instead of rebuilding the whole document. Crucially, the
1606
+ * view cannot change during a box drag (drag-pan is disabled), so every
1602
1607
  * graphic outside the selection stays a cache hit for the whole gesture and
1603
1608
  * per-frame reconcile cost becomes O(selection) rather than O(document).
1604
1609
  */
@@ -1610,9 +1615,9 @@ declare class TacticalDraw {
1610
1615
  */
1611
1616
  private buildGraphicGroup;
1612
1617
  /**
1613
- * Drop every cached render. Called whenever an input shared by all graphic
1614
- * renders changes — the live view state, or (via {@link reconcileGraphicsStack})
1615
- * the point-symbol capability's `generation`.
1618
+ * Drop every cached render when a renderer capability generation changes.
1619
+ * View changes are handled per entry by {@link renderGraphicGroup} so
1620
+ * resolution-independent graphics remain cache hits.
1616
1621
  */
1617
1622
  private invalidateGraphicGroupCache;
1618
1623
  /** Refresh capability-dependent renders before any caller-visible state is mutated. */
@@ -1624,13 +1629,13 @@ declare class TacticalDraw {
1624
1629
  /** Settle several stack overrides in one graphics-layer reconciliation. */
1625
1630
  private settleWorkingGraphics;
1626
1631
  /**
1627
- * Re-render the graphics layer on a view (zoom) change so pixel-denominated
1628
- * and not-yet-committed label-sized measures rescale live. Skipped entirely
1629
- * when nothing rendered still reads live view state — meter geometry with a
1630
- * captured label size is zoom-independent, so a rebuild would be wasted
1631
- * layer writes. A single-control-measure edit publishes through the stack
1632
- * coordinator; point symbols and transform members already present in the
1633
- * host stack do the same. Graphics without a host slot remain on preview.
1632
+ * Reconcile the graphics layer after a real resolution change so
1633
+ * pixel-denominated measures and post-clamp label-metric geometry rescale
1634
+ * live. Skipped entirely when nothing rendered reads live view state;
1635
+ * per-group resolution stamps then preserve every unaffected cached render.
1636
+ * A single-control-measure edit publishes through the stack coordinator;
1637
+ * point symbols and transform members already present in the host stack do
1638
+ * the same. Graphics without a host slot remain on preview.
1634
1639
  */
1635
1640
  private readonly handleViewChange;
1636
1641
  /**
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, 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, normalizeTextAmplifiers, 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";
@@ -1199,16 +1199,26 @@ function measureUsesAdapterResolution(measure) {
1199
1199
  /**
1200
1200
  * Whether rendering `measure` through [[renderMeasureForAdapter]] reads live
1201
1201
  * adapter view state — either a pixel-denominated size
1202
- * ([[measureUsesAdapterResolution]]) or draw-time label sizing that
1203
- * [[withCommittedAdapterMeasureOptions]] would still stamp (a
1202
+ * ([[measureUsesAdapterResolution]]), active label-metric-derived geometry, or draw-time label
1203
+ * sizing that [[withCommittedAdapterMeasureOptions]] would still stamp (a
1204
1204
  * `capturesLabelSize` kind not yet carrying any label size). The view-change
1205
- * rerender gates key off this so such measures rescale live; committed
1206
- * ground-anchored measures carry `labelSize` meters, stay zoom-independent,
1207
- * and keep skipping the rebuild.
1205
+ * rerender gates key off this so such measures rescale live. Most committed
1206
+ * ground-anchored measures carry `labelSize` meters and remain
1207
+ * zoom-independent; definitions whose geometry uses post-clamp label metrics
1208
+ * opt in explicitly (optionally scoped to the amplifier fields that activate
1209
+ * the geometry) because their effective text extent changes when the adapter's
1210
+ * pixel clamp engages.
1208
1211
  */
1209
1212
  function measureRendersFromViewState(measure) {
1210
1213
  if (measureUsesAdapterResolution(measure)) return true;
1211
- if (!getControlMeasureMetadata(measure.kind).capturesLabelSize) return false;
1214
+ const metadata = getControlMeasureMetadata(measure.kind);
1215
+ const labelMetricDependency = metadata.labelGeometryUsesResolvedMetrics;
1216
+ if (labelMetricDependency === true) return true;
1217
+ if (labelMetricDependency) {
1218
+ const textAmplifiers = normalizeTextAmplifiers(measure.textAmplifiers);
1219
+ if (labelMetricDependency.some((field) => textAmplifiers[field] !== void 0)) return true;
1220
+ }
1221
+ if (!metadata.capturesLabelSize) return false;
1212
1222
  const options = measure.options;
1213
1223
  return typeof options?.labelSizePixels !== "number" && typeof options?.labelSize !== "number";
1214
1224
  }
@@ -2093,7 +2103,8 @@ function runFixedLengthDraw(options) {
2093
2103
  function rescaleOnViewChange() {
2094
2104
  if (!measureRendersFromViewState({
2095
2105
  kind,
2096
- options: measureOptions
2106
+ options: measureOptions,
2107
+ textAmplifiers: measureTextAmplifiers
2097
2108
  })) return;
2098
2109
  renderPreview();
2099
2110
  }
@@ -2395,7 +2406,8 @@ function runVariableLengthDraw(options) {
2395
2406
  function rescaleOnViewChange() {
2396
2407
  if (!measureRendersFromViewState({
2397
2408
  kind,
2398
- options: measureOptions
2409
+ options: measureOptions,
2410
+ textAmplifiers: measureTextAmplifiers
2399
2411
  })) return;
2400
2412
  renderPreview();
2401
2413
  }
@@ -4202,7 +4214,8 @@ function runEdit(opts) {
4202
4214
  if (ctx.settled) return;
4203
4215
  if (measureRendersFromViewState({
4204
4216
  kind: measure.kind,
4205
- options: workingOptions
4217
+ options: workingOptions,
4218
+ textAmplifiers: workingTextAmplifiers
4206
4219
  })) renderWorkingGraphic();
4207
4220
  else refitBox();
4208
4221
  renderHandlesLayer();
@@ -5799,10 +5812,7 @@ function runGroupTransform(opts) {
5799
5812
  }
5800
5813
  function rescaleOnViewChange() {
5801
5814
  if (ctx.settled) return;
5802
- if (members.some((m) => isAnchoredMember(m) || measureRendersFromViewState({
5803
- kind: m.graphic.kind,
5804
- options: m.graphic.options
5805
- }))) renderAllPreviews();
5815
+ if (members.some((m) => isAnchoredMember(m) || measureRendersFromViewState(m.graphic))) renderAllPreviews();
5806
5816
  else refitBoxes();
5807
5817
  renderHandlesLayer();
5808
5818
  }
@@ -7082,11 +7092,14 @@ var TacticalDraw = class {
7082
7092
  lastRenderedMeasures = [];
7083
7093
  snapGeometryFeatures = [];
7084
7094
  /**
7085
- * Rendered graphics-layer groups, keyed on Graphic snapshot identity. See
7086
- * {@link renderGraphicGroup} for the invalidation contract; swapped for a
7087
- * fresh map (not cleared entry-by-entry) so stale entries are collectable.
7095
+ * Rendered graphics-layer groups, keyed on Graphic snapshot identity. Each
7096
+ * entry records whether and at which adapter resolution it was generated, so
7097
+ * a zoom rebuild replaces only view-dependent groups and preserves every
7098
+ * unrelated cached render.
7088
7099
  */
7089
7100
  graphicGroupCache = /* @__PURE__ */ new WeakMap();
7101
+ /** Last adapter resolution observed by the shared graphics-stack view handler. */
7102
+ lastViewResolution;
7090
7103
  /**
7091
7104
  * Last {@link PointSymbolCapability.generation} observed from `pointSymbols`,
7092
7105
  * initialised from the capability at construction. Compared at the top of
@@ -7115,6 +7128,7 @@ var TacticalDraw = class {
7115
7128
  hasHighlightOutlines = false;
7116
7129
  constructor(adapter, options) {
7117
7130
  this.adapter = adapter;
7131
+ this.lastViewResolution = adapter.getResolution();
7118
7132
  this.graphicsStyle = resolveStyleHints(BUILT_IN_GRAPHICS_STYLE, options?.graphicsStyle, void 0);
7119
7133
  this.defaultInteractionStyle = options?.interactionStyle;
7120
7134
  this.generateId = options?.generateId ?? (() => `td-${++this.idCounter}`);
@@ -7159,16 +7173,27 @@ var TacticalDraw = class {
7159
7173
  * re-renders the same reference is outside the contract — `render()` has
7160
7174
  * always been documented as taking snapshots.) Rendered output also depends
7161
7175
  * on live view state and on the resolved graphics style; the style is fixed
7162
- * at construction, and every view change drops the whole cache. Crucially,
7163
- * the view cannot change during a box drag (drag-pan is disabled), so every
7176
+ * at construction, while a resolution-dependent entry is reused only at the
7177
+ * resolution that produced it. This keeps zoom work proportional to the
7178
+ * affected graphics instead of rebuilding the whole document. Crucially, the
7179
+ * view cannot change during a box drag (drag-pan is disabled), so every
7164
7180
  * graphic outside the selection stays a cache hit for the whole gesture and
7165
7181
  * per-frame reconcile cost becomes O(selection) rather than O(document).
7166
7182
  */
7167
7183
  renderGraphicGroup(graphic) {
7168
7184
  const cached = this.graphicGroupCache.get(graphic);
7169
- if (cached) return cached;
7185
+ if (cached) {
7186
+ if (!cached.resolutionDependent) return cached.group;
7187
+ if (Object.is(cached.resolution, this.adapter.getResolution())) return cached.group;
7188
+ }
7189
+ const resolutionDependent = graphicRendersFromViewState(graphic, this.adapter.scalesGroundPointSymbolsNatively === true);
7190
+ const resolution = resolutionDependent ? this.adapter.getResolution() : void 0;
7170
7191
  const group = this.buildGraphicGroup(graphic);
7171
- this.graphicGroupCache.set(graphic, group);
7192
+ this.graphicGroupCache.set(graphic, {
7193
+ group,
7194
+ resolutionDependent,
7195
+ resolution
7196
+ });
7172
7197
  return group;
7173
7198
  }
7174
7199
  /**
@@ -7208,9 +7233,9 @@ var TacticalDraw = class {
7208
7233
  };
7209
7234
  }
7210
7235
  /**
7211
- * Drop every cached render. Called whenever an input shared by all graphic
7212
- * renders changes — the live view state, or (via {@link reconcileGraphicsStack})
7213
- * the point-symbol capability's `generation`.
7236
+ * Drop every cached render when a renderer capability generation changes.
7237
+ * View changes are handled per entry by {@link renderGraphicGroup} so
7238
+ * resolution-independent graphics remain cache hits.
7214
7239
  */
7215
7240
  invalidateGraphicGroupCache() {
7216
7241
  this.graphicGroupCache = /* @__PURE__ */ new WeakMap();
@@ -7246,18 +7271,22 @@ var TacticalDraw = class {
7246
7271
  this.reconcileGraphicsStack();
7247
7272
  }
7248
7273
  /**
7249
- * Re-render the graphics layer on a view (zoom) change so pixel-denominated
7250
- * and not-yet-committed label-sized measures rescale live. Skipped entirely
7251
- * when nothing rendered still reads live view state — meter geometry with a
7252
- * captured label size is zoom-independent, so a rebuild would be wasted
7253
- * layer writes. A single-control-measure edit publishes through the stack
7254
- * coordinator; point symbols and transform members already present in the
7255
- * host stack do the same. Graphics without a host slot remain on preview.
7274
+ * Reconcile the graphics layer after a real resolution change so
7275
+ * pixel-denominated measures and post-clamp label-metric geometry rescale
7276
+ * live. Skipped entirely when nothing rendered reads live view state;
7277
+ * per-group resolution stamps then preserve every unaffected cached render.
7278
+ * A single-control-measure edit publishes through the stack coordinator;
7279
+ * point symbols and transform members already present in the host stack do
7280
+ * the same. Graphics without a host slot remain on preview.
7256
7281
  */
7257
7282
  handleViewChange = () => {
7258
- if (this.destroyed || !this.hasRendered) return;
7259
- this.invalidateGraphicGroupCache();
7283
+ if (this.destroyed) return;
7284
+ const resolution = this.adapter.getResolution();
7285
+ const resolutionChanged = !Object.is(resolution, this.lastViewResolution);
7286
+ this.lastViewResolution = resolution;
7287
+ if (!this.hasRendered) return;
7260
7288
  this.renderHighlights();
7289
+ if (!resolutionChanged) return;
7261
7290
  const excluded = this.graphicsStackExcludedIds();
7262
7291
  const visible = excluded.size > 0 ? this.lastRenderedMeasures.filter((m) => !excluded.has(m.id)) : this.lastRenderedMeasures;
7263
7292
  const nativePointSymbolScaling = this.adapter.scalesGroundPointSymbolsNatively === true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbat-mapper/tactical-draw",
3
- "version": "0.5.6",
3
+ "version": "0.5.7",
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.17.0"
42
+ "@orbat-mapper/control-measures": "^0.18.0"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "vitest": ">=4.0.0"