{"version":3,"file":"mediaInfoFactory.cjs","names":["noopPrint","defaultLocateFile","path","prefix","url","URL","pathname","mediaInfoFactory","options","callback","errCallback","undefined","Promise","resolve","reject","locateFile","mergedOptions","DEFAULT_OPTIONS","format","mediaInfoModuleFactoryOpts","print","printErr","onAbort","err","mediaInfoModuleFactory","then","wasmModule","MediaInfo","catch","error","_default","exports","default"],"sourceRoot":"../../src","sources":["mediaInfoFactory.ts"],"sourcesContent":["import MediaInfo, { DEFAULT_OPTIONS, type FormatType } from './MediaInfo.js'\nimport mediaInfoModuleFactory, { type MediaInfoModule } from './MediaInfoModule.js'\n\ninterface MediaInfoFactoryOptions<TFormat extends FormatType> {\n  /** Output cover data as base64 */\n  coverData?: boolean\n\n  /** Chunk size used by `analyzeData` (in bytes) */\n  chunkSize?: number\n\n  /** Result format (`object`, `JSON`, `XML`, `HTML` or `text`) */\n  format?: TFormat\n\n  /** Full information display (all internal tags) */\n  full?: boolean\n\n  /**\n   * This method will be called before loading the WASM file. It should return the actual URL to\n   * `MediaInfoModule.wasm`.\n   *\n   * @see https://emscripten.org/docs/api_reference/module.html#Module.locateFile\n   */\n  locateFile?: (path: string, prefix: string) => string\n}\n\nconst noopPrint = () => {\n  // No-op\n}\n\ntype FactoryCallback<TFormat extends FormatType> = (mediainfo: MediaInfo<TFormat>) => void\ntype ErrorCallback = (error: unknown) => void\n\nfunction defaultLocateFile(path: string, prefix: string) {\n  try {\n    const url = new URL(prefix)\n    if (url.pathname === '/') {\n      return `${prefix}mediainfo.js/dist/${path}`\n    }\n  } catch {\n    // empty\n  }\n  return `${prefix}../${path}`\n}\n\n// TODO pass through more emscripten module options?\n\n/**\n * Creates a {@link MediaInfo} instance with the specified options.\n *\n * @typeParam TFormat - The format type, defaults to `object`.\n * @param options - Configuration options for creating the {@link MediaInfo} instance.\n * @returns A promise that resolves to a {@link MediaInfo} instance when no callback is provided.\n */\nfunction mediaInfoFactory<TFormat extends FormatType = typeof DEFAULT_OPTIONS.format>(\n  options?: MediaInfoFactoryOptions<TFormat>\n): Promise<MediaInfo<TFormat>>\n\n/**\n * Creates a {@link MediaInfo} instance with the specified options and executes the callback.\n *\n * @typeParam TFormat - The format type, defaults to `object`.\n * @param options - Configuration options for creating the {@link MediaInfo} instance.\n * @param callback - Function to call with the {@link MediaInfo} instance.\n * @param errCallback - Optional function to call on error.\n */\nfunction mediaInfoFactory<TFormat extends FormatType = typeof DEFAULT_OPTIONS.format>(\n  options: MediaInfoFactoryOptions<TFormat>,\n  callback: FactoryCallback<TFormat>,\n  errCallback?: ErrorCallback\n): void\n\nfunction mediaInfoFactory<TFormat extends FormatType = typeof DEFAULT_OPTIONS.format>(\n  options: MediaInfoFactoryOptions<TFormat> = {},\n  callback?: FactoryCallback<TFormat>,\n  errCallback?: ErrorCallback\n): Promise<MediaInfo<TFormat>> | undefined {\n  if (callback === undefined) {\n    return new Promise((resolve, reject) => {\n      mediaInfoFactory(options, resolve, reject)\n    })\n  }\n\n  const { locateFile, ...mergedOptions } = {\n    ...DEFAULT_OPTIONS,\n    ...options,\n    format: (options.format ?? DEFAULT_OPTIONS.format) as TFormat,\n  }\n\n  const mediaInfoModuleFactoryOpts: Partial<MediaInfoModule> = {\n    // Silence all print in module\n    print: noopPrint,\n    printErr: noopPrint,\n\n    locateFile: locateFile ?? defaultLocateFile,\n    onAbort: (err: Error) => {\n      if (errCallback) {\n        errCallback(err)\n      }\n    },\n  }\n\n  // Fetch and load WASM module\n  mediaInfoModuleFactory(mediaInfoModuleFactoryOpts)\n    .then((wasmModule) => {\n      callback(new MediaInfo<TFormat>(wasmModule, mergedOptions))\n    })\n    .catch((error: unknown) => {\n      if (errCallback) {\n        errCallback(error)\n      }\n    })\n}\n\nexport type { MediaInfoFactoryOptions }\nexport default mediaInfoFactory\n"],"mappings":";;;;;;;;;;AAyBA,MAAMA,SAAS,GAAGA,CAAA,KAAM;EACtB;AAAA,CACD;AAKD,SAASC,iBAAiBA,CAACC,IAAY,EAAEC,MAAc,EAAE;EACvD,IA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