live-atom 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/domWatcher.js +39 -0
- package/dynamicParser.js +229 -0
- package/main.js +61 -0
- package/package.json +26 -0
- package/styleManager.js +69 -0
- package/styleMap.js +169 -0
- package/styleSheet.js +28 -0
package/domWatcher.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { computeAndInjectStyles } from "./styleManager.js";
|
|
2
|
+
|
|
3
|
+
export function scanDom(node) {
|
|
4
|
+
// Process root node
|
|
5
|
+
if (node.nodeType === 1 && node.classList?.length) {
|
|
6
|
+
const hasAtomClass = [...node.classList].some((cls) => cls.includes("atom-"));
|
|
7
|
+
if (hasAtomClass) computeAndInjectStyles(node);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Process all children
|
|
11
|
+
if (node.querySelectorAll) {
|
|
12
|
+
const descendantNodes = node.querySelectorAll('[class*="atom-"]');
|
|
13
|
+
descendantNodes.forEach(computeAndInjectStyles);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function watchDOMMutations() {
|
|
18
|
+
const observer = new MutationObserver((mutations) => {
|
|
19
|
+
mutations.forEach((mutation) => {
|
|
20
|
+
// Handle new node additions
|
|
21
|
+
if (mutation.addedNodes.length) {
|
|
22
|
+
mutation.addedNodes.forEach((node) => {
|
|
23
|
+
if (node.nodeType === 1) scanDom(node);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
// Handle dynamic class manipulation
|
|
27
|
+
if (mutation.type === "attributes" && mutation.attributeName === "class") {
|
|
28
|
+
computeAndInjectStyles(mutation.target);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
observer.observe(document.body, {
|
|
34
|
+
childList: true,
|
|
35
|
+
subtree: true,
|
|
36
|
+
attributes: true,
|
|
37
|
+
attributeFilter: ["class"],
|
|
38
|
+
});
|
|
39
|
+
}
|
package/dynamicParser.js
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
const colorPalette = {
|
|
2
|
+
red: {
|
|
3
|
+
50: "#fef2f2",
|
|
4
|
+
100: "#ffe2e2",
|
|
5
|
+
200: "#ffc9c9",
|
|
6
|
+
300: "#ffa2a2",
|
|
7
|
+
400: "#ff6467",
|
|
8
|
+
500: "#fb2c36",
|
|
9
|
+
600: "#e7000b",
|
|
10
|
+
700: "#c10007",
|
|
11
|
+
800: "#9f0712",
|
|
12
|
+
900: "#82181a",
|
|
13
|
+
950: "#460809",
|
|
14
|
+
},
|
|
15
|
+
orange: {
|
|
16
|
+
50: "#fff7ed",
|
|
17
|
+
100: "#ffedd4",
|
|
18
|
+
200: "#ffd6a8",
|
|
19
|
+
300: "#ffb86a",
|
|
20
|
+
400: "#ff8904",
|
|
21
|
+
500: "#ff6900",
|
|
22
|
+
600: "#f54900",
|
|
23
|
+
700: "#ca3500",
|
|
24
|
+
800: "#9f2d00",
|
|
25
|
+
900: "#7e2a0c",
|
|
26
|
+
950: "#441306",
|
|
27
|
+
},
|
|
28
|
+
yellow: {
|
|
29
|
+
50: "#fefce8",
|
|
30
|
+
100: "#fef9c2",
|
|
31
|
+
200: "#fff085",
|
|
32
|
+
300: "#ffdf20",
|
|
33
|
+
400: "#fdc700",
|
|
34
|
+
500: "#f0b100",
|
|
35
|
+
600: "#d08700",
|
|
36
|
+
700: "#a65f00",
|
|
37
|
+
800: "#894b00",
|
|
38
|
+
900: "#733e0a",
|
|
39
|
+
950: "#432004",
|
|
40
|
+
},
|
|
41
|
+
green: {
|
|
42
|
+
50: "#f0fdf4",
|
|
43
|
+
100: "#dcfce7",
|
|
44
|
+
200: "#b9f8cf",
|
|
45
|
+
300: "#7bf1a8",
|
|
46
|
+
400: "#05df72",
|
|
47
|
+
500: "#00c950",
|
|
48
|
+
600: "#00a63e",
|
|
49
|
+
700: "#008236",
|
|
50
|
+
800: "#016630",
|
|
51
|
+
900: "#0d542b",
|
|
52
|
+
950: "#032e15",
|
|
53
|
+
},
|
|
54
|
+
blue: {
|
|
55
|
+
50: "#eff6ff",
|
|
56
|
+
100: "#dbeafe",
|
|
57
|
+
200: "#bedbff",
|
|
58
|
+
300: "#8ec5ff",
|
|
59
|
+
400: "#51a2ff",
|
|
60
|
+
500: "#2b7fff",
|
|
61
|
+
600: "#155dfc",
|
|
62
|
+
700: "#1447e6",
|
|
63
|
+
800: "#193cb8",
|
|
64
|
+
900: "#1c398e",
|
|
65
|
+
950: "#162456",
|
|
66
|
+
},
|
|
67
|
+
purple: {
|
|
68
|
+
50: "#faf5ff",
|
|
69
|
+
100: "#f3e8ff",
|
|
70
|
+
200: "#e9d4ff",
|
|
71
|
+
300: "#dab2ff",
|
|
72
|
+
400: "#c27aff",
|
|
73
|
+
500: "#ad46ff",
|
|
74
|
+
600: "#9810fa",
|
|
75
|
+
700: "#8200db",
|
|
76
|
+
800: "#6e11b0",
|
|
77
|
+
900: "#59168b",
|
|
78
|
+
950: "#3c0366",
|
|
79
|
+
},
|
|
80
|
+
pink: {
|
|
81
|
+
50: "#fdf2f8",
|
|
82
|
+
100: "#fce7f3",
|
|
83
|
+
200: "#fccee8",
|
|
84
|
+
300: "#fda5d5",
|
|
85
|
+
400: "#fb64b6",
|
|
86
|
+
500: "#f6339a",
|
|
87
|
+
600: "#e60076",
|
|
88
|
+
700: "#c6005c",
|
|
89
|
+
800: "#a3004c",
|
|
90
|
+
900: "#861043",
|
|
91
|
+
950: "#510424",
|
|
92
|
+
},
|
|
93
|
+
gray: {
|
|
94
|
+
50: "#f9fafb",
|
|
95
|
+
100: "#f3f4f6",
|
|
96
|
+
200: "#e5e7eb",
|
|
97
|
+
300: "#d1d5dc",
|
|
98
|
+
400: "#99a1af",
|
|
99
|
+
500: "#6a7282",
|
|
100
|
+
600: "#4a5565",
|
|
101
|
+
700: "#364153",
|
|
102
|
+
800: "#1e2939",
|
|
103
|
+
900: "#101828",
|
|
104
|
+
950: "#030712",
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const grammarRules = [
|
|
109
|
+
//#region Spacing
|
|
110
|
+
{ match: /^atom-p-(\d+)$/, action: ([, val]) => ({ padding: `${val * 4}px` }) },
|
|
111
|
+
{
|
|
112
|
+
match: /^atom-px-(\d+)$/,
|
|
113
|
+
action: ([, val]) => ({ "padding-left": `${val * 4}px`, "padding-right": `${val * 4}px` }),
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
match: /^atom-py-(\d+)$/,
|
|
117
|
+
action: ([, val]) => ({ "padding-top": `${val * 4}px`, "padding-bottom": `${val * 4}px` }),
|
|
118
|
+
},
|
|
119
|
+
{ match: /^atom-pt-(\d+)$/, action: ([, val]) => ({ "padding-top": `${val * 4}px` }) },
|
|
120
|
+
{ match: /^atom-pr-(\d+)$/, action: ([, val]) => ({ "padding-right": `${val * 4}px` }) },
|
|
121
|
+
{ match: /^atom-pb-(\d+)$/, action: ([, val]) => ({ "padding-bottom": `${val * 4}px` }) },
|
|
122
|
+
{ match: /^atom-pl-(\d+)$/, action: ([, val]) => ({ "padding-left": `${val * 4}px` }) },
|
|
123
|
+
|
|
124
|
+
{ match: /^atom-m-(\d+)$/, action: ([, val]) => ({ margin: `${val * 4}px` }) },
|
|
125
|
+
{
|
|
126
|
+
match: /^atom-mx-(\d+)$/,
|
|
127
|
+
action: ([, val]) => ({ "margin-left": `${val * 4}px`, "margin-right": `${val * 4}px` }),
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
match: /^atom-my-(\d+)$/,
|
|
131
|
+
action: ([, val]) => ({ "margin-top": `${val * 4}px`, "margin-bottom": `${val * 4}px` }),
|
|
132
|
+
},
|
|
133
|
+
{ match: /^atom-mt-(\d+)$/, action: ([, val]) => ({ "margin-top": `${val * 4}px` }) },
|
|
134
|
+
{ match: /^atom-mr-(\d+)$/, action: ([, val]) => ({ "margin-right": `${val * 4}px` }) },
|
|
135
|
+
{ match: /^atom-mb-(\d+)$/, action: ([, val]) => ({ "margin-bottom": `${val * 4}px` }) },
|
|
136
|
+
{ match: /^atom-ml-(\d+)$/, action: ([, val]) => ({ "margin-left": `${val * 4}px` }) },
|
|
137
|
+
//#endRegion
|
|
138
|
+
|
|
139
|
+
//#region Sizing
|
|
140
|
+
{ match: /^atom-w-(\d+)$/, action: ([, val]) => ({ width: `${val * 4}px` }) },
|
|
141
|
+
{ match: /^atom-w-\[(.+)\]$/, action: ([, val]) => ({ width: val }) },
|
|
142
|
+
{ match: /^atom-h-(\d+)$/, action: ([, val]) => ({ height: `${val * 4}px` }) },
|
|
143
|
+
{ match: /^atom-h-\[(.+)\]$/, action: ([, val]) => ({ height: val }) },
|
|
144
|
+
{ match: /^atom-max-w-(\d+)$/, action: ([, val]) => ({ "max-width": `${val * 4}px` }) },
|
|
145
|
+
{ match: /^atom-max-w-\[(.+)\]$/, action: ([, val]) => ({ "max-width": val }) },
|
|
146
|
+
{ match: /^atom-max-h-(\d+)$/, action: ([, val]) => ({ "max-height": `${val * 4}px` }) },
|
|
147
|
+
{ match: /^atom-max-h-\[(.+)\]$/, action: ([, val]) => ({ "max-height": val }) },
|
|
148
|
+
{ match: /^atom-min-w-(\d+)$/, action: ([, val]) => ({ "min-width": `${val * 4}px` }) },
|
|
149
|
+
{ match: /^atom-min-w-\[(.+)\]$/, action: ([, val]) => ({ "min-width": val }) },
|
|
150
|
+
{ match: /^atom-min-h-(\d+)$/, action: ([, val]) => ({ "min-height": `${val * 4}px` }) },
|
|
151
|
+
{ match: /^atom-min-h-\[(.+)\]$/, action: ([, val]) => ({ "min-height": val }) },
|
|
152
|
+
//#endRegion
|
|
153
|
+
|
|
154
|
+
//#region Colors & Typography
|
|
155
|
+
{
|
|
156
|
+
match: /^atom-(text|bg)-(black|white)$/,
|
|
157
|
+
action: ([, type, color]) => {
|
|
158
|
+
const hexCode = color === "black" ? "#000000" : "#ffffff";
|
|
159
|
+
return type === "text" ? { color: hexCode } : { "background-color": hexCode };
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
match: /^atom-text-([a-z]+)-(\d{2,3})$/,
|
|
164
|
+
action: ([, color, shade]) => (colorPalette[color]?.[shade] ? { color: colorPalette[color][shade] } : null),
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
match: /^atom-bg-([a-z]+)-(\d{2,3})$/,
|
|
168
|
+
action: ([, color, shade]) =>
|
|
169
|
+
colorPalette[color]?.[shade] ? { "background-color": colorPalette[color][shade] } : null,
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
match: /^atom-text-\[(.+)\]$/,
|
|
173
|
+
action: ([, val]) => {
|
|
174
|
+
if (/^(#|rgb|hsl|transparent|currentColor)/.test(val)) return { color: val };
|
|
175
|
+
return { "font-size": val };
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
{ match: /^atom-bg-\[(.+)\]$/, action: ([, val]) => ({ "background-color": val }) },
|
|
179
|
+
{ match: /^atom-font-\[(\d+)\]$/, action: ([, val]) => ({ "font-weight": val }) },
|
|
180
|
+
//#endRegion
|
|
181
|
+
|
|
182
|
+
//#region Borders & Shadows (New functionality)
|
|
183
|
+
{ match: /^atom-border-(\d+)$/, action: ([, val]) => ({ "border-width": `${val}px` }) },
|
|
184
|
+
{
|
|
185
|
+
match: /^atom-border-([a-z]+)-(\d{2,3})$/,
|
|
186
|
+
action: ([, color, shade]) =>
|
|
187
|
+
colorPalette[color]?.[shade] ? { "border-color": colorPalette[color][shade] } : null,
|
|
188
|
+
},
|
|
189
|
+
{ match: /^atom-border-\[(.+)\]$/, action: ([, val]) => ({ "border-color": val }) },
|
|
190
|
+
{ match: /^atom-rounded-\[(.+)\]$/, action: ([, val]) => ({ "border-radius": val }) },
|
|
191
|
+
//#endRegion
|
|
192
|
+
|
|
193
|
+
//#region Layout
|
|
194
|
+
{ match: /^atom-gap-(\d+)$/, action: ([, val]) => ({ gap: `${val * 4}px` }) },
|
|
195
|
+
{
|
|
196
|
+
match: /^atom-grid-cols-(\d+)$/,
|
|
197
|
+
action: ([, val]) => ({ "grid-template-columns": `repeat(${val}, minmax(0, 1fr))` }),
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
match: /^atom-grid-rows-(\d+)$/,
|
|
201
|
+
action: ([, val]) => ({ "grid-template-rows": `repeat(${val}, minmax(0, 1fr))` }),
|
|
202
|
+
},
|
|
203
|
+
//#endRegion
|
|
204
|
+
|
|
205
|
+
//#region Position
|
|
206
|
+
{ match: /^atom-top-(\d+)$/, action: ([, val]) => ({ top: `${val * 4}px` }) },
|
|
207
|
+
{ match: /^atom-right-(\d+)$/, action: ([, val]) => ({ right: `${val * 4}px` }) },
|
|
208
|
+
{ match: /^atom-bottom-(\d+)$/, action: ([, val]) => ({ bottom: `${val * 4}px` }) },
|
|
209
|
+
{ match: /^atom-left-(\d+)$/, action: ([, val]) => ({ left: `${val * 4}px` }) },
|
|
210
|
+
{ match: /^atom-top-\[(.+)\]$/, action: ([, val]) => ({ top: val }) },
|
|
211
|
+
{ match: /^atom-left-\[(.+)\]$/, action: ([, val]) => ({ left: val }) },
|
|
212
|
+
{ match: /^atom-right-\[(.+)\]$/, action: ([, val]) => ({ right: val }) },
|
|
213
|
+
{ match: /^atom-bottom-\[(.+)\]$/, action: ([, val]) => ({ bottom: val }) },
|
|
214
|
+
{ match: /^atom-z-(\d+)$/, action: ([, val]) => ({ "z-index": val }) },
|
|
215
|
+
{ match: /^atom-z-\[(.+)\]$/, action: ([, val]) => ({ "z-index": val }) },
|
|
216
|
+
//#endRegion
|
|
217
|
+
|
|
218
|
+
//#region Transitions (New functionality)
|
|
219
|
+
{ match: /^atom-duration-(\d+)$/, action: ([, val]) => ({ "transition-duration": `${val}ms` }) },
|
|
220
|
+
//#endRegion
|
|
221
|
+
];
|
|
222
|
+
|
|
223
|
+
export default function parseDynamic(className) {
|
|
224
|
+
for (const rule of grammarRules) {
|
|
225
|
+
const matchData = className.match(rule.match);
|
|
226
|
+
if (matchData) return rule.action(matchData);
|
|
227
|
+
}
|
|
228
|
+
return null;
|
|
229
|
+
}
|
package/main.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { scanDom, watchDOMMutations } from "./domWatcher.js";
|
|
2
|
+
import { parseCustomRule } from "./styleManager.js";
|
|
3
|
+
|
|
4
|
+
function resetDefaultStyle() {
|
|
5
|
+
if (document.getElementById("atom-live-reset")) return;
|
|
6
|
+
|
|
7
|
+
const style = document.createElement("style");
|
|
8
|
+
style.id = "atom-live-reset";
|
|
9
|
+
style.textContent = `
|
|
10
|
+
*, ::after, ::before, ::backdrop, ::file-selector-button {
|
|
11
|
+
box-sizing: border-box;
|
|
12
|
+
border: 0 solid;
|
|
13
|
+
margin: 0;
|
|
14
|
+
padding: 0;
|
|
15
|
+
}
|
|
16
|
+
html {
|
|
17
|
+
line-height: 1.5;
|
|
18
|
+
-webkit-text-size-adjust: 100%;
|
|
19
|
+
tab-size: 4;
|
|
20
|
+
font-family: ui-sans-serif, system-ui, sans-serif;
|
|
21
|
+
}
|
|
22
|
+
body { line-height: inherit; cursor: default; -webkit-font-smoothing: antialiased; }
|
|
23
|
+
h1, h2, h3, h4, h5, h6 { font-size: inherit; font-weight: inherit; }
|
|
24
|
+
input, button, textarea, select { font: inherit; color: inherit; }
|
|
25
|
+
textarea { resize: vertical; }
|
|
26
|
+
button { all: unset; cursor: pointer; }
|
|
27
|
+
button:focus-visible { outline: auto; }
|
|
28
|
+
a { color: inherit; text-decoration: inherit; }
|
|
29
|
+
ol, ul { list-style: none; }
|
|
30
|
+
img, svg, video, canvas, audio, iframe, embed, object { display: block; vertical-align: middle; }
|
|
31
|
+
img, video { max-width: 100%; height: auto; }
|
|
32
|
+
table { border-collapse: collapse; }
|
|
33
|
+
b, strong { font-weight: bolder; }
|
|
34
|
+
code, pre { font-family: ui-monospace, monospace; }
|
|
35
|
+
`;
|
|
36
|
+
document.head.appendChild(style);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function init() {
|
|
40
|
+
function startupSequence() {
|
|
41
|
+
resetDefaultStyle();
|
|
42
|
+
scanDom(document.body);
|
|
43
|
+
watchDOMMutations();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (document.readyState === "loading") {
|
|
47
|
+
document.addEventListener("DOMContentLoaded", startupSequence);
|
|
48
|
+
} else {
|
|
49
|
+
startupSequence();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
init();
|
|
54
|
+
|
|
55
|
+
const atomLive = {
|
|
56
|
+
init,
|
|
57
|
+
addClass: parseCustomRule,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export { init, parseCustomRule as addClass };
|
|
61
|
+
export default atomLive;
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "live-atom",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A lightweight runtime css library inspired by tailwind css.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"css",
|
|
7
|
+
"live-atom",
|
|
8
|
+
"liveAtom",
|
|
9
|
+
"tailwind"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/Musharafshaik70/live-atom#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/Musharafshaik70/live-atom/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/Musharafshaik70/live-atom.git"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "Musharaf Shaik",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"main": "main.js",
|
|
23
|
+
"scripts": {
|
|
24
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/styleManager.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import styleMap from "./styleMap.js";
|
|
2
|
+
import { styleCache, injectCSSRule } from "./styleSheet.js";
|
|
3
|
+
import parseDynamic from "./dynamicParser.js";
|
|
4
|
+
|
|
5
|
+
export function computeAndInjectStyles(element) {
|
|
6
|
+
const classArray = Array.from(element.classList);
|
|
7
|
+
classArray.forEach((fullClassName) => {
|
|
8
|
+
if (styleCache.has(fullClassName)) return;
|
|
9
|
+
|
|
10
|
+
let pseudoModifier = "";
|
|
11
|
+
let coreClass = fullClassName;
|
|
12
|
+
|
|
13
|
+
if (fullClassName.includes(":")) {
|
|
14
|
+
const parts = fullClassName.split(":");
|
|
15
|
+
coreClass = parts[parts.length - 1];
|
|
16
|
+
pseudoModifier = parts[0];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (!coreClass.startsWith("atom-")) return;
|
|
20
|
+
|
|
21
|
+
const generatedStyles = classToCss(coreClass);
|
|
22
|
+
|
|
23
|
+
if (Object.keys(generatedStyles).length > 0) {
|
|
24
|
+
constructCSSBlock(fullClassName, generatedStyles, pseudoModifier);
|
|
25
|
+
styleCache.add(fullClassName);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function constructCSSBlock(originalClassName, styleObject, pseudoModifier) {
|
|
31
|
+
// Escape special characters for valid CSS selectors
|
|
32
|
+
let cssRule = `.${CSS.escape(originalClassName)}`;
|
|
33
|
+
|
|
34
|
+
// Append standard pseudo-classes if matched
|
|
35
|
+
if (["hover", "focus", "active", "disabled"].includes(pseudoModifier)) {
|
|
36
|
+
cssRule += `:${pseudoModifier}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
cssRule += " { ";
|
|
40
|
+
for (const [property, value] of Object.entries(styleObject)) {
|
|
41
|
+
cssRule += `${property}: ${value}; `;
|
|
42
|
+
}
|
|
43
|
+
cssRule += "} \n";
|
|
44
|
+
|
|
45
|
+
injectCSSRule(cssRule);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function classToCss(className) {
|
|
49
|
+
// Static match
|
|
50
|
+
if (styleMap[className]) {
|
|
51
|
+
return { ...styleMap[className] };
|
|
52
|
+
}
|
|
53
|
+
// Dynamic match
|
|
54
|
+
const dynamicResult = parseDynamic(className);
|
|
55
|
+
return dynamicResult ? { ...dynamicResult } : {};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function parseCustomRule(customClassName, styleObject) {
|
|
59
|
+
if (!customClassName.startsWith("atom-")) {
|
|
60
|
+
throw new Error(`liveAtom: Custom class "${customClassName}" must start with "atom-"`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
styleMap[customClassName] = styleObject;
|
|
64
|
+
|
|
65
|
+
// Trigger an immediate scan of existing elements to apply the newly added class
|
|
66
|
+
document.querySelectorAll(`[class~="${customClassName}"]`).forEach((node) => {
|
|
67
|
+
computeAndInjectStyles(node);
|
|
68
|
+
});
|
|
69
|
+
}
|
package/styleMap.js
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
const styleMap = {
|
|
2
|
+
//#region Spacing
|
|
3
|
+
"atom-mx-auto": { "margin-left": "auto", "margin-right": "auto" },
|
|
4
|
+
//#endRegion
|
|
5
|
+
|
|
6
|
+
//#region Sizing
|
|
7
|
+
"atom-w-full": { width: "100%" },
|
|
8
|
+
"atom-h-full": { height: "100%" },
|
|
9
|
+
"atom-w-screen": { width: "100vw" },
|
|
10
|
+
"atom-h-screen": { height: "100vh" },
|
|
11
|
+
"atom-h-dvh": { height: "100dvh" },
|
|
12
|
+
"atom-w-dvw": { width: "100dvw" },
|
|
13
|
+
"atom-h-svh": { height: "100svh" },
|
|
14
|
+
"atom-w-svw": { width: "100svw" },
|
|
15
|
+
"atom-h-lvh": { height: "100lvh" },
|
|
16
|
+
"atom-w-lvw": { width: "100lvw" },
|
|
17
|
+
//#endRegion
|
|
18
|
+
|
|
19
|
+
//#region Borders
|
|
20
|
+
"atom-border": { "border-width": "1px" },
|
|
21
|
+
"atom-border-solid": { "border-style": "solid" },
|
|
22
|
+
"atom-border-dashed": { "border-style": "dashed" },
|
|
23
|
+
"atom-border-dotted": { "border-style": "dotted" },
|
|
24
|
+
"atom-border-double": { "border-style": "double" },
|
|
25
|
+
"atom-border-none": { "border-style": "none" },
|
|
26
|
+
"atom-rounded-none": { "border-radius": "0px" },
|
|
27
|
+
"atom-rounded-sm": { "border-radius": "4px" },
|
|
28
|
+
"atom-rounded-md": { "border-radius": "6px" },
|
|
29
|
+
"atom-rounded-lg": { "border-radius": "8px" },
|
|
30
|
+
"atom-rounded-xl": { "border-radius": "12px" },
|
|
31
|
+
"atom-rounded-2xl": { "border-radius": "16px" },
|
|
32
|
+
"atom-rounded-3xl": { "border-radius": "24px" },
|
|
33
|
+
"atom-rounded-4xl": { "border-radius": "32px" },
|
|
34
|
+
"atom-rounded-full": { "border-radius": "9999px" },
|
|
35
|
+
//#endRegion
|
|
36
|
+
|
|
37
|
+
//#region Typography
|
|
38
|
+
"atom-text-xs": { "font-size": "12px" },
|
|
39
|
+
"atom-text-sm": { "font-size": "14px" },
|
|
40
|
+
"atom-text-base": { "font-size": "16px" },
|
|
41
|
+
"atom-text-lg": { "font-size": "18px" },
|
|
42
|
+
"atom-text-xl": { "font-size": "20px" },
|
|
43
|
+
"atom-text-2xl": { "font-size": "24px" },
|
|
44
|
+
"atom-text-3xl": { "font-size": "30px" },
|
|
45
|
+
"atom-text-4xl": { "font-size": "36px" },
|
|
46
|
+
"atom-text-5xl": { "font-size": "48px" },
|
|
47
|
+
"atom-text-6xl": { "font-size": "60px" },
|
|
48
|
+
"atom-text-7xl": { "font-size": "72px" },
|
|
49
|
+
"atom-text-8xl": { "font-size": "96px" },
|
|
50
|
+
"atom-text-9xl": { "font-size": "128px" },
|
|
51
|
+
|
|
52
|
+
"atom-text-left": { "text-align": "left" },
|
|
53
|
+
"atom-text-center": { "text-align": "center" },
|
|
54
|
+
"atom-text-right": { "text-align": "right" },
|
|
55
|
+
"atom-text-justify": { "text-align": "justify" },
|
|
56
|
+
"atom-text-start": { "text-align": "start" },
|
|
57
|
+
"atom-text-end": { "text-align": "end" },
|
|
58
|
+
|
|
59
|
+
"atom-font-thin": { "font-weight": "100" },
|
|
60
|
+
"atom-font-extralight": { "font-weight": "200" },
|
|
61
|
+
"atom-font-light": { "font-weight": "300" },
|
|
62
|
+
"atom-font-normal": { "font-weight": "400" },
|
|
63
|
+
"atom-font-medium": { "font-weight": "500" },
|
|
64
|
+
"atom-font-semibold": { "font-weight": "600" },
|
|
65
|
+
"atom-font-bold": { "font-weight": "700" },
|
|
66
|
+
"atom-font-extrabold": { "font-weight": "800" },
|
|
67
|
+
"atom-font-black": { "font-weight": "900" },
|
|
68
|
+
|
|
69
|
+
"atom-uppercase": { "text-transform": "uppercase" },
|
|
70
|
+
"atom-lowercase": { "text-transform": "lowercase" },
|
|
71
|
+
"atom-capitalize": { "text-transform": "capitalize" },
|
|
72
|
+
"atom-normal-case": { "text-transform": "none" },
|
|
73
|
+
|
|
74
|
+
"atom-underline": { "text-decoration": "underline" },
|
|
75
|
+
"atom-overline": { "text-decoration": "overline" },
|
|
76
|
+
"atom-line-through": { "text-decoration": "line-through" },
|
|
77
|
+
"atom-no-underline": { "text-decoration": "none" },
|
|
78
|
+
//#endRegion
|
|
79
|
+
|
|
80
|
+
//#region Display & Layout
|
|
81
|
+
"atom-block": { display: "block" },
|
|
82
|
+
"atom-inline": { display: "inline" },
|
|
83
|
+
"atom-inline-block": { display: "inline-block" },
|
|
84
|
+
"atom-hidden": { display: "none" },
|
|
85
|
+
|
|
86
|
+
"atom-flex": { display: "flex" },
|
|
87
|
+
"atom-inline-flex": { display: "inline-flex" },
|
|
88
|
+
"atom-grid": { display: "grid" },
|
|
89
|
+
"atom-inline-grid": { display: "inline-grid" },
|
|
90
|
+
|
|
91
|
+
"atom-flex-row": { "flex-direction": "row" },
|
|
92
|
+
"atom-flex-row-reverse": { "flex-direction": "row-reverse" },
|
|
93
|
+
"atom-flex-col": { "flex-direction": "column" },
|
|
94
|
+
"atom-flex-col-reverse": { "flex-direction": "column-reverse" },
|
|
95
|
+
"atom-flex-wrap": { "flex-wrap": "wrap" },
|
|
96
|
+
"atom-flex-nowrap": { "flex-wrap": "nowrap" },
|
|
97
|
+
"atom-flex-wrap-reverse": { "flex-wrap": "wrap-reverse" },
|
|
98
|
+
|
|
99
|
+
"atom-items-start": { "align-items": "flex-start" },
|
|
100
|
+
"atom-items-center": { "align-items": "center" },
|
|
101
|
+
"atom-items-end": { "align-items": "flex-end" },
|
|
102
|
+
"atom-items-stretch": { "align-items": "stretch" },
|
|
103
|
+
"atom-items-baseline": { "align-items": "baseline" },
|
|
104
|
+
|
|
105
|
+
"atom-justify-start": { "justify-content": "flex-start" },
|
|
106
|
+
"atom-justify-center": { "justify-content": "center" },
|
|
107
|
+
"atom-justify-end": { "justify-content": "flex-end" },
|
|
108
|
+
"atom-justify-between": { "justify-content": "space-between" },
|
|
109
|
+
"atom-justify-around": { "justify-content": "space-around" },
|
|
110
|
+
"atom-justify-evenly": { "justify-content": "space-evenly" },
|
|
111
|
+
//#endRegion
|
|
112
|
+
|
|
113
|
+
//#region Cursor
|
|
114
|
+
"atom-cursor-pointer": { cursor: "pointer" },
|
|
115
|
+
"atom-cursor-default": { cursor: "default" },
|
|
116
|
+
"atom-cursor-not-allowed": { cursor: "not-allowed" },
|
|
117
|
+
"atom-cursor-text": { cursor: "text" },
|
|
118
|
+
"atom-cursor-move": { cursor: "move" },
|
|
119
|
+
//#endRegion
|
|
120
|
+
|
|
121
|
+
//#region Position
|
|
122
|
+
"atom-static": { position: "static" },
|
|
123
|
+
"atom-relative": { position: "relative" },
|
|
124
|
+
"atom-absolute": { position: "absolute" },
|
|
125
|
+
"atom-fixed": { position: "fixed" },
|
|
126
|
+
"atom-sticky": { position: "sticky" },
|
|
127
|
+
|
|
128
|
+
"atom-top-0": { top: "0" },
|
|
129
|
+
"atom-left-0": { left: "0" },
|
|
130
|
+
"atom-right-0": { right: "0" },
|
|
131
|
+
"atom-bottom-0": { bottom: "0" },
|
|
132
|
+
//#endRegion
|
|
133
|
+
|
|
134
|
+
//#region Transitions
|
|
135
|
+
"atom-transition-all": {
|
|
136
|
+
"transition-property": "all",
|
|
137
|
+
"transition-timing-function": "cubic-bezier(0.4, 0, 0.2, 1)",
|
|
138
|
+
},
|
|
139
|
+
"atom-transition-colors": {
|
|
140
|
+
"transition-property": "color, background-color, border-color, text-decoration-color, fill, stroke",
|
|
141
|
+
"transition-timing-function": "cubic-bezier(0.4, 0, 0.2, 1)",
|
|
142
|
+
},
|
|
143
|
+
"atom-transition-opacity": {
|
|
144
|
+
"transition-property": "opacity",
|
|
145
|
+
"transition-timing-function": "cubic-bezier(0.4, 0, 0.2, 1)",
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
"atom-overflow-hidden": { overflow: "hidden" },
|
|
149
|
+
"atom-overflow-auto": { overflow: "auto" },
|
|
150
|
+
"atom-overflow-scroll": { overflow: "scroll" },
|
|
151
|
+
|
|
152
|
+
"atom-object-cover": { "object-fit": "cover" },
|
|
153
|
+
"atom-object-contain": { "object-fit": "contain" },
|
|
154
|
+
|
|
155
|
+
"atom-whitespace-nowrap": { "white-space": "nowrap" },
|
|
156
|
+
"atom-truncate": { overflow: "hidden", "text-overflow": "ellipsis", "white-space": "nowrap" },
|
|
157
|
+
|
|
158
|
+
"atom-box-border": { "box-sizing": "border-box" },
|
|
159
|
+
"atom-box-content": { "box-sizing": "content-box" },
|
|
160
|
+
|
|
161
|
+
"atom-opacity-0": { opacity: "0" },
|
|
162
|
+
"atom-opacity-25": { opacity: "0.25" },
|
|
163
|
+
"atom-opacity-50": { opacity: "0.5" },
|
|
164
|
+
"atom-opacity-75": { opacity: "0.75" },
|
|
165
|
+
"atom-opacity-100": { opacity: "1" },
|
|
166
|
+
//#endRegion
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export default styleMap;
|
package/styleSheet.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const styleCache = new Set();
|
|
2
|
+
let runtimeStylesheet = null;
|
|
3
|
+
|
|
4
|
+
export function fetchStyleSheet() {
|
|
5
|
+
if (!runtimeStylesheet) {
|
|
6
|
+
runtimeStylesheet = document.createElement("style");
|
|
7
|
+
runtimeStylesheet.id = "live-atom-runtime";
|
|
8
|
+
document.head.appendChild(runtimeStylesheet);
|
|
9
|
+
}
|
|
10
|
+
return runtimeStylesheet;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function injectCSSRule(cssString) {
|
|
14
|
+
const stylesheet = fetchStyleSheet();
|
|
15
|
+
// Use the CSSOM for high-performance rule insertion if available
|
|
16
|
+
if (stylesheet.sheet) {
|
|
17
|
+
try {
|
|
18
|
+
stylesheet.sheet.insertRule(cssString, stylesheet.sheet.cssRules.length);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
console.warn(`LiveAtom: Failed to parse rule - ${cssString}`);
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
// Fallback for immediate DOM execution contexts
|
|
24
|
+
stylesheet.appendChild(document.createTextNode(cssString));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { styleCache };
|