dirk-cfx-react 1.1.2 → 1.1.6

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,9 +1,9 @@
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';
@@ -19,6 +19,10 @@ import { fab } from '@fortawesome/free-brands-svg-icons';
19
19
  import { far } from '@fortawesome/free-regular-svg-icons';
20
20
  import { fas } from '@fortawesome/free-solid-svg-icons';
21
21
 
22
+ var __defProp = Object.defineProperty;
23
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
24
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
25
+
22
26
  // src/utils/colorWithAlpha.ts
23
27
  var colorNames = {
24
28
  AliceBlue: { r: 240, g: 248, b: 255 },
@@ -797,6 +801,33 @@ async function getImageShape(file) {
797
801
  img.src = typeof file === "string" ? file : URL.createObjectURL(file);
798
802
  });
799
803
  }
804
+ var useSettings = create(() => ({
805
+ hydrated: false,
806
+ game: "fivem",
807
+ primaryColor: "dirk",
808
+ primaryShade: 9,
809
+ itemImgPath: "",
810
+ customTheme: [
811
+ "#f0f4ff",
812
+ "#d9e3ff",
813
+ "#bfcfff",
814
+ "#a6bbff",
815
+ "#8ca7ff",
816
+ "#7393ff",
817
+ "#5a7fff",
818
+ "#406bff",
819
+ "#2547ff",
820
+ "#0b33ff"
821
+ ]
822
+ }));
823
+ registerInitialFetch("GET_SETTINGS").then((data) => {
824
+ useSettings.setState({
825
+ ...data,
826
+ hydrated: true
827
+ });
828
+ }).catch(() => {
829
+ useSettings.setState({ hydrated: true });
830
+ });
800
831
  function BorderedIcon(props) {
801
832
  const theme2 = useMantineTheme();
802
833
  return /* @__PURE__ */ jsx(
@@ -2135,6 +2166,70 @@ function useForm() {
2135
2166
  if (!store) throw new Error("useForm must be used inside a <FormProvider>");
2136
2167
  return useStore(store);
2137
2168
  }
2169
+ function useTornEdges() {
2170
+ const game = useSettings((state) => state.game);
2171
+ return game === "rdr3" ? "torn-edge-wrapper" : "";
2172
+ }
2173
+ function TornEdgeSVGFilter() {
2174
+ return /* @__PURE__ */ jsx(
2175
+ "svg",
2176
+ {
2177
+ style: { position: "absolute", width: 0, height: 0, pointerEvents: "none" },
2178
+ "aria-hidden": "true",
2179
+ children: /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("filter", { id: "torn-edge-filter", x: "-50%", y: "-50%", width: "200%", height: "200%", children: [
2180
+ /* @__PURE__ */ jsx(
2181
+ "feTurbulence",
2182
+ {
2183
+ type: "fractalNoise",
2184
+ baseFrequency: "0.018 0.022",
2185
+ numOctaves: "5",
2186
+ seed: "9",
2187
+ result: "noise1"
2188
+ }
2189
+ ),
2190
+ /* @__PURE__ */ jsx(
2191
+ "feTurbulence",
2192
+ {
2193
+ type: "fractalNoise",
2194
+ baseFrequency: "0.08 0.12",
2195
+ numOctaves: "2",
2196
+ seed: "3",
2197
+ result: "noise2"
2198
+ }
2199
+ ),
2200
+ /* @__PURE__ */ jsx("feBlend", { in: "noise1", in2: "noise2", mode: "multiply", result: "combinedNoise" }),
2201
+ /* @__PURE__ */ jsx(
2202
+ "feDisplacementMap",
2203
+ {
2204
+ in: "SourceGraphic",
2205
+ in2: "combinedNoise",
2206
+ scale: "52",
2207
+ xChannelSelector: "R",
2208
+ yChannelSelector: "G",
2209
+ result: "displaced"
2210
+ }
2211
+ ),
2212
+ /* @__PURE__ */ jsx("feGaussianBlur", { stdDeviation: "0.8", in: "displaced", result: "blurred" }),
2213
+ /* @__PURE__ */ jsx("feComponentTransfer", { in: "blurred", result: "alphaFade", children: /* @__PURE__ */ jsx("feFuncA", { type: "gamma", amplitude: "1", exponent: "1.3", offset: "-0.05" }) }),
2214
+ /* @__PURE__ */ jsx("feMorphology", { operator: "erode", radius: "0.4", in: "alphaFade", result: "eroded" }),
2215
+ /* @__PURE__ */ jsx("feMerge", { children: /* @__PURE__ */ jsx("feMergeNode", { in: "eroded" }) })
2216
+ ] }) })
2217
+ }
2218
+ );
2219
+ }
2220
+ function createScriptSettings(defaultValue) {
2221
+ const store = create(() => defaultValue);
2222
+ const useScriptSettingHooks = () => {
2223
+ useNuiEvent("UPDATE_SCRIPT_SETTINGS", (newSettings) => {
2224
+ store.setState((prev) => ({ ...prev, ...newSettings }));
2225
+ });
2226
+ };
2227
+ const updateScriptSettings = async (newSettings) => {
2228
+ store.setState((prev) => ({ ...prev, ...newSettings }));
2229
+ return await fetchNui("UPDATE_SCRIPT_SETTINGS", newSettings);
2230
+ };
2231
+ return { store, updateScriptSettings, useScriptSettingHooks };
2232
+ }
2138
2233
  var label = {
2139
2234
  fontSize: "var(--mantine-font-size-xs)",
2140
2235
  fontFamily: "Akrobat Bold",
@@ -2294,134 +2389,77 @@ var theme = createTheme({
2294
2389
  }
2295
2390
  });
