basalt-ui 2.7.3 → 2.8.1

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 (70) hide show
  1. package/CHANGELOG.md +194 -172
  2. package/MIGRATING.md +137 -16
  3. package/agent/rules/basalt-batteries.md +1 -1
  4. package/agent/rules/basalt-controls.md +1 -1
  5. package/agent/rules/basalt-mantine.md +1 -1
  6. package/agent/skills/basalt-app/SKILL.md +7 -7
  7. package/agent/templates/AGENTS-block.md.tpl +1 -1
  8. package/dist/charts/BandStrip.d.ts +13 -0
  9. package/dist/charts/BandStrip.d.ts.map +1 -1
  10. package/dist/charts/BandStrip.js +142 -44
  11. package/dist/cli/doctor-upgrade.d.ts +16 -4
  12. package/dist/cli/doctor-upgrade.d.ts.map +1 -1
  13. package/dist/cli/doctor-upgrade.js +132 -96
  14. package/dist/cli/doctor.d.ts +2 -1
  15. package/dist/cli/doctor.d.ts.map +1 -1
  16. package/dist/cli/doctor.js +21 -13
  17. package/dist/cli/help.js +1 -1
  18. package/dist/cli/index.d.ts +18 -4
  19. package/dist/cli/index.d.ts.map +1 -1
  20. package/dist/cli/index.js +25 -24
  21. package/dist/cli/init.d.ts.map +1 -1
  22. package/dist/cli/init.js +10 -4
  23. package/dist/cli/router-wiring.d.ts +37 -0
  24. package/dist/cli/router-wiring.d.ts.map +1 -0
  25. package/dist/cli/router-wiring.js +116 -0
  26. package/dist/cli/source-text.d.ts +12 -0
  27. package/dist/cli/source-text.d.ts.map +1 -0
  28. package/dist/cli/source-text.js +46 -0
  29. package/dist/cli/sync.d.ts.map +1 -1
  30. package/dist/cli/sync.js +32 -2
  31. package/dist/content/code-block.d.ts.map +1 -1
  32. package/dist/content/code-block.js +36 -27
  33. package/dist/content/code-block.module.css +19 -1
  34. package/dist/content/mermaid-sanitize.d.ts +15 -0
  35. package/dist/content/mermaid-sanitize.d.ts.map +1 -0
  36. package/dist/content/mermaid-sanitize.js +28 -0
  37. package/dist/content/mermaid.d.ts +6 -0
  38. package/dist/content/mermaid.d.ts.map +1 -1
  39. package/dist/content/mermaid.js +3 -1
  40. package/dist/provider/index.d.ts +22 -4
  41. package/dist/provider/index.d.ts.map +1 -1
  42. package/dist/provider/index.js +24 -8
  43. package/dist/provider/test-router.d.ts +2 -1
  44. package/dist/provider/test-router.d.ts.map +1 -1
  45. package/dist/provider/test-router.js +6 -7
  46. package/dist/vite-boot.d.ts +25 -0
  47. package/dist/vite-boot.d.ts.map +1 -0
  48. package/dist/vite-boot.js +36 -0
  49. package/dist/vite.d.ts +24 -3
  50. package/dist/vite.d.ts.map +1 -1
  51. package/dist/vite.js +7 -16
  52. package/llms.txt +37 -4
  53. package/package.json +1 -1
  54. package/src/charts/BandStrip.tsx +223 -48
  55. package/src/cli/doctor-upgrade.ts +181 -141
  56. package/src/cli/doctor.ts +23 -14
  57. package/src/cli/help.ts +1 -1
  58. package/src/cli/index.ts +37 -36
  59. package/src/cli/init.ts +10 -6
  60. package/src/cli/router-wiring.ts +185 -0
  61. package/src/cli/source-text.ts +62 -0
  62. package/src/cli/sync.ts +36 -2
  63. package/src/content/code-block.module.css +19 -1
  64. package/src/content/code-block.tsx +7 -2
  65. package/src/content/mermaid-sanitize.ts +49 -0
  66. package/src/content/mermaid.tsx +3 -2
  67. package/src/provider/index.tsx +71 -18
  68. package/src/provider/test-router.tsx +9 -9
  69. package/src/vite-boot.ts +109 -0
  70. package/src/vite.ts +32 -61
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import { Outlet, createRootRoute, createRoute } from '@tanstack/react-router'
6
6
  import type { AnyRouter } from '@tanstack/react-router'
