@mark1russell7/cartography 0.1.0 → 0.1.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/README.md CHANGED
@@ -48,6 +48,8 @@ const svg = renderMap(map);
48
48
  | `attributionLines(map)` | The lines of the attribution block: the scale, the projection and each source. |
49
49
  | `scaleBarLength(meters, units)` | The longest round length of a scale bar that is not longer than a length on the ground. |
50
50
  | `mapLabels(map, options)` | The labels of the map with their places, and the texts with no place. |
51
+ | `mapMargins(map, options)` | The space of the SVG around the frame: the column at the right, the block below, and the least height of the frame. |
52
+ | `fitFrame(map, spaces, options)` | The frame with the largest area in one of a list of spaces, for example a paper, and the place of its legend. |
51
53
  | `placeLabels(layers, view, font)` | The places of the labels of the layers, with no overlap, inside the frame. |
52
54
  | `labelText(rule, feature)` | The text of the label of a feature, or `undefined`. |
53
55
 
@@ -90,3 +92,20 @@ const svg = renderMap({ ...map, layers: [roads] }, { labelFont });
90
92
  ## License
91
93
 
92
94
  MIT
95
+
96
+ ## A map that fills a paper
97
+
98
+ `fitFrame` gives the frame with the largest area in one of a list of spaces, and the place of the legend. The scale does not change, so a larger frame shows more ground.
99
+
100
+ ```ts
101
+ // A paper of 24 by 36 in with a margin of 0.5 in, upright and in landscape, below a heading of 50 mm.
102
+ const spaces = [{ widthMm: 584.2, heightMm: 889 - 50 }, { widthMm: 889, heightMm: 584.2 - 50 }];
103
+ const fit = fitFrame(map, spaces, { labelFont });
104
+ const frame = { ...map.frame, widthMm: fit.widthMm, heightMm: fit.heightMm };
105
+ const svg = renderMap({ ...map, frame, legendPlace: fit.legendPlace }, { labelFont });
106
+ ```
107
+
108
+ - The place `below` puts the scale bars and the legend in two columns below the frame. This is the default.
109
+ - The place `side` puts them in one column at the right of the frame. The attribution block stays below the frame.
110
+ - `mapMargins` gives the space around the frame for each place. The label font measures the legend texts.
111
+ - `fit.space` is the index of the space of the frame. In this example, the value 1 tells to print the map in landscape.
package/dist/index.d.ts CHANGED
@@ -337,7 +337,11 @@ interface MapDocument {
337
337
  readonly scaleBar?: ScaleBarUnits;
338
338
  /** The value `false` gives no north arrow. The default is `true`. */
339
339
  readonly northArrow?: boolean;
340
+ /** The place of the scale bars and the legend. The default is `below`. `fitFrame` finds the place with the largest frame. */
341
+ readonly legendPlace?: LegendPlace;
340
342
  }
343
+ /** The place of the scale bars and the legend: below the frame, or in a column at the right side of the frame. */
344
+ type LegendPlace = "below" | "side";
341
345
  /**
342
346
  * This function examines a map. It refuses a frame, an identifier, a style, a filter or a source that is not correct.
343
347
  * Each layer must have a source with a title and a license, so the attribution block names each source of the map.
@@ -357,12 +361,65 @@ interface RenderOptions {
357
361
  * @throws MapError - The map is not correct, as `checkMap` tells, or a layer has labels and the options have no font.
358
362
  */
359
363
  export declare function mapLabels(map: MapDocument, options?: RenderOptions): LabelPlacement;
364
+ /** The space of the SVG of a map around its frame, in millimetres. */
365
+ interface MapMargins {
366
+ /** The width at the right of the frame: the gap and the column of the legend at the side, or 0. */
367
+ readonly rightMm: number;
368
+ /** The height below the frame: the legend below the frame, if it is there, and the attribution block. */
369
+ readonly belowMm: number;
370
+ /** The height of the column of the legend at the side, or 0. A frame with less height makes the SVG taller. */
371
+ readonly leastHeightMm: number;
372
+ }
373
+ /**
374
+ * This function gives the space of the SVG of a map around its frame, for the place of the legend of the map. The
375
+ * size of the frame does not change it.
376
+ *
377
+ * - The label font of the options measures the legend texts. With no font, each character is 0.6 of the size of the font.
378
+ * - The SVG of the map is `rightMm` wider and `belowMm` taller than its frame.
379
+ *
380
+ * @throws MapError - The map is not correct, as `checkMap` tells.
381
+ */
382
+ export declare function mapMargins(map: MapDocument, options?: RenderOptions): MapMargins;
383
+ /** A space for the SVG of a map, in millimetres, for example the printable area of a paper below a heading. */
384
+ interface MapSpace {
385
+ readonly widthMm: number;
386
+ readonly heightMm: number;
387
+ }
388
+ /** The options of `fitFrame`. */
389
+ interface FitOptions {
390
+ /** The font of the labels. It also measures the legend texts. */
391
+ readonly labelFont?: LabelFont;
392
+ /** The places of the legend to examine. The default is `below` and `side`. */
393
+ readonly places?: readonly LegendPlace[];
394
+ }
395
+ /** The frame with the largest area for a map in one of a list of spaces. */
396
+ interface FrameFit {
397
+ readonly widthMm: number;
398
+ readonly heightMm: number;
399
+ readonly legendPlace: LegendPlace;
400
+ /** The index of the space of the frame in the list of spaces. */
401
+ readonly space: number;
402
+ }
403
+ /**
404
+ * This function gives the frame with the largest area for a map in one of a list of spaces, and the place of its
405
+ * legend. The SVG of the map with that frame and that place fits that space.
406
+ *
407
+ * - Give one space for each choice of the caller, for example a paper upright and the same paper in landscape.
408
+ * - The scale of the map does not change, so a larger frame shows more ground.
409
+ * - The size of the frame of the map does not change the result.
410
+ * - With two choices of equal area, the first place of the options wins, and then the first space.
411
+ *
412
+ * @throws MapError - The map is not correct, a place or a space is not correct, or no choice leaves space for a frame.
413
+ */
414
+ export declare function fitFrame(map: MapDocument, spaces: readonly MapSpace[], options?: FitOptions): FrameFit;
360
415
  /** This function gives the lines of the attribution block: the scale, the projection and each source one time. */
361
416
  export declare function attributionLines(map: MapDocument): string[];
362
417
  /**
363
418
  * This function gives the SVG of a map. The units of the SVG are millimetres, for a print at the scale of the frame.
364
419
  *
365
420
  * - The map is at the top. Below it are the scale bars, the legend and the attribution block.
421
+ * - With the place `side`, the scale bars and the legend are in a column at the right of the frame. The attribution
422
+ * block stays below.
366
423
  * - The layers are in their sequence, from the bottom to the top. The frame clips each layer.
367
424
  * - A feature that is not on the frame is not in the SVG.
368
425
  * - Each identifier in the SVG starts with the identifier of the map. Thus two maps can be in one HTML page.
@@ -373,5 +430,5 @@ export declare function attributionLines(map: MapDocument): string[];
373
430
  * @throws GeoError - A position is not correct for the projection.
374
431
  */
375
432
  export declare function renderMap(map: MapDocument, options?: RenderOptions): string;
