refactor: automatic proxy constructor

This commit is contained in:
velzie 2024-07-19 13:52:34 -04:00
parent eba3e759fd
commit 80d51ed7a7
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F
11 changed files with 192 additions and 131 deletions

View file

@ -1,3 +1,4 @@
import { client } from ".";
import { rewriteCss } from "./shared";
const cssProperties = [
@ -13,14 +14,9 @@ const cssProperties = [
];
// const jsProperties = ["background", "backgroundImage", "mask", "maskImage", "listStyle", "listStyleImage", "borderImage", "borderImageSource", "cursor"];
CSSStyleDeclaration.prototype.setProperty = new Proxy(
CSSStyleDeclaration.prototype.setProperty,
{
apply(target, thisArg, argArray) {
if (cssProperties.includes(argArray[0]))
argArray[1] = rewriteCss(argArray[1]);
return Reflect.apply(target, thisArg, argArray);
},
}
);
client.Proxy(CSSStyleDeclaration.prototype, "setProperty", {
apply(ctx) {
if (cssProperties.includes(ctx.args[0]))
ctx.args[1] = rewriteCss(ctx.args[1]);
},
});