Skip to main content

REF_CLIP_RECT_JS

Constant REF_CLIP_RECT_JS 

Source
pub const REF_CLIP_RECT_JS: &str = r#"
/* bc:clip */
(function(id) {
    const reg = window.__bcRefs;
    const r = reg && reg.byId.get(Number(id));
    const el = r && typeof r.deref === 'function' ? r.deref() : r;
    if (!el || !el.isConnected) return JSON.stringify({ gone: true });
    try { el.scrollIntoView({ block: 'center', inline: 'center' }); } catch (e) {}
    const rect = el.getBoundingClientRect();
    if (rect.width === 0 || rect.height === 0) return JSON.stringify({ error: 'element has zero area' });
    return JSON.stringify({
        x: rect.left + window.scrollX,
        y: rect.top + window.scrollY,
        width: rect.width,
        height: rect.height,
    });
})
"#;
Expand description

(id) → the element’s border box in document coordinates (same contract as GET_CLIP_RECT_JS).