@emberbox/ui 0.4.1 → 0.6.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/logo.d.ts +3 -2
- package/dist/vite/logo.js +13 -26
- package/dist/vite/manifest.d.ts +18 -0
- package/dist/vite/manifest.js +53 -0
- package/dist/vite/root-files.d.ts +14 -0
- package/dist/vite/root-files.js +28 -0
- package/dist/vite.d.ts +4 -0
- package/dist/vite.js +6 -1
- package/logos/alarmzettel-192.png +0 -0
- package/logos/alarmzettel-maskable-192.png +0 -0
- package/logos/alarmzettel-maskable-512.png +0 -0
- package/logos/calltaker-192.png +0 -0
- package/logos/calltaker-maskable-192.png +0 -0
- package/logos/calltaker-maskable-512.png +0 -0
- package/logos/emberbox-192.png +0 -0
- package/logos/emberbox-maskable-192.png +0 -0
- package/logos/emberbox-maskable-512.png +0 -0
- package/logos/planspiel-192.png +0 -0
- package/logos/planspiel-maskable-192.png +0 -0
- package/logos/planspiel-maskable-512.png +0 -0
- package/logos/statussim-192.png +0 -0
- package/logos/statussim-maskable-192.png +0 -0
- package/logos/statussim-maskable-512.png +0 -0
- package/package.json +7 -2
- package/src/components/TacticalSymbol.vue +41 -0
- package/src/index.ts +6 -0
- package/src/symbols/tactical.ts +222 -0
- package/src/vite/logo.ts +14 -26
- package/src/vite/manifest.ts +69 -0
- package/src/vite/root-files.ts +34 -0
- package/src/vite.ts +9 -1
package/dist/vite/logo.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import type { Plugin } from 'vite';
|
|
|
2
2
|
/** The tools for which `@emberbox/ui` ships a logo. */
|
|
3
3
|
export type Logo = 'emberbox' | 'alarmzettel' | 'statussim' | 'calltaker' | 'planspiel';
|
|
4
4
|
/**
|
|
5
|
-
* Serves a tool's logo as `favicon.svg`, `apple-touch-icon.png`
|
|
6
|
-
*
|
|
5
|
+
* Serves a tool's logo as `favicon.svg`, `apple-touch-icon.png`, `logo-192.png`, `logo-512.png` and the
|
|
6
|
+
* maskable `logo-maskable-192.png` and `logo-maskable-512.png` at the root, in the dev server as in
|
|
7
|
+
* the build, and links the first two in the head of every page; the rest are the app icons.
|
|
7
8
|
*/
|
|
8
9
|
export declare function logoPlugin(logo: Logo): Plugin;
|
package/dist/vite/logo.js
CHANGED
|
@@ -1,40 +1,27 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { rootFilesPlugin } from './root-files.js';
|
|
3
4
|
const LOGOS = fileURLToPath(new URL('../../logos/', import.meta.url));
|
|
4
|
-
|
|
5
|
-
/** Which file is served under which name at the tool's root. */
|
|
5
|
+
/** Which file of the logo is served under which name at the tool's root. */
|
|
6
6
|
function logoFiles(logo) {
|
|
7
|
+
const file = (source, type) => ({ content: () => readFileSync(`${LOGOS}${source}`), type });
|
|
7
8
|
return {
|
|
8
|
-
'favicon.svg': `${
|
|
9
|
-
'apple-touch-icon.png': `${
|
|
10
|
-
'logo-
|
|
9
|
+
'favicon.svg': file(`${logo}.svg`, 'image/svg+xml'),
|
|
10
|
+
'apple-touch-icon.png': file(`${logo}-180.png`, 'image/png'),
|
|
11
|
+
'logo-192.png': file(`${logo}-192.png`, 'image/png'),
|
|
12
|
+
'logo-512.png': file(`${logo}-512.png`, 'image/png'),
|
|
13
|
+
'logo-maskable-192.png': file(`${logo}-maskable-192.png`, 'image/png'),
|
|
14
|
+
'logo-maskable-512.png': file(`${logo}-maskable-512.png`, 'image/png'),
|
|
11
15
|
};
|
|
12
16
|
}
|
|
13
17
|
/**
|
|
14
|
-
* Serves a tool's logo as `favicon.svg`, `apple-touch-icon.png`
|
|
15
|
-
*
|
|
18
|
+
* Serves a tool's logo as `favicon.svg`, `apple-touch-icon.png`, `logo-192.png`, `logo-512.png` and the
|
|
19
|
+
* maskable `logo-maskable-192.png` and `logo-maskable-512.png` at the root, in the dev server as in
|
|
20
|
+
* the build, and links the first two in the head of every page; the rest are the app icons.
|
|
16
21
|
*/
|
|
17
22
|
export function logoPlugin(logo) {
|
|
18
|
-
const files = logoFiles(logo);
|
|
19
23
|
return {
|
|
20
|
-
|
|
21
|
-
configureServer(server) {
|
|
22
|
-
server.middlewares.use((request, response, next) => {
|
|
23
|
-
const name = request.url?.split('?')[0]?.slice(1) ?? '';
|
|
24
|
-
const file = files[name];
|
|
25
|
-
if (!file)
|
|
26
|
-
return next();
|
|
27
|
-
response.setHeader('Content-Type', CONTENT_TYPES[name.split('.').pop() ?? ''] ?? 'application/octet-stream');
|
|
28
|
-
response.end(readFileSync(file));
|
|
29
|
-
});
|
|
30
|
-
},
|
|
31
|
-
generateBundle() {
|
|
32
|
-
if (this.environment?.config.build.ssr)
|
|
33
|
-
return;
|
|
34
|
-
for (const [name, file] of Object.entries(files)) {
|
|
35
|
-
this.emitFile({ type: 'asset', fileName: name, source: readFileSync(file) });
|
|
36
|
-
}
|
|
37
|
-
},
|
|
24
|
+
...rootFilesPlugin('emberbox:logo', logoFiles(logo)),
|
|
38
25
|
transformIndexHtml: () => [
|
|
39
26
|
{ tag: 'link', attrs: { rel: 'icon', type: 'image/svg+xml', href: '/favicon.svg' }, injectTo: 'head' },
|
|
40
27
|
{ tag: 'link', attrs: { rel: 'apple-touch-icon', href: '/apple-touch-icon.png' }, injectTo: 'head' },
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
/** What a tool calls itself once it is installed as an app. */
|
|
3
|
+
export interface AppOptions {
|
|
4
|
+
/** The full name, shown when the app is installed and in its window title. */
|
|
5
|
+
name: string;
|
|
6
|
+
/** A short name for the home screen, the full name by default. */
|
|
7
|
+
shortName?: string;
|
|
8
|
+
/** One sentence about what the app does. */
|
|
9
|
+
description?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Serves `manifest.webmanifest` at the root, in the dev server as in the build, and links it with
|
|
13
|
+
* the theme colour in the head of every page.
|
|
14
|
+
*
|
|
15
|
+
* @param app the app's names and description
|
|
16
|
+
* @returns the plugin
|
|
17
|
+
*/
|
|
18
|
+
export declare function manifestPlugin(app: AppOptions): Plugin;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { rootFilesPlugin } from './root-files.js';
|
|
2
|
+
/** The colour of the app's title bar: the signal red of the logos. */
|
|
3
|
+
const THEME_COLOR = '#d5271b';
|
|
4
|
+
/** The splash screen behind the starting app: the logo's red, so it looks the same in light and dark mode. */
|
|
5
|
+
const BACKGROUND_COLOR = THEME_COLOR;
|
|
6
|
+
const MANIFEST = 'manifest.webmanifest';
|
|
7
|
+
/**
|
|
8
|
+
* The web app manifest of a tool, which makes it installable on phones and desktops. It starts at
|
|
9
|
+
* the root, runs without browser chrome and uses the icons the logo plugin serves. There is no
|
|
10
|
+
* service worker: the app always loads from the server, and the new-build banner remains the way
|
|
11
|
+
* updates arrive.
|
|
12
|
+
*
|
|
13
|
+
* @param app the app's names and description
|
|
14
|
+
* @returns the manifest as JSON
|
|
15
|
+
*/
|
|
16
|
+
function manifest(app) {
|
|
17
|
+
return JSON.stringify({
|
|
18
|
+
id: '/',
|
|
19
|
+
name: app.name,
|
|
20
|
+
short_name: app.shortName ?? app.name,
|
|
21
|
+
description: app.description,
|
|
22
|
+
lang: 'de',
|
|
23
|
+
start_url: '/',
|
|
24
|
+
scope: '/',
|
|
25
|
+
display: 'standalone',
|
|
26
|
+
theme_color: THEME_COLOR,
|
|
27
|
+
background_color: BACKGROUND_COLOR,
|
|
28
|
+
icons: [
|
|
29
|
+
{ src: '/logo-192.png', sizes: '192x192', type: 'image/png', purpose: 'any' },
|
|
30
|
+
{ src: '/logo-512.png', sizes: '512x512', type: 'image/png', purpose: 'any' },
|
|
31
|
+
{ src: '/logo-maskable-192.png', sizes: '192x192', type: 'image/png', purpose: 'maskable' },
|
|
32
|
+
{ src: '/logo-maskable-512.png', sizes: '512x512', type: 'image/png', purpose: 'maskable' },
|
|
33
|
+
{ src: '/favicon.svg', sizes: 'any', type: 'image/svg+xml', purpose: 'any' },
|
|
34
|
+
],
|
|
35
|
+
}, null, 2);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Serves `manifest.webmanifest` at the root, in the dev server as in the build, and links it with
|
|
39
|
+
* the theme colour in the head of every page.
|
|
40
|
+
*
|
|
41
|
+
* @param app the app's names and description
|
|
42
|
+
* @returns the plugin
|
|
43
|
+
*/
|
|
44
|
+
export function manifestPlugin(app) {
|
|
45
|
+
const source = manifest(app);
|
|
46
|
+
return {
|
|
47
|
+
...rootFilesPlugin('emberbox:manifest', { [MANIFEST]: { content: () => source, type: 'application/manifest+json' } }),
|
|
48
|
+
transformIndexHtml: () => [
|
|
49
|
+
{ tag: 'link', attrs: { rel: 'manifest', href: `/${MANIFEST}` }, injectTo: 'head' },
|
|
50
|
+
{ tag: 'meta', attrs: { name: 'theme-color', content: THEME_COLOR }, injectTo: 'head' },
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
/** A file served at the tool's root: its content and its media type. */
|
|
3
|
+
export interface RootFile {
|
|
4
|
+
content: () => string | Uint8Array;
|
|
5
|
+
type: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A plugin that serves fixed files at the root of a tool, in the dev server as in the client build.
|
|
9
|
+
*
|
|
10
|
+
* @param name the plugin's name
|
|
11
|
+
* @param files the files by their name at the root
|
|
12
|
+
* @returns the plugin, to be extended with further hooks
|
|
13
|
+
*/
|
|
14
|
+
export declare function rootFilesPlugin(name: string, files: Record<string, RootFile>): Plugin;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A plugin that serves fixed files at the root of a tool, in the dev server as in the client build.
|
|
3
|
+
*
|
|
4
|
+
* @param name the plugin's name
|
|
5
|
+
* @param files the files by their name at the root
|
|
6
|
+
* @returns the plugin, to be extended with further hooks
|
|
7
|
+
*/
|
|
8
|
+
export function rootFilesPlugin(name, files) {
|
|
9
|
+
return {
|
|
10
|
+
name,
|
|
11
|
+
configureServer(server) {
|
|
12
|
+
server.middlewares.use((request, response, next) => {
|
|
13
|
+
const file = files[request.url?.split('?')[0]?.slice(1) ?? ''];
|
|
14
|
+
if (!file)
|
|
15
|
+
return next();
|
|
16
|
+
response.setHeader('Content-Type', file.type);
|
|
17
|
+
response.end(file.content());
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
generateBundle() {
|
|
21
|
+
if (this.environment?.config.build.ssr)
|
|
22
|
+
return;
|
|
23
|
+
for (const [fileName, file] of Object.entries(files)) {
|
|
24
|
+
this.emitFile({ type: 'asset', fileName, source: file.content() });
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { NuxtUIOptions } from '@nuxt/ui/unplugin';
|
|
2
2
|
import type { PluginOption } from 'vite';
|
|
3
3
|
import { type Logo } from './vite/logo.js';
|
|
4
|
+
import { type AppOptions } from './vite/manifest.js';
|
|
4
5
|
import { type PrerenderOptions } from './vite/prerender.js';
|
|
5
6
|
export { PAGES_DIR, type PrerenderOptions } from './vite/prerender.js';
|
|
6
7
|
export type { Logo } from './vite/logo.js';
|
|
8
|
+
export type { AppOptions } from './vite/manifest.js';
|
|
7
9
|
/** Settings a tool passes to `emberbox()`. */
|
|
8
10
|
export interface EmberboxOptions {
|
|
9
11
|
/** `false` for tools without vue-router; links are then rendered as plain anchors. */
|
|
@@ -16,6 +18,8 @@ export interface EmberboxOptions {
|
|
|
16
18
|
logo?: Logo;
|
|
17
19
|
/** Which public pages are prerendered at build time; needs `url`. */
|
|
18
20
|
prerender?: PrerenderOptions;
|
|
21
|
+
/** Makes the tool installable as an app under this name; needs `logo` for the app icons. */
|
|
22
|
+
app?: AppOptions;
|
|
19
23
|
}
|
|
20
24
|
/**
|
|
21
25
|
* The icons of the `@emberbox/ui` components. The scan does not walk `node_modules`, so they are
|
package/dist/vite.js
CHANGED
|
@@ -2,6 +2,7 @@ import ui from '@nuxt/ui/vite';
|
|
|
2
2
|
import { defu } from 'defu';
|
|
3
3
|
import { execSync } from 'node:child_process';
|
|
4
4
|
import { logoPlugin } from './vite/logo.js';
|
|
5
|
+
import { manifestPlugin } from './vite/manifest.js';
|
|
5
6
|
import { prerenderPlugin } from './vite/prerender.js';
|
|
6
7
|
export { PAGES_DIR } from './vite/prerender.js';
|
|
7
8
|
const COLORS = ['primary', 'signal', 'success', 'info', 'warning', 'error'];
|
|
@@ -87,6 +88,9 @@ export function emberbox(options = {}) {
|
|
|
87
88
|
if (options.prerender && !url) {
|
|
88
89
|
throw new Error('emberbox(): prerendering needs a url.');
|
|
89
90
|
}
|
|
91
|
+
if (options.app && !options.logo) {
|
|
92
|
+
throw new Error('emberbox(): an installable app needs a logo.');
|
|
93
|
+
}
|
|
90
94
|
return [
|
|
91
95
|
ui({
|
|
92
96
|
router: options.router ?? true,
|
|
@@ -108,7 +112,7 @@ export function emberbox(options = {}) {
|
|
|
108
112
|
},
|
|
109
113
|
optimizeDeps: { exclude: ['@emberbox/ui', '@iconify/vue'] },
|
|
110
114
|
resolve: { dedupe: ['vue', 'vue-router', '@nuxt/ui'] },
|
|
111
|
-
ssr: { noExternal: ['@emberbox/ui', '@nuxt/ui'] },
|
|
115
|
+
ssr: { noExternal: ['@emberbox/ui', '@nuxt/ui', 'vue-router'] },
|
|
112
116
|
}),
|
|
113
117
|
transformIndexHtml: () => [
|
|
114
118
|
{ tag: 'script', children: COLOR_MODE_SCRIPT, injectTo: 'head' },
|
|
@@ -120,6 +124,7 @@ export function emberbox(options = {}) {
|
|
|
120
124
|
},
|
|
121
125
|
},
|
|
122
126
|
options.logo ? logoPlugin(options.logo) : false,
|
|
127
|
+
options.app && options.logo ? manifestPlugin(options.app) : false,
|
|
123
128
|
options.prerender && url ? prerenderPlugin(options.prerender, url) : false,
|
|
124
129
|
];
|
|
125
130
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emberbox/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
13
|
"src",
|
|
14
|
+
"!src/**/*.test.ts",
|
|
14
15
|
"dist",
|
|
15
16
|
"logos"
|
|
16
17
|
],
|
|
@@ -28,6 +29,7 @@
|
|
|
28
29
|
}
|
|
29
30
|
},
|
|
30
31
|
"scripts": {
|
|
32
|
+
"test": "vitest run",
|
|
31
33
|
"build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.vite.json && node scripts/build-types.mjs",
|
|
32
34
|
"typecheck": "vue-tsc -b",
|
|
33
35
|
"icons": "node scripts/check-icons.mjs",
|
|
@@ -53,12 +55,15 @@
|
|
|
53
55
|
"vue": "^3.5.0"
|
|
54
56
|
},
|
|
55
57
|
"devDependencies": {
|
|
56
|
-
"@emberbox/lint": "^0.
|
|
58
|
+
"@emberbox/lint": "^0.2.0",
|
|
57
59
|
"@types/node": "^24.0.0",
|
|
60
|
+
"@vitejs/plugin-vue": "^6.0.11",
|
|
58
61
|
"@vue/tsconfig": "^0.9.1",
|
|
59
62
|
"eslint": "^10.15.0",
|
|
63
|
+
"happy-dom": "^21.0.4",
|
|
60
64
|
"typescript": "~6.0.3",
|
|
61
65
|
"vite": "^8.3.8",
|
|
66
|
+
"vitest": "^5.1.1",
|
|
62
67
|
"vue": "^3.5.46",
|
|
63
68
|
"vue-tsc": "^3.3.14"
|
|
64
69
|
},
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import {h, type VNode} from 'vue'
|
|
3
|
+
import type {SvgElement} from '../symbols/tactical'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A tactical symbol drawn into the page as SVG nodes, so the theme's signal red applies to it.
|
|
7
|
+
* The tree comes from `unitSymbolTree` or `markSymbolTree`.
|
|
8
|
+
*/
|
|
9
|
+
const props = defineProps<{
|
|
10
|
+
/** The symbol to draw. */
|
|
11
|
+
symbol: SvgElement
|
|
12
|
+
/** Width in pixels; the height follows the symbol's aspect ratio. */
|
|
13
|
+
width?: number
|
|
14
|
+
}>()
|
|
15
|
+
|
|
16
|
+
/** Builds the Vue nodes of one element and everything below it. */
|
|
17
|
+
function draw(node: SvgElement): VNode {
|
|
18
|
+
return h(node.tag, node.attributes, node.text ?? node.children?.map(draw))
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The symbol as Vue nodes. */
|
|
22
|
+
function Drawing(): VNode {
|
|
23
|
+
return draw(props.symbol)
|
|
24
|
+
}
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<template>
|
|
28
|
+
<span class="tactical-symbol" :style="{width: `${width ?? 48}px`}"><Drawing/></span>
|
|
29
|
+
</template>
|
|
30
|
+
|
|
31
|
+
<style scoped>
|
|
32
|
+
.tactical-symbol {
|
|
33
|
+
display: inline-block;
|
|
34
|
+
line-height: 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.tactical-symbol :deep(svg) {
|
|
38
|
+
width: 100%;
|
|
39
|
+
height: auto;
|
|
40
|
+
}
|
|
41
|
+
</style>
|
package/src/index.ts
CHANGED
|
@@ -26,6 +26,12 @@ export {default as ComboboxField} from './components/ComboboxField.vue'
|
|
|
26
26
|
export {default as YesNoField} from './components/YesNoField.vue'
|
|
27
27
|
export {default as DateTimeField} from './components/DateTimeField.vue'
|
|
28
28
|
export {default as CollapsibleSection} from './components/CollapsibleSection.vue'
|
|
29
|
+
export {default as TacticalSymbol} from './components/TacticalSymbol.vue'
|
|
30
|
+
export {
|
|
31
|
+
INCIDENT_MARK_KINDS, MARK_KINDS, SYMBOL_HEIGHT, SYMBOL_WIDTH, WATER_SUPPLY_MARK_KINDS, escapeSvg, markSymbol,
|
|
32
|
+
markSymbolTree, unitSymbol, unitSymbolTree,
|
|
33
|
+
type MarkKind, type Organisation, type SvgElement, type SymbolShape, type SymbolSpec, type UnitSize,
|
|
34
|
+
} from './symbols/tactical'
|
|
29
35
|
|
|
30
36
|
/**
|
|
31
37
|
* Vue plugin that installs Nuxt UI in the Emberbox style. Icons come only from the bundled set; a
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tactical symbols after DIN 14034-6 and the recommendations of the BBK for DV 102. The drawings
|
|
3
|
+
* follow the system of the recommendations (basic form, size mark, writing) without copying their
|
|
4
|
+
* artwork.
|
|
5
|
+
*
|
|
6
|
+
* A symbol is built as a tree of SVG elements: `TacticalSymbol` renders the tree as Vue nodes in
|
|
7
|
+
* the page, and `renderSvg` writes it as an escaped string for map icons. Every symbol is drawn on
|
|
8
|
+
* the same 120 × 80 canvas: the size mark above, the basic form in the middle, wheels or keel
|
|
9
|
+
* below. The fire service draws red with white writing; medical services draw red on white. Red
|
|
10
|
+
* comes from the theme's signal palette, so a symbol has to be part of the page (not loaded as an
|
|
11
|
+
* image) for it to apply.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** The organisation a unit belongs to, which sets its colours. */
|
|
15
|
+
export type Organisation = 'fire' | 'medical'
|
|
16
|
+
|
|
17
|
+
/** The basic form of a unit's symbol. */
|
|
18
|
+
export type SymbolShape = 'vehicle' | 'container' | 'trailer' | 'boat' | 'unit'
|
|
19
|
+
|
|
20
|
+
/** The size of a unit, shown by dots or a bar above its symbol. */
|
|
21
|
+
export type UnitSize = 'squad' | 'section' | 'group' | 'platoon'
|
|
22
|
+
|
|
23
|
+
/** Marks of places and events of an incident. */
|
|
24
|
+
export const INCIDENT_MARK_KINDS = ['incident', 'fire', 'hazard', 'staging', 'command-post', 'water', 'casualty-collection'] as const
|
|
25
|
+
|
|
26
|
+
/** Marks of the water supply along a relay line. */
|
|
27
|
+
export const WATER_SUPPLY_MARK_KINDS = ['hydrant-underground', 'hydrant-pillar', 'open-water', 'water-tank', 'dividing-breeching'] as const
|
|
28
|
+
|
|
29
|
+
/** Every kind of mark that is not a unit. */
|
|
30
|
+
export const MARK_KINDS = [...INCIDENT_MARK_KINDS, ...WATER_SUPPLY_MARK_KINDS] as const
|
|
31
|
+
|
|
32
|
+
/** A kind of mark. */
|
|
33
|
+
export type MarkKind = typeof MARK_KINDS[number]
|
|
34
|
+
|
|
35
|
+
/** What a unit's symbol is drawn from. */
|
|
36
|
+
export interface SymbolSpec {
|
|
37
|
+
shape: SymbolShape
|
|
38
|
+
organisation: Organisation
|
|
39
|
+
text: string
|
|
40
|
+
size?: UnitSize
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** One SVG element of a symbol, with its attributes and either child elements or text. */
|
|
44
|
+
export interface SvgElement {
|
|
45
|
+
tag: string
|
|
46
|
+
attributes: Record<string, string | number>
|
|
47
|
+
children?: SvgElement[]
|
|
48
|
+
text?: string
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The width of every symbol's canvas. */
|
|
52
|
+
export const SYMBOL_WIDTH = 120
|
|
53
|
+
/** The height of every symbol's canvas. */
|
|
54
|
+
export const SYMBOL_HEIGHT = 80
|
|
55
|
+
|
|
56
|
+
const RED = 'var(--color-signal-500)'
|
|
57
|
+
const WHITE = 'white'
|
|
58
|
+
const STROKE = 3
|
|
59
|
+
const MAX_TEXT_WIDTH = 86
|
|
60
|
+
|
|
61
|
+
interface Colours {
|
|
62
|
+
fill: string
|
|
63
|
+
line: string
|
|
64
|
+
text: string
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
type Attributes = SvgElement['attributes']
|
|
68
|
+
|
|
69
|
+
/** An SVG element without children. */
|
|
70
|
+
function element(tag: string, attributes: Attributes): SvgElement {
|
|
71
|
+
return {tag, attributes}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The attributes of an outlined form. */
|
|
75
|
+
function outlined(fill: string, line: string): Attributes {
|
|
76
|
+
return {fill, stroke: line, 'stroke-width': STROKE}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The attributes of a plain line. */
|
|
80
|
+
function stroked(line: string): Attributes {
|
|
81
|
+
return {fill: 'none', stroke: line, 'stroke-width': STROKE}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The colours of an organisation. */
|
|
85
|
+
function colours(organisation: Organisation): Colours {
|
|
86
|
+
return organisation === 'medical'
|
|
87
|
+
? {fill: WHITE, line: RED, text: RED}
|
|
88
|
+
: {fill: RED, line: RED, text: WHITE}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Escapes text for use inside SVG or HTML markup. */
|
|
92
|
+
export function escapeSvg(text: string): string {
|
|
93
|
+
return text.replace(/[&<>"']/g, character => `&#${character.charCodeAt(0)};`)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Writes a symbol tree as SVG markup, escaping every attribute value and text. Tag and attribute
|
|
98
|
+
* names are written as they are, so the tree must be built by code, as the trees of this module are.
|
|
99
|
+
*/
|
|
100
|
+
export function renderSvg(node: SvgElement): string {
|
|
101
|
+
const attributes = Object.entries(node.attributes)
|
|
102
|
+
.map(([name, value]) => ` ${name}="${escapeSvg(String(value))}"`)
|
|
103
|
+
.join('')
|
|
104
|
+
const content = node.text !== undefined
|
|
105
|
+
? escapeSvg(node.text)
|
|
106
|
+
: (node.children ?? []).map(renderSvg).join('')
|
|
107
|
+
return content ? `<${node.tag}${attributes}>${content}</${node.tag}>` : `<${node.tag}${attributes}/>`
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The writing inside a symbol, squeezed to fit when it is long. */
|
|
111
|
+
function label(text: string, x: number, y: number, colour: string): SvgElement {
|
|
112
|
+
const size = text.length > 8 ? 17 : 22
|
|
113
|
+
const squeeze: Attributes = text.length * size * 0.5 > MAX_TEXT_WIDTH
|
|
114
|
+
? {textLength: MAX_TEXT_WIDTH, lengthAdjust: 'spacingAndGlyphs'}
|
|
115
|
+
: {}
|
|
116
|
+
return {
|
|
117
|
+
tag: 'text',
|
|
118
|
+
attributes: {
|
|
119
|
+
x, y, fill: colour, 'font-size': size, 'font-weight': 700,
|
|
120
|
+
'font-family': 'Barlow Condensed, Barlow, sans-serif', 'text-anchor': 'middle',
|
|
121
|
+
'dominant-baseline': 'central', ...squeeze,
|
|
122
|
+
},
|
|
123
|
+
text,
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The dots or bar above a unit that tell its size. */
|
|
128
|
+
function sizeMark(size: UnitSize | undefined, colour: string): SvgElement[] {
|
|
129
|
+
if (!size) return []
|
|
130
|
+
if (size === 'platoon') return [element('line', {x1: 60, y1: 1, x2: 60, y2: 11, ...stroked(colour)})]
|
|
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}))
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** The basic form of a unit's symbol, with the writing inside. */
|
|
137
|
+
function body(shape: SymbolShape, colour: Colours, text: string): SvgElement[] {
|
|
138
|
+
const outline = outlined(colour.fill, colour.line)
|
|
139
|
+
const wheel = (x: number) => element('circle', {cx: x, cy: 70, r: 6, ...outlined(WHITE, colour.line)})
|
|
140
|
+
switch (shape) {
|
|
141
|
+
case 'vehicle':
|
|
142
|
+
return [element('rect', {x: 10, y: 16, width: 100, height: 44, ...outline}), wheel(34), wheel(86), label(text, 60, 38, colour.text)]
|
|
143
|
+
case 'container':
|
|
144
|
+
return [
|
|
145
|
+
element('rect', {x: 14, y: 16, width: 92, height: 44, ...outline}),
|
|
146
|
+
element('path', {d: 'M8 66 H112 M14 60 L8 66 M106 60 L112 66', ...stroked(colour.line)}),
|
|
147
|
+
label(text, 60, 38, colour.text),
|
|
148
|
+
]
|
|
149
|
+
case 'trailer':
|
|
150
|
+
return [
|
|
151
|
+
element('rect', {x: 24, y: 16, width: 86, height: 44, ...outline}),
|
|
152
|
+
element('path', {d: 'M24 50 H6', ...stroked(colour.line)}),
|
|
153
|
+
wheel(67),
|
|
154
|
+
label(text, 67, 38, colour.text),
|
|
155
|
+
]
|
|
156
|
+
case 'boat':
|
|
157
|
+
return [element('path', {d: 'M10 16 H110 L100 56 Q60 72 20 56 Z', ...outline}), label(text, 60, 36, colour.text)]
|
|
158
|
+
case 'unit':
|
|
159
|
+
return [element('rect', {x: 10, y: 16, width: 100, height: 52, ...outline}), label(text, 60, 42, colour.text)]
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** The symbol of a unit: a vehicle, container, trailer, boat or squad. */
|
|
164
|
+
export function unitSymbolTree(spec: SymbolSpec): SvgElement {
|
|
165
|
+
const colour = colours(spec.organisation)
|
|
166
|
+
return canvas([...sizeMark(spec.size, colour.line), ...body(spec.shape, colour, spec.text)])
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const OUTLINE = outlined(WHITE, RED)
|
|
170
|
+
const TRIANGLE = element('path', {d: 'M60 6 L108 74 H12 Z', ...OUTLINE})
|
|
171
|
+
const RING = element('circle', {cx: 60, cy: 40, r: 30, ...OUTLINE})
|
|
172
|
+
|
|
173
|
+
/** A circle with writing, the form most water supply marks share. */
|
|
174
|
+
function waterPoint(text: string): SvgElement[] {
|
|
175
|
+
return [RING, label(text, 60, 40, RED)]
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** The drawing of every kind of mark. */
|
|
179
|
+
const MARK_DRAWINGS: Record<MarkKind, () => SvgElement[]> = {
|
|
180
|
+
'incident': () => [TRIANGLE],
|
|
181
|
+
'fire': () => [TRIANGLE, element('path', {d: 'M60 30 C50 44 46 52 52 62 C54 54 58 52 60 48 C62 54 66 56 68 62 C74 52 70 42 60 30 Z', fill: RED})],
|
|
182
|
+
'hazard': () => [TRIANGLE, label('!', 60, 52, RED)],
|
|
183
|
+
'staging': () => [element('rect', {x: 10, y: 14, width: 100, height: 52, rx: 26, ...OUTLINE}), label('BR', 60, 40, RED)],
|
|
184
|
+
'command-post': () => [element('path', {d: 'M30 70 V8 M30 10 H96 L84 24 L96 38 H30', ...OUTLINE}), label('EL', 58, 24, RED)],
|
|
185
|
+
'water': () => waterPoint('W'),
|
|
186
|
+
'casualty-collection': () => [RING, element('path', {d: 'M60 22 V58 M42 40 H78', fill: 'none', stroke: RED, 'stroke-width': 8})],
|
|
187
|
+
'hydrant-underground': () => waterPoint('UH'),
|
|
188
|
+
'hydrant-pillar': () => waterPoint('ÜH'),
|
|
189
|
+
'open-water': () => [RING, element('path', {d: 'M38 36 Q49 28 60 36 T82 36 M38 48 Q49 40 60 48 T82 48', ...stroked(RED)})],
|
|
190
|
+
'water-tank': () => [element('path', {d: 'M24 22 V62 H96 V22', ...OUTLINE}), label('LWB', 60, 44, RED)],
|
|
191
|
+
'dividing-breeching': () => [
|
|
192
|
+
element('path', {d: 'M60 14 V40 M60 40 L32 68 M60 40 V68 M60 40 L88 68', ...stroked(RED)}),
|
|
193
|
+
element('circle', {cx: 60, cy: 40, r: 7, fill: RED}),
|
|
194
|
+
],
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** The symbol of a mark: a place or event of an incident, or a point of the water supply. */
|
|
198
|
+
export function markSymbolTree(kind: MarkKind): SvgElement {
|
|
199
|
+
return canvas(MARK_DRAWINGS[kind]())
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** A unit's symbol as SVG markup, for map icons. */
|
|
203
|
+
export function unitSymbol(spec: SymbolSpec): string {
|
|
204
|
+
return renderSvg(unitSymbolTree(spec))
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** A mark's symbol as SVG markup, for map icons. */
|
|
208
|
+
export function markSymbol(kind: MarkKind): string {
|
|
209
|
+
return renderSvg(markSymbolTree(kind))
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** The SVG element of the common canvas around a symbol's content. */
|
|
213
|
+
function canvas(children: SvgElement[]): SvgElement {
|
|
214
|
+
return {
|
|
215
|
+
tag: 'svg',
|
|
216
|
+
attributes: {
|
|
217
|
+
xmlns: 'http://www.w3.org/2000/svg', viewBox: `0 0 ${SYMBOL_WIDTH} ${SYMBOL_HEIGHT}`,
|
|
218
|
+
width: SYMBOL_WIDTH, height: SYMBOL_HEIGHT,
|
|
219
|
+
},
|
|
220
|
+
children,
|
|
221
|
+
}
|
|
222
|
+
}
|
package/src/vite/logo.ts
CHANGED
|
@@ -1,46 +1,34 @@
|
|
|
1
1
|
import {readFileSync} from 'node:fs'
|
|
2
2
|
import {fileURLToPath} from 'node:url'
|
|
3
3
|
import type {Plugin} from 'vite'
|
|
4
|
+
import {type RootFile, rootFilesPlugin} from './root-files.js'
|
|
4
5
|
|
|
5
6
|
/** The tools for which `@emberbox/ui` ships a logo. */
|
|
6
7
|
export type Logo = 'emberbox' | 'alarmzettel' | 'statussim' | 'calltaker' | 'planspiel'
|
|
7
8
|
|
|
8
9
|
const LOGOS = fileURLToPath(new URL('../../logos/', import.meta.url))
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function logoFiles(logo: Logo): Record<string, string> {
|
|
11
|
+
/** Which file of the logo is served under which name at the tool's root. */
|
|
12
|
+
function logoFiles(logo: Logo): Record<string, RootFile> {
|
|
13
|
+
const file = (source: string, type: string): RootFile => ({content: () => readFileSync(`${LOGOS}${source}`), type})
|
|
14
14
|
return {
|
|
15
|
-
'favicon.svg': `${
|
|
16
|
-
'apple-touch-icon.png': `${
|
|
17
|
-
'logo-
|
|
15
|
+
'favicon.svg': file(`${logo}.svg`, 'image/svg+xml'),
|
|
16
|
+
'apple-touch-icon.png': file(`${logo}-180.png`, 'image/png'),
|
|
17
|
+
'logo-192.png': file(`${logo}-192.png`, 'image/png'),
|
|
18
|
+
'logo-512.png': file(`${logo}-512.png`, 'image/png'),
|
|
19
|
+
'logo-maskable-192.png': file(`${logo}-maskable-192.png`, 'image/png'),
|
|
20
|
+
'logo-maskable-512.png': file(`${logo}-maskable-512.png`, 'image/png'),
|
|
18
21
|
}
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
/**
|
|
22
|
-
* Serves a tool's logo as `favicon.svg`, `apple-touch-icon.png`
|
|
23
|
-
*
|
|
25
|
+
* Serves a tool's logo as `favicon.svg`, `apple-touch-icon.png`, `logo-192.png`, `logo-512.png` and the
|
|
26
|
+
* maskable `logo-maskable-192.png` and `logo-maskable-512.png` at the root, in the dev server as in
|
|
27
|
+
* the build, and links the first two in the head of every page; the rest are the app icons.
|
|
24
28
|
*/
|
|
25
29
|
export function logoPlugin(logo: Logo): Plugin {
|
|
26
|
-
const files = logoFiles(logo)
|
|
27
30
|
return {
|
|
28
|
-
|
|
29
|
-
configureServer(server) {
|
|
30
|
-
server.middlewares.use((request, response, next) => {
|
|
31
|
-
const name = request.url?.split('?')[0]?.slice(1) ?? ''
|
|
32
|
-
const file = files[name]
|
|
33
|
-
if (!file) return next()
|
|
34
|
-
response.setHeader('Content-Type', CONTENT_TYPES[name.split('.').pop() ?? ''] ?? 'application/octet-stream')
|
|
35
|
-
response.end(readFileSync(file))
|
|
36
|
-
})
|
|
37
|
-
},
|
|
38
|
-
generateBundle() {
|
|
39
|
-
if (this.environment?.config.build.ssr) return
|
|
40
|
-
for (const [name, file] of Object.entries(files)) {
|
|
41
|
-
this.emitFile({type: 'asset', fileName: name, source: readFileSync(file)})
|
|
42
|
-
}
|
|
43
|
-
},
|
|
31
|
+
...rootFilesPlugin('emberbox:logo', logoFiles(logo)),
|
|
44
32
|
transformIndexHtml: () => [
|
|
45
33
|
{tag: 'link', attrs: {rel: 'icon', type: 'image/svg+xml', href: '/favicon.svg'}, injectTo: 'head'},
|
|
46
34
|
{tag: 'link', attrs: {rel: 'apple-touch-icon', href: '/apple-touch-icon.png'}, injectTo: 'head'},
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type {Plugin} from 'vite'
|
|
2
|
+
import {rootFilesPlugin} from './root-files.js'
|
|
3
|
+
|
|
4
|
+
/** What a tool calls itself once it is installed as an app. */
|
|
5
|
+
export interface AppOptions {
|
|
6
|
+
/** The full name, shown when the app is installed and in its window title. */
|
|
7
|
+
name: string
|
|
8
|
+
/** A short name for the home screen, the full name by default. */
|
|
9
|
+
shortName?: string
|
|
10
|
+
/** One sentence about what the app does. */
|
|
11
|
+
description?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** The colour of the app's title bar: the signal red of the logos. */
|
|
15
|
+
const THEME_COLOR = '#d5271b'
|
|
16
|
+
|
|
17
|
+
/** The splash screen behind the starting app: the logo's red, so it looks the same in light and dark mode. */
|
|
18
|
+
const BACKGROUND_COLOR = THEME_COLOR
|
|
19
|
+
|
|
20
|
+
const MANIFEST = 'manifest.webmanifest'
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The web app manifest of a tool, which makes it installable on phones and desktops. It starts at
|
|
24
|
+
* the root, runs without browser chrome and uses the icons the logo plugin serves. There is no
|
|
25
|
+
* service worker: the app always loads from the server, and the new-build banner remains the way
|
|
26
|
+
* updates arrive.
|
|
27
|
+
*
|
|
28
|
+
* @param app the app's names and description
|
|
29
|
+
* @returns the manifest as JSON
|
|
30
|
+
*/
|
|
31
|
+
function manifest(app: AppOptions): string {
|
|
32
|
+
return JSON.stringify({
|
|
33
|
+
id: '/',
|
|
34
|
+
name: app.name,
|
|
35
|
+
short_name: app.shortName ?? app.name,
|
|
36
|
+
description: app.description,
|
|
37
|
+
lang: 'de',
|
|
38
|
+
start_url: '/',
|
|
39
|
+
scope: '/',
|
|
40
|
+
display: 'standalone',
|
|
41
|
+
theme_color: THEME_COLOR,
|
|
42
|
+
background_color: BACKGROUND_COLOR,
|
|
43
|
+
icons: [
|
|
44
|
+
{src: '/logo-192.png', sizes: '192x192', type: 'image/png', purpose: 'any'},
|
|
45
|
+
{src: '/logo-512.png', sizes: '512x512', type: 'image/png', purpose: 'any'},
|
|
46
|
+
{src: '/logo-maskable-192.png', sizes: '192x192', type: 'image/png', purpose: 'maskable'},
|
|
47
|
+
{src: '/logo-maskable-512.png', sizes: '512x512', type: 'image/png', purpose: 'maskable'},
|
|
48
|
+
{src: '/favicon.svg', sizes: 'any', type: 'image/svg+xml', purpose: 'any'},
|
|
49
|
+
],
|
|
50
|
+
}, null, 2)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Serves `manifest.webmanifest` at the root, in the dev server as in the build, and links it with
|
|
55
|
+
* the theme colour in the head of every page.
|
|
56
|
+
*
|
|
57
|
+
* @param app the app's names and description
|
|
58
|
+
* @returns the plugin
|
|
59
|
+
*/
|
|
60
|
+
export function manifestPlugin(app: AppOptions): Plugin {
|
|
61
|
+
const source = manifest(app)
|
|
62
|
+
return {
|
|
63
|
+
...rootFilesPlugin('emberbox:manifest', {[MANIFEST]: {content: () => source, type: 'application/manifest+json'}}),
|
|
64
|
+
transformIndexHtml: () => [
|
|
65
|
+
{tag: 'link', attrs: {rel: 'manifest', href: `/${MANIFEST}`}, injectTo: 'head'},
|
|
66
|
+
{tag: 'meta', attrs: {name: 'theme-color', content: THEME_COLOR}, injectTo: 'head'},
|
|
67
|
+
],
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type {Plugin} from 'vite'
|
|
2
|
+
|
|
3
|
+
/** A file served at the tool's root: its content and its media type. */
|
|
4
|
+
export interface RootFile {
|
|
5
|
+
content: () => string | Uint8Array
|
|
6
|
+
type: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A plugin that serves fixed files at the root of a tool, in the dev server as in the client build.
|
|
11
|
+
*
|
|
12
|
+
* @param name the plugin's name
|
|
13
|
+
* @param files the files by their name at the root
|
|
14
|
+
* @returns the plugin, to be extended with further hooks
|
|
15
|
+
*/
|
|
16
|
+
export function rootFilesPlugin(name: string, files: Record<string, RootFile>): Plugin {
|
|
17
|
+
return {
|
|
18
|
+
name,
|
|
19
|
+
configureServer(server) {
|
|
20
|
+
server.middlewares.use((request, response, next) => {
|
|
21
|
+
const file = files[request.url?.split('?')[0]?.slice(1) ?? '']
|
|
22
|
+
if (!file) return next()
|
|
23
|
+
response.setHeader('Content-Type', file.type)
|
|
24
|
+
response.end(file.content())
|
|
25
|
+
})
|
|
26
|
+
},
|
|
27
|
+
generateBundle() {
|
|
28
|
+
if (this.environment?.config.build.ssr) return
|
|
29
|
+
for (const [fileName, file] of Object.entries(files)) {
|
|
30
|
+
this.emitFile({type: 'asset', fileName, source: file.content()})
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/vite.ts
CHANGED
|
@@ -4,10 +4,12 @@ import {defu} from 'defu'
|
|
|
4
4
|
import {execSync} from 'node:child_process'
|
|
5
5
|
import type {PluginOption} from 'vite'
|
|
6
6
|
import {type Logo, logoPlugin} from './vite/logo.js'
|
|
7
|
+
import {type AppOptions, manifestPlugin} from './vite/manifest.js'
|
|
7
8
|
import {prerenderPlugin, type PrerenderOptions} from './vite/prerender.js'
|
|
8
9
|
|
|
9
10
|
export {PAGES_DIR, type PrerenderOptions} from './vite/prerender.js'
|
|
10
11
|
export type {Logo} from './vite/logo.js'
|
|
12
|
+
export type {AppOptions} from './vite/manifest.js'
|
|
11
13
|
|
|
12
14
|
/** Settings a tool passes to `emberbox()`. */
|
|
13
15
|
export interface EmberboxOptions {
|
|
@@ -21,6 +23,8 @@ export interface EmberboxOptions {
|
|
|
21
23
|
logo?: Logo
|
|
22
24
|
/** Which public pages are prerendered at build time; needs `url`. */
|
|
23
25
|
prerender?: PrerenderOptions
|
|
26
|
+
/** Makes the tool installable as an app under this name; needs `logo` for the app icons. */
|
|
27
|
+
app?: AppOptions
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
const COLORS = ['primary', 'signal', 'success', 'info', 'warning', 'error']
|
|
@@ -111,6 +115,9 @@ export function emberbox(options: EmberboxOptions = {}): PluginOption[] {
|
|
|
111
115
|
if (options.prerender && !url) {
|
|
112
116
|
throw new Error('emberbox(): prerendering needs a url.')
|
|
113
117
|
}
|
|
118
|
+
if (options.app && !options.logo) {
|
|
119
|
+
throw new Error('emberbox(): an installable app needs a logo.')
|
|
120
|
+
}
|
|
114
121
|
return [
|
|
115
122
|
ui({
|
|
116
123
|
router: options.router ?? true,
|
|
@@ -132,7 +139,7 @@ export function emberbox(options: EmberboxOptions = {}): PluginOption[] {
|
|
|
132
139
|
},
|
|
133
140
|
optimizeDeps: {exclude: ['@emberbox/ui', '@iconify/vue']},
|
|
134
141
|
resolve: {dedupe: ['vue', 'vue-router', '@nuxt/ui']},
|
|
135
|
-
ssr: {noExternal: ['@emberbox/ui', '@nuxt/ui']},
|
|
142
|
+
ssr: {noExternal: ['@emberbox/ui', '@nuxt/ui', 'vue-router']},
|
|
136
143
|
}),
|
|
137
144
|
transformIndexHtml: () => [
|
|
138
145
|
{tag: 'script', children: COLOR_MODE_SCRIPT, injectTo: 'head'},
|
|
@@ -144,6 +151,7 @@ export function emberbox(options: EmberboxOptions = {}): PluginOption[] {
|
|
|
144
151
|
},
|
|
145
152
|
},
|
|
146
153
|
options.logo ? logoPlugin(options.logo) : false,
|
|
154
|
+
options.app && options.logo ? manifestPlugin(options.app) : false,
|
|
147
155
|
options.prerender && url ? prerenderPlugin(options.prerender, url) : false,
|
|
148
156
|
]
|
|
149
157
|
}
|