@emberbox/ui 0.0.0-stage → 0.2.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.
Files changed (45) hide show
  1. package/LICENSE +44 -0
  2. package/README.md +17 -2
  3. package/dist/vite/logo.d.ts +8 -0
  4. package/dist/vite/logo.js +43 -0
  5. package/dist/vite/prerender.d.ts +17 -0
  6. package/dist/vite/prerender.js +57 -0
  7. package/dist/vite.d.ts +39 -0
  8. package/dist/vite.js +121 -0
  9. package/logos/alarmzettel-180.png +0 -0
  10. package/logos/alarmzettel-512.png +0 -0
  11. package/logos/alarmzettel.svg +1 -0
  12. package/logos/calltaker-180.png +0 -0
  13. package/logos/calltaker-512.png +0 -0
  14. package/logos/calltaker.svg +1 -0
  15. package/logos/emberbox-180.png +0 -0
  16. package/logos/emberbox-512.png +0 -0
  17. package/logos/emberbox.svg +1 -0
  18. package/logos/statussim-180.png +0 -0
  19. package/logos/statussim-512.png +0 -0
  20. package/logos/statussim.svg +1 -0
  21. package/package.json +62 -4
  22. package/src/build-info.ts +23 -0
  23. package/src/clipboard.ts +34 -0
  24. package/src/components/AppFooter.vue +66 -0
  25. package/src/components/AppHeader.vue +45 -0
  26. package/src/components/CodeDisplay.vue +78 -0
  27. package/src/components/ConfirmDialog.vue +25 -0
  28. package/src/components/EmberboxApp.vue +22 -0
  29. package/src/components/HelpMockup.vue +15 -0
  30. package/src/components/HelpPage.vue +16 -0
  31. package/src/components/HelpSection.vue +11 -0
  32. package/src/components/HelpTopic.vue +20 -0
  33. package/src/components/NewBuildBanner.vue +24 -0
  34. package/src/composables/useConfirm.ts +27 -0
  35. package/src/composables/useNewBuild.ts +45 -0
  36. package/src/composables/usePolling.ts +91 -0
  37. package/src/create-app.ts +11 -0
  38. package/src/index.ts +34 -0
  39. package/src/page.ts +81 -0
  40. package/src/prerender.ts +23 -0
  41. package/src/style.css +172 -0
  42. package/src/urls.ts +8 -0
  43. package/src/vite/logo.ts +49 -0
  44. package/src/vite/prerender.ts +72 -0
  45. package/src/vite.ts +145 -0
