MCPcopy Create free account
hub / github.com/editablejs/editable / calculateElementHeight

Function calculateElementHeight

packages/editor/src/utils/selection.ts:106–134  ·  view source on GitHub ↗
(el: DOMElement)

Source from the content-addressed store, hash-verified

104 * @returns The calculated height
105 */
106const calculateElementHeight = (el: DOMElement) => {
107 const { lineHeight, fontSize } = window.getComputedStyle(el)
108
109 // TODO: Handle pt, em, rem units
110
111 let height = 0
112 // Ends with px
113 if (lineHeight.endsWith('px')) {
114 height = parseFloat(lineHeight)
115 return height
116 }
117 // Ends with %
118 else if (lineHeight.endsWith('%')) {
119 height = parseInt(lineHeight, 10) / 100
120 }
121 // Number
122 else if (/^\d+(\.\d+)?$/.test(lineHeight)) {
123 height = parseFloat(lineHeight)
124 } else {
125 return el.getBoundingClientRect().height
126 }
127
128 let size = 0
129 if (fontSize.endsWith('px')) {
130 size = parseInt(fontSize, 10)
131 }
132
133 return height * size
134}
135
136/**
137 * Resets the DOMRect of an element to the specified height

Callers 1

matchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…