dirk-cfx-react 1.1.2 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,23 +1,19 @@
1
- import { createContext, useEffect, useRef, useState, useContext, useMemo } from 'react';
1
+ import React3, { createContext, useEffect, useRef, useState, useContext, useMemo } from 'react';
2
2
  import { create, useStore, createStore } from 'zustand';
3
3
  import axios from 'axios';
4
4
  import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
5
- import { Flex, Text, Image as Image$1, createTheme, useMantineTheme, alpha, Progress, RingProgress, Button, MantineProvider, BackgroundImage } from '@mantine/core';
6
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
+ import { Flex, Text, Image as Image$1, createTheme, Box, Code, useMantineTheme, alpha, Progress, RingProgress, Button, MantineProvider, BackgroundImage } from '@mantine/core';
6
+ import { jsxs, jsx } from 'react/jsx-runtime';
7
7
  import { motion, AnimatePresence, useMotionValue } from 'framer-motion';
8
8
  import clickSoundUrl from './click_sound-PNCRRTM4.mp3';
9
9
  import hoverSoundUrl from './hover_sound-NBUA222C.mp3';
10
10
  import { useClickOutside } from '@mantine/hooks';
11
11
  import '@mantine/core/styles.css';
12
12
  import '@mantine/notifications/styles.css';
13
- import './styles/notify.css';
14
- import './styles/fonts.css';
15
- import './styles/scrollBar.css';
16
- import './styles/tornEdge.css';
17
- import { library } from '@fortawesome/fontawesome-svg-core';
18
- import { fab } from '@fortawesome/free-brands-svg-icons';
19
- import { far } from '@fortawesome/free-regular-svg-icons';
20
- import { fas } from '@fortawesome/free-solid-svg-icons';
13
+
14
+ var __defProp = Object.defineProperty;
15
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
16
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
21
17
 
22
18
  // src/utils/colorWithAlpha.ts
23
19
  var colorNames = {
@@ -1487,6 +1483,22 @@ function SegmentedProgress(props) {
1487
1483
  }
1488
1484
  );
1489
1485
  }
1486
+ var useSettings = create(() => ({
1487
+ hydrated: false,
1488
+ game: "fivem",
1489
+ primaryColor: "dirk",
1490
+ primaryShade: 9,
1491
+ itemImgPath: "",
1492
+ customTheme: {}
1493
+ }));
1494
+ registerInitialFetch("GET_SETTINGS").then((data) => {
1495
+ useSettings.setState({
1496
+ ...data,
1497
+ hydrated: true
1498
+ });
1499
+ }).catch(() => {
1500
+ useSettings.setState({ hydrated: true });
1501
+ });
1490
1502
  function Title(props) {
1491
1503
  const game = useSettings((state) => state.game);
1492
1504
  const theme2 = useMantineTheme();
@@ -2135,6 +2147,70 @@ function useForm() {
2135
2147
  if (!store) throw new Error("useForm must be used inside a <FormProvider>");
2136
2148
  return useStore(store);
2137
2149
  }
2150
+ function useTornEdges() {
2151
+ const game = useSettings((state) => state.game);
2152
+ return game === "rdr3" ? "torn-edge-wrapper" : "";
2153
+ }
2154
+ function TornEdgeSVGFilter() {
2155
+ return /* @__PURE__ */ jsx(
2156
+ "svg",
2157
+ {
2158
+ style: { position: "absolute", width: 0, height: 0, pointerEvents: "none" },
2159
+ "aria-hidden": "true",
2160
+ children: /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("filter", { id: "torn-edge-filter", x: "-50%", y: "-50%", width: "200%", height: "200%", children: [
2161
+ /* @__PURE__ */ jsx(
2162
+ "feTurbulence",
2163
+ {
2164
+ type: "fractalNoise",
2165
+ baseFrequency: "0.018 0.022",
2166
+ numOctaves: "5",
2167
+ seed: "9",
2168
+ result: "noise1"
2169
+ }
2170
+ ),
2171
+ /* @__PURE__ */ jsx(
2172
+ "feTurbulence",
2173
+ {
2174
+ type: "fractalNoise",
2175
+ baseFrequency: "0.08 0.12",
2176
+ numOctaves: "2",
2177
+ seed: "3",
2178
+ result: "noise2"
2179
+ }
2180
+ ),
2181
+ /* @__PURE__ */ jsx("feBlend", { in: "noise1", in2: "noise2", mode: "multiply", result: "combinedNoise" }),
2182
+ /* @__PURE__ */ jsx(
2183
+ "feDisplacementMap",
2184
+ {
2185
+ in: "SourceGraphic",
2186
+ in2: "combinedNoise",
2187
+ scale: "52",
2188
+ xChannelSelector: "R",
2189
+ yChannelSelector: "G",
2190
+ result: "displaced"
2191
+ }
2192
+ ),
2193
+ /* @__PURE__ */ jsx("feGaussianBlur", { stdDeviation: "0.8", in: "displaced", result: "blurred" }),
2194
+ /* @__PURE__ */ jsx("feComponentTransfer", { in: "blurred", result: "alphaFade", children: /* @__PURE__ */ jsx("feFuncA", { type: "gamma", amplitude: "1", exponent: "1.3", offset: "-0.05" }) }),
2195
+ /* @__PURE__ */ jsx("feMorphology", { operator: "erode", radius: "0.4", in: "alphaFade", result: "eroded" }),
2196
+ /* @__PURE__ */ jsx("feMerge", { children: /* @__PURE__ */ jsx("feMergeNode", { in: "eroded" }) })
2197
+ ] }) })
2198
+ }
2199
+ );
2200
+ }
2201
+ function createScriptSettings(defaultValue) {
2202
+ const store = create(() => defaultValue);
2203
+ const useScriptSettingHooks = () => {
2204
+ useNuiEvent("UPDATE_SCRIPT_SETTINGS", (newSettings) => {
2205
+ store.setState((prev) => ({ ...prev, ...newSettings }));
2206
+ });
2207
+ };
2208
+ const updateScriptSettings = async (newSettings) => {
2209
+ store.setState((prev) => ({ ...prev, ...newSettings }));
2210
+ return await fetchNui("UPDATE_SCRIPT_SETTINGS", newSettings);
2211
+ };
2212
+ return { store, updateScriptSettings, useScriptSettingHooks };
2213
+ }
2138
2214
  var label = {
2139
2215
  fontSize: "var(--mantine-font-size-xs)",
2140
2216
  fontFamily: "Akrobat Bold",
@@ -2294,136 +2370,81 @@ var theme = createTheme({
2294
2370
  }
2295
2371
  });
