| | |
| | | return color || fallback |
| | | } |
| | | |
| | | function getImageNaturalSize(element = {}) { |
| | | const naturalWidth = normalizeNumber(element?.naturalWidth, 0) |
| | | const naturalHeight = normalizeNumber(element?.naturalHeight, 0) |
| | | return { |
| | | naturalWidth, |
| | | naturalHeight |
| | | } |
| | | } |
| | | |
| | | export function getImageMinHeight(width, element = {}, fallback = 8) { |
| | | const { naturalWidth, naturalHeight } = getImageNaturalSize(element) |
| | | if (naturalWidth > 0 && naturalHeight > 0) { |
| | | return Number( |
| | | ((Math.max(1, normalizeNumber(width, 1)) * naturalHeight) / naturalWidth).toFixed(2) |
| | | ) |
| | | } |
| | | return Math.max(8, normalizeNumber(fallback, 8)) |
| | | } |
| | | |
| | | function createElementId(prefix = 'el') { |
| | | return `${prefix}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}` |
| | | } |
| | |
| | | |
| | | if (base.type === 'qrcode') { |
| | | base.resolvedValue = resolveTemplatePlaceholders(base.valueTemplate, record) |
| | | return base |
| | | } |
| | | |
| | | if (base.type === 'image') { |
| | | base.resolvedSrc = normalizeText(base.src) |
| | | base.objectFit = ['contain', 'cover', 'fill'].includes(base.objectFit) |
| | | ? base.objectFit |
| | | : 'contain' |
| | | return base |
| | | } |
| | | |
| | |
| | | normalized.valueTemplate = normalizeText(element?.valueTemplate) |
| | | normalized.w = Math.max(8, normalizeNumber(element?.w, 18)) |
| | | normalized.h = Math.max(8, normalizeNumber(element?.h, 18)) |
| | | return normalized |
| | | } |
| | | |
| | | if (normalized.type === 'image') { |
| | | normalized.src = normalizeText(element?.src) |
| | | normalized.objectFit = ['contain', 'cover', 'fill'].includes(element?.objectFit) |
| | | ? element.objectFit |
| | | : 'contain' |
| | | normalized.naturalWidth = Math.max(0, normalizeNumber(element?.naturalWidth, 0)) |
| | | normalized.naturalHeight = Math.max(0, normalizeNumber(element?.naturalHeight, 0)) |
| | | normalized.w = Math.max(8, normalizeNumber(element?.w, 20)) |
| | | normalized.h = Math.max( |
| | | getImageMinHeight(normalized.w, element, normalizeNumber(element?.h, 20)), |
| | | normalizeNumber(element?.h, 20) |
| | | ) |
| | | return normalized |
| | | } |
| | | |
| | |
| | | }) |
| | | } |
| | | |
| | | if (type === 'image') { |
| | | return normalizeElement({ |
| | | ...common, |
| | | w: 20, |
| | | h: 20, |
| | | src: '', |
| | | naturalWidth: 0, |
| | | naturalHeight: 0, |
| | | objectFit: 'contain' |
| | | }) |
| | | } |
| | | |
| | | if (type === 'line') { |
| | | return normalizeElement({ |
| | | ...common, |