This commit is contained in:
iqudoo
2026-06-14 18:02:18 +08:00
parent b4c2cf07d0
commit 8c9b53b1b6
7 changed files with 229 additions and 35 deletions

View File

@@ -30,6 +30,21 @@ export const VARIABLE_MAPPING_ROW_INDEX_LABEL = '数据序号';
/** 粘贴副本时相对原位置的偏移 (mm) */
export const PASTE_ELEMENT_OFFSET_MM = 2;
/** 在标签画布上居中放置元素mm保留 1 位小数) */
export function centerElementOnLabel(
labelWidth: number,
labelHeight: number,
elementWidth: number,
elementHeight: number
): { x: number; y: number } {
const x = Math.round(((labelWidth - elementWidth) / 2) * 10) / 10;
const y = Math.round(((labelHeight - elementHeight) / 2) * 10) / 10;
return {
x: Math.max(0, x),
y: Math.max(0, y),
};
}
/** 深拷贝元素并生成新 id用于复制/粘贴 */
export function cloneTemplateElementsForPaste(
elements: TemplateElement[],