7
+ import type { ReactNode } from 'react'
7
8
  import { createBasaltRouter } from './create-router'
8
9
  import type { BasaltRouterContext } from './create-router'
9
10
 
@@ -11,15 +12,14 @@ import type { BasaltRouterContext } from './create-router'
11
12
  export const queryClientOf = (router: AnyRouter): BasaltRouterContext['queryClient'] =>
12
13
  (router.options.context as BasaltRouterContext).queryClient
13
14
 
14
- export function testRouter(text = 'content') {
15
- const root = createRootRoute({
16
- component: () => (
17
- <>
18
- <div>{text}</div>
19
- <Outlet />
20
- </>
21
- ),
22
- })
15
+ export function testRouter(text = 'content', wrap?: (children: ReactNode) => ReactNode) {
16
+ const body = (
17
+ <>
18
+ <div>{text}</div>
19
+ <Outlet />
20
+ </>
21
+ )
22
+ const root = createRootRoute({ component: () => (wrap ? wrap(body) : body) })
23
23
  const other = createRoute({ getParentRoute: () => root, path: '/other', component: () => null })
24
24
  return createBasaltRouter({ routeTree: root.addChildren([other]) })
25
25
  }
@@ -0,0 +1,109 @@
1
+ /**
2
+ * vite-boot.ts — the anti-FOUC boot subsystem of `basaltAppPlugin`: the unlayered `<style>` that
3
+ * paints the page before any stylesheet lands, and the tiny inline script that makes that paint
4
+ * follow the scheme the user last stored.
5
+ *
6
+ * Internal to the `./vite` subpath only — deliberately NOT re-exported from `vite.ts`.
7
+ */
8
+ import type { HtmlTagDescriptor } from 'vite'
9
+
10
+ /**
11
+ * The selector every anti-FOUC declaration is scoped to.
12
+ *
13
+ * The rule paints the page before any stylesheet lands, so it is UNLAYERED by construction — and an
14
+ * unlayered declaration outranks every layered one regardless of specificity. Through 1.20.0 that
15
+ * meant a flat `html{color-scheme:dark}` permanently beat Mantine's own
16
+ * `@layer mantine{:root{color-scheme:var(--mantine-color-scheme)}}`: a light-scheme consumer got
17
+ * dark scrollbars, dark `<select>` popups and dark date pickers forever, with no opt-out (found
18
+ * independently by two consumers).
19
+ *
20
+ * `MantineProvider` writes `data-mantine-color-scheme` onto `<html>` as soon as it mounts, so
21
+ * scoping the boot rule to its ABSENCE makes it expire exactly when the real theme exists — which
22
+ * is the anti-FOUC contract stated honestly. A cascade layer would also work in principle and is
23
+ * deliberately NOT used: a layer's position is fixed by where its name is first encountered, and in
24
+ * dev Mantine's CSS is injected by JS after this `<style>` is already in the document, so the layer
25
+ * order would depend on bundler mode. Selector scoping depends on nothing.
26
+ */
27
+ const BOOT_SCOPE = 'html:not([data-mantine-color-scheme])'
28
+
29
+ /** Boot-only attribute `BOOT_SCRIPT` sets; never `data-mantine-color-scheme`, which would expire the rule. */
30
+ const BOOT_ATTRIBUTE = 'data-basalt-boot'
31
+
32
+ /** Mantine's default `localStorageColorSchemeManager` key — BasaltProvider installs no manager of its own. */
33
+ const BOOT_STORAGE_KEY = 'mantine-color-scheme-value'
34
+
35
+ /**
36
+ * Stored value is Mantine's raw `light` | `dark` | `auto` string; `auto` resolves through
37
+ * `prefers-color-scheme`. A throwing or empty store, or a missing `matchMedia`, leaves the
38
+ * attribute off. IIFE + `let`: a classic inline script shares the page's global scope.
39
+ */
40
+ const BOOT_SCRIPT =
41
+ '(function(){try{' +
42
+ `let v=localStorage.getItem('${BOOT_STORAGE_KEY}');` +
43
+ "if(v==='auto')v=matchMedia('(prefers-color-scheme: dark)').matches?'dark':'light';" +
44
+ `if(v==='light'||v==='dark')document.documentElement.setAttribute('${BOOT_ATTRIBUTE}',v)` +
45
+ '}catch(e){}})()'
46
+
47
+ /** The `color-scheme` value each boot mode declares. `false` declares none. */
48
+ const BOOT_COLOR_SCHEME = { dark: 'dark', light: 'light', auto: 'light dark' } as const
49
+
50
+ /** The `colorScheme` option: which scheme the boot paint assumes; `false` declares no `color-scheme`. */
51
+ export type BootColorScheme = 'dark' | 'light' | 'auto' | false
52
+
53
+ type BootInput = {
54
+ colorScheme: BootColorScheme
55
+ themeColor: { light: string; dark: string }
56
+ backgroundColor: string
57
+ explicitBackground: boolean
58
+ /** Inject the stored-scheme script and the variant rules it drives. */
59
+ bootScript: boolean
60
+ }
61
+
62
+ /**
63
+ * The base rule: paint the surface (and, unless opted out, tell the UA which native-control palette
64
+ * to use) for the frames between first paint and Mantine's stylesheet.
65
+ *
66
+ * `'auto'` with no explicit `backgroundColor` emits a `prefers-color-scheme` pair so the pre-boot
67
+ * paint follows the OS the same way `color-scheme: light dark` does; an explicit `backgroundColor`
68
+ * is used verbatim for both, since the consumer has named one color on purpose.
69
+ */
70
+ function buildBaseBootStyle(input: BootInput): string {
71
+ const { colorScheme, themeColor, backgroundColor, explicitBackground } = input
72
+
73
+ if (colorScheme === false) return `${BOOT_SCOPE}{background-color:${backgroundColor}}`
74
+
75
+ const scheme = BOOT_COLOR_SCHEME[colorScheme]
76
+ if (colorScheme !== 'auto' || explicitBackground) {
77
+ return `${BOOT_SCOPE}{background-color:${backgroundColor};color-scheme:${scheme}}`
78
+ }
79
+ return (
80
+ `${BOOT_SCOPE}{background-color:${themeColor.light};color-scheme:${scheme}}` +
81
+ `@media(prefers-color-scheme:dark){${BOOT_SCOPE}{background-color:${themeColor.dark}}}`
82
+ )
83
+ }
84
+
85
+ function buildBootStyle(input: BootInput): string {
86
+ const { colorScheme, themeColor, explicitBackground, bootScript } = input
87
+ const base = buildBaseBootStyle(input)
88
+ if (!bootScript) return base
89
+
90
+ // Stored-scheme variants: keyed off the attribute BOOT_SCRIPT sets, still inside BOOT_SCOPE so
91
+ // they expire with the rest. The extra attribute outranks the base rule and its `auto` media pair.
92
+ // An explicit backgroundColor is the consumer's one chosen color — only `color-scheme` follows.
93
+ const variants = (['light', 'dark'] as const).map((scheme) => {
94
+ const declarations = [
95
+ ...(explicitBackground ? [] : [`background-color:${themeColor[scheme]}`]),
96
+ ...(colorScheme === false ? [] : [`color-scheme:${scheme}`]),
97
+ ]
98
+ if (declarations.length === 0) return ''
99
+ return `${BOOT_SCOPE}[${BOOT_ATTRIBUTE}=${scheme}]{${declarations.join(';')}}`
100
+ })
101
+ return base + variants.join('')
102
+ }
103
+
104
+ /** The boot `<style>`, then (unless `bootScript: false`) the script — adjacent, head-prepend. */
105
+ export function buildBootTags(input: BootInput): HtmlTagDescriptor[] {
106
+ const tags: HtmlTagDescriptor[] = [{ tag: 'style', children: buildBootStyle(input) }]
107
+ if (input.bootScript) tags.push({ tag: 'script', children: BOOT_SCRIPT })
108
+ return tags
109
+ }
package/src/vite.ts CHANGED
@@ -23,6 +23,8 @@ import { dirname, resolve } from 'node:path'
23
23
  import { searchForWorkspaceRoot } from 'vite'
24
24
  import type { HtmlTagDescriptor, Plugin, PluginOption, UserConfig } from 'vite'
25
25
  import { SURFACE } from './tokens/palette'
26
+ import { buildBootTags } from './vite-boot'
27
+ import type { BootColorScheme } from './vite-boot'
26
28
  import { resolveColorMix } from './vite-color-mix'
27
29
 
28
30
  type BasaltViteOptions = {
@@ -243,9 +245,29 @@ type BasaltAppOptions = {
243
245
  *
244
246
  * Set this to whatever the app passes as `defaultColorScheme` — a mismatch is a visible flash of
245
247
  * the wrong surface, not a correctness bug: the boot rule stops applying the moment Mantine
246
- * writes `data-mantine-color-scheme` on `<html>` (see `BOOT_SCOPE`).
248
+ * writes `data-mantine-color-scheme` on `<html>` (see `./vite-boot.ts`).
247
249
  */
248
- colorScheme?: 'dark' | 'light' | 'auto' | false
250
+ colorScheme?: BootColorScheme
251
+ /**
252
+ * Default `true`. Injects a ~300-byte inline `<script>` that reads the scheme the user last chose
253
+ * (Mantine's default `mantine-color-scheme-value` localStorage key — `light`, `dark` or `auto`,
254
+ * `auto` resolved through `prefers-color-scheme`) and sets a boot-only `data-basalt-boot`
255
+ * attribute on `<html>`, so the pre-boot paint matches the stored scheme instead of the build-time
256
+ * `colorScheme`. Storage unavailable or unset → the `colorScheme` paint stands. The script never
257
+ * writes `data-mantine-color-scheme`, so the boot rule still expires when Mantine mounts.
258
+ *
259
+ * `colorScheme: false` still gets the stored-scheme background paint; only `color-scheme` is
260
+ * suppressed. A stored value wins over the build-time `colorScheme`: an app that removes its scheme toggle
261
+ * should clear the stored key or set `bootScript: false`.
262
+ *
263
+ * CSP: Vite stamps `html.cspNonce` onto every `<script>`/`<style>` in the transformed HTML,
264
+ * plugin-injected ones included, so one nonce covers both boot tags. Without a nonce, a CSP that
265
+ * forbids inline scripts needs `bootScript: false`.
266
+ *
267
+ * Also set `false` when `BasaltProvider` gets a custom `colorSchemeManager` with another key
268
+ * (e.g. `localStorageColorSchemeManager({ key })`) — the script reads only the default key.
269
+ */
270
+ bootScript?: boolean
249
271
  /**
250
272
  * Manifest `background_color` + anti-FOUC paint color. Default: the theme color matching
251
273
  * `colorScheme` (the dark one for `'dark'` / `'auto'` / `false`, the light one for `'light'`).
@@ -409,58 +431,6 @@ const VIEWPORT_TAG: HtmlTagDescriptor = {
409
431
  attrs: { name: 'viewport', content: 'width=device-width, initial-scale=1.0, viewport-fit=cover' },
410
432
  }
411
433
 
412
- // ── The anti-FOUC boot rule ───────────────────────────────────────────────────────────────────
413
-
414
- /**
415
- * The selector every anti-FOUC declaration is scoped to.
416
- *
417
- * The rule paints the page before any stylesheet lands, so it is UNLAYERED by construction — and an
418
- * unlayered declaration outranks every layered one regardless of specificity. Through 1.20.0 that
419
- * meant a flat `html{color-scheme:dark}` permanently beat Mantine's own
420
- * `@layer mantine{:root{color-scheme:var(--mantine-color-scheme)}}`: a light-scheme consumer got
421
- * dark scrollbars, dark `<select>` popups and dark date pickers forever, with no opt-out (found
422
- * independently by two consumers).
423
- *
424
- * `MantineProvider` writes `data-mantine-color-scheme` onto `<html>` as soon as it mounts, so
425
- * scoping the boot rule to its ABSENCE makes it expire exactly when the real theme exists — which
426
- * is the anti-FOUC contract stated honestly. A cascade layer would also work in principle and is
427
- * deliberately NOT used: a layer's position is fixed by where its name is first encountered, and in
428
- * dev Mantine's CSS is injected by JS after this `<style>` is already in the document, so the layer
429
- * order would depend on bundler mode. Selector scoping depends on nothing.
430
- */
431
- const BOOT_SCOPE = 'html:not([data-mantine-color-scheme])'
432
-
433
- /** The `color-scheme` value each boot mode declares. `false` declares none. */
434
- const BOOT_COLOR_SCHEME = { dark: 'dark', light: 'light', auto: 'light dark' } as const
435
-
436
- /**
437
- * Builds the anti-FOUC stylesheet: paint the surface (and, unless opted out, tell the UA which
438
- * native-control palette to use) for the frames between first paint and Mantine's stylesheet.
439
- *
440
- * `'auto'` with no explicit `backgroundColor` emits a `prefers-color-scheme` pair so the pre-boot
441
- * paint follows the OS the same way `color-scheme: light dark` does; an explicit `backgroundColor`
442
- * is used verbatim for both, since the consumer has named one color on purpose.
443
- */
444
- function buildBootStyle(input: {
445
- colorScheme: 'dark' | 'light' | 'auto' | false
446
- themeColor: { light: string; dark: string }
447
- backgroundColor: string
448
- explicitBackground: boolean
449
- }): string {
450
- const { colorScheme, themeColor, backgroundColor, explicitBackground } = input
451
-
452
- if (colorScheme === false) return `${BOOT_SCOPE}{background-color:${backgroundColor}}`
453
-
454
- const scheme = BOOT_COLOR_SCHEME[colorScheme]
455
- if (colorScheme !== 'auto' || explicitBackground) {
456
- return `${BOOT_SCOPE}{background-color:${backgroundColor};color-scheme:${scheme}}`
457
- }
458
- return (
459
- `${BOOT_SCOPE}{background-color:${themeColor.light};color-scheme:${scheme}}` +
460
- `@media(prefers-color-scheme:dark){${BOOT_SCOPE}{background-color:${themeColor.dark}}}`
461
- )
462
- }
463
-
464
434
  // ── The encoding declaration ──────────────────────────────────────────────────────────────────
465
435
 
466
436
  /** `<meta charset="…">`, with the value in group 1/2/3 depending on the quoting style. */
@@ -549,7 +519,7 @@ function buildStaticTags(input: {
549
519
  options: BasaltAppOptions
550
520
  shortName: string
551
521
  themeColor: { light: string; dark: string }
552
- bootStyle: string
522
+ bootTags: HtmlTagDescriptor[]
553
523
  icons: ResolvedIcons
554
524
  darkreader: 'lock' | false
555
525
  manifestEnabled: boolean
@@ -560,7 +530,7 @@ function buildStaticTags(input: {
560
530
  options,
561
531
  shortName,
562
532
  themeColor,
563
- bootStyle,
533
+ bootTags,
564
534
  icons,
565
535
  darkreader,
566
536
  manifestEnabled,
@@ -592,8 +562,8 @@ function buildStaticTags(input: {
592
562
  // Anti-FOUC — paints the boot surface before any stylesheet loads. injectTo defaults to
593
563
  // 'head-prepend', so this (and every tag below) lands immediately after <head> and the hoisted
594
564
  // <meta charset>, ahead of the consumer's own <link rel="stylesheet"> tags. Scoped to
595
- // BOOT_SCOPE so it expires the moment Mantine resolves the real scheme — see buildBootStyle.
596
- tags.push({ tag: 'style', children: bootStyle })
565
+ // BOOT_SCOPE so it expires the moment Mantine resolves the real scheme — see ./vite-boot.ts.
566
+ tags.push(...bootTags)
597
567
 
598
568
  if (icons.mode === 'default') {
599
569
  tags.push(
@@ -763,11 +733,12 @@ function createMainPlugin(options: BasaltAppOptions): Plugin {
763
733
  const colorScheme = options.colorScheme ?? 'dark'
764
734
  const schemeColor = colorScheme === 'light' ? themeColor.light : themeColor.dark
765
735
  const backgroundColor = options.backgroundColor ?? schemeColor
766
- const bootStyle = buildBootStyle({
736
+ const bootTags = buildBootTags({
767
737
  colorScheme,
768
738
  themeColor,
769
739
  backgroundColor,
770
740
  explicitBackground: options.backgroundColor !== undefined,
741
+ bootScript: options.bootScript !== false,
771
742
  })
772
743
 
773
744
  // Icon hrefs, the manifest link, and the manifest's start_url/scope/icon src all depend on
@@ -805,7 +776,7 @@ function createMainPlugin(options: BasaltAppOptions): Plugin {
805
776
  options,
806
777
  shortName,
807
778
  themeColor,
808
- bootStyle,
779
+ bootTags,
809
780
  icons,
810
781
  darkreader,
811
782
  manifestEnabled,
@@ -907,7 +878,7 @@ function createServiceWorkerPlugin(
907
878
  * • It HOISTS the shell's `<meta charset>` ahead of everything it injects, so the encoding
908
879
  * declaration stays inside the spec's first 1024 bytes (see `hoistCharset`).
909
880
  * • The anti-FOUC `<style>` expires the moment Mantine resolves the real scheme, and `colorScheme`
910
- * selects which surface it paints until then (see `BOOT_SCOPE` / `buildBootStyle`).
881
+ * selects which surface it paints until then (see `./vite-boot.ts`).
911
882
  *
912
883
  * @example
913
884
  * // vite.config.ts