chai-tini 0.1.0 → 0.1.1
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/README.md +76 -26
- package/dist/applyChaiUtilities.js +2 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.js +49 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
# chai-tini
|
|
2
2
|
|
|
3
|
-
Lightweight utility-first
|
|
3
|
+
Lightweight utility-first "CSS engine" that converts `chai-*` class names into inline styles by scanning the DOM.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- Scans the DOM for elements with `chai-*` utility classes.
|
|
12
|
+
- Applies matching inline styles (the original classes stay intact).
|
|
13
|
+
- Auto-initializes on import, with an optional manual + scoped API.
|
|
4
14
|
|
|
5
15
|
## Install
|
|
6
16
|
|
|
@@ -8,15 +18,15 @@ Lightweight utility-first “CSS engine” that converts `chai-*` class names in
|
|
|
8
18
|
npm i chai-tini
|
|
9
19
|
```
|
|
10
20
|
|
|
11
|
-
##
|
|
21
|
+
## Quick Start
|
|
12
22
|
|
|
13
|
-
###
|
|
23
|
+
### Auto init (default)
|
|
14
24
|
|
|
15
25
|
```js
|
|
16
26
|
import "chai-tini";
|
|
17
27
|
```
|
|
18
28
|
|
|
19
|
-
###
|
|
29
|
+
### Manual init
|
|
20
30
|
|
|
21
31
|
```js
|
|
22
32
|
import { initChaiUtilities } from "chai-tini";
|
|
@@ -24,30 +34,70 @@ import { initChaiUtilities } from "chai-tini";
|
|
|
24
34
|
initChaiUtilities();
|
|
25
35
|
```
|
|
26
36
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
### Scope to a subtree (recommended for SPA routes)
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
import { initChaiUtilities } from "chai-tini";
|
|
41
|
+
|
|
42
|
+
const root = document.getElementById("app");
|
|
43
|
+
initChaiUtilities({ root: root ?? undefined });
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Example
|
|
47
|
+
|
|
48
|
+
```html
|
|
49
|
+
<div class="chai-p-2 chai-bg-red chai-text-center chai-fs-16 chai-font-semibold">
|
|
50
|
+
Hello
|
|
51
|
+
</div>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Supported Utilities
|
|
55
|
+
|
|
56
|
+
### Spacing (padding / margin)
|
|
57
|
+
|
|
58
|
+
- `chai-p-<n>` / `chai-m-<n>` -> `padding` / `margin`
|
|
59
|
+
- Directional variants: `chai-px-<n>`, `chai-py-<n>`, `chai-pt-<n>`, `chai-pr-<n>`, `chai-pb-<n>`, `chai-pl-<n>` (and the same for `chai-m*`)
|
|
60
|
+
|
|
61
|
+
### Colors / alignment
|
|
62
|
+
|
|
63
|
+
- `chai-bg-<color>` -> `background-color: <color>`
|
|
64
|
+
- `chai-text-<color>` -> `color: <color>`
|
|
65
|
+
- `chai-text-center|left|right|justify` -> `text-align: ...`
|
|
66
|
+
|
|
67
|
+
### Typography
|
|
68
|
+
|
|
69
|
+
- `chai-fs-<n>` -> `font-size: <n>px`
|
|
70
|
+
- `chai-font-light|normal|semibold|bold` -> `font-weight`
|
|
71
|
+
|
|
72
|
+
### Borders & radius
|
|
73
|
+
|
|
74
|
+
- `chai-rounded-<n>` -> `border-radius`
|
|
75
|
+
- `chai-rounded-(t|r|b|l)-<n>` -> corner radii
|
|
76
|
+
- `chai-border-w-<n>` -> `border-width: <n>px` and `border-style: solid`
|
|
77
|
+
- `chai-border-color-<color>` -> `border-color`
|
|
78
|
+
|
|
79
|
+
### Layout / display
|
|
80
|
+
|
|
81
|
+
- `chai-flex` -> `display: flex`
|
|
82
|
+
- `chai-grid` -> `display: grid`
|
|
83
|
+
- `chai-block` -> `display: block`
|
|
84
|
+
- `chai-inline` -> `display: inline`
|
|
85
|
+
- `chai-inline-block` -> `display: inline-block`
|
|
86
|
+
- `chai-none` -> `display: none`
|
|
87
|
+
|
|
88
|
+
### Sizing
|
|
89
|
+
|
|
90
|
+
- `chai-w-<n>` -> `width: <n>px`
|
|
91
|
+
- `chai-h-<n>` -> `height: <n>px`
|
|
92
|
+
|
|
93
|
+
### Animation
|
|
94
|
+
|
|
95
|
+
- `chai-animate-spin` -> `animation: chai-animate-spin 1s linear infinite`
|
|
96
|
+
- Also injects the required `@keyframes` into the page.
|
|
48
97
|
|
|
49
98
|
## Notes
|
|
50
99
|
|
|
51
100
|
- Numeric tokens like `2` are treated as `2px`. Tokens like `10rem` or `5%` are passed through as-is.
|
|
52
|
-
- The library
|
|
101
|
+
- The library runs in the browser only. If `document` is not available, `initChaiUtilities()` is a no-op.
|
|
102
|
+
- Inline styles are applied; if you update classes after init, call `applyChaiUtilities(root?)` again (or re-run `initChaiUtilities` for your scope).
|
|
53
103
|
|
|
@@ -4,12 +4,9 @@ export function applyChaiUtilities(root) {
|
|
|
4
4
|
const queryRoot = root ?? (typeof document !== "undefined" ? document : null);
|
|
5
5
|
if (!queryRoot)
|
|
6
6
|
return;
|
|
7
|
-
const doc =
|
|
8
|
-
// If `queryRoot` is a document, use it directly.
|
|
9
|
-
typeof queryRoot.createElement === "function"
|
|
7
|
+
const doc = typeof queryRoot.createElement === "function"
|
|
10
8
|
? queryRoot
|
|
11
|
-
:
|
|
12
|
-
queryRoot.ownerDocument ?? (typeof document !== "undefined" ? document : null);
|
|
9
|
+
: queryRoot.ownerDocument ?? (typeof document !== "undefined" ? document : null);
|
|
13
10
|
let needsAnimateSpinKeyframes = false;
|
|
14
11
|
const selectorRoot = queryRoot;
|
|
15
12
|
const elements = typeof selectorRoot.querySelectorAll === "function" ? Array.from(selectorRoot.querySelectorAll(`[class*="${prefix}"]`)) : [];
|
package/dist/index.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ import { applyChaiUtilities } from "./applyChaiUtilities.js";
|
|
|
2
2
|
export type ChaiUtilitiesInitOptions = {
|
|
3
3
|
root?: ParentNode;
|
|
4
4
|
};
|
|
5
|
+
export declare function stopChaiUtilities(root?: ParentNode): void;
|
|
5
6
|
export declare function initChaiUtilities(options?: ChaiUtilitiesInitOptions): void;
|
|
6
7
|
export { applyChaiUtilities };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,57 @@
|
|
|
1
1
|
import { applyChaiUtilities } from "./applyChaiUtilities.js";
|
|
2
|
+
const activeObservers = new WeakMap();
|
|
3
|
+
function supportsMutationObserver() {
|
|
4
|
+
return typeof MutationObserver !== "undefined";
|
|
5
|
+
}
|
|
6
|
+
function watchForChaiMutations(root) {
|
|
7
|
+
if (!supportsMutationObserver())
|
|
8
|
+
return;
|
|
9
|
+
if (activeObservers.has(root))
|
|
10
|
+
return;
|
|
11
|
+
let scheduled = false;
|
|
12
|
+
const scheduleApply = () => {
|
|
13
|
+
if (scheduled)
|
|
14
|
+
return;
|
|
15
|
+
scheduled = true;
|
|
16
|
+
queueMicrotask(() => {
|
|
17
|
+
scheduled = false;
|
|
18
|
+
applyChaiUtilities(root);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
const observer = new MutationObserver((mutations) => {
|
|
22
|
+
for (const mutation of mutations) {
|
|
23
|
+
if (mutation.type === "attributes" && mutation.attributeName !== "class")
|
|
24
|
+
continue;
|
|
25
|
+
scheduleApply();
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
observer.observe(root, {
|
|
30
|
+
subtree: true,
|
|
31
|
+
childList: true,
|
|
32
|
+
attributes: true,
|
|
33
|
+
attributeFilter: ["class"],
|
|
34
|
+
});
|
|
35
|
+
activeObservers.set(root, observer);
|
|
36
|
+
}
|
|
37
|
+
export function stopChaiUtilities(root) {
|
|
38
|
+
const target = root ?? (typeof document !== "undefined" ? document : undefined);
|
|
39
|
+
if (!target)
|
|
40
|
+
return;
|
|
41
|
+
const observer = activeObservers.get(target);
|
|
42
|
+
if (!observer)
|
|
43
|
+
return;
|
|
44
|
+
observer.disconnect();
|
|
45
|
+
activeObservers.delete(target);
|
|
46
|
+
}
|
|
2
47
|
export function initChaiUtilities(options = {}) {
|
|
3
48
|
if (typeof document === "undefined")
|
|
4
49
|
return;
|
|
5
50
|
const root = options.root ?? document;
|
|
6
|
-
const run = () =>
|
|
51
|
+
const run = () => {
|
|
52
|
+
applyChaiUtilities(root);
|
|
53
|
+
watchForChaiMutations(root);
|
|
54
|
+
};
|
|
7
55
|
if (document.readyState === "loading") {
|
|
8
56
|
document.addEventListener("DOMContentLoaded", run, { once: true });
|
|
9
57
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chai-tini",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "A lightweight client-side engine that converts `chai-*` utility classes into inline styles by scanning the DOM.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
12
|
"default": "./dist/index.js"
|
|
13
13
|
}
|
|
14
|
-
}
|
|
14
|
+
}
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"dist"
|