2296
2391
  var theme_default = theme;
2392
+
2393
+ // src/utils/mergeMantineTheme.ts
2394
+ var isValidColorScale = (v) => Array.isArray(v) && v.length === 10 && v.every((shade) => typeof shade === "string");
2395
+ function mergeMantineThemeSafe(base, custom, override) {
2396
+ const colors = { ...base.colors };
2397
+ if (custom && isValidColorScale(custom)) {
2398
+ colors["custom"] = custom;
2399
+ }
2400
+ return {
2401
+ ...base,
2402
+ ...override,
2403
+ colors: {
2404
+ ...colors,
2405
+ ...override?.colors ?? {}
2406
+ }
2407
+ };
2408
+ }
2409
+ var DirkErrorBoundary = class extends React3.Component {
2410
+ constructor() {
2411
+ super(...arguments);
2412
+ __publicField(this, "state", { error: null });
2413
+ }
2414
+ static getDerivedStateFromError(error2) {
2415
+ return { error: error2 };
2416
+ }
2417
+ componentDidCatch(error2, info) {
2418
+ console.group("\u{1F525} Dirk UI Crash");
2419
+ console.error(error2);
2420
+ console.error(info.componentStack);
2421
+ console.groupEnd();
2422
+ }
2423
+ render() {
2424
+ if (!this.state.error) return this.props.children;
2425
+ return /* @__PURE__ */ jsxs(Box, { p: "md", bg: "dark.8", children: [
2426
+ /* @__PURE__ */ jsx(Text, { c: "red", fw: 600, children: "UI crashed" }),
2427
+ /* @__PURE__ */ jsx(Code, { block: true, mt: "sm", children: this.state.error.message })
2428
+ ] });
2429
+ }
2430
+ };
2297
2431
  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,
2432
+ function DirkProvider({ children, themeOverride }) {
2433
+ const {
2434
+ hydrated,
2324
2435
  primaryColor,
2325
2436
  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]);
2437
+ customTheme,
2438
+ game
2439
+ } = useSettings();
2440
+ if (!hydrated) return null;
2441
+ const mergedTheme = useMemo(
2442
+ () => mergeMantineThemeSafe(
2443
+ { ...theme_default, primaryColor, primaryShade },
2444
+ customTheme,
2445
+ themeOverride
2446
+ ),
2447
+ [primaryColor, primaryShade, customTheme, themeOverride]
2448
+ );
2336
2449
  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
- });
2450
+ document.body.style.fontFamily = game === "rdr3" ? '"Red Dead", sans-serif' : '"Akrobat Regular", sans-serif';
2451
+ console.log(`%cNew Font Applied: ${document.body.style.fontFamily}`, "font-family: " + document.body.style.fontFamily);
2340
2452
  }, [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(
2453
+ const content = isEnvBrowser() ? /* @__PURE__ */ jsx(
2352
2454
  BackgroundImage,
2353
2455
  {
2354
2456
  w: "100vw",
2355
2457
  h: "100vh",
2356
- style: { overflow: "hidden", backgroundColor: "transparent" },
2357
2458
  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
2459
  children
2359
2460
  }
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 };
2461
+ ) : children;
2462
+ return /* @__PURE__ */ jsx(DirkErrorBoundary, { children: /* @__PURE__ */ jsx(MantineProvider, { theme: mergedTheme, defaultColorScheme: "dark", children: content }) });
2425
2463
  }
2426
2464
 
2427
2465
  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 };