@teacss/classes 0.4.7 → 0.5.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 CHANGED
@@ -1,240 +1,92 @@
1
1
  # @teacss/classes
2
2
 
3
- **Typed class composition and semantic merging for TeaCSS.**
3
+ Typed class composition and vocabulary-aware conflict resolution.
4
4
 
5
- ## Purpose
5
+ Applications using the official vocabulary should import `cn` and `recipe`
6
+ from `teacss`. Use this low-level package to build a custom merger or
7
+ integration. It does not generate CSS or validate utility values.
6
8
 
7
- This package joins nested class-value inputs and removes earlier TeaCSS tokens
8
- that are overridden by later tokens under the same condition sequence. The
9
- algorithm is independent of CSS generation and ships with no runtime
10
- dependencies: callers provide vocabulary-specific conflict metadata and optional
11
- merger plugins.
9
+ ## Recipes
12
10
 
13
- It is the low-level package for custom integration and merger authors.
14
- Applications and component libraries built on the official vocabulary use the
15
- pre-bound `cn` and `recipe` exports from `teacss`. This package does not
16
- generate CSS, validate whether a class value is supported, or own the Standard
17
- and icon vocabularies.
18
-
19
- ## Recipe composition
20
-
21
- Most applications should use `recipe` from `teacss`. It is pre-bound to
22
- the official standard-and-icon `cn`, so conflicts are resolved inside each
23
- recipe output.
24
-
25
- Use a primitive string for the top-level `className` when a recipe styles one
26
- element. Variant choices and compound outputs are strings, and calling the
27
- recipe returns the merged string directly. The call also accepts caller
28
- `className`:
11
+ A string `className` defines a single-element recipe. Calling it returns a
12
+ merged string and accepts a caller override:
29
13
 
30
14
  ```ts
31
15
  import { recipe, type ClassProp, type VariantProps } from "teacss";
32
16
 
33
17
  const badge = recipe({
34
- className: "d:inline-flex align-items:center rd:full p-x:2",
18
+ className: "d:inline-flex align-items:center p-x:2",
35
19
  variants: {
36
20
  tone: {
37
21
  neutral: "bg-color:gray-100 text-color:gray-900",
38
22
  accent: "bg-color:blue-500 text-color:white",
39
23
  },
40
24
  },
41
- compoundVariants: [
42
- {
43
- tone: "accent",
44
- className: "font-weight:700",
45
- },
46
- ],
25
+ defaultVariants: { tone: "neutral" },
47
26
  });
48
27
 
49
- badge({
50
- tone: "accent",
51
- className: "p-x:3",
52
- }); // "d:inline-flex align-items:center rd:full bg-color:blue-500 text-color:white font-weight:700 p-x:3"
28
+ badge({ tone: "accent", className: "p-x:3" });
53
29
 
54
30
  type BadgeProps = VariantProps<typeof badge> & ClassProp;
55
-
56
- function badgeClassName({ className, ...variants }: BadgeProps) {
57
- return badge({ ...variants, className });
58
- }
59
31
  ```
60
32
 
61
- Use a non-empty object for the top-level `className` when a recipe has multiple
62
- elements. There is no distinguished or required `root` key: every declared key
63
- is an ordinary named class and becomes a resolver in the result. Variant
64
- choices target those names with maps; compounds support a targeted map or a
65
- shared broadcast:
33
+ An object `className` defines named elements. Every key is ordinary; `root`
34
+ is not required or special. The recipe call selects shared variants and returns
35
+ one resolver per key. Caller `className` belongs to a resolver, not the recipe
36
+ call.
66
37
 
67
38
  ```ts
68
39
  const button = recipe({
69
40
  className: {
70
- container: "d:inline-flex align-items:center p:2 p:4@md",
41
+ container: "d:inline-flex align-items:center p:2",
71
42
  icon: "inline-size:4x",
72
- label: "",
73
43
  },
74
44
  variants: {
75
45
  size: {
76
- small: {
77
- container: "p:2",
78
- icon: "inline-size:3x",
79
- },
80
- large: {
81
- container: "p:4",
82
- icon: "inline-size:5x",
83
- },
46
+ small: { container: "p:2", icon: "inline-size:3x" },
47
+ large: { container: "p:4", icon: "inline-size:5x" },
84
48
  },
85
- disabled: {
86
- true: {
87
- container: "opacity:50 pointer-events:none",
88
- },
89
- },
90
- },
91
- defaultVariants: {
92
- size: "small",
93
- disabled: false,
94
49
  },
95
50
  compoundVariants: [
96
51
  {
97
52
  size: "large",
98
- disabled: true,
99
- className: {
100
- container: "font-weight:700",
101
- icon: "inline-size:6x",
102
- },
103
- },
104
- {
105
- disabled: true,
106
53
  classKeys: ["container", "icon"],
107
54
  className: "opacity:80",
108
55
  },
109
56
  ],
110
57
  });
111
58
 
112
- const large = button({
113
- size: "large",
114
- });
115
-
116
- large.container({
117
- disabled: true,
118
- className: "p:6",
119
- });
120
- large.icon();
121
- large.label();
122
-
123
- type ButtonProps = VariantProps<typeof button> & ClassProp;
124
-
125
- function buttonClassName({ className, ...variants }: ButtonProps) {
126
- const classes = button(variants);
127
- return classes.container({ className });
128
- }
129
- ```
130
-
131
- For an object-form recipe, the recipe call accepts only shared variant
132
- selections. Each resolver accepts all recipe selections plus `ClassProp`; its
133
- local selections and `className` apply only to that resolver invocation.
134
- Compounds are re-evaluated against that local selection without mutating the
135
- captured recipe result or sibling resolvers. A string-form recipe has no
136
- resolver layer, so its recipe call accepts `className` and returns a string.
137
-
138
- Multi-element variant choices are always class-target maps. Each compound uses
139
- exactly one of two forms: a non-empty `className` target map, or a
140
- primitive-string `className` paired with a non-empty `classKeys` array that
141
- broadcasts the class to every listed effective named class. `classKeys` may
142
- contain declared or inherited class names and must be dense, duplicate-free,
143
- and free of unknown names. Matching entries contribute to the selected classes
144
- in compound declaration order. The two forms cannot be combined. `classKeys`
145
- is reserved as a variant name, while `parts`, `styles`, and `styleKeys` are
146
- available as ordinary variant names.
147
-
148
- The field name `className` is intentionally reused only at distinct
149
- boundaries: top-level `definition.className` supplies base classes and selects
150
- string or object mode; `compoundVariants[].className` supplies a compound
151
- output; and caller `className` is accepted by a single-element recipe call or a
152
- named resolver. A multi-element recipe call does not accept caller
153
- `className`.
154
-
155
- The one-sided `disabled` variant above is boolean-capable. `true` is
156
- branch-backed and emits its fragment; boolean `false` is a distinct branchless
157
- state that emits no variant fragment but remains available to defaults,
158
- resolver-local selections, and compound matching. The undeclared string
159
- `"false"` is not an alias for that branchless state.
160
-
161
- Responsive and stateful behavior stays in static TeaCSS class values using
162
- suffix conditions such as `p:4@md` and `bg-color:blue-600@hover`; recipe props
163
- do not introduce responsive objects.
164
-
165
- Recipes extend one parent created by the exact same reciper. An extending child
166
- may omit `className` to inherit the parent's string or object mode, base
167
- fragments, and existing named classes. If a child declares `className`, it must
168
- preserve that mode; an object child may add new names:
169
-
170
- ```ts
171
- const primaryButton = recipe({
172
- extend: button,
173
- variants: {
174
- emphasis: {
175
- strong: {
176
- container: "font-weight:700",
177
- },
178
- },
179
- },
180
- });
181
-
182
- const strongBadge = recipe({
183
- extend: badge,
184
- className: "font-weight:700",
185
- });
59
+ const classes = button({ size: "large" });
60
+ classes.container({ className: "p:6" });
61
+ classes.icon();
186
62
  ```
187
63
 
188
- Typed definitions require one finite, statically stable schema. Optional,
189
- union-valued, or open index-signature key sets for object-form `className`,
190
- `variants`, or variant choices are rejected because they could promise
191
- resolvers or selections absent from the runtime branch. A `string | object`
192
- `className` value and a union-typed `extend` parent must be narrowed before
193
- calling `recipe()`. Finite required named interfaces are accepted without an
194
- artificial string index signature. `__proto__` is reserved as a statically
195
- unsafe schema name because ordinary object-literal syntax does not create a
196
- predictable own property for it; an explicitly constructed null-prototype
197
- runtime record can still carry that own name safely.
64
+ Multi-element choices target named elements with maps. A compound uses either a
65
+ `className` target map or a string `className` plus a non-empty, unique
66
+ `classKeys` list. The forms cannot be combined. `class`, `className`, and
67
+ `classKeys` are reserved variant names.
198
68
 
199
- Every definition without `extend` requires its own `className` field. An
200
- explicitly declared object `className` value must contain at least one key. The
201
- retired top-level definition field `styles` and former nested compound selector
202
- `parts` are not compatibility aliases; broadcast compounds use
203
- `compoundVariants[].classKeys`.
69
+ A one-sided boolean variant supports the undeclared opposite boolean as a
70
+ branchless state. The corresponding string is not an alias. Keep responsive
71
+ behavior in class conditions such as `p:4@md`, not variant objects.
204
72
 
205
- ### Reciper creation
73
+ Recipes may `extend` one parent created by the exact same reciper. A child may
74
+ inherit `className`, but an explicit value must preserve the parent's string or
75
+ object mode.
206
76
 
207
- `@teacss/classes` exports the `createReciper` factory and no pre-bound
208
- reciper. Each integration binds its own merger once and exports the
209
- result under the name appropriate for that integration:
77
+ ## Custom reciper
210
78
 
211
79
  ```ts
212
- import { createReciper, createMerger } from "@teacss/classes";
80
+ import { createMerger, createReciper } from "@teacss/classes";
213
81
 
214
82
  export const merge = createMerger({ conflicts, plugins });
215
83
  export const recipe = createReciper({ merge });
216
-
217
- export const libraryButton = recipe({
218
- className: "p:2",
219
- });
220
84
  ```
221
85
 
222
- `createReciper` accepts the required `merge` field; there is no default merger
223
- and no `merger` alias. Extension identity belongs to the exact reciper function,
224
- not merely to the merger. Its return type is the type-only `Reciper`
225
- export, so an integration can re-export its reciper without inlining the
226
- complete generic recipe contract into generated declarations.
227
-
228
- Libraries that export official recipes for downstream extension peer-depend on
229
- and externalize `teacss`, which owns the official reciper. A custom integration
230
- peer-depends on `@teacss/classes` and exports the exact reciper used to create
231
- its parents. Consumers deduplicate that owning integration. Recreating a
232
- reciper, loading another physical or versioned runtime, or loading the parent
233
- and reciper from different provider-package instances breaks extension
234
- identity even when declarations and merger behavior match. Deduplicating only
235
- `@teacss/classes` does not repair a duplicated custom-reciper provider.
236
- `VariantProps` extraction is type-only and needs no runtime identity; only
237
- `extend` has this exact-identity requirement.
86
+ A custom integration must export and deduplicate the exact reciper that created
87
+ its extendable recipes. Recreating it breaks extension identity even when the
88
+ merger is equivalent. `VariantProps` is type-only and has no runtime identity
89
+ requirement.
238
90
 
239
91
  ## Class merging
240
92
 
@@ -247,10 +99,7 @@ import { createMerger } from "@teacss/classes";
247
99
 
