{"version":3,"file":"requestIdleCallback.mjs","names":[],"sources":["../../src/tools/requestIdleCallback.ts"],"sourcesContent":["import { dateNow } from '@openobserve/js-core/time'\nimport { setTimeout, clearTimeout } from './timer'\nimport { monitor } from './monitor'\n\n// This type is not yet supported in TS 3.8. Imported from the TS source until we upgrade the\n// minimum supported TS version.\n// https://github.com/microsoft/TypeScript/blob/13c374a868c926f6a907666a5599992c1351b773/src/lib/dom.generated.d.ts#L9513-L9516\nexport interface IdleDeadline {\n  readonly didTimeout: boolean\n  timeRemaining(): DOMHighResTimeStamp\n}\n\n/**\n * 'requestIdleCallback' with a shim.\n */\nexport function requestIdleCallback(callback: (deadline: IdleDeadline) => void, opts?: { timeout?: number }) {\n  // Note: check both 'requestIdleCallback' and 'cancelIdleCallback' existence because some polyfills only implement 'requestIdleCallback'.\n  if (window.requestIdleCallback && window.cancelIdleCallback) {\n    const id = window.requestIdleCallback(monitor(callback), opts)\n    return () => window.cancelIdleCallback(id)\n  }\n  return requestIdleCallbackShim(callback)\n}\n\nexport const MAX_TASK_TIME = 50\n\n/*\n * Shim from https://developer.chrome.com/blog/using-requestidlecallback#checking_for_requestidlecallback\n * Note: there is no simple way to support the \"timeout\" option, so we ignore it.\n */\nexport function requestIdleCallbackShim(callback: (deadline: IdleDeadline) => void) {\n  const start = dateNow()\n  const timeoutId = setTimeout(() => {\n    callback({\n      didTimeout: false,\n      timeRemaining: () => Math.max(0, MAX_TASK_TIME - (dateNow() - start)),\n    })\n  }, 0)\n  return () => clearTimeout(timeoutId)\n}\n"],"mappings":";;;;;;;AAeA,SAAgB,oBAAoB,UAA4C,MAA6B;CAE3G,IAAI,OAAO,uBAAuB,OAAO,oBAAoB;EAC3D,MAAM,KAAK,OAAO,oBAAoB,QAAQ,QAAQ,GAAG,IAAI;EAC7D,aAAa,OAAO,mBAAmB,EAAE;CAC3C;CACA,OAAO,wBAAwB,QAAQ;AACzC;AAQA,SAAgB,wBAAwB,UAA4C;CAClF,MAAM,QAAQ,QAAQ;CACtB,MAAM,YAAY,iBAAiB;EACjC,SAAS;GACP,YAAY;GACZ,qBAAqB,KAAK,IAAI,GAAA,MAAoB,QAAQ,IAAI,MAAM;EACtE,CAAC;CACH,GAAG,CAAC;CACJ,aAAa,aAAa,SAAS;AACrC"}