UNPKG

prism-code-editor

Version:

Lightweight, extensible code editor component for the web using Prism

49 lines (48 loc) 1.83 kB
import { c as createTemplate } from "./index-q0zRzWVD.js"; import { b as addOverlay, g as getStyleValue } from "./index-CxiLA9IO.js"; const template = /* @__PURE__ */ createTemplate( "<div class=pce-tooltip style=z-index:5;top:auto;display:flex;overflow-x:clip><div>" ); const addTooltip = (editor, element, fixedWidth = true) => { const container = template(); const style = container.style; const spacer = container.firstChild; container.append(element); (fixedWidth ? element : spacer).style.flexShrink = 0; return [ (above) => { let pos = editor.extensions.cursor?.getPosition(); if (pos) { container.parentNode || addOverlay(editor, container); spacer.style.width = (editor.options.rtl ? pos.right : pos.left) + "px"; let top = pos.top; let bottom = pos.bottom; let placeAbove = !above == top > bottom && (above ? top : bottom) < container.clientHeight ? !above : above; let offset = pos.height + (placeAbove ? bottom : top) + "px"; style.bottom = placeAbove ? offset : "auto"; style.top = placeAbove ? "auto" : offset; } }, () => container.remove() ]; }; const observer = window.ResizeObserver && /* @__PURE__ */ new ResizeObserver( (e) => e.forEach((entry) => { const el = entry.target; const wrapper = el.querySelector(".pce-wrapper"); wrapper.style.paddingBottom = `${el.clientHeight - getStyleValue(wrapper, "marginBottom") - getStyleValue(wrapper, "lineHeight")}px`; }) ); const addOverscroll = (editor) => { observer && observer.observe(editor.container); }; const removeOverscroll = (editor) => { observer && observer.unobserve(editor.container); editor.wrapper.style.paddingBottom = ""; }; export { addOverscroll, addTooltip, removeOverscroll }; //# sourceMappingURL=tooltips.js.map