@orbat-mapper/tactical-draw 0.4.0 → 0.4.2

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 { C as EditPointerDriver, S as makeFillPatternImage, T as PointerEventInfo, _ as HatchPattern, a as LayerId, b as fillPatternImageId, c as MapEvent, d as PickHandler, f as PickOptions, g as HATCH_PATTERNS, h as TextStyleOptions, i as ImageOverlayResource, l as MapEventHandler, m as StyleOptions, n as HandleStyle, o as MapAdapter, p as PixelCoordinate, r as IconResource, s as MapCursor, t as FeatureGroup, u as PickEvent, v as MINE_PATTERN_TILE_SIZE, w as PointerCallback, x as isMinePattern, y as fillPatternImageDimension } from "./map-adapter-BkDIEriM.mjs";
1
+ import { C as EditPointerDriver, S as makeFillPatternImage, T as PointerEventInfo, _ as HatchPattern, a as LayerId, b as fillPatternImageId, c as MapEvent, d as PickHandler, f as PickOptions, g as HATCH_PATTERNS, h as TextStyleOptions, i as ImageOverlayResource, l as MapEventHandler, m as StyleOptions, n as HandleStyle, o as MapAdapter, p as PixelCoordinate, r as IconResource, s as MapCursor, t as FeatureGroup, u as PickEvent, v as MINE_PATTERN_TILE_SIZE, w as PointerCallback, x as isMinePattern, y as fillPatternImageDimension } from "./map-adapter-BWvKku2P.mjs";
2
2
  import { AmplifierPlacement, AmplifierPlacements, ControlMeasure, ControlMeasureKind, ControlMeasureRender, ControlMeasureStyle, TextAmplifiers } from "@orbat-mapper/control-measures";
3
3
  import { Feature, Position } from "geojson";
4
4
 
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { applyBoxTransformOptions, canonicalTextAmplifierKey, cloneControlMeasure, controlMeasureIdFromFeature, foldsBoxTransformOptions, freezeOrientationOptions, getControlMeasureMetadata, getDefaultOptions, renderControlMeasure, resolveAmplifierPlacement, resolveStyleHints, roundToFixed } from "@orbat-mapper/control-measures";
1
+ import { FILL_PATTERN_DEFINITIONS, NON_SOLID_FILL_PATTERNS, 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";
@@ -1275,25 +1275,6 @@ function bakePixelSizeToGround(measure, adapter) {
1275
1275
  };
1276
1276
  }
1277
1277
  /**
1278
- * Stamp the adapter's current `metersPerPixel` onto a measure that sizes itself
1279
- * in pixels, so the generator resolves pixel options (`radiusPixels`,
1280
- * `toothSizePixels`, `toothHeightPixels`) against the live map zoom. Returns the
1281
- * measure unchanged when the adapter has no usable resolution or the
1282
- * kind/options don't opt into pixel sizing.
1283
- */
1284
- function withAdapterMeasureOptions(measure, adapter) {
1285
- const mpp = adapter.getResolution();
1286
- if (mpp === void 0 || mpp <= 0) return measure;
1287
- if (!measureUsesAdapterResolution(measure)) return measure;
1288
- return {
1289
- ...measure,
1290
- options: {
1291
- ...measure.options,
1292
- metersPerPixel: mpp
1293
- }
1294
- };
1295
- }
1296
- /**
1297
1278
  * Stamp the draw-time default label size, in its screen-anchored
1298
1279
  * (`labelSizePixels`) form, onto a `capturesLabelSize` measure that carries no
1299
1280
  * label size of its own (ADR-0028). The pixel form keeps the in-flight
@@ -1316,21 +1297,39 @@ function withCommittedAdapterMeasureOptions(measure) {
1316
1297
  };
1317
1298
  }
1318
1299
  /**
1319
- * Render a measure with the adapter's resolution injected. The single seam for
1300
+ * Render a measure with the adapter's live scale supplied through core's
1301
+ * renderer-owned context. The single seam for
1320
1302
  * "turn a measure into features against the live map" — every TacticalDraw
1321
1303
  * layer write (graphics reconcile, draw preview, edit preview, commit snapshot)
1322
- * routes through here so pixel sizing is resolved identically everywhere and no
1323
- * call site can forget the injection. Composes [[withAdapterMeasureOptions]]
1324
- * (pixel size → `metersPerPixel`) with [[withCommittedAdapterMeasureOptions]]
1325
- * (label size defaults for `capturesLabelSize` kinds), so draw/edit previews
1326
- * get the same label clearance a commit would bake in — the input `measure`
1327
- * is never mutated, and callers that need the persisted/working measure to
1328
- * stay free of these render-only options must keep using that separately
1329
- * (draw/edit commit paths call [[withCommittedAdapterMeasureOptions]]
1330
- * directly to produce the value they persist).
1304
+ * routes through here so pixel sizing is resolved identically everywhere. The
1305
+ * adapter resolution is Web Mercator construction scale; converting it to true
1306
+ * ground at the Graphic midpoint lets core's compatibility boundary round-trip
1307
+ * to the same construction scale. Default label capture remains a derived copy
1308
+ * for previews, while the input Graphic is never augmented with live scale.
1331
1309
  */
