@emberbox/ui 0.4.1 → 0.5.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.
@@ -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` and `logo-512.png` at the root, in
6
- * the dev server as in the build, and links the first two in the head of every page.
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
- const CONTENT_TYPES = { svg: 'image/svg+xml', png: 'image/png' };
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': `${LOGOS}${logo}.svg`,
9
- 'apple-touch-icon.png': `${LOGOS}${logo}-180.png`,
10
- 'logo-512.png': `${LOGOS}${logo}-512.png`,
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` and `logo-512.png` at the root, in
15
- * the dev server as in the build, and links the first two in the head of every page.
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
- name: 'emberbox:logo',
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emberbox/ui",
3
- "version": "0.4.1",
3
+ "version": "0.5.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",
@@ -53,7 +53,7 @@
53
53
  "vue": "^3.5.0"
54
54
  },
55
55
  "devDependencies": {
56
- "@emberbox/lint": "^0.1.0",
56
+ "@emberbox/lint": "^0.2.0",
57
57
  "@types/node": "^24.0.0",
58
58
  "@vue/tsconfig": "^0.9.1",
59
59
  "eslint": "^10.15.0",
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
- const CONTENT_TYPES: Record<string, string> = {svg: 'image/svg+xml', png: 'image/png'}
11
-
12
- /** Which file is served under which name at the tool's root. */
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': `${LOGOS}${logo}.svg`,
16
- 'apple-touch-icon.png': `${LOGOS}${logo}-180.png`,
17
- 'logo-512.png': `${LOGOS}${logo}-512.png`,
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` and `logo-512.png` at the root, in
23
- * the dev server as in the build, and links the first two in the head of every page.
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
- name: 'emberbox:logo',
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
  }