@omnitron-dev/prism 0.1.1

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.
Files changed (83) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -0
  3. package/bin/prism.js +13 -0
  4. package/dist/accessibility/index.d.ts +157 -0
  5. package/dist/accessibility/index.js +186 -0
  6. package/dist/accessibility/index.js.map +1 -0
  7. package/dist/blocks/index.d.ts +1239 -0
  8. package/dist/blocks/index.js +1712 -0
  9. package/dist/blocks/index.js.map +1 -0
  10. package/dist/chunk-77KIJLPP.js +37 -0
  11. package/dist/chunk-77KIJLPP.js.map +1 -0
  12. package/dist/chunk-BTIT7WYH.js +339 -0
  13. package/dist/chunk-BTIT7WYH.js.map +1 -0
  14. package/dist/chunk-BV32OJ2A.js +1409 -0
  15. package/dist/chunk-BV32OJ2A.js.map +1 -0
  16. package/dist/chunk-DDY7TLUI.js +139 -0
  17. package/dist/chunk-DDY7TLUI.js.map +1 -0
  18. package/dist/chunk-DXXZ3ITR.js +4227 -0
  19. package/dist/chunk-DXXZ3ITR.js.map +1 -0
  20. package/dist/chunk-E3XANPTO.js +2319 -0
  21. package/dist/chunk-E3XANPTO.js.map +1 -0
  22. package/dist/chunk-FU52GL2E.js +3 -0
  23. package/dist/chunk-FU52GL2E.js.map +1 -0
  24. package/dist/chunk-GYDT5EKX.js +16505 -0
  25. package/dist/chunk-GYDT5EKX.js.map +1 -0
  26. package/dist/chunk-HO2GKTWJ.js +28 -0
  27. package/dist/chunk-HO2GKTWJ.js.map +1 -0
  28. package/dist/chunk-JDTC2SBY.js +140 -0
  29. package/dist/chunk-JDTC2SBY.js.map +1 -0
  30. package/dist/chunk-JNU4QHJK.js +6 -0
  31. package/dist/chunk-JNU4QHJK.js.map +1 -0
  32. package/dist/chunk-LAEY5USO.js +2621 -0
  33. package/dist/chunk-LAEY5USO.js.map +1 -0
  34. package/dist/chunk-UR6X3W5I.js +530 -0
  35. package/dist/chunk-UR6X3W5I.js.map +1 -0
  36. package/dist/chunk-WC2WM2JD.js +883 -0
  37. package/dist/chunk-WC2WM2JD.js.map +1 -0
  38. package/dist/chunk-XWL6J6IO.js +40 -0
  39. package/dist/chunk-XWL6J6IO.js.map +1 -0
  40. package/dist/cli/index.js +2695 -0
  41. package/dist/cli/index.js.map +1 -0
  42. package/dist/config-BA6IeTq9.d.ts +100 -0
  43. package/dist/core/index.d.ts +454 -0
  44. package/dist/core/index.js +9 -0
  45. package/dist/core/index.js.map +1 -0
  46. package/dist/forms/index.d.ts +562 -0
  47. package/dist/forms/index.js +545 -0
  48. package/dist/forms/index.js.map +1 -0
  49. package/dist/hooks/index.d.ts +7 -0
  50. package/dist/hooks/index.js +10 -0
  51. package/dist/hooks/index.js.map +1 -0
  52. package/dist/http/index.d.ts +233 -0
  53. package/dist/http/index.js +282 -0
  54. package/dist/http/index.js.map +1 -0
  55. package/dist/index-odhPSv9I.d.ts +2491 -0
  56. package/dist/index.css +131 -0
  57. package/dist/index.css.map +1 -0
  58. package/dist/index.d.ts +9109 -0
  59. package/dist/index.js +13280 -0
  60. package/dist/index.js.map +1 -0
  61. package/dist/layouts/index.d.ts +854 -0
  62. package/dist/layouts/index.js +6 -0
  63. package/dist/layouts/index.js.map +1 -0
  64. package/dist/netron/index.d.ts +4 -0
  65. package/dist/netron/index.js +4 -0
  66. package/dist/netron/index.js.map +1 -0
  67. package/dist/registry/index.d.ts +352 -0
  68. package/dist/registry/index.js +4 -0
  69. package/dist/registry/index.js.map +1 -0
  70. package/dist/registry-BrDNftd5.d.ts +574 -0
  71. package/dist/settings-plpR26Xk.d.ts +455 -0
  72. package/dist/state/index.d.ts +981 -0
  73. package/dist/state/index.js +5 -0
  74. package/dist/state/index.js.map +1 -0
  75. package/dist/theme/index.d.ts +1049 -0
  76. package/dist/theme/index.js +5 -0
  77. package/dist/theme/index.js.map +1 -0
  78. package/dist/theme-CrXLfP1c.d.ts +389 -0
  79. package/dist/types/index.d.ts +146 -0
  80. package/dist/types/index.js +5 -0
  81. package/dist/types/index.js.map +1 -0
  82. package/dist/use-timeout-D7U3EAtH.d.ts +808 -0
  83. package/package.json +194 -0
