@molecule/app-styling 1.0.0 → 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.
- package/README.md +179 -0
- package/package.json +5 -4
package/README.md
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
3
|
+
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
|
+
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
|
+
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
+
Generated: 2026-08-04T00:41:18.664Z
|
|
7
|
+
-->
|
|
8
|
+
|
|
9
|
+
# @molecule/app-styling
|
|
10
|
+
|
|
11
|
+
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
12
|
+
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
13
|
+
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
14
|
+
|
|
15
|
+
Styling interface and utilities for molecule.dev.
|
|
16
|
+
|
|
17
|
+
Framework-agnostic class-name merging ({@link cn}), variant generation
|
|
18
|
+
({@link cva}), and theme→CSS-variable conversion ({@link themeToCSS}) — the
|
|
19
|
+
low-level plumbing that styling bonds (e.g. `@molecule/app-styling-tailwind`)
|
|
20
|
+
and ClassMap bonds build on.
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { cn, cva } from '@molecule/app-styling'
|
|
26
|
+
|
|
27
|
+
// inside a ClassMap bond / shared-component plumbing:
|
|
28
|
+
cn('base', isActive && 'active', { disabled: isDisabled })
|
|
29
|
+
const button = cva('btn', { variants: { size: { sm: 'btn-sm', lg: 'btn-lg' } } })
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Type
|
|
33
|
+
|
|
34
|
+
`core`
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install @molecule/app-styling
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## API
|
|
43
|
+
|
|
44
|
+
### Interfaces
|
|
45
|
+
|
|
46
|
+
#### `CVAConfig`
|
|
47
|
+
|
|
48
|
+
Configuration for a class-variance-authority (`cva`) function: the variant
|
|
49
|
+
definitions, default selections, and compound variants used to resolve a
|
|
50
|
+
component's final class string from its props.
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
interface CVAConfig<T extends Record<string, Record<string, string>>> {
|
|
54
|
+
variants?: T
|
|
55
|
+
defaultVariants?: { [K in keyof T]?: keyof T[K] }
|
|
56
|
+
compoundVariants?: Array<{ [K in keyof T]?: keyof T[K] } & { class: string }>
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Types
|
|
61
|
+
|
|
62
|
+
#### `ClassMerger`
|
|
63
|
+
|
|
64
|
+
A class-name merger: post-processes the joined class string produced by
|
|
65
|
+
`cn()` to resolve conflicts (e.g. `tailwind-merge`). Registered by a styling
|
|
66
|
+
bond via `setClassMerger` so the styling core stays framework-agnostic.
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
type ClassMerger = (className: string) => string
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
#### `ClassValue`
|
|
73
|
+
|
|
74
|
+
Class name value types accepted by {@link cn}.
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
type ClassValue =
|
|
78
|
+
| string
|
|
79
|
+
| number
|
|
80
|
+
| boolean
|
|
81
|
+
| undefined
|
|
82
|
+
| null
|
|
83
|
+
| ClassValue[]
|
|
84
|
+
| Record<string, boolean | undefined | null>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Functions
|
|
88
|
+
|
|
89
|
+
#### `camelToKebab(str)`
|
|
90
|
+
|
|
91
|
+
Converts a camelCase string to kebab-case.
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
function camelToKebab(str: string): string
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
- `str` — The camelCase string to convert.
|
|
98
|
+
|
|
99
|
+
**Returns:** The kebab-case version (e.g. `'borderRadius'` → `'border-radius'`).
|
|
100
|
+
|
|
101
|
+
#### `cn(classes)`
|
|
102
|
+
|
|
103
|
+
Merges class names, filtering out falsy values. Supports strings,
|
|
104
|
+
numbers, conditional objects, and nested arrays.
|
|
105
|
+
|
|
106
|
+
When a class merger is registered via {@link setClassMerger} (e.g. the
|
|
107
|
+
Tailwind bond registers `tailwind-merge`), conflicting utilities such as two
|
|
108
|
+
`gap-*` classes are resolved by it; otherwise the joined string is returned
|
|
109
|
+
as-is.
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
function cn(classes?: ClassValue[]): string
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
- `classes` — Class values to merge (strings, booleans, objects, arrays).
|
|
116
|
+
|
|
117
|
+
**Returns:** A single space-separated class string.
|
|
118
|
+
|
|
119
|
+
#### `cva(base, config)`
|
|
120
|
+
|
|
121
|
+
Creates a class variance authority (CVA) function for component variants.
|
|
122
|
+
Given a base class and variant configuration, returns a function that
|
|
123
|
+
resolves the final class string based on selected variants.
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
function cva(
|
|
127
|
+
base: string,
|
|
128
|
+
config?: CVAConfig<T>,
|
|
129
|
+
): (props?: { [K in keyof T]?: keyof T[K] } & { class?: string }) => string
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
- `base` — The base class that is always included.
|
|
133
|
+
- `config` — Variant definitions, defaults, and compound variants.
|
|
134
|
+
|
|
135
|
+
**Returns:** A function that accepts variant props and returns the resolved class string.
|
|
136
|
+
|
|
137
|
+
#### `setClassMerger(merger)`
|
|
138
|
+
|
|
139
|
+
Registers the class-name merger used by {@link cn} to resolve conflicting
|
|
140
|
+
classes. Styling bonds call this at startup; pass `null` to clear it.
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
function setClassMerger(merger: ClassMerger | null): void
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
- `merger` — Post-processes the joined class string, or `null` to disable merging.
|
|
147
|
+
|
|
148
|
+
#### `themeToCSS(theme)`
|
|
149
|
+
|
|
150
|
+
Maps a molecule theme to CSS custom properties.
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
function themeToCSS(theme: ThemeLike): Record<string, string>
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
- `theme` — A theme object with colors, spacing, typography, borderRadius, and shadows.
|
|
157
|
+
|
|
158
|
+
**Returns:** A flat record of CSS custom properties (e.g. `{ '--color-primary': '#3b82f6' }`).
|
|
159
|
+
|
|
160
|
+
## Available Providers
|
|
161
|
+
|
|
162
|
+
| Provider | Package |
|
|
163
|
+
| ------------ | -------------------------------- |
|
|
164
|
+
| Tailwind CSS | `@molecule/app-styling-tailwind` |
|
|
165
|
+
|
|
166
|
+
## Injection Notes
|
|
167
|
+
|
|
168
|
+
- **This package does NOT license raw class names in app code.** CSS class
|
|
169
|
+
STRINGS still live only inside ClassMap bond packages — application
|
|
170
|
+
components style via `getClassMap()` / `cm.*` from `@molecule/app-ui`
|
|
171
|
+
(compose with `cm.cn`). Reach for this package's `cn`/`cva` only when
|
|
172
|
+
building a styling bond or shared-component infrastructure.
|
|
173
|
+
- **Conflict resolution requires a registered merger.** Bare {@link cn} just
|
|
174
|
+
joins strings — two conflicting utilities (e.g. two `gap-*` classes) both
|
|
175
|
+
survive. A styling bond registers its merger via {@link setClassMerger} at
|
|
176
|
+
startup (the Tailwind bond registers `tailwind-merge`); without one, never
|
|
177
|
+
rely on "last class wins".
|
|
178
|
+
- {@link themeToCSS} converts a theme object into CSS-variable pairs — pair
|
|
179
|
+
it with `@molecule/app-theme` bonds instead of hand-writing variable maps.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-styling",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Styling interface and utilities for molecule.dev",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
|
-
"dist"
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
21
22
|
],
|
|
22
23
|
"keywords": [
|
|
23
24
|
"molecule",
|
|
@@ -30,14 +31,14 @@
|
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@types/node": "26.1.2",
|
|
32
33
|
"typescript": "6.0.3",
|
|
33
|
-
"vitest": "4.1.
|
|
34
|
+
"vitest": "4.1.11"
|
|
34
35
|
},
|
|
35
36
|
"repository": {
|
|
36
37
|
"type": "git",
|
|
37
38
|
"url": "https://github.com/molecule-dev/molecule.git",
|
|
38
39
|
"directory": "packages/app/core/styling"
|
|
39
40
|
},
|
|
40
|
-
"homepage": "https://
|
|
41
|
+
"homepage": "https://www.molecule.dev/packages/app-styling",
|
|
41
42
|
"bugs": "https://github.com/molecule-dev/molecule/issues",
|
|
42
43
|
"publishConfig": {
|
|
43
44
|
"access": "public"
|