tadka-css 1.0.1 → 1.0.2

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 (3) hide show
  1. package/README.md +208 -114
  2. package/package.json +1 -1
  3. package/types/index.d.ts +4 -4
package/README.md CHANGED
@@ -1,40 +1,31 @@
1
1
  # tadka-css
2
2
 
3
- Add spice to your styles. Utility-first CSS engine in vanilla JS.
4
-
5
- ![npm](https://img.shields.io/npm/v/tadka-css?label=npm)
6
- ![npm downloads](https://img.shields.io/npm/dm/tadka-css)
7
- ![license](https://img.shields.io/npm/l/tadka-css)
8
- ![bundlephobia](https://img.shields.io/bundlephobia/minzip/tadka-css)
9
- ![github stars](https://img.shields.io/github/stars/ashaafkhan/tadka-css)
3
+ A lightweight, runtime utility-first CSS engine for the browser.
10
4
 
11
5
  - npm: https://www.npmjs.com/package/tadka-css
12
- - GitHub: https://github.com/ashaafkhan/tadka-css
6
+ - GitHub repository: https://github.com/ashaafkhan/tadka-css
13
7
  - Live Demo: https://tadkacss.vercel.app/
14
8
  - Playground: https://tadkacss.vercel.app/playground/
15
9
 
16
- TypeScript typings are included out of the box through `types/index.d.ts`.
10
+ TypeScript typings are included through `types/index.d.ts`.
17
11
 
18
- ## What Is This?
12
+ ## What Is Tadka CSS?
19
13
 
20
- tadka-css is a utility-first styling engine that runs in the browser.
14
+ tadka-css lets you style HTML using utility class names like `tadka-p-4`, `tadka-bg-orange-500`, and `tadka-rounded-lg`.
21
15
 
22
- Instead of writing custom CSS rules, you write class names like:
16
+ At runtime, tadka-css scans the DOM, parses matching class names, and applies styles directly.
23
17
 
24
- - `tadka-p-4`
25
- - `tadka-bg-orange-500`
26
- - `tadka-text-white`
18
+ This project is browser-first, no build step required for basic use.
27
19
 
28
- The library scans your DOM, converts those class names into style objects, and applies styles automatically.
20
+ ## Demo App Built With the npm Package
29
21
 
30
- ## Why Beginners Like It
22
+ The demo application in this repository is built using the `tadka-css` npm package (via the published CDN bundle).
31
23
 
32
- - You can style pages without writing separate CSS files.
33
- - You can learn utility-first thinking quickly.
34
- - You can inspect styles directly in browser devtools.
35
- - You can switch from this to Tailwind-style workflows later very easily.
24
+ 1. Demo app: https://tadkacss.vercel.app/
25
+ 2. Playground: https://tadkacss.vercel.app/playground/
26
+ 3. Demo source: https://github.com/ashaafkhan/tadka-css/blob/main/demo/index.html
36
27
 
37
- ## Install
28
+ ## Installation
38
29
 
39
30
  ### npm
40
31
 
@@ -55,9 +46,7 @@ pnpm add tadka-css
55
46
  <script src="https://unpkg.com/tadka-css/dist/tadka-css.js"></script>
56
47
  ```
57
48
 
58
- ## 2-Minute Quick Start
59
-
60
- Create an HTML file and paste this:
49
+ ## Quick Start
61
50
 
62
51
  ```html
63
52
  <!doctype html>
@@ -75,56 +64,145 @@ Create an HTML file and paste this:
75
64
  </html>
76
65
  ```
77
66
 
78
- If you are using npm in a module project:
67
+ For npm/bundlers:
79
68
 
80
69
  ```js
81
70
  import TadkaCSS from "tadka-css";
82
71
  TadkaCSS.init();
83
72
  ```
84
73
 
85
- ## How It Works Internally
74
+ ## Class Name Anatomy
75
+
76
+ tadka-css parses class names using this grammar:
77
+
78
+ 1. Base utility: `tadka-{utility}-{value}`
79
+ 2. Responsive utility: `tadka-{breakpoint}:{utility}-{value}`
80
+ 3. Pseudo utility: `tadka-{pseudo}:{utility}-{value}`
81
+
82
+ Examples:
83
+
84
+ ```html
85
+ <div class="tadka-p-4 tadka-bg-orange-500 tadka-md:w-1/2 tadka-hover:scale-105"></div>
86
+ ```
87
+
88
+ ## Supported Attributes
89
+
90
+ This list reflects currently implemented resolver support.
91
+
92
+ ### 1) Spacing Attributes
93
+
94
+ - `p`, `px`, `py`, `pt`, `pr`, `pb`, `pl`
95
+ - `m`, `mx`, `my`, `mt`, `mr`, `mb`, `ml`
96
+ - `mx-auto`
97
+ - `gap`, `gap-x`, `gap-y`
98
+ - Arbitrary values with `[]`
99
+
100
+ Examples:
101
+
102
+ ```html
103
+ <div class="tadka-p-4 tadka-mx-auto tadka-gap-3 tadka-mt-[18px]"></div>
104
+ ```
105
+
106
+ ### 2) Color Attributes
107
+
108
+ - `bg-*`, `text-*`, `border-*`, `accent-*`, `caret-*`, `fill-*`, `stroke-*`
109
+ - Gradient helpers: `from-*`, `to-*`, plus `bg-gradient-to-r`
110
+ - Opacity vars: `bg-opacity-*`, `text-opacity-*`
111
+ - Ring color var: `ring-*` (color form)
112
+ - Arbitrary colors like `bg-[#FF5733]`
113
+
114
+ ### 3) Typography Attributes
115
+
116
+ - Font sizes: `text-xs` to `text-9xl`, plus `text-[...]`
117
+ - Text align: `text-left`, `text-center`, `text-right`, `text-justify`, `text-start`, `text-end`
118
+ - Font weight: `font-thin` ... `font-black`
119
+ - Font family: `font-sans`, `font-serif`, `font-mono`
120
+ - Decorations and casing: `italic`, `not-italic`, `underline`, `line-through`, `no-underline`, `uppercase`, `lowercase`, `capitalize`
121
+ - Text overflow utility: `truncate`
122
+ - Line-height: `leading-*` including named values and scaled/arbitrary values
123
+
124
+ ### 4) Border and Ring Attributes
125
+
126
+ - `border`, `border-{number}`
127
+ - Border style: `border-solid`, `border-dashed`, `border-dotted`, `border-double`, `border-hidden`, `border-none`
128
+ - Radius: `rounded`, `rounded-none`, `rounded-sm`, `rounded-md`, `rounded-lg`, `rounded-xl`, `rounded-2xl`, `rounded-3xl`, `rounded-full`
129
+ - Ring size: `ring-{number}`
130
+ - `outline-none`
131
+
132
+ ### 5) Layout Attributes
133
+
134
+ - Display: `block`, `inline-block`, `inline`, `flex`, `inline-flex`, `grid`, `hidden`, `contents`
135
+ - Flex direction: `flex-row`, `flex-col`, `flex-row-reverse`, `flex-col-reverse`
136
+ - Justify: `justify-start`, `justify-end`, `justify-center`, `justify-between`, `justify-around`, `justify-evenly`
137
+ - Align items: `items-start`, `items-end`, `items-center`, `items-baseline`, `items-stretch`
138
+ - Grid templates: `grid-cols-{n}`, `grid-rows-{n}`
139
+ - Flex basis: `basis-{n}`, `basis-full`, `basis-auto`
140
+ - Flex shorthands: `flex-1`, `flex-auto`, `flex-none`, `flex-wrap`, `flex-nowrap`
141
+
142
+ ### 6) Positioning Attributes
143
+
144
+ - Position: `static`, `relative`, `absolute`, `fixed`, `sticky`
145
+ - Float: `float-left`, `float-right`, `float-none`
146
+ - Side offsets: `top-*`, `right-*`, `bottom-*`, `left-*` including `auto`, `full`, scale, arbitrary
147
+ - Insets: `inset-*`, `inset-x-*`, `inset-y-*`
148
+ - Isolation: `isolate`, `isolation-auto`
86
149
 
87
- 1. Finds classes with the configured prefix (`tadka-` by default).
88
- 2. Parses each utility token into a CSS style object.
89
- 3. Applies standard utilities as inline styles.
90
- 4. Handles responsive utilities by injecting media query rules.
91
- 5. Handles pseudo-like interactions (hover/focus/active) via JS listeners.
150
+ ### 7) Sizing Attributes
92
151
 
93
- ## Most Common Utilities
152
+ - Width: `w-*`, fractions (`w-1/2`, etc), named values (`w-full`, `w-screen`, etc), arbitrary values
153
+ - Height: `h-*`, named viewport values (`h-screen`, `h-svh`, etc), arbitrary values
154
+ - Combined: `size-*`
155
+ - Min/max: `min-w-*`, `max-w-*`, `min-h-*`, `max-h-*`
156
+ - Aspect ratio: `aspect-auto`, `aspect-square`, `aspect-video`
94
157
 
95
- ### Spacing
158
+ ### 8) Effects Attributes
96
159
 
97
- - `tadka-p-4` (padding)
98
- - `tadka-mx-auto` (horizontal auto margin)
99
- - `tadka-gap-4` (gap)
100
- - `tadka-p-[13px]` (arbitrary value)
160
+ - Opacity: `opacity-*`
161
+ - Shadows: `shadow-none`, `shadow-sm`, `shadow`, `shadow-md`, `shadow-lg`, `shadow-xl`, `shadow-2xl`, `shadow-inner`
162
+ - Blur/filter: `blur*`, `brightness-*`, `contrast-*`, `grayscale`, `grayscale-0`
101
163
 
102
- ### Colors
164
+ ### 9) Overflow / Interaction Attributes
103
165
 
104
- - `tadka-bg-orange-500`
105
- - `tadka-text-slate-900`
106
- - `tadka-border-blue-300`
166
+ - Overflow: `overflow-*`, `overflow-x-*`, `overflow-y-*`
167
+ - Scroll behavior: `scroll-smooth`, `scroll-auto`
168
+ - Scroll spacing: `scroll-p-*`, `scroll-m-*`
169
+ - Cursor: `cursor-pointer`, `cursor-default`, `cursor-text`, `cursor-not-allowed`
170
+ - Selection: `select-none`, `select-text`
171
+ - Pointer events: `pointer-events-none`, `pointer-events-auto`
172
+ - Resize: `resize`, `resize-x`, `resize-y`, `resize-none`
173
+ - Z-index: `z-*`, `z-auto`
107
174
 
108
- ### Typography
175
+ ### 10) Transition Attributes
109
176
 
110
- - `tadka-text-sm`, `tadka-text-lg`, `tadka-text-3xl`
111
- - `tadka-font-bold`
112
- - `tadka-underline`
177
+ - `transition`, `transition-none`, `transition-all`, `transition-colors`, `transition-opacity`, `transition-shadow`, `transition-transform`
178
+ - Duration: `duration-*`
179
+ - Delay: `delay-*`
180
+ - Easing: `ease-linear`, `ease-in`, `ease-out`, `ease-in-out`
113
181
 
114
- ### Layout
182
+ ### 11) Transform Attributes
115
183
 
116
- - `tadka-flex`, `tadka-items-center`, `tadka-justify-between`
117
- - `tadka-grid`, `tadka-grid-cols-3`
184
+ - `scale-*`
185
+ - `rotate-*`, `-rotate-*`
186
+ - `translate-x-*`, `translate-y-*`, `-translate-x-*`, `-translate-y-*`
187
+ - `skew-x-*`, `skew-y-*`
188
+ - Origin: `origin-*` variants
189
+ - `perspective-*`
118
190
 
119
- ## Responsive Usage
191
+ ### 12) Animation Attributes
192
+
193
+ - `animate-none`, `animate-spin`, `animate-ping`, `animate-pulse`, `animate-bounce`
194
+
195
+ ## Responsive Attributes
196
+
197
+ Default breakpoints:
120
198
 
121
199
  | Prefix | Min Width |
122
200
  |---|---|
123
- | `tadka-sm:` | `640px` |
124
- | `tadka-md:` | `768px` |
125
- | `tadka-lg:` | `1024px` |
126
- | `tadka-xl:` | `1280px` |
127
- | `tadka-2xl:` | `1536px` |
201
+ | `sm` | `640px` |
202
+ | `md` | `768px` |
203
+ | `lg` | `1024px` |
204
+ | `xl` | `1280px` |
205
+ | `2xl` | `1536px` |
128
206
 
129
207
  Example:
130
208
 
@@ -132,30 +210,37 @@ Example:
132
210
  <div class="tadka-w-full tadka-lg:w-1/2 tadka-xl:w-1/4"></div>
133
211
  ```
134
212
 
135
- ## Interactivity Prefixes
213
+ ## Pseudo Attributes (JS-driven)
136
214
 
137
- - `tadka-hover:*`
138
- - `tadka-focus:*`
139
- - `tadka-active:*`
140
- - `tadka-disabled:*`
141
- - `tadka-checked:*`
215
+ Parser recognizes:
142
216
 
143
- Example:
217
+ - `hover`, `focus`, `active`, `disabled`, `checked`, `visited`, `group-hover`, `group-focus`, `peer-hover`
144
218
 
145
- ```html
146
- <button class="tadka-bg-orange-500 tadka-hover:bg-orange-700 tadka-active:scale-95">
147
- Hover me
148
- </button>
149
- ```
219
+ Runtime listeners currently implemented:
220
+
221
+ - `hover`, `focus`, `active`, `disabled`, `checked`
150
222
 
151
- ## Config and Custom Utilities
223
+ Important caveat:
224
+
225
+ - Pseudo support is implemented through JavaScript event listeners (not native CSS selectors).
226
+
227
+ ## Configuration
152
228
 
153
229
  ```js
154
230
  import TadkaCSS from "tadka-css";
155
231
 
156
232
  TadkaCSS.init({
157
233
  prefix: "tadka",
234
+ scale: 4,
235
+ removeClasses: false,
158
236
  watch: true,
237
+ breakpoints: {
238
+ sm: "640px",
239
+ md: "768px",
240
+ lg: "1024px",
241
+ xl: "1280px",
242
+ "2xl": "1536px",
243
+ },
159
244
  extend: {
160
245
  spicy: { color: "#E8550A", fontWeight: "800" },
161
246
  btn: (value) => ({
@@ -163,65 +248,80 @@ TadkaCSS.init({
163
248
  borderRadius: "6px",
164
249
  }),
165
250
  },
166
- colors: {
167
- masala: { 500: "#7B3F00", 300: "#C17F3C", 100: "#F5E6D0" },
168
- },
169
251
  });
170
252
  ```
171
253
 
254
+ ### Config Fields
255
+
256
+ | Field | Type | Description |
257
+ |---|---|---|
258
+ | `prefix` | `string` | Class prefix to scan (default `tadka`) |
259
+ | `scale` | `number` | Base spacing scale multiplier |
260
+ | `removeClasses` | `boolean` | If true, removes tadka classes after applying styles |
261
+ | `watch` | `boolean` | Enables MutationObserver auto re-scan |
262
+ | `breakpoints` | `object` | Responsive breakpoint map |
263
+ | `colors` | `object` | Override/extend palette |
264
+ | `extend` | `object` | Add custom static/dynamic utilities |
265
+
172
266
  ## Public API
173
267
 
174
268
  | Method | Description |
175
269
  |---|---|
176
- | `init(options)` | Initialize engine, scan DOM, start observer |
177
- | `refresh()` | Re-scan the DOM |
178
- | `apply(element)` | Apply utilities to one element |
179
- | `applyAll(nodeList)` | Apply utilities to many elements |
180
- | `parse(className)` | Return parsed style object |
181
- | `register(name, styles)` | Register a custom utility |
182
- | `unregister(name)` | Remove a custom utility |
270
+ | `init(options?)` | Build config, scan/apply, optionally start observer; returns processed element count |
271
+ | `refresh()` | Re-scan entire document; emits `refresh` |
272
+ | `apply(element)` | Apply utilities on one element |
273
+ | `applyAll(nodeList)` | Apply utilities on collection |
274
+ | `parse(className)` | Return parsed style object or `null` |
275
+ | `register(name, styles)` | Register custom utility at runtime |
276
+ | `unregister(name)` | Remove custom utility |
183
277
  | `getConfig()` | Get active config |
184
- | `setConfig(options)` | Merge and apply config changes |
185
- | `reset()` | Remove generated styles/listeners |
186
- | `on(event, handler)` | Subscribe to `ready`, `apply`, `parse-error`, `refresh` |
278
+ | `setConfig(options)` | Merge config and rebuild parser/engine |
279
+ | `reset()` | Restore original inline styles and clear listeners/rules |
280
+ | `on(event, handler)` | Subscribe to events; returns unsubscribe function |
187
281
 
188
- ### init Options
282
+ ### Events and Payloads
189
283
 
190
- | Option | Type | Default |
191
- |---|---|---|
192
- | `prefix` | `string` | `tadka` |
193
- | `scale` | `number` | `4` |
194
- | `removeClasses` | `boolean` | `false` |
195
- | `watch` | `boolean` | `true` |
196
- | `breakpoints` | `object` | `sm/md/lg/xl/2xl` |
197
- | `extend` | `object` | `{}` |
198
- | `colors` | `object` | generated palette |
284
+ | Event | Payload |
285
+ |---|---|
286
+ | `ready` | `{ count }` |
287
+ | `refresh` | `{ count }` |
288
+ | `apply` | `{ element, className, styles }` |
289
+ | `parse-error` | `{ className }` |
199
290
 
200
- ## Arbitrary Values
291
+ ## TypeScript Example
201
292
 
202
- Use square brackets for direct values:
293
+ ```ts
294
+ import TadkaCSS, { TadkaInitOptions } from "tadka-css";
203
295
 
204
- ```html
205
- <div class="tadka-p-[13px] tadka-w-[420px] tadka-bg-[#FF5733]"></div>
296
+ const config: TadkaInitOptions = {
297
+ prefix: "tadka",
298
+ watch: true,
299
+ };
300
+
301
+ TadkaCSS.init(config);
206
302
  ```
207
303
 
208
- ## Troubleshooting
304
+ ## Under the Hood
209
305
 
210
- ### My classes are not applying
306
+ 1. DOM scanner queries classes containing the configured prefix.
307
+ 2. Parser resolves each token through utility resolvers.
308
+ 3. Standard utilities become inline styles.
309
+ 4. Responsive utilities become generated `@media` rules scoped via data attributes.
310
+ 5. `watch: true` enables a MutationObserver on subtree/class changes.
311
+ 6. `reset()` restores original inline style values and clears listeners/rules.
211
312
 
212
- - Make sure class names start with `tadka-`.
213
- - If using npm import, ensure `TadkaCSS.init()` runs after DOM is ready.
214
- - If you add HTML dynamically, call `TadkaCSS.refresh()` (or keep `watch: true`).
313
+ ## Troubleshooting
215
314
 
216
- ### Responsive classes are not showing
315
+ ### Classes are not applying
217
316
 
218
- - Confirm prefixes like `tadka-md:` are written correctly.
219
- - Check if viewport width actually matches breakpoint.
317
+ 1. Ensure classes start with your configured prefix.
318
+ 2. Ensure `TadkaCSS.init()` runs after DOM is available.
319
+ 3. For dynamic content, use `watch: true` or call `refresh()`.
220
320
 
221
- ### npm page did not update after README edit
321
+ ### README on npm is not updating
222
322
 
223
- - npm README updates only after publishing a new version.
224
- - Bump version and publish again (for example, 1.0.1).
323
+ 1. README updates on npm only after publishing a new version.
324
+ 2. Run patch release (`npm version patch` + `npm publish`).
225
325
 
226
326
  ## Development
227
327
 
@@ -233,12 +333,6 @@ npm run build
233
333
  npm test
234
334
  ```
235
335
 
236
- ## Demo
237
-
238
- - Main demo: https://tadkacss.vercel.app/
239
- - Playground: https://tadkacss.vercel.app/playground/
240
- - Demo source: https://github.com/ashaafkhan/tadka-css/blob/main/demo/index.html
241
-
242
336
  ## Contributing
243
337
 
244
338
  Issues and pull requests are welcome.
@@ -247,8 +341,8 @@ Before opening a PR:
247
341
 
248
342
  1. Run `npm test`
249
343
  2. Run `npm run build`
250
- 3. Add or update tests for behavior changes
344
+ 3. Update docs/tests for behavior changes
251
345
 
252
346
  ## License
253
347
 
254
- MIT
348
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tadka-css",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Utility-first CSS engine for the DOM. Add spice to your styles.",
5
5
  "main": "dist/tadka-css.cjs.js",
6
6
  "module": "dist/tadka-css.esm.js",
package/types/index.d.ts CHANGED
@@ -39,7 +39,7 @@ interface TadkaCSSApi {
39
39
  on(event: "apply" | "parse-error" | "ready" | "refresh", handler: (payload: unknown) => void): () => void;
40
40
  }
41
41
 
42
- declare const TadkaCSS: TadkaCSSApi;
43
-
44
- export { TadkaCSS as default };
45
- export type { TadkaBreakpoints, TadkaCSSApi, TadkaDynamicStyle, TadkaInitOptions, TadkaParseResult, TadkaStyleObject };
42
+ declare const TadkaCSS: TadkaCSSApi;
43
+
44
+ export { TadkaCSS as default };
45
+ export type { TadkaBreakpoints, TadkaCSSApi, TadkaDynamicStyle, TadkaInitOptions, TadkaParseResult, TadkaStyleObject };