1332
1310
  function renderMeasureForAdapter(adapter, measure, opts) {
1333
- return renderControlMeasure(withAdapterMeasureOptions(withCommittedAdapterMeasureOptions(measure), adapter), opts);
1311
+ const withLabelSize = withCommittedAdapterMeasureOptions(measure);
1312
+ const resolution = adapter.getResolution();
1313
+ const midpointLatitude = geographicMidpointLatitude(measure.controlPoints);
1314
+ const groundMetersPerCssPixel = resolution !== void 0 && resolution > 0 && midpointLatitude !== void 0 ? resolution * Math.cos(midpointLatitude * Math.PI / 180) : void 0;
1315
+ return renderControlMeasure(withLabelSize, {
1316
+ ...opts,
1317
+ context: {
1318
+ ...opts?.context,
1319
+ ...groundMetersPerCssPixel !== void 0 ? { groundMetersPerCssPixel } : {}
1320
+ }
1321
+ });
1322
+ }
1323
+ /** Geographic bounding-box midpoint latitude used by core's Mercator compatibility boundary. */
1324
+ function geographicMidpointLatitude(points) {
1325
+ if (points.length === 0) return void 0;
1326
+ let min = Infinity;
1327
+ let max = -Infinity;
1328
+ for (const point of points) {
1329
+ min = Math.min(min, point[1]);
1330
+ max = Math.max(max, point[1]);
1331
+ }
1332
+ return (min + max) / 2;
1334
1333
  }
1335
1334
  //#endregion
1336
1335
  //#region src/tactical-draw/run-interaction.ts
