I was the original asker of this question, but I failed to provide a clear description which led to not getting an answer. However, I will now explain everything here. Essentially, I am looking for a JavaScript function that can identify a class with a specific prefix on any element within the entire document. Let's consider the following HTML markup as an example:
<body class="c:bg-#008eff">
<h1 class="c:bg-#ff5c5c">Hello, <span class="c:bg-white">World !</span></h1>
In the above example, we have a common prefix c:bg- in all the classes. I envision a function understand() that can:
(1) Identify all classes with the prefix c: in an HTML document.
(2) Determine what comes after the c: prefix, such as c:bg- indicating a CSS background property and c:text- representing a CSS color property, among others.
(3) Extract and set the value, for instance, c:bg-#008eff signifies a CSS background property with the value #008eff.
(4) Strip away the c:bg-, c:text-, etc. prefixes from the obtained class string and utilize the remaining part to define styles.
We have our example:
<body class="c:bg-#008eff">
<h1 class="c:bg-#ff5c5c">Hello, <span class="c:bg-white">World !</span></h1>
In the output of the above code in a browser window, we would see the body with a background of #008eff, h1 with a background of #ff5c5c, and span with a white background.
Another example:
<body>
<h1 class="c:text-#ff5c5c c:pad-20px">Hello, <span class="c:text-#008eff c:mar-20px">World !</span></h1>
In the output of the above code in a browser window, the h1 element would have a color of #ff5c5c and a padding of 20px while the span would have a color of #008eff and a margin of 20px.
Lastly, it is crucial to note that if the same type of code is repeated, the last one will overwrite the first one. For example:
<h1 class="c:bg-blue c:bg-red">Hello</h1>
<!-- Executes red background -->
I hope my explanation is clearer now! Can the understand() function become a reality?
Thank you for taking the time to read this.