@@ -0,0 +1,883 @@
1
+ import { createPrismTheme } from './chunk-DXXZ3ITR.js';
2
+ import { defaultPrismConfig } from './chunk-XWL6J6IO.js';
3
+ import { useSettingsStore } from './chunk-DDY7TLUI.js';
4
+ import { createContext, useContext, useMemo, useEffect, useCallback, useState, useRef, createElement } from 'react';
5
+ import createCache from '@emotion/cache';
6
+ import { CacheProvider } from '@emotion/react';
7
+ import { ThemeProvider, useTheme } from '@mui/material/styles';
8
+ import CssBaseline from '@mui/material/CssBaseline';
9
+ import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
10
+ import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
11
+ import rtlPlugin from 'stylis-plugin-rtl';
12
+ import { useMediaQuery as useMediaQuery$1 } from '@mui/material';
13
+ export { useMediaQuery as useMuiMediaQuery } from '@mui/material';
14
+ import { jsx, jsxs } from 'react/jsx-runtime';
15
+ import useMediaQuery from '@mui/material/useMediaQuery';
16
+
17
+ var PrismContext = createContext(null);
18
+ PrismContext.displayName = "PrismContext";
19
+ function usePrismContext() {
20
+ const context = useContext(PrismContext);
21
+ if (!context) {
22
+ throw new Error("usePrismContext must be used within a PrismProvider");
23
+ }
24
+ return context;
25
+ }
26
+ function usePrefersDarkMode() {
27
+ return useMediaQuery$1("(prefers-color-scheme: dark)");
28
+ }
29
+ function useResolvedMode(mode) {
30
+ const prefersDark = usePrefersDarkMode();
31
+ if (mode === "system") {
32
+ return prefersDark ? "dark" : "light";
33
+ }
34
+ return mode;
35
+ }
36
+ function mergeConfig(base, overrides) {
37
+ if (!overrides) return base;
38
+ return {
39
+ ...base,
40
+ ...overrides,
41
+ paths: { ...base.paths, ...overrides.paths },
42
+ registries: { ...base.registries, ...overrides.registries },
43
+ theme: { ...base.theme, ...overrides.theme },
44
+ style: { ...base.style, ...overrides.style },
45
+ features: { ...base.features, ...overrides.features }
46
+ };
47
+ }
48
+ var noOpDrawerWarning = () => {
49
+ if (process.env.NODE_ENV !== "production") {
50
+ console.warn(
51
+ "[PrismProvider] Settings drawer is now managed by SettingsProvider. Use useSettingsDrawer() from @omnitron-dev/prism/components/settings instead."
52
+ );
53
+ }
54
+ };
55
+ function PrismProvider({
56
+ children,
57
+ config: configOverrides,
58
+ defaultSettings,
59
+ disableCssBaseline = false,
60
+ themeOverrides
61
+ }) {
62
+ const config = useMemo(() => mergeConfig(defaultPrismConfig, configOverrides), [configOverrides]);
63
+ const {
64
+ // State values
65
+ mode: storeMode,
66
+ preset: storePreset,
67
+ direction: storeDirection,
68
+ primaryColor: storePrimaryColor,
69
+ contrast: storeContrast,
70
+ compactSidebar,
71
+ fontSize: storeFontSize,
72
+ fontFamily: storeFontFamily,
73
+ navLayout: storeNavLayout,
74
+ navColor: storeNavColor,
75
+ // Actions (stable references from Zustand)
76
+ setMode,
77
+ toggleMode,
78
+ setPreset,
79
+ setDirection,
80
+ setCompactSidebar,
81
+ reset: resetSettings
82
+ } = useSettingsStore();
83
+ useEffect(() => {
84
+ if (defaultSettings?.mode) setMode(defaultSettings.mode);
85
+ if (defaultSettings?.preset) setPreset(defaultSettings.preset);
86
+ if (defaultSettings?.direction) setDirection(defaultSettings.direction);
87
+ }, []);
88
+ const settings = useMemo(
89
+ () => ({
90
+ mode: storeMode,
91
+ preset: storePreset,
92
+ direction: storeDirection,
93
+ sidebarCollapsed: compactSidebar,
94
+ settingsDrawerOpen: false,
95
+ // Managed by SettingsProvider component
96
+ primaryColor: storePrimaryColor,
97
+ contrast: storeContrast,
98
+ fontSize: storeFontSize,
99
+ fontFamily: storeFontFamily ?? "Public Sans Variable",
100
+ navLayout: storeNavLayout,
101
+ navColor: storeNavColor
102
+ }),
103
+ [
104
+ storeMode,
105
+ storePreset,
106
+ storeDirection,
107
+ compactSidebar,
108
+ storePrimaryColor,
109
+ storeContrast,
110
+ storeFontSize,
111
+ storeFontFamily,
112
+ storeNavLayout,
113
+ storeNavColor
114
+ ]
115
+ );
116
+ const toggleSidebar = useCallback(() => {
117
+ const current = useSettingsStore.getState().compactSidebar;
118
+ setCompactSidebar(!current);
119
+ }, [setCompactSidebar]);
120
+ const emotionCache = useMemo(
121
+ () => storeDirection === "rtl" ? createCache({ key: "prism-rtl", stylisPlugins: [rtlPlugin] }) : createCache({ key: "prism-ltr" }),
122
+ [storeDirection]
123
+ );
124
+ useEffect(() => {
125
+ if (typeof document !== "undefined") {
126
+ document.documentElement.dir = storeDirection;
127
+ }
128
+ }, [storeDirection]);
129
+ useEffect(() => {
130
+ if (typeof document !== "undefined") {
131
+ if (storeFontSize && storeFontSize !== 16) {
132
+ document.documentElement.style.fontSize = `${storeFontSize}px`;
133
+ } else {
134
+ document.documentElement.style.removeProperty("font-size");
135
+ }
136
+ }
137
+ }, [storeFontSize]);
138
+ const resolvedMode = useResolvedMode(storeMode);
139
+ const theme = useMemo(
140
+ () => createPrismTheme({
141
+ preset: storePreset,
142
+ mode: resolvedMode,
143
+ direction: storeDirection,
144
+ primaryColor: storePrimaryColor || config.theme.primaryColor,
145
+ typography: config.theme.typography,
146
+ cssVariables: config.theme.cssVariables,
147
+ components: config.theme.components,
148
+ contrast: storeContrast,
149
+ fontFamily: storeFontFamily,
150
+ fontSize: storeFontSize,
151
+ overrides: themeOverrides
152
+ }),
153
+ [
154
+ storePreset,
155
+ resolvedMode,
156
+ storeDirection,
157
+ storePrimaryColor,
158
+ storeContrast,
159
+ storeFontSize,
160
+ storeFontFamily,
161
+ config.theme,
162
+ themeOverrides
163
+ ]
164
+ );
165
+ const contextValue = useMemo(
166
+ () => ({
167
+ config,
168
+ theme,
169
+ settings,
170
+ // Zustand actions (stable references)
171
+ setMode,
172
+ toggleMode,
173
+ setPreset,
174
+ setDirection,
175
+ toggleSidebar,
176
+ setSidebarCollapsed: setCompactSidebar,
177
+ resetSettings,
178
+ // Deprecated drawer controls (no-ops, stable module-level reference)
179
+ openSettingsDrawer: noOpDrawerWarning,
180
+ closeSettingsDrawer: noOpDrawerWarning,
181
+ toggleSettingsDrawer: noOpDrawerWarning
182
+ }),
183
+ [
184
+ config,
185
+ theme,
186
+ settings,
187
+ setMode,
188
+ toggleMode,
189
+ setPreset,
190
+ setDirection,
191
+ toggleSidebar,
192
+ setCompactSidebar,
193
+ resetSettings
194
+ ]
195
+ );
196
+ return /* @__PURE__ */ jsx(CacheProvider, { value: emotionCache, children: /* @__PURE__ */ jsx(PrismContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(ThemeProvider, { theme, children: /* @__PURE__ */ jsxs(LocalizationProvider, { dateAdapter: AdapterDayjs, children: [
197
+ !disableCssBaseline && /* @__PURE__ */ jsx(CssBaseline, {}),
198
+ children
199
+ ] }) }) }) });
200
+ }
201
+ function composeProviders(providers) {
202
+ const ComposedProviders = ({ children }) => (
203
+ // Build the provider tree from inside-out (reverse iteration)
204
+ providers.reduceRight((acc, provider) => {
205
+ if (Array.isArray(provider)) {
206
+ const [Component, props] = provider;
207
+ return createElement(Component, { ...props, children: acc });
208
+ }
209
+ return createElement(provider, { children: acc });
210
+ }, children)
211
+ );
212
+ ComposedProviders.displayName = "ComposedProviders";
213
+ return ComposedProviders;
214
+ }
215
+ function createProviderStack(baseProviders, options = {}) {
216
+ const { displayName = "ProviderStack" } = options;
217
+ return (config = {}) => {
218
+ const { prepend = [], append = [], replace } = config;
219
+ const providers = replace ?? [...prepend, ...baseProviders, ...append];
220
+ const Component = composeProviders(providers);
221
+ Component.displayName = displayName;
222
+ return Component;
223
+ };
224
+ }
225
+ function ProviderStack({ providers, children }) {
226
+ const Provider = useMemo(() => composeProviders(providers), [providers]);
227
+ return /* @__PURE__ */ jsx(Provider, { children });
228
+ }
229
+ function withProviderProps(Provider, props) {
230
+ const BoundProvider = ({ children }) => createElement(Provider, { ...props, children });
231
+ BoundProvider.displayName = `withProviderProps(${Provider.displayName || Provider.name || "Component"})`;
232
+ return BoundProvider;
233
+ }
234
+ function conditionalProvider(Provider, condition, props) {
235
+ if (!condition) return null;
236
+ if (props) {
237
+ return [Provider, props];
238
+ }
239
+ return Provider;
240
+ }
241
+ function filterProviders(providers) {
242
+ return providers.filter((p) => p != null);
243
+ }
244
+ function useSetState(initialState) {
245
+ const [state, setInternalState] = useState(initialState);
246
+ const setState = useCallback((patch) => {
247
+ setInternalState((prevState) => {
248
+ const newPartial = typeof patch === "function" ? patch(prevState) : patch;
249
+ return { ...prevState, ...newPartial };
250
+ });
251
+ }, []);
252
+ const resetState = useCallback(() => {
253
+ setInternalState(typeof initialState === "function" ? initialState() : initialState);
254
+ }, [initialState]);
255
+ return {
256
+ state,
257
+ setState,
258
+ resetState
259
+ };
260
+ }
261
+ function useMultiSelect(options = {}) {
262
+ const { initial = [], maxSelections, onChange } = options;
263
+ const [selected, setInternalSelected] = useState(initial);
264
+ const selectedSet = useMemo(() => new Set(selected), [selected]);
265
+ const setSelected = useCallback(
266
+ (items) => {
267
+ const limited = maxSelections ? items.slice(0, maxSelections) : items;
268
+ setInternalSelected(limited);
269
+ onChange?.(limited);
270
+ },
271
+ [maxSelections, onChange]
272
+ );
273
+ const isSelected = useCallback((item) => selectedSet.has(item), [selectedSet]);
274
+ const select = useCallback(
275
+ (item) => {
276
+ if (selectedSet.has(item)) return;
277
+ if (maxSelections && selected.length >= maxSelections) return;
278
+ const newSelected = [...selected, item];
279
+ setInternalSelected(newSelected);
280
+ onChange?.(newSelected);
281
+ },
282
+ [selected, selectedSet, maxSelections, onChange]
283
+ );
284
+ const deselect = useCallback(
285
+ (item) => {
286
+ if (!selectedSet.has(item)) return;
287
+ const newSelected = selected.filter((s) => s !== item);
288
+ setInternalSelected(newSelected);
289
+ onChange?.(newSelected);
290
+ },
291
+ [selected, selectedSet, onChange]
292
+ );
293
+ const toggle = useCallback(
294
+ (item) => {
295
+ if (selectedSet.has(item)) {
296
+ deselect(item);
297
+ } else {
298
+ select(item);
299
+ }
300
+ },
301
+ [selectedSet, select, deselect]
302
+ );
303
+ const selectMany = useCallback(
304
+ (items) => {
305
+ const toAdd = items.filter((item) => !selectedSet.has(item));
306
+ if (toAdd.length === 0) return;
307
+ let newSelected = [...selected, ...toAdd];
308
+ if (maxSelections) {
309
+ newSelected = newSelected.slice(0, maxSelections);
310
+ }
311
+ setInternalSelected(newSelected);
312
+ onChange?.(newSelected);
313
+ },
314
+ [selected, selectedSet, maxSelections, onChange]
315
+ );
316
+ const deselectMany = useCallback(
317
+ (items) => {
318
+ const toRemove = new Set(items);
319
+ const newSelected = selected.filter((s) => !toRemove.has(s));
320
+ if (newSelected.length === selected.length) return;
321
+ setInternalSelected(newSelected);
322
+ onChange?.(newSelected);
323
+ },
324
+ [selected, onChange]
325
+ );
326
+ const clear = useCallback(() => {
327
+ if (selected.length === 0) return;
328
+ setInternalSelected([]);
329
+ onChange?.([]);
330
+ }, [selected.length, onChange]);
331
+ const selectAll = useCallback(
332
+ (allItems) => {
333
+ const limited = maxSelections ? allItems.slice(0, maxSelections) : allItems;
334
+ setInternalSelected(limited);
335
+ onChange?.(limited);
336
+ },
337
+ [maxSelections, onChange]
338
+ );
339
+ const isAllSelected = useCallback(
340
+ (allItems) => {
341
+ if (allItems.length === 0) return false;
342
+ return allItems.every((item) => selectedSet.has(item));
343
+ },
344
+ [selectedSet]
345
+ );
346
+ const isPartiallySelected = useCallback(
347
+ (allItems) => {
348
+ if (allItems.length === 0) return false;
349
+ const selectedCount = allItems.filter((item) => selectedSet.has(item)).length;
350
+ return selectedCount > 0 && selectedCount < allItems.length;
351
+ },
352
+ [selectedSet]
353
+ );
354
+ return {
355
+ selected,
356
+ count: selected.length,
357
+ isEmpty: selected.length === 0,
358
+ isSelected,
359
+ toggle,
360
+ select,
361
+ deselect,
362
+ selectMany,
363
+ deselectMany,
364
+ clear,
365
+ setSelected,
366
+ selectAll,
367
+ isAllSelected,
368
+ isPartiallySelected
369
+ };
370
+ }
371
+ function isLocalStorageAvailable() {
372
+ try {
373
+ const testKey = "__prism_test__";
374
+ localStorage.setItem(testKey, testKey);
375
+ localStorage.removeItem(testKey);
376
+ return true;
377
+ } catch {
378
+ return false;
379
+ }
380
+ }
381
+ function serialize(value) {
382
+ return JSON.stringify(value);
383
+ }
384
+ function deserialize(value, fallback) {
385
+ if (value === null) return fallback;
386
+ try {
387
+ return JSON.parse(value);
388
+ } catch {
389
+ return fallback;
390
+ }
391
+ }
392
+ function useLocalStorage(key, initialValue) {
393
+ const storageAvailable = useMemo(() => isLocalStorageAvailable(), []);
394
+ const [storedValue, setStoredValue] = useState(() => {
395
+ if (!storageAvailable) return initialValue;
396
+ try {
397
+ const item = localStorage.getItem(key);
398
+ return deserialize(item, initialValue);
399
+ } catch (error) {
400
+ console.warn(`Error reading localStorage key "${key}":`, error);
401
+ return initialValue;
402
+ }
403
+ });
404
+ const setValue = useCallback(
405
+ (value) => {
406
+ setStoredValue((prev) => {
407
+ const newValue = value instanceof Function ? value(prev) : value;
408
+ if (storageAvailable) {
409
+ try {
410
+ localStorage.setItem(key, serialize(newValue));
411
+ } catch (error) {
412
+ console.warn(`Error setting localStorage key "${key}":`, error);
413
+ }
414
+ }
415
+ return newValue;
416
+ });
417
+ },
418
+ [key, storageAvailable]
419
+ );
420
+ const removeValue = useCallback(() => {
421
+ setStoredValue(initialValue);
422
+ if (storageAvailable) {
423
+ try {
424
+ localStorage.removeItem(key);
425
+ } catch (error) {
426
+ console.warn(`Error removing localStorage key "${key}":`, error);
427
+ }
428
+ }
429
+ }, [key, initialValue, storageAvailable]);
430
+ useEffect(() => {
431
+ if (!storageAvailable) {
432
+ return void 0;
433
+ }
434
+ const handleStorageChange = (event) => {
435
+ if (event.key === key && event.newValue !== null) {
436
+ setStoredValue(deserialize(event.newValue, initialValue));
437
+ }
438
+ };
439
+ window.addEventListener("storage", handleStorageChange);
440
+ return () => {
441
+ window.removeEventListener("storage", handleStorageChange);
442
+ };
443
+ }, [key, initialValue, storageAvailable]);
444
+ return [storedValue, setValue, removeValue];
445
+ }
446
+ function useCopyToClipboard(options = {}) {
447
+ const { resetTimeout = 2e3, onSuccess, onError } = options;
448
+ const [state, setState] = useState("idle");
449
+ const [copiedText, setCopiedText] = useState(null);
450
+ const timeoutRef = useRef(null);
451
+ useEffect(
452
+ () => () => {
453
+ if (timeoutRef.current) {
454
+ clearTimeout(timeoutRef.current);
455
+ }
456
+ },
457
+ []
458
+ );
459
+ const reset = useCallback(() => {
460
+ if (timeoutRef.current) {
461
+ clearTimeout(timeoutRef.current);
462
+ timeoutRef.current = null;
463
+ }
464
+ setState("idle");
465
+ setCopiedText(null);
466
+ }, []);
467
+ const copy = useCallback(
468
+ async (text) => {
469
+ if (timeoutRef.current) {
470
+ clearTimeout(timeoutRef.current);
471
+ timeoutRef.current = null;
472
+ }
473
+ if (!navigator?.clipboard) {
474
+ const error = new Error("Clipboard API not available");
475
+ setState("error");
476
+ onError?.(error);
477
+ return false;
478
+ }
479
+ try {
480
+ await navigator.clipboard.writeText(text);
481
+ setCopiedText(text);
482
+ setState("success");
483
+ onSuccess?.(text);
484
+ if (resetTimeout > 0) {
485
+ timeoutRef.current = setTimeout(reset, resetTimeout);
486
+ }
487
+ return true;
488
+ } catch (err) {
489
+ const error = err instanceof Error ? err : new Error("Failed to copy");
490
+ setState("error");
491
+ onError?.(error);
492
+ if (resetTimeout > 0) {
493
+ timeoutRef.current = setTimeout(reset, resetTimeout);
494
+ }
495
+ return false;
496
+ }
497
+ },
498
+ [resetTimeout, reset, onSuccess, onError]
499
+ );
500
+ return useMemo(
501
+ () => ({
502
+ state,
503
+ copiedText,
504
+ copy,
505
+ reset
506
+ }),
507
+ [state, copiedText, copy, reset]
508
+ );
509
+ }
510
+ function useDebounce(value, delay = 500) {
511
+ const [debouncedValue, setDebouncedValue] = useState(value);
512
+ useEffect(() => {
513
+ const timer = setTimeout(() => {
514
+ setDebouncedValue(value);
515
+ }, delay);
516
+ return () => {
517
+ clearTimeout(timer);
518
+ };
519
+ }, [value, delay]);
520
+ return debouncedValue;
521
+ }
522
+ function useDebounceCallback(callback, delay = 500) {
523
+ const timeoutRef = useRef(null);
524
+ const callbackRef = useRef(callback);
525
+ const argsRef = useRef(null);
526
+ callbackRef.current = callback;
527
+ const cancel = useCallback(() => {
528
+ if (timeoutRef.current) {
529
+ clearTimeout(timeoutRef.current);
530
+ timeoutRef.current = null;
531
+ }
532
+ argsRef.current = null;
533
+ }, []);
534
+ const flush = useCallback(() => {
535
+ if (timeoutRef.current && argsRef.current) {
536
+ clearTimeout(timeoutRef.current);
537
+ timeoutRef.current = null;
538
+ callbackRef.current(...argsRef.current);
539
+ argsRef.current = null;
540
+ }
541
+ }, []);
542
+ const debouncedCallback = useCallback(
543
+ (...args) => {
544
+ argsRef.current = args;
545
+ if (timeoutRef.current) {
546
+ clearTimeout(timeoutRef.current);
547
+ }
548
+ timeoutRef.current = setTimeout(() => {
549
+ callbackRef.current(...args);
550
+ timeoutRef.current = null;
551
+ argsRef.current = null;
552
+ }, delay);
553
+ },
554
+ [delay]
555
+ );
556
+ useEffect(
557
+ () => () => {
558
+ if (timeoutRef.current) {
559
+ clearTimeout(timeoutRef.current);
560
+ }
561
+ },
562
+ []
563
+ );
564
+ return { debouncedCallback, cancel, flush };
565
+ }
566
+ function getTimeParts(totalSeconds) {
567
+ const hours = Math.floor(totalSeconds / 3600);
568
+ const minutes = Math.floor(totalSeconds % 3600 / 60);
569
+ const seconds = totalSeconds % 60;
570
+ return { hours, minutes, seconds };
571
+ }
572
+ function formatTime(totalSeconds) {
573
+ const { hours, minutes, seconds } = getTimeParts(totalSeconds);
574
+ const pad = (n) => n.toString().padStart(2, "0");
575
+ if (hours > 0) {
576
+ return `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
577
+ }
578
+ return `${pad(minutes)}:${pad(seconds)}`;
579
+ }
580
+ function useCountdown(options) {
581
+ const { duration, autoStart = false, onComplete, onTick, interval = 1e3 } = options;
582
+ const [seconds, setSeconds] = useState(duration);
583
+ const [isRunning, setIsRunning] = useState(autoStart);
584
+ const intervalRef = useRef(null);
585
+ const onCompleteRef = useRef(onComplete);
586
+ const onTickRef = useRef(onTick);
587
+ useEffect(() => {
588
+ onCompleteRef.current = onComplete;
589
+ onTickRef.current = onTick;
590
+ }, [onComplete, onTick]);
591
+ useEffect(
592
+ () => () => {
593
+ if (intervalRef.current) {
594
+ clearInterval(intervalRef.current);
595
+ }
596
+ },
597
+ []
598
+ );
599
+ useEffect(() => {
600
+ if (!isRunning) {
601
+ if (intervalRef.current) {
602
+ clearInterval(intervalRef.current);
603
+ intervalRef.current = null;
604
+ }
605
+ return void 0;
606
+ }
607
+ intervalRef.current = setInterval(() => {
608
+ setSeconds((prev) => {
609
+ const next = prev - 1;
610
+ onTickRef.current?.(next);
611
+ if (next <= 0) {
612
+ setIsRunning(false);
613
+ onCompleteRef.current?.();
614
+ return 0;
615
+ }
616
+ return next;
617
+ });
618
+ }, interval);
619
+ return () => {
620
+ if (intervalRef.current) {
621
+ clearInterval(intervalRef.current);
622
+ intervalRef.current = null;
623
+ }
624
+ };
625
+ }, [isRunning, interval]);
626
+ const start = useCallback(() => {
627
+ if (seconds > 0) {
628
+ setIsRunning(true);
629
+ }
630
+ }, [seconds]);
631
+ const pause = useCallback(() => {
632
+ setIsRunning(false);
633
+ }, []);
634
+ const reset = useCallback(() => {
635
+ setIsRunning(false);
636
+ setSeconds(duration);
637
+ }, [duration]);
638
+ const setDuration = useCallback((newDuration) => {
639
+ setIsRunning(false);
640
+ setSeconds(newDuration);
641
+ }, []);
642
+ return {
643
+ seconds,
644
+ isRunning,
645
+ isFinished: seconds <= 0,
646
+ formatted: formatTime(seconds),
647
+ parts: getTimeParts(seconds),
648
+ start,
649
+ pause,
650
+ reset,
651
+ setDuration
652
+ };
653
+ }
654
+ function useBreakpoints() {
655
+ const theme = useTheme();
656
+ const isXsUp = useMediaQuery(theme.breakpoints.up("xs"));
657
+ const isSmUp = useMediaQuery(theme.breakpoints.up("sm"));
658
+ const isMdUp = useMediaQuery(theme.breakpoints.up("md"));
659
+ const isLgUp = useMediaQuery(theme.breakpoints.up("lg"));
660
+ const isXlUp = useMediaQuery(theme.breakpoints.up("xl"));
661
+ const { current, isXs, isSm, isMd, isLg, isXl } = useMemo(() => {
662
+ let currentBreakpoint = "xs";
663
+ if (isXlUp) currentBreakpoint = "xl";
664
+ else if (isLgUp) currentBreakpoint = "lg";
665
+ else if (isMdUp) currentBreakpoint = "md";
666
+ else if (isSmUp) currentBreakpoint = "sm";
667
+ return {
668
+ current: currentBreakpoint,
669
+ isXs: !isSmUp,
670
+ isSm: isSmUp && !isMdUp,
671
+ isMd: isMdUp && !isLgUp,
672
+ isLg: isLgUp && !isXlUp,
673
+ isXl: isXlUp
674
+ };
675
+ }, [isXsUp, isSmUp, isMdUp, isLgUp, isXlUp]);
676
+ const isMobile = !isMdUp;
677
+ const isTablet = isMdUp && !isLgUp;
678
+ const isDesktop = isLgUp;
679
+ const up = useMemo(
680
+ () => (breakpoint) => {
681
+ switch (breakpoint) {
682
+ case "xs":
683
+ return isXsUp;
684
+ case "sm":
685
+ return isSmUp;
686
+ case "md":
687
+ return isMdUp;
688
+ case "lg":
689
+ return isLgUp;
690
+ case "xl":
691
+ return isXlUp;
692
+ default:
693
+ return false;
694
+ }
695
+ },
696
+ [isXsUp, isSmUp, isMdUp, isLgUp, isXlUp]
697
+ );
698
+ const down = useMemo(
699
+ () => (breakpoint) => {
700
+ switch (breakpoint) {
701
+ case "xs":
702
+ return false;
703
+ // Nothing is below xs
704
+ case "sm":
705
+ return !isSmUp;
706
+ case "md":
707
+ return !isMdUp;
708
+ case "lg":
709
+ return !isLgUp;
710
+ case "xl":
711
+ return !isXlUp;
712
+ default:
713
+ return false;
714
+ }
715
+ },
716
+ [isSmUp, isMdUp, isLgUp, isXlUp]
717
+ );
718
+ const only = useMemo(
719
+ () => (breakpoint) => {
720
+ switch (breakpoint) {
721
+ case "xs":
722
+ return isXs;
723
+ case "sm":
724
+ return isSm;
725
+ case "md":
726
+ return isMd;
727
+ case "lg":
728
+ return isLg;
729
+ case "xl":
730
+ return isXl;
731
+ default:
732
+ return false;
733
+ }
734
+ },
735
+ [isXs, isSm, isMd, isLg, isXl]
736
+ );
737
+ const between = useMemo(
738
+ () => (start, end) => {
739
+ const breakpointOrder = ["xs", "sm", "md", "lg", "xl"];
740
+ const startIndex = breakpointOrder.indexOf(start);
741
+ const endIndex = breakpointOrder.indexOf(end);
742
+ const currentIndex = breakpointOrder.indexOf(current);
743
+ return currentIndex >= startIndex && currentIndex <= endIndex;
744
+ },
745
+ [current]
746
+ );
747
+ const values = useMemo(
748
+ () => ({
749
+ xs: theme.breakpoints.values.xs,
750
+ sm: theme.breakpoints.values.sm,
751
+ md: theme.breakpoints.values.md,
752
+ lg: theme.breakpoints.values.lg,
753
+ xl: theme.breakpoints.values.xl
754
+ }),
755
+ [theme.breakpoints.values]
756
+ );
757
+ return {
758
+ current,
759
+ isXs,
760
+ isSm,
761
+ isMd,
762
+ isLg,
763
+ isXl,
764
+ isMobile,
765
+ isTablet,
766
+ isDesktop,
767
+ up,
768
+ down,
769
+ only,
770
+ between,
771
+ values
772
+ };
773
+ }
774
+ function useIsClient() {
775
+ const [isClient, setIsClient] = useState(false);
776
+ useEffect(() => {
777
+ setIsClient(true);
778
+ }, []);
779
+ return isClient;
780
+ }
781
+ function useMounted() {
782
+ const mountedRef = useRef(false);
783
+ useEffect(() => {
784
+ mountedRef.current = true;
785
+ return () => {
786
+ mountedRef.current = false;
787
+ };
788
+ }, []);
789
+ const isMounted = useCallback(() => mountedRef.current, []);
790
+ return { isMounted };
791
+ }
792
+ function usePrevious(value) {
793
+ const ref = useRef(void 0);
794
+ useEffect(() => {
795
+ ref.current = value;
796
+ }, [value]);
797
+ return ref.current;
798
+ }
799
+ function useEventListener(eventName, handler, element, options) {
800
+ const savedHandler = useRef(handler);
801
+ useEffect(() => {
802
+ savedHandler.current = handler;
803
+ }, [handler]);
804
+ useEffect(() => {
805
+ const targetElement = element?.current ?? window;
806
+ if (!targetElement?.addEventListener) {
807
+ return void 0;
808
+ }
809
+ const eventListener = (event) => savedHandler.current(event);
810
+ targetElement.addEventListener(eventName, eventListener, options);
811
+ return () => {
812
+ targetElement.removeEventListener(eventName, eventListener, options);
813
+ };
814
+ }, [eventName, element, options]);
815
+ }
816
+ function useClickOutside(handler, providedRef) {
817
+ const internalRef = useRef(null);
818
+ const ref = providedRef ?? internalRef;
819
+ const handlerRef = useRef(handler);
820
+ handlerRef.current = handler;
821
+ useEffect(() => {
822
+ const listener = (event) => {
823
+ const element = ref.current;
824
+ if (!element || element.contains(event.target)) {
825
+ return;
826
+ }
827
+ handlerRef.current(event);
828
+ };
829
+ document.addEventListener("mousedown", listener);
830
+ document.addEventListener("touchstart", listener);
831
+ return () => {
832
+ document.removeEventListener("mousedown", listener);
833
+ document.removeEventListener("touchstart", listener);
834
+ };
835
+ }, [ref]);
836
+ return ref;
837
+ }
838
+ function useInterval(callback, delay) {
839
+ const savedCallback = useRef(callback);
840
+ useEffect(() => {
841
+ savedCallback.current = callback;
842
+ }, [callback]);
843
+ useEffect(() => {
844
+ if (delay === null) {
845
+ return void 0;
846
+ }
847
+ const tick = () => savedCallback.current();
848
+ const id = setInterval(tick, delay);
849
+ return () => clearInterval(id);
850
+ }, [delay]);
851
+ }
852
+ function useTimeout(callback, delay) {
853
+ const savedCallback = useRef(callback);
854
+ const timeoutRef = useRef(null);
855
+ const [isActive, setIsActive] = useState(true);
856
+ useEffect(() => {
857
+ savedCallback.current = callback;
858
+ }, [callback]);
859
+ const clear = useCallback(() => {
860
+ if (timeoutRef.current) {
861
+ clearTimeout(timeoutRef.current);
862
+ timeoutRef.current = null;
863
+ setIsActive(false);
864
+ }
865
+ }, []);
866
+ const reset = useCallback(() => {
867
+ clear();
868
+ timeoutRef.current = setTimeout(() => {
869
+ savedCallback.current();
870
+ setIsActive(false);
871
+ }, delay);
872
+ setIsActive(true);
873
+ }, [clear, delay]);
874
+ useEffect(() => {
875
+ reset();
876
+ return clear;
877
+ }, [reset, clear]);
878
+ return useMemo(() => ({ reset, clear, isActive }), [reset, clear, isActive]);
879
+ }
880
+
881
+ export { PrismContext, PrismProvider, ProviderStack, composeProviders, conditionalProvider, createProviderStack, filterProviders, useBreakpoints, useClickOutside, useCopyToClipboard, useCountdown, useDebounce, useDebounceCallback, useEventListener, useInterval, useIsClient, useLocalStorage, useMounted, useMultiSelect, usePrevious, usePrismContext, useSetState, useTimeout, withProviderProps };
882
+ //# sourceMappingURL=chunk-WC2WM2JD.js.map
883
+ //# sourceMappingURL=chunk-WC2WM2JD.js.map