@emberbox/ui 0.6.0 → 0.7.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.
- package/dist/vite/prerender.js +17 -0
- package/package.json +1 -1
- package/src/symbols/tactical.ts +26 -15
- package/src/vite/prerender.ts +18 -0
package/dist/vite/prerender.js
CHANGED
|
@@ -11,6 +11,22 @@ function sitemap(url, paths) {
|
|
|
11
11
|
const entries = paths.map(path => ` <url><loc>${url}${path}</loc></url>`).join('\n');
|
|
12
12
|
return `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${entries}\n</urlset>\n`;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Vue's compile-time feature flags with their production values. Dependencies that Node loads in
|
|
16
|
+
* their bundler build, such as vue-i18n, read them as globals: a bundler replaces them, Node does not.
|
|
17
|
+
* The values are the defaults of `@vitejs/plugin-vue`.
|
|
18
|
+
*/
|
|
19
|
+
const VUE_FLAGS = {
|
|
20
|
+
__VUE_OPTIONS_API__: true,
|
|
21
|
+
__VUE_PROD_DEVTOOLS__: false,
|
|
22
|
+
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false,
|
|
23
|
+
};
|
|
24
|
+
/** Defines Vue's feature flags as globals where nothing has defined them yet, as Vue's own bundler build does. */
|
|
25
|
+
function defineVueFlags() {
|
|
26
|
+
const scope = globalThis;
|
|
27
|
+
for (const [flag, value] of Object.entries(VUE_FLAGS))
|
|
28
|
+
scope[flag] ??= value;
|
|
29
|
+
}
|
|
14
30
|
/**
|
|
15
31
|
* Prerenders the public pages once the client build is written. It builds the entry as an SSR
|
|
16
32
|
* bundle, calls `render` for every path with the built `index.html` as template and writes the
|
|
@@ -41,6 +57,7 @@ export function prerenderPlugin(options, url) {
|
|
|
41
57
|
const bundle = readdirSync(ssrOutDir).find(candidate => /^(.+)\.m?js$/.exec(candidate)?.[1] === name);
|
|
42
58
|
if (!bundle)
|
|
43
59
|
throw new Error(`The SSR bundle of ${options.entry} is missing in ${ssrOutDir}.`);
|
|
60
|
+
defineVueFlags();
|
|
44
61
|
const entry = await import(pathToFileURL(join(ssrOutDir, bundle)).href);
|
|
45
62
|
const template = readFileSync(join(outDir, 'index.html'), 'utf8');
|
|
46
63
|
for (const path of options.paths) {
|
package/package.json
CHANGED
package/src/symbols/tactical.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Tactical symbols after
|
|
3
|
-
* follow the system of the recommendations (basic form,
|
|
4
|
-
* artwork.
|
|
2
|
+
* Tactical symbols after the recommendations "Taktische Zeichen im Bevölkerungsschutz" of the BBK
|
|
3
|
+
* (2024, for FwDV 102 / DV 102). The drawings follow the system of the recommendations (basic form,
|
|
4
|
+
* size mark, writing) without copying their artwork.
|
|
5
5
|
*
|
|
6
6
|
* A symbol is built as a tree of SVG elements: `TacticalSymbol` renders the tree as Vue nodes in
|
|
7
7
|
* the page, and `renderSvg` writes it as an escaped string for map icons. Every symbol is drawn on
|
|
@@ -14,10 +14,13 @@
|
|
|
14
14
|
/** The organisation a unit belongs to, which sets its colours. */
|
|
15
15
|
export type Organisation = 'fire' | 'medical'
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
|
|
17
|
+
/**
|
|
18
|
+
* The basic form of a unit's symbol. `squad` is not part of the recommendations: a compact,
|
|
19
|
+
* rounded form that sets a dismounted squad apart from vehicles on a busy map.
|
|
20
|
+
*/
|
|
21
|
+
export type SymbolShape = 'vehicle' | 'container' | 'trailer' | 'boat' | 'unit' | 'squad'
|
|
19
22
|
|
|
20
|
-
/** The size of a unit, shown by dots
|
|
23
|
+
/** The size of a tactical unit, shown by dots above its symbol: Trupp, Staffel, Gruppe, Zug. */
|
|
21
24
|
export type UnitSize = 'squad' | 'section' | 'group' | 'platoon'
|
|
22
25
|
|
|
23
26
|
/** Marks of places and events of an incident. */
|
|
@@ -57,6 +60,7 @@ const RED = 'var(--color-signal-500)'
|
|
|
57
60
|
const WHITE = 'white'
|
|
58
61
|
const STROKE = 3
|
|
59
62
|
const MAX_TEXT_WIDTH = 86
|
|
63
|
+
const SQUAD_TEXT_WIDTH = 62
|
|
60
64
|
|
|
61
65
|
interface Colours {
|
|
62
66
|
fill: string
|
|
@@ -108,10 +112,10 @@ export function renderSvg(node: SvgElement): string {
|
|
|
108
112
|
}
|
|
109
113
|
|
|
110
114
|
/** The writing inside a symbol, squeezed to fit when it is long. */
|
|
111
|
-
function label(text: string, x: number, y: number, colour: string): SvgElement {
|
|
115
|
+
function label(text: string, x: number, y: number, colour: string, maxWidth = MAX_TEXT_WIDTH): SvgElement {
|
|
112
116
|
const size = text.length > 8 ? 17 : 22
|
|
113
|
-
const squeeze: Attributes = text.length * size * 0.5 >
|
|
114
|
-
? {textLength:
|
|
117
|
+
const squeeze: Attributes = text.length * size * 0.5 > maxWidth
|
|
118
|
+
? {textLength: maxWidth, lengthAdjust: 'spacingAndGlyphs'}
|
|
115
119
|
: {}
|
|
116
120
|
return {
|
|
117
121
|
tag: 'text',
|
|
@@ -124,13 +128,18 @@ function label(text: string, x: number, y: number, colour: string): SvgElement {
|
|
|
124
128
|
}
|
|
125
129
|
}
|
|
126
130
|
|
|
127
|
-
/**
|
|
131
|
+
/** Where the dots of each unit size sit above the symbol: one, two stacked, two apart, three in a row. */
|
|
132
|
+
const SIZE_DOTS: Record<UnitSize, [number, number][]> = {
|
|
133
|
+
squad: [[60, 6]],
|
|
134
|
+
section: [[60, 3], [60, 10]],
|
|
135
|
+
group: [[52, 6], [68, 6]],
|
|
136
|
+
platoon: [[50, 6], [60, 6], [70, 6]],
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** The dots above a unit that tell its size, after the BBK recommendations of 2010 and 2024 alike. */
|
|
128
140
|
function sizeMark(size: UnitSize | undefined, colour: string): SvgElement[] {
|
|
129
141
|
if (!size) return []
|
|
130
|
-
|
|
131
|
-
const count = {squad: 1, section: 2, group: 3}[size]
|
|
132
|
-
return Array.from({length: count}, (_, index) =>
|
|
133
|
-
element('circle', {cx: 60 + (index - (count - 1) / 2) * 10, cy: 6, r: 3.5, fill: colour}))
|
|
142
|
+
return SIZE_DOTS[size].map(([cx, cy]) => element('circle', {cx, cy, r: 3, fill: colour}))
|
|
134
143
|
}
|
|
135
144
|
|
|
136
145
|
/** The basic form of a unit's symbol, with the writing inside. */
|
|
@@ -157,10 +166,12 @@ function body(shape: SymbolShape, colour: Colours, text: string): SvgElement[] {
|
|
|
157
166
|
return [element('path', {d: 'M10 16 H110 L100 56 Q60 72 20 56 Z', ...outline}), label(text, 60, 36, colour.text)]
|
|
158
167
|
case 'unit':
|
|
159
168
|
return [element('rect', {x: 10, y: 16, width: 100, height: 52, ...outline}), label(text, 60, 42, colour.text)]
|
|
169
|
+
case 'squad':
|
|
170
|
+
return [element('rect', {x: 24, y: 18, width: 72, height: 46, rx: 14, ...outline}), label(text, 60, 41, colour.text, SQUAD_TEXT_WIDTH)]
|
|
160
171
|
}
|
|
161
172
|
}
|
|
162
173
|
|
|
163
|
-
/** The symbol of a unit: a vehicle, container, trailer, boat or squad. */
|
|
174
|
+
/** The symbol of a unit: a vehicle, container, trailer, boat, unit or dismounted squad. */
|
|
164
175
|
export function unitSymbolTree(spec: SymbolSpec): SvgElement {
|
|
165
176
|
const colour = colours(spec.organisation)
|
|
166
177
|
return canvas([...sizeMark(spec.size, colour.line), ...body(spec.shape, colour, spec.text)])
|
package/src/vite/prerender.ts
CHANGED
|
@@ -28,6 +28,23 @@ function sitemap(url: string, paths: string[]): string {
|
|
|
28
28
|
return `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${entries}\n</urlset>\n`
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Vue's compile-time feature flags with their production values. Dependencies that Node loads in
|
|
33
|
+
* their bundler build, such as vue-i18n, read them as globals: a bundler replaces them, Node does not.
|
|
34
|
+
* The values are the defaults of `@vitejs/plugin-vue`.
|
|
35
|
+
*/
|
|
36
|
+
const VUE_FLAGS = {
|
|
37
|
+
__VUE_OPTIONS_API__: true,
|
|
38
|
+
__VUE_PROD_DEVTOOLS__: false,
|
|
39
|
+
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false,
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Defines Vue's feature flags as globals where nothing has defined them yet, as Vue's own bundler build does. */
|
|
43
|
+
function defineVueFlags(): void {
|
|
44
|
+
const scope = globalThis as Record<string, unknown>
|
|
45
|
+
for (const [flag, value] of Object.entries(VUE_FLAGS)) scope[flag] ??= value
|
|
46
|
+
}
|
|
47
|
+
|
|
31
48
|
/**
|
|
32
49
|
* Prerenders the public pages once the client build is written. It builds the entry as an SSR
|
|
33
50
|
* bundle, calls `render` for every path with the built `index.html` as template and writes the
|
|
@@ -56,6 +73,7 @@ export function prerenderPlugin(options: PrerenderOptions, url: string): Plugin
|
|
|
56
73
|
const name = basename(options.entry, extname(options.entry))
|
|
57
74
|
const bundle = readdirSync(ssrOutDir).find(candidate => /^(.+)\.m?js$/.exec(candidate)?.[1] === name)
|
|
58
75
|
if (!bundle) throw new Error(`The SSR bundle of ${options.entry} is missing in ${ssrOutDir}.`)
|
|
76
|
+
defineVueFlags()
|
|
59
77
|
const entry = await import(pathToFileURL(join(ssrOutDir, bundle)).href) as PrerenderEntry
|
|
60
78
|
const template = readFileSync(join(outDir, 'index.html'), 'utf8')
|
|
61
79
|
for (const path of options.paths) {
|