701702if (curRes === curResMax) {703artBoard.setAttribute('data-artboard-height', autoHeight);704} else {705artBoard.setAttribute('data-artboard-height-res-' + curRes, autoHeight);706}707708t396_ab__renderView(artBoard);709artBoard.closest('.t396')?.dispatchEvent(new CustomEvent('zero:height-changed'));710}711712function t396__getAutoHeight(artBoard) {
let minimalHeight; const isAutolayout = artBoard.classList.contains('t396__artboard-flex'); // Важно искать только root элементы и группы, чтобы корректно обрабатывать группы с overflow. const elements = Array.from(artBoard.querySelectorAll(':scope > .tn-group, :scope > .tn-elem')); const isArtboardHeightSetted = artBoard.style.height; const canAutocalculateHeight = t396__autoHeight__canAutocalculateHeight(artBoard, elements); if (canAutocalculateHeight && isArtboardHeightSetted) { const cachedHeight = artBoard.style.height; artBoard.style.height = 'auto'; minimalHeight = artBoard.offsetHeight; artBoard.style.height = cachedHeight; } else { minimalHeight = elements.reduce((accumulator, element) => { const axisY = t396_core__getFieldValue(element, 'axisy'); const topunits = t396_core__getFieldValue(element, 'topunits'); const heightunits = t396_core__getFieldValue(element, 'heightunits'); const excludeFromAutoHeight = t396_core__getFieldValue(element, 'excludefromautoheight') === 'y'; if ( topunits === '%' || heightunits === '%' || axisY === 'bottom' || axisY === 'center' || excludeFromAutoHeight ) { return accumulator; } let additionalOffset = 0; if (element.getAttribute('data-elem-type') === 'gallery') { additionalOffset = t396__autoHeight__getAdditionalOffsetForGallery(element); } if (isAutolayout) { const paddingBottom = t396__ab__getPaddingValue(artBoard, 'paddingbottom'); additionalOffset += parseInt(paddingBottom, 10); } let bottom = element.offsetTop + element.offsetHeight + additionalOffset; const isScaled = t396_ab__getFieldValue(artBoard, 'upscale') === 'window'; /* * Элементы, к которым не применяется css zoom, уже имеют отмасштабированные * offsetTop/offsetHeight, поэтому повторное умножение на currentScaleFactor * приводит к двойному масштабированию и лишнему отступу снизу артборда */ if (isScaled && !window.tn.isEditMode && !t396__autoHeight__isElementPrescaled(element)) { const recid = artBoard.getAttribute('data-artboard-recid'); const currentScaleFactor = t396__getCurrentScaleFactor(recid); bottom = bottom * currentScaleFactor; } if (bottom > accumulator) { return bottom; } return accumulator; }, -Infinity); } return minimalHeight === -Infinity ? 0 : minimalHeight;}/** * Проверяет, отмасштабированы ли уже координаты и размеры элемента * Часть элементов не использует css zoom: галерея масштабируется через calc, * а тонким шейпам скрипт автоскейла пересчитывает координаты вручную и проставляет data-scale-off * * @param {HTMLElement} element - элемент артборда * @returns {boolean} true, если элемент уже отмасштабирован */function t396__autoHeight__isElementPrescaled(element) { if (t396__isElementUsingCalcZoom(element)) return true; return element.getAttribute('data-scale-off') === 'yes';}/** * Просчитываем дополнительный отступ галереи: контролы и подпись, которые выходят за нижнюю границу элемента * * @param {HTMLElement} gallery - элемент галереи * @returns {number} дополнительный отступ для галереи */function t396__autoHeight__getAdditionalOffsetForGallery(gallery) { if (zero__getGalleryVersion(gallery) === GALLERY_VERSION.V1) { return t396__autoHeight__getAdditionalOffsetForGallery__legacy(gallery); }