diff options
author | Ven <vendicated@riseup.net> | 2022-12-25 20:47:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-25 20:47:35 +0100 |
commit | 2e5d27b6b63097e96e25819df7a8cdd667c521b3 (patch) | |
tree | 082b0f1c7cb0210d208c7cb8017e9da97b3b4196 /src/plugins/shikiCodeblocks | |
parent | 2172cae779fb24f9bcc8c54a0b6538da0b52bafd (diff) | |
download | Vencord-2e5d27b6b63097e96e25819df7a8cdd667c521b3.tar.gz Vencord-2e5d27b6b63097e96e25819df7a8cdd667c521b3.tar.bz2 Vencord-2e5d27b6b63097e96e25819df7a8cdd667c521b3.zip |
feat: Proper CSS api & css bundle (#269)
Co-authored-by: Vap0r1ze <superdash993@gmail.com>
Diffstat (limited to 'src/plugins/shikiCodeblocks')
-rw-r--r-- | src/plugins/shikiCodeblocks/components/Header.tsx | 2 | ||||
-rw-r--r-- | src/plugins/shikiCodeblocks/components/Highlighter.tsx | 6 | ||||
-rw-r--r-- | src/plugins/shikiCodeblocks/devicon.css | 1 | ||||
-rw-r--r-- | src/plugins/shikiCodeblocks/index.ts | 17 | ||||
-rw-r--r-- | src/plugins/shikiCodeblocks/shiki.css | 4 | ||||
-rw-r--r-- | src/plugins/shikiCodeblocks/utils/misc.ts | 3 |
6 files changed, 15 insertions, 18 deletions
diff --git a/src/plugins/shikiCodeblocks/components/Header.tsx b/src/plugins/shikiCodeblocks/components/Header.tsx index c2db386..320dde9 100644 --- a/src/plugins/shikiCodeblocks/components/Header.tsx +++ b/src/plugins/shikiCodeblocks/components/Header.tsx @@ -33,7 +33,7 @@ export function Header({ langName, useDevIcon, shikiLang }: HeaderProps) { <div className={cl("lang")}> {useDevIcon !== DeviconSetting.Disabled && shikiLang?.devicon && ( <i - className={`devicon-${shikiLang.devicon}${useDevIcon === DeviconSetting.Color ? " colored" : ""}`} + className={`${cl("devicon")} devicon-${shikiLang.devicon}${useDevIcon === DeviconSetting.Color ? " colored" : ""}`} /> )} {langName} diff --git a/src/plugins/shikiCodeblocks/components/Highlighter.tsx b/src/plugins/shikiCodeblocks/components/Highlighter.tsx index d26cd81..badb3c8 100644 --- a/src/plugins/shikiCodeblocks/components/Highlighter.tsx +++ b/src/plugins/shikiCodeblocks/components/Highlighter.tsx @@ -90,14 +90,10 @@ export const Highlighter = ({ let langName; if (lang) langName = useHljs ? hljs?.getLanguage?.(lang)?.name : shikiLang?.name; - const preClasses = [cl("root")]; - if (!langName) preClasses.push(cl("plain")); - if (isPreview) preClasses.push(cl("preview")); - return ( <div ref={rootRef} - className={preClasses.join(" ")} + className={cl("root", { plain: !langName, preview: isPreview })} style={{ backgroundColor: useHljs ? themeBase.backgroundColor diff --git a/src/plugins/shikiCodeblocks/devicon.css b/src/plugins/shikiCodeblocks/devicon.css new file mode 100644 index 0000000..f5c4921 --- /dev/null +++ b/src/plugins/shikiCodeblocks/devicon.css @@ -0,0 +1 @@ +@import url('https://cdn.jsdelivr.net/gh/devicons/devicon@v2.10.1/devicon.min.css'); diff --git a/src/plugins/shikiCodeblocks/index.ts b/src/plugins/shikiCodeblocks/index.ts index 58e0048..428a273 100644 --- a/src/plugins/shikiCodeblocks/index.ts +++ b/src/plugins/shikiCodeblocks/index.ts @@ -16,23 +16,25 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ +import "./shiki.css"; + +import { disableStyle, enableStyle } from "@api/Styles"; import { Devs } from "@utils/constants"; import { parseUrl } from "@utils/misc"; import { wordsFromPascal, wordsToTitle } from "@utils/text"; import definePlugin, { OptionType } from "@utils/types"; import previewExampleText from "~fileContent/previewExample.tsx"; -import cssText from "~fileContent/shiki.css"; import { Settings } from "../../Vencord"; import { shiki } from "./api/shiki"; import { themes } from "./api/themes"; import { createHighlighter } from "./components/Highlighter"; -import { DeviconSetting, HljsSetting, ShikiSettings, StyleSheets } from "./types"; -import { clearStyles, removeStyle, setStyle } from "./utils/createStyle"; +import deviconStyle from "./devicon.css?managed"; +import { DeviconSetting, HljsSetting, ShikiSettings } from "./types"; +import { clearStyles } from "./utils/createStyle"; const themeNames = Object.keys(themes); -const devIconCss = "@import url('https://cdn.jsdelivr.net/gh/devicons/devicon@v2.10.1/devicon.min.css');"; const getSettings = () => Settings.plugins.ShikiCodeblocks as ShikiSettings; @@ -50,9 +52,8 @@ export default definePlugin({ }, ], start: async () => { - setStyle(cssText, StyleSheets.Main); if (getSettings().useDevIcon !== DeviconSetting.Disabled) - setStyle(devIconCss, StyleSheets.DevIcons); + enableStyle(deviconStyle); await shiki.init(getSettings().customTheme || getSettings().theme); }, @@ -135,8 +136,8 @@ export default definePlugin({ }, ], onChange: (newValue: DeviconSetting) => { - if (newValue === DeviconSetting.Disabled) removeStyle(StyleSheets.DevIcons); - else setStyle(devIconCss, StyleSheets.DevIcons); + if (newValue === DeviconSetting.Disabled) disableStyle(deviconStyle); + else enableStyle(deviconStyle); }, }, bgOpacity: { diff --git a/src/plugins/shikiCodeblocks/shiki.css b/src/plugins/shikiCodeblocks/shiki.css index b871d99..d71b673 100644 --- a/src/plugins/shikiCodeblocks/shiki.css +++ b/src/plugins/shikiCodeblocks/shiki.css @@ -1,6 +1,5 @@ .shiki-container { border: 4px; - /* fallback background */ background-color: var(--background-secondary); } @@ -22,8 +21,7 @@ border: none; } -.shiki-root [class^='devicon-'], -.shiki-root [class*=' devicon-'] { +.shiki-devicon { margin-right: 8px; user-select: none; } diff --git a/src/plugins/shikiCodeblocks/utils/misc.ts b/src/plugins/shikiCodeblocks/utils/misc.ts index 1342ff5..fefe938 100644 --- a/src/plugins/shikiCodeblocks/utils/misc.ts +++ b/src/plugins/shikiCodeblocks/utils/misc.ts @@ -16,13 +16,14 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ +import { classNameFactory } from "@api/Styles"; import { hljs } from "@webpack/common"; import { resolveLang } from "../api/languages"; import { HighlighterProps } from "../components/Highlighter"; import { HljsSetting, ShikiSettings } from "../types"; -export const cl = (className: string) => `shiki-${className}`; +export const cl = classNameFactory("shiki-"); export const shouldUseHljs = ({ lang, |