| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 |
- /**
- * @license React
- * scheduler.development.js
- *
- * Copyright (c) Meta Platforms, Inc. and affiliates.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- */
- "use strict";
- "production" !== process.env.NODE_ENV &&
- (function () {
- function performWorkUntilDeadline() {
- needsPaint = !1;
- if (isMessageLoopRunning) {
- var currentTime = exports.unstable_now();
- startTime = currentTime;
- var hasMoreWork = !0;
- try {
- a: {
- isHostCallbackScheduled = !1;
- isHostTimeoutScheduled &&
- ((isHostTimeoutScheduled = !1),
- localClearTimeout(taskTimeoutID),
- (taskTimeoutID = -1));
- isPerformingWork = !0;
- var previousPriorityLevel = currentPriorityLevel;
- try {
- b: {
- advanceTimers(currentTime);
- for (
- currentTask = peek(taskQueue);
- null !== currentTask &&
- !(
- currentTask.expirationTime > currentTime &&
- shouldYieldToHost()
- );
- ) {
- var callback = currentTask.callback;
- if ("function" === typeof callback) {
- currentTask.callback = null;
- currentPriorityLevel = currentTask.priorityLevel;
- var continuationCallback = callback(
- currentTask.expirationTime <= currentTime
- );
- currentTime = exports.unstable_now();
- if ("function" === typeof continuationCallback) {
- currentTask.callback = continuationCallback;
- advanceTimers(currentTime);
- hasMoreWork = !0;
- break b;
- }
- currentTask === peek(taskQueue) && pop(taskQueue);
- advanceTimers(currentTime);
- } else pop(taskQueue);
- currentTask = peek(taskQueue);
- }
- if (null !== currentTask) hasMoreWork = !0;
- else {
- var firstTimer = peek(timerQueue);
- null !== firstTimer &&
- requestHostTimeout(
- handleTimeout,
- firstTimer.startTime - currentTime
- );
- hasMoreWork = !1;
- }
- }
- break a;
- } finally {
- (currentTask = null),
- (currentPriorityLevel = previousPriorityLevel),
- (isPerformingWork = !1);
- }
- hasMoreWork = void 0;
- }
- } finally {
- hasMoreWork
- ? schedulePerformWorkUntilDeadline()
- : (isMessageLoopRunning = !1);
- }
- }
- }
- function push(heap, node) {
- var index = heap.length;
- heap.push(node);
- a: for (; 0 < index; ) {
- var parentIndex = (index - 1) >>> 1,
- parent = heap[parentIndex];
- if (0 < compare(parent, node))
- (heap[parentIndex] = node),
- (heap[index] = parent),
- (index = parentIndex);
- else break a;
- }
- }
- function peek(heap) {
- return 0 === heap.length ? null : heap[0];
- }
- function pop(heap) {
- if (0 === heap.length) return null;
- var first = heap[0],
- last = heap.pop();
- if (last !== first) {
- heap[0] = last;
- a: for (
- var index = 0, length = heap.length, halfLength = length >>> 1;
- index < halfLength;
- ) {
- var leftIndex = 2 * (index + 1) - 1,
- left = heap[leftIndex],
- rightIndex = leftIndex + 1,
- right = heap[rightIndex];
- if (0 > compare(left, last))
- rightIndex < length && 0 > compare(right, left)
- ? ((heap[index] = right),
- (heap[rightIndex] = last),
- (index = rightIndex))
- : ((heap[index] = left),
- (heap[leftIndex] = last),
- (index = leftIndex));
- else if (rightIndex < length && 0 > compare(right, last))
- (heap[index] = right),
- (heap[rightIndex] = last),
- (index = rightIndex);
- else break a;
- }
- }
- return first;
- }
- function compare(a, b) {
- var diff = a.sortIndex - b.sortIndex;
- return 0 !== diff ? diff : a.id - b.id;
- }
- function advanceTimers(currentTime) {
- for (var timer = peek(timerQueue); null !== timer; ) {
- if (null === timer.callback) pop(timerQueue);
- else if (timer.startTime <= currentTime)
- pop(timerQueue),
- (timer.sortIndex = timer.expirationTime),
- push(taskQueue, timer);
- else break;
- timer = peek(timerQueue);
- }
- }
- function handleTimeout(currentTime) {
- isHostTimeoutScheduled = !1;
- advanceTimers(currentTime);
- if (!isHostCallbackScheduled)
- if (null !== peek(taskQueue))
- (isHostCallbackScheduled = !0),
- isMessageLoopRunning ||
- ((isMessageLoopRunning = !0), schedulePerformWorkUntilDeadline());
- else {
- var firstTimer = peek(timerQueue);
- null !== firstTimer &&
- requestHostTimeout(
- handleTimeout,
- firstTimer.startTime - currentTime
- );
- }
- }
- function shouldYieldToHost() {
- return needsPaint
- ? !0
- : exports.unstable_now() - startTime < frameInterval
- ? !1
- : !0;
- }
- function requestHostTimeout(callback, ms) {
- taskTimeoutID = localSetTimeout(function () {
- callback(exports.unstable_now());
- }, ms);
- }
- "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
- "function" ===
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart &&
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
- exports.unstable_now = void 0;
- if (
- "object" === typeof performance &&
- "function" === typeof performance.now
- ) {
- var localPerformance = performance;
- exports.unstable_now = function () {
- return localPerformance.now();
- };
- } else {
- var localDate = Date,
- initialTime = localDate.now();
- exports.unstable_now = function () {
- return localDate.now() - initialTime;
- };
- }
- var taskQueue = [],
- timerQueue = [],
- taskIdCounter = 1,
- currentTask = null,
- currentPriorityLevel = 3,
- isPerformingWork = !1,
- isHostCallbackScheduled = !1,
- isHostTimeoutScheduled = !1,
- needsPaint = !1,
- localSetTimeout = "function" === typeof setTimeout ? setTimeout : null,
- localClearTimeout =
- "function" === typeof clearTimeout ? clearTimeout : null,
- localSetImmediate =
- "undefined" !== typeof setImmediate ? setImmediate : null,
- isMessageLoopRunning = !1,
- taskTimeoutID = -1,
- frameInterval = 5,
- startTime = -1;
- if ("function" === typeof localSetImmediate)
- var schedulePerformWorkUntilDeadline = function () {
- localSetImmediate(performWorkUntilDeadline);
- };
- else if ("undefined" !== typeof MessageChannel) {
- var channel = new MessageChannel(),
- port = channel.port2;
- channel.port1.onmessage = performWorkUntilDeadline;
- schedulePerformWorkUntilDeadline = function () {
- port.postMessage(null);
- };
- } else
- schedulePerformWorkUntilDeadline = function () {
- localSetTimeout(performWorkUntilDeadline, 0);
- };
- exports.unstable_IdlePriority = 5;
- exports.unstable_ImmediatePriority = 1;
- exports.unstable_LowPriority = 4;
- exports.unstable_NormalPriority = 3;
- exports.unstable_Profiling = null;
- exports.unstable_UserBlockingPriority = 2;
- exports.unstable_cancelCallback = function (task) {
- task.callback = null;
- };
- exports.unstable_forceFrameRate = function (fps) {
- 0 > fps || 125 < fps
- ? console.error(
- "forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"
- )
- : (frameInterval = 0 < fps ? Math.floor(1e3 / fps) : 5);
- };
- exports.unstable_getCurrentPriorityLevel = function () {
- return currentPriorityLevel;
- };
- exports.unstable_next = function (eventHandler) {
- switch (currentPriorityLevel) {
- case 1:
- case 2:
- case 3:
- var priorityLevel = 3;
- break;
- default:
- priorityLevel = currentPriorityLevel;
- }
- var previousPriorityLevel = currentPriorityLevel;
- currentPriorityLevel = priorityLevel;
- try {
- return eventHandler();
- } finally {
- currentPriorityLevel = previousPriorityLevel;
- }
- };
- exports.unstable_requestPaint = function () {
- needsPaint = !0;
- };
- exports.unstable_runWithPriority = function (priorityLevel, eventHandler) {
- switch (priorityLevel) {
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- break;
- default:
- priorityLevel = 3;
- }
- var previousPriorityLevel = currentPriorityLevel;
- currentPriorityLevel = priorityLevel;
- try {
- return eventHandler();
- } finally {
- currentPriorityLevel = previousPriorityLevel;
- }
- };
- exports.unstable_scheduleCallback = function (
- priorityLevel,
- callback,
- options
- ) {
- var currentTime = exports.unstable_now();
- "object" === typeof options && null !== options
- ? ((options = options.delay),
- (options =
- "number" === typeof options && 0 < options
- ? currentTime + options
- : currentTime))
- : (options = currentTime);
- switch (priorityLevel) {
- case 1:
- var timeout = -1;
- break;
- case 2:
- timeout = 250;
- break;
- case 5:
- timeout = 1073741823;
- break;
- case 4:
- timeout = 1e4;
- break;
- default:
- timeout = 5e3;
- }
- timeout = options + timeout;
- priorityLevel = {
- id: taskIdCounter++,
- callback: callback,
- priorityLevel: priorityLevel,
- startTime: options,
- expirationTime: timeout,
- sortIndex: -1
- };
- options > currentTime
- ? ((priorityLevel.sortIndex = options),
- push(timerQueue, priorityLevel),
- null === peek(taskQueue) &&
- priorityLevel === peek(timerQueue) &&
- (isHostTimeoutScheduled
- ? (localClearTimeout(taskTimeoutID), (taskTimeoutID = -1))
- : (isHostTimeoutScheduled = !0),
- requestHostTimeout(handleTimeout, options - currentTime)))
- : ((priorityLevel.sortIndex = timeout),
- push(taskQueue, priorityLevel),
- isHostCallbackScheduled ||
- isPerformingWork ||
- ((isHostCallbackScheduled = !0),
- isMessageLoopRunning ||
- ((isMessageLoopRunning = !0),
- schedulePerformWorkUntilDeadline())));
- return priorityLevel;
- };
- exports.unstable_shouldYield = shouldYieldToHost;
- exports.unstable_wrapCallback = function (callback) {
- var parentPriorityLevel = currentPriorityLevel;
- return function () {
- var previousPriorityLevel = currentPriorityLevel;
- currentPriorityLevel = parentPriorityLevel;
- try {
- return callback.apply(this, arguments);
- } finally {
- currentPriorityLevel = previousPriorityLevel;
- }
- };
- };
- "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
- "function" ===
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
- })();
|