@decky/ui 4.16.4 → 5.0.0

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 (92) hide show
  1. package/README.md +4 -1
  2. package/dist/class-mapper.d.ts +1 -1
  3. package/dist/class-mapper.js +3 -3
  4. package/dist/common-modules.d.ts +3 -0
  5. package/dist/common-modules.js +12 -0
  6. package/dist/components/ButtonItem.js +3 -3
  7. package/dist/components/Carousel.js +2 -2
  8. package/dist/components/ControlsList.js +2 -2
  9. package/dist/components/Dialog.js +10 -9
  10. package/dist/components/DialogCheckbox.js +2 -3
  11. package/dist/components/Dropdown.js +1 -1
  12. package/dist/components/ErrorBoundary.js +1 -1
  13. package/dist/components/Field.js +2 -2
  14. package/dist/components/FocusRing.js +1 -1
  15. package/dist/components/Focusable.js +1 -1
  16. package/dist/components/Marquee.js +2 -2
  17. package/dist/components/Menu.js +7 -5
  18. package/dist/components/Modal.js +9 -4
  19. package/dist/components/Panel.d.ts +2 -4
  20. package/dist/components/Panel.js +5 -4
  21. package/dist/components/ProgressBar.d.ts +3 -3
  22. package/dist/components/ProgressBar.js +4 -4
  23. package/dist/components/Scroll.js +3 -3
  24. package/dist/components/SidebarNavigation.js +2 -2
  25. package/dist/components/SliderField.js +2 -2
  26. package/dist/components/Spinner.js +2 -2
  27. package/dist/components/SteamSpinner.js +2 -2
  28. package/dist/components/Tabs.d.ts +2 -2
  29. package/dist/components/Tabs.js +4 -3
  30. package/dist/components/TextField.js +1 -1
  31. package/dist/components/Toggle.js +1 -1
  32. package/dist/components/ToggleField.js +2 -2
  33. package/dist/components/Wrappers.d.ts +2 -0
  34. package/dist/components/Wrappers.js +3 -0
  35. package/dist/components/index.d.ts +1 -0
  36. package/dist/components/index.js +1 -0
  37. package/dist/custom-components/ColorPickerModal.js +5 -6
  38. package/dist/deck-hooks/useParams.js +1 -1
  39. package/dist/globals/stores/appstore.d.ts +1 -1
  40. package/dist/index.d.ts +3 -1
  41. package/dist/index.js +3 -1
  42. package/dist/{webpack.d.ts → module-system.d.ts} +12 -3
  43. package/dist/module-system.js +244 -0
  44. package/dist/modules/Router.js +1 -1
  45. package/dist/tsconfig.tsbuildinfo +1 -1
  46. package/dist/utils/classData/index.d.ts +811 -0
  47. package/dist/utils/classData/index.js +1645 -0
  48. package/dist/utils/react/react.js +1 -1
  49. package/dist/utils/react/treepatcher.js +1 -1
  50. package/dist/utils/static-classes.d.ts +1 -46
  51. package/dist/utils/static-classes.js +1 -24
  52. package/package.json +1 -1
  53. package/src/class-mapper.ts +3 -3
  54. package/src/common-modules.ts +15 -0
  55. package/src/components/ButtonItem.ts +3 -3
  56. package/src/components/Carousel.ts +2 -2
  57. package/src/components/ControlsList.ts +2 -2
  58. package/src/components/Dialog.ts +12 -14
  59. package/src/components/DialogCheckbox.ts +2 -5
  60. package/src/components/Dropdown.tsx +1 -1
  61. package/src/components/ErrorBoundary.ts +1 -1
  62. package/src/components/Field.ts +2 -2
  63. package/src/components/FocusRing.ts +1 -1
  64. package/src/components/Focusable.ts +1 -1
  65. package/src/components/Marquee.ts +3 -3
  66. package/src/components/Menu.ts +20 -6
  67. package/src/components/Modal.ts +23 -7
  68. package/src/components/Panel.ts +12 -10
  69. package/src/components/ProgressBar.ts +12 -15
  70. package/src/components/Scroll.ts +3 -3
  71. package/src/components/SidebarNavigation.ts +3 -3
  72. package/src/components/SliderField.ts +2 -3
  73. package/src/components/Spinner.ts +2 -2
  74. package/src/components/SteamSpinner.ts +3 -3
  75. package/src/components/Tabs.ts +4 -3
  76. package/src/components/TextField.ts +2 -1
  77. package/src/components/Toggle.ts +1 -1
  78. package/src/components/ToggleField.ts +2 -3
  79. package/src/components/Wrappers.ts +12 -0
  80. package/src/components/index.ts +1 -0
  81. package/src/custom-components/ColorPickerModal.tsx +5 -6
  82. package/src/deck-hooks/useParams.ts +1 -1
  83. package/src/globals/stores/appstore.ts +1 -1
  84. package/src/index.ts +3 -1
  85. package/src/module-system.ts +309 -0
  86. package/src/modules/Router.ts +1 -1
  87. package/src/utils/classData/index.ts +1680 -0
  88. package/src/utils/react/react.ts +1 -1
  89. package/src/utils/react/treepatcher.ts +1 -1
  90. package/src/utils/static-classes.ts +1 -984
  91. package/dist/webpack.js +0 -121
  92. package/src/webpack.ts +0 -160
