@orbat-mapper/tactical-draw 0.2.0-alpha.27 → 0.2.0-alpha.28

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
@@ -1,4 +1,4 @@
1
- import { AmplifierPlacement, AmplifierPlacements, ControlMeasure, ControlMeasureKind, ControlMeasureRender, ControlMeasureStyle, TextAmplifiers } from "@orbat-mapper/control-measures";
1
+ import { AmplifierPlacement, AmplifierPlacements, ControlMeasure, ControlMeasureKind, ControlMeasureRender, ControlMeasureStyle, FillPattern, TextAmplifiers } from "@orbat-mapper/control-measures";
2
2
  import { Feature, Position } from "geojson";
3
3
 
4
4
  //#region src/gestures/types.d.ts
@@ -40,6 +40,51 @@ interface EditPointerDriver {
40
40
  dispose(): void;
41
41
  }
42
42
  //#endregion
43
+ //#region src/fill-pattern.d.ts
44
+ /**
45
+ * Shared hatch fill-pattern tiles for area control-measure fills (ADR-0035
46
+ * `FillPattern`, excluding `"solid"` which every adapter already renders as a
47
+ * flat color). Both the MapLibre adapter (raster `addImage` pattern) and the
48
+ * OpenLayers adapter (canvas `Pattern` fill) need the *same* diagonal-hachure
49
+ * texture, so it is rasterized once here in pure math — no `HTMLCanvasElement`
50
+ * — so it works in adapter code and in jsdom/node tests alike.
51
+ */
52
+ type HatchPattern = Exclude<FillPattern, "solid">;
53
+ /**
54
+ * Every non-solid `FillPattern` as a runtime list — the value-level companion
55
+ * to {@link HatchPattern}, so adapters can test membership and build filter
56
+ * expressions without re-spelling the pattern vocabulary.
57
+ */
58
+ declare const HATCH_PATTERNS: readonly HatchPattern[];
59
+ /**
60
+ * Stable id for a rasterized tile, keyed by pattern and color. Adapters use
61
+ * this as the image-registry key (MapLibre `addImage` id, OpenLayers pattern
62
+ * cache key) so the same color+pattern never gets rasterized twice. Color is
63
+ * lowercased so `"#FF0000"` and `"#ff0000"` share one texture.
64
+ */
65
+ declare function fillPatternImageId(color: string, pattern: HatchPattern): string;
66
+ /**
67
+ * Tile edge length in device pixels for a given `pixelRatio`. Must be a power
68
+ * of two — MapLibre requires POT dimensions for seamless WebGL texture wrap —
69
+ * and scales linearly with `pixelRatio` for the ratios that matter in
70
+ * practice (1x/2x displays: 32 -> 64, both already POT). Non-POT products
71
+ * (e.g. a 3x ratio, 32*3=96) round up to the next POT rather than losing the
72
+ * power-of-two guarantee.
73
+ */
74
+ declare function fillPatternImageDimension(pixelRatio: number): number;
75
+ /**
76
+ * Rasterize one seamless hatch tile as a straight RGBA pixel buffer — no
77
+ * canvas involved, so this runs identically in a browser adapter and in
78
+ * jsdom/node tests. Diagonal lines are snapped to slope ±1 (45°) so the
79
+ * mod-based coverage math in {@link lineCoverage} tiles exactly; `"cross"`
80
+ * unions both diagonals via `Math.max` coverage.
81
+ */
82
+ declare function makeFillPatternImage(color: string, pattern: HatchPattern, pixelRatio?: number): {
83
+ width: number;
84
+ height: number;
85
+ data: Uint8ClampedArray;
86
+ };
87
+ //#endregion
43
88
  //#region src/map-adapter.d.ts
44
89
  type PixelCoordinate = [number, number];
45
90
  type MapCursor = "" | "default" | "crosshair" | "grab" | "grabbing" | "pointer";
