rainbowindex 0.5.1 → 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.
Files changed (43) hide show
  1. package/CHANGELOG.md +876 -0
  2. package/LICENSE +16 -17
  3. package/NOTICE.md +106 -0
  4. package/README.md +225 -69
  5. package/dist/browser.d.ts +4 -2
  6. package/dist/browser.mjs +12 -6
  7. package/dist/chunk-2T7V5XLK.mjs +912 -0
  8. package/dist/chunk-6OORICWF.mjs +16 -0
  9. package/dist/{chunk-PDORZSQX.mjs → chunk-FJOZJIKB.mjs} +7814 -5174
  10. package/dist/chunk-L56IRO7A.mjs +491 -0
  11. package/dist/chunk-PZDVDEZJ.mjs +196 -0
  12. package/dist/{chunk-4CTJLMYM.mjs → chunk-RC6DDE4L.mjs} +37 -23
  13. package/dist/chunk-TQJYVQPE.mjs +217 -0
  14. package/dist/chunk-W756NVYI.mjs +33 -0
  15. package/dist/chunk-WBESS2ZD.mjs +598 -0
  16. package/dist/{chunk-3HRMFZGE.mjs → chunk-X66Z2YHT.mjs} +2 -1
  17. package/dist/{chunk-4UKFK2GE.mjs → chunk-XQGSG2HK.mjs} +213 -756
  18. package/dist/cli.mjs +1101 -125
  19. package/dist/{context-B9yhJxd5.d.ts → context-DcBtnnan.d.ts} +55 -108
  20. package/dist/editor.d.ts +82 -421
  21. package/dist/editor.mjs +68 -363
  22. package/dist/eslint.d.ts +16 -0
  23. package/dist/eslint.mjs +32 -0
  24. package/dist/{index-Dx-NpFFx.d.ts → imports-C9esHd5Q.d.ts} +98 -81
  25. package/dist/index-CNqdL5U0.d.ts +56 -0
  26. package/dist/index-Czx-EUwh.d.ts +138 -0
  27. package/dist/index-DW8YSxTz.d.ts +104 -0
  28. package/dist/index.d.ts +49 -5
  29. package/dist/index.mjs +40 -13
  30. package/dist/oxlint.d.ts +21 -3
  31. package/dist/oxlint.mjs +19 -1
  32. package/dist/recipe.d.ts +111 -0
  33. package/dist/recipe.mjs +71 -0
  34. package/dist/safelist-CH3_PywB.d.ts +43 -0
  35. package/dist/session-CMaskdB7.d.ts +543 -0
  36. package/dist/tailwind.css +644 -0
  37. package/dist/theme-CIZiGlce.d.ts +115 -0
  38. package/dist/vite.d.ts +10 -1
  39. package/dist/vite.mjs +273 -113
  40. package/package.json +27 -5
  41. package/dist/chunk-F4VCBISU.mjs +0 -1866
  42. package/dist/chunk-RU4756NG.mjs +0 -243
  43. package/dist/safelist-DAkKuxCk.d.ts +0 -96
