basalt-ui 2.8.0 → 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.
- package/CHANGELOG.md +186 -190
- package/MIGRATING.md +52 -13
- package/dist/cli/doctor-upgrade.d.ts +5 -4
- package/dist/cli/doctor-upgrade.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.js +23 -99
- package/dist/cli/doctor.d.ts +2 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +17 -13
- package/dist/cli/index.d.ts +15 -6
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +16 -27
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +9 -6
- package/dist/cli/router-wiring.d.ts +37 -0
- package/dist/cli/router-wiring.d.ts.map +1 -0
- package/dist/cli/router-wiring.js +116 -0
- package/dist/cli/source-text.d.ts +12 -0
- package/dist/cli/source-text.d.ts.map +1 -0
- package/dist/cli/source-text.js +46 -0
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +15 -10
- package/dist/content/code-block.d.ts.map +1 -1
- package/dist/content/code-block.js +36 -27
- package/dist/content/code-block.module.css +19 -1
- package/dist/content/mermaid-sanitize.d.ts +15 -0
- package/dist/content/mermaid-sanitize.d.ts.map +1 -0
- package/dist/content/mermaid-sanitize.js +28 -0
- package/dist/content/mermaid.d.ts +6 -0
- package/dist/content/mermaid.d.ts.map +1 -1
- package/dist/content/mermaid.js +3 -1
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/provider/index.js +3 -2
- package/dist/vite-boot.d.ts +25 -0
- package/dist/vite-boot.d.ts.map +1 -0
- package/dist/vite-boot.js +36 -0
- package/dist/vite.d.ts +24 -3
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +7 -16
- package/llms.txt +4 -3
- package/package.json +1 -1
- package/src/cli/doctor-upgrade.ts +29 -145
- package/src/cli/doctor.ts +19 -14
- package/src/cli/index.ts +26 -41
- package/src/cli/init.ts +9 -6
- package/src/cli/router-wiring.ts +185 -0
- package/src/cli/source-text.ts +62 -0
- package/src/cli/sync.ts +17 -10
- package/src/content/code-block.module.css +19 -1
- package/src/content/code-block.tsx +7 -2
- package/src/content/mermaid-sanitize.ts +49 -0
- package/src/content/mermaid.tsx +3 -2
- package/src/provider/index.tsx +6 -3
- package/src/vite-boot.ts +109 -0
- package/src/vite.ts +32 -61
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 `
|
|
248
|
+
* writes `data-mantine-color-scheme` on `<html>` (see `./vite-boot.ts`).
|
|
247
249
|
*/
|
|
248
|
-
colorScheme?:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
596
|
-
tags.push(
|
|
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
|
|
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
|
-
|
|
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 `
|
|
881
|
+
* selects which surface it paints until then (see `./vite-boot.ts`).
|
|
911
882
|
*
|
|
912
883
|
* @example
|
|
913
884
|
* // vite.config.ts
|