@emberbox/ui 0.7.0 → 0.9.0

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.
@@ -1,6 +1,6 @@
1
1
  import type { Plugin } from 'vite';
2
2
  /** The tools for which `@emberbox/ui` ships a logo. */
3
- export type Logo = 'emberbox' | 'alarmzettel' | 'statussim' | 'calltaker' | 'planspiel';
3
+ export type Logo = 'emberbox' | 'alarmzettel' | 'statussim' | 'calltaker' | 'planspiel' | 'lernkarten';
4
4
  /**
5
5
  * Serves a tool's logo as `favicon.svg`, `apple-touch-icon.png`, `logo-192.png`, `logo-512.png` and the
6
6
  * maskable `logo-maskable-192.png` and `logo-maskable-512.png` at the root, in the dev server as in
Binary file
Binary file
Binary file
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" rx="8" fill="#d5271b"/><g transform="translate(14 14) scale(1.5)" color="#fff"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M21.42 10.922a1 1 0 0 0-.019-1.838L12.83 5.18a2 2 0 0 0-1.66 0L2.6 9.08a1 1 0 0 0 0 1.832l8.57 3.908a2 2 0 0 0 1.66 0zM22 10v6"/><path d="M6 12.5V16a6 3 0 0 0 12 0v-3.5"/></g></g></svg>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emberbox/ui",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "Shared look and building blocks of the Emberbox tools, built on Nuxt UI.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -12,6 +12,7 @@
12
12
  "files": [
13
13
  "src",
14
14
  "!src/**/*.test.ts",
15
+ "!src/**/__snapshots__",
15
16
  "dist",
16
17
  "logos"
17
18
  ],
@@ -55,7 +56,7 @@
55
56
  "vue": "^3.5.0"
56
57
  },