package/dist/editor.mjs CHANGED
@@ -1,21 +1,31 @@
1
1
  import {
2
+ analyzeMerge,
3
+ createEditorSession,
4
+ renderStylesheet,
5
+ sortClasses
6
+ } from "./chunk-PZDVDEZJ.mjs";
7
+ import {
8
+ CANONICAL_COLOR_STOPS,
2
9
  CSS_ENTRY_CANDIDATES,
3
10
  UTILITY_VALUE_SPACES,
4
- enumerateClassNames
5
- } from "./chunk-RU4756NG.mjs";
11
+ createClassInspector,
12
+ cssColorToHex,
13
+ enumerateClassNames,
14
+ listThemeTokens,
15
+ oklchToHex,
16
+ outermostCandidates,
17
+ resolveColorSwatch
18
+ } from "./chunk-WBESS2ZD.mjs";
6
19
  import {
7
20
  isSourceFile
8
- } from "./chunk-3HRMFZGE.mjs";
21
+ } from "./chunk-X66Z2YHT.mjs";
9
22
  import {
10
23
  CLASS_HELPER_NAMES,
11
24
  RI_IMPORT_SPECIFIERS,
12
- STATIC_UTILITIES,
13
25
  VARIANT_HELPER_NAMES,
14
26
  analyzeProjectCSS,
15
- buildBreakpointWeights,
16
- compileUtility,
17
- createEmptyCompilationResult,
18
27
  createThemeSnapshot,
28
+ describeLoadedWeights,
19
29
  diagnosticFromWarning,
20
30
  expandVariantGroups,
21
31
  extractClassCandidates,
@@ -23,366 +33,26 @@ import {
23
33
  extractClassesFromSource,
24
34
  findClosest,
25
35
  hasRIActivation,
36
+ inlineDirectiveImports,
37
+ isSuppressible,
26
38
  listVariants,
27
39
  parseUtility,
28
40
  severityForCode,
29
- warningCode
30
- } from "./chunk-PDORZSQX.mjs";
41
+ stripRIDirectives,
42
+ warningCode,
43
+ weightIsLoaded
44
+ } from "./chunk-FJOZJIKB.mjs";
31
45
  import {
32
- computeDarkStop,
33
- defaultTheme,
34
- formatOklch,
35
- generateStop,
36
- linearToSrgb,
37
- mergeUncached,
38
- oklabToLinearSrgb,
39
- oklchToOklab,
40
- resolverFor
41
- } from "./chunk-4UKFK2GE.mjs";
42
-
43
- // src/engine/inspector.ts
44
- var RESOLUTION_CACHE_CAP = 1e4;
45
- var OK = Object.freeze({ ok: true });
46
- function createClassInspector(theme) {
47
- const customVariantMap = new Map(theme.customVariants.map((cv) => [cv.name, cv]));
48
- const breakpointWeights = buildBreakpointWeights(theme.breakpoints);
49
- const variantMemo = /* @__PURE__ */ new Map();
50
- const scratch = createEmptyCompilationResult();
51
- const warnSeen = /* @__PURE__ */ new Set();
52
- const detail = { reason: null, variant: null, declarations: null };
53
- const cache = /* @__PURE__ */ new Map();
54
- let variantList = null;
55
- let variantNames = null;
56
- let utilityCorpus = null;
57
- function variants() {
58
- if (!variantList) variantList = Object.freeze(listVariants(theme));
59
- return variantList;
60
- }
61
- function variantSuggestionCorpus() {
62
- if (!variantNames) {
63
- const names = [];
64
- for (const v of variants()) {
65
- if (v.kind !== "pattern") names.push(v.name);
66
- }
67
- variantNames = names;
68
- }
69
- return variantNames;
70
- }
71
- function utilitySuggestionCorpus() {
72
- if (!utilityCorpus) {
73
- const names = new Set(STATIC_UTILITIES);
74
- for (const custom of theme.customUtilities) {
75
- if (!custom.functional) names.add(custom.name);
76
- }
77
- for (const entry of enumerateClassNames(theme).classes) names.add(entry.name);
78
- utilityCorpus = [...names];
79
- }
80
- return utilityCorpus;
81
- }
82
- function baseName(raw, parsed) {
83
- let base = raw;
84
- if (parsed.variants.length > 0) {
85
- const prefix = `${parsed.variants.join(":")}:`;
86
- if (base.startsWith(prefix)) base = base.slice(prefix.length);
87
- }
88
- if (parsed.important && base.endsWith("!")) base = base.slice(0, -1);
89
- return base;
90
- }
91
- function resolve(className) {
92
- const cached = cache.get(className);
93
- if (cached) return cached;
94
- if (cache.size >= RESOLUTION_CACHE_CAP) {
95
- cache.clear();
96
- variantMemo.clear();
97
- }
98
- scratch.warnings.length = 0;
99
- warnSeen.clear();
100
- const parsed = parseUtility(className);
101
- const rule = compileUtility(
102
- parsed,
103
- theme,
104
- scratch,
105
- customVariantMap,
106
- warnSeen,
107
- breakpointWeights,
108
- variantMemo,
109
- detail
110
- );
111
- let entry;
112
- if (rule) {
113
- entry = {
114
- validation: OK,
115
- explanation: {
116
- parsed,
117
- declarations: detail.declarations ? [...detail.declarations] : [],
118
- selector: rule.selector,
119
- css: rule.css,
120
- sortKey: rule.sortKey
121
- }
122
- };
123
- } else if (detail.reason === "unknown-variant" && detail.variant !== null) {
124
- const suggestion = findClosest(detail.variant, variantSuggestionCorpus());
125
- entry = {
126
- validation: {
127
- ok: false,
128
- reason: "unknown-variant",
129
- offender: detail.variant,
130
- ...suggestion ? { suggestion } : {}
131
- },
132
- explanation: null
133
- };
134
- } else {
135
- const base = baseName(className, parsed);
136
- if (parsed.arbitrary || parsed.arbitraryProperty !== null) {
137
- entry = {
138
- validation: { ok: false, reason: "invalid-arbitrary", offender: base },
139
- explanation: null
140
- };
141
- } else {
142
- const suggestion = findClosest(base, utilitySuggestionCorpus());
143
- entry = {
144
- validation: {
145
- ok: false,
146
- reason: "unknown-utility",
147
- offender: base,
148
- ...suggestion ? { suggestion } : {}
149
- },
150
- explanation: null
151
- };
152
- }
153
- }
154
- cache.set(className, entry);
155
- return entry;
156
- }
157
- return {
158
- theme,
159
- validate: (className) => resolve(className).validation,
160
- explain: (className) => resolve(className).explanation,
161
- variants
162
- };
163
- }
164
-
165
- // src/merge/analyze.ts
166
- function analyzeMerge(classes, snapshot) {
167
- const resolve = resolverFor(snapshot);
168
- const trace = { claimers: /* @__PURE__ */ new Map(), dropped: [] };
169
- const output = mergeUncached(classes, resolve, trace);
170
- trace.dropped.sort((a, b) => a.index - b.index);
171
- const droppedIndexes = new Set(trace.dropped.map((d) => d.index));
172
- const kept = [];
173
- for (let i = 0; i < classes.length; i++) {
174
- if (!droppedIndexes.has(i)) kept.push(i);
175
- }
176
- return {
177
- output,
178
- kept,
179
- dropped: trace.dropped.map((d) => ({
180
- index: d.index,
181
- className: classes[d.index],
182
- overriddenBy: d.overriddenBy
183
- }))
184
- };
185
- }
186
-
187
- // src/theme/swatch.ts
188
- var CANONICAL_COLOR_STOPS = Object.freeze([
189
- 50,
190
- 100,
191
- 150,
192
- 200,
193
- 250,
194
- 300,
195
- 350,
196
- 400,
197
- 450,
198
- 500,
199
- 550,
200
- 600,
201
- 650,
202
- 700,
203
- 750,
204
- 800,
205
- 850,
206
- 900,
207
- 950
208
- ]);
209
- function channelHex(value) {
210
- return Math.round(Math.min(1, Math.max(0, value)) * 255).toString(16).padStart(2, "0");
211
- }
212
- function oklchToHex(l, c, h) {
213
- const [labL, labA, labB] = oklchToOklab(l, c, h);
214
- const [r, g, b] = oklabToLinearSrgb(labL, labA, labB);
215
- return `#${channelHex(linearToSrgb(r))}${channelHex(linearToSrgb(g))}${channelHex(linearToSrgb(b))}`;
216
- }
217
- var OKLCH_TEXT_RE = /^oklch\(\s*([\d.]+%?)\s+([\d.]+)\s+([\d.-]+)\s*(?:\/\s*[\d.]+%?\s*)?\)$/i;
218
- var HEX_TEXT_RE = /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
219
- function cssColorToHex(css) {
220
- const text = css.trim();
221
- if (HEX_TEXT_RE.test(text)) {
222
- if (text.length === 4 || text.length === 5) {
223
- return `#${text[1]}${text[1]}${text[2]}${text[2]}${text[3]}${text[3]}`.toLowerCase();
224
- }
225
- return text.slice(0, 7).toLowerCase();
226
- }
227
- const match = OKLCH_TEXT_RE.exec(text);
228
- if (match) {
229
- const rawL = match[1];
230
- const l = rawL.endsWith("%") ? Number.parseFloat(rawL) / 100 : Number.parseFloat(rawL);
231
- const c = Number.parseFloat(match[2]);
232
- const h = Number.parseFloat(match[3]);
233
- if (Number.isFinite(l) && Number.isFinite(c) && Number.isFinite(h)) {
234
- return oklchToHex(l, c, h);
235
- }
236
- }
237
- return null;
238
- }
239
- var MAX_ALIAS_HOPS = 8;
240
- var SEMANTIC_SWATCHES = Object.freeze({
241
- paper: {
242
- light: { css: "oklch(1 0 0)", hex: "#ffffff" },
243
- dark: { css: "oklch(0 0 0)", hex: "#000000" }
244
- },
245
- ink: {
246
- light: { css: "oklch(0 0 0)", hex: "#000000" },
247
- dark: { css: "oklch(1 0 0)", hex: "#ffffff" }
248
- },
249
- white: {
250
- light: { css: "oklch(1 0 0)", hex: "#ffffff" },
251
- dark: null
252
- },
253
- black: {
254
- light: { css: "oklch(0 0 0)", hex: "#000000" },
255
- dark: null
256
- }
257
- });
258
- function swatchFromCss(css) {
259
- return { css, hex: cssColorToHex(css) };
260
- }
261
- function resolveColorSwatch(theme, name, stop = 500) {
262
- let def = theme.colors[name];
263
- for (let hop = 0; def && def.type === "alias" && hop < MAX_ALIAS_HOPS; hop++) {
264
- def = theme.colors[def.source];
265
- }
266
- if (!def || def.type === "alias") {
267
- return SEMANTIC_SWATCHES[name] ?? null;
268
- }
269
- switch (def.type) {
270
- case "generative": {
271
- const light = generateStop(def, stop);
272
- const lightSwatch = {
273
- css: formatOklch(light.l, light.c, light.h),
274
- hex: oklchToHex(light.l, light.c, light.h)
275
- };
276
- if (theme.darkConfig.mode === "off" || def.dark?.strategy === "fixed") {
277
- return { light: lightSwatch, dark: null };
278
- }
279
- const dark = computeDarkStop(def, stop, theme.darkConfig, def.dark);
280
- return {
281
- light: lightSwatch,
282
- dark: {
283
- css: formatOklch(dark.l, dark.c, dark.h),
284
- hex: oklchToHex(dark.l, dark.c, dark.h)
285
- }
286
- };
287
- }
288
- case "explicit":
289
- return { light: swatchFromCss(def.value), dark: null };
290
- case "pair":
291
- return {
292
- light: swatchFromCss(def.light),
293
- dark: theme.darkConfig.mode === "off" ? null : swatchFromCss(def.dark)
294
- };
295
- case "keyword":
296
- return null;
297
- }
298
- }
299
- function listThemeTokens(theme) {
300
- return {
301
- colors: Object.entries(theme.colors).map(([name, def]) => ({ name, kind: def.type })),
302
- colorStops: CANONICAL_COLOR_STOPS,
303
- spacingBase: theme.spacing.base,
304
- textSizes: Object.entries(theme.text).map(([name, def]) => ({
305
- name,
306
- fontSize: def.fontSize,
307
- lineHeight: def.lineHeight
308
- })),
309
- breakpoints: { ...theme.breakpoints },
310
- shadows: { ...theme.shadows },
311
- weights: { ...theme.weights },
312
- easing: { ...theme.easing },
313
- blur: { ...theme.blur },
314
- z: { ...theme.z },
315
- leading: { ...theme.leading },
316
- tracking: { ...theme.tracking },
317
- opacity: { ...theme.opacity },
318
- duration: { ...theme.duration },
319
- fonts: theme.fonts.map((slot) => ({ slot: slot.slot, family: slot.family })),
320
- animations: Object.keys(theme.animations)
321
- };
322
- }
323
-
324
- // src/editor/session.ts
325
- function createEditorSession(options = {}) {
326
- let css = options.css ?? "";
327
- let analysis = null;
328
- let inspector = null;
329
- let enumeration = null;
330
- let tokens = null;
331
- let snapshot = null;
332
- const ensureAnalysis = () => {
333
- analysis ??= analyzeProjectCSS(css);
334
- return analysis;
335
- };
336
- const ensureSnapshot = () => {
337
- snapshot ??= createThemeSnapshot(ensureAnalysis().theme);
338
- return snapshot;
339
- };
340
- return {
341
- get css() {
342
- return css;
343
- },
344
- setCss(next) {
345
- if (next === css) return;
346
- css = next;
347
- analysis = null;
348
- inspector = null;
349
- enumeration = null;
350
- tokens = null;
351
- snapshot = null;
352
- },
353
- get theme() {
354
- return ensureAnalysis().theme;
355
- },
356
- get diagnostics() {
357
- return ensureAnalysis().diagnostics;
358
- },
359
- get inspector() {
360
- inspector ??= createClassInspector(ensureAnalysis().theme);
361
- return inspector;
362
- },
363
- enumerate() {
364
- enumeration ??= enumerateClassNames(ensureAnalysis().theme);
365
- return enumeration;
366
- },
367
- tokens() {
368
- tokens ??= listThemeTokens(ensureAnalysis().theme);
369
- return tokens;
370
- },
371
- snapshot: ensureSnapshot,
372
- analyzeMerge(classes) {
373
- return analyzeMerge(classes, ensureSnapshot());
374
- },
375
- extractCandidates(content, path) {
376
- return extractClassCandidates({ content, path });
377
- },
378
- swatch(name, stop) {
379
- return resolveColorSwatch(ensureAnalysis().theme, name, stop);
380
- }
381
- };
382
- }
46
+ defaultTheme
47
+ } from "./chunk-L56IRO7A.mjs";
48
+ import {
49
+ hydrateSnapshot,
50
+ publishSnapshot,
51
+ serializeSnapshot
52
+ } from "./chunk-XQGSG2HK.mjs";
383
53
 
