Commit ed14d577c05509ce81845efc6921bb35c1ee7ee4
1 parent
d04fb45a
remove throttle and use depence
Showing
2 changed files
with
1 additions
and
440 deletions
Show diff stats
src/components/color-picker/saturation.vue
src/utils/throttle.js deleted
1 | -/** | ||
2 | - * lodash (Custom Build) <https://lodash.com/> | ||
3 | - * Build: `lodash modularize exports="npm" -o ./` | ||
4 | - * Copyright jQuery Foundation and other contributors <https://jquery.org/> | ||
5 | - * Released under MIT license <https://lodash.com/license> | ||
6 | - * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE> | ||
7 | - * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
8 | - */ | ||
9 | - | ||
10 | -/** Used as the `TypeError` message for "Functions" methods. */ | ||
11 | -var FUNC_ERROR_TEXT = 'Expected a function'; | ||
12 | - | ||
13 | -/** Used as references for various `Number` constants. */ | ||
14 | -var NAN = 0 / 0; | ||
15 | - | ||
16 | -/** `Object#toString` result references. */ | ||
17 | -var symbolTag = '[object Symbol]'; | ||
18 | - | ||
19 | -/** Used to match leading and trailing whitespace. */ | ||
20 | -var reTrim = /^\s+|\s+$/g; | ||
21 | - | ||
22 | -/** Used to detect bad signed hexadecimal string values. */ | ||
23 | -var reIsBadHex = /^[-+]0x[0-9a-f]+$/i; | ||
24 | - | ||
25 | -/** Used to detect binary string values. */ | ||
26 | -var reIsBinary = /^0b[01]+$/i; | ||
27 | - | ||
28 | -/** Used to detect octal string values. */ | ||
29 | -var reIsOctal = /^0o[0-7]+$/i; | ||
30 | - | ||
31 | -/** Built-in method references without a dependency on `root`. */ | ||
32 | -var freeParseInt = parseInt; | ||
33 | - | ||
34 | -/** Detect free variable `global` from Node.js. */ | ||
35 | -var freeGlobal = typeof global == 'object' && global && global.Object === Object && global; | ||
36 | - | ||
37 | -/** Detect free variable `self`. */ | ||
38 | -var freeSelf = typeof self == 'object' && self && self.Object === Object && self; | ||
39 | - | ||
40 | -/** Used as a reference to the global object. */ | ||
41 | -var root = freeGlobal || freeSelf || Function('return this')(); | ||
42 | - | ||
43 | -/** Used for built-in method references. */ | ||
44 | -var objectProto = Object.prototype; | ||
45 | - | ||
46 | -/** | ||
47 | - * Used to resolve the | ||
48 | - * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) | ||
49 | - * of values. | ||
50 | - */ | ||
51 | -var objectToString = objectProto.toString; | ||
52 | - | ||
53 | -/* Built-in method references for those with the same name as other `lodash` methods. */ | ||
54 | -var nativeMax = Math.max, | ||
55 | - nativeMin = Math.min; | ||
56 | - | ||
57 | -/** | ||
58 | - * Gets the timestamp of the number of milliseconds that have elapsed since | ||
59 | - * the Unix epoch (1 January 1970 00:00:00 UTC). | ||
60 | - * | ||
61 | - * @static | ||
62 | - * @memberOf _ | ||
63 | - * @since 2.4.0 | ||
64 | - * @category Date | ||
65 | - * @returns {number} Returns the timestamp. | ||
66 | - * @example | ||
67 | - * | ||
68 | - * _.defer(function(stamp) { | ||
69 | - * console.log(_.now() - stamp); | ||
70 | - * }, _.now()); | ||
71 | - * // => Logs the number of milliseconds it took for the deferred invocation. | ||
72 | - */ | ||
73 | -var now = function() { | ||
74 | - return root.Date.now(); | ||
75 | -}; | ||
76 | - | ||
77 | -/** | ||
78 | - * Creates a debounced function that delays invoking `func` until after `wait` | ||
79 | - * milliseconds have elapsed since the last time the debounced function was | ||
80 | - * invoked. The debounced function comes with a `cancel` method to cancel | ||
81 | - * delayed `func` invocations and a `flush` method to immediately invoke them. | ||
82 | - * Provide `options` to indicate whether `func` should be invoked on the | ||
83 | - * leading and/or trailing edge of the `wait` timeout. The `func` is invoked | ||
84 | - * with the last arguments provided to the debounced function. Subsequent | ||
85 | - * calls to the debounced function return the result of the last `func` | ||
86 | - * invocation. | ||
87 | - * | ||
88 | - * **Note:** If `leading` and `trailing` options are `true`, `func` is | ||
89 | - * invoked on the trailing edge of the timeout only if the debounced function | ||
90 | - * is invoked more than once during the `wait` timeout. | ||
91 | - * | ||
92 | - * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred | ||
93 | - * until to the next tick, similar to `setTimeout` with a timeout of `0`. | ||
94 | - * | ||
95 | - * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/) | ||
96 | - * for details over the differences between `_.debounce` and `_.throttle`. | ||
97 | - * | ||
98 | - * @static | ||
99 | - * @memberOf _ | ||
100 | - * @since 0.1.0 | ||
101 | - * @category Function | ||
102 | - * @param {Function} func The function to debounce. | ||
103 | - * @param {number} [wait=0] The number of milliseconds to delay. | ||
104 | - * @param {Object} [options={}] The options object. | ||
105 | - * @param {boolean} [options.leading=false] | ||
106 | - * Specify invoking on the leading edge of the timeout. | ||
107 | - * @param {number} [options.maxWait] | ||
108 | - * The maximum time `func` is allowed to be delayed before it's invoked. | ||
109 | - * @param {boolean} [options.trailing=true] | ||
110 | - * Specify invoking on the trailing edge of the timeout. | ||
111 | - * @returns {Function} Returns the new debounced function. | ||
112 | - * @example | ||
113 | - * | ||
114 | - * // Avoid costly calculations while the window size is in flux. | ||
115 | - * jQuery(window).on('resize', _.debounce(calculateLayout, 150)); | ||
116 | - * | ||
117 | - * // Invoke `sendMail` when clicked, debouncing subsequent calls. | ||
118 | - * jQuery(element).on('click', _.debounce(sendMail, 300, { | ||
119 | - * 'leading': true, | ||
120 | - * 'trailing': false | ||
121 | - * })); | ||
122 | - * | ||
123 | - * // Ensure `batchLog` is invoked once after 1 second of debounced calls. | ||
124 | - * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 }); | ||
125 | - * var source = new EventSource('/stream'); | ||
126 | - * jQuery(source).on('message', debounced); | ||
127 | - * | ||
128 | - * // Cancel the trailing debounced invocation. | ||
129 | - * jQuery(window).on('popstate', debounced.cancel); | ||
130 | - */ | ||
131 | -function debounce(func, wait, options) { | ||
132 | - var lastArgs, | ||
133 | - lastThis, | ||
134 | - maxWait, | ||
135 | - result, | ||
136 | - timerId, | ||
137 | - lastCallTime, | ||
138 | - lastInvokeTime = 0, | ||
139 | - leading = false, | ||
140 | - maxing = false, | ||
141 | - trailing = true; | ||
142 | - | ||
143 | - if (typeof func != 'function') { | ||
144 | - throw new TypeError(FUNC_ERROR_TEXT); | ||
145 | - } | ||
146 | - wait = toNumber(wait) || 0; | ||
147 | - if (isObject(options)) { | ||
148 | - leading = !!options.leading; | ||
149 | - maxing = 'maxWait' in options; | ||
150 | - maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait; | ||
151 | - trailing = 'trailing' in options ? !!options.trailing : trailing; | ||
152 | - } | ||
153 | - | ||
154 | - function invokeFunc(time) { | ||
155 | - var args = lastArgs, | ||
156 | - thisArg = lastThis; | ||
157 | - | ||
158 | - lastArgs = lastThis = undefined; | ||
159 | - lastInvokeTime = time; | ||
160 | - result = func.apply(thisArg, args); | ||
161 | - return result; | ||
162 | - } | ||
163 | - | ||
164 | - function leadingEdge(time) { | ||
165 | - // Reset any `maxWait` timer. | ||
166 | - lastInvokeTime = time; | ||
167 | - // Start the timer for the trailing edge. | ||
168 | - timerId = setTimeout(timerExpired, wait); | ||
169 | - // Invoke the leading edge. | ||
170 | - return leading ? invokeFunc(time) : result; | ||
171 | - } | ||
172 | - | ||
173 | - function remainingWait(time) { | ||
174 | - var timeSinceLastCall = time - lastCallTime, | ||
175 | - timeSinceLastInvoke = time - lastInvokeTime, | ||
176 | - result = wait - timeSinceLastCall; | ||
177 | - | ||
178 | - return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result; | ||
179 | - } | ||
180 | - | ||
181 | - function shouldInvoke(time) { | ||
182 | - var timeSinceLastCall = time - lastCallTime, | ||
183 | - timeSinceLastInvoke = time - lastInvokeTime; | ||
184 | - | ||
185 | - // Either this is the first call, activity has stopped and we're at the | ||
186 | - // trailing edge, the system time has gone backwards and we're treating | ||
187 | - // it as the trailing edge, or we've hit the `maxWait` limit. | ||
188 | - return (lastCallTime === undefined || (timeSinceLastCall >= wait) || | ||
189 | - (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait)); | ||
190 | - } | ||
191 | - | ||
192 | - function timerExpired() { | ||
193 | - var time = now(); | ||
194 | - if (shouldInvoke(time)) { | ||
195 | - return trailingEdge(time); | ||
196 | - } | ||
197 | - // Restart the timer. | ||
198 | - timerId = setTimeout(timerExpired, remainingWait(time)); | ||
199 | - } | ||
200 | - | ||
201 | - function trailingEdge(time) { | ||
202 | - timerId = undefined; | ||
203 | - | ||
204 | - // Only invoke if we have `lastArgs` which means `func` has been | ||
205 | - // debounced at least once. | ||
206 | - if (trailing && lastArgs) { | ||
207 | - return invokeFunc(time); | ||
208 | - } | ||
209 | - lastArgs = lastThis = undefined; | ||
210 | - return result; | ||
211 | - } | ||
212 | - | ||
213 | - function cancel() { | ||
214 | - if (timerId !== undefined) { | ||
215 | - clearTimeout(timerId); | ||
216 | - } | ||
217 | - lastInvokeTime = 0; | ||
218 | - lastArgs = lastCallTime = lastThis = timerId = undefined; | ||
219 | - } | ||
220 | - | ||
221 | - function flush() { | ||
222 | - return timerId === undefined ? result : trailingEdge(now()); | ||
223 | - } | ||
224 | - | ||
225 | - function debounced() { | ||
226 | - var time = now(), | ||
227 | - isInvoking = shouldInvoke(time); | ||
228 | - | ||
229 | - lastArgs = arguments; | ||
230 | - lastThis = this; | ||
231 | - lastCallTime = time; | ||
232 | - | ||
233 | - if (isInvoking) { | ||
234 | - if (timerId === undefined) { | ||
235 | - return leadingEdge(lastCallTime); | ||
236 | - } | ||
237 | - if (maxing) { | ||
238 | - // Handle invocations in a tight loop. | ||
239 | - timerId = setTimeout(timerExpired, wait); | ||
240 | - return invokeFunc(lastCallTime); | ||
241 | - } | ||
242 | - } | ||
243 | - if (timerId === undefined) { | ||
244 | - timerId = setTimeout(timerExpired, wait); | ||
245 | - } | ||
246 | - return result; | ||
247 | - } | ||
248 | - debounced.cancel = cancel; | ||
249 | - debounced.flush = flush; | ||
250 | - return debounced; | ||
251 | -} | ||
252 | - | ||
253 | -/** | ||
254 | - * Creates a throttled function that only invokes `func` at most once per | ||
255 | - * every `wait` milliseconds. The throttled function comes with a `cancel` | ||
256 | - * method to cancel delayed `func` invocations and a `flush` method to | ||
257 | - * immediately invoke them. Provide `options` to indicate whether `func` | ||
258 | - * should be invoked on the leading and/or trailing edge of the `wait` | ||
259 | - * timeout. The `func` is invoked with the last arguments provided to the | ||
260 | - * throttled function. Subsequent calls to the throttled function return the | ||
261 | - * result of the last `func` invocation. | ||
262 | - * | ||
263 | - * **Note:** If `leading` and `trailing` options are `true`, `func` is | ||
264 | - * invoked on the trailing edge of the timeout only if the throttled function | ||
265 | - * is invoked more than once during the `wait` timeout. | ||
266 | - * | ||
267 | - * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred | ||
268 | - * until to the next tick, similar to `setTimeout` with a timeout of `0`. | ||
269 | - * | ||
270 | - * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/) | ||
271 | - * for details over the differences between `_.throttle` and `_.debounce`. | ||
272 | - * | ||
273 | - * @static | ||
274 | - * @memberOf _ | ||
275 | - * @since 0.1.0 | ||
276 | - * @category Function | ||
277 | - * @param {Function} func The function to throttle. | ||
278 | - * @param {number} [wait=0] The number of milliseconds to throttle invocations to. | ||
279 | - * @param {Object} [options={}] The options object. | ||
280 | - * @param {boolean} [options.leading=true] | ||
281 | - * Specify invoking on the leading edge of the timeout. | ||
282 | - * @param {boolean} [options.trailing=true] | ||
283 | - * Specify invoking on the trailing edge of the timeout. | ||
284 | - * @returns {Function} Returns the new throttled function. | ||
285 | - * @example | ||
286 | - * | ||
287 | - * // Avoid excessively updating the position while scrolling. | ||
288 | - * jQuery(window).on('scroll', _.throttle(updatePosition, 100)); | ||
289 | - * | ||
290 | - * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes. | ||
291 | - * var throttled = _.throttle(renewToken, 300000, { 'trailing': false }); | ||
292 | - * jQuery(element).on('click', throttled); | ||
293 | - * | ||
294 | - * // Cancel the trailing throttled invocation. | ||
295 | - * jQuery(window).on('popstate', throttled.cancel); | ||
296 | - */ | ||
297 | -function throttle(func, wait, options) { | ||
298 | - var leading = true, | ||
299 | - trailing = true; | ||
300 | - | ||
301 | - if (typeof func != 'function') { | ||
302 | - throw new TypeError(FUNC_ERROR_TEXT); | ||
303 | - } | ||
304 | - if (isObject(options)) { | ||
305 | - leading = 'leading' in options ? !!options.leading : leading; | ||
306 | - trailing = 'trailing' in options ? !!options.trailing : trailing; | ||
307 | - } | ||
308 | - return debounce(func, wait, { | ||
309 | - 'leading': leading, | ||
310 | - 'maxWait': wait, | ||
311 | - 'trailing': trailing | ||
312 | - }); | ||
313 | -} | ||
314 | - | ||
315 | -/** | ||
316 | - * Checks if `value` is the | ||
317 | - * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) | ||
318 | - * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) | ||
319 | - * | ||
320 | - * @static | ||
321 | - * @memberOf _ | ||
322 | - * @since 0.1.0 | ||
323 | - * @category Lang | ||
324 | - * @param {*} value The value to check. | ||
325 | - * @returns {boolean} Returns `true` if `value` is an object, else `false`. | ||
326 | - * @example | ||
327 | - * | ||
328 | - * _.isObject({}); | ||
329 | - * // => true | ||
330 | - * | ||
331 | - * _.isObject([1, 2, 3]); | ||
332 | - * // => true | ||
333 | - * | ||
334 | - * _.isObject(_.noop); | ||
335 | - * // => true | ||
336 | - * | ||
337 | - * _.isObject(null); | ||
338 | - * // => false | ||
339 | - */ | ||
340 | -function isObject(value) { | ||
341 | - var type = typeof value; | ||
342 | - return !!value && (type == 'object' || type == 'function'); | ||
343 | -} | ||
344 | - | ||
345 | -/** | ||
346 | - * Checks if `value` is object-like. A value is object-like if it's not `null` | ||
347 | - * and has a `typeof` result of "object". | ||
348 | - * | ||
349 | - * @static | ||
350 | - * @memberOf _ | ||
351 | - * @since 4.0.0 | ||
352 | - * @category Lang | ||
353 | - * @param {*} value The value to check. | ||
354 | - * @returns {boolean} Returns `true` if `value` is object-like, else `false`. | ||
355 | - * @example | ||
356 | - * | ||
357 | - * _.isObjectLike({}); | ||
358 | - * // => true | ||
359 | - * | ||
360 | - * _.isObjectLike([1, 2, 3]); | ||
361 | - * // => true | ||
362 | - * | ||
363 | - * _.isObjectLike(_.noop); | ||
364 | - * // => false | ||
365 | - * | ||
366 | - * _.isObjectLike(null); | ||
367 | - * // => false | ||
368 | - */ | ||
369 | -function isObjectLike(value) { | ||
370 | - return !!value && typeof value == 'object'; | ||
371 | -} | ||
372 | - | ||
373 | -/** | ||
374 | - * Checks if `value` is classified as a `Symbol` primitive or object. | ||
375 | - * | ||
376 | - * @static | ||
377 | - * @memberOf _ | ||
378 | - * @since 4.0.0 | ||
379 | - * @category Lang | ||
380 | - * @param {*} value The value to check. | ||
381 | - * @returns {boolean} Returns `true` if `value` is a symbol, else `false`. | ||
382 | - * @example | ||
383 | - * | ||
384 | - * _.isSymbol(Symbol.iterator); | ||
385 | - * // => true | ||
386 | - * | ||
387 | - * _.isSymbol('abc'); | ||
388 | - * // => false | ||
389 | - */ | ||
390 | -function isSymbol(value) { | ||
391 | - return typeof value == 'symbol' || | ||
392 | - (isObjectLike(value) && objectToString.call(value) == symbolTag); | ||
393 | -} | ||
394 | - | ||
395 | -/** | ||
396 | - * Converts `value` to a number. | ||
397 | - * | ||
398 | - * @static | ||
399 | - * @memberOf _ | ||
400 | - * @since 4.0.0 | ||
401 | - * @category Lang | ||
402 | - * @param {*} value The value to process. | ||
403 | - * @returns {number} Returns the number. | ||
404 | - * @example | ||
405 | - * | ||
406 | - * _.toNumber(3.2); | ||
407 | - * // => 3.2 | ||
408 | - * | ||
409 | - * _.toNumber(Number.MIN_VALUE); | ||
410 | - * // => 5e-324 | ||
411 | - * | ||
412 | - * _.toNumber(Infinity); | ||
413 | - * // => Infinity | ||
414 | - * | ||
415 | - * _.toNumber('3.2'); | ||
416 | - * // => 3.2 | ||
417 | - */ | ||
418 | -function toNumber(value) { | ||
419 | - if (typeof value == 'number') { | ||
420 | - return value; | ||
421 | - } | ||
422 | - if (isSymbol(value)) { | ||
423 | - return NAN; | ||
424 | - } | ||
425 | - if (isObject(value)) { | ||
426 | - var other = typeof value.valueOf == 'function' ? value.valueOf() : value; | ||
427 | - value = isObject(other) ? (other + '') : other; | ||
428 | - } | ||
429 | - if (typeof value != 'string') { | ||
430 | - return value === 0 ? value : +value; | ||
431 | - } | ||
432 | - value = value.replace(reTrim, ''); | ||
433 | - var isBinary = reIsBinary.test(value); | ||
434 | - return (isBinary || reIsOctal.test(value)) | ||
435 | - ? freeParseInt(value.slice(2), isBinary ? 2 : 8) | ||
436 | - : (reIsBadHex.test(value) ? NAN : +value); | ||
437 | -} | ||
438 | - | ||
439 | -module.exports = throttle; |