57
58
  "devDependencies": {
58
- "@emberbox/lint": "^0.2.0",
59
+ "@emberbox/lint": "^0.3.0",
59
60
  "@types/node": "^24.0.0",
60
61
  "@vitejs/plugin-vue": "^6.0.11",
61
62
  "@vue/tsconfig": "^0.9.1",
@@ -1,91 +1,17 @@
1
- import {onBeforeUnmount, onMounted, ref} from 'vue'
2
-
3
- /** How a tool polls the server. */
4
- export interface PollingOptions {
5
- /** Delay between two requests while the server answers. */
6
- intervalMs?: number
7
- /** Longest delay the wait grows to after failures. */
8
- maxIntervalMs?: number
9
- }
1
+ import {onBeforeUnmount, onMounted} from 'vue'
2
+ import {createPoller, type PollingOptions} from '../poller'
10
3
 
11
4
  /**
12
- * Polls regularly while the page is visible. When a request fails, the delay doubles up to
13
- * `maxIntervalMs`, so a server that is down is not hit every second; the first successful request
14
- * resets it. A hidden tab does not poll, and coming back polls at once.
15
- *
16
- * Never more than one request runs at a time, so a late older answer cannot overwrite a newer one.
17
- * A trigger during a running request queues exactly one more request after it.
5
+ * Polls while the component is mounted, with the loop of `createPoller`: backoff after failures,
6
+ * one request at a time, and a hidden tab that pauses or, with `hiddenIntervalMs`, polls slower.
18
7
  *
19
8
  * @param request fetches the state; an error counts as a lost connection
20
- * @returns whether the last request succeeded, and `refresh`, which polls immediately
9
+ * @param options the delays
10
+ * @returns whether the last request succeeded, `refresh`, which polls immediately, and `stop`
21
11
  */
22
12
  export function usePolling(request: () => Promise<unknown>, options: PollingOptions = {}) {
23
- const intervalMs = options.intervalMs ?? 2_000
24
- const maxIntervalMs = options.maxIntervalMs ?? 30_000
25
- const connected = ref(false)
26
- let delay = intervalMs
27
- let timer: ReturnType<typeof setTimeout> | undefined
28
- let active = false
29
- let running = false
30
- let again = false
31
-
32
- function schedule(): void {
33
- clearTimeout(timer)
34
- if (active && document.visibilityState === 'visible') {
35
- timer = setTimeout(() => void poll(), delay)
36
- }
37
- }
38
-
39
- async function poll(): Promise<void> {
40
- if (running) {
41
- again = true
42
- return
43
- }
44
- running = true
45
- clearTimeout(timer)
46
- try {
47
- await request()
48
- connected.value = true
49
- delay = intervalMs
50
- } catch {
51
- connected.value = false
52
- delay = Math.min(delay * 2, maxIntervalMs)
53
- } finally {
54
- running = false
55
- }
56
- if (again && active) {
57
- again = false
58
- void poll()
59
- return
60
- }
61
- schedule()
62
- }
63
-
64
- function onVisibilityChange(): void {
65
- if (document.visibilityState === 'visible') {
66
- void poll()
67
- } else {
68
- clearTimeout(timer)
69
- }
70
- }
71
-
72
- function refresh(): void {
73
- delay = intervalMs
74
- void poll()
75
- }
76
-
77
- onMounted(() => {
78
- active = true
79
- document.addEventListener('visibilitychange', onVisibilityChange)
80
- void poll()
81
- })
82
-
83
- onBeforeUnmount(() => {
84
- active = false
85
- again = false
86
- clearTimeout(timer)
87
- document.removeEventListener('visibilitychange', onVisibilityChange)
88
- })
89
-
90
- return {connected, refresh}
13
+ const poller = createPoller(request, options)
14
+ onMounted(poller.start)
15
+ onBeforeUnmount(poller.stop)
16
+ return {connected: poller.connected, refresh: poller.refresh, stop: poller.stop}
91
17
  }
package/src/index.ts CHANGED
@@ -8,7 +8,9 @@ export {createToolApp} from './create-app'
8
8
  export {copyToClipboard} from './clipboard'
9
9
  export {SITE_URL, usePage, webApplicationData, type PageMeta, type WebApplicationInfo} from './page'
10
10
  export {useNewBuild} from './composables/useNewBuild'
11
- export {usePolling, type PollingOptions} from './composables/usePolling'
11
+ export {usePolling} from './composables/usePolling'
12
+ export {createPoller, type Poller, type PollingOptions} from './poller'
13
+ export {cleanUpStorage, type StorageCleanUp} from './storage'
12
14
  export {useConfirm, type ConfirmOptions} from './composables/useConfirm'
13
15
  export {default as EmberboxApp} from './components/EmberboxApp.vue'
14
16
  export {default as AppHeader} from './components/AppHeader.vue'
@@ -32,6 +34,12 @@ export {
32
34
  markSymbolTree, unitSymbol, unitSymbolTree,
33
35
  type MarkKind, type Organisation, type SvgElement, type SymbolShape, type SymbolSpec, type UnitSize,
34
36
  } from './symbols/tactical'
37
+ export {
38
+ BASIC_FORMS, DRIVES, FLIGHTS, ORGANISATION_COLOURS, SIGN_ORGANISATIONS, SIGN_SIZES, SUPPLEMENTS, VEHICLE_BODIES, tacticalSign,
39
+ tacticalSignTree, type BasicForm, type Drive, type Flight, type SignOrganisation, type SignSize, type SignStyle, type Supplement,
40
+ type TacticalSignSpec, type VehicleBody,
41
+ } from './symbols/signs'
42
+ export {CATALOG_SOURCE, TACTICAL_SIGN_CATALOG, catalogSignTree, type CatalogEntry} from './symbols/catalog'
35
43
 
36
44
  /**
37
45
  * Vue plugin that installs Nuxt UI in the Emberbox style. Icons come only from the bundled set; a
package/src/poller.ts ADDED
@@ -0,0 +1,125 @@
1
+ import {readonly, ref, type Ref} from 'vue'
2
+
3
+ /** How a tool polls the server. */
4
+ export interface PollingOptions {
5
+ /** Delay between two requests while the server answers. */
6
+ intervalMs?: number
7
+ /** Longest delay the wait grows to after failures. */
8
+ maxIntervalMs?: number
9
+ /**
10
+ * Delay between two requests while the tab is hidden. Without it a hidden tab does not poll at
11
+ * all; with it the tab keeps polling at this slower pace, for state that must stay alive in the
12
+ * background, such as a heartbeat.
13
+ */
14
+ hiddenIntervalMs?: number
15
+ }
16
+
17
+ /** A running poll loop, controlled without a component. */
18
+ export interface Poller {
19
+ /** Whether the last request succeeded. */
20
+ connected: Readonly<Ref<boolean>>
21
+ /** Polls at once and then on schedule, and follows the tab's visibility. */
22
+ start(): void
23
+ /** Ends polling until the next `start`; a request already running still completes, a queued one is dropped. */
24
+ stop(): void
25
+ /**
26
+ * Polls at once and resolves once a request started after this call has completed. On a stopped
27
+ * poller it still fetches once if no request is running, without scheduling more.
28
+ */
29
+ refresh(): Promise<void>
30
+ }
31
+
32
+ /**
33
+ * Whether the page is hidden; outside a browser, while prerendering, it counts as visible.
34
+ *
35
+ * @returns true for a hidden tab
36
+ */
37
+ function pageHidden(): boolean {
38
+ return typeof document !== 'undefined' && document.visibilityState === 'hidden'
39
+ }
40
+
41
+ /**
42
+ * Creates a poll loop. When a request fails, the delay doubles up to `maxIntervalMs`, so a server
43
+ * that is down is not hit every second; the first successful request resets it. A hidden tab
44
+ * pauses, or polls every `hiddenIntervalMs` when that is set; coming back polls at once.
45
+ *
46
+ * Never more than one request runs at a time, so a late older answer cannot overwrite a newer one.
47
+ * A trigger during a running request queues exactly one more request after it. The request may call
48
+ * `stop` itself, for example when the server says the thing polled for no longer exists.
49
+ *
50
+ * @param request fetches the state; an error counts as a lost connection
51
+ * @param options the delays
52
+ * @returns the poller, not yet started
53
+ */
54
+ export function createPoller(request: () => Promise<unknown>, options: PollingOptions = {}): Poller {
55
+ const intervalMs = options.intervalMs ?? 2_000
56
+ const maxIntervalMs = options.maxIntervalMs ?? 30_000
57
+ const hiddenIntervalMs = options.hiddenIntervalMs
58
+ const connected = ref(false)
59
+ let delay = intervalMs
60
+ let timer: ReturnType<typeof setTimeout> | undefined
61
+ let active = false
62
+ let running: Promise<void> | null = null
63
+ let queued: Promise<void> | null = null
64
+
65
+ function schedule(): void {
66
+ clearTimeout(timer)
67
+ if (!active) return
68
+ if (!pageHidden()) {
69
+ timer = setTimeout(() => void poll(), delay)
70
+ } else if (hiddenIntervalMs !== undefined) {
71
+ timer = setTimeout(() => void poll(), Math.max(delay, hiddenIntervalMs))
72
+ }
73
+ }
74
+
75
+ async function once(): Promise<void> {
76
+ clearTimeout(timer)
77
+ try {
78
+ await request()
79
+ connected.value = true
80
+ delay = intervalMs
81
+ } catch {
82
+ connected.value = false
83
+ delay = Math.min(delay * 2, maxIntervalMs)
84
+ }
85
+ }
86
+
87
+ function poll(): Promise<void> {
88
+ if (running) {
89
+ queued ??= running.then(() => {
90
+ queued = null
91
+ return active ? poll() : undefined
92
+ })
93
+ return queued
94
+ }
95
+ running = once().finally(() => {
96
+ running = null
97
+ schedule()
98
+ })
99
+ return running
100
+ }
101
+
102
+ function onVisibilityChange(): void {
103
+ if (pageHidden()) schedule()
104
+ else void poll()
105
+ }
106
+
107
+ return {
108
+ connected: readonly(connected),
109
+ start() {
110
+ if (active) return
111
+ active = true
112
+ if (typeof document !== 'undefined') document.addEventListener('visibilitychange', onVisibilityChange)
113
+ void poll()
114
+ },
115
+ stop() {
116
+ active = false
117
+ clearTimeout(timer)
118
+ if (typeof document !== 'undefined') document.removeEventListener('visibilitychange', onVisibilityChange)
119
+ },
120
+ refresh() {
121
+ delay = intervalMs
122
+ return poll()
123
+ },
124
+ }
125
+ }
package/src/storage.ts ADDED
@@ -0,0 +1,45 @@
1
+ /** Which browser storage entries a tool no longer wants under their current names. */
2
+ export interface StorageCleanUp {
3
+ /** Keys to delete; a key ending in `*` deletes every key starting with the part before it. */
4
+ remove?: string[]
5
+ /** Old key to new key: the value moves over unless the new key already holds one. */
6
+ move?: Record<string, string>
7
+ }
8
+
9
+ /**
10
+ * Whether a stored key matches a key or a prefix pattern ending in `*`.
11
+ *
12
+ * @param key the stored key
13
+ * @param pattern a key or a prefix pattern
14
+ * @returns true when it matches
15
+ */
16
+ function matches(key: string, pattern: string): boolean {
17
+ return pattern.endsWith('*') ? key.startsWith(pattern.slice(0, -1)) : key === pattern
18
+ }
19
+
20
+ /**
21
+ * Tidies a tool's browser storage at startup: moves values from retired keys to their new names and
22
+ * deletes keys the tool no longer reads. A storage the browser refuses, as in some private modes,
23
+ * is left alone.
24
+ *
25
+ * @param cleanUp what to delete and what to move
26
+ * @param storage the storage to tidy, `localStorage` by default
27
+ */
28
+ export function cleanUpStorage(cleanUp: StorageCleanUp, storage?: Storage): void {
29
+ try {
30
+ const target = storage ?? localStorage
31
+ for (const [from, to] of Object.entries(cleanUp.move ?? {})) {
32
+ if (from === to) continue
33
+ const value = target.getItem(from)
34
+ if (value !== null && target.getItem(to) === null) target.setItem(to, value)
35
+ target.removeItem(from)
36
+ }
37
+ const patterns = cleanUp.remove ?? []
38
+ const keys = Array.from({length: target.length}, (_, index) => target.key(index))
39
+ for (const key of keys) {
40
+ if (key !== null && patterns.some(pattern => matches(key, pattern))) target.removeItem(key)
41
+ }
42
+ } catch {
43
+ return
44
+ }
45
+ }
@@ -0,0 +1,113 @@
1
+ import {tacticalSignTree, type TacticalSignSpec} from './signs'
2
+ import type {SvgElement} from './svg'
3
+ import {markSymbolTree, type MarkKind} from './tactical'
4
+
5
+ /**
6
+ * One sign of the catalogue: its number and name after the recommendations "Taktische Zeichen im
7
+ * Bevölkerungsschutz" (BBK, 2024), shortened where the printed name runs on, the printed page it is
8
+ * on, and how the library draws it. Numbers repeat in a few places of the recommendations (5.1.1
9
+ * and 5.1.2 name both a vehicle and a section), so `id` is what tells entries apart.
10
+ *
11
+ * A few signs the library draws are not part of the recommendations, such as the marks of the
12
+ * water supply; they carry `recommended: false`, no page and a number of their own, and should not
13
+ * be asked about as if they were.
14
+ */
15
+ export interface CatalogEntry {
16
+ id: string
17
+ number: string
18
+ name: string
19
+ page?: number
20
+ recommended: boolean
21
+ drawing: {sign: TacticalSignSpec} | {mark: MarkKind}
22
+ }
23
+
24
+ /** The source the catalogue follows, to be named wherever its signs are shown. */
25
+ export const CATALOG_SOURCE = 'Bundesamt für Bevölkerungsschutz und Katastrophenhilfe (BBK): Taktische Zeichen im Bevölkerungsschutz – '
26
+ + 'Empfehlungen zur Einführung einer FwDV 102/DV 102, Stand Mai 2024, ISBN 978-3-949117-29-9'
27
+
28
+ function entry(number: string, name: string, page: number, sign: TacticalSignSpec, id = number): CatalogEntry {
29
+ return {id, number, name, page, recommended: true, drawing: {sign}}
30
+ }
31
+
32
+ function ownMark(number: string, name: string, mark: MarkKind): CatalogEntry {
33
+ return {id: number, number, name, recommended: false, drawing: {mark}}
34
+ }
35
+
36
+ /** The drawing of a catalogue entry as a tree of SVG elements. */
37
+ export function catalogSignTree(entry: CatalogEntry): SvgElement {
38
+ return 'sign' in entry.drawing ? tacticalSignTree(entry.drawing.sign) : markSymbolTree(entry.drawing.mark)
39
+ }
40
+
41
+ const FIRE = {organisation: 'fire'} as const
42
+
43
+ /**
44
+ * The signs of chapters 1, 2, 3 and 5.1, 5.4 and 5.5 of the recommendations, in their order, then
45
+ * the library's own water supply marks. Chapter 1 is drawn black on white as printed; colours are
46
+ * shown on a tactical formation, supplements, vehicles and sizes in fire service red.
47
+ */
48
+ export const TACTICAL_SIGN_CATALOG: readonly CatalogEntry[] = [
49
+ entry('1.1', 'Taktische Formation', 14, {form: 'formation'}),
50
+ entry('1.2', 'Person', 14, {form: 'person'}),
51
+ entry('1.3', 'Landfahrzeug', 14, {form: 'land-vehicle'}),
52
+ entry('1.4', 'Luftfahrzeug', 14, {form: 'aircraft'}),
53
+ entry('1.5', 'Wasserfahrzeug', 14, {form: 'watercraft'}),
54
+ entry('1.6', 'Stelle, Platz, Einrichtung', 14, {form: 'place'}),
55
+ entry('1.7', 'Gebäude', 14, {form: 'building'}),
56
+ entry('1.8', 'Raum, Behälter, Ressource, Grundzeichen für Funkgeräte', 14, {form: 'room'}),
57
+ entry('1.9', 'Gebiet, Fläche, Bereich', 15, {form: 'area'}),
58
+ entry('1.10', 'Maßnahme', 15, {form: 'measure'}),
59
+ entry('1.11', 'Gefahr', 15, {form: 'hazard'}),
60
+ entry('1.12', 'Markanter Punkt/Markierung', 15, {form: 'landmark'}),
61
+ entry('1.13', 'Ereignis', 15, {form: 'event'}),
62
+ entry('1.14', 'Spontanhelfer', 15, {form: 'volunteer', organisation: 'civil'}),
63
+ entry('2.1', 'Feuerwehr', 16, {form: 'formation', organisation: 'fire', abbreviation: true}),
64
+ entry('2.2', '(Hilfs-)Organisationen', 16, {form: 'formation', organisation: 'aid', abbreviation: true}),
65
+ entry('2.3', 'Technisches Hilfswerk', 16, {form: 'formation', organisation: 'thw', abbreviation: true}),
66
+ entry('2.4', 'Führung, Leitung', 17, {form: 'formation', organisation: 'command'}),
67
+ entry('2.5', 'Polizei', 17, {form: 'formation', organisation: 'police', abbreviation: true}),
68
+ entry('2.6', 'Bundeswehr', 17, {form: 'formation', organisation: 'military', abbreviation: true}),
69
+ entry('2.7', 'Sonstige Gefahrenabwehr', 17, {form: 'formation', organisation: 'other', abbreviation: true}),
70
+ entry('2.8', 'Zivile Einheiten/ungebundene Kräfte', 17, {form: 'formation', organisation: 'civil', abbreviation: true}),
71
+ entry('3.1', 'Schwerpunkt Einsatzführung (Balken oben)', 20, {form: 'formation', ...FIRE, supplements: ['command']}),
72
+ entry('3.2', 'Person mit Sonderfunktion (Litze)', 20, {form: 'person', ...FIRE, supplements: ['special-function']}),
73
+ entry('3.3', 'Schwerpunkt Versorgung, Entsorgung, Logistik (Balken unten)', 20, {form: 'formation', ...FIRE, supplements: ['logistics']}),
74
+ entry('3.4', 'Drohne, unbemannt', 20, {form: 'aircraft', ...FIRE, supplements: ['uncrewed']}),
75
+ entry('3.5', 'Zweirad, Fahrrad', 20, {form: 'formation', ...FIRE, supplements: ['bicycle']}),
76
+ entry('3.6', 'Zweirad, Kraftrad', 21, {form: 'formation', ...FIRE, supplements: ['motorcycle']}),
77
+ entry('3.7', 'Temporär ortsfeste Struktur (mit festem Dach)', 21, {form: 'place', ...FIRE, supplements: ['roof']}),
78
+ entry('5.1.1', 'Fahrzeug, ungeschützt', 32, {form: 'land-vehicle', ...FIRE}, '5.1.1-unprotected'),
79
+ entry('5.1.2', 'Fahrzeug, geschützt', 32, {form: 'land-vehicle', ...FIRE, protected: true}, '5.1.2-protected'),
80
+ entry('5.1.1.1', 'Kraftfahrzeug, straßenfähig (Kategorie 1)', 32, {form: 'land-vehicle', ...FIRE, drive: 'road'}),
81
+ entry('5.1.1.2', 'Kraftfahrzeug, geländefähig (Kategorie 2)', 32, {form: 'land-vehicle', ...FIRE, drive: 'offroad'}),
82
+ entry('5.1.1.3', 'Kraftfahrzeug, geländegängig (Kategorie 3)', 32, {form: 'land-vehicle', ...FIRE, drive: 'all-terrain'}),
83
+ entry('5.1.1.4', 'Amphibienfahrzeug', 32, {form: 'land-vehicle', ...FIRE, drive: 'amphibious'}),
84
+ entry('5.1.1.5', 'Kettenfahrzeug', 33, {form: 'land-vehicle', ...FIRE, drive: 'tracked'}),
85
+ entry('5.1.1.6', 'Schienenfahrzeug', 33, {form: 'land-vehicle', ...FIRE, drive: 'rail'}),
86
+ entry('5.1.1.7', 'Kraftfahrzeug, aufgleisbar', 33, {form: 'land-vehicle', ...FIRE, drive: 'rail-capable'}),
87
+ entry('5.1.1.8', 'Kraftfahrzeug, straßenfähig, Typ Wechsellader', 33, {form: 'land-vehicle', ...FIRE, body: 'swap-loader', drive: 'road'}),
88
+ entry('5.1.1.9', 'Kraftfahrzeug, straßenfähig, Typ Wechselbehälter/Container', 33, {form: 'formation', ...FIRE, body: 'container-carrier', drive: 'road'}),
89
+ entry('5.1.2.1', 'Anhänger, allgemein', 33, {form: 'land-vehicle', ...FIRE, body: 'trailer'}),
90
+ entry('5.1.2.2', 'Anhänger, Typ Abrollbehälter', 33, {form: 'land-vehicle', ...FIRE, body: 'roll-off-trailer'}),
91
+ entry('5.1.2.3', 'Anhänger, Typ Wechselbehälter/Container', 33, {form: 'formation', ...FIRE, body: 'container-trailer'}),
92
+ entry('5.1.2.4', 'Anhänger, von PKW gezogen', 33, {form: 'land-vehicle', ...FIRE, body: 'trailer', drive: 'towed-by-car'}),
93
+ entry('5.1.2.5', 'Anhänger, von LKW gezogen', 33, {form: 'land-vehicle', ...FIRE, body: 'trailer', drive: 'towed-by-truck'}),
94
+ entry('5.1.3.1', 'Abrollbehälter', 34, {form: 'land-vehicle', ...FIRE, body: 'roll-off-container'}),
95
+ entry('5.1.3.2', 'Wechselbehälter/Container', 34, {form: 'formation', ...FIRE, body: 'swap-container'}),
96
+ entry('5.1.3.3', 'Wechselbrücke', 34, {form: 'formation', ...FIRE, body: 'swap-body'}),
97
+ entry('5.1.3.4', 'Behälter zieh-/schiebbar (z. B. Rollcontainer)', 34, {form: 'land-vehicle', ...FIRE, body: 'roll-container'}),
98
+ entry('5.1.4.1', 'Einsatz von Luftfahrzeugen/Fliegen allgemein', 34, {form: 'aircraft', ...FIRE, flight: 'flying'}),
99
+ entry('5.1.4.2', 'Drehflügler/Hubschrauber', 34, {form: 'aircraft', ...FIRE, flight: 'rotary-wing'}),
100
+ entry('5.1.4.3', 'Flächenflügler/Flugzeug', 34, {form: 'aircraft', ...FIRE, flight: 'fixed-wing'}),
101
+ entry('5.4.1', 'Trupp/selbstständiger Trupp', 37, {form: 'formation', ...FIRE, size: 'squad'}),
102
+ entry('5.4.2', 'Staffel', 37, {form: 'formation', ...FIRE, size: 'section'}),
103
+ entry('5.4.3', 'Gruppe', 37, {form: 'formation', ...FIRE, size: 'group'}),
104
+ entry('5.4.4', 'Zug', 37, {form: 'formation', ...FIRE, size: 'platoon'}),
105
+ entry('5.5.1', 'Bereitschaft (Verband I)', 37, {form: 'formation', ...FIRE, size: 'association-1'}),
106
+ entry('5.5.2', 'Abteilung (Verband II)', 37, {form: 'formation', ...FIRE, size: 'association-2'}),
107
+ entry('5.5.3', 'Großverband (Verband III)', 37, {form: 'formation', ...FIRE, size: 'association-3'}),
108
+ ownMark('W.1', 'Unterflurhydrant', 'hydrant-underground'),
109
+ ownMark('W.2', 'Überflurhydrant', 'hydrant-pillar'),
110
+ ownMark('W.3', 'Offenes Gewässer', 'open-water'),
111
+ ownMark('W.4', 'Löschwasserbehälter', 'water-tank'),
112
+ ownMark('W.5', 'Verteiler', 'dividing-breeching'),
113
+ ]
@@ -0,0 +1,349 @@
1
+ /**
2
+ * Tactical signs built from the building blocks of the recommendations "Taktische Zeichen im
3
+ * Bevölkerungsschutz" of the BBK (2024, for FwDV 102 / DV 102): a basic form (chapter 1), the
4
+ * colour of an organisation (chapter 2) in one of three styles, supplementary signs (chapter 3),
5
+ * a unit size or association (5.4, 5.5), and for vehicles how they move and what they carry (5.1).
6
+ * The drawings follow the system of the recommendations without copying their artwork.
7
+ *
8
+ * Colours are fixed values, not theme variables, because the same signs go into map icons as
9
+ * markup strings where no stylesheet applies. They are the HEX column of annex O; for orange the
10
+ * annex gives 250–130–0 as RGB but #FA8C00 as HEX, and the HEX value is used. Signs are drawn for a
11
+ * light background, as on paper: size marks, frames and wheels are black, so a page in dark mode
12
+ * shows them on a light backdrop.
13
+ *
14
+ * Every sign is drawn on the 120 × 80 canvas of the library. Size marks, roofs and supplements are
15
+ * placed relative to the form they belong to, so they fit every basic form; under a roof the size
16
+ * marks sit inside the roof, since the canvas has no room above it.
17
+ */
18
+
19
+ import {canvas, element, group, label, renderSvg, type SvgElement} from './svg'
20
+
21
+ /** The basic forms of chapter 1, in its order. */
22
+ export const BASIC_FORMS = [
23
+ 'formation', 'person', 'land-vehicle', 'aircraft', 'watercraft', 'place', 'building', 'room', 'area',
24
+ 'measure', 'hazard', 'landmark', 'event', 'volunteer',
25
+ ] as const
26
+
27
+ /** A basic form of a tactical sign. */
28
+ export type BasicForm = typeof BASIC_FORMS[number]
29
+
30
+ /** The organisations of chapter 2, in its order. */
31
+ export const SIGN_ORGANISATIONS = ['fire', 'aid', 'thw', 'command', 'police', 'military', 'other', 'civil'] as const
32
+
33
+ /** An organisation whose colour a sign carries. */
34
+ export type SignOrganisation = typeof SIGN_ORGANISATIONS[number]
35
+
36
+ /** How the colour is applied: filling the form, only as its outline, or black on white. */
37
+ export type SignStyle = 'filled' | 'outline' | 'mono'
38
+
39
+ /** The tactical units of 5.4 and the associations of 5.5. */
40
+ export const SIGN_SIZES = ['squad', 'section', 'group', 'platoon', 'association-1', 'association-2', 'association-3'] as const
41
+
42
+ /** The size of what a sign stands for. */
43
+ export type SignSize = typeof SIGN_SIZES[number]
44
+
45
+ /** The supplementary signs of chapter 3, in its order. */
46
+ export const SUPPLEMENTS = ['command', 'special-function', 'logistics', 'uncrewed', 'bicycle', 'motorcycle', 'roof'] as const
47
+
48
+ /** A supplementary sign. */
49
+ export type Supplement = typeof SUPPLEMENTS[number]
50
+
51
+ /** How a land vehicle or trailer runs, after 5.1.1 and 5.1.2: its wheels, tracks or rails. */
52
+ export const DRIVES = ['road', 'offroad', 'all-terrain', 'amphibious', 'tracked', 'rail', 'rail-capable', 'towed-by-car', 'towed-by-truck'] as const
53
+
54
+ /** The running gear of a land vehicle or trailer. */
55
+ export type Drive = typeof DRIVES[number]
56
+
57
+ /** What a land vehicle is or carries, after 5.1.1 to 5.1.3: trailers, swap bodies and containers. */
58
+ export const VEHICLE_BODIES = [
59
+ 'swap-loader', 'container-carrier', 'trailer', 'roll-off-trailer', 'container-trailer',
60
+ 'roll-off-container', 'swap-container', 'swap-body', 'roll-container',
61
+ ] as const
62
+
63
+ /** The body of a land vehicle. */
64
+ export type VehicleBody = typeof VEHICLE_BODIES[number]
65
+
66
+ /** How an aircraft flies, after 5.1.4. */
67
+ export const FLIGHTS = ['flying', 'rotary-wing', 'fixed-wing'] as const
68
+
69
+ /** The flight of an aircraft. */
70
+ export type Flight = typeof FLIGHTS[number]
71
+
72
+ /** What a tactical sign is drawn from. */
73
+ export interface TacticalSignSpec {
74
+ form: BasicForm
75
+ organisation?: SignOrganisation
76
+ style?: SignStyle
77
+ size?: SignSize
78
+ supplements?: readonly Supplement[]
79
+ /** For land vehicles: a protected vehicle has a straight top and an inward-curving underside (5.1). */
80
+ protected?: boolean
81
+ drive?: Drive
82
+ body?: VehicleBody
83
+ flight?: Flight
84
+ /** Writing inside the form, such as a function or a vehicle name. */
85
+ text?: string
86
+ /** Shows the organisation's short name, which chapter 2 asks for whenever colour is missing. */
87
+ abbreviation?: boolean
88
+ }
89
+
90
+ /** The colour, its writing colour and short name of each organisation, after chapter 2 and annex O. */
91
+ export const ORGANISATION_COLOURS: Readonly<Record<SignOrganisation, Readonly<{fill: string, text: string, abbreviation: string}>>> = {
92
+ fire: {fill: '#FA321E', text: '#FFFFFF', abbreviation: 'Fw'},
93
+ aid: {fill: '#FFFFFF', text: '#000000', abbreviation: 'HiOrg'},
94
+ thw: {fill: '#003399', text: '#FFFFFF', abbreviation: 'THW'},
95
+ command: {fill: '#FAFA00', text: '#000000', abbreviation: ''},
96
+ police: {fill: '#64DC32', text: '#000000', abbreviation: 'Pol'},
97
+ military: {fill: '#B4783C', text: '#FFFFFF', abbreviation: 'Bw'},
98
+ other: {fill: '#FA8C00', text: '#000000', abbreviation: 'Sonst.'},
99
+ civil: {fill: '#BEBEBE', text: '#000000', abbreviation: 'ZIV'},
100
+ }
101
+
102
+ const BLACK = '#000000'
103
+ const WHITE = '#FFFFFF'
104
+ const HAZARD_RED = '#FA321E'
105
+ const MEASURE_BLUE = '#3264FA'
106
+ const STROKE = 3
107
+
108
+ /** Where a form lies on the canvas and where its writing, bars and short name go. */
109
+ interface Layout {
110
+ d: string
111
+ closed: boolean
112
+ left: number
113
+ right: number
114
+ top: number
115
+ bottom: number
116
+ textWidth: number
117
+ textY: number
118
+ /** The command bar along the top inside the form (3.1), following a curved top. */
119
+ commandBar: string
120
+ /** The logistics bar along the bottom inside the form (3.3). */
121
+ logisticsBar: string
122
+ /** Where the short name sits; outside the form where the form has no room for it. */
123
+ short: {x: number, y: number, inside: boolean}
124
+ }
125
+
126
+ /** A layout with straight bars inset from the bounds and the short name in the lower right corner. */
127
+ function layout(d: string, left: number, right: number, top: number, bottom: number, textWidth: number, textY: number,
128
+ extra: Partial<Layout> = {}): Layout {
129
+ return {
130
+ d, closed: true, left, right, top, bottom, textWidth, textY,
131
+ commandBar: `M${left + 5} ${top + 6} H${right - 5}`,
132
+ logisticsBar: `M${left + 5} ${bottom - 6} H${right - 5}`,
133
+ short: {x: right - 14, y: bottom - 8, inside: true},
134
+ ...extra,
135
+ }
136
+ }
137
+
138
+ const SHORT_BESIDE = {x: 104, y: 42, inside: false}
139
+
140
+ /** The layout of each basic form. */
141
+ const FORMS: Record<BasicForm, Layout> = {
142
+ 'formation': layout('M10 16 H110 V68 H10 Z', 10, 110, 16, 68, 86, 42),
143
+ 'person': layout('M60 16 L86 42 L60 68 L34 42 Z', 34, 86, 16, 68, 30, 42,
144
+ {commandBar: 'M48 28 H72', logisticsBar: 'M48 56 H72', short: SHORT_BESIDE}),
145
+ 'land-vehicle': layout('M10 16 Q60 24 110 16 V60 H10 Z', 10, 110, 16, 60, 86, 40, {commandBar: 'M15 23 Q60 31 105 23'}),
146
+ 'aircraft': layout('M22 62 A38 38 0 0 1 98 62 Z', 22, 98, 24, 62, 56, 48,
147
+ {commandBar: 'M40 34 H80', short: {x: 84, y: 56, inside: true}}),
148
+ 'watercraft': layout('M22 20 A38 38 0 0 0 98 20 Z', 22, 98, 20, 58, 56, 34,
149
+ {logisticsBar: 'M40 48 H80', short: {x: 80, y: 28, inside: true}}),
150
+ 'place': layout('M86 42 A26 26 0 1 1 34 42 A26 26 0 1 1 86 42 Z', 34, 86, 16, 68, 40, 42,
151
+ {commandBar: 'M42 26 H78', logisticsBar: 'M42 58 H78', short: SHORT_BESIDE}),
152
+ 'building': layout('M24 32 L60 16 L96 32 V68 H24 Z', 24, 96, 16, 68, 60, 50, {commandBar: 'M29 38 H91'}),
153
+ 'room': layout('M34 16 H86 V68 H34 Z', 34, 86, 16, 68, 44, 42, {short: SHORT_BESIDE}),
154
+ 'area': layout('M28 30 Q34 16 54 20 Q78 12 90 24 Q100 36 92 50 Q96 64 76 66 Q58 70 44 64 Q24 66 22 52 Q18 40 28 30 Z',
155
+ 22, 96, 16, 68, 56, 42, {commandBar: 'M34 28 H86', logisticsBar: 'M34 58 H86'}),
156
+ 'measure': layout('M28 18 H92 L60 68 Z', 28, 92, 18, 68, 36, 34, {logisticsBar: 'M50 50 H70', short: SHORT_BESIDE}),
157
+ 'hazard': layout('M60 16 L92 66 H28 Z', 28, 92, 16, 66, 36, 52, {commandBar: 'M50 32 H70', short: SHORT_BESIDE}),
158
+ 'landmark': layout('M46 16 H74 V54 L60 68 L46 54 Z', 46, 74, 16, 68, 24, 36, {short: SHORT_BESIDE}),
159
+ 'event': {...layout('M38 22 L60 64 L82 22', 38, 82, 22, 64, 30, 34, {short: SHORT_BESIDE}), closed: false},
160
+ 'volunteer': layout('M47 29 A13 13 0 0 1 73 29 A13 13 0 0 1 73 55 A13 13 0 0 1 47 55 A13 13 0 0 1 47 29 Z',
161
+ 34, 86, 16, 68, 34, 42, {commandBar: 'M46 28 H74', logisticsBar: 'M46 56 H74', short: SHORT_BESIDE}),
162
+ }
163
+
164
+ /** The colours a sign is drawn in. */
165
+ interface Paint {
166
+ fill: string
167
+ line: string
168
+ text: string
169
+ }
170
+
171
+ /**
172
+ * The colours of a sign. In black and white everything is black on white. Otherwise a hazard is
173
+ * red and a measure blue, whatever the organisation, and an event has no fill. Filled signs carry a
174
+ * black outline, outlined signs the organisation's colour (black for the white of the aid
175
+ * organisations). A sign without an organisation is drawn black on white, as chapter 1 shows the
176
+ * basic forms; a volunteer without one is grey, as 1.14 asks.
177
+ */
178
+ function paint(spec: TacticalSignSpec): Paint {
179
+ const style = spec.style ?? 'filled'
180
+ if (style === 'mono') return {fill: WHITE, line: BLACK, text: BLACK}
181
+ if (spec.form === 'hazard') return {fill: 'none', line: HAZARD_RED, text: HAZARD_RED}
182
+ if (spec.form === 'measure') return {fill: 'none', line: MEASURE_BLUE, text: MEASURE_BLUE}
183
+ if (spec.form === 'event') return {fill: 'none', line: BLACK, text: BLACK}
184
+ const organisation = spec.organisation ?? (spec.form === 'volunteer' ? 'civil' : undefined)
185
+ if (!organisation) return {fill: WHITE, line: BLACK, text: BLACK}
186
+ const colour = ORGANISATION_COLOURS[organisation]
187
+ if (style === 'outline') {
188
+ const line = colour.fill === WHITE ? BLACK : colour.fill
189
+ return {fill: WHITE, line, text: line}
190
+ }
191
+ return {fill: colour.fill, line: BLACK, text: colour.text}
192
+ }
193
+
194
+ function dot(cx: number, cy: number): SvgElement {
195
+ return element('circle', {cx, cy, r: 3, fill: BLACK})
196
+ }
197
+
198
+ function bar(cx: number, bottom: number): SvgElement {
199
+ return element('rect', {x: cx - 2.5, y: bottom - 12, width: 5, height: 12, fill: BLACK})
200
+ }
201
+
202
+ /** The marks of a unit size or association, resting just above `above`. */
203
+ function sizeMark(size: SignSize, above: number): SvgElement[] {
204
+ const y = above - 7
205
+ switch (size) {
206
+ case 'squad': return [dot(60, y)]
207
+ case 'section': return [dot(60, y - 6), dot(60, y + 1)]
208
+ case 'group': return [dot(52, y), dot(68, y)]
209
+ case 'platoon': return [dot(50, y), dot(60, y), dot(70, y)]
210
+ case 'association-1': return [bar(60, above - 3)]
211
+ case 'association-2': return [bar(52, above - 3), bar(68, above - 3)]
212
+ case 'association-3': return [bar(48, above - 3), bar(60, above - 3), bar(72, above - 3)]
213
+ }
214
+ }
215
+
216
+ /** A line of the given colour and width. */
217
+ function line(d: string, colour: string, width = STROKE): SvgElement {
218
+ return element('path', {d, fill: 'none', stroke: colour, 'stroke-width': width, 'stroke-linecap': 'round', 'stroke-linejoin': 'round'})
219
+ }
220
+
221
+ const ROOF_HEIGHT = 11
222
+
223
+ /** The drawing of a supplementary sign of chapter 3 on a form. */
224
+ function supplement(kind: Supplement, form: Layout, colour: string): SvgElement[] {
225
+ const y = form.textY
226
+ switch (kind) {
227
+ case 'command': return [line(form.commandBar, BLACK, 5)]
228
+ case 'logistics': return [line(form.logisticsBar, BLACK, 5)]
229
+ case 'special-function': return [line(`M52 ${form.top + 8} H68`, colour)]
230
+ case 'uncrewed': return [line(`M50 ${y - 14} L60 ${y - 6} L70 ${y - 14}`, colour, 4)]
231
+ case 'bicycle': return [line(`M50 ${y - 6} Q60 ${y - 18} 70 ${y - 6} M60 ${y - 12} V${y + 12}`, colour)]
232
+ case 'motorcycle': return [line(`M50 ${y - 6} Q60 ${y - 18} 70 ${y - 6} M58 ${y - 12} V${y + 12} M62 ${y - 12} V${y + 12}`, colour)]
233
+ case 'roof': return [line(`M${form.left + 4} ${form.top - 3} L60 ${form.top - 3 - ROOF_HEIGHT} L${form.right - 4} ${form.top - 3}`, BLACK)]
234
+ }
235
+ }
236
+
237
+ function wheel(cx: number, cy: number, colour: string): SvgElement {
238
+ return element('circle', {cx, cy, r: 4, fill: WHITE, stroke: colour, 'stroke-width': 2})
239
+ }
240
+
241
+ /** The running gear below a vehicle. */
242
+ function driveMarks(drive: Drive, form: Layout, colour: string, framed: boolean): SvgElement[] {
243
+ const y = form.bottom + (framed ? 10 : 6)
244
+ const left = form.left + 8
245
+ const right = form.right - 8
246
+ const middle = (form.left + form.right) / 2
247
+ switch (drive) {
248
+ case 'road': return [wheel(left, y, colour), wheel(right, y, colour)]
249
+ case 'offroad': return [wheel(left, y, colour), wheel(middle, y, colour), wheel(right, y, colour)]
250
+ case 'all-terrain': return [line(`M${left} ${y} H${right}`, colour, 2), wheel(left, y, colour), wheel(middle, y, colour), wheel(right, y, colour)]
251
+ case 'amphibious': return [wheel(left, y, colour), wheel(right, y, colour),
252
+ line(`M${left + 8} ${y} Q${left + 16} ${y - 8} ${left + 24} ${y} T${left + 40} ${y} T${left + 56} ${y} T${left + 72} ${y}`, colour, 2)]
253
+ case 'tracked': return [element('rect', {x: form.left + 2, y: y - 4, width: form.right - form.left - 4, height: 10, rx: 5, fill: WHITE, stroke: colour, 'stroke-width': 2})]
254
+ case 'rail': return [wheel(left - 2, y, colour), wheel(left + 8, y, colour), wheel(right - 8, y, colour), wheel(right + 2, y, colour)]
255
+ case 'rail-capable': return [wheel(left - 2, y, colour), wheel(left + 8, y, colour), wheel(middle, y, colour), wheel(right - 8, y, colour), wheel(right + 2, y, colour)]
256
+ case 'towed-by-car': return [wheel(middle, y, colour)]
257
+ case 'towed-by-truck': return [wheel(middle - 5, y, colour), wheel(middle + 5, y, colour)]
258
+ }
259
+ }
260
+
261
+ /** The hook of a roll-off container at the top left of a body. */
262
+ function rollOffHook(form: Layout, colour: string): SvgElement {
263
+ return line(`M${form.left + 4} ${form.top + 6} Q${form.left} ${form.top} ${form.left + 6} ${form.top - 2}`, colour, 2)
264
+ }
265
+
266
+ /** The two lifting eyes of a swap body or container on top. */
267
+ function containerEyes(form: Layout, colour: string): SvgElement {
268
+ const top = form.top
269
+ return line(`M${form.left + 4} ${top} Q${form.left + 4} ${top - 6} ${form.left + 10} ${top - 6} Q${form.left + 16} ${top - 6} ${form.left + 16} ${top}`
270
+ + ` M${form.right - 16} ${top} Q${form.right - 16} ${top - 6} ${form.right - 10} ${top - 6} Q${form.right - 4} ${top - 6} ${form.right - 4} ${top}`, colour, 2)
271
+ }
272
+
273
+ /** The L-shaped frame that carries a swap body. */
274
+ function carrierFrame(form: Layout, colour: string): SvgElement {
275
+ return line(`M${form.left - 6} ${form.top + 2} V${form.bottom + 4} H${form.right + 4}`, colour, 2)
276
+ }
277
+
278
+ /** The drawbar on the left of a trailer, at 60 % of its height, ending at the body or its frame. */
279
+ function drawbar(form: Layout, colour: string, framed: boolean): SvgElement {
280
+ const y = form.top + (form.bottom - form.top) * 0.6
281
+ const end = form.left - (framed ? 6 : 0)
282
+ return line(`M${end - 7} ${y} H${end} M${end - 7} ${y - 3} V${y + 3}`, colour, 2)
283
+ }
284
+
285
+ const FRAMED: ReadonlySet<VehicleBody> = new Set(['swap-loader', 'container-carrier', 'roll-off-trailer', 'container-trailer'])
286
+ const TRAILERS: ReadonlySet<VehicleBody> = new Set(['trailer', 'roll-off-trailer', 'container-trailer'])
287
+ const BOXES: ReadonlySet<VehicleBody> = new Set(['container-carrier', 'container-trailer', 'swap-container', 'swap-body'])
288
+
289
+ /** What a vehicle body adds around its form. */
290
+ function bodyMarks(body: VehicleBody, form: Layout, colour: string): SvgElement[] {
291
+ const marks: SvgElement[] = []
292
+ if (FRAMED.has(body)) marks.push(carrierFrame(form, colour))
293
+ if (TRAILERS.has(body)) marks.push(drawbar(form, colour, FRAMED.has(body)))
294
+ if (body === 'swap-loader' || body === 'roll-off-trailer' || body === 'roll-off-container') marks.push(rollOffHook(form, colour))
295
+ if (body === 'container-carrier' || body === 'container-trailer' || body === 'swap-container') marks.push(containerEyes(form, colour))
296
+ if (body === 'swap-body') marks.push(line(`M${form.left + 10} ${form.bottom} V${form.bottom + 8} M${form.right - 10} ${form.bottom} V${form.bottom + 8}`, colour, 2))
297
+ if (body === 'roll-container') marks.push(line(`M${form.right} ${form.top + 2} Q${form.right + 8} ${form.top - 4} ${form.right + 3} ${form.top - 9}`, colour, 2),
298
+ wheel(54, form.bottom + 6, colour), wheel(66, form.bottom + 6, colour))
299
+ return marks
300
+ }
301
+
302
+ /** What 5.1.4 adds to an aircraft: the flying line beneath it or its drive inside. */
303
+ function flightMarks(flight: Flight, form: Layout, colour: string): SvgElement[] {
304
+ switch (flight) {
305
+ case 'flying': return [line(`M${form.left - 2} ${form.bottom + 8} H54 L60 ${form.bottom + 14} L66 ${form.bottom + 8} H${form.right + 2}`, colour, 2)]
306
+ case 'rotary-wing': return [element('path', {d: 'M40 40 L60 48 L80 40 V56 L60 48 L40 56 Z', fill: colour})]
307
+ case 'fixed-wing': return [element('path', {d: 'M60 48 C52 36 38 38 38 48 C38 58 52 60 60 48 C68 36 82 38 82 48 C82 58 68 60 60 48 Z', fill: colour})]
308
+ }
309
+ }
310
+
311
+ /**
312
+ * The layout of a sign: a protected land vehicle has a straight top and a curved underside, a body
313
+ * that is a container sits as a box above its gear, and a roll container is narrow.
314
+ */
315
+ function layoutOf(spec: TacticalSignSpec): Layout {
316
+ const form = FORMS[spec.form]
317
+ if (spec.form === 'land-vehicle' && spec.protected) return {...form, d: 'M10 16 H110 V60 Q60 52 10 60 Z', commandBar: 'M15 22 H105'}
318
+ if (spec.body && BOXES.has(spec.body)) return layout('M14 18 H106 V60 H14 Z', 14, 106, 18, 60, 80, 39)
319
+ if (spec.body === 'roll-container') return layout('M42 18 Q60 22 78 18 V62 H42 Z', 42, 78, 18, 62, 30, 40, {short: SHORT_BESIDE})
320
+ return form
321
+ }
322
+
323
+ /** The sign as a tree of SVG elements on the common canvas. */
324
+ export function tacticalSignTree(spec: TacticalSignSpec): SvgElement {
325
+ const form = layoutOf(spec)
326
+ const colours = paint(spec)
327
+ const supplements = spec.supplements ?? []
328
+ const parts: SvgElement[] = [element('path', {
329
+ d: form.d,
330
+ fill: form.closed ? colours.fill : 'none',
331
+ stroke: colours.line,
332
+ 'stroke-width': STROKE,
333
+ 'stroke-linejoin': 'round',
334
+ })]
335
+ if (spec.body) parts.push(...bodyMarks(spec.body, form, colours.line))
336
+ if (spec.drive) parts.push(...driveMarks(spec.drive, form, colours.line, spec.body !== undefined && FRAMED.has(spec.body)))
337
+ if (spec.flight) parts.push(...flightMarks(spec.flight, form, colours.line))
338
+ for (const kind of supplements) parts.push(...supplement(kind, form, colours.line))
339
+ if (spec.size) parts.push(...sizeMark(spec.size, form.top))
340
+ if (spec.text) parts.push(label(spec.text, 60, form.textY, colours.text, form.textWidth))
341
+ const short = spec.abbreviation && spec.organisation ? ORGANISATION_COLOURS[spec.organisation].abbreviation : ''
342
+ if (short) parts.push(label(short, form.short.x, form.short.y, form.short.inside ? colours.text : BLACK, 24, 10))
343
+ return canvas([group(parts)])
344
+ }
345
+
346
+ /** The sign as SVG markup, for map icons. */
347
+ export function tacticalSign(spec: TacticalSignSpec): string {
348
+ return renderSvg(tacticalSignTree(spec))
349
+ }
@@ -0,0 +1,81 @@
1
+ /**
2
+ * The small SVG toolkit every symbol of the library is built with: a tree of elements that
3
+ * `TacticalSymbol` renders as Vue nodes and `renderSvg` writes as escaped markup.
4
+ */
5
+
6
+ /** One SVG element of a symbol, with its attributes and either child elements or text. */
7
+ export interface SvgElement {
8
+ tag: string
9
+ attributes: Record<string, string | number>
10
+ children?: SvgElement[]
11
+ text?: string
12
+ }
13
+
14
+ /** The attributes of an SVG element. */
15
+ export type Attributes = SvgElement['attributes']
16
+
17
+ /** The width of every symbol's canvas. */
18
+ export const SYMBOL_WIDTH = 120
19
+ /** The height of every symbol's canvas. */
20
+ export const SYMBOL_HEIGHT = 80
21
+
22
+ /** The default width of writing inside a symbol before it is squeezed. */
23
+ export const MAX_TEXT_WIDTH = 86
24
+
25
+ /** An SVG element without children. */
26
+ export function element(tag: string, attributes: Attributes): SvgElement {
27
+ return {tag, attributes}
28
+ }
29
+
30
+ /** A group of elements. */
31
+ export function group(children: SvgElement[], attributes: Attributes = {}): SvgElement {
32
+ return {tag: 'g', attributes, children}
33
+ }
34
+
35
+ /** Escapes text for use inside SVG or HTML markup. */
36
+ export function escapeSvg(text: string): string {
37
+ return text.replace(/[&<>"']/g, character => `&#${character.charCodeAt(0)};`)
38
+ }
39
+
40
+ /**
41
+ * Writes a symbol tree as SVG markup, escaping every attribute value and text. Tag and attribute
42
+ * names are written as they are, so the tree must be built by code, as the trees of this library are.
43
+ */
44
+ export function renderSvg(node: SvgElement): string {
45
+ const attributes = Object.entries(node.attributes)
46
+ .map(([name, value]) => ` ${name}="${escapeSvg(String(value))}"`)
47
+ .join('')
48
+ const content = node.text !== undefined
49
+ ? escapeSvg(node.text)
50
+ : (node.children ?? []).map(renderSvg).join('')
51
+ return content ? `<${node.tag}${attributes}>${content}</${node.tag}>` : `<${node.tag}${attributes}/>`
52
+ }
53
+
54
+ /** Writing at a point, squeezed to `maxWidth` when it is long. */
55
+ export function label(text: string, x: number, y: number, colour: string, maxWidth = MAX_TEXT_WIDTH, size?: number): SvgElement {
56
+ const fontSize = size ?? (text.length > 8 ? 17 : 22)
57
+ const squeeze: Attributes = text.length * fontSize * 0.5 > maxWidth
58
+ ? {textLength: maxWidth, lengthAdjust: 'spacingAndGlyphs'}
59
+ : {}
60
+ return {
61
+ tag: 'text',
62
+ attributes: {
63
+ x, y, fill: colour, 'font-size': fontSize, 'font-weight': 700,
64
+ 'font-family': 'Barlow Condensed, Barlow, sans-serif', 'text-anchor': 'middle',
65
+ 'dominant-baseline': 'central', ...squeeze,
66
+ },
67
+ text,
68
+ }
69
+ }
70
+
71
+ /** The SVG element of the common 120 × 80 canvas around a symbol's content. */
72
+ export function canvas(children: SvgElement[]): SvgElement {
73
+ return {
74
+ tag: 'svg',
75
+ attributes: {
76
+ xmlns: 'http://www.w3.org/2000/svg', viewBox: `0 0 ${SYMBOL_WIDTH} ${SYMBOL_HEIGHT}`,
77
+ width: SYMBOL_WIDTH, height: SYMBOL_HEIGHT,
78
+ },
79
+ children,
80
+ }
81
+ }
@@ -11,6 +11,10 @@
11
11
  * image) for it to apply.
12
12
  */
13
13
 
14
+ import {canvas, element, label, renderSvg, type Attributes, type SvgElement} from './svg'
15
+
16
+ export {SYMBOL_HEIGHT, SYMBOL_WIDTH, escapeSvg, renderSvg, type SvgElement} from './svg'
17
+
14
18
  /** The organisation a unit belongs to, which sets its colours. */
15
19
  export type Organisation = 'fire' | 'medical'
16
20
 
@@ -43,23 +47,9 @@ export interface SymbolSpec {
43
47
  size?: UnitSize
44
48
  }
45
49
 
46
- /** One SVG element of a symbol, with its attributes and either child elements or text. */
47
- export interface SvgElement {
48
- tag: string
49
- attributes: Record<string, string | number>
50
- children?: SvgElement[]
51
- text?: string
52
- }
53
-
54
- /** The width of every symbol's canvas. */
55
- export const SYMBOL_WIDTH = 120
56
- /** The height of every symbol's canvas. */
57
- export const SYMBOL_HEIGHT = 80
58
-
59
50
  const RED = 'var(--color-signal-500)'
60
51
  const WHITE = 'white'
61
52
  const STROKE = 3
62
- const MAX_TEXT_WIDTH = 86
63
53
  const SQUAD_TEXT_WIDTH = 62
64
54
 
65
55
  interface Colours {
@@ -68,13 +58,6 @@ interface Colours {
68
58
  text: string
69
59
  }
70
60
 
71
- type Attributes = SvgElement['attributes']
72
-
73
- /** An SVG element without children. */
74
- function element(tag: string, attributes: Attributes): SvgElement {
75
- return {tag, attributes}
76
- }
77
-
78
61
  /** The attributes of an outlined form. */
79
62
  function outlined(fill: string, line: string): Attributes {
80
63
  return {fill, stroke: line, 'stroke-width': STROKE}
@@ -92,42 +75,6 @@ function colours(organisation: Organisation): Colours {
92
75
  : {fill: RED, line: RED, text: WHITE}
93
76
  }
94
77
 
95
- /** Escapes text for use inside SVG or HTML markup. */
96
- export function escapeSvg(text: string): string {
97
- return text.replace(/[&<>"']/g, character => `&#${character.charCodeAt(0)};`)
98
- }
99
-
100
- /**
101
- * Writes a symbol tree as SVG markup, escaping every attribute value and text. Tag and attribute
102
- * names are written as they are, so the tree must be built by code, as the trees of this module are.
103
- */
104
- export function renderSvg(node: SvgElement): string {
105
- const attributes = Object.entries(node.attributes)
106
- .map(([name, value]) => ` ${name}="${escapeSvg(String(value))}"`)
107
- .join('')
108
- const content = node.text !== undefined
109
- ? escapeSvg(node.text)
110
- : (node.children ?? []).map(renderSvg).join('')
111
- return content ? `<${node.tag}${attributes}>${content}</${node.tag}>` : `<${node.tag}${attributes}/>`
112
- }
113
-
114
- /** The writing inside a symbol, squeezed to fit when it is long. */
115
- function label(text: string, x: number, y: number, colour: string, maxWidth = MAX_TEXT_WIDTH): SvgElement {
116
- const size = text.length > 8 ? 17 : 22
117
- const squeeze: Attributes = text.length * size * 0.5 > maxWidth
118
- ? {textLength: maxWidth, lengthAdjust: 'spacingAndGlyphs'}
119
- : {}
120
- return {
121
- tag: 'text',
122
- attributes: {
123
- x, y, fill: colour, 'font-size': size, 'font-weight': 700,
124
- 'font-family': 'Barlow Condensed, Barlow, sans-serif', 'text-anchor': 'middle',
125
- 'dominant-baseline': 'central', ...squeeze,
126
- },
127
- text,
128
- }
129
- }
130
-
131
78
  /** Where the dots of each unit size sit above the symbol: one, two stacked, two apart, three in a row. */
132
79
  const SIZE_DOTS: Record<UnitSize, [number, number][]> = {
133
80
  squad: [[60, 6]],
@@ -220,14 +167,3 @@ export function markSymbol(kind: MarkKind): string {
220
167
  return renderSvg(markSymbolTree(kind))
221
168
  }
222
169
 
223
- /** The SVG element of the common canvas around a symbol's content. */
224
- function canvas(children: SvgElement[]): SvgElement {
225
- return {
226
- tag: 'svg',
227
- attributes: {
228
- xmlns: 'http://www.w3.org/2000/svg', viewBox: `0 0 ${SYMBOL_WIDTH} ${SYMBOL_HEIGHT}`,
229
- width: SYMBOL_WIDTH, height: SYMBOL_HEIGHT,
230
- },
231
- children,
232
- }
233
- }
package/src/vite/logo.ts CHANGED
@@ -4,7 +4,7 @@ import type {Plugin} from 'vite'
4
4
  import {type RootFile, rootFilesPlugin} from './root-files.js'
5
5
 
6
6
  /** The tools for which `@emberbox/ui` ships a logo. */
7
- export type Logo = 'emberbox' | 'alarmzettel' | 'statussim' | 'calltaker' | 'planspiel'
7
+ export type Logo = 'emberbox' | 'alarmzettel' | 'statussim' | 'calltaker' | 'planspiel' | 'lernkarten'
8
8
 
9
9
  const LOGOS = fileURLToPath(new URL('../../logos/', import.meta.url))
10
10