// Return a map of `{ oids, rects }` for all `oid` elements on the page. // // Pass an `onlyOids` map to restrict to only those elements. // Pass an `intersectingClientRect` to restrict to only oids which intersect that rect. getOidRects(onlyOids, intersectingClientRect) { if (!this._projectComponent) return undefined; // console.time("oidRects"); //TODO: somehow we want to know the root element on the page so don't include toolbars... const oidElements = document.querySelectorAll("[data-oid]"); const oids = []; const rects = []; let i = -1, element; while (element = oidElements[++i]) { const oid = element.getAttribute("data-oid"); // skip if not in the `onlyOids` map if (onlyOids && onlyOids[oid] === undefined) continue; // skip if doesn't intersect the `intersectingClientRect` const rect = elements.clientRect(element); if (intersectingClientRect && !intersectingClientRect.intersects(rect)) continue; // ok, add to our lists oids.push(oid); rects.push(rect); } // console.timeEnd("oidRects"); return { oids, rects }; }
// Given an `oid`, return the `clientRect` for it as currently rendered. getRectForOid(oid) { const element = this.getElementForOid(oid); return elements.clientRect(element); }