From fc5219705c6ef163aa69972b902c167dee9723fb Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Mon, 23 Dec 2024 06:26:16 +0700 Subject: [PATCH] Add BxIconRaw tyoe --- dist/better-xcloud.lite.user.js | 2 +- dist/better-xcloud.user.js | 2 +- src/modules/stream/stream-badges.ts | 4 ++-- src/modules/stream/stream-ui.ts | 6 +++--- src/modules/ui/dialog/settings-dialog.ts | 4 ++-- src/types/index.d.ts | 25 +++++++++++++++++++----- src/utils/bx-icon.ts | 2 ++ src/utils/html.ts | 8 ++++---- 8 files changed, 35 insertions(+), 18 deletions(-) diff --git a/dist/better-xcloud.lite.user.js b/dist/better-xcloud.lite.user.js index e950bdb..0aec4b4 100755 --- a/dist/better-xcloud.lite.user.js +++ b/dist/better-xcloud.lite.user.js @@ -787,7 +787,7 @@ function createElement(elmName, props, ..._) { } var domParser = new DOMParser; function createSvgIcon(icon) { - return domParser.parseFromString(icon.toString(), "image/svg+xml").documentElement; + return domParser.parseFromString(icon, "image/svg+xml").documentElement; } var ButtonStyleIndices = Object.keys(ButtonStyleClass).map((i) => parseInt(i)); function createButton(options) { diff --git a/dist/better-xcloud.user.js b/dist/better-xcloud.user.js index f955df5..2225614 100755 --- a/dist/better-xcloud.user.js +++ b/dist/better-xcloud.user.js @@ -819,7 +819,7 @@ function createElement(elmName, props, ..._) { } var domParser = new DOMParser; function createSvgIcon(icon) { - return domParser.parseFromString(icon.toString(), "image/svg+xml").documentElement; + return domParser.parseFromString(icon, "image/svg+xml").documentElement; } var ButtonStyleIndices = Object.keys(ButtonStyleClass).map((i) => parseInt(i)); function createButton(options) { diff --git a/src/modules/stream/stream-badges.ts b/src/modules/stream/stream-badges.ts index b4f6b7a..37dd907 100755 --- a/src/modules/stream/stream-badges.ts +++ b/src/modules/stream/stream-badges.ts @@ -5,7 +5,7 @@ import { BxEvent } from "@utils/bx-event"; import { CE, createSvgIcon, humanFileSize } from "@utils/html"; import { STATES } from "@utils/global"; import { BxLogger } from "@/utils/bx-logger"; -import { BxIcon } from "@/utils/bx-icon"; +import { BxIcon, type BxIconRaw } from "@/utils/bx-icon"; import { GuideMenuTab } from "../ui/guide-menu"; import { StreamStatsCollector } from "@/utils/stream-stats-collector"; import { StreamStat } from "@/enums/pref-values"; @@ -14,7 +14,7 @@ import { StreamStat } from "@/enums/pref-values"; type StreamBadgeInfo = { name: string, $element?: HTMLElement, - icon: typeof BxIcon, + icon: BxIconRaw, color: string, }; diff --git a/src/modules/stream/stream-ui.ts b/src/modules/stream/stream-ui.ts index c12a6ff..38662c5 100755 --- a/src/modules/stream/stream-ui.ts +++ b/src/modules/stream/stream-ui.ts @@ -1,6 +1,6 @@ import { STATES } from "@utils/global.ts"; import { createSvgIcon } from "@utils/html.ts"; -import { BxIcon } from "@utils/bx-icon"; +import { BxIcon, type BxIconRaw } from "@utils/bx-icon"; import { t } from "@utils/translation.ts"; import { StreamBadges } from "./stream-badges.ts"; import { StreamStats } from "./stream-stats.ts"; @@ -15,7 +15,7 @@ export class StreamUiHandler { private static $btnHome: HTMLElement | null | undefined; private static observer: MutationObserver | undefined; - private static cloneStreamHudButton($btnOrg: HTMLElement, label: string, svgIcon: typeof BxIcon): HTMLElement | null { + private static cloneStreamHudButton($btnOrg: HTMLElement, label: string, svgIcon: BxIconRaw): HTMLElement | null { if (!$btnOrg) { return null; } @@ -78,7 +78,7 @@ export class StreamUiHandler { return $container; } - private static cloneCloseButton($btnOrg: HTMLElement, icon: typeof BxIcon, className: string, onChange: any): HTMLElement | null { + private static cloneCloseButton($btnOrg: HTMLElement, icon: BxIconRaw, className: string, onChange: any): HTMLElement | null { if (!$btnOrg) { return null; } diff --git a/src/modules/ui/dialog/settings-dialog.ts b/src/modules/ui/dialog/settings-dialog.ts index 675e814..346c590 100755 --- a/src/modules/ui/dialog/settings-dialog.ts +++ b/src/modules/ui/dialog/settings-dialog.ts @@ -7,7 +7,7 @@ import { SoundShortcut } from "@/modules/shortcuts/sound-shortcut"; import { StreamStats } from "@/modules/stream/stream-stats"; import { TouchController } from "@/modules/touch-controller"; import { BxEvent } from "@/utils/bx-event"; -import { BxIcon } from "@/utils/bx-icon"; +import { BxIcon, type BxIconRaw } from "@/utils/bx-icon"; import { STATES, AppInterface, deepClone, SCRIPT_VERSION, STORAGE, SCRIPT_VARIANT } from "@/utils/global"; import { t, Translations } from "@/utils/translation"; import { BxSelectElement } from "@/web-components/bx-select"; @@ -65,7 +65,7 @@ type SettingTabSection = { }; type SettingTab = { - icon: SVGElement; + icon: BxIconRaw; group: SettingTabGroup, items: Array | (() => Array); requiredVariants?: BuildVariant | Array; diff --git a/src/types/index.d.ts b/src/types/index.d.ts index a6054fd..e2575a3 100755 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -101,12 +101,27 @@ type XcloudWaitTimeInfo = Partial<{ estimatedTotalWaitTimeInSeconds: number, }>; -declare module '*.js'; -declare module '*.svg'; -declare module '*.styl'; +declare module '*.js' { + const content: string; + export default content; +} +declare module '*.svg' { + const content: string; + export default content; +} +declare module '*.styl' { + const content: string; + export default content; +} -declare module '*.fs'; -declare module '*.vert'; +declare module '*.fs' { + const content: string; + export default content; +} +declare module '*.vert' { + const content: string; + export default content; +} type MkbMouseMove = { movementX: number; diff --git a/src/utils/bx-icon.ts b/src/utils/bx-icon.ts index 1de2b41..b57c4c2 100755 --- a/src/utils/bx-icon.ts +++ b/src/utils/bx-icon.ts @@ -83,3 +83,5 @@ export const BxIcon = { UPLOAD: iconUpload, AUDIO: iconSpeakerHigh, } as const; + +export type BxIconRaw = (typeof BxIcon)[keyof typeof BxIcon]; diff --git a/src/utils/html.ts b/src/utils/html.ts index 4caa393..1caece2 100755 --- a/src/utils/html.ts +++ b/src/utils/html.ts @@ -1,4 +1,4 @@ -import type { BxIcon } from "@utils/bx-icon"; +import type { BxIconRaw } from "@utils/bx-icon"; import { setNearby } from "./navigation-utils"; import type { NavigationNearbyElements } from "@/modules/ui/dialog/navigation-dialog"; import type { PresetRecord, AllPresets } from "@/types/presets"; @@ -43,7 +43,7 @@ export type BxButtonOptions = Partial<{ style: ButtonStyle; url: string; classes: string[]; - icon: typeof BxIcon; + icon: BxIconRaw; label: string; secondaryText: HTMLElement | string; title: string; @@ -149,8 +149,8 @@ function createElement(elmName: T, props? const domParser = new DOMParser(); -export function createSvgIcon(icon: typeof BxIcon) { - return domParser.parseFromString(icon.toString(), 'image/svg+xml').documentElement; +export function createSvgIcon(icon: BxIconRaw) { + return domParser.parseFromString(icon, 'image/svg+xml').documentElement; } const ButtonStyleIndices = Object.keys(ButtonStyleClass).map(i => parseInt(i));