@@ -102,6 +147,14 @@ interface HandleStyle {
102
147
  strokeWidth?: number;
103
148
  strokeDash?: readonly number[];
104
149
  fillColor?: string;
150
+ /**
151
+ * How `fillColor` paints a filled part's interior. Absent or `"solid"` is
152
+ * today's flat fill; `"hachure"`/`"cross"` request the shared hatch texture
153
+ * ({@link makeFillPatternImage}). Alpha rides in `fillColor` — there is no
154
+ * separate opacity field. Adapters that cannot rasterize a pattern degrade
155
+ * to solid. Per-feature only: layer-level `StyleOptions` has no equivalent.
156
+ */
157
+ fillPattern?: "solid" | HatchPattern;
105
158
  pointRadius?: number;
106
159
  }
107
160
  type LayerId = string;
@@ -1910,4 +1963,4 @@ declare function nearestWorldCopyLng(lng: number, refLng: number): number;
1910
1963
  /** `nearestWorldCopyLng` applied to a lon/lat position. */
1911
1964
  declare function nearestWorldCopyPosition(position: Position, refLng: number): Position;
1912
1965
  //#endregion
1913
- export { BaseMapAdapter, type CombinedAbort, DEFAULT_LABEL_SIZE_PIXELS, DEFAULT_TEXT_SIZE_MAX_PIXELS, DEFAULT_TEXT_SIZE_MIN_PIXELS, type DrawMeasureDraft, type DrawOptions, type DrawPointSymbolDraft, type DrawSession, type EditChangeEvent, type EditManyOptions, type EditMode, type EditOptions, type EditPointerDriver, type EditSession, type FeatureOps, type Graphic, type GraphicEditChangeEvent, type GraphicEditSession, type GraphicGeometrySnappingOptions, type GraphicRender, type GraphicSnapshot, type GuideStyle, type HandleStyle, type IconResource, type InteractionHit, type InteractionStyle, type LayerId, type MapAdapter, type MapCursor, type MapEvent, type MapEventHandler, type NativeEventEntry, type PickEvent, type PickHandler, type PickOptions, type PixelCoordinate, type PointSymbol, type PointSymbolAnchor, type PointSymbolCapability, PointSymbolCapabilityRequiredError, type PointSymbolColors, type PointSymbolFootprint, type PointSymbolGraphicModifiers, type PointSymbolRender, type PointSymbolSize, type PointSymbolStyle, type PointerCallback, PointerCallbackHub, type PointerEventInfo, type SessionChangeSource, type SessionHistory, type SessionHistoryState, type SettleReason, type SizeAnchor, type SnapCandidate, type SnapCandidateProvider, type SnapCandidateRequest, type SnapInteraction, type SnapResult, type SnappingOptions, type StyleOptions, TOUCH_HIT_TOLERANCE_PX, TacticalDraw, TacticalDrawAbortError, type TacticalDrawAbortReason, TacticalDrawDestroyedError, type TacticalDrawLayerOptions, type TacticalDrawOptions, type TextStyleOptions, type ToPixel, type TransformBox, type TransformChangeEvent, type TransformSession, bindAbortable, clonePointSymbol, coerceHandleStyle, combineWithHostSignal, effectivePointSymbolPixelSize, getSizeAnchor, hitTestFeature, hitTestIconFeature, ignoreAbort, isPointSymbol, isTacticalDrawAbortError, nearestWorldCopyLng, nearestWorldCopyPosition, pickHitTolerance, pointSymbolFootprint, resizePointSymbolSize, resolveGroundTextSizePixels, tryControlMeasureIdFromFeature };
1966
+ export { BaseMapAdapter, type CombinedAbort, DEFAULT_LABEL_SIZE_PIXELS, DEFAULT_TEXT_SIZE_MAX_PIXELS, DEFAULT_TEXT_SIZE_MIN_PIXELS, type DrawMeasureDraft, type DrawOptions, type DrawPointSymbolDraft, type DrawSession, type EditChangeEvent, type EditManyOptions, type EditMode, type EditOptions, type EditPointerDriver, type EditSession, type FeatureOps, type Graphic, type GraphicEditChangeEvent, type GraphicEditSession, type GraphicGeometrySnappingOptions, type GraphicRender, type GraphicSnapshot, type GuideStyle, HATCH_PATTERNS, type HandleStyle, type HatchPattern, type IconResource, type InteractionHit, type InteractionStyle, type LayerId, type MapAdapter, type MapCursor, type MapEvent, type MapEventHandler, type NativeEventEntry, type PickEvent, type PickHandler, type PickOptions, type PixelCoordinate, type PointSymbol, type PointSymbolAnchor, type PointSymbolCapability, PointSymbolCapabilityRequiredError, type PointSymbolColors, type PointSymbolFootprint, type PointSymbolGraphicModifiers, type PointSymbolRender, type PointSymbolSize, type PointSymbolStyle, type PointerCallback, PointerCallbackHub, type PointerEventInfo, type SessionChangeSource, type SessionHistory, type SessionHistoryState, type SettleReason, type SizeAnchor, type SnapCandidate, type SnapCandidateProvider, type SnapCandidateRequest, type SnapInteraction, type SnapResult, type SnappingOptions, type StyleOptions, TOUCH_HIT_TOLERANCE_PX, TacticalDraw, TacticalDrawAbortError, type TacticalDrawAbortReason, TacticalDrawDestroyedError, type TacticalDrawLayerOptions, type TacticalDrawOptions, type TextStyleOptions, type ToPixel, type TransformBox, type TransformChangeEvent, type TransformSession, bindAbortable, clonePointSymbol, coerceHandleStyle, combineWithHostSignal, effectivePointSymbolPixelSize, fillPatternImageDimension, fillPatternImageId, getSizeAnchor, hitTestFeature, hitTestIconFeature, ignoreAbort, isPointSymbol, isTacticalDrawAbortError, makeFillPatternImage, nearestWorldCopyLng, nearestWorldCopyPosition, pickHitTolerance, pointSymbolFootprint, resizePointSymbolSize, resolveGroundTextSizePixels, tryControlMeasureIdFromFeature };
package/dist/index.mjs CHANGED
@@ -6093,6 +6093,141 @@ function resolveSlot(adapter, supplied, owned) {
6093
6093
  return id;
6094
6094
  }