2296
2372
  var theme_default = theme;
2297
- library.add(fas, far, fab);
2298
- var useSettings = create((set) => ({
2299
- game: "fivem",
2300
- primaryColor: "dirk",
2301
- primaryShade: 9,
2302
- itemImgPath: "https://assets.dirkcfx.com/items/",
2303
- customTheme: {}
2304
- }));
2305
- registerInitialFetch("GET_SETTINGS", void 0, {
2306
- game: "fivem",
2307
- primaryColor: "dirk",
2308
- primaryShade: 9,
2309
- itemImgPath: "https://assets.dirkcfx.com/items/",
2310
- customTheme: {}
2311
- }).then((data) => {
2312
- console.log("Fetched initial settings:");
2313
- useSettings.setState({
2314
- ...data
2315
- });
2316
- });
2317
- function DirkProvider(props) {
2318
- const primaryColor = useSettings((data) => data.primaryColor);
2319
- const primaryShade = useSettings((data) => data.primaryShade);
2320
- const customTheme = useSettings((data) => data.customTheme);
2321
- const game = useSettings((data) => data.game);
2322
- const mergedTheme = useMemo(() => ({
2323
- ...theme_default,
2373
+
2374
+ // src/utils/mergeMantineTheme.ts
2375
+ var isValidColorScale = (v) => Array.isArray(v) && v.length >= 5 && v.every((c) => typeof c === "string");
2376
+ function mergeMantineThemeSafe(base, custom, override) {
2377
+ const colors = { ...base.colors };
2378
+ for (const [key, value] of Object.entries(custom ?? {})) {
2379
+ if (isValidColorScale(value)) {
2380
+ colors[key] = value;
2381
+ } else {
2382
+ console.warn(`[theme] invalid color ignored: ${key}`, value);
2383
+ }
2384
+ }
2385
+ return {
2386
+ ...base,
2387
+ ...override,
2388
+ colors: {
2389
+ ...colors,
2390
+ ...override?.colors ?? {}
2391
+ }
2392
+ };
2393
+ }
2394
+ var DirkErrorBoundary = class extends React3.Component {
2395
+ constructor() {
2396
+ super(...arguments);
2397
+ __publicField(this, "state", { error: null });
2398
+ }
2399
+ static getDerivedStateFromError(error2) {
2400
+ return { error: error2 };
2401
+ }
2402
+ componentDidCatch(error2, info) {
2403
+ console.group("\u{1F525} Dirk UI Crash");
2404
+ console.error(error2);
2405
+ console.error(info.componentStack);
2406
+ console.groupEnd();
2407
+ }
2408
+ render() {
2409
+ if (!this.state.error) return this.props.children;
2410
+ return /* @__PURE__ */ jsxs(Box, { p: "md", bg: "dark.8", children: [
2411
+ /* @__PURE__ */ jsx(Text, { c: "red", fw: 600, children: "UI crashed" }),
2412
+ /* @__PURE__ */ jsx(Code, { block: true, mt: "sm", children: this.state.error.message })
2413
+ ] });
2414
+ }
2415
+ };
2416
+ function DirkProvider({ children, themeOverride }) {
2417
+ const {
2418
+ hydrated,
2324
2419
  primaryColor,
2325
2420
  primaryShade,
2326
- colors: {
2327
- ...theme_default.colors,
2328
- ...customTheme,
2329
- // Custom theme colors will override/extend base colors
2330
- ...props.themeOverride?.colors
2331
- // Props theme colors will override/extend previous colors
2332
- },
2333
- ...props.themeOverride
2334
- // Props theme will override/extend the entire theme
2335
- }), [primaryColor, primaryShade, customTheme, props.themeOverride]);
2421
+ customTheme,
2422
+ game
2423
+ } = useSettings();
2424
+ if (!hydrated) return null;
2425
+ const mergedTheme = useMemo(
2426
+ () => mergeMantineThemeSafe(
2427
+ { ...theme_default, primaryColor, primaryShade },
2428
+ customTheme,
2429
+ themeOverride
2430
+ ),
2431
+ [primaryColor, primaryShade, customTheme, themeOverride]
2432
+ );
2336
2433
  useEffect(() => {
2337
- document.fonts.ready.then(() => {
2338
- document.body.style.fontFamily = game === "rdr3" ? '"Red Dead", sans-serif' : game === "fivem" ? '"Akrobat Regular", sans-serif' : "sans-serif";
2339
- });
2434
+ document.body.style.fontFamily = game === "rdr3" ? '"Red Dead", sans-serif' : '"Akrobat Regular", sans-serif';
2340
2435
  }, [game]);
2341
- useEffect(() => {
2342
- fetchNui("NUI_READY");
2343
- }, []);
2344
- useAutoFetcher();
2345
- console.log("DirkProvider rendered with game:", game);
2346
- return /* @__PURE__ */ jsx(MantineProvider, { theme: mergedTheme, defaultColorScheme: "dark", children: /* @__PURE__ */ jsx(Wrapper, { children: props.children }) });
2347
- }
2348
- function Wrapper({ children }) {
2349
- const game = useSettings((data) => data.game);
2350
- if (!isEnvBrowser()) return /* @__PURE__ */ jsx(Fragment, { children });
2351
- return /* @__PURE__ */ jsx(
2436
+ const content = isEnvBrowser() ? /* @__PURE__ */ jsx(
2352
2437
  BackgroundImage,
2353
2438
  {
2354
2439
  w: "100vw",
2355
2440
  h: "100vh",
2356
- style: { overflow: "hidden", backgroundColor: "transparent" },
2357
2441
  src: game === "fivem" ? "https://i.ytimg.com/vi/TOxuNbXrO28/maxresdefault.jpg" : "https://raw.githubusercontent.com/Jump-On-Studios/RedM-jo_libs/refs/heads/main/source-repositories/Menu/public/assets/images/background_dev.jpg",
2358
2442
  children
2359
2443
  }
2360
- );
2361
- }
2362
- function useTornEdges() {
2363
- const game = useSettings((state) => state.game);
2364
- return game === "rdr3" ? "torn-edge-wrapper" : "";
2365
- }
2366
- function TornEdgeSVGFilter() {
2367
- return /* @__PURE__ */ jsx(
2368
- "svg",
2369
- {
2370
- style: { position: "absolute", width: 0, height: 0, pointerEvents: "none" },
2371
- "aria-hidden": "true",
2372
- children: /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("filter", { id: "torn-edge-filter", x: "-50%", y: "-50%", width: "200%", height: "200%", children: [
2373
- /* @__PURE__ */ jsx(
2374
- "feTurbulence",
2375
- {
2376
- type: "fractalNoise",
2377
- baseFrequency: "0.018 0.022",
2378
- numOctaves: "5",
2379
- seed: "9",
2380
- result: "noise1"
2381
- }
2382
- ),
2383
- /* @__PURE__ */ jsx(
2384
- "feTurbulence",
2385
- {
2386
- type: "fractalNoise",
2387
- baseFrequency: "0.08 0.12",
2388
- numOctaves: "2",
2389
- seed: "3",
2390
- result: "noise2"
2391
- }
2392
- ),
2393
- /* @__PURE__ */ jsx("feBlend", { in: "noise1", in2: "noise2", mode: "multiply", result: "combinedNoise" }),
2394
- /* @__PURE__ */ jsx(
2395
- "feDisplacementMap",
2396
- {
2397
- in: "SourceGraphic",
2398
- in2: "combinedNoise",
2399
- scale: "52",
2400
- xChannelSelector: "R",
2401
- yChannelSelector: "G",
2402
- result: "displaced"
2403
- }
2404
- ),
2405
- /* @__PURE__ */ jsx("feGaussianBlur", { stdDeviation: "0.8", in: "displaced", result: "blurred" }),
2406
- /* @__PURE__ */ jsx("feComponentTransfer", { in: "blurred", result: "alphaFade", children: /* @__PURE__ */ jsx("feFuncA", { type: "gamma", amplitude: "1", exponent: "1.3", offset: "-0.05" }) }),
2407
- /* @__PURE__ */ jsx("feMorphology", { operator: "erode", radius: "0.4", in: "alphaFade", result: "eroded" }),
2408
- /* @__PURE__ */ jsx("feMerge", { children: /* @__PURE__ */ jsx("feMergeNode", { in: "eroded" }) })
2409
- ] }) })
2410
- }
2411
- );
2412
- }
2413
- function createScriptSettings(defaultValue) {
2414
- const store = create(() => defaultValue);
2415
- const useScriptSettingHooks = () => {
2416
- useNuiEvent("UPDATE_SCRIPT_SETTINGS", (newSettings) => {
2417
- store.setState((prev) => ({ ...prev, ...newSettings }));
2418
- });
2419
- };
2420
- const updateScriptSettings = async (newSettings) => {
2421
- store.setState((prev) => ({ ...prev, ...newSettings }));
2422
- return await fetchNui("UPDATE_SCRIPT_SETTINGS", newSettings);
2423
- };
2424
- return { store, updateScriptSettings, useScriptSettingHooks };
2444
+ ) : children;
2445
+ return /* @__PURE__ */ jsx(DirkErrorBoundary, { children: /* @__PURE__ */ jsx(MantineProvider, { theme: mergedTheme, defaultColorScheme: "dark", children: content }) });
2425
2446
  }