@@ -8192,38 +8191,15 @@ function resolveSlot(adapter, supplied, owned) {
8192
8191
  * to {@link HatchPattern}, so adapters can test membership and build filter
8193
8192
  * expressions without re-spelling the pattern vocabulary.
8194
8193
  */
8195
- const HATCH_PATTERNS = [
8196
- "hatch",
8197
- "reverse-hatch",
8198
- "cross-hatch",
8199
- "horizontal",
8200
- "vertical",
8201
- "dots",
8202
- "mine-unspecified",
8203
- "mine-antipersonnel",
8204
- "mine-antipersonnel-directional",
8205
- "mine-antitank",
8206
- "mine-antitank-antihandling",
8207
- "mine-wide-area-antitank",
8208
- "mine-cluster"
8209
- ];
8194
+ const HATCH_PATTERNS = NON_SOLID_FILL_PATTERNS;
8210
8195
  /** Tile edge length, CSS px, before `pixelRatio` scaling. Kept a power of two. */
8211
8196
  const BASE_TILE_SIZE = 32;
8212
8197
  /** Tile edge, CSS px, of the mine-pictogram family (they use the full 32-unit tile). */
8213
- const MINE_PATTERN_TILE_SIZE = 32;
8198
+ const MINE_PATTERN_TILE_SIZE = FILL_PATTERN_DEFINITIONS["mine-unspecified"].tile.width;
8214
8199
  /** True for the mine-pictogram family — a screen-space glyph texture rather than a repeating hatch. */
8215
8200
  function isMinePattern(pattern) {
8216
8201
  return pattern.startsWith("mine-");
8217
8202
  }
8218
- /** Line spacing as a fraction of the tile edge — 4 repeats per tile. */
8219
- const SPACING_DIVISOR = 4;
8220
- /**
8221
- * Dot radius, CSS px, before `pixelRatio` scaling — the `"dots"` counterpart to
8222
- * the 1px line width, sized so a dot reads at the same weight as a hatch line.
8223
- * Must stay in lockstep with the vector tiles in the Leaflet adapter and the
8224
- * static previews.
8225
- */
8226
- const DOT_RADIUS = 1.25;
8227
8203
  /**
8228
8204
  * Stable id for a rasterized tile, keyed by pattern and color. Adapters use
8229
8205
  * this as the image-registry key (MapLibre `addImage` id, OpenLayers pattern
@@ -8295,40 +8271,6 @@ function parseColor(color) {
8295
8271
  a: 1
8296
8272
  };
8297
8273
  }
8298
- /** `v mod m`, folded into `[-m/2, m/2)`. Used to find distance to the nearest line in a periodic family. */
8299
- function centeredMod(v, m) {
8300
- const wrapped = (v % m + m) % m;
8301
- return wrapped >= m / 2 ? wrapped - m : wrapped;
8302
- }
8303
- const SQRT2 = Math.SQRT2;
8304
- /**
8305
- * Coverage in `[0, 1]` of one diagonal line family (slope +1 or -1, both
8306
- * period `spacing`) at pixel center `(x, y)`, antialiased over a ~1 device-px
8307
- * band. `axis` selects `y - x` (the "/" hatch) or `y + x` (the "\" mirror,
8308
- * "reverse-hatch", which "cross-hatch" unions on top of the hatch). Because `spacing`
8309
- * divides the tile dimension evenly, shifting
8310
- * `x` or `y` by a whole tile is a whole number of `spacing` periods, so the
8311
- * mod-distance — and therefore the coverage — is identical at the tile edges
8312
- * as at their wrapped continuation. That periodicity is what makes the tile
8313
- * seamless.
8314
- */
8315
- function lineCoverage(x, y, spacing, lineWidth, axis) {
8316
- const t = axis === "/" ? y - x : axis === "\\" ? y + x : (axis === "-" ? y : x) - spacing / 2;
8317
- const raw = Math.abs(centeredMod(t, spacing));
8318
- const perpDist = axis === "/" || axis === "\\" ? raw / SQRT2 : raw;
8319
- const halfWidth = lineWidth / 2;
8320
- return Math.min(1, Math.max(0, halfWidth + .5 - perpDist));
8321
- }
8322
- /**
8323
- * Coverage in `[0, 1]` of a square lattice of dots — one per `spacing × spacing`
8324
- * cell, centered in the cell so the tile stays seamless — antialiased over the
8325
- * same ~1px band as {@link lineCoverage}.
8326
- */
8327
- function dotCoverage(x, y, spacing, radius) {
8328
- const dx = centeredMod(x - spacing / 2, spacing);
8329
- const dy = centeredMod(y - spacing / 2, spacing);
8330
- return Math.min(1, Math.max(0, radius + .5 - Math.hypot(dx, dy)));
8331
- }
8332
8274
  function segmentCoverage(x, y, ax, ay, bx, by, width) {
8333
8275
  const dx = bx - ax;
8334
8276
  const dy = by - ay;
@@ -8336,36 +8278,24 @@ function segmentCoverage(x, y, ax, ay, bx, by, width) {
8336
8278
  const t = length2 > 0 ? Math.min(1, Math.max(0, ((x - ax) * dx + (y - ay) * dy) / length2)) : 0;
8337
8279
  return Math.min(1, Math.max(0, width / 2 + .5 - Math.hypot(x - (ax + t * dx), y - (ay + t * dy))));
8338
8280
  }
8339
- function cubicMinePoint(t, p0, p1, p2, p3) {
8281
+ function cubicPoint(t, p0, p1, p2, p3) {
8340
8282
  const u = 1 - t;
8341
8283
  const u2 = u * u;
8342
8284
  const t2 = t * t;
8343
8285
  return [u2 * u * p0[0] + 3 * u2 * t * p1[0] + 3 * u * t2 * p2[0] + t2 * t * p3[0], u2 * u * p0[1] + 3 * u2 * t * p1[1] + 3 * u * t2 * p2[1] + t2 * t * p3[1]];
8344
8286
  }
8345
- /**
8346
- * Raster segments for milsymbol's dashed 36×20-unit mine-cluster outline. The
8347
- * same curve is emitted as vector geometry by `minefield.ts`'s
8348
- * `mineClusterGlyph` in `@orbat-mapper/control-measures` (in meters, y up
8349
- * rather than tile units, y down) — keep the control points and dash cadence in
8350
- * step so the area fill and the point glyph read alike.
8351
- */
8352
- function mineClusterSegments() {
8353
- const scale = 1 / 3;
8354
- const point = (x, y) => [16 + x * scale, 16 + y * scale];
8355
- const right = point(18, 10);
8356
- const left = point(-18, 10);
8357
- const top = point(0, -10);
8358
- const outline = [right, left];
8359
- for (let index = 1; index <= 16; index++) outline.push(cubicMinePoint(index / 16, left, point(-18, 0), point(-15, -10), top));
8360
- for (let index = 1; index <= 16; index++) outline.push(cubicMinePoint(index / 16, top, point(15, -10), point(18, 0), right));
8361
- const segments = [];
8287
+ function scaledPoint(point, scale) {
8288
+ return [point[0] * scale, point[1] * scale];
8289
+ }
8290
+ function dashSegments(segments, dash) {
8291
+ if (dash.length === 0) return [...segments];
8292
+ const result = [];
8293
+ let dashIndex = 0;
8294
+ let remaining = dash[0];
8362
8295
  let drawing = true;
8363
- let remaining = 7.5 * scale;
8364
- for (let index = 0; index < outline.length - 1; index++) {
8365
- const a = outline[index];
8366
- const b = outline[index + 1];
8367
- const dx = b[0] - a[0];
8368
- const dy = b[1] - a[1];
8296
+ for (const [ax, ay, bx, by] of segments) {
8297
+ const dx = bx - ax;
8298
+ const dy = by - ay;
8369
8299
  const length = Math.hypot(dx, dy);
8370
8300
  let walked = 0;
8371
8301
  while (walked < length - 1e-9) {
@@ -8373,186 +8303,124 @@ function mineClusterSegments() {
8373
8303
  if (drawing) {
8374
8304
  const t0 = walked / length;
8375
8305
  const t1 = (walked + step) / length;
8376
- segments.push([
8377
- a[0] + dx * t0,
8378
- a[1] + dy * t0,
8379
- a[0] + dx * t1,
8380
- a[1] + dy * t1
8306
+ result.push([
8307
+ ax + dx * t0,
8308
+ ay + dy * t0,
8309
+ ax + dx * t1,
8310
+ ay + dy * t1
8381
8311
  ]);
8382
8312
  }
8383
8313
  walked += step;
8384
8314
  remaining -= step;
8385
8315
  if (remaining <= 1e-9) {
8386
- drawing = !drawing;
8387
- remaining = (drawing ? 7.5 : 5) * scale;
8316
+ dashIndex = (dashIndex + 1) % dash.length;
8317
+ drawing = dashIndex % 2 === 0;
8318
+ remaining = dash[dashIndex];
8388
8319
  }
8389
8320
  }
8390
8321
  }
8391
- return segments;
8322
+ return result;
8392
8323
  }
8393
- const MINE_GLYPHS = {
8394
- "mine-unspecified": {
8395
- body: "ring",
8396
- segments: []
8397
- },
8398
- "mine-antipersonnel": {
8399
- body: "disc",
8400
- segments: [[
8401
- 12.867,
8402
- 12.1,
8403
- 9.333,
8404
- 7.667
8405
- ], [
8406
- 19.133,
8407
- 12.1,
8408
- 22.667,
8409
- 7.667
8410
- ]]
8411
- },
8412
- "mine-antipersonnel-directional": {
8413
- body: "disc",
8414
- segments: [
8415
- [
8416
- 12.867,
8417
- 12.1,
8418
- 9.333,
8419
- 7.667
8420
- ],
8421
- [
8422
- 19.133,
8423
- 12.1,
8424
- 22.667,
8425
- 7.667
8426
- ],
8427
- [
8428
- 21,
8429
- 16,
8430
- 22.1,
8431
- 16
8432
- ],
8433
- [
8434
- 23.667,
8435
- 15.333,
8436
- 24.333,
8437
- 15.9
8438
- ],
8439
- [
8440
- 24.333,
8441
- 15.9,
8442
- 23.667,
8443
- 16.667
8444
- ],
8445
- [
8446
- 23.667,
8447
- 16.667,
8448
- 23.667,
8449
- 15.333
8450
- ]
8451
- ]
8452
- },
8453
- "mine-antitank": {
8454
- body: "disc",
8455
- segments: []
8456
- },
8457
- "mine-antitank-antihandling": {
8458
- body: "disc",
8459
- segments: [[
8460
- 16,
8461
- 21,
8462
- 16,
8463
- 25.333
8464
- ], [
8465
- 16,
8466
- 25.333,
8467
- 18,
8468
- 23.333
8469
- ]]
8470
- },
8471
- "mine-wide-area-antitank": {
8472
- body: "disc",
8473
- segments: [
8474
- [
8475
- 9.333,
8476
- 21,
8477
- 12,
8478
- 24.333
8479
- ],
8480
- [
8481
- 12,
8482
- 24.333,
8483
- 13.833,
8484
- 20.667
8485
- ],
8486
- [
8487
- 18.167,
8488
- 20.667,
8489
- 20,
8490
- 24.333
8491
- ],
8492
- [
8493
- 20,
8494
- 24.333,
8495
- 22.667,
8496
- 21
8497
- ]
8498
- ]
8499
- },
8500
- "mine-cluster": {
8501
- body: "none",
8502
- segments: mineClusterSegments()
8324
+ function pathSegments(command, scale) {
8325
+ const segments = [];
8326
+ let current;
8327
+ let start;
8328
+ for (const operation of command.operations) if (operation.type === "move") {
8329
+ current = scaledPoint(operation.to, scale);
8330
+ start = current;
8331
+ } else if (operation.type === "line" && current) {
8332
+ const next = scaledPoint(operation.to, scale);
8333
+ segments.push([
8334
+ current[0],
8335
+ current[1],
8336
+ next[0],
8337
+ next[1]
8338
+ ]);
8339
+ current = next;
8340
+ } else if (operation.type === "cubic" && current) {
8341
+ const control1 = scaledPoint(operation.control1, scale);
8342
+ const control2 = scaledPoint(operation.control2, scale);
8343
+ const end = scaledPoint(operation.to, scale);
8344
+ for (let index = 1; index <= 16; index++) {
8345
+ const next = cubicPoint(index / 16, current, control1, control2, end);
8346
+ const previous = index === 1 ? current : cubicPoint((index - 1) / 16, current, control1, control2, end);
8347
+ segments.push([
8348
+ previous[0],
8349
+ previous[1],
8350
+ next[0],
8351
+ next[1]
8352
+ ]);
8353
+ }
8354
+ current = end;
8355
+ } else if (operation.type === "close" && current && start) {
8356
+ if (current[0] !== start[0] || current[1] !== start[1]) segments.push([
8357
+ current[0],
8358
+ current[1],
8359
+ start[0],
8360
+ start[1]
8361
+ ]);
8362
+ current = start;
8363
+ }
8364
+ const dash = command.paint.stroke?.dash?.map((value) => value * scale);
8365
+ return dash ? dashSegments(segments, dash) : segments;
8366
+ }
8367
+ function rasterCommands(pattern, coordinateScale, paintScale) {
8368
+ return FILL_PATTERN_DEFINITIONS[pattern].commands.flatMap((command) => {
8369
+ if (command.type === "circle") return [{
8370
+ type: "circle",
8371
+ cx: command.center[0] * coordinateScale,
8372
+ cy: command.center[1] * coordinateScale,
8373
+ radius: command.radius * paintScale,
8374
+ fill: command.paint.fill !== void 0,
8375
+ ...command.paint.stroke ? { strokeWidth: Math.max(1, command.paint.stroke.width * paintScale) } : {}
8376
+ }];
8377
+ if (!command.paint.stroke) return [];
8378
+ return [{
8379
+ type: "path",
8380
+ segments: pathSegments(command, coordinateScale),
8381
+ strokeWidth: Math.max(1, command.paint.stroke.width * paintScale)
8382
+ }];
8383
+ });
8384
+ }
8385
+ function commandCoverage(x, y, command) {
8386
+ if (command.type === "circle") {
8387
+ const distance = Math.hypot(x - command.cx, y - command.cy);
8388
+ const fillCoverage = command.fill ? Math.min(1, Math.max(0, command.radius + .5 - distance)) : 0;
8389
+ const strokeCoverage = command.strokeWidth ? Math.min(1, Math.max(0, command.strokeWidth / 2 + .5 - Math.abs(distance - command.radius))) : 0;
8390
+ return Math.max(fillCoverage, strokeCoverage);
8503
8391
  }
8504
- };
8505
- function minePatternCoverage(x, y, pattern, scale) {
8506
- const glyph = MINE_GLYPHS[pattern];
8507
- const cx = 16 * scale;
8508
- const cy = 16 * scale;
8509
- const radius = 5 * scale;
8510
- const lineWidth = Math.max(1, scale);
8511
- const distance = Math.hypot(x - cx, y - cy);
8512
- let coverage = glyph.body === "none" ? 0 : glyph.body === "disc" ? Math.min(1, Math.max(0, radius + .5 - distance)) : Math.min(1, Math.max(0, lineWidth / 2 + .5 - Math.abs(distance - radius)));
8513
- for (const [ax, ay, bx, by] of glyph.segments) coverage = Math.max(coverage, segmentCoverage(x, y, ax * scale, ay * scale, bx * scale, by * scale, lineWidth));
8392
+ let coverage = 0;
8393
+ for (const [ax, ay, bx, by] of command.segments) coverage = Math.max(coverage, segmentCoverage(x, y, ax, ay, bx, by, command.strokeWidth));
8514
8394
  return coverage;
8515
8395
  }
8396
+ function preparePatternRaster(pattern, pixelRatio) {
8397
+ const size = fillPatternImageDimension(pixelRatio);
8398
+ const definition = FILL_PATTERN_DEFINITIONS[pattern];
8399
+ const coordinateScale = size / BASE_TILE_SIZE;
8400
+ return {
8401
+ commands: rasterCommands(pattern, coordinateScale, isMinePattern(pattern) ? coordinateScale : Math.max(1, Math.round(pixelRatio))),
8402
+ tileWidth: definition.tile.width * coordinateScale,
8403
+ tileHeight: definition.tile.height * coordinateScale
8404
+ };
8405
+ }
8516
8406
  /**
8517
8407
  * Rasterize one seamless hatch tile as a straight RGBA pixel buffer — no
8518
8408
  * canvas involved, so this runs identically in a browser adapter and in
8519
- * jsdom/node tests. Diagonal lines are snapped to slope ±1 (45°) so the
8520
- * mod-based coverage math in {@link lineCoverage} tiles exactly. `"hatch"`
8521
- * draws the "/" diagonal, `"reverse-hatch"` its "\" mirror, and `"cross-hatch"` unions
8522
- * both via `Math.max` coverage. `"horizontal"`/`"vertical"` draw the
8523
- * axis-aligned families at the same spacing, and `"dots"` a square lattice of
8524
- * dots (see {@link dotCoverage}).
8409
+ * jsdom/node tests. Every command, tile dimension, stroke, fill, and dash is
8410
+ * read from the public renderer-neutral pattern definition.
8525
8411
  */
8526
8412
  function makeFillPatternImage(color, pattern, pixelRatio = 1) {
8527
8413
  const size = fillPatternImageDimension(pixelRatio);
8528
- const spacing = size / SPACING_DIVISOR;
8529
- const lineWidth = Math.max(1, Math.round(pixelRatio));
8530
- const dotRadius = DOT_RADIUS * Math.max(1, Math.round(pixelRatio));
8414
+ const prepared = preparePatternRaster(pattern, pixelRatio);
8531
8415
  const { r, g, b, a } = parseColor(color);
8532
8416
  const data = new Uint8ClampedArray(size * size * 4);
8533
8417
  for (let y = 0; y < size; y++) for (let x = 0; x < size; x++) {
8534
8418
  const cx = x + .5;
8535
8419
  const cy = y + .5;
8536
- let coverage;
8537
- if (isMinePattern(pattern)) coverage = minePatternCoverage(cx, cy, pattern, size / BASE_TILE_SIZE);
8538
- else switch (pattern) {
8539
- case "reverse-hatch":
8540
- coverage = lineCoverage(cx, cy, spacing, lineWidth, "\\");
8541
- break;
8542
- case "cross-hatch":
8543
- coverage = Math.max(lineCoverage(cx, cy, spacing, lineWidth, "/"), lineCoverage(cx, cy, spacing, lineWidth, "\\"));
8544
- break;
8545
- case "horizontal":
8546
- coverage = lineCoverage(cx, cy, spacing, lineWidth, "-");
8547
- break;
8548
- case "vertical":
8549
- coverage = lineCoverage(cx, cy, spacing, lineWidth, "|");
8550
- break;
8551
- case "dots":
8552
- coverage = dotCoverage(cx, cy, spacing, dotRadius);
8553
- break;
8554
- default: coverage = lineCoverage(cx, cy, spacing, lineWidth, "/");
8555
- }
8420
+ const localX = cx % prepared.tileWidth;
8421
+ const localY = cy % prepared.tileHeight;
8422
+ let coverage = 0;
8423
+ for (const command of prepared.commands) coverage = Math.max(coverage, commandCoverage(localX, localY, command));
8556
8424
  const i = (y * size + x) * 4;
8557
8425
  data[i] = r;
8558
8426
  data[i + 1] = g;
@@ -1,4 +1,4 @@
1
- import { FillPattern } from "@orbat-mapper/control-measures";
1
+ import { PatternId } from "@orbat-mapper/control-measures";
2
2
  import { Feature, Position } from "geojson";
3
3
 
4
4
  //#region src/gestures/types.d.ts
@@ -49,7 +49,7 @@ interface EditPointerDriver {
49
49
  * texture, so it is rasterized once here in pure math — no `HTMLCanvasElement`
50
50
  * — so it works in adapter code and in jsdom/node tests alike.
51
51
  */
52
- type HatchPattern = Exclude<FillPattern, "solid">;
52
+ type HatchPattern = PatternId;
53
53
  /**
54
54
  * Every non-solid `FillPattern` as a runtime list — the value-level companion
55
55
  * to {@link HatchPattern}, so adapters can test membership and build filter
@@ -57,7 +57,7 @@ type HatchPattern = Exclude<FillPattern, "solid">;
57
57
  */
58
58
  declare const HATCH_PATTERNS: readonly HatchPattern[];
59
59
  /** Tile edge, CSS px, of the mine-pictogram family (they use the full 32-unit tile). */
60
- declare const MINE_PATTERN_TILE_SIZE = 32;
60
+ declare const MINE_PATTERN_TILE_SIZE: number;
61
61
  /** True for the mine-pictogram family — a screen-space glyph texture rather than a repeating hatch. */
62
62
  declare function isMinePattern(pattern: HatchPattern): pattern is MinePattern;
63
63
  /**
@@ -78,15 +78,12 @@ declare function fillPatternImageId(color: string, pattern: HatchPattern): strin
78
78
  declare function fillPatternImageDimension(pixelRatio: number): number;
79
79
  /** The mine-pictogram members of {@link HatchPattern}, derived so the family stays in one place. */
80
80
  type MinePattern = Extract<HatchPattern, `mine-${string}`>;
81
+ /** Coverage from the canonical command interpreter, exposed only for focused conformance tests. */
81
82
  /**
82
83
  * Rasterize one seamless hatch tile as a straight RGBA pixel buffer — no
83
84
  * canvas involved, so this runs identically in a browser adapter and in
84
- * jsdom/node tests. Diagonal lines are snapped to slope ±1 (45°) so the
85
- * mod-based coverage math in {@link lineCoverage} tiles exactly. `"hatch"`
86
- * draws the "/" diagonal, `"reverse-hatch"` its "\" mirror, and `"cross-hatch"` unions
87
- * both via `Math.max` coverage. `"horizontal"`/`"vertical"` draw the
88
- * axis-aligned families at the same spacing, and `"dots"` a square lattice of
89
- * dots (see {@link dotCoverage}).
85
+ * jsdom/node tests. Every command, tile dimension, stroke, fill, and dash is
86
+ * read from the public renderer-neutral pattern definition.
90
87
  */
91
88
  declare function makeFillPatternImage(color: string, pattern: HatchPattern, pixelRatio?: number): {
92
89
  width: number;
@@ -198,8 +195,10 @@ interface ImageOverlayResource {
198
195
  /**
199
196
  * One stable, atomic unit in a logical layer's bottom-to-top paint stack.
200
197
  *
201
- * Features retain their renderer-defined order inside the group. An empty
202
- * group is valid and keeps its identity and stack position.
198
+ * Features paint in array order inside the group. A filled feature paints its
199
+ * interior before its outline, and text or icon content paints at that
200
+ * feature's array position. An empty group is valid and keeps its identity and
201
+ * stack position.
203
202
  */
204
203
  interface FeatureGroup {
205
204
  id: string;
@@ -1,4 +1,4 @@
1
- import { a as LayerId, o as MapAdapter, p as PixelCoordinate } from "./map-adapter-BkDIEriM.mjs";
1
+ import { a as LayerId, o as MapAdapter, p as PixelCoordinate } from "./map-adapter-BWvKku2P.mjs";
2
2
  import { Feature } from "geojson";
3
3
 
4
4
  //#region src/testing/feature-group-conformance.d.ts
@@ -11,8 +11,12 @@ interface FeatureGroupConformanceSubject {
11
11
  rendersFeatureStyle(id: string | number, channel: "fill" | "stroke"): boolean;
12
12
  mutationCount(): number;
13
13
  operationLog(): readonly string[];
14
+ /** Bottom-to-top native paint operations, when the engine exposes ordering conformance. */
15
+ paintSequence?(): readonly string[];
14
16
  }
15
- declare function runFeatureGroupConformance(name: string, createSubject: () => FeatureGroupConformanceSubject): void;
17
+ declare function runFeatureGroupConformance(name: string, createSubject: () => FeatureGroupConformanceSubject, options?: {
18
+ canonicalFeatureOrder?: boolean;
19
+ }): void;
16
20
  //#endregion
17
21
  //#region src/testing/grouped-pick-conformance.d.ts
18
22
  interface GroupedPickConformanceSubject {
package/dist/testing.mjs CHANGED
@@ -1,7 +1,54 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  //#region src/testing/feature-group-conformance.ts
3
- function runFeatureGroupConformance(name, createSubject) {
3
+ function runFeatureGroupConformance(name, createSubject, options = {}) {
4
4
  describe(`${name} feature-group conformance`, () => {
5
+ if (options.canonicalFeatureOrder) it("paints interleaved feature content in canonical array order", () => {
6
+ const subject = createSubject();
7
+ const { adapter, layerId } = subject;
8
+ const icon = iconResource("order-icon");
9
+ const mixed = canonicalOrderFeatures(icon.id);
10
+ adapter.setLayerStyle(layerId, { text: { labelProperty: "label" } });
11
+ adapter.setLayerFeatureGroups(layerId, [group$1("mixed", mixed, [icon]), group$1("upper", [line$1("upper-stroke")])]);
12
+ expect(subject.paintSequence?.()).toEqual([
13
+ "solid:fill",
14
+ "solid:stroke",
15
+ "label:text",
16
+ "pattern:pattern",
17
+ "pattern:stroke",
18
+ "icon:icon",
19
+ "last-stroke:stroke",
20
+ "upper-stroke:stroke"
21
+ ]);
22
+ const updated = [
23
+ mixed[3],
24
+ mixed[0],
25
+ mixed[1],
26
+ mixed[2],
27
+ mixed[4]
28
+ ];
29
+ adapter.setLayerFeatureGroups(layerId, [group$1("mixed", updated, [icon]), group$1("upper", [line$1("upper-stroke")])]);
30
+ expect(subject.paintSequence?.()).toEqual([
31
+ "icon:icon",
32
+ "solid:fill",
33
+ "solid:stroke",
34
+ "label:text",
35
+ "pattern:pattern",
36
+ "pattern:stroke",
37
+ "last-stroke:stroke",
38
+ "upper-stroke:stroke"
39
+ ]);
40
+ adapter.setLayerFeatureGroups(layerId, [group$1("upper", [line$1("upper-stroke")]), group$1("mixed", updated, [icon])]);
41
+ expect(subject.paintSequence?.()).toEqual([
42
+ "upper-stroke:stroke",
43
+ "icon:icon",
44
+ "solid:fill",
45
+ "solid:stroke",
46
+ "label:text",
47
+ "pattern:pattern",
48
+ "pattern:stroke",
49
+ "last-stroke:stroke"
50
+ ]);
51
+ });
5
52
  it("reconciles complete ordered group state, including pure reorders", () => {
6
53
  const subject = createSubject();
7
54
  const { adapter, layerId } = subject;
@@ -157,6 +204,26 @@ function polygon$1(id) {
157
204
  }
158
205
  };
159
206
  }
207
+ function canonicalOrderFeatures(iconId) {
208
+ return [
209
+ polygon$1("solid"),
210
+ {
211
+ ...point("label"),
212
+ properties: { label: "LABEL" }
213
+ },
214
+ {
215
+ ...polygon$1("pattern"),
216
+ properties: { style: {
217
+ fillColor: "#ffffff",
218
+ fillPattern: "hatch",
219
+ strokeColor: "#000000",
220
+ strokeWidth: 2
221
+ } }
222
+ },
223
+ iconPoint("icon", iconId),
224
+ line$1("last-stroke")
225
+ ];
226
+ }
160
227
  function featureIds(features) {
161
228
  return features.map((feature) => feature.id);
162
229
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbat-mapper/tactical-draw",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
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.6.0"
42
+ "@orbat-mapper/control-measures": "^0.8.0"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "vitest": ">=4.0.0"