export const configPackageName = "personal-brand-config"; import { generatedTemplatePackageRegistry } from "./generated-template-packages.js"; export type BrandTemplateKey = "personal" | "food" | "doors"; export type VisualTemplateKey = "linjing-editorial" | "acheng-campus-food"; export type CapabilityKey = "offerings" | "inquiry" | "booking" | "quote-request"; export interface WorkflowDefinition { key: string; version: string; initialState: string; transitions: Record; } export interface CapabilityDefinition { key: CapabilityKey; version: string; workflowKey?: string; } export const workflowRegistry = { "booking.basic": { key: "booking.basic", version: "1.0.0", initialState: "received", transitions: { received: ["contacting", "cancelled"], contacting: ["confirmed", "cancelled"], confirmed: ["completed", "cancelled"], completed: [], cancelled: [], }, }, } as const satisfies Record; export const capabilityRegistry = { offerings: { key: "offerings", version: "1.0.0" }, inquiry: { key: "inquiry", version: "1.0.0" }, booking: { key: "booking", version: "1.0.0", workflowKey: "booking.basic" }, "quote-request": { key: "quote-request", version: "1.0.0" }, } as const satisfies Record; export const capabilityPlugins = { inquiry: { key: "inquiry", version: "1.0.0", displayName: "通用咨询", purpose: "inquiry", requiredModules: ["inquiry", "records", "success-summary"], apiContract: "/customer/inquiry-submissions", configSchema: "capability.inquiry.v1", }, "quote-request": { key: "quote-request", version: "1.0.0", displayName: "报价咨询", purpose: "quote-request", requiredModules: ["inquiry", "records", "success-summary"], apiContract: "/customer/inquiry-submissions", configSchema: "capability.quote-request.v1", }, } as const; export type BrandTemplateModuleType = "identity" | "trust" | "offering" | "inquiry" | "contact"; export interface BrandTemplateModuleDefinition { key: string; type: BrandTemplateModuleType; title: string; required: boolean; } export interface BrandTemplateFieldDefinition { scope: string; key: string; label: string; type: string; required: boolean; } export interface BrandTemplateDefinition { key: BrandTemplateKey; version: string; name: string; description: string; serviceCategories: string[]; trustContentTypes: string[]; modules: BrandTemplateModuleDefinition[]; fields: BrandTemplateFieldDefinition[]; capabilities: CapabilityKey[]; } export interface VisualTemplateDefinition { key: VisualTemplateKey; version: string; name: string; description: string; supportedIndustryTemplates: readonly BrandTemplateKey[]; variants: Record; theme: { colors: Record; radius: Record }; layout?: { home: string[]; offerings: string[]; detail: string[]; profile: string[] }; } export type VisualPageKey = "home" | "offerings" | "detail" | "inquiry" | "success" | "records" | "profile"; export type VisualModuleType = | "brand-identity" | "hero" | "trust" | "offering-list" | "offering-detail" | "inquiry-form" | "success-summary" | "records-list" | "contact"; export interface VisualTokenSet { colors: Record; spacing: Record; typography: Record; radius: Record; shadows?: Record; } export interface VisualAssetSlot { key: string; label: string; required: boolean; kind: "image" | "icon" | "logo" | "texture"; aspectRatio?: string; fallback?: string; } export interface VisualDataSlot { key: string; source: "brand" | "trust" | "offering" | "inquiry" | "records" | "profile"; required: boolean; description: string; } export interface VisualModuleDefinition { key: string; type: VisualModuleType; variant: string; required: boolean; dataSlots?: string[]; assetSlots?: string[]; capability?: CapabilityKey; } export interface VisualPageDefinition { key: VisualPageKey; title: string; renderer?: string; modules: VisualModuleDefinition[]; } export interface VisualTemplateManifest { schemaVersion: "1.0"; key: VisualTemplateKey; version: string; name: string; description: string; supportedIndustryTemplates: BrandTemplateKey[]; brandFirst: true; tokens: VisualTokenSet; pages: VisualPageDefinition[]; assets: VisualAssetSlot[]; dataSlots: VisualDataSlot[]; capabilities: CapabilityKey[]; } export interface TemplatePackage { manifest: VisualTemplateManifest; industryTemplateKey: BrandTemplateKey; content: Record; forms: Record[]; capabilityConfig: Record; fixtures: { runtime: Record; visual: Record; }; } export interface TemplatePackageManifest { packageKey: string; version: string; displayName: string; visualTemplateKey: VisualTemplateKey; runtimeContract: "1.0"; supportedIndustryTemplates: readonly BrandTemplateKey[]; entrypoints: Readonly>; requiredCapabilities: readonly CapabilityKey[]; defaultBrandSlug: string; navigation: readonly { key: string; label: string; page: string; iconPath?: string; selectedIconPath?: string; }[]; renderers: Readonly>; runtimeOwnedPages: readonly string[]; dataSlots: readonly { key: string; source: string; required: boolean; description: string; }[]; assetSlots: readonly { key: string; binding: string; target: "brand" | "offering" | "trust"; label: string; help: string; required: boolean; }[]; admin: { sections: readonly { key: string; title: string; description: string; target: "brand" | "offering" | "trust" | "inquiry"; fields: readonly { key: string; binding: string; label: string; required?: boolean }[]; }[]; }; trustContentTypes?: readonly { type: string; label: string; help?: string; placeholder?: string; required?: boolean; }[]; sampleContent?: Partial>; } export const templatePackageRegistry: readonly TemplatePackageManifest[] = generatedTemplatePackageRegistry; export function getTemplatePackageManifest(key: string): TemplatePackageManifest | undefined { return templatePackageRegistry.find((item) => item.packageKey === key); } export function getTemplatePackageManifestForVisualKey( visualTemplateKey: string, ): TemplatePackageManifest | undefined { return templatePackageRegistry.find((item) => item.visualTemplateKey === visualTemplateKey); } export function validateTemplatePackageManifest(manifest: TemplatePackageManifest): string[] { const errors: string[] = []; if (!manifest.packageKey.trim()) errors.push("packageKey is required"); if (!manifest.version.trim()) errors.push("version is required"); if (manifest.runtimeContract !== "1.0") errors.push("unsupported runtimeContract"); if (!manifest.supportedIndustryTemplates.length) errors.push("supportedIndustryTemplates must not be empty"); for (const page of [ "home", "offerings", "detail", "inquiry", "success", "records", "profile", ] as const) { if (!manifest.entrypoints[page]?.trim()) errors.push(`entrypoints.${page} is required`); } return errors; } export interface TemplateSampleContent { templateKey: BrandTemplateKey; offerings: Array<{ kind: "service" | "product" | "package" | "subscription"; name: string; summary: string; categoryKey: string; }>; trustContent: Array<{ type: string; title: string; content: string; summary?: string }>; fields: Array<{ key: string; label: string; type: string; required: boolean; options?: Array<{ label: string; value: string }>; }>; capabilityKey: string; } const doorsSampleContent: TemplateSampleContent = { templateKey: "doors", offerings: [ { kind: "product", name: "序章·入户门", summary: "为别墅入口定制的整樘门系统", categoryKey: "entrance-door", }, { kind: "product", name: "庭院·边界门", summary: "连接建筑与庭院的定制门", categoryKey: "garden-door", }, { kind: "product", name: "室内·静谧门", summary: "统一室内空间秩序的户内门", categoryKey: "interior-door", }, { kind: "service", name: "一对一门系统设计咨询", summary: "从现场到方案的完整设计沟通", categoryKey: "custom", }, ], trustContent: [ { type: "credential", title: "主理人的门作观", content: "示例内容,待品牌主理人完善。" }, { type: "case", title: "别墅门系统案例", content: "示例内容,待品牌主理人完善。" }, { type: "process", title: "从测量到交付", content: "示例内容,待品牌主理人完善。" }, { type: "credential", title: "材料与工艺标准", content: "示例内容,待品牌主理人完善。" }, ], fields: [ { key: "projectType", label: "项目类型", type: "select", required: false }, { key: "projectStage", label: "项目阶段", type: "select", required: false }, { key: "siteDescription", label: "项目概况", type: "textarea", required: false }, { key: "phone", label: "联系方式", type: "phone", required: true }, ], capabilityKey: "doors", }; const foodSampleContent: TemplateSampleContent = { templateKey: "food", offerings: [ { kind: "package", name: "示例·今日套餐", summary: "现做家常套餐示例内容。", categoryKey: "set-meal", }, { kind: "service", name: "示例·聚餐定制", summary: "按人数和口味沟通定制餐品。", categoryKey: "private-chef", }, ], trustContent: [ { type: "credential", title: "关于主理人", content: "示例内容,待品牌主理人完善。" }, { type: "process", title: "从预订到取餐", content: "示例内容,待品牌主理人完善。" }, ], fields: [ { key: "date", label: "用餐日期", type: "date", required: true }, { key: "number", label: "用餐人数", type: "number", required: true }, { key: "phone", label: "联系方式", type: "phone", required: true }, ], capabilityKey: "booking", }; const personalSampleContent: TemplateSampleContent = { templateKey: "personal", offerings: [ { kind: "service", name: "示例·品牌定位咨询", summary: "梳理品牌定位与下一步行动。", categoryKey: "consulting", }, { kind: "service", name: "示例·长期顾问支持", summary: "围绕表达和转化提供持续支持。", categoryKey: "advisory", }, ], trustContent: [ { type: "credential", title: "关于主理人", content: "示例内容,待品牌主理人完善。" }, { type: "process", title: "合作方法", content: "示例内容,待品牌主理人完善。" }, ], fields: [ { key: "name", label: "您的称呼", type: "text", required: true }, { key: "phone", label: "联系方式", type: "phone", required: true }, { key: "remark", label: "合作需求", type: "textarea", required: true }, ], capabilityKey: "inquiry", }; export const templateSampleContent: Record = { personal: personalSampleContent, food: foodSampleContent, doors: doorsSampleContent, }; export function getTemplateSampleContent(templateKey: string): TemplateSampleContent | undefined { const packageSample = templatePackageRegistry.find((item) => item.supportedIndustryTemplates.includes(templateKey as BrandTemplateKey), )?.sampleContent?.[templateKey as BrandTemplateKey]; return packageSample ?? templateSampleContent[templateKey as keyof typeof templateSampleContent]; } const linjingEditorialManifest: VisualTemplateManifest = { schemaVersion: "1.0", key: "linjing-editorial", version: "1.0.0", name: "林境建筑画册", description: "以个人品牌信任为主线、以高端项目作品为表达重点的编辑式视觉模板。", supportedIndustryTemplates: ["personal", "doors"], brandFirst: true, tokens: { colors: { background: "#F7F5F1", surface: "#FFFFFF", foreground: "#252525", muted: "#77736C", accent: "#8A6846", dark: "#202221", }, spacing: { page: "32rpx", section: "56rpx", module: "24rpx" }, typography: { display: "56rpx", heading: "36rpx", body: "28rpx", caption: "22rpx" }, radius: { card: "16rpx", button: "999rpx", media: "12rpx" }, shadows: { card: "0 8rpx 32rpx rgba(32,34,33,0.08)" }, }, assets: [ { key: "brand.logo", label: "品牌标志", required: false, kind: "logo" }, { key: "home.hero", label: "首页首屏图", required: true, kind: "image", aspectRatio: "16:9", }, { key: "offering.cover", label: "业务提供项封面", required: true, kind: "image", aspectRatio: "1:1", }, { key: "profile.portrait", label: "主理人肖像", required: false, kind: "image", aspectRatio: "1:1", }, { key: "brand.texture", label: "品牌底纹", required: false, kind: "texture" }, ], dataSlots: [ { key: "brand.identity", source: "brand", required: true, description: "品牌名、定位和主理人身份", }, { key: "brand.hero", source: "brand", required: true, description: "品牌首屏表达和行动入口" }, { key: "trust.proof", source: "trust", required: true, description: "经历、资质、案例和方法" }, { key: "offerings.list", source: "offering", required: true, description: "可展示的业务提供项", }, { key: "offering.detail", source: "offering", required: true, description: "单个提供项的详情内容", }, { key: "inquiry.form", source: "inquiry", required: true, description: "品牌咨询或预约表单" }, { key: "records.items", source: "records", required: true, description: "用户提交后的跟进记录", }, { key: "profile.contact", source: "profile", required: true, description: "联系方式和合作预期", }, ], pages: [ { key: "home", title: "首页", renderer: "linjing-home", modules: [ { key: "identity", type: "brand-identity", variant: "editorial-card", required: true, dataSlots: ["brand.identity"], assetSlots: ["brand.logo"], }, { key: "hero", type: "hero", variant: "architectural", required: true, dataSlots: ["brand.hero"], assetSlots: ["home.hero"], }, { key: "proof", type: "trust", variant: "proof-strip", required: true, dataSlots: ["trust.proof"], }, { key: "offerings", type: "offering-list", variant: "editorial-list", required: true, dataSlots: ["offerings.list"], assetSlots: ["offering.cover"], capability: "offerings", }, { key: "contact", type: "contact", variant: "quiet-footer", required: true, dataSlots: ["profile.contact"], }, ], }, { key: "offerings", title: "业务提供项", renderer: "linjing-offerings", modules: [ { key: "offerings", type: "offering-list", variant: "editorial-grid", required: true, dataSlots: ["offerings.list"], assetSlots: ["offering.cover"], capability: "offerings", }, ], }, { key: "detail", title: "提供项详情", renderer: "linjing-offering-detail", modules: [ { key: "detail", type: "offering-detail", variant: "project-case", required: true, dataSlots: ["offering.detail"], assetSlots: ["offering.cover"], capability: "offerings", }, ], }, { key: "inquiry", title: "咨询与预约", renderer: "linjing-inquiry", modules: [ { key: "inquiry", type: "inquiry-form", variant: "editorial-form", required: true, dataSlots: ["inquiry.form"], capability: "inquiry", }, ], }, { key: "success", title: "提交成功", renderer: "linjing-success", modules: [ { key: "success", type: "success-summary", variant: "editorial-confirmation", required: true, dataSlots: ["brand.identity"], }, ], }, { key: "records", title: "我的记录", renderer: "linjing-records", modules: [ { key: "records", type: "records-list", variant: "timeline", required: true, dataSlots: ["records.items"], }, ], }, { key: "profile", title: "主理人与我", renderer: "linjing-profile", modules: [ { key: "identity", type: "brand-identity", variant: "profile-editorial", required: true, dataSlots: ["brand.identity"], assetSlots: ["profile.portrait"], }, { key: "contact", type: "contact", variant: "contact-sheet", required: true, dataSlots: ["profile.contact"], }, ], }, ], capabilities: ["offerings", "inquiry"], }; export const visualTemplateManifests: Record = { "linjing-editorial": linjingEditorialManifest, "acheng-campus-food": { ...linjingEditorialManifest, key: "acheng-campus-food", version: "1.0.0", name: "阿成校园餐", description: "面向校园餐饮摊贩的菜单、出摊动态和团体预订视觉模板。", supportedIndustryTemplates: ["food"], tokens: { ...linjingEditorialManifest.tokens, colors: { background: "#FFF8F0", surface: "#FFFFFF", foreground: "#29231F", muted: "#7A6A60", accent: "#E87532", dark: "#3B2118", }, radius: { card: "24rpx", button: "999rpx", media: "20rpx" }, }, pages: linjingEditorialManifest.pages.map((pageDefinition) => { const renderer = pageDefinition.key === "home" ? "acheng-home" : pageDefinition.key === "offerings" ? "acheng-offerings" : pageDefinition.key === "profile" ? "acheng-profile" : pageDefinition.renderer; return renderer ? { ...pageDefinition, renderer } : pageDefinition; }), capabilities: ["offerings", "inquiry", "booking"], }, }; export function getVisualTemplateManifest(key: string): VisualTemplateManifest | undefined { return visualTemplateManifests[key as VisualTemplateKey]; } export function isVisualTemplateCompatible( visualTemplate: VisualTemplateDefinition | VisualTemplateManifest, industryTemplateKey: string, ): boolean { return visualTemplate.supportedIndustryTemplates.includes( industryTemplateKey as BrandTemplateKey, ); } export const visualTemplates: Record = { "linjing-editorial": { key: "linjing-editorial", version: "1.0.0", name: "林境建筑画册", description: "适合高端定制、建筑作品和项目型个人品牌。", supportedIndustryTemplates: ["personal", "doors"], variants: { hero: "architectural", offeringList: "editorial", detail: "project-case" }, theme: { colors: { background: "#F7F5F1", foreground: "#252525", accent: "#8A6846", dark: "#202221" }, radius: { card: "16rpx" }, }, layout: { home: ["founder-card", "brand-hero", "trust-proof", "trust-manifesto", "offering-list"], offerings: ["offering-list"], detail: ["offering-detail"], profile: ["profile"], }, }, "acheng-campus-food": { key: "acheng-campus-food", version: "1.0.0", name: "阿成校园餐", description: "适合校园餐饮、套餐预订和团体定制的暖橙菜单视觉。", supportedIndustryTemplates: ["food"], variants: { hero: "stall-board", offeringList: "menu-card", detail: "dish-detail" }, theme: { colors: { background: "#FFF8F0", foreground: "#29231F", accent: "#E87532", dark: "#3B2118" }, radius: { card: "24rpx" }, }, layout: { home: ["founder-card", "brand-hero", "trust-proof", "offering-list"], offerings: ["offering-list"], detail: ["offering-detail"], profile: ["profile"], }, }, }; export function listVisualTemplateKeys(): VisualTemplateKey[] { return Object.keys(visualTemplates) as VisualTemplateKey[]; } export function getVisualTemplate(key: string): VisualTemplateDefinition | undefined { return visualTemplates[key as VisualTemplateKey]; } export function getDefaultVisualTemplateKey(industryTemplateKey: string): VisualTemplateKey { return ( listVisualTemplateKeys().find((key) => visualTemplates[key].supportedIndustryTemplates.includes( industryTemplateKey as BrandTemplateKey, ), ) ?? "linjing-editorial" ); } export function canTransitionWorkflow(workflowKey: string, from: string, to: string): boolean { const workflow = workflowRegistry[workflowKey as keyof typeof workflowRegistry] as WorkflowDefinition | undefined; return workflow ? from === to || workflow.transitions[from]?.includes(to) === true : false; } export function resolveCapabilities(keys: readonly CapabilityKey[]): CapabilityDefinition[] { return keys.map((key) => capabilityRegistry[key]); } export const brandTemplates = { personal: { key: "personal", version: "1.0.0", name: "个人品牌", description: "围绕定位、信任、作品与合作建立个人品牌。", serviceCategories: ["consulting", "collaboration", "custom"], trustContentTypes: [ "profile", "experience", "credential", "portfolio", "process", "testimonial", ], modules: [ { key: "identity", type: "identity", title: "品牌身份", required: true }, { key: "trust", type: "trust", title: "信任内容", required: true }, { key: "offerings", type: "offering", title: "业务提供项", required: true }, { key: "inquiry", type: "inquiry", title: "联系与咨询", required: true }, { key: "contact", type: "contact", title: "品牌表达", required: true }, ], fields: [ { scope: "profile", key: "name", label: "品牌名称", type: "text", required: true }, { scope: "profile", key: "tagline", label: "一句话定位", type: "text", required: true }, { scope: "profile", key: "audience", label: "服务对象", type: "textarea", required: true }, { scope: "profile", key: "valueProposition", label: "提供的价值", type: "textarea", required: true, }, { scope: "profile", key: "trustProof", label: "信任证明入口", type: "textarea", required: true, }, ], capabilities: ["offerings", "inquiry"], }, food: { key: "food", version: "1.0.0", name: "餐饮模板", description: "适用于餐饮服务与套餐预约的行业模板。", serviceCategories: ["food-package", "private-chef", "custom"], trustContentTypes: [ "profile", "experience", "credential", "portfolio", "process", "testimonial", ], modules: [ { key: "identity", type: "identity", title: "品牌身份", required: true }, { key: "trust", type: "trust", title: "信任内容", required: true }, { key: "offerings", type: "offering", title: "菜单与服务", required: true }, { key: "inquiry", type: "inquiry", title: "预约与咨询", required: true }, { key: "contact", type: "contact", title: "品牌表达", required: true }, ], fields: [ { scope: "profile", key: "name", label: "品牌名称", type: "text", required: true }, { scope: "profile", key: "tagline", label: "一句话定位", type: "text", required: true }, { scope: "profile", key: "audience", label: "服务对象", type: "textarea", required: true }, { scope: "profile", key: "valueProposition", label: "提供的价值", type: "textarea", required: true, }, { scope: "profile", key: "trustProof", label: "信任证明入口", type: "textarea", required: true, }, ], capabilities: ["offerings", "inquiry", "booking"], }, doors: { key: "doors", version: "1.0.0", name: "高端门窗模板", description: "适用于别墅门、院门、室内门与定制门窗服务的行业模板。", serviceCategories: ["entrance-door", "garden-door", "interior-door", "custom"], trustContentTypes: [ "profile", "experience", "credential", "portfolio", "process", "testimonial", ], modules: [ { key: "identity", type: "identity", title: "品牌身份", required: true }, { key: "trust", type: "trust", title: "工艺与信任", required: true }, { key: "offerings", type: "offering", title: "门窗系列", required: true }, { key: "inquiry", type: "inquiry", title: "设计咨询", required: true }, { key: "contact", type: "contact", title: "品牌表达", required: true }, ], fields: [ { scope: "profile", key: "name", label: "品牌名称", type: "text", required: true }, { scope: "profile", key: "tagline", label: "一句话定位", type: "text", required: true }, { scope: "profile", key: "audience", label: "服务对象", type: "textarea", required: true }, { scope: "profile", key: "valueProposition", label: "提供的价值", type: "textarea", required: true, }, { scope: "profile", key: "trustProof", label: "信任证明入口", type: "textarea", required: true, }, ], capabilities: ["offerings", "inquiry"], }, } satisfies Record; export function isBrandTemplateKey(value: string): value is BrandTemplateKey { return Object.prototype.hasOwnProperty.call(brandTemplates, value); } export function getBrandTemplate(key: string): BrandTemplateDefinition | undefined { return isBrandTemplateKey(key) ? brandTemplates[key] : undefined; }