dirk-cfx-react 1.1.1 → 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.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var react = require('react');
3
+ var React3 = require('react');
4
4
  var zustand = require('zustand');
5
5
  var axios = require('axios');
6
6
  var reactFontawesome = require('@fortawesome/react-fontawesome');
@@ -12,21 +12,18 @@ var hoverSoundUrl = require('./hover_sound-NBUA222C.mp3');
12
12
  var hooks = require('@mantine/hooks');
13
13
  require('@mantine/core/styles.css');
14
14
  require('@mantine/notifications/styles.css');
15
- require('./styles/notify.css');
16
- require('./styles/fonts.css');
17
- require('./styles/scrollBar.css');
18
- require('./styles/tornEdge.css');
19
- var fontawesomeSvgCore = require('@fortawesome/fontawesome-svg-core');
20
- var freeBrandsSvgIcons = require('@fortawesome/free-brands-svg-icons');
21
- var freeRegularSvgIcons = require('@fortawesome/free-regular-svg-icons');
22
- var freeSolidSvgIcons = require('@fortawesome/free-solid-svg-icons');
23
15
 
24
16
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
25
17
 
18
+ var React3__default = /*#__PURE__*/_interopDefault(React3);
26
19
  var axios__default = /*#__PURE__*/_interopDefault(axios);
27
20
  var clickSoundUrl__default = /*#__PURE__*/_interopDefault(clickSoundUrl);
28
21
  var hoverSoundUrl__default = /*#__PURE__*/_interopDefault(hoverSoundUrl);
29
22
 
23
+ var __defProp = Object.defineProperty;
24
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
25
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
26
+
30
27
  // src/utils/colorWithAlpha.ts
31
28
  var colorNames = {
32
29
  AliceBlue: { r: 240, g: 248, b: 255 },
@@ -259,7 +256,7 @@ async function runFetches() {
259
256
  );
260
257
  }
