@orbat-mapper/control-measures 0.2.0-alpha.10 → 0.2.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index-D3uCYKe3.d.mts → index-C6nqkw1A.d.mts} +316 -68
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/preview/index.d.mts +65 -10
- package/dist/preview/index.mjs +129 -18
- package/dist/{renderControlMeasure-BblcXXLp.mjs → renderControlMeasure-NKEYq3Fg.mjs} +1430 -595
- package/media/airborne-attack.svg +1 -1
- package/media/ambush.svg +1 -1
- package/media/antitank-ditch-completed.svg +1 -1
- package/media/antitank-ditch-under-construction.svg +1 -1
- package/media/antitank-wall.svg +1 -1
- package/media/area-of-operations.svg +1 -0
- package/media/assembly-area.svg +1 -0
- package/media/attack-by-fire.svg +1 -1
- package/media/attack-helicopter.svg +1 -1
- package/media/battle-handover-line.svg +1 -0
- package/media/battle-position.svg +1 -1
- package/media/block-arrow.svg +1 -1
- package/media/block-mission-task.svg +1 -1
- package/media/block.svg +1 -1
- package/media/boundary.svg +1 -1
- package/media/breach.svg +1 -1
- package/media/bypass.svg +1 -1
- package/media/canalize.svg +1 -1
- package/media/circle.svg +1 -1
- package/media/classic-arrow.svg +1 -1
- package/media/clear.svg +1 -1
- package/media/delay.svg +1 -1
- package/media/disrupt.svg +1 -1
- package/media/encirclement.svg +1 -1
- package/media/engineer-work-line.svg +1 -0
- package/media/final-protective-fire-left.svg +1 -1
- package/media/final-protective-fire-right.svg +1 -1
- package/media/fix.svg +1 -1
- package/media/flot.svg +1 -1
- package/media/fortified-area.svg +1 -1
- package/media/fortified-line.svg +1 -1
- package/media/generic-c2-line.svg +1 -0
- package/media/handover-line.svg +1 -0
- package/media/isolate.svg +1 -1
- package/media/joint-tactical-action-area.svg +1 -0
- package/media/landing-zone.svg +1 -0
- package/media/light-line.svg +1 -0
- package/media/line.svg +1 -1
- package/media/main-attack.svg +1 -1
- package/media/obstacle-bypass-difficult.svg +1 -1
- package/media/obstacle-bypass-easy.svg +1 -1
- package/media/obstacle-bypass-impossible.svg +1 -1
- package/media/phase-line.svg +1 -0
- package/media/pickup-zone.svg +1 -0
- package/media/polygon.svg +1 -1
- package/media/principal-direction-of-fire.svg +1 -1
- package/media/rectangle.svg +1 -1
- package/media/search-area.svg +1 -1
- package/media/strong-point.svg +1 -1
- package/media/support-by-fire.svg +1 -1
- package/media/supporting-attack.svg +1 -1
- package/media/turn.svg +1 -1
- package/package.json +1 -1
package/dist/preview/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { X as ControlMeasureId } from "../index-
|
|
1
|
+
import { X as ControlMeasureId, or as TextAmplifiers } from "../index-C6nqkw1A.mjs";
|
|
2
2
|
import { FeatureCollection, Geometry } from "geojson";
|
|
3
3
|
|
|
4
4
|
//#region src/preview/index.d.ts
|
|
@@ -7,8 +7,16 @@ import { FeatureCollection, Geometry } from "geojson";
|
|
|
7
7
|
* so it runs identically at build time (docs catalog, README generator) and in
|
|
8
8
|
* the browser (preview app). Returns an empty collection if the generator
|
|
9
9
|
* throws, so a single broken measure never breaks a whole gallery.
|
|
10
|
+
*
|
|
11
|
+
* `overrides.textAmplifiers` and `overrides.options` are each merged over the
|
|
12
|
+
* sample's own amplifiers/options (override wins per key, sample-only keys
|
|
13
|
+
* survive) — used by the params panel's placement preview to substitute
|
|
14
|
+
* placeholder values (`<T>`, `<N>`, …) for whatever the sample carries.
|
|
10
15
|
*/
|
|
11
|
-
declare function renderRepresentative(id: ControlMeasureId
|
|
16
|
+
declare function renderRepresentative(id: ControlMeasureId, overrides?: {
|
|
17
|
+
textAmplifiers?: TextAmplifiers;
|
|
18
|
+
options?: Record<string, unknown>;
|
|
19
|
+
}): FeatureCollection<Geometry, unknown>;
|
|
12
20
|
/** A styling-free preview primitive. Consumers supply stroke, radius, font,
|
|
13
21
|
* and colors when they draw it. */
|
|
14
22
|
interface PreviewShape {
|
|
@@ -26,13 +34,14 @@ interface PreviewShape {
|
|
|
26
34
|
rotation?: number;
|
|
27
35
|
/**
|
|
28
36
|
* Text height in the same SVG units as `d`/`cx`/`cy`, derived from the
|
|
29
|
-
* source label's ground-anchored `
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
37
|
+
* source label's ground-anchored `textSizeMeters` (ADR-0028) scaled through
|
|
38
|
+
* the fit into the viewBox, then clamped so a long string can't exceed ~40%
|
|
39
|
+
* of the viewBox width. Present only when the label carried real
|
|
40
|
+
* ground-anchored sizing; a fixed glyph with no sizing (e.g. breach's "B",
|
|
41
|
+
* or Boundary's echelon-only sample) or a screen-anchored label (bare
|
|
42
|
+
* `textSizePixels`, unresolvable to a ground size without a live map
|
|
43
|
+
* resolution) leaves this `undefined` — a consumer should fall back to its
|
|
44
|
+
* own fixed font size, matching behavior from before this field existed.
|
|
36
45
|
*/
|
|
37
46
|
heightPx?: number;
|
|
38
47
|
/** Horizontal alignment relative to (`cx`, `cy`), mirroring the label
|
|
@@ -56,5 +65,51 @@ declare function projectRenderToShapes(fc: FeatureCollection<Geometry, unknown>,
|
|
|
56
65
|
shapes: PreviewShape[];
|
|
57
66
|
ok: boolean;
|
|
58
67
|
};
|
|
68
|
+
/**
|
|
69
|
+
* Grows a viewBox to include every `text` shape's estimated on-screen box —
|
|
70
|
+
* {@link projectRenderToShapes} fits geometry coordinates only, so an
|
|
71
|
+
* anchor-aware label (e.g. a phase line's end-anchored "PL ECHO") can extend
|
|
72
|
+
* well past the plain `0 0 width height` viewBox. Consumers should build
|
|
73
|
+
* their SVG `viewBox` from this instead.
|
|
74
|
+
*
|
|
75
|
+
* For each text shape (skipping shapes without `cx`/`cy`), estimates a box
|
|
76
|
+
* from its glyph count (`CHAR_WIDTH_RATIO` × `fontSize`) and `fontSize`
|
|
77
|
+
* itself, placed per `textAnchor` horizontally and centered on `cy`
|
|
78
|
+
* vertically (SVG text uses `dominant-baseline="central"`), rotates its
|
|
79
|
+
* corners around `(cx, cy)` by the same angle the SVG transform applies
|
|
80
|
+
* (`renderedAngle = PI - rotation`, negated for SVG's y-down axis — see
|
|
81
|
+
* {@link svgTextTransform}; labels commonly carry `rotation = PI`,
|
|
82
|
+
* which renders flat, so an undefined rotation must not be treated as
|
|
83
|
+
* rotated), and unions the result with the base `[0, 0, width, height]` box.
|
|
84
|
+
*
|
|
85
|
+
* `fontSize` is supplied by the caller since each gallery picks its own
|
|
86
|
+
* fallback/cap for `heightPx`.
|
|
87
|
+
*/
|
|
88
|
+
declare function viewBoxWithLabels(shapes: PreviewShape[], dims: {
|
|
89
|
+
width: number;
|
|
90
|
+
height: number;
|
|
91
|
+
}, fontSize: (s: PreviewShape) => number): {
|
|
92
|
+
minX: number;
|
|
93
|
+
minY: number;
|
|
94
|
+
width: number;
|
|
95
|
+
height: number;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* The SVG `viewBox` string for a preview, grown to include every label's
|
|
99
|
+
* on-screen box (see {@link viewBoxWithLabels}). The convenience every Vue
|
|
100
|
+
* consumer wants — they only ever format the box into this exact string.
|
|
101
|
+
*/
|
|
102
|
+
declare function viewBoxString(shapes: PreviewShape[], dims: {
|
|
103
|
+
width: number;
|
|
104
|
+
height: number;
|
|
105
|
+
}, fontSize: (s: PreviewShape) => number): string;
|
|
106
|
+
/**
|
|
107
|
+
* The SVG `transform` attribute that rotates a `text` shape into place, or
|
|
108
|
+
* `undefined` for an unrotated/incomplete shape. Text rotations use the same
|
|
109
|
+
* generator convention as the map adapters (`renderedAngle = PI - rotation`);
|
|
110
|
+
* SVG's y-axis points down, so the angle is negated. Shared by every SVG
|
|
111
|
+
* preview consumer (sidebar gallery, docs catalog, README generator).
|
|
112
|
+
*/
|
|
113
|
+
declare function svgTextTransform(s: PreviewShape): string | undefined;
|
|
59
114
|
//#endregion
|
|
60
|
-
export { PreviewShape, ProjectDimensions, projectRenderToShapes, renderRepresentative };
|
|
115
|
+
export { PreviewShape, ProjectDimensions, projectRenderToShapes, renderRepresentative, svgTextTransform, viewBoxString, viewBoxWithLabels };
|
package/dist/preview/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as DEFINITIONS, t as renderControlMeasure } from "../renderControlMeasure-
|
|
1
|
+
import { c as DEFINITIONS, t as renderControlMeasure } from "../renderControlMeasure-NKEYq3Fg.mjs";
|
|
2
2
|
//#region src/preview/index.ts
|
|
3
3
|
/**
|
|
4
4
|
* Unitless `previewSample` points (~`[-1, 1]`) are scaled by this degree offset
|
|
@@ -59,16 +59,27 @@ function representativeSample(id) {
|
|
|
59
59
|
* so it runs identically at build time (docs catalog, README generator) and in
|
|
60
60
|
* the browser (preview app). Returns an empty collection if the generator
|
|
61
61
|
* throws, so a single broken measure never breaks a whole gallery.
|
|
62
|
+
*
|
|
63
|
+
* `overrides.textAmplifiers` and `overrides.options` are each merged over the
|
|
64
|
+
* sample's own amplifiers/options (override wins per key, sample-only keys
|
|
65
|
+
* survive) — used by the params panel's placement preview to substitute
|
|
66
|
+
* placeholder values (`<T>`, `<N>`, …) for whatever the sample carries.
|
|
62
67
|
*/
|
|
63
|
-
function renderRepresentative(id) {
|
|
68
|
+
function renderRepresentative(id, overrides) {
|
|
64
69
|
try {
|
|
65
70
|
const { controlPoints, options, textAmplifiers } = representativeSample(id);
|
|
66
71
|
return renderControlMeasure({
|
|
67
72
|
id: "preview",
|
|
68
73
|
kind: id,
|
|
69
74
|
controlPoints,
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
options: {
|
|
76
|
+
...options,
|
|
77
|
+
...overrides?.options
|
|
78
|
+
},
|
|
79
|
+
textAmplifiers: {
|
|
80
|
+
...textAmplifiers,
|
|
81
|
+
...overrides?.textAmplifiers
|
|
82
|
+
}
|
|
72
83
|
});
|
|
73
84
|
} catch {
|
|
74
85
|
return {
|
|
@@ -117,33 +128,133 @@ function projectRenderToShapes(fc, dims) {
|
|
|
117
128
|
ok: shapes.length > 0
|
|
118
129
|
};
|
|
119
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Meters per degree of latitude, converting a label's ground-meter height
|
|
133
|
+
* (`textSizeMeters`, ADR-0028) into the lon/lat degree frame the render was
|
|
134
|
+
* fit in. Preview samples sit near the origin (see `D`), where this holds for
|
|
135
|
+
* both axes. Without it the raw height overshoots by ~5 orders of magnitude,
|
|
136
|
+
* pinning every label to the width/height caps — larger than its geometric
|
|
137
|
+
* footprint, swallowing the clearance the generator baked in between line and
|
|
138
|
+
* label.
|
|
139
|
+
*/
|
|
140
|
+
const METERS_PER_DEGREE = 111320;
|
|
120
141
|
/** Rough average glyph width, as a ratio of height, for a bold sans-serif
|
|
121
142
|
* label — used only to estimate whether a string will overflow the viewBox,
|
|
122
143
|
* not to lay out real text. */
|
|
123
144
|
const CHAR_WIDTH_RATIO = .62;
|
|
145
|
+
/**
|
|
146
|
+
* Glyph-width ratio for {@link viewBoxWithLabels}' extent boxes. Deliberately
|
|
147
|
+
* wider than {@link CHAR_WIDTH_RATIO}: the average slightly undershoots bold
|
|
148
|
+
* uppercase strings ("PL ECHO"), and an extent estimate that undershoots crops
|
|
149
|
+
* the label edge while one that overshoots only costs a little slack.
|
|
150
|
+
*/
|
|
151
|
+
const EXTENT_CHAR_WIDTH_RATIO = .75;
|
|
124
152
|
/** A text shape may not claim more than this fraction of the viewBox width;
|
|
125
153
|
* longer strings shrink their `heightPx` to fit. */
|
|
126
154
|
const MAX_TEXT_WIDTH_RATIO = .4;
|
|
127
155
|
/**
|
|
128
156
|
* A text shape may not claim more than this fraction of the viewBox height —
|
|
129
157
|
* guards short strings (e.g. "LL", "BHL") whose ground-anchored size would
|
|
130
|
-
* otherwise fit the width cap easily but still tower over the sample line.
|
|
131
|
-
*
|
|
158
|
+
* otherwise fit the width cap easily but still tower over the sample line. The
|
|
159
|
+
* preview samples sit near the origin (see `D`), so the fit `scale` is large
|
|
160
|
+
* and a real-sized label's `raw` height overshoots this cap almost every time;
|
|
161
|
+
* the cap, not the ground size, is what sets the on-screen height. Kept well
|
|
162
|
+
* below the fixed glyph fallback so labels read as annotations on the line
|
|
163
|
+
* rather than dominating a 96×48 thumbnail.
|
|
132
164
|
*/
|
|
133
|
-
const MAX_TEXT_HEIGHT_RATIO = .
|
|
165
|
+
const MAX_TEXT_HEIGHT_RATIO = .16;
|
|
166
|
+
/**
|
|
167
|
+
* Grows a viewBox to include every `text` shape's estimated on-screen box —
|
|
168
|
+
* {@link projectRenderToShapes} fits geometry coordinates only, so an
|
|
169
|
+
* anchor-aware label (e.g. a phase line's end-anchored "PL ECHO") can extend
|
|
170
|
+
* well past the plain `0 0 width height` viewBox. Consumers should build
|
|
171
|
+
* their SVG `viewBox` from this instead.
|
|
172
|
+
*
|
|
173
|
+
* For each text shape (skipping shapes without `cx`/`cy`), estimates a box
|
|
174
|
+
* from its glyph count (`CHAR_WIDTH_RATIO` × `fontSize`) and `fontSize`
|
|
175
|
+
* itself, placed per `textAnchor` horizontally and centered on `cy`
|
|
176
|
+
* vertically (SVG text uses `dominant-baseline="central"`), rotates its
|
|
177
|
+
* corners around `(cx, cy)` by the same angle the SVG transform applies
|
|
178
|
+
* (`renderedAngle = PI - rotation`, negated for SVG's y-down axis — see
|
|
179
|
+
* {@link svgTextTransform}; labels commonly carry `rotation = PI`,
|
|
180
|
+
* which renders flat, so an undefined rotation must not be treated as
|
|
181
|
+
* rotated), and unions the result with the base `[0, 0, width, height]` box.
|
|
182
|
+
*
|
|
183
|
+
* `fontSize` is supplied by the caller since each gallery picks its own
|
|
184
|
+
* fallback/cap for `heightPx`.
|
|
185
|
+
*/
|
|
186
|
+
function viewBoxWithLabels(shapes, dims, fontSize) {
|
|
187
|
+
let minX = 0;
|
|
188
|
+
let minY = 0;
|
|
189
|
+
let maxX = dims.width;
|
|
190
|
+
let maxY = dims.height;
|
|
191
|
+
for (const s of shapes) {
|
|
192
|
+
if (s.type !== "text" || s.cx === void 0 || s.cy === void 0) continue;
|
|
193
|
+
const font = fontSize(s);
|
|
194
|
+
const w = (s.text?.length ?? 0) * EXTENT_CHAR_WIDTH_RATIO * font;
|
|
195
|
+
const h = font;
|
|
196
|
+
const left = s.textAnchor === "start" ? s.cx : s.textAnchor === "end" ? s.cx - w : s.cx - w / 2;
|
|
197
|
+
const right = left + w;
|
|
198
|
+
const top = s.cy - h / 2;
|
|
199
|
+
const bottom = s.cy + h / 2;
|
|
200
|
+
const theta = s.rotation === void 0 ? 0 : -(Math.PI - s.rotation);
|
|
201
|
+
const cos = Math.cos(theta);
|
|
202
|
+
const sin = Math.sin(theta);
|
|
203
|
+
for (const [x, y] of [
|
|
204
|
+
[left, top],
|
|
205
|
+
[right, top],
|
|
206
|
+
[right, bottom],
|
|
207
|
+
[left, bottom]
|
|
208
|
+
]) {
|
|
209
|
+
const rx = s.cx + (x - s.cx) * cos - (y - s.cy) * sin;
|
|
210
|
+
const ry = s.cy + (x - s.cx) * sin + (y - s.cy) * cos;
|
|
211
|
+
if (rx < minX) minX = rx;
|
|
212
|
+
if (rx > maxX) maxX = rx;
|
|
213
|
+
if (ry < minY) minY = ry;
|
|
214
|
+
if (ry > maxY) maxY = ry;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
minX,
|
|
219
|
+
minY,
|
|
220
|
+
width: maxX - minX,
|
|
221
|
+
height: maxY - minY
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* The SVG `viewBox` string for a preview, grown to include every label's
|
|
226
|
+
* on-screen box (see {@link viewBoxWithLabels}). The convenience every Vue
|
|
227
|
+
* consumer wants — they only ever format the box into this exact string.
|
|
228
|
+
*/
|
|
229
|
+
function viewBoxString(shapes, dims, fontSize) {
|
|
230
|
+
const box = viewBoxWithLabels(shapes, dims, fontSize);
|
|
231
|
+
return `${box.minX} ${box.minY} ${box.width} ${box.height}`;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* The SVG `transform` attribute that rotates a `text` shape into place, or
|
|
235
|
+
* `undefined` for an unrotated/incomplete shape. Text rotations use the same
|
|
236
|
+
* generator convention as the map adapters (`renderedAngle = PI - rotation`);
|
|
237
|
+
* SVG's y-axis points down, so the angle is negated. Shared by every SVG
|
|
238
|
+
* preview consumer (sidebar gallery, docs catalog, README generator).
|
|
239
|
+
*/
|
|
240
|
+
function svgTextTransform(s) {
|
|
241
|
+
if (s.rotation === void 0 || s.cx === void 0 || s.cy === void 0) return void 0;
|
|
242
|
+
return `rotate(${(-((Math.PI - s.rotation) * 180) / Math.PI).toFixed(3)} ${s.cx.toFixed(3)} ${s.cy.toFixed(3)})`;
|
|
243
|
+
}
|
|
134
244
|
/**
|
|
135
|
-
* Resolves a label's SVG-unit text height from its `
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
245
|
+
* Resolves a label's SVG-unit text height from its `textSizeMeters` property
|
|
246
|
+
* (ADR-0028's ground anchor), scaled by the same `scale` the geometry was fit
|
|
247
|
+
* with, then clamped by both the height cap and the width the string would
|
|
248
|
+
* occupy at that height (so a long string can't overflow `maxWidthPx`).
|
|
249
|
+
* Returns `undefined` when the label carries no ground-anchored sizing — a
|
|
250
|
+
* screen-anchored label (bare `textSizePixels`, meaningless without a live map
|
|
251
|
+
* resolution to convert it) or one with no size at all — and the caller
|
|
252
|
+
* leaves `heightPx` unset.
|
|
141
253
|
*/
|
|
142
254
|
function resolveTextHeightPx(labelProps, text, limits) {
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const raw = sizePixels * sizeResolution * limits.scale;
|
|
255
|
+
const sizeMeters = labelProps.textSizeMeters;
|
|
256
|
+
if (typeof sizeMeters !== "number") return void 0;
|
|
257
|
+
const raw = sizeMeters * limits.scale / METERS_PER_DEGREE;
|
|
147
258
|
const widthLimit = text.length > 0 ? limits.maxWidthPx / (text.length * CHAR_WIDTH_RATIO) : Infinity;
|
|
148
259
|
return Math.min(raw, limits.maxHeightPx, widthLimit);
|
|
149
260
|
}
|
|
@@ -251,4 +362,4 @@ function collectShapes(g, tx, out, bboxArea, textLimits, props) {
|
|
|
251
362
|
}
|
|
252
363
|
}
|
|
253
364
|
//#endregion
|
|
254
|
-
export { projectRenderToShapes, renderRepresentative };
|
|
365
|
+
export { projectRenderToShapes, renderRepresentative, svgTextTransform, viewBoxString, viewBoxWithLabels };
|