// Metro module 264 (f265). import Module265 from "./Module265"; import { getNativeNodeReference, getInstanceHandle } from "./Module136"; import nullthrows from "./nullthrows"; import { beginEvent, endEvent } from "./Module46"; import { createIntersectionObserverEntry } from "./IntersectionObserverEntry"; let c276_5, c276_6, c276_7, c276_8, c276_10, notifyIntersectionObservers, throwIfNoNativeIntersectionObserver; const getTargetFromInstanceHandle = function getTargetFromInstanceHandle(targetInstanceHandle) { return c276_8.get(targetInstanceHandle); }; notifyIntersectionObservers = function notifyIntersectionObservers() { beginEvent("IntersectionObserverManager.notifyIntersectionObservers"); try { (function doNotifyIntersectionObservers() { let r35; if (Module265 == null) { throwIfNoNativeIntersectionObserver(); throw new Error("unreachable"); } const r43 = Module265.takeRecords(); const map = new Map(); let r47 = r43[Symbol.iterator](); const next = r47.next; const r10 = "Could not find target to create IntersectionObserverEntry"; while (true) { const r50 = r47 === void 0 ? void 0 : (r35 = next.call(r47)).done ? r47 = void 0 : r35.value; if (r47 === void 0) { for (const item of map) { const [r87, r88] = item; const r91 = c276_7.get(r87); if (r91) { const { observer, callback } = r91; try { const call = callback.call; if (call === Function.prototype.call) { callback.call(observer, r88, observer); continue; } call.call(callback, observer, r88, observer); continue; } catch ($e) { console.error($e); continue; } } return void 0; } return void 0; } try { const r54 = map.get(r50.intersectionObserverId); let r55 = r54; if (r54 == null) { const r19 = []; r55 = r19; map.set(r50.intersectionObserverId, r19); } const targetFromInstanceHandle = getTargetFromInstanceHandle(r50.targetInstanceHandle); if (targetFromInstanceHandle != null) { r55.push(createIntersectionObserverEntry(r50, targetFromInstanceHandle)); } else { console.warn(r10); } } catch (r77) { if (r47 !== void 0 && typeof r47.return === "function") { try { r47.return(); } catch {} } throw r77; } } })(); } catch (r16) { endEvent(); throw r16; } endEvent(); }; throwIfNoNativeIntersectionObserver = function throwIfNoNativeIntersectionObserver() { throw new Error("Missing native implementation of IntersectionObserver"); }; c276_5 = 1; c276_6 = false; c276_7 = new Map(); c276_8 = new WeakMap(); c276_10 = new WeakMap(); export function registerObserver(a0, a1) { const r1 = c276_5; c276_5 = r1 + 1; c276_7.set(r1, { observer: a0, callback: a1 }); return r1; } export function unregisterObserver(a0) { if (c276_7.delete(a0) && c276_7.size === 0) { if (Module265 != null) { Module265.disconnect(); } c276_6 = false; } } export function observe({ intersectionObserverId, root, target }) { if (Module265 == null) { throw new Error("Missing native implementation of IntersectionObserver"); } const r21 = c276_7.get(intersectionObserverId); if (r21 == null) { console.error(`IntersectionObserverManager: could not start observing target because IntersectionObserver with ID ${intersectionObserverId} was not registered.`); return false; } const nativeNodeReference = getNativeNodeReference(target); if (nativeNodeReference == null) { return false; } const instanceHandle = getInstanceHandle(target); if (instanceHandle == null) { console.error("IntersectionObserverManager: could not find reference to instance handle from target"); return false; } const rootShadowNode = root != null ? getNativeNodeReference(root) : null; if (root != null && rootShadowNode == null) { console.error("IntersectionObserverManager: could not find shadow node for observation root"); return false; } c276_8.set(instanceHandle, target); if (!c276_6) { Module265.connect(notifyIntersectionObservers); c276_6 = true; } c276_10.set(target, nullthrows(Module265.observeV2)({ intersectionObserverId, rootShadowNode, targetShadowNode: nativeNodeReference, thresholds: r21.observer.thresholds, rootThresholds: r21.observer.rnRootThresholds, rootMargin: r21.observer.rootMargin })); return true; } export function unobserve(a0, a1) { if (Module265 != null) { if (c276_7.get(a0) != null) { const r31 = c276_10.get(a1); if (r31 != null) { nullthrows(Module265.unobserveV2)(a0, r31); } else { console.error("IntersectionObserverManager: could not find registration data for target"); } } else { console.error(`IntersectionObserverManager: could not stop observing target because IntersectionObserver with ID ${a0} was not registered.`); } return void 0; } throw new Error("Missing native implementation of IntersectionObserver"); }