gongxiangp2/apps/detail-agent-pi/src/copy-image-alignment.mjs

62 lines
4.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export const COPY_IMAGE_PROMPT_GUIDANCE='让画面清晰呈现关联文案的重点。模板原图与目标画面不符时可设置 useTemplateReference: false,用本款实拍保持商品一致。构图可用 transform_slot_image 调整,具体创作要求见适用企业 Skill。';
export const COPY_IMAGE_REVIEW_GUIDANCE='用 shownSubject 描述实际可见内容,再对照关联和同屏实时文案,填写 checks.copyAlignment,检查对应部位是否清晰可见,指出不符的文案和可见依据。按适用企业 Skill 判断视觉标准。';
export const OVERLAY_SCREEN_CRITERIA='核对叠层错位、压字或数值不符。overlayLayers 的 overlapsSlots 对应图位 fieldId,bounds 为像素边界,text 为当前文字,mapped 表示是否已映射。group 是直属图层组,overlayGroups 按组列出本屏的成员 ID。同组尺寸线、端点和数字应作为一套核对和处理。belowSlot 标出图位下方可能露出的图层,留意其中的旧字和底条。每项按 fieldId 指向图位,coverage 是屏内图层边界的覆盖比例,opacity 是图位内容不透明度,blendMode 是图位混合模式。';
export const COPY_IMAGE_SCREEN_GUIDANCE='对照商品资料、实时文案和适用企业 Skill 核对整屏实际画面。检查材质、颜色、款式、结构、尺寸与标注是否一致,以及文字溢出、裁切和可读性。'+OVERLAY_SCREEN_CRITERIA;
const fieldId = row => row.field ?? row.fieldId;
const belongsTo = (ids, id) => Array.isArray(ids) && ids.includes(id);
const fieldPage = row => row.page ?? row.pageId;
const liveText = row => row.visible !== false && typeof row.currentText === 'string' && row.currentText.trim();
function screenCopyRow(row) {
return {field:fieldId(row),label:row.label,role:row.role,text:row.currentText,templateSample:Boolean(row.templateSample)};
}
export function resolveLiveSlotCopy({slot,copyFields=[],journalCopy=[]}) {
const slotIds=[slot.fieldId,slot.id].filter(Boolean);
const directJournal=journalCopy.filter(row=>slotIds.some(id=>belongsTo(row.pictures,id)));
const journalByField=new Map(directJournal.map(row=>[fieldId(row),row]));
const isDirect=row=>journalByField.has(fieldId(row))||
slotIds.some(id=>belongsTo(row.relatedFields,id))||belongsTo(slot.relatedFields,fieldId(row));
const directPage=copyFields.find(row=>isDirect(row)&&fieldPage(row));
const page=slot.page??slot.pageId??slot.documentId??(directPage&&fieldPage(directPage));
const liveFields=new Set(copyFields.map(fieldId));
const resolved=new Map();
for(const row of copyFields){
const field=fieldId(row);
if(!liveText(row)||row.templateSample||!field)continue;
const direct=isDirect(row);
const sameScreen=page!=null&&fieldPage(row)===page;
if(!sameScreen&&(!direct||resolved.has(field)))continue;
const journal=journalByField.get(field);
resolved.set(field,{
...(journal?.text===row.currentText?journal:null),
...screenCopyRow(row),binding:direct?'direct':'same_screen',
});
}
for(const row of directJournal){
if(fieldId(row)&&!liveFields.has(fieldId(row))&&row.text?.trim()){
resolved.set(fieldId(row),{...row,field:fieldId(row),binding:'direct'});
}
}
return [...resolved.values()];
}
export function mergeReviewCopy({copy=[],relatedCopy=[],liveScreenCopy=[]}) {
const merged=new Map();
const nativeCopy=(relatedCopy??[]).map(row=>({...row,binding:'direct'}));
for(const row of [...copy,...nativeCopy,...liveScreenCopy]){
const field=fieldId(row);
if(row.templateSample||!(row.text?.trim()||row.claims?.length))continue;
const binding=merged.get(field)?.binding==='direct'?'direct':row.binding;
merged.set(field??row,{...row,...(field?{field}:null),...(binding?{binding}:null)});
}
return [...merged.values()];
}
export function extractPageLiveCopy({pageIndex,pages=[],fields=[]}) {
const page=pages[pageIndex];
if(page==null)return [];
return fields.filter(row=>fieldPage(row)===page&&fieldId(row)&&liveText(row)).map(screenCopyRow);
}