Skip to content

Is this possible to obfuscate "hover:" class name or something like that from TailwindCSS? I also have some question and feature request #6

Closed
@hoangnhan2ka3

Description

@hoangnhan2ka3

First of all, I really appreciate your efforts on this project ✨, thank you @soranoo and all Sponsors !

This is almost what I needed, really easy to use, really full features and highly customizable.
Besides, it also helps my code look mysterious 😈 and professional.

I want to make some contributions to make this project even more perfect, to be widely known and to be a perfect replacement for a certain "no longer maintained package" named Post*** 😄.

My specs:

OS: Windows 11
IDE: VS Code v1.85.2
Nextjs 14.1
Frontend cloud: Vercel
Using: next-css-obfuscator v2.0.6

👉 1. Also obfuscate something like "hover:" in TailwindCSS class:

There are things that are really easy to confuse like *:hover in normal CSS and hover:* in TailwindCSS class, both have hover and :.

In my test project, I have ONLY one class end with "...text-yellow-300" (I mean there is no other class named "yellow") like this:

Screenshot 2024-01-29 070831


And when npm run build, in css-obfuscator/conversion.json file:

Screenshot 2024-01-29 071613

(I also delete .next/cache folder and old css-obfuscator folder, which contain conversion.json before running this build command).

Result:

Screenshot 2024-01-29 092640


In expected:

".hover\\:text-yellow-300": ".kj33u9",

// or at least

".hover\\:text-yellow-300": ".hover\\:kj33u9",

But no. So... I don't know what is the :hover suffix (which is the main problem) when detecting that class name 🥲. And why it detect another alone class ".text-yellow-300" which doesn't exist.

Actually, I found a temporary solution when editing your utils.js file in the node_modules folder, I will talk about this problem in part 2.

👉 2. The problem of selectorClasses.length > 1:

I think part of the problem lies in this line of utils.js:

if (selectorClasses.length > 1) {

When I edit it to selectorClasses.length >= 1, this is the result:

Screenshot 2024-01-29 081320

"Nears". But of course this does not work ⛔ too because of wrong class detected with :hover suffix.

Doesn't stop there, this edit also affects "single character" then "-[${custom parameter}]"
eg: z-[9999], min-h-[80rem], etc. (almost all)


With selectorClasses.length > 1:

Screenshot 2024-01-29 092229


With selectorClasses.length >= 1:

Screenshot 2024-01-29 084939

Almost every TW custom parameter class except hover: works perfectly (for me) with selectorClasses.length >= 1. And I run dev, run build + run start or deploy to Vercel with no error (I haven't tried all the TW classes and don't know if there are any special cases or exceptions, but this works for me for now)

🫶 If possible, please update an option for this selectorClassesLength as a temporary solution for custom parameter TW class.

👉 3. Truth about select direct child "*:":

If u know u know:

Screenshot 2024-01-29 094126

Even though this *: class exists in the parent div, it really only has an effect on the children div.

I'm really not sure what will happen if we successfully obfuscate this *: class ⁉️

Screenshot 2024-01-29 094937

I think it's possible but quite difficult to do hmmm...

The script is to just obfuscate the .\\*\\:font-extrabold part and I think

.jzn6lz > * {
    font-weight: 800;
}

will do the rest.

Okay and... the remain problem of *: is same same as hover:

Screenshot 2024-01-29 095924

It is true that it must be .\\*\\:font-extrabold > * to work but we don't need to detect the > * part but .\\*\\:font-extrabold right?

At last I do think that fix the hover: problem is much possible than *: haha 😄.

👉 4. Feature request:

Screenshot 2024-01-29 101716

You know 👉👈... I think this feature is not useless but it's really not as useful as doing the opposite. I mean the tag with marker class will not be obfuscated, it is more valuable to use than having to add a marker to each tag you want to obfuscate, but yes, don't delete the current option because it is usable in some cases. Is it possible?

And once again I really thank you and everyone who has contributed and built this project, please continue to develop it further 🥳.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions