build/scripts/priority-queue
index.js
10.1 KB
7 months ago
index.js.map
16.1 KB
9 months ago
index.min.asset.php
83 B
7 months ago
index.min.js
3.4 KB
7 months ago
index.min.js.map
16.2 KB
7 months ago
index.js in Gutenberg 23.2.0, at build/scripts/priority-queue/index.js
| 1 | "use strict"; |
| 2 | var wp; |
| 3 | (wp ||= {}).priorityQueue = (() => { |
| 4 | var __create = Object.create; |
| 5 | var __defProp = Object.defineProperty; |
| 6 | var __getOwnPropDesc = Object.getOwnPropertyDescriptor; |
| 7 | var __getOwnPropNames = Object.getOwnPropertyNames; |
| 8 | var __getProtoOf = Object.getPrototypeOf; |
| 9 | var __hasOwnProp = Object.prototype.hasOwnProperty; |
| 10 | var __commonJS = (cb, mod) => function __require() { |
| 11 | return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; |
| 12 | }; |
| 13 | var __export = (target, all) => { |
| 14 | for (var name in all) |
| 15 | __defProp(target, name, { get: all[name], enumerable: true }); |
| 16 | }; |
| 17 | var __copyProps = (to, from, except, desc) => { |
| 18 | if (from && typeof from === "object" || typeof from === "function") { |
| 19 | for (let key of __getOwnPropNames(from)) |
| 20 | if (!__hasOwnProp.call(to, key) && key !== except) |
| 21 | __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); |
| 22 | } |
| 23 | return to; |
| 24 | }; |
| 25 | var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( |
| 26 | // If the importer is in node compatibility mode or this is not an ESM |
| 27 | // file that has been converted to a CommonJS file using a Babel- |
| 28 | // compatible transform (i.e. "__esModule" has not been set), then set |
| 29 | // "default" to the CommonJS "module.exports" for node compatibility. |
| 30 | isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, |
| 31 | mod |
| 32 | )); |
| 33 | var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); |
| 34 | |
| 35 | // node_modules/requestidlecallback/index.js |
| 36 | var require_requestidlecallback = __commonJS({ |
| 37 | "node_modules/requestidlecallback/index.js"(exports, module) { |
| 38 | (function(factory) { |
| 39 | if (typeof define === "function" && define.amd) { |
| 40 | define([], factory); |
| 41 | } else if (typeof module === "object" && module.exports) { |
| 42 | module.exports = factory(); |
| 43 | } else { |
| 44 | window.idleCallbackShim = factory(); |
| 45 | } |
| 46 | })(function() { |
| 47 | "use strict"; |
| 48 | var scheduleStart, throttleDelay, lazytimer, lazyraf; |
| 49 | var root = typeof window != "undefined" ? window : typeof global != void 0 ? global : this || {}; |
| 50 | var requestAnimationFrame = root.cancelRequestAnimationFrame && root.requestAnimationFrame || setTimeout; |
| 51 | var cancelRequestAnimationFrame = root.cancelRequestAnimationFrame || clearTimeout; |
| 52 | var tasks = []; |
| 53 | var runAttempts = 0; |
| 54 | var isRunning = false; |
| 55 | var remainingTime = 7; |
| 56 | var minThrottle = 35; |
| 57 | var throttle = 125; |
| 58 | var index = 0; |
| 59 | var taskStart = 0; |
| 60 | var tasklength = 0; |
| 61 | var IdleDeadline = { |
| 62 | get didTimeout() { |
| 63 | return false; |
| 64 | }, |
| 65 | timeRemaining: function() { |
| 66 | var timeRemaining = remainingTime - (Date.now() - taskStart); |
| 67 | return timeRemaining < 0 ? 0 : timeRemaining; |
| 68 | } |
| 69 | }; |
| 70 | var setInactive = debounce(function() { |
| 71 | remainingTime = 22; |
| 72 | throttle = 66; |
| 73 | minThrottle = 0; |
| 74 | }); |
| 75 | function debounce(fn) { |
| 76 | var id, timestamp; |
| 77 | var wait = 99; |
| 78 | var check = function() { |
| 79 | var last = Date.now() - timestamp; |
| 80 | if (last < wait) { |
| 81 | id = setTimeout(check, wait - last); |
| 82 | } else { |
| 83 | id = null; |
| 84 | fn(); |
| 85 | } |
| 86 | }; |
| 87 | return function() { |
| 88 | timestamp = Date.now(); |
| 89 | if (!id) { |
| 90 | id = setTimeout(check, wait); |
| 91 | } |
| 92 | }; |
| 93 | } |
| 94 | function abortRunning() { |
| 95 | if (isRunning) { |
| 96 | if (lazyraf) { |
| 97 | cancelRequestAnimationFrame(lazyraf); |
| 98 | } |
| 99 | if (lazytimer) { |
| 100 | clearTimeout(lazytimer); |
| 101 | } |
| 102 | isRunning = false; |
| 103 | } |
| 104 | } |
| 105 | function onInputorMutation() { |
| 106 | if (throttle != 125) { |
| 107 | remainingTime = 7; |
| 108 | throttle = 125; |
| 109 | minThrottle = 35; |
| 110 | if (isRunning) { |
| 111 | abortRunning(); |
| 112 | scheduleLazy(); |
| 113 | } |
| 114 | } |
| 115 | setInactive(); |
| 116 | } |
| 117 | function scheduleAfterRaf() { |
| 118 | lazyraf = null; |
| 119 | lazytimer = setTimeout(runTasks, 0); |
| 120 | } |
| 121 | function scheduleRaf() { |
| 122 | lazytimer = null; |
| 123 | requestAnimationFrame(scheduleAfterRaf); |
| 124 | } |
| 125 | function scheduleLazy() { |
| 126 | if (isRunning) { |
| 127 | return; |
| 128 | } |
| 129 | throttleDelay = throttle - (Date.now() - taskStart); |
| 130 | scheduleStart = Date.now(); |
| 131 | isRunning = true; |
| 132 | if (minThrottle && throttleDelay < minThrottle) { |
| 133 | throttleDelay = minThrottle; |
| 134 | } |
| 135 | if (throttleDelay > 9) { |
| 136 | lazytimer = setTimeout(scheduleRaf, throttleDelay); |
| 137 | } else { |
| 138 | throttleDelay = 0; |
| 139 | scheduleRaf(); |
| 140 | } |
| 141 | } |
| 142 | function runTasks() { |
| 143 | var task, i, len; |
| 144 | var timeThreshold = remainingTime > 9 ? 9 : 1; |
| 145 | taskStart = Date.now(); |
| 146 | isRunning = false; |
| 147 | lazytimer = null; |
| 148 | if (runAttempts > 2 || taskStart - throttleDelay - 50 < scheduleStart) { |
| 149 | for (i = 0, len = tasks.length; i < len && IdleDeadline.timeRemaining() > timeThreshold; i++) { |
| 150 | task = tasks.shift(); |
| 151 | tasklength++; |
| 152 | if (task) { |
| 153 | task(IdleDeadline); |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | if (tasks.length) { |
| 158 | scheduleLazy(); |
| 159 | } else { |
| 160 | runAttempts = 0; |
| 161 | } |
| 162 | } |
| 163 | function requestIdleCallbackShim(task) { |
| 164 | index++; |
| 165 | tasks.push(task); |
| 166 | scheduleLazy(); |
| 167 | return index; |
| 168 | } |
| 169 | function cancelIdleCallbackShim(id) { |
| 170 | var index2 = id - 1 - tasklength; |
| 171 | if (tasks[index2]) { |
| 172 | tasks[index2] = null; |
| 173 | } |
| 174 | } |
| 175 | if (!root.requestIdleCallback || !root.cancelIdleCallback) { |
| 176 | root.requestIdleCallback = requestIdleCallbackShim; |
| 177 | root.cancelIdleCallback = cancelIdleCallbackShim; |
| 178 | if (root.document && document.addEventListener) { |
| 179 | root.addEventListener("scroll", onInputorMutation, true); |
| 180 | root.addEventListener("resize", onInputorMutation); |
| 181 | document.addEventListener("focus", onInputorMutation, true); |
| 182 | document.addEventListener("mouseover", onInputorMutation, true); |
| 183 | ["click", "keypress", "touchstart", "mousedown"].forEach(function(name) { |
| 184 | document.addEventListener(name, onInputorMutation, { capture: true, passive: true }); |
| 185 | }); |
| 186 | if (root.MutationObserver) { |
| 187 | new MutationObserver(onInputorMutation).observe(document.documentElement, { childList: true, subtree: true, attributes: true }); |
| 188 | } |
| 189 | } |
| 190 | } else { |
| 191 | try { |
| 192 | root.requestIdleCallback(function() { |
| 193 | }, { timeout: 0 }); |
| 194 | } catch (e) { |
| 195 | (function(rIC) { |
| 196 | var timeRemainingProto, timeRemaining; |
| 197 | root.requestIdleCallback = function(fn, timeout) { |
| 198 | if (timeout && typeof timeout.timeout == "number") { |
| 199 | return rIC(fn, timeout.timeout); |
| 200 | } |
| 201 | return rIC(fn); |
| 202 | }; |
| 203 | if (root.IdleCallbackDeadline && (timeRemainingProto = IdleCallbackDeadline.prototype)) { |
| 204 | timeRemaining = Object.getOwnPropertyDescriptor(timeRemainingProto, "timeRemaining"); |
| 205 | if (!timeRemaining || !timeRemaining.configurable || !timeRemaining.get) { |
| 206 | return; |
| 207 | } |
| 208 | Object.defineProperty(timeRemainingProto, "timeRemaining", { |
| 209 | value: function() { |
| 210 | return timeRemaining.get.call(this); |
| 211 | }, |
| 212 | enumerable: true, |
| 213 | configurable: true |
| 214 | }); |
| 215 | } |
| 216 | })(root.requestIdleCallback); |
| 217 | } |
| 218 | } |
| 219 | return { |
| 220 | request: requestIdleCallbackShim, |
| 221 | cancel: cancelIdleCallbackShim |
| 222 | }; |
| 223 | }); |
| 224 | } |
| 225 | }); |
| 226 | |
| 227 | // packages/priority-queue/build-module/index.mjs |
| 228 | var index_exports = {}; |
| 229 | __export(index_exports, { |
| 230 | createQueue: () => createQueue |
| 231 | }); |
| 232 | |
| 233 | // packages/priority-queue/build-module/request-idle-callback.mjs |
| 234 | var import_requestidlecallback = __toESM(require_requestidlecallback(), 1); |
| 235 | function createRequestIdleCallback() { |
| 236 | if (typeof window === "undefined") { |
| 237 | return (callback) => { |
| 238 | setTimeout(() => callback(Date.now()), 0); |
| 239 | }; |
| 240 | } |
| 241 | return window.requestIdleCallback; |
| 242 | } |
| 243 | var request_idle_callback_default = createRequestIdleCallback(); |
| 244 | |
| 245 | // packages/priority-queue/build-module/index.mjs |
| 246 | var createQueue = () => { |
| 247 | const waitingList = /* @__PURE__ */ new Map(); |
| 248 | let isRunning = false; |
| 249 | const runWaitingList = (deadline) => { |
| 250 | for (const [nextElement, callback] of waitingList) { |
| 251 | waitingList.delete(nextElement); |
| 252 | callback(); |
| 253 | if ("number" === typeof deadline || deadline.timeRemaining() <= 0) { |
| 254 | break; |
| 255 | } |
| 256 | } |
| 257 | if (waitingList.size === 0) { |
| 258 | isRunning = false; |
| 259 | return; |
| 260 | } |
| 261 | request_idle_callback_default(runWaitingList); |
| 262 | }; |
| 263 | const add = (element, item) => { |
| 264 | waitingList.set(element, item); |
| 265 | if (!isRunning) { |
| 266 | isRunning = true; |
| 267 | request_idle_callback_default(runWaitingList); |
| 268 | } |
| 269 | }; |
| 270 | const flush = (element) => { |
| 271 | const callback = waitingList.get(element); |
| 272 | if (void 0 === callback) { |
| 273 | return false; |
| 274 | } |
| 275 | waitingList.delete(element); |
| 276 | callback(); |
| 277 | return true; |
| 278 | }; |
| 279 | const cancel = (element) => { |
| 280 | return waitingList.delete(element); |
| 281 | }; |
| 282 | const reset = () => { |
| 283 | waitingList.clear(); |
| 284 | isRunning = false; |
| 285 | }; |
| 286 | return { |
| 287 | add, |
| 288 | flush, |
| 289 | cancel, |
| 290 | reset |
| 291 | }; |
| 292 | }; |
| 293 | return __toCommonJS(index_exports); |
| 294 | })(); |
| 295 | //# sourceMappingURL=index.js.map |
| 296 |