@mantine/hooks.umd

UMD of @mantine/hooks

目前为 2024-06-29 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/499180/1402239/%40mantinehooksumd.js

  1. // ==UserScript==
  2. // @name @mantine/hooks.umd
  3. // @namespace flomk.userscripts
  4. // @version 1.0
  5. // @description UMD of @mantine/hooks
  6. // @author flomk
  7. // ==/UserScript==
  8. (function (global, factory) {
  9. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
  10. typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
  11. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MantineHooks = {}, global.React));
  12. })(this, (function (exports, React) { 'use strict';
  13.  
  14. /* esm.sh - esbuild bundle(@mantine/hooks@7.11.0) es2022 development */
  15. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/utils/clamp/clamp.mjs
  16. function clamp(value, min, max) {
  17. if (min === void 0 && max === void 0) {
  18. return value;
  19. }
  20. if (min !== void 0 && max === void 0) {
  21. return Math.max(value, min);
  22. }
  23. if (min === void 0 && max !== void 0) {
  24. return Math.min(value, max);
  25. }
  26. return Math.min(Math.max(value, min), max);
  27. }
  28.  
  29. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/utils/lower-first/lower-first.mjs
  30. function lowerFirst(value) {
  31. return typeof value !== "string" ? "" : value.charAt(0).toLowerCase() + value.slice(1);
  32. }
  33.  
  34. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/utils/random-id/random-id.mjs
  35. function randomId() {
  36. return `mantine-${Math.random().toString(36).slice(2, 11)}`;
  37. }
  38.  
  39. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/utils/range/range.mjs
  40. function range(start, end) {
  41. const length = Math.abs(end - start) + 1;
  42. const reversed = start > end;
  43. if (!reversed) {
  44. return Array.from({ length }, (_, index) => index + start);
  45. }
  46. return Array.from({ length }, (_, index) => start - index);
  47. }
  48.  
  49. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/utils/shallow-equal/shallow-equal.mjs
  50. function shallowEqual(a, b) {
  51. if (a === b) {
  52. return true;
  53. }
  54. if (!(a instanceof Object) || !(b instanceof Object)) {
  55. return false;
  56. }
  57. const keys = Object.keys(a);
  58. const { length } = keys;
  59. if (length !== Object.keys(b).length) {
  60. return false;
  61. }
  62. for (let i = 0; i < length; i += 1) {
  63. const key = keys[i];
  64. if (!(key in b)) {
  65. return false;
  66. }
  67. if (a[key] !== b[key]) {
  68. return false;
  69. }
  70. }
  71. return true;
  72. }
  73.  
  74. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/utils/upper-first/upper-first.mjs
  75. function upperFirst(value) {
  76. return typeof value !== "string" ? "" : value.charAt(0).toUpperCase() + value.slice(1);
  77. }
  78. function useCallbackRef(callback) {
  79. const callbackRef = React.useRef(callback);
  80. React.useEffect(() => {
  81. callbackRef.current = callback;
  82. });
  83. return React.useMemo(() => (...args) => callbackRef.current?.(...args), []);
  84. }
  85. function useDebouncedCallback(callback, delay) {
  86. const handleCallback = useCallbackRef(callback);
  87. const debounceTimerRef = React.useRef(0);
  88. React.useEffect(() => () => window.clearTimeout(debounceTimerRef.current), []);
  89. return React.useCallback(
  90. (...args) => {
  91. window.clearTimeout(debounceTimerRef.current);
  92. debounceTimerRef.current = window.setTimeout(() => handleCallback(...args), delay);
  93. },
  94. [handleCallback, delay]
  95. );
  96. }
  97. var DEFAULT_EVENTS = ["mousedown", "touchstart"];
  98. function useClickOutside(handler, events, nodes) {
  99. const ref = React.useRef();
  100. React.useEffect(() => {
  101. const listener = (event) => {
  102. const { target } = event ?? {};
  103. if (Array.isArray(nodes)) {
  104. const shouldIgnore = target?.hasAttribute("data-ignore-outside-clicks") || !document.body.contains(target) && target.tagName !== "HTML";
  105. const shouldTrigger = nodes.every((node) => !!node && !event.composedPath().includes(node));
  106. shouldTrigger && !shouldIgnore && handler();
  107. } else if (ref.current && !ref.current.contains(target)) {
  108. handler();
  109. }
  110. };
  111. (events || DEFAULT_EVENTS).forEach((fn) => document.addEventListener(fn, listener));
  112. return () => {
  113. (events || DEFAULT_EVENTS).forEach((fn) => document.removeEventListener(fn, listener));
  114. };
  115. }, [ref, handler, nodes]);
  116. return ref;
  117. }
  118. function useClipboard({ timeout = 2e3 } = {}) {
  119. const [error, setError] = React.useState(null);
  120. const [copied, setCopied] = React.useState(false);
  121. const [copyTimeout, setCopyTimeout] = React.useState(null);
  122. const handleCopyResult = (value) => {
  123. window.clearTimeout(copyTimeout);
  124. setCopyTimeout(window.setTimeout(() => setCopied(false), timeout));
  125. setCopied(value);
  126. };
  127. const copy = (valueToCopy) => {
  128. if ("clipboard" in navigator) {
  129. navigator.clipboard.writeText(valueToCopy).then(() => handleCopyResult(true)).catch((err) => setError(err));
  130. } else {
  131. setError(new Error("useClipboard: navigator.clipboard is not supported"));
  132. }
  133. };
  134. const reset = () => {
  135. setCopied(false);
  136. setError(null);
  137. window.clearTimeout(copyTimeout);
  138. };
  139. return { copy, reset, error, copied };
  140. }
  141. function attachMediaListener(query, callback) {
  142. try {
  143. query.addEventListener("change", callback);
  144. return () => query.removeEventListener("change", callback);
  145. } catch (e) {
  146. query.addListener(callback);
  147. return () => query.removeListener(callback);
  148. }
  149. }
  150. function getInitialValue(query, initialValue) {
  151. if (typeof initialValue === "boolean") {
  152. return initialValue;
  153. }
  154. if (typeof window !== "undefined" && "matchMedia" in window) {
  155. return window.matchMedia(query).matches;
  156. }
  157. return false;
  158. }
  159. function useMediaQuery(query, initialValue, { getInitialValueInEffect } = {
  160. getInitialValueInEffect: true
  161. }) {
  162. const [matches, setMatches] = React.useState(
  163. getInitialValueInEffect ? initialValue : getInitialValue(query)
  164. );
  165. const queryRef = React.useRef();
  166. React.useEffect(() => {
  167. if ("matchMedia" in window) {
  168. queryRef.current = window.matchMedia(query);
  169. setMatches(queryRef.current.matches);
  170. return attachMediaListener(queryRef.current, (event) => setMatches(event.matches));
  171. }
  172. return void 0;
  173. }, [query]);
  174. return matches;
  175. }
  176.  
  177. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/use-color-scheme/use-color-scheme.mjs
  178. function useColorScheme(initialValue, options) {
  179. return useMediaQuery("(prefers-color-scheme: dark)", initialValue === "dark", options) ? "dark" : "light";
  180. }
  181. var DEFAULT_OPTIONS = {
  182. min: -Infinity,
  183. max: Infinity
  184. };
  185. function useCounter(initialValue = 0, options) {
  186. const { min, max } = { ...DEFAULT_OPTIONS, ...options };
  187. const [count, setCount] = React.useState(clamp(initialValue, min, max));
  188. const increment = () => setCount((current) => clamp(current + 1, min, max));
  189. const decrement = () => setCount((current) => clamp(current - 1, min, max));
  190. const set = (value) => setCount(clamp(value, min, max));
  191. const reset = () => setCount(clamp(initialValue, min, max));
  192. return [count, { increment, decrement, set, reset }];
  193. }
  194. function useDebouncedState(defaultValue, wait, options = { leading: false }) {
  195. const [value, setValue] = React.useState(defaultValue);
  196. const timeoutRef = React.useRef(null);
  197. const leadingRef = React.useRef(true);
  198. const clearTimeout2 = () => window.clearTimeout(timeoutRef.current);
  199. React.useEffect(() => clearTimeout2, []);
  200. const debouncedSetValue = React.useCallback(
  201. (newValue) => {
  202. clearTimeout2();
  203. if (leadingRef.current && options.leading) {
  204. setValue(newValue);
  205. } else {
  206. timeoutRef.current = window.setTimeout(() => {
  207. leadingRef.current = true;
  208. setValue(newValue);
  209. }, wait);
  210. }
  211. leadingRef.current = false;
  212. },
  213. [options.leading]
  214. );
  215. return [value, debouncedSetValue];
  216. }
  217. function useDebouncedValue(value, wait, options = { leading: false }) {
  218. const [_value, setValue] = React.useState(value);
  219. const mountedRef = React.useRef(false);
  220. const timeoutRef = React.useRef(null);
  221. const cooldownRef = React.useRef(false);
  222. const cancel = () => window.clearTimeout(timeoutRef.current);
  223. React.useEffect(() => {
  224. if (mountedRef.current) {
  225. if (!cooldownRef.current && options.leading) {
  226. cooldownRef.current = true;
  227. setValue(value);
  228. } else {
  229. cancel();
  230. timeoutRef.current = window.setTimeout(() => {
  231. cooldownRef.current = false;
  232. setValue(value);
  233. }, wait);
  234. }
  235. }
  236. }, [value, options.leading, wait]);
  237. React.useEffect(() => {
  238. mountedRef.current = true;
  239. return cancel;
  240. }, []);
  241. return [_value, cancel];
  242. }
  243. var useIsomorphicEffect = typeof document !== "undefined" ? React.useLayoutEffect : React.useEffect;
  244.  
  245. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/use-document-title/use-document-title.mjs
  246. function useDocumentTitle(title) {
  247. useIsomorphicEffect(() => {
  248. if (typeof title === "string" && title.trim().length > 0) {
  249. document.title = title.trim();
  250. }
  251. }, [title]);
  252. }
  253. function useDocumentVisibility() {
  254. const [documentVisibility, setDocumentVisibility] = React.useState("visible");
  255. React.useEffect(() => {
  256. const listener = () => setDocumentVisibility(document.visibilityState);
  257. document.addEventListener("visibilitychange", listener);
  258. return () => document.removeEventListener("visibilitychange", listener);
  259. }, []);
  260. return documentVisibility;
  261. }
  262. function useDidUpdate(fn, dependencies) {
  263. const mounted = React.useRef(false);
  264. React.useEffect(
  265. () => () => {
  266. mounted.current = false;
  267. },
  268. []
  269. );
  270. React.useEffect(() => {
  271. if (mounted.current) {
  272. return fn();
  273. }
  274. mounted.current = true;
  275. return void 0;
  276. }, dependencies);
  277. }
  278.  
  279. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/use-focus-return/use-focus-return.mjs
  280. function useFocusReturn({ opened, shouldReturnFocus = true }) {
  281. const lastActiveElement = React.useRef();
  282. const returnFocus = () => {
  283. if (lastActiveElement.current && "focus" in lastActiveElement.current && typeof lastActiveElement.current.focus === "function") {
  284. lastActiveElement.current?.focus({ preventScroll: true });
  285. }
  286. };
  287. useDidUpdate(() => {
  288. let timeout = -1;
  289. const clearFocusTimeout = (event) => {
  290. if (event.key === "Tab") {
  291. window.clearTimeout(timeout);
  292. }
  293. };
  294. document.addEventListener("keydown", clearFocusTimeout);
  295. if (opened) {
  296. lastActiveElement.current = document.activeElement;
  297. } else if (shouldReturnFocus) {
  298. timeout = window.setTimeout(returnFocus, 10);
  299. }
  300. return () => {
  301. window.clearTimeout(timeout);
  302. document.removeEventListener("keydown", clearFocusTimeout);
  303. };
  304. }, [opened, shouldReturnFocus]);
  305. return returnFocus;
  306. }
  307.  
  308. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/use-focus-trap/create-aria-hider.mjs
  309. function createAriaHider(containerNode, selector = "body > :not(script)") {
  310. const id = randomId();
  311. const rootNodes = Array.from(
  312. document.querySelectorAll(selector)
  313. ).map((node) => {
  314. if (node?.shadowRoot?.contains(containerNode) || node.contains(containerNode)) {
  315. return void 0;
  316. }
  317. const ariaHidden = node.getAttribute("aria-hidden");
  318. const prevAriaHidden = node.getAttribute("data-hidden");
  319. const prevFocusId = node.getAttribute("data-focus-id");
  320. node.setAttribute("data-focus-id", id);
  321. if (ariaHidden === null || ariaHidden === "false") {
  322. node.setAttribute("aria-hidden", "true");
  323. } else if (!prevAriaHidden && !prevFocusId) {
  324. node.setAttribute("data-hidden", ariaHidden);
  325. }
  326. return {
  327. node,
  328. ariaHidden: prevAriaHidden || null
  329. };
  330. });
  331. return () => {
  332. rootNodes.forEach((item) => {
  333. if (!item || id !== item.node.getAttribute("data-focus-id")) {
  334. return;
  335. }
  336. if (item.ariaHidden === null) {
  337. item.node.removeAttribute("aria-hidden");
  338. } else {
  339. item.node.setAttribute("aria-hidden", item.ariaHidden);
  340. }
  341. item.node.removeAttribute("data-focus-id");
  342. item.node.removeAttribute("data-hidden");
  343. });
  344. };
  345. }
  346.  
  347. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/use-focus-trap/tabbable.mjs
  348. var TABBABLE_NODES = /input|select|textarea|button|object/;
  349. var FOCUS_SELECTOR = "a, input, select, textarea, button, object, [tabindex]";
  350. function hidden(element) {
  351. if (false) {
  352. return false;
  353. }
  354. return element.style.display === "none";
  355. }
  356. function visible(element) {
  357. const isHidden = element.getAttribute("aria-hidden") || element.getAttribute("hidden") || element.getAttribute("type") === "hidden";
  358. if (isHidden) {
  359. return false;
  360. }
  361. let parentElement = element;
  362. while (parentElement) {
  363. if (parentElement === document.body || parentElement.nodeType === 11) {
  364. break;
  365. }
  366. if (hidden(parentElement)) {
  367. return false;
  368. }
  369. parentElement = parentElement.parentNode;
  370. }
  371. return true;
  372. }
  373. function getElementTabIndex(element) {
  374. let tabIndex = element.getAttribute("tabindex");
  375. if (tabIndex === null) {
  376. tabIndex = void 0;
  377. }
  378. return parseInt(tabIndex, 10);
  379. }
  380. function focusable(element) {
  381. const nodeName = element.nodeName.toLowerCase();
  382. const isTabIndexNotNaN = !Number.isNaN(getElementTabIndex(element));
  383. const res = (
  384. // @ts-expect-error function accepts any html element but if it is a button, it should not be disabled to trigger the condition
  385. TABBABLE_NODES.test(nodeName) && !element.disabled || (element instanceof HTMLAnchorElement ? element.href || isTabIndexNotNaN : isTabIndexNotNaN)
  386. );
  387. return res && visible(element);
  388. }
  389. function tabbable(element) {
  390. const tabIndex = getElementTabIndex(element);
  391. const isTabIndexNaN = Number.isNaN(tabIndex);
  392. return (isTabIndexNaN || tabIndex >= 0) && focusable(element);
  393. }
  394. function findTabbableDescendants(element) {
  395. return Array.from(element.querySelectorAll(FOCUS_SELECTOR)).filter(tabbable);
  396. }
  397.  
  398. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/use-focus-trap/scope-tab.mjs
  399. function scopeTab(node, event) {
  400. const tabbable2 = findTabbableDescendants(node);
  401. if (!tabbable2.length) {
  402. event.preventDefault();
  403. return;
  404. }
  405. const finalTabbable = tabbable2[event.shiftKey ? 0 : tabbable2.length - 1];
  406. const root = node.getRootNode();
  407. let leavingFinalTabbable = finalTabbable === root.activeElement || node === root.activeElement;
  408. const activeElement = root.activeElement;
  409. const activeElementIsRadio = activeElement.tagName === "INPUT" && activeElement.getAttribute("type") === "radio";
  410. if (activeElementIsRadio) {
  411. const activeRadioGroup = tabbable2.filter(
  412. (element) => element.getAttribute("type") === "radio" && element.getAttribute("name") === activeElement.getAttribute("name")
  413. );
  414. leavingFinalTabbable = activeRadioGroup.includes(finalTabbable);
  415. }
  416. if (!leavingFinalTabbable) {
  417. return;
  418. }
  419. event.preventDefault();
  420. const target = tabbable2[event.shiftKey ? tabbable2.length - 1 : 0];
  421. if (target) {
  422. target.focus();
  423. }
  424. }
  425.  
  426. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/use-focus-trap/use-focus-trap.mjs
  427. function useFocusTrap(active = true) {
  428. const ref = React.useRef();
  429. const restoreAria = React.useRef(null);
  430. const focusNode = (node) => {
  431. let focusElement = node.querySelector("[data-autofocus]");
  432. if (!focusElement) {
  433. const children = Array.from(node.querySelectorAll(FOCUS_SELECTOR));
  434. focusElement = children.find(tabbable) || children.find(focusable) || null;
  435. if (!focusElement && focusable(node))
  436. focusElement = node;
  437. }
  438. if (focusElement) {
  439. focusElement.focus({ preventScroll: true });
  440. } else if (true) {
  441. console.warn(
  442. "[@mantine/hooks/use-focus-trap] Failed to find focusable element within provided node",
  443. node
  444. );
  445. }
  446. };
  447. const setRef = React.useCallback(
  448. (node) => {
  449. if (!active) {
  450. return;
  451. }
  452. if (node === null) {
  453. if (restoreAria.current) {
  454. restoreAria.current();
  455. restoreAria.current = null;
  456. }
  457. return;
  458. }
  459. restoreAria.current = createAriaHider(node);
  460. if (ref.current === node) {
  461. return;
  462. }
  463. if (node) {
  464. setTimeout(() => {
  465. if (node.getRootNode()) {
  466. focusNode(node);
  467. } else if (true) {
  468. console.warn("[@mantine/hooks/use-focus-trap] Ref node is not part of the dom", node);
  469. }
  470. });
  471. ref.current = node;
  472. } else {
  473. ref.current = null;
  474. }
  475. },
  476. [active]
  477. );
  478. React.useEffect(() => {
  479. if (!active) {
  480. return void 0;
  481. }
  482. ref.current && setTimeout(() => focusNode(ref.current));
  483. const handleKeyDown = (event) => {
  484. if (event.key === "Tab" && ref.current) {
  485. scopeTab(ref.current, event);
  486. }
  487. };
  488. document.addEventListener("keydown", handleKeyDown);
  489. return () => {
  490. document.removeEventListener("keydown", handleKeyDown);
  491. if (restoreAria.current) {
  492. restoreAria.current();
  493. }
  494. };
  495. }, [active]);
  496. return setRef;
  497. }
  498. var reducer = (value) => (value + 1) % 1e6;
  499. function useForceUpdate() {
  500. const [, update] = React.useReducer(reducer, 0);
  501. return update;
  502. }
  503. var __useId = React["useId".toString()] || (() => void 0);
  504. function useReactId() {
  505. const id = __useId();
  506. return id ? `mantine-${id.replace(/:/g, "")}` : "";
  507. }
  508.  
  509. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/use-id/use-id.mjs
  510. function useId(staticId) {
  511. const reactId = useReactId();
  512. const [uuid, setUuid] = React.useState(reactId);
  513. useIsomorphicEffect(() => {
  514. setUuid(randomId());
  515. }, []);
  516. if (typeof staticId === "string") {
  517. return staticId;
  518. }
  519. if (typeof window === "undefined") {
  520. return reactId;
  521. }
  522. return uuid;
  523. }
  524. var DEFAULT_EVENTS2 = [
  525. "keypress",
  526. "mousemove",
  527. "touchmove",
  528. "click",
  529. "scroll"
  530. ];
  531. var DEFAULT_OPTIONS2 = {
  532. events: DEFAULT_EVENTS2,
  533. initialState: true
  534. };
  535. function useIdle(timeout, options) {
  536. const { events, initialState } = { ...DEFAULT_OPTIONS2, ...options };
  537. const [idle, setIdle] = React.useState(initialState);
  538. const timer = React.useRef();
  539. React.useEffect(() => {
  540. const handleEvents = () => {
  541. setIdle(false);
  542. if (timer.current) {
  543. window.clearTimeout(timer.current);
  544. }
  545. timer.current = window.setTimeout(() => {
  546. setIdle(true);
  547. }, timeout);
  548. };
  549. events.forEach((event) => document.addEventListener(event, handleEvents));
  550. return () => {
  551. events.forEach((event) => document.removeEventListener(event, handleEvents));
  552. };
  553. }, [timeout]);
  554. return idle;
  555. }
  556. function useInterval(fn, interval) {
  557. const [active, setActive] = React.useState(false);
  558. const intervalRef = React.useRef();
  559. const fnRef = React.useRef();
  560. React.useEffect(() => {
  561. fnRef.current = fn;
  562. }, [fn]);
  563. const start = () => {
  564. setActive((old) => {
  565. if (!old && !intervalRef.current) {
  566. intervalRef.current = window.setInterval(fnRef.current, interval);
  567. }
  568. return true;
  569. });
  570. };
  571. const stop = () => {
  572. setActive(false);
  573. window.clearInterval(intervalRef.current);
  574. intervalRef.current = void 0;
  575. };
  576. const toggle = () => {
  577. if (active) {
  578. stop();
  579. } else {
  580. start();
  581. }
  582. };
  583. return { start, stop, toggle, active };
  584. }
  585. function useListState(initialValue = []) {
  586. const [state, setState] = React.useState(initialValue);
  587. const append = (...items) => setState((current) => [...current, ...items]);
  588. const prepend = (...items) => setState((current) => [...items, ...current]);
  589. const insert = (index, ...items) => setState((current) => [...current.slice(0, index), ...items, ...current.slice(index)]);
  590. const apply = (fn) => setState((current) => current.map((item, index) => fn(item, index)));
  591. const remove = (...indices) => setState((current) => current.filter((_, index) => !indices.includes(index)));
  592. const pop = () => setState((current) => {
  593. const cloned = [...current];
  594. cloned.pop();
  595. return cloned;
  596. });
  597. const shift = () => setState((current) => {
  598. const cloned = [...current];
  599. cloned.shift();
  600. return cloned;
  601. });
  602. const reorder = ({ from, to }) => setState((current) => {
  603. const cloned = [...current];
  604. const item = current[from];
  605. cloned.splice(from, 1);
  606. cloned.splice(to, 0, item);
  607. return cloned;
  608. });
  609. const swap = ({ from, to }) => setState((current) => {
  610. const cloned = [...current];
  611. const fromItem = cloned[from];
  612. const toItem = cloned[to];
  613. cloned.splice(to, 1, fromItem);
  614. cloned.splice(from, 1, toItem);
  615. return cloned;
  616. });
  617. const setItem = (index, item) => setState((current) => {
  618. const cloned = [...current];
  619. cloned[index] = item;
  620. return cloned;
  621. });
  622. const setItemProp = (index, prop, value) => setState((current) => {
  623. const cloned = [...current];
  624. cloned[index] = { ...cloned[index], [prop]: value };
  625. return cloned;
  626. });
  627. const applyWhere = (condition, fn) => setState(
  628. (current) => current.map((item, index) => condition(item, index) ? fn(item, index) : item)
  629. );
  630. const filter = (fn) => {
  631. setState((current) => current.filter(fn));
  632. };
  633. return [
  634. state,
  635. {
  636. setState,
  637. append,
  638. prepend,
  639. insert,
  640. pop,
  641. shift,
  642. apply,
  643. applyWhere,
  644. remove,
  645. reorder,
  646. swap,
  647. setItem,
  648. setItemProp,
  649. filter
  650. }
  651. ];
  652. }
  653. function useWindowEvent(type, listener, options) {
  654. React.useEffect(() => {
  655. window.addEventListener(type, listener, options);
  656. return () => window.removeEventListener(type, listener, options);
  657. }, [type, listener]);
  658. }
  659.  
  660. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/use-local-storage/create-storage.mjs
  661. function serializeJSON(value, hookName = "use-local-storage") {
  662. try {
  663. return JSON.stringify(value);
  664. } catch (error) {
  665. throw new Error(`@mantine/hooks ${hookName}: Failed to serialize the value`);
  666. }
  667. }
  668. function deserializeJSON(value) {
  669. try {
  670. return value && JSON.parse(value);
  671. } catch {
  672. return value;
  673. }
  674. }
  675. function createStorageHandler(type) {
  676. const getItem = (key) => {
  677. try {
  678. return window[type].getItem(key);
  679. } catch (error) {
  680. console.warn("use-local-storage: Failed to get value from storage, localStorage is blocked");
  681. return null;
  682. }
  683. };
  684. const setItem = (key, value) => {
  685. try {
  686. window[type].setItem(key, value);
  687. } catch (error) {
  688. console.warn("use-local-storage: Failed to set value to storage, localStorage is blocked");
  689. }
  690. };
  691. const removeItem = (key) => {
  692. try {
  693. window[type].removeItem(key);
  694. } catch (error) {
  695. console.warn(
  696. "use-local-storage: Failed to remove value from storage, localStorage is blocked"
  697. );
  698. }
  699. };
  700. return { getItem, setItem, removeItem };
  701. }
  702. function createStorage(type, hookName) {
  703. const eventName = type === "localStorage" ? "mantine-local-storage" : "mantine-session-storage";
  704. const { getItem, setItem, removeItem } = createStorageHandler(type);
  705. return function useStorage({
  706. key,
  707. defaultValue,
  708. getInitialValueInEffect = true,
  709. deserialize = deserializeJSON,
  710. serialize = (value) => serializeJSON(value, hookName)
  711. }) {
  712. const readStorageValue = React.useCallback(
  713. (skipStorage) => {
  714. let storageBlockedOrSkipped;
  715. try {
  716. storageBlockedOrSkipped = typeof window === "undefined" || !(type in window) || window[type] === null || !!skipStorage;
  717. } catch (_e) {
  718. storageBlockedOrSkipped = true;
  719. }
  720. if (storageBlockedOrSkipped) {
  721. return defaultValue;
  722. }
  723. const storageValue = getItem(key);
  724. return storageValue !== null ? deserialize(storageValue) : defaultValue;
  725. },
  726. [key, defaultValue]
  727. );
  728. const [value, setValue] = React.useState(readStorageValue(getInitialValueInEffect));
  729. const setStorageValue = React.useCallback(
  730. (val) => {
  731. if (val instanceof Function) {
  732. setValue((current) => {
  733. const result = val(current);
  734. setItem(key, serialize(result));
  735. window.dispatchEvent(
  736. new CustomEvent(eventName, { detail: { key, value: val(current) } })
  737. );
  738. return result;
  739. });
  740. } else {
  741. setItem(key, serialize(val));
  742. window.dispatchEvent(new CustomEvent(eventName, { detail: { key, value: val } }));
  743. setValue(val);
  744. }
  745. },
  746. [key]
  747. );
  748. const removeStorageValue = React.useCallback(() => {
  749. removeItem(key);
  750. window.dispatchEvent(new CustomEvent(eventName, { detail: { key, value: defaultValue } }));
  751. }, []);
  752. useWindowEvent("storage", (event) => {
  753. if (event.storageArea === window[type] && event.key === key) {
  754. setValue(deserialize(event.newValue ?? void 0));
  755. }
  756. });
  757. useWindowEvent(eventName, (event) => {
  758. if (event.detail.key === key) {
  759. setValue(event.detail.value);
  760. }
  761. });
  762. React.useEffect(() => {
  763. if (defaultValue !== void 0 && value === void 0) {
  764. setStorageValue(defaultValue);
  765. }
  766. }, [defaultValue, value, setStorageValue]);
  767. React.useEffect(() => {
  768. const val = readStorageValue();
  769. val !== void 0 && setStorageValue(val);
  770. }, []);
  771. return [value === void 0 ? defaultValue : value, setStorageValue, removeStorageValue];
  772. };
  773. }
  774. function readValue(type) {
  775. const { getItem } = createStorageHandler(type);
  776. return function read({
  777. key,
  778. defaultValue,
  779. deserialize = deserializeJSON
  780. }) {
  781. let storageBlockedOrSkipped;
  782. try {
  783. storageBlockedOrSkipped = typeof window === "undefined" || !(type in window) || window[type] === null;
  784. } catch (_e) {
  785. storageBlockedOrSkipped = true;
  786. }
  787. if (storageBlockedOrSkipped) {
  788. return defaultValue;
  789. }
  790. const storageValue = getItem(key);
  791. return storageValue !== null ? deserialize(storageValue) : defaultValue;
  792. };
  793. }
  794.  
  795. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/use-local-storage/use-local-storage.mjs
  796. function useLocalStorage(props) {
  797. return createStorage("localStorage", "use-local-storage")(props);
  798. }
  799. var readLocalStorageValue = readValue("localStorage");
  800.  
  801. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/use-session-storage/use-session-storage.mjs
  802. function useSessionStorage(props) {
  803. return createStorage("sessionStorage", "use-session-storage")(props);
  804. }
  805. var readSessionStorageValue = readValue("sessionStorage");
  806. function assignRef(ref, value) {
  807. if (typeof ref === "function") {
  808. ref(value);
  809. } else if (typeof ref === "object" && ref !== null && "current" in ref) {
  810. ref.current = value;
  811. }
  812. }
  813. function mergeRefs(...refs) {
  814. return (node) => {
  815. refs.forEach((ref) => assignRef(ref, node));
  816. };
  817. }
  818. function useMergedRef(...refs) {
  819. return React.useCallback(mergeRefs(...refs), refs);
  820. }
  821. function useMouse(options = { resetOnExit: false }) {
  822. const [position, setPosition] = React.useState({ x: 0, y: 0 });
  823. const ref = React.useRef();
  824. const setMousePosition = (event) => {
  825. if (ref.current) {
  826. const rect = event.currentTarget.getBoundingClientRect();
  827. const x = Math.max(
  828. 0,
  829. Math.round(event.pageX - rect.left - (window.pageXOffset || window.scrollX))
  830. );
  831. const y = Math.max(
  832. 0,
  833. Math.round(event.pageY - rect.top - (window.pageYOffset || window.scrollY))
  834. );
  835. setPosition({ x, y });
  836. } else {
  837. setPosition({ x: event.clientX, y: event.clientY });
  838. }
  839. };
  840. const resetMousePosition = () => setPosition({ x: 0, y: 0 });
  841. React.useEffect(() => {
  842. const element = ref?.current ? ref.current : document;
  843. element.addEventListener("mousemove", setMousePosition);
  844. if (options.resetOnExit)
  845. element.addEventListener("mouseleave", resetMousePosition);
  846. return () => {
  847. element.removeEventListener("mousemove", setMousePosition);
  848. if (options.resetOnExit)
  849. element.removeEventListener("mouseleave", resetMousePosition);
  850. };
  851. }, [ref.current]);
  852. return { ref, ...position };
  853. }
  854. function clampUseMovePosition(position) {
  855. return {
  856. x: clamp(position.x, 0, 1),
  857. y: clamp(position.y, 0, 1)
  858. };
  859. }
  860. function useMove(onChange, handlers, dir = "ltr") {
  861. const ref = React.useRef(null);
  862. const mounted = React.useRef(false);
  863. const isSliding = React.useRef(false);
  864. const frame = React.useRef(0);
  865. const [active, setActive] = React.useState(false);
  866. React.useEffect(() => {
  867. mounted.current = true;
  868. }, []);
  869. React.useEffect(() => {
  870. const onScrub = ({ x, y }) => {
  871. cancelAnimationFrame(frame.current);
  872. frame.current = requestAnimationFrame(() => {
  873. if (mounted.current && ref.current) {
  874. ref.current.style.userSelect = "none";
  875. const rect = ref.current.getBoundingClientRect();
  876. if (rect.width && rect.height) {
  877. const _x = clamp((x - rect.left) / rect.width, 0, 1);
  878. onChange({
  879. x: dir === "ltr" ? _x : 1 - _x,
  880. y: clamp((y - rect.top) / rect.height, 0, 1)
  881. });
  882. }
  883. }
  884. });
  885. };
  886. const bindEvents = () => {
  887. document.addEventListener("mousemove", onMouseMove);
  888. document.addEventListener("mouseup", stopScrubbing);
  889. document.addEventListener("touchmove", onTouchMove);
  890. document.addEventListener("touchend", stopScrubbing);
  891. };
  892. const unbindEvents = () => {
  893. document.removeEventListener("mousemove", onMouseMove);
  894. document.removeEventListener("mouseup", stopScrubbing);
  895. document.removeEventListener("touchmove", onTouchMove);
  896. document.removeEventListener("touchend", stopScrubbing);
  897. };
  898. const startScrubbing = () => {
  899. if (!isSliding.current && mounted.current) {
  900. isSliding.current = true;
  901. typeof handlers?.onScrubStart === "function" && handlers.onScrubStart();
  902. setActive(true);
  903. bindEvents();
  904. }
  905. };
  906. const stopScrubbing = () => {
  907. if (isSliding.current && mounted.current) {
  908. isSliding.current = false;
  909. setActive(false);
  910. unbindEvents();
  911. setTimeout(() => {
  912. typeof handlers?.onScrubEnd === "function" && handlers.onScrubEnd();
  913. }, 0);
  914. }
  915. };
  916. const onMouseDown = (event) => {
  917. startScrubbing();
  918. event.preventDefault();
  919. onMouseMove(event);
  920. };
  921. const onMouseMove = (event) => onScrub({ x: event.clientX, y: event.clientY });
  922. const onTouchStart = (event) => {
  923. if (event.cancelable) {
  924. event.preventDefault();
  925. }
  926. startScrubbing();
  927. onTouchMove(event);
  928. };
  929. const onTouchMove = (event) => {
  930. if (event.cancelable) {
  931. event.preventDefault();
  932. }
  933. onScrub({ x: event.changedTouches[0].clientX, y: event.changedTouches[0].clientY });
  934. };
  935. ref.current?.addEventListener("mousedown", onMouseDown);
  936. ref.current?.addEventListener("touchstart", onTouchStart, { passive: false });
  937. return () => {
  938. if (ref.current) {
  939. ref.current.removeEventListener("mousedown", onMouseDown);
  940. ref.current.removeEventListener("touchstart", onTouchStart);
  941. }
  942. };
  943. }, [dir, onChange]);
  944. return { ref, active };
  945. }
  946. function useUncontrolled({
  947. value,
  948. defaultValue,
  949. finalValue,
  950. onChange = () => {
  951. }
  952. }) {
  953. const [uncontrolledValue, setUncontrolledValue] = React.useState(
  954. defaultValue !== void 0 ? defaultValue : finalValue
  955. );
  956. const handleUncontrolledChange = (val, ...payload) => {
  957. setUncontrolledValue(val);
  958. onChange?.(val, ...payload);
  959. };
  960. if (value !== void 0) {
  961. return [value, onChange, true];
  962. }
  963. return [uncontrolledValue, handleUncontrolledChange, false];
  964. }
  965.  
  966. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/use-pagination/use-pagination.mjs
  967. function range2(start, end) {
  968. const length = end - start + 1;
  969. return Array.from({ length }, (_, index) => index + start);
  970. }
  971. var DOTS = "dots";
  972. function usePagination({
  973. total,
  974. siblings = 1,
  975. boundaries = 1,
  976. page,
  977. initialPage = 1,
  978. onChange
  979. }) {
  980. const _total = Math.max(Math.trunc(total), 0);
  981. const [activePage, setActivePage] = useUncontrolled({
  982. value: page,
  983. onChange,
  984. defaultValue: initialPage,
  985. finalValue: initialPage
  986. });
  987. const setPage = (pageNumber) => {
  988. if (pageNumber <= 0) {
  989. setActivePage(1);
  990. } else if (pageNumber > _total) {
  991. setActivePage(_total);
  992. } else {
  993. setActivePage(pageNumber);
  994. }
  995. };
  996. const next = () => setPage(activePage + 1);
  997. const previous = () => setPage(activePage - 1);
  998. const first = () => setPage(1);
  999. const last = () => setPage(_total);
  1000. const paginationRange = React.useMemo(() => {
  1001. const totalPageNumbers = siblings * 2 + 3 + boundaries * 2;
  1002. if (totalPageNumbers >= _total) {
  1003. return range2(1, _total);
  1004. }
  1005. const leftSiblingIndex = Math.max(activePage - siblings, boundaries);
  1006. const rightSiblingIndex = Math.min(activePage + siblings, _total - boundaries);
  1007. const shouldShowLeftDots = leftSiblingIndex > boundaries + 2;
  1008. const shouldShowRightDots = rightSiblingIndex < _total - (boundaries + 1);
  1009. if (!shouldShowLeftDots && shouldShowRightDots) {
  1010. const leftItemCount = siblings * 2 + boundaries + 2;
  1011. return [...range2(1, leftItemCount), DOTS, ...range2(_total - (boundaries - 1), _total)];
  1012. }
  1013. if (shouldShowLeftDots && !shouldShowRightDots) {
  1014. const rightItemCount = boundaries + 1 + 2 * siblings;
  1015. return [...range2(1, boundaries), DOTS, ...range2(_total - rightItemCount, _total)];
  1016. }
  1017. return [
  1018. ...range2(1, boundaries),
  1019. DOTS,
  1020. ...range2(leftSiblingIndex, rightSiblingIndex),
  1021. DOTS,
  1022. ...range2(_total - boundaries + 1, _total)
  1023. ];
  1024. }, [_total, siblings, activePage]);
  1025. return {
  1026. range: paginationRange,
  1027. active: activePage,
  1028. setPage,
  1029. next,
  1030. previous,
  1031. first,
  1032. last
  1033. };
  1034. }
  1035. function useQueue({ initialValues = [], limit }) {
  1036. const [{ state, queue }, setState] = React.useState({
  1037. state: initialValues.slice(0, limit),
  1038. queue: initialValues.slice(limit)
  1039. });
  1040. const add = (...items) => setState((current) => {
  1041. const results = [...current.state, ...current.queue, ...items];
  1042. return {
  1043. state: results.slice(0, limit),
  1044. queue: results.slice(limit)
  1045. };
  1046. });
  1047. const update = (fn) => setState((current) => {
  1048. const results = fn([...current.state, ...current.queue]);
  1049. return {
  1050. state: results.slice(0, limit),
  1051. queue: results.slice(limit)
  1052. };
  1053. });
  1054. const cleanQueue = () => setState((current) => ({ state: current.state, queue: [] }));
  1055. return {
  1056. state,
  1057. queue,
  1058. add,
  1059. update,
  1060. cleanQueue
  1061. };
  1062. }
  1063. function usePageLeave(onPageLeave) {
  1064. React.useEffect(() => {
  1065. document.documentElement.addEventListener("mouseleave", onPageLeave);
  1066. return () => document.documentElement.removeEventListener("mouseleave", onPageLeave);
  1067. }, []);
  1068. }
  1069.  
  1070. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/use-reduced-motion/use-reduced-motion.mjs
  1071. function useReducedMotion(initialValue, options) {
  1072. return useMediaQuery("(prefers-reduced-motion: reduce)", initialValue, options);
  1073. }
  1074.  
  1075. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/use-scroll-into-view/utils/ease-in-out-quad.mjs
  1076. var easeInOutQuad = (t) => t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
  1077.  
  1078. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/use-scroll-into-view/utils/get-relative-position.mjs
  1079. var getRelativePosition = ({
  1080. axis,
  1081. target,
  1082. parent,
  1083. alignment,
  1084. offset,
  1085. isList
  1086. }) => {
  1087. if (!target || !parent && typeof document === "undefined") {
  1088. return 0;
  1089. }
  1090. const isCustomParent = !!parent;
  1091. const parentElement = parent || document.body;
  1092. const parentPosition = parentElement.getBoundingClientRect();
  1093. const targetPosition = target.getBoundingClientRect();
  1094. const getDiff = (property) => targetPosition[property] - parentPosition[property];
  1095. if (axis === "y") {
  1096. const diff = getDiff("top");
  1097. if (diff === 0)
  1098. return 0;
  1099. if (alignment === "start") {
  1100. const distance = diff - offset;
  1101. const shouldScroll = distance <= targetPosition.height * (isList ? 0 : 1) || !isList;
  1102. return shouldScroll ? distance : 0;
  1103. }
  1104. const parentHeight = isCustomParent ? parentPosition.height : window.innerHeight;
  1105. if (alignment === "end") {
  1106. const distance = diff + offset - parentHeight + targetPosition.height;
  1107. const shouldScroll = distance >= -targetPosition.height * (isList ? 0 : 1) || !isList;
  1108. return shouldScroll ? distance : 0;
  1109. }
  1110. if (alignment === "center") {
  1111. return diff - parentHeight / 2 + targetPosition.height / 2;
  1112. }
  1113. return 0;
  1114. }
  1115. if (axis === "x") {
  1116. const diff = getDiff("left");
  1117. if (diff === 0)
  1118. return 0;
  1119. if (alignment === "start") {
  1120. const distance = diff - offset;
  1121. const shouldScroll = distance <= targetPosition.width || !isList;
  1122. return shouldScroll ? distance : 0;
  1123. }
  1124. const parentWidth = isCustomParent ? parentPosition.width : window.innerWidth;
  1125. if (alignment === "end") {
  1126. const distance = diff + offset - parentWidth + targetPosition.width;
  1127. const shouldScroll = distance >= -targetPosition.width || !isList;
  1128. return shouldScroll ? distance : 0;
  1129. }
  1130. if (alignment === "center") {
  1131. return diff - parentWidth / 2 + targetPosition.width / 2;
  1132. }
  1133. return 0;
  1134. }
  1135. return 0;
  1136. };
  1137.  
  1138. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/use-scroll-into-view/utils/get-scroll-start.mjs
  1139. var getScrollStart = ({ axis, parent }) => {
  1140. if (!parent && typeof document === "undefined") {
  1141. return 0;
  1142. }
  1143. const method = axis === "y" ? "scrollTop" : "scrollLeft";
  1144. if (parent) {
  1145. return parent[method];
  1146. }
  1147. const { body, documentElement } = document;
  1148. return body[method] + documentElement[method];
  1149. };
  1150.  
  1151. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/use-scroll-into-view/utils/set-scroll-param.mjs
  1152. var setScrollParam = ({ axis, parent, distance }) => {
  1153. if (!parent && typeof document === "undefined") {
  1154. return;
  1155. }
  1156. const method = axis === "y" ? "scrollTop" : "scrollLeft";
  1157. if (parent) {
  1158. parent[method] = distance;
  1159. } else {
  1160. const { body, documentElement } = document;
  1161. body[method] = distance;
  1162. documentElement[method] = distance;
  1163. }
  1164. };
  1165.  
  1166. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/use-scroll-into-view/use-scroll-into-view.mjs
  1167. function useScrollIntoView({
  1168. duration = 1250,
  1169. axis = "y",
  1170. onScrollFinish,
  1171. easing = easeInOutQuad,
  1172. offset = 0,
  1173. cancelable = true,
  1174. isList = false
  1175. } = {}) {
  1176. const frameID = React.useRef(0);
  1177. const startTime = React.useRef(0);
  1178. const shouldStop = React.useRef(false);
  1179. const scrollableRef = React.useRef(null);
  1180. const targetRef = React.useRef(null);
  1181. const reducedMotion = useReducedMotion();
  1182. const cancel = () => {
  1183. if (frameID.current) {
  1184. cancelAnimationFrame(frameID.current);
  1185. }
  1186. };
  1187. const scrollIntoView = React.useCallback(
  1188. ({ alignment = "start" } = {}) => {
  1189. shouldStop.current = false;
  1190. if (frameID.current) {
  1191. cancel();
  1192. }
  1193. const start = getScrollStart({ parent: scrollableRef.current, axis }) ?? 0;
  1194. const change = getRelativePosition({
  1195. parent: scrollableRef.current,
  1196. target: targetRef.current,
  1197. axis,
  1198. alignment,
  1199. offset,
  1200. isList
  1201. }) - (scrollableRef.current ? 0 : start);
  1202. function animateScroll() {
  1203. if (startTime.current === 0) {
  1204. startTime.current = performance.now();
  1205. }
  1206. const now = performance.now();
  1207. const elapsed = now - startTime.current;
  1208. const t = reducedMotion || duration === 0 ? 1 : elapsed / duration;
  1209. const distance = start + change * easing(t);
  1210. setScrollParam({
  1211. parent: scrollableRef.current,
  1212. axis,
  1213. distance
  1214. });
  1215. if (!shouldStop.current && t < 1) {
  1216. frameID.current = requestAnimationFrame(animateScroll);
  1217. } else {
  1218. typeof onScrollFinish === "function" && onScrollFinish();
  1219. startTime.current = 0;
  1220. frameID.current = 0;
  1221. cancel();
  1222. }
  1223. }
  1224. animateScroll();
  1225. },
  1226. [axis, duration, easing, isList, offset, onScrollFinish, reducedMotion]
  1227. );
  1228. const handleStop = () => {
  1229. if (cancelable) {
  1230. shouldStop.current = true;
  1231. }
  1232. };
  1233. useWindowEvent("wheel", handleStop, {
  1234. passive: true
  1235. });
  1236. useWindowEvent("touchmove", handleStop, {
  1237. passive: true
  1238. });
  1239. React.useEffect(() => cancel, []);
  1240. return {
  1241. scrollableRef,
  1242. targetRef,
  1243. scrollIntoView,
  1244. cancel
  1245. };
  1246. }
  1247. var defaultState = {
  1248. x: 0,
  1249. y: 0,
  1250. width: 0,
  1251. height: 0,
  1252. top: 0,
  1253. left: 0,
  1254. bottom: 0,
  1255. right: 0
  1256. };
  1257. function useResizeObserver(options) {
  1258. const frameID = React.useRef(0);
  1259. const ref = React.useRef(null);
  1260. const [rect, setRect] = React.useState(defaultState);
  1261. const observer = React.useMemo(
  1262. () => typeof window !== "undefined" ? new ResizeObserver((entries) => {
  1263. const entry = entries[0];
  1264. if (entry) {
  1265. cancelAnimationFrame(frameID.current);
  1266. frameID.current = requestAnimationFrame(() => {
  1267. if (ref.current) {
  1268. setRect(entry.contentRect);
  1269. }
  1270. });
  1271. }
  1272. }) : null,
  1273. []
  1274. );
  1275. React.useEffect(() => {
  1276. if (ref.current) {
  1277. observer?.observe(ref.current, options);
  1278. }
  1279. return () => {
  1280. observer?.disconnect();
  1281. if (frameID.current) {
  1282. cancelAnimationFrame(frameID.current);
  1283. }
  1284. };
  1285. }, [ref.current]);
  1286. return [ref, rect];
  1287. }
  1288. function useElementSize(options) {
  1289. const [ref, { width, height }] = useResizeObserver(options);
  1290. return { ref, width, height };
  1291. }
  1292. function shallowCompare(prevValue, currValue) {
  1293. if (!prevValue || !currValue) {
  1294. return false;
  1295. }
  1296. if (prevValue === currValue) {
  1297. return true;
  1298. }
  1299. if (prevValue.length !== currValue.length) {
  1300. return false;
  1301. }
  1302. for (let i = 0; i < prevValue.length; i += 1) {
  1303. if (!shallowEqual(prevValue[i], currValue[i])) {
  1304. return false;
  1305. }
  1306. }
  1307. return true;
  1308. }
  1309. function useShallowCompare(dependencies) {
  1310. const ref = React.useRef([]);
  1311. const updateRef = React.useRef(0);
  1312. if (!shallowCompare(ref.current, dependencies)) {
  1313. ref.current = dependencies;
  1314. updateRef.current += 1;
  1315. }
  1316. return [updateRef.current];
  1317. }
  1318. function useShallowEffect(cb, dependencies) {
  1319. React.useEffect(cb, useShallowCompare(dependencies));
  1320. }
  1321. function useToggle(options = [false, true]) {
  1322. const [[option], toggle] = React.useReducer((state, action) => {
  1323. const value = action instanceof Function ? action(state[0]) : action;
  1324. const index = Math.abs(state.indexOf(value));
  1325. return state.slice(index).concat(state.slice(0, index));
  1326. }, options);
  1327. return [option, toggle];
  1328. }
  1329. var eventListerOptions = {
  1330. passive: true
  1331. };
  1332. function useViewportSize() {
  1333. const [windowSize, setWindowSize] = React.useState({
  1334. width: 0,
  1335. height: 0
  1336. });
  1337. const setSize = React.useCallback(() => {
  1338. setWindowSize({ width: window.innerWidth || 0, height: window.innerHeight || 0 });
  1339. }, []);
  1340. useWindowEvent("resize", setSize, eventListerOptions);
  1341. useWindowEvent("orientationchange", setSize, eventListerOptions);
  1342. React.useEffect(setSize, []);
  1343. return windowSize;
  1344. }
  1345. function getScrollPosition() {
  1346. return typeof window !== "undefined" ? { x: window.pageXOffset, y: window.pageYOffset } : { x: 0, y: 0 };
  1347. }
  1348. function scrollTo({ x, y }) {
  1349. if (typeof window !== "undefined") {
  1350. const scrollOptions = { behavior: "smooth" };
  1351. if (typeof x === "number") {
  1352. scrollOptions.left = x;
  1353. }
  1354. if (typeof y === "number") {
  1355. scrollOptions.top = y;
  1356. }
  1357. window.scrollTo(scrollOptions);
  1358. }
  1359. }
  1360. function useWindowScroll() {
  1361. const [position, setPosition] = React.useState({ x: 0, y: 0 });
  1362. useWindowEvent("scroll", () => setPosition(getScrollPosition()));
  1363. useWindowEvent("resize", () => setPosition(getScrollPosition()));
  1364. React.useEffect(() => {
  1365. setPosition(getScrollPosition());
  1366. }, []);
  1367. return [position, scrollTo];
  1368. }
  1369. function useIntersection(options) {
  1370. const [entry, setEntry] = React.useState(null);
  1371. const observer = React.useRef(null);
  1372. const ref = React.useCallback(
  1373. (element) => {
  1374. if (observer.current) {
  1375. observer.current.disconnect();
  1376. observer.current = null;
  1377. }
  1378. if (element === null) {
  1379. setEntry(null);
  1380. return;
  1381. }
  1382. observer.current = new IntersectionObserver(([_entry]) => {
  1383. setEntry(_entry);
  1384. }, options);
  1385. observer.current.observe(element);
  1386. },
  1387. [options?.rootMargin, options?.root, options?.threshold]
  1388. );
  1389. return { ref, entry };
  1390. }
  1391. function useHash({ getInitialValueInEffect = true } = {}) {
  1392. const [hash, setHashValue] = React.useState(
  1393. getInitialValueInEffect ? "" : window.location.hash || ""
  1394. );
  1395. const setHash = (value) => {
  1396. const valueWithHash = value.startsWith("#") ? value : `#${value}`;
  1397. window.location.hash = valueWithHash;
  1398. setHashValue(valueWithHash);
  1399. };
  1400. useWindowEvent("hashchange", () => {
  1401. const newHash = window.location.hash;
  1402. if (hash !== newHash) {
  1403. setHashValue(newHash);
  1404. }
  1405. });
  1406. React.useEffect(() => {
  1407. if (getInitialValueInEffect) {
  1408. setHashValue(window.location.hash);
  1409. }
  1410. }, []);
  1411. return [hash, setHash];
  1412. }
  1413.  
  1414. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/use-hotkeys/parse-hotkey.mjs
  1415. function parseHotkey(hotkey) {
  1416. const keys = hotkey.toLowerCase().split("+").map((part) => part.trim());
  1417. const modifiers = {
  1418. alt: keys.includes("alt"),
  1419. ctrl: keys.includes("ctrl"),
  1420. meta: keys.includes("meta"),
  1421. mod: keys.includes("mod"),
  1422. shift: keys.includes("shift")
  1423. };
  1424. const reservedKeys = ["alt", "ctrl", "meta", "shift", "mod"];
  1425. const freeKey = keys.find((key) => !reservedKeys.includes(key));
  1426. return {
  1427. ...modifiers,
  1428. key: freeKey
  1429. };
  1430. }
  1431. function isExactHotkey(hotkey, event) {
  1432. const { alt, ctrl, meta, mod, shift, key } = hotkey;
  1433. const { altKey, ctrlKey, metaKey, shiftKey, key: pressedKey } = event;
  1434. if (alt !== altKey) {
  1435. return false;
  1436. }
  1437. if (mod) {
  1438. if (!ctrlKey && !metaKey) {
  1439. return false;
  1440. }
  1441. } else {
  1442. if (ctrl !== ctrlKey) {
  1443. return false;
  1444. }
  1445. if (meta !== metaKey) {
  1446. return false;
  1447. }
  1448. }
  1449. if (shift !== shiftKey) {
  1450. return false;
  1451. }
  1452. if (key && (pressedKey.toLowerCase() === key.toLowerCase() || event.code.replace("Key", "").toLowerCase() === key.toLowerCase())) {
  1453. return true;
  1454. }
  1455. return false;
  1456. }
  1457. function getHotkeyMatcher(hotkey) {
  1458. return (event) => isExactHotkey(parseHotkey(hotkey), event);
  1459. }
  1460. function getHotkeyHandler(hotkeys) {
  1461. return (event) => {
  1462. const _event = "nativeEvent" in event ? event.nativeEvent : event;
  1463. hotkeys.forEach(([hotkey, handler, options = { preventDefault: true }]) => {
  1464. if (getHotkeyMatcher(hotkey)(_event)) {
  1465. if (options.preventDefault) {
  1466. event.preventDefault();
  1467. }
  1468. handler(_event);
  1469. }
  1470. });
  1471. };
  1472. }
  1473.  
  1474. // ../esmd/npm/@mantine/hooks@7.11.0/node_modules/.pnpm/@mantine+hooks@7.11.0_react@18.3.1/node_modules/@mantine/hooks/esm/use-hotkeys/use-hotkeys.mjs
  1475. function shouldFireEvent(event, tagsToIgnore, triggerOnContentEditable = false) {
  1476. if (event.target instanceof HTMLElement) {
  1477. if (triggerOnContentEditable) {
  1478. return !tagsToIgnore.includes(event.target.tagName);
  1479. }
  1480. return !event.target.isContentEditable && !tagsToIgnore.includes(event.target.tagName);
  1481. }
  1482. return true;
  1483. }
  1484. function useHotkeys(hotkeys, tagsToIgnore = ["INPUT", "TEXTAREA", "SELECT"], triggerOnContentEditable = false) {
  1485. React.useEffect(() => {
  1486. const keydownListener = (event) => {
  1487. hotkeys.forEach(([hotkey, handler, options = { preventDefault: true }]) => {
  1488. if (getHotkeyMatcher(hotkey)(event) && shouldFireEvent(event, tagsToIgnore, triggerOnContentEditable)) {
  1489. if (options.preventDefault) {
  1490. event.preventDefault();
  1491. }
  1492. handler(event);
  1493. }
  1494. });
  1495. };
  1496. document.documentElement.addEventListener("keydown", keydownListener);
  1497. return () => document.documentElement.removeEventListener("keydown", keydownListener);
  1498. }, [hotkeys]);
  1499. }
  1500. function getFullscreenElement() {
  1501. const _document = window.document;
  1502. const fullscreenElement = _document.fullscreenElement || _document.webkitFullscreenElement || _document.mozFullScreenElement || _document.msFullscreenElement;
  1503. return fullscreenElement;
  1504. }
  1505. async function exitFullscreen() {
  1506. const _document = window.document;
  1507. if (typeof _document.exitFullscreen === "function")
  1508. return _document.exitFullscreen();
  1509. if (typeof _document.msExitFullscreen === "function")
  1510. return _document.msExitFullscreen();
  1511. if (typeof _document.webkitExitFullscreen === "function")
  1512. return _document.webkitExitFullscreen();
  1513. if (typeof _document.mozCancelFullScreen === "function")
  1514. return _document.mozCancelFullScreen();
  1515. return null;
  1516. }
  1517. async function enterFullScreen(element) {
  1518. const _element = element;
  1519. return _element.requestFullscreen?.() || _element.msRequestFullscreen?.() || _element.webkitEnterFullscreen?.() || _element.webkitRequestFullscreen?.() || _element.mozRequestFullscreen?.();
  1520. }
  1521. var prefixes = ["", "webkit", "moz", "ms"];
  1522. function addEvents(element, {
  1523. onFullScreen,
  1524. onError
  1525. }) {
  1526. prefixes.forEach((prefix) => {
  1527. element.addEventListener(`${prefix}fullscreenchange`, onFullScreen);
  1528. element.addEventListener(`${prefix}fullscreenerror`, onError);
  1529. });
  1530. return () => {
  1531. prefixes.forEach((prefix) => {
  1532. element.removeEventListener(`${prefix}fullscreenchange`, onFullScreen);
  1533. element.removeEventListener(`${prefix}fullscreenerror`, onError);
  1534. });
  1535. };
  1536. }
  1537. function useFullscreen() {
  1538. const [fullscreen, setFullscreen] = React.useState(false);
  1539. const _ref = React.useRef();
  1540. const handleFullscreenChange = React.useCallback(
  1541. (event) => {
  1542. setFullscreen(event.target === getFullscreenElement());
  1543. },
  1544. [setFullscreen]
  1545. );
  1546. const handleFullscreenError = React.useCallback(
  1547. (event) => {
  1548. setFullscreen(false);
  1549. console.error(
  1550. `[@mantine/hooks] use-fullscreen: Error attempting full-screen mode method: ${event} (${event.target})`
  1551. );
  1552. },
  1553. [setFullscreen]
  1554. );
  1555. const toggle = React.useCallback(async () => {
  1556. if (!getFullscreenElement()) {
  1557. await enterFullScreen(_ref.current);
  1558. } else {
  1559. await exitFullscreen();
  1560. }
  1561. }, []);
  1562. const ref = React.useCallback((element) => {
  1563. if (element === null) {
  1564. _ref.current = window.document.documentElement;
  1565. } else {
  1566. _ref.current = element;
  1567. }
  1568. }, []);
  1569. React.useEffect(() => {
  1570. if (!_ref.current && window.document) {
  1571. _ref.current = window.document.documentElement;
  1572. return addEvents(_ref.current, {
  1573. onFullScreen: handleFullscreenChange,
  1574. onError: handleFullscreenError
  1575. });
  1576. }
  1577. if (_ref.current) {
  1578. return addEvents(_ref.current, {
  1579. onFullScreen: handleFullscreenChange,
  1580. onError: handleFullscreenError
  1581. });
  1582. }
  1583. return void 0;
  1584. }, []);
  1585. return { ref, toggle, fullscreen };
  1586. }
  1587. function useLogger(componentName, props) {
  1588. React.useEffect(() => {
  1589. console.log(`${componentName} mounted`, ...props);
  1590. return () => console.log(`${componentName} unmounted`);
  1591. }, []);
  1592. useDidUpdate(() => {
  1593. console.log(`${componentName} updated`, ...props);
  1594. }, props);
  1595. return null;
  1596. }
  1597. function useHover() {
  1598. const [hovered, setHovered] = React.useState(false);
  1599. const ref = React.useRef(null);
  1600. const onMouseEnter = React.useCallback(() => setHovered(true), []);
  1601. const onMouseLeave = React.useCallback(() => setHovered(false), []);
  1602. React.useEffect(() => {
  1603. if (ref.current) {
  1604. ref.current.addEventListener("mouseenter", onMouseEnter);
  1605. ref.current.addEventListener("mouseleave", onMouseLeave);
  1606. return () => {
  1607. ref.current?.removeEventListener("mouseenter", onMouseEnter);
  1608. ref.current?.removeEventListener("mouseleave", onMouseLeave);
  1609. };
  1610. }
  1611. return void 0;
  1612. }, []);
  1613. return { ref, hovered };
  1614. }
  1615. function useValidatedState(initialValue, validation, initialValidationState) {
  1616. const [value, setValue] = React.useState(initialValue);
  1617. const [lastValidValue, setLastValidValue] = React.useState(
  1618. validation(initialValue) ? initialValue : void 0
  1619. );
  1620. const [valid, setValid] = React.useState(
  1621. typeof initialValidationState === "boolean" ? initialValidationState : validation(initialValue)
  1622. );
  1623. const onChange = (val) => {
  1624. if (validation(val)) {
  1625. setLastValidValue(val);
  1626. setValid(true);
  1627. } else {
  1628. setValid(false);
  1629. }
  1630. setValue(val);
  1631. };
  1632. return [{ value, lastValidValue, valid }, onChange];
  1633. }
  1634. function getOS() {
  1635. if (typeof window === "undefined") {
  1636. return "undetermined";
  1637. }
  1638. const { userAgent } = window.navigator;
  1639. const macosPlatforms = /(Macintosh)|(MacIntel)|(MacPPC)|(Mac68K)/i;
  1640. const windowsPlatforms = /(Win32)|(Win64)|(Windows)|(WinCE)/i;
  1641. const iosPlatforms = /(iPhone)|(iPad)|(iPod)/i;
  1642. if (macosPlatforms.test(userAgent)) {
  1643. return "macos";
  1644. }
  1645. if (iosPlatforms.test(userAgent)) {
  1646. return "ios";
  1647. }
  1648. if (windowsPlatforms.test(userAgent)) {
  1649. return "windows";
  1650. }
  1651. if (/Android/i.test(userAgent)) {
  1652. return "android";
  1653. }
  1654. if (/Linux/i.test(userAgent)) {
  1655. return "linux";
  1656. }
  1657. return "undetermined";
  1658. }
  1659. function useOs(options = { getValueInEffect: true }) {
  1660. const [value, setValue] = React.useState(options.getValueInEffect ? "undetermined" : getOS());
  1661. useIsomorphicEffect(() => {
  1662. if (options.getValueInEffect) {
  1663. setValue(getOS);
  1664. }
  1665. }, []);
  1666. return value;
  1667. }
  1668. function useSetState(initialState) {
  1669. const [state, _setState] = React.useState(initialState);
  1670. const setState = React.useCallback(
  1671. (statePartial) => _setState((current) => ({
  1672. ...current,
  1673. ...typeof statePartial === "function" ? statePartial(current) : statePartial
  1674. })),
  1675. []
  1676. );
  1677. return [state, setState];
  1678. }
  1679. function getInputOnChange(setValue) {
  1680. return (val) => {
  1681. if (!val) {
  1682. setValue(val);
  1683. } else if (typeof val === "function") {
  1684. setValue(val);
  1685. } else if (typeof val === "object" && "nativeEvent" in val) {
  1686. const { currentTarget } = val;
  1687. if (currentTarget.type === "checkbox") {
  1688. setValue(currentTarget.checked);
  1689. } else {
  1690. setValue(currentTarget.value);
  1691. }
  1692. } else {
  1693. setValue(val);
  1694. }
  1695. };
  1696. }
  1697. function useInputState(initialState) {
  1698. const [value, setValue] = React.useState(initialState);
  1699. return [value, getInputOnChange(setValue)];
  1700. }
  1701. function useEventListener(type, listener, options) {
  1702. const ref = React.useRef();
  1703. React.useEffect(() => {
  1704. if (ref.current) {
  1705. ref.current.addEventListener(type, listener, options);
  1706. return () => ref.current?.removeEventListener(type, listener, options);
  1707. }
  1708. return void 0;
  1709. }, [listener, options]);
  1710. return ref;
  1711. }
  1712. function useDisclosure(initialState = false, callbacks) {
  1713. const { onOpen, onClose } = callbacks || {};
  1714. const [opened, setOpened] = React.useState(initialState);
  1715. const open = React.useCallback(() => {
  1716. setOpened((isOpened) => {
  1717. if (!isOpened) {
  1718. onOpen?.();
  1719. return true;
  1720. }
  1721. return isOpened;
  1722. });
  1723. }, [onOpen]);
  1724. const close = React.useCallback(() => {
  1725. setOpened((isOpened) => {
  1726. if (isOpened) {
  1727. onClose?.();
  1728. return false;
  1729. }
  1730. return isOpened;
  1731. });
  1732. }, [onClose]);
  1733. const toggle = React.useCallback(() => {
  1734. opened ? close() : open();
  1735. }, [close, open, opened]);
  1736. return [opened, { open, close, toggle }];
  1737. }
  1738. function containsRelatedTarget(event) {
  1739. if (event.currentTarget instanceof HTMLElement && event.relatedTarget instanceof HTMLElement) {
  1740. return event.currentTarget.contains(event.relatedTarget);
  1741. }
  1742. return false;
  1743. }
  1744. function useFocusWithin({
  1745. onBlur,
  1746. onFocus
  1747. } = {}) {
  1748. const ref = React.useRef();
  1749. const [focused, _setFocused] = React.useState(false);
  1750. const focusedRef = React.useRef(false);
  1751. const setFocused = (value) => {
  1752. _setFocused(value);
  1753. focusedRef.current = value;
  1754. };
  1755. const handleFocusIn = (event) => {
  1756. if (!focusedRef.current) {
  1757. setFocused(true);
  1758. onFocus?.(event);
  1759. }
  1760. };
  1761. const handleFocusOut = (event) => {
  1762. if (focusedRef.current && !containsRelatedTarget(event)) {
  1763. setFocused(false);
  1764. onBlur?.(event);
  1765. }
  1766. };
  1767. React.useEffect(() => {
  1768. if (ref.current) {
  1769. ref.current.addEventListener("focusin", handleFocusIn);
  1770. ref.current.addEventListener("focusout", handleFocusOut);
  1771. return () => {
  1772. ref.current?.removeEventListener("focusin", handleFocusIn);
  1773. ref.current?.removeEventListener("focusout", handleFocusOut);
  1774. };
  1775. }
  1776. return void 0;
  1777. }, [handleFocusIn, handleFocusOut]);
  1778. return { ref, focused };
  1779. }
  1780. function getConnection() {
  1781. if (typeof navigator === "undefined") {
  1782. return {};
  1783. }
  1784. const _navigator = navigator;
  1785. const connection = _navigator.connection || _navigator.mozConnection || _navigator.webkitConnection;
  1786. if (!connection) {
  1787. return {};
  1788. }
  1789. return {
  1790. downlink: connection?.downlink,
  1791. downlinkMax: connection?.downlinkMax,
  1792. effectiveType: connection?.effectiveType,
  1793. rtt: connection?.rtt,
  1794. saveData: connection?.saveData,
  1795. type: connection?.type
  1796. };
  1797. }
  1798. function useNetwork() {
  1799. const [status, setStatus] = React.useState({
  1800. online: true
  1801. });
  1802. const handleConnectionChange = React.useCallback(
  1803. () => setStatus((current) => ({ ...current, ...getConnection() })),
  1804. []
  1805. );
  1806. useWindowEvent("online", () => setStatus({ online: true, ...getConnection() }));
  1807. useWindowEvent("offline", () => setStatus({ online: false, ...getConnection() }));
  1808. React.useEffect(() => {
  1809. const _navigator = navigator;
  1810. if (_navigator.connection) {
  1811. setStatus({ online: _navigator.onLine, ...getConnection() });
  1812. _navigator.connection.addEventListener("change", handleConnectionChange);
  1813. return () => _navigator.connection.removeEventListener("change", handleConnectionChange);
  1814. }
  1815. if (typeof _navigator.onLine === "boolean") {
  1816. setStatus((current) => ({ ...current, online: _navigator.onLine }));
  1817. }
  1818. return void 0;
  1819. }, []);
  1820. return status;
  1821. }
  1822. function useTimeout(callback, delay, options = { autoInvoke: false }) {
  1823. const timeoutRef = React.useRef(null);
  1824. const start = React.useCallback(
  1825. (...callbackParams) => {
  1826. if (!timeoutRef.current) {
  1827. timeoutRef.current = window.setTimeout(() => {
  1828. callback(callbackParams);
  1829. timeoutRef.current = null;
  1830. }, delay);
  1831. }
  1832. },
  1833. [delay]
  1834. );
  1835. const clear = React.useCallback(() => {
  1836. if (timeoutRef.current) {
  1837. window.clearTimeout(timeoutRef.current);
  1838. timeoutRef.current = null;
  1839. }
  1840. }, []);
  1841. React.useEffect(() => {
  1842. if (options.autoInvoke) {
  1843. start();
  1844. }
  1845. return clear;
  1846. }, [clear, start]);
  1847. return { start, clear };
  1848. }
  1849. function useTextSelection() {
  1850. const forceUpdate = useForceUpdate();
  1851. const [selection, setSelection] = React.useState(null);
  1852. const handleSelectionChange = () => {
  1853. setSelection(document.getSelection());
  1854. forceUpdate();
  1855. };
  1856. React.useEffect(() => {
  1857. setSelection(document.getSelection());
  1858. document.addEventListener("selectionchange", handleSelectionChange);
  1859. return () => document.removeEventListener("selectionchange", handleSelectionChange);
  1860. }, []);
  1861. return selection;
  1862. }
  1863. function usePrevious(value) {
  1864. const ref = React.useRef();
  1865. React.useEffect(() => {
  1866. ref.current = value;
  1867. }, [value]);
  1868. return ref.current;
  1869. }
  1870. var MIME_TYPES = {
  1871. ico: "image/x-icon",
  1872. png: "image/png",
  1873. svg: "image/svg+xml",
  1874. gif: "image/gif"
  1875. };
  1876. function useFavicon(url) {
  1877. const link = React.useRef();
  1878. useIsomorphicEffect(() => {
  1879. if (!url) {
  1880. return;
  1881. }
  1882. if (!link.current) {
  1883. const existingElements = document.querySelectorAll('link[rel*="icon"]');
  1884. existingElements.forEach((element2) => document.head.removeChild(element2));
  1885. const element = document.createElement("link");
  1886. element.rel = "shortcut icon";
  1887. link.current = element;
  1888. document.querySelector("head").appendChild(element);
  1889. }
  1890. const splittedUrl = url.split(".");
  1891. link.current.setAttribute(
  1892. "type",
  1893. MIME_TYPES[splittedUrl[splittedUrl.length - 1].toLowerCase()]
  1894. );
  1895. link.current.setAttribute("href", url);
  1896. }, [url]);
  1897. }
  1898. var isFixed = (current, fixedAt) => current <= fixedAt;
  1899. var isPinnedOrReleased = (current, fixedAt, isCurrentlyPinnedRef, isScrollingUp, onPin, onRelease) => {
  1900. const isInFixedPosition = isFixed(current, fixedAt);
  1901. if (isInFixedPosition && !isCurrentlyPinnedRef.current) {
  1902. isCurrentlyPinnedRef.current = true;
  1903. onPin?.();
  1904. } else if (!isInFixedPosition && isScrollingUp && !isCurrentlyPinnedRef.current) {
  1905. isCurrentlyPinnedRef.current = true;
  1906. onPin?.();
  1907. } else if (!isInFixedPosition && isCurrentlyPinnedRef.current) {
  1908. isCurrentlyPinnedRef.current = false;
  1909. onRelease?.();
  1910. }
  1911. };
  1912. var useScrollDirection = () => {
  1913. const [lastScrollTop, setLastScrollTop] = React.useState(0);
  1914. const [isScrollingUp, setIsScrollingUp] = React.useState(false);
  1915. const [isResizing, setIsResizing] = React.useState(false);
  1916. React.useEffect(() => {
  1917. let resizeTimer;
  1918. const onResize = () => {
  1919. setIsResizing(true);
  1920. clearTimeout(resizeTimer);
  1921. resizeTimer = setTimeout(() => {
  1922. setIsResizing(false);
  1923. }, 300);
  1924. };
  1925. const onScroll = () => {
  1926. if (isResizing) {
  1927. return;
  1928. }
  1929. const currentScrollTop = window.pageYOffset || document.documentElement.scrollTop;
  1930. setIsScrollingUp(currentScrollTop < lastScrollTop);
  1931. setLastScrollTop(currentScrollTop);
  1932. };
  1933. window.addEventListener("scroll", onScroll);
  1934. window.addEventListener("resize", onResize);
  1935. return () => {
  1936. window.removeEventListener("scroll", onScroll);
  1937. window.removeEventListener("resize", onResize);
  1938. };
  1939. }, [lastScrollTop, isResizing]);
  1940. return isScrollingUp;
  1941. };
  1942. function useHeadroom({ fixedAt = 0, onPin, onFix, onRelease } = {}) {
  1943. const isCurrentlyPinnedRef = React.useRef(false);
  1944. const isScrollingUp = useScrollDirection();
  1945. const [{ y: scrollPosition }] = useWindowScroll();
  1946. useIsomorphicEffect(() => {
  1947. isPinnedOrReleased(
  1948. scrollPosition,
  1949. fixedAt,
  1950. isCurrentlyPinnedRef,
  1951. isScrollingUp,
  1952. onPin,
  1953. onRelease
  1954. );
  1955. }, [scrollPosition]);
  1956. useIsomorphicEffect(() => {
  1957. if (isFixed(scrollPosition, fixedAt)) {
  1958. onFix?.();
  1959. }
  1960. }, [scrollPosition, fixedAt, onFix]);
  1961. if (isFixed(scrollPosition, fixedAt) || isScrollingUp) {
  1962. return true;
  1963. }
  1964. return false;
  1965. }
  1966. function useEyeDropper() {
  1967. const [supported, setSupported] = React.useState(false);
  1968. useIsomorphicEffect(() => {
  1969. setSupported(typeof window !== "undefined" && "EyeDropper" in window);
  1970. }, []);
  1971. const open = React.useCallback(
  1972. (options = {}) => {
  1973. if (supported) {
  1974. const eyeDropper = new window.EyeDropper();
  1975. return eyeDropper.open(options);
  1976. }
  1977. return Promise.resolve(void 0);
  1978. },
  1979. [supported]
  1980. );
  1981. return { supported, open };
  1982. }
  1983. function useInViewport() {
  1984. const ref = React.useRef(null);
  1985. const [inViewport, setInViewport] = React.useState(false);
  1986. const observer = React.useMemo(() => {
  1987. if (typeof IntersectionObserver === "undefined") {
  1988. return null;
  1989. }
  1990. return new IntersectionObserver(([entry]) => setInViewport(entry.isIntersecting));
  1991. }, [ref]);
  1992. React.useEffect(() => {
  1993. if (ref.current && observer) {
  1994. observer.observe(ref.current);
  1995. return () => observer.disconnect();
  1996. }
  1997. return () => null;
  1998. }, []);
  1999. return { ref, inViewport };
  2000. }
  2001. function useMutationObserver(callback, options, target) {
  2002. const observer = React.useRef();
  2003. const ref = React.useRef(null);
  2004. React.useEffect(() => {
  2005. const targetElement = typeof target === "function" ? target() : target;
  2006. if (targetElement || ref.current) {
  2007. observer.current = new MutationObserver(callback);
  2008. observer.current.observe(targetElement || ref.current, options);
  2009. }
  2010. return () => {
  2011. observer.current?.disconnect();
  2012. };
  2013. }, [callback, options]);
  2014. return ref;
  2015. }
  2016. function useMounted() {
  2017. const [mounted, setMounted] = React.useState(false);
  2018. React.useEffect(() => setMounted(true), []);
  2019. return mounted;
  2020. }
  2021. function useStateHistory(initialValue) {
  2022. const [state, setState] = React.useState({
  2023. history: [initialValue],
  2024. current: 0
  2025. });
  2026. const set = React.useCallback(
  2027. (val) => setState((currentState) => {
  2028. const nextState = [...currentState.history.slice(0, currentState.current + 1), val];
  2029. return {
  2030. history: nextState,
  2031. current: nextState.length - 1
  2032. };
  2033. }),
  2034. []
  2035. );
  2036. const back = React.useCallback(
  2037. (steps = 1) => setState((currentState) => ({
  2038. history: currentState.history,
  2039. current: Math.max(0, currentState.current - steps)
  2040. })),
  2041. []
  2042. );
  2043. const forward = React.useCallback(
  2044. (steps = 1) => setState((currentState) => ({
  2045. history: currentState.history,
  2046. current: Math.min(currentState.history.length - 1, currentState.current + steps)
  2047. })),
  2048. []
  2049. );
  2050. const handlers = React.useMemo(() => ({ set, forward, back }), []);
  2051. return [state.history[state.current], handlers, state];
  2052. }
  2053. function useMap(initialState) {
  2054. const mapRef = React.useRef(new Map(initialState));
  2055. const forceUpdate = useForceUpdate();
  2056. mapRef.current.set = (...args) => {
  2057. Map.prototype.set.apply(mapRef.current, args);
  2058. forceUpdate();
  2059. return mapRef.current;
  2060. };
  2061. mapRef.current.clear = (...args) => {
  2062. Map.prototype.clear.apply(mapRef.current, args);
  2063. forceUpdate();
  2064. };
  2065. mapRef.current.delete = (...args) => {
  2066. const res = Map.prototype.delete.apply(mapRef.current, args);
  2067. forceUpdate();
  2068. return res;
  2069. };
  2070. return mapRef.current;
  2071. }
  2072. function useSet(values) {
  2073. const setRef = React.useRef(new Set(values));
  2074. const forceUpdate = useForceUpdate();
  2075. setRef.current.add = (...args) => {
  2076. const res = Set.prototype.add.apply(setRef.current, args);
  2077. forceUpdate();
  2078. return res;
  2079. };
  2080. setRef.current.clear = (...args) => {
  2081. Set.prototype.clear.apply(setRef.current, args);
  2082. forceUpdate();
  2083. };
  2084. setRef.current.delete = (...args) => {
  2085. const res = Set.prototype.delete.apply(setRef.current, args);
  2086. forceUpdate();
  2087. return res;
  2088. };
  2089. return setRef.current;
  2090. }
  2091. function useThrottledCallbackWithClearTimeout(callback, wait) {
  2092. const handleCallback = useCallbackRef(callback);
  2093. const latestInArgsRef = React.useRef();
  2094. const latestOutArgsRef = React.useRef();
  2095. const active = React.useRef(true);
  2096. const waitRef = React.useRef(wait);
  2097. const timeoutRef = React.useRef(-1);
  2098. const clearTimeout2 = () => window.clearTimeout(timeoutRef.current);
  2099. const callThrottledCallback = React.useCallback(
  2100. (...args) => {
  2101. handleCallback(...args);
  2102. latestInArgsRef.current = args;
  2103. latestOutArgsRef.current = args;
  2104. active.current = false;
  2105. },
  2106. [handleCallback]
  2107. );
  2108. const timerCallback = React.useCallback(() => {
  2109. if (latestInArgsRef.current && latestInArgsRef.current !== latestOutArgsRef.current) {
  2110. callThrottledCallback(...latestInArgsRef.current);
  2111. timeoutRef.current = window.setTimeout(timerCallback, waitRef.current);
  2112. } else {
  2113. active.current = true;
  2114. }
  2115. }, [callThrottledCallback]);
  2116. const throttled = React.useCallback(
  2117. (...args) => {
  2118. if (active.current) {
  2119. callThrottledCallback(...args);
  2120. timeoutRef.current = window.setTimeout(timerCallback, waitRef.current);
  2121. } else {
  2122. latestInArgsRef.current = args;
  2123. }
  2124. },
  2125. [callThrottledCallback, timerCallback]
  2126. );
  2127. React.useEffect(() => {
  2128. waitRef.current = wait;
  2129. }, [wait]);
  2130. return [throttled, clearTimeout2];
  2131. }
  2132. function useThrottledCallback(callback, wait) {
  2133. return useThrottledCallbackWithClearTimeout(callback, wait)[0];
  2134. }
  2135. function useThrottledState(defaultValue, wait) {
  2136. const [value, setValue] = React.useState(defaultValue);
  2137. const [setThrottledValue, clearTimeout2] = useThrottledCallbackWithClearTimeout(setValue, wait);
  2138. React.useEffect(() => clearTimeout2, []);
  2139. return [value, setThrottledValue];
  2140. }
  2141. function useThrottledValue(value, wait) {
  2142. const [throttledValue, setThrottledValue] = React.useState(value);
  2143. const valueRef = React.useRef(value);
  2144. const [throttledSetValue, clearTimeout2] = useThrottledCallbackWithClearTimeout(
  2145. setThrottledValue,
  2146. wait
  2147. );
  2148. React.useEffect(() => {
  2149. if (value !== valueRef.current) {
  2150. valueRef.current = value;
  2151. throttledSetValue(value);
  2152. }
  2153. }, [throttledSetValue, value]);
  2154. React.useEffect(() => clearTimeout2, []);
  2155. return throttledValue;
  2156. }
  2157. function useIsFirstRender() {
  2158. const renderRef = React.useRef(true);
  2159. if (renderRef.current === true) {
  2160. renderRef.current = false;
  2161. return true;
  2162. }
  2163. return renderRef.current;
  2164. }
  2165. function useOrientation() {
  2166. const [orientation, setOrientation] = React.useState({ angle: 0, type: "landscape-primary" });
  2167. const handleOrientationChange = (event) => {
  2168. const target = event.currentTarget;
  2169. setOrientation({ angle: target?.angle || 0, type: target?.type || "landscape-primary" });
  2170. };
  2171. useIsomorphicEffect(() => {
  2172. window.screen.orientation?.addEventListener("change", handleOrientationChange);
  2173. return () => window.screen.orientation?.removeEventListener("change", handleOrientationChange);
  2174. }, []);
  2175. return orientation;
  2176. }
  2177. function useFetch(url, { autoInvoke = true, ...options } = {}) {
  2178. const [data, setData] = React.useState(null);
  2179. const [loading, setLoading] = React.useState(false);
  2180. const [error, setError] = React.useState(null);
  2181. const controller = React.useRef(null);
  2182. const refetch = React.useCallback(() => {
  2183. if (!url) {
  2184. return;
  2185. }
  2186. if (controller.current) {
  2187. controller.current.abort();
  2188. }
  2189. controller.current = new AbortController();
  2190. setLoading(true);
  2191. return fetch(url, { signal: controller.current.signal, ...options }).then((res) => res.json()).then((res) => {
  2192. setData(res);
  2193. setLoading(false);
  2194. return res;
  2195. }).catch((err) => {
  2196. setLoading(false);
  2197. if (err.name !== "AbortError") {
  2198. setError(err);
  2199. }
  2200. return err;
  2201. });
  2202. }, [url]);
  2203. const abort = React.useCallback(() => {
  2204. if (controller.current) {
  2205. controller.current?.abort("");
  2206. }
  2207. }, []);
  2208. React.useEffect(() => {
  2209. if (autoInvoke) {
  2210. refetch();
  2211. }
  2212. return () => {
  2213. if (controller.current) {
  2214. controller.current.abort("");
  2215. }
  2216. };
  2217. }, [refetch, autoInvoke]);
  2218. return { data, loading, error, refetch, abort };
  2219. }
  2220.  
  2221. exports.assignRef = assignRef;
  2222. exports.clamp = clamp;
  2223. exports.clampUseMovePosition = clampUseMovePosition;
  2224. exports.getHotkeyHandler = getHotkeyHandler;
  2225. exports.lowerFirst = lowerFirst;
  2226. exports.mergeRefs = mergeRefs;
  2227. exports.randomId = randomId;
  2228. exports.range = range;
  2229. exports.readLocalStorageValue = readLocalStorageValue;
  2230. exports.readSessionStorageValue = readSessionStorageValue;
  2231. exports.shallowEqual = shallowEqual;
  2232. exports.upperFirst = upperFirst;
  2233. exports.useCallbackRef = useCallbackRef;
  2234. exports.useClickOutside = useClickOutside;
  2235. exports.useClipboard = useClipboard;
  2236. exports.useColorScheme = useColorScheme;
  2237. exports.useCounter = useCounter;
  2238. exports.useDebouncedCallback = useDebouncedCallback;
  2239. exports.useDebouncedState = useDebouncedState;
  2240. exports.useDebouncedValue = useDebouncedValue;
  2241. exports.useDidUpdate = useDidUpdate;
  2242. exports.useDisclosure = useDisclosure;
  2243. exports.useDocumentTitle = useDocumentTitle;
  2244. exports.useDocumentVisibility = useDocumentVisibility;
  2245. exports.useElementSize = useElementSize;
  2246. exports.useEventListener = useEventListener;
  2247. exports.useEyeDropper = useEyeDropper;
  2248. exports.useFavicon = useFavicon;
  2249. exports.useFetch = useFetch;
  2250. exports.useFocusReturn = useFocusReturn;
  2251. exports.useFocusTrap = useFocusTrap;
  2252. exports.useFocusWithin = useFocusWithin;
  2253. exports.useForceUpdate = useForceUpdate;
  2254. exports.useFullscreen = useFullscreen;
  2255. exports.useHash = useHash;
  2256. exports.useHeadroom = useHeadroom;
  2257. exports.useHotkeys = useHotkeys;
  2258. exports.useHover = useHover;
  2259. exports.useId = useId;
  2260. exports.useIdle = useIdle;
  2261. exports.useInViewport = useInViewport;
  2262. exports.useInputState = useInputState;
  2263. exports.useIntersection = useIntersection;
  2264. exports.useInterval = useInterval;
  2265. exports.useIsFirstRender = useIsFirstRender;
  2266. exports.useIsomorphicEffect = useIsomorphicEffect;
  2267. exports.useListState = useListState;
  2268. exports.useLocalStorage = useLocalStorage;
  2269. exports.useLogger = useLogger;
  2270. exports.useMap = useMap;
  2271. exports.useMediaQuery = useMediaQuery;
  2272. exports.useMergedRef = useMergedRef;
  2273. exports.useMounted = useMounted;
  2274. exports.useMouse = useMouse;
  2275. exports.useMove = useMove;
  2276. exports.useMutationObserver = useMutationObserver;
  2277. exports.useNetwork = useNetwork;
  2278. exports.useOrientation = useOrientation;
  2279. exports.useOs = useOs;
  2280. exports.usePageLeave = usePageLeave;
  2281. exports.usePagination = usePagination;
  2282. exports.usePrevious = usePrevious;
  2283. exports.useQueue = useQueue;
  2284. exports.useReducedMotion = useReducedMotion;
  2285. exports.useResizeObserver = useResizeObserver;
  2286. exports.useScrollIntoView = useScrollIntoView;
  2287. exports.useSessionStorage = useSessionStorage;
  2288. exports.useSet = useSet;
  2289. exports.useSetState = useSetState;
  2290. exports.useShallowEffect = useShallowEffect;
  2291. exports.useStateHistory = useStateHistory;
  2292. exports.useTextSelection = useTextSelection;
  2293. exports.useThrottledCallback = useThrottledCallback;
  2294. exports.useThrottledState = useThrottledState;
  2295. exports.useThrottledValue = useThrottledValue;
  2296. exports.useTimeout = useTimeout;
  2297. exports.useToggle = useToggle;
  2298. exports.useUncontrolled = useUncontrolled;
  2299. exports.useValidatedState = useValidatedState;
  2300. exports.useViewportSize = useViewportSize;
  2301. exports.useWindowEvent = useWindowEvent;
  2302. exports.useWindowScroll = useWindowScroll;
  2303.  
  2304. }));

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址