@orbat-mapper/tactical-draw 0.2.1 → 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.
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";
@@ -220,11 +220,11 @@ function evaluateGeometry(feature, presentation, context) {
220
220
  distance
221
221
  } : null;
222
222
  }
223
- if (geometry.type === "Polygon") return evaluatePolygon(pixel, geometry.coordinates, presentation, context);
224
- if (geometry.type === "MultiPolygon") return bestPolygonHit(geometry.coordinates.map((polygon) => evaluatePolygon(pixel, polygon, presentation, context)).filter((hit) => hit !== null));
223
+ if (geometry.type === "Polygon") return evaluatePolygon(pixel, geometry.coordinates, presentation, context, feature.properties?.pickInterior === true);
224
+ if (geometry.type === "MultiPolygon") return bestPolygonHit(geometry.coordinates.map((polygon) => evaluatePolygon(pixel, polygon, presentation, context, feature.properties?.pickInterior === true)).filter((hit) => hit !== null));
225
225
  return null;
226
226
  }
227
- function evaluatePolygon(pixel, rings, presentation, context) {
227
+ function evaluatePolygon(pixel, rings, presentation, context, pickInterior) {
228
228
  const { tolerance, toPixel, viewport } = context;
229
229
  const projectedRings = rings.map((ring) => ring.map(toPixel));
230
230
  const distance = hasVisibleBoundary(presentation) ? minimum(projectedRings.map((points) => minVisibleSegmentDistance(pixel, points, viewport))) : null;
@@ -235,7 +235,7 @@ function evaluatePolygon(pixel, rings, presentation, context) {
235
235
  if (!(projectedRings.length > 0 && pointInProjectedRing(pixel, projectedRings[0]) && !projectedRings.slice(1).some((points) => pointInProjectedRing(pixel, points)))) return null;
236
236
  const visiblyFilled = (presentation.fill?.opacity ?? 0) > 0;
237
237
  const inwardReach = context.pointerType === "touch" ? 36 : 24;
238
- if (visiblyFilled || distance !== null && distance <= inwardReach) return {
238
+ if (pickInterior || visiblyFilled || distance !== null && distance <= inwardReach) return {
239
239
  kind: "polygon-interior",
240
240
  distance
241
241
  };
@@ -487,6 +487,7 @@ var BaseMapAdapter = class {
487
487
  id: group.id,
488
488
  features: [...group.features],
489
489
  iconResources: [...group.iconResources],
490
+ ...group.imageOverlays ? { imageOverlays: [...group.imageOverlays] } : {},
490
491
  revision: group.revision
491
492
  }));
492
493
  const nextFeatures = nextGroups.flatMap((group) => group.features);
@@ -615,6 +616,7 @@ function indexFeatureGroupOrder(groups) {
615
616
  function validateFeatureGroups(groups) {
616
617
  const groupIds = /* @__PURE__ */ new Set();
617
618
  const featureIds = /* @__PURE__ */ new Set();
619
+ const overlayIds = /* @__PURE__ */ new Set();
618
620
  for (const group of groups) {
619
621
  if (typeof group.id !== "string" || group.id.trim().length === 0) throw new Error("Feature group id must be a non-empty string");
620
622
  if (groupIds.has(group.id)) throw new Error(`Duplicate feature group id: ${group.id}`);
@@ -624,6 +626,12 @@ function validateFeatureGroups(groups) {
624
626
  if (featureIds.has(feature.id)) throw new Error(`Duplicate feature id: ${String(feature.id)}`);
625
627
  featureIds.add(feature.id);
626
628
  }
629
+ for (const overlay of group.imageOverlays ?? []) {
630
+ if (!overlay.id) throw new Error(`Image overlay in group "${group.id}" is missing an id`);
631
+ if (overlayIds.has(overlay.id)) throw new Error(`Duplicate image overlay id: ${overlay.id}`);
632
+ if (overlay.coordinates.length !== 4) throw new Error(`Image overlay "${overlay.id}" must have four coordinates`);
633
+ overlayIds.add(overlay.id);
634
+ }
627
635
  }
628
636
  }
629
637
  //#endregion
@@ -849,6 +857,50 @@ function resizePointSymbolSize(size, value) {
849
857
  };
850
858
  }
851
859
  //#endregion
860
+ //#region src/image-graphic.ts
861
+ function isImageGraphic(graphic) {
862
+ return typeof graphic === "object" && graphic !== null && "kind" in graphic && graphic.kind === "image";
863
+ }
864
+ function cloneImageGraphic(image) {
865
+ return structuredClone(image);
866
+ }
867
+ function normalizeImageGraphic(image) {
868
+ validateImageGraphic(image);
869
+ const next = cloneImageGraphic(image);
870
+ next.rotation = normalizeImageRotation(next.rotation);
871
+ if (next.style?.opacity !== void 0) next.style.opacity = Math.max(0, Math.min(1, next.style.opacity));
872
+ return next;
873
+ }
874
+ function imageOpacity(image) {
875
+ const opacity = image.style?.opacity ?? 1;
876
+ if (!Number.isFinite(opacity)) throw new TypeError("ImageGraphic.style.opacity must be finite");
877
+ return Math.max(0, Math.min(1, opacity));
878
+ }
879
+ function validateImageGraphic(image) {
880
+ if (!image.id) throw new TypeError("ImageGraphic.id must not be empty");
881
+ if (!image.resourceId) throw new TypeError("ImageGraphic.resourceId must not be empty");
882
+ if (!isFinitePositive(image.intrinsicSize.width)) throw new TypeError("ImageGraphic.intrinsicSize.width must be a positive finite number");
883
+ if (!isFinitePositive(image.intrinsicSize.height)) throw new TypeError("ImageGraphic.intrinsicSize.height must be a positive finite number");
884
+ if (!isFinitePositive(image.size.value)) throw new TypeError("ImageGraphic.size.value must be a positive finite number");
885
+ if (image.size.unit !== "meters") throw new TypeError("ImageGraphic.size.unit must be \"meters\"");
886
+ if (!Number.isFinite(image.rotation)) throw new TypeError("ImageGraphic.rotation must be finite");
887
+ if (image.schemaVersion !== 1) throw new TypeError("ImageGraphic.schemaVersion must be 1");
888
+ imageOpacity(image);
889
+ if (!Array.isArray(image.position) || image.position.length < 2 || !Number.isFinite(image.position[0]) || !Number.isFinite(image.position[1])) throw new TypeError("ImageGraphic.position must be a finite geographic position");
890
+ }
891
+ function isFinitePositive(value) {
892
+ return Number.isFinite(value) && value > 0;
893
+ }
894
+ function normalizeImageRotation(value) {
895
+ const turn = Math.PI * 2;
896
+ return (value % turn + turn) % turn;
897
+ }
898
+ //#endregion
899
+ //#region src/graphic.ts
900
+ function isAnchoredGraphic(graphic) {
901
+ return isPointSymbol(graphic) || isImageGraphic(graphic);
902
+ }
903
+ //#endregion
852
904
  //#region src/tactical-draw/active-interaction.ts
853
905
  /**
854
906
  * Owns the facade's public interaction state: the abort handle used by
@@ -1050,6 +1102,10 @@ const PIXEL_SIZE_OPTIONS = {
1050
1102
  pixels: "toothHeightPixels",
1051
1103
  meters: "toothHeight"
1052
1104
  },
1105
+ minefield: {
1106
+ pixels: "sizePixels",
1107
+ meters: "sizeMeters"
1108
+ },
1053
1109
  text: {
1054
1110
  pixels: "sizePixels",
1055
1111
  meters: "sizeMeters"
@@ -1074,6 +1130,22 @@ function sizeOptionSpecs(kind) {
1074
1130
  return specs;
1075
1131
  }
1076
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
+ /**
1077
1149
  * Whether `measure` carries a pixel-denominated size option whose resolution
1078
1150
  * to meters depends on the live map (`metersPerPixel`) — i.e. it is
1079
1151
  * *screen-anchored*. Used both to inject the override
@@ -1084,7 +1156,11 @@ function sizeOptionSpecs(kind) {
1084
1156
  */
1085
1157
  function measureUsesAdapterResolution(measure) {
1086
1158
  const options = measure.options;
1087
- 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
+ });
1088
1164
  }