376
- export type { FillStyle, Filter, FilterValue, Frame, FrameView, GeometryKind, HatchStyle, LabelFont, LabelLayer, LabelPlacement, LabelRule, Layer, MapDocument, MapErrorCode, PaperPoint, PlacedLabel, PointStyle, PointSymbol, RenderOptions, ScaleBarLength, ScaleBarUnits, Source, StrokeStyle, Style };
433
+ export type { FillStyle, Filter, FilterValue, FitOptions, Frame, FrameFit, FrameView, GeometryKind, HatchStyle, LabelFont, LabelLayer, LabelPlacement, LabelRule, Layer, LegendPlace, MapDocument, MapErrorCode, MapMargins, MapSpace, PaperPoint, PlacedLabel, PointStyle, PointSymbol, RenderOptions, ScaleBarLength, ScaleBarUnits, Source, StrokeStyle, Style };
377
434
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/errors.ts","../src/filter.ts","../src/frame.ts","../src/labels.ts","../src/marks.ts","../src/style.ts","../src/render.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;KAeY;;qBAGC,iBAAiB;;WAEnB,MAAM;;;;;EAMf,YAAY,MAAM,cAAc;;;KChBtB;;KAGA;;;;;;;;;KAUA;WACG,cAAc;;WACd,cAAc;;WACd,KAAK;;WACL;WAA2B,aAAa;;WACxC;WAA2B;;WAC3B,UAAU;;;wBAGT,aAAa,UAAU,WAAW;;wBAmBlC,cAAc,QAAQ,QAAQ,SAAS;;;;;;wBAkBvC,YAAY,iBAAiB,wBAA0B,UAAU;;UC1DhE;;WAEN,YAAY;;WAEZ,QAAQ;;WAER;;WAEA;;WAEA;;;UAIM;;WAEN;;WAEA;;;UAIM;;WAEN,OAAO;;WAEP;;WAEA;;WAEA,UAAU,OAAO,WAAW;;WAE5B,YAAY,OAAO,eAAe;;WAElC;;;wBAIK,WAAW,OAAO;;;;;;;;;;;;wBAqBlB,UAAU,OAAO,QAAQ;;;;;;;wBA2BzB,UAAU,OAAO,QAAQ;;UCpFxB;;WAEN;;WAEA;;WAEA;;WAEA;;;UAIM;;WAEN;;WAEA,UAAU,cAAc;;;UAIlB;;WAEN;WACA;;WAEA;WACA;;WAEA;WACA;WACA;;;UAIM;WACN,iBAAiB;;WAEjB;aAA6B;aAAwB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EN;;WAEA;;WAEA;;;UAIM;;WAEN;;WAEA;;WAEA;;WAEA;;;UAIM;;WAEN;;WAEA,QAAQ;;;KAIP;;UAGK;;WAEN,QAAQ;;WAER;;WAEA;;;UAIM;;WAEN,SAAS;;WAET,OAAO;;WAEP,QAAQ;;;;;;;wBAuBH,WAAW,OAAO,OAAO;;wBA6BzB,GAAG;;wBAKH,UAAU;;wBAQV,iBAAiB,QAAQ;;wBAMzB,aAAa,YAAY,OAAO;;wBAYhC,YAAY,OAAO,YAAY,WAAW;;UChIzC;;WAEN;;WAEA;;WAEA;;WAEA;;;UAIM;;WAEN;;WAEA,mBAAmB;;WAEnB,OAAO;;WAEP,QAAQ;;WAER,SAAS;;WAET;;WAEA;;WAEA,QAAQ;;;UAIF;;WAEN;;WAEA;;WAEA,OAAO;;WAEP,iBAAiB;;WAEjB,WAAW;;WAEX;;WAEA,cAAc;;;KAIb;;;;;;;wBAsBI,SAAS,KAAK;;UAkHb;;WAEN,YAAY;;;;;;;;wBA4BP,UAAU,KAAK,aAAa,UAAS,gBAAqB;;UA4EzD;;WAEN;;WAEA;;WAEA;;;;;;;;;;;wBAoBK,WAAW,KAAK,aAAa,UAAS,gBAAqB;;UAM1D;WACN;WACA;;;UAIM;;WAEN,YAAY;;WAEZ,kBAAkB;;;UAIZ;WACN;WACA;WACA,aAAa;;WAEb;;;;;;;;;;;;;wBAcK,SAAS,KAAK,aAAa,iBAAiB,YAAY,UAAS,aAAkB;;wBA2BnF,iBAAiB,KAAK;;;;;;;;;;;;;;;;wBA2BtB,UAAU,KAAK,aAAa,UAAS"}
package/dist/index.js CHANGED
@@ -717,6 +717,7 @@ function northArrowSvg(x, y, northDegrees) {
717
717
  *
718
718
  * @packageDocumentation
719
719
  */
720
+ const LEGEND_PLACES = ["below", "side"];
720
721
  const ID = /^[a-z][a-z0-9-]*$/;
721
722
  function checkId(id, what) {
722
723
  if (!ID.test(id)) throw new MapError("id", `The identifier "${id}" of the ${what} is not lower case letters, digits and hyphens that start with a letter`);
@@ -735,6 +736,7 @@ function checkSource(source, layer) {
735
736
  function checkMap(map) {
736
737
  checkId(map.id, "map");
737
738
  frameView(map.frame);
739
+ if (map.legendPlace !== void 0 && !LEGEND_PLACES.includes(map.legendPlace)) throw new MapError("style", `The place of the legend "${String(map.legendPlace)}" is not "below" or "side"`);
738
740
  const ids = /* @__PURE__ */ new Set();
739
741
  for (const layer of map.layers) {
740
742
  checkId(layer.id, "layer");
@@ -877,6 +879,110 @@ function swatch(style, x, y, fill) {
877
879
  function thousands(value) {
878
880
  return String(Math.round(value)).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
879
881
  }
882
+ /** The space between the frame and the column of the legend at the side, in millimetres. */
883
+ const SIDE_GAP_MM = 3;
884
+ /** The space above the first row of the column of the legend at the side, in millimetres. */
885
+ const SIDE_TOP_MM = 1;
886
+ /** The least width of the column of the legend at the side, in millimetres. */
887
+ const SIDE_LEAST_WIDTH_MM = 30;
888
+ /** The space between the scale bars and the legend in the column at the side, in millimetres. */
889
+ const SIDE_GROUP_GAP_MM = 1.5;
890
+ /** The space at the right of a scale bar in the column at the side for its label, in millimetres. */
891
+ const SCALE_LABEL_MM = 12;
892
+ /** The size of the font of the legend texts, in millimetres. */
893
+ const LEGEND_TEXT_MM = 2.4;
894
+ /** The distance from the left side of a swatch to its text, in millimetres. */
895
+ const LEGEND_TEXT_X_MM = 7.5;
896
+ /** The width of a character of a legend text, as a part of the size of the font, when the options have no font. */
897
+ const CHARACTER_WIDTH = .6;
898
+ /** This function gives the font that measures the legend texts: the label font of the options, if it has a measure. */
899
+ function measureFontOf(options) {
900
+ const font = options.labelFont;
901
+ return font !== void 0 && typeof font.measure === "function" ? font : void 0;
902
+ }
903
+ function legendLayout(map, font) {
904
+ const units = map.scaleBar ?? "both";
905
+ const bars = units === "none" ? [] : units === "both" ? ["metric", "imperial"] : [units];
906
+ const texts = map.layers.flatMap((layer) => layer.legend === void 0 ? [] : [layer.legend]);
907
+ const lines = attributionLines(map);
908
+ const place = map.legendPlace ?? "below";
909
+ if (place === "below" || bars.length + texts.length === 0) return {
910
+ bars,
911
+ lines,
912
+ columnMm: 0,
913
+ columnHeightMm: 0,
914
+ blockMm: place === "below" ? Math.max(bars.length, Math.ceil(texts.length / 2)) * SCALE_BAR_ROW_MM : 0
915
+ };
916
+ const width = (text) => font === void 0 ? text.length * LEGEND_TEXT_MM * CHARACTER_WIDTH : font.measure(text, LEGEND_TEXT_MM);
917
+ const widest = Math.max(0, ...texts.map(width));
918
+ const columnMm = Math.max(SIDE_LEAST_WIDTH_MM, LEGEND_TEXT_X_MM + widest + 1);
919
+ const gap = bars.length > 0 && texts.length > 0 ? SIDE_GROUP_GAP_MM : 0;
920
+ return {
921
+ bars,
922
+ lines,
923
+ columnMm,
924
+ columnHeightMm: SIDE_TOP_MM + (bars.length + texts.length) * SCALE_BAR_ROW_MM + gap,
925
+ blockMm: 0
926
+ };
927
+ }
928
+ function marginsOf(layout) {
929
+ return {
930
+ rightMm: layout.columnMm === 0 ? 0 : SIDE_GAP_MM + layout.columnMm,
931
+ belowMm: 2 + layout.blockMm + 2.5 + (layout.lines.length - 1) * 3 + 1.5,
932
+ leastHeightMm: layout.columnHeightMm
933
+ };
934
+ }
935
+ /**
936
+ * This function gives the space of the SVG of a map around its frame, for the place of the legend of the map. The
937
+ * size of the frame does not change it.
938
+ *
939
+ * - The label font of the options measures the legend texts. With no font, each character is 0.6 of the size of the font.
940
+ * - The SVG of the map is `rightMm` wider and `belowMm` taller than its frame.
941
+ *
942
+ * @throws MapError - The map is not correct, as `checkMap` tells.
943
+ */
944
+ function mapMargins(map, options = {}) {
945
+ checkMap(map);
946
+ return marginsOf(legendLayout(map, measureFontOf(options)));
947
+ }
948
+ /**
949
+ * This function gives the frame with the largest area for a map in one of a list of spaces, and the place of its
950
+ * legend. The SVG of the map with that frame and that place fits that space.
951
+ *
952
+ * - Give one space for each choice of the caller, for example a paper upright and the same paper in landscape.
953
+ * - The scale of the map does not change, so a larger frame shows more ground.
954
+ * - The size of the frame of the map does not change the result.
955
+ * - With two choices of equal area, the first place of the options wins, and then the first space.
956
+ *
957
+ * @throws MapError - The map is not correct, a place or a space is not correct, or no choice leaves space for a frame.
958
+ */
959
+ function fitFrame(map, spaces, options = {}) {
960
+ checkMap(map);
961
+ for (const { widthMm, heightMm } of spaces) if (![widthMm, heightMm].every((value) => Number.isFinite(value) && value > 0)) throw new MapError("frame", `The space ${widthMm} by ${heightMm} mm is not two finite numbers more than 0`);
962
+ const places = options.places ?? LEGEND_PLACES;
963
+ const font = measureFontOf(options);
964
+ let best;
965
+ for (const place of places) {
966
+ if (!LEGEND_PLACES.includes(place)) throw new MapError("style", `The place of the legend "${String(place)}" is not "below" or "side"`);
967
+ const margins = marginsOf(legendLayout({
968
+ ...map,
969
+ legendPlace: place
970
+ }, font));
971
+ for (const [index, { widthMm, heightMm }] of spaces.entries()) {
972
+ const frameWidth = widthMm - margins.rightMm;
973
+ const frameHeight = heightMm - margins.belowMm;
974
+ if (!(frameWidth > 0 && frameHeight > 0 && frameHeight >= margins.leastHeightMm)) continue;
975
+ if (best === void 0 || frameWidth * frameHeight > best.widthMm * best.heightMm) best = {
976
+ widthMm: frameWidth,
977
+ heightMm: frameHeight,
978
+ legendPlace: place,
979
+ space: index
980
+ };
981
+ }
982
+ }
983
+ if (best === void 0) throw new MapError("frame", "No space of the list has space for a frame after the legend");
984
+ return best;
985
+ }
880
986
  /** This function gives the lines of the attribution block: the scale, the projection and each source one time. */
881
987
  function attributionLines(map) {
882
988
  const lines = [`Scale 1:${thousands(map.frame.scale)} at the center. Projection: ${map.frame.projection.name}.`];
@@ -893,6 +999,8 @@ function attributionLines(map) {
893
999
  * This function gives the SVG of a map. The units of the SVG are millimetres, for a print at the scale of the frame.
894
1000
  *
895
1001
  * - The map is at the top. Below it are the scale bars, the legend and the attribution block.
1002
+ * - With the place `side`, the scale bars and the legend are in a column at the right of the frame. The attribution
1003
+ * block stays below.
896
1004
  * - The layers are in their sequence, from the bottom to the top. The frame clips each layer.
897
1005
  * - A feature that is not on the frame is not in the SVG.
898
1006
  * - Each identifier in the SVG starts with the identifier of the map. Thus two maps can be in one HTML page.
@@ -921,29 +1029,34 @@ function renderMap(map, options = {}) {
921
1029
  return `<g id="${map.id}-${layer.id}">${body}</g>`;
922
1030
  });
923
1031
  const labels = font === void 0 ? "" : labelsSvg(placementOf(map, features, view, font), font);
924
- const top = h + 2;
925
- const units = map.scaleBar ?? "both";
926
- const bars = units === "none" ? [] : units === "both" ? ["metric", "imperial"] : [units];
927
- const maxMeters = .3 * w / view.mmPerMeter;
928
- const scaleBars = bars.map((unit, i) => scaleBarSvg(.5, top + i * SCALE_BAR_ROW_MM, scaleBarLength(maxMeters, unit), view.mmPerMeter)).join("");
1032
+ const layout = legendLayout(map, measureFontOf(options));
1033
+ const side = layout.columnMm > 0;
1034
+ const { bars, lines } = layout;
1035
+ const top = (side ? Math.max(h, layout.columnHeightMm) : h) + 2;
1036
+ const sideX = w + SIDE_GAP_MM;
1037
+ const maxMeters = (side ? layout.columnMm - SCALE_LABEL_MM : .3 * w) / view.mmPerMeter;
1038
+ const scaleBars = bars.map((unit, i) => {
1039
+ const length = scaleBarLength(maxMeters, unit);
1040
+ return side ? scaleBarSvg(sideX, SIDE_TOP_MM + i * SCALE_BAR_ROW_MM, length, view.mmPerMeter) : scaleBarSvg(.5, top + i * SCALE_BAR_ROW_MM, length, view.mmPerMeter);
1041
+ }).join("");
929
1042
  const legendLayers = map.layers.flatMap((layer, i) => layer.legend === void 0 ? [] : [{
930
1043
  layer,
931
1044
  fill: fills[i]
932
1045
  }]);
933
1046
  const columnWidth = w * .275;
1047
+ const sideTop = SIDE_TOP_MM + bars.length * SCALE_BAR_ROW_MM + (bars.length > 0 ? SIDE_GROUP_GAP_MM : 0);
934
1048
  const legend = legendLayers.map(({ layer, fill }, i) => {
935
- const x = w * .45 + i % 2 * columnWidth;
936
- const y = top + Math.floor(i / 2) * SCALE_BAR_ROW_MM - 1;
937
- return `${swatch(layer.style, x, y, fill)}<text x="${mm(x + 7.5)}" y="${mm(y + 2.9)}" font-size="2.4">${escapeHtml(layer.legend)}</text>`;
1049
+ const x = side ? sideX : w * .45 + i % 2 * columnWidth;
1050
+ const y = side ? sideTop + i * SCALE_BAR_ROW_MM : top + Math.floor(i / 2) * SCALE_BAR_ROW_MM - 1;
1051
+ return `${swatch(layer.style, x, y, fill)}<text x="${mm(x + LEGEND_TEXT_X_MM)}" y="${mm(y + 2.9)}" font-size="${LEGEND_TEXT_MM}">${escapeHtml(layer.legend)}</text>`;
938
1052
  }).join("");
939
- const blockHeight = Math.max(bars.length, Math.ceil(legendLayers.length / 2)) * SCALE_BAR_ROW_MM;
940
- const lines = attributionLines(map);
941
- const firstLine = top + blockHeight + 2.5;
1053
+ const firstLine = top + layout.blockMm + 2.5;
942
1054
  const attribution = lines.map((line, i) => `<text x="0.5" y="${mm(firstLine + i * 3)}" font-size="2.2">${escapeHtml(line)}</text>`).join("");
943
1055
  const total = firstLine + (lines.length - 1) * 3 + 1.5;
1056
+ const width = side ? sideX + layout.columnMm : w;
944
1057
  const arrow = map.northArrow === false ? "" : northArrowSvg(w - 6.5, 6.5, view.northDegrees);
945
- return `<svg xmlns="http://www.w3.org/2000/svg" width="${mm(w)}mm" height="${mm(total)}mm" viewBox="0 0 ${mm(w)} ${mm(total)}" role="img" aria-label="${escapeAttribute(map.title)}" font-family="sans-serif"><title>${escapeHtml(map.title)}</title><defs>${defs.join("")}</defs><rect width="${mm(w)}" height="${mm(total)}" fill="#ffffff"/><g clip-path="url(#${map.id}-clip)">${layers.join("")}</g>${labels}<rect width="${mm(w)}" height="${mm(h)}" fill="none" stroke="#000000" stroke-width="0.3"/>${arrow}<g class="legend">${scaleBars}${legend}</g><g class="attribution">${attribution}</g></svg>`;
1058
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${mm(width)}mm" height="${mm(total)}mm" viewBox="0 0 ${mm(width)} ${mm(total)}" role="img" aria-label="${escapeAttribute(map.title)}" font-family="sans-serif"><title>${escapeHtml(map.title)}</title><defs>${defs.join("")}</defs><rect width="${mm(width)}" height="${mm(total)}" fill="#ffffff"/><g clip-path="url(#${map.id}-clip)">${layers.join("")}</g>${labels}<rect width="${mm(w)}" height="${mm(h)}" fill="none" stroke="#000000" stroke-width="0.3"/>${arrow}<g class="legend">${scaleBars}${legend}</g><g class="attribution">${attribution}</g></svg>`;
946
1059
  }
947
- export { MapError, SCALE_BAR_ROW_MM, attributionLines, checkFilter, checkFrame, checkLabelRule, checkMap, checkStyle, frameBBox, frameView, geometryKind, grayColor, hatchPattern, labelText, labelsSvg, mapLabels, matchesFilter, mm, niceNumber, northArrowSvg, placeLabels, pointSymbol, renderMap, scaleBarLength, scaleBarSvg, strokeAttributes };
1060
+ export { MapError, SCALE_BAR_ROW_MM, attributionLines, checkFilter, checkFrame, checkLabelRule, checkMap, checkStyle, fitFrame, frameBBox, frameView, geometryKind, grayColor, hatchPattern, labelText, labelsSvg, mapLabels, mapMargins, matchesFilter, mm, niceNumber, northArrowSvg, placeLabels, pointSymbol, renderMap, scaleBarLength, scaleBarSvg, strokeAttributes };
948
1061
 
949
1062
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["paperOf"],"sources":["../src/errors.ts","../src/filter.ts","../src/frame.ts","../src/style.ts","../src/labels.ts","../src/marks.ts","../src/render.ts"],"sourcesContent":["/**\n * The error of this package. Each refusal has a code, so a caller can test the reason without the text of the message.\n *\n * @packageDocumentation\n */\n\n/**\n * The reason of a refusal.\n *\n * - `frame`: the scale or the size of a frame is not a finite number more than 0.\n * - `id`: an identifier is not lower case letters, digits and hyphens, or two layers have the same identifier.\n * - `filter`: a filter is not one of the forms of `Filter`.\n * - `style`: a style draws nothing, or a size, a gray level or a dash is not correct.\n * - `source`: a layer has no source, or its source has no title or no license.\n */\nexport type MapErrorCode = \"frame\" | \"id\" | \"filter\" | \"style\" | \"source\" | \"label\";\n\n/** The error that each function of this package throws for an incorrect map. */\nexport class MapError extends Error {\n /** The reason of the refusal. */\n readonly code: MapErrorCode;\n\n /**\n * @param code - The reason of the refusal.\n * @param message - The text for a person.\n */\n constructor(code: MapErrorCode, message: string) {\n super(message);\n this.name = \"MapError\";\n this.code = code;\n }\n}\n","/**\n * The filters of the layers. A filter is data, so a map document can be JSON.\n *\n * @packageDocumentation\n */\n\nimport type { Feature, Geometry } from \"@mark1russell7/geo\";\nimport { MapError } from \"./errors.ts\";\n\n/** A value that a filter compares with a property of a feature. */\nexport type FilterValue = string | number | boolean;\n\n/** The kind of a geometry: points, lines or areas. A collection of two kinds is `mixed`. */\nexport type GeometryKind = \"point\" | \"line\" | \"area\" | \"mixed\";\n\n/**\n * A filter of the features of a layer.\n *\n * - `{ all }` matches when each filter matches. `{ any }` matches when one filter matches. `{ not }` reverses a filter.\n * - `{ property, in }` matches a feature whose property is equal to one of the values.\n * - `{ property, exists }` matches a feature that has the property, or that does not have it.\n * - `{ geometry }` matches a feature whose geometry has the kind.\n */\nexport type Filter =\n | { readonly all: readonly Filter[] }\n | { readonly any: readonly Filter[] }\n | { readonly not: Filter }\n | { readonly property: string; readonly in: readonly FilterValue[] }\n | { readonly property: string; readonly exists: boolean }\n | { readonly geometry: GeometryKind };\n\n/** This function gives the kind of a geometry. */\nexport function geometryKind(geometry: Geometry): GeometryKind {\n switch (geometry.type) {\n case \"Point\":\n case \"MultiPoint\":\n return \"point\";\n case \"LineString\":\n case \"MultiLineString\":\n return \"line\";\n case \"Polygon\":\n case \"MultiPolygon\":\n return \"area\";\n case \"GeometryCollection\": {\n const kinds = new Set(geometry.geometries.map(geometryKind));\n return kinds.size === 1 ? ([...kinds][0] as GeometryKind) : \"mixed\";\n }\n }\n}\n\n/** This function tells if a feature matches a filter. A feature with no geometry matches no `{ geometry }` filter. */\nexport function matchesFilter(filter: Filter, feature: Feature): boolean {\n if (\"all\" in filter) return filter.all.every((item) => matchesFilter(item, feature));\n if (\"any\" in filter) return filter.any.some((item) => matchesFilter(item, feature));\n if (\"not\" in filter) return !matchesFilter(filter.not, feature);\n if (\"geometry\" in filter) return feature.geometry !== null && geometryKind(feature.geometry) === filter.geometry;\n const properties = feature.properties ?? {};\n const has = Object.hasOwn(properties, filter.property);\n if (\"exists\" in filter) return has === filter.exists;\n return has && filter.in.includes(properties[filter.property] as FilterValue);\n}\n\nconst KINDS: readonly string[] = [\"point\", \"line\", \"area\", \"mixed\"];\n\n/**\n * This function refuses a value that is not a `Filter`, for example a filter from JSON.\n *\n * @throws MapError - The code is `filter`.\n */\nexport function checkFilter(filter: unknown, path = \"filter\"): asserts filter is Filter {\n const fail = (reason: string): never => {\n throw new MapError(\"filter\", `${path}: ${reason}`);\n };\n if (typeof filter !== \"object\" || filter === null || Array.isArray(filter)) fail(\"a filter must be an object\");\n const value = filter as Record<string, unknown>;\n const keys = Object.keys(value).toSorted().join(\",\");\n if (keys === \"all\" || keys === \"any\") {\n const items = value[keys];\n if (!Array.isArray(items)) fail(`the member ${keys} must be an array`);\n (items as unknown[]).forEach((item, i) => checkFilter(item, `${path}.${keys}[${i}]`));\n } else if (keys === \"not\") {\n checkFilter(value[\"not\"], `${path}.not`);\n } else if (keys === \"geometry\") {\n if (!KINDS.includes(value[\"geometry\"] as string)) fail(`the geometry must be one of ${KINDS.join(\", \")}`);\n } else if (keys === \"in,property\" || keys === \"exists,property\") {\n if (typeof value[\"property\"] !== \"string\") fail(\"the property must be a string\");\n if (keys === \"exists,property\" && typeof value[\"exists\"] !== \"boolean\") fail(\"the member exists must be true or false\");\n if (keys === \"in,property\") {\n const items = value[\"in\"];\n if (!Array.isArray(items) || !items.every((item) => [\"string\", \"number\", \"boolean\"].includes(typeof item))) {\n fail(\"the member in must be an array of strings, numbers and booleans\");\n }\n }\n } else {\n fail(`the members ${keys === \"\" ? \"(none)\" : keys} are not a form of a filter`);\n }\n}\n","/**\n * The frame of a map: the part of the Earth that the map shows, its scale and its size on the paper.\n *\n * @packageDocumentation\n */\n\nimport { bboxOfPoints, geodesicDirect, type BBox, type LatLon } from \"@mark1russell7/geo\";\nimport type { Projection } from \"@mark1russell7/geo/projection\";\nimport { MapError } from \"./errors.ts\";\n\n/** The frame of a map. The center of the frame is at the middle of the paper. */\nexport interface Frame {\n /** The projection from the Earth to the plane, from `@mark1russell7/geo/projection`. */\n readonly projection: Projection;\n /** The point on the Earth at the middle of the map. */\n readonly center: LatLon;\n /** The denominator of the scale at the center: 24000 for the scale 1:24,000. */\n readonly scale: number;\n /** The width of the map on the paper, in millimetres. */\n readonly widthMm: number;\n /** The height of the map on the paper, in millimetres. */\n readonly heightMm: number;\n}\n\n/** A point on the paper in millimetres, from the top left corner of the map. The y axis points down. */\nexport interface PaperPoint {\n /** The distance to the right, in millimetres. */\n readonly x: number;\n /** The distance down, in millimetres. */\n readonly y: number;\n}\n\n/** The functions of a frame between the Earth and the paper. */\nexport interface FrameView {\n /** The frame. */\n readonly frame: Frame;\n /** The millimetres of paper for one metre on the ground at the center. */\n readonly mmPerMeter: number;\n /** The millimetres of paper for one metre on the plane of the projection. */\n readonly mmPerPlaneMeter: number;\n /** This function gives the point on the paper for a point on the Earth. */\n readonly toPaper: (point: LatLon) => PaperPoint;\n /** This function gives the point on the Earth for a point on the paper. */\n readonly fromPaper: (point: PaperPoint) => LatLon;\n /** The direction of north at the center, in degrees clockwise from the top of the paper. */\n readonly northDegrees: number;\n}\n\n/** This function refuses a frame with a scale or a size that is not a finite number more than 0. */\nexport function checkFrame(frame: Frame): void {\n for (const [name, value] of [\n [\"scale\", frame.scale],\n [\"width\", frame.widthMm],\n [\"height\", frame.heightMm],\n ] as const) {\n if (!(Number.isFinite(value) && value > 0)) throw new MapError(\"frame\", `The ${name} ${value} of the frame is not a finite number more than 0`);\n }\n}\n\n/**\n * This function gives the functions of a frame between the Earth and the paper.\n *\n * - The scale of the frame is the true scale at the center. The function divides by the scale factor of the projection\n * at the center: the square root of `max * min` of `projection.scale`.\n * - For Web Mercator, the scale changes with the latitude. For `azimuthalEquidistant`, it is almost the same on all\n * the map.\n *\n * @throws MapError - The code is `frame`.\n * @throws GeoError - The center is not a correct point for the projection.\n */\nexport function frameView(frame: Frame): FrameView {\n checkFrame(frame);\n const { projection, center } = frame;\n const factors = projection.scale(center);\n const mmPerMeter = 1000 / frame.scale;\n const mmPerPlaneMeter = mmPerMeter / Math.sqrt(factors.max * factors.min);\n const origin = projection.toPlane(center);\n const middleX = frame.widthMm / 2;\n const middleY = frame.heightMm / 2;\n const toPaper = (point: LatLon): PaperPoint => {\n const plane = projection.toPlane(point);\n return { x: middleX + (plane.x - origin.x) * mmPerPlaneMeter, y: middleY - (plane.y - origin.y) * mmPerPlaneMeter };\n };\n const fromPaper = (point: PaperPoint): LatLon =>\n projection.fromPlane({ x: origin.x + (point.x - middleX) / mmPerPlaneMeter, y: origin.y - (point.y - middleY) / mmPerPlaneMeter });\n // The direction of a geodesic of 1 mm on the paper to the north.\n const north = toPaper(geodesicDirect(center, 0, 1 / mmPerMeter).point);\n const northDegrees = (Math.atan2(north.x - middleX, middleY - north.y) * 180) / Math.PI;\n return Object.freeze({ frame, mmPerMeter, mmPerPlaneMeter, toPaper, fromPaper, northDegrees: northDegrees + 0 });\n}\n\n/**\n * This function gives the box on the Earth around the frame, for a fetch of the data of a map. It is the box of 64\n * points on each side of the frame, so it contains the corners and the edges of the frame.\n *\n * @throws MapError - The code is `frame`.\n */\nexport function frameBBox(frame: Frame): BBox {\n const view = frameView(frame);\n const { widthMm: w, heightMm: h } = frame;\n const points: LatLon[] = [];\n const steps = 64;\n for (let i = 0; i < steps; i += 1) {\n const t = i / steps;\n points.push(view.fromPaper({ x: t * w, y: 0 }), view.fromPaper({ x: w, y: t * h }), view.fromPaper({ x: w - t * w, y: h }), view.fromPaper({ x: 0, y: h - t * h }));\n }\n return bboxOfPoints(points) as BBox;\n}\n","/**\n * The black and white styles of the layers: lines with dashes, areas with gray levels and hatches, and point symbols.\n * The print of a map has no color, so each style uses black, white and gray only.\n *\n * @packageDocumentation\n */\n\nimport { MapError } from \"./errors.ts\";\n\n/**\n * A line. The gray level goes from 0 (black) to 1 (white). The default is 0.\n */\nexport interface StrokeStyle {\n /** The width of the line in millimetres. */\n readonly widthMm: number;\n /** The gray level from 0 (black) to 1 (white). The default is 0. */\n readonly gray?: number;\n /** The lengths of the dashes and the gaps in millimetres. No value gives a solid line. */\n readonly dashMm?: readonly number[];\n}\n\n/** Parallel lines in an area. A cross hatch adds the same lines at right angles. */\nexport interface HatchStyle {\n /** The angle of the lines in degrees, clockwise from horizontal. */\n readonly angleDegrees: number;\n /** The distance between two lines in millimetres. It is more than the width of a line. */\n readonly spacingMm: number;\n /** The width of a line in millimetres. */\n readonly widthMm: number;\n /** The value `true` adds the lines at right angles. The default is `false`. */\n readonly cross?: boolean;\n}\n\n/** The fill of an area: a gray level, a hatch, or the two. The hatch is on top of the gray level. */\nexport interface FillStyle {\n /** The gray level from 0 (black) to 1 (white). No value gives no solid fill. */\n readonly gray?: number;\n /** The hatch. No value gives no hatch. */\n readonly hatch?: HatchStyle;\n}\n\n/** The symbols of the points. */\nexport type PointSymbol = \"circle\" | \"square\" | \"triangle\" | \"diamond\" | \"cross\";\n\n/** The symbol of each point. */\nexport interface PointStyle {\n /** The shape of the symbol. */\n readonly symbol: PointSymbol;\n /** The size of the symbol in millimetres. */\n readonly sizeMm: number;\n /** The value `false` gives a white symbol with a black outline. The default is `true`, a black symbol. */\n readonly filled?: boolean;\n}\n\n/** The style of a layer. The line is for the lines and the edges of the areas. The fill is for the areas, and the symbol is for the points. */\nexport interface Style {\n /** The line. */\n readonly stroke?: StrokeStyle;\n /** The fill of the areas. */\n readonly fill?: FillStyle;\n /** The symbol of the points. */\n readonly point?: PointStyle;\n}\n\nconst SYMBOLS: readonly string[] = [\"circle\", \"square\", \"triangle\", \"diamond\", \"cross\"];\n\nfunction positive(value: unknown, name: string, layer: string): void {\n if (!(typeof value === \"number\" && Number.isFinite(value) && value > 0)) {\n throw new MapError(\"style\", `The layer \"${layer}\": the ${name} ${String(value)} is not a finite number more than 0`);\n }\n}\n\nfunction grayLevel(value: unknown, layer: string): void {\n if (value === undefined) return;\n if (!(typeof value === \"number\" && value >= 0 && value <= 1)) {\n throw new MapError(\"style\", `The layer \"${layer}\": the gray level ${String(value)} is not from 0 to 1`);\n }\n}\n\n/**\n * This function refuses a style that draws nothing, and a size, a gray level, a dash or a symbol that is not correct.\n *\n * @throws MapError - The code is `style`.\n */\nexport function checkStyle(style: Style, layer: string): void {\n if (style.stroke === undefined && style.fill === undefined && style.point === undefined) {\n throw new MapError(\"style\", `The layer \"${layer}\": the style has no stroke, no fill and no point, so it draws nothing`);\n }\n if (style.stroke !== undefined) {\n positive(style.stroke.widthMm, \"width of the line\", layer);\n grayLevel(style.stroke.gray, layer);\n for (const dash of style.stroke.dashMm ?? []) positive(dash, \"length of a dash\", layer);\n }\n if (style.fill !== undefined) {\n grayLevel(style.fill.gray, layer);\n if (style.fill.gray === undefined && style.fill.hatch === undefined) {\n throw new MapError(\"style\", `The layer \"${layer}\": the fill has no gray level and no hatch`);\n }\n const hatch = style.fill.hatch;\n if (hatch !== undefined) {\n positive(hatch.widthMm, \"width of a hatch line\", layer);\n positive(hatch.spacingMm, \"spacing of the hatch\", layer);\n if (!Number.isFinite(hatch.angleDegrees)) throw new MapError(\"style\", `The layer \"${layer}\": the angle ${hatch.angleDegrees} is not finite`);\n if (hatch.spacingMm <= hatch.widthMm) throw new MapError(\"style\", `The layer \"${layer}\": the spacing of the hatch is not more than its width`);\n }\n }\n if (style.point !== undefined) {\n positive(style.point.sizeMm, \"size of the symbol\", layer);\n if (!SYMBOLS.includes(style.point.symbol)) throw new MapError(\"style\", `The layer \"${layer}\": the symbol \"${style.point.symbol}\" is not one of ${SYMBOLS.join(\", \")}`);\n }\n}\n\n/** This function gives a number for SVG, to 0.01 mm. */\nexport function mm(value: number): string {\n return String(Math.round(value * 100) / 100 + 0);\n}\n\n/** This function gives the color of a gray level, from `#000000` to `#ffffff`. */\nexport function grayColor(gray: number): string {\n const hex = Math.round(gray * 255)\n .toString(16)\n .padStart(2, \"0\");\n return `#${hex}${hex}${hex}`;\n}\n\n/** This function gives the SVG attributes of a line. */\nexport function strokeAttributes(stroke: StrokeStyle): string {\n const dash = stroke.dashMm === undefined || stroke.dashMm.length === 0 ? \"\" : ` stroke-dasharray=\"${stroke.dashMm.map(mm).join(\" \")}\"`;\n return `stroke=\"${grayColor(stroke.gray ?? 0)}\" stroke-width=\"${mm(stroke.widthMm)}\"${dash} stroke-linecap=\"round\" stroke-linejoin=\"round\"`;\n}\n\n/** This function gives the SVG pattern of a hatch, with an identifier. */\nexport function hatchPattern(id: string, hatch: HatchStyle): string {\n const s = mm(hatch.spacingMm);\n const half = mm(hatch.spacingMm / 2);\n const line = `stroke=\"#000000\" stroke-width=\"${mm(hatch.widthMm)}\"`;\n const across = hatch.cross === true ? `<line x1=\"${half}\" y1=\"0\" x2=\"${half}\" y2=\"${s}\" ${line}/>` : \"\";\n return (\n `<pattern id=\"${id}\" patternUnits=\"userSpaceOnUse\" width=\"${s}\" height=\"${s}\" patternTransform=\"rotate(${mm(hatch.angleDegrees)})\">` +\n `<line x1=\"0\" y1=\"${half}\" x2=\"${s}\" y2=\"${half}\" ${line}/>${across}</pattern>`\n );\n}\n\n/** This function gives the SVG of a point symbol at a point on the paper. */\nexport function pointSymbol(point: PointStyle, x: number, y: number): string {\n const r = point.sizeMm / 2;\n const filled = point.filled !== false;\n const paint = filled ? `fill=\"#000000\"` : `fill=\"#ffffff\" stroke=\"#000000\" stroke-width=\"${mm(point.sizeMm / 8)}\"`;\n switch (point.symbol) {\n case \"circle\":\n return `<circle cx=\"${mm(x)}\" cy=\"${mm(y)}\" r=\"${mm(r)}\" ${paint}/>`;\n case \"square\":\n return `<rect x=\"${mm(x - r)}\" y=\"${mm(y - r)}\" width=\"${mm(2 * r)}\" height=\"${mm(2 * r)}\" ${paint}/>`;\n case \"triangle\":\n return `<path d=\"M${mm(x)} ${mm(y - r)}L${mm(x + r)} ${mm(y + r)}L${mm(x - r)} ${mm(y + r)}Z\" ${paint}/>`;\n case \"diamond\":\n return `<path d=\"M${mm(x)} ${mm(y - r)}L${mm(x + r)} ${mm(y)}L${mm(x)} ${mm(y + r)}L${mm(x - r)} ${mm(y)}Z\" ${paint}/>`;\n case \"cross\":\n return `<path d=\"M${mm(x - r)} ${mm(y)}L${mm(x + r)} ${mm(y)}M${mm(x)} ${mm(y - r)}L${mm(x)} ${mm(y + r)}\" stroke=\"#000000\" stroke-width=\"${mm(point.sizeMm / 5)}\" fill=\"none\"/>`;\n }\n}\n","/**\n * The labels of a map: the names of points, lines and areas, with no overlap.\n *\n * @packageDocumentation\n */\n\nimport { locatePoint, type Feature, type Geometry, type Polygon, type Position } from \"@mark1russell7/geo\";\nimport { escapeAttribute, escapeHtml } from \"@mark1russell7/text\";\nimport { MapError } from \"./errors.ts\";\nimport type { FrameView, PaperPoint } from \"./frame.ts\";\nimport { mm } from \"./style.ts\";\n\n/** The rule of the labels of a layer. */\nexport interface LabelRule {\n /** The properties of a feature, in sequence. The first property with a text that is not empty gives the label. */\n readonly properties: readonly string[];\n /** The size of the font in millimetres on the paper. */\n readonly sizeMm: number;\n /** The rank of the labels of the layer. A lower rank gets its places first. The default is 0. */\n readonly priority?: number;\n /** For a line: the distance in millimetres between two labels of the same text. No value gives one label for each text. */\n readonly repeatMm?: number;\n}\n\n/** The font of the labels. The width of a label comes from `measure`, so the font of the print must be the same font. */\nexport interface LabelFont {\n /** The CSS font family of the labels, for example `\"Liberation Sans\", Arial, sans-serif`. */\n readonly family: string;\n /** This function gives the width in millimetres of a text at a size of the font in millimetres. */\n readonly measure: (text: string, sizeMm: number) => number;\n}\n\n/** A label with its place: the middle of its box on the paper, and its angle. */\nexport interface PlacedLabel {\n /** The identifier of the layer of the label. */\n readonly layer: string;\n readonly text: string;\n /** The middle of the label on the paper, in millimetres from the top left corner of the frame. */\n readonly x: number;\n readonly y: number;\n /** The angle of the text in degrees, clockwise, more than -90 and not more than 90. So each label reads from the left. */\n readonly angle: number;\n readonly sizeMm: number;\n readonly widthMm: number;\n}\n\n/** The labels of a map: the labels with a place, and the texts with no place. */\nexport interface LabelPlacement {\n readonly placed: readonly PlacedLabel[];\n /** Each text that has no place with no overlap, inside the frame. */\n readonly skipped: readonly { readonly layer: string; readonly text: string }[];\n}\n\n/** A layer as the labels see it: its identifier, its features after its filter, its rule and the size of its points. */\nexport interface LabelLayer {\n readonly id: string;\n readonly features: readonly Feature[];\n readonly label?: LabelRule | undefined;\n /** The size in millimetres of the point symbol of the layer, when its style has points. */\n readonly pointSizeMm?: number | undefined;\n}\n\n/** The gap in millimetres between a point symbol and its label. */\nconst POINT_GAP_MM = 0.6;\n/** The margin in millimetres between a label and the edge of the frame. */\nconst FRAME_MARGIN_MM = 0.5;\n/** The height of the box of a label, as a part of the size of the font. */\nconst BOX_HEIGHT = 1.2;\n/** The room in millimetres at each end of a label along a line. */\nconst LINE_PAD_MM = 1;\n/** The largest distance from a line to the chord of a label, as a part of the size of the font. */\nconst LINE_BEND = 0.25;\n\n/**\n * This function examines the label rule of a layer.\n *\n * @throws MapError - The code is `label`.\n */\nexport function checkLabelRule(rule: LabelRule, layer: string): void {\n const fail = (reason: string): never => {\n throw new MapError(\"label\", `The labels of the layer \"${layer}\": ${reason}`);\n };\n if (!Array.isArray(rule.properties) || rule.properties.length === 0) fail(\"give at least one property\");\n for (const property of rule.properties) if (typeof property !== \"string\" || property === \"\") fail(\"each property is a text that is not empty\");\n if (!(Number.isFinite(rule.sizeMm) && rule.sizeMm > 0)) fail(`the size ${rule.sizeMm} is not a finite number more than 0`);\n if (rule.priority !== undefined && !Number.isFinite(rule.priority)) fail(`the priority ${rule.priority} is not a finite number`);\n if (rule.repeatMm !== undefined && !(Number.isFinite(rule.repeatMm) && rule.repeatMm > 0)) fail(`the distance ${rule.repeatMm} is not a finite number more than 0`);\n}\n\n/** This function gives the text of the label of a feature: the first property of the rule with a text. */\nexport function labelText(rule: LabelRule, feature: Feature): string | undefined {\n for (const property of rule.properties) {\n const value = feature.properties?.[property];\n if ((typeof value === \"string\" || typeof value === \"number\") && String(value).trim() !== \"\") return String(value).trim();\n }\n return undefined;\n}\n\n/** A box on the paper with an angle: its middle, its half width, its half height and its angle in radians. */\ninterface Box {\n readonly x: number;\n readonly y: number;\n readonly hw: number;\n readonly hh: number;\n readonly angle: number;\n}\n\nfunction corners(box: Box): PaperPoint[] {\n const c = Math.cos(box.angle);\n const s = Math.sin(box.angle);\n return [\n [-box.hw, -box.hh],\n [box.hw, -box.hh],\n [box.hw, box.hh],\n [-box.hw, box.hh],\n ].map(([u, v]) => ({ x: box.x + u! * c - v! * s, y: box.y + u! * s + v! * c }));\n}\n\n/** This function tells if two boxes overlap: the test of the separating axis for two rectangles. */\nfunction overlaps(a: Box, b: Box): boolean {\n const ca = corners(a);\n const cb = corners(b);\n for (const angle of [a.angle, a.angle + Math.PI / 2, b.angle, b.angle + Math.PI / 2]) {\n const ax = Math.cos(angle);\n const ay = Math.sin(angle);\n const pa = ca.map((p) => p.x * ax + p.y * ay);\n const pb = cb.map((p) => p.x * ax + p.y * ay);\n if (Math.max(...pa) <= Math.min(...pb) || Math.max(...pb) <= Math.min(...pa)) return false;\n }\n return true;\n}\n\n/** The boxes that a label must not overlap, and the frame. */\nclass Room {\n readonly boxes: Box[] = [];\n readonly widthMm: number;\n readonly heightMm: number;\n\n constructor(widthMm: number, heightMm: number) {\n this.widthMm = widthMm;\n this.heightMm = heightMm;\n }\n\n fits(box: Box): boolean {\n for (const p of corners(box)) {\n if (p.x < FRAME_MARGIN_MM || p.y < FRAME_MARGIN_MM || p.x > this.widthMm - FRAME_MARGIN_MM || p.y > this.heightMm - FRAME_MARGIN_MM) return false;\n }\n return !this.boxes.some((other) => overlaps(box, other));\n }\n}\n\nfunction paperOf(position: Position, view: FrameView): PaperPoint {\n return view.toPaper({ lat: position[1] as number, lon: position[0] as number });\n}\n\n/** This function gives the points, the lines and the areas of a geometry. */\nfunction parts(geometry: Geometry, out: { points: Position[]; lines: (readonly Position[])[]; areas: Polygon[] }): void {\n switch (geometry.type) {\n case \"Point\":\n out.points.push(geometry.coordinates);\n break;\n case \"MultiPoint\":\n out.points.push(...geometry.coordinates);\n break;\n case \"LineString\":\n out.lines.push(geometry.coordinates);\n break;\n case \"MultiLineString\":\n out.lines.push(...geometry.coordinates);\n break;\n case \"Polygon\":\n out.areas.push(geometry);\n break;\n case \"MultiPolygon\":\n for (const coordinates of geometry.coordinates) out.areas.push({ type: \"Polygon\", coordinates });\n break;\n case \"GeometryCollection\":\n for (const item of geometry.geometries) parts(item, out);\n break;\n }\n}\n\n/** This function gives the angle of a direction in radians, more than -pi/2 and not more than pi/2, so the text reads from the left. */\nfunction readable(dx: number, dy: number): number {\n let angle = Math.atan2(dy, dx);\n if (angle > Math.PI / 2) angle -= Math.PI;\n if (angle <= -Math.PI / 2) angle += Math.PI;\n return angle;\n}\n\n/**\n * This function gives the runs of a line on the paper: the parts with each segment in a box that touches the frame. So\n * a segment that crosses the frame stays in its run. A run can go past the frame, but a label box outside the frame\n * does not fit.\n */\nfunction runs(line: readonly Position[], view: FrameView): PaperPoint[][] {\n const { widthMm: w, heightMm: h } = view.frame;\n const points = line.map((position) => paperOf(position, view));\n const out: PaperPoint[][] = [];\n let run: PaperPoint[] = [];\n for (let i = 1; i < points.length; i += 1) {\n const a = points[i - 1]!;\n const b = points[i]!;\n if (Math.max(a.x, b.x) >= 0 && Math.min(a.x, b.x) <= w && Math.max(a.y, b.y) >= 0 && Math.min(a.y, b.y) <= h) {\n if (run.length === 0) run.push(a);\n run.push(b);\n } else {\n if (run.length > 1) out.push(run);\n run = [];\n }\n }\n if (run.length > 1) out.push(run);\n return out;\n}\n\n/** This function gives the length of a run on the paper. */\nfunction runLength(run: readonly PaperPoint[]): number {\n let total = 0;\n for (let i = 1; i < run.length; i += 1) total += Math.hypot(run[i]!.x - run[i - 1]!.x, run[i]!.y - run[i - 1]!.y);\n return total;\n}\n\n/** This function gives the point at a distance along a run, with the cumulative lengths of the run. */\nfunction along(run: readonly PaperPoint[], lengths: readonly number[], s: number): PaperPoint {\n let i = 1;\n while (i < run.length - 1 && lengths[i]! < s) i += 1;\n const a = run[i - 1]!;\n const b = run[i]!;\n const span = lengths[i]! - lengths[i - 1]!;\n const t = span === 0 ? 0 : (s - lengths[i - 1]!) / span;\n return { x: a.x + t * (b.x - a.x), y: a.y + t * (b.y - a.y) };\n}\n\n/**\n * This function gives the boxes of a label along a run, from the middle of the run to its ends. A box is on an almost\n * straight part of the run. No point of that part is farther from the chord than `LINE_BEND` of the size.\n */\nfunction lineCandidates(run: readonly PaperPoint[], width: number, size: number): Box[] {\n const lengths = [0];\n for (let i = 1; i < run.length; i += 1) lengths.push(lengths[i - 1]! + Math.hypot(run[i]!.x - run[i - 1]!.x, run[i]!.y - run[i - 1]!.y));\n const total = lengths.at(-1)!;\n const span = width + 2 * LINE_PAD_MM;\n if (total < span) return [];\n const step = Math.max(span / 4, 2);\n // The middles go from the middle of the run to its ends, one step at a time, first toward the start.\n const middles = [total / 2];\n for (let k = 1; k * step <= total / 2 - span / 2; k += 1) middles.push(total / 2 - k * step, total / 2 + k * step);\n const boxes: Box[] = [];\n for (const middle of middles) {\n const start = along(run, lengths, middle - span / 2);\n const end = along(run, lengths, middle + span / 2);\n const chord = Math.hypot(end.x - start.x, end.y - start.y);\n if (chord < 0.9 * span) continue;\n const inside = run.filter((_, i) => lengths[i]! > middle - span / 2 && lengths[i]! < middle + span / 2);\n const bend = Math.max(0, ...inside.map((p) => Math.abs((end.x - start.x) * (start.y - p.y) - (start.x - p.x) * (end.y - start.y)) / chord));\n if (bend > LINE_BEND * size) continue;\n boxes.push({ x: (start.x + end.x) / 2, y: (start.y + end.y) / 2, hw: width / 2, hh: (BOX_HEIGHT * size) / 2, angle: readable(end.x - start.x, end.y - start.y) });\n }\n return boxes;\n}\n\n/** This function gives the boxes of a label around a point, in the sequence of the preferred places. */\nfunction pointCandidates(p: PaperPoint, width: number, size: number, symbolMm: number): Box[] {\n const hw = width / 2;\n const hh = (BOX_HEIGHT * size) / 2;\n const d = symbolMm / 2 + POINT_GAP_MM;\n const k = d * Math.SQRT1_2;\n return [\n [d + hw, 0],\n [-d - hw, 0],\n [0, -d - hh],\n [0, d + hh],\n [k + hw, -k - hh],\n [k + hw, k + hh],\n [-k - hw, -k - hh],\n [-k - hw, k + hh],\n ].map(([dx, dy]) => ({ x: p.x + dx!, y: p.y + dy!, hw, hh, angle: 0 }));\n}\n\n/** This function gives the box of a label in the middle of an area, when the area has each corner of the box. */\nfunction areaCandidates(area: Polygon, view: FrameView, width: number, size: number): Box[] {\n const ring = area.coordinates[0] ?? [];\n if (ring.length < 4) return [];\n const points = ring.map((position) => paperOf(position, view));\n let doubled = 0;\n let cx = 0;\n let cy = 0;\n for (let i = 0; i + 1 < points.length; i += 1) {\n const a = points[i]!;\n const b = points[i + 1]!;\n const cross = a.x * b.y - b.x * a.y;\n doubled += cross;\n cx += (a.x + b.x) * cross;\n cy += (a.y + b.y) * cross;\n }\n const xs = points.map((p) => p.x);\n const ys = points.map((p) => p.y);\n const middle = { x: (Math.min(...xs) + Math.max(...xs)) / 2, y: (Math.min(...ys) + Math.max(...ys)) / 2 };\n const centers = doubled === 0 ? [middle] : [{ x: cx / (3 * doubled), y: cy / (3 * doubled) }, middle];\n const hw = width / 2;\n const hh = (BOX_HEIGHT * size) / 2;\n return centers\n .map((c) => ({ x: c.x, y: c.y, hw, hh, angle: 0 }))\n .filter((box) => [...corners(box), { x: box.x, y: box.y }].every((p) => locatePoint(view.fromPaper(p), area) === \"inside\"));\n}\n\n/** This function tells if the box of the outer ring of an area on the paper touches the frame. */\nfunction areaOnFrame(area: Polygon, view: FrameView): boolean {\n const points = (area.coordinates[0] ?? []).map((position) => paperOf(position, view));\n const xs = points.map((p) => p.x);\n const ys = points.map((p) => p.y);\n return points.length > 0 && Math.max(...xs) >= 0 && Math.min(...xs) <= view.frame.widthMm && Math.max(...ys) >= 0 && Math.min(...ys) <= view.frame.heightMm;\n}\n\n/** One text of a layer, and the parts of the features with that text. */\ninterface Job {\n readonly layer: LabelLayer;\n readonly rule: LabelRule;\n readonly text: string;\n readonly width: number;\n readonly points: Position[];\n readonly lines: (readonly Position[])[];\n readonly areas: Polygon[];\n}\n\n/**\n * This function gives the places of the labels of the layers. The labels do not overlap, and each label is inside the\n * frame.\n *\n * - The layers with a lower `priority` get their places first. With the same priority, a higher layer is first.\n * - In a layer, the features with the same text are one job. A longer line is first, then the sequence of the features.\n * - A point gets the first free place of 8 places around its symbol: right, left, above, below, then the corners.\n * - A line gets its text along an almost straight part. The longest run is first, and the middle of a run is first.\n * - With `repeatMm`, a line gets more labels of its text, at that distance or more from each other.\n * - An area gets its text at its centroid or at the middle of its box, when the area has the box of the text.\n * - Each point symbol of the layers and the north arrow are obstacles too.\n * - A text with a part on the frame and no free place is in `skipped`. A text with no part on the frame is in neither list.\n *\n * @param obstacles - The boxes on the paper that no label covers, as the middle and the half size in millimetres.\n * @throws MapError - The code is `label`: the width of a text from `measure` is not a finite number of 0 or more.\n */\nexport function placeLabels(layers: readonly LabelLayer[], view: FrameView, font: LabelFont, obstacles: readonly { x: number; y: number; half: number }[] = []): LabelPlacement {\n const room = new Room(view.frame.widthMm, view.frame.heightMm);\n for (const o of obstacles) room.boxes.push({ x: o.x, y: o.y, hw: o.half, hh: o.half, angle: 0 });\n for (const layer of layers) {\n if (layer.pointSizeMm === undefined) continue;\n const out: { points: Position[]; lines: (readonly Position[])[]; areas: Polygon[] } = { points: [], lines: [], areas: [] };\n for (const feature of layer.features) if (feature.geometry !== null) parts(feature.geometry, out);\n for (const position of out.points) {\n const p = paperOf(position, view);\n room.boxes.push({ x: p.x, y: p.y, hw: layer.pointSizeMm / 2, hh: layer.pointSizeMm / 2, angle: 0 });\n }\n }\n\n const order = layers\n .map((layer, index) => ({ layer, index }))\n .filter((entry): entry is { layer: LabelLayer & { label: LabelRule }; index: number } => entry.layer.label !== undefined)\n .sort((a, b) => (a.layer.label.priority ?? 0) - (b.layer.label.priority ?? 0) || b.index - a.index);\n\n const placed: PlacedLabel[] = [];\n const skipped: { layer: string; text: string }[] = [];\n for (const { layer } of order) {\n const rule = layer.label;\n const jobs = new Map<string, Job>();\n for (const feature of layer.features) {\n if (feature.geometry === null) continue;\n const text = labelText(rule, feature);\n if (text === undefined) continue;\n let job = jobs.get(text);\n if (job === undefined) {\n const width = font.measure(text, rule.sizeMm);\n if (!(Number.isFinite(width) && width >= 0)) throw new MapError(\"label\", `The width ${width} of the label \"${text}\" is not a finite number of 0 or more`);\n job = { layer, rule, text, width, points: [], lines: [], areas: [] };\n jobs.set(text, job);\n }\n parts(feature.geometry, job);\n }\n // The runs of each job, the longest first. The jobs with the most length of line are first.\n const sorted = [...jobs.values()]\n .map((job) => {\n const lineRuns = job.lines\n .flatMap((line) => runs(line, view))\n .map((run) => ({ run, length: runLength(run) }))\n .sort((a, b) => b.length - a.length);\n return { job, lineRuns, length: lineRuns.reduce((t, entry) => t + entry.length, 0) };\n })\n .sort((a, b) => b.length - a.length);\n for (const { job, lineRuns } of sorted) {\n const mine: PlacedLabel[] = [];\n // A text is in `skipped` only when a part of its features is on the frame.\n let onFrame = false;\n const take = (box: Box): boolean => {\n if (!room.fits(box)) return false;\n if (job.rule.repeatMm !== undefined && mine.some((other) => Math.hypot(other.x - box.x, other.y - box.y) < job.rule.repeatMm!)) return false;\n room.boxes.push(box);\n mine.push({ layer: layer.id, text: job.text, x: box.x, y: box.y, angle: (box.angle * 180) / Math.PI + 0, sizeMm: job.rule.sizeMm, widthMm: job.width });\n return true;\n };\n for (const position of job.points) {\n const p = paperOf(position, view);\n if (p.x < 0 || p.y < 0 || p.x > view.frame.widthMm || p.y > view.frame.heightMm) continue;\n onFrame = true;\n pointCandidates(p, job.width, job.rule.sizeMm, layer.pointSizeMm ?? 0).some(take);\n }\n if (lineRuns.length > 0) onFrame = true;\n lines: for (const { run } of lineRuns) {\n for (const box of lineCandidates(run, job.width, job.rule.sizeMm)) {\n if (take(box) && job.rule.repeatMm === undefined) break lines;\n }\n }\n for (const area of job.areas) {\n if (!areaOnFrame(area, view)) continue;\n onFrame = true;\n areaCandidates(area, view, job.width, job.rule.sizeMm).some(take);\n }\n if (mine.length === 0 && onFrame) skipped.push({ layer: layer.id, text: job.text });\n placed.push(...mine);\n }\n }\n return { placed, skipped };\n}\n\n/** This function gives the SVG of the labels: black text with a white halo, so a label reads over the lines of the map. */\nexport function labelsSvg(placement: LabelPlacement, font: LabelFont): string {\n const texts = placement.placed.map((label) => {\n const rotate = label.angle === 0 ? \"\" : ` transform=\"rotate(${mm(label.angle)} ${mm(label.x)} ${mm(label.y)})\"`;\n return (\n `<text x=\"${mm(label.x)}\" y=\"${mm(label.y)}\" font-size=\"${mm(label.sizeMm)}\"${rotate} text-anchor=\"middle\" dominant-baseline=\"central\" ` +\n `fill=\"#000000\" stroke=\"#ffffff\" stroke-width=\"${mm(label.sizeMm * 0.25)}\" stroke-linejoin=\"round\" paint-order=\"stroke\">${escapeHtml(label.text)}</text>`\n );\n });\n return `<g class=\"labels\" font-family=\"${escapeAttribute(font.family)}\" data-skipped=\"${placement.skipped.length}\">${texts.join(\"\")}</g>`;\n}\n","/**\n * The marks of a map: the scale bar and the north arrow.\n *\n * @packageDocumentation\n */\n\nimport { escapeHtml } from \"@mark1russell7/text\";\nimport { mm } from \"./style.ts\";\n\n/** The units of the scale bars of a map. `both` gives a metric bar and an imperial bar. */\nexport type ScaleBarUnits = \"metric\" | \"imperial\" | \"both\" | \"none\";\n\n/** The length of a scale bar on the ground and its label. */\nexport interface ScaleBarLength {\n /** The length on the ground in metres. */\n readonly meters: number;\n /** The label, for example `500 m`, `2 km`, `0.5 mi` or `200 ft`. */\n readonly label: string;\n}\n\nconst METERS_PER_MILE = 1609.344;\nconst METERS_PER_FOOT = 0.3048;\n\n/** This function gives the largest number 1, 2 or 5 times a power of 10 that is not more than a number more than 0. */\nexport function niceNumber(max: number): number {\n const power = 10 ** Math.floor(Math.log10(max));\n for (const step of [5, 2, 1]) {\n const value = Number((step * power).toPrecision(1));\n if (value <= max) return value;\n }\n return Number((power / 2).toPrecision(1));\n}\n\n/**\n * This function gives the length of a scale bar that is not longer than a length on the ground.\n *\n * - The metric bar is in metres below 1 km, and in kilometres from 1 km.\n * - The imperial bar is in miles from a quarter of a mile, and in feet below that.\n */\nexport function scaleBarLength(maxMeters: number, units: \"metric\" | \"imperial\"): ScaleBarLength {\n if (units === \"metric\") {\n const meters = niceNumber(maxMeters);\n return { meters, label: meters >= 1000 ? `${meters / 1000} km` : `${meters} m` };\n }\n const miles = maxMeters / METERS_PER_MILE;\n if (miles >= 0.25) {\n const value = niceNumber(miles);\n return { meters: value * METERS_PER_MILE, label: `${value} mi` };\n }\n const feet = niceNumber(maxMeters / METERS_PER_FOOT);\n return { meters: feet * METERS_PER_FOOT, label: `${feet} ft` };\n}\n\n/** The height of one scale bar with its label, in millimetres. */\nexport const SCALE_BAR_ROW_MM = 4.5;\n\n/** This function gives the SVG of a scale bar of four parts, with its top left corner at a point on the paper. */\nexport function scaleBarSvg(x: number, y: number, length: ScaleBarLength, mmPerMeter: number): string {\n const total = length.meters * mmPerMeter;\n const part = total / 4;\n let parts = \"\";\n for (let i = 0; i < 4; i += 1) {\n parts += `<rect x=\"${mm(x + i * part)}\" y=\"${mm(y)}\" width=\"${mm(part)}\" height=\"1.5\" fill=\"${i % 2 === 0 ? \"#000000\" : \"#ffffff\"}\" stroke=\"#000000\" stroke-width=\"0.15\"/>`;\n }\n return `<g class=\"scale-bar\">${parts}<text x=\"${mm(x + total + 1.5)}\" y=\"${mm(y + 1.5)}\" font-size=\"2.4\">${escapeHtml(length.label)}</text></g>`;\n}\n\n/** This function gives the SVG of a north arrow at a point on the paper, with the direction of north in degrees. */\nexport function northArrowSvg(x: number, y: number, northDegrees: number): string {\n return (\n `<g class=\"north-arrow\" transform=\"translate(${mm(x)} ${mm(y)}) rotate(${mm(northDegrees)})\">` +\n `<circle r=\"4.5\" fill=\"#ffffff\" stroke=\"#000000\" stroke-width=\"0.2\"/>` +\n `<path d=\"M0 -3.6L1.6 1.2L0 0.4L-1.6 1.2Z\" fill=\"#000000\"/>` +\n `<text y=\"3.9\" font-size=\"2.2\" text-anchor=\"middle\">N</text></g>`\n );\n}\n","/**\n * A map as data, and its render to SVG.\n *\n * @packageDocumentation\n */\n\nimport { simplifyRegions, type Feature, type Geometry, type Position, type Region } from \"@mark1russell7/geo\";\nimport { escapeAttribute, escapeHtml } from \"@mark1russell7/text\";\nimport { MapError } from \"./errors.ts\";\nimport { checkFilter, matchesFilter, type Filter } from \"./filter.ts\";\nimport { frameView, type Frame, type FrameView, type PaperPoint } from \"./frame.ts\";\nimport { checkLabelRule, labelsSvg, placeLabels, type LabelFont, type LabelPlacement, type LabelRule } from \"./labels.ts\";\nimport { northArrowSvg, SCALE_BAR_ROW_MM, scaleBarLength, scaleBarSvg, type ScaleBarUnits } from \"./marks.ts\";\nimport { checkStyle, grayColor, hatchPattern, mm, pointSymbol, strokeAttributes, type Style } from \"./style.ts\";\n\n/** The source of the data of a layer. The map prints each source in its attribution block. */\nexport interface Source {\n /** The name of the source, for example `© OpenStreetMap contributors`. */\n readonly title: string;\n /** The license of the data, for example `ODbL 1.0`. */\n readonly license: string;\n /** The web address of the source or of its license. */\n readonly url?: string;\n /** The date of the data, for example `2026-11-21`. */\n readonly date?: string;\n}\n\n/** A layer of a map: features, a filter, a style and the source of the features. */\nexport interface Layer {\n /** The identifier of the layer: lower case letters, digits and hyphens. It starts with a letter. */\n readonly id: string;\n /** The features. Their positions are `[lon, lat]` on WGS84. */\n readonly features: readonly Feature[];\n /** The style of the features. */\n readonly style: Style;\n /** The source of the features. */\n readonly source: Source;\n /** The filter of the features. No filter keeps each feature. */\n readonly filter?: Filter;\n /** The text of the layer in the legend. No text gives no entry in the legend. */\n readonly legend?: string;\n /** The tolerance in millimetres on the paper for the simplification of the areas. No value keeps each position. */\n readonly simplifyMm?: number;\n /** The rule of the labels of the features. No rule gives no labels. */\n readonly label?: LabelRule;\n}\n\n/** A map: a frame, layers from the bottom to the top, and its marks. */\nexport interface MapDocument {\n /** The identifier of the map: lower case letters, digits and hyphens. It starts each identifier in the SVG. */\n readonly id: string;\n /** The title of the map, for a reader of the screen. */\n readonly title: string;\n /** The frame. */\n readonly frame: Frame;\n /** The layers, from the bottom to the top. */\n readonly layers: readonly Layer[];\n /** The units of the scale bars. The default is `both`. */\n readonly scaleBar?: ScaleBarUnits;\n /** The value `false` gives no north arrow. The default is `true`. */\n readonly northArrow?: boolean;\n}\n\nconst ID = /^[a-z][a-z0-9-]*$/;\n\nfunction checkId(id: string, what: string): void {\n if (!ID.test(id)) throw new MapError(\"id\", `The identifier \"${id}\" of the ${what} is not lower case letters, digits and hyphens that start with a letter`);\n}\n\nfunction checkSource(source: Source | undefined, layer: string): void {\n if (source === undefined || typeof source !== \"object\") throw new MapError(\"source\", `The layer \"${layer}\" has no source`);\n if (typeof source.title !== \"string\" || source.title.trim() === \"\") throw new MapError(\"source\", `The source of the layer \"${layer}\" has no title`);\n if (typeof source.license !== \"string\" || source.license.trim() === \"\") throw new MapError(\"source\", `The source of the layer \"${layer}\" has no license`);\n}\n\n/**\n * This function examines a map. It refuses a frame, an identifier, a style, a filter or a source that is not correct.\n * Each layer must have a source with a title and a license, so the attribution block names each source of the map.\n *\n * @throws MapError - The code tells the reason.\n */\nexport function checkMap(map: MapDocument): void {\n checkId(map.id, \"map\");\n frameView(map.frame);\n const ids = new Set<string>();\n for (const layer of map.layers) {\n checkId(layer.id, \"layer\");\n if (ids.has(layer.id)) throw new MapError(\"id\", `Two layers have the identifier \"${layer.id}\"`);\n ids.add(layer.id);\n checkSource(layer.source, layer.id);\n checkStyle(layer.style, layer.id);\n if (layer.filter !== undefined) checkFilter(layer.filter, `layer \"${layer.id}\" filter`);\n if (layer.label !== undefined) checkLabelRule(layer.label, layer.id);\n if (layer.simplifyMm !== undefined && !(Number.isFinite(layer.simplifyMm) && layer.simplifyMm > 0)) {\n throw new MapError(\"style\", `The layer \"${layer.id}\": the tolerance ${layer.simplifyMm} is not a finite number more than 0`);\n }\n }\n}\n\n/** The box of the points on the paper that a feature uses. */\nclass PaperBox {\n minX = Number.POSITIVE_INFINITY;\n minY = Number.POSITIVE_INFINITY;\n maxX = Number.NEGATIVE_INFINITY;\n maxY = Number.NEGATIVE_INFINITY;\n\n add(point: PaperPoint): void {\n this.minX = Math.min(this.minX, point.x);\n this.minY = Math.min(this.minY, point.y);\n this.maxX = Math.max(this.maxX, point.x);\n this.maxY = Math.max(this.maxY, point.y);\n }\n\n /** It tells if the box touches the frame, with a margin in millimetres. */\n touches(frame: Frame, margin: number): boolean {\n return this.maxX >= -margin && this.minX <= frame.widthMm + margin && this.maxY >= -margin && this.minY <= frame.heightMm + margin;\n }\n}\n\nfunction paperOf(position: Position, view: FrameView): PaperPoint {\n return view.toPaper({ lat: position[1] as number, lon: position[0] as number });\n}\n\nfunction linePath(positions: readonly Position[], view: FrameView, box: PaperBox, close: boolean): string {\n let d = \"\";\n positions.forEach((position, i) => {\n const point = paperOf(position, view);\n box.add(point);\n d += `${i === 0 ? \"M\" : \"L\"}${mm(point.x)} ${mm(point.y)}`;\n });\n return close ? `${d}Z` : d;\n}\n\n/** This function gives the SVG of one geometry with a style. */\nfunction drawGeometry(geometry: Geometry, style: Style, view: FrameView, fill: string | undefined): string {\n const frame = view.frame;\n switch (geometry.type) {\n case \"Point\":\n case \"MultiPoint\": {\n if (style.point === undefined) return \"\";\n const positions = geometry.type === \"Point\" ? [geometry.coordinates] : geometry.coordinates;\n return positions\n .map((position) => paperOf(position, view))\n .filter((point) => point.x >= -style.point!.sizeMm && point.x <= frame.widthMm + style.point!.sizeMm && point.y >= -style.point!.sizeMm && point.y <= frame.heightMm + style.point!.sizeMm)\n .map((point) => pointSymbol(style.point!, point.x, point.y))\n .join(\"\");\n }\n case \"LineString\":\n case \"MultiLineString\": {\n if (style.stroke === undefined) return \"\";\n const box = new PaperBox();\n const lines = geometry.type === \"LineString\" ? [geometry.coordinates] : geometry.coordinates;\n const d = lines.map((line) => linePath(line, view, box, false)).join(\"\");\n if (!box.touches(frame, style.stroke.widthMm)) return \"\";\n return `<path d=\"${d}\" fill=\"none\" ${strokeAttributes(style.stroke)}/>`;\n }\n case \"Polygon\":\n case \"MultiPolygon\": {\n const box = new PaperBox();\n const polygons = geometry.type === \"Polygon\" ? [geometry.coordinates] : geometry.coordinates;\n const d = polygons.flatMap((rings) => rings.map((ring) => linePath(ring, view, box, true))).join(\"\");\n if (!box.touches(frame, style.stroke?.widthMm ?? 0)) return \"\";\n const stroke = style.stroke === undefined ? `stroke=\"none\"` : strokeAttributes(style.stroke);\n let svg = \"\";\n if (style.fill?.gray !== undefined) svg += `<path d=\"${d}\" fill=\"${grayColor(style.fill.gray)}\" fill-rule=\"evenodd\" stroke=\"none\"/>`;\n svg += `<path d=\"${d}\" fill=\"${fill ?? \"none\"}\" fill-rule=\"evenodd\" ${stroke}/>`;\n return svg;\n }\n case \"GeometryCollection\":\n return geometry.geometries.map((item) => drawGeometry(item, style, view, fill)).join(\"\");\n }\n}\n\n/** This function gives the features of a layer after its filter and its simplification. */\nfunction featuresOf(layer: Layer, frame: Frame): Feature[] {\n const kept = layer.features.filter((feature) => feature.geometry !== null && (layer.filter === undefined || matchesFilter(layer.filter, feature)));\n if (layer.simplifyMm === undefined) return kept;\n const areas = kept.flatMap((feature, i) => (feature.geometry?.type === \"Polygon\" || feature.geometry?.type === \"MultiPolygon\" ? [i] : []));\n if (areas.length === 0) return kept;\n // A tolerance of t mm on the paper is t * scale mm on the ground, and t * scale / 1e6 km.\n const simplified = simplifyRegions(\n areas.map((i) => kept[i]!.geometry as Region),\n (layer.simplifyMm * frame.scale) / 1e6,\n );\n const result = [...kept];\n areas.forEach((index, j) => {\n result[index] = { ...kept[index]!, geometry: simplified[j]! };\n });\n return result;\n}\n\n/** The options of `renderMap` and `mapLabels`. */\nexport interface RenderOptions {\n /** The font of the labels. A map with a label rule needs it. */\n readonly labelFont?: LabelFont;\n}\n\n/** The middle of the north arrow, from the top right corner of the frame, and the half size of its box, in millimetres. */\nconst NORTH_ARROW = { inset: 6.5, half: 4.7 };\n\nfunction placementOf(map: MapDocument, features: readonly Feature[][], view: FrameView, font: LabelFont): LabelPlacement {\n const obstacles = map.northArrow === false ? [] : [{ x: map.frame.widthMm - NORTH_ARROW.inset, y: NORTH_ARROW.inset, half: NORTH_ARROW.half }];\n const layers = map.layers.map((layer, i) => ({ id: layer.id, features: features[i]!, label: layer.label, pointSizeMm: layer.style.point?.sizeMm }));\n return placeLabels(layers, view, font, obstacles);\n}\n\nfunction labelFontOf(map: MapDocument, options: RenderOptions): LabelFont | undefined {\n const labelled = map.layers.find((layer) => layer.label !== undefined);\n if (labelled === undefined) return undefined;\n const font = options.labelFont;\n if (font === undefined || typeof font.measure !== \"function\" || typeof font.family !== \"string\" || font.family.trim() === \"\") {\n throw new MapError(\"label\", `The layer \"${labelled.id}\" has labels, so the options need a label font with a family and a measure`);\n }\n return font;\n}\n\n/**\n * This function gives the labels of a map with their places, and the texts with no place. `renderMap` draws the same\n * labels.\n *\n * @throws MapError - The map is not correct, as `checkMap` tells, or a layer has labels and the options have no font.\n */\nexport function mapLabels(map: MapDocument, options: RenderOptions = {}): LabelPlacement {\n checkMap(map);\n const font = labelFontOf(map, options);\n if (font === undefined) return { placed: [], skipped: [] };\n return placementOf(map, map.layers.map((layer) => featuresOf(layer, map.frame)), frameView(map.frame), font);\n}\n\n/** This function gives the swatch of a layer in the legend, with its top left corner at a point. */\nfunction swatch(style: Style, x: number, y: number, fill: string | undefined): string {\n if (style.point !== undefined) return pointSymbol(style.point, x + 3, y + 1.75);\n if (style.fill !== undefined) {\n const stroke = style.stroke === undefined ? `stroke=\"#000000\" stroke-width=\"0.1\"` : strokeAttributes(style.stroke);\n const base = style.fill.gray === undefined ? \"\" : `<rect x=\"${mm(x)}\" y=\"${mm(y)}\" width=\"6\" height=\"3.5\" fill=\"${grayColor(style.fill.gray)}\"/>`;\n return `${base}<rect x=\"${mm(x)}\" y=\"${mm(y)}\" width=\"6\" height=\"3.5\" fill=\"${fill ?? \"none\"}\" ${stroke}/>`;\n }\n return `<path d=\"M${mm(x)} ${mm(y + 1.75)}L${mm(x + 6)} ${mm(y + 1.75)}\" ${strokeAttributes(style.stroke!)}/>`;\n}\n\nfunction thousands(value: number): string {\n return String(Math.round(value)).replace(/\\B(?=(\\d{3})+(?!\\d))/g, \",\");\n}\n\n/** This function gives the lines of the attribution block: the scale, the projection and each source one time. */\nexport function attributionLines(map: MapDocument): string[] {\n const lines = [`Scale 1:${thousands(map.frame.scale)} at the center. Projection: ${map.frame.projection.name}.`];\n const seen = new Set<string>();\n for (const { source } of map.layers) {\n const line = `Data: ${source.title}. License: ${source.license}.${source.url === undefined ? \"\" : ` ${source.url}`}${source.date === undefined ? \"\" : ` Date: ${source.date}.`}`;\n if (seen.has(line)) continue;\n seen.add(line);\n lines.push(line);\n }\n return lines;\n}\n\n/**\n * This function gives the SVG of a map. The units of the SVG are millimetres, for a print at the scale of the frame.\n *\n * - The map is at the top. Below it are the scale bars, the legend and the attribution block.\n * - The layers are in their sequence, from the bottom to the top. The frame clips each layer.\n * - A feature that is not on the frame is not in the SVG.\n * - Each identifier in the SVG starts with the identifier of the map. Thus two maps can be in one HTML page.\n * - The labels are above the layers. `placeLabels` tells their places. The group of the labels tells the number of\n * texts with no place in `data-skipped`.\n *\n * @throws MapError - The map is not correct, as `checkMap` tells, or a layer has labels and the options have no font.\n * @throws GeoError - A position is not correct for the projection.\n */\nexport function renderMap(map: MapDocument, options: RenderOptions = {}): string {\n checkMap(map);\n const font = labelFontOf(map, options);\n const view = frameView(map.frame);\n const { widthMm: w, heightMm: h } = map.frame;\n const defs: string[] = [`<clipPath id=\"${map.id}-clip\"><rect width=\"${mm(w)}\" height=\"${mm(h)}\"/></clipPath>`];\n const fills = map.layers.map((layer) => {\n const hatch = layer.style.fill?.hatch;\n if (hatch === undefined) return undefined;\n const id = `${map.id}-${layer.id}-hatch`;\n defs.push(hatchPattern(id, hatch));\n return `url(#${id})`;\n });\n const features = map.layers.map((layer) => featuresOf(layer, map.frame));\n const layers = map.layers.map((layer, i) => {\n const body = features[i]!\n .map((feature) => drawGeometry(feature.geometry as Geometry, layer.style, view, fills[i]))\n .join(\"\");\n return `<g id=\"${map.id}-${layer.id}\">${body}</g>`;\n });\n const labels = font === undefined ? \"\" : labelsSvg(placementOf(map, features, view, font), font);\n\n const top = h + 2;\n const units = map.scaleBar ?? \"both\";\n const bars = units === \"none\" ? [] : units === \"both\" ? ([\"metric\", \"imperial\"] as const) : [units];\n const maxMeters = (0.3 * w) / view.mmPerMeter;\n const scaleBars = bars.map((unit, i) => scaleBarSvg(0.5, top + i * SCALE_BAR_ROW_MM, scaleBarLength(maxMeters, unit), view.mmPerMeter)).join(\"\");\n const legendLayers = map.layers.flatMap((layer, i) => (layer.legend === undefined ? [] : [{ layer, fill: fills[i] }]));\n const columnWidth = w * 0.275;\n const legend = legendLayers\n .map(({ layer, fill }, i) => {\n const x = w * 0.45 + (i % 2) * columnWidth;\n const y = top + Math.floor(i / 2) * SCALE_BAR_ROW_MM - 1;\n return `${swatch(layer.style, x, y, fill)}<text x=\"${mm(x + 7.5)}\" y=\"${mm(y + 2.9)}\" font-size=\"2.4\">${escapeHtml(layer.legend!)}</text>`;\n })\n .join(\"\");\n const blockHeight = Math.max(bars.length, Math.ceil(legendLayers.length / 2)) * SCALE_BAR_ROW_MM;\n const lines = attributionLines(map);\n const firstLine = top + blockHeight + 2.5;\n const attribution = lines.map((line, i) => `<text x=\"0.5\" y=\"${mm(firstLine + i * 3)}\" font-size=\"2.2\">${escapeHtml(line)}</text>`).join(\"\");\n const total = firstLine + (lines.length - 1) * 3 + 1.5;\n const arrow = map.northArrow === false ? \"\" : northArrowSvg(w - 6.5, 6.5, view.northDegrees);\n\n return (\n `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"${mm(w)}mm\" height=\"${mm(total)}mm\" viewBox=\"0 0 ${mm(w)} ${mm(total)}\" ` +\n `role=\"img\" aria-label=\"${escapeAttribute(map.title)}\" font-family=\"sans-serif\">` +\n `<title>${escapeHtml(map.title)}</title><defs>${defs.join(\"\")}</defs>` +\n `<rect width=\"${mm(w)}\" height=\"${mm(total)}\" fill=\"#ffffff\"/>` +\n `<g clip-path=\"url(#${map.id}-clip)\">${layers.join(\"\")}</g>${labels}` +\n `<rect width=\"${mm(w)}\" height=\"${mm(h)}\" fill=\"none\" stroke=\"#000000\" stroke-width=\"0.3\"/>` +\n `${arrow}<g class=\"legend\">${scaleBars}${legend}</g><g class=\"attribution\">${attribution}</g></svg>`\n );\n}\n\n"],"mappings":";;;;AAkBA,IAAa,WAAb,cAA8B,MAAM;;CAEzB;;;;;CAMT,YAAY,MAAoB,SAAiB;EAC/C,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF;;;ACCA,SAAgB,aAAa,UAAkC;CAC7D,QAAQ,SAAS,MAAjB;EACE,KAAK;EACL,KAAK,cACH,OAAO;EACT,KAAK;EACL,KAAK,mBACH,OAAO;EACT,KAAK;EACL,KAAK,gBACH,OAAO;EACT,KAAK,sBAAsB;GACzB,MAAM,QAAQ,IAAI,IAAI,SAAS,WAAW,IAAI,YAAY,CAAC;GAC3D,OAAO,MAAM,SAAS,IAAK,CAAC,GAAG,KAAK,CAAC,CAAC,KAAsB;EAC9D;CACF;AACF;;AAGA,SAAgB,cAAc,QAAgB,SAA2B;CACvE,IAAI,SAAS,QAAQ,OAAO,OAAO,IAAI,OAAO,SAAS,cAAc,MAAM,OAAO,CAAC;CACnF,IAAI,SAAS,QAAQ,OAAO,OAAO,IAAI,MAAM,SAAS,cAAc,MAAM,OAAO,CAAC;CAClF,IAAI,SAAS,QAAQ,OAAO,CAAC,cAAc,OAAO,KAAK,OAAO;CAC9D,IAAI,cAAc,QAAQ,OAAO,QAAQ,aAAa,QAAQ,aAAa,QAAQ,QAAQ,MAAM,OAAO;CACxG,MAAM,aAAa,QAA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AAG,CAAC,EAAE,GAAG,GAAG,KAAK,EAAE,2BAC5F,gBAAgB,IAAI,KAAK,EAAE,oCAC3C,WAAW,IAAI,KAAK,EAAE,gBAAgB,KAAK,KAAK,EAAE,EAAE,sBAC9C,GAAG,CAAC,EAAE,YAAY,GAAG,KAAK,EAAE,uCACtB,IAAI,GAAG,UAAU,OAAO,KAAK,EAAE,EAAE,MAAM,OAAA,eAC7C,GAAG,CAAC,EAAE,YAAY,GAAG,CAAC,EAAE,qDACrC,MAAM,oBAAoB,YAAY,OAAO,6BAA6B,YAAY;AAE7F"}
1
+ {"version":3,"file":"index.js","names":["paperOf"],"sources":["../src/errors.ts","../src/filter.ts","../src/frame.ts","../src/style.ts","../src/labels.ts","../src/marks.ts","../src/render.ts"],"sourcesContent":["/**\n * The error of this package. Each refusal has a code, so a caller can test the reason without the text of the message.\n *\n * @packageDocumentation\n */\n\n/**\n * The reason of a refusal.\n *\n * - `frame`: the scale or the size of a frame is not a finite number more than 0.\n * - `id`: an identifier is not lower case letters, digits and hyphens, or two layers have the same identifier.\n * - `filter`: a filter is not one of the forms of `Filter`.\n * - `style`: a style draws nothing, or a size, a gray level or a dash is not correct.\n * - `source`: a layer has no source, or its source has no title or no license.\n */\nexport type MapErrorCode = \"frame\" | \"id\" | \"filter\" | \"style\" | \"source\" | \"label\";\n\n/** The error that each function of this package throws for an incorrect map. */\nexport class MapError extends Error {\n /** The reason of the refusal. */\n readonly code: MapErrorCode;\n\n /**\n * @param code - The reason of the refusal.\n * @param message - The text for a person.\n */\n constructor(code: MapErrorCode, message: string) {\n super(message);\n this.name = \"MapError\";\n this.code = code;\n }\n}\n","/**\n * The filters of the layers. A filter is data, so a map document can be JSON.\n *\n * @packageDocumentation\n */\n\nimport type { Feature, Geometry } from \"@mark1russell7/geo\";\nimport { MapError } from \"./errors.ts\";\n\n/** A value that a filter compares with a property of a feature. */\nexport type FilterValue = string | number | boolean;\n\n/** The kind of a geometry: points, lines or areas. A collection of two kinds is `mixed`. */\nexport type GeometryKind = \"point\" | \"line\" | \"area\" | \"mixed\";\n\n/**\n * A filter of the features of a layer.\n *\n * - `{ all }` matches when each filter matches. `{ any }` matches when one filter matches. `{ not }` reverses a filter.\n * - `{ property, in }` matches a feature whose property is equal to one of the values.\n * - `{ property, exists }` matches a feature that has the property, or that does not have it.\n * - `{ geometry }` matches a feature whose geometry has the kind.\n */\nexport type Filter =\n | { readonly all: readonly Filter[] }\n | { readonly any: readonly Filter[] }\n | { readonly not: Filter }\n | { readonly property: string; readonly in: readonly FilterValue[] }\n | { readonly property: string; readonly exists: boolean }\n | { readonly geometry: GeometryKind };\n\n/** This function gives the kind of a geometry. */\nexport function geometryKind(geometry: Geometry): GeometryKind {\n switch (geometry.type) {\n case \"Point\":\n case \"MultiPoint\":\n return \"point\";\n case \"LineString\":\n case \"MultiLineString\":\n return \"line\";\n case \"Polygon\":\n case \"MultiPolygon\":\n return \"area\";\n case \"GeometryCollection\": {\n const kinds = new Set(geometry.geometries.map(geometryKind));\n return kinds.size === 1 ? ([...kinds][0] as GeometryKind) : \"mixed\";\n }\n }\n}\n\n/** This function tells if a feature matches a filter. A feature with no geometry matches no `{ geometry }` filter. */\nexport function matchesFilter(filter: Filter, feature: Feature): boolean {\n if (\"all\" in filter) return filter.all.every((item) => matchesFilter(item, feature));\n if (\"any\" in filter) return filter.any.some((item) => matchesFilter(item, feature));\n if (\"not\" in filter) return !matchesFilter(filter.not, feature);\n if (\"geometry\" in filter) return feature.geometry !== null && geometryKind(feature.geometry) === filter.geometry;\n const properties = feature.properties ?? {};\n const has = Object.hasOwn(properties, filter.property);\n if (\"exists\" in filter) return has === filter.exists;\n return has && filter.in.includes(properties[filter.property] as FilterValue);\n}\n\nconst KINDS: readonly string[] = [\"point\", \"line\", \"area\", \"mixed\"];\n\n/**\n * This function refuses a value that is not a `Filter`, for example a filter from JSON.\n *\n * @throws MapError - The code is `filter`.\n */\nexport function checkFilter(filter: unknown, path = \"filter\"): asserts filter is Filter {\n const fail = (reason: string): never => {\n throw new MapError(\"filter\", `${path}: ${reason}`);\n };\n if (typeof filter !== \"object\" || filter === null || Array.isArray(filter)) fail(\"a filter must be an object\");\n const value = filter as Record<string, unknown>;\n const keys = Object.keys(value).toSorted().join(\",\");\n if (keys === \"all\" || keys === \"any\") {\n const items = value[keys];\n if (!Array.isArray(items)) fail(`the member ${keys} must be an array`);\n (items as unknown[]).forEach((item, i) => checkFilter(item, `${path}.${keys}[${i}]`));\n } else if (keys === \"not\") {\n checkFilter(value[\"not\"], `${path}.not`);\n } else if (keys === \"geometry\") {\n if (!KINDS.includes(value[\"geometry\"] as string)) fail(`the geometry must be one of ${KINDS.join(\", \")}`);\n } else if (keys === \"in,property\" || keys === \"exists,property\") {\n if (typeof value[\"property\"] !== \"string\") fail(\"the property must be a string\");\n if (keys === \"exists,property\" && typeof value[\"exists\"] !== \"boolean\") fail(\"the member exists must be true or false\");\n if (keys === \"in,property\") {\n const items = value[\"in\"];\n if (!Array.isArray(items) || !items.every((item) => [\"string\", \"number\", \"boolean\"].includes(typeof item))) {\n fail(\"the member in must be an array of strings, numbers and booleans\");\n }\n }\n } else {\n fail(`the members ${keys === \"\" ? \"(none)\" : keys} are not a form of a filter`);\n }\n}\n","/**\n * The frame of a map: the part of the Earth that the map shows, its scale and its size on the paper.\n *\n * @packageDocumentation\n */\n\nimport { bboxOfPoints, geodesicDirect, type BBox, type LatLon } from \"@mark1russell7/geo\";\nimport type { Projection } from \"@mark1russell7/geo/projection\";\nimport { MapError } from \"./errors.ts\";\n\n/** The frame of a map. The center of the frame is at the middle of the paper. */\nexport interface Frame {\n /** The projection from the Earth to the plane, from `@mark1russell7/geo/projection`. */\n readonly projection: Projection;\n /** The point on the Earth at the middle of the map. */\n readonly center: LatLon;\n /** The denominator of the scale at the center: 24000 for the scale 1:24,000. */\n readonly scale: number;\n /** The width of the map on the paper, in millimetres. */\n readonly widthMm: number;\n /** The height of the map on the paper, in millimetres. */\n readonly heightMm: number;\n}\n\n/** A point on the paper in millimetres, from the top left corner of the map. The y axis points down. */\nexport interface PaperPoint {\n /** The distance to the right, in millimetres. */\n readonly x: number;\n /** The distance down, in millimetres. */\n readonly y: number;\n}\n\n/** The functions of a frame between the Earth and the paper. */\nexport interface FrameView {\n /** The frame. */\n readonly frame: Frame;\n /** The millimetres of paper for one metre on the ground at the center. */\n readonly mmPerMeter: number;\n /** The millimetres of paper for one metre on the plane of the projection. */\n readonly mmPerPlaneMeter: number;\n /** This function gives the point on the paper for a point on the Earth. */\n readonly toPaper: (point: LatLon) => PaperPoint;\n /** This function gives the point on the Earth for a point on the paper. */\n readonly fromPaper: (point: PaperPoint) => LatLon;\n /** The direction of north at the center, in degrees clockwise from the top of the paper. */\n readonly northDegrees: number;\n}\n\n/** This function refuses a frame with a scale or a size that is not a finite number more than 0. */\nexport function checkFrame(frame: Frame): void {\n for (const [name, value] of [\n [\"scale\", frame.scale],\n [\"width\", frame.widthMm],\n [\"height\", frame.heightMm],\n ] as const) {\n if (!(Number.isFinite(value) && value > 0)) throw new MapError(\"frame\", `The ${name} ${value} of the frame is not a finite number more than 0`);\n }\n}\n\n/**\n * This function gives the functions of a frame between the Earth and the paper.\n *\n * - The scale of the frame is the true scale at the center. The function divides by the scale factor of the projection\n * at the center: the square root of `max * min` of `projection.scale`.\n * - For Web Mercator, the scale changes with the latitude. For `azimuthalEquidistant`, it is almost the same on all\n * the map.\n *\n * @throws MapError - The code is `frame`.\n * @throws GeoError - The center is not a correct point for the projection.\n */\nexport function frameView(frame: Frame): FrameView {\n checkFrame(frame);\n const { projection, center } = frame;\n const factors = projection.scale(center);\n const mmPerMeter = 1000 / frame.scale;\n const mmPerPlaneMeter = mmPerMeter / Math.sqrt(factors.max * factors.min);\n const origin = projection.toPlane(center);\n const middleX = frame.widthMm / 2;\n const middleY = frame.heightMm / 2;\n const toPaper = (point: LatLon): PaperPoint => {\n const plane = projection.toPlane(point);\n return { x: middleX + (plane.x - origin.x) * mmPerPlaneMeter, y: middleY - (plane.y - origin.y) * mmPerPlaneMeter };\n };\n const fromPaper = (point: PaperPoint): LatLon =>\n projection.fromPlane({ x: origin.x + (point.x - middleX) / mmPerPlaneMeter, y: origin.y - (point.y - middleY) / mmPerPlaneMeter });\n // The direction of a geodesic of 1 mm on the paper to the north.\n const north = toPaper(geodesicDirect(center, 0, 1 / mmPerMeter).point);\n const northDegrees = (Math.atan2(north.x - middleX, middleY - north.y) * 180) / Math.PI;\n return Object.freeze({ frame, mmPerMeter, mmPerPlaneMeter, toPaper, fromPaper, northDegrees: northDegrees + 0 });\n}\n\n/**\n * This function gives the box on the Earth around the frame, for a fetch of the data of a map. It is the box of 64\n * points on each side of the frame, so it contains the corners and the edges of the frame.\n *\n * @throws MapError - The code is `frame`.\n */\nexport function frameBBox(frame: Frame): BBox {\n const view = frameView(frame);\n const { widthMm: w, heightMm: h } = frame;\n const points: LatLon[] = [];\n const steps = 64;\n for (let i = 0; i < steps; i += 1) {\n const t = i / steps;\n points.push(view.fromPaper({ x: t * w, y: 0 }), view.fromPaper({ x: w, y: t * h }), view.fromPaper({ x: w - t * w, y: h }), view.fromPaper({ x: 0, y: h - t * h }));\n }\n return bboxOfPoints(points) as BBox;\n}\n","/**\n * The black and white styles of the layers: lines with dashes, areas with gray levels and hatches, and point symbols.\n * The print of a map has no color, so each style uses black, white and gray only.\n *\n * @packageDocumentation\n */\n\nimport { MapError } from \"./errors.ts\";\n\n/**\n * A line. The gray level goes from 0 (black) to 1 (white). The default is 0.\n */\nexport interface StrokeStyle {\n /** The width of the line in millimetres. */\n readonly widthMm: number;\n /** The gray level from 0 (black) to 1 (white). The default is 0. */\n readonly gray?: number;\n /** The lengths of the dashes and the gaps in millimetres. No value gives a solid line. */\n readonly dashMm?: readonly number[];\n}\n\n/** Parallel lines in an area. A cross hatch adds the same lines at right angles. */\nexport interface HatchStyle {\n /** The angle of the lines in degrees, clockwise from horizontal. */\n readonly angleDegrees: number;\n /** The distance between two lines in millimetres. It is more than the width of a line. */\n readonly spacingMm: number;\n /** The width of a line in millimetres. */\n readonly widthMm: number;\n /** The value `true` adds the lines at right angles. The default is `false`. */\n readonly cross?: boolean;\n}\n\n/** The fill of an area: a gray level, a hatch, or the two. The hatch is on top of the gray level. */\nexport interface FillStyle {\n /** The gray level from 0 (black) to 1 (white). No value gives no solid fill. */\n readonly gray?: number;\n /** The hatch. No value gives no hatch. */\n readonly hatch?: HatchStyle;\n}\n\n/** The symbols of the points. */\nexport type PointSymbol = \"circle\" | \"square\" | \"triangle\" | \"diamond\" | \"cross\";\n\n/** The symbol of each point. */\nexport interface PointStyle {\n /** The shape of the symbol. */\n readonly symbol: PointSymbol;\n /** The size of the symbol in millimetres. */\n readonly sizeMm: number;\n /** The value `false` gives a white symbol with a black outline. The default is `true`, a black symbol. */\n readonly filled?: boolean;\n}\n\n/** The style of a layer. The line is for the lines and the edges of the areas. The fill is for the areas, and the symbol is for the points. */\nexport interface Style {\n /** The line. */\n readonly stroke?: StrokeStyle;\n /** The fill of the areas. */\n readonly fill?: FillStyle;\n /** The symbol of the points. */\n readonly point?: PointStyle;\n}\n\nconst SYMBOLS: readonly string[] = [\"circle\", \"square\", \"triangle\", \"diamond\", \"cross\"];\n\nfunction positive(value: unknown, name: string, layer: string): void {\n if (!(typeof value === \"number\" && Number.isFinite(value) && value > 0)) {\n throw new MapError(\"style\", `The layer \"${layer}\": the ${name} ${String(value)} is not a finite number more than 0`);\n }\n}\n\nfunction grayLevel(value: unknown, layer: string): void {\n if (value === undefined) return;\n if (!(typeof value === \"number\" && value >= 0 && value <= 1)) {\n throw new MapError(\"style\", `The layer \"${layer}\": the gray level ${String(value)} is not from 0 to 1`);\n }\n}\n\n/**\n * This function refuses a style that draws nothing, and a size, a gray level, a dash or a symbol that is not correct.\n *\n * @throws MapError - The code is `style`.\n */\nexport function checkStyle(style: Style, layer: string): void {\n if (style.stroke === undefined && style.fill === undefined && style.point === undefined) {\n throw new MapError(\"style\", `The layer \"${layer}\": the style has no stroke, no fill and no point, so it draws nothing`);\n }\n if (style.stroke !== undefined) {\n positive(style.stroke.widthMm, \"width of the line\", layer);\n grayLevel(style.stroke.gray, layer);\n for (const dash of style.stroke.dashMm ?? []) positive(dash, \"length of a dash\", layer);\n }\n if (style.fill !== undefined) {\n grayLevel(style.fill.gray, layer);\n if (style.fill.gray === undefined && style.fill.hatch === undefined) {\n throw new MapError(\"style\", `The layer \"${layer}\": the fill has no gray level and no hatch`);\n }\n const hatch = style.fill.hatch;\n if (hatch !== undefined) {\n positive(hatch.widthMm, \"width of a hatch line\", layer);\n positive(hatch.spacingMm, \"spacing of the hatch\", layer);\n if (!Number.isFinite(hatch.angleDegrees)) throw new MapError(\"style\", `The layer \"${layer}\": the angle ${hatch.angleDegrees} is not finite`);\n if (hatch.spacingMm <= hatch.widthMm) throw new MapError(\"style\", `The layer \"${layer}\": the spacing of the hatch is not more than its width`);\n }\n }\n if (style.point !== undefined) {\n positive(style.point.sizeMm, \"size of the symbol\", layer);\n if (!SYMBOLS.includes(style.point.symbol)) throw new MapError(\"style\", `The layer \"${layer}\": the symbol \"${style.point.symbol}\" is not one of ${SYMBOLS.join(\", \")}`);\n }\n}\n\n/** This function gives a number for SVG, to 0.01 mm. */\nexport function mm(value: number): string {\n return String(Math.round(value * 100) / 100 + 0);\n}\n\n/** This function gives the color of a gray level, from `#000000` to `#ffffff`. */\nexport function grayColor(gray: number): string {\n const hex = Math.round(gray * 255)\n .toString(16)\n .padStart(2, \"0\");\n return `#${hex}${hex}${hex}`;\n}\n\n/** This function gives the SVG attributes of a line. */\nexport function strokeAttributes(stroke: StrokeStyle): string {\n const dash = stroke.dashMm === undefined || stroke.dashMm.length === 0 ? \"\" : ` stroke-dasharray=\"${stroke.dashMm.map(mm).join(\" \")}\"`;\n return `stroke=\"${grayColor(stroke.gray ?? 0)}\" stroke-width=\"${mm(stroke.widthMm)}\"${dash} stroke-linecap=\"round\" stroke-linejoin=\"round\"`;\n}\n\n/** This function gives the SVG pattern of a hatch, with an identifier. */\nexport function hatchPattern(id: string, hatch: HatchStyle): string {\n const s = mm(hatch.spacingMm);\n const half = mm(hatch.spacingMm / 2);\n const line = `stroke=\"#000000\" stroke-width=\"${mm(hatch.widthMm)}\"`;\n const across = hatch.cross === true ? `<line x1=\"${half}\" y1=\"0\" x2=\"${half}\" y2=\"${s}\" ${line}/>` : \"\";\n return (\n `<pattern id=\"${id}\" patternUnits=\"userSpaceOnUse\" width=\"${s}\" height=\"${s}\" patternTransform=\"rotate(${mm(hatch.angleDegrees)})\">` +\n `<line x1=\"0\" y1=\"${half}\" x2=\"${s}\" y2=\"${half}\" ${line}/>${across}</pattern>`\n );\n}\n\n/** This function gives the SVG of a point symbol at a point on the paper. */\nexport function pointSymbol(point: PointStyle, x: number, y: number): string {\n const r = point.sizeMm / 2;\n const filled = point.filled !== false;\n const paint = filled ? `fill=\"#000000\"` : `fill=\"#ffffff\" stroke=\"#000000\" stroke-width=\"${mm(point.sizeMm / 8)}\"`;\n switch (point.symbol) {\n case \"circle\":\n return `<circle cx=\"${mm(x)}\" cy=\"${mm(y)}\" r=\"${mm(r)}\" ${paint}/>`;\n case \"square\":\n return `<rect x=\"${mm(x - r)}\" y=\"${mm(y - r)}\" width=\"${mm(2 * r)}\" height=\"${mm(2 * r)}\" ${paint}/>`;\n case \"triangle\":\n return `<path d=\"M${mm(x)} ${mm(y - r)}L${mm(x + r)} ${mm(y + r)}L${mm(x - r)} ${mm(y + r)}Z\" ${paint}/>`;\n case \"diamond\":\n return `<path d=\"M${mm(x)} ${mm(y - r)}L${mm(x + r)} ${mm(y)}L${mm(x)} ${mm(y + r)}L${mm(x - r)} ${mm(y)}Z\" ${paint}/>`;\n case \"cross\":\n return `<path d=\"M${mm(x - r)} ${mm(y)}L${mm(x + r)} ${mm(y)}M${mm(x)} ${mm(y - r)}L${mm(x)} ${mm(y + r)}\" stroke=\"#000000\" stroke-width=\"${mm(point.sizeMm / 5)}\" fill=\"none\"/>`;\n }\n}\n","/**\n * The labels of a map: the names of points, lines and areas, with no overlap.\n *\n * @packageDocumentation\n */\n\nimport { locatePoint, type Feature, type Geometry, type Polygon, type Position } from \"@mark1russell7/geo\";\nimport { escapeAttribute, escapeHtml } from \"@mark1russell7/text\";\nimport { MapError } from \"./errors.ts\";\nimport type { FrameView, PaperPoint } from \"./frame.ts\";\nimport { mm } from \"./style.ts\";\n\n/** The rule of the labels of a layer. */\nexport interface LabelRule {\n /** The properties of a feature, in sequence. The first property with a text that is not empty gives the label. */\n readonly properties: readonly string[];\n /** The size of the font in millimetres on the paper. */\n readonly sizeMm: number;\n /** The rank of the labels of the layer. A lower rank gets its places first. The default is 0. */\n readonly priority?: number;\n /** For a line: the distance in millimetres between two labels of the same text. No value gives one label for each text. */\n readonly repeatMm?: number;\n}\n\n/** The font of the labels. The width of a label comes from `measure`, so the font of the print must be the same font. */\nexport interface LabelFont {\n /** The CSS font family of the labels, for example `\"Liberation Sans\", Arial, sans-serif`. */\n readonly family: string;\n /** This function gives the width in millimetres of a text at a size of the font in millimetres. */\n readonly measure: (text: string, sizeMm: number) => number;\n}\n\n/** A label with its place: the middle of its box on the paper, and its angle. */\nexport interface PlacedLabel {\n /** The identifier of the layer of the label. */\n readonly layer: string;\n readonly text: string;\n /** The middle of the label on the paper, in millimetres from the top left corner of the frame. */\n readonly x: number;\n readonly y: number;\n /** The angle of the text in degrees, clockwise, more than -90 and not more than 90. So each label reads from the left. */\n readonly angle: number;\n readonly sizeMm: number;\n readonly widthMm: number;\n}\n\n/** The labels of a map: the labels with a place, and the texts with no place. */\nexport interface LabelPlacement {\n readonly placed: readonly PlacedLabel[];\n /** Each text that has no place with no overlap, inside the frame. */\n readonly skipped: readonly { readonly layer: string; readonly text: string }[];\n}\n\n/** A layer as the labels see it: its identifier, its features after its filter, its rule and the size of its points. */\nexport interface LabelLayer {\n readonly id: string;\n readonly features: readonly Feature[];\n readonly label?: LabelRule | undefined;\n /** The size in millimetres of the point symbol of the layer, when its style has points. */\n readonly pointSizeMm?: number | undefined;\n}\n\n/** The gap in millimetres between a point symbol and its label. */\nconst POINT_GAP_MM = 0.6;\n/** The margin in millimetres between a label and the edge of the frame. */\nconst FRAME_MARGIN_MM = 0.5;\n/** The height of the box of a label, as a part of the size of the font. */\nconst BOX_HEIGHT = 1.2;\n/** The room in millimetres at each end of a label along a line. */\nconst LINE_PAD_MM = 1;\n/** The largest distance from a line to the chord of a label, as a part of the size of the font. */\nconst LINE_BEND = 0.25;\n\n/**\n * This function examines the label rule of a layer.\n *\n * @throws MapError - The code is `label`.\n */\nexport function checkLabelRule(rule: LabelRule, layer: string): void {\n const fail = (reason: string): never => {\n throw new MapError(\"label\", `The labels of the layer \"${layer}\": ${reason}`);\n };\n if (!Array.isArray(rule.properties) || rule.properties.length === 0) fail(\"give at least one property\");\n for (const property of rule.properties) if (typeof property !== \"string\" || property === \"\") fail(\"each property is a text that is not empty\");\n if (!(Number.isFinite(rule.sizeMm) && rule.sizeMm > 0)) fail(`the size ${rule.sizeMm} is not a finite number more than 0`);\n if (rule.priority !== undefined && !Number.isFinite(rule.priority)) fail(`the priority ${rule.priority} is not a finite number`);\n if (rule.repeatMm !== undefined && !(Number.isFinite(rule.repeatMm) && rule.repeatMm > 0)) fail(`the distance ${rule.repeatMm} is not a finite number more than 0`);\n}\n\n/** This function gives the text of the label of a feature: the first property of the rule with a text. */\nexport function labelText(rule: LabelRule, feature: Feature): string | undefined {\n for (const property of rule.properties) {\n const value = feature.properties?.[property];\n if ((typeof value === \"string\" || typeof value === \"number\") && String(value).trim() !== \"\") return String(value).trim();\n }\n return undefined;\n}\n\n/** A box on the paper with an angle: its middle, its half width, its half height and its angle in radians. */\ninterface Box {\n readonly x: number;\n readonly y: number;\n readonly hw: number;\n readonly hh: number;\n readonly angle: number;\n}\n\nfunction corners(box: Box): PaperPoint[] {\n const c = Math.cos(box.angle);\n const s = Math.sin(box.angle);\n return [\n [-box.hw, -box.hh],\n [box.hw, -box.hh],\n [box.hw, box.hh],\n [-box.hw, box.hh],\n ].map(([u, v]) => ({ x: box.x + u! * c - v! * s, y: box.y + u! * s + v! * c }));\n}\n\n/** This function tells if two boxes overlap: the test of the separating axis for two rectangles. */\nfunction overlaps(a: Box, b: Box): boolean {\n const ca = corners(a);\n const cb = corners(b);\n for (const angle of [a.angle, a.angle + Math.PI / 2, b.angle, b.angle + Math.PI / 2]) {\n const ax = Math.cos(angle);\n const ay = Math.sin(angle);\n const pa = ca.map((p) => p.x * ax + p.y * ay);\n const pb = cb.map((p) => p.x * ax + p.y * ay);\n if (Math.max(...pa) <= Math.min(...pb) || Math.max(...pb) <= Math.min(...pa)) return false;\n }\n return true;\n}\n\n/** The boxes that a label must not overlap, and the frame. */\nclass Room {\n readonly boxes: Box[] = [];\n readonly widthMm: number;\n readonly heightMm: number;\n\n constructor(widthMm: number, heightMm: number) {\n this.widthMm = widthMm;\n this.heightMm = heightMm;\n }\n\n fits(box: Box): boolean {\n for (const p of corners(box)) {\n if (p.x < FRAME_MARGIN_MM || p.y < FRAME_MARGIN_MM || p.x > this.widthMm - FRAME_MARGIN_MM || p.y > this.heightMm - FRAME_MARGIN_MM) return false;\n }\n return !this.boxes.some((other) => overlaps(box, other));\n }\n}\n\nfunction paperOf(position: Position, view: FrameView): PaperPoint {\n return view.toPaper({ lat: position[1] as number, lon: position[0] as number });\n}\n\n/** This function gives the points, the lines and the areas of a geometry. */\nfunction parts(geometry: Geometry, out: { points: Position[]; lines: (readonly Position[])[]; areas: Polygon[] }): void {\n switch (geometry.type) {\n case \"Point\":\n out.points.push(geometry.coordinates);\n break;\n case \"MultiPoint\":\n out.points.push(...geometry.coordinates);\n break;\n case \"LineString\":\n out.lines.push(geometry.coordinates);\n break;\n case \"MultiLineString\":\n out.lines.push(...geometry.coordinates);\n break;\n case \"Polygon\":\n out.areas.push(geometry);\n break;\n case \"MultiPolygon\":\n for (const coordinates of geometry.coordinates) out.areas.push({ type: \"Polygon\", coordinates });\n break;\n case \"GeometryCollection\":\n for (const item of geometry.geometries) parts(item, out);\n break;\n }\n}\n\n/** This function gives the angle of a direction in radians, more than -pi/2 and not more than pi/2, so the text reads from the left. */\nfunction readable(dx: number, dy: number): number {\n let angle = Math.atan2(dy, dx);\n if (angle > Math.PI / 2) angle -= Math.PI;\n if (angle <= -Math.PI / 2) angle += Math.PI;\n return angle;\n}\n\n/**\n * This function gives the runs of a line on the paper: the parts with each segment in a box that touches the frame. So\n * a segment that crosses the frame stays in its run. A run can go past the frame, but a label box outside the frame\n * does not fit.\n */\nfunction runs(line: readonly Position[], view: FrameView): PaperPoint[][] {\n const { widthMm: w, heightMm: h } = view.frame;\n const points = line.map((position) => paperOf(position, view));\n const out: PaperPoint[][] = [];\n let run: PaperPoint[] = [];\n for (let i = 1; i < points.length; i += 1) {\n const a = points[i - 1]!;\n const b = points[i]!;\n if (Math.max(a.x, b.x) >= 0 && Math.min(a.x, b.x) <= w && Math.max(a.y, b.y) >= 0 && Math.min(a.y, b.y) <= h) {\n if (run.length === 0) run.push(a);\n run.push(b);\n } else {\n if (run.length > 1) out.push(run);\n run = [];\n }\n }\n if (run.length > 1) out.push(run);\n return out;\n}\n\n/** This function gives the length of a run on the paper. */\nfunction runLength(run: readonly PaperPoint[]): number {\n let total = 0;\n for (let i = 1; i < run.length; i += 1) total += Math.hypot(run[i]!.x - run[i - 1]!.x, run[i]!.y - run[i - 1]!.y);\n return total;\n}\n\n/** This function gives the point at a distance along a run, with the cumulative lengths of the run. */\nfunction along(run: readonly PaperPoint[], lengths: readonly number[], s: number): PaperPoint {\n let i = 1;\n while (i < run.length - 1 && lengths[i]! < s) i += 1;\n const a = run[i - 1]!;\n const b = run[i]!;\n const span = lengths[i]! - lengths[i - 1]!;\n const t = span === 0 ? 0 : (s - lengths[i - 1]!) / span;\n return { x: a.x + t * (b.x - a.x), y: a.y + t * (b.y - a.y) };\n}\n\n/**\n * This function gives the boxes of a label along a run, from the middle of the run to its ends. A box is on an almost\n * straight part of the run. No point of that part is farther from the chord than `LINE_BEND` of the size.\n */\nfunction lineCandidates(run: readonly PaperPoint[], width: number, size: number): Box[] {\n const lengths = [0];\n for (let i = 1; i < run.length; i += 1) lengths.push(lengths[i - 1]! + Math.hypot(run[i]!.x - run[i - 1]!.x, run[i]!.y - run[i - 1]!.y));\n const total = lengths.at(-1)!;\n const span = width + 2 * LINE_PAD_MM;\n if (total < span) return [];\n const step = Math.max(span / 4, 2);\n // The middles go from the middle of the run to its ends, one step at a time, first toward the start.\n const middles = [total / 2];\n for (let k = 1; k * step <= total / 2 - span / 2; k += 1) middles.push(total / 2 - k * step, total / 2 + k * step);\n const boxes: Box[] = [];\n for (const middle of middles) {\n const start = along(run, lengths, middle - span / 2);\n const end = along(run, lengths, middle + span / 2);\n const chord = Math.hypot(end.x - start.x, end.y - start.y);\n if (chord < 0.9 * span) continue;\n const inside = run.filter((_, i) => lengths[i]! > middle - span / 2 && lengths[i]! < middle + span / 2);\n const bend = Math.max(0, ...inside.map((p) => Math.abs((end.x - start.x) * (start.y - p.y) - (start.x - p.x) * (end.y - start.y)) / chord));\n if (bend > LINE_BEND * size) continue;\n boxes.push({ x: (start.x + end.x) / 2, y: (start.y + end.y) / 2, hw: width / 2, hh: (BOX_HEIGHT * size) / 2, angle: readable(end.x - start.x, end.y - start.y) });\n }\n return boxes;\n}\n\n/** This function gives the boxes of a label around a point, in the sequence of the preferred places. */\nfunction pointCandidates(p: PaperPoint, width: number, size: number, symbolMm: number): Box[] {\n const hw = width / 2;\n const hh = (BOX_HEIGHT * size) / 2;\n const d = symbolMm / 2 + POINT_GAP_MM;\n const k = d * Math.SQRT1_2;\n return [\n [d + hw, 0],\n [-d - hw, 0],\n [0, -d - hh],\n [0, d + hh],\n [k + hw, -k - hh],\n [k + hw, k + hh],\n [-k - hw, -k - hh],\n [-k - hw, k + hh],\n ].map(([dx, dy]) => ({ x: p.x + dx!, y: p.y + dy!, hw, hh, angle: 0 }));\n}\n\n/** This function gives the box of a label in the middle of an area, when the area has each corner of the box. */\nfunction areaCandidates(area: Polygon, view: FrameView, width: number, size: number): Box[] {\n const ring = area.coordinates[0] ?? [];\n if (ring.length < 4) return [];\n const points = ring.map((position) => paperOf(position, view));\n let doubled = 0;\n let cx = 0;\n let cy = 0;\n for (let i = 0; i + 1 < points.length; i += 1) {\n const a = points[i]!;\n const b = points[i + 1]!;\n const cross = a.x * b.y - b.x * a.y;\n doubled += cross;\n cx += (a.x + b.x) * cross;\n cy += (a.y + b.y) * cross;\n }\n const xs = points.map((p) => p.x);\n const ys = points.map((p) => p.y);\n const middle = { x: (Math.min(...xs) + Math.max(...xs)) / 2, y: (Math.min(...ys) + Math.max(...ys)) / 2 };\n const centers = doubled === 0 ? [middle] : [{ x: cx / (3 * doubled), y: cy / (3 * doubled) }, middle];\n const hw = width / 2;\n const hh = (BOX_HEIGHT * size) / 2;\n return centers\n .map((c) => ({ x: c.x, y: c.y, hw, hh, angle: 0 }))\n .filter((box) => [...corners(box), { x: box.x, y: box.y }].every((p) => locatePoint(view.fromPaper(p), area) === \"inside\"));\n}\n\n/** This function tells if the box of the outer ring of an area on the paper touches the frame. */\nfunction areaOnFrame(area: Polygon, view: FrameView): boolean {\n const points = (area.coordinates[0] ?? []).map((position) => paperOf(position, view));\n const xs = points.map((p) => p.x);\n const ys = points.map((p) => p.y);\n return points.length > 0 && Math.max(...xs) >= 0 && Math.min(...xs) <= view.frame.widthMm && Math.max(...ys) >= 0 && Math.min(...ys) <= view.frame.heightMm;\n}\n\n/** One text of a layer, and the parts of the features with that text. */\ninterface Job {\n readonly layer: LabelLayer;\n readonly rule: LabelRule;\n readonly text: string;\n readonly width: number;\n readonly points: Position[];\n readonly lines: (readonly Position[])[];\n readonly areas: Polygon[];\n}\n\n/**\n * This function gives the places of the labels of the layers. The labels do not overlap, and each label is inside the\n * frame.\n *\n * - The layers with a lower `priority` get their places first. With the same priority, a higher layer is first.\n * - In a layer, the features with the same text are one job. A longer line is first, then the sequence of the features.\n * - A point gets the first free place of 8 places around its symbol: right, left, above, below, then the corners.\n * - A line gets its text along an almost straight part. The longest run is first, and the middle of a run is first.\n * - With `repeatMm`, a line gets more labels of its text, at that distance or more from each other.\n * - An area gets its text at its centroid or at the middle of its box, when the area has the box of the text.\n * - Each point symbol of the layers and the north arrow are obstacles too.\n * - A text with a part on the frame and no free place is in `skipped`. A text with no part on the frame is in neither list.\n *\n * @param obstacles - The boxes on the paper that no label covers, as the middle and the half size in millimetres.\n * @throws MapError - The code is `label`: the width of a text from `measure` is not a finite number of 0 or more.\n */\nexport function placeLabels(layers: readonly LabelLayer[], view: FrameView, font: LabelFont, obstacles: readonly { x: number; y: number; half: number }[] = []): LabelPlacement {\n const room = new Room(view.frame.widthMm, view.frame.heightMm);\n for (const o of obstacles) room.boxes.push({ x: o.x, y: o.y, hw: o.half, hh: o.half, angle: 0 });\n for (const layer of layers) {\n if (layer.pointSizeMm === undefined) continue;\n const out: { points: Position[]; lines: (readonly Position[])[]; areas: Polygon[] } = { points: [], lines: [], areas: [] };\n for (const feature of layer.features) if (feature.geometry !== null) parts(feature.geometry, out);\n for (const position of out.points) {\n const p = paperOf(position, view);\n room.boxes.push({ x: p.x, y: p.y, hw: layer.pointSizeMm / 2, hh: layer.pointSizeMm / 2, angle: 0 });\n }\n }\n\n const order = layers\n .map((layer, index) => ({ layer, index }))\n .filter((entry): entry is { layer: LabelLayer & { label: LabelRule }; index: number } => entry.layer.label !== undefined)\n .sort((a, b) => (a.layer.label.priority ?? 0) - (b.layer.label.priority ?? 0) || b.index - a.index);\n\n const placed: PlacedLabel[] = [];\n const skipped: { layer: string; text: string }[] = [];\n for (const { layer } of order) {\n const rule = layer.label;\n const jobs = new Map<string, Job>();\n for (const feature of layer.features) {\n if (feature.geometry === null) continue;\n const text = labelText(rule, feature);\n if (text === undefined) continue;\n let job = jobs.get(text);\n if (job === undefined) {\n const width = font.measure(text, rule.sizeMm);\n if (!(Number.isFinite(width) && width >= 0)) throw new MapError(\"label\", `The width ${width} of the label \"${text}\" is not a finite number of 0 or more`);\n job = { layer, rule, text, width, points: [], lines: [], areas: [] };\n jobs.set(text, job);\n }\n parts(feature.geometry, job);\n }\n // The runs of each job, the longest first. The jobs with the most length of line are first.\n const sorted = [...jobs.values()]\n .map((job) => {\n const lineRuns = job.lines\n .flatMap((line) => runs(line, view))\n .map((run) => ({ run, length: runLength(run) }))\n .sort((a, b) => b.length - a.length);\n return { job, lineRuns, length: lineRuns.reduce((t, entry) => t + entry.length, 0) };\n })\n .sort((a, b) => b.length - a.length);\n for (const { job, lineRuns } of sorted) {\n const mine: PlacedLabel[] = [];\n // A text is in `skipped` only when a part of its features is on the frame.\n let onFrame = false;\n const take = (box: Box): boolean => {\n if (!room.fits(box)) return false;\n if (job.rule.repeatMm !== undefined && mine.some((other) => Math.hypot(other.x - box.x, other.y - box.y) < job.rule.repeatMm!)) return false;\n room.boxes.push(box);\n mine.push({ layer: layer.id, text: job.text, x: box.x, y: box.y, angle: (box.angle * 180) / Math.PI + 0, sizeMm: job.rule.sizeMm, widthMm: job.width });\n return true;\n };\n for (const position of job.points) {\n const p = paperOf(position, view);\n if (p.x < 0 || p.y < 0 || p.x > view.frame.widthMm || p.y > view.frame.heightMm) continue;\n onFrame = true;\n pointCandidates(p, job.width, job.rule.sizeMm, layer.pointSizeMm ?? 0).some(take);\n }\n if (lineRuns.length > 0) onFrame = true;\n lines: for (const { run } of lineRuns) {\n for (const box of lineCandidates(run, job.width, job.rule.sizeMm)) {\n if (take(box) && job.rule.repeatMm === undefined) break lines;\n }\n }\n for (const area of job.areas) {\n if (!areaOnFrame(area, view)) continue;\n onFrame = true;\n areaCandidates(area, view, job.width, job.rule.sizeMm).some(take);\n }\n if (mine.length === 0 && onFrame) skipped.push({ layer: layer.id, text: job.text });\n placed.push(...mine);\n }\n }\n return { placed, skipped };\n}\n\n/** This function gives the SVG of the labels: black text with a white halo, so a label reads over the lines of the map. */\nexport function labelsSvg(placement: LabelPlacement, font: LabelFont): string {\n const texts = placement.placed.map((label) => {\n const rotate = label.angle === 0 ? \"\" : ` transform=\"rotate(${mm(label.angle)} ${mm(label.x)} ${mm(label.y)})\"`;\n return (\n `<text x=\"${mm(label.x)}\" y=\"${mm(label.y)}\" font-size=\"${mm(label.sizeMm)}\"${rotate} text-anchor=\"middle\" dominant-baseline=\"central\" ` +\n `fill=\"#000000\" stroke=\"#ffffff\" stroke-width=\"${mm(label.sizeMm * 0.25)}\" stroke-linejoin=\"round\" paint-order=\"stroke\">${escapeHtml(label.text)}</text>`\n );\n });\n return `<g class=\"labels\" font-family=\"${escapeAttribute(font.family)}\" data-skipped=\"${placement.skipped.length}\">${texts.join(\"\")}</g>`;\n}\n","/**\n * The marks of a map: the scale bar and the north arrow.\n *\n * @packageDocumentation\n */\n\nimport { escapeHtml } from \"@mark1russell7/text\";\nimport { mm } from \"./style.ts\";\n\n/** The units of the scale bars of a map. `both` gives a metric bar and an imperial bar. */\nexport type ScaleBarUnits = \"metric\" | \"imperial\" | \"both\" | \"none\";\n\n/** The length of a scale bar on the ground and its label. */\nexport interface ScaleBarLength {\n /** The length on the ground in metres. */\n readonly meters: number;\n /** The label, for example `500 m`, `2 km`, `0.5 mi` or `200 ft`. */\n readonly label: string;\n}\n\nconst METERS_PER_MILE = 1609.344;\nconst METERS_PER_FOOT = 0.3048;\n\n/** This function gives the largest number 1, 2 or 5 times a power of 10 that is not more than a number more than 0. */\nexport function niceNumber(max: number): number {\n const power = 10 ** Math.floor(Math.log10(max));\n for (const step of [5, 2, 1]) {\n const value = Number((step * power).toPrecision(1));\n if (value <= max) return value;\n }\n return Number((power / 2).toPrecision(1));\n}\n\n/**\n * This function gives the length of a scale bar that is not longer than a length on the ground.\n *\n * - The metric bar is in metres below 1 km, and in kilometres from 1 km.\n * - The imperial bar is in miles from a quarter of a mile, and in feet below that.\n */\nexport function scaleBarLength(maxMeters: number, units: \"metric\" | \"imperial\"): ScaleBarLength {\n if (units === \"metric\") {\n const meters = niceNumber(maxMeters);\n return { meters, label: meters >= 1000 ? `${meters / 1000} km` : `${meters} m` };\n }\n const miles = maxMeters / METERS_PER_MILE;\n if (miles >= 0.25) {\n const value = niceNumber(miles);\n return { meters: value * METERS_PER_MILE, label: `${value} mi` };\n }\n const feet = niceNumber(maxMeters / METERS_PER_FOOT);\n return { meters: feet * METERS_PER_FOOT, label: `${feet} ft` };\n}\n\n/** The height of one scale bar with its label, in millimetres. */\nexport const SCALE_BAR_ROW_MM = 4.5;\n\n/** This function gives the SVG of a scale bar of four parts, with its top left corner at a point on the paper. */\nexport function scaleBarSvg(x: number, y: number, length: ScaleBarLength, mmPerMeter: number): string {\n const total = length.meters * mmPerMeter;\n const part = total / 4;\n let parts = \"\";\n for (let i = 0; i < 4; i += 1) {\n parts += `<rect x=\"${mm(x + i * part)}\" y=\"${mm(y)}\" width=\"${mm(part)}\" height=\"1.5\" fill=\"${i % 2 === 0 ? \"#000000\" : \"#ffffff\"}\" stroke=\"#000000\" stroke-width=\"0.15\"/>`;\n }\n return `<g class=\"scale-bar\">${parts}<text x=\"${mm(x + total + 1.5)}\" y=\"${mm(y + 1.5)}\" font-size=\"2.4\">${escapeHtml(length.label)}</text></g>`;\n}\n\n/** This function gives the SVG of a north arrow at a point on the paper, with the direction of north in degrees. */\nexport function northArrowSvg(x: number, y: number, northDegrees: number): string {\n return (\n `<g class=\"north-arrow\" transform=\"translate(${mm(x)} ${mm(y)}) rotate(${mm(northDegrees)})\">` +\n `<circle r=\"4.5\" fill=\"#ffffff\" stroke=\"#000000\" stroke-width=\"0.2\"/>` +\n `<path d=\"M0 -3.6L1.6 1.2L0 0.4L-1.6 1.2Z\" fill=\"#000000\"/>` +\n `<text y=\"3.9\" font-size=\"2.2\" text-anchor=\"middle\">N</text></g>`\n );\n}\n","/**\n * A map as data, and its render to SVG.\n *\n * @packageDocumentation\n */\n\nimport { simplifyRegions, type Feature, type Geometry, type Position, type Region } from \"@mark1russell7/geo\";\nimport { escapeAttribute, escapeHtml } from \"@mark1russell7/text\";\nimport { MapError } from \"./errors.ts\";\nimport { checkFilter, matchesFilter, type Filter } from \"./filter.ts\";\nimport { frameView, type Frame, type FrameView, type PaperPoint } from \"./frame.ts\";\nimport { checkLabelRule, labelsSvg, placeLabels, type LabelFont, type LabelPlacement, type LabelRule } from \"./labels.ts\";\nimport { northArrowSvg, SCALE_BAR_ROW_MM, scaleBarLength, scaleBarSvg, type ScaleBarUnits } from \"./marks.ts\";\nimport { checkStyle, grayColor, hatchPattern, mm, pointSymbol, strokeAttributes, type Style } from \"./style.ts\";\n\n/** The source of the data of a layer. The map prints each source in its attribution block. */\nexport interface Source {\n /** The name of the source, for example `© OpenStreetMap contributors`. */\n readonly title: string;\n /** The license of the data, for example `ODbL 1.0`. */\n readonly license: string;\n /** The web address of the source or of its license. */\n readonly url?: string;\n /** The date of the data, for example `2026-11-21`. */\n readonly date?: string;\n}\n\n/** A layer of a map: features, a filter, a style and the source of the features. */\nexport interface Layer {\n /** The identifier of the layer: lower case letters, digits and hyphens. It starts with a letter. */\n readonly id: string;\n /** The features. Their positions are `[lon, lat]` on WGS84. */\n readonly features: readonly Feature[];\n /** The style of the features. */\n readonly style: Style;\n /** The source of the features. */\n readonly source: Source;\n /** The filter of the features. No filter keeps each feature. */\n readonly filter?: Filter;\n /** The text of the layer in the legend. No text gives no entry in the legend. */\n readonly legend?: string;\n /** The tolerance in millimetres on the paper for the simplification of the areas. No value keeps each position. */\n readonly simplifyMm?: number;\n /** The rule of the labels of the features. No rule gives no labels. */\n readonly label?: LabelRule;\n}\n\n/** A map: a frame, layers from the bottom to the top, and its marks. */\nexport interface MapDocument {\n /** The identifier of the map: lower case letters, digits and hyphens. It starts each identifier in the SVG. */\n readonly id: string;\n /** The title of the map, for a reader of the screen. */\n readonly title: string;\n /** The frame. */\n readonly frame: Frame;\n /** The layers, from the bottom to the top. */\n readonly layers: readonly Layer[];\n /** The units of the scale bars. The default is `both`. */\n readonly scaleBar?: ScaleBarUnits;\n /** The value `false` gives no north arrow. The default is `true`. */\n readonly northArrow?: boolean;\n /** The place of the scale bars and the legend. The default is `below`. `fitFrame` finds the place with the largest frame. */\n readonly legendPlace?: LegendPlace;\n}\n\n/** The place of the scale bars and the legend: below the frame, or in a column at the right side of the frame. */\nexport type LegendPlace = \"below\" | \"side\";\n\nconst LEGEND_PLACES: readonly LegendPlace[] = [\"below\", \"side\"];\n\nconst ID = /^[a-z][a-z0-9-]*$/;\n\nfunction checkId(id: string, what: string): void {\n if (!ID.test(id)) throw new MapError(\"id\", `The identifier \"${id}\" of the ${what} is not lower case letters, digits and hyphens that start with a letter`);\n}\n\nfunction checkSource(source: Source | undefined, layer: string): void {\n if (source === undefined || typeof source !== \"object\") throw new MapError(\"source\", `The layer \"${layer}\" has no source`);\n if (typeof source.title !== \"string\" || source.title.trim() === \"\") throw new MapError(\"source\", `The source of the layer \"${layer}\" has no title`);\n if (typeof source.license !== \"string\" || source.license.trim() === \"\") throw new MapError(\"source\", `The source of the layer \"${layer}\" has no license`);\n}\n\n/**\n * This function examines a map. It refuses a frame, an identifier, a style, a filter or a source that is not correct.\n * Each layer must have a source with a title and a license, so the attribution block names each source of the map.\n *\n * @throws MapError - The code tells the reason.\n */\nexport function checkMap(map: MapDocument): void {\n checkId(map.id, \"map\");\n frameView(map.frame);\n if (map.legendPlace !== undefined && !LEGEND_PLACES.includes(map.legendPlace)) {\n throw new MapError(\"style\", `The place of the legend \"${String(map.legendPlace)}\" is not \"below\" or \"side\"`);\n }\n const ids = new Set<string>();\n for (const layer of map.layers) {\n checkId(layer.id, \"layer\");\n if (ids.has(layer.id)) throw new MapError(\"id\", `Two layers have the identifier \"${layer.id}\"`);\n ids.add(layer.id);\n checkSource(layer.source, layer.id);\n checkStyle(layer.style, layer.id);\n if (layer.filter !== undefined) checkFilter(layer.filter, `layer \"${layer.id}\" filter`);\n if (layer.label !== undefined) checkLabelRule(layer.label, layer.id);\n if (layer.simplifyMm !== undefined && !(Number.isFinite(layer.simplifyMm) && layer.simplifyMm > 0)) {\n throw new MapError(\"style\", `The layer \"${layer.id}\": the tolerance ${layer.simplifyMm} is not a finite number more than 0`);\n }\n }\n}\n\n/** The box of the points on the paper that a feature uses. */\nclass PaperBox {\n minX = Number.POSITIVE_INFINITY;\n minY = Number.POSITIVE_INFINITY;\n maxX = Number.NEGATIVE_INFINITY;\n maxY = Number.NEGATIVE_INFINITY;\n\n add(point: PaperPoint): void {\n this.minX = Math.min(this.minX, point.x);\n this.minY = Math.min(this.minY, point.y);\n this.maxX = Math.max(this.maxX, point.x);\n this.maxY = Math.max(this.maxY, point.y);\n }\n\n /** It tells if the box touches the frame, with a margin in millimetres. */\n touches(frame: Frame, margin: number): boolean {\n return this.maxX >= -margin && this.minX <= frame.widthMm + margin && this.maxY >= -margin && this.minY <= frame.heightMm + margin;\n }\n}\n\nfunction paperOf(position: Position, view: FrameView): PaperPoint {\n return view.toPaper({ lat: position[1] as number, lon: position[0] as number });\n}\n\nfunction linePath(positions: readonly Position[], view: FrameView, box: PaperBox, close: boolean): string {\n let d = \"\";\n positions.forEach((position, i) => {\n const point = paperOf(position, view);\n box.add(point);\n d += `${i === 0 ? \"M\" : \"L\"}${mm(point.x)} ${mm(point.y)}`;\n });\n return close ? `${d}Z` : d;\n}\n\n/** This function gives the SVG of one geometry with a style. */\nfunction drawGeometry(geometry: Geometry, style: Style, view: FrameView, fill: string | undefined): string {\n const frame = view.frame;\n switch (geometry.type) {\n case \"Point\":\n case \"MultiPoint\": {\n if (style.point === undefined) return \"\";\n const positions = geometry.type === \"Point\" ? [geometry.coordinates] : geometry.coordinates;\n return positions\n .map((position) => paperOf(position, view))\n .filter((point) => point.x >= -style.point!.sizeMm && point.x <= frame.widthMm + style.point!.sizeMm && point.y >= -style.point!.sizeMm && point.y <= frame.heightMm + style.point!.sizeMm)\n .map((point) => pointSymbol(style.point!, point.x, point.y))\n .join(\"\");\n }\n case \"LineString\":\n case \"MultiLineString\": {\n if (style.stroke === undefined) return \"\";\n const box = new PaperBox();\n const lines = geometry.type === \"LineString\" ? [geometry.coordinates] : geometry.coordinates;\n const d = lines.map((line) => linePath(line, view, box, false)).join(\"\");\n if (!box.touches(frame, style.stroke.widthMm)) return \"\";\n return `<path d=\"${d}\" fill=\"none\" ${strokeAttributes(style.stroke)}/>`;\n }\n case \"Polygon\":\n case \"MultiPolygon\": {\n const box = new PaperBox();\n const polygons = geometry.type === \"Polygon\" ? [geometry.coordinates] : geometry.coordinates;\n const d = polygons.flatMap((rings) => rings.map((ring) => linePath(ring, view, box, true))).join(\"\");\n if (!box.touches(frame, style.stroke?.widthMm ?? 0)) return \"\";\n const stroke = style.stroke === undefined ? `stroke=\"none\"` : strokeAttributes(style.stroke);\n let svg = \"\";\n if (style.fill?.gray !== undefined) svg += `<path d=\"${d}\" fill=\"${grayColor(style.fill.gray)}\" fill-rule=\"evenodd\" stroke=\"none\"/>`;\n svg += `<path d=\"${d}\" fill=\"${fill ?? \"none\"}\" fill-rule=\"evenodd\" ${stroke}/>`;\n return svg;\n }\n case \"GeometryCollection\":\n return geometry.geometries.map((item) => drawGeometry(item, style, view, fill)).join(\"\");\n }\n}\n\n/** This function gives the features of a layer after its filter and its simplification. */\nfunction featuresOf(layer: Layer, frame: Frame): Feature[] {\n const kept = layer.features.filter((feature) => feature.geometry !== null && (layer.filter === undefined || matchesFilter(layer.filter, feature)));\n if (layer.simplifyMm === undefined) return kept;\n const areas = kept.flatMap((feature, i) => (feature.geometry?.type === \"Polygon\" || feature.geometry?.type === \"MultiPolygon\" ? [i] : []));\n if (areas.length === 0) return kept;\n // A tolerance of t mm on the paper is t * scale mm on the ground, and t * scale / 1e6 km.\n const simplified = simplifyRegions(\n areas.map((i) => kept[i]!.geometry as Region),\n (layer.simplifyMm * frame.scale) / 1e6,\n );\n const result = [...kept];\n areas.forEach((index, j) => {\n result[index] = { ...kept[index]!, geometry: simplified[j]! };\n });\n return result;\n}\n\n/** The options of `renderMap` and `mapLabels`. */\nexport interface RenderOptions {\n /** The font of the labels. A map with a label rule needs it. */\n readonly labelFont?: LabelFont;\n}\n\n/** The middle of the north arrow, from the top right corner of the frame, and the half size of its box, in millimetres. */\nconst NORTH_ARROW = { inset: 6.5, half: 4.7 };\n\nfunction placementOf(map: MapDocument, features: readonly Feature[][], view: FrameView, font: LabelFont): LabelPlacement {\n const obstacles = map.northArrow === false ? [] : [{ x: map.frame.widthMm - NORTH_ARROW.inset, y: NORTH_ARROW.inset, half: NORTH_ARROW.half }];\n const layers = map.layers.map((layer, i) => ({ id: layer.id, features: features[i]!, label: layer.label, pointSizeMm: layer.style.point?.sizeMm }));\n return placeLabels(layers, view, font, obstacles);\n}\n\nfunction labelFontOf(map: MapDocument, options: RenderOptions): LabelFont | undefined {\n const labelled = map.layers.find((layer) => layer.label !== undefined);\n if (labelled === undefined) return undefined;\n const font = options.labelFont;\n if (font === undefined || typeof font.measure !== \"function\" || typeof font.family !== \"string\" || font.family.trim() === \"\") {\n throw new MapError(\"label\", `The layer \"${labelled.id}\" has labels, so the options need a label font with a family and a measure`);\n }\n return font;\n}\n\n/**\n * This function gives the labels of a map with their places, and the texts with no place. `renderMap` draws the same\n * labels.\n *\n * @throws MapError - The map is not correct, as `checkMap` tells, or a layer has labels and the options have no font.\n */\nexport function mapLabels(map: MapDocument, options: RenderOptions = {}): LabelPlacement {\n checkMap(map);\n const font = labelFontOf(map, options);\n if (font === undefined) return { placed: [], skipped: [] };\n return placementOf(map, map.layers.map((layer) => featuresOf(layer, map.frame)), frameView(map.frame), font);\n}\n\n/** This function gives the swatch of a layer in the legend, with its top left corner at a point. */\nfunction swatch(style: Style, x: number, y: number, fill: string | undefined): string {\n if (style.point !== undefined) return pointSymbol(style.point, x + 3, y + 1.75);\n if (style.fill !== undefined) {\n const stroke = style.stroke === undefined ? `stroke=\"#000000\" stroke-width=\"0.1\"` : strokeAttributes(style.stroke);\n const base = style.fill.gray === undefined ? \"\" : `<rect x=\"${mm(x)}\" y=\"${mm(y)}\" width=\"6\" height=\"3.5\" fill=\"${grayColor(style.fill.gray)}\"/>`;\n return `${base}<rect x=\"${mm(x)}\" y=\"${mm(y)}\" width=\"6\" height=\"3.5\" fill=\"${fill ?? \"none\"}\" ${stroke}/>`;\n }\n return `<path d=\"M${mm(x)} ${mm(y + 1.75)}L${mm(x + 6)} ${mm(y + 1.75)}\" ${strokeAttributes(style.stroke!)}/>`;\n}\n\nfunction thousands(value: number): string {\n return String(Math.round(value)).replace(/\\B(?=(\\d{3})+(?!\\d))/g, \",\");\n}\n\n/** The space between the frame and the column of the legend at the side, in millimetres. */\nconst SIDE_GAP_MM = 3;\n/** The space above the first row of the column of the legend at the side, in millimetres. */\nconst SIDE_TOP_MM = 1;\n/** The least width of the column of the legend at the side, in millimetres. */\nconst SIDE_LEAST_WIDTH_MM = 30;\n/** The space between the scale bars and the legend in the column at the side, in millimetres. */\nconst SIDE_GROUP_GAP_MM = 1.5;\n/** The space at the right of a scale bar in the column at the side for its label, in millimetres. */\nconst SCALE_LABEL_MM = 12;\n/** The size of the font of the legend texts, in millimetres. */\nconst LEGEND_TEXT_MM = 2.4;\n/** The distance from the left side of a swatch to its text, in millimetres. */\nconst LEGEND_TEXT_X_MM = 7.5;\n/** The width of a character of a legend text, as a part of the size of the font, when the options have no font. */\nconst CHARACTER_WIDTH = 0.6;\n\n/** The parts of the legend of a map, with the space that they use. The size of the frame does not change them. */\ninterface LegendLayout {\n readonly bars: readonly (\"metric\" | \"imperial\")[];\n readonly lines: readonly string[];\n /** The width of the column at the side, or 0. */\n readonly columnMm: number;\n /** The height of the column at the side, or 0. */\n readonly columnHeightMm: number;\n /** The height of the block of the scale bars and the legend below the frame, or 0. */\n readonly blockMm: number;\n}\n\n/** This function gives the font that measures the legend texts: the label font of the options, if it has a measure. */\nfunction measureFontOf(options: RenderOptions): LabelFont | undefined {\n const font = options.labelFont;\n return font !== undefined && typeof font.measure === \"function\" ? font : undefined;\n}\n\nfunction legendLayout(map: MapDocument, font: LabelFont | undefined): LegendLayout {\n const units = map.scaleBar ?? \"both\";\n const bars = units === \"none\" ? [] : units === \"both\" ? ([\"metric\", \"imperial\"] as const) : [units];\n const texts = map.layers.flatMap((layer) => (layer.legend === undefined ? [] : [layer.legend]));\n const lines = attributionLines(map);\n const place = map.legendPlace ?? \"below\";\n if (place === \"below\" || bars.length + texts.length === 0) {\n const blockMm = place === \"below\" ? Math.max(bars.length, Math.ceil(texts.length / 2)) * SCALE_BAR_ROW_MM : 0;\n return { bars, lines, columnMm: 0, columnHeightMm: 0, blockMm };\n }\n const width = (text: string): number => (font === undefined ? text.length * LEGEND_TEXT_MM * CHARACTER_WIDTH : font.measure(text, LEGEND_TEXT_MM));\n const widest = Math.max(0, ...texts.map(width));\n const columnMm = Math.max(SIDE_LEAST_WIDTH_MM, LEGEND_TEXT_X_MM + widest + 1);\n const gap = bars.length > 0 && texts.length > 0 ? SIDE_GROUP_GAP_MM : 0;\n const columnHeightMm = SIDE_TOP_MM + (bars.length + texts.length) * SCALE_BAR_ROW_MM + gap;\n return { bars, lines, columnMm, columnHeightMm, blockMm: 0 };\n}\n\n/** The space of the SVG of a map around its frame, in millimetres. */\nexport interface MapMargins {\n /** The width at the right of the frame: the gap and the column of the legend at the side, or 0. */\n readonly rightMm: number;\n /** The height below the frame: the legend below the frame, if it is there, and the attribution block. */\n readonly belowMm: number;\n /** The height of the column of the legend at the side, or 0. A frame with less height makes the SVG taller. */\n readonly leastHeightMm: number;\n}\n\nfunction marginsOf(layout: LegendLayout): MapMargins {\n return {\n rightMm: layout.columnMm === 0 ? 0 : SIDE_GAP_MM + layout.columnMm,\n belowMm: 2 + layout.blockMm + 2.5 + (layout.lines.length - 1) * 3 + 1.5,\n leastHeightMm: layout.columnHeightMm,\n };\n}\n\n/**\n * This function gives the space of the SVG of a map around its frame, for the place of the legend of the map. The\n * size of the frame does not change it.\n *\n * - The label font of the options measures the legend texts. With no font, each character is 0.6 of the size of the font.\n * - The SVG of the map is `rightMm` wider and `belowMm` taller than its frame.\n *\n * @throws MapError - The map is not correct, as `checkMap` tells.\n */\nexport function mapMargins(map: MapDocument, options: RenderOptions = {}): MapMargins {\n checkMap(map);\n return marginsOf(legendLayout(map, measureFontOf(options)));\n}\n\n/** A space for the SVG of a map, in millimetres, for example the printable area of a paper below a heading. */\nexport interface MapSpace {\n readonly widthMm: number;\n readonly heightMm: number;\n}\n\n/** The options of `fitFrame`. */\nexport interface FitOptions {\n /** The font of the labels. It also measures the legend texts. */\n readonly labelFont?: LabelFont;\n /** The places of the legend to examine. The default is `below` and `side`. */\n readonly places?: readonly LegendPlace[];\n}\n\n/** The frame with the largest area for a map in one of a list of spaces. */\nexport interface FrameFit {\n readonly widthMm: number;\n readonly heightMm: number;\n readonly legendPlace: LegendPlace;\n /** The index of the space of the frame in the list of spaces. */\n readonly space: number;\n}\n\n/**\n * This function gives the frame with the largest area for a map in one of a list of spaces, and the place of its\n * legend. The SVG of the map with that frame and that place fits that space.\n *\n * - Give one space for each choice of the caller, for example a paper upright and the same paper in landscape.\n * - The scale of the map does not change, so a larger frame shows more ground.\n * - The size of the frame of the map does not change the result.\n * - With two choices of equal area, the first place of the options wins, and then the first space.\n *\n * @throws MapError - The map is not correct, a place or a space is not correct, or no choice leaves space for a frame.\n */\nexport function fitFrame(map: MapDocument, spaces: readonly MapSpace[], options: FitOptions = {}): FrameFit {\n checkMap(map);\n for (const { widthMm, heightMm } of spaces) {\n if (![widthMm, heightMm].every((value) => Number.isFinite(value) && value > 0)) {\n throw new MapError(\"frame\", `The space ${widthMm} by ${heightMm} mm is not two finite numbers more than 0`);\n }\n }\n const places = options.places ?? LEGEND_PLACES;\n const font = measureFontOf(options);\n let best: FrameFit | undefined;\n for (const place of places) {\n if (!LEGEND_PLACES.includes(place)) throw new MapError(\"style\", `The place of the legend \"${String(place)}\" is not \"below\" or \"side\"`);\n const margins = marginsOf(legendLayout({ ...map, legendPlace: place }, font));\n for (const [index, { widthMm, heightMm }] of spaces.entries()) {\n const frameWidth = widthMm - margins.rightMm;\n const frameHeight = heightMm - margins.belowMm;\n if (!(frameWidth > 0 && frameHeight > 0 && frameHeight >= margins.leastHeightMm)) continue;\n if (best === undefined || frameWidth * frameHeight > best.widthMm * best.heightMm) {\n best = { widthMm: frameWidth, heightMm: frameHeight, legendPlace: place, space: index };\n }\n }\n }\n if (best === undefined) throw new MapError(\"frame\", \"No space of the list has space for a frame after the legend\");\n return best;\n}\n\n/** This function gives the lines of the attribution block: the scale, the projection and each source one time. */\nexport function attributionLines(map: MapDocument): string[] {\n const lines = [`Scale 1:${thousands(map.frame.scale)} at the center. Projection: ${map.frame.projection.name}.`];\n const seen = new Set<string>();\n for (const { source } of map.layers) {\n const line = `Data: ${source.title}. License: ${source.license}.${source.url === undefined ? \"\" : ` ${source.url}`}${source.date === undefined ? \"\" : ` Date: ${source.date}.`}`;\n if (seen.has(line)) continue;\n seen.add(line);\n lines.push(line);\n }\n return lines;\n}\n\n/**\n * This function gives the SVG of a map. The units of the SVG are millimetres, for a print at the scale of the frame.\n *\n * - The map is at the top. Below it are the scale bars, the legend and the attribution block.\n * - With the place `side`, the scale bars and the legend are in a column at the right of the frame. The attribution\n * block stays below.\n * - The layers are in their sequence, from the bottom to the top. The frame clips each layer.\n * - A feature that is not on the frame is not in the SVG.\n * - Each identifier in the SVG starts with the identifier of the map. Thus two maps can be in one HTML page.\n * - The labels are above the layers. `placeLabels` tells their places. The group of the labels tells the number of\n * texts with no place in `data-skipped`.\n *\n * @throws MapError - The map is not correct, as `checkMap` tells, or a layer has labels and the options have no font.\n * @throws GeoError - A position is not correct for the projection.\n */\nexport function renderMap(map: MapDocument, options: RenderOptions = {}): string {\n checkMap(map);\n const font = labelFontOf(map, options);\n const view = frameView(map.frame);\n const { widthMm: w, heightMm: h } = map.frame;\n const defs: string[] = [`<clipPath id=\"${map.id}-clip\"><rect width=\"${mm(w)}\" height=\"${mm(h)}\"/></clipPath>`];\n const fills = map.layers.map((layer) => {\n const hatch = layer.style.fill?.hatch;\n if (hatch === undefined) return undefined;\n const id = `${map.id}-${layer.id}-hatch`;\n defs.push(hatchPattern(id, hatch));\n return `url(#${id})`;\n });\n const features = map.layers.map((layer) => featuresOf(layer, map.frame));\n const layers = map.layers.map((layer, i) => {\n const body = features[i]!\n .map((feature) => drawGeometry(feature.geometry as Geometry, layer.style, view, fills[i]))\n .join(\"\");\n return `<g id=\"${map.id}-${layer.id}\">${body}</g>`;\n });\n const labels = font === undefined ? \"\" : labelsSvg(placementOf(map, features, view, font), font);\n\n const layout = legendLayout(map, measureFontOf(options));\n const side = layout.columnMm > 0;\n const { bars, lines } = layout;\n const top = (side ? Math.max(h, layout.columnHeightMm) : h) + 2;\n const sideX = w + SIDE_GAP_MM;\n const maxMeters = (side ? layout.columnMm - SCALE_LABEL_MM : 0.3 * w) / view.mmPerMeter;\n const scaleBars = bars\n .map((unit, i) => {\n const length = scaleBarLength(maxMeters, unit);\n return side ? scaleBarSvg(sideX, SIDE_TOP_MM + i * SCALE_BAR_ROW_MM, length, view.mmPerMeter) : scaleBarSvg(0.5, top + i * SCALE_BAR_ROW_MM, length, view.mmPerMeter);\n })\n .join(\"\");\n const legendLayers = map.layers.flatMap((layer, i) => (layer.legend === undefined ? [] : [{ layer, fill: fills[i] }]));\n const columnWidth = w * 0.275;\n const sideTop = SIDE_TOP_MM + bars.length * SCALE_BAR_ROW_MM + (bars.length > 0 ? SIDE_GROUP_GAP_MM : 0);\n const legend = legendLayers\n .map(({ layer, fill }, i) => {\n const x = side ? sideX : w * 0.45 + (i % 2) * columnWidth;\n const y = side ? sideTop + i * SCALE_BAR_ROW_MM : top + Math.floor(i / 2) * SCALE_BAR_ROW_MM - 1;\n return `${swatch(layer.style, x, y, fill)}<text x=\"${mm(x + LEGEND_TEXT_X_MM)}\" y=\"${mm(y + 2.9)}\" font-size=\"${LEGEND_TEXT_MM}\">${escapeHtml(layer.legend!)}</text>`;\n })\n .join(\"\");\n const firstLine = top + layout.blockMm + 2.5;\n const attribution = lines.map((line, i) => `<text x=\"0.5\" y=\"${mm(firstLine + i * 3)}\" font-size=\"2.2\">${escapeHtml(line)}</text>`).join(\"\");\n const total = firstLine + (lines.length - 1) * 3 + 1.5;\n const width = side ? sideX + layout.columnMm : w;\n const arrow = map.northArrow === false ? \"\" : northArrowSvg(w - 6.5, 6.5, view.northDegrees);\n\n return (\n `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"${mm(width)}mm\" height=\"${mm(total)}mm\" viewBox=\"0 0 ${mm(width)} ${mm(total)}\" ` +\n `role=\"img\" aria-label=\"${escapeAttribute(map.title)}\" font-family=\"sans-serif\">` +\n `<title>${escapeHtml(map.title)}</title><defs>${defs.join(\"\")}</defs>` +\n `<rect width=\"${mm(width)}\" height=\"${mm(total)}\" fill=\"#ffffff\"/>` +\n `<g clip-path=\"url(#${map.id}-clip)\">${layers.join(\"\")}</g>${labels}` +\n `<rect width=\"${mm(w)}\" height=\"${mm(h)}\" fill=\"none\" stroke=\"#000000\" stroke-width=\"0.3\"/>` +\n `${arrow}<g class=\"legend\">${scaleBars}${legend}</g><g class=\"attribution\">${attribution}</g></svg>`\n );\n}\n\n"],"mappings":";;;;AAkBA,IAAa,WAAb,cAA8B,MAAM;;CAEzB;;;;;CAMT,YAAY,MAAoB,SAAiB;EAC/C,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF;;;ACCA,SAAgB,aAAa,UAAkC;CAC7D,QAAQ,SAAS,MAAjB;EACE,KAAK;EACL,KAAK,cACH,OAAO;EACT,KAAK;EACL,KAAK,mBACH,OAAO;EACT,KAAK;EACL,KAAK,gBACH,OAAO;EACT,KAAK,sBAAsB;GACzB,MAAM,QAAQ,IAAI,IAAI,SAAS,WAAW,IAAI,YAAY,CAAC;GAC3D,OAAO,MAAM,SAAS,IAAK,CAAC,GAAG,KAAK,CAAC,CAAC,KAAsB;EAC9D;CACF;AACF;;AAGA,SAAgB,cAAc,QAAgB,SAA2B;CACvE,IAAI,SAAS,QAAQ,OAAO,OAAO,IAAI,OAAO,SAAS,cAAc,MAAM,OAAO,CAAC;CACnF,IAAI,SAAS,QAAQ,OAAO,OAAO,IAAI,MAAM,SAAS,cAAc,MAAM,OAAO,CAAC;CAClF,IAAI,SAAS,QAAQ,O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,mBAAmB;EAC/F,OAAO,GAAG,OAAO,MAAM,OAAO,GAAG,GAAG,IAAI,EAAE,WAAW,GAAG,IAAI,gBAAgB,EAAE,OAAO,GAAG,IAAI,GAAG,EAAE,eAAe,eAAe,IAAI,WAAW,MAAM,MAAO,EAAE;CAC/J,CAAC,CAAC,CACD,KAAK,EAAE;CACV,MAAM,YAAY,MAAM,OAAO,UAAU;CACzC,MAAM,cAAc,MAAM,KAAK,MAAM,MAAM,oBAAoB,GAAG,YAAY,IAAI,CAAC,EAAE,oBAAoB,WAAW,IAAI,EAAE,QAAQ,CAAC,CAAC,KAAK,EAAE;CAC3I,MAAM,QAAQ,aAAa,MAAM,SAAS,KAAK,IAAI;CACnD,MAAM,QAAQ,OAAO,QAAQ,OAAO,WAAW;CAC/C,MAAM,QAAQ,IAAI,eAAe,QAAQ,KAAK,cAAc,IAAI,KAAK,KAAK,KAAK,YAAY;CAE3F,OACE,kDAAkD,GAAG,KAAK,EAAE,cAAc,GAAG,KAAK,EAAE,mBAAmB,GAAG,KAAK,EAAE,GAAG,GAAG,KAAK,EAAE,2BACpG,gBAAgB,IAAI,KAAK,EAAE,oCAC3C,WAAW,IAAI,KAAK,EAAE,gBAAgB,KAAK,KAAK,EAAE,EAAE,sBAC9C,GAAG,KAAK,EAAE,YAAY,GAAG,KAAK,EAAE,uCAC1B,IAAI,GAAG,UAAU,OAAO,KAAK,EAAE,EAAE,MAAM,OAAA,eAC7C,GAAG,CAAC,EAAE,YAAY,GAAG,CAAC,EAAE,qDACrC,MAAM,oBAAoB,YAAY,OAAO,6BAA6B,YAAY;AAE7F"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/cartography",
4
- "version": "0.1.0",
4
+ "version": "0.1.1",
5
5
  "description": "Maps as data: a frame, layers with filters and black and white styles, and a render to SVG in millimetres with a scale bar, a north arrow, a legend and the attribution of each source.",
6
6
  "keywords": [
7
7
  "map",