{"version":3,"names":["reportFatalErrorOnJS","isChromeDebugger","isJest","shouldBeUseWeb","runOnJS","setupMicrotasks","callMicrotasks","runOnUIImmediately","mockedRequestAnimationFrame","IS_JEST","SHOULD_BE_USE_WEB","IS_CHROME_DEBUGGER","callGuardDEV","fn","_len","arguments","length","args","Array","_key","e","global","__ErrorUtils","reportFatalError","setupCallGuard","__callGuardDEV","error","message","stack","capturableConsole","console","setupConsole","assert","debug","log","warn","info","setupRequestAnimationFrame","nativeRequestAnimationFrame","requestAnimationFrame","animationFrameCallbacks","lastNativeAnimationFrameTimestamp","__flushAnimationFrame","frameTimestamp","currentCallbacks","forEach","f","callback","push","timestamp","__frameTimestamp","undefined","initializeUIRuntime","globalThis"],"sources":["initializers.ts"],"sourcesContent":["'use strict';\nimport { reportFatalErrorOnJS } from './errors';\nimport { isChromeDebugger, isJest, shouldBeUseWeb } from './PlatformChecker';\nimport {\n runOnJS,\n setupMicrotasks,\n callMicrotasks,\n runOnUIImmediately,\n} from './threads';\nimport { mockedRequestAnimationFrame } from './mockedRequestAnimationFrame';\n\nconst IS_JEST = isJest();\nconst SHOULD_BE_USE_WEB = shouldBeUseWeb();\nconst IS_CHROME_DEBUGGER = isChromeDebugger();\n\n// callGuard is only used with debug builds\nexport function callGuardDEV(\n fn: (...args: Args) => ReturnValue,\n ...args: Args\n): ReturnValue | void {\n 'worklet';\n try {\n return fn(...args);\n } catch (e) {\n if (global.__ErrorUtils) {\n global.__ErrorUtils.reportFatalError(e as Error);\n } else {\n throw e;\n }\n }\n}\n\nexport function setupCallGuard() {\n 'worklet';\n global.__callGuardDEV = callGuardDEV;\n global.__ErrorUtils = {\n reportFatalError: (error: Error) => {\n runOnJS(reportFatalErrorOnJS)({\n message: error.message,\n stack: error.stack,\n });\n },\n };\n}\n\n// We really have to create a copy of console here. Function runOnJS we use on elements inside\n// this object makes it not configurable\nconst capturableConsole = { ...console };\n\nexport function setupConsole() {\n 'worklet';\n if (!IS_CHROME_DEBUGGER) {\n // @ts-ignore TypeScript doesn't like that there are missing methods in console object, but we don't provide all the methods for the UI runtime console version\n global.console = {\n /* eslint-disable @typescript-eslint/unbound-method */\n assert: runOnJS(capturableConsole.assert),\n debug: runOnJS(capturableConsole.debug),\n log: runOnJS(capturableConsole.log),\n warn: runOnJS(capturableConsole.warn),\n error: runOnJS(capturableConsole.error),\n info: runOnJS(capturableConsole.info),\n /* eslint-enable @typescript-eslint/unbound-method */\n };\n }\n}\n\nfunction setupRequestAnimationFrame() {\n 'worklet';\n\n // Jest mocks requestAnimationFrame API and it does not like if that mock gets overridden\n // so we avoid doing requestAnimationFrame batching in Jest environment.\n const nativeRequestAnimationFrame = global.requestAnimationFrame;\n\n let animationFrameCallbacks: Array<(timestamp: number) => void> = [];\n let lastNativeAnimationFrameTimestamp = -1;\n\n global.__flushAnimationFrame = (frameTimestamp: number) => {\n const currentCallbacks = animationFrameCallbacks;\n animationFrameCallbacks = [];\n currentCallbacks.forEach((f) => f(frameTimestamp));\n callMicrotasks();\n };\n\n global.requestAnimationFrame = (\n callback: (timestamp: number) => void\n ): number => {\n animationFrameCallbacks.push(callback);\n if (animationFrameCallbacks.length === 1) {\n // We schedule native requestAnimationFrame only when the first callback\n // is added and then use it to execute all the enqueued callbacks. Once\n // the callbacks are run, we clear the array.\n nativeRequestAnimationFrame((timestamp) => {\n if (lastNativeAnimationFrameTimestamp >= timestamp) {\n // Make sure we only execute the callbacks once for a given frame\n return;\n }\n lastNativeAnimationFrameTimestamp = timestamp;\n global.__frameTimestamp = timestamp;\n global.__flushAnimationFrame(timestamp);\n global.__frameTimestamp = undefined;\n });\n }\n // Reanimated currently does not support cancelling callbacks requested with\n // requestAnimationFrame. We return -1 as identifier which isn't in line\n // with the spec but it should give users better clue in case they actually\n // attempt to store the value returned from rAF and use it for cancelling.\n return -1;\n };\n}\n\nexport function initializeUIRuntime() {\n if (IS_JEST) {\n // requestAnimationFrame react-native jest's setup is incorrect as it polyfills\n // the method directly using setTimeout, therefore the callback doesn't get the\n // expected timestamp as the only argument: https://github.com/facebook/react-native/blob/main/packages/react-native/jest/setup.js#L28\n // We override this setup here to make sure that callbacks get the proper timestamps\n // when executed. For non-jest environments we define requestAnimationFrame in setupRequestAnimationFrame\n // @ts-ignore TypeScript uses Node definition for rAF, setTimeout, etc which returns a Timeout object rather than a number\n globalThis.requestAnimationFrame = mockedRequestAnimationFrame;\n }\n\n runOnUIImmediately(() => {\n 'worklet';\n setupCallGuard();\n setupConsole();\n if (!SHOULD_BE_USE_WEB) {\n setupMicrotasks();\n setupRequestAnimationFrame();\n }\n })();\n}\n"],"mappings":"AAAA,YAAY;;AACZ,SAASA,oBAAoB,QAAQ,UAAU;AAC/C,SAASC,gBAAgB,EAAEC,MAAM,EAAEC,cAAc,QAAQ,mBAAmB;AAC5E,SACEC,OAAO,EACPC,eAAe,EACfC,cAAc,EACdC,kBAAkB,QACb,WAAW;AAClB,SAASC,2BAA2B,QAAQ,+BAA+B;AAE3E,MAAMC,OAAO,GAAGP,MAAM,EAAE;AACxB,MAAMQ,iBAAiB,GAAGP,cAAc,EAAE;AAC1C,MAAMQ,kBAAkB,GAAGV,gBAAgB,EAAE;;AAE7C;AACA,OAAO,SAASW,YAAYA,CAC1BC,EAAkC,EAEd;EACpB,SAAS;;EAAC,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAFPC,IAAI,OAAAC,KAAA,CAAAJ,IAAA,OAAAA,IAAA,WAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;IAAJF,IAAI,CAAAE,IAAA,QAAAJ,SAAA,CAAAI,IAAA;EAAA;EAGP,IAAI;IACF,OAAON,EAAE,CAAC,GAAGI,IAAI,CAAC;EACpB,CAAC,CAAC,OAAOG,CAAC,EAAE;IACV,IAAIC,MAAM,CAACC,YAAY,EAAE;MACvBD,MAAM,CAACC,YAAY,CAACC,gBAAgB,CAACH,CAAC,CAAU;IAClD,CAAC,MAAM;MACL,MAAMA,CAAC;IACT;EACF;AACF;AAEA,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