scheduler.native.production.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /**
  2. * @license React
  3. * scheduler.native.production.js
  4. *
  5. * Copyright (c) Meta Platforms, Inc. and affiliates.
  6. *
  7. * This source code is licensed under the MIT license found in the
  8. * LICENSE file in the root directory of this source tree.
  9. */
  10. "use strict";
  11. function push(heap, node) {
  12. var index = heap.length;
  13. heap.push(node);
  14. a: for (; 0 < index; ) {
  15. var parentIndex = (index - 1) >>> 1,
  16. parent = heap[parentIndex];
  17. if (0 < compare(parent, node))
  18. (heap[parentIndex] = node), (heap[index] = parent), (index = parentIndex);
  19. else break a;
  20. }
  21. }
  22. function peek(heap) {
  23. return 0 === heap.length ? null : heap[0];
  24. }
  25. function pop(heap) {
  26. if (0 === heap.length) return null;
  27. var first = heap[0],
  28. last = heap.pop();
  29. if (last !== first) {
  30. heap[0] = last;
  31. a: for (
  32. var index = 0, length = heap.length, halfLength = length >>> 1;
  33. index < halfLength;
  34. ) {
  35. var leftIndex = 2 * (index + 1) - 1,
  36. left = heap[leftIndex],
  37. rightIndex = leftIndex + 1,
  38. right = heap[rightIndex];
  39. if (0 > compare(left, last))
  40. rightIndex < length && 0 > compare(right, left)
  41. ? ((heap[index] = right),
  42. (heap[rightIndex] = last),
  43. (index = rightIndex))
  44. : ((heap[index] = left),
  45. (heap[leftIndex] = last),
  46. (index = leftIndex));
  47. else if (rightIndex < length && 0 > compare(right, last))
  48. (heap[index] = right), (heap[rightIndex] = last), (index = rightIndex);
  49. else break a;
  50. }
  51. }
  52. return first;
  53. }
  54. function compare(a, b) {
  55. var diff = a.sortIndex - b.sortIndex;
  56. return 0 !== diff ? diff : a.id - b.id;
  57. }
  58. var getCurrentTime;
  59. if ("object" === typeof performance && "function" === typeof performance.now) {
  60. var localPerformance = performance;
  61. getCurrentTime = function () {
  62. return localPerformance.now();
  63. };
  64. } else {
  65. var localDate = Date,
  66. initialTime = localDate.now();
  67. getCurrentTime = function () {
  68. return localDate.now() - initialTime;
  69. };
  70. }
  71. var taskQueue = [],
  72. timerQueue = [],
  73. taskIdCounter = 1,
  74. currentTask = null,
  75. currentPriorityLevel = 3,
  76. isPerformingWork = !1,
  77. isHostCallbackScheduled = !1,
  78. isHostTimeoutScheduled = !1,
  79. needsPaint = !1,
  80. localSetTimeout = "function" === typeof setTimeout ? setTimeout : null,
  81. localClearTimeout = "function" === typeof clearTimeout ? clearTimeout : null,
  82. localSetImmediate = "undefined" !== typeof setImmediate ? setImmediate : null;
  83. function advanceTimers(currentTime) {
  84. for (var timer = peek(timerQueue); null !== timer; ) {
  85. if (null === timer.callback) pop(timerQueue);
  86. else if (timer.startTime <= currentTime)
  87. pop(timerQueue),
  88. (timer.sortIndex = timer.expirationTime),
  89. push(taskQueue, timer);
  90. else break;
  91. timer = peek(timerQueue);
  92. }
  93. }
  94. function handleTimeout(currentTime) {
  95. isHostTimeoutScheduled = !1;
  96. advanceTimers(currentTime);
  97. if (!isHostCallbackScheduled)
  98. if (null !== peek(taskQueue))
  99. (isHostCallbackScheduled = !0),
  100. isMessageLoopRunning ||
  101. ((isMessageLoopRunning = !0), schedulePerformWorkUntilDeadline());
  102. else {
  103. var firstTimer = peek(timerQueue);
  104. null !== firstTimer &&
  105. requestHostTimeout(handleTimeout, firstTimer.startTime - currentTime);
  106. }
  107. }
  108. function unstable_scheduleCallback$1(priorityLevel, callback, options) {
  109. var currentTime = getCurrentTime();
  110. "object" === typeof options && null !== options
  111. ? ((options = options.delay),
  112. (options =
  113. "number" === typeof options && 0 < options
  114. ? currentTime + options
  115. : currentTime))
  116. : (options = currentTime);
  117. switch (priorityLevel) {
  118. case 1:
  119. var timeout = -1;
  120. break;
  121. case 2:
  122. timeout = 250;
  123. break;
  124. case 5:
  125. timeout = 1073741823;
  126. break;
  127. case 4:
  128. timeout = 1e4;
  129. break;
  130. default:
  131. timeout = 5e3;
  132. }
  133. timeout = options + timeout;
  134. priorityLevel = {
  135. id: taskIdCounter++,
  136. callback: callback,
  137. priorityLevel: priorityLevel,
  138. startTime: options,
  139. expirationTime: timeout,
  140. sortIndex: -1
  141. };
  142. options > currentTime
  143. ? ((priorityLevel.sortIndex = options),
  144. push(timerQueue, priorityLevel),
  145. null === peek(taskQueue) &&
  146. priorityLevel === peek(timerQueue) &&
  147. (isHostTimeoutScheduled
  148. ? (localClearTimeout(taskTimeoutID), (taskTimeoutID = -1))
  149. : (isHostTimeoutScheduled = !0),
  150. requestHostTimeout(handleTimeout, options - currentTime)))
  151. : ((priorityLevel.sortIndex = timeout),
  152. push(taskQueue, priorityLevel),
  153. isHostCallbackScheduled ||
  154. isPerformingWork ||
  155. ((isHostCallbackScheduled = !0),
  156. isMessageLoopRunning ||
  157. ((isMessageLoopRunning = !0), schedulePerformWorkUntilDeadline())));
  158. return priorityLevel;
  159. }
  160. function unstable_cancelCallback$1(task) {
  161. task.callback = null;
  162. }
  163. function unstable_getCurrentPriorityLevel$1() {
  164. return currentPriorityLevel;
  165. }
  166. var isMessageLoopRunning = !1,
  167. taskTimeoutID = -1,
  168. startTime = -1;
  169. function shouldYieldToHost() {
  170. return needsPaint ? !0 : 5 > getCurrentTime() - startTime ? !1 : !0;
  171. }
  172. function requestPaint() {
  173. needsPaint = !0;
  174. }
  175. function performWorkUntilDeadline() {
  176. needsPaint = !1;
  177. if (isMessageLoopRunning) {
  178. var currentTime = getCurrentTime();
  179. startTime = currentTime;
  180. var hasMoreWork = !0;
  181. try {
  182. a: {
  183. isHostCallbackScheduled = !1;
  184. isHostTimeoutScheduled &&
  185. ((isHostTimeoutScheduled = !1),
  186. localClearTimeout(taskTimeoutID),
  187. (taskTimeoutID = -1));
  188. isPerformingWork = !0;
  189. var previousPriorityLevel = currentPriorityLevel;
  190. try {
  191. b: {
  192. advanceTimers(currentTime);
  193. for (
  194. currentTask = peek(taskQueue);
  195. null !== currentTask &&
  196. !(
  197. currentTask.expirationTime > currentTime && shouldYieldToHost()
  198. );
  199. ) {
  200. var callback = currentTask.callback;
  201. if ("function" === typeof callback) {
  202. currentTask.callback = null;
  203. currentPriorityLevel = currentTask.priorityLevel;
  204. var continuationCallback = callback(
  205. currentTask.expirationTime <= currentTime
  206. );
  207. currentTime = getCurrentTime();
  208. if ("function" === typeof continuationCallback) {
  209. currentTask.callback = continuationCallback;
  210. advanceTimers(currentTime);
  211. hasMoreWork = !0;
  212. break b;
  213. }
  214. currentTask === peek(taskQueue) && pop(taskQueue);
  215. advanceTimers(currentTime);
  216. } else pop(taskQueue);
  217. currentTask = peek(taskQueue);
  218. }
  219. if (null !== currentTask) hasMoreWork = !0;
  220. else {
  221. var firstTimer = peek(timerQueue);
  222. null !== firstTimer &&
  223. requestHostTimeout(
  224. handleTimeout,
  225. firstTimer.startTime - currentTime
  226. );
  227. hasMoreWork = !1;
  228. }
  229. }
  230. break a;
  231. } finally {
  232. (currentTask = null),
  233. (currentPriorityLevel = previousPriorityLevel),
  234. (isPerformingWork = !1);
  235. }
  236. hasMoreWork = void 0;
  237. }
  238. } finally {
  239. hasMoreWork
  240. ? schedulePerformWorkUntilDeadline()
  241. : (isMessageLoopRunning = !1);
  242. }
  243. }
  244. }
  245. var schedulePerformWorkUntilDeadline;
  246. if ("function" === typeof localSetImmediate)
  247. schedulePerformWorkUntilDeadline = function () {
  248. localSetImmediate(performWorkUntilDeadline);
  249. };
  250. else if ("undefined" !== typeof MessageChannel) {
  251. var channel = new MessageChannel(),
  252. port = channel.port2;
  253. channel.port1.onmessage = performWorkUntilDeadline;
  254. schedulePerformWorkUntilDeadline = function () {
  255. port.postMessage(null);
  256. };
  257. } else
  258. schedulePerformWorkUntilDeadline = function () {
  259. localSetTimeout(performWorkUntilDeadline, 0);
  260. };
  261. function requestHostTimeout(callback, ms) {
  262. taskTimeoutID = localSetTimeout(function () {
  263. callback(getCurrentTime());
  264. }, ms);
  265. }
  266. var unstable_UserBlockingPriority =
  267. "undefined" !== typeof nativeRuntimeScheduler
  268. ? nativeRuntimeScheduler.unstable_UserBlockingPriority
  269. : 2,
  270. unstable_NormalPriority =
  271. "undefined" !== typeof nativeRuntimeScheduler
  272. ? nativeRuntimeScheduler.unstable_NormalPriority
  273. : 3,
  274. unstable_LowPriority =
  275. "undefined" !== typeof nativeRuntimeScheduler
  276. ? nativeRuntimeScheduler.unstable_LowPriority
  277. : 4,
  278. unstable_ImmediatePriority =
  279. "undefined" !== typeof nativeRuntimeScheduler
  280. ? nativeRuntimeScheduler.unstable_ImmediatePriority
  281. : 1,
  282. unstable_scheduleCallback =
  283. "undefined" !== typeof nativeRuntimeScheduler
  284. ? nativeRuntimeScheduler.unstable_scheduleCallback
  285. : unstable_scheduleCallback$1,
  286. unstable_cancelCallback =
  287. "undefined" !== typeof nativeRuntimeScheduler
  288. ? nativeRuntimeScheduler.unstable_cancelCallback
  289. : unstable_cancelCallback$1,
  290. unstable_getCurrentPriorityLevel =
  291. "undefined" !== typeof nativeRuntimeScheduler
  292. ? nativeRuntimeScheduler.unstable_getCurrentPriorityLevel
  293. : unstable_getCurrentPriorityLevel$1,
  294. unstable_shouldYield =
  295. "undefined" !== typeof nativeRuntimeScheduler
  296. ? nativeRuntimeScheduler.unstable_shouldYield
  297. : shouldYieldToHost,
  298. unstable_requestPaint =
  299. "undefined" !== typeof nativeRuntimeScheduler
  300. ? nativeRuntimeScheduler.unstable_requestPaint
  301. : requestPaint,
  302. unstable_now =
  303. "undefined" !== typeof nativeRuntimeScheduler
  304. ? nativeRuntimeScheduler.unstable_now
  305. : getCurrentTime;
  306. function throwNotImplemented() {
  307. throw Error("Not implemented.");
  308. }
  309. exports.unstable_IdlePriority =
  310. "undefined" !== typeof nativeRuntimeScheduler
  311. ? nativeRuntimeScheduler.unstable_IdlePriority
  312. : 5;
  313. exports.unstable_ImmediatePriority = unstable_ImmediatePriority;
  314. exports.unstable_LowPriority = unstable_LowPriority;
  315. exports.unstable_NormalPriority = unstable_NormalPriority;
  316. exports.unstable_Profiling = null;
  317. exports.unstable_UserBlockingPriority = unstable_UserBlockingPriority;
  318. exports.unstable_cancelCallback = unstable_cancelCallback;
  319. exports.unstable_forceFrameRate = throwNotImplemented;
  320. exports.unstable_getCurrentPriorityLevel = unstable_getCurrentPriorityLevel;
  321. exports.unstable_next = throwNotImplemented;
  322. exports.unstable_now = unstable_now;
  323. exports.unstable_requestPaint = unstable_requestPaint;
  324. exports.unstable_runWithPriority = throwNotImplemented;
  325. exports.unstable_scheduleCallback = unstable_scheduleCallback;
  326. exports.unstable_shouldYield = unstable_shouldYield;
  327. exports.unstable_wrapCallback = throwNotImplemented;