/* DokuWiki MoaiEditor Scroll_tools.js file Version : 0.5 (May 5, 2026) Author : MoaiTools License : GPL 3 (http://www.gnu.org/licenses/gpl.html) */ MoaiEditor.ScrollTools = class { getMaxScrollY(element) { const extraHeight = this.calcExtraHeight(element); const bounds = element.getBoundingClientRect(); const height = bounds.height - extraHeight.border; const maxScroll = Math.round(element.scrollHeight - height); return maxScroll; } // ──────────────────────────────────── getMaxScrollX(element) { const extraWidth = this.calcExtraWidth(element); const bounds = element.getBoundingClientRect(); const width = bounds.width - extraWidth.total; const maxScroll = Math.round(element.scrollWidth - width); return maxScroll; } // ──────────────────────────────────── calcExtraHeight(element) { const styles = window.getComputedStyle(element); const parseValue = (v) => v.endsWith('px') ? parseInt(v.slice(0, -2), 10) : 0; const paddingTop = parseValue(styles.paddingTop); const paddingBottom = parseValue(styles.paddingBottom); const borderTopWidth = parseValue(styles.borderTopWidth); const borderBottomWidth = parseValue(styles.borderBottomWidth); return { top : paddingTop + borderTopWidth, bottom : paddingBottom + borderBottomWidth, total : paddingTop + paddingBottom + borderTopWidth + borderBottomWidth, border : borderTopWidth + borderBottomWidth } } // ──────────────────────────────────── calcExtraWidth(element) { const styles = window.getComputedStyle(element); const parseValue = (v) => v.endsWith('px') ? parseInt(v.slice(0, -2), 10) : 0; const paddingLeft = parseValue(styles.paddingLeft); const paddingRight = parseValue(styles.paddingRight); const borderLeftWidth = parseValue(styles.borderLeftWidth); const borderRightWidth = parseValue(styles.borderRightWidth); return { left : paddingLeft + borderLeftWidth, right : paddingRight + borderRightWidth, total : paddingLeft + paddingRight + borderLeftWidth + borderRightWidth } } // ──────────────────────────────────── getRectRelativeToParent(element) { const parent = element.parentElement; const parentRect = parent.getBoundingClientRect(); const elementRect = element.getBoundingClientRect(); return { top : elementRect.top - parentRect.top + parent.scrollTop, bottom : elementRect.bottom - parentRect.top + parent.scrollTop, left : elementRect.left - parentRect.left, right : elementRect.right - parentRect.left, height : elementRect.bottom - elementRect.top, width : elementRect.right - elementRect.left, }; } }; // End Class