UNPKG

@pdf-viewer/react

Version:

A react-pdf-viewer component for React and Next.js. Suitable for react-pdf document.

85 lines (84 loc) 2.4 kB
function g(e, o) { !e || typeof e != "object" || Object.entries(e).forEach(([d, i]) => { if (i == null) return; const s = d.replace(/([A-Z])/g, "-$1").toLowerCase(), n = [ "width", "height", "top", "right", "bottom", "left", "margin", "margin-top", "margin-right", "margin-bottom", "margin-left", "padding", "padding-top", "padding-right", "padding-bottom", "padding-left", "border-width", "border-top-width", "border-right-width", "border-bottom-width", "border-left-width", "font-size", "line-height", "letter-spacing", "word-spacing", "min-width", "min-height", "max-width", "max-height", "flex-basis", "grid-gap", "grid-row-gap", "grid-column-gap" ]; let t; typeof i == "number" && i !== 0 ? t = n.includes(s) ? `${i}px` : String(i) : t = String(i), o.style.setProperty(s, t); }); } const f = (e, o, d, i, s) => { let n = "center"; switch (i) { case 90: n = `${e.width / 2}px ${e.width / 2}px`; break; case -90: case 270: n = `${e.height / 2}px ${e.height / 2}px`; break; default: n = "center"; } const t = document.createElement("div"); t.id = "parent-element", t.style.width = `${e.width}px`, t.style.height = `${e.height}px`, t.style.setProperty("--scale-factor", s.toString()), t.style.setProperty("--rotation", i.toString()), t.style.setProperty("--transform-origin", n), t.style.left = "-99999px", t.style.visibility = "hidden", t.style.position = "absolute"; const l = document.createElement("div"); l.style.position = "relative", l.style.width = "100%", l.style.height = "100%", t.appendChild(l); let r; if (d instanceof HTMLElement) r = d.cloneNode(!0), l.appendChild(r); else { const p = d.props; r = document.createElement("div"), p.style && g(p.style, r), p.className && (r.className = p.className), l.appendChild(r); } o.appendChild(t); const c = t.getBoundingClientRect(), h = r.getBoundingClientRect(); o.removeChild(t); const a = { top: o.clientHeight / 2, left: o.clientWidth / 2 }; return { left: h.left - c.left - a.left, top: h.top - c.top - a.top, width: h.width, height: h.height }; }; export { f as getElementPagePosition };