@@ -1,13 +1,13 @@
1
1
  import { FC, ReactNode } from 'react';
2
2
 
3
- import { Export, findModuleByExport, findModuleExport } from '../webpack';
3
+ import { Export, findModuleByExport, findModuleExport } from '../module-system';
4
4
 
5
- const ScrollingModule = findModuleByExport((e: Export) => e?.render?.toString?.().includes('{case"x":'));
5
+ const ScrollingModule = findModuleByExport((e: Export) => e?.render?.toString?.().includes('{case`x`:'));
6
6
 
7
7
  const ScrollingModuleProps = ScrollingModule ? Object.values(ScrollingModule) : [];
8
8
 
9
9
  export const ScrollPanel = ScrollingModuleProps.find((prop: any) =>
10
- prop?.render?.toString?.().includes('{case"x":'),
10
+ prop?.render?.toString?.().includes('{case`x`:')
11
11
  ) as FC<{ children?: ReactNode }>;
12
12
 
13
13
  export const ScrollPanelGroup: FC<{ children?: ReactNode }> = findModuleExport((e: Export) =>
@@ -1,6 +1,6 @@
1
1
  import { ReactNode, FC } from 'react';
2
2
 
3
- import { Export, findModuleExport } from '../webpack';
3
+ import { Var, findVar } from '../module-system';
4
4
  import { createPropListRegex } from '../utils';
5
5
 
6
6
  export interface SidebarNavigationPage {
@@ -25,6 +25,6 @@ export interface SidebarNavigationProps {
25
25
  }
26
26
 
27
27
  const sidebarNavigationRegex = createPropListRegex(["pages", "fnSetNavigateToPage", "disableRouteReporting"]);
28
- export const SidebarNavigation = findModuleExport((e: Export) =>
29
- e?.toString && sidebarNavigationRegex.test(e.toString?.()),
28
+ export const SidebarNavigation = findVar((e: Var) =>
29
+ typeof e == "function" && sidebarNavigationRegex.test(e.toString?.()),
30
30
  ) as FC<SidebarNavigationProps>;
@@ -1,6 +1,6 @@
1
1
  import { FC } from 'react';
2
2
 
3
- import { CommonUIModule } from '../webpack';
3
+ import { CommonUIModule } from '../common-modules';
4
4
  import { ItemProps } from './Item';
5
5
 
6
6
  export interface NotchLabel {
@@ -29,6 +29,5 @@ export interface SliderFieldProps extends ItemProps {
29
29
  }
30
30
 
31
31
  export const SliderField = Object.values(CommonUIModule).find((mod: any) =>
32
- // stable || beta as of oct 2 2024
33
- mod?.toString?.()?.includes('SliderField,fallback') || mod?.toString?.()?.includes("SliderField\",")
32
+ mod?.toString?.()?.includes("SliderField`,")
34
33
  ) as FC<SliderFieldProps>;
@@ -1,8 +1,8 @@
1
1
  import { FC, SVGAttributes } from 'react';
2
2
 
3
- import { IconsModule } from '../webpack';
3
+ import { IconsModule } from '../common-modules';
4
4
 
5
5
  // TODO type this and other icons?
6
6
  export const Spinner = IconsModule && Object.values(IconsModule)?.find(
7
- (mod: any) => mod?.toString && /Spinner\),children:\[\(0,\w+\.jsx\)\("path",\{d:"M18 /.test(mod.toString()) || /Spinner\)}\)?,.\.createElement\(\"path\",{d:\"M18 /.test(mod.toString()),
7
+ (mod: any) => mod?.toString && /,[a-zA-Z0-9_$]+\),children:\[\(0,[a-zA-Z0-9_$]+\.jsx\)\(`path`,\{d:`M18 /.test(mod.toString()) ,
8
8
  ) as FC<SVGAttributes<SVGElement>>;
@@ -1,12 +1,12 @@
1
1
  import { FC, ReactNode, SVGAttributes } from 'react';
2
2
 
3
- import { Export, findModuleExport } from '../webpack';
3
+ import { Var, findVar } from '../module-system';
4
4
 
5
5
  interface SteamSpinnerProps {
6
6
  children?: ReactNode;
7
7
  background?: "transparent"; // defaults to black seemingly, but only "transparent" is checked against
8
8
  }
9
9
 
10
- export const SteamSpinner = findModuleExport(
11
- (e: Export) => e?.toString?.()?.includes('Steam Spinner') && e?.toString?.()?.includes('src'),
10
+ export const SteamSpinner = findVar(
11
+ (e: Var) => typeof e == "function" && e?.toString?.()?.includes('Steam Spinner') && e?.toString?.()?.includes('src'),
12
12
  ) as FC<SVGAttributes<SVGElement> & SteamSpinnerProps>;
@@ -1,6 +1,7 @@
1
1
  import { FC, ReactNode } from 'react';
2
- import { findModuleByExport } from '../webpack';
2
+ import { findVar } from '../module-system';
3
3
  import { FooterLegendProps } from './FooterLegend';
4
+ import { createPropListRegex } from '../utils';
4
5
 
5
6
  /**
6
7
  * Individual tab objects for the Tabs component
@@ -62,9 +63,9 @@ export interface TabsProps {
62
63
  autoFocusContents?: boolean;
63
64
  }
64
65
 
65
- const tabsModule = findModuleByExport(e => e?.toString?.()?.includes(".TabRowTabs") && e?.toString?.()?.includes("activeTab:"));
66
+ const tabsRegex = createPropListRegex(["activeTab", "autoFocusContents", "cancelSkipTabHeader", "tabs"]);
66
67
 
67
68
  /**
68
69
  * Tabs component as used in the library and media tabs. See {@link TabsProps}.
69
70
  */
70
- export const Tabs = tabsModule && Object.values(tabsModule).find((e: any) => e?.type?.toString?.()?.includes("(function()")) as FC<TabsProps>;
71
+ export const Tabs = findVar(e => typeof e == "function" && tabsRegex.test(e.toString())) as FC<TabsProps>;
@@ -1,6 +1,7 @@
1
1
  import { ChangeEventHandler, HTMLAttributes, ReactNode, FC } from 'react';
2
2
 
3
- import { CommonUIModule, Module } from '../webpack';
3
+ import { CommonUIModule } from '../common-modules';
4
+ import { Module } from '../module-system';
4
5
 
5
6
  export interface TextFieldProps extends HTMLAttributes<HTMLInputElement> {
6
7
  label?: ReactNode;
@@ -1,6 +1,6 @@
1
1
  import { FC } from 'react';
2
2
 
3
- import { CommonUIModule } from '../webpack';
3
+ import { CommonUIModule } from '../common-modules';
4
4
 
5
5
  export interface ToggleProps {
6
6
  value: boolean;
@@ -1,6 +1,6 @@
1
1
  import { FC } from 'react';
2
2
 
3
- import { CommonUIModule } from '../webpack';
3
+ import { CommonUIModule } from '../common-modules';
4
4
  import { ItemProps } from './Item';
5
5
 
6
6
  export interface ToggleFieldProps extends ItemProps {
@@ -11,6 +11,5 @@ export interface ToggleFieldProps extends ItemProps {
11
11
  }
12
12
 
13
13
  export const ToggleField = Object.values(CommonUIModule).find((mod: any) =>
14
- // stable || beta as of oct 2 2024
15
- mod?.render?.toString?.()?.includes('ToggleField,fallback') || mod?.render?.toString?.()?.includes("ToggleField\",")
14
+ mod?.render?.toString?.()?.includes("ToggleField`,")
16
15
  ) as FC<ToggleFieldProps>;
@@ -0,0 +1,12 @@
1
+ import { ForwardRefExoticComponent } from 'react';
2
+
3
+ import { findModuleExport } from '../module-system';
4
+
5
+ export const createDivWrapper: (
6
+ className: string,
7
+ role?: string,
8
+ defaultProps?: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>,
9
+ ) => ForwardRefExoticComponent<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>> = findModuleExport(e =>
10
+ typeof e == "function" &&
11
+ /return [a-zA-Z0-9_$]+\.forwardRef\(function\([a-zA-Z0-9_$]+,[a-zA-Z0-9_$]+\){return.*role:/.test(e?.toString())
12
+ )
@@ -24,3 +24,4 @@ export * from './TextField';
24
24
  export * from './Toggle';
25
25
  export * from './ToggleField';
26
26
  export * from './Scroll';
27
+ export * from './Wrappers';
@@ -1,7 +1,6 @@
1
1
  import { CSSProperties, FC, useState } from 'react';
2
2
 
3
3
  import { ConfirmModal, SliderField } from '../components';
4
- import { gamepadSliderClasses } from '../utils/static-classes';
5
4
 
6
5
  interface ColorPickerModalProps {
7
6
  closeModal: () => void;
@@ -46,13 +45,13 @@ export const ColorPickerModal: FC<ColorPickerModalProps> = ({
46
45
  <style>
47
46
  {`
48
47
  /* This removes the cyan track color that is behind the slider head */
49
- .ColorPicker_Container .${gamepadSliderClasses.SliderTrack} {
48
+ .ColorPicker_Container .SliderTrack {
50
49
  --left-track-color: #0000;
51
50
  /* This is for compatibility with the "Colored Toggles" CSSLoader Theme*/
52
51
  --colored-toggles-main-color: #0000;
53
52
  }
54
53
 
55
- .ColorPicker_HSlider .${gamepadSliderClasses.SliderTrack} {
54
+ .ColorPicker_HSlider .SliderTrack {
56
55
  background: linear-gradient(
57
56
  270deg,
58
57
  hsla(360, var(--decky-color-picker-svalue), var(--decky-color-picker-lvalue), var(--decky-color-picker-avalue)),
@@ -63,7 +62,7 @@ export const ColorPickerModal: FC<ColorPickerModalProps> = ({
63
62
  );
64
63
  }
65
64
 
66
- .ColorPicker_SSlider .${gamepadSliderClasses.SliderTrack} {
65
+ .ColorPicker_SSlider .SliderTrack {
67
66
  background: linear-gradient(
68
67
  90deg,
69
68
  hsla(var(--decky-color-picker-hvalue), 0%, var(--decky-color-picker-lvalue), var(--decky-color-picker-avalue)),
@@ -71,7 +70,7 @@ export const ColorPickerModal: FC<ColorPickerModalProps> = ({
71
70
  );
72
71
  }
73
72
 
74
- .ColorPicker_LSlider .${gamepadSliderClasses.SliderTrack} {
73
+ .ColorPicker_LSlider .SliderTrack {
75
74
  background: linear-gradient(
76
75
  90deg,
77
76
  hsla(var(--decky-color-picker-hvalue), var(--decky-color-picker-svalue), 0%, var(--decky-color-picker-avalue)),
@@ -80,7 +79,7 @@ export const ColorPickerModal: FC<ColorPickerModalProps> = ({
80
79
  );
81
80
  }
82
81
 
83
- .ColorPicker_ASlider .${gamepadSliderClasses.SliderTrack} {
82
+ .ColorPicker_ASlider .SliderTrack {
84
83
  background: linear-gradient(
85
84
  90deg,
86
85
  hsla(var(--decky-color-picker-hvalue), var(--decky-color-picker-svalue), var(--decky-color-picker-lvalue), 0),
@@ -1,4 +1,4 @@
1
- import { ReactRouter } from '../webpack';
1
+ import { ReactRouter } from '../common-modules';
2
2
 
3
3
  /**
4
4
  * Get the current params from ReactRouter
@@ -53,7 +53,7 @@ interface StoreTag {
53
53
 
54
54
  export declare class CAppStore {
55
55
  m_bIsInitialized: boolean;
56
- m_mapApps: Map<IAppOverview, string>;
56
+ m_mapApps: Map<number, IAppOverview>;
57
57
  m_mapStoreTagLocalization: Map<EGenre, string>;
58
58
  m_msTagMapLoaded: number;
59
59
 
package/src/index.ts CHANGED
@@ -1,13 +1,15 @@
1
1
  // export * from './deck-libs';
2
+ export * from './module-system';
2
3
  export * from './custom-components';
3
4
  export * from './custom-hooks';
4
5
  export * from './components';
5
6
  export * from './deck-hooks';
6
7
  export * from './modules';
7
8
  export * from './globals';
8
- export * from './webpack';
9
+ export * from './modules';
9
10
  export * from './utils';
10
11
  export * from './class-mapper';
12
+ export * from './common-modules';
11
13
 
12
14
  /**
13
15
  * @deprecated use @decky/api instead
@@ -0,0 +1,309 @@
1
+ import Logger from './logger';
2
+
3
+ declare global {
4
+ interface Window {
5
+ webpackChunksteamui: any;
6
+ }
7
+ }
8
+
9
+ const logger = new Logger('Modules');
10
+
11
+ // In most case an object with getters for each property. Look for the first call to r.d in the module, usually near or at the top.
12
+ export type ModuleID = string; // number string on webpack, filename on esmodule
13
+ export type Module = any;
14
+ export type Export = any;
15
+ export type Var = any;
16
+ type FilterFn = (module: any) => boolean;
17
+ type ExportFilterFn = (moduleExport: any, exportName?: any) => boolean;
18
+ type VarFilterFn = (variable: any, varName?: any) => boolean;
19
+ type FindFn = (module: any) => any;
20
+
21
+ type ResolveModuleScopeFn = (objectFromScope: any, moduleForDebug?: string) => Promise<Module>;
22
+ let resolveModuleScope: ResolveModuleScopeFn;
23
+
24
+ export let processedModules: string[] = [];
25
+ export let modules = new Map<ModuleID, Module>();
26
+ export let moduleScopes = new Map<ModuleID, Module>();
27
+
28
+ // const dec = new TextDecoder();
29
+ // async function processModuleDeps(path: string) {
30
+ // const deps: Promise<void>[] = [];
31
+ // const startTime = performance.now();
32
+ // const req = await fetch(path);
33
+ // for await (const chunk of req.body!) {
34
+ // const hdr = chunk.subarray(0, 22);
35
+ // const hdrText = dec.decode(hdr);
36
+ // if (hdrText == "const __vite__mapDeps=") {
37
+ // const startIdx = chunk.indexOf("[".charCodeAt(0));
38
+ // const endIdx = chunk.indexOf("]".charCodeAt(0));
39
+
40
+ // const arrBuf = chunk.subarray(startIdx + 1, endIdx - 1);
41
+ // const arrText = dec.decode(arrBuf);
42
+ // // TODO prefix globally instead
43
+ // const arr = arrText.replace(/\"/g, "").split(",").filter(m => m.includes(".js")).map(m => m.replace(/^\.\//g, "https://steamloopback.host/"));
44
+ // logger.debug(`Dependency array found in ${path} at ${startIdx}:${endIdx} in ${performance.now() - startTime}ms`);
45
+ // arr.forEach(e => {
46
+ // const modStr = e.replace("https://steamloopback.host/", "");
47
+ // if (!processedModules.includes(modStr)) {
48
+ // processedModules.push(modStr);
49
+ // deps.push(processModule(e));
50
+ // }
51
+ // });
52
+ // }
53
+ // break;
54
+ // }
55
+ // await Promise.allSettled(deps);
56
+ // }
57
+
58
+ async function processModuleDeps(depsArr: string[]) {
59
+ const deps: Promise<void>[] = [];
60
+ logger.debug("Processing module deps", depsArr);
61
+ for (let e of depsArr.filter(m => m.includes(".js"))) {
62
+ const modStr = e.replace("./", "https://steamloopback.host/");
63
+ if (!processedModules.includes(modStr)) {
64
+ processedModules.push(modStr);
65
+ deps.push(processModule(modStr));
66
+ }
67
+ };
68
+ await Promise.allSettled(deps);
69
+ }
70
+
71
+ async function processScope(file: string, mod: Module) {
72
+ const startTime = performance.now();
73
+ try {
74
+ let tries = 0;
75
+ for (let expKey in mod) {
76
+ if (tries > 4) {
77
+ logger.debug(`No scope found for ${file} in ${performance.now() - startTime}ms out of tries`)
78
+ }
79
+ const exp = mod[expKey];
80
+ // TODO make this constraint more resilient to reexports somehow? or maybe just loop and check over, idk
81
+ if (typeof exp == "function" && exp.toString().length > 15) {
82
+ const scope = await resolveModuleScope(exp, file);
83
+ if (scope) {
84
+ logger.debug(`Scope resolved for ${file} in ${performance.now() - startTime}ms`);
85
+ moduleScopes.set(file, scope?.object);
86
+ if (scope?.object?.__vite__mapDeps) await processModuleDeps(scope.object.__vite__mapDeps.f);
87
+ break;
88
+ } else {
89
+ logger.debug(`No scope found for ${file} try ${tries} in ${performance.now() - startTime}ms export used:`, exp);
90
+ tries++;
91
+ }
92
+ }
93
+ }
94
+ } catch (e) {
95
+ logger.debug(`Failed to process scope of ${file}`, e);
96
+ }
97
+ }
98
+
99
+ async function processModule(path: string) {
100
+ const startTime = performance.now();
101
+ try {
102
+ const mod = await import(path);
103
+ logger.debug(`Processed exports for ${path} in ${performance.now() - startTime}ms`, path);
104
+ const file = path.replace("https://steamloopback.host/", "");
105
+ modules.set(file, mod);
106
+
107
+ const scope = processScope(file, mod);
108
+
109
+ const cjsStartTime = performance.now();
110
+ let cjsFound = false;
111
+ for (let expKey in mod) {
112
+ try {
113
+ const exp = mod[expKey];
114
+ // TODO make more robust?
115
+ if (typeof exp == "function" && exp?.toString?.()?.includes("={exports:{}}).exports,")) {
116
+ const cjsKey = `${file}#cjs_${expKey}`;
117
+ cjsFound = true;
118
+ modules.set(cjsKey, mod[expKey]());
119
+ logger.debug(`Processed CommonJS module ${cjsKey}`);
120
+ }
121
+ } catch (e) {
122
+ logger.debug(`Ignoring CommonJS module import error for ${path}.${expKey}`, e);
123
+ }
124
+ }
125
+ if (cjsFound) logger.debug(`CommonJS module imports for ${file} finished in ${performance.now() - cjsStartTime}ms`);
126
+ await scope;
127
+ } catch (e) {
128
+ logger.debug(`Ignoring module error for ${path}`, e);
129
+ }
130
+ }
131
+
132
+ export async function initModules(resolveModuleScopeFn: ResolveModuleScopeFn) {
133
+ resolveModuleScope = resolveModuleScopeFn;
134
+ const startTime = performance.now();
135
+ logger.group('Module System Init');
136
+ // Vite
137
+ for (let node of document.querySelectorAll("script[type=module]") as NodeListOf<HTMLScriptElement>) {
138
+ const path = node.src;
139
+ if (!path.startsWith("https://steamloopback.host")) continue;
140
+ await processModule(path);
141
+ }
142
+
143
+ logger.groupEnd(`Modules initialized in ${performance.now() - startTime}ms...`);
144
+ }
145
+
146
+ export const findModule = (filter: FilterFn) => {
147
+ for (const m of modules.values()) {
148
+ if (m.default && filter(m.default)) return m.default;
149
+ if (filter(m)) return m;
150
+ }
151
+ };
152
+
153
+ export const findModuleDetailsByExport = (
154
+ filter: ExportFilterFn,
155
+ minExports?: number,
156
+ ): [module: Module | undefined, moduleExport: any, exportName: any, moduleID: string | undefined] => {
157
+ for (const [id, m] of modules) {
158
+ if (!m) continue;
159
+ for (const mod of [m.default, m]) {
160
+ // special cases
161
+ if (typeof mod !== 'object') continue;
162
+ if (mod == window) continue; // wtf
163
+ if (minExports && Object.keys(mod).length < minExports) continue;
164
+
165
+ for (let exportName in mod) {
166
+ if (mod?.[exportName]) {
167
+ try {
168
+ const filterRes = filter(mod[exportName], exportName);
169
+ if (filterRes) {
170
+ return [mod, mod[exportName], exportName, id];
171
+ } else {
172
+ continue;
173
+ }
174
+ } catch (e) {
175
+ logger.warn("Module filter threw exception: ", e, "Filter: ", filter);
176
+ }
177
+ }
178
+ }
179
+ }
180
+ }
181
+ return [undefined, undefined, undefined, undefined];
182
+ };
183
+
184
+ export const findModuleByExport = (filter: ExportFilterFn, minExports?: number) => {
185
+ return findModuleDetailsByExport(filter, minExports)?.[0];
186
+ };
187
+
188
+ export const findModuleExport = (filter: ExportFilterFn, minExports?: number) => {
189
+ return findModuleDetailsByExport(filter, minExports)?.[1];
190
+ };
191
+
192
+ export const findScope = (filter: FilterFn) => {
193
+ for (const m of moduleScopes.values()) {
194
+ if (m.default && filter(m.default)) return m.default;
195
+ if (filter(m)) return m;
196
+ }
197
+ };
198
+
199
+ export const findScopeDetailsByVar = (
200
+ filter: VarFilterFn,
201
+ minExports?: number,
202
+ ): [moduleScope: Module | undefined, moduleExport: any, exportName: any, moduleID: string | undefined] => {
203
+ for (const [id, m] of moduleScopes) {
204
+ if (!m) continue;
205
+ for (const mod of [m.default, m]) {
206
+ // special cases
207
+ if (typeof mod !== 'object') continue;
208
+ if (mod == window) continue; // wtf
209
+ if (minExports && Object.keys(mod).length < minExports) continue;
210
+
211
+ for (let varName in mod) {
212
+ if (mod?.[varName]) {
213
+ try {
214
+ const filterRes = filter(mod[varName], varName);
215
+ if (filterRes) {
216
+ return [mod, mod[varName], varName, id];
217
+ } else {
218
+ continue;
219
+ }
220
+ } catch (e) {
221
+ // @ts-expect-error
222
+ if (!e?.startsWith?.("TypeError: Function.prototype.toString requires that 'this' be a Function"))
223
+ logger.warn("Scope filter threw exception:", e, "Filter: ", filter, mod?.[varName]);
224
+ }
225
+ }
226
+ }
227
+ }
228
+ }
229
+ return [undefined, undefined, undefined, undefined];
230
+ };
231
+
232
+ export const findModuleScopeByVar = (filter: VarFilterFn, minVars?: number) => {
233
+ return findScopeDetailsByVar(filter, minVars)?.[0];
234
+ };
235
+
236
+ export const findVar = (filter: VarFilterFn, minVars?: number) => {
237
+ return findScopeDetailsByVar(filter, minVars)?.[1];
238
+ };
239
+
240
+ /**
241
+ * @deprecated use findModuleExport instead
242
+ */
243
+ export const findModuleChild = (filter: FindFn) => {
244
+ logger.warn("findModuleChild is deprecated and will be removed soon. Use findModuleExport instead. Used in:", new Error().stack?.substring(5))
245
+ for (const m of modules.values()) {
246
+ for (const mod of [m.default, m]) {
247
+ const filterRes = filter(mod);
248
+ if (filterRes) {
249
+ return filterRes;
250
+ } else {
251
+ continue;
252
+ }
253
+ }
254
+ }
255
+ };
256
+
257
+ /**
258
+ * @deprecated use createModuleMapping instead
259
+ */
260
+ export const findAllModules = (filter: FilterFn) => {
261
+ logger.warn("findAllModules is deprecated and will be removed soon. Use createModuleMapping instead. Used in:", new Error().stack?.substring(5))
262
+ const out = [];
263
+
264
+ for (const m of modules.values()) {
265
+ if (m.default && filter(m.default)) out.push(m.default);
266
+ if (filter(m)) out.push(m);
267
+ }
268
+
269
+ return out;
270
+ };
271
+
272
+ export const createModuleMapping = (filter: FilterFn) => {
273
+ const mapping = new Map<ModuleID, Module>();
274
+
275
+ for (const [id, m] of modules) {
276
+ if (m.default && filter(m.default)) mapping.set(id, m.default);
277
+ if (filter(m)) mapping.set(id, m);
278
+ }
279
+
280
+ return mapping;
281
+ };
282
+
283
+ export const createScopeMapping = (filter: FilterFn) => {
284
+ const mapping = new Map<ModuleID, Module>();
285
+
286
+ for (const [id, m] of moduleScopes) {
287
+ if (m.default && filter(m.default)) mapping.set(id, m.default);
288
+ if (filter(m)) mapping.set(id, m);
289
+ }
290
+
291
+ return mapping;
292
+ };
293
+
294
+ export const createVarMapping = (filter: FilterFn) => {
295
+ const mapping = new Map<string, any>();
296
+
297
+ for (const [id, m] of moduleScopes) {
298
+ for (const key in m) {
299
+ try {
300
+ const val = m[key];
301
+ if (filter(val)) mapping.set(id + "#." + key, val);
302
+ } catch (e) {
303
+ logger.warn("Var mapping error", e);
304
+ }
305
+ }
306
+ }
307
+
308
+ return mapping;
309
+ };
@@ -2,7 +2,7 @@ import type { CSteamUIStore } from "../globals/stores/steamuistore";
2
2
  import type { QuickAccessTab, SideMenu } from "../globals/stores/steamuistore/menu";
3
3
  import type { SteamUIWindowInstance } from "../globals/stores/steamuistore/window";
4
4
  import Logger from "../logger";
5
- import { type Export, findModuleExport } from "../webpack";
5
+ import { type Export, findModuleExport } from "../module-system";
6
6
 
7
7
  // TODO(globals): maybe just use window.SteamUIStore ? it"s the exact same thing
8
8
  export const Router = findModuleExport((e: Export) => e.Navigate && e.NavigationManager) as CSteamUIStore;