@orbat-mapper/point-symbols 0.1.0-alpha.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Orbat Mapper
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # @orbat-mapper/point-symbols
2
+
3
+ Optional milsymbol-backed point-symbol rendering for
4
+ `@orbat-mapper/tactical-draw`. Installing this package is opt-in; applications
5
+ that only use control measures do not install or bundle milsymbol.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pnpm add @orbat-mapper/point-symbols milsymbol
11
+ ```
12
+
13
+ `milsymbol` is a peer dependency so the host and this capability share one
14
+ instance and its global registries.
15
+
16
+ ## Usage
17
+
18
+ ```ts
19
+ import { TacticalDraw } from "@orbat-mapper/tactical-draw";
20
+ import { milsymbolPointSymbols } from "@orbat-mapper/point-symbols";
21
+
22
+ const pointSymbols = milsymbolPointSymbols();
23
+ const tacticalDraw = new TacticalDraw(adapter, { pointSymbols });
24
+
25
+ tacticalDraw.render([
26
+ {
27
+ id: "unit-1",
28
+ kind: "point-symbol",
29
+ sidc: "130315003611010300000000000000",
30
+ position: [10.75, 59.91],
31
+ rotation: 0,
32
+ size: { value: 32, unit: "pixels" },
33
+ },
34
+ ]);
35
+ ```
36
+
37
+ Use `renderPointSymbol(symbol)` for standalone synchronous SVG rendering.
38
+ Capability instances may be shared by several TacticalDraw facades and retain
39
+ an LRU render cache. Call `capability.invalidate()` after changing milsymbol's
40
+ global configuration.
41
+
42
+ The bundled capability emits SVG produced by milsymbol. A custom
43
+ `PointSymbolCapability` must return trusted or sanitized SVG: the Leaflet
44
+ adapter inserts that SVG into the live DOM when it constructs a `divIcon`.
45
+
46
+ ## License
47
+
48
+ MIT
@@ -0,0 +1,21 @@
1
+ import { PointSymbol, PointSymbol as PointSymbol$1, PointSymbolAnchor, PointSymbolCapability, PointSymbolColors, PointSymbolGraphicModifiers, PointSymbolRender, PointSymbolRender as PointSymbolRender$1, PointSymbolSize, PointSymbolSize as PointSymbolSize$1, PointSymbolStyle } from "@orbat-mapper/tactical-draw";
2
+
3
+ //#region src/render-point-symbol.d.ts
4
+ declare function renderPointSymbol(symbol: PointSymbol$1): PointSymbolRender$1;
5
+ //#endregion
6
+ //#region src/capability.d.ts
7
+ interface MilsymbolPointSymbolsOptions {
8
+ defaultSize?: PointSymbolSize$1;
9
+ defaultRotation?: number;
10
+ maxCacheEntries?: number;
11
+ /** Capability-wide milsymbol options, below per-symbol and canonical fields. */
12
+ milsymbolOptions?: Record<string, unknown>;
13
+ /** Compute uncommon per-symbol milsymbol options before persisted raw overrides. */
14
+ resolveOptions?: (symbol: PointSymbol$1) => Record<string, unknown> | undefined;
15
+ }
16
+ interface MilsymbolPointSymbolCapability extends PointSymbolCapability {
17
+ clearCache(): void;
18
+ }
19
+ declare function milsymbolPointSymbols(options?: MilsymbolPointSymbolsOptions): MilsymbolPointSymbolCapability;
20
+ //#endregion
21
+ export { type MilsymbolPointSymbolCapability, type MilsymbolPointSymbolsOptions, type PointSymbol, type PointSymbolAnchor, type PointSymbolColors, type PointSymbolGraphicModifiers, type PointSymbolRender, type PointSymbolSize, type PointSymbolStyle, milsymbolPointSymbols, renderPointSymbol };
package/dist/index.mjs ADDED
@@ -0,0 +1,136 @@
1
+ import ms from "milsymbol";
2
+ import { normalizeTextAmplifiers } from "@orbat-mapper/control-measures";
3
+ //#region src/render-point-symbol.ts
4
+ const CANONICAL_OCTAGON_SIZE = 100;
5
+ function stableValue(value) {
6
+ if (Array.isArray(value)) return value.map(stableValue);
7
+ if (value && typeof value === "object") return Object.fromEntries(Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([key, nested]) => [key, stableValue(nested)]));
8
+ return value;
9
+ }
10
+ function pointSymbolDrawingKey(symbol, capabilityOptions, resolvedOptions) {
11
+ const drawingStyle = { ...symbol.style ?? {} };
12
+ delete drawingStyle.opacity;
13
+ return JSON.stringify(stableValue({
14
+ sidc: symbol.sidc.trim(),
15
+ textAmplifiers: normalizeTextAmplifiers(symbol.textAmplifiers),
16
+ graphicModifiers: symbol.graphicModifiers,
17
+ style: drawingStyle,
18
+ capabilityOptions,
19
+ resolvedOptions,
20
+ rendererOptions: symbol.rendererOptions?.milsymbol
21
+ }));
22
+ }
23
+ function hashKey(value) {
24
+ let hash = 14695981039346656037n;
25
+ for (let i = 0; i < value.length; i += 1) {
26
+ hash ^= BigInt(value.charCodeAt(i));
27
+ hash = BigInt.asUintN(64, hash * 1099511628211n);
28
+ }
29
+ return hash.toString(36);
30
+ }
31
+ const TEXT_OPTION_BY_FIELD = {
32
+ C: "quantity",
33
+ H: "additionalInformation",
34
+ N: "hostile",
35
+ T: "uniqueDesignation",
36
+ V: "type",
37
+ W: "dtg",
38
+ X: "altitudeDepth",
39
+ Y: "location",
40
+ AM: "distance",
41
+ AN: "azimuth",
42
+ AP: "targetNumber",
43
+ AS: "country"
44
+ };
45
+ function resolveMilsymbolOptions(symbol, capabilityOptions, resolvedOptions) {
46
+ const raw = {
47
+ ...capabilityOptions ?? {},
48
+ ...resolvedOptions ?? {},
49
+ ...symbol.rendererOptions?.milsymbol ?? {}
50
+ };
51
+ delete raw.sidc;
52
+ delete raw.SIDC;
53
+ delete raw.size;
54
+ const options = raw;
55
+ const text = normalizeTextAmplifiers(symbol.textAmplifiers);
56
+ for (const [field, option] of Object.entries(TEXT_OPTION_BY_FIELD)) {
57
+ const value = text[field];
58
+ if (value !== void 0) options[option] = value;
59
+ }
60
+ const direction = symbol.graphicModifiers?.direction;
61
+ if (direction !== void 0) options.direction = direction * 180 / Math.PI;
62
+ const style = symbol.style;
63
+ if (style?.colors?.fill !== void 0) options.fillColor = style.colors.fill;
64
+ if (style?.colors?.frame !== void 0) options.frameColor = style.colors.frame;
65
+ if (style?.colors?.icon !== void 0) options.iconColor = style.colors.icon;
66
+ if (style?.colors?.info !== void 0) options.infoColor = style.colors.info;
67
+ if (style?.colors?.outline !== void 0) options.outlineColor = style.colors.outline;
68
+ if (style?.outlineWidth !== void 0) options.outlineWidth = style.outlineWidth;
69
+ if (style?.fill !== void 0) options.fill = style.fill;
70
+ if (style?.frame !== void 0) options.frame = style.frame;
71
+ if (style?.icon !== void 0) options.icon = style.icon;
72
+ if (style?.monoColor !== void 0) options.monoColor = style.monoColor;
73
+ options.size = CANONICAL_OCTAGON_SIZE;
74
+ return options;
75
+ }
76
+ function renderPointSymbolWithRevision(symbol, revision, capabilityOptions, resolvedOptions) {
77
+ const rendered = new ms.Symbol(symbol.sidc.trim(), resolveMilsymbolOptions(symbol, capabilityOptions, resolvedOptions));
78
+ const { width, height } = rendered.getSize();
79
+ const valid = rendered.isValid() === true;
80
+ const validation = rendered.isValid(true);
81
+ return {
82
+ resourceId: `milsymbol-${revision}-${hashKey(pointSymbolDrawingKey(symbol, capabilityOptions, resolvedOptions))}`,
83
+ svg: rendered.asSVG(),
84
+ octagonSize: CANONICAL_OCTAGON_SIZE,
85
+ width,
86
+ height,
87
+ anchor: rendered.getAnchor(),
88
+ octagonAnchor: rendered.getOctagonAnchor(),
89
+ valid,
90
+ ...valid ? {} : { validation }
91
+ };
92
+ }
93
+ function renderPointSymbol(symbol) {
94
+ return renderPointSymbolWithRevision(symbol, 0);
95
+ }
96
+ //#endregion
97
+ //#region src/capability.ts
98
+ function milsymbolPointSymbols(options = {}) {
99
+ const maxEntries = Math.max(0, Math.floor(options.maxCacheEntries ?? 1024));
100
+ const cache = /* @__PURE__ */ new Map();
101
+ let revision = 0;
102
+ const clearCache = () => cache.clear();
103
+ return {
104
+ defaultSize: structuredClone(options.defaultSize ?? {
105
+ value: 25,
106
+ unit: "pixels"
107
+ }),
108
+ defaultRotation: options.defaultRotation ?? 0,
109
+ render(symbol) {
110
+ const resolved = options.resolveOptions?.(structuredClone(symbol));
111
+ const key = pointSymbolDrawingKey(symbol, options.milsymbolOptions, resolved);
112
+ const cached = cache.get(key);
113
+ if (cached) {
114
+ cache.delete(key);
115
+ cache.set(key, cached);
116
+ return cached;
117
+ }
118
+ const render = renderPointSymbolWithRevision(symbol, revision, options.milsymbolOptions, resolved);
119
+ if (maxEntries > 0) {
120
+ cache.set(key, render);
121
+ if (cache.size > maxEntries) {
122
+ const oldest = cache.keys().next().value;
123
+ if (oldest !== void 0) cache.delete(oldest);
124
+ }
125
+ }
126
+ return render;
127
+ },
128
+ invalidate() {
129
+ revision += 1;
130
+ clearCache();
131
+ },
132
+ clearCache
133
+ };
134
+ }
135
+ //#endregion
136
+ export { milsymbolPointSymbols, renderPointSymbol };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@orbat-mapper/point-symbols",
3
+ "version": "0.1.0-alpha.1",
4
+ "description": "Milsymbol-backed MIL-STD-2525 and APP-6 point symbols for tactical-draw.",
5
+ "license": "MIT",
6
+ "author": "Orbat Mapper",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/orbat-mapper/tactical-graphics.git",
10
+ "directory": "packages/point-symbols"
11
+ },
12
+ "type": "module",
13
+ "exports": {
14
+ ".": "./dist/index.mjs",
15
+ "./package.json": "./package.json"
16
+ },
17
+ "sideEffects": false,
18
+ "files": [
19
+ "dist",
20
+ "README.md",
21
+ "LICENSE"
22
+ ],
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "dependencies": {
27
+ "@orbat-mapper/control-measures": "^0.2.0-alpha.15",
28
+ "@orbat-mapper/tactical-draw": "^0.2.0-alpha.20"
29
+ },
30
+ "peerDependencies": {
31
+ "milsymbol": ">=3.0.4 <4.0.0"
32
+ },
33
+ "devDependencies": {
34
+ "@arethetypeswrong/core": "^0.18.3",
35
+ "@types/geojson": "^7946.0.16",
36
+ "milsymbol": "^3.0.4",
37
+ "publint": "^0.3.21",
38
+ "tsdown": "^0.22.2",
39
+ "typescript": "~5.9.3",
40
+ "vite": "^8.0.16",
41
+ "vitest": "^4.1.8"
42
+ },
43
+ "scripts": {
44
+ "build": "tsdown",
45
+ "test": "vitest run",
46
+ "lint": "eslint . --fix"
47
+ }
48
+ }