kulhadcss 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/demo/index.html +0 -0
- package/package.json +13 -0
- package/src/applier.js +17 -0
- package/src/index.js +9 -0
- package/src/parser.js +36 -0
package/demo/index.html
ADDED
|
File without changes
|
package/package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "kulhadcss",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A Kadak utility-first CSS engine brewed with Vanilla JS.",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
+
},
|
|
10
|
+
"keywords": ["css", "utility", "desi", "kulhad"],
|
|
11
|
+
"author": "Rachit",
|
|
12
|
+
"license": "ISC"
|
|
13
|
+
}
|
package/src/applier.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { parseClass } from './parser.js';
|
|
2
|
+
|
|
3
|
+
export function applyStyles(element) {
|
|
4
|
+
let element_classes = Array.from(element.classList);
|
|
5
|
+
|
|
6
|
+
element_classes.forEach(cls => {
|
|
7
|
+
const styleObject = parseClass(cls);
|
|
8
|
+
if (styleObject) {
|
|
9
|
+
Object.assign(element.style, styleObject);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function scanDom() {
|
|
15
|
+
const elements_list = Array.from(document.querySelectorAll('[class]'));
|
|
16
|
+
elements_list.forEach(element => applyStyles(element));
|
|
17
|
+
}
|
package/src/index.js
ADDED
package/src/parser.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const SCALE = 4;
|
|
2
|
+
|
|
3
|
+
const staticStyles = {
|
|
4
|
+
"milkar": { "display": "flex" },
|
|
5
|
+
"beech": {
|
|
6
|
+
"display": "flex",
|
|
7
|
+
"justifyContent": "center",
|
|
8
|
+
"alignItems": "center"
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function parseClass(className) {
|
|
13
|
+
if (staticStyles[className]) return staticStyles[className];
|
|
14
|
+
const parts = className.split("-");
|
|
15
|
+
if (parts.length !== 2) return null;
|
|
16
|
+
let [prefix, value] = parts;
|
|
17
|
+
let numValue = Number(value);
|
|
18
|
+
if (isNaN(numValue)) return null;
|
|
19
|
+
prefix = prefix.toLowerCase();
|
|
20
|
+
switch (prefix) {
|
|
21
|
+
case "malai":
|
|
22
|
+
return {
|
|
23
|
+
"padding": `${numValue * SCALE}px`
|
|
24
|
+
};
|
|
25
|
+
case "doori":
|
|
26
|
+
return {
|
|
27
|
+
"margin": `${numValue * SCALE}px`
|
|
28
|
+
};
|
|
29
|
+
case "ghumaav":
|
|
30
|
+
return {
|
|
31
|
+
"borderRadius": `${numValue * SCALE}px`
|
|
32
|
+
};
|
|
33
|
+
default:
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|