chaiwindjs 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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +124 -0
  3. package/chai-wind.js +272 -0
  4. package/package.json +32 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Atharv Dange
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,124 @@
1
+ # chaiwindjs
2
+
3
+ A runtime CSS utility engine — apply Tailwind-style `chai-*` class names as inline styles, with **no build step, no stylesheet, and no configuration**.
4
+
5
+ Just drop in the script, add classes, done.
6
+
7
+ ---
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install chaiwindjs
13
+ ```
14
+
15
+ Or via CDN:
16
+
17
+ ```html
18
+ <script src="https://cdn.jsdelivr.net/npm/chaiwindjs/chai-wind.js"></script>
19
+ ```
20
+
21
+ ---
22
+
23
+ ## Usage
24
+
25
+ ### CDN / Script tag
26
+
27
+ ```html
28
+ <script src="https://cdn.jsdelivr.net/npm/chaiwindjs/chai-wind.js"></script>
29
+ <script>
30
+ ChaiWind.init();
31
+ </script>
32
+ ```
33
+
34
+ ### ES Module / bundler
35
+
36
+ ```js
37
+ import ChaiWind from "chaiwindjs";
38
+ // or: const ChaiWind = require("chaiwindjs");
39
+
40
+ ChaiWind.init();
41
+ ```
42
+
43
+ Then use classes directly in your HTML:
44
+
45
+ ```html
46
+ <div
47
+ class="chai-flex chai-items-center chai-gap-4 chai-p-4 chai-bg-white chai-rounded-lg chai-shadow-md"
48
+ >
49
+ <p class="chai-text-lg chai-font-semibold chai-text-ink">Hello, ChaiWind!</p>
50
+ </div>
51
+ ```
52
+
53
+ ---
54
+
55
+ ## API
56
+
57
+ ### `ChaiWind.init(options?)`
58
+
59
+ Scans the DOM, applies all matching `chai-*` classes as inline styles, and starts watching for future DOM changes.
60
+
61
+ ```js
62
+ ChaiWind.init();
63
+
64
+ // With options:
65
+ ChaiWind.init({
66
+ debug: true, // logs matches to the console (default: false)
67
+ styles: {
68
+ // extend with custom classes at init time
69
+ "my-card": "border-radius: 12px; padding: 24px; background: #fff",
70
+ },
71
+ });
72
+ ```
73
+
74
+ ### `ChaiWind.register(styles)`
75
+
76
+ Register additional custom classes at any time after init. Immediately applied to any matching elements already in the DOM.
77
+
78
+ ```js
79
+ ChaiWind.register({
80
+ "my-badge":
81
+ "font-size: 12px; background: #f97316; color: #fff; padding: 2px 8px; border-radius: 9999px",
82
+ "my-card": "border-radius: 12px; padding: 24px; background: #fff",
83
+ });
84
+ ```
85
+
86
+ ### `ChaiWind.refresh()`
87
+
88
+ Re-scans the entire DOM. Useful after surgically modifying HTML outside of React/Vue reactivity.
89
+
90
+ ```js
91
+ ChaiWind.refresh();
92
+ ```
93
+
94
+ ### `ChaiWind.listClasses()`
95
+
96
+ Prints all registered classes and their styles to the console as a table. Great for debugging.
97
+
98
+ ```js
99
+ ChaiWind.listClasses();
100
+ ```
101
+
102
+ ---
103
+
104
+ ## Built-in Classes
105
+
106
+ | Category | Examples |
107
+ | ------------ | --------------------------------------------------------------------------------------- |
108
+ | Spacing | `chai-p-2`, `chai-px-4`, `chai-m-4`, `chai-mx-auto` |
109
+ | Sizing | `chai-w-full`, `chai-h-screen`, `chai-max-w-xl` |
110
+ | Typography | `chai-text-lg`, `chai-font-bold`, `chai-uppercase`, `chai-text-center` |
111
+ | Colors | `chai-text-orange`, `chai-bg-dark`, `chai-text-white` |
112
+ | Flexbox | `chai-flex`, `chai-flex-col`, `chai-items-center`, `chai-justify-between`, `chai-gap-4` |
113
+ | Borders | `chai-border`, `chai-rounded-lg`, `chai-rounded-full` |
114
+ | Shadows | `chai-shadow`, `chai-shadow-md`, `chai-shadow-lg` |
115
+ | Display | `chai-block`, `chai-hidden`, `chai-overflow-hidden` |
116
+ | Position | `chai-relative`, `chai-absolute`, `chai-fixed` |
117
+ | Effects | `chai-transition`, `chai-opacity-50`, `chai-cursor-pointer` |
118
+ | Neobrutalist | `chai-neo-shadow`, `chai-border-neo`, `chai-bg-cream`, `chai-bg-ink` |
119
+
120
+ ---
121
+
122
+ ## License
123
+
124
+ [MIT](LICENSE)
package/chai-wind.js ADDED
@@ -0,0 +1,272 @@
1
+ const customStyles = {
2
+ // Padding
3
+ "chai-p-0": "padding: 0px",
4
+ "chai-p-1": "padding: 4px",
5
+ "chai-p-2": "padding: 8px",
6
+ "chai-p-3": "padding: 12px",
7
+ "chai-p-4": "padding: 16px",
8
+ "chai-p-6": "padding: 24px",
9
+ "chai-p-8": "padding: 32px",
10
+
11
+ "chai-px-2": "padding-left: 8px; padding-right: 8px",
12
+ "chai-px-4": "padding-left: 16px; padding-right: 16px",
13
+ "chai-py-2": "padding-top: 8px; padding-bottom: 8px",
14
+ "chai-py-4": "padding-top: 16px; padding-bottom: 16px",
15
+
16
+ // Margin
17
+ "chai-m-0": "margin: 0px",
18
+ "chai-m-1": "margin: 4px",
19
+ "chai-m-2": "margin: 8px",
20
+ "chai-m-4": "margin: 16px",
21
+ "chai-m-8": "margin: 32px",
22
+ "chai-mx-auto": "margin-left: auto; margin-right: auto",
23
+ "chai-mt-4": "margin-top: 16px",
24
+ "chai-mb-4": "margin-bottom: 16px",
25
+
26
+ // Width / Height
27
+ "chai-w-full": "width: 100%",
28
+ "chai-w-half": "width: 50%",
29
+ "chai-w-screen": "width: 100vw",
30
+ "chai-h-full": "height: 100%",
31
+ "chai-h-screen": "height: 100vh",
32
+ "chai-max-w-lg": "max-width: 512px",
33
+ "chai-max-w-xl": "max-width: 768px",
34
+
35
+ // Typography
36
+ "chai-text-xs": "font-size: 12px; line-height: 16px",
37
+ "chai-text-sm": "font-size: 14px; line-height: 20px",
38
+ "chai-text-base": "font-size: 16px; line-height: 24px",
39
+ "chai-text-lg": "font-size: 18px; line-height: 28px",
40
+ "chai-text-xl": "font-size: 20px; line-height: 28px",
41
+ "chai-text-2xl": "font-size: 24px; line-height: 32px",
42
+ "chai-text-3xl": "font-size: 30px; line-height: 36px",
43
+ "chai-text-4xl": "font-size: 36px; line-height: 40px",
44
+
45
+ "chai-font-normal": "font-weight: 400",
46
+ "chai-font-medium": "font-weight: 500",
47
+ "chai-font-semibold": "font-weight: 600",
48
+ "chai-font-bold": "font-weight: 700",
49
+
50
+ "chai-italic": "font-style: italic",
51
+ "chai-underline": "text-decoration: underline",
52
+ "chai-uppercase": "text-transform: uppercase",
53
+ "chai-text-center": "text-align: center",
54
+ "chai-text-right": "text-align: right",
55
+ "chai-tracking-wide": "letter-spacing: 0.05em",
56
+
57
+ // Colors text
58
+ "chai-text-white": "color: #ffffff",
59
+ "chai-text-black": "color: #000000",
60
+ "chai-text-gray": "color: #6b7280",
61
+ "chai-text-red": "color: #ef4444",
62
+ "chai-text-green": "color: #22c55e",
63
+ "chai-text-blue": "color: #3b82f6",
64
+ "chai-text-orange": "color: #f97316",
65
+ "chai-text-purple": "color: #a855f7",
66
+
67
+ // Colors background
68
+ "chai-bg-white": "background-color: #ffffff",
69
+ "chai-bg-black": "background-color: #000000",
70
+ "chai-bg-gray": "background-color: #f3f4f6",
71
+ "chai-bg-red": "background-color: #fee2e2",
72
+ "chai-bg-green": "background-color: #dcfce7",
73
+ "chai-bg-blue": "background-color: #dbeafe",
74
+ "chai-bg-orange": "background-color: #fff7ed",
75
+ "chai-bg-purple": "background-color: #f5f3ff",
76
+ "chai-bg-dark": "background-color: #1e1e2e",
77
+
78
+ // Border
79
+ "chai-border": "border: 1px solid #d1d5db",
80
+ "chai-border-2": "border: 2px solid #d1d5db",
81
+ "chai-border-dark": "border: 2px solid #111827",
82
+ "chai-rounded": "border-radius: 4px",
83
+ "chai-rounded-md": "border-radius: 8px",
84
+ "chai-rounded-lg": "border-radius: 12px",
85
+ "chai-rounded-full": "border-radius: 9999px",
86
+
87
+ // Shadow
88
+ "chai-shadow":
89
+ "box-shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06)",
90
+ "chai-shadow-md":
91
+ "box-shadow: 0 4px 6px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06)",
92
+ "chai-shadow-lg":
93
+ "box-shadow: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05)",
94
+
95
+ // Flexbox
96
+ "chai-flex": "display: flex",
97
+ "chai-inline-flex": "display: inline-flex",
98
+ "chai-flex-col": "flex-direction: column",
99
+ "chai-flex-wrap": "flex-wrap: wrap",
100
+ "chai-items-center": "align-items: center",
101
+ "chai-items-start": "align-items: flex-start",
102
+ "chai-justify-center": "justify-content: center",
103
+ "chai-justify-between": "justify-content: space-between",
104
+ "chai-justify-end": "justify-content: flex-end",
105
+ "chai-gap-2": "gap: 8px",
106
+ "chai-gap-4": "gap: 16px",
107
+ "chai-gap-6": "gap: 24px",
108
+
109
+ // Display / Overflow
110
+ "chai-block": "display: block",
111
+ "chai-inline": "display: inline",
112
+ "chai-inline-block": "display: inline-block",
113
+ "chai-hidden": "display: none",
114
+ "chai-overflow-hidden": "overflow: hidden",
115
+ "chai-cursor-pointer": "cursor: pointer",
116
+ "chai-select-none": "user-select: none",
117
+
118
+ // Position
119
+ "chai-relative": "position: relative",
120
+ "chai-absolute": "position: absolute",
121
+ "chai-fixed": "position: fixed",
122
+
123
+ // Opacity
124
+ "chai-opacity-50": "opacity: 0.5",
125
+ "chai-opacity-75": "opacity: 0.75",
126
+
127
+ // Transition
128
+ "chai-transition": "transition: all 0.2s ease",
129
+
130
+ // Neobrutalist
131
+ "chai-neo-shadow": "box-shadow: 5px 5px 0px #0a0a0a",
132
+ "chai-neo-shadow-lg": "box-shadow: 7px 7px 0px #0a0a0a",
133
+ "chai-neo-shadow-sm": "box-shadow: 3px 3px 0px #0a0a0a",
134
+ "chai-border-neo": "border: 3px solid #0a0a0a",
135
+ "chai-border-neo-thick": "border: 4px solid #0a0a0a",
136
+ "chai-bg-cream": "background-color: #fdfaf2",
137
+ "chai-bg-ink": "background-color: #0a0a0a",
138
+ "chai-text-ink": "color: #0a0a0a",
139
+ "chai-text-cream": "color: #fdfaf2",
140
+ "chai-bg-neo-blue": "background-color: #60b5ff",
141
+ "chai-bg-neo-orange": "background-color: #ff9149",
142
+ "chai-mb-6": "margin-bottom: 24px",
143
+ };
144
+
145
+ function applyStyleString(el, styleStr) {
146
+ styleStr.split(";").forEach((declaration) => {
147
+ const colonIdx = declaration.indexOf(":");
148
+ if (colonIdx === -1) return;
149
+
150
+ const property = declaration.slice(0, colonIdx).trim();
151
+ const value = declaration.slice(colonIdx + 1).trim();
152
+
153
+ if (property && value) {
154
+ el.style.setProperty(property, value);
155
+ }
156
+ });
157
+ }
158
+
159
+ const SKIP_TAGS = new Set(["SCRIPT", "STYLE", "NOSCRIPT"]);
160
+
161
+ function processElement(el) {
162
+ if (el.nodeType !== Node.ELEMENT_NODE) return;
163
+ if (SKIP_TAGS.has(el.tagName)) return;
164
+ if (!el.classList || el.classList.length === 0) return;
165
+
166
+ const matched = [];
167
+
168
+ el.classList.forEach((cls) => {
169
+ if (customStyles[cls]) {
170
+ applyStyleString(el, customStyles[cls]);
171
+ matched.push(cls);
172
+ }
173
+ });
174
+
175
+ if (matched.length > 0) {
176
+ el.setAttribute("data-chai-applied", matched.join(" "));
177
+
178
+ if (ChaiWind.debug) {
179
+ console.log(
180
+ `%c[chai-wind]%c matched on <${el.tagName.toLowerCase()}>:`,
181
+ "color: #f97316; font-weight: bold",
182
+ "color: inherit",
183
+ matched,
184
+ "→ style applied:",
185
+ el.getAttribute("style"),
186
+ );
187
+ }
188
+ }
189
+ }
190
+
191
+ function scanDOM(root = document.body) {
192
+ const elements = root.querySelectorAll('[class*="chai-"]');
193
+ elements.forEach(processElement);
194
+ processElement(root);
195
+ }
196
+
197
+ let _pendingNodes = new Set();
198
+ let _rafId = null;
199
+
200
+ function _flushPending() {
201
+ _pendingNodes.forEach((node) => {
202
+ processElement(node);
203
+ node.querySelectorAll?.('[class*="chai-"]').forEach(processElement);
204
+ });
205
+ _pendingNodes.clear();
206
+ _rafId = null;
207
+ }
208
+
209
+ const observer = new MutationObserver((mutations) => {
210
+ mutations.forEach((mutation) => {
211
+ mutation.addedNodes.forEach((node) => {
212
+ if (node.nodeType !== Node.ELEMENT_NODE) return;
213
+ _pendingNodes.add(node);
214
+ });
215
+
216
+ if (mutation.type === "attributes" && mutation.attributeName === "class") {
217
+ _pendingNodes.add(mutation.target);
218
+ }
219
+ });
220
+
221
+ if (!_rafId) {
222
+ _rafId = requestAnimationFrame(_flushPending);
223
+ }
224
+ });
225
+
226
+ const ChaiWind = {
227
+ debug: false,
228
+
229
+ init(options = {}) {
230
+ if (options.debug !== undefined) this.debug = options.debug;
231
+
232
+ if (options.styles) {
233
+ Object.assign(customStyles, options.styles);
234
+ }
235
+
236
+ scanDOM();
237
+
238
+ observer.observe(document.body, {
239
+ childList: true,
240
+ subtree: true,
241
+ attributes: true,
242
+ attributeFilter: ["class"],
243
+ });
244
+
245
+ console.log(
246
+ `%c chai-wind initialized %c ${Object.keys(customStyles).length} classes registered`,
247
+ "background: #f97316; color: white; font-weight: bold; padding: 2px 6px; border-radius: 3px",
248
+ "color: #f97316",
249
+ );
250
+ },
251
+
252
+ register(newStyles = {}) {
253
+ Object.assign(customStyles, newStyles);
254
+ Object.keys(newStyles).forEach((cls) => {
255
+ document.querySelectorAll(`[class~="${cls}"]`).forEach(processElement);
256
+ });
257
+ },
258
+
259
+ refresh() {
260
+ scanDOM();
261
+ },
262
+
263
+ listClasses() {
264
+ console.table(customStyles);
265
+ },
266
+ };
267
+
268
+ if (typeof module !== "undefined" && module.exports) {
269
+ module.exports = ChaiWind;
270
+ } else if (typeof window !== "undefined") {
271
+ window.ChaiWind = ChaiWind;
272
+ }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "chaiwindjs",
3
+ "version": "1.0.0",
4
+ "description": "A runtime CSS utility engine — apply Tailwind-style class names as inline styles, with no build step and no stylesheet.",
5
+ "main": "chai-wind.js",
6
+ "files": [
7
+ "chai-wind.js"
8
+ ],
9
+ "scripts": {
10
+ "prepublishOnly": "echo 'Publishing chaiwindjs...'"
11
+ },
12
+ "keywords": [
13
+ "css",
14
+ "utility",
15
+ "tailwind",
16
+ "inline-styles",
17
+ "no-build",
18
+ "chaiwind",
19
+ "chaicode",
20
+ "runtime-css"
21
+ ],
22
+ "author": "Atharv Dange",
23
+ "license": "MIT",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/atharvdangedev/Chaiwind.git"
27
+ },
28
+ "homepage": "https://github.com/atharvdangedev/Chaiwind#readme",
29
+ "bugs": {
30
+ "url": "https://github.com/atharvdangedev/Chaiwind/issues"
31
+ }
32
+ }