2426
2447
 
2427
- export { BorderedIcon, Counter, DirkProvider, FloatingParticles, FormProvider, InfoBox, InputContainer, LevelBanner, LevelPanel, ModalContext, ModalProvider, MotionFlex, MotionIcon, MotionImage, MotionText, NavBar, NavigationContext, NavigationProvider, PromptModal, SegmentedControl, SegmentedProgress, Title, TornEdgeSVGFilter, colorWithAlpha, copyToClipboard, createFormStore, createScriptSettings, createSkill, fetchNui, gameToMap, getImageShape, initialFetches, internalEvent, isEnvBrowser, isProfanity, latPr100, locale, localeStore, mapCenter, mapToGame, noop, numberToRoman, openLink, registerInitialFetch, runFetches, splitFAString, updatePresignedURL, uploadImage, useAutoFetcher, useForm, useModal, useModalActions, useNavigation, useNavigationStore, useNuiEvent, useProfanityStore, useSettings, useTornEdges };
2448
+ export { BorderedIcon, Counter, DirkProvider, FloatingParticles, FormProvider, InfoBox, InputContainer, LevelBanner, LevelPanel, ModalContext, ModalProvider, MotionFlex, MotionIcon, MotionImage, MotionText, NavBar, NavigationContext, NavigationProvider, PromptModal, SegmentedControl, SegmentedProgress, Title, TornEdgeSVGFilter, colorWithAlpha, copyToClipboard, createFormStore, createScriptSettings, createSkill, fetchNui, gameToMap, getImageShape, initialFetches, internalEvent, isEnvBrowser, isProfanity, latPr100, locale, localeStore, mapCenter, mapToGame, noop, numberToRoman, openLink, registerInitialFetch, runFetches, splitFAString, updatePresignedURL, uploadImage, useAutoFetcher, useForm, useModal, useModalActions, useNavigation, useNavigationStore, useNuiEvent, useProfanityStore, useTornEdges };
2428
2449
  //# sourceMappingURL=index.js.map
2429
2450
  //# sourceMappingURL=index.js.map