mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-17 10:27:03 -04:00
feat: Proper CSS api & css bundle (#269)
Co-authored-by: Vap0r1ze <superdash993@gmail.com>
This commit is contained in:
parent
2172cae779
commit
2e5d27b6b6
31 changed files with 438 additions and 126 deletions
|
@ -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}
|
||||
|
|
|
@ -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
|
||||
|
|
1
src/plugins/shikiCodeblocks/devicon.css
Normal file
1
src/plugins/shikiCodeblocks/devicon.css
Normal file
|
@ -0,0 +1 @@
|
|||
@import url('https://cdn.jsdelivr.net/gh/devicons/devicon@v2.10.1/devicon.min.css');
|
|
@ -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: {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue