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.
- package/CHANGELOG.md +194 -172
- package/MIGRATING.md +137 -16
- package/agent/rules/basalt-batteries.md +1 -1
- package/agent/rules/basalt-controls.md +1 -1
- package/agent/rules/basalt-mantine.md +1 -1
- package/agent/skills/basalt-app/SKILL.md +7 -7
- package/agent/templates/AGENTS-block.md.tpl +1 -1
- package/dist/charts/BandStrip.d.ts +13 -0
- package/dist/charts/BandStrip.d.ts.map +1 -1
- package/dist/charts/BandStrip.js +142 -44
- package/dist/cli/doctor-upgrade.d.ts +16 -4
- package/dist/cli/doctor-upgrade.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.js +132 -96
- package/dist/cli/doctor.d.ts +2 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +21 -13
- package/dist/cli/help.js +1 -1
- package/dist/cli/index.d.ts +18 -4
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +25 -24
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +10 -4
- 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 +32 -2
- 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 +22 -4
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/provider/index.js +24 -8
- package/dist/provider/test-router.d.ts +2 -1
- package/dist/provider/test-router.d.ts.map +1 -1
- package/dist/provider/test-router.js +6 -7
- 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 +37 -4
- package/package.json +1 -1
- package/src/charts/BandStrip.tsx +223 -48
- package/src/cli/doctor-upgrade.ts +181 -141
- package/src/cli/doctor.ts +23 -14
- package/src/cli/help.ts +1 -1
- package/src/cli/index.ts +37 -36
- package/src/cli/init.ts +10 -6
- package/src/cli/router-wiring.ts +185 -0
- package/src/cli/source-text.ts +62 -0
- package/src/cli/sync.ts +36 -2
- 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 +71 -18
- package/src/provider/test-router.tsx +9 -9
- package/src/vite-boot.ts +109 -0
- package/src/vite.ts +32 -61
package/dist/cli/index.js
CHANGED
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
existsSync,
|
|
5
5
|
mkdirSync,
|
|
6
6
|
readdirSync,
|
|
7
|
-
readFileSync,
|
|
8
7
|
rmdirSync,
|
|
9
8
|
statSync,
|
|
10
9
|
realpathSync,
|
|
@@ -21,6 +20,8 @@ import { guardHook } from "./guard-hook.js";
|
|
|
21
20
|
import { COMMAND_OPTIONS, USAGE, unknownFlag } from "./help.js";
|
|
22
21
|
import { init } from "./init.js";
|
|
23
22
|
import { sync } from "./sync.js";
|
|
23
|
+
import { CODE_ROUTED_NOTE, routerSeedSkip } from "./router-wiring.js";
|
|
24
|
+
import { hasDependency, readIfExists, readPackageJson } from "./source-text.js";
|
|
24
25
|
import { fontsCss, normalizeColorFunctions, tokensCss } from "./tokens-css.js";
|
|
25
26
|
import { DEFAULT_ROOT, exemptRulePaths, resolveRoots } from "./config.js";
|
|
26
27
|
const GUARD_PASSTHROUGH = {
|
|
@@ -224,21 +225,6 @@ const LEGACY_BLOCK_HOST = "CLAUDE.md";
|
|
|
224
225
|
function sha256(text) {
|
|
225
226
|
return createHash("sha256").update(text, "utf8").digest("hex");
|
|
226
227
|
}
|
|
227
|
-
function readIfExists(abs) {
|
|
228
|
-
try {
|
|
229
|
-
return readFileSync(abs, "utf8");
|
|
230
|
-
} catch {
|
|
231
|
-
return null;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
function readPackageJson(dir) {
|
|
235
|
-
const raw = readIfExists(resolve(dir, "package.json"));
|
|
236
|
-
try {
|
|
237
|
-
return raw === null ? null : JSON.parse(raw);
|
|
238
|
-
} catch {
|
|
239
|
-
return null;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
228
|
function readSource(pkgRoot, source) {
|
|
243
229
|
return readIfExists(resolve(pkgRoot, source));
|
|
244
230
|
}
|
|
@@ -355,6 +341,20 @@ const ROUTER_SEED_DESTS = {
|
|
|
355
341
|
function routerSeedDest(appRel, seed) {
|
|
356
342
|
return appRel === "" ? ROUTER_SEED_DESTS[seed] : `${appRel}/${ROUTER_SEED_DESTS[seed]}`;
|
|
357
343
|
}
|
|
344
|
+
function routerSeedDests(appRel) {
|
|
345
|
+
return Object.keys(ROUTER_SEED_DESTS).map(
|
|
346
|
+
(seed) => routerSeedDest(appRel, seed)
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
const START_APP_NOTE = "TanStack Start app \u2014 no main.tsx/nav.tsx/__root.tsx seeded (Start owns the router); render <BasaltProvider><Outlet /></BasaltProvider> in your root route component.";
|
|
350
|
+
function routerSeedPlan(cwd, appRel, tokensOnly = false) {
|
|
351
|
+
const skip = tokensOnly ? null : routerSeedSkip(cwd, appRel);
|
|
352
|
+
return { skip, skipped: new Set(tokensOnly || skip !== null ? routerSeedDests(appRel) : []) };
|
|
353
|
+
}
|
|
354
|
+
function seedSkipNote(skip) {
|
|
355
|
+
if (skip === "start") return START_APP_NOTE;
|
|
356
|
+
return skip === "code-routed" ? CODE_ROUTED_NOTE : null;
|
|
357
|
+
}
|
|
358
358
|
const appRelative = (root, dir) => relativePosix(root, dir).replace(/^\.\/?/, "");
|
|
359
359
|
const hasViteEntry = (dir) => existsSync(resolve(dir, "src/main.tsx")) || existsSync(resolve(dir, "index.html"));
|
|
360
360
|
function resolveAppDir(root) {
|
|
@@ -383,12 +383,6 @@ function resolveAppDir(root) {
|
|
|
383
383
|
error: `${candidates.length} workspace packages depend on basalt-ui and have a Vite entry (${names}) \u2014 cannot tell which is the app. Set \`basalt.app\` (e.g. \`"basalt": { "app": "apps/web" }\`) in the root package.json.`
|
|
384
384
|
};
|
|
385
385
|
}
|
|
386
|
-
function hasDependency(cwd, pkgName) {
|
|
387
|
-
const pkg = readPackageJson(cwd);
|
|
388
|
-
return Boolean(
|
|
389
|
-
pkg?.dependencies?.[pkgName] ?? pkg?.devDependencies?.[pkgName] ?? pkg?.peerDependencies?.[pkgName]
|
|
390
|
-
);
|
|
391
|
-
}
|
|
392
386
|
const ROOT_PLACEMENT = {
|
|
393
387
|
isPackageRepoRoot: true,
|
|
394
388
|
repoRoot: "",
|
|
@@ -970,6 +964,8 @@ function run(argv, cwd = process.cwd()) {
|
|
|
970
964
|
return 1;
|
|
971
965
|
}
|
|
972
966
|
}
|
|
967
|
+
import { isStartApp } from "./router-wiring.js";
|
|
968
|
+
import { readIfExists as readIfExists2, readPackageJson as readPackageJson2 } from "./source-text.js";
|
|
973
969
|
export {
|
|
974
970
|
AGENTS_MD,
|
|
975
971
|
LEGACY_BLOCK_HOST,
|
|
@@ -982,6 +978,7 @@ export {
|
|
|
982
978
|
SERIES_MODULE_HINT_RE,
|
|
983
979
|
SKILL_NAMES,
|
|
984
980
|
SKIP,
|
|
981
|
+
START_APP_NOTE,
|
|
985
982
|
basaltBinCommand,
|
|
986
983
|
basaltPresetEntry,
|
|
987
984
|
checkTheme,
|
|
@@ -1002,6 +999,7 @@ export {
|
|
|
1002
999
|
init,
|
|
1003
1000
|
inspectLefthookGate,
|
|
1004
1001
|
isAgentsImportLine,
|
|
1002
|
+
isStartApp,
|
|
1005
1003
|
isStringArray,
|
|
1006
1004
|
managedFiles,
|
|
1007
1005
|
mergeOxlintExtends,
|
|
@@ -1017,9 +1015,9 @@ export {
|
|
|
1017
1015
|
pruneRetiredManagedFiles,
|
|
1018
1016
|
readBasaltConfig,
|
|
1019
1017
|
readFrameworkVersion,
|
|
1020
|
-
readIfExists,
|
|
1018
|
+
readIfExists2 as readIfExists,
|
|
1021
1019
|
readManifest,
|
|
1022
|
-
readPackageJson,
|
|
1020
|
+
readPackageJson2 as readPackageJson,
|
|
1023
1021
|
readSource,
|
|
1024
1022
|
reconcileRoots,
|
|
1025
1023
|
relativePosix,
|
|
@@ -1032,10 +1030,13 @@ export {
|
|
|
1032
1030
|
retiredManagedDests,
|
|
1033
1031
|
rootsNotices,
|
|
1034
1032
|
routerSeedDest,
|
|
1033
|
+
routerSeedDests,
|
|
1034
|
+
routerSeedPlan,
|
|
1035
1035
|
run,
|
|
1036
1036
|
sameFile,
|
|
1037
1037
|
scanBlock,
|
|
1038
1038
|
scannableFiles,
|
|
1039
|
+
seedSkipNote,
|
|
1039
1040
|
sha256,
|
|
1040
1041
|
shippedAssetPath,
|
|
1041
1042
|
sync,
|
package/dist/cli/init.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/cli/init.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAmB,aAAa,EAAE,MAAM,SAAS,CAAA;AA6D7D,yGAAyG;AACzG,wBAAgB,IAAI,CAAC,GAAG,GAAE,MAAsB,EAAE,aAAa,GAAE,aAAkB,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/cli/init.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAmB,aAAa,EAAE,MAAM,SAAS,CAAA;AA6D7D,yGAAyG;AACzG,wBAAgB,IAAI,CAAC,GAAG,GAAE,MAAsB,EAAE,aAAa,GAAE,aAAkB,GAAG,MAAM,CA8L3F"}
|
package/dist/cli/init.js
CHANGED
|
@@ -4,9 +4,9 @@ import { deriveSpacing } from "../tokens/core.js";
|
|
|
4
4
|
import {
|
|
5
5
|
MANIFEST_PATH,
|
|
6
6
|
declaredProfile,
|
|
7
|
+
routerSeedPlan,
|
|
8
|
+
seedSkipNote,
|
|
7
9
|
readBasaltConfig,
|
|
8
|
-
ROUTER_SEED_DESTS,
|
|
9
|
-
routerSeedDest,
|
|
10
10
|
findBasaltInstall,
|
|
11
11
|
managedFiles,
|
|
12
12
|
mergeOxlintExtends,
|
|
@@ -80,8 +80,12 @@ function init(cwd = process.cwd(), scaffoldFlags = {}) {
|
|
|
80
80
|
const manifest = readManifest(cwd);
|
|
81
81
|
const placement = resolvePlacement(cwd);
|
|
82
82
|
const tokensOnly = declaredProfile(readBasaltConfig(cwd), []) === "tokens-only";
|
|
83
|
-
const
|
|
84
|
-
|
|
83
|
+
const { skip: seedSkip, skipped: skippedSeeds } = routerSeedPlan(
|
|
84
|
+
cwd,
|
|
85
|
+
placement.appRel,
|
|
86
|
+
tokensOnly
|
|
87
|
+
);
|
|
88
|
+
const files = managedFiles(placement).filter((f) => !skippedSeeds.has(f.dest));
|
|
85
89
|
const writtenFiles = [];
|
|
86
90
|
const keptFiles = [];
|
|
87
91
|
const missingSources = [];
|
|
@@ -134,6 +138,8 @@ Kept (already present \u2014 basalt did not touch them):`);
|
|
|
134
138
|
const tsconfigLine = tokensOnly ? null : seedTsconfigExtends(cwd);
|
|
135
139
|
if (tsconfigLine !== null) console.log(`basalt-ui init: ${tsconfigLine}`);
|
|
136
140
|
if (buildNote !== null) console.log(`basalt-ui init: ${buildNote}`);
|
|
141
|
+
const skipNote = seedSkipNote(seedSkip);
|
|
142
|
+
if (skipNote !== null) console.log(`basalt-ui init: ${skipNote}`);
|
|
137
143
|
const rootsMessages = rootsNotices(rootsState);
|
|
138
144
|
for (const line of rootsMessages.log) console.log(`basalt-ui init: ${line}`);
|
|
139
145
|
for (const line of rootsMessages.error) console.error(`\u26A0 basalt-ui init: ${line}`);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { tokenize } from './source-text.js';
|
|
2
|
+
/** The module `index.html` loads for the app at `dir` (default src/main.tsx), relative to `dir`. */
|
|
3
|
+
export declare function appEntry(dir: string): string;
|
|
4
|
+
type Tokens = ReturnType<typeof tokenize>;
|
|
5
|
+
/**
|
|
6
|
+
* Whether the entry or a module it imports (relative imports, static or dynamic, `IMPORT_DEPTH`
|
|
7
|
+
* hops) matches `pattern` in code — a global regex, ignoring comments and string literals; an
|
|
8
|
+
* import inside a comment or a string is not followed. `entryTokens` reuses an already-tokenized entry.
|
|
9
|
+
*/
|
|
10
|
+
export declare function callsIn(dir: string, entry: string, pattern: RegExp, entryTokens?: Tokens): boolean;
|
|
11
|
+
/** A global regex matching a CALL of `name` (itself a regex source), generic or not — not an import or bare mention. */
|
|
12
|
+
export declare function callOf(pattern: string): RegExp;
|
|
13
|
+
/** The directories a generated `routeTree.gen.*` is looked for in: beside the entry, then src/. */
|
|
14
|
+
export declare function routeTreeDirs(entry: string): string[];
|
|
15
|
+
/** A TanStack router plugin in the vite config, or a `routeTree.gen.*` in `routeTreeDirs`. */
|
|
16
|
+
export declare function hasRouteTree(dir: string, entry: string): boolean;
|
|
17
|
+
/** Whether `createBasaltRouter` is called in a module reachable from the entry. */
|
|
18
|
+
export declare function hasRouter(dir: string, entry: string, entryTokens?: Tokens): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* THE classification, shared by `init`, `sync` and `doctor`: code-routed = `createBasaltRouter` is
|
|
21
|
+
* called in a module reachable from the entry, no router plugin is registered and no
|
|
22
|
+
* `routeTree.gen.*` exists, and the entry does not import a generated tree (a freshly seeded entry
|
|
23
|
+
* does, before the first vite run — that app is file-routed). Comments and strings do not count.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isCodeRoutedApp(cwd: string, appRel: string): boolean;
|
|
26
|
+
/** A TanStack Start app owns its router, so its router seeds give way to an in-tree `<BasaltProvider>`. */
|
|
27
|
+
export declare function isStartApp(cwd: string, appRel: string): boolean;
|
|
28
|
+
/** Why an app's router seeds are not placed (see `routerSeedSkip`). */
|
|
29
|
+
export type RouterSeedSkip = 'start' | 'code-routed' | null;
|
|
30
|
+
export declare const CODE_ROUTED_NOTE = "code-routed app (createBasaltRouter, no route-tree plugin or routeTree.gen) \u2014 no main.tsx/nav.tsx/__root.tsx seeded.";
|
|
31
|
+
/**
|
|
32
|
+
* Why an app's router seeds (main/nav/__root) are not placed: `start` (Start owns the router, and
|
|
33
|
+
* wins when both apply) or `code-routed` (no generated tree to assume); null when they are.
|
|
34
|
+
*/
|
|
35
|
+
export declare function routerSeedSkip(cwd: string, appRel: string): RouterSeedSkip;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=router-wiring.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-wiring.d.ts","sourceRoot":"","sources":["../../src/cli/router-wiring.ts"],"names":[],"mappings":"AAOA,OAAO,EAA+B,QAAQ,EAAE,MAAM,eAAe,CAAA;AAuErE,oGAAoG;AACpG,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG5C;AAED,KAAK,MAAM,GAAG,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAA;AAEzC;;;;GAIG;AACH,wBAAgB,OAAO,CACrB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAqBT;AAED,wHAAwH;AACxH,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE9C;AAID,mGAAmG;AACnG,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAErD;AAED,8FAA8F;AAC9F,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAQhE;AAED,mFAAmF;AACnF,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAEnF;AAOD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAMpE;AAED,2GAA2G;AAC3G,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAE/D;AAED,uEAAuE;AACvE,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,aAAa,GAAG,IAAI,CAAA;AAE3D,eAAO,MAAM,gBAAgB,8HAC2F,CAAA;AAExH;;;GAGG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,CAG1E"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { hasDependency, readIfExists, tokenize } from "./source-text.js";
|
|
4
|
+
const IMPORT_DEPTH = 3;
|
|
5
|
+
const VITE_CONFIGS = ["ts", "mts", "cts", "js", "mjs", "cjs"].map((e) => `vite.config.${e}`);
|
|
6
|
+
function htmlEntry(html) {
|
|
7
|
+
for (const [, attrs = ""] of html.replace(/<!--[\s\S]*?-->/g, "").matchAll(/<script\b([^>]*)>/gi)) {
|
|
8
|
+
const src = /\bsrc\s*=\s*["']?([^"'\s>]+)/i.exec(attrs)?.[1];
|
|
9
|
+
if (/\btype\s*=\s*["']?module\b/i.test(attrs) && src !== void 0 && !/^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(src)) {
|
|
10
|
+
return src;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return void 0;
|
|
14
|
+
}
|
|
15
|
+
function registersRouterPlugin(src) {
|
|
16
|
+
const { code, inLiteral } = tokenize(src);
|
|
17
|
+
const pluginsAt = [...code.matchAll(/\bplugins\b/g)].find((m) => !inLiteral(m.index))?.index;
|
|
18
|
+
if (pluginsAt === void 0) return false;
|
|
19
|
+
const imports = code.matchAll(
|
|
20
|
+
/(?:^|;)[ \t]*import\s+(?:type\s+)?([^'"`;]*?)\s*from\s*(['"])@tanstack\/router-plugin(?:\/[^'"]*)?\2/gm
|
|
21
|
+
);
|
|
22
|
+
return [...imports].some((m) => {
|
|
23
|
+
if (inLiteral(m.index)) return false;
|
|
24
|
+
const names = (m[1] ?? "").replace(/[{}]/g, "").split(",").map((part) => part.trim()).filter((part) => part !== "" && !/^type\s/.test(part)).map((part) => part.split(/\s+as\s+/).pop() ?? part);
|
|
25
|
+
return names.some(
|
|
26
|
+
(name) => [
|
|
27
|
+
...code.matchAll(
|
|
28
|
+
new RegExp(`(?<![.\\w$])${name.replace(/\$/g, "\\$")}(?:\\.\\w+)?\\s*\\(`, "g")
|
|
29
|
+
)
|
|
30
|
+
].some((call) => call.index > pluginsAt && !inLiteral(call.index))
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
const RELATIVE_IMPORT = /(?<![.\w$])(?:(?:import|export)\b[^'";]*?\bfrom|import\s*\(?)\s*['"](\.{1,2}\/[^'"]+)['"]/g;
|
|
35
|
+
const GENERATED_TREE_IMPORT = /(?<![.\w$])(?:(?:import|export)\b[^'";]*?\bfrom|import\s*\(?)\s*['"][^'"]*routeTree\.gen[^'"]*['"]/g;
|
|
36
|
+
function resolveRelative(from, spec) {
|
|
37
|
+
const base = resolve(dirname(from), spec.replace(/\.[jt]sx?$/, ""));
|
|
38
|
+
return [
|
|
39
|
+
resolve(dirname(from), spec),
|
|
40
|
+
`${base}.ts`,
|
|
41
|
+
`${base}.tsx`,
|
|
42
|
+
`${base}/index.ts`,
|
|
43
|
+
`${base}/index.tsx`
|
|
44
|
+
].find((f) => /\.[jt]sx?$/.test(f) && existsSync(f)) ?? null;
|
|
45
|
+
}
|
|
46
|
+
function appEntry(dir) {
|
|
47
|
+
const src = htmlEntry(readIfExists(resolve(dir, "index.html")) ?? "") ?? "src/main.tsx";
|
|
48
|
+
return src.replace(/^\//, "");
|
|
49
|
+
}
|
|
50
|
+
function callsIn(dir, entry, pattern, entryTokens) {
|
|
51
|
+
const entryPath = resolve(dir, entry);
|
|
52
|
+
const seen = /* @__PURE__ */ new Set([entryPath]);
|
|
53
|
+
let frontier = [entryPath];
|
|
54
|
+
for (let depth = 0; depth <= IMPORT_DEPTH && frontier.length > 0; depth++) {
|
|
55
|
+
const next = [];
|
|
56
|
+
for (const file of frontier) {
|
|
57
|
+
const { code, inLiteral } = file === entryPath && entryTokens ? entryTokens : tokenize(readIfExists(file) ?? "");
|
|
58
|
+
if ([...code.matchAll(pattern)].some((c) => !inLiteral(c.index))) return true;
|
|
59
|
+
for (const m of code.matchAll(RELATIVE_IMPORT)) {
|
|
60
|
+
if (inLiteral(m.index)) continue;
|
|
61
|
+
const dep = resolveRelative(file, m[1] ?? "");
|
|
62
|
+
if (dep === null || seen.has(dep)) continue;
|
|
63
|
+
seen.add(dep);
|
|
64
|
+
next.push(dep);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
frontier = next;
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
function callOf(pattern) {
|
|
72
|
+
return new RegExp(`\\b${pattern}\\b\\s*(?:<[^()]*>)?\\s*\\(`, "g");
|
|
73
|
+
}
|
|
74
|
+
const CREATE_BASALT_ROUTER = callOf("createBasaltRouter");
|
|
75
|
+
function routeTreeDirs(entry) {
|
|
76
|
+
return [.../* @__PURE__ */ new Set([dirname(entry), "src"])];
|
|
77
|
+
}
|
|
78
|
+
function hasRouteTree(dir, entry) {
|
|
79
|
+
const vite = VITE_CONFIGS.map((f) => readIfExists(resolve(dir, f))).find((t) => t !== null) ?? "";
|
|
80
|
+
return registersRouterPlugin(vite) || routeTreeDirs(entry).some(
|
|
81
|
+
(d) => ["ts", "tsx", "js"].some((e) => existsSync(resolve(dir, d, `routeTree.gen.${e}`)))
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
function hasRouter(dir, entry, entryTokens) {
|
|
85
|
+
return callsIn(dir, entry, CREATE_BASALT_ROUTER, entryTokens);
|
|
86
|
+
}
|
|
87
|
+
function importsGeneratedTree({ code, inLiteral }) {
|
|
88
|
+
return [...code.matchAll(GENERATED_TREE_IMPORT)].some((m) => !inLiteral(m.index));
|
|
89
|
+
}
|
|
90
|
+
function isCodeRoutedApp(cwd, appRel) {
|
|
91
|
+
const dir = resolve(cwd, appRel);
|
|
92
|
+
const entry = appEntry(dir);
|
|
93
|
+
const tokens = tokenize(readIfExists(resolve(dir, entry)) ?? "");
|
|
94
|
+
if (importsGeneratedTree(tokens)) return false;
|
|
95
|
+
return hasRouter(dir, entry, tokens) && !hasRouteTree(dir, entry);
|
|
96
|
+
}
|
|
97
|
+
function isStartApp(cwd, appRel) {
|
|
98
|
+
return hasDependency(resolve(cwd, appRel), "@tanstack/react-start");
|
|
99
|
+
}
|
|
100
|
+
const CODE_ROUTED_NOTE = "code-routed app (createBasaltRouter, no route-tree plugin or routeTree.gen) \u2014 no main.tsx/nav.tsx/__root.tsx seeded.";
|
|
101
|
+
function routerSeedSkip(cwd, appRel) {
|
|
102
|
+
if (isStartApp(cwd, appRel)) return "start";
|
|
103
|
+
return isCodeRoutedApp(cwd, appRel) ? "code-routed" : null;
|
|
104
|
+
}
|
|
105
|
+
export {
|
|
106
|
+
CODE_ROUTED_NOTE,
|
|
107
|
+
appEntry,
|
|
108
|
+
callOf,
|
|
109
|
+
callsIn,
|
|
110
|
+
hasRouteTree,
|
|
111
|
+
hasRouter,
|
|
112
|
+
isCodeRoutedApp,
|
|
113
|
+
isStartApp,
|
|
114
|
+
routeTreeDirs,
|
|
115
|
+
routerSeedSkip
|
|
116
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** `abs` read as text, or null: absent, a directory, unreadable or raced away all mean "not there". */
|
|
2
|
+
export declare function readIfExists(abs: string): string | null;
|
|
3
|
+
/** `<dir>/package.json` parsed as `T`; null when absent or not JSON. */
|
|
4
|
+
export declare function readPackageJson<T>(dir: string): T | null;
|
|
5
|
+
/** True when `pkgName` appears in any of the consumer's dependencies, devDependencies or peerDependencies. */
|
|
6
|
+
export declare function hasDependency(cwd: string, pkgName: string): boolean;
|
|
7
|
+
/** Source with comments blanked (and template text), plus a test for "offset sits inside a string". */
|
|
8
|
+
export declare function tokenize(src: string): {
|
|
9
|
+
code: string;
|
|
10
|
+
inLiteral: (at: number) => boolean;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=source-text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-text.d.ts","sourceRoot":"","sources":["../../src/cli/source-text.ts"],"names":[],"mappings":"AAOA,uGAAuG;AACvG,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAMvD;AAED,wEAAwE;AACxE,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,CAOxD;AAID,8GAA8G;AAC9G,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAMnE;AAUD,uGAAuG;AACvG,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAA;CAAE,CAe1F"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
function readIfExists(abs) {
|
|
4
|
+
try {
|
|
5
|
+
return readFileSync(abs, "utf8");
|
|
6
|
+
} catch {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function readPackageJson(dir) {
|
|
11
|
+
const raw = readIfExists(resolve(dir, "package.json"));
|
|
12
|
+
try {
|
|
13
|
+
return raw === null ? null : JSON.parse(raw);
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const DEPENDENCY_FIELDS = ["dependencies", "devDependencies", "peerDependencies"];
|
|
19
|
+
function hasDependency(cwd, pkgName) {
|
|
20
|
+
const pkg = readPackageJson(
|
|
21
|
+
cwd
|
|
22
|
+
);
|
|
23
|
+
return DEPENDENCY_FIELDS.some((field) => pkg?.[field]?.[pkgName] !== void 0);
|
|
24
|
+
}
|
|
25
|
+
const TOKEN = /("(?:\\.|[^"\\\n])*"|'(?:\\.|[^'\\\n])*'|`(?:\\.|[^`\\])*`)|\/\/[^\n]*|\/\*[\s\S]*?\*\//g;
|
|
26
|
+
function tokenize(src) {
|
|
27
|
+
const literals = [];
|
|
28
|
+
const code = src.replace(TOKEN, (m, literal, at) => {
|
|
29
|
+
if (literal === void 0) return m.replace(/[^\n]/g, " ");
|
|
30
|
+
if (!literal.startsWith("`")) {
|
|
31
|
+
literals.push([at, at + m.length]);
|
|
32
|
+
return m;
|
|
33
|
+
}
|
|
34
|
+
return m.replace(
|
|
35
|
+
/(\$\{[^}]*\})|[^\n`]/g,
|
|
36
|
+
(c, interpolation) => interpolation ?? " "
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
return { code, inLiteral: (at) => literals.some(([from, to]) => at >= from && at < to) };
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
hasDependency,
|
|
43
|
+
readIfExists,
|
|
44
|
+
readPackageJson,
|
|
45
|
+
tokenize
|
|
46
|
+
};
|
package/dist/cli/sync.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/cli/sync.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/cli/sync.ts"],"names":[],"mappings":"AA0CA,gGAAgG;AAChG,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAGjE;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,mGAAmG;IACnG,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAC1B,CAAA;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAKrF;AAED,qFAAqF;AACrF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQ5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,IAAI,CAAC,IAAI,GAAE,WAAgB,EAAE,aAAa,GAAE,MAAsB,GAAG,MAAM,CAgO1F"}
|
package/dist/cli/sync.js
CHANGED
|
@@ -28,9 +28,11 @@ import {
|
|
|
28
28
|
reportPrune,
|
|
29
29
|
resolvePlacement,
|
|
30
30
|
resolveProjectDir,
|
|
31
|
+
routerSeedPlan,
|
|
31
32
|
rootsNotices,
|
|
32
33
|
sha256,
|
|
33
34
|
shippedAssetPath,
|
|
35
|
+
START_APP_NOTE,
|
|
34
36
|
unitState,
|
|
35
37
|
writeFileEnsuringDir,
|
|
36
38
|
writeUnit
|
|
@@ -70,7 +72,9 @@ function sync(opts = {}, invocationCwd = process.cwd()) {
|
|
|
70
72
|
}
|
|
71
73
|
if (!existsSync(resolve(cwd, MANIFEST_PATH))) {
|
|
72
74
|
const elsewhere = findManifestAbove(cwd);
|
|
73
|
-
const
|
|
75
|
+
const refused = resolvePlacement(cwd);
|
|
76
|
+
const { skipped: skippedSeeds } = routerSeedPlan(cwd, refused.appRel);
|
|
77
|
+
const wouldWrite = managedFiles(refused).filter((f) => !skippedSeeds.has(f.dest)).length;
|
|
74
78
|
console.error(
|
|
75
79
|
`\u2716 basalt-ui sync: no ${MANIFEST_PATH} at ${cwd} \u2014 refusing to scaffold. \`sync\` refreshes an EXISTING basalt install; creating one is \`basalt-ui init\`'s decision, and continuing here would write ${wouldWrite} managed file(s) into this directory.` + (elsewhere === null ? " No manifest exists at any ancestor either \u2014 run `basalt-ui init` here if this package really is meant to be a consumer." : ` ${parentInstallAdvice(cwd, elsewhere, "sync")}`)
|
|
76
80
|
);
|
|
@@ -80,7 +84,8 @@ function sync(opts = {}, invocationCwd = process.cwd()) {
|
|
|
80
84
|
const ctx = renderContext(cwd);
|
|
81
85
|
const manifest = readManifest(cwd);
|
|
82
86
|
const placement = resolvePlacement(cwd);
|
|
83
|
-
const
|
|
87
|
+
const { skip: seedSkip, skipped } = routerSeedPlan(cwd, placement.appRel);
|
|
88
|
+
const files = managedFiles(placement).filter((f) => !skipped.has(f.dest));
|
|
84
89
|
let updated = 0;
|
|
85
90
|
let created = 0;
|
|
86
91
|
let recreated = 0;
|
|
@@ -126,6 +131,31 @@ function sync(opts = {}, invocationCwd = process.cwd()) {
|
|
|
126
131
|
force: opts.force === true
|
|
127
132
|
});
|
|
128
133
|
staleForCheck += pruned.removed.length + pruned.drifted.length;
|
|
134
|
+
const isTracked = (d) => manifest.files[d] !== void 0;
|
|
135
|
+
const codeRoutedSeeds = seedSkip === "code-routed" ? [...skipped].filter(isTracked) : [];
|
|
136
|
+
if (codeRoutedSeeds.length > 0 && !opts.check) {
|
|
137
|
+
for (const d of codeRoutedSeeds) delete manifest.files[d];
|
|
138
|
+
console.error(
|
|
139
|
+
`\u26A0 basalt-ui sync: code-routed app \u2014 dropped ${codeRoutedSeeds.join(", ")} from the manifest (any file is yours).`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
const startSkippedSeeds = seedSkip === "start" ? [...skipped] : [];
|
|
143
|
+
const stale = startSkippedSeeds.filter((d) => isTracked(d) && existsSync(resolve(cwd, d)));
|
|
144
|
+
const mounting = stale.filter((d) => !d.endsWith("nav.tsx"));
|
|
145
|
+
const inert = stale.filter((d) => d.endsWith("nav.tsx"));
|
|
146
|
+
const embedded = "Delete them and render <BasaltProvider><Outlet /></BasaltProvider> in the Start root route (embedded mode).";
|
|
147
|
+
if (mounting.length > 0) {
|
|
148
|
+
console.error(
|
|
149
|
+
`\u26A0 basalt-ui sync: ${mounting.join(", ")} mount a second router inside this TanStack Start app; left untouched. ${embedded}`
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
if (inert.length > 0) {
|
|
153
|
+
console.error(
|
|
154
|
+
`\u26A0 basalt-ui sync: ${inert.join(", ")} was seeded before this became a Start app; it mounts nothing, so keep or delete it. Left untouched.`
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
if (seedSkip === "start" && (!opts.check || syncFlags.includes("--verbose")))
|
|
158
|
+
console.log(`basalt-ui sync: ${START_APP_NOTE}`);
|
|
129
159
|
const placementSkips = placementNotices(cwd, placement);
|
|
130
160
|
if (opts.check !== true || syncFlags.includes("--verbose")) {
|
|
131
161
|
for (const line of placementSkips) console.log(`basalt-ui sync: ${line}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-block.d.ts","sourceRoot":"","sources":["../../src/content/code-block.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAO1C,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACvB,yDAAyD;IACzD,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAA;CAC/B,CAAA;AAED,wBAAgB,SAAS,CAAC,EACxB,IAAI,EACJ,QAAQ,EACR,KAAK,EACL,QAAe,EACf,SAAS,EACT,KAAK,GACN,EAAE,cAAc,+
|
|
1
|
+
{"version":3,"file":"code-block.d.ts","sourceRoot":"","sources":["../../src/content/code-block.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAO1C,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACvB,yDAAyD;IACzD,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAA;CAC/B,CAAA;AAED,wBAAgB,SAAS,CAAC,EACxB,IAAI,EACJ,QAAQ,EACR,KAAK,EACL,QAAe,EACf,SAAS,EACT,KAAK,GACN,EAAE,cAAc,+BA4FhB"}
|
|
@@ -46,33 +46,42 @@ function CodeBlock({
|
|
|
46
46
|
};
|
|
47
47
|
}, [html, code]);
|
|
48
48
|
const containerClass = [classes.container, className].filter(Boolean).join(" ");
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
49
|
+
const showFloatingCopy = title === void 0 && showCopy;
|
|
50
|
+
return /* @__PURE__ */ jsxs(
|
|
51
|
+
"div",
|
|
52
|
+
{
|
|
53
|
+
className: containerClass,
|
|
54
|
+
...showFloatingCopy && { "data-floating-copy": true },
|
|
55
|
+
...style !== void 0 && { style },
|
|
56
|
+
children: [
|
|
57
|
+
title !== void 0 && /* @__PURE__ */ jsxs("div", { className: classes.header, children: [
|
|
58
|
+
/* @__PURE__ */ jsx("span", { className: classes.title, children: title }),
|
|
59
|
+
/* @__PURE__ */ jsxs("div", { className: classes.headerRight, children: [
|
|
60
|
+
language !== void 0 && /* @__PURE__ */ jsx("span", { className: classes.langBadge, children: language }),
|
|
61
|
+
showCopy && /* @__PURE__ */ jsx(CopyAction, { value: code, ariaLabel: "Copy code" })
|
|
62
|
+
] })
|
|
63
|
+
] }),
|
|
64
|
+
html !== null ? /* @__PURE__ */ jsx(
|
|
65
|
+
"div",
|
|
66
|
+
{
|
|
67
|
+
ref: setBodyRef,
|
|
68
|
+
className: classes.body,
|
|
69
|
+
...showOverflowFade && { "data-code-overflow": true },
|
|
70
|
+
dangerouslySetInnerHTML: { __html: html }
|
|
71
|
+
}
|
|
72
|
+
) : /* @__PURE__ */ jsx(
|
|
73
|
+
"pre",
|
|
74
|
+
{
|
|
75
|
+
ref: setBodyRef,
|
|
76
|
+
className: classes.body,
|
|
77
|
+
...showOverflowFade && { "data-code-overflow": true },
|
|
78
|
+
children: /* @__PURE__ */ jsx("code", { children: code })
|
|
79
|
+
}
|
|
80
|
+
),
|
|
81
|
+
showFloatingCopy && /* @__PURE__ */ jsx("div", { className: classes.floatingCopy, children: /* @__PURE__ */ jsx(CopyAction, { value: code, ariaLabel: "Copy code" }) })
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
);
|
|
76
85
|
}
|
|
77
86
|
export {
|
|
78
87
|
CodeBlock
|
|
@@ -77,7 +77,13 @@
|
|
|
77
77
|
);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
/* Both body states — the highlighted wrapper's `pre.shiki` and the bare fallback `<pre class=body>`
|
|
81
|
+
* — outrank Prose's `.root.article pre` block margin (0,2,1): at a tie, stylesheet order decided
|
|
82
|
+
* whether the inner pre kept 18px, so the fallback was ~36px taller than the highlighted fence and
|
|
83
|
+
* the swap jumped. `.body.body` lifts the fallback to (0,3,0); the outer `.container` margin alone
|
|
84
|
+
* owns the rhythm. */
|
|
85
|
+
.container .body.body,
|
|
86
|
+
.container .body :global(pre.shiki) {
|
|
81
87
|
margin: 0;
|
|
82
88
|
padding: 0;
|
|
83
89
|
background: transparent !important;
|
|
@@ -93,6 +99,18 @@ html[data-mantine-color-scheme='light'] .body :global(.shiki span) {
|
|
|
93
99
|
color: var(--shiki-light);
|
|
94
100
|
}
|
|
95
101
|
|
|
102
|
+
/* The floating button sits over the body's top-right corner, so the body reserves its box: the
|
|
103
|
+
* first line starts below offset + button height instead of running underneath it on touch (always
|
|
104
|
+
* visible) or on hover. `--code-block-copy-size` mirrors ActionIcon size="sm" (Mantine scopes its
|
|
105
|
+
* own `--ai-size-sm` to the button, out of the body's reach); the layout suite pins the two. */
|
|
106
|
+
.container[data-floating-copy] {
|
|
107
|
+
--code-block-copy-size: calc(1.375rem * var(--mantine-scale, 1));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.container[data-floating-copy] .body {
|
|
111
|
+
padding-top: calc(var(--vx-space-code-block-floating-copy-offset) + var(--code-block-copy-size));
|
|
112
|
+
}
|
|
113
|
+
|
|
96
114
|
/* Floating copy button — shown only when there is no header (no title), revealed on hover/focus. */
|
|
97
115
|
.floatingCopy {
|
|
98
116
|
position: absolute;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Post-process for beautiful-mermaid's SVG (consumed by `./mermaid`).
|
|
3
|
+
*
|
|
4
|
+
* `buildStyleBlock(font)` treats the font as a family NAME: it emits a Google Fonts `@import` (plus
|
|
5
|
+
* a JetBrains Mono one when `mono` is set) and writes `text { font-family: '<font>', … }`. basalt
|
|
6
|
+
* feeds it `var(--basalt-font-sans)`, so the import is a broken request and the quoted `'var(…)'`
|
|
7
|
+
* is an invalid family. basalt self-hosts its fonts: drop the import, unquote the var().
|
|
8
|
+
*
|
|
9
|
+
* Patterns verified against beautiful-mermaid 1.1.3 (peer range ^1.1.0): the style block is a
|
|
10
|
+
* single `<style>` holding the `@import`s and one `text { font-family }` rule; `font-family`
|
|
11
|
+
* never appears as a presentation attribute. Only `<style>` content is rewritten — a node label
|
|
12
|
+
* that happens to contain the same text is left alone.
|
|
13
|
+
*/
|
|
14
|
+
export declare function sanitizeMermaidFonts(svg: string): string;
|
|
15
|
+
//# sourceMappingURL=mermaid-sanitize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mermaid-sanitize.d.ts","sourceRoot":"","sources":["../../src/content/mermaid-sanitize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA+BH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAKxD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const STYLE_BLOCK = /(<style\b[^>]*>)([\s\S]*?)(<\/style>)/gi;
|
|
2
|
+
const HOST = String.raw`(?:https?:)?\/\/fonts\.googleapis\.com`;
|
|
3
|
+
const QUOTED_FORM = String.raw`(?:url\(\s*)?(['"])${HOST}[^'"}\n]*\1(?:\s*\))?`;
|
|
4
|
+
const URL_FORM = String.raw`url\(\s*${HOST}[^}'"\n]*?\)`;
|
|
5
|
+
const MEDIA_LIST = String.raw`(?:[ \t]+[^;{}\n]*)?`;
|
|
6
|
+
const GOOGLE_FONTS_IMPORT = new RegExp(
|
|
7
|
+
String.raw`@import\s+(?:${QUOTED_FORM}|${URL_FORM})${MEDIA_LIST}[ \t]*;?`,
|
|
8
|
+
"g"
|
|
9
|
+
);
|
|
10
|
+
const QUOTED_VAR_FONT_FAMILY = /(font-family\s*:\s*)(['"])(var\([^'"]*\))\2/g;
|
|
11
|
+
function sanitizeStyle(css) {
|
|
12
|
+
const cleaned = css.replace(GOOGLE_FONTS_IMPORT, "").replace(QUOTED_VAR_FONT_FAMILY, "$1$3");
|
|
13
|
+
if (process.env.NODE_ENV !== "production" && /googleapis/i.test(cleaned)) {
|
|
14
|
+
console.warn(
|
|
15
|
+
"[basalt] MermaidDiagram: a remote font import survived sanitization \u2014 beautiful-mermaid changed its <style> output; update src/content/mermaid-sanitize.ts."
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
return cleaned;
|
|
19
|
+
}
|
|
20
|
+
function sanitizeMermaidFonts(svg) {
|
|
21
|
+
return svg.replace(
|
|
22
|
+
STYLE_BLOCK,
|
|
23
|
+
(_block, open, css, close) => open + sanitizeStyle(css) + close
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
sanitizeMermaidFonts
|
|
28
|
+
};
|
|
@@ -20,6 +20,12 @@
|
|
|
20
20
|
* <MermaidDiagram code={'graph TD\n A --> B'} />
|
|
21
21
|
*/
|
|
22
22
|
import type { CSSProperties, ReactNode } from 'react';
|
|
23
|
+
import type { RenderOptions } from 'beautiful-mermaid';
|
|
24
|
+
/**
|
|
25
|
+
* Static theme mapping onto the `--vx-*` token layer — every value is a `var(--vx-*)` string, so
|
|
26
|
+
* this object never changes across renders/schemes and can live at module scope.
|
|
27
|
+
*/
|
|
28
|
+
export declare const MERMAID_THEME_OPTIONS: RenderOptions;
|
|
23
29
|
export type MermaidDiagramProps = {
|
|
24
30
|
/** Raw mermaid source (the fence body, without the surrounding ``` marks). */
|
|
25
31
|
readonly code: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mermaid.d.ts","sourceRoot":"","sources":["../../src/content/mermaid.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"mermaid.d.ts","sourceRoot":"","sources":["../../src/content/mermaid.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAQrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAMtD;;;GAGG;AACH,eAAO,MAAM,qBAAqB,EAAE,aAUnC,CAAA;AAUD,MAAM,MAAM,mBAAmB,GAAG;IAChC,8EAA8E;IAC9E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAA;IAC9B,8EAA8E;IAC9E,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAC9B,CAAA;AAED,wBAAgB,cAAc,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,mBAAmB,4SA0DvF"}
|