248
100
  const cn = createMerger({
249
101
  conflicts: {
250
- keywords: {
251
- flex: "display",
252
- hidden: "display",
253
- },
102
+ keywords: { hidden: "display" },
254
103
  overlaps: {
255
104
  p: ["padding-top", "padding-right", "padding-bottom", "padding-left"],
256
105
  "p-x": ["padding-left", "padding-right"],
@@ -258,148 +107,29 @@ const cn = createMerger({
258
107
  },
259
108
  });
260
109
 
261
- cn("p:4 flex", "p:8"); // "flex p:8"
262
- cn("p:4", "p-x:8"); // "p:4 p-x:8"
263
110
  cn("p:4", "p-x:8!"); // "p:4 p-x:8!"
264
- cn('content:["hello world"]', 'content:["good bye"]'); // 'content:["good bye"]'
265
- ```
266
-
267
- Attached `[]` literal regions keep their internal whitespace in one token and
268
- protect braces and semicolons from group expansion. Braces inside attached
269
- `()` CSS functions are likewise not mistaken for groups. Top-level
270
- `{p:4;m:2}@hover` group syntax still expands normally.
271
-
272
- For the standard TeaCSS vocabulary, use the pre-bound merger instead:
273
-
274
- ```ts
275
- import { cn } from "@teacss/preset-standard/merge";
276
- ```
277
-
278
- ## Merger API
279
-
280
- `createMerger(options?)` returns a callable `Merger` that accepts strings,
281
- mutable or readonly nested arrays and tuples, conditional class dictionaries,
282
- falsy values, numbers, and tagged templates. It preserves the order of
283
- surviving tokens; it does not sort them. Finite named interfaces are valid
284
- class dictionaries and conflict tables; runtime protocol validation still
285
- checks every supplied conflict atom.
286
-
287
- Tagged-template literal segments and resolved expressions concatenate exactly.
288
- Put whitespace in the template wherever two class tokens need a boundary:
289
-
290
- ```ts
291
- cn`p:${0}`; // "p:0"
292
- cn`p:4@${"hover"}`; // "p:4@hover"
293
- cn`${"p:4"} ${"m:2"}`; // "p:4 m:2"
294
- ```
295
-
296
- Options:
297
-
298
- - `conflicts`: keyword and shorthand/longhand conflict footprints.
299
- - `overlap`: `"precise"` by default, or `"symmetric"` for last-intersection
300
- wins between equal-importance tokens. Differing importance still requires
301
- full winner coverage.
302
- - `plugins`: ordered, uniquely named plugins with optional static `conflicts`,
303
- token transforms, dynamic groups, drop-only finalizers, and pair resolvers.
304
- - `cache`: one input LRU shared by normal and tagged-template calls, or `false`
305
- to disable caching. `cache.max` defaults to `1500` and must be a finite
306
- non-negative integer; `0` disables caching.
307
-
308
- Each static conflict value is one atom or a readonly atom array. Static metadata
309
- is composed once from top-level options and then plugins. Identical atom sets
310
- deduplicate; a different set for the same keyword or declaration key is a
311
- protocol error. Keyword and declaration keys are separate namespaces.
312
- Shared CSS atoms use CSS property names; a third-party private atom must begin
313
- with that plugin's unique name.
314
-
315
- ```ts
316
- import {
317
- createMerger,
318
- MERGE_OPAQUE,
319
- type MergerPlugin,
320
- } from "@teacss/classes";
321
-
322
- const plugin: MergerPlugin = {
323
- name: "example-icons",
324
- conflicts: {
325
- keywords: {},
326
- overlaps: { icon: "example-icons:icon" },
327
- },
328
- group(token) {
329
- if (token.keyword || token.prefix !== "icon") return null;
330
- return token.value?.includes("-") ? null : MERGE_OPAQUE;
331
- },
332
- };
333
-
334
- const cn = createMerger({ plugins: [plugin] });
335
111
  ```
336
112
 
337
- `MERGE_OPAQUE` is terminal classification. Different opaque raw strings survive;
338
- an exact duplicate keeps only its last occurrence and never enters finalizers or
339
- pair resolution. Import and return the named marker rather than raw `false`.
340
-
341
- Token transforms receive a readonly token list and a run-local `viewToken()`
342
- function. Their result must be an array of individual non-empty class tokens;
343
- whitespace is valid only inside an attached `[]` literal region. Transform
344
- output is not split or group-expanded again. Dynamic
345
- `group()` hooks return atoms, `MERGE_OPAQUE`, or `null`. `finalize()` receives
346
- current non-opaque occurrences with stable ids and may only return ids to drop;
347
- `null` and `[]` both drop nothing. Every returned id must be an integer, unique,
348
- and present in that exact input. Core validates the whole result before applying
349
- any drop. `resolve()` may return `"earlier"`, `"later"`, `"none"`, or `null`.
350
- Its context reports real full coverage in both directions through `covers`
351
- (later over earlier) and `earlierCoversLater`, independently of symmetric mode.
352
-
353
- A resolver is global by default. A plugin may add `resolveFamily(token)` to
354
- scope it: the family hook runs once per non-opaque occurrence, and `resolve()`
355
- is considered only when both tokens return the same non-empty family. A
356
- `resolveFamily` hook requires a `resolve` hook. Use this metadata whenever a
357
- resolver owns a finite semantic family. A run made entirely of one unowned
358
- static prefix, such as standard `p:*`, can then use the linear winner path;
359
- dynamic groups and resolver-owned families still use pair resolution.
113
+ `createMerger` accepts nested class values, conditional dictionaries, tagged
114
+ templates, and falsy values. It preserves surviving-token order.
360
115
 
361
- The package exports the `MergerProtocolError` class and the
362
- `MergerProtocolErrorCode` type. Errors expose `code` plus optional `plugin` and
363
- `hook` fields. Stable codes distinguish malformed options, cache bounds,
364
- conflict metadata, plugin names and hooks, static conflicts, and invalid
365
- transform, group, finalizer, resolver-family, or resolver results. Hook
366
- exceptions are propagated unchanged. A failed run writes no input-LRU entry.
116
+ | Option | Purpose |
117
+ | ----------- | ---------------------------------------------------------------- |
118
+ | `conflicts` | Defines keyword and declaration footprints. |
119
+ | `overlap` | Uses precise coverage by default or symmetric intersection. |
120
+ | `plugins` | Adds transforms, dynamic groups, finalizers, and pair resolvers. |
121
+ | `cache` | Configures the shared input LRU; `false` disables it. |
367
122
 
368
- Only own option, cache, conflict-shape, plugin-name, and plugin-hook fields are
369
- used; inherited prototype fields cannot alter a merger. Plugin arrays, own hook
370
- references, static records, and atom arrays are snapshotted when
371
- `createMerger()` runs. Array-shaped protocol results are validated from a fixed
372
- length and own numeric indexes; custom iterators and inherited sparse entries
373
- are not trusted. Every accepted array length must be an integer from `0` through
374
- `4294967294`; malformed plugin, metadata, and hook arrays retain their
375
- surface-specific protocol codes, while malformed class-value and tagged-template
376
- arrays report `INVALID_ARRAY_LENGTH`. Hooks are called with
377
- `this === undefined` and should be pure. If a hook closes over mutable state,
378
- use `cache: false`.
379
-
380
- ## Conflict Semantics
381
-
382
- Only tokens with the same ordered condition sequence and intersecting atom
383
- footprints are candidates. When importance differs, the important token removes
384
- the non-important token only when its footprint fully covers the token being
385
- removed; partial overlaps survive so unrelated declarations are not lost. With
386
- equal importance, precise mode drops an earlier token only when the later
387
- footprint covers it; symmetric mode treats any intersection as coverage.
388
- Surviving tokens keep their original order. A custom `resolve()` hook remains an
389
- explicit override of the default verdict.
390
-
391
- Merge never validates TeaCSS or CSS values. A structurally parsed declaration
392
- uses its declared or fallback footprint even when the value is unsupported or
393
- empty:
123
+ Only tokens with the same ordered conditions can conflict. With different
124
+ importance, the important token removes the other only when it covers the full
125
+ footprint. Merge never validates values:
394
126
 
395
127
  ```ts
396
128
  cn("p:4", "p:invalid"); // "p:invalid"
397
- cn("p:4", "p:"); // "p:"
398
129
  ```
399
130
 
400
- Run `bun run bench:merger` from the workspace root to measure the uncached
401
- standard static-prefix `p:*` path at 500, 1,000, 2,000, and 4,000 tokens.
402
-
403
- ## Status
131
+ Plugins use uniquely named private atoms, `MERGE_OPAQUE` for terminal token
132
+ classification, and `MergerProtocolError` for stable protocol failures. Hooks
133
+ should be pure; use `cache: false` when they close over mutable state.
404
134
 
405
135
  Pre-1.0. Public recipe and merge APIs may change before the stable release.
package/dist/index.d.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * Use it to strip component-owned attributes before spreading the rest onto an
11
11
  * element. The input object is not mutated; symbol-keyed entries are preserved.
12
12
  */
13
- declare function omitAttributes<T extends object>(attributes: T, ownedNames: readonly string[]): Partial<T>;
13
+ export declare function omitAttributes<T extends object>(attributes: T, ownedNames: readonly string[]): Partial<T>;
14
14
  //#endregion
15
15
  //#region src/merge.d.ts
16
16
  type ClassDict = Record<string, any>;
@@ -41,7 +41,7 @@ interface MergerTokenOccurrence {
41
41
  }
42
42
  type ResolveVerdict = "earlier" | "later" | "none";
43
43
  /** Dedicated, allocation-free classification result. */
44
- declare const MERGE_OPAQUE: false;
44
+ export declare const MERGE_OPAQUE: false;
45
45
  interface MergerPlugin<Keywords extends object = ConflictTable, Overlaps extends object = ConflictTable> {
46
46
  readonly name: string;
47
47
  readonly conflicts?: ConflictMeta<Keywords, Overlaps>;
@@ -109,7 +109,7 @@ interface Merger {
109
109
  (...inputs: ClassValue[]): string;
110
110
  }
111
111
  type MergerProtocolErrorCode = "INVALID_ARRAY_LENGTH" | "INVALID_OPTIONS" | "INVALID_CACHE_OPTIONS" | "INVALID_CONFLICT_META" | "INVALID_PLUGIN_NAME" | "DUPLICATE_PLUGIN_NAME" | "INVALID_PLUGIN_HOOK" | "INVALID_STATIC_CONFLICT" | "STATIC_CONFLICT_COLLISION" | "INVALID_TOKEN_TRANSFORM_RESULT" | "INVALID_GROUP_RESULT" | "INVALID_FINALIZER_RESULT" | "INVALID_RESOLVE_FAMILY_RESULT" | "INVALID_RESOLVE_RESULT";
112
- declare class MergerProtocolError extends TypeError {
112
+ export declare class MergerProtocolError extends TypeError {
113
113
  readonly name: "MergerProtocolError";
114
114
  readonly code: MergerProtocolErrorCode;
115
115
  readonly plugin?: string;
@@ -117,8 +117,8 @@ declare class MergerProtocolError extends TypeError {
117
117
  constructor(code: MergerProtocolErrorCode, detail: string, plugin?: string, hook?: "tokens" | "group" | "finalize" | "resolveFamily" | "resolve");
118
118
  }
119
119
  /** Build a merger bound to static footprints, overlap mode, plugins, and cache. */
120
- declare function createMerger<const Options extends MergerOptionsCarrier = {}>(options?: MergerOptionsCarrier & Options & (InvalidMergerOptions<Options> extends never ? unknown : never)): Merger;
121
- declare function createMerger(options?: MergerOptions): Merger;
120
+ export declare function createMerger<const Options extends MergerOptionsCarrier = {}>(options?: MergerOptionsCarrier & Options & (InvalidMergerOptions<Options> extends never ? unknown : never)): Merger;
121
+ export declare function createMerger(options?: MergerOptions): Merger;
122
122
  //#endregion
123
123
  //#region src/recipe.d.ts
124
124
  type ClassProp = {
@@ -279,9 +279,9 @@ type Reciper = {
279
279
  <const Parent extends MultiElementBrandedRecipe, const Styles extends StylesInput, const Variants extends VariantsInput | undefined = undefined, const Compounds extends readonly MultiElementCompoundDefinition<EffectiveSlots<Parent, Styles>, EffectiveVariants<Parent, Variants>>[] | undefined = undefined, const Definition = unknown>(definition: ExtendedRecipeInference<Styles, Parent, Variants, Compounds> & Definition & NoInfer<MultiElementRecipeDefinition<Styles, Parent, Variants, Compounds>> & NoInfer<ValidateDefinitionInput<Definition>>): TeaMultiElementRecipe<EffectiveSlots<Parent, Styles>, EffectiveVariants<Parent, Variants>>;
280
280
  };
281
281
  type VariantProps<Recipe> = Recipe extends RecipeCarrier & ((props?: infer Props) => unknown) ? VariantSelections<SchemaFromSelections<Props>> : never;
282
- declare function createReciper<const Options = unknown>(options: {
282
+ export declare function createReciper<const Options = unknown>(options: {
283
283
  readonly merge: RecipeMerger;
284
284
  } & Options & NoInfer<ValidateRecordShape<Options> & ValidateKnownKeys<Options, "merge">>): Reciper;
285
- declare function createReciper(options: ReciperOptions): Reciper;
285
+ export declare function createReciper(options: ReciperOptions): Reciper;
286
286
  //#endregion
287
- export { type ClassDict, type ClassProp, type ClassValue, type ConflictAtoms, type ConflictMeta, MERGE_OPAQUE, type Merger, type MergerOptions, type MergerPlugin, MergerProtocolError, type MergerProtocolErrorCode, type MergerTokenOccurrence, type MergerTokenView, type OverlapMode, type RecipeIntrospection, type Reciper, type ResolveVerdict, type VariantProps, createMerger, createReciper, omitAttributes };
287
+ export type { ClassDict, ClassProp, ClassValue, ConflictAtoms, ConflictMeta, Merger, MergerOptions, MergerPlugin, MergerProtocolErrorCode, MergerTokenOccurrence, MergerTokenView, OverlapMode, RecipeIntrospection, Reciper, ResolveVerdict, VariantProps };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- function e(e,t){let n={...e},r=new Set(t.map(e=>e.toLowerCase()));for(let e of Object.keys(n))r.has(e.toLowerCase())&&delete n[e];return n}function t(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0})}function n(e,n){let r=e.length;r in e?t(e,r,n):e[r]=n}function r(e){let t=``,r,i=-1,a=-1,o=-1,s=[];for(let c=0;c<e.length;c++){let l=e[c];if(r){l===`\\`?c++:l===r&&(r=void 0);continue}if(t.length>0&&l===`\\`){c++;continue}if(t.length>0&&(l===`"`||l===`'`)){r=l;continue}if(t.length>0&&l===`/`&&e[c+1]===`*`){let t=e.indexOf(`*/`,c+2);if(t<0)break;c=t+1;continue}l===`(`||l===`[`?t+=l===`(`?`)`:`]`:l===t.at(-1)?t=t.slice(0,-1):t.length===0&&(l===`@`?(a===-1&&(a=c),n(s,c)):a===-1&&(l===`:`&&i===-1?i=c:l===`!`&&(o=c)))}let c=a===-1?e.length:a,l=e.slice(0,c),u=!1;c>0&&o===c-1&&(u=!0,l=l.slice(0,-1));let d=[];for(let t=0;t<s.length;t++){let r=s[t]+1,i=t+1<s.length?s[t+1]:e.length;n(d,e.slice(r,i))}return i!==-1&&i<c?{raw:e,body:l,property:e.slice(0,i),value:l.slice(i+1),keyword:!1,important:u,conditions:d}:{raw:e,body:l,keyword:!0,important:u,conditions:d}}function i(e,t){let n=e.length;n in e?Object.defineProperty(e,n,{configurable:!0,enumerable:!0,value:t,writable:!0}):e[n]=t}function a(e){let t=[],n=[],r=new Map,a=!1,o,s;for(let c=0;c<e.length;c++){let l=e[c];if(n.length===0){l===`\\`?(/\s/.test(e[c+1]??``)&&(o=void 0),c++):/\s/.test(l)?o=void 0:l===`"`||l===`'`?o=o===l?void 0:o??l:!o&&l===`[`&&i(n,c);continue}if((s||a)&&l===`[`&&/[:@\s]/.test(e[c-1])){i(n,c),r.set(c,s??a),a=!1,s=void 0;continue}if(a){l===`*`&&e[c+1]===`/`&&(a=!1,c++);continue}if(s){l===`\\`?c++:l===s&&(s=void 0);continue}if(l===`/`&&e[c+1]===`*`)a=!0,c++;else if(l===`"`||l===`'`)s=l;else if(l===`\\`)c++;else if(l===`[`)i(n,c);else if(l===`]`){let o=n.pop(),l=r.get(o);(/[:@]/.test(e[o-1])||e[c+1]===`:`)&&i(t,{end:c+1,start:o}),l===!0?a=!0:l&&(s=l)}}let c=[];for(let e of t.sort((e,t)=>e.start-t.start||t.end-e.end))(!c.length||e.start>=c.at(-1).end)&&i(c,e);return c}function o(e,t,n){let r=e[t];if(n.blockComment)return r===`*`&&e[t+1]===`/`?(n.blockComment=!1,t+1):t;if(n.quote)return r===`\\`?t+1:(r===n.quote&&(n.quote=void 0),t);if(n.closers.length>0&&r===`/`&&e[t+1]===`*`)return n.blockComment=!0,t+1;if(n.closers.length>0&&(r===`"`||r===`'`))return n.quote=r,t;if(n.closers.length>0&&r===`\\`)return t+1;if(r===`(`||r===`[`)return d(n.closers,r===`(`?`)`:`]`),t;if(r===n.closers.at(-1))return n.closers.pop(),t}function s(e,t,n=e.length){let r={closers:[]};for(let i=t+1;i<n;i++){let t=e[i],n=o(e,i,r);if(n!==void 0){i=n;continue}if(r.closers.length===0){if(t===`}`)return{index:i,kind:`close`};if(t===`{`)return{index:i,kind:`open`}}}return{index:n,kind:`limit`}}const c=/[\s'"`;{},\])]/;function l(e,t,n=e.length){if(e[t]!==`@`)return{conds:``,end:t};let r={closers:[]},i=t;for(;i<n;i++){let t=e[i],n=o(e,i,r);if(n!==void 0){i=n;continue}if(t===`/`&&(e[i+1]===`/`||e[i+1]===`*`)&&r.closers.length===0||c.test(t)&&r.closers.length===0)break}return{conds:e.slice(t,i),end:i}}function u(e){let t=[],n={closers:[]},r=0;for(let i=0;i<e.length;i++){let a=e[i],s=o(e,i,n);if(s!==void 0){i=s;continue}a===`;`&&n.closers.length===0&&(d(t,e.slice(r,i)),r=i+1)}return d(t,e.slice(r)),t.map(e=>e.trim()).filter(Boolean)}function d(e,t){Object.defineProperty(e,e.length,{configurable:!0,enumerable:!0,value:t,writable:!0})}const f=/^(?:--?[\w-]+|[A-Z_$][\w$-]*|@teacss-skip-bracket-[\da-z]{6})$/i;function p(e,t){let n=t;for(;n>0&&/[\w-]/.test(e[n-1]);)n--;if(n===t||e[n-1]!==`:`)return!1;let r=n-1,i=r;for(;i>0&&/[\w$@-]/.test(e[i-1]);)i--;if(!f.test(e.slice(i,r)))return!1;let a=i-1;for(;a>=0&&/\s/.test(e[a]);)a--;return a<0||!`{,?`.includes(e[a])}function m(e){let t=[],n=[],r=[],i=!1,a;for(let o=0;o<e.length;o++){let s=e[o],c=e[o+1];if(n.length===0){s===`(`&&p(e,o)&&d(n,{attached:!0,start:o});continue}if(i)s===`*`&&c===`/`&&(i=!1,o++);else if(a)s===`\\`?o++:s===a&&(a=void 0);else if(s===`\\`)o++;else if(s===`/`&&c===`*`)i=!0,o++;else if(s===`'`||s===`"`||s==="`")a=s;else if(r.length>0)s===`[`||s===`(`?d(r,s===`[`?`]`:`)`):s===r.at(-1)&&r.pop();else if(s===`[`)d(r,`]`);else if(s===`(`)d(n,{attached:p(e,o),start:o});else if(s===`)`){let e=n.pop();e.attached&&d(t,{end:o+1,start:e.start})}}let o=[];for(let e of t.sort((e,t)=>e.start-t.start||t.end-e.end))(o.length===0||e.start>=o.at(-1).end)&&d(o,e);return o}function h(e){let t={seen:!1},n=g(e,t);for(let e=1;e<5&&t.seen;e++){t.seen=!1;let e=g(n,t);if(e===n)break;n=e}return n}function g(e,t){if(!e.includes(`{`))return e;let n=``,r=0,i=-1,c=0,d=0,f=e.includes(`[`)?a(e):[],p=e.includes(`(`)?m(e):[],h={closers:[]};for(;r<e.length;){for(;c<f.length&&f[c].end<=r;)c++;for(;d<p.length&&p[d].end<=r;)d++;let a=c<f.length?f[c]:void 0,m=d<p.length?p[d]:void 0,g=a?.start===r?a:m?.start===r?m:void 0;if(g&&h.blockComment!==!0&&h.quote===void 0){n+=e.slice(r,g.end),r=g.end;continue}h.closers.length>0&&/\s/.test(e[r])&&(h.blockComment=!1,h.closers.length=0,h.quote=void 0);let _=o(e,r,h);if(_!==void 0){n+=e.slice(r,_+1),r=_+1;continue}let v=e[r];if(h.closers.length>0||v!==`{`){n+=v,r++;continue}let y=s(e,r);if(y.kind!==`close`){y.kind===`open`&&t&&(t.seen=!0),n+=e.slice(r,y.index),r=y.index;continue}let b=y.index,x=e.slice(r+1,b),{conds:S,end:C}=l(e,b+1),w=u(x);if(w.length===0){n+=v,r++;continue}i===r&&n.length>0&&!/\s/.test(n.at(-1))&&(n+=` `),n+=w.map(e=>`${e}${S}`).join(` `),i=C,r=C}return n}function _(e){let t=e.split(/\s+/);return t[0]===``&&t.shift(),t.at(-1)===``&&t.pop(),t}function v(e){if(!e.includes(`[`))return _(e);let t=a(e);if(t.length===0)return _(e);let n=[],r=0,o=-1;for(let a=0;a<e.length;a++){let s=t[r];if(s&&a===s.start){o<0&&(o=a),a=s.end-1,r++;continue}/\s/.test(e[a])?(o>=0&&i(n,e.slice(o,a)),o=-1):o<0&&(o=a)}return o>=0&&i(n,e.slice(o)),n}const y=!1;var b=class extends TypeError{name=`MergerProtocolError`;code;plugin;hook;constructor(e,t,n,r){super(`[TeaCSS merge:${e}] ${t}`),this.code=e,n!==void 0&&(this.plugin=n),r!==void 0&&(this.hook=r)}};function x(){return Object.create(null)}const S=`must have an integer length from 0 through 4294967294`,C=Symbol(`missing-own-value`);function w(e,t){return`value`in t?t.value:t.get===void 0?void 0:Reflect.apply(t.get,e,[])}function T(e,t){let n=Reflect.getOwnPropertyDescriptor(e,t);return n===void 0?C:w(e,n)}function E(e,t){let n=T(e,t);return n===C?void 0:n}function D(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0})}function O(e,t){let n=e.length;n in e?D(e,n,t):e[n]=t}function k(e){let t=T(e,`length`);return typeof t==`number`&&Number.isInteger(t)&&t>=0&&t<4294967295?t:null}function ee(e){let t=``,n=k(e);if(n===null)throw new b(`INVALID_ARRAY_LENGTH`,`class-value array ${S}`);for(let r=0;r<n;r++){let n=T(e,r);if(n===C)continue;let i=te(n);i&&(t+=(t&&` `)+i)}return t}function te(e){if(!e)return``;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`bigint`)return String(e);if(Array.isArray(e))return ee(e);if(typeof e==`object`){let t=e,n=``;for(let e of Reflect.ownKeys(t)){if(typeof e!=`string`)continue;let r=Reflect.getOwnPropertyDescriptor(t,e);r===void 0||!r.enumerable||w(t,r)&&(n+=(n&&` `)+e)}return n}return``}function ne(e,t){let n=e;for(let e of t){let t=n.children??=new Map,r=t.get(e);r===void 0&&(r=x(),t.set(e,r)),n=r}return n}function re(e,t,n){let r=ne(e,t);return n?r.keywords??=new Map:r.declarations??=new Map}function ie(e){if(e.length===0)return``;if(e.length===1){let t=T(e,0);return t===C?``:t??``}let t=x(),n=new Uint8Array(e.length),i=new Uint8Array(e.length);for(let a=0;a<e.length;a++){let o=r(e[a]),s=re(t,o.conditions,o.keyword),c=o.property??o.body,l=s.get(c);n[a]=+!!o.important,l===void 0?s.set(c,a):n[l]!==0&&n[a]===0?i[a]=1:(i[l]=1,s.set(c,a))}let a=[];for(let t=0;t<e.length;t++)i[t]===0&&O(a,e[t]);return a.join(` `)}function ae(e,t){if(typeof e==`string`)return e.length===0?null:[e];if(!Array.isArray(e))return null;let n=k(e);if(n===null||n===0)return null;let r=[],i=null;for(let a=0;a<n;a++){let n=T(e,a);if(n===C||typeof n!=`string`||n.length===0)return null;(i===null?r.includes(n):i.has(n))||(O(r,n),i===null?r.length===(t?64:4)&&(i=new Set(r)):i.add(n))}return t&&r.length>1&&r.sort(),r}function oe(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function A(e,t,n,r,i){for(let a of Reflect.ownKeys(t)){if(typeof a!=`string`)continue;let o=Reflect.getOwnPropertyDescriptor(t,a);if(o===void 0||!o.enumerable)continue;let s=ae(w(t,o),!0);if(s===null)throw new b(`INVALID_STATIC_CONFLICT`,`"${r}" ${n} "${a}" must contain at least one non-empty atom`,i);let c=e.get(a);if(c===void 0){e.set(a,{atoms:s,atomSet:s.length>4?new Set(s):null,source:r});continue}if(!oe(c.atoms,s))throw new b(`STATIC_CONFLICT_COLLISION`,`static ${n} "${a}" has conflicting atom sets from "${c.source}" and "${r}"`,i)}}function j(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function M(e){if(!j(e))return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function se(e,t,n){if(!j(e))throw new b(`INVALID_CONFLICT_META`,`"${t}" conflicts must be an object`,n);let r=E(e,`keywords`);if(!M(r))throw new b(`INVALID_CONFLICT_META`,`"${t}" keywords must be a record`,n);let i=E(e,`overlaps`);if(!M(i))throw new b(`INVALID_CONFLICT_META`,`"${t}" overlaps must be a record`,n);return{keywords:r,overlaps:i}}function N(e,t,n,r){if(n!==void 0){if(typeof n!=`function`)throw new b(`INVALID_PLUGIN_HOOK`,`plugin "${e}" ${t} must be a function`,e,r);return n}}function ce(e){let t=[],n=[],r=[],i=[],a=[],o=new Set,s=k(e);if(s===null)throw new b(`INVALID_OPTIONS`,`options.plugins must be an array with an integer length from 0 through 4294967294`);for(let c=0;c<s;c++){let s=T(e,c),l=s===C?void 0:s;if(!j(l))throw new b(`INVALID_PLUGIN_NAME`,`plugin at index ${c} must have a non-empty name`);let u=E(l,`name`);if(typeof u!=`string`||u.length===0)throw new b(`INVALID_PLUGIN_NAME`,`plugin at index ${c} must have a non-empty name`);if(o.has(u))throw new b(`DUPLICATE_PLUGIN_NAME`,`duplicate plugin name "${u}"`,u);o.add(u);let d=E(l,`conflicts`),f=N(u,`tokens`,E(l,`tokens`),`tokens`),p=N(u,`group`,E(l,`group`),`group`),m=N(u,`finalize`,E(l,`finalize`),`finalize`),h=N(u,`resolveFamily`,E(l,`resolveFamily`),`resolveFamily`),g=N(u,`resolve`,E(l,`resolve`),`resolve`);if(h!==void 0&&g===void 0)throw new b(`INVALID_PLUGIN_HOOK`,`plugin "${u}" resolveFamily requires resolve`,u,`resolveFamily`);O(t,{name:u,conflicts:d===void 0?void 0:se(d,u,u)}),f!==void 0&&O(n,{name:u,hook:f}),p!==void 0&&O(r,{name:u,hook:p}),m!==void 0&&O(i,{name:u,hook:m}),g!==void 0&&O(a,{name:u,hook:g,family:h})}return{metadata:t,tokens:n,groups:r,finalizers:i,resolvers:a,allResolversScoped:a.every(e=>e.family!==void 0)}}function le(e,t){let n=new Map,r=new Map;e!==void 0&&(A(n,e.keywords,`keyword`,`<options.conflicts>`),A(r,e.overlaps,`declaration`,`<options.conflicts>`));for(let e of t)e.conflicts!==void 0&&(A(n,e.conflicts.keywords,`keyword`,e.name,e.name),A(r,e.conflicts.overlaps,`declaration`,e.name,e.name));return{keywords:n,overlaps:r}}function ue(e){let t=r(e);return{raw:e,prefix:t.property??t.body,body:t.body,value:t.value,keyword:t.keyword,conditions:t.conditions,important:t.important}}function de(){let e=new Map;return t=>{let n=e.get(t);if(n!==void 0)return n;let r=ue(t);return e.set(t,r),r}}function fe(e,t,n){if(t.length===0)return e;let r=e,i={viewToken:n};for(let e of t){let t=e.hook,n=t(r,i),a=`plugin "${e.name}" tokens() must return an array of individual non-empty class tokens`;if(!Array.isArray(n))throw new b(`INVALID_TOKEN_TRANSFORM_RESULT`,a,e.name,`tokens`);let o=[],s=k(n);if(s===null)throw new b(`INVALID_TOKEN_TRANSFORM_RESULT`,a,e.name,`tokens`);for(let t=0;t<s;t++){let r=T(n,t);if(r===C||typeof r!=`string`||r.length===0)throw new b(`INVALID_TOKEN_TRANSFORM_RESULT`,a,e.name,`tokens`);let i=v(r);if(i.length!==1||i[0]!==r)throw new b(`INVALID_TOKEN_TRANSFORM_RESULT`,a,e.name,`tokens`);O(o,r)}r=o}return r}function pe(e,t){let n=null;for(let r=0;r<t.length;r++){let i=t[r];if(i.family===void 0)continue;let a=i.family,o=a(e);if(o!==null&&(typeof o!=`string`||o.length===0))throw new b(`INVALID_RESOLVE_FAMILY_RESULT`,`plugin "${i.name}" resolveFamily() must return null or a non-empty string`,i.name,`resolveFamily`);o!==null&&((n??=Array.from({length:t.length},()=>null))[r]=o)}return n}function me(e,t,n,r,i,a){let o=a(e);for(let e of n){let n=e.hook,i=n(o);if(i===null)continue;if(i===!1)return{id:t,view:o,atoms:[],atomSet:null,pluginGrouped:!0,opaque:!0,resolverFamilies:null};let a=ae(i,!1);if(a===null)throw new b(`INVALID_GROUP_RESULT`,`plugin "${e.name}" group() must return null, MERGE_OPAQUE, or at least one non-empty atom`,e.name,`group`);return{id:t,view:o,atoms:a,atomSet:a.length>4?new Set(a):null,pluginGrouped:!0,opaque:!1,resolverFamilies:pe(o,r)}}let s=o.keyword?i.keywords.get(o.prefix):i.overlaps.get(o.prefix);return{id:t,view:o,atoms:s===void 0?[o.keyword?`@teacss/classes:keyword:${o.prefix}`:`@teacss/classes:declaration:${o.prefix}`]:s.atoms,atomSet:s===void 0?null:s.atomSet,opaque:!1,resolverFamilies:pe(o,r)}}function he(e,t){let n=new Map;for(let r of e){if(!r.opaque)continue;let e=n.get(r.view.raw);e!==void 0&&(t[e]=1),n.set(r.view.raw,r.id)}}function P(e,t){return new b(`INVALID_FINALIZER_RESULT`,`plugin "${e}" finalize() returned invalid occurrence id ${typeof t==`bigint`?`${t}n`:typeof t==`number`||typeof t==`boolean`||t==null?String(t):typeof t}`,e,`finalize`)}function ge(e,t){let n=[];for(let r of e)!r.opaque&&t[r.id]===0&&O(n,r);return n}function _e(e,t,n,r){let i=!1,a=r;for(let r of t){let t=r.hook,o=t(a?ge(e,n):e.slice());if(o===null)continue;if(!Array.isArray(o))throw P(r.name,o);let s=k(o);if(s===null)throw new b(`INVALID_FINALIZER_RESULT`,`plugin "${r.name}" finalize() result ${S}`,r.name,`finalize`);if(s===0)continue;let c=new Set;for(let t=0;t<s;t++){let i=T(o,t);if(i===C)throw P(r.name,void 0);let a=i;if(!Number.isInteger(a))throw P(r.name,a);let s=a,l=e[s];if(l===void 0||l.opaque||n[s]!==0||c.has(s))throw P(r.name,a);c.add(s)}for(let e of c)n[e]=1;c.size!==0&&(i=!0,a=!0)}return i}function ve(e,t){return e.atomSet?.has(t)??e.atoms.includes(t)}function ye(e,t){return e.pluginGrouped!==!0&&t.pluginGrouped!==!0&&e.view.keyword===t.view.keyword&&e.view.prefix===t.view.prefix}function be(e,t){if(ye(e,t))return!0;if(e.atoms.length<t.atoms.length)return!1;for(let n of t.atoms)if(!ve(e,n))return!1;return!0}function xe(e,t){if(e.atomSet!==null){for(let n of t.atoms)if(e.atomSet.has(n))return!0;return!1}if(t.atomSet!==null){for(let n of e.atoms)if(t.atomSet.has(n))return!0;return!1}for(let n of t.atoms)if(e.atoms.includes(n))return!0;return!1}function Se(e,t){let n=ne(e,t);return n.winners??=new Map}function Ce(e,t,n){let r=x();for(let i of e){if(i.opaque||t[i.id]!==0)continue;let a=n?re(r,i.view.conditions,i.view.keyword):Se(r,i.view.conditions),o=n?i.view.prefix:i.atoms[0],s=a.get(o);if(s===void 0){a.set(o,i.id);continue}e[s].view.important&&!i.view.important?t[i.id]=1:(t[s]=1,a.set(o,i.id))}}function we(e,t,n,r,i){return e.view.important===t.view.important?n||i===`symmetric`?`earlier`:`none`:t.view.important?n?`earlier`:`none`:r?`later`:`none`}function Te(e,t,n,r){let i=be(t,e),a=be(e,t),o=we(e,t,i,a,n);for(let n=0;n<r.length;n++){let s=r[n];if(s.family!==void 0){let r=e.resolverFamilies?.[n]??null,i=t.resolverFamilies?.[n]??null;if(r===null||r!==i)continue}let c=s.hook,l=c(e.view,t.view,{covers:i,earlierCoversLater:a,defaultDrop:o});if(l!==null){if(l===`earlier`||l===`later`||l===`none`)return l;throw new b(`INVALID_RESOLVE_RESULT`,`plugin "${s.name}" resolve() must return null, "earlier", "later", or "none"`,s.name,`resolve`)}}return o}function Ee(e,t,n,r,i){let a=Te(e,t,n,r);a===`earlier`?i[e.id]=1:a===`later`&&(i[t.id]=1)}function De(e,t,n,r,i){let a=t[e];for(let o=e+1;o<t.length;o++){let e=t[o];oe(a.view.conditions,e.view.conditions)&&(!ye(a,e)&&!xe(a,e)||Ee(a,e,n,r,i))}}function Oe(e,t){let n=ne(e,t);return n.postings??=new Map}function ke(e){let t=x(),n=[],r=[],i=e.length*(e.length-1)/2,a=0;for(let o=0;o<e.length;o++){let s=e[o],c=Oe(t,s.view.conditions),l=[];O(n,c),O(r,l);for(let e of s.atoms){let t=c.get(e);if(t===void 0&&(t=[],c.set(e,t)),a+=t.length,a>i)return null;O(l,t.length),O(t,o)}}return{postingMaps:n,positions:r,postingPairVisits:a}}function Ae(e,t,n,r){for(let i=0;i<e.length;i++)De(i,e,t,n,r)}function je(e,t,n,r,i,a){if(a!==null){Ce(e,r,a===`static-prefix`);return}let o=i?ge(e,r):e;if(o.length<16){Ae(o,t,n,r);return}let s=ke(o);if(s===null){Ae(o,t,n,r);return}if(s.postingPairVisits===0)return;let c=new Uint32Array(o.length),l=[];for(let e=0;e<o.length;e++){let i=o[e],a=s.postingMaps[e],u=s.positions[e];if(i.atoms.length===1){let e=a.get(i.atoms[0]);for(let a=u[0]+1;a<e.length;a++)Ee(i,o[e[a]],t,n,r);continue}let d=0;for(let e=0;e<i.atoms.length;e++){let t=a.get(i.atoms[e]);d+=t.length-u[e]-1}if(d>=o.length-e-1){De(e,o,t,n,r);continue}l.length=0;let f=!0,p=e+1;for(let e=0;e<i.atoms.length;e++){let t=a.get(i.atoms[e]);for(let n=u[e]+1;n<t.length;n++){let e=t[n];c[e]!==p&&(c[e]=p,l.length!==0&&e<l[l.length-1]&&(f=!1),O(l,e))}}f||l.sort((e,t)=>e-t);for(let e of l)Ee(i,o[e],t,n,r)}}function Me(e,t,n,r,i){let a=fe(e,r.tokens,i);if(a.length<2&&r.groups.length===0&&r.finalizers.length===0&&r.resolvers.length===0){if(a.length===0)return``;let e=T(a,0);return e===C?``:e??``}let o=[],s=!1,c=a.length>=16&&r.allResolversScoped,l=c,u=c,d,f,p=0;for(let e=0;e<a.length;e++){let n=me(a[e],e,r.groups,r.resolvers,t,i);if(n.opaque)s=!0;else if(p++,n.atoms.length!==1&&(l=!1),n.pluginGrouped===!0?u=!1:d===void 0?(d=n.view.prefix,f=n.view.keyword):(n.view.prefix!==d||n.view.keyword!==f)&&(u=!1),n.resolverFamilies!==null){for(let e of n.resolverFamilies)if(e!==null){l=!1,u=!1;break}}O(o,n)}let m=new Uint8Array(o.length);s&&he(o,m);let h=_e(o,r.finalizers,m,s),g=p<16?null:l?`singleton`:u?`static-prefix`:null;je(o,n,r.resolvers,m,s||h,g);let _=[];for(let e of o)m[e.id]===0&&O(_,e.view.raw);return _.join(` `)}function Ne(e,t,n){let r=T(e,n);if(r===C)return``;if(typeof r==`string`)return r;if(Array.isArray(t)){let e=T(t,n);if(typeof e==`string`)return e}return``}function Pe(e){return typeof e==`number`||typeof e==`bigint`?String(e):te(e)}function Fe(e,t,n){let r=``,i=k(e);if(i===null)throw new b(`INVALID_ARRAY_LENGTH`,`tagged-template strings ${S}`);for(let a=0;a<i;a++)if(r+=Ne(e,t,a),a+1<i&&a+1<n.length){let e=Pe(n[a+1]);r+=e}return r}function Ie(e={}){if(!M(e))throw new b(`INVALID_OPTIONS`,`options must be an object`);let t=E(e,`conflicts`),n=E(e,`overlap`),r=E(e,`plugins`),i=E(e,`cache`);if(n!==void 0&&n!==`precise`&&n!==`symmetric`)throw new b(`INVALID_OPTIONS`,`options.overlap must be "precise" or "symmetric"`);if(r!==void 0&&!Array.isArray(r))throw new b(`INVALID_OPTIONS`,`options.plugins must be an array`);let a=ce(r===void 0?[]:r),o=le(t===void 0?void 0:se(t,`<options.conflicts>`),a.metadata),s=a.tokens.length!==0||a.groups.length!==0||a.finalizers.length!==0||a.resolvers.length!==0,c=!s&&o.keywords.size===0&&o.overlaps.size===0,l=n??`precise`,u=1500;if(i===!1)u=0;else if(i!==void 0){if(!M(i))throw new b(`INVALID_CACHE_OPTIONS`,`options.cache must be false or an object`);let e=E(i,`max`);if(e!==void 0){if(typeof e!=`number`||!Number.isFinite(e)||!Number.isInteger(e)||e<0)throw new b(`INVALID_CACHE_OPTIONS`,`options.cache.max must be a finite non-negative integer`);u=e}}let d=u>0?new Map:null;function f(e){if(d!==null){let t=d.get(e);if(t!==void 0)return d.delete(e),d.set(e,t),t}let t=v(h(e).trim()),n=c?ie(t):Me(t,o,l,a,s?de():ue);return d!==null&&(d.set(e,n),d.size>u&&d.delete(d.keys().next().value)),n}function p(...e){let t=e[0],n=Array.isArray(t)?T(t,`raw`):C;return f(Array.isArray(n)?Fe(t,n,e):ee(e))}return p}const F=Object.prototype.propertyIsEnumerable,I=`definition.className`,L=`definition.variants`,R=`definition.defaultVariants`,z=`definition.compoundVariants`,B=`createReciper options`,Le=`${B}.merge`,V=`recipe props`,H=`className`,Re=`classKeys`,ze=`null is not allowed`,Be=`required own enumerable field`,Ve=new Set([`className`,`variants`,`defaultVariants`,`compoundVariants`,`extend`]),He=new Set([`class`,`className`,`then`,`toJSON`,`toString`,`valueOf`]),Ue=new Set([`class`,`className`,`classKeys`]);function U(e){return e.length>16?new Set(e):void 0}function W(e,t,n){return t?.has(n)??e.includes(n)}function G(e,t){return TypeError(`[TeaCSS recipe] ${e}: ${t}`)}function K(e,t){if(typeof e!=`object`||!e||Array.isArray(e))throw G(t,`expected a plain record`);let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==null)throw G(t,`expected Object.prototype or null prototype`);return Object.keys(e)}function We(e,t){if(typeof e!=`object`||!e||Array.isArray(e))throw G(t,`expected a non-null, non-array object`);return Object.keys(e)}function q(e,t,n){let r=Reflect.getOwnPropertyDescriptor(e,t);if(r===void 0||!r.enumerable)throw G(n,`expected an own enumerable field`);return`value`in r?r.value:r.get===void 0?void 0:Reflect.apply(r.get,e,[])}function Ge(e,t){let n=Reflect.getOwnPropertyDescriptor(e,`length`),r=n!==void 0&&`value`in n?n.value:void 0;if(typeof r!=`number`||!Number.isInteger(r)||r<0||r>=4294967295)throw G(t,`expected an array with a valid own length`);return r}function Ke(e,t,n){if(!Array.isArray(e))throw G(t,`expected an array`);let r=Object.keys(e),i=Ge(e,t);if(!n&&i===0)throw G(t,`expected a non-empty array`);if(r.length!==i)throw G(t,`expected a dense own-indexed array`);for(let e of r){let n=Number(e);if(!Number.isInteger(n)||n<0||n>=i||String(n)!==e)throw G(t,`expected a dense own-indexed array`)}let a=X(i);for(let n=0;n<i;n++)a[n]=q(e,n,`${t}[${n}]`);return a}function qe(e,t){if(e.trim().length===0)throw G(t,`name must contain a non-whitespace character`)}function J(e){let t=ee([e]);return t.length===0?void 0:t}function Y(e,t,n){if(n===void 0)return;let r=F.call(e,t)?e[t]:void 0;e[t]=r===void 0?[n]:[...r,n]}function X(e){let t=Array(e);for(let n=0;n<e;n++)n in t?D(t,n,void 0):t[n]=void 0;return t}function Je(){return[void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0]}const Ye=Je().length;function Z(e,t,n){t<Ye||!(t in e)?e[t]=n:D(e,t,n)}function Q(e,t=e.length){let n=X(t),r=Math.min(e.length,t);for(let t=0;t<r;t++){if(!F.call(e,t))continue;let r=e[t];r!==void 0&&(n[t]=[...r])}return n}function Xe(e,t){return e.map(e=>{let n=Object.create(null);for(let r of Object.keys(e.choices))n[r]={fragmentsBySlot:Q(e.choices[r].fragmentsBySlot,t)};return{name:e.name,choices:n,booleanCapable:e.booleanCapable}})}function $(e,t,n){if(e===null)return null;if(typeof e==`string`){if(!F.call(t.choices,e))throw G(n,`unknown choice ${JSON.stringify(e)}`);return e}if(typeof e==`number`){if(!Number.isFinite(e))throw G(n,`expected a finite numeric choice`);let r=String(e);if(!F.call(t.choices,r))throw G(n,`unknown choice ${JSON.stringify(r)}`);return r}if(typeof e==`boolean`){if(!t.booleanCapable)throw G(n,`boolean selection requires a true or false choice`);return String(e)}throw G(n,`expected null, a declared string or finite numeric choice, or a supported boolean state`)}function Ze(e,t,n){if(n&&(e=t.slotNames.length===0?``:{}),typeof e==`string`){if(t!==void 0&&t.slotNames.length>0)throw G(I,`must be a record when extending a multi-element recipe`);let n=t===void 0?X(1):Q(t.baseFragmentsBySlot,1);return Y(n,0,J(e)),{names:[],indexes:Object.create(null),baseFragments:n}}let r=K(e,I);if(t!==void 0&&t.slotNames.length===0)throw G(I,`must be a string when extending a single-element recipe`);if(!n&&r.length===0)throw G(I,`expected at least one named class`);for(let e of r){let t=`${I}.${e}`;if(qe(e,t),He.has(e))throw G(t,`reserved class name`)}let i=t===void 0?[]:[...t.slotNames],a=Object.create(null);for(let e=0;e<i.length;e++)a[i[e]]=e;let o=t===void 0?[]:Q(t.baseFragmentsBySlot),s=e;for(let e of r){let t=a[e];t===void 0&&(t=i.length,O(i,e),a[e]=t,O(o,void 0)),Y(o,t,J(q(s,e,`${I}.${e}`)))}return{names:i,indexes:a,baseFragments:o}}function Qe(e,t,n,r,i,a){if(n){if(typeof t!=`string`)throw G(i,`expected a primitive string`);Y(e,0,J(t));return}let o=K(t,i);if(a&&o.length===0)throw G(i,`expected at least one class target`);let s=t;for(let t of o){let n=r[t];if(n===void 0)throw G(`${i}.${t}`,`unknown class target`);Y(e,n,J(q(s,t,`${i}.${t}`)))}}function $e(e,t,n,r,i){let a=t===void 0?[]:Xe(t.variants,i),o=Object.create(null);for(let e=0;e<a.length;e++)o[a[e].name]=e;if(e===void 0)return{variants:a,indexes:o};if(e===null)throw G(L,ze);let s=K(e,L),c=e;for(let e of s){let t=`${L}.${e}`;if(qe(e,t),Ue.has(e))throw G(t,`reserved variant name`);let s=q(c,e,t),l=K(s,t);if(l.length===0)throw G(t,`expected at least one choice`);let u=s,d=o[e],f;d===void 0?(d=a.length,o[e]=d,f=Object.create(null),O(a,{name:e,choices:f,booleanCapable:!1})):f=a[d].choices;for(let e of l){let a=`${t}.${e}`,o=q(u,e,a),s=f[e],c=s===void 0?X(i):Q(s.fragmentsBySlot,i);Qe(c,o,n,r,a,!1),f[e]={fragmentsBySlot:c}}a[d]={name:e,choices:f,booleanCapable:F.call(f,`true`)||F.call(f,`false`)}}return{variants:a,indexes:o}}function et(e,t,n,r){let i=X(n.length);if(t!==void 0){let e=Math.min(t.defaultStates.length,n.length);for(let n=0;n<e;n++)F.call(t.defaultStates,n)&&(i[n]=t.defaultStates[n])}if(e===void 0)return i;if(e===null)throw G(R,ze);let a=K(e,R),o=U(a);for(let e of a)if(r[e]===void 0)throw G(`${R}.${e}`,`unknown variant`);let s=e;for(let e=0;e<n.length;e++){let t=n[e];if(!W(a,o,t.name))continue;let r=`${R}.${t.name}`,c=q(s,t.name,r);c!==void 0&&(i[e]=$(c,t,r))}return i}function tt(e,t,n){if(!Array.isArray(e)){if(e===void 0)throw G(n,`undefined is not a condition`);return[$(e,t,n)]}let r=Ke(e,n,!1),i=[];for(let e=0;e<r.length;e++){let a=r[e];if(a===void 0)throw G(`${n}[${e}]`,`undefined is not a condition`);O(i,$(a,t,`${n}[${e}]`))}return i}function nt(e,t,n,r,i,a,o){let s=t===void 0?[]:t.compounds.map(e=>({conditions:e.conditions,fragmentsBySlot:Q(e.fragmentsBySlot,i)}));if(e===void 0)return s;if(e===null)throw G(z,ze);let c=Ke(e,z,!0);for(let e=0;e<c.length;e++){let t=c[e],l=`${z}[${e}]`,u=K(t,l),d=U(u),f=W(u,d,Re);if(!W(u,d,H))throw G(`${l}.className`,n||f?`required own enumerable string`:`required own enumerable class map`);for(let e of u)if(e!==H&&e!==Re&&o[e]===void 0)throw G(`${l}.${e}`,`unknown variant condition`);let p=t,m=[];for(let e=0;e<a.length;e++){let t=a[e];if(!W(u,d,t.name))continue;let n=`${l}.${t.name}`;O(m,{variantIndex:e,states:tt(q(p,t.name,n),t,n)})}let h=`${l}.className`,g=q(p,H,h),_=X(i);if(f){let e=`${l}.classKeys`;if(n)throw G(e,`only valid for multi-element recipes`);if(typeof g!=`string`)throw G(h,`expected a primitive string when classKeys is present`);let t=Ke(q(p,Re,e),e,!1),i=J(g);for(let n=0;n<t.length;n++){let a=t[n],o=`${e}[${n}]`;if(typeof a!=`string`)throw G(o,`expected a declared class name`);let s=r[a];if(s===void 0)throw G(o,`unknown class target`);if(t.indexOf(a)!==n)throw G(o,`duplicate class target ${JSON.stringify(a)}`);Y(_,s,i)}}else Qe(_,g,n,r,h,!0);O(s,{conditions:m,fragmentsBySlot:_})}return s}function rt(e,t){let n=K(e,`definition`);for(let e of n)if(!Ve.has(e))throw G(`definition.${e}`,`unknown field`);let r=e,i;if(n.includes(`extend`)){let e=q(r,`extend`,`definition.extend`);if(e!==void 0&&(typeof e!=`function`||(i=t.get(e))===void 0))throw G(`definition.extend`,`expected a recipe from this exact reciper`)}let a=n.includes(H);if(!a&&i===void 0)throw G(I,Be);let o=Ze(a?q(r,H,I):void 0,i,!a),s=o.baseFragments.length,c=o.names.length===0,l=$e(n.includes(`variants`)?q(r,`variants`,L):void 0,i,c,o.indexes,s),u=et(n.includes(`defaultVariants`)?q(r,`defaultVariants`,R):void 0,i,l.variants,l.indexes),d=nt(n.includes(`compoundVariants`)?q(r,`compoundVariants`,z):void 0,i,c,o.indexes,s,l.variants,l.indexes),f=X(s);for(let e of d)for(let t=0;t<s;t++)e.fragmentsBySlot[t]!==void 0&&O(f[t]??=[],e);return{slotNames:o.names,baseFragmentsBySlot:o.baseFragments,variants:l.variants,defaultStates:u,compounds:d,compoundsBySlot:f}}function it(e,t){if(e===void 0)return t.defaultStates;let n=We(e,V),r=U(n);if(W(n,r,`class`))throw G(`${V}.class`,`reserved field`);if(W(n,r,H))throw G(`${V}.className`,`caller classes belong to a style resolver`);let i=e,a;for(let e=0;e<t.variants.length;e++){let o=t.variants[e];if(!W(n,r,o.name))continue;let s=`${V}.${o.name}`,c=q(i,o.name,s);c!==void 0&&(a??=[...t.defaultStates],a[e]=$(c,o,s))}return a??t.defaultStates}function at(e,t,n){if(t!==void 0){let e=n<Ye||F.call(t,n)?t[n]:void 0;if(e!==void 0)return e}return e[n]}function ot(e,t,n){for(let r of e.conditions){let e=at(t,n,r.variantIndex),i=!1;for(let t of r.states)if(e===t){i=!0;break}if(!i)return!1}return!0}function st(e,t,n){if(n===void 0)return t;for(let r of n)Z(e,t,r),t++;return t}function ct(e,t,n,r,i,a,o){let s,c;if(r!==void 0){let t=We(r,a),n=U(t);if(W(t,n,`class`))throw G(`${a}.class`,`reserved field`);let i=r;for(let r=0;r<e.variants.length;r++){let o=e.variants[r];if(!W(t,n,o.name))continue;let c=`${a}.${o.name}`,l=q(i,o.name,c);l!==void 0&&(s??=Je(),Z(s,r,$(l,o,c)))}W(t,n,`className`)&&(c=q(i,`className`,`${a}.className`))}let l=Je(),u=st(l,0,e.baseFragmentsBySlot[t]);for(let r=0;r<e.variants.length;r++){let i=at(n,s,r);if(i==null)continue;let a=e.variants[r].choices[i];a!==void 0&&(u=st(l,u,a.fragmentsBySlot[t]))}let d=e.compoundsBySlot[t];if(d!==void 0)for(let e of d)ot(e,n,s)&&(u=st(l,u,e.fragmentsBySlot[t]));c!==void 0&&(Z(l,u,c),u++),l.length=u;let f=Reflect.apply(i,void 0,l);if(typeof f!=`string`)throw G(o,`merger must return a primitive string`);return f}function lt(e,t,n){Object.defineProperty(e,t,{value:n,configurable:!0,enumerable:!0,writable:!0})}function ut(e){let t={};for(let n of e.variants)lt(t,n.name,Object.freeze(Object.keys(n.choices)));let n={};for(let t=0;t<e.variants.length;t++){let r=e.defaultStates[t];typeof r==`string`&&lt(n,e.variants[t].name,r)}return Object.freeze({anatomy:Object.freeze([...e.slotNames]),variants:Object.freeze(t),defaultVariants:Object.freeze(n),compoundVariantCount:e.compounds.length})}function dt(e,t){return Object.defineProperty(e,"config",{value:ut(t),configurable:!1,enumerable:!1,writable:!1}),e}function ft(e,t){return e.slotNames.length===0?dt((n=>ct(e,0,e.defaultStates,n,t,V,`recipe result`)),e):dt((n=>{let r=it(n,e),i=Object.create(null);for(let n=0;n<e.slotNames.length;n++){let a=e.slotNames[n];i[a]=i=>ct(e,n,r,i,t,`style props.${a}`,`style result.${a}`)}return i}),e)}function pt(e){let t=K(e,B);for(let e of t)if(e!==`merge`)throw G(B,`unknown field ${JSON.stringify(e)}`);if(!t.includes(`merge`))throw G(Le,Be);let n=q(e,`merge`,Le);if(typeof n!=`function`)throw G(Le,`expected a callable merger`);let r=n,i=new WeakMap;return(e=>{let t=rt(e,i),n=ft(t,r);return i.set(n,t),n})}export{y as MERGE_OPAQUE,b as MergerProtocolError,Ie as createMerger,pt as createReciper,e as omitAttributes};
1
+ function e(e,t){let n={...e},r=new Set(t.map(e=>e.toLowerCase()));for(let e of Object.keys(n))r.has(e.toLowerCase())&&delete n[e];return n}function t(e,t){Object.defineProperty(e,e.length,{configurable:!0,enumerable:!0,value:t,writable:!0})}function n(e,t){let n=e.length;n in e?Object.defineProperty(e,n,{configurable:!0,enumerable:!0,value:t,writable:!0}):e[n]=t}function r(e){let t=[],r=[],i=new Map,a=!1,o,s;for(let c=0;c<e.length;c++){let l=e[c];if(r.length===0){l===`\\`?(/\s/.test(e[c+1]??``)&&(o=void 0),c++):/\s/.test(l)?o=void 0:l===`"`||l===`'`?o=o===l?void 0:o??l:!o&&l===`[`&&n(r,c);continue}if((s||a)&&l===`[`&&/[:@\s]/.test(e[c-1])){n(r,c),i.set(c,s??a),a=!1,s=void 0;continue}if(a){l===`*`&&e[c+1]===`/`&&(a=!1,c++);continue}if(s){l===`\\`?c++:l===s&&(s=void 0);continue}if(l===`/`&&e[c+1]===`*`)a=!0,c++;else if(l===`"`||l===`'`)s=l;else if(l===`\\`)c++;else if(l===`[`)n(r,c);else if(l===`]`){let o=r.pop(),l=i.get(o);(/[:@]/.test(e[o-1])||e[c+1]===`:`)&&n(t,{end:c+1,start:o}),l===!0?a=!0:l&&(s=l)}}let c=[];for(let e of t.sort((e,t)=>e.start-t.start||t.end-e.end))(!c.length||e.start>=c.at(-1).end)&&n(c,e);return c}function i(e){let t=``,r,i=-1,a=-1,o=-1,s=[];for(let c=0;c<e.length;c++){let l=e[c];if(r){l===`\\`?c++:l===r&&(r=void 0);continue}if((t.length>0||a!==-1)&&l===`\\`){c++;continue}if(t.length>0&&(l===`"`||l===`'`)){r=l;continue}if((t.length>0||a!==-1)&&l===`/`&&e[c+1]===`*`){let t=e.indexOf(`*/`,c+2);if(t<0)break;c=t+1;continue}l===`(`||l===`[`?t+=l===`(`?`)`:`]`:l===t.at(-1)?t=t.slice(0,-1):t.length===0&&(l===`@`?(a===-1&&(a=c),n(s,c)):a===-1&&(l===`:`&&i===-1?i=c:l===`!`&&(o=c)))}let c=a===-1?e.length:a,l=e.slice(0,c),u=!1;c>0&&o===c-1&&(u=!0,l=l.slice(0,-1));let d=[];for(let t=0;t<s.length;t++){let r=s[t]+1,i=t+1<s.length?s[t+1]:e.length;n(d,e.slice(r,i))}return i!==-1&&i<c?{raw:e,body:l,property:e.slice(0,i),value:l.slice(i+1),keyword:!1,important:u,conditions:d}:{raw:e,body:l,keyword:!0,important:u,conditions:d}}function a(e,n,r){let i=e[n];if(r.blockComment)return i===`*`&&e[n+1]===`/`?(r.blockComment=!1,n+1):n;if(r.quote)return i===`\\`?n+1:(i===r.quote&&(r.quote=void 0),n);if(r.closers.length>0&&i===`/`&&e[n+1]===`*`)return r.blockComment=!0,n+1;if(r.closers.length>0&&(i===`"`||i===`'`))return r.quote=i,n;if(i===`\\`)return n+1;if(i===`(`||i===`[`)return t(r.closers,i===`(`?`)`:`]`),n;if(i===r.closers.at(-1))return r.closers.pop(),n}function o(e,t,n=e.length){let r={closers:[]};for(let i=t+1;i<n;i++){let t=e[i],n=a(e,i,r);if(n!==void 0){i=n;continue}if(r.closers.length===0){if(t===`}`)return{index:i,kind:`close`};if(t===`{`)return{index:i,kind:`open`}}}return{index:n,kind:`limit`}}const s=/[\s'"`;{},\])]/;function c(e,t,n=e.length){if(e[t]!==`@`)return{conds:``,end:t};let r={closers:[]},i=t;for(;i<n;i++){let t=e[i],n=a(e,i,r);if(n!==void 0){i=n;continue}if(t===`/`&&(e[i+1]===`/`||e[i+1]===`*`)&&r.closers.length===0||s.test(t)&&r.closers.length===0)break}return{conds:e.slice(t,i),end:i}}function l(e,n=!1){let r=[],i={closers:[]},o=0;for(let s=0;s<e.length;s++){let c=e[s],l=a(e,s,i);if(l!==void 0){s=l;continue}(c===`;`||n&&/\s/.test(c))&&i.closers.length===0&&(t(r,e.slice(o,s)),o=s+1)}return t(r,e.slice(o)),r.map(e=>e.trim()).filter(Boolean)}const u=/^(?:--?[\w-]+|[A-Z_$][\w$-]*|@teacss-skip-bracket-[\da-z]{6})$/i;function d(e,t){let n=t;for(;n>0&&/[\w-]/.test(e[n-1]);)n--;if(n===t||e[n-1]!==`:`)return!1;let r=n-1,i=r;for(;i>0&&/[\w$@-]/.test(e[i-1]);)i--;if(!u.test(e.slice(i,r)))return!1;let a=i-1;for(;a>=0&&/\s/.test(e[a]);)a--;return a<0||!`{,?`.includes(e[a])}function f(e){let n=[],r=[],i=[],a=!1,o;for(let s=0;s<e.length;s++){let c=e[s],l=e[s+1];if(r.length===0){c===`(`&&d(e,s)&&t(r,{attached:!0,start:s});continue}if(a)c===`*`&&l===`/`&&(a=!1,s++);else if(o)c===`\\`?s++:c===o&&(o=void 0);else if(c===`\\`)s++;else if(c===`/`&&l===`*`)a=!0,s++;else if(c===`'`||c===`"`||c==="`")o=c;else if(i.length>0)c===`[`||c===`(`?t(i,c===`[`?`]`:`)`):c===i.at(-1)&&i.pop();else if(c===`[`)t(i,`]`);else if(c===`(`)t(r,{attached:d(e,s),start:s});else if(c===`)`){let e=r.pop();e.attached&&t(n,{end:s+1,start:e.start})}}let s=[];for(let e of n.sort((e,t)=>e.start-t.start||t.end-e.end))(s.length===0||e.start>=s.at(-1).end)&&t(s,e);return s}function p(e){let t={seen:!1},n=m(e,t);for(let e=1;e<5&&t.seen;e++){t.seen=!1;let e=m(n,t);if(e===n)break;n=e}return n}function m(e,t){if(!e.includes(`{`))return e;let n=``,i=0,s=-1,u=0,d=0,p=e.includes(`[`)?r(e):[],m=e.includes(`(`)?f(e):[],h={closers:[]};for(;i<e.length;){for(;u<p.length&&p[u].end<=i;)u++;for(;d<m.length&&m[d].end<=i;)d++;let r=u<p.length?p[u]:void 0,f=d<m.length?m[d]:void 0,g=r?.start===i?r:f?.start===i?f:void 0;if(g&&h.blockComment!==!0&&h.quote===void 0){n+=e.slice(i,g.end),i=g.end;continue}h.closers.length>0&&/\s/.test(e[i])&&(h.blockComment=!1,h.closers.length=0,h.quote=void 0);let _=a(e,i,h);if(_!==void 0){n+=e.slice(i,_+1),i=_+1;continue}let v=e[i];if(h.closers.length>0||v!==`{`){n+=v,i++;continue}let y=o(e,i);if(y.kind!==`close`){y.kind===`open`&&t&&(t.seen=!0),n+=e.slice(i,y.index),i=y.index;continue}let b=y.index,x=e.slice(i+1,b),{conds:S,end:C}=c(e,b+1),w=l(x,!0);if(w.length===0){n+=v,i++;continue}s===i&&n.length>0&&!/\s/.test(n.at(-1))&&(n+=` `),n+=w.map(e=>`${e}${S}`).join(` `),s=C,i=C}return n}function h(e){let t=e.split(/\s+/);return t[0]===``&&t.shift(),t.at(-1)===``&&t.pop(),t}function g(e){if(!e.includes(`[`))return h(e);let t=r(e);if(t.length===0)return h(e);let i=[],a=0,o=-1;for(let r=0;r<e.length;r++){let s=t[a];if(s&&r===s.start){o<0&&(o=r),r=s.end-1,a++;continue}/\s/.test(e[r])?(o>=0&&n(i,e.slice(o,r)),o=-1):o<0&&(o=r)}return o>=0&&n(i,e.slice(o)),i}const _=!1;var v=class extends TypeError{name=`MergerProtocolError`;code;plugin;hook;constructor(e,t,n,r){super(`[TeaCSS merge:${e}] ${t}`),this.code=e,n!==void 0&&(this.plugin=n),r!==void 0&&(this.hook=r)}};function y(){return Object.create(null)}const b=`must have an integer length from 0 through 4294967294`,x=Symbol(`missing-own-value`);function S(e,t){return`value`in t?t.value:t.get===void 0?void 0:Reflect.apply(t.get,e,[])}function C(e,t){let n=Reflect.getOwnPropertyDescriptor(e,t);return n===void 0?x:S(e,n)}function w(e,t){let n=C(e,t);return n===x?void 0:n}function ee(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0})}function T(e,t){let n=e.length;n in e?ee(e,n,t):e[n]=t}function E(e){let t=C(e,`length`);return typeof t==`number`&&Number.isInteger(t)&&t>=0&&t<4294967295?t:null}function D(e){let t=``,n=E(e);if(n===null)throw new v(`INVALID_ARRAY_LENGTH`,`class-value array ${b}`);for(let r=0;r<n;r++){let n=C(e,r);if(n===x)continue;let i=te(n);i&&(t+=(t&&` `)+i)}return t}function te(e){if(!e)return``;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`bigint`)return String(e);if(Array.isArray(e))return D(e);if(typeof e==`object`){let t=e,n=``;for(let e of Reflect.ownKeys(t)){if(typeof e!=`string`)continue;let r=Reflect.getOwnPropertyDescriptor(t,e);r!==void 0&&r.enumerable&&S(t,r)&&(n+=(n&&` `)+e)}return n}return``}function O(e,t){let n=e;for(let e of t){let t=n.children??(n.children=new Map),r=t.get(e);r===void 0&&(r=y(),t.set(e,r)),n=r}return n}function ne(e,t,n){let r=O(e,t);return n?r.keywords??=new Map:r.declarations??=new Map}function re(e){if(e.length===0)return``;if(e.length===1){let t=C(e,0);return t===x?``:t??``}let t=y(),n=new Uint8Array(e.length),r=new Uint8Array(e.length);for(let a=0;a<e.length;a++){let o=i(e[a]),s=ne(t,o.conditions,o.keyword),c=o.property??o.body,l=s.get(c);n[a]=+!!o.important,l===void 0?s.set(c,a):n[l]!==0&&n[a]===0?r[a]=1:(r[l]=1,s.set(c,a))}let a=[];for(let t=0;t<e.length;t++)r[t]===0&&T(a,e[t]);return a.join(` `)}function ie(e,t){if(typeof e==`string`)return e.length===0?null:[e];if(!Array.isArray(e))return null;let n=E(e);if(n===null||n===0)return null;let r=[],i=null;for(let a=0;a<n;a++){let n=C(e,a);if(n===x||typeof n!=`string`||n.length===0)return null;(i===null?r.includes(n):i.has(n))||(T(r,n),i===null?r.length===(t?64:4)&&(i=new Set(r)):i.add(n))}return t&&r.length>1&&r.sort(),r}function ae(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function k(e,t,n,r,i){for(let a of Reflect.ownKeys(t)){if(typeof a!=`string`)continue;let o=Reflect.getOwnPropertyDescriptor(t,a);if(o===void 0||!o.enumerable)continue;let s=ie(S(t,o),!0);if(s===null)throw new v(`INVALID_STATIC_CONFLICT`,`"${r}" ${n} "${a}" must contain at least one non-empty atom`,i);let c=e.get(a);if(c===void 0){e.set(a,{atoms:s,atomSet:s.length>4?new Set(s):null,source:r});continue}if(!ae(c.atoms,s))throw new v(`STATIC_CONFLICT_COLLISION`,`static ${n} "${a}" has conflicting atom sets from "${c.source}" and "${r}"`,i)}}function oe(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function A(e){if(!oe(e))return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function se(e,t,n){if(!oe(e))throw new v(`INVALID_CONFLICT_META`,`"${t}" conflicts must be an object`,n);let r=w(e,`keywords`);if(!A(r))throw new v(`INVALID_CONFLICT_META`,`"${t}" keywords must be a record`,n);let i=w(e,`overlaps`);if(!A(i))throw new v(`INVALID_CONFLICT_META`,`"${t}" overlaps must be a record`,n);return{keywords:r,overlaps:i}}function j(e,t,n,r){if(n!==void 0){if(typeof n!=`function`)throw new v(`INVALID_PLUGIN_HOOK`,`plugin "${e}" ${t} must be a function`,e,r);return n}}function ce(e){let t=[],n=[],r=[],i=[],a=[],o=new Set,s=E(e);if(s===null)throw new v(`INVALID_OPTIONS`,`options.plugins must be an array with an integer length from 0 through 4294967294`);for(let c=0;c<s;c++){let s=C(e,c),l=s===x?void 0:s;if(!oe(l))throw new v(`INVALID_PLUGIN_NAME`,`plugin at index ${c} must have a non-empty name`);let u=w(l,`name`);if(typeof u!=`string`||u.length===0)throw new v(`INVALID_PLUGIN_NAME`,`plugin at index ${c} must have a non-empty name`);if(o.has(u))throw new v(`DUPLICATE_PLUGIN_NAME`,`duplicate plugin name "${u}"`,u);o.add(u);let d=w(l,`conflicts`),f=j(u,`tokens`,w(l,`tokens`),`tokens`),p=j(u,`group`,w(l,`group`),`group`),m=j(u,`finalize`,w(l,`finalize`),`finalize`),h=j(u,`resolveFamily`,w(l,`resolveFamily`),`resolveFamily`),g=j(u,`resolve`,w(l,`resolve`),`resolve`);if(h!==void 0&&g===void 0)throw new v(`INVALID_PLUGIN_HOOK`,`plugin "${u}" resolveFamily requires resolve`,u,`resolveFamily`);T(t,{name:u,conflicts:d===void 0?void 0:se(d,u,u)}),f!==void 0&&T(n,{name:u,hook:f}),p!==void 0&&T(r,{name:u,hook:p}),m!==void 0&&T(i,{name:u,hook:m}),g!==void 0&&T(a,{name:u,hook:g,family:h})}return{metadata:t,tokens:n,groups:r,finalizers:i,resolvers:a,allResolversScoped:a.every(e=>e.family!==void 0)}}function le(e,t){let n=new Map,r=new Map;e!==void 0&&(k(n,e.keywords,`keyword`,`<options.conflicts>`),k(r,e.overlaps,`declaration`,`<options.conflicts>`));for(let e of t)e.conflicts!==void 0&&(k(n,e.conflicts.keywords,`keyword`,e.name,e.name),k(r,e.conflicts.overlaps,`declaration`,e.name,e.name));return{keywords:n,overlaps:r}}function ue(e){let t=i(e);return{raw:e,prefix:t.property??t.body,body:t.body,value:t.value,keyword:t.keyword,conditions:t.conditions,important:t.important}}function de(){let e=new Map;return t=>{let n=e.get(t);if(n!==void 0)return n;let r=ue(t);return e.set(t,r),r}}function fe(e,t,n){if(t.length===0)return e;let r=e,i={viewToken:n};for(let e of t){let t=e.hook,n=t(r,i),a=`plugin "${e.name}" tokens() must return an array of individual non-empty class tokens`;if(!Array.isArray(n))throw new v(`INVALID_TOKEN_TRANSFORM_RESULT`,a,e.name,`tokens`);let o=[],s=E(n);if(s===null)throw new v(`INVALID_TOKEN_TRANSFORM_RESULT`,a,e.name,`tokens`);for(let t=0;t<s;t++){let r=C(n,t);if(r===x||typeof r!=`string`||r.length===0)throw new v(`INVALID_TOKEN_TRANSFORM_RESULT`,a,e.name,`tokens`);let i=g(r);if(i.length!==1||i[0]!==r)throw new v(`INVALID_TOKEN_TRANSFORM_RESULT`,a,e.name,`tokens`);T(o,r)}r=o}return r}function pe(e,t){let n=null;for(let r=0;r<t.length;r++){let i=t[r];if(i.family===void 0)continue;let a=i.family,o=a(e);if(o!==null&&(typeof o!=`string`||o.length===0))throw new v(`INVALID_RESOLVE_FAMILY_RESULT`,`plugin "${i.name}" resolveFamily() must return null or a non-empty string`,i.name,`resolveFamily`);o!==null&&((n??=Array.from({length:t.length},()=>null))[r]=o)}return n}function me(e,t,n,r,i,a){let o=a(e);for(let e of n){let n=e.hook,i=n(o);if(i===null)continue;if(i===!1)return{id:t,view:o,atoms:[],atomSet:null,pluginGrouped:!0,opaque:!0,resolverFamilies:null};let a=ie(i,!1);if(a===null)throw new v(`INVALID_GROUP_RESULT`,`plugin "${e.name}" group() must return null, MERGE_OPAQUE, or at least one non-empty atom`,e.name,`group`);return{id:t,view:o,atoms:a,atomSet:a.length>4?new Set(a):null,pluginGrouped:!0,opaque:!1,resolverFamilies:pe(o,r)}}let s=o.keyword?i.keywords.get(o.prefix):i.overlaps.get(o.prefix);return{id:t,view:o,atoms:s===void 0?[o.keyword?`@teacss/classes:keyword:${o.prefix}`:`@teacss/classes:declaration:${o.prefix}`]:s.atoms,atomSet:s===void 0?null:s.atomSet,opaque:!1,resolverFamilies:pe(o,r)}}function he(e,t){let n=new Map;for(let r of e){if(!r.opaque)continue;let e=n.get(r.view.raw);e!==void 0&&(t[e]=1),n.set(r.view.raw,r.id)}}function M(e,t){return new v(`INVALID_FINALIZER_RESULT`,`plugin "${e}" finalize() returned invalid occurrence id ${typeof t==`bigint`?`${t}n`:typeof t==`number`||typeof t==`boolean`||t==null?String(t):typeof t}`,e,`finalize`)}function ge(e,t){let n=[];for(let r of e)!r.opaque&&t[r.id]===0&&T(n,r);return n}function _e(e,t,n,r){let i=!1,a=r;for(let r of t){let t=r.hook,o=t(a?ge(e,n):e.slice());if(o===null)continue;if(!Array.isArray(o))throw M(r.name,o);let s=E(o);if(s===null)throw new v(`INVALID_FINALIZER_RESULT`,`plugin "${r.name}" finalize() result ${b}`,r.name,`finalize`);if(s===0)continue;let c=new Set;for(let t=0;t<s;t++){let i=C(o,t);if(i===x)throw M(r.name,void 0);let a=i;if(!Number.isInteger(a))throw M(r.name,a);let s=a,l=e[s];if(l===void 0||l.opaque||n[s]!==0||c.has(s))throw M(r.name,a);c.add(s)}for(let e of c)n[e]=1;c.size!==0&&(i=!0,a=!0)}return i}function ve(e,t){return e.atomSet?.has(t)??e.atoms.includes(t)}function ye(e,t){return e.pluginGrouped!==!0&&t.pluginGrouped!==!0&&e.view.keyword===t.view.keyword&&e.view.prefix===t.view.prefix}function be(e,t){if(ye(e,t))return!0;if(e.atoms.length<t.atoms.length)return!1;for(let n of t.atoms)if(!ve(e,n))return!1;return!0}function xe(e,t){if(e.atomSet!==null){for(let n of t.atoms)if(e.atomSet.has(n))return!0;return!1}if(t.atomSet!==null){for(let n of e.atoms)if(t.atomSet.has(n))return!0;return!1}for(let n of t.atoms)if(e.atoms.includes(n))return!0;return!1}function Se(e,t){let n=O(e,t);return n.winners??=new Map}function Ce(e,t,n){let r=y();for(let i of e){if(i.opaque||t[i.id]!==0)continue;let a=n?ne(r,i.view.conditions,i.view.keyword):Se(r,i.view.conditions),o=n?i.view.prefix:i.atoms[0],s=a.get(o);if(s===void 0){a.set(o,i.id);continue}e[s].view.important&&!i.view.important?t[i.id]=1:(t[s]=1,a.set(o,i.id))}}function we(e,t,n,r,i){return e.view.important===t.view.important?n||i===`symmetric`?`earlier`:`none`:t.view.important?n?`earlier`:`none`:r?`later`:`none`}function Te(e,t,n,r){let i=be(t,e),a=be(e,t),o=we(e,t,i,a,n);for(let n=0;n<r.length;n++){let s=r[n];if(s.family!==void 0){let r=e.resolverFamilies?.[n]??null,i=t.resolverFamilies?.[n]??null;if(r===null||r!==i)continue}let c=s.hook,l=c(e.view,t.view,{covers:i,earlierCoversLater:a,defaultDrop:o});if(l!==null){if(l===`earlier`||l===`later`||l===`none`)return l;throw new v(`INVALID_RESOLVE_RESULT`,`plugin "${s.name}" resolve() must return null, "earlier", "later", or "none"`,s.name,`resolve`)}}return o}function N(e,t,n,r,i){let a=Te(e,t,n,r);a===`earlier`?i[e.id]=1:a===`later`&&(i[t.id]=1)}function Ee(e,t,n,r,i){let a=t[e];for(let o=e+1;o<t.length;o++){let e=t[o];ae(a.view.conditions,e.view.conditions)&&(ye(a,e)||xe(a,e))&&N(a,e,n,r,i)}}function De(e,t){let n=O(e,t);return n.postings??=new Map}function Oe(e){let t=y(),n=[],r=[],i=e.length*(e.length-1)/2,a=0;for(let o=0;o<e.length;o++){let s=e[o],c=De(t,s.view.conditions),l=[];T(n,c),T(r,l);for(let e of s.atoms){let t=c.get(e);if(t===void 0&&(t=[],c.set(e,t)),a+=t.length,a>i)return null;T(l,t.length),T(t,o)}}return{postingMaps:n,positions:r,postingPairVisits:a}}function ke(e,t,n,r){for(let i=0;i<e.length;i++)Ee(i,e,t,n,r)}function Ae(e,t,n,r,i,a){if(a!==null){Ce(e,r,a===`static-prefix`);return}let o=i?ge(e,r):e;if(o.length<16){ke(o,t,n,r);return}let s=Oe(o);if(s===null){ke(o,t,n,r);return}if(s.postingPairVisits===0)return;let c=new Uint32Array(o.length),l=[];for(let e=0;e<o.length;e++){let i=o[e],a=s.postingMaps[e],u=s.positions[e];if(i.atoms.length===1){let e=a.get(i.atoms[0]);for(let a=u[0]+1;a<e.length;a++)N(i,o[e[a]],t,n,r);continue}let d=0;for(let e=0;e<i.atoms.length;e++){let t=a.get(i.atoms[e]);d+=t.length-u[e]-1}if(d>=o.length-e-1){Ee(e,o,t,n,r);continue}l.length=0;let f=!0,p=e+1;for(let e=0;e<i.atoms.length;e++){let t=a.get(i.atoms[e]);for(let n=u[e]+1;n<t.length;n++){let e=t[n];c[e]!==p&&(c[e]=p,l.length!==0&&e<l[l.length-1]&&(f=!1),T(l,e))}}f||l.sort((e,t)=>e-t);for(let e of l)N(i,o[e],t,n,r)}}function je(e,t,n,r,i){let a=fe(e,r.tokens,i);if(a.length<2&&r.groups.length===0&&r.finalizers.length===0&&r.resolvers.length===0){if(a.length===0)return``;let e=C(a,0);return e===x?``:e??``}let o=[],s=!1,c=a.length>=16&&r.allResolversScoped,l=c,u=c,d,f,p=0;for(let e=0;e<a.length;e++){let n=me(a[e],e,r.groups,r.resolvers,t,i);if(n.opaque)s=!0;else if(p++,n.atoms.length!==1&&(l=!1),n.pluginGrouped===!0?u=!1:d===void 0?(d=n.view.prefix,f=n.view.keyword):(n.view.prefix!==d||n.view.keyword!==f)&&(u=!1),n.resolverFamilies!==null){for(let e of n.resolverFamilies)if(e!==null){l=!1,u=!1;break}}T(o,n)}let m=new Uint8Array(o.length);s&&he(o,m);let h=_e(o,r.finalizers,m,s),g=p<16?null:l?`singleton`:u?`static-prefix`:null;Ae(o,n,r.resolvers,m,s||h,g);let _=[];for(let e of o)m[e.id]===0&&T(_,e.view.raw);return _.join(` `)}function Me(e,t,n){let r=C(e,n);if(r===x)return``;if(typeof r==`string`)return r;if(Array.isArray(t)){let e=C(t,n);if(typeof e==`string`)return e}return``}function Ne(e){return typeof e==`number`||typeof e==`bigint`?String(e):te(e)}function Pe(e,t,n){let r=``,i=E(e);if(i===null)throw new v(`INVALID_ARRAY_LENGTH`,`tagged-template strings ${b}`);for(let a=0;a<i;a++)if(r+=Me(e,t,a),a+1<i&&a+1<n.length){let e=Ne(n[a+1]);r+=e}return r}function Fe(e={}){if(!A(e))throw new v(`INVALID_OPTIONS`,`options must be an object`);let t=w(e,`conflicts`),n=w(e,`overlap`),r=w(e,`plugins`),i=w(e,`cache`);if(n!==void 0&&n!==`precise`&&n!==`symmetric`)throw new v(`INVALID_OPTIONS`,`options.overlap must be "precise" or "symmetric"`);if(r!==void 0&&!Array.isArray(r))throw new v(`INVALID_OPTIONS`,`options.plugins must be an array`);let a=ce(r===void 0?[]:r),o=le(t===void 0?void 0:se(t,`<options.conflicts>`),a.metadata),s=a.tokens.length!==0||a.groups.length!==0||a.finalizers.length!==0||a.resolvers.length!==0,c=!s&&o.keywords.size===0&&o.overlaps.size===0,l=n??`precise`,u=1500;if(i===!1)u=0;else if(i!==void 0){if(!A(i))throw new v(`INVALID_CACHE_OPTIONS`,`options.cache must be false or an object`);let e=w(i,`max`);if(e!==void 0){if(typeof e!=`number`||!Number.isFinite(e)||!Number.isInteger(e)||e<0)throw new v(`INVALID_CACHE_OPTIONS`,`options.cache.max must be a finite non-negative integer`);u=e}}let d=u>0?new Map:null;function f(e){if(d!==null){let t=d.get(e);if(t!==void 0)return d.delete(e),d.set(e,t),t}let t=g(p(e).trim()),n=c?re(t):je(t,o,l,a,s?de():ue);return d!==null&&(d.set(e,n),d.size>u&&d.delete(d.keys().next().value)),n}function m(...e){let t=e[0],n=Array.isArray(t)?C(t,`raw`):x;return f(Array.isArray(n)?Pe(t,n,e):D(e))}return m}const P=Object.prototype.propertyIsEnumerable,F=`definition.className`,I=`definition.variants`,L=`definition.defaultVariants`,R=`definition.compoundVariants`,z=`createReciper options`,B=`${z}.merge`,V=`recipe props`,H=`className`,Ie=`classKeys`,Le=`null is not allowed`,Re=`required own enumerable field`,ze=new Set([`className`,`variants`,`defaultVariants`,`compoundVariants`,`extend`]),Be=new Set([`class`,`className`,`then`,`toJSON`,`toString`,`valueOf`]),Ve=new Set([`class`,`className`,`classKeys`]);function U(e){return e.length>16?new Set(e):void 0}function W(e,t,n){return t?.has(n)??e.includes(n)}function G(e,t){return TypeError(`[TeaCSS recipe] ${e}: ${t}`)}function K(e,t){if(typeof e!=`object`||!e||Array.isArray(e))throw G(t,`expected a plain record`);let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==null)throw G(t,`expected Object.prototype or null prototype`);return Object.keys(e)}function He(e,t){if(typeof e!=`object`||!e||Array.isArray(e))throw G(t,`expected a non-null, non-array object`);return Object.keys(e)}function q(e,t,n){let r=Reflect.getOwnPropertyDescriptor(e,t);if(r===void 0||!r.enumerable)throw G(n,`expected an own enumerable field`);return`value`in r?r.value:r.get===void 0?void 0:Reflect.apply(r.get,e,[])}function Ue(e,t){let n=Reflect.getOwnPropertyDescriptor(e,`length`),r=n!==void 0&&`value`in n?n.value:void 0;if(typeof r!=`number`||!Number.isInteger(r)||r<0||r>=4294967295)throw G(t,`expected an array with a valid own length`);return r}function We(e,t,n){if(!Array.isArray(e))throw G(t,`expected an array`);let r=Object.keys(e),i=Ue(e,t);if(!n&&i===0)throw G(t,`expected a non-empty array`);if(r.length!==i)throw G(t,`expected a dense own-indexed array`);for(let e of r){let n=Number(e);if(!Number.isInteger(n)||n<0||n>=i||String(n)!==e)throw G(t,`expected a dense own-indexed array`)}let a=X(i);for(let n=0;n<i;n++)a[n]=q(e,n,`${t}[${n}]`);return a}function Ge(e,t){if(e.trim().length===0)throw G(t,`name must contain a non-whitespace character`)}function J(e){let t=D([e]);return t.length===0?void 0:t}function Y(e,t,n){if(n===void 0)return;let r=P.call(e,t)?e[t]:void 0;e[t]=r===void 0?[n]:[...r,n]}function X(e){let t=Array(e);for(let n=0;n<e;n++)n in t?ee(t,n,void 0):t[n]=void 0;return t}function Ke(){return[void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0]}const qe=Ke().length;function Je(e,t,n){t<qe||!(t in e)?e[t]=n:ee(e,t,n)}function Z(e,t=e.length){let n=X(t),r=Math.min(e.length,t);for(let t=0;t<r;t++){if(!P.call(e,t))continue;let r=e[t];r!==void 0&&(n[t]=[...r])}return n}function Ye(e,t){return e.map(e=>{let n=Object.create(null);for(let r of Object.keys(e.choices))n[r]={fragmentsBySlot:Z(e.choices[r].fragmentsBySlot,t)};return{name:e.name,choices:n,booleanCapable:e.booleanCapable}})}function Q(e,t,n){if(e===null)return null;if(typeof e==`string`){if(!P.call(t.choices,e))throw G(n,`unknown choice ${JSON.stringify(e)}`);return e}if(typeof e==`number`){if(!Number.isFinite(e))throw G(n,`expected a finite numeric choice`);let r=String(e);if(!P.call(t.choices,r))throw G(n,`unknown choice ${JSON.stringify(r)}`);return r}if(typeof e==`boolean`){if(!t.booleanCapable)throw G(n,`boolean selection requires a true or false choice`);return String(e)}throw G(n,`expected null, a declared string or finite numeric choice, or a supported boolean state`)}function Xe(e,t,n){if(n&&(e=t.slotNames.length===0?``:{}),typeof e==`string`){if(t!==void 0&&t.slotNames.length>0)throw G(F,`must be a record when extending a multi-element recipe`);let n=t===void 0?X(1):Z(t.baseFragmentsBySlot,1);return Y(n,0,J(e)),{names:[],indexes:Object.create(null),baseFragments:n}}let r=K(e,F);if(t!==void 0&&t.slotNames.length===0)throw G(F,`must be a string when extending a single-element recipe`);if(!n&&r.length===0)throw G(F,`expected at least one named class`);for(let e of r){let t=`${F}.${e}`;if(Ge(e,t),Be.has(e))throw G(t,`reserved class name`)}let i=t===void 0?[]:[...t.slotNames],a=Object.create(null);for(let e=0;e<i.length;e++)a[i[e]]=e;let o=t===void 0?[]:Z(t.baseFragmentsBySlot),s=e;for(let e of r){let t=a[e];t===void 0&&(t=i.length,T(i,e),a[e]=t,T(o,void 0)),Y(o,t,J(q(s,e,`${F}.${e}`)))}return{names:i,indexes:a,baseFragments:o}}function Ze(e,t,n,r,i,a){if(n){if(typeof t!=`string`)throw G(i,`expected a primitive string`);Y(e,0,J(t));return}let o=K(t,i);if(a&&o.length===0)throw G(i,`expected at least one class target`);let s=t;for(let t of o){let n=r[t];if(n===void 0)throw G(`${i}.${t}`,`unknown class target`);Y(e,n,J(q(s,t,`${i}.${t}`)))}}function Qe(e,t,n,r,i){let a=t===void 0?[]:Ye(t.variants,i),o=Object.create(null);for(let e=0;e<a.length;e++)o[a[e].name]=e;if(e===void 0)return{variants:a,indexes:o};if(e===null)throw G(I,Le);let s=K(e,I),c=e;for(let e of s){let t=`${I}.${e}`;if(Ge(e,t),Ve.has(e))throw G(t,`reserved variant name`);let s=q(c,e,t),l=K(s,t);if(l.length===0)throw G(t,`expected at least one choice`);let u=s,d=o[e],f;d===void 0?(d=a.length,o[e]=d,f=Object.create(null),T(a,{name:e,choices:f,booleanCapable:!1})):f=a[d].choices;for(let e of l){let a=`${t}.${e}`,o=q(u,e,a),s=f[e],c=s===void 0?X(i):Z(s.fragmentsBySlot,i);Ze(c,o,n,r,a,!1),f[e]={fragmentsBySlot:c}}a[d]={name:e,choices:f,booleanCapable:P.call(f,`true`)||P.call(f,`false`)}}return{variants:a,indexes:o}}function $e(e,t,n,r){let i=X(n.length);if(t!==void 0){let e=Math.min(t.defaultStates.length,n.length);for(let n=0;n<e;n++)P.call(t.defaultStates,n)&&(i[n]=t.defaultStates[n])}if(e===void 0)return i;if(e===null)throw G(L,Le);let a=K(e,L),o=U(a);for(let e of a)if(r[e]===void 0)throw G(`${L}.${e}`,`unknown variant`);let s=e;for(let e=0;e<n.length;e++){let t=n[e];if(!W(a,o,t.name))continue;let r=`${L}.${t.name}`,c=q(s,t.name,r);c!==void 0&&(i[e]=Q(c,t,r))}return i}function et(e,t,n){if(!Array.isArray(e)){if(e===void 0)throw G(n,`undefined is not a condition`);return[Q(e,t,n)]}let r=We(e,n,!1),i=[];for(let e=0;e<r.length;e++){let a=r[e];if(a===void 0)throw G(`${n}[${e}]`,`undefined is not a condition`);T(i,Q(a,t,`${n}[${e}]`))}return i}function tt(e,t,n,r,i,a,o){let s=t===void 0?[]:t.compounds.map(e=>({conditions:e.conditions,fragmentsBySlot:Z(e.fragmentsBySlot,i)}));if(e===void 0)return s;if(e===null)throw G(R,Le);let c=We(e,R,!0);for(let e=0;e<c.length;e++){let t=c[e],l=`${R}[${e}]`,u=K(t,l),d=U(u),f=W(u,d,Ie);if(!W(u,d,H))throw G(`${l}.className`,n||f?`required own enumerable string`:`required own enumerable class map`);for(let e of u)if(e!==H&&e!==Ie&&o[e]===void 0)throw G(`${l}.${e}`,`unknown variant condition`);let p=t,m=[];for(let e=0;e<a.length;e++){let t=a[e];if(!W(u,d,t.name))continue;let n=`${l}.${t.name}`;T(m,{variantIndex:e,states:et(q(p,t.name,n),t,n)})}let h=`${l}.className`,g=q(p,H,h),_=X(i);if(f){let e=`${l}.classKeys`;if(n)throw G(e,`only valid for multi-element recipes`);if(typeof g!=`string`)throw G(h,`expected a primitive string when classKeys is present`);let t=We(q(p,Ie,e),e,!1),i=J(g);for(let n=0;n<t.length;n++){let a=t[n],o=`${e}[${n}]`;if(typeof a!=`string`)throw G(o,`expected a declared class name`);let s=r[a];if(s===void 0)throw G(o,`unknown class target`);if(t.indexOf(a)!==n)throw G(o,`duplicate class target ${JSON.stringify(a)}`);Y(_,s,i)}}else Ze(_,g,n,r,h,!0);T(s,{conditions:m,fragmentsBySlot:_})}return s}function nt(e,t){let n=K(e,`definition`);for(let e of n)if(!ze.has(e))throw G(`definition.${e}`,`unknown field`);let r=e,i;if(n.includes(`extend`)){let e=q(r,`extend`,`definition.extend`);if(e!==void 0&&(typeof e!=`function`||(i=t.get(e))===void 0))throw G(`definition.extend`,`expected a recipe from this exact reciper`)}let a=n.includes(H);if(!a&&i===void 0)throw G(F,Re);let o=Xe(a?q(r,H,F):void 0,i,!a),s=o.baseFragments.length,c=o.names.length===0,l=Qe(n.includes(`variants`)?q(r,`variants`,I):void 0,i,c,o.indexes,s),u=$e(n.includes(`defaultVariants`)?q(r,`defaultVariants`,L):void 0,i,l.variants,l.indexes),d=tt(n.includes(`compoundVariants`)?q(r,`compoundVariants`,R):void 0,i,c,o.indexes,s,l.variants,l.indexes),f=X(s);for(let e of d)for(let t=0;t<s;t++)e.fragmentsBySlot[t]!==void 0&&T(f[t]??=[],e);return{slotNames:o.names,baseFragmentsBySlot:o.baseFragments,variants:l.variants,defaultStates:u,compounds:d,compoundsBySlot:f}}function rt(e,t){if(e===void 0)return t.defaultStates;let n=He(e,V),r=U(n);if(W(n,r,`class`))throw G(`${V}.class`,`reserved field`);if(W(n,r,H))throw G(`${V}.className`,`caller classes belong to a style resolver`);let i=e,a;for(let e=0;e<t.variants.length;e++){let o=t.variants[e];if(!W(n,r,o.name))continue;let s=`${V}.${o.name}`,c=q(i,o.name,s);c!==void 0&&(a??=[...t.defaultStates],a[e]=Q(c,o,s))}return a??t.defaultStates}function it(e,t,n){if(t!==void 0){let e=n<qe||P.call(t,n)?t[n]:void 0;if(e!==void 0)return e}return e[n]}function at(e,t,n){for(let r of e.conditions){let e=it(t,n,r.variantIndex),i=!1;for(let t of r.states)if(e===t){i=!0;break}if(!i)return!1}return!0}function $(e,t,n){if(n===void 0)return t;for(let r of n)Je(e,t,r),t++;return t}function ot(e,t,n,r,i,a,o){let s,c;if(r!==void 0){let t=He(r,a),n=U(t);if(W(t,n,`class`))throw G(`${a}.class`,`reserved field`);let i=r;for(let r=0;r<e.variants.length;r++){let o=e.variants[r];if(!W(t,n,o.name))continue;let c=`${a}.${o.name}`,l=q(i,o.name,c);l!==void 0&&(s??=Ke(),Je(s,r,Q(l,o,c)))}W(t,n,`className`)&&(c=q(i,`className`,`${a}.className`))}let l=Ke(),u=$(l,0,e.baseFragmentsBySlot[t]);for(let r=0;r<e.variants.length;r++){let i=it(n,s,r);if(i==null)continue;let a=e.variants[r].choices[i];a!==void 0&&(u=$(l,u,a.fragmentsBySlot[t]))}let d=e.compoundsBySlot[t];if(d!==void 0)for(let e of d)at(e,n,s)&&(u=$(l,u,e.fragmentsBySlot[t]));c!==void 0&&(Je(l,u,c),u++),l.length=u;let f=Reflect.apply(i,void 0,l);if(typeof f!=`string`)throw G(o,`merger must return a primitive string`);return f}function st(e,t,n){Object.defineProperty(e,t,{value:n,configurable:!0,enumerable:!0,writable:!0})}function ct(e){let t={};for(let n of e.variants)st(t,n.name,Object.freeze(Object.keys(n.choices)));let n={};for(let t=0;t<e.variants.length;t++){let r=e.defaultStates[t];typeof r==`string`&&st(n,e.variants[t].name,r)}return Object.freeze({anatomy:Object.freeze([...e.slotNames]),variants:Object.freeze(t),defaultVariants:Object.freeze(n),compoundVariantCount:e.compounds.length})}function lt(e,t){return Object.defineProperty(e,"config",{value:ct(t),configurable:!1,enumerable:!1,writable:!1}),e}function ut(e,t){return e.slotNames.length===0?lt((n=>ot(e,0,e.defaultStates,n,t,V,`recipe result`)),e):lt((n=>{let r=rt(n,e),i=Object.create(null);for(let n=0;n<e.slotNames.length;n++){let a=e.slotNames[n];i[a]=i=>ot(e,n,r,i,t,`style props.${a}`,`style result.${a}`)}return i}),e)}function dt(e){let t=K(e,z);for(let e of t)if(e!==`merge`)throw G(z,`unknown field ${JSON.stringify(e)}`);if(!t.includes(`merge`))throw G(B,Re);let n=q(e,`merge`,B);if(typeof n!=`function`)throw G(B,`expected a callable merger`);let r=n,i=new WeakMap;return(e=>{let t=nt(e,i),n=ut(t,r);return i.set(n,t),n})}export{_ as MERGE_OPAQUE,v as MergerProtocolError,Fe as createMerger,dt as createReciper,e as omitAttributes};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teacss/classes",
3
- "version": "0.4.7",
3
+ "version": "0.5.1",
4
4
  "description": "TeaCSS class composition — typed recipes, nested class-value joining, and semantic conflict resolution.",
5
5
  "homepage": "https://css.teasim.com",
6
6
  "funding": "https://github.com/sponsors/billgo",
@@ -22,7 +22,7 @@
22
22
  "dev": "tsdown --watch"
23
23
  },
24
24
  "devDependencies": {
25
- "@teacss/core": "0.4.7"
25
+ "@teacss/core": "0.5.1"
26
26
  },
27
27
  "engines": {
28
28
  "node": ">=22.12.0"