basalt-ui 1.1.1 → 1.3.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 (191) hide show
  1. package/AGENTS.md +2 -2
  2. package/CHANGELOG.md +46 -0
  3. package/README.md +64 -8
  4. package/agent/rules/basalt-app.md +126 -0
  5. package/agent/rules/basalt-content.md +3 -1
  6. package/agent/rules/basalt-tokens.md +14 -5
  7. package/agent/skills/basalt-app/SKILL.md +28 -7
  8. package/dist/agent/part-list.d.ts.map +1 -1
  9. package/dist/agent/part-list.js +17 -7
  10. package/dist/agent/stick-to-bottom.js +2 -2
  11. package/dist/agent-chat/thread-detail-panel.d.ts.map +1 -1
  12. package/dist/agent-chat/thread-detail-panel.js +37 -33
  13. package/dist/agent-chat/thread-message.d.ts.map +1 -1
  14. package/dist/agent-chat/thread-message.js +8 -5
  15. package/dist/agent-chat/thread-outcome-card.js +3 -3
  16. package/dist/agent-chat/thread-workspace.js +1 -1
  17. package/dist/charts/primitives/ChartLegend.js +2 -0
  18. package/dist/charts/primitives/ChartTooltip.js +2 -1
  19. package/dist/cli/index.d.ts +29 -0
  20. package/dist/cli/index.d.ts.map +1 -1
  21. package/dist/cli/index.js +80 -9
  22. package/dist/connectivity/connectivity-indicator.d.ts.map +1 -1
  23. package/dist/connectivity/connectivity-indicator.js +3 -3
  24. package/dist/content/article-card.module.css +7 -5
  25. package/dist/content/article-layout.module.css +16 -12
  26. package/dist/content/callout.module.css +4 -4
  27. package/dist/content/code-block.module.css +8 -7
  28. package/dist/content/guide.module.css +3 -3
  29. package/dist/content/mermaid.module.css +2 -2
  30. package/dist/content/prose.module.css +59 -29
  31. package/dist/content/reading-progress.module.css +2 -0
  32. package/dist/content/toc.module.css +6 -3
  33. package/dist/dashboard/delta-badge.d.ts.map +1 -1
  34. package/dist/dashboard/delta-badge.js +10 -2
  35. package/dist/dashboard/empty-state.d.ts.map +1 -1
  36. package/dist/dashboard/empty-state.js +3 -16
  37. package/dist/dashboard/settings-section.js +2 -2
  38. package/dist/dashboard/settings-section.module.css +2 -2
  39. package/dist/dashboard/stat-card.js +2 -1
  40. package/dist/data/virtual-list.d.ts.map +1 -1
  41. package/dist/data/virtual-list.js +12 -2
  42. package/dist/forms/FormErrorSummary.js +2 -2
  43. package/dist/guard/index.d.ts +20 -4
  44. package/dist/guard/index.d.ts.map +1 -1
  45. package/dist/guard/index.js +266 -38
  46. package/dist/guard/types.d.ts +24 -3
  47. package/dist/guard/types.d.ts.map +1 -1
  48. package/dist/index.d.ts +1 -0
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/provider/index.d.ts +30 -1
  51. package/dist/provider/index.d.ts.map +1 -1
  52. package/dist/provider/index.js +32 -7
  53. package/dist/provider/lab-theme.d.ts +39 -0
  54. package/dist/provider/lab-theme.d.ts.map +1 -0
  55. package/dist/provider/lab-theme.js +52 -0
  56. package/dist/shell/app-header.module.css +2 -2
  57. package/dist/shell/app-mobile-nav.module.css +1 -1
  58. package/dist/shell/app-sidebar-account.d.ts.map +1 -1
  59. package/dist/shell/app-sidebar-account.js +4 -2
  60. package/dist/shell/app-sidebar.d.ts.map +1 -1
  61. package/dist/shell/app-sidebar.js +4 -2
  62. package/dist/shell/app-sidebar.module.css +36 -26
  63. package/dist/shell/index.d.ts.map +1 -1
  64. package/dist/shell/index.js +11 -4
  65. package/dist/shell/sidebar-search.module.css +16 -4
  66. package/dist/styles.css +22 -11
  67. package/dist/surfaces.d.ts +21 -11
  68. package/dist/surfaces.d.ts.map +1 -1
  69. package/dist/surfaces.js +10 -3
  70. package/dist/theme/controls.module.css +1 -1
  71. package/dist/theme/floating.module.css +1 -1
  72. package/dist/theme/index.d.ts +116 -11
  73. package/dist/theme/index.d.ts.map +1 -1
  74. package/dist/theme/index.js +703 -566
  75. package/dist/theme/nav-link.module.css +1 -1
  76. package/dist/theme/use-basalt-spacing.d.ts +3 -0
  77. package/dist/theme/use-basalt-spacing.d.ts.map +1 -0
  78. package/dist/theme/use-basalt-spacing.js +8 -0
  79. package/dist/theme-lab/derive-controls.d.ts +13 -0
  80. package/dist/theme-lab/derive-controls.d.ts.map +1 -0
  81. package/dist/theme-lab/derive-controls.js +137 -0
  82. package/dist/theme-lab/derive-state.d.ts +55 -0
  83. package/dist/theme-lab/derive-state.d.ts.map +1 -0
  84. package/dist/theme-lab/derive-state.js +81 -0
  85. package/dist/theme-lab/index.d.ts +12 -2
  86. package/dist/theme-lab/index.d.ts.map +1 -1
  87. package/dist/theme-lab/index.js +13 -62
  88. package/dist/theme-toggle/index.d.ts.map +1 -1
  89. package/dist/theme-toggle/index.js +3 -2
  90. package/dist/tokens/derive.d.ts +89 -0
  91. package/dist/tokens/derive.d.ts.map +1 -0
  92. package/dist/tokens/derive.js +250 -0
  93. package/dist/tokens/hct.d.ts +34 -0
  94. package/dist/tokens/hct.d.ts.map +1 -0
  95. package/dist/tokens/hct.js +159 -0
  96. package/dist/tokens/index.d.ts +143 -7
  97. package/dist/tokens/index.d.ts.map +1 -1
  98. package/dist/tokens/index.js +322 -48
  99. package/dist/tokens/palette.d.ts +984 -167
  100. package/dist/tokens/palette.d.ts.map +1 -1
  101. package/dist/tokens/palette.js +617 -119
  102. package/dist/tokens.css +248 -0
  103. package/dist/vite-color-mix.d.ts +30 -0
  104. package/dist/vite-color-mix.d.ts.map +1 -0
  105. package/dist/vite-color-mix.js +80 -0
  106. package/dist/vite.d.ts +82 -1
  107. package/dist/vite.d.ts.map +1 -1
  108. package/dist/vite.js +312 -0
  109. package/llms.txt +14 -4
  110. package/package.json +41 -10
  111. package/src/agent/part-list.tsx +13 -7
  112. package/src/agent/stick-to-bottom.tsx +2 -2
  113. package/src/agent-chat/thread-detail-panel.tsx +13 -10
  114. package/src/agent-chat/thread-message.tsx +8 -5
  115. package/src/agent-chat/thread-outcome-card.tsx +2 -2
  116. package/src/agent-chat/thread-workspace.tsx +2 -2
  117. package/src/charts/primitives/ChartLegend.tsx +2 -2
  118. package/src/charts/primitives/ChartTooltip.tsx +2 -2
  119. package/src/cli/check-theme.test.ts +18 -0
  120. package/src/cli/index.ts +129 -6
  121. package/src/cli/tokens-css.test.ts +90 -0
  122. package/src/connectivity/connectivity-indicator.tsx +8 -2
  123. package/src/content/article-card.module.css +7 -5
  124. package/src/content/article-layout.module.css +16 -12
  125. package/src/content/callout.module.css +4 -4
  126. package/src/content/code-block.module.css +8 -7
  127. package/src/content/guide.module.css +3 -3
  128. package/src/content/mermaid.module.css +2 -2
  129. package/src/content/prose.module.css +59 -29
  130. package/src/content/prose.module.css.test.ts +55 -0
  131. package/src/content/reading-progress.module.css +2 -0
  132. package/src/content/toc.module.css +6 -3
  133. package/src/dashboard/delta-badge.tsx +10 -4
  134. package/src/dashboard/empty-state.tsx +3 -16
  135. package/src/dashboard/settings-section.module.css +2 -2
  136. package/src/dashboard/settings-section.tsx +2 -2
  137. package/src/dashboard/stat-card.tsx +2 -2
  138. package/src/data/virtual-list.tsx +12 -2
  139. package/src/forms/FormErrorSummary.tsx +1 -1
  140. package/src/guard/check-source.test.ts +483 -15
  141. package/src/guard/index.ts +426 -47
  142. package/src/guard/types.ts +24 -2
  143. package/src/index.ts +1 -0
  144. package/src/provider/index.test.tsx +100 -0
  145. package/src/provider/index.tsx +79 -7
  146. package/src/provider/lab-theme.test.ts +147 -0
  147. package/src/provider/lab-theme.ts +166 -0
  148. package/src/shell/app-header.module.css +2 -2
  149. package/src/shell/app-mobile-nav.module.css +1 -1
  150. package/src/shell/app-sidebar-account.tsx +9 -2
  151. package/src/shell/app-sidebar.module.css +36 -26
  152. package/src/shell/app-sidebar.tsx +12 -2
  153. package/src/shell/index.tsx +14 -3
  154. package/src/shell/sidebar-search.module.css +16 -4
  155. package/src/styles.css +22 -11
  156. package/src/surfaces.ts +24 -10
  157. package/src/theme/contrast.test.ts +19 -3
  158. package/src/theme/controls.module.css +1 -1
  159. package/src/theme/density-option.test.ts +96 -0
  160. package/src/theme/density-relations.test.ts +428 -0
  161. package/src/theme/derive-theme.test.ts +101 -0
  162. package/src/theme/floating.module.css +1 -1
  163. package/src/theme/fonts-option.test.ts +69 -0
  164. package/src/theme/index.ts +930 -563
  165. package/src/theme/nav-link.module.css +1 -1
  166. package/src/theme/radius-option.test.ts +86 -0
  167. package/src/theme/radius.test.ts +132 -0
  168. package/src/theme/spacing.test.ts +432 -0
  169. package/src/theme/use-basalt-spacing.test.tsx +51 -0
  170. package/src/theme/use-basalt-spacing.ts +38 -0
  171. package/src/theme-lab/derive-controls.test.ts +94 -0
  172. package/src/theme-lab/derive-controls.tsx +227 -0
  173. package/src/theme-lab/derive-state.test.ts +71 -0
  174. package/src/theme-lab/derive-state.ts +163 -0
  175. package/src/theme-lab/index.tsx +29 -68
  176. package/src/theme-lab/theme-lab.test.ts +4 -18
  177. package/src/theme-toggle/index.tsx +9 -4
  178. package/src/tokens/build-fonts-css.test.ts +51 -0
  179. package/src/tokens/build-radius-css.test.ts +25 -0
  180. package/src/tokens/density.test.ts +274 -0
  181. package/src/tokens/derive-radius.test.ts +62 -0
  182. package/src/tokens/derive.test.ts +30 -0
  183. package/src/tokens/derive.ts +481 -0
  184. package/src/tokens/hct.ts +231 -0
  185. package/src/tokens/index.ts +534 -48
  186. package/src/tokens/palette.test.ts +114 -0
  187. package/src/tokens/palette.ts +1118 -180
  188. package/src/vite-color-mix.test.ts +46 -0
  189. package/src/vite-color-mix.ts +137 -0
  190. package/src/vite.test.ts +192 -0
  191. package/src/vite.ts +502 -1