1089
1165
  /**
1090
1166
  * Whether rendering `measure` through [[renderMeasureForAdapter]] reads live
@@ -1441,7 +1517,7 @@ const DEFAULT_TOLERANCE_PIXELS = 12;
1441
1517
  function graphicCandidates(graphics) {
1442
1518
  const candidates = [];
1443
1519
  for (const graphic of graphics) {
1444
- if (isPointSymbol(graphic)) {
1520
+ if (isAnchoredGraphic(graphic)) {
1445
1521
  candidates.push({
1446
1522
  id: `${graphic.id}:anchor`,
1447
1523
  coordinate: graphic.position,
@@ -3814,6 +3890,7 @@ function runEdit(opts) {
3814
3890
  const guideEnabled = (guideOpt ?? true) && !shouldSuppressGuide(metadata);
3815
3891
  const isAreaKind = metadata.geometry === "area";
3816
3892
  const isTextGraphic = measure.kind === "text";
3893
+ const foldsTransformIntoOptions = foldsBoxTransformOptions(measure.kind);
3817
3894
  const requestedModes = normaliseModes(initialModes);
3818
3895
  const editStartPoints = measure.controlPoints.map((p) => [...p]);
3819
3896
  const workingPoints = editStartPoints.map((p) => [...p]);
@@ -3972,7 +4049,7 @@ function runEdit(opts) {
3972
4049
  const px = driver.toPixel(p);
3973
4050
  if (px) pixels.push(px);
3974
4051
  }
3975
- return fitTransformBox(pixels, boxAngle, interactionStyle?.boxPadding ?? 0);
4052
+ return fitTransformBox(pixels, activeOptionTransformInFlight() ? activeBoxDrag.lastSnapshot.box.angle : boxAngle, interactionStyle?.boxPadding ?? 0);
3976
4053
  }
3977
4054
  /**
3978
4055
  * The Text footprint box (rotated rectangle hugging the rendered text),
@@ -3991,12 +4068,12 @@ function runEdit(opts) {
3991
4068
  * Re-fit `box` from `lastWorkingFeatures`. A no-op while a box gesture is
3992
4069
  * in flight — that drag paints the box rigidly from its own snapshot
3993
4070
  * (`BoxDragSnapshot.box`) instead of a re-fit, so a corner/rotate/body drag
3994
- * doesn't fight its own paint. Text is the exception: its box follows the
3995
- * rendered footprint live (a rotate/scale gesture changes the rendered text),
3996
- * 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.
3997
4074
  */
3998
4075
  function refitBox() {
3999
- if (activeBoxDrag && !isTextGraphic) return;
4076
+ if (activeBoxDrag && !activeOptionTransformInFlight()) return;
4000
4077
  box = fitBoxFromFeatures(lastWorkingFeatures);
4001
4078
  }
4002
4079
  function renderWorkingGraphic() {
@@ -4048,7 +4125,7 @@ function runEdit(opts) {
4048
4125
  }), handleIdPrefix, interactionStyle);
4049
4126
  if (modes.includes("labeldrag")) features.push(...labels.handleFeatures());
