@teacss/classes 1.0.1 → 1.1.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/README.md CHANGED
@@ -8,9 +8,8 @@ No other package re-exports these helpers. Classes do not
8
8
  generate CSS or validate utility values; merger plugins and custom conflict
9
9
  configuration are not supported.
10
10
 
11
- The full [usage reference](docs/usage.md) covers every `cn` input, the merge
12
- model, recipe fields and selections. [Coverage principles](docs/coverage-principles.md)
13
- records the constraints and design lessons behind the conflict rules.
11
+ The full usage reference ships in this package as `docs/usage.md`: every `cn`
12
+ input, the merge model, recipe fields and selections.
14
13
 
15
14
  ## Recipes
16
15
 
@@ -195,9 +194,10 @@ The exports are `cn`, `recipe`, `omitAttributes`, and the types `ClassDict`,
195
194
 
196
195
  ## Where the conflict policy comes from
197
196
 
198
- The conflict footprints are not written in this package. They live in the Rust
199
- rule tables of the [teacss-rs](https://github.com/teacss/teacss-rs) repository,
200
- next to the rules they describe; paths below are relative to its root. Each
197
+ The conflict footprints are not written in this package. They come from the rule
198
+ tables of the TeaCSS Rust engine, next to the rules they describe, and this
199
+ package ships the generated result. The rest of this section is for maintainers
200
+ of the TeaCSS source; its paths are relative to the root of that source. Each
201
201
  Standard family declares its footprints in the `MERGE` table of
202
202
  `crates/teacss-standard/src/<family>.rs`. The `icon` row is in
203
203
  `crates/teacss-icons/src/merge.rs`, and the numbered typography group is in
package/docs/usage.md ADDED
@@ -0,0 +1,214 @@
1
+ # Runtime Classes
2
+
3
+ Install `@teacss/classes` for `cn`, `recipe` and their types; no other package
4
+ re-exports runtime helpers. Recipe libraries peer-depend on it, see
5
+ [shared recipe identity](../README.md#shared-recipe-identity).
6
+
7
+ ## `cn`
8
+
9
+ Pass classes in source order, with caller overrides last:
10
+
11
+ ```ts
12
+ import { cn } from "@teacss/classes";
13
+
14
+ cn("d:flex p:2", "p:4"); // "d:flex p:4"
15
+
16
+ const className = cn(
17
+ "d:inline-flex gap:2x p-x:3x",
18
+ compact && "gap:1x p-x:2x",
19
+ { "bg-color:primary-800 text-color:primary-000": active },
20
+ callerClassName,
21
+ );
22
+ ```
23
+
24
+ Inputs: strings, nested arrays/tuples, truthy object keys, falsy branches, numbers,
25
+ bigints or tagged templates. Keep tokens static for extraction. Templates
26
+ concatenate exactly; include spaces:
27
+
28
+ ```ts
29
+ const spacing = "p:4";
30
+ cn`${spacing} ${callerClassName}`;
31
+ ```
32
+
33
+ ### Merge model
34
+
35
+ Coverage rules resolve conflicts within one ordered condition sequence.
36
+ Partial overrides preserve the broader declaration:
37
+
38
+ ```ts
39
+ cn("p:2@hover", "p:4"); // "p:2@hover p:4"
40
+ cn("p:2@hover", "p:4@hover"); // "p:4@hover"
41
+ cn("p:2", "p-x:4!"); // "p:2 p-x:4!" — vertical padding survives
42
+ cn("blur:2!", "filter:none"); // "blur:2!"
43
+ ```
44
+
45
+ - Importance precedes source order. Important filter, backdrop-filter, shadow
46
+ or scrollbar components also remove ordinary whole-property tokens.
47
+ - `animation-composition:` survives `animation:` in either order.
48
+ - `dimensions:` / `size:` and their `min-` / `max-` groups collect both axis
49
+ overrides: `cn("size:4x", "inline-size:8", "block-size:10")` drops `size:4x`.
50
+ One axis override keeps it. The six groups remain independent; other properties
51
+ such as `p:1 p-x:2 p-y:3` keep pairwise coverage.
52
+ - Only complete `lang-` / `!lang-` tag payloads ignore ASCII case.
53
+ `cn("p:1@lang-zh-CN", "p:2@lang-zh-cn")` returns `"p:2@lang-zh-cn"`.
54
+ `zh`, `zh-CN`, and `zh-Hans` stay separate. Other condition case, order, and
55
+ repetition stay significant; the winner keeps its spelling.
56
+ - Conditions of different roles normalize to the generator's order, so
57
+ `cn("p:4@md@hover", "p:2@hover@md")` returns `"p:2@hover@md"`. Conditions of
58
+ one role keep their order: `p:1@hover@focus` and `p:2@focus@hover` both stay.
59
+ Consecutive `dark`, `light`, `rtl` and `ltr` guards are the
60
+ exception: `cn("p:4@rtl@dark", "p:2@dark@rtl")` returns `"p:2@dark@rtl"`.
61
+ A combinator between them keeps the order: `p:4@rtl@>li` and `p:2@>li@rtl`
62
+ both stay.
63
+ - Coverage follows shorthands as browsers ship them. `text-align:` and
64
+ `vertical-align:` do not remove `text-align-last:`, `baseline-source:`,
65
+ `alignment-baseline:` or `baseline-shift:`. The `corner` shorthands and
66
+ `text-spacing:` follow their specifications, although browsers do not parse
67
+ them yet.
68
+ - All `icon:value` tokens share the `icon` identity, including unsupported
69
+ values: `cn("icon:bad icon:other icon:bad")` returns `"icon:bad"`. Bare `icon`
70
+ has a separate keyword identity.
71
+ - Official `label-Nx`, `prose-Nx` and `heading-Nx` (N = 1…9), including `-mono`, form one group: same conditions,
72
+ importance first, then last wins. Atomic metrics remain. Other bare names
73
+ merge only with themselves; unknown declarations merge by prefix.
74
+ No merger plugins/injection or DOM role/scheme merging.
75
+
76
+ `cn` generates no CSS and validates no values/conditions:
77
+ `cn("p:4", "p:invalid")` returns `"p:invalid"`, which emits nothing.
78
+ Check names and values against the presets before relying on them.
79
+
80
+ Pass raw fragments to one final `cn`: merging `filter:none!` and `brightness:50`
81
+ before adding `blur:2!` loses brightness; merging all three retains it.
82
+ Recipes preserve fragments until each element's final merge.
83
+
84
+ ## `recipe` fields
85
+
86
+ | Field | Meaning |
87
+ | --- | --- |
88
+ | `defaults` | Base styles: a string for one element, or a map of named slots. Required unless extending. |
89
+ | `variants` | Styles added by each selected condition. |
90
+ | `defaultVariants` | Initial selections used when a selection is omitted. |
91
+ | `compoundVariants` | `className` styles applied when its selections match. |
92
+ | `extend` | Parent recipe whose mode, slots, styles, and variants are inherited. |
93
+
94
+ Use `defaults` at the definition's top level in both modes. Do not rename
95
+ `compoundVariants[].className` or caller `className` to `defaults`.
96
+
97
+ Each element merges in this order: base styles → selected variants → matching
98
+ compounds in declaration order → caller `className`.
99
+
100
+ ## Single-element recipe
101
+
102
+ ```ts
103
+ import { recipe } from "@teacss/classes";
104
+
105
+ const badge = recipe({
106
+ defaults: "d:inline-flex gap:1x p-y:1x p-x:2x rd:9999px",
107
+ variants: {
108
+ tone: {
109
+ ready: "bg-color:success-200 text-color:success-950",
110
+ queued: "bg-color:neutral-200 text-color:neutral-950",
111
+ },
112
+ },
113
+ defaultVariants: { tone: "ready" },
114
+ compoundVariants: [
115
+ { tone: "ready", className: "font-weight:7x" },
116
+ ],
117
+ });
118
+
119
+ badge({ tone: "ready", className: "p-x:3x" }); // one merged string
120
+ ```
121
+
122
+ String-mode variant choices and compound outputs must also be strings.
123
+
124
+ ## Multi-element recipe
125
+
126
+ ```ts
127
+ const notice = recipe({
128
+ defaults: {
129
+ frame: "d:grid gap:3x p:4",
130
+ icon: "w:4x h:4x",
131
+ title: "font-weight:7x",
132
+ message: "line-height:[1.5]",
133
+ },
134
+ variants: {
135
+ tone: {
136
+ neutral: { frame: "border-color:neutral-500" },
137
+ success: { frame: "border-color:success-600", title: "text-color:success-950" },
138
+ },
139
+ compact: { true: { frame: "p:2" } },
140
+ },
141
+ defaultVariants: { tone: "neutral", compact: false },
142
+ compoundVariants: [
143
+ { tone: "success", compact: true, className: { frame: "bg-color:success-200" } },
144
+ { tone: "success", classKeys: ["title", "message"], className: "letter-spacing:[0]" },
145
+ ],
146
+ });
147
+
148
+ const classes = notice({ tone: "success", compact: false });
149
+ classes.frame({ compact: true, className: "p:3" });
150
+ classes.icon();
151
+ classes.title();
152
+ ```
153
+
154
+ Any slot map uses multi-element mode; `root` has no special meaning. Resolvers
155
+ replace selections and append `className` independently. Pass caller `className`
156
+ to a resolver, not the top-level multi-element call.
157
+
158
+ Variant choices use slot maps. Each compound uses exactly one output form:
159
+
160
+ - A non-empty `className` slot map.
161
+ - A string `className` broadcast to a non-empty `classKeys` array of distinct,
162
+ declared or inherited slots. Sparse arrays are invalid.
163
+
164
+ Only `compoundVariants[].classKeys` broadcasts styles.
165
+
166
+ ## Selections and names
167
+
168
+ - Omitted selections use `defaultVariants`; `null` disables a selection.
169
+ - A compound may match any choice in a non-empty array:
170
+ `{ tone: ["ready", "queued"], className: "shadow:2x" }`.
171
+ - A canonical numeric choice key such as `"2"` accepts both `2` and `"2"`.
172
+ - Declaring `"true"` or `"false"` permits both boolean selections. An undeclared
173
+ boolean side adds no variant styles but can match compounds. Its string form
174
+ is valid only if declared.
175
+ - Slot names cannot be empty/whitespace-only or `class`, `className`, `then`,
176
+ `toJSON`, `toString`, `valueOf`. Avoid object-literal `__proto__`, which does
177
+ not create an own key.
178
+ - Variant names reserve `class`, `className`, `classKeys`; `defaults`, `parts`,
179
+ `styles`, and `styleKeys` remain available. `defaults` is also a valid slot.
180
+ - Put responsive/state conditions in static classes such as `p:2 p:4@md`;
181
+ recipes have no responsive-prop syntax.
182
+
183
+ ## Component props
184
+
185
+ ```ts
186
+ import { omitAttributes, type ClassProp, type VariantProps } from "@teacss/classes";
187
+
188
+ type NoticeProps = VariantProps<typeof notice> & ClassProp;
189
+
190
+ function noticeClassName({ className, ...variants }: NoticeProps) {
191
+ return notice(variants).frame({ className });
192
+ }
193
+
194
+ const rest = omitAttributes(props, ["tone", "compact", "className"]);
195
+ // Spread rest onto the DOM element; the listed props stay component-owned.
196
+ ```
197
+
198
+ `VariantProps` extracts effective selections; `ClassProp` adds optional
199
+ `className`. `class` is not an alias.
200
+
201
+ `omitAttributes` compares names case-insensitively, copies own enumerable
202
+ entries without mutating the input, and preserves symbol-keyed entries.
203
+
204
+ ## Extension and introspection
205
+
206
+ `extend: notice` inherits that recipe. Omit `defaults` to inherit base styles;
207
+ explicit defaults must retain mode but may add slots. Use finite schemas and
208
+ one loaded `@teacss/classes` module for parent and child; duplicate modules
209
+ have separate recipe identities.
210
+
211
+ Deeply frozen `.config`, typed as `RecipeIntrospection`, includes inherited `anatomy`
212
+ (slot names; `[]` for single-element recipes), `variants` (choice names),
213
+ `defaultVariants` (boolean selections become `"true"` / `"false"`), and
214
+ `compoundVariantCount`.
package/package.json CHANGED
@@ -1,14 +1,10 @@
1
1
  {
2
2
  "name": "@teacss/classes",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "TeaCSS class composition — typed recipes, nested class-value joining, and semantic conflict resolution.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
- "repository": {
8
- "type": "git",
9
- "url": "git+https://github.com/teacss/teacss-rs.git",
10
- "directory": "packages/classes"
11
- },
7
+ "homepage": "https://css.teakit.org",
12
8
  "types": "./dist/index.d.ts",
13
9
  "exports": {
14
10
  ".": {
@@ -21,6 +17,7 @@
21
17
  "dist/**/*.js",
22
18
  "dist/**/*.d.ts",
23
19
  "README.md",
20
+ "docs/usage.md",
24
21
  "LICENSE"
25
22
  ],
26
23
  "sideEffects": false,