1/* DokuWiki MoaiEditor Scroll_tools.js file 2 Version : 0.5 (May 5, 2026) 3 Author : MoaiTools <info@moaitools.org> 4 License : GPL 3 (http://www.gnu.org/licenses/gpl.html) */ 5 6MoaiEditor.ScrollTools = class { 7 8 9 getMaxScrollY(element) { 10 const extraHeight = this.calcExtraHeight(element); 11 const bounds = element.getBoundingClientRect(); 12 const height = bounds.height - extraHeight.border; 13 const maxScroll = Math.round(element.scrollHeight - height); 14 return maxScroll; 15 } 16 // ──────────────────────────────────── 17 getMaxScrollX(element) { 18 const extraWidth = this.calcExtraWidth(element); 19 const bounds = element.getBoundingClientRect(); 20 const width = bounds.width - extraWidth.total; 21 const maxScroll = Math.round(element.scrollWidth - width); 22 return maxScroll; 23 } 24 // ──────────────────────────────────── 25 calcExtraHeight(element) { 26 const styles = window.getComputedStyle(element); 27 const parseValue = (v) => v.endsWith('px') ? parseInt(v.slice(0, -2), 10) : 0; 28 const paddingTop = parseValue(styles.paddingTop); 29 const paddingBottom = parseValue(styles.paddingBottom); 30 const borderTopWidth = parseValue(styles.borderTopWidth); 31 const borderBottomWidth = parseValue(styles.borderBottomWidth); 32 return { 33 top : paddingTop + borderTopWidth, 34 bottom : paddingBottom + borderBottomWidth, 35 total : paddingTop + paddingBottom + borderTopWidth + borderBottomWidth, 36 border : borderTopWidth + borderBottomWidth 37 } 38 } 39 // ──────────────────────────────────── 40 calcExtraWidth(element) { 41 const styles = window.getComputedStyle(element); 42 const parseValue = (v) => v.endsWith('px') ? parseInt(v.slice(0, -2), 10) : 0; 43 const paddingLeft = parseValue(styles.paddingLeft); 44 const paddingRight = parseValue(styles.paddingRight); 45 const borderLeftWidth = parseValue(styles.borderLeftWidth); 46 const borderRightWidth = parseValue(styles.borderRightWidth); 47 return { 48 left : paddingLeft + borderLeftWidth, 49 right : paddingRight + borderRightWidth, 50 total : paddingLeft + paddingRight + borderLeftWidth + borderRightWidth 51 } 52 } 53 // ──────────────────────────────────── 54 getRectRelativeToParent(element) { 55 const parent = element.parentElement; 56 const parentRect = parent.getBoundingClientRect(); 57 const elementRect = element.getBoundingClientRect(); 58 return { 59 top : elementRect.top - parentRect.top + parent.scrollTop, 60 bottom : elementRect.bottom - parentRect.top + parent.scrollTop, 61 left : elementRect.left - parentRect.left, 62 right : elementRect.right - parentRect.left, 63 height : elementRect.bottom - elementRect.top, 64 width : elementRect.right - elementRect.left, 65 }; 66 } 67}; // End Class 68 69 70 71