-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Utility Groups (Why not?!) #9
Comments
It requires transformations to the source file, not just serving the css. Which I don't think it's capable for postcss's plugin interface. |
Is it possible to push the css as string instead of a file path? |
Sorry what do you mean? |
Sorry, the extractFile function receive the css as string and should make the group handling too. But it does not work in my case. |
Hello @antfu, I implemented a tiny devtool script that transforms the class declaration like Windi under the hood. But today I have no idea how to dynamically insert it into the development code. // windi stuff
const regexClassGroup = /([!\w+-][\w+:_/-]*?\w):\(([\w\s/-]*?)\)/gm;
function transformGroups(str: string) {
return str.replace(regexClassGroup, (_, a: string, b: string) =>
b
.split(/\s/g)
.map((i) => `${a}:${i}`)
.join(' ')
);
}
// devtool
document.addEventListener('DOMNodeInserted', (event: MutationEvent) => {
const nodes: NodeListOf<HTMLElement> = event.relatedNode.querySelectorAll('[class]');
nodes.forEach((node: HTMLElement) => {
const transformed = transformGroups(node.getAttribute('class') || '');
if (node.getAttribute('class') != transformed) {
node.setAttribute('class', transformed);
}
});
}); |
Oh, like a runtime? |
I could try to inject the devtool snippet only in |
Update prototype - valid W3C - https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver const regexClassGroup = /([!\w+-][\w+:_/-]*?\w):\(([\w\s/-]*?)\)/gm;
function transformGroups(str: string) {
return str.replace(regexClassGroup, (_, a: string, b: string) =>
b
.split(/\s/g)
.map((i) => `${a}:${i}`)
.join(' ')
);
}
new MutationObserver((records: MutationRecord[]) => {
records.forEach((record: MutationRecord) => {
record.addedNodes.forEach((node: Node) => {
const nodes: NodeListOf<HTMLElement> | undefined = node.parentElement?.querySelectorAll('[class]');
if (nodes) {
nodes.forEach((node: HTMLElement) => {
const transformed = transformGroups(node.getAttribute('class') || '');
if (node.getAttribute('class') != transformed) {
node.setAttribute('class', transformed);
}
});
}
});
});
}).observe(document.body, {
attributes: true,
childList: true,
subtree: true,
}); |
Interesting, do you think we can make a package called /cc @voorjaar do you feel we can make this one official? |
Hi! Is this usable now? Really wanted to have variant grouping. |
That is currently not possible?!
We give the parser the files and he extract the css classes. Why he did not detect the utility groups?
The text was updated successfully, but these errors were encountered: