rainbowindex 0.0.0 → 0.1.4

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/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ This project is a fork of Tailwind CSS v4.
4
+
5
+ Portions of this software are derived from Tailwind CSS: Copyright (c) Tailwind Labs, Inc.
6
+
7
+ The animation system is inspired by tw-animate-css: Copyright (c) 2025 Wombosvideo (Luca Bosin)
8
+
9
+ Rainbow Index modifications and additions: Copyright (c) 2026 Milo Tech Forecast
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
12
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
13
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
14
+ persons to whom the Software is furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
17
+ Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
21
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,192 @@
1
+ # rainbowindex
2
+
3
+ The core CSS compiler for Rainbow Index. This package handles parsing, transformation, and generation—everything needed
4
+ to turn utility classes into CSS.
5
+
6
+ The compiler has zero runtime dependencies and uses a custom CSS parser. Most projects will interact with Rainbow Index
7
+ through the [Vite plugin](../vite) or [CLI](../cli), but direct access to the compiler is useful for building custom
8
+ tooling or understanding how the system works.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install rainbowindex
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ### Compile Classes
19
+
20
+ The most common operation: turn a list of utility class names into CSS.
21
+
22
+ ```typescript
23
+ import { compileClasses, createDesignSystem } from "rainbowindex";
24
+
25
+ const designSystem = createDesignSystem();
26
+
27
+ const result = compileClasses(["p-4", "bg-blue-500", "hover:bg-blue-600"], {
28
+ designSystem,
29
+ });
30
+
31
+ console.log(result.css);
32
+ // .p-4 { padding: 1rem; }
33
+ // .bg-blue-500 { background-color: oklch(55.3% 0.213 253.075); }
34
+ // .hover\:bg-blue-600:hover { background-color: oklch(47.4% 0.195 251.802); }
35
+ ```
36
+
37
+ ### Parse and Print CSS
38
+
39
+ The parser produces an AST that can be inspected, transformed, or printed back to a string. This is useful for tools
40
+ that need to analyze or modify CSS programmatically.
41
+
42
+ ```typescript
43
+ import { parse, print } from "rainbowindex";
44
+
45
+ const { ast } = parse(`
46
+ .button {
47
+ padding: 1rem;
48
+ background: blue;
49
+ }
50
+ `);
51
+
52
+ const output = print(ast);
53
+ ```
54
+
55
+ ### Transform CSS with Theme
56
+
57
+ When processing CSS that contains Rainbow Index directives (`@theme`, `@apply`, etc.), use `transformCSS` to expand
58
+ them.
59
+
60
+ ```typescript
61
+ import { parse, transformCSS, createDesignSystem, print } from "rainbowindex";
62
+
63
+ const designSystem = createDesignSystem();
64
+
65
+ const { ast } = parse(`
66
+ @theme {
67
+ --color-primary: oklch(0.6 0.2 250);
68
+ }
69
+
70
+ .button {
71
+ background: var(--color-primary);
72
+ }
73
+ `);
74
+
75
+ const transformed = transformCSS(ast, { designSystem });
76
+ const output = print(transformed);
77
+ ```
78
+
79
+ ## Directive Handling
80
+
81
+ Rainbow Index processes `@rainbowindex` directives as injection points for generated styles. Unknown at-rules (including
82
+ `@tailwind`) are preserved and pass through unchanged, rather than being treated as migration inputs.
83
+
84
+ ## API Reference
85
+
86
+ ### `compileClasses(candidates, options)`
87
+
88
+ Compile utility class names into CSS.
89
+
90
+ ```typescript
91
+ interface CompileOptions {
92
+ designSystem: DesignSystem;
93
+ }
94
+
95
+ interface CompileResult {
96
+ css: string;
97
+ classes: string[];
98
+ }
99
+ ```
100
+
101
+ ### `createDesignSystem()`
102
+
103
+ Create a design system instance with the default theme, utilities, and variants. The design system is the central
104
+ registry that maps class names to CSS output.
105
+
106
+ ```typescript
107
+ interface DesignSystem {
108
+ theme: Theme;
109
+ utilities: Utilities;
110
+ variants: Variants;
111
+ parseCandidate(candidate: string): Candidate[];
112
+ compileAstNodes(candidate: Candidate): AstNode[];
113
+ getClassOrder(classes: string[]): [string, bigint | null][];
114
+ }
115
+ ```
116
+
117
+ ### `parse(css, options?)`
118
+
119
+ Parse a CSS string into an AST.
120
+
121
+ ```typescript
122
+ interface ParseOptions {
123
+ from?: string; // Source file path for source maps
124
+ }
125
+
126
+ interface ParseResult {
127
+ ast: AstNode[];
128
+ }
129
+ ```
130
+
131
+ ### `print(ast, options?)`
132
+
133
+ Convert an AST back to a CSS string.
134
+
135
+ ```typescript
136
+ interface PrintOptions {
137
+ minify?: boolean;
138
+ indent?: string;
139
+ }
140
+ ```
141
+
142
+ ### `transformCSS(ast, options)`
143
+
144
+ Transform a CSS AST, processing `@theme`, `@apply`, and other directives.
145
+
146
+ ```typescript
147
+ interface TransformOptions {
148
+ designSystem: DesignSystem;
149
+ }
150
+ ```
151
+
152
+ ## Default Theme
153
+
154
+ The default theme provides a comprehensive set of design tokens:
155
+
156
+ **Colors** — Full OKLCH palette: gray, red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo,
157
+ violet, purple, fuchsia, pink, rose.
158
+
159
+ **Spacing** — Scale from 0 to 96: 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 20, 24, 28, 32,
160
+ 36, 40, 44, 48, 52, 56, 60, 64, 72, 80, 96.
161
+
162
+ **Typography** — Font sizes, weights, and line heights.
163
+
164
+ **Breakpoints** — Numeric (rem-based) and named.
165
+
166
+ ## Utilities
167
+
168
+ Core utilities included:
169
+
170
+ - **Spacing**: `p-*`, `m-*`, `gap-*`, `space-*`
171
+ - **Sizing**: `w-*`, `h-*`, `min-w-*`, `max-w-*`, `min-h-*`, `max-h-*`
172
+ - **Colors**: `bg-*`, `text-*`, `border-*`
173
+ - **Typography**: `font-*`, `text-*`, `leading-*`, `tracking-*`
174
+ - **Layout**: `flex`, `grid`, `block`, `inline`, `hidden`
175
+ - **Flexbox**: `flex-*`, `items-*`, `justify-*`, `grow-*`, `shrink-*`
176
+ - **Grid**: `grid-cols-*`, `grid-rows-*`, `col-span-*`, `row-span-*`
177
+ - **Effects**: `shadow-*`, `opacity-*`, `blur-*`
178
+ - **Borders**: `rounded-*`, `border-*`
179
+
180
+ ## Variants
181
+
182
+ Built-in variants:
183
+
184
+ - **Pseudo-classes**: `hover`, `focus`, `active`, `visited`, `disabled`, `first`, `last`, `odd`, `even`
185
+ - **Pseudo-elements**: `before`, `after`, `placeholder`, `selection`
186
+ - **Media**: `dark`, numeric breakpoints (`48:`, `64:`, etc.)
187
+ - **Compound**: `group-*`, `peer-*`
188
+ - **Data/Aria**: `data-*`, `aria-*`
189
+
190
+ ## License
191
+
192
+ MIT
package/css/index.css ADDED
@@ -0,0 +1,5 @@
1
+ @import "./theme.css";
2
+ @import "./preflight.css";
3
+
4
+ /* Where generated utilities are injected */
5
+ @rainbowindex utilities;
@@ -0,0 +1,370 @@
1
+ /**
2
+ * Rainbow Index - Preflight (CSS Reset)
3
+ *
4
+ * A modern CSS reset based on best practices.
5
+ * Includes accessibility defaults and modern CSS features.
6
+ *
7
+ * Modules: box-sizing, document, typography, tables, forms, lists, media, spacing, accessibility
8
+ * Use @preflight directive to include/exclude modules.
9
+ */
10
+
11
+ @layer base {
12
+ /*! @preflight-module: box-sizing */
13
+ *,
14
+ ::before,
15
+ ::after {
16
+ box-sizing: border-box;
17
+ border-width: 0;
18
+ border-style: solid;
19
+ border-color: var(--color-border, currentColor);
20
+ }
21
+
22
+ /*! @preflight-module-end: box-sizing */
23
+
24
+ /*! @preflight-module: document */
25
+ html,
26
+ :host {
27
+ line-height: 1.5;
28
+ -webkit-text-size-adjust: 100%;
29
+ tab-size: 4;
30
+ font-family: var(
31
+ --font-sans,
32
+ ui-sans-serif,
33
+ system-ui,
34
+ sans-serif,
35
+ "Apple Color Emoji",
36
+ "Segoe UI Emoji",
37
+ "Segoe UI Symbol",
38
+ "Noto Color Emoji"
39
+ );
40
+ font-feature-settings: normal;
41
+ font-variation-settings: normal;
42
+ -webkit-tap-highlight-color: transparent;
43
+ }
44
+
45
+ body {
46
+ margin: 0;
47
+ line-height: inherit;
48
+ }
49
+
50
+ html[data-appearance="light"] {
51
+ color-scheme: light;
52
+ }
53
+
54
+ html[data-appearance="dark"] {
55
+ color-scheme: dark;
56
+ }
57
+
58
+ html[data-appearance="system"],
59
+ html:not([data-appearance]) {
60
+ color-scheme: light;
61
+ }
62
+
63
+ @media (prefers-color-scheme: dark) {
64
+ html[data-appearance="system"],
65
+ html:not([data-appearance]) {
66
+ color-scheme: dark;
67
+ }
68
+ }
69
+ /*! @preflight-module-end: document */
70
+
71
+ /*! @preflight-module: typography */
72
+ hr {
73
+ height: 0;
74
+ color: inherit;
75
+ border-top-width: 1px;
76
+ }
77
+
78
+ abbr:where([title]) {
79
+ text-decoration: underline dotted;
80
+ }
81
+
82
+ h1,
83
+ h2,
84
+ h3,
85
+ h4,
86
+ h5,
87
+ h6 {
88
+ font-size: inherit;
89
+ font-weight: inherit;
90
+ }
91
+
92
+ a {
93
+ color: inherit;
94
+ text-decoration: inherit;
95
+ }
96
+
97
+ b,
98
+ strong {
99
+ font-weight: bolder;
100
+ }
101
+
102
+ code,
103
+ kbd,
104
+ samp,
105
+ pre {
106
+ font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace);
107
+ font-feature-settings: normal;
108
+ font-variation-settings: normal;
109
+ font-size: 1em;
110
+ }
111
+
112
+ small {
113
+ font-size: 80%;
114
+ }
115
+
116
+ sub,
117
+ sup {
118
+ font-size: 75%;
119
+ line-height: 0;
120
+ position: relative;
121
+ vertical-align: baseline;
122
+ }
123
+
124
+ sub {
125
+ bottom: -0.25em;
126
+ }
127
+
128
+ sup {
129
+ top: -0.5em;
130
+ }
131
+ /*! @preflight-module-end: typography */
132
+
133
+ /*! @preflight-module: tables */
134
+ table {
135
+ text-indent: 0;
136
+ border-color: inherit;
137
+ border-collapse: collapse;
138
+ }
139
+ /*! @preflight-module-end: tables */
140
+
141
+ /*! @preflight-module: forms */
142
+ button,
143
+ input,
144
+ optgroup,
145
+ select,
146
+ textarea {
147
+ font-family: inherit;
148
+ font-feature-settings: inherit;
149
+ font-variation-settings: inherit;
150
+ font-size: 100%;
151
+ font-weight: inherit;
152
+ line-height: inherit;
153
+ letter-spacing: inherit;
154
+ color: inherit;
155
+ margin: 0;
156
+ padding: 0;
157
+ }
158
+
159
+ button,
160
+ select {
161
+ text-transform: none;
162
+ }
163
+
164
+ button,
165
+ input:where([type="button"]),
166
+ input:where([type="reset"]),
167
+ input:where([type="submit"]) {
168
+ -webkit-appearance: button;
169
+ background-color: transparent;
170
+ background-image: none;
171
+ }
172
+
173
+ :-moz-focusring {
174
+ outline: auto;
175
+ }
176
+
177
+ :-moz-ui-invalid {
178
+ box-shadow: none;
179
+ }
180
+
181
+ progress {
182
+ vertical-align: baseline;
183
+ }
184
+
185
+ ::-webkit-inner-spin-button,
186
+ ::-webkit-outer-spin-button {
187
+ height: auto;
188
+ }
189
+
190
+ [type="search"] {
191
+ -webkit-appearance: textfield;
192
+ outline-offset: -2px;
193
+ }
194
+
195
+ ::-webkit-search-decoration {
196
+ -webkit-appearance: none;
197
+ }
198
+
199
+ ::-webkit-file-upload-button {
200
+ -webkit-appearance: button;
201
+ font: inherit;
202
+ }
203
+
204
+ summary {
205
+ display: list-item;
206
+ }
207
+
208
+ textarea {
209
+ resize: vertical;
210
+ }
211
+
212
+ ::placeholder {
213
+ opacity: 1;
214
+ }
215
+
216
+ /* Use color-mix for adaptive placeholder colors (Safari 17+, all other modern browsers) */
217
+ @supports (not (-webkit-appearance: -apple-pay-button)) or (contain-intrinsic-size: 1px) {
218
+ ::placeholder {
219
+ color: color-mix(in oklab, currentcolor 50%, transparent);
220
+ }
221
+ }
222
+
223
+ button,
224
+ [role="button"] {
225
+ cursor: pointer;
226
+ }
227
+
228
+ :disabled {
229
+ cursor: default;
230
+ }
231
+ /*! @preflight-module-end: forms */
232
+
233
+ /*! @preflight-module: spacing */
234
+ blockquote,
235
+ dl,
236
+ dd,
237
+ h1,
238
+ h2,
239
+ h3,
240
+ h4,
241
+ h5,
242
+ h6,
243
+ hr,
244
+ figure,
245
+ p,
246
+ pre {
247
+ margin: 0;
248
+ }
249
+
250
+ fieldset {
251
+ margin: 0;
252
+ padding: 0;
253
+ }
254
+
255
+ legend {
256
+ padding: 0;
257
+ }
258
+ /*! @preflight-module-end: spacing */
259
+
260
+ /*! @preflight-module: lists */
261
+ ol,
262
+ ul,
263
+ menu {
264
+ list-style: none;
265
+ margin: 0;
266
+ padding: 0;
267
+ }
268
+ /*! @preflight-module-end: lists */
269
+
270
+ /*! @preflight-module: media */
271
+ img,
272
+ svg,
273
+ video,
274
+ canvas,
275
+ audio,
276
+ iframe,
277
+ embed,
278
+ object {
279
+ display: block;
280
+ vertical-align: middle;
281
+ }
282
+
283
+ img,
284
+ video {
285
+ max-width: 100%;
286
+ height: auto;
287
+ }
288
+
289
+ /* SVG fill inherits text color by default */
290
+ svg:not([fill]) {
291
+ fill: currentColor;
292
+ }
293
+
294
+ [hidden]:where(:not([hidden="until-found"])) {
295
+ display: none !important;
296
+ }
297
+ /*! @preflight-module-end: media */
298
+
299
+ /*! @preflight-module: accessibility */
300
+ /* Focus visible for keyboard accessibility */
301
+ :focus-visible {
302
+ outline: 2px solid var(--color-focus, oklch(55% 0.2 250));
303
+ outline-offset: 2px;
304
+ }
305
+
306
+ /* Remove default focus for mouse users */
307
+ :focus:not(:focus-visible) {
308
+ outline: none;
309
+ }
310
+
311
+ /* Dialog improvements */
312
+ dialog {
313
+ padding: 0;
314
+ background-color: var(--color-surface, white);
315
+ color: inherit;
316
+ }
317
+
318
+ dialog::backdrop {
319
+ background-color: oklch(0% 0 0 / 50%);
320
+ }
321
+
322
+ /* Ensure mark uses theme colors */
323
+ mark {
324
+ background-color: var(--color-highlight, oklch(90% 0.1 90));
325
+ color: inherit;
326
+ }
327
+
328
+ /* Horizontal rule styling */
329
+ hr {
330
+ border-color: var(--color-border, oklch(85% 0 0));
331
+ }
332
+
333
+ /* Selection styling */
334
+ ::selection {
335
+ background-color: var(--color-selection-bg, oklch(85% 0.1 250));
336
+ color: var(--color-selection-fg, inherit);
337
+ }
338
+
339
+ /* Autofill styling */
340
+ input:-webkit-autofill,
341
+ input:-webkit-autofill:hover,
342
+ input:-webkit-autofill:focus,
343
+ textarea:-webkit-autofill,
344
+ textarea:-webkit-autofill:hover,
345
+ textarea:-webkit-autofill:focus,
346
+ select:-webkit-autofill,
347
+ select:-webkit-autofill:hover,
348
+ select:-webkit-autofill:focus {
349
+ -webkit-text-fill-color: inherit;
350
+ -webkit-box-shadow: 0 0 0px 1000px var(--color-surface, white) inset;
351
+ transition: background-color 5000s ease-in-out 0s;
352
+ }
353
+
354
+ /* Ensure file input button matches theme */
355
+ ::file-selector-button {
356
+ font: inherit;
357
+ color: inherit;
358
+ background-color: var(--color-surface-alt, oklch(95% 0 0));
359
+ border: 1px solid var(--color-border, oklch(85% 0 0));
360
+ border-radius: calc(0.5 * var(--spacing, 0.25rem));
361
+ padding-inline: 1rem;
362
+ padding-block: 0.5rem;
363
+ cursor: pointer;
364
+ }
365
+
366
+ ::file-selector-button:hover {
367
+ background-color: var(--color-surface-hover, oklch(92% 0 0));
368
+ }
369
+ /*! @preflight-module-end: accessibility */
370
+ }