"use strict"; "use client"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { createCustomEvent: () => createCustomEvent, useCustomEventListener: () => useCustomEventListener }); module.exports = __toCommonJS(src_exports); var import_react = require("react"); var DOCUMENT = typeof document !== "undefined" ? document : void 0; function createCustomEvent(eventName) { function dispatch(payload, eventInitDict) { DOCUMENT?.dispatchEvent( new CustomEvent(eventName, { ...eventInitDict, detail: payload }) ); } const hook = useCustomEventListener.bind(null, eventName); hook.dispatch = dispatch; hook.eventName = eventName; return hook; } function useCustomEventListener(eventName, onListen, options, deps) { const { listen, onStartListening, onStopListening } = options ?? {}; function getDepList() { const depList = []; if (deps !== void 0) { depList.push(...deps); if (listen !== void 0) { depList.push(listen); } } if (depList.length === 0) { return; } return depList; } function handleCallback(event) { const customEvent = event; onListen(customEvent.detail, customEvent); } (0, import_react.useEffect)(() => { if (listen !== void 0 && !listen) { return; } onStartListening?.(); DOCUMENT?.addEventListener(eventName, handleCallback); return () => { onStopListening?.(); DOCUMENT?.removeEventListener(eventName, handleCallback); }; }, getDepList()); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { createCustomEvent, useCustomEventListener });