6095
6095
  //#endregion
6096
+ //#region src/fill-pattern.ts
6097
+ /**
6098
+ * Every non-solid `FillPattern` as a runtime list — the value-level companion
6099
+ * to {@link HatchPattern}, so adapters can test membership and build filter
6100
+ * expressions without re-spelling the pattern vocabulary.
6101
+ */
6102
+ const HATCH_PATTERNS = ["hachure", "cross"];
6103
+ /** Tile edge length, CSS px, before `pixelRatio` scaling. Kept a power of two. */
6104
+ const BASE_TILE_SIZE = 32;
6105
+ /** Line spacing as a fraction of the tile edge — 4 repeats per tile. */
6106
+ const SPACING_DIVISOR = 4;
6107
+ /**
6108
+ * Stable id for a rasterized tile, keyed by pattern and color. Adapters use
6109
+ * this as the image-registry key (MapLibre `addImage` id, OpenLayers pattern
6110
+ * cache key) so the same color+pattern never gets rasterized twice. Color is
6111
+ * lowercased so `"#FF0000"` and `"#ff0000"` share one texture.
6112
+ */
6113
+ function fillPatternImageId(color, pattern) {
6114
+ return `td-hatch-${pattern}-${color.trim().toLowerCase()}`;
6115
+ }
6116
+ /**
6117
+ * Tile edge length in device pixels for a given `pixelRatio`. Must be a power
6118
+ * of two — MapLibre requires POT dimensions for seamless WebGL texture wrap —
6119
+ * and scales linearly with `pixelRatio` for the ratios that matter in
6120
+ * practice (1x/2x displays: 32 -> 64, both already POT). Non-POT products
6121
+ * (e.g. a 3x ratio, 32*3=96) round up to the next POT rather than losing the
6122
+ * power-of-two guarantee.
6123
+ */
6124
+ function fillPatternImageDimension(pixelRatio) {
6125
+ const target = BASE_TILE_SIZE * Math.max(1, Math.round(pixelRatio));
6126
+ return 2 ** Math.ceil(Math.log2(target));
6127
+ }
6128
+ /**
6129
+ * Parse a hex (`#rgb`, `#rrggbb`, `#rrggbbaa`) or `rgb()`/`rgba()` color
6130
+ * string into normalized channels, alpha in `[0, 1]`. Unparseable input falls
6131
+ * back to opaque black rather than throwing, since a mis-themed fill should
6132
+ * still render *something*.
6133
+ */
6134
+ function parseColor(color) {
6135
+ const s = color.trim();
6136
+ if (s.startsWith("#")) {
6137
+ const hex = s.slice(1);
6138
+ if (hex.length === 3) return {
6139
+ r: parseInt(hex[0] + hex[0], 16),
6140
+ g: parseInt(hex[1] + hex[1], 16),
6141
+ b: parseInt(hex[2] + hex[2], 16),
6142
+ a: 1
6143
+ };
6144
+ if (hex.length === 6) return {
6145
+ r: parseInt(hex.slice(0, 2), 16),
6146
+ g: parseInt(hex.slice(2, 4), 16),
6147
+ b: parseInt(hex.slice(4, 6), 16),
6148
+ a: 1
6149
+ };
6150
+ if (hex.length === 8) return {
6151
+ r: parseInt(hex.slice(0, 2), 16),
6152
+ g: parseInt(hex.slice(2, 4), 16),
6153
+ b: parseInt(hex.slice(4, 6), 16),
6154
+ a: parseInt(hex.slice(6, 8), 16) / 255
6155
+ };
6156
+ }
6157
+ const fn = s.match(/^rgba?\(([^)]+)\)$/i);
6158
+ if (fn) {
6159
+ const parts = fn[1].split(",").map((p) => p.trim());
6160
+ const r = Number.parseFloat(parts[0] ?? "0");
6161
+ const g = Number.parseFloat(parts[1] ?? "0");
6162
+ const b = Number.parseFloat(parts[2] ?? "0");
6163
+ const a = parts.length > 3 ? Number.parseFloat(parts[3]) : 1;
6164
+ return {
6165
+ r,
6166
+ g,
6167
+ b,
6168
+ a: Number.isFinite(a) ? a : 1
6169
+ };
6170
+ }
6171
+ return {
6172
+ r: 0,
6173
+ g: 0,
6174
+ b: 0,
6175
+ a: 1
6176
+ };
6177
+ }
6178
+ /** `v mod m`, folded into `[-m/2, m/2)`. Used to find distance to the nearest line in a periodic family. */
6179
+ function centeredMod(v, m) {
6180
+ const wrapped = (v % m + m) % m;
6181
+ return wrapped >= m / 2 ? wrapped - m : wrapped;
6182
+ }
6183
+ const SQRT2 = Math.SQRT2;
6184
+ /**
6185
+ * Coverage in `[0, 1]` of one diagonal line family (slope +1 or -1, both
6186
+ * period `spacing`) at pixel center `(x, y)`, antialiased over a ~1 device-px
6187
+ * band. `axis` selects `y - x` (the "/" hachure) or `y + x` (its mirror, added
6188
+ * for "cross"). Because `spacing` divides the tile dimension evenly, shifting
6189
+ * `x` or `y` by a whole tile is a whole number of `spacing` periods, so the
6190
+ * mod-distance — and therefore the coverage — is identical at the tile edges
6191
+ * as at their wrapped continuation. That periodicity is what makes the tile
6192
+ * seamless.
6193
+ */
6194
+ function lineCoverage(x, y, spacing, lineWidth, axis) {
6195
+ const t = axis === "/" ? y - x : y + x;
6196
+ const perpDist = Math.abs(centeredMod(t, spacing)) / SQRT2;
6197
+ const halfWidth = lineWidth / 2;
6198
+ return Math.min(1, Math.max(0, halfWidth + .5 - perpDist));
6199
+ }
6200
+ /**
6201
+ * Rasterize one seamless hatch tile as a straight RGBA pixel buffer — no
6202
+ * canvas involved, so this runs identically in a browser adapter and in
6203
+ * jsdom/node tests. Diagonal lines are snapped to slope ±1 (45°) so the
6204
+ * mod-based coverage math in {@link lineCoverage} tiles exactly; `"cross"`
6205
+ * unions both diagonals via `Math.max` coverage.
6206
+ */
6207
+ function makeFillPatternImage(color, pattern, pixelRatio = 1) {
6208
+ const size = fillPatternImageDimension(pixelRatio);
6209
+ const spacing = size / SPACING_DIVISOR;
6210
+ const lineWidth = Math.max(1, Math.round(pixelRatio));
6211
+ const { r, g, b, a } = parseColor(color);
6212
+ const data = new Uint8ClampedArray(size * size * 4);
6213
+ for (let y = 0; y < size; y++) for (let x = 0; x < size; x++) {
6214
+ const cx = x + .5;
6215
+ const cy = y + .5;
6216
+ let coverage = lineCoverage(cx, cy, spacing, lineWidth, "/");
6217
+ if (pattern === "cross") coverage = Math.max(coverage, lineCoverage(cx, cy, spacing, lineWidth, "\\"));
6218
+ const i = (y * size + x) * 4;
6219
+ data[i] = r;
6220
+ data[i + 1] = g;
6221
+ data[i + 2] = b;
6222
+ data[i + 3] = Math.round(255 * a * coverage);
6223
+ }
6224
+ return {
6225
+ width: size,
6226
+ height: size,
6227
+ data
6228
+ };
6229
+ }
6230
+ //#endregion
6096
6231
  //#region src/world-wrap.ts
