feat: release design system engine, studio and component contracts
This commit is contained in:
1 parent
ff1065fb27
commit
3943b946d6
693 files changed
+175546
-3894
No files matched your search
@@ -0,0 +1,47 @@
|
||||
import type { DesignDiagnostic, ResolveOptions } from "./types.ts";
|
||||
import {
|
||||
validateDesignSystem as validateSchema,
|
||||
DesignSystemError,
|
||||
assertDesignSystem,
|
||||
} from "./validation.ts";
|
||||
import { compileDesignSystem } from "./compile.ts";
|
||||
|
||||
/** Validate schema and every available mode/density combination, including output bindings. */
|
||||
export function validateDesignSystem(
|
||||
input: unknown,
|
||||
options: ResolveOptions = {},
|
||||
): DesignDiagnostic[] {
|
||||
const diagnostics = validateSchema(input);
|
||||
if (diagnostics.length) return diagnostics;
|
||||
assertDesignSystem(input);
|
||||
try {
|
||||
const initial = compileDesignSystem(input, options);
|
||||
// Discover inherited density names using a bounded traversal of validated parents.
|
||||
const densities = new Set<string>();
|
||||
const seen = new Set<string>();
|
||||
const walk = (system: typeof input) => {
|
||||
if (seen.has(system.id)) return;
|
||||
seen.add(system.id);
|
||||
for (const name of Object.keys(system.densities ?? {})) densities.add(name);
|
||||
for (const id of system.extends ?? []) {
|
||||
const parent = options.registry?.[id];
|
||||
if (parent) walk(parent);
|
||||
}
|
||||
};
|
||||
walk(input);
|
||||
if (densities.size * Math.max(initial.resolved.modes.length, 1) > 1024)
|
||||
return [
|
||||
{
|
||||
code: "WRN-DS-LIMIT",
|
||||
path: "densities",
|
||||
message: "Validation exceeds 1024 mode/density combinations.",
|
||||
},
|
||||
];
|
||||
for (const density of [...densities].sort())
|
||||
compileDesignSystem(input, { ...options, density });
|
||||
return [];
|
||||
} catch (error) {
|
||||
if (error instanceof DesignSystemError) return error.diagnostics;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user