@orbat-mapper/tactical-map-sheet 0.8.2 → 0.8.3

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.
@@ -210,6 +210,11 @@ interface ScenePath {
210
210
  readonly kind: "path";
211
211
  readonly points: readonly ScenePoint[];
212
212
  readonly closed?: boolean;
213
+ /**
214
+ * Closed inner rings cut out of a closed path's fill by the even-odd rule;
215
+ * each ring is also stroked like the outline. Omitted when there are none.
216
+ */
217
+ readonly holes?: readonly (readonly ScenePoint[])[];
213
218
  readonly strokeColor: string;
214
219
  /** `0` means the path is not stroked at all (fill only), never a hairline. */
215
220
  readonly strokeWidthMm: number;
@@ -677,16 +677,12 @@ function serializeElement(element) {
677
677
  return `<g data-vector-resource="${escapeXml(element.resourceId)}" data-octagon-anchor="${formatDecimal(element.octagonAnchor.x)} ${formatDecimal(element.octagonAnchor.y)}" transform="${transform}" opacity="${formatDecimal(element.opacity)}"${element.usesFont ? " font-family=\"Open Sans\"" : ""}>${vector}</g>`;
678
678
  }
679
679
  if (element.kind === "text") return serializeText(element);
680
- const [first, ...rest] = element.points;
681
- if (!first) throw new Error("Cannot serialize an empty path");
682
- const commands = [
683
- `M ${formatDecimal(first.xMm)} ${formatDecimal(first.yMm)}`,
684
- ...rest.map((point) => `L ${formatDecimal(point.xMm)} ${formatDecimal(point.yMm)}`),
685
- ...element.closed ? ["Z"] : []
686
- ];
680
+ if (element.points.length === 0) throw new Error("Cannot serialize an empty path");
681
+ const commands = [element.points, ...element.holes ?? []].flatMap((ring, ringIndex) => [...ring.map((point, index) => `${index === 0 ? "M" : "L"} ${formatDecimal(point.xMm)} ${formatDecimal(point.yMm)}`), ...ringIndex > 0 || element.closed ? ["Z"] : []]);
687
682
  const fillAttribute = ` fill="${element.fillPatternId ? `url(#${escapeXml(element.fillPatternId)})` : escapeXml(element.fillColor ?? "none")}"`;
683
+ const fillRule = element.holes ? ` fill-rule="evenodd"` : "";
688
684
  const attributes = serializeAttributes(element.attributes);
689
- if (element.strokeWidthMm === 0) return `<path d="${commands.join(" ")}" stroke="none"${fillAttribute}${attributes}/>`;
685
+ if (element.strokeWidthMm === 0) return `<path d="${commands.join(" ")}" stroke="none"${fillAttribute}${fillRule}${attributes}/>`;
690
686
  return [
691
687
  `<path d="${commands.join(" ")}"`,
692
688
  ` stroke="${escapeXml(element.strokeColor)}"`,
@@ -696,6 +692,7 @@ function serializeElement(element) {
696
692
  element.strokeDashMm.length > 0 ? ` stroke-dasharray="${element.strokeDashMm.map(formatDecimal).join(" ")}"` : "",
697
693
  element.fillColor || element.fillPatternId ? ` paint-order="fill stroke"` : "",
698
694
  fillAttribute,
695
+ fillRule,
699
696
  attributes,
700
697
  "/>"
701
698
  ].join("");
@@ -1654,6 +1651,12 @@ function clipRingToBounds(positions, bounds) {
1654
1651
  if (clipped.length > 0) clipped.push([...clipped[0]]);
1655
1652
  return clipped;
1656
1653
  }
1654
+ /** A polygon whose outer ring clips away is dropped whole; its holes cannot stand alone. */
1655
+ function clipPolygonToBounds(rings, bounds) {
1656
+ const [outer, ...holes] = rings.map((ring) => clipRingToBounds(ring, bounds));
1657
+ if (!outer || outer.length < 4) return;
1658
+ return [outer, ...holes.filter((ring) => ring.length >= 4)];
1659
+ }
1657
1660
  function clipGeometryToBounds(geometry, bounds) {
1658
1661
  if (geometry.type === "Point") return;
1659
1662
  if (geometry.type === "LineString") {
@@ -1675,12 +1678,19 @@ function clipGeometryToBounds(geometry, bounds) {
1675
1678
  };
1676
1679
  }
1677
1680
  if (geometry.type === "Polygon") {
1678
- const rings = geometry.coordinates.map((ring) => clipRingToBounds(ring, bounds)).filter((ring) => ring.length >= 4);
1679
- return rings.length === 0 ? void 0 : {
1681
+ const rings = clipPolygonToBounds(geometry.coordinates, bounds);
1682
+ return rings && {
1680
1683
  type: "Polygon",
1681
1684
  coordinates: rings
1682
1685
  };
1683
1686
  }
1687
+ if (geometry.type === "MultiPolygon") {
1688
+ const polygons = geometry.coordinates.map((polygon) => clipPolygonToBounds(polygon, bounds)).filter((polygon) => polygon !== void 0);
1689
+ return polygons.length === 0 ? void 0 : {
1690
+ type: "MultiPolygon",
1691
+ coordinates: polygons
1692
+ };
1693
+ }
1684
1694
  return geometry;
1685
1695
  }
1686
1696
  function geometryPositions(geometry) {
@@ -1822,7 +1832,7 @@ function resolvePortrayal(input) {
1822
1832
  function toScenePoint(position, context) {
1823
1833
  return projectedToScenePoint(geographicLibGridProjection.forward(context.crs, position), context);
1824
1834
  }
1825
- function pathFromPositions(positions, closed, properties, portrayal, context) {
1835
+ function pathFromPositions(positions, closed, properties, portrayal, context, holes) {
1826
1836
  if (positions.length < 2) throw new Error("A document path requires at least two positions");
1827
1837
  const style = properties.style;
1828
1838
  const strokeWidthCssPixels = style?.strokeWidth ?? portrayal.strokeWidthCssPixels;
@@ -1832,10 +1842,12 @@ function pathFromPositions(positions, closed, properties, portrayal, context) {
1832
1842
  const fillPattern = style?.fillPattern;
1833
1843
  const fillColor = style?.fillColor;
1834
1844
  const fillPatternId = fillPattern && fillPattern !== "solid" && fillColor ? registerPattern(fillPattern, fillColor, context) : void 0;
1845
+ const toScenePoints = (ring) => ring.map((position) => toScenePoint(position, context));
1835
1846
  return {
1836
1847
  kind: "path",
1837
- points: positions.map((position) => toScenePoint(position, context)),
1848
+ points: toScenePoints(positions),
1838
1849
  ...closed ? { closed: true } : {},
1850
+ ...holes.length > 0 ? { holes: holes.map(toScenePoints) } : {},
1839
1851
  strokeColor: style?.strokeColor ?? portrayal.symbolColor,
1840
1852
  strokeWidthMm: strokeWidthCssPixels * MILLIMETRES_PER_CSS_PIXEL,
1841
1853
  strokeDashMm: strokeDashCssPixels.map((value) => value * MILLIMETRES_PER_CSS_PIXEL),
@@ -1921,6 +1933,7 @@ function highlightBandPaths(band, parts) {
1921
1933
  kind: "path",
1922
1934
  points: part.points,
1923
1935
  ...part.closed ? { closed: true } : {},
1936
+ ...part.holes ? { holes: part.holes } : {},
1924
1937
  strokeColor: band.color,
1925
1938
  strokeWidthMm: band.width * MILLIMETRES_PER_CSS_PIXEL,
1926
1939
  ...band.opacity < 1 ? { strokeOpacity: band.opacity } : {},
@@ -1933,14 +1946,13 @@ function elementsFromGeometry(feature, portrayal, context, constructionMetersPer
1933
1946
  const text = textFromFeature(feature, portrayal, context, constructionMetersPerCssPixel);
1934
1947
  if (text) return [text];
1935
1948
  if (feature.geometry.type === "Point" && feature.properties.text !== void 0) return [];
1936
- const path = (positions, closed = false) => pathFromPositions(positions, closed, feature.properties, portrayal, context);
1949
+ const path = (positions, closed = false, holes = []) => pathFromPositions(positions, closed, feature.properties, portrayal, context, holes);
1950
+ const polygonPath = ([outer, ...holes]) => path(outer, true, holes);
1937
1951
  switch (feature.geometry.type) {
1938
1952
  case "LineString": return [path(feature.geometry.coordinates)];
1939
1953
  case "MultiLineString": return feature.geometry.coordinates.map((line) => path(line));
1940
- case "Polygon":
1941
- if (feature.geometry.coordinates.length !== 1) throw new Error("Polygon holes are not representable in this milestone");
1942
- return [path(feature.geometry.coordinates[0], true)];
1943
- case "MultiPolygon":
1954
+ case "Polygon": return [polygonPath(feature.geometry.coordinates)];
1955
+ case "MultiPolygon": return feature.geometry.coordinates.map(polygonPath);
1944
1956
  case "Point":
1945
1957
  case "MultiPoint": throw new Error(`${feature.geometry.type} features are not representable in this milestone`);
1946
1958
  case "GeometryCollection": throw new Error("GeometryCollection features cannot be represented by this document renderer");
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as MapSheetMarginaliaOptions, A as PaperSizeName, B as PointSymbolOffsetWarning, C as ResolvedMapSheetRasterTileMetadata, D as ResolvedRegistrationMark, E as MapSheetRegistrationRequest, F as GraphicOutsideFrameWarning, G as PrepareMapSheetNotesOptions, H as MapSheetNote, I as GraphicRenderWarning, J as MapSheetCustomSymbol, K as prepareMapSheetNotes, L as MapSheetAuthoredGraphic, M as AuthoredMapSheetGraphic, N as GraphicClippedWarning, O as PAPER_SIZES, P as GraphicHiddenWarning, Q as VectorSymbolAnchor, R as MapSheetPortrayalDefaults, S as ResolvedMapSheetRasterLayerMetadata, T as AuthoredRegistrationMark, U as MapSheetNoteCapability, V as TacticalMapSheetLayer, W as MapSheetNoteRaster, X as MapSheetPointSymbolCapability, Y as MapSheetPointSymbol, Z as MapSheetSymbolSize, _ as MapSheetRasterLayer, a as ResolvedMapSheetMetadata, at as MapSheetPatternIdentity, b as RasterDpiAnisotropyWarning, c as TacticalMapSheetResources, ct as GeographicPosition, d as UpsProjection, dt as UtmCrs, et as MapSheetMetadata, f as UtmProjection, g as MapSheetRasterBasemap, h as MapSheetRasterAttribution, i as MapSheetPageInput, it as MgrsSnapInterval, j as resolvePaperSize, k as PaperOrientation, l as TacticalMapSheetResult, lt as GridCrs, m as LowRasterDpiWarning, n as CrossZoneFootprintWarning, nt as ResolvedMgrsGridMetadata, o as ScaleDeviationWarning, p as createTacticalMapSheet, pt as Position, q as ControlledVectorSymbol, r as MapSheetFontIdentity, rt as MgrsPrecision, s as TacticalMapSheetRequest, st as SceneRectangle, t as CrossProjectionFootprintWarning, tt as MgrsGridOptions, u as TacticalMapSheetWarning, ut as UpsCrs, v as MapSheetRasterTile, w as PrinterCalibrationRequest, x as ResolvedMapSheetRasterBasemapMetadata, y as MapSheetRasterWarning, z as PointSymbolFallbackWarning } from "./create-tactical-map-sheet-aMfOzCpu.mjs";
1
+ import { $ as MapSheetMarginaliaOptions, A as PaperSizeName, B as PointSymbolOffsetWarning, C as ResolvedMapSheetRasterTileMetadata, D as ResolvedRegistrationMark, E as MapSheetRegistrationRequest, F as GraphicOutsideFrameWarning, G as PrepareMapSheetNotesOptions, H as MapSheetNote, I as GraphicRenderWarning, J as MapSheetCustomSymbol, K as prepareMapSheetNotes, L as MapSheetAuthoredGraphic, M as AuthoredMapSheetGraphic, N as GraphicClippedWarning, O as PAPER_SIZES, P as GraphicHiddenWarning, Q as VectorSymbolAnchor, R as MapSheetPortrayalDefaults, S as ResolvedMapSheetRasterLayerMetadata, T as AuthoredRegistrationMark, U as MapSheetNoteCapability, V as TacticalMapSheetLayer, W as MapSheetNoteRaster, X as MapSheetPointSymbolCapability, Y as MapSheetPointSymbol, Z as MapSheetSymbolSize, _ as MapSheetRasterLayer, a as ResolvedMapSheetMetadata, at as MapSheetPatternIdentity, b as RasterDpiAnisotropyWarning, c as TacticalMapSheetResources, ct as GeographicPosition, d as UpsProjection, dt as UtmCrs, et as MapSheetMetadata, f as UtmProjection, g as MapSheetRasterBasemap, h as MapSheetRasterAttribution, i as MapSheetPageInput, it as MgrsSnapInterval, j as resolvePaperSize, k as PaperOrientation, l as TacticalMapSheetResult, lt as GridCrs, m as LowRasterDpiWarning, n as CrossZoneFootprintWarning, nt as ResolvedMgrsGridMetadata, o as ScaleDeviationWarning, p as createTacticalMapSheet, pt as Position, q as ControlledVectorSymbol, r as MapSheetFontIdentity, rt as MgrsPrecision, s as TacticalMapSheetRequest, st as SceneRectangle, t as CrossProjectionFootprintWarning, tt as MgrsGridOptions, u as TacticalMapSheetWarning, ut as UpsCrs, v as MapSheetRasterTile, w as PrinterCalibrationRequest, x as ResolvedMapSheetRasterBasemapMetadata, y as MapSheetRasterWarning, z as PointSymbolFallbackWarning } from "./create-tactical-map-sheet-CYvzCyFD.mjs";
2
2
 
3
3
  //#region src/mgrs.d.ts
4
4
  interface ProjectedGridCoordinate {
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as geographicToMgrs, c as normalizeMgrsReference, d as snapGeographicToMgrs, f as snapProjectedToMgrs, i as resolveMapSheetRasterPlan, l as parseMgrsReference, o as mgrsToGeographic, p as prepareMapSheetNotes, r as mapSheetRasterPointToGeographic, s as mgrsToProjected, t as createTacticalMapSheet, u as projectedToMgrs } from "./create-tactical-map-sheet-DVr96Nie.mjs";
1
+ import { a as geographicToMgrs, c as normalizeMgrsReference, d as snapGeographicToMgrs, f as snapProjectedToMgrs, i as resolveMapSheetRasterPlan, l as parseMgrsReference, o as mgrsToGeographic, p as prepareMapSheetNotes, r as mapSheetRasterPointToGeographic, s as mgrsToProjected, t as createTacticalMapSheet, u as projectedToMgrs } from "./create-tactical-map-sheet-nkwRfvRc.mjs";
2
2
  //#region src/paper.ts
3
3
  const A0 = Object.freeze({
4
4
  widthMm: 841,
package/dist/pdf.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as ResolvedMapSheetMetadata, c as TacticalMapSheetResources, ft as Polygon, l as TacticalMapSheetResult, ot as MillimetreScene, s as TacticalMapSheetRequest, u as TacticalMapSheetWarning } from "./create-tactical-map-sheet-aMfOzCpu.mjs";
1
+ import { a as ResolvedMapSheetMetadata, c as TacticalMapSheetResources, ft as Polygon, l as TacticalMapSheetResult, ot as MillimetreScene, s as TacticalMapSheetRequest, u as TacticalMapSheetWarning } from "./create-tactical-map-sheet-CYvzCyFD.mjs";
2
2
 
3
3
  //#region src/pdf.d.ts
4
4
  interface TacticalMapSheetPdfResult {
package/dist/pdf.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as openSansCentralBaselineOffset, g as POINTS_PER_MILLIMETRE, h as MILLIMETRES_PER_CSS_PIXEL, m as formatDecimal, n as createTacticalMapSheetDocument, v as openSansMiddleBaselineOffset } from "./create-tactical-map-sheet-DVr96Nie.mjs";
1
+ import { _ as openSansCentralBaselineOffset, g as POINTS_PER_MILLIMETRE, h as MILLIMETRES_PER_CSS_PIXEL, m as formatDecimal, n as createTacticalMapSheetDocument, v as openSansMiddleBaselineOffset } from "./create-tactical-map-sheet-nkwRfvRc.mjs";
2
2
  import { jsPDF } from "jspdf";
3
3
  //#region src/pdf-transparency.ts
4
4
  const FORM_DICTIONARY_MARKER = new TextEncoder().encode("/Subtype /Form\n/BBox");
@@ -140,7 +140,7 @@ function applyStroke(pdf, paint) {
140
140
  pdf.setLineJoin(paint.lineJoin);
141
141
  pdf.setLineDashPattern([...paint.dash], 0);
142
142
  }
143
- function paintPath(pdf, paint, patternKey) {
143
+ function paintPath(pdf, paint, patternKey, evenOdd = false) {
144
144
  const fill = paint.fill ? pdfColor(paint.fill) : void 0;
145
145
  const stroke = paint.stroke ? pdfColor(paint.stroke) : void 0;
146
146
  if (fill) pdf.setFillColor(fill.color);
@@ -153,8 +153,10 @@ function paintPath(pdf, paint, patternKey) {
153
153
  "stroke-opacity": paint.opacity * paint.strokeOpacity * (stroke?.alpha ?? 1)
154
154
  }));
155
155
  const pattern = patternKey ? { key: patternKey } : void 0;
156
- if ((paint.fill || pattern) && paint.stroke) pdf.fillStroke(pattern);
157
- else if (paint.fill || pattern) pdf.fill(pattern);
156
+ if ((paint.fill || pattern) && paint.stroke) if (evenOdd) pdf.fillStrokeEvenOdd(pattern);
157
+ else pdf.fillStroke(pattern);
158
+ else if (paint.fill || pattern) if (evenOdd) pdf.fillEvenOdd(pattern);
159
+ else pdf.fill(pattern);
158
160
  else if (paint.stroke) pdf.stroke();
159
161
  else pdf.discardPath();
160
162
  }
@@ -577,22 +579,14 @@ function renderElement(pdf, element, formIds) {
577
579
  pdf.restoreGraphicsState();
578
580
  return;
579
581
  }
580
- const [first, ...rest] = element.points;
581
- if (!first) throw new Error("Cannot serialize an empty path");
582
- pdf.path([
583
- {
584
- op: "m",
585
- c: [first.xMm, first.yMm]
586
- },
587
- ...rest.map((point) => ({
588
- op: "l",
589
- c: [point.xMm, point.yMm]
590
- })),
591
- ...element.closed ? [{
592
- op: "h",
593
- c: []
594
- }] : []
595
- ]);
582
+ if (element.points.length === 0) throw new Error("Cannot serialize an empty path");
583
+ pdf.path([element.points, ...element.holes ?? []].flatMap((ring, ringIndex) => [...ring.map((point, index) => ({
584
+ op: index === 0 ? "m" : "l",
585
+ c: [point.xMm, point.yMm]
586
+ })), ...ringIndex > 0 || element.closed ? [{
587
+ op: "h",
588
+ c: []
589
+ }] : []]));
596
590
  paintPath(pdf, {
597
591
  ...DEFAULT_VECTOR_PAINT,
598
592
  fill: element.fillColor,
@@ -602,7 +596,7 @@ function renderElement(pdf, element, formIds) {
602
596
  lineCap: element.lineCap,
603
597
  lineJoin: element.lineJoin,
604
598
  dash: element.strokeDashMm
605
- }, element.fillPatternId);
599
+ }, element.fillPatternId, element.holes !== void 0);
606
600
  }
607
601
  function patternPaint(paint) {
608
602
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbat-mapper/tactical-map-sheet",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "Scale-accurate projected vector tactical map-sheet renderer.",
5
5
  "license": "MIT",
6
6
  "author": "Orbat Mapper",
@@ -30,8 +30,8 @@
30
30
  "jspdf": "4.2.1",
31
31
  "opentype.js": "2.0.0",
32
32
  "saxes": "6.0.0",
33
- "@orbat-mapper/control-measures": "^0.46.0",
34
33
  "@orbat-mapper/tactical-draw": "^0.32.0",
34
+ "@orbat-mapper/control-measures": "^0.46.0",
35
35
  "@orbat-mapper/tactical-notes": "^0.2.0"
36
36
  },
37
37
  "devDependencies": {