Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix(poster): resolve element overlaps and standardize card sections on template switch

tianma-if1b569033330e
diff --git a/apps/api/src/demo-seed-data.ts b/apps/api/src/demo-seed-data.ts
index 3732723f..50c25d95 100644
--- a/apps/api/src/demo-seed-data.ts
+++ b/apps/api/src/demo-seed-data.ts
@@ -288,8 +288,8 @@ export const DEMO_POSTER_DOCUMENT_ZH: PosterDocument = {
},
elements: [
{
- id: "accent-bar",
- name: "accent-bar",
+ id: "accent",
+ name: "accent",
type: "rect",
x: 96,
y: 110,
@@ -301,8 +301,8 @@ export const DEMO_POSTER_DOCUMENT_ZH: PosterDocument = {
locked: false,
},
{
- id: "badge-text",
- name: "badge-text",
+ id: "badge",
+ name: "badge",
type: "text",
role: "badge",
text: "EDGEEVER · 知识艺术",
@@ -359,8 +359,8 @@ export const DEMO_POSTER_DOCUMENT_ZH: PosterDocument = {
textAlign: "left",
},
{
- id: "card-1-bg",
- name: "card-1-bg",
+ id: "section-1-card",
+ name: "section-1-card",
type: "rect",
x: 96,
y: 590,
@@ -373,8 +373,8 @@ export const DEMO_POSTER_DOCUMENT_ZH: PosterDocument = {
locked: false,
},
{
- id: "card-1-title",
- name: "card-1-title",
+ id: "section-1-heading",
+ name: "section-1-heading",
type: "text",
text: "01 · 原生 MCP / ACP 双协议支持",
x: 136,
@@ -391,8 +391,8 @@ export const DEMO_POSTER_DOCUMENT_ZH: PosterDocument = {
textAlign: "left",
},
{
- id: "card-1-body",
- name: "card-1-body",
+ id: "section-1-body",
+ name: "section-1-body",
type: "text",
text: "原生对接 Claude、Cursor、Codex 等外部 Agent,桌面端无缝协同本地智能体。",
x: 136,
@@ -410,8 +410,8 @@ export const DEMO_POSTER_DOCUMENT_ZH: PosterDocument = {
lineHeight: 1.4,
},
{
- id: "card-2-bg",
- name: "card-2-bg",
+ id: "section-2-card",
+ name: "section-2-card",
type: "rect",
x: 96,
y: 840,
@@ -424,8 +424,8 @@ export const DEMO_POSTER_DOCUMENT_ZH: PosterDocument = {
locked: false,
},
{
- id: "card-2-title",
- name: "card-2-title",
+ id: "section-2-heading",
+ name: "section-2-heading",
type: "text",
text: "02 · 零成本 Serverless 与自由部署",
x: 136,
@@ -442,8 +442,8 @@ export const DEMO_POSTER_DOCUMENT_ZH: PosterDocument = {
textAlign: "left",
},
{
- id: "card-2-body",
- name: "card-2-body",
+ id: "section-2-body",
+ name: "section-2-body",
type: "text",
text: "跑在 Cloudflare 免费额度内或一键 Docker 自建,标准 SQLite 存储,导出无阻碍。",
x: 136,
@@ -461,8 +461,8 @@ export const DEMO_POSTER_DOCUMENT_ZH: PosterDocument = {
lineHeight: 1.4,
},
{
- id: "card-3-bg",
- name: "card-3-bg",
+ id: "section-3-card",
+ name: "section-3-card",
type: "rect",
x: 96,
y: 1090,
@@ -475,8 +475,8 @@ export const DEMO_POSTER_DOCUMENT_ZH: PosterDocument = {
locked: false,
},
{
- id: "card-3-title",
- name: "card-3-title",
+ id: "section-3-heading",
+ name: "section-3-heading",
type: "text",
text: "03 · 全平台客户端与独立知识库",
x: 136,
@@ -493,8 +493,8 @@ export const DEMO_POSTER_DOCUMENT_ZH: PosterDocument = {
textAlign: "left",
},
{
- id: "card-3-body",
- name: "card-3-body",
+ id: "section-3-body",
+ name: "section-3-body",
type: "text",
text: "macOS、Windows、Linux、iOS 与 Android 覆盖,支持一键将笔记本发布为知识库网站。",
x: 136,
@@ -527,8 +527,8 @@ export const DEMO_POSTER_DOCUMENT_EN: PosterDocument = {
},
elements: [
{
- id: "accent-bar",
- name: "accent-bar",
+ id: "accent",
+ name: "accent",
type: "rect",
x: 96,
y: 110,
@@ -540,8 +540,8 @@ export const DEMO_POSTER_DOCUMENT_EN: PosterDocument = {
locked: false,
},
{
- id: "badge-text",
- name: "badge-text",
+ id: "badge",
+ name: "badge",
type: "text",
role: "badge",
text: "EDGEEVER · KNOWLEDGE ART",
@@ -598,8 +598,8 @@ export const DEMO_POSTER_DOCUMENT_EN: PosterDocument = {
textAlign: "left",
},
{
- id: "card-1-bg",
- name: "card-1-bg",
+ id: "section-1-card",
+ name: "section-1-card",
type: "rect",
x: 96,
y: 590,
@@ -612,8 +612,8 @@ export const DEMO_POSTER_DOCUMENT_EN: PosterDocument = {
locked: false,
},
{
- id: "card-1-title",
- name: "card-1-title",
+ id: "section-1-heading",
+ name: "section-1-heading",
type: "text",
text: "01 · Native MCP & ACP Dual Protocols",
x: 136,
@@ -630,8 +630,8 @@ export const DEMO_POSTER_DOCUMENT_EN: PosterDocument = {
textAlign: "left",
},
{
- id: "card-1-body",
- name: "card-1-body",
+ id: "section-1-body",
+ name: "section-1-body",
type: "text",
text: "Connect Claude, Cursor, and Codex via MCP, and drive local agents seamlessly via ACP on desktop.",
x: 136,
@@ -649,8 +649,8 @@ export const DEMO_POSTER_DOCUMENT_EN: PosterDocument = {
lineHeight: 1.4,
},
{
- id: "card-2-bg",
- name: "card-2-bg",
+ id: "section-2-card",
+ name: "section-2-card",
type: "rect",
x: 96,
y: 840,
@@ -663,8 +663,8 @@ export const DEMO_POSTER_DOCUMENT_EN: PosterDocument = {
locked: false,
},
{
- id: "card-2-title",
- name: "card-2-title",
+ id: "section-2-heading",
+ name: "section-2-heading",
type: "text",
text: "02 · 100% Free Serverless & Self-Hosting",
x: 136,
@@ -681,8 +681,8 @@ export const DEMO_POSTER_DOCUMENT_EN: PosterDocument = {
textAlign: "left",
},
{
- id: "card-2-body",
- name: "card-2-body",
+ id: "section-2-body",
+ name: "section-2-body",
type: "text",
text: "Run within Cloudflare free quotas or one-command Docker on your VPS/NAS with standard SQLite storage.",
x: 136,
@@ -700,8 +700,8 @@ export const DEMO_POSTER_DOCUMENT_EN: PosterDocument = {
lineHeight: 1.4,
},
{
- id: "card-3-bg",
- name: "card-3-bg",
+ id: "section-3-card",
+ name: "section-3-card",
type: "rect",
x: 96,
y: 1090,
@@ -714,8 +714,8 @@ export const DEMO_POSTER_DOCUMENT_EN: PosterDocument = {
locked: false,
},
{
- id: "card-3-title",
- name: "card-3-title",
+ id: "section-3-heading",
+ name: "section-3-heading",
type: "text",
text: "03 · Full-Platform Apps & Knowledge Sites",
x: 136,
@@ -732,8 +732,8 @@ export const DEMO_POSTER_DOCUMENT_EN: PosterDocument = {
textAlign: "left",
},
{
- id: "card-3-body",
- name: "card-3-body",
+ id: "section-3-body",
+ name: "section-3-body",
type: "text",
text: "Native coverage on macOS, Windows, Linux, iOS & Android; publish entire notebooks as standalone sites.",
x: 136,
diff --git a/apps/web/src/lib/poster-template-content.test.mjs b/apps/web/src/lib/poster-template-content.test.mjs
index acfac662..6eebea84 100644
--- a/apps/web/src/lib/poster-template-content.test.mjs
+++ b/apps/web/src/lib/poster-template-content.test.mjs
@@ -1,7 +1,7 @@
import { expect, test } from "bun:test";
import { PosterDocumentSchema, createPosterDocument, parsePosterDocument, serializePosterDocument } from "@edgeever/shared";
import { compilePosterMemo } from "../../../api/src/mcp-poster-tools";
-import { composePosterTemplate, posterTemplateHeaderHeight } from "./poster-template-content";
+import { composePosterTemplate, hasPosterSections, posterTemplateHeaderHeight } from "./poster-template-content";
const sections = Array.from({ length: 6 }, (_, i) => ({ heading: `业务 ${i + 1}`, body: `保留业务说明 ${i + 1}` }));
const source = () => compilePosterMemo({ notebookId: "inbox", title: "产业版图", heading: "产业版图", subtitle: "连接内容与服务", badge: "产业观察", footer: "数字生态", sections, template: "bold" }).document;
@@ -44,3 +44,33 @@ test("short canvases scale the template header and clear stale previews", () =>
expect(next.elements.find(element => element.id === "design_0").y).toBe(67.5);
expect(next.elements.find(element => element.id === "section-1-card").y).toBeGreaterThan(216);
});
+
+test("legacy card-1-bg and badge-text formats compose cleanly without ghost badges or overlaps", () => {
+ const legacy = PosterDocumentSchema.parse({
+ schemaVersion: 1,
+ width: 1080,
+ height: 1440,
+ background: "#f4efe4",
+ templateId: "editorial",
+ copy: { badge: "EDGEEVER", title: "大标题", subtitle: "副标题" },
+ elements: [
+ { id: "accent-bar", name: "accent-bar", type: "rect", x: 96, y: 110, width: 120, height: 12, fill: "#16a06e", rotation: 0, opacity: 1 },
+ { id: "badge-text", name: "badge-text", type: "text", role: "badge", text: "EDGEEVER", x: 96, y: 150, width: 888, height: 40, rotation: 0, opacity: 1, fill: "#0f766e", fontSize: 24, fontFamily: "sans-serif", fontWeight: "bold", textAlign: "left" },
+ { id: "heading", name: "heading", type: "text", role: "title", text: "大标题", x: 96, y: 220, width: 888, height: 220, rotation: 0, opacity: 1, fill: "#07130b", fontSize: 84, fontFamily: "serif", fontWeight: "bold", textAlign: "left" },
+ { id: "subtitle", name: "subtitle", type: "text", role: "subtitle", text: "副标题", x: 96, y: 470, width: 888, height: 80, rotation: 0, opacity: 1, fill: "#3f3f46", fontSize: 32, fontFamily: "sans-serif", fontWeight: "normal", textAlign: "left" },
+ { id: "card-1-bg", name: "card-1-bg", type: "rect", x: 96, y: 590, width: 888, height: 220, fill: "#ffffff", rotation: 0, opacity: 1 },
+ { id: "card-1-title", name: "card-1-title", type: "text", text: "01 · 卡片一", x: 136, y: 630, width: 808, height: 48, rotation: 0, opacity: 1, fill: "#07130b", fontSize: 32, fontFamily: "sans-serif", fontWeight: "bold", textAlign: "left" },
+ { id: "card-1-body", name: "card-1-body", type: "text", text: "卡片正文说明", x: 136, y: 695, width: 808, height: 70, rotation: 0, opacity: 1, fill: "#71717a", fontSize: 24, fontFamily: "sans-serif", fontWeight: "normal", textAlign: "left" },
+ ],
+ });
+
+ expect(hasPosterSections(legacy)).toBe(true);
+ const headerHeight = posterTemplateHeaderHeight(legacy, 1440);
+ const next = composePosterTemplate(legacy, cover(headerHeight), 1080, 1440, headerHeight);
+
+ expect(next.elements.some(element => ["accent-bar", "badge-text", "heading", "subtitle"].includes(element.id))).toBe(false);
+ const card = next.elements.find(element => element.id === "card-1-bg");
+ expect(card).toBeDefined();
+ const title = next.elements.find(element => element.role === "title");
+ expect(card.y).toBeGreaterThan(title.y + title.height);
+});
diff --git a/apps/web/src/lib/poster-template-content.ts b/apps/web/src/lib/poster-template-content.ts
index 8f411645..c06d29a2 100644
--- a/apps/web/src/lib/poster-template-content.ts
+++ b/apps/web/src/lib/poster-template-content.ts
@@ -1,39 +1,57 @@
import { PosterDocumentSchema, resizePosterDocument, type PosterDocument } from "@edgeever/shared";
import { ensureReadable, readableOn } from "./poster-design/vendor/qiaomu/quality";
-const sectionId = /^section-\d+-(?:card|accent|number|heading|body)$/;
-export const hasPosterSections = (document: PosterDocument) => document.elements.some(element => /^section-\d+-card$/.test(element.id));
+const sectionId = /^(?:section-\d+-(?:card|accent|number|heading|body)|card-\d+-(?:bg|card|accent|number|title|heading|body))$/;
+export const isSectionCard = (id: string) => /^(?:section-\d+-card|card-\d+-(?:bg|card))$/.test(id);
+export const hasPosterSections = (document: PosterDocument) => document.elements.some(element => isSectionCard(element.id));
export const posterTemplateHeaderHeight = (document: PosterDocument, height: number) => hasPosterSections(document) ? Math.round(height * 0.36) : height;
+const headerSemanticIds = ["content-header", "heading", "subtitle", "badge", "badge-text", "accent", "accent-bar", "footer", "footer-rule"];
+
// Template artwork owns the cover region. Semantic sections own the body region.
// Only known generated IDs are replaced; user-created objects remain independent.
export function composePosterTemplate(source: PosterDocument, cover: PosterDocument, width: number, height: number, headerHeight: number) {
// Hairline rules must remain at least one document pixel after resizing.
const scaled = resizePosterDocument({ ...source, elements: source.elements.map(element => ({ ...element, width: Math.max(element.width, source.width / width), height: Math.max(element.height, source.height / height) })) }, width, height);
const structured = hasPosterSections(source);
- const extras = scaled.elements.filter(element => !element.id.startsWith("design_") && !["heading", "subtitle", "accent"].includes(element.id)
- && !(structured && ["content-header", "badge", "footer", "footer-rule"].includes(element.id)) && !(structured && sectionId.test(element.id)));
+ const isHeaderSemantic = (element: { id: string; role?: string }) =>
+ element.id.startsWith("design_") ||
+ headerSemanticIds.includes(element.id) ||
+ element.role === "title" ||
+ element.role === "subtitle" ||
+ element.role === "badge";
+
+ const extras = scaled.elements.filter(element => !isHeaderSemantic(element) && !(structured && sectionId.test(element.id)));
if (!structured) return PosterDocumentSchema.parse({ ...cover, sourceMemoId: source.sourceMemoId, platformId: source.platformId, elements: [...cover.elements, ...extras] });
const headerScale = headerHeight / cover.height;
const header = cover.elements.map(element => ({ ...element, y: element.y * headerScale, height: Math.max(1, element.height * headerScale),
...(element.type === "text" ? { fontSize: Math.max(4, element.fontSize * headerScale) } : {}) }));
const sections = scaled.elements.filter(element => sectionId.test(element.id));
- const cards = sections.filter(element => element.id.endsWith("-card"));
+ const cards = sections.filter(element => isSectionCard(element.id));
const oldTop = Math.min(...cards.map(element => element.y));
const oldBottom = Math.max(...cards.map(element => element.y + element.height));
const unit = Math.min(width, height);
- const top = headerHeight + unit * 0.025;
+ const headerBottom = header.length > 0
+ ? Math.max(...header.filter(e => e.role === "title" || e.role === "subtitle" || e.role === "badge" || e.id.startsWith("design_")).map(e => e.y + e.height), headerHeight)
+ : headerHeight;
+ const top = Math.max(headerHeight, headerBottom) + unit * 0.025;
const bottom = scaled.elements.some(element => element.id === "footer") ? height * 0.88 : height - unit * 0.065;
- const bodyScale = (bottom - top) / (oldBottom - oldTop);
+ const bodyScale = Math.max(0.2, (bottom - top) / Math.max(1, oldBottom - oldTop));
const backdrop = cover.elements.filter(element => element.type === "rect" && /^#[\da-f]{6}$/i.test(element.fill))
.sort((a, b) => b.width * b.height - a.width * a.height)[0];
const cardFill = backdrop && backdrop.type === "rect" ? backdrop.fill : cover.background;
const ink = readableOn(cardFill);
const badge = cover.elements.find(element => element.type === "text" && element.role === "badge");
const accent = ensureReadable(badge?.type === "text" ? badge.fill : ink, cardFill);
- const body = sections.map(element => ({ ...element, y: top + (element.y - oldTop) * bodyScale, height: Math.max(1, element.height * bodyScale),
- ...(element.type === "text" ? { fontSize: Math.max(4, element.fontSize * Math.min(1, bodyScale)), fill: element.id.endsWith("-number") ? accent : ink } : { fill: element.id.endsWith("-card") ? cardFill : accent }) }));
+ const body = sections.map(element => ({
+ ...element,
+ y: top + (element.y - oldTop) * bodyScale,
+ height: Math.max(1, element.height * bodyScale),
+ ...(element.type === "text"
+ ? { fontSize: Math.max(4, element.fontSize * Math.min(1, bodyScale)), fill: element.id.endsWith("-number") ? accent : ink }
+ : { fill: isSectionCard(element.id) ? cardFill : accent }),
+ }));
const footer = scaled.elements.filter(element => ["footer", "footer-rule"].includes(element.id)).map(element => ({ ...element, fill: readableOn(cover.background) }));
return PosterDocumentSchema.parse({ ...cover, width, height, sourceMemoId: source.sourceMemoId, platformId: source.platformId,
elements: [...header, ...body, ...footer, ...extras] });