matsuri-ui 18.0.3-alpha-1765249068881-c6f8403.0 → 18.0.3-alpha-1766239260045-3f82224.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@utils/debounce.js +2 -0
- package/@utils/debounce.js.map +1 -1
- package/AsComponentProps.js.map +1 -1
- package/cjs/@utils/debounce.js +2 -0
- package/cjs/@utils/debounce.js.map +1 -1
- package/cjs/AsComponentProps.js.map +1 -1
- package/esm/@utils/debounce.js +2 -0
- package/esm/@utils/debounce.js.map +1 -1
- package/esm/AsComponentProps.js.map +1 -1
- package/package.json +7 -10
package/@utils/debounce.js
CHANGED
|
@@ -63,6 +63,8 @@ import { isObject } from "./isObject";
|
|
|
63
63
|
*/
|
|
64
64
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
65
|
export function debounce(func, wait, options) {
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
67
|
+
|
|
66
68
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
69
|
var lastArgs;
|
|
68
70
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/@utils/debounce.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debounce.js","names":["isObject","debounce","func","wait","options","lastArgs","lastThis","result","lastCallTime","timerId","lastInvokeTime","useRAF","undefined","window","requestAnimationFrame","TypeError","waitValue","Number","leading","trailing","maxWait","Math","max","invokeFunc","time","args","thisArg","apply","startTimer","pendingFunc","cancelAnimationFrame","setTimeout","cancelTimer","id","clearTimeout","leadingEdge","timerExpired","remainingWait","timeSinceLastCall","timeSinceLastInvoke","timeWaiting","min","shouldInvoke","Date","now","trailingEdge","cancel","flush","pending","debounced","isInvoking","_len","arguments","length","Array","_key"],"sources":["../../../src/@utils/debounce.ts"],"sourcesContent":["import { isObject } from \"./isObject\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface DebouncedFunc<T extends (...args: any[]) => any> {\n /**\n * Call the original function, but applying the debounce rules.\n *\n * If the debounced function can be run immediately, this calls it and returns its return\n * value.\n *\n * Otherwise, it returns the return value of the last invokation, or undefined if the debounced\n * function was not invoked yet.\n */\n (...args: Parameters<T>): ReturnType<T> | undefined;\n\n /**\n * Throw away any pending invokation of the debounced function.\n */\n cancel(): void;\n\n /**\n * If there is a pending invokation of the debounced function, invoke it immediately and return\n * its return value.\n *\n * Otherwise, return the value from the last invokation, or undefined if the debounced function\n * was never invoked.\n */\n flush(): ReturnType<T> | undefined;\n}\n\ninterface DebounceOptions {\n maxWait?: number;\n leading?: boolean;\n trailing?: boolean;\n}\n\ntype TimeoutId = ReturnType<typeof setTimeout>;\n\n/**\n * Creates a debounced function that delays invoking `func` until after `wait`\n * milliseconds have elapsed since the last time the debounced function was\n * invoked, or until the next browser frame is drawn. The debounced function\n * comes with a `cancel` method to cancel delayed `func` invocations and a\n * `flush` method to immediately invoke them. Provide `options` to indicate\n * whether `func` should be invoked on the leading and/or trailing edge of the\n * `wait` timeout. The `func` is invoked with the last arguments provided to the\n * debounced function. Subsequent calls to the debounced function return the\n * result of the last `func` invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the debounced function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * If `wait` is omitted in an environment with `requestAnimationFrame`, `func`\n * invocation will be deferred until the next frame is drawn (typically about\n * 16ms).\n *\n * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)\n * for details over the differences between `debounce` and `throttle`.\n *\n * @param {Function} func The function to debounce.\n * @param {number} [wait=0]\n * The number of milliseconds to delay; if omitted, `requestAnimationFrame` is\n * used (if available).\n * @param {Object} [options={}] The options object.\n * @param {boolean} [options.leading=false]\n * Specify invoking on the leading edge of the timeout.\n * @param {number} [options.maxWait]\n * The maximum time `func` is allowed to be delayed before it's invoked.\n * @param {boolean} [options.trailing=true]\n * Specify invoking on the trailing edge of the timeout.\n * @returns {Function} Returns the new debounced function.\n * @example\n *\n * // Avoid costly calculations while the window size is in flux.\n * window.addEventListener('resize', debounce(calculateLayout, 150))\n *\n * // Invoke `sendMail` when clicked, debouncing subsequent calls.\n * element.addEventListener('click', debounce(sendMail, 300, {\n * 'leading': true,\n * 'trailing': false\n * }))\n *\n * // Ensure `batchLog` is invoked once after 1 second of debounced calls.\n * const debounced = debounce(batchLog, 250, { 'maxWait': 1000 })\n * const source = new EventSource('/stream')\n * source.addEventListener('message', debounced)\n *\n * // Cancel the trailing debounced invocation.\n * window.addEventListener('popstate', debounced.cancel)\n *\n * // Check for pending invocations.\n * const status = debounced.pending() ? \"Pending...\" : \"Ready\"\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function debounce<T extends (...args: any) => any>(\n func: T,\n wait?: number,\n options?: DebounceOptions,\n): DebouncedFunc<T> {\n type Result = ReturnType<T> | undefined;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let lastArgs: any;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let lastThis: any;\n let result: Result;\n let lastCallTime: number | undefined;\n let timerId: TimeoutId | undefined;\n let lastInvokeTime = 0;\n\n // Bypass `requestAnimationFrame` by explicitly setting `wait=0`.\n const useRAF =\n wait === undefined &&\n typeof window !== \"undefined\" &&\n typeof window.requestAnimationFrame === \"function\";\n\n if (typeof func !== \"function\") {\n throw new TypeError(\"Expected a function\");\n }\n\n const waitValue = Number(wait) || 0;\n\n let leading = false;\n let trailing = true;\n let maxWait: number | null = null;\n if (isObject(options)) {\n leading = !!options.leading;\n maxWait =\n \"maxWait\" in options\n ? Math.max(Number(options.maxWait) || 0, waitValue)\n : maxWait;\n trailing = \"trailing\" in options ? !!options.trailing : trailing;\n }\n\n function invokeFunc(time: number): Result {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const args = lastArgs;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const thisArg = lastThis;\n\n lastArgs = lastThis = undefined;\n lastInvokeTime = time;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument\n result = func.apply(thisArg, args);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result;\n }\n\n function startTimer(pendingFunc: () => Result, wait: number): TimeoutId {\n if (useRAF && typeof timerId === \"number\") {\n window.cancelAnimationFrame(timerId);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-return\n return window.requestAnimationFrame(pendingFunc) as any;\n }\n return setTimeout(pendingFunc, wait);\n }\n\n function cancelTimer(id: TimeoutId): void {\n if (useRAF && typeof id === \"number\") {\n window.cancelAnimationFrame(id);\n }\n clearTimeout(id);\n }\n\n function leadingEdge(time: number): Result {\n // Reset any `maxWait` timer.\n lastInvokeTime = time;\n // Start the timer for the trailing edge.\n timerId = startTimer(timerExpired, waitValue);\n // Invoke the leading edge.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return leading ? invokeFunc(time) : result;\n }\n\n function remainingWait(time: number): number {\n if (lastCallTime === undefined) return 0;\n\n const timeSinceLastCall = time - lastCallTime;\n const timeSinceLastInvoke = time - lastInvokeTime;\n const timeWaiting = waitValue - timeSinceLastCall;\n\n return maxWait !== null\n ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke)\n : timeWaiting;\n }\n\n function shouldInvoke(time: number): boolean {\n if (lastCallTime === undefined) return true;\n\n const timeSinceLastCall = time - lastCallTime;\n const timeSinceLastInvoke = time - lastInvokeTime;\n\n // Either this is the first call, activity has stopped and we're at the\n // trailing edge, the system time has gone backwards and we're treating\n // it as the trailing edge, or we've hit the `maxWait` limit.\n return (\n timeSinceLastCall >= waitValue ||\n timeSinceLastCall < 0 ||\n (maxWait !== null && timeSinceLastInvoke >= maxWait)\n );\n }\n\n function timerExpired(): Result {\n const time = Date.now();\n if (shouldInvoke(time)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return trailingEdge(time);\n }\n\n // Restart the timer.\n timerId = startTimer(timerExpired, remainingWait(time));\n\n return;\n }\n\n function trailingEdge(time: number): Result {\n timerId = undefined;\n\n // Only invoke if we have `lastArgs` which means `func` has been\n // debounced at least once.\n if (trailing && lastArgs) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return invokeFunc(time);\n }\n lastArgs = lastThis = undefined;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result;\n }\n\n function cancel(): void {\n if (timerId !== undefined) {\n cancelTimer(timerId);\n }\n lastInvokeTime = 0;\n lastArgs = lastCallTime = lastThis = timerId = undefined;\n }\n\n function flush(): Result {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return timerId === undefined ? result : trailingEdge(Date.now());\n }\n\n function pending(): boolean {\n return timerId !== undefined;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n function debounced(this: any, ...args: any[]): Result {\n const time = Date.now();\n const isInvoking = shouldInvoke(time);\n\n lastArgs = args;\n // eslint-disable-next-line @typescript-eslint/no-this-alias,@typescript-eslint/no-unsafe-assignment\n lastThis = this;\n lastCallTime = time;\n\n if (isInvoking) {\n if (timerId === undefined) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return leadingEdge(lastCallTime);\n }\n if (maxWait !== null) {\n // Handle invocations in a tight loop.\n timerId = startTimer(timerExpired, waitValue);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return invokeFunc(lastCallTime);\n }\n }\n timerId ??= startTimer(timerExpired, waitValue);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result;\n }\n\n debounced.cancel = cancel;\n debounced.flush = flush;\n debounced.pending = pending;\n\n return debounced;\n}\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,YAAY;;AAErC;;AAoCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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GAAGsC,YAAY,CAACF,IAAI,CAACC,GAAG,CAAC,CAAC,CAAC;EAClE;EAEA,SAASI,OAAOA,CAAA,EAAY;IAC1B,OAAOvC,OAAO,KAAKG,SAAS;EAC9B;;EAEA;EACA,SAASqC,SAASA,CAAA,EAAoC;IACpD,IAAMzB,IAAI,GAAGmB,IAAI,CAACC,GAAG,CAAC,CAAC;IACvB,IAAMM,UAAU,GAAGR,YAAY,CAAClB,IAAI,CAAC;IAAC,SAAA2B,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAFP5B,IAAI,OAAA6B,KAAA,CAAAH,IAAA,GAAAI,IAAA,MAAAA,IAAA,GAAAJ,IAAA,EAAAI,IAAA;MAAJ9B,IAAI,CAAA8B,IAAA,IAAAH,SAAA,CAAAG,IAAA;IAAA;IAInClD,QAAQ,GAAGoB,IAAI;IACf;IACAnB,QAAQ,GAAG,IAAI;IACfE,YAAY,GAAGgB,IAAI;IAEnB,IAAI0B,UAAU,EAAE;MACd,IAAIzC,OAAO,KAAKG,SAAS,EAAE;QACzB;QACA,OAAOuB,WAAW,CAAC3B,YAAY,CAAC;MAClC;MACA,IAAIY,OAAO,KAAK,IAAI,EAAE;QACpB;QACAX,OAAO,GAAGmB,UAAU,CAACQ,YAAY,EAAEpB,SAAS,CAAC;QAC7C;QACA,OAAOO,UAAU,CAACf,YAAY,CAAC;MACjC;IACF;IACAC,OAAO,WAAPA,OAAO,GAAPA,OAAO,GAAKmB,UAAU,CAACQ,YAAY,EAAEpB,SAAS,CAAC;IAC/C;IACA,OAAOT,MAAM;EACf;EAEA0C,SAAS,CAACH,MAAM,GAAGA,MAAM;EACzBG,SAAS,CAACF,KAAK,GAAGA,KAAK;EACvBE,SAAS,CAACD,OAAO,GAAGA,OAAO;EAE3B,OAAOC,SAAS;AAClB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"debounce.js","names":["isObject","debounce","func","wait","options","lastArgs","lastThis","result","lastCallTime","timerId","lastInvokeTime","useRAF","undefined","window","requestAnimationFrame","TypeError","waitValue","Number","leading","trailing","maxWait","Math","max","invokeFunc","time","args","thisArg","apply","startTimer","pendingFunc","cancelAnimationFrame","setTimeout","cancelTimer","id","clearTimeout","leadingEdge","timerExpired","remainingWait","timeSinceLastCall","timeSinceLastInvoke","timeWaiting","min","shouldInvoke","Date","now","trailingEdge","cancel","flush","pending","debounced","isInvoking","_len","arguments","length","Array","_key"],"sources":["../../../src/@utils/debounce.ts"],"sourcesContent":["import { isObject } from \"./isObject\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface DebouncedFunc<T extends (...args: any[]) => any> {\n /**\n * Call the original function, but applying the debounce rules.\n *\n * If the debounced function can be run immediately, this calls it and returns its return\n * value.\n *\n * Otherwise, it returns the return value of the last invokation, or undefined if the debounced\n * function was not invoked yet.\n */\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n (...args: Parameters<T>): ReturnType<T> | undefined;\n\n /**\n * Throw away any pending invokation of the debounced function.\n */\n cancel(): void;\n\n /**\n * If there is a pending invokation of the debounced function, invoke it immediately and return\n * its return value.\n *\n * Otherwise, return the value from the last invokation, or undefined if the debounced function\n * was never invoked.\n */\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n flush(): ReturnType<T> | undefined;\n}\n\ninterface DebounceOptions {\n maxWait?: number;\n leading?: boolean;\n trailing?: boolean;\n}\n\ntype TimeoutId = ReturnType<typeof setTimeout>;\n\n/**\n * Creates a debounced function that delays invoking `func` until after `wait`\n * milliseconds have elapsed since the last time the debounced function was\n * invoked, or until the next browser frame is drawn. The debounced function\n * comes with a `cancel` method to cancel delayed `func` invocations and a\n * `flush` method to immediately invoke them. Provide `options` to indicate\n * whether `func` should be invoked on the leading and/or trailing edge of the\n * `wait` timeout. The `func` is invoked with the last arguments provided to the\n * debounced function. Subsequent calls to the debounced function return the\n * result of the last `func` invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the debounced function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * If `wait` is omitted in an environment with `requestAnimationFrame`, `func`\n * invocation will be deferred until the next frame is drawn (typically about\n * 16ms).\n *\n * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)\n * for details over the differences between `debounce` and `throttle`.\n *\n * @param {Function} func The function to debounce.\n * @param {number} [wait=0]\n * The number of milliseconds to delay; if omitted, `requestAnimationFrame` is\n * used (if available).\n * @param {Object} [options={}] The options object.\n * @param {boolean} [options.leading=false]\n * Specify invoking on the leading edge of the timeout.\n * @param {number} [options.maxWait]\n * The maximum time `func` is allowed to be delayed before it's invoked.\n * @param {boolean} [options.trailing=true]\n * Specify invoking on the trailing edge of the timeout.\n * @returns {Function} Returns the new debounced function.\n * @example\n *\n * // Avoid costly calculations while the window size is in flux.\n * window.addEventListener('resize', debounce(calculateLayout, 150))\n *\n * // Invoke `sendMail` when clicked, debouncing subsequent calls.\n * element.addEventListener('click', debounce(sendMail, 300, {\n * 'leading': true,\n * 'trailing': false\n * }))\n *\n * // Ensure `batchLog` is invoked once after 1 second of debounced calls.\n * const debounced = debounce(batchLog, 250, { 'maxWait': 1000 })\n * const source = new EventSource('/stream')\n * source.addEventListener('message', debounced)\n *\n * // Cancel the trailing debounced invocation.\n * window.addEventListener('popstate', debounced.cancel)\n *\n * // Check for pending invocations.\n * const status = debounced.pending() ? \"Pending...\" : \"Ready\"\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function debounce<T extends (...args: any) => any>(\n func: T,\n wait?: number,\n options?: DebounceOptions,\n): DebouncedFunc<T> {\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n type Result = ReturnType<T> | undefined;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let lastArgs: any;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let lastThis: any;\n let result: Result;\n let lastCallTime: number | undefined;\n let timerId: TimeoutId | undefined;\n let lastInvokeTime = 0;\n\n // Bypass `requestAnimationFrame` by explicitly setting `wait=0`.\n const useRAF =\n wait === undefined &&\n typeof window !== \"undefined\" &&\n typeof window.requestAnimationFrame === \"function\";\n\n if (typeof func !== \"function\") {\n throw new TypeError(\"Expected a function\");\n }\n\n const waitValue = Number(wait) || 0;\n\n let leading = false;\n let trailing = true;\n let maxWait: number | null = null;\n if (isObject(options)) {\n leading = !!options.leading;\n maxWait =\n \"maxWait\" in options\n ? Math.max(Number(options.maxWait) || 0, waitValue)\n : maxWait;\n trailing = \"trailing\" in options ? !!options.trailing : trailing;\n }\n\n function invokeFunc(time: number): Result {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const args = lastArgs;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const thisArg = lastThis;\n\n lastArgs = lastThis = undefined;\n lastInvokeTime = time;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument\n result = func.apply(thisArg, args);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result;\n }\n\n function startTimer(pendingFunc: () => Result, wait: number): TimeoutId {\n if (useRAF && typeof timerId === \"number\") {\n window.cancelAnimationFrame(timerId);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-return\n return window.requestAnimationFrame(pendingFunc) as any;\n }\n return setTimeout(pendingFunc, wait);\n }\n\n function cancelTimer(id: TimeoutId): void {\n if (useRAF && typeof id === \"number\") {\n window.cancelAnimationFrame(id);\n }\n clearTimeout(id);\n }\n\n function leadingEdge(time: number): Result {\n // Reset any `maxWait` timer.\n lastInvokeTime = time;\n // Start the timer for the trailing edge.\n timerId = startTimer(timerExpired, waitValue);\n // Invoke the leading edge.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return leading ? invokeFunc(time) : result;\n }\n\n function remainingWait(time: number): number {\n if (lastCallTime === undefined) return 0;\n\n const timeSinceLastCall = time - lastCallTime;\n const timeSinceLastInvoke = time - lastInvokeTime;\n const timeWaiting = waitValue - timeSinceLastCall;\n\n return maxWait !== null\n ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke)\n : timeWaiting;\n }\n\n function shouldInvoke(time: number): boolean {\n if (lastCallTime === undefined) return true;\n\n const timeSinceLastCall = time - lastCallTime;\n const timeSinceLastInvoke = time - lastInvokeTime;\n\n // Either this is the first call, activity has stopped and we're at the\n // trailing edge, the system time has gone backwards and we're treating\n // it as the trailing edge, or we've hit the `maxWait` limit.\n return (\n timeSinceLastCall >= waitValue ||\n timeSinceLastCall < 0 ||\n (maxWait !== null && timeSinceLastInvoke >= maxWait)\n );\n }\n\n function timerExpired(): Result {\n const time = Date.now();\n if (shouldInvoke(time)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return trailingEdge(time);\n }\n\n // Restart the timer.\n timerId = startTimer(timerExpired, remainingWait(time));\n\n return;\n }\n\n function trailingEdge(time: number): Result {\n timerId = undefined;\n\n // Only invoke if we have `lastArgs` which means `func` has been\n // debounced at least once.\n if (trailing && lastArgs) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return invokeFunc(time);\n }\n lastArgs = lastThis = undefined;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result;\n }\n\n function cancel(): void {\n if (timerId !== undefined) {\n cancelTimer(timerId);\n }\n lastInvokeTime = 0;\n lastArgs = lastCallTime = lastThis = timerId = undefined;\n }\n\n function flush(): Result {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return timerId === undefined ? result : trailingEdge(Date.now());\n }\n\n function pending(): boolean {\n return timerId !== undefined;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n function debounced(this: any, ...args: any[]): Result {\n const time = Date.now();\n const isInvoking = shouldInvoke(time);\n\n lastArgs = args;\n // eslint-disable-next-line @typescript-eslint/no-this-alias,@typescript-eslint/no-unsafe-assignment\n lastThis = this;\n lastCallTime = time;\n\n if (isInvoking) {\n if (timerId === undefined) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return leadingEdge(lastCallTime);\n }\n if (maxWait !== null) {\n // Handle invocations in a tight loop.\n timerId = startTimer(timerExpired, waitValue);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return invokeFunc(lastCallTime);\n }\n }\n timerId ??= startTimer(timerExpired, waitValue);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result;\n }\n\n debounced.cancel = cancel;\n debounced.flush = flush;\n debounced.pending = pending;\n\n return debounced;\n}\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,YAAY;;AAErC;;AAsCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CACtBC,IAAO,EACPC,IAAa,EACbC,OAAyB,EACP;EAClB;;EAGA;EACA,IAAIC,QAAa;EACjB;EACA,IAAIC,QAAa;EACjB,IAAIC,MAAc;EAClB,IAAIC,YAAgC;EACpC,IAAIC,OAA8B;EAClC,IAAIC,cAAc,GAAG,CAAC;;EAEtB;EACA,IAAMC,MAAM,GACVR,IAAI,KAAKS,SAAS,IAClB,OAAOC,MAAM,KAAK,WAAW,IAC7B,OAAOA,MAAM,CAACC,qBAAqB,KAAK,UAAU;EAEpD,IAAI,OAAOZ,IAAI,KAAK,UAAU,EAAE;IAC9B,MAAM,IAAIa,SAAS,CAAC,qBAAqB,CAAC;EAC5C;EAEA,IAAMC,SAAS,GAAGC,MAAM,CAACd,IAAI,CAAC,IAAI,CAAC;EAEnC,IAAIe,OAAO,GAA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AAU,CAACQ,YAAY,EAAEpB,SAAS,CAAC;QAC7C;QACA,OAAOO,UAAU,CAACf,YAAY,CAAC;MACjC;IACF;IACAC,OAAO,WAAPA,OAAO,GAAPA,OAAO,GAAKmB,UAAU,CAACQ,YAAY,EAAEpB,SAAS,CAAC;IAC/C;IACA,OAAOT,MAAM;EACf;EAEA0C,SAAS,CAACH,MAAM,GAAGA,MAAM;EACzBG,SAAS,CAACF,KAAK,GAAGA,KAAK;EACvBE,SAAS,CAACD,OAAO,GAAGA,OAAO;EAE3B,OAAOC,SAAS;AAClB","ignoreList":[]}
|
package/AsComponentProps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsComponentProps.js","names":[],"sources":["../../src/AsComponentProps.ts"],"sourcesContent":["import { Dict } from \"./@types/Dict\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type As<Props = any> = React.ElementType<Props>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type DistributiveOmit<T, K extends keyof any> = T extends any\n ? Omit<T, K>\n : never;\n\nexport type AsComponentProp<C extends As, Props = Dict> = Props & {\n as?: C;\n} & DistributiveOmit<React.ComponentPropsWithoutRef<C>, keyof Props | \"as\">;\n\nexport type AsRef<C extends React.ElementType> =\n React.ComponentPropsWithRef<C>[\"ref\"];\n\nexport type MergeWithAs<\n ComponentProps extends object,\n AsProps extends object,\n AdditionalProps extends object = Dict,\n AsComponent extends As = As,\n> = AdditionalProps &\n Omit<ComponentProps, keyof AdditionalProps | \"as\"> &\n Omit<AsProps, keyof ComponentProps | keyof AdditionalProps | \"as\"> & {\n as?: AsComponent;\n };\n\nexport type ComponentWithAs<\n Component extends As,\n Props extends object = Dict,\n> = <AsComponent extends As = Component>(\n props: MergeWithAs<\n React.ComponentProps<Component>,\n React.ComponentProps<AsComponent>,\n Props,\n AsComponent\n > & {\n ref?: AsRef<AsComponent>;\n },\n) => React.JSX.Element | null;\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"AsComponentProps.js","names":[],"sources":["../../src/AsComponentProps.ts"],"sourcesContent":["import { Dict } from \"./@types/Dict\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type As<Props = any> = React.ElementType<Props>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type DistributiveOmit<T, K extends keyof any> = T extends any\n ? Omit<T, K>\n : never;\n\n// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\nexport type AsComponentProp<C extends As, Props = Dict> = Props & {\n as?: C;\n} & DistributiveOmit<React.ComponentPropsWithoutRef<C>, keyof Props | \"as\">;\n\nexport type AsRef<C extends React.ElementType> =\n React.ComponentPropsWithRef<C>[\"ref\"];\n\nexport type MergeWithAs<\n ComponentProps extends object,\n AsProps extends object,\n AdditionalProps extends object = Dict,\n AsComponent extends As = As,\n> = AdditionalProps &\n Omit<ComponentProps, keyof AdditionalProps | \"as\"> &\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n Omit<AsProps, keyof ComponentProps | keyof AdditionalProps | \"as\"> & {\n as?: AsComponent;\n };\n\nexport type ComponentWithAs<\n Component extends As,\n Props extends object = Dict,\n> = <AsComponent extends As = Component>(\n props: MergeWithAs<\n React.ComponentProps<Component>,\n React.ComponentProps<AsComponent>,\n Props,\n AsComponent\n > & {\n ref?: AsRef<AsComponent>;\n },\n) => React.JSX.Element | null;\n"],"mappings":"","ignoreList":[]}
|
package/cjs/@utils/debounce.js
CHANGED
|
@@ -66,6 +66,8 @@ var _isObject = require("./isObject");
|
|
|
66
66
|
*/
|
|
67
67
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
68
68
|
function debounce(func, wait, options) {
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
70
|
+
|
|
69
71
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
72
|
let lastArgs;
|
|
71
73
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debounce.js","names":["_isObject","require","debounce","func","wait","options","lastArgs","lastThis","result","lastCallTime","timerId","lastInvokeTime","useRAF","undefined","window","requestAnimationFrame","TypeError","waitValue","Number","leading","trailing","maxWait","isObject","Math","max","invokeFunc","time","args","thisArg","apply","startTimer","pendingFunc","cancelAnimationFrame","setTimeout","cancelTimer","id","clearTimeout","leadingEdge","timerExpired","remainingWait","timeSinceLastCall","timeSinceLastInvoke","timeWaiting","min","shouldInvoke","Date","now","trailingEdge","cancel","flush","pending","debounced","isInvoking"],"sources":["../../../src/@utils/debounce.ts"],"sourcesContent":["import { isObject } from \"./isObject\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface DebouncedFunc<T extends (...args: any[]) => any> {\n /**\n * Call the original function, but applying the debounce rules.\n *\n * If the debounced function can be run immediately, this calls it and returns its return\n * value.\n *\n * Otherwise, it returns the return value of the last invokation, or undefined if the debounced\n * function was not invoked yet.\n */\n (...args: Parameters<T>): ReturnType<T> | undefined;\n\n /**\n * Throw away any pending invokation of the debounced function.\n */\n cancel(): void;\n\n /**\n * If there is a pending invokation of the debounced function, invoke it immediately and return\n * its return value.\n *\n * Otherwise, return the value from the last invokation, or undefined if the debounced function\n * was never invoked.\n */\n flush(): ReturnType<T> | undefined;\n}\n\ninterface DebounceOptions {\n maxWait?: number;\n leading?: boolean;\n trailing?: boolean;\n}\n\ntype TimeoutId = ReturnType<typeof setTimeout>;\n\n/**\n * Creates a debounced function that delays invoking `func` until after `wait`\n * milliseconds have elapsed since the last time the debounced function was\n * invoked, or until the next browser frame is drawn. The debounced function\n * comes with a `cancel` method to cancel delayed `func` invocations and a\n * `flush` method to immediately invoke them. Provide `options` to indicate\n * whether `func` should be invoked on the leading and/or trailing edge of the\n * `wait` timeout. The `func` is invoked with the last arguments provided to the\n * debounced function. Subsequent calls to the debounced function return the\n * result of the last `func` invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the debounced function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * If `wait` is omitted in an environment with `requestAnimationFrame`, `func`\n * invocation will be deferred until the next frame is drawn (typically about\n * 16ms).\n *\n * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)\n * for details over the differences between `debounce` and `throttle`.\n *\n * @param {Function} func The function to debounce.\n * @param {number} [wait=0]\n * The number of milliseconds to delay; if omitted, `requestAnimationFrame` is\n * used (if available).\n * @param {Object} [options={}] The options object.\n * @param {boolean} [options.leading=false]\n * Specify invoking on the leading edge of the timeout.\n * @param {number} [options.maxWait]\n * The maximum time `func` is allowed to be delayed before it's invoked.\n * @param {boolean} [options.trailing=true]\n * Specify invoking on the trailing edge of the timeout.\n * @returns {Function} Returns the new debounced function.\n * @example\n *\n * // Avoid costly calculations while the window size is in flux.\n * window.addEventListener('resize', debounce(calculateLayout, 150))\n *\n * // Invoke `sendMail` when clicked, debouncing subsequent calls.\n * element.addEventListener('click', debounce(sendMail, 300, {\n * 'leading': true,\n * 'trailing': false\n * }))\n *\n * // Ensure `batchLog` is invoked once after 1 second of debounced calls.\n * const debounced = debounce(batchLog, 250, { 'maxWait': 1000 })\n * const source = new EventSource('/stream')\n * source.addEventListener('message', debounced)\n *\n * // Cancel the trailing debounced invocation.\n * window.addEventListener('popstate', debounced.cancel)\n *\n * // Check for pending invocations.\n * const status = debounced.pending() ? \"Pending...\" : \"Ready\"\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function debounce<T extends (...args: any) => any>(\n func: T,\n wait?: number,\n options?: DebounceOptions,\n): DebouncedFunc<T> {\n type Result = ReturnType<T> | undefined;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let lastArgs: any;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let lastThis: any;\n let result: Result;\n let lastCallTime: number | undefined;\n let timerId: TimeoutId | undefined;\n let lastInvokeTime = 0;\n\n // Bypass `requestAnimationFrame` by explicitly setting `wait=0`.\n const useRAF =\n wait === undefined &&\n typeof window !== \"undefined\" &&\n typeof window.requestAnimationFrame === \"function\";\n\n if (typeof func !== \"function\") {\n throw new TypeError(\"Expected a function\");\n }\n\n const waitValue = Number(wait) || 0;\n\n let leading = false;\n let trailing = true;\n let maxWait: number | null = null;\n if (isObject(options)) {\n leading = !!options.leading;\n maxWait =\n \"maxWait\" in options\n ? Math.max(Number(options.maxWait) || 0, waitValue)\n : maxWait;\n trailing = \"trailing\" in options ? !!options.trailing : trailing;\n }\n\n function invokeFunc(time: number): Result {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const args = lastArgs;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const thisArg = lastThis;\n\n lastArgs = lastThis = undefined;\n lastInvokeTime = time;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument\n result = func.apply(thisArg, args);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result;\n }\n\n function startTimer(pendingFunc: () => Result, wait: number): TimeoutId {\n if (useRAF && typeof timerId === \"number\") {\n window.cancelAnimationFrame(timerId);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-return\n return window.requestAnimationFrame(pendingFunc) as any;\n }\n return setTimeout(pendingFunc, wait);\n }\n\n function cancelTimer(id: TimeoutId): void {\n if (useRAF && typeof id === \"number\") {\n window.cancelAnimationFrame(id);\n }\n clearTimeout(id);\n }\n\n function leadingEdge(time: number): Result {\n // Reset any `maxWait` timer.\n lastInvokeTime = time;\n // Start the timer for the trailing edge.\n timerId = startTimer(timerExpired, waitValue);\n // Invoke the leading edge.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return leading ? invokeFunc(time) : result;\n }\n\n function remainingWait(time: number): number {\n if (lastCallTime === undefined) return 0;\n\n const timeSinceLastCall = time - lastCallTime;\n const timeSinceLastInvoke = time - lastInvokeTime;\n const timeWaiting = waitValue - timeSinceLastCall;\n\n return maxWait !== null\n ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke)\n : timeWaiting;\n }\n\n function shouldInvoke(time: number): boolean {\n if (lastCallTime === undefined) return true;\n\n const timeSinceLastCall = time - lastCallTime;\n const timeSinceLastInvoke = time - lastInvokeTime;\n\n // Either this is the first call, activity has stopped and we're at the\n // trailing edge, the system time has gone backwards and we're treating\n // it as the trailing edge, or we've hit the `maxWait` limit.\n return (\n timeSinceLastCall >= waitValue ||\n timeSinceLastCall < 0 ||\n (maxWait !== null && timeSinceLastInvoke >= maxWait)\n );\n }\n\n function timerExpired(): Result {\n const time = Date.now();\n if (shouldInvoke(time)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return trailingEdge(time);\n }\n\n // Restart the timer.\n timerId = startTimer(timerExpired, remainingWait(time));\n\n return;\n }\n\n function trailingEdge(time: number): Result {\n timerId = undefined;\n\n // Only invoke if we have `lastArgs` which means `func` has been\n // debounced at least once.\n if (trailing && lastArgs) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return invokeFunc(time);\n }\n lastArgs = lastThis = undefined;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result;\n }\n\n function cancel(): void {\n if (timerId !== undefined) {\n cancelTimer(timerId);\n }\n lastInvokeTime = 0;\n lastArgs = lastCallTime = lastThis = timerId = undefined;\n }\n\n function flush(): Result {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return timerId === undefined ? result : trailingEdge(Date.now());\n }\n\n function pending(): boolean {\n return timerId !== undefined;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n function debounced(this: any, ...args: any[]): Result {\n const time = Date.now();\n const isInvoking = shouldInvoke(time);\n\n lastArgs = args;\n // eslint-disable-next-line @typescript-eslint/no-this-alias,@typescript-eslint/no-unsafe-assignment\n lastThis = this;\n lastCallTime = time;\n\n if (isInvoking) {\n if (timerId === undefined) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return leadingEdge(lastCallTime);\n }\n if (maxWait !== null) {\n // Handle invocations in a tight loop.\n timerId = startTimer(timerExpired, waitValue);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return invokeFunc(lastCallTime);\n }\n }\n timerId ??= startTimer(timerExpired, waitValue);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result;\n }\n\n debounced.cancel = cancel;\n debounced.flush = flush;\n debounced.pending = pending;\n\n return debounced;\n}\n"],"mappings":";;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAEA;;AAoCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,QAAQA,CACtBC,IAAO,EACPC,IAAa,EACbC,OAAyB,EACP;EAGlB;EACA,IAAIC,QAAa;EACjB;EACA,IAAIC,QAAa;EACjB,IAAIC,MAAc;EAClB,IAAIC,YAAgC;EACpC,IAAIC,OAA8B;EAClC,IAAIC,cAAc,GAAG,CAAC;;EAEtB;EACA,MAAMC,MAAM,GACVR,IAAI,KAAKS,SAAS,IAClB,OAAOC,MAAM,KAAK,WAAW,IAC7B,OAAOA,MAAM,CAACC,qBAAqB,KAAK,UAAU;EAEpD,IAAI,OAAOZ,IAAI,KAAK,UAAU,EAAE;IAC9B,MAAM,IAAIa,SAAS,CAAC,qBAAqB,CAAC;EAC5C;EAEA,MAAMC,SAAS,GAAGC,MAAM,CAACd,IAAI,CAAC,IAAI,CAAC;EAEnC,IAAIe,OAAO,GAAG,K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EA2C,SAAS,CAACH,MAAM,GAAGA,MAAM;EACzBG,SAAS,CAACF,KAAK,GAAGA,KAAK;EACvBE,SAAS,CAACD,OAAO,GAAGA,OAAO;EAE3B,OAAOC,SAAS;AAClB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"debounce.js","names":["_isObject","require","debounce","func","wait","options","lastArgs","lastThis","result","lastCallTime","timerId","lastInvokeTime","useRAF","undefined","window","requestAnimationFrame","TypeError","waitValue","Number","leading","trailing","maxWait","isObject","Math","max","invokeFunc","time","args","thisArg","apply","startTimer","pendingFunc","cancelAnimationFrame","setTimeout","cancelTimer","id","clearTimeout","leadingEdge","timerExpired","remainingWait","timeSinceLastCall","timeSinceLastInvoke","timeWaiting","min","shouldInvoke","Date","now","trailingEdge","cancel","flush","pending","debounced","isInvoking"],"sources":["../../../src/@utils/debounce.ts"],"sourcesContent":["import { isObject } from \"./isObject\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface DebouncedFunc<T extends (...args: any[]) => any> {\n /**\n * Call the original function, but applying the debounce rules.\n *\n * If the debounced function can be run immediately, this calls it and returns its return\n * value.\n *\n * Otherwise, it returns the return value of the last invokation, or undefined if the debounced\n * function was not invoked yet.\n */\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n (...args: Parameters<T>): ReturnType<T> | undefined;\n\n /**\n * Throw away any pending invokation of the debounced function.\n */\n cancel(): void;\n\n /**\n * If there is a pending invokation of the debounced function, invoke it immediately and return\n * its return value.\n *\n * Otherwise, return the value from the last invokation, or undefined if the debounced function\n * was never invoked.\n */\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n flush(): ReturnType<T> | undefined;\n}\n\ninterface DebounceOptions {\n maxWait?: number;\n leading?: boolean;\n trailing?: boolean;\n}\n\ntype TimeoutId = ReturnType<typeof setTimeout>;\n\n/**\n * Creates a debounced function that delays invoking `func` until after `wait`\n * milliseconds have elapsed since the last time the debounced function was\n * invoked, or until the next browser frame is drawn. The debounced function\n * comes with a `cancel` method to cancel delayed `func` invocations and a\n * `flush` method to immediately invoke them. Provide `options` to indicate\n * whether `func` should be invoked on the leading and/or trailing edge of the\n * `wait` timeout. The `func` is invoked with the last arguments provided to the\n * debounced function. Subsequent calls to the debounced function return the\n * result of the last `func` invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the debounced function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * If `wait` is omitted in an environment with `requestAnimationFrame`, `func`\n * invocation will be deferred until the next frame is drawn (typically about\n * 16ms).\n *\n * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)\n * for details over the differences between `debounce` and `throttle`.\n *\n * @param {Function} func The function to debounce.\n * @param {number} [wait=0]\n * The number of milliseconds to delay; if omitted, `requestAnimationFrame` is\n * used (if available).\n * @param {Object} [options={}] The options object.\n * @param {boolean} [options.leading=false]\n * Specify invoking on the leading edge of the timeout.\n * @param {number} [options.maxWait]\n * The maximum time `func` is allowed to be delayed before it's invoked.\n * @param {boolean} [options.trailing=true]\n * Specify invoking on the trailing edge of the timeout.\n * @returns {Function} Returns the new debounced function.\n * @example\n *\n * // Avoid costly calculations while the window size is in flux.\n * window.addEventListener('resize', debounce(calculateLayout, 150))\n *\n * // Invoke `sendMail` when clicked, debouncing subsequent calls.\n * element.addEventListener('click', debounce(sendMail, 300, {\n * 'leading': true,\n * 'trailing': false\n * }))\n *\n * // Ensure `batchLog` is invoked once after 1 second of debounced calls.\n * const debounced = debounce(batchLog, 250, { 'maxWait': 1000 })\n * const source = new EventSource('/stream')\n * source.addEventListener('message', debounced)\n *\n * // Cancel the trailing debounced invocation.\n * window.addEventListener('popstate', debounced.cancel)\n *\n * // Check for pending invocations.\n * const status = debounced.pending() ? \"Pending...\" : \"Ready\"\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function debounce<T extends (...args: any) => any>(\n func: T,\n wait?: number,\n options?: DebounceOptions,\n): DebouncedFunc<T> {\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n type Result = ReturnType<T> | undefined;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let lastArgs: any;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let lastThis: any;\n let result: Result;\n let lastCallTime: number | undefined;\n let timerId: TimeoutId | undefined;\n let lastInvokeTime = 0;\n\n // Bypass `requestAnimationFrame` by explicitly setting `wait=0`.\n const useRAF =\n wait === undefined &&\n typeof window !== \"undefined\" &&\n typeof window.requestAnimationFrame === \"function\";\n\n if (typeof func !== \"function\") {\n throw new TypeError(\"Expected a function\");\n }\n\n const waitValue = Number(wait) || 0;\n\n let leading = false;\n let trailing = true;\n let maxWait: number | null = null;\n if (isObject(options)) {\n leading = !!options.leading;\n maxWait =\n \"maxWait\" in options\n ? Math.max(Number(options.maxWait) || 0, waitValue)\n : maxWait;\n trailing = \"trailing\" in options ? !!options.trailing : trailing;\n }\n\n function invokeFunc(time: number): Result {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const args = lastArgs;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const thisArg = lastThis;\n\n lastArgs = lastThis = undefined;\n lastInvokeTime = time;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument\n result = func.apply(thisArg, args);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result;\n }\n\n function startTimer(pendingFunc: () => Result, wait: number): TimeoutId {\n if (useRAF && typeof timerId === \"number\") {\n window.cancelAnimationFrame(timerId);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-return\n return window.requestAnimationFrame(pendingFunc) as any;\n }\n return setTimeout(pendingFunc, wait);\n }\n\n function cancelTimer(id: TimeoutId): void {\n if (useRAF && typeof id === \"number\") {\n window.cancelAnimationFrame(id);\n }\n clearTimeout(id);\n }\n\n function leadingEdge(time: number): Result {\n // Reset any `maxWait` timer.\n lastInvokeTime = time;\n // Start the timer for the trailing edge.\n timerId = startTimer(timerExpired, waitValue);\n // Invoke the leading edge.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return leading ? invokeFunc(time) : result;\n }\n\n function remainingWait(time: number): number {\n if (lastCallTime === undefined) return 0;\n\n const timeSinceLastCall = time - lastCallTime;\n const timeSinceLastInvoke = time - lastInvokeTime;\n const timeWaiting = waitValue - timeSinceLastCall;\n\n return maxWait !== null\n ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke)\n : timeWaiting;\n }\n\n function shouldInvoke(time: number): boolean {\n if (lastCallTime === undefined) return true;\n\n const timeSinceLastCall = time - lastCallTime;\n const timeSinceLastInvoke = time - lastInvokeTime;\n\n // Either this is the first call, activity has stopped and we're at the\n // trailing edge, the system time has gone backwards and we're treating\n // it as the trailing edge, or we've hit the `maxWait` limit.\n return (\n timeSinceLastCall >= waitValue ||\n timeSinceLastCall < 0 ||\n (maxWait !== null && timeSinceLastInvoke >= maxWait)\n );\n }\n\n function timerExpired(): Result {\n const time = Date.now();\n if (shouldInvoke(time)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return trailingEdge(time);\n }\n\n // Restart the timer.\n timerId = startTimer(timerExpired, remainingWait(time));\n\n return;\n }\n\n function trailingEdge(time: number): Result {\n timerId = undefined;\n\n // Only invoke if we have `lastArgs` which means `func` has been\n // debounced at least once.\n if (trailing && lastArgs) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return invokeFunc(time);\n }\n lastArgs = lastThis = undefined;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result;\n }\n\n function cancel(): void {\n if (timerId !== undefined) {\n cancelTimer(timerId);\n }\n lastInvokeTime = 0;\n lastArgs = lastCallTime = lastThis = timerId = undefined;\n }\n\n function flush(): Result {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return timerId === undefined ? result : trailingEdge(Date.now());\n }\n\n function pending(): boolean {\n return timerId !== undefined;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n function debounced(this: any, ...args: any[]): Result {\n const time = Date.now();\n const isInvoking = shouldInvoke(time);\n\n lastArgs = args;\n // eslint-disable-next-line @typescript-eslint/no-this-alias,@typescript-eslint/no-unsafe-assignment\n lastThis = this;\n lastCallTime = time;\n\n if (isInvoking) {\n if (timerId === undefined) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return leadingEdge(lastCallTime);\n }\n if (maxWait !== null) {\n // Handle invocations in a tight loop.\n timerId = startTimer(timerExpired, waitValue);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return invokeFunc(lastCallTime);\n }\n }\n timerId ??= startTimer(timerExpired, waitValue);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result;\n }\n\n debounced.cancel = cancel;\n debounced.flush = flush;\n debounced.pending = pending;\n\n return debounced;\n}\n"],"mappings":";;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAEA;;AAsCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,QAAQA,CACtBC,IAAO,EACPC,IAAa,EACbC,OAAyB,EACP;EAClB;;EAGA;EACA,IAAIC,QAAa;EACjB;EACA,IAAIC,QAAa;EACjB,IAAIC,MAAc;EAClB,IAAIC,YAAgC;EACpC,IAAIC,OAA8B;EAClC,IAAIC,cAAc,GAAG,CAAC;;EAEtB;EACA,MAAMC,MAAM,GACVR,IAAI,KAAKS,SAAS,IAClB,OAAOC,MAA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C;MACA,IAAIY,OAAO,KAAK,IAAI,EAAE;QACpB;QACAX,OAAO,GAAGoB,UAAU,CAACQ,YAAY,EAAErB,SAAS,CAAC;QAC7C;QACA,OAAOQ,UAAU,CAAChB,YAAY,CAAC;MACjC;IACF;IACAC,OAAO,KAAKoB,UAAU,CAACQ,YAAY,EAAErB,SAAS,CAAC;IAC/C;IACA,OAAOT,MAAM;EACf;EAEA2C,SAAS,CAACH,MAAM,GAAGA,MAAM;EACzBG,SAAS,CAACF,KAAK,GAAGA,KAAK;EACvBE,SAAS,CAACD,OAAO,GAAGA,OAAO;EAE3B,OAAOC,SAAS;AAClB","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsComponentProps.js","names":[],"sources":["../../src/AsComponentProps.ts"],"sourcesContent":["import { Dict } from \"./@types/Dict\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type As<Props = any> = React.ElementType<Props>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type DistributiveOmit<T, K extends keyof any> = T extends any\n ? Omit<T, K>\n : never;\n\nexport type AsComponentProp<C extends As, Props = Dict> = Props & {\n as?: C;\n} & DistributiveOmit<React.ComponentPropsWithoutRef<C>, keyof Props | \"as\">;\n\nexport type AsRef<C extends React.ElementType> =\n React.ComponentPropsWithRef<C>[\"ref\"];\n\nexport type MergeWithAs<\n ComponentProps extends object,\n AsProps extends object,\n AdditionalProps extends object = Dict,\n AsComponent extends As = As,\n> = AdditionalProps &\n Omit<ComponentProps, keyof AdditionalProps | \"as\"> &\n Omit<AsProps, keyof ComponentProps | keyof AdditionalProps | \"as\"> & {\n as?: AsComponent;\n };\n\nexport type ComponentWithAs<\n Component extends As,\n Props extends object = Dict,\n> = <AsComponent extends As = Component>(\n props: MergeWithAs<\n React.ComponentProps<Component>,\n React.ComponentProps<AsComponent>,\n Props,\n AsComponent\n > & {\n ref?: AsRef<AsComponent>;\n },\n) => React.JSX.Element | null;\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"AsComponentProps.js","names":[],"sources":["../../src/AsComponentProps.ts"],"sourcesContent":["import { Dict } from \"./@types/Dict\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type As<Props = any> = React.ElementType<Props>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type DistributiveOmit<T, K extends keyof any> = T extends any\n ? Omit<T, K>\n : never;\n\n// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\nexport type AsComponentProp<C extends As, Props = Dict> = Props & {\n as?: C;\n} & DistributiveOmit<React.ComponentPropsWithoutRef<C>, keyof Props | \"as\">;\n\nexport type AsRef<C extends React.ElementType> =\n React.ComponentPropsWithRef<C>[\"ref\"];\n\nexport type MergeWithAs<\n ComponentProps extends object,\n AsProps extends object,\n AdditionalProps extends object = Dict,\n AsComponent extends As = As,\n> = AdditionalProps &\n Omit<ComponentProps, keyof AdditionalProps | \"as\"> &\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n Omit<AsProps, keyof ComponentProps | keyof AdditionalProps | \"as\"> & {\n as?: AsComponent;\n };\n\nexport type ComponentWithAs<\n Component extends As,\n Props extends object = Dict,\n> = <AsComponent extends As = Component>(\n props: MergeWithAs<\n React.ComponentProps<Component>,\n React.ComponentProps<AsComponent>,\n Props,\n AsComponent\n > & {\n ref?: AsRef<AsComponent>;\n },\n) => React.JSX.Element | null;\n"],"mappings":"","ignoreList":[]}
|
package/esm/@utils/debounce.js
CHANGED
|
@@ -63,6 +63,8 @@ import { isObject } from "./isObject";
|
|
|
63
63
|
*/
|
|
64
64
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
65
|
export function debounce(func, wait, options) {
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
67
|
+
|
|
66
68
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
69
|
var lastArgs;
|
|
68
70
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debounce.js","names":["isObject","debounce","func","wait","options","lastArgs","lastThis","result","lastCallTime","timerId","lastInvokeTime","useRAF","undefined","window","requestAnimationFrame","TypeError","waitValue","Number","leading","trailing","maxWait","Math","max","invokeFunc","time","args","thisArg","apply","startTimer","pendingFunc","cancelAnimationFrame","setTimeout","cancelTimer","id","clearTimeout","leadingEdge","timerExpired","remainingWait","timeSinceLastCall","timeSinceLastInvoke","timeWaiting","min","shouldInvoke","Date","now","trailingEdge","cancel","flush","pending","debounced","isInvoking","_len","arguments","length","Array","_key"],"sources":["../../../src/@utils/debounce.ts"],"sourcesContent":["import { isObject } from \"./isObject\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface DebouncedFunc<T extends (...args: any[]) => any> {\n /**\n * Call the original function, but applying the debounce rules.\n *\n * If the debounced function can be run immediately, this calls it and returns its return\n * value.\n *\n * Otherwise, it returns the return value of the last invokation, or undefined if the debounced\n * function was not invoked yet.\n */\n (...args: Parameters<T>): ReturnType<T> | undefined;\n\n /**\n * Throw away any pending invokation of the debounced function.\n */\n cancel(): void;\n\n /**\n * If there is a pending invokation of the debounced function, invoke it immediately and return\n * its return value.\n *\n * Otherwise, return the value from the last invokation, or undefined if the debounced function\n * was never invoked.\n */\n flush(): ReturnType<T> | undefined;\n}\n\ninterface DebounceOptions {\n maxWait?: number;\n leading?: boolean;\n trailing?: boolean;\n}\n\ntype TimeoutId = ReturnType<typeof setTimeout>;\n\n/**\n * Creates a debounced function that delays invoking `func` until after `wait`\n * milliseconds have elapsed since the last time the debounced function was\n * invoked, or until the next browser frame is drawn. The debounced function\n * comes with a `cancel` method to cancel delayed `func` invocations and a\n * `flush` method to immediately invoke them. Provide `options` to indicate\n * whether `func` should be invoked on the leading and/or trailing edge of the\n * `wait` timeout. The `func` is invoked with the last arguments provided to the\n * debounced function. Subsequent calls to the debounced function return the\n * result of the last `func` invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the debounced function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * If `wait` is omitted in an environment with `requestAnimationFrame`, `func`\n * invocation will be deferred until the next frame is drawn (typically about\n * 16ms).\n *\n * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)\n * for details over the differences between `debounce` and `throttle`.\n *\n * @param {Function} func The function to debounce.\n * @param {number} [wait=0]\n * The number of milliseconds to delay; if omitted, `requestAnimationFrame` is\n * used (if available).\n * @param {Object} [options={}] The options object.\n * @param {boolean} [options.leading=false]\n * Specify invoking on the leading edge of the timeout.\n * @param {number} [options.maxWait]\n * The maximum time `func` is allowed to be delayed before it's invoked.\n * @param {boolean} [options.trailing=true]\n * Specify invoking on the trailing edge of the timeout.\n * @returns {Function} Returns the new debounced function.\n * @example\n *\n * // Avoid costly calculations while the window size is in flux.\n * window.addEventListener('resize', debounce(calculateLayout, 150))\n *\n * // Invoke `sendMail` when clicked, debouncing subsequent calls.\n * element.addEventListener('click', debounce(sendMail, 300, {\n * 'leading': true,\n * 'trailing': false\n * }))\n *\n * // Ensure `batchLog` is invoked once after 1 second of debounced calls.\n * const debounced = debounce(batchLog, 250, { 'maxWait': 1000 })\n * const source = new EventSource('/stream')\n * source.addEventListener('message', debounced)\n *\n * // Cancel the trailing debounced invocation.\n * window.addEventListener('popstate', debounced.cancel)\n *\n * // Check for pending invocations.\n * const status = debounced.pending() ? \"Pending...\" : \"Ready\"\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function debounce<T extends (...args: any) => any>(\n func: T,\n wait?: number,\n options?: DebounceOptions,\n): DebouncedFunc<T> {\n type Result = ReturnType<T> | undefined;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let lastArgs: any;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let lastThis: any;\n let result: Result;\n let lastCallTime: number | undefined;\n let timerId: TimeoutId | undefined;\n let lastInvokeTime = 0;\n\n // Bypass `requestAnimationFrame` by explicitly setting `wait=0`.\n const useRAF =\n wait === undefined &&\n typeof window !== \"undefined\" &&\n typeof window.requestAnimationFrame === \"function\";\n\n if (typeof func !== \"function\") {\n throw new TypeError(\"Expected a function\");\n }\n\n const waitValue = Number(wait) || 0;\n\n let leading = false;\n let trailing = true;\n let maxWait: number | null = null;\n if (isObject(options)) {\n leading = !!options.leading;\n maxWait =\n \"maxWait\" in options\n ? Math.max(Number(options.maxWait) || 0, waitValue)\n : maxWait;\n trailing = \"trailing\" in options ? !!options.trailing : trailing;\n }\n\n function invokeFunc(time: number): Result {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const args = lastArgs;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const thisArg = lastThis;\n\n lastArgs = lastThis = undefined;\n lastInvokeTime = time;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument\n result = func.apply(thisArg, args);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result;\n }\n\n function startTimer(pendingFunc: () => Result, wait: number): TimeoutId {\n if (useRAF && typeof timerId === \"number\") {\n window.cancelAnimationFrame(timerId);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-return\n return window.requestAnimationFrame(pendingFunc) as any;\n }\n return setTimeout(pendingFunc, wait);\n }\n\n function cancelTimer(id: TimeoutId): void {\n if (useRAF && typeof id === \"number\") {\n window.cancelAnimationFrame(id);\n }\n clearTimeout(id);\n }\n\n function leadingEdge(time: number): Result {\n // Reset any `maxWait` timer.\n lastInvokeTime = time;\n // Start the timer for the trailing edge.\n timerId = startTimer(timerExpired, waitValue);\n // Invoke the leading edge.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return leading ? invokeFunc(time) : result;\n }\n\n function remainingWait(time: number): number {\n if (lastCallTime === undefined) return 0;\n\n const timeSinceLastCall = time - lastCallTime;\n const timeSinceLastInvoke = time - lastInvokeTime;\n const timeWaiting = waitValue - timeSinceLastCall;\n\n return maxWait !== null\n ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke)\n : timeWaiting;\n }\n\n function shouldInvoke(time: number): boolean {\n if (lastCallTime === undefined) return true;\n\n const timeSinceLastCall = time - lastCallTime;\n const timeSinceLastInvoke = time - lastInvokeTime;\n\n // Either this is the first call, activity has stopped and we're at the\n // trailing edge, the system time has gone backwards and we're treating\n // it as the trailing edge, or we've hit the `maxWait` limit.\n return (\n timeSinceLastCall >= waitValue ||\n timeSinceLastCall < 0 ||\n (maxWait !== null && timeSinceLastInvoke >= maxWait)\n );\n }\n\n function timerExpired(): Result {\n const time = Date.now();\n if (shouldInvoke(time)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return trailingEdge(time);\n }\n\n // Restart the timer.\n timerId = startTimer(timerExpired, remainingWait(time));\n\n return;\n }\n\n function trailingEdge(time: number): Result {\n timerId = undefined;\n\n // Only invoke if we have `lastArgs` which means `func` has been\n // debounced at least once.\n if (trailing && lastArgs) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return invokeFunc(time);\n }\n lastArgs = lastThis = undefined;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result;\n }\n\n function cancel(): void {\n if (timerId !== undefined) {\n cancelTimer(timerId);\n }\n lastInvokeTime = 0;\n lastArgs = lastCallTime = lastThis = timerId = undefined;\n }\n\n function flush(): Result {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return timerId === undefined ? result : trailingEdge(Date.now());\n }\n\n function pending(): boolean {\n return timerId !== undefined;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n function debounced(this: any, ...args: any[]): Result {\n const time = Date.now();\n const isInvoking = shouldInvoke(time);\n\n lastArgs = args;\n // eslint-disable-next-line @typescript-eslint/no-this-alias,@typescript-eslint/no-unsafe-assignment\n lastThis = this;\n lastCallTime = time;\n\n if (isInvoking) {\n if (timerId === undefined) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return leadingEdge(lastCallTime);\n }\n if (maxWait !== null) {\n // Handle invocations in a tight loop.\n timerId = startTimer(timerExpired, waitValue);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return invokeFunc(lastCallTime);\n }\n }\n timerId ??= startTimer(timerExpired, waitValue);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result;\n }\n\n debounced.cancel = cancel;\n debounced.flush = flush;\n debounced.pending = pending;\n\n return debounced;\n}\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,YAAY;;AAErC;;AAoCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CACtBC,IAAO,EACPC,IAAa,EACbC,OAAyB,EACP;EAGlB;EACA,IAAIC,QAAa;EACjB;EACA,IAAIC,QAAa;EACjB,IAAIC,MAAc;EAClB,IAAIC,YAAgC;EACpC,IAAIC,OAA8B;EAClC,IAAIC,cAAc,GAAG,CAAC;;EAEtB;EACA,IAAMC,MAAM,GACVR,IAAI,KAAKS,SAAS,IAClB,OAAOC,MAAM,KAAK,WAAW,IAC7B,OAAOA,MAAM,CAACC,qBAAqB,KAAK,UAAU;EAEpD,IAAI,OAAOZ,IAAI,KAAK,UAAU,EAAE;IAC9B,MAAM,IAAIa,SAAS,CAAC,qBAAqB,CAAC;EAC5C;EAEA,IAAMC,SAAS,GAAGC,MAAM,CAACd,IAAI,CAAC,IAAI,CAAC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pB;QACAX,OAAO,GAAGmB,UAAU,CAACQ,YAAY,EAAEpB,SAAS,CAAC;QAC7C;QACA,OAAOO,UAAU,CAACf,YAAY,CAAC;MACjC;IACF;IACAC,OAAO,WAAPA,OAAO,GAAPA,OAAO,GAAKmB,UAAU,CAACQ,YAAY,EAAEpB,SAAS,CAAC;IAC/C;IACA,OAAOT,MAAM;EACf;EAEA0C,SAAS,CAACH,MAAM,GAAGA,MAAM;EACzBG,SAAS,CAACF,KAAK,GAAGA,KAAK;EACvBE,SAAS,CAACD,OAAO,GAAGA,OAAO;EAE3B,OAAOC,SAAS;AAClB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"debounce.js","names":["isObject","debounce","func","wait","options","lastArgs","lastThis","result","lastCallTime","timerId","lastInvokeTime","useRAF","undefined","window","requestAnimationFrame","TypeError","waitValue","Number","leading","trailing","maxWait","Math","max","invokeFunc","time","args","thisArg","apply","startTimer","pendingFunc","cancelAnimationFrame","setTimeout","cancelTimer","id","clearTimeout","leadingEdge","timerExpired","remainingWait","timeSinceLastCall","timeSinceLastInvoke","timeWaiting","min","shouldInvoke","Date","now","trailingEdge","cancel","flush","pending","debounced","isInvoking","_len","arguments","length","Array","_key"],"sources":["../../../src/@utils/debounce.ts"],"sourcesContent":["import { isObject } from \"./isObject\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface DebouncedFunc<T extends (...args: any[]) => any> {\n /**\n * Call the original function, but applying the debounce rules.\n *\n * If the debounced function can be run immediately, this calls it and returns its return\n * value.\n *\n * Otherwise, it returns the return value of the last invokation, or undefined if the debounced\n * function was not invoked yet.\n */\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n (...args: Parameters<T>): ReturnType<T> | undefined;\n\n /**\n * Throw away any pending invokation of the debounced function.\n */\n cancel(): void;\n\n /**\n * If there is a pending invokation of the debounced function, invoke it immediately and return\n * its return value.\n *\n * Otherwise, return the value from the last invokation, or undefined if the debounced function\n * was never invoked.\n */\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n flush(): ReturnType<T> | undefined;\n}\n\ninterface DebounceOptions {\n maxWait?: number;\n leading?: boolean;\n trailing?: boolean;\n}\n\ntype TimeoutId = ReturnType<typeof setTimeout>;\n\n/**\n * Creates a debounced function that delays invoking `func` until after `wait`\n * milliseconds have elapsed since the last time the debounced function was\n * invoked, or until the next browser frame is drawn. The debounced function\n * comes with a `cancel` method to cancel delayed `func` invocations and a\n * `flush` method to immediately invoke them. Provide `options` to indicate\n * whether `func` should be invoked on the leading and/or trailing edge of the\n * `wait` timeout. The `func` is invoked with the last arguments provided to the\n * debounced function. Subsequent calls to the debounced function return the\n * result of the last `func` invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the debounced function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * If `wait` is omitted in an environment with `requestAnimationFrame`, `func`\n * invocation will be deferred until the next frame is drawn (typically about\n * 16ms).\n *\n * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)\n * for details over the differences between `debounce` and `throttle`.\n *\n * @param {Function} func The function to debounce.\n * @param {number} [wait=0]\n * The number of milliseconds to delay; if omitted, `requestAnimationFrame` is\n * used (if available).\n * @param {Object} [options={}] The options object.\n * @param {boolean} [options.leading=false]\n * Specify invoking on the leading edge of the timeout.\n * @param {number} [options.maxWait]\n * The maximum time `func` is allowed to be delayed before it's invoked.\n * @param {boolean} [options.trailing=true]\n * Specify invoking on the trailing edge of the timeout.\n * @returns {Function} Returns the new debounced function.\n * @example\n *\n * // Avoid costly calculations while the window size is in flux.\n * window.addEventListener('resize', debounce(calculateLayout, 150))\n *\n * // Invoke `sendMail` when clicked, debouncing subsequent calls.\n * element.addEventListener('click', debounce(sendMail, 300, {\n * 'leading': true,\n * 'trailing': false\n * }))\n *\n * // Ensure `batchLog` is invoked once after 1 second of debounced calls.\n * const debounced = debounce(batchLog, 250, { 'maxWait': 1000 })\n * const source = new EventSource('/stream')\n * source.addEventListener('message', debounced)\n *\n * // Cancel the trailing debounced invocation.\n * window.addEventListener('popstate', debounced.cancel)\n *\n * // Check for pending invocations.\n * const status = debounced.pending() ? \"Pending...\" : \"Ready\"\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function debounce<T extends (...args: any) => any>(\n func: T,\n wait?: number,\n options?: DebounceOptions,\n): DebouncedFunc<T> {\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n type Result = ReturnType<T> | undefined;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let lastArgs: any;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let lastThis: any;\n let result: Result;\n let lastCallTime: number | undefined;\n let timerId: TimeoutId | undefined;\n let lastInvokeTime = 0;\n\n // Bypass `requestAnimationFrame` by explicitly setting `wait=0`.\n const useRAF =\n wait === undefined &&\n typeof window !== \"undefined\" &&\n typeof window.requestAnimationFrame === \"function\";\n\n if (typeof func !== \"function\") {\n throw new TypeError(\"Expected a function\");\n }\n\n const waitValue = Number(wait) || 0;\n\n let leading = false;\n let trailing = true;\n let maxWait: number | null = null;\n if (isObject(options)) {\n leading = !!options.leading;\n maxWait =\n \"maxWait\" in options\n ? Math.max(Number(options.maxWait) || 0, waitValue)\n : maxWait;\n trailing = \"trailing\" in options ? !!options.trailing : trailing;\n }\n\n function invokeFunc(time: number): Result {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const args = lastArgs;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const thisArg = lastThis;\n\n lastArgs = lastThis = undefined;\n lastInvokeTime = time;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument\n result = func.apply(thisArg, args);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result;\n }\n\n function startTimer(pendingFunc: () => Result, wait: number): TimeoutId {\n if (useRAF && typeof timerId === \"number\") {\n window.cancelAnimationFrame(timerId);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-return\n return window.requestAnimationFrame(pendingFunc) as any;\n }\n return setTimeout(pendingFunc, wait);\n }\n\n function cancelTimer(id: TimeoutId): void {\n if (useRAF && typeof id === \"number\") {\n window.cancelAnimationFrame(id);\n }\n clearTimeout(id);\n }\n\n function leadingEdge(time: number): Result {\n // Reset any `maxWait` timer.\n lastInvokeTime = time;\n // Start the timer for the trailing edge.\n timerId = startTimer(timerExpired, waitValue);\n // Invoke the leading edge.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return leading ? invokeFunc(time) : result;\n }\n\n function remainingWait(time: number): number {\n if (lastCallTime === undefined) return 0;\n\n const timeSinceLastCall = time - lastCallTime;\n const timeSinceLastInvoke = time - lastInvokeTime;\n const timeWaiting = waitValue - timeSinceLastCall;\n\n return maxWait !== null\n ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke)\n : timeWaiting;\n }\n\n function shouldInvoke(time: number): boolean {\n if (lastCallTime === undefined) return true;\n\n const timeSinceLastCall = time - lastCallTime;\n const timeSinceLastInvoke = time - lastInvokeTime;\n\n // Either this is the first call, activity has stopped and we're at the\n // trailing edge, the system time has gone backwards and we're treating\n // it as the trailing edge, or we've hit the `maxWait` limit.\n return (\n timeSinceLastCall >= waitValue ||\n timeSinceLastCall < 0 ||\n (maxWait !== null && timeSinceLastInvoke >= maxWait)\n );\n }\n\n function timerExpired(): Result {\n const time = Date.now();\n if (shouldInvoke(time)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return trailingEdge(time);\n }\n\n // Restart the timer.\n timerId = startTimer(timerExpired, remainingWait(time));\n\n return;\n }\n\n function trailingEdge(time: number): Result {\n timerId = undefined;\n\n // Only invoke if we have `lastArgs` which means `func` has been\n // debounced at least once.\n if (trailing && lastArgs) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return invokeFunc(time);\n }\n lastArgs = lastThis = undefined;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result;\n }\n\n function cancel(): void {\n if (timerId !== undefined) {\n cancelTimer(timerId);\n }\n lastInvokeTime = 0;\n lastArgs = lastCallTime = lastThis = timerId = undefined;\n }\n\n function flush(): Result {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return timerId === undefined ? result : trailingEdge(Date.now());\n }\n\n function pending(): boolean {\n return timerId !== undefined;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n function debounced(this: any, ...args: any[]): Result {\n const time = Date.now();\n const isInvoking = shouldInvoke(time);\n\n lastArgs = args;\n // eslint-disable-next-line @typescript-eslint/no-this-alias,@typescript-eslint/no-unsafe-assignment\n lastThis = this;\n lastCallTime = time;\n\n if (isInvoking) {\n if (timerId === undefined) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return leadingEdge(lastCallTime);\n }\n if (maxWait !== null) {\n // Handle invocations in a tight loop.\n timerId = startTimer(timerExpired, waitValue);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return invokeFunc(lastCallTime);\n }\n }\n timerId ??= startTimer(timerExpired, waitValue);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result;\n }\n\n debounced.cancel = cancel;\n debounced.flush = flush;\n debounced.pending = pending;\n\n return debounced;\n}\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,YAAY;;AAErC;;AAsCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CACtBC,I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AAY,CAAClB,IAAI,CAAC;IAAC,SAAA2B,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAFP5B,IAAI,OAAA6B,KAAA,CAAAH,IAAA,GAAAI,IAAA,MAAAA,IAAA,GAAAJ,IAAA,EAAAI,IAAA;MAAJ9B,IAAI,CAAA8B,IAAA,IAAAH,SAAA,CAAAG,IAAA;IAAA;IAInClD,QAAQ,GAAGoB,IAAI;IACf;IACAnB,QAAQ,GAAG,IAAI;IACfE,YAAY,GAAGgB,IAAI;IAEnB,IAAI0B,UAAU,EAAE;MACd,IAAIzC,OAAO,KAAKG,SAAS,EAAE;QACzB;QACA,OAAOuB,WAAW,CAAC3B,YAAY,CAAC;MAClC;MACA,IAAIY,OAAO,KAAK,IAAI,EAAE;QACpB;QACAX,OAAO,GAAGmB,UAAU,CAACQ,YAAY,EAAEpB,SAAS,CAAC;QAC7C;QACA,OAAOO,UAAU,CAACf,YAAY,CAAC;MACjC;IACF;IACAC,OAAO,WAAPA,OAAO,GAAPA,OAAO,GAAKmB,UAAU,CAACQ,YAAY,EAAEpB,SAAS,CAAC;IAC/C;IACA,OAAOT,MAAM;EACf;EAEA0C,SAAS,CAACH,MAAM,GAAGA,MAAM;EACzBG,SAAS,CAACF,KAAK,GAAGA,KAAK;EACvBE,SAAS,CAACD,OAAO,GAAGA,OAAO;EAE3B,OAAOC,SAAS;AAClB","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsComponentProps.js","names":[],"sources":["../../src/AsComponentProps.ts"],"sourcesContent":["import { Dict } from \"./@types/Dict\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type As<Props = any> = React.ElementType<Props>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type DistributiveOmit<T, K extends keyof any> = T extends any\n ? Omit<T, K>\n : never;\n\nexport type AsComponentProp<C extends As, Props = Dict> = Props & {\n as?: C;\n} & DistributiveOmit<React.ComponentPropsWithoutRef<C>, keyof Props | \"as\">;\n\nexport type AsRef<C extends React.ElementType> =\n React.ComponentPropsWithRef<C>[\"ref\"];\n\nexport type MergeWithAs<\n ComponentProps extends object,\n AsProps extends object,\n AdditionalProps extends object = Dict,\n AsComponent extends As = As,\n> = AdditionalProps &\n Omit<ComponentProps, keyof AdditionalProps | \"as\"> &\n Omit<AsProps, keyof ComponentProps | keyof AdditionalProps | \"as\"> & {\n as?: AsComponent;\n };\n\nexport type ComponentWithAs<\n Component extends As,\n Props extends object = Dict,\n> = <AsComponent extends As = Component>(\n props: MergeWithAs<\n React.ComponentProps<Component>,\n React.ComponentProps<AsComponent>,\n Props,\n AsComponent\n > & {\n ref?: AsRef<AsComponent>;\n },\n) => React.JSX.Element | null;\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"AsComponentProps.js","names":[],"sources":["../../src/AsComponentProps.ts"],"sourcesContent":["import { Dict } from \"./@types/Dict\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type As<Props = any> = React.ElementType<Props>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type DistributiveOmit<T, K extends keyof any> = T extends any\n ? Omit<T, K>\n : never;\n\n// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\nexport type AsComponentProp<C extends As, Props = Dict> = Props & {\n as?: C;\n} & DistributiveOmit<React.ComponentPropsWithoutRef<C>, keyof Props | \"as\">;\n\nexport type AsRef<C extends React.ElementType> =\n React.ComponentPropsWithRef<C>[\"ref\"];\n\nexport type MergeWithAs<\n ComponentProps extends object,\n AsProps extends object,\n AdditionalProps extends object = Dict,\n AsComponent extends As = As,\n> = AdditionalProps &\n Omit<ComponentProps, keyof AdditionalProps | \"as\"> &\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n Omit<AsProps, keyof ComponentProps | keyof AdditionalProps | \"as\"> & {\n as?: AsComponent;\n };\n\nexport type ComponentWithAs<\n Component extends As,\n Props extends object = Dict,\n> = <AsComponent extends As = Component>(\n props: MergeWithAs<\n React.ComponentProps<Component>,\n React.ComponentProps<AsComponent>,\n Props,\n AsComponent\n > & {\n ref?: AsRef<AsComponent>;\n },\n) => React.JSX.Element | null;\n"],"mappings":"","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "matsuri-ui",
|
|
3
|
-
"version": "18.0.3-alpha-
|
|
4
|
-
"repository":
|
|
5
|
-
"type": "git",
|
|
6
|
-
"url": "git+https://github.com/matsuri-tech/matsuri-ui.git"
|
|
7
|
-
},
|
|
3
|
+
"version": "18.0.3-alpha-1766239260045-3f82224.0",
|
|
4
|
+
"repository": "https://github.com/matsuri-tech/matsuri-ui.git",
|
|
8
5
|
"license": "GPL-3.0",
|
|
9
6
|
"sideEffects": false,
|
|
10
7
|
"main": "./index.js",
|
|
@@ -32,10 +29,10 @@
|
|
|
32
29
|
"node_modules"
|
|
33
30
|
],
|
|
34
31
|
"dependencies": {
|
|
35
|
-
"@mui/icons-material": "7.3.
|
|
36
|
-
"@mui/material": "7.3.
|
|
32
|
+
"@mui/icons-material": "7.3.6",
|
|
33
|
+
"@mui/material": "7.3.6",
|
|
37
34
|
"@popperjs/core": "2.11.8",
|
|
38
|
-
"motion": "12.23.
|
|
35
|
+
"motion": "12.23.26",
|
|
39
36
|
"react-popper": "2.3.0",
|
|
40
37
|
"relative-time-format": "1.1.11",
|
|
41
38
|
"resize-observer-polyfill": "1.5.1"
|
|
@@ -65,14 +62,14 @@
|
|
|
65
62
|
"@emotion/babel-preset-css-prop": "11.12.0",
|
|
66
63
|
"@emotion/react": "11.14.0",
|
|
67
64
|
"@emotion/styled": "11.14.1",
|
|
68
|
-
"@tanstack/react-virtual": "3.13.
|
|
65
|
+
"@tanstack/react-virtual": "3.13.13",
|
|
69
66
|
"@testing-library/react": "16.3.0",
|
|
70
67
|
"@types/jest": "29.5.14",
|
|
71
68
|
"concurrently": "9.2.1",
|
|
72
69
|
"dayjs": "1.11.19",
|
|
73
70
|
"jest": "30.2.0",
|
|
74
71
|
"jest-environment-jsdom": "30.2.0",
|
|
75
|
-
"react-router-dom": "7.
|
|
72
|
+
"react-router-dom": "7.10.1",
|
|
76
73
|
"ress": "5.0.2",
|
|
77
74
|
"tslib": "2.8.1"
|
|
78
75
|
},
|