6097
6232
  /**
6098
6233
  * Shift `lng` by whole world widths (360°) onto the copy nearest `refLng`.
@@ -6111,4 +6246,4 @@ function nearestWorldCopyPosition(position, refLng) {
6111
6246
  return [nearestWorldCopyLng(position[0], refLng), ...position.slice(1)];
6112
6247
  }
6113
6248
  //#endregion
6114
- export { BaseMapAdapter, DEFAULT_LABEL_SIZE_PIXELS, DEFAULT_TEXT_SIZE_MAX_PIXELS, DEFAULT_TEXT_SIZE_MIN_PIXELS, PointSymbolCapabilityRequiredError, PointerCallbackHub, TOUCH_HIT_TOLERANCE_PX, TacticalDraw, TacticalDrawAbortError, TacticalDrawDestroyedError, bindAbortable, clonePointSymbol, coerceHandleStyle, combineWithHostSignal, effectivePointSymbolPixelSize, getSizeAnchor, hitTestFeature, hitTestIconFeature, ignoreAbort, isPointSymbol, isTacticalDrawAbortError, nearestWorldCopyLng, nearestWorldCopyPosition, pickHitTolerance, pointSymbolFootprint, resizePointSymbolSize, resolveGroundTextSizePixels, tryControlMeasureIdFromFeature };
6249
+ export { BaseMapAdapter, DEFAULT_LABEL_SIZE_PIXELS, DEFAULT_TEXT_SIZE_MAX_PIXELS, DEFAULT_TEXT_SIZE_MIN_PIXELS, HATCH_PATTERNS, PointSymbolCapabilityRequiredError, PointerCallbackHub, TOUCH_HIT_TOLERANCE_PX, TacticalDraw, TacticalDrawAbortError, TacticalDrawDestroyedError, bindAbortable, clonePointSymbol, coerceHandleStyle, combineWithHostSignal, effectivePointSymbolPixelSize, fillPatternImageDimension, fillPatternImageId, getSizeAnchor, hitTestFeature, hitTestIconFeature, ignoreAbort, isPointSymbol, isTacticalDrawAbortError, makeFillPatternImage, nearestWorldCopyLng, nearestWorldCopyPosition, pickHitTolerance, pointSymbolFootprint, resizePointSymbolSize, resolveGroundTextSizePixels, tryControlMeasureIdFromFeature };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbat-mapper/tactical-draw",
3
- "version": "0.2.0-alpha.27",
3
+ "version": "0.2.0-alpha.28",
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",
@@ -38,7 +38,7 @@
38
38
  "access": "public"
39
39
  },
40
40
  "dependencies": {
41
- "@orbat-mapper/control-measures": "^0.2.0-alpha.16"
41
+ "@orbat-mapper/control-measures": "^0.2.0-alpha.20"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@arethetypeswrong/core": "^0.18.3",