261
258
  var useAutoFetcher = () => {
262
- react.useEffect(() => {
259
+ React3.useEffect(() => {
263
260
  if (isEnvBrowser()) return;
264
261
  const run = async () => {
265
262
  await runFetches();
@@ -734,7 +731,7 @@ function createSkill(defaultSettings) {
734
731
  }));
735
732
  const useSkill = (xp) => {
736
733
  const { settings, levelMap } = useStore4();
737
- return react.useMemo(() => {
734
+ return React3.useMemo(() => {
738
735
  const currentLevel = getLevelFromXP(xp, levelMap, settings);
739
736
  const nextLevel = Math.min(currentLevel + 1, settings.maxLevel);
740
737
  const currentLevelXP = levelMap[currentLevel.toString()] || 0;
@@ -868,8 +865,8 @@ var FloatingParticles = ({
868
865
  mouseRepelStrength = 50,
869
866
  backgroundColor = "transparent"
870
867
  }) => {
871
- const containerRef = react.useRef(null);
872
- const [particles, setParticles] = react.useState([]);
868
+ const containerRef = React3.useRef(null);
869
+ const [particles, setParticles] = React3.useState([]);
873
870
  const mouseX = framerMotion.useMotionValue(0);
874
871
  const mouseY = framerMotion.useMotionValue(0);
875
872
  const durationMap = {
@@ -882,7 +879,7 @@ var FloatingParticles = ({
882
879
  const x = Math.sin(seed) * 1e4;
883
880
  return x - Math.floor(x);
884
881
  };
885
- react.useEffect(() => {
882
+ React3.useEffect(() => {
886
883
  if (!containerRef.current) return;
887
884
  const bounds = containerRef.current.getBoundingClientRect();
888
885
  const newParticles = [...Array(particleCount)].map((_, i) => {
@@ -903,7 +900,7 @@ var FloatingParticles = ({
903
900
  });
904
901
  setParticles(newParticles);
905
902
  }, [particleCount, icons.length, duration.base, duration.variance]);
906
- react.useEffect(() => {
903
+ React3.useEffect(() => {
907
904
  if (!containerRef.current) return;
908
905
  const handleMouseMove = (e) => {
909
906
  const bounds = containerRef.current.getBoundingClientRect();
@@ -952,7 +949,7 @@ var FloatingParticles = ({
952
949
  container.removeEventListener("mouseleave", handleMouseLeave);
953
950
  };
954
951
  }, [mouseX, mouseY, mouseRepelDistance, mouseRepelStrength]);
955
- react.useEffect(() => {
952
+ React3.useEffect(() => {
956
953
  const handleResize = () => {
957
954
  if (!containerRef.current) return;
958
955
  const bounds = containerRef.current.getBoundingClientRect();
@@ -1380,23 +1377,23 @@ function Segment(props) {
1380
1377
  }
1381
1378
  );
1382
1379
  }
1383
- var NavigationContext = react.createContext(null);
1380
+ var NavigationContext = React3.createContext(null);
1384
1381
  function useNavigation(selector) {
1385
- const navigation = react.useContext(NavigationContext);
1382
+ const navigation = React3.useContext(NavigationContext);
1386
1383
  if (!navigation) {
1387
1384
  throw new Error("useNavigation must be used within a NavigationProvider");
1388
1385
  }
1389
1386
  return zustand.useStore(navigation, selector);
1390
1387
  }
1391
1388
  function useNavigationStore() {
1392
- const navigation = react.useContext(NavigationContext);
1389
+ const navigation = React3.useContext(NavigationContext);
1393
1390
  if (!navigation) {
1394
1391
  throw new Error("useNavigationStore must be used within a NavigationProvider");
1395
1392
  }
1396
1393
  return navigation;
1397
1394
  }
1398
1395
  function NavigationProvider({ children, defaultPage }) {
1399
- const storeRef = react.useRef(
1396
+ const storeRef = React3.useRef(
1400
1397
  zustand.create(() => ({
1401
1398
  pageId: defaultPage || "home"
1402
1399
  }))
@@ -1495,6 +1492,22 @@ function SegmentedProgress(props) {
1495
1492
  }
1496
1493
  );
1497
1494
  }
1495
+ var useSettings = zustand.create(() => ({
1496
+ hydrated: false,
1497
+ game: "fivem",
1498
+ primaryColor: "dirk",
1499
+ primaryShade: 9,
1500
+ itemImgPath: "",
1501
+ customTheme: {}
1502
+ }));
1503
+ registerInitialFetch("GET_SETTINGS").then((data) => {
1504
+ useSettings.setState({
1505
+ ...data,
1506
+ hydrated: true
1507
+ });
1508
+ }).catch(() => {
1509
+ useSettings.setState({ hydrated: true });
1510
+ });
1498
1511
  function Title(props) {
1499
1512
  const game = useSettings((state) => state.game);
1500
1513
  const theme2 = core.useMantineTheme();
@@ -1738,16 +1751,16 @@ function LevelPanel(props) {
1738
1751
  }
1739
1752
  );
1740
1753
  }
1741
- var ModalContext = react.createContext(null);
1754
+ var ModalContext = React3.createContext(null);
1742
1755
  function useModal(selector) {
1743
- const modal = react.useContext(ModalContext);
1756
+ const modal = React3.useContext(ModalContext);
1744
1757
  if (!modal) {
1745
1758
  throw new Error("useModal must be used within a ModalProvider");
1746
1759
  }
1747
1760
  return zustand.useStore(modal, selector);
1748
1761
  }
1749
1762
  function ModalProvider({ children, defaultPage }) {
1750
- const storeRef = react.useRef(
1763
+ const storeRef = React3.useRef(
1751
1764
  zustand.create(() => ({
1752
1765
  active: null
1753
1766
  }))
@@ -1758,7 +1771,7 @@ function ModalProvider({ children, defaultPage }) {
1758
1771
  ] });
1759
1772
  }
1760
1773
  function useModalActions() {
1761
- const modal = react.useContext(ModalContext);
1774
+ const modal = React3.useContext(ModalContext);
1762
1775
  if (!modal) throw new Error("useModalActions must be used within a ModalProvider");
1763
1776
  const showModal = (openModal) => {
1764
1777
  modal.setState({ active: openModal });
@@ -1935,11 +1948,11 @@ function PromptModal(props) {
1935
1948
  );
1936
1949
  }
1937
1950
  var useNuiEvent = (action, handler) => {
1938
- const savedHandler = react.useRef(noop);
1939
- react.useEffect(() => {
1951
+ const savedHandler = React3.useRef(noop);
1952
+ React3.useEffect(() => {
1940
1953
  savedHandler.current = handler;
1941
1954
  }, [handler]);
1942
- react.useEffect(() => {
1955
+ React3.useEffect(() => {
1943
1956
  const eventListener = (event) => {
1944
1957
  const { action: eventAction, data } = event.data;
1945
1958
  if (savedHandler.current) {
@@ -2128,21 +2141,85 @@ function createFormStore(initialValues, validationRules, onSubmit) {
2128
2141
  }
2129
2142
  }));
2130
2143
  }
2131
- var FormContext = react.createContext(null);
2144
+ var FormContext = React3.createContext(null);
2132
2145
  function FormProvider({
2133
2146
  initialValues,
2134
2147
  validate,
2135
2148
  onSubmit,
2136
2149
  children
2137
2150
  }) {
2138
- const storeRef = react.useRef(createFormStore(initialValues, validate, onSubmit));
2151
+ const storeRef = React3.useRef(createFormStore(initialValues, validate, onSubmit));
2139
2152
  return /* @__PURE__ */ jsxRuntime.jsx(FormContext.Provider, { value: storeRef.current, children });
2140
2153
  }
2141
2154
  function useForm() {
2142
- const store = react.useContext(FormContext);
2155
+ const store = React3.useContext(FormContext);
2143
2156
  if (!store) throw new Error("useForm must be used inside a <FormProvider>");
2144
2157
  return zustand.useStore(store);
2145
2158
  }
2159
+ function useTornEdges() {
2160
+ const game = useSettings((state) => state.game);
2161
+ return game === "rdr3" ? "torn-edge-wrapper" : "";
2162
+ }
2163
+ function TornEdgeSVGFilter() {
2164
+ return /* @__PURE__ */ jsxRuntime.jsx(
2165
+ "svg",
2166
+ {
2167
+ style: { position: "absolute", width: 0, height: 0, pointerEvents: "none" },
2168
+ "aria-hidden": "true",
2169
+ children: /* @__PURE__ */ jsxRuntime.jsx("defs", { children: /* @__PURE__ */ jsxRuntime.jsxs("filter", { id: "torn-edge-filter", x: "-50%", y: "-50%", width: "200%", height: "200%", children: [
2170
+ /* @__PURE__ */ jsxRuntime.jsx(
2171
+ "feTurbulence",
2172
+ {
2173
+ type: "fractalNoise",
2174
+ baseFrequency: "0.018 0.022",
2175
+ numOctaves: "5",
2176
+ seed: "9",
2177
+ result: "noise1"
2178
+ }
2179
+ ),
2180
+ /* @__PURE__ */ jsxRuntime.jsx(
2181
+ "feTurbulence",
2182
+ {
2183
+ type: "fractalNoise",
2184
+ baseFrequency: "0.08 0.12",
2185
+ numOctaves: "2",
2186
+ seed: "3",
2187
+ result: "noise2"
2188
+ }
2189
+ ),
2190
+ /* @__PURE__ */ jsxRuntime.jsx("feBlend", { in: "noise1", in2: "noise2", mode: "multiply", result: "combinedNoise" }),
2191
+ /* @__PURE__ */ jsxRuntime.jsx(
2192
+ "feDisplacementMap",
2193
+ {
2194
+ in: "SourceGraphic",
2195
+ in2: "combinedNoise",
2196
+ scale: "52",
2197
+ xChannelSelector: "R",
2198
+ yChannelSelector: "G",
2199
+ result: "displaced"
2200
+ }
2201
+ ),
2202
+ /* @__PURE__ */ jsxRuntime.jsx("feGaussianBlur", { stdDeviation: "0.8", in: "displaced", result: "blurred" }),
2203
+ /* @__PURE__ */ jsxRuntime.jsx("feComponentTransfer", { in: "blurred", result: "alphaFade", children: /* @__PURE__ */ jsxRuntime.jsx("feFuncA", { type: "gamma", amplitude: "1", exponent: "1.3", offset: "-0.05" }) }),
2204
+ /* @__PURE__ */ jsxRuntime.jsx("feMorphology", { operator: "erode", radius: "0.4", in: "alphaFade", result: "eroded" }),
2205
+ /* @__PURE__ */ jsxRuntime.jsx("feMerge", { children: /* @__PURE__ */ jsxRuntime.jsx("feMergeNode", { in: "eroded" }) })
2206
+ ] }) })
2207
+ }
2208
+ );
2209
+ }
2210
+ function createScriptSettings(defaultValue) {
2211
+ const store = zustand.create(() => defaultValue);
2212
+ const useScriptSettingHooks = () => {
2213
+ useNuiEvent("UPDATE_SCRIPT_SETTINGS", (newSettings) => {
2214
+ store.setState((prev) => ({ ...prev, ...newSettings }));
2215
+ });
2216
+ };
2217
+ const updateScriptSettings = async (newSettings) => {
2218
+ store.setState((prev) => ({ ...prev, ...newSettings }));
2219
+ return await fetchNui("UPDATE_SCRIPT_SETTINGS", newSettings);
2220
+ };
2221
+ return { store, updateScriptSettings, useScriptSettingHooks };
2222
+ }
2146
2223
  var label = {
2147
2224
  fontSize: "var(--mantine-font-size-xs)",
2148
2225
  fontFamily: "Akrobat Bold",
@@ -2302,134 +2379,79 @@ var theme = core.createTheme({
2302
2379
  }
2303
2380
  });
2304
2381
  var theme_default = theme;
2305
- fontawesomeSvgCore.library.add(freeSolidSvgIcons.fas, freeRegularSvgIcons.far, freeBrandsSvgIcons.fab);
2306
- var useSettings = zustand.create((set) => ({
2307
- game: "fivem",
2308
- primaryColor: "dirk",
2309
- primaryShade: 9,
2310
- itemImgPath: "https://assets.dirkcfx.com/items/",
2311
- customTheme: {}
2312
- }));
2313
- registerInitialFetch("GET_SETTINGS", void 0, {
2314
- game: "fivem",
2315
- primaryColor: "dirk",
2316
- primaryShade: 9,
2317
- itemImgPath: "https://assets.dirkcfx.com/items/",
2318
- customTheme: {}
2319
- }).then((data) => {
2320
- useSettings.setState({
2321
- ...data
2322
- });
2323
- });
2324
- function DirkProvider(props) {
2325
- const primaryColor = useSettings((data) => data.primaryColor);
2326
- const primaryShade = useSettings((data) => data.primaryShade);
2327
- const customTheme = useSettings((data) => data.customTheme);
2328
- const game = useSettings((data) => data.game);
2329
- const mergedTheme = react.useMemo(() => ({
2330
- ...theme_default,
2382
+
2383
+ // src/utils/mergeMantineTheme.ts
2384
+ var isValidColorScale = (v) => Array.isArray(v) && v.length >= 5 && v.every((c) => typeof c === "string");
2385
+ function mergeMantineThemeSafe(base, custom, override) {
2386
+ const colors = { ...base.colors };
2387
+ for (const [key, value] of Object.entries(custom ?? {})) {
2388
+ if (isValidColorScale(value)) {
2389
+ colors[key] = value;
2390
+ } else {
2391
+ console.warn(`[theme] invalid color ignored: ${key}`, value);
2392
+ }
2393
+ }
2394
+ return {
2395
+ ...base,
2396
+ ...override,
2397
+ colors: {
2398
+ ...colors,
2399
+ ...override?.colors ?? {}
2400
+ }
2401
+ };
2402
+ }
2403
+ var DirkErrorBoundary = class extends React3__default.default.Component {
2404
+ constructor() {
2405
+ super(...arguments);
2406
+ __publicField(this, "state", { error: null });
2407
+ }
2408
+ static getDerivedStateFromError(error2) {
2409
+ return { error: error2 };
2410
+ }
2411
+ componentDidCatch(error2, info) {
2412
+ console.group("\u{1F525} Dirk UI Crash");
2413
+ console.error(error2);
2414
+ console.error(info.componentStack);
2415
+ console.groupEnd();
2416
+ }
2417
+ render() {
2418
+ if (!this.state.error) return this.props.children;
2419
+ return /* @__PURE__ */ jsxRuntime.jsxs(core.Box, { p: "md", bg: "dark.8", children: [
2420
+ /* @__PURE__ */ jsxRuntime.jsx(core.Text, { c: "red", fw: 600, children: "UI crashed" }),
2421
+ /* @__PURE__ */ jsxRuntime.jsx(core.Code, { block: true, mt: "sm", children: this.state.error.message })
2422
+ ] });
2423
+ }
2424
+ };
2425
+ function DirkProvider({ children, themeOverride }) {
2426
+ const {
2427
+ hydrated,
2331
2428
  primaryColor,
2332
2429
  primaryShade,
2333
- colors: {
2334
- ...theme_default.colors,
2335
- ...customTheme,
2336
- // Custom theme colors will override/extend base colors
2337
- ...props.themeOverride?.colors
2338
- // Props theme colors will override/extend previous colors
2339
- },
2340
- ...props.themeOverride
2341
- // Props theme will override/extend the entire theme
2342
- }), [primaryColor, primaryShade, customTheme, props.themeOverride]);
2343
- console.log("created merged theme:");
2344
- console.log(mergedTheme);
2345
- react.useEffect(() => {
2346
- document.fonts.ready.then(() => {
2347
- document.body.style.fontFamily = game === "rdr3" ? '"Red Dead", sans-serif' : game === "fivem" ? '"Akrobat Regular", sans-serif' : "sans-serif";
2348
- });
2430
+ customTheme,
2431
+ game
2432
+ } = useSettings();
2433
+ if (!hydrated) return null;
2434
+ const mergedTheme = React3.useMemo(
2435
+ () => mergeMantineThemeSafe(
2436
+ { ...theme_default, primaryColor, primaryShade },
2437
+ customTheme,
2438
+ themeOverride
2439
+ ),
2440
+ [primaryColor, primaryShade, customTheme, themeOverride]
2441
+ );
2442
+ React3.useEffect(() => {
2443
+ document.body.style.fontFamily = game === "rdr3" ? '"Red Dead", sans-serif' : '"Akrobat Regular", sans-serif';
2349
2444
  }, [game]);
2350
- react.useEffect(() => {
2351
- fetchNui("NUI_READY");
2352
- }, []);
2353
- useAutoFetcher();
2354
- return /* @__PURE__ */ jsxRuntime.jsx(core.MantineProvider, { theme: mergedTheme, defaultColorScheme: "dark", children: /* @__PURE__ */ jsxRuntime.jsx(Wrapper, { children: props.children }) });
2355
- }
2356
- function Wrapper({ children }) {
2357
- const game = useSettings((data) => data.game);
2358
- if (!isEnvBrowser()) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
2359
- return /* @__PURE__ */ jsxRuntime.jsx(
2445
+ const content = isEnvBrowser() ? /* @__PURE__ */ jsxRuntime.jsx(
2360
2446
  core.BackgroundImage,
2361
2447
  {
2362
2448
  w: "100vw",
2363
2449
  h: "100vh",
2364
- style: { overflow: "hidden", backgroundColor: "transparent" },
2365
2450
  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",
2366
2451
  children
2367
2452
  }
2368
- );
2369
- }
2370
- function useTornEdges() {
2371
- const game = useSettings((state) => state.game);
2372
- return game === "rdr3" ? "torn-edge-wrapper" : "";
2373
- }
2374
- function TornEdgeSVGFilter() {
2375
- return /* @__PURE__ */ jsxRuntime.jsx(
2376
- "svg",
2377
- {
2378
- style: { position: "absolute", width: 0, height: 0, pointerEvents: "none" },
2379
- "aria-hidden": "true",
2380
- children: /* @__PURE__ */ jsxRuntime.jsx("defs", { children: /* @__PURE__ */ jsxRuntime.jsxs("filter", { id: "torn-edge-filter", x: "-50%", y: "-50%", width: "200%", height: "200%", children: [
2381
- /* @__PURE__ */ jsxRuntime.jsx(
2382
- "feTurbulence",
2383
- {
2384
- type: "fractalNoise",
2385
- baseFrequency: "0.018 0.022",
2386
- numOctaves: "5",
2387
- seed: "9",
2388
- result: "noise1"
2389
- }
2390
- ),
2391
- /* @__PURE__ */ jsxRuntime.jsx(
2392
- "feTurbulence",
2393
- {
2394
- type: "fractalNoise",
2395
- baseFrequency: "0.08 0.12",
2396
- numOctaves: "2",
2397
- seed: "3",
2398
- result: "noise2"
2399
- }
2400
- ),
2401
- /* @__PURE__ */ jsxRuntime.jsx("feBlend", { in: "noise1", in2: "noise2", mode: "multiply", result: "combinedNoise" }),
2402
- /* @__PURE__ */ jsxRuntime.jsx(
2403
- "feDisplacementMap",
2404
- {
2405
- in: "SourceGraphic",
2406
- in2: "combinedNoise",
2407
- scale: "52",
2408
- xChannelSelector: "R",
2409
- yChannelSelector: "G",
2410
- result: "displaced"
2411
- }
2412
- ),
2413
- /* @__PURE__ */ jsxRuntime.jsx("feGaussianBlur", { stdDeviation: "0.8", in: "displaced", result: "blurred" }),
2414
- /* @__PURE__ */ jsxRuntime.jsx("feComponentTransfer", { in: "blurred", result: "alphaFade", children: /* @__PURE__ */ jsxRuntime.jsx("feFuncA", { type: "gamma", amplitude: "1", exponent: "1.3", offset: "-0.05" }) }),
2415
- /* @__PURE__ */ jsxRuntime.jsx("feMorphology", { operator: "erode", radius: "0.4", in: "alphaFade", result: "eroded" }),
2416
- /* @__PURE__ */ jsxRuntime.jsx("feMerge", { children: /* @__PURE__ */ jsxRuntime.jsx("feMergeNode", { in: "eroded" }) })
2417
- ] }) })
2418
- }
2419
- );
2420
- }
2421
- function createScriptSettings(defaultValue) {
2422
- const store = zustand.create(() => defaultValue);
2423
- const useScriptSettingHooks = () => {
2424
- useNuiEvent("UPDATE_SCRIPT_SETTINGS", (newSettings) => {
2425
- store.setState((prev) => ({ ...prev, ...newSettings }));
2426
- });
2427
- };
2428
- const updateScriptSettings = async (newSettings) => {
2429
- store.setState((prev) => ({ ...prev, ...newSettings }));
2430
- return await fetchNui("UPDATE_SCRIPT_SETTINGS", newSettings);
2431
- };
2432
- return { store, updateScriptSettings, useScriptSettingHooks };
2453
+ ) : children;
2454
+ return /* @__PURE__ */ jsxRuntime.jsx(DirkErrorBoundary, { children: /* @__PURE__ */ jsxRuntime.jsx(core.MantineProvider, { theme: mergedTheme, defaultColorScheme: "dark", children: content }) });
2433
2455
  }
2434
2456
 
2435
2457
  exports.BorderedIcon = BorderedIcon;
@@ -2488,7 +2510,6 @@ exports.useNavigation = useNavigation;
2488
2510
  exports.useNavigationStore = useNavigationStore;
2489
2511
  exports.useNuiEvent = useNuiEvent;
2490
2512
  exports.useProfanityStore = useProfanityStore;
2491
- exports.useSettings = useSettings;
2492
2513
  exports.useTornEdges = useTornEdges;
2493
2514
  //# sourceMappingURL=index.cjs.map
2494
2515
  //# sourceMappingURL=index.cjs.map