scheduler.native.development.js 12 KB

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