79 lines
2.7 KiB
JavaScript
79 lines
2.7 KiB
JavaScript
import { clampHeroFocus, heroFocusCss } from '@/composables/posterDefaults'
|
|
|
|
/** 爱心拼接槽位:百分比绝对定位(顶开叉、中最宽、底收尖) */
|
|
export const HEART_SLOTS = [
|
|
{ l: 10, t: 0, w: 32, h: 13 }, // 0 左上叶
|
|
{ l: 58, t: 0, w: 32, h: 13 }, // 1 右上叶
|
|
{ l: 0, t: 14, w: 14, h: 15.5 }, // 2 左外上
|
|
{ l: 0, t: 30.5, w: 14, h: 15.5 }, // 3 左外下
|
|
{ l: 15, t: 14, w: 26, h: 32 }, // 4 左大图
|
|
{ l: 42, t: 14, w: 16, h: 32 }, // 5 中轴
|
|
{ l: 59, t: 14, w: 26, h: 32 }, // 6 右大图
|
|
{ l: 86, t: 14, w: 14, h: 15.5 }, // 7 右外上
|
|
{ l: 86, t: 30.5, w: 14, h: 15.5 }, // 8 右外下
|
|
{ l: 10, t: 47, w: 13, h: 16 }, // 9 左下收腰
|
|
{ l: 24, t: 47, w: 52, h: 16 }, // 10 中下横
|
|
{ l: 77, t: 47, w: 13, h: 16 }, // 11 右下收腰
|
|
{ l: 38, t: 64, w: 24, h: 14 }, // 12 心尖
|
|
]
|
|
|
|
export const HEART_SLOT_COUNT = HEART_SLOTS.length
|
|
|
|
export const HEART_SLOT_LABELS = [
|
|
'左上叶', '右上叶', '左外上', '左外下', '左大图', '中轴', '右大图',
|
|
'右外上', '右外下', '左下', '中下横', '右下', '心尖',
|
|
]
|
|
|
|
export function heartSlotStyle(slot) {
|
|
return {
|
|
left: `${slot.l}%`,
|
|
top: `${slot.t}%`,
|
|
width: `${slot.w}%`,
|
|
height: `${slot.h}%`,
|
|
}
|
|
}
|
|
|
|
export function heartSlotLabel(i) {
|
|
return HEART_SLOT_LABELS[i] || `图${i + 1}`
|
|
}
|
|
|
|
export function heartFocusAt(page, i, axis = 'x') {
|
|
const arr = axis === 'y' ? page?.imagesFocusY : page?.imagesFocusX
|
|
const v = Array.isArray(arr) ? arr[i] : 50
|
|
return clampHeroFocus(v, 50)
|
|
}
|
|
|
|
export function heartFocusCssAt(page, i) {
|
|
return heroFocusCss(heartFocusAt(page, i, 'x'), heartFocusAt(page, i, 'y'))
|
|
}
|
|
|
|
/** 保证 imagesFocusX/Y 与 images 等长;非爱心版式则清除 */
|
|
export function syncImagesFocus(page) {
|
|
if (!page || page.type !== 'heart-collage' || !Array.isArray(page.images)) {
|
|
if (page) {
|
|
delete page.imagesFocusX
|
|
delete page.imagesFocusY
|
|
}
|
|
return
|
|
}
|
|
if (!Array.isArray(page.imagesFocusX)) page.imagesFocusX = []
|
|
if (!Array.isArray(page.imagesFocusY)) page.imagesFocusY = []
|
|
const n = page.images.length
|
|
while (page.imagesFocusX.length < n) page.imagesFocusX.push(50)
|
|
while (page.imagesFocusY.length < n) page.imagesFocusY.push(50)
|
|
for (let i = 0; i < n; i += 1) {
|
|
page.imagesFocusX[i] = clampHeroFocus(page.imagesFocusX[i], 50)
|
|
page.imagesFocusY[i] = clampHeroFocus(page.imagesFocusY[i], 50)
|
|
}
|
|
page.imagesFocusX.length = n
|
|
page.imagesFocusY.length = n
|
|
}
|
|
|
|
export function setHeartFocus(page, i, x, y) {
|
|
if (!page || page.type !== 'heart-collage') return
|
|
syncImagesFocus(page)
|
|
if (i < 0 || i >= page.images.length) return
|
|
page.imagesFocusX[i] = clampHeroFocus(x, 50)
|
|
page.imagesFocusY[i] = clampHeroFocus(y, 50)
|
|
}
|