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,EAAYU,OAAQE,GACpBpB,KAEO,GAiBP6B,MATa,KACbtB,EAAc,GACdC,EAAc,IAAIC,QAClBC,GAAY,M","sources":["webpack://wp/webpack/bootstrap","webpack://wp/webpack/runtime/define property getters","webpack://wp/webpack/runtime/hasOwnProperty shorthand","webpack://wp/webpack/runtime/make namespace object","webpack://wp/./packages/priority-queue/build-module/@wordpress/priority-queue/src/request-idle-callback.js","webpack://wp/./packages/priority-queue/build-module/@wordpress/priority-queue/src/index.js"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = function(exports, definition) {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }","// define __esModule on exports\n__webpack_require__.r = function(exports) {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/**\n * @typedef {( timeOrDeadline: IdleDeadline | number ) => void} Callback\n */\n\n/**\n * @return {(callback: Callback) => void} RequestIdleCallback\n */\nexport function createRequestIdleCallback() {\n\tif ( typeof window === 'undefined' ) {\n\t\treturn ( callback ) => {\n\t\t\tsetTimeout( () => callback( Date.now() ), 0 );\n\t\t};\n\t}\n\n\treturn window.requestIdleCallback || window.requestAnimationFrame;\n}\n\nexport default createRequestIdleCallback();\n","/**\n * Internal dependencies\n */\nimport requestIdleCallback from './request-idle-callback';\n\n/**\n * Enqueued callback to invoke once idle time permits.\n *\n * @typedef {()=>void} WPPriorityQueueCallback\n */\n\n/**\n * An object used to associate callbacks in a particular context grouping.\n *\n * @typedef {{}} WPPriorityQueueContext\n */\n\n/**\n * Function to add callback to priority queue.\n *\n * @typedef {(element:WPPriorityQueueContext,item:WPPriorityQueueCallback)=>void} WPPriorityQueueAdd\n */\n\n/**\n * Function to flush callbacks from priority queue.\n *\n * @typedef {(element:WPPriorityQueueContext)=>boolean} WPPriorityQueueFlush\n */\n\n/**\n * Reset the queue.\n *\n * @typedef {()=>void} WPPriorityQueueReset\n */\n\n/**\n * Priority queue instance.\n *\n * @typedef {Object} WPPriorityQueue\n *\n * @property {WPPriorityQueueAdd} add Add callback to queue for context.\n * @property {WPPriorityQueueFlush} flush Flush queue for context.\n * @property {WPPriorityQueueReset} reset Reset queue.\n */\n\n/**\n * Creates a context-aware queue that only executes\n * the last task of a given context.\n *\n * @example\n *```js\n * import { createQueue } from '@wordpress/priority-queue';\n *\n * const queue = createQueue();\n *\n * // Context objects.\n * const ctx1 = {};\n * const ctx2 = {};\n *\n * // For a given context in the queue, only the last callback is executed.\n * queue.add( ctx1, () => console.log( 'This will be printed first' ) );\n * queue.add( ctx2, () => console.log( 'This won\\'t be printed' ) );\n * queue.add( ctx2, () => console.log( 'This will be printed second' ) );\n *```\n *\n * @return {WPPriorityQueue} Queue object with `add`, `flush` and `reset` methods.\n */\nexport const createQueue = () => {\n\t/** @type {WPPriorityQueueContext[]} */\n\tlet waitingList = [];\n\n\t/** @type {WeakMap} */\n\tlet elementsMap = new WeakMap();\n\n\tlet isRunning = false;\n\n\t/**\n\t * Callback to process as much queue as time permits.\n\t *\n\t * @param {IdleDeadline|number} deadline Idle callback deadline object, or\n\t * animation frame timestamp.\n\t */\n\tconst runWaitingList = ( deadline ) => {\n\t\tconst hasTimeRemaining =\n\t\t\ttypeof deadline === 'number'\n\t\t\t\t? () => false\n\t\t\t\t: () => deadline.timeRemaining() > 0;\n\n\t\tdo {\n\t\t\tif ( waitingList.length === 0 ) {\n\t\t\t\tisRunning = false;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst nextElement = /** @type {WPPriorityQueueContext} */ ( waitingList.shift() );\n\t\t\tconst callback = /** @type {WPPriorityQueueCallback} */ ( elementsMap.get(\n\t\t\t\tnextElement\n\t\t\t) );\n\t\t\t// If errors with undefined callbacks are encountered double check that all of your useSelect calls\n\t\t\t// have all dependecies set correctly in second parameter. Missing dependencies can cause unexpected\n\t\t\t// loops and race conditions in the queue.\n\t\t\tcallback();\n\t\t\telementsMap.delete( nextElement );\n\t\t} while ( hasTimeRemaining() );\n\n\t\trequestIdleCallback( runWaitingList );\n\t};\n\n\t/**\n\t * Add a callback to the queue for a given context.\n\t *\n\t * @type {WPPriorityQueueAdd}\n\t *\n\t * @param {WPPriorityQueueContext} element Context object.\n\t * @param {WPPriorityQueueCallback} item Callback function.\n\t */\n\tconst add = ( element, item ) => {\n\t\tif ( ! elementsMap.has( element ) ) {\n\t\t\twaitingList.push( element );\n\t\t}\n\t\telementsMap.set( element, item );\n\t\tif ( ! isRunning ) {\n\t\t\tisRunning = true;\n\t\t\trequestIdleCallback( runWaitingList );\n\t\t}\n\t};\n\n\t/**\n\t * Flushes queue for a given context, returning true if the flush was\n\t * performed, or false if there is no queue for the given context.\n\t *\n\t * @type {WPPriorityQueueFlush}\n\t *\n\t * @param {WPPriorityQueueContext} element Context object.\n\t *\n\t * @return {boolean} Whether flush was performed.\n\t */\n\tconst flush = ( element ) => {\n\t\tif ( ! elementsMap.has( element ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst index = waitingList.indexOf( element );\n\t\twaitingList.splice( index, 1 );\n\t\tconst callback = /** @type {WPPriorityQueueCallback} */ ( elementsMap.get(\n\t\t\telement\n\t\t) );\n\t\telementsMap.delete( element );\n\t\tcallback();\n\n\t\treturn true;\n\t};\n\n\t/**\n\t * Reset the queue without running the pending callbacks.\n\t *\n\t * @type {WPPriorityQueueReset}\n\t */\n\tconst reset = () => {\n\t\twaitingList = [];\n\t\telementsMap = new WeakMap();\n\t\tisRunning = false;\n\t};\n\n\treturn {\n\t\tadd,\n\t\tflush,\n\t\treset,\n\t};\n};\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","window","callback","setTimeout","Date","now","requestIdleCallback","requestAnimationFrame","createQueue","waitingList","elementsMap","WeakMap","isRunning","runWaitingList","deadline","hasTimeRemaining","timeRemaining","length","nextElement","shift","delete","add","element","item","has","push","set","flush","index","indexOf","splice","reset"],"sourceRoot":""}