{"version":3,"file":"index.cjs","sources":[""],"sourcesContent":["export type TOnIntersectionArgs = Parameters<typeof onIntersection>;\n\nexport type TOnIntersectionReturn = ReturnType<typeof onIntersection>;\n\n/**\n * Observes intersection changes for one or more elements.\n * It is a no-op when IntersectionObserver is unavailable.\n * @param {Element|Element[]} elements Elements to observe\n * @param {IntersectionObserverCallback} callback Observer callback\n * @param {IntersectionObserverInit} [options={}] Observer options\n * @param {boolean} [isAutoInit=true] Start observing immediately\n * @returns {{ observer: IntersectionObserver|null; observe: () => void; disconnect: () => void; }} Controls\n * @throws {TypeError} onIntersection: arguments are invalid\n * @example\n * const visibility = onIntersection(card, ([ entry ]) => setVisible(entry.isIntersecting));\n * @example\n * // Lazy-load an image when it approaches the viewport\n * const lazyImage = onIntersection(image, ([ entry ]) => {\n *   if (entry.isIntersecting) image.src = image.dataset.src ?? \"\";\n * }, { rootMargin: \"200px\" });\n */\nexport const onIntersection = (\n  elements: Element | readonly Element[],\n  callback: IntersectionObserverCallback,\n  options: IntersectionObserverInit = {},\n  isAutoInit: boolean = true\n): {\n  disconnect: () => void;\n  observe: () => void;\n  observer: IntersectionObserver | null;\n} => {\n  const targets = Array.isArray(elements) ? elements : [ elements ];\n  if (targets.length === 0 || targets.some((element) => !element || element.nodeType !== 1)) {\n    throw new TypeError(\"onIntersection: elements must contain DOM elements\");\n  }\n  if (typeof callback !== \"function\") {\n    throw new TypeError(\"onIntersection: callback must be a function\");\n  }\n  if (!options || typeof options !== \"object\" || Array.isArray(options)) {\n    throw new TypeError(\"onIntersection: options must be a plain object\");\n  }\n  if (typeof isAutoInit !== \"boolean\") {\n    throw new TypeError(\"onIntersection: isAutoInit must be a boolean\");\n  }\n  const Observer = globalThis.IntersectionObserver;\n  const observer = typeof Observer === \"function\" ? new Observer(callback, options) : null;\n  const observe = (): void => targets.forEach((element) => observer?.observe(element));\n  const disconnect = (): void => observer?.disconnect();\n  if (isAutoInit) {\n    observe();\n  }\n  return { disconnect, observe, observer };\n};\n"],"names":["onIntersection","elements","callback","options","isAutoInit","targets","Array","isArray","length","some","element","nodeType","TypeError","Observer","globalThis","IntersectionObserver","observer","observe","forEach","disconnect"],"mappings":"+DAqBaA,eAAiB,CAC5BC,SACAC,SACAC,QAAoC,CAAA,EACpCC,WAAsB,QAMtB,MAAMC,QAAUC,MAAMC,QAAQN,UAAYA,SAAW,CAAEA,UACvD,GAAII,QAAQG,SAAW,GAAKH,QAAQI,KAAMC,UAAaA,SAAWA,QAAQC,WAAa,GACrF,MAAM,IAAIC,UAAU,sDAEtB,UAAWV,WAAa,WACtB,MAAM,IAAIU,UAAU,+CAEtB,IAAKT,gBAAkBA,UAAY,UAAYG,MAAMC,QAAQJ,SAC3D,MAAM,IAAIS,UAAU,kDAEtB,UAAWR,aAAe,UACxB,MAAM,IAAIQ,UAAU,gDAEtB,MAAMC,SAAWC,WAAWC,qBAC5B,MAAMC,gBAAkBH,WAAa,WAAa,IAAIA,SAASX,SAAUC,SAAW,KACpF,MAAMc,QAAU,IAAYZ,QAAQa,QAASR,SAAYM,UAAUC,QAAQP,UAC3E,MAAMS,WAAa,IAAYH,UAAUG,aACzC,GAAIf,WACFa,UAEF,MAAO,CAAEE,sBAAYF,gBAASD"}