package/src/style.css ADDED
@@ -0,0 +1,172 @@
1
+ @import "tailwindcss";
2
+ @import "@nuxt/ui";
3
+ @import "@fontsource/barlow/400.css";
4
+ @import "@fontsource/barlow/500.css";
5
+ @import "@fontsource/barlow/600.css";
6
+ @import "@fontsource/barlow-condensed/600.css";
7
+ @import "@fontsource/barlow-condensed/700.css";
8
+ @import "@fontsource/ibm-plex-mono/400.css";
9
+ @import "@fontsource/ibm-plex-mono/500.css";
10
+
11
+ @source "./";
12
+
13
+ @theme {
14
+ --font-sans: "Barlow", ui-sans-serif, system-ui, sans-serif;
15
+ --font-condensed: "Barlow Condensed", "Barlow", ui-sans-serif, sans-serif;
16
+ --font-mono: "IBM Plex Mono", ui-monospace, monospace;
17
+
18
+ --color-signal-50: #fdf5f4;
19
+ --color-signal-100: #fbe4e1;
20
+ --color-signal-200: #f7c9c3;
21
+ --color-signal-300: #f0a097;
22
+ --color-signal-400: #e0331f;
23
+ --color-signal-500: #d5271b;
24
+ --color-signal-600: #c02116;
25
+ --color-signal-700: #a81e15;
26
+ --color-signal-800: #8a1a13;
27
+ --color-signal-900: #721914;
28
+ --color-signal-950: #2a1614;
29
+
30
+ --color-steel-50: #f4f6f8;
31
+ --color-steel-100: #eef1f4;
32
+ --color-steel-200: #dce1e7;
33
+ --color-steel-300: #c1c8d1;
34
+ --color-steel-400: #8a94a2;
35
+ --color-steel-500: #5c6775;
36
+ --color-steel-600: #444e5b;
37
+ --color-steel-700: #2a333e;
38
+ --color-steel-800: #212932;
39
+ --color-steel-900: #1a2027;
40
+ --color-steel-950: #12161c;
41
+
42
+ --color-ink: #10141a;
43
+ --color-sky: #4fa3e3;
44
+ }
45
+
46
+ :root {
47
+ --ui-radius: 4px;
48
+
49
+ --ui-color-neutral-50: var(--color-steel-50);
50
+ --ui-color-neutral-100: var(--color-steel-100);
51
+ --ui-color-neutral-200: var(--color-steel-200);
52
+ --ui-color-neutral-300: var(--color-steel-300);
53
+ --ui-color-neutral-400: var(--color-steel-400);
54
+ --ui-color-neutral-500: var(--color-steel-500);
55
+ --ui-color-neutral-600: var(--color-steel-600);
56
+ --ui-color-neutral-700: var(--color-steel-700);
57
+ --ui-color-neutral-800: var(--color-steel-800);
58
+ --ui-color-neutral-900: var(--color-steel-900);
59
+ --ui-color-neutral-950: var(--color-steel-950);
60
+
61
+ --ui-primary: var(--color-ink);
62
+ --ui-signal: var(--color-signal-500);
63
+ --ui-error: var(--color-signal-500);
64
+
65
+ --ui-bg: #ffffff;
66
+ --ui-bg-muted: var(--color-steel-50);
67
+ --ui-bg-elevated: var(--color-steel-100);
68
+ --ui-bg-accented: var(--color-steel-200);
69
+ --ui-bg-inverted: var(--color-ink);
70
+
71
+ --ui-text-dimmed: var(--color-steel-400);
72
+ --ui-text-muted: var(--color-steel-500);
73
+ --ui-text-toned: var(--color-steel-600);
74
+ --ui-text: var(--color-ink);
75
+ --ui-text-highlighted: var(--color-ink);
76
+ --ui-text-inverted: #ffffff;
77
+
78
+ --ui-border: var(--color-steel-200);
79
+ --ui-border-muted: var(--color-steel-100);
80
+ --ui-border-accented: var(--color-steel-300);
81
+ --ui-border-inverted: var(--color-ink);
82
+
83
+ --eb-page: var(--color-steel-50);
84
+ --eb-signal-text: var(--color-signal-700);
85
+ --eb-focus: var(--color-signal-500);
86
+ }
87
+
88
+ :root.dark {
89
+ --ui-primary: #edf0f3;
90
+ --ui-signal: var(--color-signal-400);
91
+ --ui-error: #ff6a58;
92
+
93
+ --ui-bg: var(--color-steel-900);
94
+ --ui-bg-muted: var(--color-steel-950);
95
+ --ui-bg-elevated: var(--color-steel-800);
96
+ --ui-bg-accented: var(--color-steel-700);
97
+ --ui-bg-inverted: #edf0f3;
98
+
99
+ --ui-text-dimmed: var(--color-steel-500);
100
+ --ui-text-muted: #8892a0;
101
+ --ui-text-toned: var(--color-steel-300);
102
+ --ui-text: #edf0f3;
103
+ --ui-text-highlighted: #ffffff;
104
+ --ui-text-inverted: var(--color-steel-950);
105
+
106
+ --ui-border: var(--color-steel-700);
107
+ --ui-border-muted: var(--color-steel-800);
108
+ --ui-border-accented: var(--color-steel-600);
109
+ --ui-border-inverted: #edf0f3;
110
+
111
+ --eb-page: var(--color-steel-950);
112
+ --eb-signal-text: #ff6a58;
113
+ --eb-focus: var(--color-sky);
114
+ }
115
+
116
+ html,
117
+ body {
118
+ background-color: var(--eb-page);
119
+ }
120
+
121
+ body {
122
+ min-width: 320px;
123
+ min-height: 100vh;
124
+ font-family: var(--font-sans);
125
+ font-size: 15px;
126
+ line-height: 1.5;
127
+ }
128
+
129
+ @layer base {
130
+ :where(button, a, input, select, textarea, [tabindex]):focus-visible {
131
+ outline: 2px solid var(--eb-focus);
132
+ outline-offset: 2px;
133
+ }
134
+ }
135
+
136
+ @utility eyebrow {
137
+ font-family: var(--font-condensed);
138
+ font-weight: 600;
139
+ font-size: 13px;
140
+ letter-spacing: 0.12em;
141
+ text-transform: uppercase;
142
+ color: var(--ui-text-muted);
143
+ }
144
+
145
+ @utility headline {
146
+ font-family: var(--font-condensed);
147
+ font-weight: 700;
148
+ letter-spacing: 0.01em;
149
+ line-height: 1.05;
150
+ }
151
+
152
+ @utility tabular {
153
+ font-family: var(--font-mono);
154
+ font-variant-numeric: tabular-nums;
155
+ }
156
+
157
+ @media (prefers-reduced-motion: reduce) {
158
+ *, *::before, *::after {
159
+ animation-duration: 0.01ms !important;
160
+ transition-duration: 0.01ms !important;
161
+ }
162
+ }
163
+
164
+ @utility field-label {
165
+ font-family: var(--font-condensed);
166
+ font-weight: 600;
167
+ font-size: 12px;
168
+ line-height: 1.2;
169
+ letter-spacing: 0.06em;
170
+ text-transform: uppercase;
171
+ color: var(--ui-text-muted);
172
+ }
package/src/urls.ts ADDED
@@ -0,0 +1,8 @@
1
+ /** The start page of all Emberbox tools. */
2
+ export const HUB_URL = 'https://emberbox.app'
3
+
4
+ /** The imprint shared by all tools. */
5
+ export const IMPRINT_URL = `${HUB_URL}/impressum`
6
+
7
+ /** The privacy policy shared by all tools. */
8
+ export const PRIVACY_URL = `${HUB_URL}/datenschutz`
@@ -0,0 +1,49 @@
1
+ import {readFileSync} from 'node:fs'
2
+ import {fileURLToPath} from 'node:url'
3
+ import type {Plugin} from 'vite'
4
+
5
+ /** The tools for which `@emberbox/ui` ships a logo. */
6
+ export type Logo = 'emberbox' | 'alarmzettel' | 'statussim' | 'calltaker'
7
+
8
+ const LOGOS = fileURLToPath(new URL('../../logos/', import.meta.url))
9
+
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> {
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`,
18
+ }
19
+ }
20
+
21
+ /**
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.
24
+ */
25
+ export function logoPlugin(logo: Logo): Plugin {
26
+ const files = logoFiles(logo)
27
+ 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
+ },
44
+ transformIndexHtml: () => [
45
+ {tag: 'link', attrs: {rel: 'icon', type: 'image/svg+xml', href: '/favicon.svg'}, injectTo: 'head'},
46
+ {tag: 'link', attrs: {rel: 'apple-touch-icon', href: '/apple-touch-icon.png'}, injectTo: 'head'},
47
+ ],
48
+ }
49
+ }
@@ -0,0 +1,72 @@
1
+ import {mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync} from 'node:fs'
2
+ import {basename, extname, join, resolve} from 'node:path'
3
+ import {pathToFileURL} from 'node:url'
4
+ import {build, type Plugin, type ResolvedConfig} from 'vite'
5
+
6
+ /** Which pages of a tool become finished HTML at build time. */
7
+ export interface PrerenderOptions {
8
+ /** Module that exports `render(path, template)`, such as `src/prerender.ts`. */
9
+ entry: string
10
+ /** The public paths, such as `['/', '/hilfe']`. */
11
+ paths: string[]
12
+ }
13
+
14
+ /** What a tool's entry module provides. */
15
+ interface PrerenderEntry {
16
+ render(path: string, template: string): Promise<string>
17
+ }
18
+
19
+ /** The directory below the build output that holds the prerendered pages. */
20
+ export const PAGES_DIR = 'pages'
21
+
22
+ function pageFile(outDir: string, path: string): string {
23
+ return join(outDir, PAGES_DIR, path.replace(/^\/+|\/+$/g, ''), 'index.html')
24
+ }
25
+
26
+ function sitemap(url: string, paths: string[]): string {
27
+ const entries = paths.map(path => ` <url><loc>${url}${path}</loc></url>`).join('\n')
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
+ }
30
+
31
+ /**
32
+ * Prerenders the public pages once the client build is written. It builds the entry as an SSR
33
+ * bundle, calls `render` for every path with the built `index.html` as template and writes the
34
+ * result to `pages/<path>/index.html`. `index.html` itself stays the empty shell for all other
35
+ * routes. `sitemap.xml` and `robots.txt` are written next to it.
36
+ */
37
+ export function prerenderPlugin(options: PrerenderOptions, url: string): Plugin {
38
+ let config: ResolvedConfig
39
+ return {
40
+ name: 'emberbox:prerender',
41
+ apply: 'build',
42
+ configResolved(resolved) {
43
+ config = resolved
44
+ },
45
+ async writeBundle() {
46
+ if (config.build.ssr) return
47
+ const outDir = resolve(config.root, config.build.outDir)
48
+ const ssrOutDir = resolve(config.root, 'node_modules', '.emberbox-prerender')
49
+ await build({
50
+ configFile: config.configFile,
51
+ root: config.root,
52
+ mode: config.mode,
53
+ logLevel: 'warn',
54
+ build: {ssr: options.entry, outDir: ssrOutDir, emptyOutDir: true, copyPublicDir: false},
55
+ })
56
+ const name = basename(options.entry, extname(options.entry))
57
+ const bundle = readdirSync(ssrOutDir).find(candidate => /^(.+)\.m?js$/.exec(candidate)?.[1] === name)
58
+ if (!bundle) throw new Error(`The SSR bundle of ${options.entry} is missing in ${ssrOutDir}.`)
59
+ const entry = await import(pathToFileURL(join(ssrOutDir, bundle)).href) as PrerenderEntry
60
+ const template = readFileSync(join(outDir, 'index.html'), 'utf8')
61
+ for (const path of options.paths) {
62
+ const target = pageFile(outDir, path)
63
+ mkdirSync(join(target, '..'), {recursive: true})
64
+ writeFileSync(target, await entry.render(path, template))
65
+ }
66
+ writeFileSync(join(outDir, 'sitemap.xml'), sitemap(url, options.paths))
67
+ writeFileSync(join(outDir, 'robots.txt'), `User-agent: *\nAllow: /\n\nSitemap: ${url}/sitemap.xml\n`)
68
+ rmSync(ssrOutDir, {recursive: true, force: true})
69
+ config.logger.info(`emberbox: prerendered ${options.paths.length} pages`)
70
+ },
71
+ }
72
+ }
package/src/vite.ts ADDED
@@ -0,0 +1,145 @@
1
+ import ui from '@nuxt/ui/vite'
2
+ import type {NuxtUIOptions} from '@nuxt/ui/unplugin'
3
+ import {defu} from 'defu'
4
+ import {execSync} from 'node:child_process'
5
+ import type {PluginOption} from 'vite'
6
+ import {type Logo, logoPlugin} from './vite/logo.js'
7
+ import {prerenderPlugin, type PrerenderOptions} from './vite/prerender.js'
8
+
9
+ export {PAGES_DIR, type PrerenderOptions} from './vite/prerender.js'
10
+ export type {Logo} from './vite/logo.js'
11
+
12
+ /** Settings a tool passes to `emberbox()`. */
13
+ export interface EmberboxOptions {
14
+ /** `false` for tools without vue-router; links are then rendered as plain anchors. */
15
+ router?: boolean
16
+ /** Additional Nuxt UI settings of the tool, applied on top of the Emberbox defaults. */
17
+ ui?: NuxtUIOptions['ui']
18
+ /** The public address, such as `https://calltaker.emberbox.app`; a trailing `/` is dropped. */
19
+ url?: string
20
+ /** Which Emberbox logo is served as favicon, touch icon and preview image. */
21
+ logo?: Logo
22
+ /** Which public pages are prerendered at build time; needs `url`. */
23
+ prerender?: PrerenderOptions
24
+ }
25
+
26
+ const COLORS = ['primary', 'signal', 'success', 'info', 'warning', 'error']
27
+
28
+ /**
29
+ * The defaults that make every Nuxt UI component appear in the Emberbox style. The colour names
30
+ * point to the palettes in `style.css`; `primary` is ink there, red is kept for signals and errors.
31
+ */
32
+ const DEFAULTS: NuxtUIOptions['ui'] = {
33
+ colors: {
34
+ primary: 'steel',
35
+ signal: 'signal',
36
+ success: 'green',
37
+ info: 'blue',
38
+ warning: 'amber',
39
+ error: 'signal',
40
+ neutral: 'slate',
41
+ },
42
+ formField: {
43
+ slots: {
44
+ label: 'field-label',
45
+ },
46
+ },
47
+ }
48
+
49
+ /**
50
+ * Where to look for used icons. Unlike the `@nuxt/icon` default this includes `.ts` and `.js`
51
+ * files, because tools list icons in menu and route tables.
52
+ */
53
+ const ICON_SCAN = {
54
+ globInclude: ['**/*.{vue,ts,tsx,js,jsx}'],
55
+ globExclude: ['node_modules', 'dist', 'build', 'coverage', 'test', 'tests', '.*', '**/*.d.ts'],
56
+ }
57
+
58
+ /**
59
+ * The icons of the `@emberbox/ui` components. The scan does not walk `node_modules`, so they are
60
+ * listed here; whoever gives a component an icon adds it here.
61
+ */
62
+ export const OWN_ICONS = [
63
+ 'i-lucide-check',
64
+ 'i-lucide-copy',
65
+ 'i-lucide-github',
66
+ 'i-lucide-layout-grid',
67
+ 'i-lucide-link',
68
+ 'i-lucide-qr-code',
69
+ 'i-lucide-rotate-cw',
70
+ 'i-lucide-x',
71
+ ]
72
+
73
+ /**
74
+ * Sets the class `dark` before the first paint, so the page does not flash light. Reads the same
75
+ * key as Nuxt UI's colour mode (`useDark` from VueUse) and follows the system without a choice.
76
+ */
77
+ export const COLOR_MODE_SCRIPT = `(function(){try{var w=localStorage.getItem('vueuse-color-scheme');var d=w==='dark'||((!w||w==='auto')&&matchMedia('(prefers-color-scheme: dark)').matches);document.documentElement.classList.toggle('dark',d)}catch(e){}})()`
78
+
79
+ /**
80
+ * The short commit being built. An image build without `.git` passes it in as the environment
81
+ * variable `COMMIT`; without either it is `dev`.
82
+ */
83
+ function commit(): string {
84
+ if (process.env.COMMIT) return process.env.COMMIT
85
+ try {
86
+ return execSync('git rev-parse --short HEAD', {encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore']}).trim()
87
+ } catch {
88
+ return 'dev'
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Commit and build time of this build. Determined once per process, so the client and SSR build of
94
+ * a tool carry the same build info.
95
+ */
96
+ const BUILD_INFO = {commit: commit(), builtAt: process.env.BUILD_TIME || new Date().toISOString()}
97
+
98
+ /**
99
+ * Sets up Nuxt UI in the Emberbox style and puts the colour mode script into every HTML page.
100
+ * Replaces `@tailwindcss/vite` in a tool, since Nuxt UI brings it along. Icons are bundled from the
101
+ * installed Iconify collections, so the browser fetches nothing from the Iconify API.
102
+ *
103
+ * Commit and build time (`BUILD_TIME` from the environment, or now) are available as `buildInfo`
104
+ * from `@emberbox/ui`, and every build gets a `build.json` by which open pages notice a newer
105
+ * build.
106
+ */
107
+ export function emberbox(options: EmberboxOptions = {}): PluginOption[] {
108
+ const url = options.url?.replace(/\/+$/, '') ?? ''
109
+ if (options.prerender && !url) {
110
+ throw new Error('emberbox(): prerendering needs a url.')
111
+ }
112
+ return [
113
+ ui({
114
+ router: options.router ?? true,
115
+ theme: {colors: COLORS},
116
+ ui: defu(options.ui, DEFAULTS),
117
+ icon: {clientBundle: {scan: ICON_SCAN, icons: OWN_ICONS}},
118
+ scanPackages: ['@emberbox/ui'],
119
+ }),
120
+ {
121
+ name: 'emberbox',
122
+ config: () => ({
123
+ define: {
124
+ __EMBERBOX_COMMIT__: JSON.stringify(BUILD_INFO.commit),
125
+ __EMBERBOX_BUILT_AT__: JSON.stringify(BUILD_INFO.builtAt),
126
+ __EMBERBOX_URL__: JSON.stringify(url),
127
+ __EMBERBOX_IMAGE__: JSON.stringify(options.logo ? '/logo-512.png' : ''),
128
+ },
129
+ optimizeDeps: {exclude: ['@emberbox/ui', '@iconify/vue']},
130
+ resolve: {dedupe: ['vue', 'vue-router', '@nuxt/ui']},
131
+ ssr: {noExternal: ['@emberbox/ui', '@nuxt/ui']},
132
+ }),
133
+ transformIndexHtml: () => [
134
+ {tag: 'script', children: COLOR_MODE_SCRIPT, injectTo: 'head'},
135
+ ],
136
+ generateBundle(this, output) {
137
+ if (output.format === 'es' && !this.environment?.config.build.ssr) {
138
+ this.emitFile({type: 'asset', fileName: 'build.json', source: JSON.stringify(BUILD_INFO)})
139
+ }
140
+ },
141
+ },
142
+ options.logo ? logoPlugin(options.logo) : false,
143
+ options.prerender && url ? prerenderPlugin(options.prerender, url) : false,
144
+ ]
145
+ }