-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unified Styles API #3153
base: dev
Are you sure you want to change the base?
Unified Styles API #3153
Conversation
…, replace style names with style objects
@@ -276,7 +276,7 @@ export const stylePlugin = { | |||
name: "style-plugin", | |||
setup: ({ onResolve, onLoad }) => { | |||
onResolve({ filter: /\.css\?managed$/, namespace: "file" }, ({ path, resolveDir }) => ({ | |||
path: relative(process.cwd(), join(resolveDir, path.replace("?managed", ""))), | |||
path: relative(process.cwd(), join(resolveDir, path.replace(/\?managed$/, ""))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in this current state, yes it's unnecessary
i was just working on adding enabled by default styles, would there be ANY usecase for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idc about the styles being enabled idea anymore, should this just be left as a string
…enableStyle/disableStyle in start/stop
8d15983
to
330532c
Compare
Converts the managed styles API to be a unified API for all styles
The problem
Vencord does not inject styles into popout windows.
Additionally, plugins that create their own styles at runtime contain a lot of (ugly) code to add these styles.
How this solves the problem
Almost every call to
document.createElement("style")
1 is replaced with the unified styles API.This API should be considered the single source of truth regarding stylesheets for everything from now on.
The underlying data structure for "managed styles" has been changed to not store references to DOM
<style>
elements.Instead, DOM elements are looked up in all available documents (current document and popouts) when necessary.
When a popout is created, all enabled styles are injected to that document.
Please note that there is no "style updated" event system implemented into this API.
How to use it
The major functions that should be commonly used are
createStyle
2,deleteStyle
, andsetStyle
. The existingenableStyle
anddisableStyle
can still be used for managed styles.I am aware that there's still a decent amount of out-of-date documentation in the code, and some things should be renamed or moved around. Please do provide feedback on this.
Some code was taken from #3080 (thank you @Masterjoona for originally developing code for CSS in popouts)
Footnotes
Not used in YoutubeAdblock or ShikiCodeblocks, though the code in ShikiCodeblocks looks redundant. ↩
createStyle
is also used to update styles ↩