{"version":3,"file":"utils.cjs","names":["noop"],"sources":["../../src/AsyncComponent/utils.ts"],"sourcesContent":["import { isObject, noop } from '@pastweb/tools';\nimport type { Dependency, DependencyInfo } from './types';\n\n/**\n * Loads a dependency and returns the requested export.\n *\n * @param info - A dependency function, promise, or `DependencyInfo` object to load.\n * @returns A promise that resolves to the requested export from the loaded module.\n *\n * @throws Will throw an error if the dependency fails to load.\n *\n * @remarks\n * - The `dependency` can be a function that returns a promise or a direct promise.\n * - The `exportName` specifies which export to return from the loaded module (default is `'default'`).\n * - Optional `onSuccess` and `onError` callbacks can be provided in the `DependencyInfo` for handling success or failure.\n * \n * @example\n * // Example usage:\n * const info: DependencyInfo = { dependency: () => import('./module'), exportName: 'default' };\n * const moduleExport = await loadDependency(info);\n * // `moduleExport` contains the default export from the loaded module.\n */\nexport async function loadDependency(info: Dependency | DependencyInfo): Promise<any> {\n  const normalized = isObject(info)\n    ? {\n        ...info,\n        exportName: (info as DependencyInfo).exportName ?? 'default',\n      } as DependencyInfo\n    : {\n        exportName: 'default',\n        dependency: typeof info === 'function' ? info() : info,\n      } as DependencyInfo;\n\n  const { exportName, dependency, onSuccess = noop, onError = noop } = normalized;\n\n  const depPromise =  typeof dependency === 'function' ? dependency() : dependency;\n  try {\n    const module = await Promise.resolve(depPromise);\n    onSuccess(module[exportName as string]);\n    return module[exportName as string];\n  } catch(e) {\n    (onError as any)(e);\n    throw e;\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,eAAsB,eAAe,MAAiD;CAWpF,MAAM,EAAE,YAAY,YAAY,YAAYA,eAAAA,MAAM,UAAUA,eAAAA,UAAAA,GAAAA,eAAAA,SAAAA,CAVhC,IAAI,IAC5B;EACE,GAAG;EACH,YAAa,KAAwB,cAAc;CACrD,IACA;EACE,YAAY;EACZ,YAAY,OAAO,SAAS,aAAa,KAAK,IAAI;CACpD;CAIJ,MAAM,aAAc,OAAO,eAAe,aAAa,WAAW,IAAI;CACtE,IAAI;EACF,MAAM,SAAS,MAAM,QAAQ,QAAQ,UAAU;EAC/C,UAAU,OAAO,WAAqB;EACtC,OAAO,OAAO;CAChB,SAAQ,GAAG;EACT,QAAiB,CAAC;EAClB,MAAM;CACR;AACF"}