basalt-ui 2.8.1 → 2.9.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/AGENTS.md +2 -2
- package/CHANGELOG.md +33 -0
- package/MIGRATING.md +81 -27
- package/README.md +7 -8
- package/agent/rules/basalt-controls.md +1 -1
- package/agent/rules/basalt-state.md +1 -1
- package/agent/skills/basalt-design/SKILL.md +1 -1
- package/agent/templates/AGENTS-block.md.tpl +2 -2
- package/configs/oxlint-plugin.js +25 -68
- package/configs/oxlint-plugin.test.ts +19 -27
- package/configs/oxlint.json +4 -0
- package/dist/charts/BandStrip.d.ts +1 -1
- package/dist/charts/BandStrip.d.ts.map +1 -1
- package/dist/charts/BandStrip.js +1 -10
- package/dist/charts/MirroredBars.d.ts.map +1 -1
- package/dist/charts/MirroredBars.js +2 -9
- package/dist/charts/band-fold.d.ts +15 -0
- package/dist/charts/band-fold.d.ts.map +1 -0
- package/dist/charts/band-fold.js +19 -0
- package/dist/charts/index.d.ts +1 -0
- package/dist/charts/index.d.ts.map +1 -1
- package/dist/charts/index.js +3 -1
- package/dist/cli/audit-allows.d.ts.map +1 -1
- package/dist/cli/audit-allows.js +1 -1
- package/dist/cli/check-theme.d.ts.map +1 -1
- package/dist/cli/check-theme.js +4 -1
- package/dist/cli/config.d.ts +14 -4
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +7 -2
- package/dist/cli/doctor-upgrade.d.ts +9 -0
- package/dist/cli/doctor-upgrade.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.js +14 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +10 -12
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +2 -3
- package/dist/cli/index.d.ts +3 -2
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +4 -2
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +6 -0
- package/dist/cli/install-root.d.ts +10 -0
- package/dist/cli/install-root.d.ts.map +1 -0
- package/dist/cli/install-root.js +32 -0
- package/dist/cli/router-wiring.d.ts +4 -2
- package/dist/cli/router-wiring.d.ts.map +1 -1
- package/dist/cli/router-wiring.js +2 -0
- package/dist/cli/sync.d.ts +0 -2
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +19 -15
- package/dist/cli/tokens-css.d.ts.map +1 -1
- package/dist/cli/tokens-css.js +1 -6
- package/dist/common/errors.d.ts +1 -6
- package/dist/common/errors.d.ts.map +1 -1
- package/dist/common/errors.js +0 -7
- package/dist/common/index.d.ts +1 -1
- package/dist/common/index.d.ts.map +1 -1
- package/dist/common/index.js +1 -9
- package/dist/common/props.d.ts +2 -2
- package/dist/common/vx-family.d.ts +1 -1
- package/dist/content/toc-click-pin.d.ts +45 -0
- package/dist/content/toc-click-pin.d.ts.map +1 -0
- package/dist/content/toc-click-pin.js +111 -0
- package/dist/content/toc-spy.d.ts +25 -0
- package/dist/content/toc-spy.d.ts.map +1 -0
- package/dist/content/toc-spy.js +43 -0
- package/dist/content/toc.d.ts +1 -4
- package/dist/content/toc.d.ts.map +1 -1
- package/dist/content/toc.js +38 -49
- package/dist/controls/number-filter.d.ts.map +1 -1
- package/dist/controls/number-filter.js +1 -1
- package/dist/dashboard/index.d.ts +1 -1
- package/dist/dashboard/index.d.ts.map +1 -1
- package/dist/dashboard/index.js +1 -3
- package/dist/dashboard/section.d.ts +10 -2
- package/dist/dashboard/section.d.ts.map +1 -1
- package/dist/dashboard/section.js +20 -3
- package/dist/dashboard/stat-card.d.ts +2 -8
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +1 -1
- package/dist/guard/index.d.ts +13 -9
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +74 -37
- package/dist/guard/types.d.ts +8 -7
- package/dist/guard/types.d.ts.map +1 -1
- package/dist/guard/vx-names.d.ts +1 -1
- package/dist/guard/vx-names.d.ts.map +1 -1
- package/dist/guard/vx-names.js +1 -33
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/router-tanstack/search-store.d.ts +1 -11
- package/dist/router-tanstack/search-store.d.ts.map +1 -1
- package/dist/router-tanstack/search-store.js +1 -2
- package/dist/shell/index.d.ts +1 -0
- package/dist/shell/index.d.ts.map +1 -1
- package/dist/shell/index.js +3 -0
- package/dist/shell/nav-types.d.ts +1 -1
- package/dist/shell/page-bar.d.ts +6 -0
- package/dist/shell/page-bar.d.ts.map +1 -1
- package/dist/shell/page-bar.js +12 -2
- package/dist/state/fields.d.ts +1 -1
- package/dist/state/fields.d.ts.map +1 -1
- package/dist/state/fields.js +3 -1
- package/dist/surfaces.d.ts +1 -1
- package/dist/surfaces.d.ts.map +1 -1
- package/dist/surfaces.js +5 -11
- package/dist/table/data-table.d.ts +2 -2
- package/dist/tokens/core.d.ts +0 -10
- package/dist/tokens/core.d.ts.map +1 -1
- package/dist/tokens/core.js +6 -44
- package/llms.txt +24 -8
- package/package.json +8 -5
- package/src/charts/BandStrip.tsx +4 -16
- package/src/charts/MirroredBars.tsx +2 -11
- package/src/charts/band-fold.ts +26 -0
- package/src/charts/index.ts +1 -0
- package/src/cli/audit-allows.ts +1 -3
- package/src/cli/check-theme.ts +7 -1
- package/src/cli/config.ts +21 -5
- package/src/cli/doctor-upgrade.ts +23 -1
- package/src/cli/doctor.ts +10 -17
- package/src/cli/help.ts +1 -4
- package/src/cli/index.ts +9 -6
- package/src/cli/init.ts +7 -0
- package/src/cli/install-root.ts +40 -0
- package/src/cli/router-wiring.ts +6 -2
- package/src/cli/sync.ts +28 -17
- package/src/cli/tokens-css.ts +0 -5
- package/src/common/errors.ts +1 -18
- package/src/common/index.ts +1 -8
- package/src/common/props.ts +2 -2
- package/src/common/vx-family.ts +1 -1
- package/src/content/toc-click-pin.ts +156 -0
- package/src/content/toc-spy.ts +61 -0
- package/src/content/toc.tsx +47 -95
- package/src/controls/form-layout.tsx +1 -1
- package/src/controls/number-filter.tsx +6 -1
- package/src/dashboard/index.ts +1 -6
- package/src/dashboard/section.tsx +39 -8
- package/src/dashboard/stat-card.tsx +4 -11
- package/src/guard/index.ts +114 -89
- package/src/guard/types.ts +8 -7
- package/src/guard/vx-names.ts +1 -33
- package/src/index.ts +1 -2
- package/src/router-tanstack/search-store.ts +2 -14
- package/src/shell/index.tsx +2 -0
- package/src/shell/nav-types.ts +1 -1
- package/src/shell/page-bar.tsx +21 -2
- package/src/state/fields.ts +7 -2
- package/src/surfaces.ts +5 -11
- package/src/table/data-table.tsx +2 -2
- package/src/tokens/core.ts +6 -67
- package/dist/tokens.css +0 -331
|
@@ -6,12 +6,13 @@ import { writeFileSync } from 'node:fs'
|
|
|
6
6
|
import { createRequire } from 'node:module'
|
|
7
7
|
import { dirname, relative, resolve } from 'node:path'
|
|
8
8
|
|
|
9
|
-
import { BASALT_CONFIG_KEYS, RETIRED_CONFIG_KEYS } from './config'
|
|
9
|
+
import { BASALT_CONFIG_KEYS, RETIRED_CONFIG_KEYS, shellConfigError } from './config'
|
|
10
10
|
import type { BasaltConfig } from './config'
|
|
11
11
|
import { parseJsonc, routerSeedDest, scannableFiles } from './index'
|
|
12
12
|
import type { BasaltInstall } from './index'
|
|
13
13
|
import {
|
|
14
14
|
appEntry,
|
|
15
|
+
callsIn,
|
|
15
16
|
hasRouteTree,
|
|
16
17
|
hasRouter,
|
|
17
18
|
isCodeRoutedApp,
|
|
@@ -451,6 +452,27 @@ export function startWiringWarnings(cwd: string): string[] {
|
|
|
451
452
|
return out
|
|
452
453
|
}
|
|
453
454
|
|
|
455
|
+
const BASALT_SHELL_TAG = /<BasaltShell\b/g
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* `basalt.shell: false` is a declaration, never a heuristic — but a declaration can go stale: warn
|
|
459
|
+
* when a module reachable from the entry renders `<BasaltShell` (JSX open tag, outside literals),
|
|
460
|
+
* and fail on a non-boolean value. Empty when `shell` is not `false`.
|
|
461
|
+
*/
|
|
462
|
+
export function shellDeclarationFindings(
|
|
463
|
+
cwd: string,
|
|
464
|
+
cfg: BasaltConfig,
|
|
465
|
+
): { fail: string | null; warnings: string[] } {
|
|
466
|
+
const fail = shellConfigError(cfg)
|
|
467
|
+
if (cfg.shell !== false || !callsIn(cwd, appEntry(cwd), BASALT_SHELL_TAG)) {
|
|
468
|
+
return { fail, warnings: [] }
|
|
469
|
+
}
|
|
470
|
+
return {
|
|
471
|
+
fail,
|
|
472
|
+
warnings: ['declared basalt.shell: false but the app renders BasaltShell — drop the key.'],
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
454
476
|
/**
|
|
455
477
|
* `app-wiring`: the entry module `index.html` loads (default src/main.tsx) mounts `BasaltProvider`
|
|
456
478
|
* on a `createBasaltRouter` router (called in the entry or a module it imports), and the router tree
|
package/src/cli/doctor.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { relative, resolve } from 'node:path'
|
|
|
9
9
|
import {
|
|
10
10
|
AGENTS_MD,
|
|
11
11
|
LEGACY_BLOCK_HOST,
|
|
12
|
+
scanBlock,
|
|
12
13
|
MANIFEST_PATH,
|
|
13
14
|
basaltBinCommand,
|
|
14
15
|
basaltPresetEntry,
|
|
@@ -31,12 +32,12 @@ import {
|
|
|
31
32
|
ROUTER_SEED_DESTS,
|
|
32
33
|
sameFile,
|
|
33
34
|
scannableFiles,
|
|
34
|
-
scanBlock,
|
|
35
35
|
shippedAssetPath,
|
|
36
36
|
} from './index'
|
|
37
37
|
import { resolveRoots } from './config'
|
|
38
38
|
import {
|
|
39
39
|
appWiringCheck,
|
|
40
|
+
shellDeclarationFindings,
|
|
40
41
|
startWiringWarnings,
|
|
41
42
|
droppedSubpathsCheck,
|
|
42
43
|
exactPeersCheck,
|
|
@@ -47,7 +48,8 @@ import {
|
|
|
47
48
|
unknownConfigKeysCheck,
|
|
48
49
|
} from './doctor-upgrade'
|
|
49
50
|
import type { Check } from './doctor-upgrade'
|
|
50
|
-
import { findManifestAbove,
|
|
51
|
+
import { findManifestAbove, installRootAbove } from './install-root'
|
|
52
|
+
import { parentInstallAdvice } from './sync'
|
|
51
53
|
|
|
52
54
|
/** `sameFile`, but doctor never crashes: a path that cannot be inspected is "not provably the same". */
|
|
53
55
|
function isSameFile(a: string, b: string): boolean {
|
|
@@ -123,17 +125,9 @@ export function doctor(invocationCwd: string = process.cwd(), flags: string[] =
|
|
|
123
125
|
if (conflictingProfileFlags('doctor', flags)) return 1
|
|
124
126
|
const project = resolveProjectDir(invocationCwd)
|
|
125
127
|
// Inside the app package of a monorepo the manifest is above: read the install root instead.
|
|
126
|
-
const aboveRoot =
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
: null
|
|
130
|
-
const insideApp =
|
|
131
|
-
aboveRoot !== null &&
|
|
132
|
-
(() => {
|
|
133
|
-
const app = resolveAppDir(aboveRoot)
|
|
134
|
-
return !('error' in app) && app.dir === project.dir
|
|
135
|
-
})()
|
|
136
|
-
const cwd = insideApp && aboveRoot !== null ? aboveRoot : project.dir
|
|
128
|
+
const aboveRoot = project.relocatedFrom === null ? installRootAbove(project.dir) : null
|
|
129
|
+
const insideApp = aboveRoot !== null
|
|
130
|
+
const cwd = aboveRoot ?? project.dir
|
|
137
131
|
const cfg = readBasaltConfig(cwd)
|
|
138
132
|
const result: DoctorResult = { hardFailures: 0, warnings: 0, skipped: 0 }
|
|
139
133
|
const lines: string[] = [`\nbasalt-ui doctor — ${cwd}\n`]
|
|
@@ -319,10 +313,6 @@ export function doctor(invocationCwd: string = process.cwd(), flags: string[] =
|
|
|
319
313
|
const issues: string[] = []
|
|
320
314
|
if (scan.problem !== null) {
|
|
321
315
|
issues.push(`has a malformed basalt block (${scan.problem}) — fix it by hand, then \`sync\``)
|
|
322
|
-
} else if (scan.region !== null) {
|
|
323
|
-
issues.push(
|
|
324
|
-
`still carries a stale basalt block — delete it by hand; \`sync\` keeps ${AGENTS_MD} current`,
|
|
325
|
-
)
|
|
326
316
|
}
|
|
327
317
|
if (!importsAgentsMd(legacy)) {
|
|
328
318
|
issues.push(
|
|
@@ -425,6 +415,9 @@ export function doctor(invocationCwd: string = process.cwd(), flags: string[] =
|
|
|
425
415
|
],
|
|
426
416
|
])
|
|
427
417
|
for (const line of startWiringWarnings(appDir)) warn(line)
|
|
418
|
+
const shell = shellDeclarationFindings(appDir, cfg)
|
|
419
|
+
if (shell.fail !== null) fail(shell.fail)
|
|
420
|
+
for (const line of shell.warnings) warn(line)
|
|
428
421
|
}
|
|
429
422
|
|
|
430
423
|
// ── Report ──────────────────────────────────────────────────────────────────
|
package/src/cli/help.ts
CHANGED
|
@@ -41,7 +41,6 @@ export const COMMAND_OPTIONS: Record<string, Record<string, { type: 'string' | '
|
|
|
41
41
|
'default-scheme': { type: 'string' },
|
|
42
42
|
'media-fallback': { type: 'boolean' },
|
|
43
43
|
only: { type: 'string' },
|
|
44
|
-
'no-legacy-aliases': { type: 'boolean' },
|
|
45
44
|
},
|
|
46
45
|
'fonts:css': { out: { type: 'string' }, check: { type: 'boolean' } },
|
|
47
46
|
}
|
|
@@ -75,12 +74,10 @@ export const USAGE =
|
|
|
75
74
|
'tokens:css [--out <path>] [--check] [--selector-attribute <attr> | --selector-class <class>]\n' +
|
|
76
75
|
' [--light-class <class>] [--dark-value <v>] [--light-value <v>]\n' +
|
|
77
76
|
' [--default-scheme <dark|light|none>] [--media-fallback] [--only <core|all>]\n' +
|
|
78
|
-
' [--no-legacy-aliases]\n' +
|
|
79
77
|
' Emit the --vx-* stylesheet (stdout unless --out). Defaults emit the stock identity; commit the output as your tokens file.\n' +
|
|
80
78
|
' --selector-class emits `:root.dark` instead of an attribute selector (the Tailwind convention).\n' +
|
|
81
79
|
' --check writes nothing and exits 1 when --out differs from what would be emitted (a CI gate).\n' +
|
|
82
|
-
'
|
|
83
|
-
' which are emitted by default as aliases of the canonical kebab-case names.\n\n' +
|
|
80
|
+
'\n' +
|
|
84
81
|
'fonts:css [--out <path>] [--check]\n' +
|
|
85
82
|
' Emit the shipped --basalt-font-* stacks as plain CSS — the typeface half of the token layer,\n' +
|
|
86
83
|
' otherwise reachable only by importing styles.css.\n\n' +
|
package/src/cli/index.ts
CHANGED
|
@@ -29,7 +29,7 @@ import { guardHook } from './guard-hook'
|
|
|
29
29
|
import { COMMAND_OPTIONS, USAGE, unknownFlag } from './help'
|
|
30
30
|
import { init } from './init'
|
|
31
31
|
import { sync } from './sync'
|
|
32
|
-
import { CODE_ROUTED_NOTE, routerSeedSkip } from './router-wiring'
|
|
32
|
+
import { CODE_ROUTED_NOTE, SHELL_LESS_NOTE, routerSeedSkip } from './router-wiring'
|
|
33
33
|
import type { RouterSeedSkip } from './router-wiring'
|
|
34
34
|
import { hasDependency, readIfExists, readPackageJson } from './source-text'
|
|
35
35
|
import { fontsCss, normalizeColorFunctions, tokensCss } from './tokens-css'
|
|
@@ -666,21 +666,25 @@ export const START_APP_NOTE =
|
|
|
666
666
|
'<BasaltProvider><Outlet /></BasaltProvider> in your root route component.'
|
|
667
667
|
|
|
668
668
|
/**
|
|
669
|
-
* The router seeds an app does not get, for `init` and `sync`: why (`start` | `code-routed` |
|
|
670
|
-
* and which dests. A tokens-only consumer gets none of them either
|
|
669
|
+
* The router seeds an app does not get, for `init` and `sync`: why (`start` | `code-routed` |
|
|
670
|
+
* `shell-less` | null) and which dests. A tokens-only consumer gets none of them either; so does an
|
|
671
|
+
* app that declares `basalt.shell: false` — the nav and root seeds are a pair, so the whole set goes.
|
|
671
672
|
*/
|
|
672
673
|
export function routerSeedPlan(
|
|
673
674
|
cwd: string,
|
|
674
675
|
appRel: string,
|
|
675
676
|
tokensOnly = false,
|
|
676
677
|
): { skip: RouterSeedSkip; skipped: Set<string> } {
|
|
677
|
-
const
|
|
678
|
+
const detected = tokensOnly ? null : routerSeedSkip(cwd, appRel)
|
|
679
|
+
const skip =
|
|
680
|
+
detected ?? (!tokensOnly && readBasaltConfig(cwd).shell === false ? 'shell-less' : null)
|
|
678
681
|
return { skip, skipped: new Set(tokensOnly || skip !== null ? routerSeedDests(appRel) : []) }
|
|
679
682
|
}
|
|
680
683
|
|
|
681
684
|
/** The note `init` prints for a router-seed skip, or null when nothing was skipped. */
|
|
682
685
|
export function seedSkipNote(skip: RouterSeedSkip): string | null {
|
|
683
686
|
if (skip === 'start') return START_APP_NOTE
|
|
687
|
+
if (skip === 'shell-less') return SHELL_LESS_NOTE
|
|
684
688
|
return skip === 'code-routed' ? CODE_ROUTED_NOTE : null
|
|
685
689
|
}
|
|
686
690
|
|
|
@@ -845,8 +849,7 @@ export function managedFiles(placement: PlacementFlags = ROOT_PLACEMENT): Manage
|
|
|
845
849
|
},
|
|
846
850
|
}
|
|
847
851
|
|
|
848
|
-
// Scaffold destination is `.oxfmtrc.json` — oxfmt auto-discovers that filename, not `oxfmt.json
|
|
849
|
-
// (the pre-rename scaffold; see migrateLegacyOxfmt for the one-time cleanup of the old dest).
|
|
852
|
+
// Scaffold destination is `.oxfmtrc.json` — oxfmt auto-discovers that filename, not `oxfmt.json`.
|
|
850
853
|
// Content is a starting copy, not a reference — oxfmt has no `extends` mechanism.
|
|
851
854
|
const oxfmt: ManagedFile = {
|
|
852
855
|
dest: '.oxfmtrc.json',
|
package/src/cli/init.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { existsSync } from 'node:fs'
|
|
|
7
7
|
import { resolve } from 'node:path'
|
|
8
8
|
|
|
9
9
|
import { deriveSpacing } from '../tokens/core'
|
|
10
|
+
import { shellConfigError } from './config'
|
|
10
11
|
import type { MergeLintResult, ScaffoldFlags } from './index'
|
|
11
12
|
import {
|
|
12
13
|
MANIFEST_PATH,
|
|
@@ -83,6 +84,12 @@ export function init(cwd: string = process.cwd(), scaffoldFlags: ScaffoldFlags =
|
|
|
83
84
|
)
|
|
84
85
|
}
|
|
85
86
|
|
|
87
|
+
const shellError = shellConfigError(readBasaltConfig(cwd))
|
|
88
|
+
if (shellError !== null) {
|
|
89
|
+
console.error(`✖ basalt-ui init: ${shellError}`)
|
|
90
|
+
return 1
|
|
91
|
+
}
|
|
92
|
+
|
|
86
93
|
const appError = resolvePlacement(cwd).appError
|
|
87
94
|
if (appError !== null) {
|
|
88
95
|
console.error(`✖ basalt-ui init: ${appError}`)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Which install root a project-scoped command run inside a workspace package reads — one answer for `doctor` and `sync`. */
|
|
2
|
+
import { existsSync, realpathSync } from 'node:fs'
|
|
3
|
+
import { resolve } from 'node:path'
|
|
4
|
+
|
|
5
|
+
import { MANIFEST_PATH, findBasaltInstall, resolveAppDir } from './index'
|
|
6
|
+
import { hasDependency } from './source-text'
|
|
7
|
+
|
|
8
|
+
/** The nearest ANCESTOR of `dir` (exclusive) carrying a basalt manifest, or null. */
|
|
9
|
+
export function findManifestAbove(dir: string): string | null {
|
|
10
|
+
let current = resolve(dir, '..')
|
|
11
|
+
for (;;) {
|
|
12
|
+
if (existsSync(resolve(current, MANIFEST_PATH))) return current
|
|
13
|
+
const parent = resolve(current, '..')
|
|
14
|
+
if (parent === current) return null
|
|
15
|
+
current = parent
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function sameInstall(a: string | null, b: string | null): boolean {
|
|
20
|
+
if (a === null || b === null) return false
|
|
21
|
+
return a === b || realpathSync(a) === realpathSync(b)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The install root above `dir`, when `dir` is the APP package of that install: no manifest here,
|
|
26
|
+
* basalt-ui declared here, an ancestor manifest, `resolveAppDir(root)` naming `dir`, and the
|
|
27
|
+
* basalt-ui that resolves from `dir` the same copy (or version) the root uses. Anything else is
|
|
28
|
+
* null — a sub-package with its own basalt-ui is a competing install, not part of the root's.
|
|
29
|
+
*/
|
|
30
|
+
export function installRootAbove(dir: string): string | null {
|
|
31
|
+
if (existsSync(resolve(dir, MANIFEST_PATH)) || !hasDependency(dir, 'basalt-ui')) return null
|
|
32
|
+
const root = findManifestAbove(dir)
|
|
33
|
+
if (root === null) return null
|
|
34
|
+
const app = resolveAppDir(root)
|
|
35
|
+
if ('error' in app || app.dir !== dir) return null
|
|
36
|
+
const here = findBasaltInstall(dir)
|
|
37
|
+
const there = findBasaltInstall(root)
|
|
38
|
+
const sameVersion = here.version !== null && here.version === there.version
|
|
39
|
+
return sameInstall(here.dir, there.dir) || sameVersion ? root : null
|
|
40
|
+
}
|
package/src/cli/router-wiring.ts
CHANGED
|
@@ -170,16 +170,20 @@ export function isStartApp(cwd: string, appRel: string): boolean {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
/** Why an app's router seeds are not placed (see `routerSeedSkip`). */
|
|
173
|
-
export type RouterSeedSkip = 'start' | 'code-routed' | null
|
|
173
|
+
export type RouterSeedSkip = 'start' | 'code-routed' | 'shell-less' | null
|
|
174
174
|
|
|
175
175
|
export const CODE_ROUTED_NOTE =
|
|
176
176
|
'code-routed app (createBasaltRouter, no route-tree plugin or routeTree.gen) — no main.tsx/nav.tsx/__root.tsx seeded.'
|
|
177
177
|
|
|
178
178
|
/**
|
|
179
179
|
* Why an app's router seeds (main/nav/__root) are not placed: `start` (Start owns the router, and
|
|
180
|
-
* wins when both apply) or `code-routed` (no generated tree to assume); null when they are.
|
|
180
|
+
* wins when both apply) or `code-routed` (no generated tree to assume); null when they are. The
|
|
181
|
+
* declared `shell: false` (`shell-less`) is applied by `routerSeedPlan`, which reads the config.
|
|
181
182
|
*/
|
|
182
183
|
export function routerSeedSkip(cwd: string, appRel: string): RouterSeedSkip {
|
|
183
184
|
if (isStartApp(cwd, appRel)) return 'start'
|
|
184
185
|
return isCodeRoutedApp(cwd, appRel) ? 'code-routed' : null
|
|
185
186
|
}
|
|
187
|
+
|
|
188
|
+
export const SHELL_LESS_NOTE =
|
|
189
|
+
'`basalt.shell: false` — no main.tsx/nav.tsx/__root.tsx seeded; the app owns its root route (or has none).'
|
package/src/cli/sync.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { existsSync } from 'node:fs'
|
|
|
3
3
|
import { resolve } from 'node:path'
|
|
4
4
|
|
|
5
5
|
import { deriveSpacing } from '../tokens/core'
|
|
6
|
+
import { shellConfigError } from './config'
|
|
6
7
|
import {
|
|
7
8
|
MANIFEST_PATH,
|
|
8
9
|
basaltPresetEntry,
|
|
@@ -39,6 +40,7 @@ import {
|
|
|
39
40
|
writeFileEnsuringDir,
|
|
40
41
|
writeUnit,
|
|
41
42
|
} from './index'
|
|
43
|
+
import { findManifestAbove, installRootAbove } from './install-root'
|
|
42
44
|
|
|
43
45
|
/** The oxlint plugins the shipped preset switches on — read from the preset, never restated. */
|
|
44
46
|
export function readOxlintPresetPlugins(pkgRoot: string): string[] {
|
|
@@ -64,17 +66,6 @@ export function parentInstallAdvice(cwd: string, parent: string, verb: string):
|
|
|
64
66
|
)
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
/** The nearest ANCESTOR of `dir` (exclusive) carrying a basalt manifest, or null. */
|
|
68
|
-
export function findManifestAbove(dir: string): string | null {
|
|
69
|
-
let current = resolve(dir, '..')
|
|
70
|
-
for (;;) {
|
|
71
|
-
if (existsSync(resolve(current, MANIFEST_PATH))) return current
|
|
72
|
-
const parent = resolve(current, '..')
|
|
73
|
-
if (parent === current) return null
|
|
74
|
-
current = parent
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
69
|
/**
|
|
79
70
|
* Reconcile managed files with the shipped versions via a sha256 three-way compare.
|
|
80
71
|
*
|
|
@@ -89,8 +80,15 @@ export function sync(opts: SyncOptions = {}, invocationCwd: string = process.cwd
|
|
|
89
80
|
const syncFlags = opts.flags ?? []
|
|
90
81
|
if (conflictingProfileFlags('sync', syncFlags)) return 1
|
|
91
82
|
const project = resolveProjectDir(invocationCwd)
|
|
92
|
-
const cwd = project.dir
|
|
93
83
|
noteRelocation('sync', project)
|
|
84
|
+
// Inside the app package of a workspace the manifest is at the install root above: sync there.
|
|
85
|
+
const installAbove = project.relocatedFrom === null ? installRootAbove(project.dir) : null
|
|
86
|
+
const cwd = installAbove ?? project.dir
|
|
87
|
+
if (installAbove !== null) {
|
|
88
|
+
console.log(
|
|
89
|
+
`basalt-ui sync: ${project.dir} is a package of the install at ${installAbove}; syncing there.`,
|
|
90
|
+
)
|
|
91
|
+
}
|
|
94
92
|
|
|
95
93
|
// Profile before the refusal: init is NOT the fix for a tokens-only consumer. Declared, never
|
|
96
94
|
// inferred (the answer silences the whole reconciliation); exits 0 so `sync --check` is wirable.
|
|
@@ -103,6 +101,12 @@ export function sync(opts: SyncOptions = {}, invocationCwd: string = process.cwd
|
|
|
103
101
|
return 0
|
|
104
102
|
}
|
|
105
103
|
|
|
104
|
+
const shellError = shellConfigError(readBasaltConfig(cwd))
|
|
105
|
+
if (shellError !== null) {
|
|
106
|
+
console.error(`✖ basalt-ui sync: ${shellError}`)
|
|
107
|
+
return 1
|
|
108
|
+
}
|
|
109
|
+
|
|
106
110
|
const appError = resolvePlacement(cwd).appError
|
|
107
111
|
if (appError !== null) {
|
|
108
112
|
console.error(`✖ basalt-ui sync: ${appError}`)
|
|
@@ -203,13 +207,20 @@ export function sync(opts: SyncOptions = {}, invocationCwd: string = process.cwd
|
|
|
203
207
|
})
|
|
204
208
|
staleForCheck += pruned.removed.length + pruned.drifted.length
|
|
205
209
|
|
|
206
|
-
// A code-routed app takes no router seeds: their manifest entries go
|
|
210
|
+
// A code-routed or declared shell-less app takes no router seeds: their manifest entries go
|
|
211
|
+
// (so the next sync does not resurrect them); any file stays the consumer's.
|
|
207
212
|
const isTracked = (d: string): boolean => manifest.files[d] !== undefined
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
213
|
+
const retiredBecause =
|
|
214
|
+
seedSkip === 'code-routed'
|
|
215
|
+
? 'code-routed app'
|
|
216
|
+
: seedSkip === 'shell-less'
|
|
217
|
+
? 'basalt.shell: false'
|
|
218
|
+
: null
|
|
219
|
+
const retiredSeeds = retiredBecause === null ? [] : [...skipped].filter(isTracked)
|
|
220
|
+
if (retiredSeeds.length > 0 && !opts.check) {
|
|
221
|
+
for (const d of retiredSeeds) delete manifest.files[d]
|
|
211
222
|
console.error(
|
|
212
|
-
`⚠ basalt-ui sync:
|
|
223
|
+
`⚠ basalt-ui sync: ${retiredBecause} — dropped ${retiredSeeds.join(', ')} from the manifest (any file is yours).`,
|
|
213
224
|
)
|
|
214
225
|
}
|
|
215
226
|
|
package/src/cli/tokens-css.ts
CHANGED
|
@@ -168,11 +168,6 @@ export function tokensCss(flags: string[], cwd: string = process.cwd()): number
|
|
|
168
168
|
: { defaultScheme: defaultScheme as 'dark' | 'light' | 'none' }),
|
|
169
169
|
...(flags.includes('--media-fallback') ? { mediaFallback: true } : {}),
|
|
170
170
|
...(only === undefined ? {} : { only: only as 'core' | 'all' }),
|
|
171
|
-
// The tokens-only consumer is exactly the one who writes these names by hand, so they are also
|
|
172
|
-
// the one who wants the deprecated camelCase aliases gone — and this command is their only
|
|
173
|
-
// entry point. Without the flag the CLI and the API could disagree about what basalt's tokens
|
|
174
|
-
// are, which is the one thing this command is documented never to allow.
|
|
175
|
-
...(flags.includes('--no-legacy-aliases') ? { legacyAliases: false } : {}),
|
|
176
171
|
})
|
|
177
172
|
|
|
178
173
|
if (schemeClass !== undefined) {
|
package/src/common/errors.ts
CHANGED
|
@@ -39,28 +39,11 @@ export function oneOf(
|
|
|
39
39
|
)
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
/**
|
|
43
|
-
* A prop still shipped and still working, with a named successor and the version it goes away in.
|
|
44
|
-
* Majors are banned here, so the deprecation notice IS the migration channel.
|
|
45
|
-
*/
|
|
46
|
-
export function deprecatedProp(
|
|
47
|
-
component: string,
|
|
48
|
-
oldProp: string,
|
|
49
|
-
newProp: string,
|
|
50
|
-
removeIn: string,
|
|
51
|
-
note?: string,
|
|
52
|
-
): string {
|
|
53
|
-
return message(
|
|
54
|
-
component,
|
|
55
|
-
`prop "${oldProp}" is deprecated — use "${newProp}" instead. "${oldProp}" is removed in ${removeIn}.${note === undefined ? '' : ` ${note}`}`,
|
|
56
|
-
)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
42
|
/**
|
|
60
43
|
* A prop the component ACCEPTS, reads nothing from, and cannot report as wrong — because a SECOND
|
|
61
44
|
* prop it was passed alongside decides the same thing and won.
|
|
62
45
|
*
|
|
63
|
-
* Distinct from {@link
|
|
46
|
+
* Distinct from {@link oneOf} (read, and the
|
|
64
47
|
* value is out of range): this one renders something the caller did not ask for and nothing in the
|
|
65
48
|
* type system, the linter or the console says so. A 1.x chart's `height` under `fill` was the
|
|
66
49
|
* reference case — weatherorb passed both for the life of the file and never learnt that eight height
|
package/src/common/index.ts
CHANGED
|
@@ -9,14 +9,7 @@
|
|
|
9
9
|
export { type BasaltProps, type SlotClassNames, type SlotStylesProps } from './props'
|
|
10
10
|
export { type Tone, type ToneWithNeutral, type Tier, cx } from './props'
|
|
11
11
|
export { assignRef, mergeRefs } from './refs'
|
|
12
|
-
export {
|
|
13
|
-
BASALT_PREFIX,
|
|
14
|
-
requiredProp,
|
|
15
|
-
oneOf,
|
|
16
|
-
deprecatedProp,
|
|
17
|
-
duplicateMount,
|
|
18
|
-
missingLayer,
|
|
19
|
-
} from './errors'
|
|
12
|
+
export { BASALT_PREFIX, requiredProp, oneOf, duplicateMount, missingLayer } from './errors'
|
|
20
13
|
export { useValidateProps, assertRequiredProps, resetValidatedProps } from './validate'
|
|
21
14
|
export { scrollParentOf, SCROLLPORT_ATTRIBUTE } from './scroll-parent'
|
|
22
15
|
export { useCoarsePointer } from './use-media-query'
|
package/src/common/props.ts
CHANGED
|
@@ -45,8 +45,8 @@ export interface SlotStylesProps<S extends string> {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
* The ONE status vocabulary (audit A13).
|
|
49
|
-
*
|
|
48
|
+
* The ONE status vocabulary (audit A13). Forks exist today — `SidebarBlockTone` is
|
|
49
|
+
* byte-identical to this, `CalloutKind` / `AccountBadgeTone` /
|
|
50
50
|
* `NotificationIntent` each differ — and they stay put for now: an adopter aliases its fork to this
|
|
51
51
|
* type, it does not get renamed out from under a consumer.
|
|
52
52
|
*/
|
package/src/common/vx-family.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A `--vx-*` name's FAMILY — its leading lowercase run: `--vx-surface-bg` → `surface`, `--vx-ink2`
|
|
3
|
-
* → `ink`, `--vx-
|
|
3
|
+
* → `ink`, `--vx-tooltip-bg` → `tooltip`, `--vx-fill-hover-cyan` → `fill`. Dependency-free, because
|
|
4
4
|
* three sides must agree on it byte for byte: the generator that writes `BASALT_VX_FAMILIES`, the
|
|
5
5
|
* guard that judges every name inside one of those families, and the token factories that refuse a
|
|
6
6
|
* consumer name inside one — the refusal is what makes the guard's judgement honest.
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which TOC entry the reader just ASKED for, until the page has caught up.
|
|
3
|
+
*
|
|
4
|
+
* idle ──click──▶ pinned{id} ──scrollend / 200 ms without scrolling──▶ held{id, top}
|
|
5
|
+
* ▲ │ scroll intent │ scroll moves > ε (any cause),
|
|
6
|
+
* └────────────────┴──────────────────────────────────────────┘ scroll intent, id gone, unmount
|
|
7
|
+
*
|
|
8
|
+
* The clicked heading rests under the sticky header, above the spy's band, so the spy cannot be
|
|
9
|
+
* trusted while the click's scroll is in flight; once it has settled the spy's own answer is right
|
|
10
|
+
* and the hold only has to cover the short-tail case. So: pinned while the scroll runs (until its
|
|
11
|
+
* `scrollend`, or until the scroller has been quiet for a moment where there is none), held where it
|
|
12
|
+
* settled, and handed back the moment
|
|
13
|
+
* the position moves for ANY reason — reader, find-in-page, focus, layout shift, app scroll.
|
|
14
|
+
*/
|
|
15
|
+
import { useEffect, useState } from 'react'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* How long the scroller must be quiet before a pinned click counts as settled: the fallback for a
|
|
19
|
+
* browser without a reliable `scrollend`, and the only signal for a click that needs no scroll.
|
|
20
|
+
*/
|
|
21
|
+
export const QUIET_MS = 200
|
|
22
|
+
/** Scroll movement tolerated while held (sub-pixel offsets, fractional DPR). */
|
|
23
|
+
export const HOLD_EPSILON_PX = 2
|
|
24
|
+
|
|
25
|
+
const SCROLL_KEYS: ReadonlySet<string> = new Set([
|
|
26
|
+
'PageUp',
|
|
27
|
+
'PageDown',
|
|
28
|
+
'Home',
|
|
29
|
+
'End',
|
|
30
|
+
'ArrowUp',
|
|
31
|
+
'ArrowDown',
|
|
32
|
+
' ',
|
|
33
|
+
])
|
|
34
|
+
|
|
35
|
+
/** Where the reader's input is aimed at text entry — through shadow roots, via the composed path. */
|
|
36
|
+
const isEditable = (event: Event): boolean =>
|
|
37
|
+
event
|
|
38
|
+
.composedPath()
|
|
39
|
+
.some(
|
|
40
|
+
(node) =>
|
|
41
|
+
node instanceof HTMLElement &&
|
|
42
|
+
(node.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(node.tagName)),
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
/** The document-level events that mean the reader is about to scroll (or may have). */
|
|
46
|
+
export const INTENT_EVENTS = ['wheel', 'touchstart', 'keydown', 'pointerdown'] as const
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Did the reader just do something that scrolls (or may scroll) the page? `link` is the rail link
|
|
50
|
+
* that was activated: pointing at it is the click itself, and Enter on it is not a scroll key.
|
|
51
|
+
*/
|
|
52
|
+
export function isScrollIntent(event: Event, link: Element | null): boolean {
|
|
53
|
+
switch (event.type) {
|
|
54
|
+
case 'wheel':
|
|
55
|
+
case 'touchstart':
|
|
56
|
+
return true
|
|
57
|
+
case 'pointerdown':
|
|
58
|
+
return !(event.target instanceof Node && link?.contains(event.target))
|
|
59
|
+
case 'keydown':
|
|
60
|
+
return event instanceof KeyboardEvent && SCROLL_KEYS.has(event.key) && !isEditable(event)
|
|
61
|
+
default:
|
|
62
|
+
return false
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function scrollTopOf(scroller: HTMLElement | null): number {
|
|
67
|
+
return scroller ? scroller.scrollTop : window.scrollY
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
type ClickPinState =
|
|
71
|
+
| { readonly kind: 'idle' }
|
|
72
|
+
| { readonly kind: 'pinned'; readonly id: string }
|
|
73
|
+
| { readonly kind: 'held'; readonly id: string; readonly top: number }
|
|
74
|
+
|
|
75
|
+
export class ClickPin {
|
|
76
|
+
private current: ClickPinState = { kind: 'idle' }
|
|
77
|
+
private stop: (() => void) | null = null
|
|
78
|
+
|
|
79
|
+
/** `onIdle` runs when the machine hands the rail back, so the spy can re-resolve. */
|
|
80
|
+
constructor(private readonly onIdle: () => void) {}
|
|
81
|
+
|
|
82
|
+
get state(): ClickPinState {
|
|
83
|
+
return this.current
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The entry the click owns (pinned or held), or `null` when the spy answers. A pure query. */
|
|
87
|
+
get activeId(): string | null {
|
|
88
|
+
return this.current.kind === 'idle' ? null : this.current.id
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** `link` is the rail link just activated; `scroller` the element the spy watches (`null` = document). */
|
|
92
|
+
click(id: string, link: Element | null, scroller: HTMLElement | null): void {
|
|
93
|
+
this.stop?.()
|
|
94
|
+
this.current = { kind: 'pinned', id }
|
|
95
|
+
|
|
96
|
+
const target: Window | HTMLElement = scroller ?? window
|
|
97
|
+
let quiet: ReturnType<typeof setTimeout> | undefined
|
|
98
|
+
const hold = () => {
|
|
99
|
+
clearTimeout(quiet)
|
|
100
|
+
if (this.current.kind !== 'pinned') return
|
|
101
|
+
this.current = { kind: 'held', id, top: scrollTopOf(scroller) }
|
|
102
|
+
}
|
|
103
|
+
const onScroll = () => {
|
|
104
|
+
const state = this.current
|
|
105
|
+
if (state.kind === 'pinned') {
|
|
106
|
+
clearTimeout(quiet)
|
|
107
|
+
quiet = setTimeout(hold, QUIET_MS)
|
|
108
|
+
} else if (
|
|
109
|
+
state.kind === 'held' &&
|
|
110
|
+
Math.abs(scrollTopOf(scroller) - state.top) > HOLD_EPSILON_PX
|
|
111
|
+
) {
|
|
112
|
+
this.release()
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const onIntent = (event: Event) => {
|
|
116
|
+
if (isScrollIntent(event, link)) this.release()
|
|
117
|
+
}
|
|
118
|
+
quiet = setTimeout(hold, QUIET_MS)
|
|
119
|
+
target.addEventListener('scrollend', hold, { once: true })
|
|
120
|
+
target.addEventListener('scroll', onScroll, { passive: true })
|
|
121
|
+
for (const type of INTENT_EVENTS) document.addEventListener(type, onIntent, { capture: true })
|
|
122
|
+
this.stop = () => {
|
|
123
|
+
clearTimeout(quiet)
|
|
124
|
+
target.removeEventListener('scrollend', hold)
|
|
125
|
+
target.removeEventListener('scroll', onScroll)
|
|
126
|
+
for (const type of INTENT_EVENTS) {
|
|
127
|
+
document.removeEventListener(type, onIntent, { capture: true })
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Items changed: a click on an id that no longer exists cannot stand. */
|
|
133
|
+
prune(ids: readonly string[]): void {
|
|
134
|
+
if (this.current.kind !== 'idle' && !ids.includes(this.current.id)) this.release()
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
release(): void {
|
|
138
|
+
if (this.current.kind === 'idle') return
|
|
139
|
+
this.dispose()
|
|
140
|
+
this.onIdle()
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Unmount: idle, timer and listeners gone, no callback. */
|
|
144
|
+
dispose(): void {
|
|
145
|
+
this.stop?.()
|
|
146
|
+
this.stop = null
|
|
147
|
+
this.current = { kind: 'idle' }
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** `onIdle` must be stable (a state setter): it is captured once, at construction. */
|
|
152
|
+
export function useClickPin(onIdle: () => void): ClickPin {
|
|
153
|
+
const [pin] = useState(() => new ClickPin(onIdle))
|
|
154
|
+
useEffect(() => () => pin.dispose(), [pin])
|
|
155
|
+
return pin
|
|
156
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/** The TOC scroll-spy's pure half: scroll geometry in, the reader's section out. */
|
|
2
|
+
|
|
3
|
+
/** Sub-pixel / fractional-DPR slack when asking "is the scrollport at its end". */
|
|
4
|
+
export const BOTTOM_EPSILON_PX = 2
|
|
5
|
+
/** Distance below the scrollport's top where a heading counts as reached (the observer's top inset). */
|
|
6
|
+
export const ACTIVATION_TOP_PX = 80
|
|
7
|
+
/** The observer's band: below the activation line, down to 30% of the scrollport. */
|
|
8
|
+
export const OBSERVER_ROOT_MARGIN = `-${ACTIVATION_TOP_PX}px 0px -70% 0px`
|
|
9
|
+
|
|
10
|
+
export type ScrollMetrics = {
|
|
11
|
+
readonly top: number
|
|
12
|
+
readonly scrollTop: number
|
|
13
|
+
readonly clientHeight: number
|
|
14
|
+
readonly scrollHeight: number
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The scrollport's geometry; `null` is the document, whose "top" is the viewport's. */
|
|
18
|
+
export function scrollMetrics(port: HTMLElement | null): ScrollMetrics {
|
|
19
|
+
if (port) {
|
|
20
|
+
return {
|
|
21
|
+
top: port.getBoundingClientRect().top,
|
|
22
|
+
scrollTop: port.scrollTop,
|
|
23
|
+
clientHeight: port.clientHeight,
|
|
24
|
+
scrollHeight: port.scrollHeight,
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
top: 0,
|
|
29
|
+
scrollTop: window.scrollY,
|
|
30
|
+
clientHeight: window.innerHeight,
|
|
31
|
+
scrollHeight: document.documentElement.scrollHeight,
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Is there a scroll range at all? Content that fits has no "top" or "bottom" to be at. */
|
|
36
|
+
export function canScroll(m: ScrollMetrics): boolean {
|
|
37
|
+
return m.scrollHeight - m.clientHeight > BOTTOM_EPSILON_PX
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function isAtBottom(m: ScrollMetrics): boolean {
|
|
41
|
+
return canScroll(m) && m.scrollTop + m.clientHeight >= m.scrollHeight - BOTTOM_EPSILON_PX
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The reader's section. Nothing to scroll: the first heading. At the end: the last (its section may
|
|
46
|
+
* be too short to ever reach the band). Otherwise the topmost heading inside the band, else the last
|
|
47
|
+
* heading at or above the activation line, else the first.
|
|
48
|
+
*/
|
|
49
|
+
export function pickActive(
|
|
50
|
+
elements: readonly HTMLElement[],
|
|
51
|
+
intersecting: ReadonlySet<string>,
|
|
52
|
+
m: ScrollMetrics,
|
|
53
|
+
): string | undefined {
|
|
54
|
+
if (!canScroll(m)) return elements[0]?.id
|
|
55
|
+
if (isAtBottom(m)) return elements[elements.length - 1]?.id
|
|
56
|
+
const topmost = elements.find((el) => intersecting.has(el.id))
|
|
57
|
+
if (topmost) return topmost.id
|
|
58
|
+
const line = m.top + ACTIVATION_TOP_PX
|
|
59
|
+
const passed = elements.filter((el) => el.getBoundingClientRect().top <= line)
|
|
60
|
+
return (passed[passed.length - 1] ?? elements[0])?.id
|
|
61
|
+
}
|