{
  "version": 3,
  "sources": ["../src/worker-thread.ts"],
  "sourcesContent": ["/**\n * External dependencies\n */\nimport {\n\tdefineProxy,\n\ttype Adapter,\n\ttype SendMessage,\n\ttype OnMessage,\n} from 'comctx';\n\n/**\n * Adapter for providing (worker exposing methods to main thread).\n */\nclass WorkerProvideAdapter implements Adapter {\n\tsendMessage: SendMessage = ( message, transfer ) => {\n\t\tself.postMessage( message, { transfer } );\n\t};\n\n\tonMessage: OnMessage = ( callback ) => {\n\t\tconst handler = ( event: MessageEvent ) => callback( event.data );\n\t\tself.addEventListener( 'message', handler );\n\t\treturn () => self.removeEventListener( 'message', handler );\n\t};\n}\n\n/**\n * Exposes an object's methods to be called from the main thread.\n *\n * This function should be called in the worker script to make methods\n * available for RPC calls. Only methods (functions) on the object will\n * be exposed; other properties are ignored.\n *\n * @example\n * ```typescript\n * // worker.ts\n * import { expose } from '@wordpress/worker-threads/worker';\n *\n * const api = {\n *   async processImage(buffer: ArrayBuffer): Promise<ArrayBuffer> {\n *     // ... processing logic\n *     return resultBuffer;\n *   },\n *\n *   async calculateSum(a: number, b: number): Promise<number> {\n *     return a + b;\n *   }\n * };\n *\n * expose(api);\n *\n * // Export the type for use with wrap() on main thread\n * export type WorkerAPI = typeof api;\n * ```\n *\n * @param target - Object containing methods to expose to the main thread.\n */\nexport function expose< T extends object >( target: T ): void {\n\t// Create the provide function using defineProxy with the target.\n\tconst [ provide ] = defineProxy( () => target, {\n\t\tnamespace: '__wordpress_worker__',\n\t\theartbeatCheck: false,\n\t\ttransfer: true,\n\t} );\n\n\t// Start providing the target through the adapter.\n\tprovide( new WorkerProvideAdapter() );\n}\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAKO;AAKP,IAAM,uBAAN,MAA8C;AAAA,EAC7C,cAA2B,CAAE,SAAS,aAAc;AACnD,SAAK,YAAa,SAAS,EAAE,SAAS,CAAE;AAAA,EACzC;AAAA,EAEA,YAAuB,CAAE,aAAc;AACtC,UAAM,UAAU,CAAE,UAAyB,SAAU,MAAM,IAAK;AAChE,SAAK,iBAAkB,WAAW,OAAQ;AAC1C,WAAO,MAAM,KAAK,oBAAqB,WAAW,OAAQ;AAAA,EAC3D;AACD;AAiCO,SAAS,OAA4B,QAAkB;AAE7D,QAAM,CAAE,OAAQ,QAAI,2BAAa,MAAM,QAAQ;AAAA,IAC9C,WAAW;AAAA,IACX,gBAAgB;AAAA,IAChB,UAAU;AAAA,EACX,CAAE;AAGF,UAAS,IAAI,qBAAqB,CAAE;AACrC;",
  "names": []
}
