rainbowindex 0.6.0 → 0.7.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/CHANGELOG.md +543 -0
- package/LICENSE +16 -17
- package/NOTICE.md +106 -0
- package/README.md +219 -65
- package/dist/browser.d.ts +4 -2
- package/dist/browser.mjs +12 -4
- package/dist/chunk-2T7V5XLK.mjs +912 -0
- package/dist/chunk-6OORICWF.mjs +16 -0
- package/dist/{chunk-KSNYSR3C.mjs → chunk-FJOZJIKB.mjs} +2499 -329
- package/dist/chunk-L56IRO7A.mjs +491 -0
- package/dist/chunk-PZDVDEZJ.mjs +196 -0
- package/dist/{chunk-3LWJTLOJ.mjs → chunk-RC6DDE4L.mjs} +23 -15
- package/dist/chunk-TQJYVQPE.mjs +217 -0
- package/dist/chunk-W756NVYI.mjs +33 -0
- package/dist/chunk-WBESS2ZD.mjs +598 -0
- package/dist/{chunk-3HRMFZGE.mjs → chunk-X66Z2YHT.mjs} +2 -1
- package/dist/{chunk-6U4IOFOS.mjs → chunk-XQGSG2HK.mjs} +199 -555
- package/dist/cli.mjs +1077 -123
- package/dist/{index-DSgpB6bS.d.ts → context-DcBtnnan.d.ts} +47 -103
- package/dist/editor.d.ts +71 -433
- package/dist/editor.mjs +51 -368
- package/dist/eslint.d.ts +16 -0
- package/dist/eslint.mjs +32 -0
- package/dist/{index-4Kyaq3IZ.d.ts → imports-C9esHd5Q.d.ts} +78 -84
- package/dist/index-CNqdL5U0.d.ts +56 -0
- package/dist/index-Czx-EUwh.d.ts +138 -0
- package/dist/index-DW8YSxTz.d.ts +104 -0
- package/dist/index.d.ts +46 -5
- package/dist/index.mjs +33 -9
- package/dist/oxlint.d.ts +21 -3
- package/dist/oxlint.mjs +19 -1
- package/dist/recipe.d.ts +111 -0
- package/dist/recipe.mjs +71 -0
- package/dist/safelist-CH3_PywB.d.ts +43 -0
- package/dist/session-CMaskdB7.d.ts +543 -0
- package/dist/tailwind.css +644 -0
- package/dist/theme-CIZiGlce.d.ts +115 -0
- package/dist/vite.d.ts +10 -1
- package/dist/vite.mjs +266 -118
- package/package.json +27 -5
- package/dist/chunk-WK6S4HTC.mjs +0 -1921
- package/dist/chunk-ZR7XJMUN.mjs +0 -251
- package/dist/safelist-CGCtF-Fr.d.ts +0 -96
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
import { R as ResolvedTheme, I as ImportResolver } from './imports-C9esHd5Q.js';
|
|
2
|
+
import { a as CompilationSnapshot } from './context-DcBtnnan.js';
|
|
3
|
+
import { C as ColorDefinition } from './index-Czx-EUwh.js';
|
|
4
|
+
|
|
5
|
+
/** Where a candidate was found. "expression" marks a string literal sitting
|
|
6
|
+
* in a JS expression position that cannot be a class list — today, an
|
|
7
|
+
* operand of `==`/`!=` (`mode === "default"`). It is NOT a certain origin:
|
|
8
|
+
* editors should treat it like "plain" and never report it as a bad class. */
|
|
9
|
+
type CandidateOrigin = "attribute" | "helper" | "safelist" | "plain" | "expression";
|
|
10
|
+
interface ClassCandidate {
|
|
11
|
+
/** The class string in expanded form — for variant-group members this
|
|
12
|
+
* includes the group prefix (`hover:bg-red-500`) even though the span
|
|
13
|
+
* covers only the member token inside the braces. */
|
|
14
|
+
value: string;
|
|
15
|
+
/** Absolute [start, end) span of the visible token in the original source.
|
|
16
|
+
* `source.slice(start, end)` is the member token for group members and
|
|
17
|
+
* `value` itself everywhere else. */
|
|
18
|
+
start: number;
|
|
19
|
+
end: number;
|
|
20
|
+
origin: CandidateOrigin;
|
|
21
|
+
/** The call the class was found in, when origin is "helper"/"safelist". */
|
|
22
|
+
helperName?: string;
|
|
23
|
+
/** Identity of the innermost scanned helper/safelist call context:
|
|
24
|
+
* candidates from the same call share one id, distinct calls get distinct
|
|
25
|
+
* ids. A class helper nested inside another class helper's arguments is
|
|
26
|
+
* not scanned as its own call — its literals belong to the outer call —
|
|
27
|
+
* while a class helper inside a cva/tv config does get its own id. Ids
|
|
28
|
+
* are only comparable within one extraction's result. Absent for
|
|
29
|
+
* attribute/plain candidates. */
|
|
30
|
+
callId?: number;
|
|
31
|
+
/** For variant-group members: span of the group's variant prefix (`hover:`). */
|
|
32
|
+
groupPrefix?: {
|
|
33
|
+
start: number;
|
|
34
|
+
end: number;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Structured diagnostics — the typed view of the `[RI-NNNN] message` warning
|
|
40
|
+
* strings, for editor tooling that anchors problems to source spans.
|
|
41
|
+
*
|
|
42
|
+
* The legacy string arrays stay the wire format everywhere (and the warning
|
|
43
|
+
* budget/dedup in warnings.ts keeps operating on them); a Diagnostic carries
|
|
44
|
+
* the same full message text verbatim, plus the parsed code, a severity
|
|
45
|
+
* derived from the documented code-range convention, and — when the emission
|
|
46
|
+
* site knew one — a [start, end) span into the CSS input. Consumers can rely
|
|
47
|
+
* on `diagnostics[i].message === warnings[i]` wherever both are returned.
|
|
48
|
+
*/
|
|
49
|
+
type DiagnosticSeverity = "error" | "warning";
|
|
50
|
+
interface Diagnostic {
|
|
51
|
+
/** The RI-NNNN code, or null when the message carries no parseable code. */
|
|
52
|
+
code: string | null;
|
|
53
|
+
severity: DiagnosticSeverity;
|
|
54
|
+
/** The full legacy warning text, including the `[RI-NNNN]` prefix. */
|
|
55
|
+
message: string;
|
|
56
|
+
/** [start, end) span in the analyzed CSS input, or null when unknown. */
|
|
57
|
+
start: number | null;
|
|
58
|
+
end: number | null;
|
|
59
|
+
}
|
|
60
|
+
/** Extract the RI-NNNN code from a legacy warning string, or null. */
|
|
61
|
+
declare function warningCode(message: string): string | null;
|
|
62
|
+
/**
|
|
63
|
+
* Severity by code range — the same convention warnings.ts budgets by:
|
|
64
|
+
* RI-0xxx (fatal/bootstrap) and RI-2xxx (compile/runtime errors) are errors,
|
|
65
|
+
* everything else (informational 1xxx ranges) is a warning.
|
|
66
|
+
*/
|
|
67
|
+
declare function severityForCode(code: string | null): DiagnosticSeverity;
|
|
68
|
+
/** Wrap a legacy warning string as a Diagnostic, with an optional span. */
|
|
69
|
+
declare function diagnosticFromWarning(message: string, span?: readonly [number, number] | null): Diagnostic;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Parses utility class strings into structured tokens.
|
|
73
|
+
*
|
|
74
|
+
* "hover:bg-red-500" → { variants: ["hover"], utility: "bg", value: "red-500" }
|
|
75
|
+
* "sm:p-4" → { variants: ["sm"], utility: "p", value: "4" }
|
|
76
|
+
* "text-center!" → { variants: [], utility: "text-center", value: null, important: true }
|
|
77
|
+
* "p-[13px]" → { variants: [], utility: "p", value: "[13px]", arbitrary: true }
|
|
78
|
+
* "@md:flex" → { variants: ["@md"], utility: "flex", value: null }
|
|
79
|
+
* "pl-physical-4" → { variants: [], utility: "pl", value: "4", physical: true }
|
|
80
|
+
*/
|
|
81
|
+
interface ParsedUtility {
|
|
82
|
+
/** Original class string before parsing */
|
|
83
|
+
raw: string;
|
|
84
|
+
/** Variant prefixes in order, e.g. ["hover"], ["sm", "hover"] */
|
|
85
|
+
variants: string[];
|
|
86
|
+
/** The utility name (everything before the value separator), e.g. "bg", "p", "text" */
|
|
87
|
+
utility: string;
|
|
88
|
+
/** The value part after the last `-`, or null for valueless utilities like "flex" */
|
|
89
|
+
value: string | null;
|
|
90
|
+
/** Whether the value is an arbitrary bracket expression like [13px] */
|
|
91
|
+
arbitrary: boolean;
|
|
92
|
+
/** Whether !important is applied */
|
|
93
|
+
important: boolean;
|
|
94
|
+
/** Whether the -physical- infix is present */
|
|
95
|
+
physical: boolean;
|
|
96
|
+
/** Whether the utility is negative (prefixed with -) */
|
|
97
|
+
negative: boolean;
|
|
98
|
+
/** When the class is an arbitrary property like [color:red] */
|
|
99
|
+
arbitraryProperty: {
|
|
100
|
+
property: string;
|
|
101
|
+
value: string;
|
|
102
|
+
} | null;
|
|
103
|
+
/**
|
|
104
|
+
* Explicit type hint extracted from an arbitrary value, e.g. the `length`
|
|
105
|
+
* in `border-[length:1rem]` or `border-(color:--my-color)`. When set, it
|
|
106
|
+
* forces a specific dispatch path in generators — see `borderGenerator`,
|
|
107
|
+
* `colorGenerator`, etc. Null when no hint was provided.
|
|
108
|
+
*/
|
|
109
|
+
dataType: string | null;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Parse a single utility class string into its structural components.
|
|
113
|
+
*/
|
|
114
|
+
declare function parseUtility(raw: string): ParsedUtility;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Shared leaf helpers for the utility generators — result types, tiny
|
|
118
|
+
* constructors, and value-grammar helpers. Lives below both the generators
|
|
119
|
+
* and the dispatch index (which imports every generator) so that generators
|
|
120
|
+
* never import their own aggregator: generator ↔ index cycles would let
|
|
121
|
+
* modules observe partially initialized exports.
|
|
122
|
+
*/
|
|
123
|
+
interface CSSDeclaration {
|
|
124
|
+
property: string;
|
|
125
|
+
value: string;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Variant resolution — maps variant names to CSS wrappers.
|
|
130
|
+
*
|
|
131
|
+
* Handles pseudo-classes, pseudo-elements, media queries, responsive breakpoints,
|
|
132
|
+
* container queries, data/aria attributes, :has()/:not(), arbitrary variants,
|
|
133
|
+
* and custom variants.
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
type VariantKind = "pseudo-class" | "pseudo-element" | "media" | "breakpoint" | "container" | "special" | "custom" | "pattern";
|
|
137
|
+
interface VariantInfo {
|
|
138
|
+
/** The variant as typed before the `:` — for patterns, the family prefix. */
|
|
139
|
+
name: string;
|
|
140
|
+
kind: VariantKind;
|
|
141
|
+
/** What the variant emits — a selector suffix, an at-rule, or (for
|
|
142
|
+
* patterns) a description of the accepted form. */
|
|
143
|
+
wraps: string;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Enumerate every concrete variant the given theme resolves, plus the
|
|
147
|
+
* open-ended pattern families. Concrete entries (kind ≠ "pattern") are
|
|
148
|
+
* guaranteed to resolve via resolveVariant — the list mirrors its checks,
|
|
149
|
+
* including the CSS-length guard on breakpoint values.
|
|
150
|
+
*/
|
|
151
|
+
declare function listVariants(theme: ResolvedTheme): VariantInfo[];
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Class inspector — single-class validation and explanation for editor
|
|
155
|
+
* tooling, running the exact resolution the compile loop performs.
|
|
156
|
+
*
|
|
157
|
+
* The compiler intentionally drops unknown utilities silently (reserved
|
|
158
|
+
* RI-1001): the build scanner over-collects, so at build time an unresolved
|
|
159
|
+
* candidate is usually noise. Inside an editor the certainty is inverted — a
|
|
160
|
+
* token in a class attribute is meant to be a class — so the inspector
|
|
161
|
+
* finally gives RI-1001 a voice: `validate()` reports WHY a class produces no
|
|
162
|
+
* CSS, with a typo suggestion when one is close enough.
|
|
163
|
+
*
|
|
164
|
+
* An inspector instance owns the per-theme caches the compile loop rebuilds
|
|
165
|
+
* per pass (custom-variant map, variant memo, breakpoint weights) plus a
|
|
166
|
+
* resolution cache, so per-keystroke validation of the same classes is cheap.
|
|
167
|
+
* Create one per theme and drop it when the theme changes.
|
|
168
|
+
*/
|
|
169
|
+
|
|
170
|
+
type ClassValidation = {
|
|
171
|
+
ok: true;
|
|
172
|
+
} | {
|
|
173
|
+
ok: false;
|
|
174
|
+
reason: "unknown-utility" | "unknown-variant" | "invalid-arbitrary";
|
|
175
|
+
/** The failing fragment — the variant for "unknown-variant", the
|
|
176
|
+
* base class (variants stripped) otherwise. */
|
|
177
|
+
offender: string;
|
|
178
|
+
/** Closest known name within typo distance, when one exists. */
|
|
179
|
+
suggestion?: string;
|
|
180
|
+
};
|
|
181
|
+
interface ClassExplanation {
|
|
182
|
+
parsed: ParsedUtility;
|
|
183
|
+
/** Root declarations before variant wrapping. */
|
|
184
|
+
declarations: CSSDeclaration[];
|
|
185
|
+
/** Escaped selector, including variant suffixes (`.hover\:px-2:hover`). */
|
|
186
|
+
selector: string;
|
|
187
|
+
/** The complete rule text, including wrapping at-rules. */
|
|
188
|
+
css: string;
|
|
189
|
+
/** Deterministic ordering key — lower emits earlier in generated CSS. */
|
|
190
|
+
sortKey: number;
|
|
191
|
+
/**
|
|
192
|
+
* A marker class (`group`, `peer/sidebar`): valid, and wearing no CSS of its
|
|
193
|
+
* own. `declarations` is empty and `css` is "", so a caller rendering a
|
|
194
|
+
* preview shows nothing; `selector` is the anchor a `group-*` / `peer-*`
|
|
195
|
+
* variant matches on this element.
|
|
196
|
+
*/
|
|
197
|
+
marker?: true;
|
|
198
|
+
}
|
|
199
|
+
interface ClassInspector {
|
|
200
|
+
readonly theme: ResolvedTheme;
|
|
201
|
+
/** Would this class produce CSS under the theme? Reports why not. */
|
|
202
|
+
validate(className: string): ClassValidation;
|
|
203
|
+
/** Structured breakdown + generated CSS, or null when invalid. */
|
|
204
|
+
explain(className: string): ClassExplanation | null;
|
|
205
|
+
/** Every variant the theme resolves (cached). */
|
|
206
|
+
variants(): readonly VariantInfo[];
|
|
207
|
+
}
|
|
208
|
+
declare function createClassInspector(theme: ResolvedTheme): ClassInspector;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* The single registration table for built-in utility roots: each row binds a
|
|
212
|
+
* set of roots to the generators that resolve them (in probe order) AND to the
|
|
213
|
+
* value space editor enumeration tries for them. index.ts derives
|
|
214
|
+
* PREFIX_DISPATCH from the resolver columns; enumerate.ts derives
|
|
215
|
+
* UTILITY_VALUE_SPACES from the spec column — adding a root forces deciding
|
|
216
|
+
* both in one row, so the two can never drift.
|
|
217
|
+
*
|
|
218
|
+
* Value spaces are deliberately GENEROUS (which theme namespaces and keyword
|
|
219
|
+
* families to TRY per functional root): every enumeration candidate is probed
|
|
220
|
+
* through the real utility resolver, which stays the single authority — a
|
|
221
|
+
* spec can over-approximate freely and never emit something `validate()`
|
|
222
|
+
* would reject. `{ kinds: [] }` marks a statics-only root.
|
|
223
|
+
*
|
|
224
|
+
* Ordering is load-bearing twice over: row order fixes PREFIX_DISPATCH key
|
|
225
|
+
* insertion order (which drives cross-root enumeration dedup labels), and
|
|
226
|
+
* per-root resolver order fixes which generator wins a contested root.
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
type ValueSpaceKind = "color" | "special-color" | "spacing" | "fraction" | "text-size" | "fluid-text-size" | "font-slot" | "weight" | "rounded" | "rounded-side" | "shadow" | "z" | "ease" | "blur" | "animation" | "leading" | "fluid-range" | "tracking" | "opacity" | "duration" | "breakpoint" | "int" | "percent" | "keywords";
|
|
230
|
+
interface ValueSpaceSpec {
|
|
231
|
+
kinds: readonly ValueSpaceKind[];
|
|
232
|
+
/** Extra value parts to try verbatim (for "keywords" and beyond). */
|
|
233
|
+
keywords?: readonly string[];
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Class enumeration — the completion universe for editor tooling.
|
|
238
|
+
*
|
|
239
|
+
* Design: candidates are generated from a deliberately GENEROUS value-space
|
|
240
|
+
* table (which theme namespaces and keyword families to TRY per functional
|
|
241
|
+
* root), then every candidate is probed through the real utility resolver.
|
|
242
|
+
* The resolver is the single authority — an enumerated class is one that
|
|
243
|
+
* actually compiles, so the table can over-approximate freely and can never
|
|
244
|
+
* emit something `validate()` would reject. Coverage is structural: the table
|
|
245
|
+
* derives from ROOT_GROUPS (roots.ts), where `spec` is a required field of
|
|
246
|
+
* every row — adding a root forces deciding its value space in the same row
|
|
247
|
+
* (an empty spec marks a statics-only root); the CI check in enumerate.test.ts
|
|
248
|
+
* stays on as a regression tripwire.
|
|
249
|
+
*
|
|
250
|
+
* Statics come from the merge conflict tables (STATIC_UTILITIES) plus each
|
|
251
|
+
* generator's own static-map keys — probed too, for the same guarantee.
|
|
252
|
+
*/
|
|
253
|
+
|
|
254
|
+
/** Root → value spaces to try, derived from ROOT_GROUPS. Every
|
|
255
|
+
* PREFIX_DISPATCH root is present by construction — both maps are built
|
|
256
|
+
* from the same rows. */
|
|
257
|
+
declare const UTILITY_VALUE_SPACES: ReadonlyMap<string, ValueSpaceSpec>;
|
|
258
|
+
interface EnumeratedClass {
|
|
259
|
+
name: string;
|
|
260
|
+
/** How the class was produced: a static table, a custom @utility, or the
|
|
261
|
+
* value-space kind that filled the functional root. */
|
|
262
|
+
kind: ValueSpaceKind | "static" | "custom";
|
|
263
|
+
/** The functional root, or null for statics/custom statics. */
|
|
264
|
+
root: string | null;
|
|
265
|
+
}
|
|
266
|
+
interface ClassTemplate {
|
|
267
|
+
root: string;
|
|
268
|
+
/** The open-ended space: numeric spacing scale, plain numbers, or a
|
|
269
|
+
* functional custom utility that accepts any suffix. */
|
|
270
|
+
kind: "spacing" | "number" | "custom";
|
|
271
|
+
example: string;
|
|
272
|
+
}
|
|
273
|
+
interface ClassEnumeration {
|
|
274
|
+
/** Every finite concrete class, probed valid, sorted by name. */
|
|
275
|
+
classes: EnumeratedClass[];
|
|
276
|
+
/** Families whose value space is infinite — offer as snippets. */
|
|
277
|
+
templates: ClassTemplate[];
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Enumerate the finite completion universe for a theme. Every returned class
|
|
281
|
+
* has been resolved by the real utility resolver — `validate()` accepts each
|
|
282
|
+
* one by construction. Infinite families (the spacing scale, numeric values,
|
|
283
|
+
* functional custom utilities) come back as templates; a template is emitted
|
|
284
|
+
* only when at least one of its probes resolved.
|
|
285
|
+
*/
|
|
286
|
+
declare function enumerateClassNames(theme: ResolvedTheme): ClassEnumeration;
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* analyzeMerge() — editor-only merge diagnostics.
|
|
290
|
+
*
|
|
291
|
+
* Explains ri()'s right-most-wins conflict resolution by threading a
|
|
292
|
+
* MergeTrace through the shared merge loop. Split from merge/index.ts so the
|
|
293
|
+
* browser-facing runtime file stays free of editor-only analysis; consumed by
|
|
294
|
+
* editor/session.ts and the editor entry.
|
|
295
|
+
*/
|
|
296
|
+
|
|
297
|
+
interface MergeDrop {
|
|
298
|
+
index: number;
|
|
299
|
+
className: string;
|
|
300
|
+
/** Ascending indices of the surviving classes that together claimed every
|
|
301
|
+
* CSS property this class sets (px-4 + py-4 jointly dominate p-2). */
|
|
302
|
+
overriddenBy: number[];
|
|
303
|
+
}
|
|
304
|
+
interface MergeAnalysis {
|
|
305
|
+
/** The merged output — identical to ri()'s result for this token list. */
|
|
306
|
+
output: string;
|
|
307
|
+
/** Indices of surviving classes, ascending. */
|
|
308
|
+
kept: number[];
|
|
309
|
+
/** Dropped classes with attribution, ascending by index. */
|
|
310
|
+
dropped: MergeDrop[];
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Explain ri()'s conflict resolution for a list of class tokens — which
|
|
314
|
+
* classes the right-most-wins scan drops, and which survivors claimed their
|
|
315
|
+
* properties. Powers "this class is overridden" editor diagnostics.
|
|
316
|
+
*
|
|
317
|
+
* Unlike ri(), the input is pre-tokenized: one class per element, no falsy
|
|
318
|
+
* filtering, no whitespace splitting — exactly the token list an editor
|
|
319
|
+
* extracts from one class attribute. `snapshot` binds custom utilities, text
|
|
320
|
+
* sizes, and color names the same way createRi(snapshot) does (editors build
|
|
321
|
+
* one with createThemeSnapshot()); without it, the module-level state of the
|
|
322
|
+
* most recent compile applies. Uncached — call sites own their memoization.
|
|
323
|
+
*/
|
|
324
|
+
declare function analyzeMerge(classes: readonly string[], snapshot?: CompilationSnapshot): MergeAnalysis;
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Color swatches and theme-token introspection for editor tooling.
|
|
328
|
+
*
|
|
329
|
+
* Resolves a theme color (and stop) to concrete light/dark colors — the same
|
|
330
|
+
* OKLCH math the CSS variable emitter uses (generateStop / computeDarkStop),
|
|
331
|
+
* plus an sRGB hex conversion for completion-item swatches and sidebar chips.
|
|
332
|
+
* Pure computation, no IO.
|
|
333
|
+
*/
|
|
334
|
+
|
|
335
|
+
/** The canonical palette stops every generative color defines. */
|
|
336
|
+
declare const CANONICAL_COLOR_STOPS: readonly number[];
|
|
337
|
+
/** Convert an OKLCH color to a #rrggbb hex string (sRGB, channel-clamped). */
|
|
338
|
+
declare function oklchToHex(l: number, c: number, h: number): string;
|
|
339
|
+
/** Best-effort hex for the CSS color texts theme definitions hold: `oklch()`
|
|
340
|
+
* and hex literals. Anything else (named colors, rgb(), vars) returns null —
|
|
341
|
+
* the raw CSS text still travels alongside. */
|
|
342
|
+
declare function cssColorToHex(css: string): string | null;
|
|
343
|
+
interface SwatchColor {
|
|
344
|
+
/** CSS color text (`oklch(…)`, or the definition's own value verbatim). */
|
|
345
|
+
css: string;
|
|
346
|
+
/** sRGB hex, or null when the CSS text isn't convertible. */
|
|
347
|
+
hex: string | null;
|
|
348
|
+
}
|
|
349
|
+
interface ColorSwatch {
|
|
350
|
+
light: SwatchColor;
|
|
351
|
+
/** Null when the theme's dark mode is off or the color has no dark form. */
|
|
352
|
+
dark: SwatchColor | null;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Resolve a theme color name (+ stop, for generative palettes) to concrete
|
|
356
|
+
* light/dark swatch colors — exactly the values the emitted CSS variables
|
|
357
|
+
* carry. Theme-defined colors always win; the fixed semantic swatches
|
|
358
|
+
* (paper/ink/white/black) apply only when the theme does not define the name,
|
|
359
|
+
* mirroring the emitter (a user `@color { white: … }` palette emits
|
|
360
|
+
* `--color-white-*` variables that suffixed utilities resolve against).
|
|
361
|
+
* Returns null for unknown names, unresolvable aliases, and keyword colors
|
|
362
|
+
* with no concrete value (transparent, currentColor).
|
|
363
|
+
*/
|
|
364
|
+
declare function resolveColorSwatch(theme: ResolvedTheme, name: string, stop?: number): ColorSwatch | null;
|
|
365
|
+
interface ThemeTokens {
|
|
366
|
+
/** Color names with their definition kind — pair with resolveColorSwatch. */
|
|
367
|
+
colors: Array<{
|
|
368
|
+
name: string;
|
|
369
|
+
kind: ColorDefinition["type"];
|
|
370
|
+
}>;
|
|
371
|
+
colorStops: readonly number[];
|
|
372
|
+
spacingBase: string;
|
|
373
|
+
textSizes: Array<{
|
|
374
|
+
name: string;
|
|
375
|
+
fontSize: string;
|
|
376
|
+
lineHeight: string;
|
|
377
|
+
}>;
|
|
378
|
+
breakpoints: Record<string, string>;
|
|
379
|
+
shadows: Record<string, string>;
|
|
380
|
+
weights: Record<string, number>;
|
|
381
|
+
easing: Record<string, string>;
|
|
382
|
+
blur: Record<string, string>;
|
|
383
|
+
z: Record<string, string>;
|
|
384
|
+
leading: Record<string, string>;
|
|
385
|
+
tracking: Record<string, string>;
|
|
386
|
+
opacity: Record<string, string>;
|
|
387
|
+
duration: Record<string, string>;
|
|
388
|
+
/** Named radii from `@rounded { roof: 24px; }` — the class is `rounded-roof`.
|
|
389
|
+
* Unnamed radii are spacing multiples and carry no token. */
|
|
390
|
+
radii: Record<string, string>;
|
|
391
|
+
/** Named ranges from `@fluid <name> { min; max; }` — each one makes the scope
|
|
392
|
+
* class `fluid-<name>`. A bound absent from the block is absent here. */
|
|
393
|
+
fluidRanges: Record<string, {
|
|
394
|
+
min?: string;
|
|
395
|
+
max?: string;
|
|
396
|
+
}>;
|
|
397
|
+
fonts: Array<{
|
|
398
|
+
slot: string;
|
|
399
|
+
family: string;
|
|
400
|
+
}>;
|
|
401
|
+
animations: string[];
|
|
402
|
+
}
|
|
403
|
+
/** One render-ready view of a theme's token namespaces for sidebar chips and
|
|
404
|
+
* completion detail — plain data, no theme internals to traverse. */
|
|
405
|
+
declare function listThemeTokens(theme: ResolvedTheme): ThemeTokens;
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* `renderStylesheet` — a theme plus a class list in, a stylesheet out.
|
|
409
|
+
*
|
|
410
|
+
* The rest of `rainbowindex/editor` answers questions *about* classes:
|
|
411
|
+
* is this one valid, what does it mean, what could you type next. This one
|
|
412
|
+
* produces the artifact itself, which is what a playground, a docs example,
|
|
413
|
+
* and a "show me the generated CSS" hover all need.
|
|
414
|
+
*
|
|
415
|
+
* It is the pure core of the build pipeline: the same `createCompiler()` and
|
|
416
|
+
* `assembleSections()` the PostCSS plugin and the CLI run, with the two steps
|
|
417
|
+
* that touch the world left out.
|
|
418
|
+
*
|
|
419
|
+
* - **Fonts are not resolved.** `@font … from google` needs the Google
|
|
420
|
+
* metadata endpoint to narrow a family's weights, which is IO. The slot
|
|
421
|
+
* still emits its `@import` and its `--font-*` variable; only the weight
|
|
422
|
+
* narrowing is missing, so the sheet differs from a Node build only for a
|
|
423
|
+
* Google slot whose declared weights the provider would have trimmed.
|
|
424
|
+
* - **`@apply` is not expanded.** That rewrite is PostCSS's job — it edits
|
|
425
|
+
* the user's own rules in place — and pulling PostCSS in would double the
|
|
426
|
+
* weight of an entry that exists to stay small. An `@apply` left in
|
|
427
|
+
* `userCSS` passes through verbatim.
|
|
428
|
+
*
|
|
429
|
+
* Everything else — token pruning, `@property` registration, preflight,
|
|
430
|
+
* `[data-theme]` overrides, rule ordering — is the production path.
|
|
431
|
+
*/
|
|
432
|
+
|
|
433
|
+
interface RenderStylesheetOptions {
|
|
434
|
+
/**
|
|
435
|
+
* Classes the user wrote by hand, when that is a subset of `classNames`.
|
|
436
|
+
* Diagnostics that would be noise for a generated class — an unknown
|
|
437
|
+
* utility inside a scanned template literal, say — are raised only for
|
|
438
|
+
* these. Omit to treat every class as authored.
|
|
439
|
+
*/
|
|
440
|
+
authoredClassNames?: ReadonlySet<string>;
|
|
441
|
+
/**
|
|
442
|
+
* The project's own CSS, with RI directives already removed (the entry's
|
|
443
|
+
* `stripRIDirectives` does that). It is scanned for `var(--color-…)` and
|
|
444
|
+
* friends before assembly, so a token only the user's CSS names survives
|
|
445
|
+
* pruning, and it is appended to the output after the generated sections —
|
|
446
|
+
* the same order a real build emits.
|
|
447
|
+
*/
|
|
448
|
+
userCSS?: string;
|
|
449
|
+
}
|
|
450
|
+
interface RenderedStylesheet {
|
|
451
|
+
/** The generated sections and `userCSS`, joined as a build would emit them. */
|
|
452
|
+
css: string;
|
|
453
|
+
/** Generated output only, in canonical section order. */
|
|
454
|
+
sections: string[];
|
|
455
|
+
/** `userCSS` after `--ri-*` CSS functions were compiled, or "". */
|
|
456
|
+
userCSS: string;
|
|
457
|
+
/** Compile and assembly warnings, in `[RI-NNNN] message` form. */
|
|
458
|
+
warnings: string[];
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Compile `classNames` against `theme` and assemble the stylesheet.
|
|
462
|
+
*
|
|
463
|
+
* Pure: no filesystem, no network, no module-level state. Two calls with the
|
|
464
|
+
* same arguments return the same CSS, and concurrent calls cannot see each
|
|
465
|
+
* other's fonts — the compiler owns its caches.
|
|
466
|
+
*/
|
|
467
|
+
declare function renderStylesheet(theme: ResolvedTheme, classNames: Iterable<string>, options?: RenderStylesheetOptions): RenderedStylesheet;
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Editor session — the façade that ties the editor toolkit together.
|
|
471
|
+
*
|
|
472
|
+
* An editor host holds one session per workspace, calls `setCss()` whenever
|
|
473
|
+
* the project's CSS entry changes, and everything else per keystroke. The
|
|
474
|
+
* session owns the caching story: theme analysis, the class inspector, the
|
|
475
|
+
* enumeration, token introspection, and the merge snapshot are computed
|
|
476
|
+
* lazily and invalidated together when the CSS changes — callers never
|
|
477
|
+
* juggle per-theme cache keys themselves. Every capability is also exported
|
|
478
|
+
* à la carte from `rainbowindex/editor` for hosts that want finer control.
|
|
479
|
+
*
|
|
480
|
+
* Pure computation, no IO: the host reads the CSS file (see
|
|
481
|
+
* CSS_ENTRY_CANDIDATES / hasRIActivation for locating it) and passes text.
|
|
482
|
+
*/
|
|
483
|
+
|
|
484
|
+
interface EditorSession {
|
|
485
|
+
/** The CSS input the session is currently analyzing. */
|
|
486
|
+
readonly css: string;
|
|
487
|
+
/** Swap the CSS input; all theme-derived caches invalidate together.
|
|
488
|
+
* A no-op when the text is unchanged. */
|
|
489
|
+
setCss(css: string): void;
|
|
490
|
+
readonly theme: ResolvedTheme;
|
|
491
|
+
/** Positioned diagnostics for the CSS input (see ProjectAnalysis). */
|
|
492
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
493
|
+
/** Single-class validation/explanation, cached per theme. */
|
|
494
|
+
readonly inspector: ClassInspector;
|
|
495
|
+
/** The finite completion universe + templates, cached per theme. */
|
|
496
|
+
enumerate(): ClassEnumeration;
|
|
497
|
+
/** Render-ready token namespaces, cached per theme. */
|
|
498
|
+
tokens(): ThemeTokens;
|
|
499
|
+
/** The merge snapshot for this theme, cached. */
|
|
500
|
+
snapshot(): CompilationSnapshot;
|
|
501
|
+
/** analyzeMerge bound to this theme's snapshot. */
|
|
502
|
+
analyzeMerge(classes: readonly string[]): MergeAnalysis;
|
|
503
|
+
/** Position-aware class extraction for a source document. */
|
|
504
|
+
extractCandidates(content: string, path?: string): ClassCandidate[];
|
|
505
|
+
/**
|
|
506
|
+
* Files pulled in by `@import`, in first-visit order, or empty when no
|
|
507
|
+
* resolver was supplied. A host watches these: editing an imported token
|
|
508
|
+
* file must invalidate the session just as editing the entry does.
|
|
509
|
+
*/
|
|
510
|
+
readonly importedFiles: readonly string[];
|
|
511
|
+
/** Light/dark swatch for a theme color (+ stop), or null. */
|
|
512
|
+
swatch(name: string, stop?: number): ColorSwatch | null;
|
|
513
|
+
/**
|
|
514
|
+
* Compile `classNames` against this session's theme and assemble the
|
|
515
|
+
* stylesheet, the way a build would.
|
|
516
|
+
*
|
|
517
|
+
* `userCSS` defaults to this session's own CSS entry with the directives
|
|
518
|
+
* stripped — imports already inlined — so `session.render(classes)` on its
|
|
519
|
+
* own reproduces the project's sheet. Pass `userCSS: ""` for the generated
|
|
520
|
+
* output alone. See `renderStylesheet` for what a pure render leaves out.
|
|
521
|
+
*/
|
|
522
|
+
render(classNames: Iterable<string>, options?: RenderStylesheetOptions): RenderedStylesheet;
|
|
523
|
+
/**
|
|
524
|
+
* Order a class list the way the generated stylesheet orders its rules,
|
|
525
|
+
* through this session's cached inspector. See `sortClasses` — in
|
|
526
|
+
* particular, do not sort a list that reaches `ri()`.
|
|
527
|
+
*/
|
|
528
|
+
sortClasses(classNames: readonly string[]): string[];
|
|
529
|
+
}
|
|
530
|
+
declare function createEditorSession(options?: {
|
|
531
|
+
css?: string;
|
|
532
|
+
/**
|
|
533
|
+
* Turns an `@import` specifier into text, so directives in imported
|
|
534
|
+
* files reach the theme. Synchronous by design: the host already has
|
|
535
|
+
* its open documents in memory, and this entry does no IO of its own.
|
|
536
|
+
* Without one, imports pass through and their directives stay unread.
|
|
537
|
+
*/
|
|
538
|
+
resolveImport?: ImportResolver;
|
|
539
|
+
/** Identity of the CSS entry — the base for relative specifiers. */
|
|
540
|
+
cssPath?: string;
|
|
541
|
+
}): EditorSession;
|
|
542
|
+
|
|
543
|
+
export { resolveColorSwatch as A, severityForCode as B, type ClassCandidate as C, type Diagnostic as D, type EditorSession as E, warningCode as F, type MergeAnalysis as M, type ParsedUtility as P, type RenderStylesheetOptions as R, type SwatchColor as S, type ThemeTokens as T, UTILITY_VALUE_SPACES as U, type ValueSpaceKind as V, CANONICAL_COLOR_STOPS as a, type CandidateOrigin as b, type ClassEnumeration as c, type ClassExplanation as d, type ClassInspector as e, type ClassTemplate as f, type ClassValidation as g, type ColorSwatch as h, type DiagnosticSeverity as i, type EnumeratedClass as j, type MergeDrop as k, type RenderedStylesheet as l, type ValueSpaceSpec as m, type VariantInfo as n, type VariantKind as o, analyzeMerge as p, createClassInspector as q, createEditorSession as r, cssColorToHex as s, diagnosticFromWarning as t, enumerateClassNames as u, listThemeTokens as v, listVariants as w, oklchToHex as x, parseUtility as y, renderStylesheet as z };
|