@g3nomaly/ui 0.3.3 → 0.3.4
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/README.md +47 -25
- package/dist/cli/adapter.d.ts +14 -6
- package/dist/cli/adapter.d.ts.map +1 -1
- package/dist/cli/adapter.js +23 -18
- package/dist/cli/adapter.js.map +1 -1
- package/dist/cli/afterInstall.d.ts +26 -0
- package/dist/cli/afterInstall.d.ts.map +1 -0
- package/dist/cli/afterInstall.js +54 -0
- package/dist/cli/afterInstall.js.map +1 -0
- package/dist/cli/commands/add.d.ts +8 -2
- package/dist/cli/commands/add.d.ts.map +1 -1
- package/dist/cli/commands/add.js +9 -4
- package/dist/cli/commands/add.js.map +1 -1
- package/dist/cli/commands/index.d.ts +1 -0
- package/dist/cli/commands/index.d.ts.map +1 -1
- package/dist/cli/commands/index.js +1 -0
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/init.d.ts +16 -5
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +59 -13
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/ls.d.ts +1 -1
- package/dist/cli/commands/manifest.js +1 -1
- package/dist/cli/commands/manifest.js.map +1 -1
- package/dist/cli/commands/source.d.ts +2 -1
- package/dist/cli/commands/source.d.ts.map +1 -1
- package/dist/cli/commands/source.js +29 -2
- package/dist/cli/commands/source.js.map +1 -1
- package/dist/cli/commands/sourceInit.d.ts +9 -0
- package/dist/cli/commands/sourceInit.d.ts.map +1 -0
- package/dist/cli/commands/sourceInit.js +77 -0
- package/dist/cli/commands/sourceInit.js.map +1 -0
- package/dist/cli/commands/update.d.ts +10 -3
- package/dist/cli/commands/update.d.ts.map +1 -1
- package/dist/cli/commands/update.js +9 -4
- package/dist/cli/commands/update.js.map +1 -1
- package/dist/cli/index.js +15 -5
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/npmDependencies.d.ts +11 -0
- package/dist/cli/npmDependencies.d.ts.map +1 -0
- package/dist/cli/npmDependencies.js +67 -0
- package/dist/cli/npmDependencies.js.map +1 -0
- package/dist/cli/packageFiles.d.ts +15 -0
- package/dist/cli/packageFiles.d.ts.map +1 -0
- package/dist/cli/packageFiles.js +54 -0
- package/dist/cli/packageFiles.js.map +1 -0
- package/dist/cli/themeTokens.d.ts +12 -0
- package/dist/cli/themeTokens.d.ts.map +1 -0
- package/dist/cli/themeTokens.js +52 -0
- package/dist/cli/themeTokens.js.map +1 -0
- package/dist/packages/dependencies.d.ts +44 -0
- package/dist/packages/dependencies.d.ts.map +1 -0
- package/dist/packages/dependencies.js +60 -0
- package/dist/packages/dependencies.js.map +1 -0
- package/dist/packages/install.d.ts +10 -0
- package/dist/packages/install.d.ts.map +1 -0
- package/dist/packages/install.js +21 -0
- package/dist/packages/install.js.map +1 -0
- package/dist/registry/adapters/shadcn.adapter.d.ts +32 -7
- package/dist/registry/adapters/shadcn.adapter.d.ts.map +1 -1
- package/dist/registry/adapters/shadcn.adapter.js +75 -20
- package/dist/registry/adapters/shadcn.adapter.js.map +1 -1
- package/dist/registry/adapters/shadcnImports.d.ts +10 -0
- package/dist/registry/adapters/shadcnImports.d.ts.map +1 -0
- package/dist/registry/adapters/shadcnImports.js +18 -0
- package/dist/registry/adapters/shadcnImports.js.map +1 -0
- package/dist/registry/componentsJson.d.ts +3 -1
- package/dist/registry/componentsJson.d.ts.map +1 -1
- package/dist/registry/componentsJson.js +15 -1
- package/dist/registry/componentsJson.js.map +1 -1
- package/dist/registry/index.d.ts +1 -1
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/registry/index.js +1 -1
- package/dist/registry/index.js.map +1 -1
- package/dist/registry/manifest.d.ts +2 -13
- package/dist/registry/manifest.d.ts.map +1 -1
- package/dist/registry/manifest.js +4 -76
- package/dist/registry/manifest.js.map +1 -1
- package/dist/registry/packageExports.d.ts +9 -0
- package/dist/registry/packageExports.d.ts.map +1 -0
- package/dist/registry/packageExports.js +50 -0
- package/dist/registry/packageExports.js.map +1 -0
- package/dist/registry/readSource.d.ts +4 -2
- package/dist/registry/readSource.d.ts.map +1 -1
- package/dist/registry/readSource.js +27 -3
- package/dist/registry/readSource.js.map +1 -1
- package/dist/registry/types.d.ts +86 -3
- package/dist/registry/types.d.ts.map +1 -1
- package/dist/registry/types.js +46 -3
- package/dist/registry/types.js.map +1 -1
- package/dist/sources/builtins.d.ts +1 -5
- package/dist/sources/builtins.d.ts.map +1 -1
- package/dist/sources/builtins.js +2 -7
- package/dist/sources/builtins.js.map +1 -1
- package/dist/theme/cssVars.d.ts +30 -0
- package/dist/theme/cssVars.d.ts.map +1 -0
- package/dist/theme/cssVars.js +92 -0
- package/dist/theme/cssVars.js.map +1 -0
- package/dist/theme/detectCssFile.d.ts +9 -0
- package/dist/theme/detectCssFile.d.ts.map +1 -0
- package/dist/theme/detectCssFile.js +41 -0
- package/dist/theme/detectCssFile.js.map +1 -0
- package/package.json +8 -21
- package/template/build.ts +25 -0
- package/template/package.json +18 -0
- package/template/src/components/example/Example.css +20 -0
- package/template/src/components/example/Example.tsx +26 -0
- package/template/src/components/example/example.meta.ts +61 -0
- package/dist/components/basic/Card.css +0 -32
- package/dist/components/basic/Card.debug.ts +0 -5
- package/dist/components/basic/Card.tsx +0 -31
- package/dist/components/basic/CardFooter.css +0 -16
- package/dist/components/basic/CardFooter.debug.ts +0 -5
- package/dist/components/basic/CardFooter.tsx +0 -29
- package/dist/components/basic/CardHeader.css +0 -14
- package/dist/components/basic/CardHeader.debug.ts +0 -5
- package/dist/components/basic/CardHeader.tsx +0 -29
- package/dist/components/basic/card.meta.ts +0 -14
- package/dist/components/basic/cardfooter.meta.ts +0 -14
- package/dist/components/basic/cardheader.meta.ts +0 -14
- package/dist/components/input/Button.css +0 -34
- package/dist/components/input/Button.debug.ts +0 -5
- package/dist/components/input/Button.tsx +0 -28
- package/dist/components/input/button.meta.ts +0 -14
- package/dist/components.json +0 -138
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// packages/ui/src/cli/npmDependencies.ts
|
|
2
|
+
import { c, lineError, lineSuccess, lineWarn } from "@g3nomaly/core/cli";
|
|
3
|
+
import { findDependencyProblems } from "../packages/dependencies";
|
|
4
|
+
import { bunAdd } from "../packages/install";
|
|
5
|
+
/**
|
|
6
|
+
* @brief One line naming a package the app lacks or holds at the wrong version, and the components needing it.
|
|
7
|
+
*
|
|
8
|
+
* @param problem - The package and the components that list it.
|
|
9
|
+
* @returns The line, e.g. `radix-ui is not in package.json, needed by @shadcn/dialog`.
|
|
10
|
+
*/
|
|
11
|
+
function problemLine(problem) {
|
|
12
|
+
const neededBy = problem.neededBy.map((key) => c.key(key)).join(", ");
|
|
13
|
+
return problem.installed === undefined
|
|
14
|
+
? lineWarn(`${c.key(problem.dependency.name)} is not in package.json, needed by ${neededBy}`)
|
|
15
|
+
: lineWarn(`${c.key(problem.dependency.name)} ${problem.installed} is installed, ${neededBy} needs ${c.key(problem.dependency.spec)}`);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @brief Adds the packages with `bun add`, runtime and build-time packages in separate runs, and prints the outcome.
|
|
19
|
+
*
|
|
20
|
+
* @param projectRoot - Absolute project root.
|
|
21
|
+
* @param problems - Packages to add.
|
|
22
|
+
*/
|
|
23
|
+
async function installMissing(projectRoot, problems) {
|
|
24
|
+
for (const dev of [false, true]) {
|
|
25
|
+
const specs = problems.filter((p) => p.dev === dev).map((p) => p.dependency.spec);
|
|
26
|
+
if (specs.length === 0)
|
|
27
|
+
continue;
|
|
28
|
+
const error = await bunAdd(projectRoot, specs, dev);
|
|
29
|
+
console.log(error === undefined
|
|
30
|
+
? lineSuccess(`Added ${specs.map((s) => c.key(s)).join(", ")} with ${c.cmd(dev ? "bun add -d" : "bun add")}`)
|
|
31
|
+
: lineError(`${c.cmd(dev ? "bun add -d" : "bun add")} failed: ${error}`));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @brief Prints the command that adds the packages.
|
|
36
|
+
*
|
|
37
|
+
* @param problems - Packages to add.
|
|
38
|
+
*/
|
|
39
|
+
function printInstallHint(problems) {
|
|
40
|
+
const runtime = problems.filter((p) => !p.dev).map((p) => p.dependency.spec);
|
|
41
|
+
const dev = problems.filter((p) => p.dev).map((p) => p.dependency.spec);
|
|
42
|
+
const commands = [
|
|
43
|
+
...(runtime.length > 0 ? [c.cmd(`bun add ${runtime.join(" ")}`)] : []),
|
|
44
|
+
...(dev.length > 0 ? [c.cmd(`bun add -d ${dev.join(" ")}`)] : []),
|
|
45
|
+
];
|
|
46
|
+
console.log(lineWarn(`Run ${commands.join(" and ")}, or pass ${c.flag("--install")} to add them`));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @brief Checks the npm packages of components against the app's `package.json`, and reports or adds
|
|
50
|
+
* what is missing or out of range.
|
|
51
|
+
*
|
|
52
|
+
* @param projectRoot - Absolute project root holding the app's `package.json`.
|
|
53
|
+
* @param components - Components by key just installed or updated.
|
|
54
|
+
* @param install - Add the packages with `bun add` instead of only reporting them.
|
|
55
|
+
*/
|
|
56
|
+
export async function reportNpmDependencies(projectRoot, components, install) {
|
|
57
|
+
const problems = findDependencyProblems(projectRoot, components);
|
|
58
|
+
if (problems.length === 0)
|
|
59
|
+
return;
|
|
60
|
+
for (const problem of problems)
|
|
61
|
+
console.log(problemLine(problem));
|
|
62
|
+
if (install)
|
|
63
|
+
await installMissing(projectRoot, problems);
|
|
64
|
+
else
|
|
65
|
+
printInstallHint(problems);
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=npmDependencies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"npmDependencies.js","sourceRoot":"","sources":["../../src/cli/npmDependencies.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,sBAAsB,EAAE,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EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;KAClE,CAAC;IACF,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,CAAC;AACrG,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,WAAmB,EAAE,UAAyC,EAAE,OAAgB;IAC1H,MAAM,QAAQ,GAAG,sBAAsB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACjE,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IAClC,KAAK,MAAM,OAAO,IAAI,QAAQ;QAAE,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;IAClE,IAAI,OAAO;QAAE,MAAM,cAAc,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;;QACpD,gBAAgB,CAAC,QAAQ,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ManifestTarget } from "@g3nomaly/core/cli";
|
|
2
|
+
import type { ComponentMeta } from "../registry/types";
|
|
3
|
+
import type { UiProject } from "./adapter";
|
|
4
|
+
/**
|
|
5
|
+
* @brief Copies the files that stay in the package, such as stores, next to the installed components as
|
|
6
|
+
* unsafe copies. The components keep importing the package's version: the copies are not tracked,
|
|
7
|
+
* `update` and `remove` leave them alone, and pointing an import at one is the user's own edit.
|
|
8
|
+
* A file already at the destination is left as is.
|
|
9
|
+
*
|
|
10
|
+
* @param project - The opened project.
|
|
11
|
+
* @param target - Target the components were installed in.
|
|
12
|
+
* @param components - Components by key just installed.
|
|
13
|
+
*/
|
|
14
|
+
export declare function copyPackageFiles(project: UiProject, target: ManifestTarget, components: Record<string, ComponentMeta>): void;
|
|
15
|
+
//# sourceMappingURL=packageFiles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packageFiles.d.ts","sourceRoot":"","sources":["../../src/cli/packageFiles.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAe3C;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,IAAI,CAuB5H"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// packages/ui/src/cli/packageFiles.ts
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { c, lineInfo, lineWarn } from "@g3nomaly/core/cli";
|
|
5
|
+
import { findInstalledPackage } from "@g3nomaly/core/sources";
|
|
6
|
+
import { uiSources } from "./adapter";
|
|
7
|
+
/**
|
|
8
|
+
* @brief Folder the installed source package of a component sits in.
|
|
9
|
+
*
|
|
10
|
+
* @param project - The opened project.
|
|
11
|
+
* @param component - Component whose `origin.source` names the source.
|
|
12
|
+
* @returns The package folder, or `null` when the source is not an npm package or is not installed.
|
|
13
|
+
*/
|
|
14
|
+
function sourcePackageDir(project, component) {
|
|
15
|
+
const source = uiSources(project).find((s) => s.name === component.origin.source);
|
|
16
|
+
if (source?.spec.kind !== "npm")
|
|
17
|
+
return null;
|
|
18
|
+
return findInstalledPackage(project.projectRoot, source.spec.package)?.dir ?? null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @brief Copies the files that stay in the package, such as stores, next to the installed components as
|
|
22
|
+
* unsafe copies. The components keep importing the package's version: the copies are not tracked,
|
|
23
|
+
* `update` and `remove` leave them alone, and pointing an import at one is the user's own edit.
|
|
24
|
+
* A file already at the destination is left as is.
|
|
25
|
+
*
|
|
26
|
+
* @param project - The opened project.
|
|
27
|
+
* @param target - Target the components were installed in.
|
|
28
|
+
* @param components - Components by key just installed.
|
|
29
|
+
*/
|
|
30
|
+
export function copyPackageFiles(project, target, components) {
|
|
31
|
+
for (const [key, component] of Object.entries(components)) {
|
|
32
|
+
const files = component.packageFiles ?? [];
|
|
33
|
+
if (files.length === 0)
|
|
34
|
+
continue;
|
|
35
|
+
const packageDir = sourcePackageDir(project, component);
|
|
36
|
+
if (packageDir === null) {
|
|
37
|
+
console.log(lineWarn(`${c.key(key)}: its source ${c.key(component.origin.source)} is not an installed npm package, nothing copied`));
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
for (const file of files) {
|
|
41
|
+
const from = path.join(packageDir, component.origin.dir, file.path);
|
|
42
|
+
const to = path.join(target.installDir, file.path);
|
|
43
|
+
const shown = c.file(path.relative(project.projectRoot, to));
|
|
44
|
+
if (fs.existsSync(to)) {
|
|
45
|
+
console.log(lineInfo(`${shown} already exists, left as is`));
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
fs.mkdirSync(path.dirname(to), { recursive: true });
|
|
49
|
+
fs.copyFileSync(from, to);
|
|
50
|
+
console.log(lineWarn(`Copied ${shown} as an unsafe copy: ${c.key(key)} still imports it from the package. Point imports at the copy yourself; update and remove leave it alone.`));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=packageFiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packageFiles.js","sourceRoot":"","sources":["../../src/cli/packageFiles.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,EA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AAC,UAAU,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YACpE,MAAM,EAAE,GAAK,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YACrD,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC;YAC7D,IAAI,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,CAAC;gBACtB,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,KAAK,6BAA6B,CAAC,CAAC,CAAC;gBAC7D,SAAS;YACX,CAAC;YACD,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YACpD,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC1B,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,KAAK,uBAAuB,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,2GAA2G,CAAC,CAAC,CAAC;QACrL,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ComponentMeta } from "../registry/types";
|
|
2
|
+
/**
|
|
3
|
+
* @brief Adds the theme tokens components need to the app's global stylesheet. A token the stylesheet
|
|
4
|
+
* already defines keeps its value. Without a stylesheet set in `ui.settings.cssFile`, prints the tokens
|
|
5
|
+
* to add by hand.
|
|
6
|
+
*
|
|
7
|
+
* @param projectRoot - Absolute project root.
|
|
8
|
+
* @param cssFile - The stylesheet relative to the project root, e.g. `src/index.css`; `undefined` when not set.
|
|
9
|
+
* @param components - Components by key just installed or updated.
|
|
10
|
+
*/
|
|
11
|
+
export declare function applyThemeTokens(projectRoot: string, cssFile: string | undefined, components: Record<string, ComponentMeta>): void;
|
|
12
|
+
//# sourceMappingURL=themeTokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"themeTokens.d.ts","sourceRoot":"","sources":["../../src/cli/themeTokens.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAW,MAAM,mBAAmB,CAAC;AAkBhE;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,IAAI,CAoBlI"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// packages/ui/src/cli/themeTokens.ts
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { c, lineError, lineSuccess, lineWarn } from "@g3nomaly/core/cli";
|
|
5
|
+
import { addCssVars, mergeCssVars } from "../theme/cssVars";
|
|
6
|
+
/**
|
|
7
|
+
* @brief The tokens as stylesheet blocks, for pasting by hand.
|
|
8
|
+
*
|
|
9
|
+
* @param vars - Tokens to print.
|
|
10
|
+
* @returns One line per block and token.
|
|
11
|
+
*/
|
|
12
|
+
function blockLines(vars) {
|
|
13
|
+
const blocks = [[":root", vars.light], [".dark", vars.dark], ["@theme inline", vars.theme]];
|
|
14
|
+
return blocks.flatMap(([selector, tokens]) => {
|
|
15
|
+
const entries = Object.entries(tokens ?? {});
|
|
16
|
+
if (entries.length === 0)
|
|
17
|
+
return [];
|
|
18
|
+
return [` ${selector} {`, ...entries.map(([name, value]) => ` --${name.replace(/^--/, "")}: ${value};`), " }"];
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @brief Adds the theme tokens components need to the app's global stylesheet. A token the stylesheet
|
|
23
|
+
* already defines keeps its value. Without a stylesheet set in `ui.settings.cssFile`, prints the tokens
|
|
24
|
+
* to add by hand.
|
|
25
|
+
*
|
|
26
|
+
* @param projectRoot - Absolute project root.
|
|
27
|
+
* @param cssFile - The stylesheet relative to the project root, e.g. `src/index.css`; `undefined` when not set.
|
|
28
|
+
* @param components - Components by key just installed or updated.
|
|
29
|
+
*/
|
|
30
|
+
export function applyThemeTokens(projectRoot, cssFile, components) {
|
|
31
|
+
const withTokens = Object.values(components).flatMap((component) => component.cssVars === undefined ? [] : [component.cssVars]);
|
|
32
|
+
if (withTokens.length === 0)
|
|
33
|
+
return;
|
|
34
|
+
const vars = mergeCssVars(withTokens);
|
|
35
|
+
if (cssFile === undefined) {
|
|
36
|
+
console.log(lineWarn(`These components use theme tokens. Add them to your global stylesheet, or set it with ${c.cmd("g3n-ui init")} so they are added for you:`));
|
|
37
|
+
for (const line of blockLines(vars))
|
|
38
|
+
console.log(line);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const file = path.join(projectRoot, cssFile);
|
|
42
|
+
if (!fs.existsSync(file)) {
|
|
43
|
+
console.error(lineError(`${c.file(cssFile)} does not exist, theme tokens not added. Fix ${c.key("ui.settings.cssFile")} in .g3n.config.json`));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const merged = addCssVars(fs.readFileSync(file, "utf8"), vars);
|
|
47
|
+
if (merged.added.length === 0)
|
|
48
|
+
return;
|
|
49
|
+
fs.writeFileSync(file, merged.css);
|
|
50
|
+
console.log(lineSuccess(`Added ${merged.added.length} theme token${merged.added.length === 1 ? "" : "s"} to ${c.file(cssFile)}: ${merged.added.join(", ")}`));
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=themeTokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"themeTokens.js","sourceRoot":"","sources":["../../src/cli/themeTokens.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,CA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
|
|
1
|
+
import type { ComponentMeta } from "../registry/types";
|
|
2
|
+
/**
|
|
3
|
+
* @brief One npm package as a component lists it.
|
|
4
|
+
*
|
|
5
|
+
* @property spec - The text as listed, e.g. `recharts@3.8.0`, passed to `bun add` unchanged.
|
|
6
|
+
* @property name - Package name, e.g. `recharts` or `@base-ui/react`.
|
|
7
|
+
* @property range - Version range or dist-tag after the name, e.g. `3.8.0`; absent when the spec names no version.
|
|
8
|
+
*/
|
|
9
|
+
export interface NpmDependency {
|
|
10
|
+
spec: string;
|
|
11
|
+
name: string;
|
|
12
|
+
range?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @brief An npm package the app lacks, or holds at a version outside the range a component asks for.
|
|
16
|
+
*
|
|
17
|
+
* @property dependency - The package as the first component listing it asks for it.
|
|
18
|
+
* @property dev - Whether every component listing it needs it at build time only.
|
|
19
|
+
* @property neededBy - Keys of the components that list it, e.g. `["@shadcn/dialog"]`.
|
|
20
|
+
* @property installed - Installed version when it is outside the range; absent when the package is missing.
|
|
21
|
+
*/
|
|
22
|
+
export interface DependencyProblem {
|
|
23
|
+
dependency: NpmDependency;
|
|
24
|
+
dev: boolean;
|
|
25
|
+
neededBy: string[];
|
|
26
|
+
installed?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @brief Splits an npm spec into name and version range. The range follows the last `@` that is not a scope's.
|
|
30
|
+
*
|
|
31
|
+
* @param spec - Spec such as `radix-ui`, `recharts@3.8.0` or `@base-ui/react@^1`.
|
|
32
|
+
* @returns The parsed package.
|
|
33
|
+
*/
|
|
34
|
+
export declare function parseNpmDependency(spec: string): NpmDependency;
|
|
35
|
+
/**
|
|
36
|
+
* @brief Checks the npm packages of components against the app: a package its `package.json`
|
|
37
|
+
* does not declare is missing, and an installed package outside the requested range is out of range.
|
|
38
|
+
*
|
|
39
|
+
* @param projectRoot - Absolute project root holding the app's `package.json`.
|
|
40
|
+
* @param components - Components by key whose packages to check.
|
|
41
|
+
* @returns One problem per package, in the order the components list them; empty when the app has them all.
|
|
42
|
+
*/
|
|
43
|
+
export declare function findDependencyProblems(projectRoot: string, components: Record<string, ComponentMeta>): DependencyProblem[];
|
|
44
|
+
//# sourceMappingURL=dependencies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dependencies.d.ts","sourceRoot":"","sources":["../../src/packages/dependencies.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAI,MAAM,CAAC;IACf,IAAI,EAAI,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,aAAa,CAAC;IAC1B,GAAG,EAAS,OAAO,CAAC;IACpB,QAAQ,EAAI,MAAM,EAAE,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAG9D;AAYD;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,iBAAiB,EAAE,CA4B1H"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// packages/ui/src/packages/dependencies.ts
|
|
2
|
+
import { findInstalledPackage, readDeclaredDependencies } from "@g3nomaly/core/sources";
|
|
3
|
+
/**
|
|
4
|
+
* @brief Splits an npm spec into name and version range. The range follows the last `@` that is not a scope's.
|
|
5
|
+
*
|
|
6
|
+
* @param spec - Spec such as `radix-ui`, `recharts@3.8.0` or `@base-ui/react@^1`.
|
|
7
|
+
* @returns The parsed package.
|
|
8
|
+
*/
|
|
9
|
+
export function parseNpmDependency(spec) {
|
|
10
|
+
const at = spec.lastIndexOf("@");
|
|
11
|
+
return at > 0 ? { spec, name: spec.slice(0, at), range: spec.slice(at + 1) } : { spec, name: spec };
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @brief Whether a range can be checked against a version: a dist-tag such as `latest` cannot.
|
|
15
|
+
*
|
|
16
|
+
* @param range - Range or dist-tag after the package name.
|
|
17
|
+
* @returns `true` for a semver range such as `^1.2.0`, `3.8.0` or `*`.
|
|
18
|
+
*/
|
|
19
|
+
function isSemverRange(range) {
|
|
20
|
+
return !/^[a-z]/i.test(range);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @brief Checks the npm packages of components against the app: a package its `package.json`
|
|
24
|
+
* does not declare is missing, and an installed package outside the requested range is out of range.
|
|
25
|
+
*
|
|
26
|
+
* @param projectRoot - Absolute project root holding the app's `package.json`.
|
|
27
|
+
* @param components - Components by key whose packages to check.
|
|
28
|
+
* @returns One problem per package, in the order the components list them; empty when the app has them all.
|
|
29
|
+
*/
|
|
30
|
+
export function findDependencyProblems(projectRoot, components) {
|
|
31
|
+
const declared = readDeclaredDependencies(projectRoot);
|
|
32
|
+
const problems = new Map();
|
|
33
|
+
const check = (key, spec, dev) => {
|
|
34
|
+
const dependency = parseNpmDependency(spec);
|
|
35
|
+
const known = problems.get(dependency.name);
|
|
36
|
+
if (known !== undefined) {
|
|
37
|
+
known.neededBy.push(key);
|
|
38
|
+
known.dev &&= dev;
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (declared[dependency.name] === undefined) {
|
|
42
|
+
problems.set(dependency.name, { dependency, dev, neededBy: [key] });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (dependency.range === undefined || !isSemverRange(dependency.range))
|
|
46
|
+
return;
|
|
47
|
+
const installed = findInstalledPackage(projectRoot, dependency.name)?.version;
|
|
48
|
+
if (installed !== undefined && !Bun.semver.satisfies(installed, dependency.range)) {
|
|
49
|
+
problems.set(dependency.name, { dependency, dev, neededBy: [key], installed });
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
for (const [key, component] of Object.entries(components)) {
|
|
53
|
+
for (const spec of component.dependencies ?? [])
|
|
54
|
+
check(key, spec, false);
|
|
55
|
+
for (const spec of component.devDependencies ?? [])
|
|
56
|
+
check(key, spec, true);
|
|
57
|
+
}
|
|
58
|
+
return [...problems.values()];
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=dependencies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dependencies.js","sourceRoot":"","sources":["../../src/packages/dependencies.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AA+BxF;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACjC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACtG,CAAC;AAED;;;;;GAKG;AACH,SAAS,aAAa,CAAC,KAAa;IAClC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CAAC,WAAmB,EAAE,UAAyC;IACnG,MAAM,QAAQ,GAAG,wBAAwB,CAAC,WAAW,CAAC,CAAC;IACvD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA6B,CAAC;IAEtD,MAAM,KAAK,GAAG,CAAC,GAAW,EAAE,IAAY,EAAE,G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AAC,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QAC5E,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,eAAe,IAAI,EAAE;YAAE,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @brief Runs `bun add` in the project for the given specs, with `-d` for build-time packages.
|
|
3
|
+
*
|
|
4
|
+
* @param projectRoot - Absolute project root holding the app's `package.json`.
|
|
5
|
+
* @param specs - Specs to add, e.g. `["radix-ui", "recharts@3.8.0"]`.
|
|
6
|
+
* @param dev - Add them as `devDependencies`.
|
|
7
|
+
* @returns `undefined` on success, else the error `bun add` printed.
|
|
8
|
+
*/
|
|
9
|
+
export declare function bunAdd(projectRoot: string, specs: readonly string[], dev: boolean): Promise<string | undefined>;
|
|
10
|
+
//# sourceMappingURL=install.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../src/packages/install.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAsB,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CASrH"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// packages/ui/src/packages/install.ts
|
|
2
|
+
/**
|
|
3
|
+
* @brief Runs `bun add` in the project for the given specs, with `-d` for build-time packages.
|
|
4
|
+
*
|
|
5
|
+
* @param projectRoot - Absolute project root holding the app's `package.json`.
|
|
6
|
+
* @param specs - Specs to add, e.g. `["radix-ui", "recharts@3.8.0"]`.
|
|
7
|
+
* @param dev - Add them as `devDependencies`.
|
|
8
|
+
* @returns `undefined` on success, else the error `bun add` printed.
|
|
9
|
+
*/
|
|
10
|
+
export async function bunAdd(projectRoot, specs, dev) {
|
|
11
|
+
if (specs.length === 0)
|
|
12
|
+
return undefined;
|
|
13
|
+
const proc = Bun.spawn([process.execPath, "add", ...(dev ? ["-d"] : []), ...specs], {
|
|
14
|
+
cwd: projectRoot,
|
|
15
|
+
stdout: "ignore",
|
|
16
|
+
stderr: "pipe",
|
|
17
|
+
});
|
|
18
|
+
const [stderr, exitCode] = await Promise.all([new Response(proc.stderr).text(), proc.exited]);
|
|
19
|
+
return exitCode === 0 ? undefined : stderr.trim() || `bun add exited with ${exitCode}`;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=install.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.js","sourceRoot":"","sources":["../../src/packages/install.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,WAAmB,EAAE,KAAwB,EAAE,GAAY;IACtF,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACzC,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE;QAClF,GAAG,EAAK,WAAW;QACnB,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE,MAAM;KACf,CAAC,CAAC;IACH,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9F,OAAO,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,uBAAuB,QAAQ,EAAE,CAAC;AACzF,CAAC"}
|
|
@@ -4,16 +4,39 @@ import type { ComponentFileType, ComponentMeta } from "../types";
|
|
|
4
4
|
* @brief A single file returned by fetchShadcnComponentFiles().
|
|
5
5
|
*
|
|
6
6
|
* @property path - File path relative to the user's installDir, e.g. "shadcn/button.tsx".
|
|
7
|
-
* @property type -
|
|
7
|
+
* @property type - ui `ComponentFileType` the shadcn file type maps to.
|
|
8
8
|
*/
|
|
9
9
|
export interface ShadcnFileContent {
|
|
10
10
|
path: string;
|
|
11
11
|
content: string;
|
|
12
12
|
type: ComponentFileType;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* @brief What only a fetched shadcn component tells, since the index lacks it: its npm packages and theme tokens.
|
|
16
|
+
*/
|
|
17
|
+
export type FetchedComponentFields = Pick<ComponentMeta, "dependencies" | "devDependencies" | "cssVars">;
|
|
18
|
+
/**
|
|
19
|
+
* @brief The files of one shadcn component, with what it needs beside them.
|
|
20
|
+
*
|
|
21
|
+
* @property files - Files with their contents, imports already rewritten.
|
|
22
|
+
* @property fields - npm packages and theme tokens the component lists.
|
|
23
|
+
*/
|
|
24
|
+
export interface ShadcnComponent {
|
|
25
|
+
files: ShadcnFileContent[];
|
|
26
|
+
fields: FetchedComponentFields;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @brief Key a shadcn component is offered under.
|
|
30
|
+
*
|
|
31
|
+
* @param name - shadcn component name, e.g. `alert-dialog`.
|
|
32
|
+
* @returns The key, e.g. `@shadcn/alert-dialog`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function shadcnKey(name: string): string;
|
|
14
35
|
/**
|
|
15
36
|
* @brief Fetches the shadcn component index as entries keyed `@shadcn/<name>`,
|
|
16
|
-
* recorded under the `shadcn` source
|
|
37
|
+
* recorded under the `shadcn` source with the installed shadcn version as
|
|
38
|
+
* their version, so `update` shows the change after shadcn is upgraded.
|
|
39
|
+
* Hashes are absent until install.
|
|
17
40
|
*
|
|
18
41
|
* @returns no entries and a warning when shadcn is not installed or the index cannot be fetched
|
|
19
42
|
*/
|
|
@@ -22,20 +45,22 @@ export declare function readShadcnEntries(): Promise<{
|
|
|
22
45
|
warnings: string[];
|
|
23
46
|
}>;
|
|
24
47
|
/**
|
|
25
|
-
* @brief Fetches
|
|
26
|
-
*
|
|
48
|
+
* @brief Fetches one shadcn component through the installed shadcn package: its file contents,
|
|
49
|
+
* with registry imports rewritten to the installed siblings, and the npm packages and theme tokens
|
|
50
|
+
* it lists. The index lacks the theme tokens, so they are only known here.
|
|
27
51
|
*
|
|
28
52
|
* @param name - Component name without the `@shadcn/` prefix, e.g. `button`.
|
|
29
|
-
* @returns Files
|
|
53
|
+
* @returns Files and fields; no files when the component is unknown or lists none.
|
|
30
54
|
*/
|
|
31
|
-
export declare function
|
|
55
|
+
export declare function fetchShadcnComponent(name: string): Promise<ShadcnComponent>;
|
|
32
56
|
/**
|
|
33
57
|
* @brief Entry source that fetches shadcn components, one request per component,
|
|
34
58
|
* and writes each file from its content; entries of any other source go to
|
|
35
59
|
* `fallback`.
|
|
36
60
|
*
|
|
37
61
|
* @param fallback - Entry source for every entry of another source.
|
|
62
|
+
* @param fetchedByKey - Filled with the npm packages and theme tokens of each shadcn component fetched, by component key.
|
|
38
63
|
* @returns Entry source that serves shadcn entries and delegates the rest to `fallback`.
|
|
39
64
|
*/
|
|
40
|
-
export declare function shadcnFileSource(fallback: EntrySource): EntrySource;
|
|
65
|
+
export declare function shadcnFileSource(fallback: EntrySource, fetchedByKey: Map<string, FetchedComponentFields>): EntrySource;
|
|
41
66
|
//# sourceMappingURL=shadcn.adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shadcn.adapter.d.ts","sourceRoot":"","sources":["../../../src/registry/adapters/shadcn.adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shadcn.adapter.d.ts","sourceRoot":"","sources":["../../../src/registry/adapters/shadcn.adapter.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAWjE;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAK,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAK,iBAAiB,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,aAAa,EAAE,cAAc,GAAG,iBAAiB,GAAG,SAAS,CAAC,CAAC;AAEzG;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAG,iBAAiB,EAAE,CAAC;IAC5B,MAAM,EAAE,sBAAsB,CAAC;CAChC;AAiED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC;IAAE,OAAO,EAAE,CAAC,MAAM,EAAE,aAAa,CAAC,EAAE,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAiC7G;AAED;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAiBjF;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC,GAAG,WAAW,CActH"}
|