@@ -0,0 +1,46 @@
1
+ import { describe, expect, test } from 'bun:test'
2
+ import { resolveColorMix } from './vite-color-mix'
3
+
4
+ describe('resolveColorMix', () => {
5
+ test('resolves SURFACE.bg.light exactly', () => {
6
+ expect(resolveColorMix('color-mix(in srgb, #f4f4f5 50%, #e4e4e7)')).toBe('#ececee')
7
+ })
8
+
9
+ test('resolves SURFACE.bg.dark exactly', () => {
10
+ expect(resolveColorMix('color-mix(in srgb, #27272a 70%, #18181b)')).toBe('#232326')
11
+ })
12
+
13
+ test('passes through a plain 6-digit hex unchanged (lowercased)', () => {
14
+ expect(resolveColorMix('#ABCDEF')).toBe('#abcdef')
15
+ })
16
+
17
+ test('expands a plain 3-digit hex', () => {
18
+ expect(resolveColorMix('#fff')).toBe('#ffffff')
19
+ })
20
+
21
+ test('resolves trivial named colors', () => {
22
+ expect(resolveColorMix('white')).toBe('#ffffff')
23
+ expect(resolveColorMix('black')).toBe('#000000')
24
+ })
25
+
26
+ test('defaults to a 50/50 mix when neither side carries a percentage', () => {
27
+ expect(resolveColorMix('color-mix(in srgb, #000000, #ffffff)')).toBe('#808080')
28
+ })
29
+
30
+ test('resolves nested color-mix expressions recursively', () => {
31
+ // inner: 50/50 of black/white -> #808080; outer: 50/50 of that and black -> #404040
32
+ expect(
33
+ resolveColorMix('color-mix(in srgb, color-mix(in srgb, #000000 50%, #ffffff) 50%, #000000)'),
34
+ ).toBe('#404040')
35
+ })
36
+
37
+ test('throws a clear error for an unresolvable input', () => {
38
+ expect(() => resolveColorMix('red')).toThrow(/Unresolvable color-mix input: "red"/)
39
+ })
40
+
41
+ test('throws a clear error for a non-srgb color space', () => {
42
+ expect(() => resolveColorMix('color-mix(in oklab, #000000 50%, #ffffff)')).toThrow(
43
+ /Unresolvable color-mix input/,
44
+ )
45
+ })
46
+ })
@@ -0,0 +1,137 @@
1
+ /**
2
+ * vite-color-mix.ts — resolves CSS `color-mix(in srgb, A [p%], B [p%])` expressions down to a
3
+ * flat hex string.
4
+ *
5
+ * Why this exists: `SURFACE.bg` in `tokens/palette.ts` holds `color-mix()` expressions (not hex),
6
+ * because the page background is a deliberate mix of two zinc stops. `<meta name="theme-color">`
7
+ * and the web manifest's `theme_color` both require a FLAT color — `color-mix()` cannot appear
8
+ * there — so consumers were hand-approximating the mix and getting it wrong (argo shipped
9
+ * `#EDEFF2`/`#242424`, both incorrect). This resolver computes the exact flat value at build time
10
+ * instead, which is the core value `basaltAppPlugin` (in `./vite.ts`) adds over a hand-authored
11
+ * PWA/head-metadata config.
12
+ *
13
+ * Internal to the `./vite` subpath only — deliberately NOT re-exported from `vite.ts`, so it never
14
+ * becomes part of the published surface (see `scripts/export-surface.json`).
15
+ *
16
+ * Supports: plain hex passthrough (`#rgb` / `#rrggbb`), a small set of trivial named colors, and
17
+ * one or more levels of nested `color-mix(in srgb, A [p%], B [p%])` — sRGB channel lerp on the
18
+ * 0-255 channels, round-half-up. Anything else (other color spaces, non-trivial named colors,
19
+ * `rgb()`/`hsl()` functions) throws a clear error naming the unresolvable input.
20
+ */
21
+
22
+ /**
23
+ * Only colors that map to an exact, unambiguous hex value — no gradients of named-color support.
24
+ *
25
+ * These two hexes are NOT design tokens and must not be routed through `VX.*`: they are the CSS
26
+ * specification's definitions of the `white` and `black` keywords, used to parse an input string.
27
+ * A palette reference here would make the parser resolve differently per theme, which is exactly
28
+ * what a color parser must never do.
29
+ */
30
+ const NAMED_COLORS: Record<string, string> = {
31
+ white: '#ffffff', // theme-allow — CSS keyword definition, not a design color
32
+ black: '#000000', // theme-allow — CSS keyword definition, not a design color
33
+ }
34
+
35
+ function normalizeHex(hex: string): string {
36
+ const body = hex.slice(1)
37
+ const full =
38
+ body.length === 3
39
+ ? body
40
+ .split('')
41
+ .map((c) => c + c)
42
+ .join('')
43
+ : body
44
+ return `#${full.toLowerCase()}`
45
+ }
46
+
47
+ function hexToRgb(hex: string): [number, number, number] {
48
+ const normalized = normalizeHex(hex)
49
+ const value = Number.parseInt(normalized.slice(1), 16)
50
+ return [(value >> 16) & 255, (value >> 8) & 255, value & 255]
51
+ }
52
+
53
+ function channelToHex(channel: number): string {
54
+ return channel.toString(16).padStart(2, '0')
55
+ }
56
+
57
+ function rgbToHex(channels: readonly [number, number, number]): string {
58
+ return `#${channelToHex(channels[0])}${channelToHex(channels[1])}${channelToHex(channels[2])}`
59
+ }
60
+
61
+ /** Splits a `color-mix()` argument list on top-level commas, ignoring commas nested in parens. */
62
+ function splitTopLevel(input: string): string[] {
63
+ const parts: string[] = []
64
+ let depth = 0
65
+ let current = ''
66
+ for (const char of input) {
67
+ if (char === '(') depth++
68
+ if (char === ')') depth--
69
+ if (char === ',' && depth === 0) {
70
+ parts.push(current.trim())
71
+ current = ''
72
+ continue
73
+ }
74
+ current += char
75
+ }
76
+ parts.push(current.trim())
77
+ return parts
78
+ }
79
+
80
+ /** Splits a "<color> [<percentage>%]" mix component into its color and optional percentage. */
81
+ function splitColorAndPercent(component: string): { color: string; percent: number | null } {
82
+ const trimmed = component.trim()
83
+ const match = /^(.+?)\s+(\d+(?:\.\d+)?)%$/.exec(trimmed)
84
+ if (!match) return { color: trimmed, percent: null }
85
+ return { color: match[1]!.trim(), percent: Number(match[2]) }
86
+ }
87
+
88
+ /**
89
+ * Resolves a color-mix expression (or a plain hex / trivial named color) to a flat lowercase hex
90
+ * string. Percentage semantics per CSS `color-mix()`: `A p%` means A contributes `p%`, B
91
+ * contributes `(100 - p)%`; if neither side carries a percentage, the mix is 50/50.
92
+ *
93
+ * @throws {Error} when the input is not hex, a trivial named color, or a `color-mix(in srgb, ...)`
94
+ * expression (e.g. another color space, `rgb()`/`hsl()`, or a non-trivial named color).
95
+ */
96
+ export function resolveColorMix(input: string): string {
97
+ const trimmed = input.trim()
98
+
99
+ if (/^#[0-9a-fA-F]{3}$/.test(trimmed) || /^#[0-9a-fA-F]{6}$/.test(trimmed)) {
100
+ return normalizeHex(trimmed)
101
+ }
102
+
103
+ const named = NAMED_COLORS[trimmed.toLowerCase()]
104
+ if (named !== undefined) return named
105
+
106
+ const mixMatch = /^color-mix\(\s*in\s+srgb\s*,\s*([\s\S]+)\)$/i.exec(trimmed)
107
+ if (!mixMatch) {
108
+ throw new Error(
109
+ `Unresolvable color-mix input: "${input}" — only hex (#rgb/#rrggbb), "white"/"black", ` +
110
+ 'and color-mix(in srgb, ...) are supported.',
111
+ )
112
+ }
113
+
114
+ const components = splitTopLevel(mixMatch[1]!)
115
+ const [colorAComponent, colorBComponent] = components
116
+ if (components.length !== 2 || colorAComponent === undefined || colorBComponent === undefined) {
117
+ throw new Error(`Malformed color-mix() expression: "${input}"`)
118
+ }
119
+
120
+ const a = splitColorAndPercent(colorAComponent)
121
+ const b = splitColorAndPercent(colorBComponent)
122
+
123
+ let percentA: number
124
+ if (a.percent !== null) percentA = a.percent
125
+ else if (b.percent !== null) percentA = 100 - b.percent
126
+ else percentA = 50
127
+
128
+ const rgbA = hexToRgb(resolveColorMix(a.color))
129
+ const rgbB = hexToRgb(resolveColorMix(b.color))
130
+ const percentB = 100 - percentA
131
+
132
+ const mixed: [number, number, number] = [0, 1, 2].map((i) =>
133
+ Math.round((rgbA[i]! * percentA + rgbB[i]! * percentB) / 100),
134
+ ) as [number, number, number]
135
+
136
+ return rgbToHex(mixed)
137
+ }
@@ -0,0 +1,192 @@
1
+ import { describe, expect, test } from 'bun:test'
2
+ import type { HtmlTagDescriptor, Plugin, ResolvedConfig } from 'vite'
3
+ import type { BasaltAppOptions } from './vite'
4
+ import { basaltAppPlugin } from './vite'
5
+
6
+ /** Fixed, palette-independent theme colors so these tests never couple to `tokens/palette.ts`. */
7
+ const THEME_COLOR = { light: '#ffffff', dark: '#111111' } as const
8
+
9
+ function getPlugin(options: BasaltAppOptions): Plugin {
10
+ // No `serviceWorker` option -> basaltAppPlugin returns a single, non-promise Plugin.
11
+ return basaltAppPlugin(options)[0] as Plugin
12
+ }
13
+
14
+ /** Invokes the plugin's `configResolved` hook with a minimal fake `ResolvedConfig`. */
15
+ function resolveConfig(plugin: Plugin, base: string): void {
16
+ const configResolved = plugin.configResolved as unknown as (config: ResolvedConfig) => void
17
+ configResolved({ base } as unknown as ResolvedConfig)
18
+ }
19
+
20
+ /** Invokes the plugin's `transformIndexHtml` hook and returns the emitted tags. */
21
+ function transformHtml(plugin: Plugin, html: string): HtmlTagDescriptor[] {
22
+ const transformIndexHtml = plugin.transformIndexHtml as unknown as (html: string) => {
23
+ html: string
24
+ tags: HtmlTagDescriptor[]
25
+ }
26
+ return transformIndexHtml(html).tags
27
+ }
28
+
29
+ type FakeReq = { url: string }
30
+ type FakeRes = { setHeader: (name: string, value: string) => void; end: (body: string) => void }
31
+ type Middleware = (req: FakeReq, res: FakeRes, next: () => void) => void
32
+
33
+ /** Runs `configResolved` then `configureServer`, returning the registered dev middleware. */
34
+ function getDevMiddleware(plugin: Plugin, base: string): Middleware {
35
+ resolveConfig(plugin, base)
36
+ let captured: Middleware | undefined
37
+ const fakeServer = { middlewares: { use: (fn: Middleware) => (captured = fn) } }
38
+ const configureServer = plugin.configureServer as unknown as (server: unknown) => void
39
+ configureServer(fakeServer)
40
+ if (!captured) throw new Error('basalt:app did not register a dev middleware')
41
+ return captured
42
+ }
43
+
44
+ /** Runs the middleware against a fake request, returning the served body (or `undefined`). */
45
+ function runMiddleware(middleware: Middleware, url: string): string | undefined {
46
+ let body: string | undefined
47
+ const res: FakeRes = {
48
+ setHeader: () => {},
49
+ end: (data: string) => {
50
+ body = data
51
+ },
52
+ }
53
+ middleware({ url }, res, () => {})
54
+ return body
55
+ }
56
+
57
+ const HTML_NO_VIEWPORT = '<html><head></head><body></body></html>'
58
+
59
+ describe('basaltAppPlugin — base handling', () => {
60
+ test('default base "/" regression: exact head tag output', () => {
61
+ const plugin = getPlugin({ name: 'Test App', themeColor: THEME_COLOR })
62
+ resolveConfig(plugin, '/')
63
+ const tags = transformHtml(plugin, HTML_NO_VIEWPORT)
64
+
65
+ expect(tags).toEqual([
66
+ {
67
+ tag: 'meta',
68
+ attrs: {
69
+ name: 'viewport',
70
+ content: 'width=device-width, initial-scale=1.0, viewport-fit=cover',
71
+ },
72
+ },
73
+ {
74
+ tag: 'meta',
75
+ attrs: { name: 'theme-color', media: '(prefers-color-scheme: light)', content: '#ffffff' },
76
+ },
77
+ {
78
+ tag: 'meta',
79
+ attrs: { name: 'theme-color', media: '(prefers-color-scheme: dark)', content: '#111111' },
80
+ },
81
+ { tag: 'style', children: 'html{background-color:#111111;color-scheme:dark}' },
82
+ { tag: 'link', attrs: { rel: 'shortcut icon', href: '/favicon.ico' } },
83
+ { tag: 'link', attrs: { rel: 'icon', type: 'image/svg+xml', href: '/favicon.svg' } },
84
+ { tag: 'link', attrs: { rel: 'icon', sizes: '96x96', href: '/favicon-96x96.png' } },
85
+ {
86
+ tag: 'link',
87
+ attrs: { rel: 'apple-touch-icon', sizes: '180x180', href: '/apple-touch-icon.png' },
88
+ },
89
+ { tag: 'meta', attrs: { name: 'apple-mobile-web-app-title', content: 'Test App' } },
90
+ { tag: 'meta', attrs: { name: 'apple-mobile-web-app-capable', content: 'yes' } },
91
+ { tag: 'meta', attrs: { name: 'mobile-web-app-capable', content: 'yes' } },
92
+ {
93
+ tag: 'meta',
94
+ attrs: { name: 'apple-mobile-web-app-status-bar-style', content: 'default' },
95
+ },
96
+ { tag: 'meta', attrs: { name: 'darkreader-lock' } },
97
+ { tag: 'link', attrs: { rel: 'manifest', href: '/site.webmanifest' } },
98
+ ])
99
+ })
100
+
101
+ test('default base "/" regression: manifest start_url/scope/icon src', () => {
102
+ const plugin = getPlugin({ name: 'Test App', themeColor: THEME_COLOR })
103
+ const middleware = getDevMiddleware(plugin, '/')
104
+ const body = runMiddleware(middleware, '/site.webmanifest')
105
+ const manifest = JSON.parse(body ?? '{}')
106
+
107
+ expect(manifest.start_url).toBe('/')
108
+ expect(manifest.scope).toBe('/')
109
+ expect(manifest.id).toBe('/')
110
+ expect(manifest.icons[0].src).toBe('/web-app-manifest-192x192.png')
111
+ expect(manifest.icons[1].src).toBe('/web-app-manifest-512x512.png')
112
+ })
113
+
114
+ test('non-root base "/myapp/" prefixes icon hrefs and the manifest link', () => {
115
+ const plugin = getPlugin({ name: 'Test App', themeColor: THEME_COLOR })
116
+ resolveConfig(plugin, '/myapp/')
117
+ const tags = transformHtml(plugin, HTML_NO_VIEWPORT)
118
+
119
+ const hrefOf = (rel: string): unknown => {
120
+ const found = tags.find((tag) => tag.tag === 'link' && tag.attrs?.['rel'] === rel)
121
+ return found?.attrs?.['href']
122
+ }
123
+
124
+ expect(hrefOf('shortcut icon')).toBe('/myapp/favicon.ico')
125
+ expect(hrefOf('icon')).toBe('/myapp/favicon.svg')
126
+ expect(hrefOf('apple-touch-icon')).toBe('/myapp/apple-touch-icon.png')
127
+ expect(hrefOf('manifest')).toBe('/myapp/site.webmanifest')
128
+ })
129
+
130
+ test('non-root base "/myapp/" prefixes manifest start_url/scope/icon src by default', () => {
131
+ const plugin = getPlugin({ name: 'Test App', themeColor: THEME_COLOR })
132
+ const middleware = getDevMiddleware(plugin, '/myapp/')
133
+
134
+ // Dev middleware runs before Vite's own base-stripping middleware (see the comment in
135
+ // vite.ts), so the request URL still carries the base prefix — this is the realistic path.
136
+ const bodyPrefixed = runMiddleware(middleware, '/myapp/site.webmanifest')
137
+ expect(bodyPrefixed).toBeDefined()
138
+ const manifest = JSON.parse(bodyPrefixed ?? '{}')
139
+ expect(manifest.start_url).toBe('/myapp/')
140
+ expect(manifest.scope).toBe('/myapp/')
141
+ expect(manifest.id).toBe('/myapp/')
142
+ expect(manifest.icons[0].src).toBe('/myapp/web-app-manifest-192x192.png')
143
+ expect(manifest.icons[1].src).toBe('/myapp/web-app-manifest-512x512.png')
144
+
145
+ // Bare (already-stripped) path is accepted too, defensively.
146
+ const bodyBare = runMiddleware(middleware, '/site.webmanifest')
147
+ expect(bodyBare).toBe(bodyPrefixed)
148
+ })
149
+
150
+ test('an explicit startUrl/scope is NOT re-prefixed with base', () => {
151
+ const plugin = getPlugin({
152
+ name: 'Test App',
153
+ themeColor: THEME_COLOR,
154
+ startUrl: '/custom/',
155
+ scope: '/custom/',
156
+ })
157
+ const middleware = getDevMiddleware(plugin, '/myapp/')
158
+ const body = runMiddleware(middleware, '/myapp/site.webmanifest')
159
+ const manifest = JSON.parse(body ?? '{}')
160
+
161
+ expect(manifest.start_url).toBe('/custom/')
162
+ expect(manifest.scope).toBe('/custom/')
163
+ // id defaults from the (explicit, non-reprefixed) startUrl.
164
+ expect(manifest.id).toBe('/custom/')
165
+ })
166
+
167
+ test('manifest: false keeps skipping the manifest link, generation, and dev serving', () => {
168
+ const plugin = getPlugin({ name: 'Test App', themeColor: THEME_COLOR, manifest: false })
169
+ resolveConfig(plugin, '/myapp/')
170
+
171
+ const tags = transformHtml(plugin, HTML_NO_VIEWPORT)
172
+ expect(tags.some((tag) => tag.tag === 'link' && tag.attrs?.['rel'] === 'manifest')).toBe(false)
173
+
174
+ // manifestEnabled === false -> configureServer must return before registering any middleware.
175
+ let middlewareRegistered = false
176
+ const fakeServer = { middlewares: { use: () => (middlewareRegistered = true) } }
177
+ const configureServer = plugin.configureServer as unknown as (server: unknown) => void
178
+ configureServer(fakeServer)
179
+ expect(middlewareRegistered).toBe(false)
180
+ })
181
+
182
+ test('icons: false keeps skipping icon head links entirely', () => {
183
+ const plugin = getPlugin({ name: 'Test App', themeColor: THEME_COLOR, icons: false })
184
+ resolveConfig(plugin, '/myapp/')
185
+ const tags = transformHtml(plugin, HTML_NO_VIEWPORT)
186
+
187
+ const iconRels = new Set(['shortcut icon', 'icon', 'apple-touch-icon'])
188
+ expect(tags.some((tag) => tag.tag === 'link' && iconRels.has(String(tag.attrs?.['rel'])))).toBe(
189
+ false,
190
+ )
191
+ })
192
+ })