4050
4127
  if (modes.includes("transform")) {
4051
- const liveBox = activeBoxDrag && !isTextGraphic ? activeBoxDrag.lastSnapshot.box : box;
4128
+ const liveBox = activeBoxDrag && !activeOptionTransformInFlight() ? activeBoxDrag.lastSnapshot.box : box;
4052
4129
  if (liveBox) {
4053
4130
  features.push(boxOutlineFeature(liveBox, dragProjection.fromPixel, `${handleIdPrefix}:box-outline`, interactionStyle?.boxOutline));
4054
4131
  features.push(...toFeatures(boxToHandles(liveBox, dragProjection.fromPixel), handleIdPrefix, interactionStyle));
@@ -4702,13 +4779,12 @@ function runEdit(opts) {
4702
4779
  }
4703
4780
  /**
4704
4781
  * Fold a box gesture's delta (the box `to` relative to `from`, given the
4705
- * gesture `kind`) into a Text graphic's `rotation`/size options, on top of
4706
- * `base`. A `scale` grows the active size anchor; a `rotate` adds to the
4707
- * rotation. Returns `base` unchanged when the kind produces no patch. The
4708
- * delta (uniform scale ratio, angle difference) is pivot-independent, so
4709
- * 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.
4710
4786
  */
4711
- function foldTextTransform(from, to, kind, base) {
4787
+ function foldOptionTransform(from, to, kind, base) {
4712
4788
  const { scale, rotation } = boxScaleRotation(kind, to, from);
4713
4789
  const patch = applyBoxTransformOptions(measure.kind, base ?? {}, {
4714
4790
  scale,
@@ -4717,16 +4793,23 @@ function runEdit(opts) {
4717
4793
  return patch ? {
4718
4794
  ...base ?? {},
4719
4795
  ...patch
4720
- } : 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";
4721
4803
  }
4722
4804
  function paintBoxDragSnapshot(pixel, info, constrainRotation = false) {
4723
4805
  if (!activeBoxDrag) return;
4724
4806
  const resolvedPixel = translatedBoxPixel(pixel, info, activeBoxDrag);
4725
4807
  const snapshot = activeBoxDrag.fsm.move(resolvedPixel, { constrainRotation });
4726
4808
  activeBoxDrag.lastSnapshot = snapshot;
4727
- 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);
4728
4811
  workingPoints.splice(0, workingPoints.length, ...activeBoxDrag.preDragPoints);
4729
- workingOptions = foldTextTransform(activeBoxDrag.preDragBox, snapshot.box, activeBoxDrag.fsm.kind, activeBoxDrag.preDragOptions);
4812
+ if (foldedOptions) workingOptions = foldedOptions;
4730
4813
  nonGeometryDirty = true;
4731
4814
  renderWorkingGraphic();
4732
4815
  renderHandlesLayer();
@@ -4824,13 +4907,14 @@ function runEdit(opts) {
4824
4907
  const finalSnapshot = fsm.move(finalPixel, { constrainRotation: info?.shiftKey });
4825
4908
  replaceWorkingPoints(preDragPoints);
4826
4909
  workingAmplifierPlacements = preDragAmplifierPlacements;
4827
- const textOptionFold = isTextGraphic && (fsm.kind === "rotate" || fsm.kind === "scale");
4910
+ const optionFold = foldsTransformIntoOptions && (fsm.kind === "rotate" || fsm.kind === "scale");
4828
4911
  if (fsm.kind === "rotate" && !isTextGraphic) boxAngle += finalSnapshot.box.angle - preDragBox.angle;
4829
- if (textOptionFold) {
4830
- 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;
4831
4915
  nonGeometryDirty = true;
4832
4916
  }
4833
- const committedPoints = textOptionFold ? preDragPoints : finalSnapshot.points;
4917
+ const committedPoints = optionFold ? preDragPoints : finalSnapshot.points;
4834
4918
  emitTransient("end", committedPoints, null);
4835
4919
  commitGesture(committedPoints, preDragOptions, transformAmplifierPlacements(preDragAmplifierPlacements, preDragBox, finalSnapshot.box, driver), preDragBox.angle);
4836
4920
  return;
@@ -4953,6 +5037,13 @@ var PointSymbolCapabilityRequiredError = class extends Error {
4953
5037
  this.name = "PointSymbolCapabilityRequiredError";
4954
5038
  }
4955
5039
  };
5040
+ var ImageCapabilityRequiredError = class ImageCapabilityRequiredError extends Error {
5041
+ constructor() {
5042
+ super("TacticalDraw: image capability is not configured");
5043
+ this.name = "ImageCapabilityRequiredError";
5044
+ Object.setPrototypeOf(this, ImageCapabilityRequiredError.prototype);
5045
+ }
5046
+ };
4956
5047
  //#endregion
4957
5048
  //#region src/tactical-draw/point-symbol-rendering.ts
4958
5049
  function effectivePointSymbolPixelSize(symbol, resolution) {
@@ -5037,6 +5128,117 @@ function boundProperty(key, value) {
5037
5128
  return value !== void 0 && Number.isFinite(value) && value > 0 ? { [key]: value } : {};
5038
5129
  }
5039
5130
  //#endregion
5131
+ //#region src/tactical-draw/image-rendering.ts
5132
+ function effectiveImagePixelWidth(image, resolution) {
5133
+ if (resolution === void 0 || resolution <= 0) return image.size.value;
5134
+ return image.size.value / resolution;
5135
+ }
5136
+ function imagePixelScale(image, render, resolution) {
5137
+ return effectiveImagePixelWidth(image, resolution) / render.width;
5138
+ }
5139
+ function imageFootprint(image, render, adapter) {
5140
+ const center = adapter.getPixelFromCoordinate(image.position);
5141
+ if (!center) return null;
5142
+ const scale = imagePixelScale(image, render, adapter.getResolution());
5143
+ const box = {
5144
+ center,
5145
+ halfWidth: render.width * scale / 2,
5146
+ halfHeight: render.height * scale / 2,
5147
+ angle: image.rotation - adapter.getBearing()
5148
+ };
5149
+ return {
5150
+ box,
5151
+ corners: boxCorners(box)
5152
+ };
5153
+ }
5154
+ function renderImageForAdapter(adapter, capability, image) {
5155
+ validateImageGraphic(image);
5156
+ const resolved = capability.resolve(image.resourceId);
5157
+ const source = resolved ? validateResolvedResource(image, resolved) : missingResource(image);
5158
+ const render = {
5159
+ resourceId: source.id,
5160
+ width: source.width,
5161
+ height: source.height,
5162
+ ...resolved ? { overlayUrl: source.overlayUrl } : {},
5163
+ available: resolved !== void 0
5164
+ };
5165
+ const coordinates = imageOverlayCoordinates(adapter, image, render);
5166
+ return {
5167
+ render,
5168
+ ...render.overlayUrl ? { overlay: {
5169
+ id: `${image.id}:image-overlay`,
5170
+ url: render.overlayUrl,
5171
+ width: render.width,
5172
+ height: render.height,
5173
+ coordinates,
5174
+ opacity: imageOpacity(image)
5175
+ } } : {},
5176
+ feature: imageOverlayFeature(image, coordinates, render.available)
5177
+ };
5178
+ }
5179
+ function imageOverlayCoordinates(adapter, image, render) {
5180
+ const [centerX, centerY] = adapter.fromLonLat(image.position);
5181
+ const halfWidth = image.size.value / 2;
5182
+ const halfHeight = image.size.value * render.height / render.width / 2;
5183
+ const cos = Math.cos(-image.rotation);
5184
+ const sin = Math.sin(-image.rotation);
5185
+ const rotate = (x, y) => adapter.toLonLat([centerX + x * cos - y * sin, centerY + x * sin + y * cos]);
5186
+ return [
5187
+ rotate(-halfWidth, halfHeight),
5188
+ rotate(halfWidth, halfHeight),
5189
+ rotate(halfWidth, -halfHeight),
5190
+ rotate(-halfWidth, -halfHeight)
5191
+ ];
5192
+ }
5193
+ function imageOverlayFeature(image, coordinates, available) {
5194
+ return {
5195
+ type: "Feature",
5196
+ id: `${image.id}:image`,
5197
+ geometry: {
5198
+ type: "Polygon",
5199
+ coordinates: [[...coordinates.map((coordinate) => [...coordinate]), [...coordinates[0]]]]
5200
+ },
5201
+ properties: {
5202
+ ...image.properties ?? {},
5203
+ graphicId: image.id,
5204
+ graphicKind: "image",
5205
+ imageOverlayId: `${image.id}:image-overlay`,
5206
+ imageAvailable: available,
5207
+ pickInterior: true,
5208
+ style: available ? {
5209
+ fillColor: "rgba(0,0,0,0)",
5210
+ strokeColor: "rgba(0,0,0,0)",
5211
+ strokeWidth: 0
5212
+ } : {
5213
+ fillColor: "rgba(243,244,246,0.85)",
5214
+ strokeColor: "#6b7280",
5215
+ strokeWidth: 2
5216
+ }
5217
+ }
5218
+ };
5219
+ }
5220
+ function validateResolvedResource(image, resource) {
5221
+ if (resource.id !== image.resourceId) throw new TypeError("ImageCapability returned a resource with a mismatched id");
5222
+ if (!isSelfContainedRasterDataUrl(resource.overlayUrl)) throw new TypeError("ImageResource.overlayUrl must be a self-contained raster data URL");
5223
+ if (!Number.isFinite(resource.width) || resource.width <= 0) throw new TypeError("ImageResource.width must be a positive finite number");
5224
+ if (!Number.isFinite(resource.height) || resource.height <= 0) throw new TypeError("ImageResource.height must be a positive finite number");
5225
+ if (resource.width !== image.intrinsicSize.width || resource.height !== image.intrinsicSize.height) throw new TypeError("ImageResource dimensions must match ImageGraphic.intrinsicSize");
5226
+ return resource;
5227
+ }
5228
+ function isSelfContainedRasterDataUrl(value) {
5229
+ const match = /^data:(image\/[a-z0-9.+-]+)(?:;[^,]*)?,.+$/is.exec(value);
5230
+ return match !== null && match[1].toLowerCase() !== "image/svg+xml";
5231
+ }
5232
+ function missingResource(image) {
5233
+ const { width, height } = image.intrinsicSize;
5234
+ return {
5235
+ id: `__td_missing_image__:${width}x${height}`,
5236
+ overlayUrl: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=",
5237
+ width,
5238
+ height
5239
+ };
5240
+ }
5241
+ //#endregion
5040
5242
  //#region src/tactical-draw/frame-coalescer.ts
5041
5243
  /**
5042
5244
  * @param run Callback invoked with the latest scheduled args, at most once per frame.
@@ -5106,20 +5308,32 @@ function scalePointSymbolStates(pre, scale, rotation) {
5106
5308
  * a live session without a session boundary
5107
5309
  */
5108
5310
  function runGroupTransform(opts) {
5109
- const { adapter, capability, graphics, graphicsLayer, previewLayer, handlesLayer, graphicsStyle, signal, closeOnClickAway = true, interactionStyle, onSession, handleIdPrefix, publishWorkingGraphics, settleWorkingGraphics, isOnGraphicsLayer, onSettled, onClickAwayGraphicsPick } = opts;
5311
+ const { adapter, capability, imageCapability, graphics, graphicsLayer, previewLayer, handlesLayer, graphicsStyle, signal, closeOnClickAway = true, interactionStyle, onSession, handleIdPrefix, publishWorkingGraphics, settleWorkingGraphics, isOnGraphicsLayer, onSettled, onClickAwayGraphicsPick } = opts;
5110
5312
  assertCapabilityFor(graphics);
5313
+ validateImageResources(graphics);
5111
5314
  const renderOpts = graphicsStyle ? { graphicsStyle } : void 0;
5112
5315
  let sizeAnchor = opts.sizeAnchor ?? "ground";
5113
5316
  /** Throw synchronously if any graphic in `list` is a point symbol and no capability was supplied. */
5114
5317
  function assertCapabilityFor(list) {
5115
5318
  if (!capability && list.some(isPointSymbol)) throw new PointSymbolCapabilityRequiredError();
5319
+ if (!imageCapability && list.some(isImageGraphic)) throw new ImageCapabilityRequiredError();
5320
+ }
5321
+ /** Validate host integration before listeners, layers, or interaction state are created. */
5322
+ function validateImageResources(list) {
5323
+ for (const graphic of list) if (isImageGraphic(graphic)) renderImageForAdapter(adapter, imageCapability, graphic);
5116
5324
  }
5117
5325
  function isPointSymbolMember(member) {
5118
5326
  return isPointSymbol(member.graphic);
5119
5327
  }
5328
+ function isImageMember(member) {
5329
+ return isImageGraphic(member.graphic);
5330
+ }
5331
+ function isAnchoredMember(member) {
5332
+ return isAnchoredGraphic(member.graphic);
5333
+ }
5120
5334
  /** Build a fresh working record for `graphic`, snapshotting its edit-start state. */
5121
5335
  function createMemberState(graphic) {
5122
- if (isPointSymbol(graphic)) {
5336
+ if (isAnchoredGraphic(graphic)) {
5123
5337
  const editStartPoints = [[...graphic.position]];
5124
5338
  return {
5125
5339
  graphic,
@@ -5175,6 +5389,16 @@ function runGroupTransform(opts) {
5175
5389
  symbol.rotation = member.workingRotation;
5176
5390
  return symbol;
5177
5391
  }
5392
+ function buildWorkingImage(member) {
5393
+ const image = cloneImageGraphic(member.graphic);
5394
+ image.position = [...member.workingPoints[0]];
5395
+ image.size = {
5396
+ value: member.workingSize,
5397
+ unit: "meters"
5398
+ };
5399
+ image.rotation = member.workingRotation;
5400
+ return image;
5401
+ }
5178
5402
  /** Build the working measure for member `i` with a given options override. */
5179
5403
  function buildWorkingMeasureWith(member, override) {
5180
5404
  const measure = member.graphic;
@@ -5195,6 +5419,13 @@ function runGroupTransform(opts) {
5195
5419
  render: capability.render(symbol)
5196
5420
  };
5197
5421
  }
5422
+ if (isImageMember(member)) {
5423
+ const image = buildWorkingImage(member);
5424
+ return {
5425
+ graphic: cloneImageGraphic(image),
5426
+ render: renderImageForAdapter(adapter, imageCapability, image).render
5427
+ };
5428
+ }
5198
5429
  const working = buildWorkingMeasureWith(member, override);
5199
5430
  const committed = sizeAnchor === "screen" ? working : bakePixelSizeToGround(working, adapter);
5200
5431
  return {
@@ -5206,6 +5437,7 @@ function runGroupTransform(opts) {
5206
5437
  function workingGraphicFor(i) {
5207
5438
  const member = members[i];
5208
5439
  if (isPointSymbolMember(member)) return buildWorkingPointSymbol(member);
5440
+ if (isImageMember(member)) return buildWorkingImage(member);
5209
5441
  return buildWorkingMeasureWith(member, member.optionsOverride);
5210
5442
  }
5211
5443
  let dirty = false;
@@ -5288,7 +5520,7 @@ function runGroupTransform(opts) {
5288
5520
  const { scale, rotation } = boxScaleRotation(kind, box, fromBox);
5289
5521
  if (scale === 1 && rotation === 0) return;
5290
5522
  members.forEach((member, i) => {
5291
- if (isPointSymbolMember(member)) return;
5523
+ if (isAnchoredMember(member)) return;
5292
5524
  const base = baseOverrides[i] ?? null;
5293
5525
  const effective = mergeOptions(member.graphic.options, base);
5294
5526
  const patch = applyBoxTransformOptions(member.graphic.kind, effective, {
@@ -5331,8 +5563,16 @@ function runGroupTransform(opts) {
5331
5563
  members.forEach((member, i) => {
5332
5564
  let features;
5333
5565
  let iconResources = [];
5566
+ let imageOverlays;
5334
5567
  let boxPixels = [];
5335
- try {
5568
+ if (isImageMember(member)) {
5569
+ const image = buildWorkingImage(member);
5570
+ const plan = renderImageForAdapter(adapter, imageCapability, image);
5571
+ imageOverlays = plan.overlay ? [plan.overlay] : void 0;
5572
+ features = [plan.feature];
5573
+ const footprint = imageFootprint(image, plan.render, adapter);
5574
+ if (footprint) boxPixels = footprint.corners;
5575
+ } else try {
5336
5576
  if (isPointSymbolMember(member)) {
5337
5577
  const symbol = buildWorkingPointSymbol(member);
5338
5578
  const plan = renderPointSymbolForAdapter(adapter, capability, symbol);
@@ -5353,12 +5593,14 @@ function runGroupTransform(opts) {
5353
5593
  if (member.usesGraphicStack) workingGroups.push({
5354
5594
  id: member.graphic.id,
5355
5595
  features,
5356
- iconResources
5596
+ iconResources,
5597
+ ...imageOverlays ? { imageOverlays } : {}
5357
5598
  });
5358
5599
  else previewGroups.push({
5359
5600
  id: member.graphic.id,
5360
5601
  features,
5361
- iconResources
5602
+ iconResources,
5603
+ ...imageOverlays ? { imageOverlays } : {}
5362
5604
  });
5363
5605
  });
5364
5606
  publishWorkingGraphics(workingGroups);
@@ -5367,7 +5609,7 @@ function runGroupTransform(opts) {
5367
5609
  }
5368
5610
  function rescaleOnViewChange() {
5369
5611
  if (ctx.settled) return;
5370
- if (members.some((m) => isPointSymbolMember(m) || measureRendersFromViewState({
5612
+ if (members.some((m) => isAnchoredMember(m) || measureRendersFromViewState({
5371
5613
  kind: m.graphic.kind,
5372
5614
  options: m.graphic.options
5373
5615
  }))) renderAllPreviews();
@@ -5403,7 +5645,7 @@ function runGroupTransform(opts) {
5403
5645
  return members.map((member) => buildMemberSnapshot(member, member.optionsOverride));
5404
5646
  }
5405
5647
  function recomputeDirty() {
5406
- dirty = nonGeometryDirty || members.some((m) => !pointsEqualWithinTolerance(m.workingPoints, m.editStartPoints, 1e-9) || isPointSymbolMember(m) && (m.workingSize !== m.editStartSize || m.workingRotation !== m.editStartRotation));
5648
+ dirty = nonGeometryDirty || members.some((m) => !pointsEqualWithinTolerance(m.workingPoints, m.editStartPoints, 1e-9) || isAnchoredMember(m) && (m.workingSize !== m.editStartSize || m.workingRotation !== m.editStartRotation));
5407
5649
  }
5408
5650
  /** Split `points` (the concatenation of every member's anchor points) back per member. */
5409
5651
  function applyConcatenatedPoints(points) {
@@ -5431,7 +5673,7 @@ function runGroupTransform(opts) {
5431
5673
  }
5432
5674
  /** Snapshot each point-symbol member's working size/rotation (`null` for measures). */
5433
5675
  function clonePointSymbolStateByMember() {
5434
- return members.map((m) => isPointSymbolMember(m) ? {
5676
+ return members.map((m) => isAnchoredMember(m) ? {
5435
5677
  size: m.workingSize,
5436
5678
  rotation: m.workingRotation
5437
5679
  } : null);
@@ -5440,7 +5682,7 @@ function runGroupTransform(opts) {
5440
5682
  function applyPointSymbolStateByMember(states) {
5441
5683
  members.forEach((member, i) => {
5442
5684
  const state = states[i];
5443
- if (state && isPointSymbolMember(member)) {
5685
+ if (state && isAnchoredMember(member)) {
5444
5686
  member.workingSize = state.size;
5445
5687
  member.workingRotation = state.rotation;
5446
5688
  }
@@ -5480,7 +5722,7 @@ function runGroupTransform(opts) {
5480
5722
  */
5481
5723
  function freezeOrientationForRotate() {
5482
5724
  members.forEach((member, i) => {
5483
- if (isPointSymbolMember(member)) return;
5725
+ if (isAnchoredMember(member)) return;
5484
5726
  const patch = freezeOrientationOptions(member.graphic.kind, member.workingPoints.map((p) => [...p]), effectiveOptions(i));
5485
5727
  if (patch) member.optionsOverride = {
5486
5728
  ...member.optionsOverride ?? {},
@@ -5696,7 +5938,7 @@ function runGroupTransform(opts) {
5696
5938
  },
5697
5939
  controlPointsFor(graphicId) {
5698
5940
  const member = members.find((m) => m.graphic.id === graphicId);
5699
- if (!member || isPointSymbolMember(member)) return void 0;
5941
+ if (!member || isAnchoredMember(member)) return void 0;
5700
5942
  return member.workingPoints.map((p) => [...p]);
5701
5943
  },
5702
5944
  get dirty() {
@@ -5818,7 +6060,7 @@ function runGroupTransform(opts) {
5818
6060
  applyConcatenatedPoints(preDragPoints);
5819
6061
  applyPointSymbolStateByMember(preDragPointSymbolStateByMember);
5820
6062
  applyAmplifierPlacementsByMember(preDragAmplifierPlacementsByMember);
5821
- if (members.some(isPointSymbolMember)) shell.suppressNextClickAway();
6063
+ if (members.some(isAnchoredMember)) shell.suppressNextClickAway();
5822
6064
  if (fsm.kind === "rotate") boxAngle += finalSnapshot.box.angle - preDragBox.angle;
5823
6065
  applyMeasureTransformForBox(finalSnapshot.box, preDragBox, fsm.kind, preDragOptionsOverrideByMember);
5824
6066
  commitGesture(finalSnapshot.points, preDragOptionsOverrideByMember, preDragAmplifierPlacementsByMember.map((placements) => transformAmplifierPlacements(placements, preDragBox, finalSnapshot.box, driver)), preDragBox.angle, nextPointSymbolStateByMember);
@@ -5885,7 +6127,7 @@ function runGroupTransform(opts) {
5885
6127
  }
5886
6128
  //#endregion
5887
6129
  //#region src/tactical-draw/point-symbol-draw-controller.ts
5888
- const PREVIEW_ID = "__td_point_symbol_preview__";
6130
+ const PREVIEW_ID$1 = "__td_point_symbol_preview__";
5889
6131
  function runPointSymbolDraw(options) {
5890
6132
  const { adapter, capability, draft, previewLayer, generateId, signal, onSettled, snap } = options;
5891
6133
  let latestPosition = draft.position;
@@ -5902,9 +6144,9 @@ function runPointSymbolDraw(options) {
5902
6144
  });
5903
6145
  const renderPreview = () => {
5904
6146
  if (!latestPosition) return;
5905
- const plan = renderPointSymbolForAdapter(adapter, capability, build(PREVIEW_ID, latestPosition));
6147
+ const plan = renderPointSymbolForAdapter(adapter, capability, build(PREVIEW_ID$1, latestPosition));
5906
6148
  ctx.writeLayer(previewLayer, [{
5907
- id: PREVIEW_ID,
6149
+ id: PREVIEW_ID$1,
5908
6150
  features: [plan.feature],
5909
6151
  iconResources: [plan.resource]
5910
6152
  }]);
@@ -6191,6 +6433,338 @@ function runPointSymbolEdit(opts) {
6191
6433
  return usesGraphicStack;
6192
6434
  },
6193
6435
  measureId: symbol.id,
6436
+ graphicKind: "point-symbol",
6437
+ abort: handle.abort,
6438
+ syncHostMembership(present) {
6439
+ if (handle.settled || usesGraphicStack === present) return;
6440
+ const previous = usesGraphicStack;
6441
+ usesGraphicStack = present;
6442
+ try {
6443
+ render();
6444
+ } catch (error) {
6445
+ usesGraphicStack = previous;
6446
+ throw error;
6447
+ }
6448
+ }
6449
+ };
6450
+ }
6451
+ //#endregion
6452
+ //#region src/tactical-draw/image-draw-controller.ts
6453
+ const PREVIEW_ID = "__td_image_preview__";
6454
+ const DEFAULT_IMAGE_WIDTH_PIXELS = 128;
6455
+ function runImageDraw(options) {
6456
+ const { adapter, capability, draft, previewLayer, generateId, signal, onSettled, snap } = options;
6457
+ let latestPosition = draft.position;
6458
+ let ctx;
6459
+ const savedCursor = "";
6460
+ const build = (id, position) => ({
6461
+ ...structuredClone(draft),
6462
+ id,
6463
+ kind: "image",
6464
+ resourceId: draft.resourceId,
6465
+ intrinsicSize: structuredClone(draft.intrinsicSize),
6466
+ position: [...position],
6467
+ rotation: normalizeRotation(draft.rotation ?? 0),
6468
+ schemaVersion: 1,
6469
+ size: structuredClone(draft.size ?? {
6470
+ value: DEFAULT_IMAGE_WIDTH_PIXELS * positiveResolution(adapter.getResolution()),
6471
+ unit: "meters"
6472
+ }),
6473
+ ...draft.style ? { style: {
6474
+ ...draft.style,
6475
+ opacity: Math.max(0, Math.min(1, draft.style.opacity ?? 1))
6476
+ } } : {}
6477
+ });
6478
+ const planFor = (id, position) => renderImageForAdapter(adapter, capability, build(id, position));
6479
+ const renderPreview = () => {
6480
+ if (!latestPosition) return;
6481
+ const plan = planFor(PREVIEW_ID, latestPosition);
6482
+ ctx.writeLayer(previewLayer, [{
6483
+ id: PREVIEW_ID,
6484
+ features: [plan.feature],
6485
+ iconResources: [],
6486
+ ...plan.overlay ? { imageOverlays: [plan.overlay] } : {}
6487
+ }]);
6488
+ };
6489
+ const handlePointerMove = (event) => {
6490
+ latestPosition = snappedDrawPosition(snap, event);
6491
+ renderPreview();
6492
+ };
6493
+ const handleClick = (event) => {
6494
+ latestPosition = snappedDrawPosition(snap, event);
6495
+ ctx.commit(() => {
6496
+ const graphic = build(draft.id ?? generateId(), latestPosition);
6497
+ return {
6498
+ graphic: cloneImageGraphic(graphic),
6499
+ render: planFor(graphic.id, graphic.position).render
6500
+ };
6501
+ });
6502
+ };
6503
+ return runInteraction({
6504
+ adapter,
6505
+ signal,
6506
+ layers: [previewLayer],
6507
+ onViewChange: renderPreview,
6508
+ onSettled,
6509
+ attach(interaction) {
6510
+ ctx = interaction;
6511
+ interaction.onTeardown(() => {
6512
+ adapter.off("pointermove", handlePointerMove);
6513
+ adapter.off("click", handleClick);
6514
+ adapter.setCursor(savedCursor);
6515
+ });
6516
+ adapter.setCursor("crosshair");
6517
+ adapter.on("pointermove", handlePointerMove);
6518
+ adapter.on("click", handleClick);
6519
+ renderPreview();
6520
+ }
6521
+ });
6522
+ }
6523
+ function positiveResolution(resolution) {
6524
+ return resolution !== void 0 && resolution > 0 ? resolution : 1;
6525
+ }
6526
+ //#endregion
6527
+ //#region src/tactical-draw/image-edit-controller.ts
6528
+ function normaliseImageModes(input) {
6529
+ const modes = input ?? ["transform"];
6530
+ for (const mode of modes) if (mode !== "transform" && mode !== "delete") throw new TypeError(`Image editing does not support mode "${mode}"`);
6531
+ return modes.includes("delete") ? ["delete"] : [...new Set(modes)];
6532
+ }
6533
+ function runImageEdit(opts) {
6534
+ const { adapter, capability, image, graphicsLayer, previewLayer, handlesLayer, signal, closeOnClickAway = true, interactionStyle, onSession, handleIdPrefix, settleToGraphics, publishWorkingGraphic, wasOnGraphicsLayer, onSettled, onClickAwayGraphicsPick, snap } = opts;
6535
+ validateImageGraphic(image);
6536
+ let modes = normaliseImageModes(opts.modes);
6537
+ let usesGraphicStack = wasOnGraphicsLayer;
6538
+ let working = cloneImageGraphic(image);
6539
+ let dirty = false;
6540
+ let box = null;
6541
+ let drag = null;
6542
+ let ctx;
6543
+ let driver;
6544
+ let shell;
6545
+ const changeEmitter = createChangeEmitter({
6546
+ listenerErrorsMessage: "GraphicEditSession.onChange errors",
6547
+ isSettled: () => ctx.settled,
6548
+ abort: () => ctx.fail(new TacticalDrawAbortError("session")),
6549
+ close: () => ctx.commit(snapshot)
6550
+ });
6551
+ const commitEmitter = createCommitEmitter("GraphicEditSession.onCommit listener errors");
6552
+ const settleEmitter = createSettleEmitter("GraphicEditSession.onSettled listener errors");
6553
+ const captureHistory = () => ({ working: cloneImageGraphic(working) });
6554
+ const snapshot = () => ({
6555
+ graphic: cloneImageGraphic(working),
6556
+ render: renderImageForAdapter(adapter, capability, working).render
6557
+ });
6558
+ const render = (publishGraphic = true) => {
6559
+ if (ctx.settled) return;
6560
+ const plan = renderImageForAdapter(adapter, capability, working);
6561
+ const footprint = imageFootprint(working, plan.render, adapter);
6562
+ const nextBox = footprint ? {
6563
+ ...footprint.box,
6564
+ halfWidth: Math.max(1, footprint.box.halfWidth) + (interactionStyle?.boxPadding ?? 0),
6565
+ halfHeight: Math.max(1, footprint.box.halfHeight) + (interactionStyle?.boxPadding ?? 0)
6566
+ } : null;
6567
+ const handles = [];
6568
+ if (modes.includes("transform") && nextBox) handles.push(boxOutlineFeature(nextBox, (pixel) => driver.fromPixel(pixel), `${handleIdPrefix}:box-outline`, interactionStyle?.boxOutline), ...toFeatures(boxToHandles(nextBox, (pixel) => driver.fromPixel(pixel)), handleIdPrefix, interactionStyle));
6569
+ const group = {
6570
+ id: working.id,
6571
+ features: [plan.feature],
6572
+ iconResources: [],
6573
+ ...plan.overlay ? { imageOverlays: [plan.overlay] } : {}
6574
+ };
6575
+ if (publishGraphic) {
6576
+ publishWorkingGraphic(group);
6577
+ ctx.writeLayer(previewLayer, usesGraphicStack ? [] : [group]);
6578
+ }
6579
+ box = nextBox;
6580
+ ctx.writeLayer(handlesLayer, [{
6581
+ id: `__td_image_edit_handles__:${working.id}`,
6582
+ features: handles,
6583
+ iconResources: []
6584
+ }]);
6585
+ };
6586
+ const emitChange = (previousState, source, onAccepted) => {
6587
+ const previous = {
6588
+ graphic: cloneImageGraphic(previousState.working),
6589
+ render: renderImageForAdapter(adapter, capability, previousState.working).render
6590
+ };
6591
+ return changeEmitter.emit({
6592
+ source,
6593
+ graphic: snapshot(),
6594
+ previous,
6595
+ session
6596
+ }, {
6597
+ rollback() {
6598
+ working = cloneImageGraphic(previousState.working);
6599
+ dirty = !deepEqual(working, image);
6600
+ render();
6601
+ },
6602
+ onAccepted
6603
+ });
6604
+ };
6605
+ const history = createSessionHistory({
6606
+ initial: captureHistory(),
6607
+ clone: (value) => ({ working: cloneImageGraphic(value.working) }),
6608
+ equals: (a, b) => deepEqual(a.working, b.working),
6609
+ isCurrent: (value) => deepEqual(working, value.working),
6610
+ apply(from, to, source) {
6611
+ working = cloneImageGraphic(to.working);
6612
+ dirty = !deepEqual(working, image);
6613
+ render();
6614
+ return emitChange(from, source);
6615
+ }
6616
+ });
6617
+ const apply = (next, source, label) => {
6618
+ const previous = captureHistory();
6619
+ working = cloneImageGraphic(next);
6620
+ dirty = !deepEqual(working, image);
6621
+ render();
6622
+ emitChange(previous, source, () => history.record(captureHistory(), label));
6623
+ };
6624
+ const session = {
6625
+ history,
6626
+ graphic: cloneImageGraphic(image),
6627
+ get workingGraphic() {
6628
+ return cloneImageGraphic(working);
6629
+ },
6630
+ get dirty() {
6631
+ return dirty;
6632
+ },
6633
+ get modes() {
6634
+ return modes;
6635
+ },
6636
+ close: () => ctx.commit(snapshot),
6637
+ abort: () => ctx.fail(new TacticalDrawAbortError("session")),
6638
+ setModes(next) {
6639
+ if (ctx.settled) return;
6640
+ modes = normaliseImageModes(next);
6641
+ render();
6642
+ },
6643
+ updateGraphic(updater) {
6644
+ if (ctx.settled) return;
6645
+ const next = normalizeImageGraphic(updater(cloneImageGraphic(working)));
6646
+ if (next.kind !== "image" || next.id !== image.id) throw new TypeError("updateGraphic must preserve image kind and id");
6647
+ validateImageGraphic(next);
6648
+ renderImageForAdapter(adapter, capability, next);
6649
+ apply(next, "programmatic", "Update graphic");
6650
+ },
6651
+ onChange(listener) {
6652
+ if (ctx.settled) return () => {};
6653
+ return changeEmitter.register(listener);
6654
+ },
6655
+ onCommit(listener) {
6656
+ if (ctx.settled) return () => {};
6657
+ return commitEmitter.register(listener);
6658
+ },
6659
+ onSettled(listener) {
6660
+ return settleEmitter.register(listener);
6661
+ }
6662
+ };
6663
+ const transformed = (pixel, info) => {
6664
+ if (!drag) return null;
6665
+ const next = cloneImageGraphic(drag.start);
6666
+ const result = drag.fsm.move(pixel, { constrainRotation: info?.shiftKey });
6667
+ next.position = [...result.points[0]];
6668
+ const delta = boxScaleRotation(drag.kind, result.box, drag.startBox);
6669
+ if (drag.kind === "scale") next.size = {
6670
+ value: Math.max(.1, next.size.value * delta.scale),
6671
+ unit: "meters"
6672
+ };
6673
+ else if (drag.kind === "rotate") next.rotation = normalizeRotation(next.rotation + delta.rotation);
6674
+ else {
6675
+ const anchorPixel = driver.toPixel(next.position) ?? pixel;
6676
+ const snapped = snap?.({
6677
+ coordinate: next.position,
6678
+ pixel: anchorPixel,
6679
+ interaction: "translate",
6680
+ graphicId: image.id,
6681
+ originalEvent: info?.native
6682
+ });
6683
+ if (snapped) next.position = snapped.coordinate;
6684
+ }
6685
+ return next;
6686
+ };
6687
+ const onDown = (pixel, info) => {
6688
+ if (ctx.settled || !box || !modes.includes("transform")) return;
6689
+ const hit = pickBoxHandle(box, pixel, info?.hitTolerance ?? 12);
6690
+ if (!hit) return;
6691
+ drag = {
6692
+ fsm: beginBoxDrag({
6693
+ kind: hit.kind,
6694
+ downPixel: pixel,
6695
+ points: [[...working.position]],
6696
+ projection: {
6697
+ toPixel: (position) => driver.toPixel(position),
6698
+ fromPixel: (coordinate) => driver.fromPixel(coordinate)
6699
+ },
6700
+ box,
6701
+ cornerIndex: hit.kind === "scale" ? hit.index : void 0
6702
+ }),
6703
+ kind: hit.kind,
6704
+ down: [...pixel],
6705
+ start: cloneImageGraphic(working),
6706
+ startBox: box
6707
+ };
6708
+ driver.setDragPanEnabled(false);
6709
+ };
6710
+ const onMove = (pixel, info) => {
6711
+ const next = transformed(pixel, info);
6712
+ if (!next) return;
6713
+ working = next;
6714
+ render();
6715
+ };
6716
+ const onUp = (pixel, info) => {
6717
+ if (!drag) return;
6718
+ const current = drag;
6719
+ const next = transformed(pixel, info);
6720
+ drag = null;
6721
+ shell.suppressNextClickAway();
6722
+ driver.setDragPanEnabled(true);
6723
+ working = cloneImageGraphic(current.start);
6724
+ if (!next) return;
6725
+ if (current.kind === "body" && withinClickSlop(pixel, current.down)) {
6726
+ render();
6727
+ return;
6728
+ }
6729
+ apply(next, "gesture", `${current.kind[0].toUpperCase()}${current.kind.slice(1)}`);
6730
+ };
6731
+ const handle = runEditInteraction({
6732
+ adapter,
6733
+ signal,
6734
+ layers: [previewLayer, handlesLayer],
6735
+ graphicsLayer,
6736
+ previewLayer,
6737
+ handlesLayer,
6738
+ closeOnClickAway,
6739
+ onViewChange: () => render(false),
6740
+ onBeforeTeardown: (settlement) => settleToGraphics(settlement.status === "committed" ? settlement.value.graphic : void 0),
6741
+ onDown,
6742
+ onMove,
6743
+ onUp,
6744
+ ownsGraphic: (id) => id === image.id,
6745
+ close: () => ctx.commit(snapshot),
6746
+ onForeignPick: onClickAwayGraphicsPick,
6747
+ historySettle: () => history.settle(),
6748
+ facadeOnSettled: onSettled,
6749
+ emitSettle: (settlement) => settleFromInteraction(settlement, commitEmitter, settleEmitter),
6750
+ attach(interaction, createdDriver, createdShell) {
6751
+ ctx = interaction;
6752
+ driver = createdDriver;
6753
+ shell = createdShell;
6754
+ render();
6755
+ onSession?.(session);
6756
+ }
6757
+ });
6758
+ return {
6759
+ promise: handle.promise,
6760
+ get settled() {
6761
+ return handle.settled;
6762
+ },
6763
+ get usesGraphicStack() {
6764
+ return usesGraphicStack;
6765
+ },
6766
+ measureId: image.id,
6767
+ graphicKind: "image",
6194
6768
  abort: handle.abort,
6195
6769
  syncHostMembership(present) {
6196
6770
  if (handle.settled || usesGraphicStack === present) return;
@@ -6267,6 +6841,7 @@ var TacticalDraw = class {
6267
6841
  defaultInteractionStyle;
6268
6842
  generateId;
6269
6843
  pointSymbols;
6844
+ images;
6270
6845
  snappingOptions;
6271
6846
  resolveSnap;
6272
6847
  graphicStack = new GraphicStackCoordinator();
@@ -6333,6 +6908,7 @@ var TacticalDraw = class {
6333
6908
  * there is no capability, or the capability doesn't expose `generation`.
6334
6909
  */
6335
6910
  lastSeenPointSymbolGeneration;
6911
+ lastSeenImageGeneration;
6336
6912
  /**
6337
6913
  * Ids of graphics currently carrying a passive selection-highlight outline
6338
6914
  * ({@link setHighlightedGraphics}). Declarative set-replace, no session —
@@ -6353,7 +6929,9 @@ var TacticalDraw = class {
6353
6929
  this.defaultInteractionStyle = options?.interactionStyle;
6354
6930
  this.generateId = options?.generateId ?? (() => `td-${++this.idCounter}`);
6355
6931
  this.pointSymbols = options?.pointSymbols;
6932
+ this.images = options?.images;
6356
6933
  this.lastSeenPointSymbolGeneration = this.pointSymbols?.generation;
6934
+ this.lastSeenImageGeneration = this.images?.generation;
6357
6935
  this.snappingOptions = options?.snapping;
6358
6936
  this.resolveSnap = createSnapResolver(adapter, () => this.lastRenderedMeasures, () => this.snapGeometryFeatures, () => this.snappingOptions);
6359
6937
  const owned = /* @__PURE__ */ new Set();
@@ -6420,6 +6998,17 @@ var TacticalDraw = class {
6420
6998
  revision
6421
6999
  };
6422
7000
  }
7001
+ if (isImageGraphic(graphic)) {
7002
+ if (!this.images) throw new ImageCapabilityRequiredError();
7003
+ const plan = renderImageForAdapter(this.adapter, this.images, graphic);
7004
+ return {
7005
+ id: graphic.id,
7006
+ features: [plan.feature],
7007
+ iconResources: [],
7008
+ ...plan.overlay ? { imageOverlays: [plan.overlay] } : {},
7009
+ revision
7010
+ };
7011
+ }
6423
7012
  const render = renderMeasureForAdapter(this.adapter, graphic, { graphicsStyle: this.graphicsStyle });
6424
7013
  return {
6425
7014
  id: graphic.id,
@@ -6436,13 +7025,19 @@ var TacticalDraw = class {
6436
7025
  invalidateGraphicGroupCache() {
6437
7026
  this.graphicGroupCache = /* @__PURE__ */ new WeakMap();
6438
7027
  }
6439
- /** Submit one complete grouped desired state for the host stack plus overrides. */
6440
- reconcileGraphicsStack(graphics = this.lastRenderedMeasures) {
6441
- const currentGeneration = this.pointSymbols?.generation;
6442
- if (currentGeneration !== this.lastSeenPointSymbolGeneration) {
7028
+ /** Refresh capability-dependent renders before any caller-visible state is mutated. */
7029
+ refreshCapabilityGenerations() {
7030
+ const currentPointSymbolGeneration = this.pointSymbols?.generation;
7031
+ const currentImageGeneration = this.images?.generation;
7032
+ if (currentPointSymbolGeneration !== this.lastSeenPointSymbolGeneration || currentImageGeneration !== this.lastSeenImageGeneration) {
6443
7033
  this.invalidateGraphicGroupCache();
6444
- this.lastSeenPointSymbolGeneration = currentGeneration;
7034
+ this.lastSeenPointSymbolGeneration = currentPointSymbolGeneration;
7035
+ this.lastSeenImageGeneration = currentImageGeneration;
6445
7036
  }
7037
+ }
7038
+ /** Submit one complete grouped desired state for the host stack plus overrides. */
7039
+ reconcileGraphicsStack(graphics = this.lastRenderedMeasures) {
7040
+ this.refreshCapabilityGenerations();
6446
7041
  const groups = this.graphicStack.desiredGroups(graphics, (graphic) => this.renderGraphicGroup(graphic));
6447
7042
  this.adapter.setLayerFeatureGroups(this.graphicsLayer, groups);
6448
7043
  this.snapGeometryFeatures = groups.flatMap((group) => group.features);
@@ -6475,8 +7070,8 @@ var TacticalDraw = class {
6475
7070
  this.renderHighlights();
6476
7071
  const excluded = this.graphicsStackExcludedIds();
6477
7072
  const visible = excluded.size > 0 ? this.lastRenderedMeasures.filter((m) => !excluded.has(m.id)) : this.lastRenderedMeasures;
6478
- const nativeGroundIconScaling = this.adapter.scalesGroundPointSymbolsNatively === true;
6479
- if (!visible.some((g) => graphicRendersFromViewState(g, nativeGroundIconScaling))) return;
7073
+ const nativePointSymbolScaling = this.adapter.scalesGroundPointSymbolsNatively === true;
7074
+ if (!visible.some((g) => graphicRendersFromViewState(g, nativePointSymbolScaling))) return;
6480
7075
  this.reconcileGraphicsStack(visible);
6481
7076
  };
6482
7077
  /**
@@ -6541,6 +7136,8 @@ var TacticalDraw = class {
6541
7136
  if (seen.has(m.id)) throw new Error(`TacticalDraw.render: duplicate graphic id "${m.id}"`);
6542
7137
  seen.add(m.id);
6543
7138
  }
7139
+ this.refreshCapabilityGenerations();
7140
+ for (const graphic of measures) if (isImageGraphic(graphic)) this.renderGraphicGroup(graphic);
6544
7141
  const activeEdit = this.activeEdit;
6545
7142
  const constructingSession = activeEdit ? null : this.activeInteraction.session;
6546
7143
  const constructingGraphic = constructingSession && "workingGraphic" in constructingSession ? constructingSession.workingGraphic : void 0;
@@ -6549,14 +7146,17 @@ var TacticalDraw = class {
6549
7146
  let editedRemoved = false;
6550
7147
  if (editedId !== void 0) {
6551
7148
  const candidate = measures.find((m) => m.id === editedId);
6552
- if (activeEdit && "notifyExternalMeasure" in activeEdit || constructingGraphic !== void 0 && !isPointSymbol(constructingGraphic)) {
6553
- externalEdited = candidate && !isPointSymbol(candidate) ? candidate : void 0;
7149
+ if (activeEdit && "notifyExternalMeasure" in activeEdit || constructingGraphic !== void 0 && !isAnchoredGraphic(constructingGraphic)) {
7150
+ externalEdited = candidate && !isAnchoredGraphic(candidate) ? candidate : void 0;
6554
7151
  editedRemoved = externalEdited === void 0;
6555
- } else editedRemoved = candidate === void 0 || !isPointSymbol(candidate);
7152
+ } else {
7153
+ const expectedKind = activeEdit && "graphicKind" in activeEdit ? activeEdit.graphicKind : constructingGraphic?.kind;
7154
+ editedRemoved = candidate === void 0 || candidate.kind !== expectedKind;
7155
+ }
6556
7156
  }
6557
7157
  this.lastRenderedMeasures = measures.slice();
6558
7158
  this.graphicStack.acknowledgeHostRender(measures);
6559
- if (activeEdit && "syncHostMembership" in activeEdit && measures.some((graphic) => graphic.id === activeEdit.measureId && isPointSymbol(graphic))) activeEdit.syncHostMembership(true);
7159
+ if (activeEdit && "syncHostMembership" in activeEdit && measures.some((graphic) => graphic.id === activeEdit.measureId && graphic.kind === activeEdit.graphicKind)) activeEdit.syncHostMembership(true);
6560
7160
  (this.activeTransform ?? this.activeTransformSessionRef)?.syncHostGraphics(measures);
6561
7161
  const excluded = this.graphicsStackExcludedIds();
6562
7162
  const visible = excluded.size > 0 ? measures.filter((m) => !excluded.has(m.id)) : measures;
@@ -6645,6 +7245,10 @@ var TacticalDraw = class {
6645
7245
  if (!this.pointSymbols) return null;
6646
7246
  return pointSymbolFootprint(graphic, this.pointSymbols.render(graphic), this.adapter)?.box ?? null;
6647
7247
  }
7248
+ if (isImageGraphic(graphic)) {
7249
+ if (!this.images) return null;
7250
+ return imageFootprint(graphic, renderImageForAdapter(this.adapter, this.images, graphic).render, this.adapter)?.box ?? null;
7251
+ }
6648
7252
  const render = renderMeasureForAdapter(this.adapter, graphic, { graphicsStyle: this.graphicsStyle });
6649
7253
  if (graphic.kind === "text") return fitTextFootprintFromFeatures(render.features, (lonLat) => this.adapter.getPixelFromCoordinate(lonLat), {
6650
7254
  resolution: this.adapter.getResolution(),
@@ -6756,6 +7360,21 @@ var TacticalDraw = class {
6756
7360
  }
6757
7361
  draw(draft, options) {
6758
7362
  this.assertAlive();
7363
+ if (draft.kind === "image") {
7364
+ if (!this.images) throw new ImageCapabilityRequiredError();
7365
+ const preempt = this.guardAndPreempt();
7366
+ if (preempt) return preempt;
7367
+ return this.runWithSlot((onSettled) => runImageDraw({
7368
+ adapter: this.adapter,
7369
+ capability: this.images,
7370
+ draft,
7371
+ previewLayer: this.previewLayer,
7372
+ generateId: this.generateId,
7373
+ signal: options?.signal,
7374
+ onSettled,
7375
+ snap: this.resolveSnap
7376
+ }), null);
7377
+ }
6759
7378
  if (draft.kind === "point-symbol") {
6760
7379
  if (!this.pointSymbols) throw new PointSymbolCapabilityRequiredError();
6761
7380
  const preempt = this.guardAndPreempt();
@@ -6827,6 +7446,43 @@ var TacticalDraw = class {
6827
7446
  }
6828
7447
  edit(measure, options) {
6829
7448
  this.assertAlive();
7449
+ if (isImageGraphic(measure)) {
7450
+ normaliseImageModes(options?.modes);
7451
+ if (!this.images) throw new ImageCapabilityRequiredError();
7452
+ const preempt = this.guardAndPreempt();
7453
+ if (preempt) return preempt;
7454
+ const wasOnGraphicsLayer = this.lastRenderedMeasures.some((g) => g.id === measure.id);
7455
+ const handleIdPrefix = `__td_edit_${++this.editCounter}__`;
7456
+ return this.runWithSlot((onSettled) => runImageEdit({
7457
+ adapter: this.adapter,
7458
+ capability: this.images,
7459
+ image: measure,
7460
+ graphicsLayer: this.graphicsLayer,
7461
+ previewLayer: this.previewLayer,
7462
+ handlesLayer: this.handlesLayer,
7463
+ signal: options?.signal,
7464
+ closeOnClickAway: options?.closeOnClickAway,
7465
+ modes: options?.modes,
7466
+ interactionStyle: this.resolveInteractionStyle(options?.interactionStyle),
7467
+ onSession: this.trackSession(options?.onSession),
7468
+ handleIdPrefix,
7469
+ settleToGraphics: (settled) => this.settleWorkingGraphics([{
7470
+ id: measure.id,
7471
+ committed: settled
7472
+ }]),
7473
+ publishWorkingGraphic: (group) => this.publishWorkingGraphics([group]),
7474
+ wasOnGraphicsLayer,
7475
+ onSettled,
7476
+ onClickAwayGraphicsPick: (event) => this.dispatchHostPick(this.graphicsLayer, event),
7477
+ snap: this.resolveSnap
7478
+ }), (handle) => {
7479
+ handle.syncHostMembership(this.lastRenderedMeasures.some((graphic) => graphic.id === handle.measureId && isImageGraphic(graphic)));
7480
+ this.activeEdit = handle;
7481
+ return () => {
7482
+ if (this.activeEdit === handle) this.activeEdit = null;
7483
+ };
7484
+ });
7485
+ }
6830
7486
  if (isPointSymbol(measure)) {
6831
7487
  normalisePointEditModes(options?.modes);
6832
7488
  if (!this.pointSymbols) throw new PointSymbolCapabilityRequiredError();
@@ -6923,6 +7579,7 @@ var TacticalDraw = class {
6923
7579
  seenIds.add(m.id);
6924
7580
  }
6925
7581
  if (measures.some(isPointSymbol) && !this.pointSymbols) throw new PointSymbolCapabilityRequiredError();
7582
+ if (measures.some(isImageGraphic) && !this.images) throw new ImageCapabilityRequiredError();
6926
7583
  const preempt = this.guardAndPreempt();
6927
7584
  if (preempt) return preempt;
6928
7585
  const isOnGraphicsLayer = (id) => this.lastRenderedMeasures.some((m) => m.id === id);
@@ -6937,6 +7594,7 @@ var TacticalDraw = class {
6937
7594
  return this.runWithSlot((onSettled) => runGroupTransform({
6938
7595
  adapter: this.adapter,
6939
7596
  capability: this.pointSymbols,
7597
+ imageCapability: this.images,
6940
7598
  graphics: measures,
6941
7599
  graphicsLayer: this.graphicsLayer,
6942
7600
  previewLayer: this.previewLayer,
@@ -7311,8 +7969,10 @@ var TacticalDraw = class {
7311
7969
  if (this.destroyed) throw new TacticalDrawDestroyedError();
7312
7970
  }
7313
7971
  };
7314
- function graphicRendersFromViewState(graphic, nativeGroundIconScaling) {
7315
- return isPointSymbol(graphic) ? graphic.size.unit === "meters" && !nativeGroundIconScaling : measureRendersFromViewState(graphic);
7972
+ function graphicRendersFromViewState(graphic, nativePointSymbolScaling) {
7973
+ if (isPointSymbol(graphic)) return graphic.size.unit === "meters" && !nativePointSymbolScaling;
7974
+ if (isImageGraphic(graphic)) return false;
7975
+ return measureRendersFromViewState(graphic);
7316
7976
  }
7317
7977
  function normalisePointEditModes(modes) {
7318
7978
  for (const mode of modes ?? ["transform"]) if (mode !== "transform" && mode !== "delete") throw new TypeError(`Point-symbol editing does not support mode "${mode}"`);
@@ -7628,4 +8288,4 @@ function nearestWorldCopyPosition(position, refLng) {
7628
8288
  return [nearestWorldCopyLng(position[0], refLng), ...position.slice(1)];
7629
8289
  }
7630
8290
  //#endregion
7631
- export { BaseMapAdapter, DEFAULT_LABEL_SIZE_PIXELS, DEFAULT_TEXT_SIZE_MAX_PIXELS, DEFAULT_TEXT_SIZE_MIN_PIXELS, HATCH_PATTERNS, PointSymbolCapabilityRequiredError, PointerCallbackHub, TEXT_HALO_COLOR, TOUCH_HIT_TOLERANCE_PX, TacticalDraw, TacticalDrawAbortError, TacticalDrawDestroyedError, bindAbortable, clonePointSymbol, coerceHandleStyle, combineWithHostSignal, effectivePointSymbolPixelSize, evaluatePickCandidates, fillPatternImageDimension, fillPatternImageId, getSizeAnchor, hitTestFeature, hitTestIconFeature, ignoreAbort, isPointSymbol, isTacticalDrawAbortError, makeFillPatternImage, mergeNativeAndCachedPickFeatures, nearestWorldCopyLng, nearestWorldCopyPosition, pickHitTolerance, pickPointerType, pointSymbolFootprint, renderOrderToVisualOrder, resizePointSymbolSize, resolveGroundTextSizePixels, resolvePickPresentation, resolveTextHaloWidth, resolveTextSizePixels, tryControlMeasureIdFromFeature };
8291
+ export { BaseMapAdapter, DEFAULT_LABEL_SIZE_PIXELS, DEFAULT_TEXT_SIZE_MAX_PIXELS, DEFAULT_TEXT_SIZE_MIN_PIXELS, HATCH_PATTERNS, ImageCapabilityRequiredError, PointSymbolCapabilityRequiredError, PointerCallbackHub, TEXT_HALO_COLOR, TOUCH_HIT_TOLERANCE_PX, TacticalDraw, TacticalDrawAbortError, TacticalDrawDestroyedError, bindAbortable, cloneImageGraphic, clonePointSymbol, coerceHandleStyle, combineWithHostSignal, effectivePointSymbolPixelSize, evaluatePickCandidates, fillPatternImageDimension, fillPatternImageId, getSizeAnchor, hitTestFeature, hitTestIconFeature, ignoreAbort, imageFootprint, imageOpacity, isAnchoredGraphic, isImageGraphic, isPointSymbol, isTacticalDrawAbortError, makeFillPatternImage, mergeNativeAndCachedPickFeatures, nearestWorldCopyLng, nearestWorldCopyPosition, normalizeImageGraphic, pickHitTolerance, pickPointerType, pointSymbolFootprint, renderOrderToVisualOrder, resizePointSymbolSize, resolveGroundTextSizePixels, resolvePickPresentation, resolveTextHaloWidth, resolveTextSizePixels, tryControlMeasureIdFromFeature, validateImageGraphic };