@tanstack/db
Version:
A reactive client store for building super fast apps on sync
1 lines • 1.89 kB
Source Map (JSON)
{"version":3,"file":"browser-polyfills.cjs","names":[],"sources":["../../../src/utils/browser-polyfills.ts"],"sourcesContent":["// Type definitions for requestIdleCallback - compatible with existing browser types\nexport type IdleCallbackDeadline = {\n didTimeout: boolean\n timeRemaining: () => number\n}\n\nexport type IdleCallbackFunction = (deadline: IdleCallbackDeadline) => void\n\nconst requestIdleCallbackPolyfill = (\n callback: IdleCallbackFunction,\n): number => {\n // Use a very small timeout for the polyfill to simulate idle time\n const timeout = 0\n const timeoutId = setTimeout(() => {\n callback({\n didTimeout: true, // Always indicate timeout for the polyfill\n timeRemaining: () => 50, // Return some time remaining for polyfill\n })\n }, timeout)\n return timeoutId as unknown as number\n}\n\nconst cancelIdleCallbackPolyfill = (id: number): void => {\n clearTimeout(id as unknown as ReturnType<typeof setTimeout>)\n}\n\nexport const safeRequestIdleCallback: (\n callback: IdleCallbackFunction,\n options?: { timeout?: number },\n) => number =\n typeof window !== `undefined` && `requestIdleCallback` in window\n ? (callback, options) =>\n (window as any).requestIdleCallback(callback, options)\n : (callback, _options) => requestIdleCallbackPolyfill(callback)\n\nexport const safeCancelIdleCallback: (id: number) => void =\n typeof window !== `undefined` && `cancelIdleCallback` in window\n ? (id) => (window as any).cancelIdleCallback(id)\n : cancelIdleCallbackPolyfill\n"],"mappings":"AAQA,IAAM,+BACJ,aACW;CASX,OANkB,iBAAiB;EACjC,SAAS;GACP,YAAY;GACZ,qBAAqB;EACvB,CAAC;CACH,GAAG,CACI;AACT;AAEA,IAAM,8BAA8B,OAAqB;CACvD,aAAa,EAA8C;AAC7D;AAEA,IAAa,0BAIX,OAAO,WAAW,eAAe,yBAAyB,UACrD,UAAU,YACR,OAAe,oBAAoB,UAAU,OAAO,KACtD,UAAU,aAAa,4BAA4B,QAAQ;AAElE,IAAa,yBACX,OAAO,WAAW,eAAe,wBAAwB,UACpD,OAAQ,OAAe,mBAAmB,EAAE,IAC7C"}