384
54
  // src/entries/editor.ts
385
- var version = true ? "0.5.1" : "0.0.0-dev";
55
+ var version = true ? "0.7.0" : "0.0.0-dev";
386
56
  var EDITOR_API_VERSION = 1;
387
57
  var editorCapabilities = Object.freeze([
388
58
  "class-candidates",
@@ -400,7 +70,31 @@ var editorCapabilities = Object.freeze([
400
70
  "merge-analysis",
401
71
  "structured-diagnostics",
402
72
  "color-swatches",
403
- "editor-session"
73
+ "editor-session",
74
+ // `isSuppressible` — which diagnostic codes a `ri-disable` comment may name,
75
+ // so an editor can offer the comment only where it would work.
76
+ "diagnostic-suppression",
77
+ // `ThemeTokens.radii` and `ThemeTokens.fluidRanges`, for the named radii and
78
+ // named `@fluid` ranges that carry no token before this release.
79
+ "named-radii-and-fluid-ranges",
80
+ // `weightIsLoaded` / `describeLoadedWeights` — the RI-1504 coverage check,
81
+ // so an editor can answer "does any loaded font have this weight?".
82
+ "font-weight-coverage",
83
+ // `inlineDirectiveImports`, and `createEditorSession({ resolveImport })` —
84
+ // directives living in an `@import`ed file are read, given a host resolver.
85
+ "import-inlining",
86
+ // `serializeSnapshot` / `hydrateSnapshot` / `publishSnapshot` — a snapshot
87
+ // that survives JSON, so a theme can be shipped to a client bundle.
88
+ "serializable-snapshot",
89
+ // `renderStylesheet`, and `EditorSession.render` — the whole stylesheet,
90
+ // not just an answer about one class, from a graph with no `node:` in it.
91
+ "stylesheet-rendering",
92
+ // `sortClasses` — the emission order of a class list, so an editor command,
93
+ // a formatter and a codemod cannot disagree about what sorted means.
94
+ "class-sorting",
95
+ // `outermostCandidates` — one candidate per class the author wrote, for
96
+ // anything that maps a candidate back to a place in the source.
97
+ "candidate-spans-deduped"
404
98
  ]);
405
99
  export {
406
100
  CANONICAL_COLOR_STOPS,
@@ -417,6 +111,7 @@ export {
417
111
  createThemeSnapshot,
418
112
  cssColorToHex,
419
113
  defaultTheme,
114
+ describeLoadedWeights,
420
115
  diagnosticFromWarning,
421
116
  editorCapabilities,
422
117
  enumerateClassNames,
@@ -426,13 +121,23 @@ export {
426
121
  extractClassesFromSource,
427
122
  findClosest,
428
123
  hasRIActivation,
124
+ hydrateSnapshot,
125
+ inlineDirectiveImports,
429
126
  isSourceFile,
127
+ isSuppressible,
430
128
  listThemeTokens,
431
129
  listVariants,
432
130
  oklchToHex,
131
+ outermostCandidates,
433
132
  parseUtility,
133
+ publishSnapshot,
134
+ renderStylesheet,
434
135
  resolveColorSwatch,
136
+ serializeSnapshot,
435
137
  severityForCode,
138
+ sortClasses,
139
+ stripRIDirectives,
436
140
  version,
437
- warningCode
141
+ warningCode,
142
+ weightIsLoaded
438
143
  };
@@ -0,0 +1,16 @@
1
+ import { L as LintRule } from './theme-CIZiGlce.js';
2
+ export { a as LintContext, b as LintFix, c as LintFixer, d as LintLoc, e as LintReport, f as LintSourceCode, g as LintSuggestion, h as LintVisitor, T as ThemeLintOptions, i as clearSessionCache, j as findCSSEntry, k as getSession, n as noConflictingClassesRule, l as noUnknownClassRule, r as rules } from './theme-CIZiGlce.js';
3
+ import './session-CMaskdB7.js';
4
+ import './imports-C9esHd5Q.js';
5
+ import './index-Czx-EUwh.js';
6
+ import './context-DcBtnnan.js';
7
+
8
+ /** The flat-config plugin object. `plugins: { rainbowindex }`. */
9
+ declare const plugin: {
10
+ meta: {
11
+ name: string;
12
+ };
13
+ rules: Readonly<Record<string, LintRule>>;
14
+ };
15
+
16
+ export { LintRule, plugin as default, plugin };
@@ -0,0 +1,32 @@
1
+ import {
2
+ clearSessionCache,
3
+ findCSSEntry,
4
+ getSession,
5
+ noConflictingClassesRule,
6
+ noUnknownClassRule,
7
+ rules
8
+ } from "./chunk-TQJYVQPE.mjs";
9
+ import "./chunk-PZDVDEZJ.mjs";
10
+ import "./chunk-WBESS2ZD.mjs";
11
+ import "./chunk-W756NVYI.mjs";
12
+ import "./chunk-X66Z2YHT.mjs";
13
+ import "./chunk-FJOZJIKB.mjs";
14
+ import "./chunk-L56IRO7A.mjs";
15
+ import "./chunk-XQGSG2HK.mjs";
16
+
17
+ // src/integrations/lint/index.ts
18
+ var plugin = {
19
+ meta: { name: "rainbowindex" },
20
+ rules
21
+ };
22
+ var lint_default = plugin;
23
+ export {
24
+ clearSessionCache,
25
+ lint_default as default,
26
+ findCSSEntry,
27
+ getSession,
28
+ noConflictingClassesRule,
29
+ noUnknownClassRule,
30
+ plugin,
31
+ rules
32
+ };