Files
persionalBrand/apps/miniapp/utils/module-registry.js
T

33 lines
2.0 KiB
JavaScript

const CORE_MODULES = {
brandHero: { key: "brand-hero", variants: ["architectural", "portrait", "editorial"] },
founderCard: { key: "founder-card", variants: ["compact", "contact"] },
trustProof: { key: "trust-proof", variants: ["stats", "manifesto", "timeline"] },
offeringList: { key: "offering-list", variants: ["image-first", "editorial", "square-card"] },
offeringDetail: { key: "offering-detail", variants: ["project-case", "product-spec", "service-process"] },
inquiry: { key: "inquiry", variants: ["standard", "project-brief", "booking"] },
records: { key: "records", variants: ["timeline", "list"] },
profile: { key: "profile", variants: ["contact", "editorial"] },
};
const FALLBACK_THEME = {
colors: { background: "#F7F5F1", surface: "#FFFFFF", foreground: "#252525", muted: "#77736B", accent: "#8A6846", dark: "#202221", border: "#E6DED5" },
radius: { card: "16rpx", control: "8rpx" },
spacing: { page: "32rpx", section: "28rpx" },
};
function resolveModule(module) {
const aliases = { identity: "brand-hero", trust: "trust-proof", offering: "offering-list", inquiry: "inquiry", contact: "founder-card" };
const type = aliases[module.type] || module.type;
const known = Object.values(CORE_MODULES).find((entry) => entry.key === type);
return { ...module, type, variant: module.variant || (known ? known.variants[0] : "default"), supported: Boolean(known || type === "custom") };
}
function resolveRuntime(workspace) {
const modules = Array.isArray(workspace && workspace.modules) ? workspace.modules : [];
const resolved = modules.map(resolveModule);
const home = workspace && workspace.layout && Array.isArray(workspace.layout.home) ? workspace.layout.home : resolved.map((item) => item.type);
return { theme: workspace && workspace.theme ? workspace.theme : FALLBACK_THEME, modules: resolved, layout: { home: home.filter((key) => resolved.some((item) => item.type === key)) }, capabilities: workspace && Array.isArray(workspace.capabilities) ? workspace.capabilities : [] };
}
module.exports = { CORE_MODULES, FALLBACK_THEME, resolveRuntime };