ruscus 0.0.0-stage → 0.0.2

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Justin Locsei
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,362 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <img src="./assets/logo.svg" width="500" alt="Ruscus">
3
+ </p>
2
4
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
5
+ <br>
6
+
7
+ <p align="center">
8
+ Ruscus is a TypeScript library that provides a rich vocabulary for defining component styles, with child elements, variants, and nested and global styles as first-class concerns. It enables the reuse of styles through traits and shared media queries, and can be used with any view layer that allows you to apply class names to DOM elements.
9
+ </p>
10
+
11
+ ---
12
+
13
+ [![Verify](https://github.com/justinlocsei/ruscus/actions/workflows/verify.yml/badge.svg)](https://github.com/justinlocsei/ruscus/actions/workflows/verify.yml)
14
+ [![npm version](https://img.shields.io/npm/v/ruscus.svg)](https://www.npmjs.com/package/ruscus)
15
+ [![License](https://img.shields.io/npm/l/ruscus.svg)](https://github.com/justinlocsei/ruscus/blob/main/LICENSE)
16
+
17
+
18
+ <!-- <toc> -->
19
+ - [Installation](#installation)
20
+ - [Getting Started](#getting-started)
21
+ - [Components](#components)
22
+ - [Elements](#elements)
23
+ - [Variants](#variants)
24
+ - [Nested Styles](#nested-styles)
25
+ - [Global Styles](#global-styles)
26
+ - [Identifiers](#identifiers)
27
+ - [Traits](#traits)
28
+ - [Queries](#queries)
29
+ - [Integration](#integration)
30
+ - [Vite](#vite)
31
+ - [Why the Name?](#why-the-name)
32
+ <!-- </toc> -->
33
+
34
+ ## Installation
35
+
36
+ ```sh
37
+ npm install ruscus
38
+ ```
39
+
40
+ ## Getting Started
41
+
42
+ Define component styles in a `card.ts` file:
43
+
44
+ ```ts
45
+ import { component } from 'ruscus';
46
+
47
+ export default component('card')
48
+ .css({
49
+ display: 'block',
50
+ padding: '1rem'
51
+ })
52
+ .elements(e => ({
53
+ title: e({
54
+ fontWeight: 'bold'
55
+ })
56
+ }))
57
+ .variants(s => ({
58
+ compact: s({ padding: '0.5rem' }),
59
+ featured: s({ border: '2px solid currentColor' })
60
+ }))
61
+ .apply();
62
+ ```
63
+
64
+ Apply the styles to your component in a `card.tsx` file:
65
+
66
+ ```tsx
67
+ import C from './card.ts';
68
+
69
+ export function Card({ compact }: { compact: boolean }) {
70
+ return (
71
+ <article className={card.root(compact && 'compact')}>
72
+ <h1 className={C.title}>
73
+ A card
74
+ </h1>
75
+ </article>
76
+ );
77
+ }
78
+ ```
79
+
80
+ The styles imported from `card.ts` are a map of element labels to class names that are present in the CSS generated through [bundler integration](#integration), allowing them to be used with any view layer.
81
+
82
+ ## Components
83
+
84
+ All component styles begin with a call to the `component` function, which requires a unique ID. Ruscus uses a fluent API for defining component styles, allowing you to chain calls to definition methods before exposing the component's styles as class names via the `.apply` method.
85
+
86
+ ```ts
87
+ import { component } from 'ruscus';
88
+
89
+ export default component('button')
90
+ .css({ border: 0, cursor: 'pointer' })
91
+ .apply();
92
+ ```
93
+
94
+ Component styles should be the default export of a `.ts` file. Style discovery happens via bundler integration that looks at the module graph, so there is no need for a particular file suffix. If you wish to use a convention like `.styles.ts`, however, you're more than welcome to.
95
+
96
+ ## Elements
97
+
98
+ Components define child elements via the `.elements` method. Elements can themselves have child elements, allowing for deeply nested trees.
99
+
100
+ ```ts
101
+ import { component } from 'ruscus';
102
+
103
+ export default component('card')
104
+ .elements(e => ({
105
+ body: e({ padding: '1rem' }),
106
+ footer: e({ borderTop: '1px solid currentColor' }),
107
+ header: e().children(() => ({
108
+ icon: e({ marginRight: '0.5rem' }),
109
+ title: e({ fontWeight: '700' })
110
+ }))
111
+ }))
112
+ .apply();
113
+ ```
114
+
115
+ A component's elements are known at compile time, allowing for safe access to each element's class name in the view layer:
116
+
117
+ ```ts
118
+ import C from './card.ts';
119
+
120
+ // Valid
121
+ C.body
122
+ C.footer
123
+ C.header.root
124
+ C.header.icon
125
+
126
+ // Type error
127
+ C.missing
128
+ C.header.missing
129
+ ```
130
+
131
+ ## Variants
132
+
133
+ Variants can be defined on the component root or on any element:
134
+
135
+ ```ts
136
+ import { component } from 'ruscus';
137
+
138
+ export default component('card')
139
+ .elements(e => ({
140
+ body: e().variants(s => ({
141
+ active: s({ background: 'yellow' }),
142
+ compact: s({ padding: '0.5rem' })
143
+ }))
144
+ }))
145
+ .variants(s => ({
146
+ featured: s({ boxShadow: '0 0 0 2px currentColor' })
147
+ }))
148
+ .apply();
149
+ ```
150
+
151
+ Variants are applied in the view layer via functions on the element or component with variants. These functions take variant names and falsy or truthy values which can be used to conditionally apply the named variant:
152
+
153
+ ```tsx
154
+ import C from './card.ts';
155
+
156
+ export function Card({
157
+ active,
158
+ compact,
159
+ featured
160
+ }: {
161
+ active?: boolean;
162
+ compact?: boolean;
163
+ featured?: boolean;
164
+ }) {
165
+ return (
166
+ <article className={C.root(featured && 'featured')}>
167
+ <div className={C.body(active && 'active', compact && 'compact')}>
168
+ A card
169
+ </div>
170
+ </article>
171
+ );
172
+ }
173
+ ```
174
+
175
+ ## Nested Styles
176
+
177
+ Use the `.nested` method for selectors that are relative to a component or element. A selector can use `&` to refer to the current node, or omit it to generate a selector whose parent is the class name of the component or element:
178
+
179
+ ```ts
180
+ import { component } from 'ruscus';
181
+
182
+ export default component('button')
183
+ .css({ color: 'black' })
184
+ .elements(e => ({
185
+ button: e({
186
+ color: 'red'
187
+ }).nested(s => ({
188
+ '&:active': s({ color: 'green' })
189
+ }))
190
+ }))
191
+ .nested((s, { els }) => ({
192
+ a: s({ color: 'blue' }),
193
+ [`&:hover ${els.button}`]: s({ textDecoration: 'underline' }),
194
+ }))
195
+ .apply();
196
+ ```
197
+
198
+ The provider function can reference the component's variants, allowing styles to be applied to combinations of variants:
199
+
200
+ ```ts
201
+ import { component } from 'ruscus';
202
+
203
+ export default component('card')
204
+ .variants(s => ({
205
+ compact: s(),
206
+ featured: s()
207
+ }))
208
+ .nested((s, { variants }) => ({
209
+ [variants('compact', 'featured')]: s({
210
+ border: '2px solid currentColor'
211
+ })
212
+ }))
213
+ .apply();
214
+ ```
215
+
216
+ ## Global Styles
217
+
218
+ Use the `.global` method for selectors that are not scoped to the component root. This is useful for document-level rules and other intentionally shared CSS:
219
+
220
+ ```ts
221
+ import { component } from 'ruscus';
222
+
223
+ export default component('editor')
224
+ .global(s => ({
225
+ ':root': s({ colorScheme: 'light dark' }),
226
+ html: s({ fontFamily: 'system-ui, sans-serif' })
227
+ }))
228
+ .apply();
229
+ ```
230
+
231
+ Global definitions can also contain nested rules such as [media queries](#queries).
232
+
233
+ ## Identifiers
234
+
235
+ Identifiers are component-specific values that are defined via the `.identifiers` method. String identifiers become class-scoped names, while variable identifiers become scoped CSS custom properties:
236
+
237
+ ```ts
238
+ import { component } from 'ruscus';
239
+
240
+ export default component('card')
241
+ .identifiers({
242
+ animation: 'string',
243
+ spacing: 'variable'
244
+ })
245
+ .elements((e, { ids }) => ({
246
+ body: e({ animation: `${ids.animation} 500ms` }),
247
+ items: e({
248
+ display: 'flex',
249
+ gap: `var(${ids.spacing})`
250
+ })
251
+ }))
252
+ .global((s, { ids }) => ({
253
+ [`@keyframes ${ids.animation}`]: s.rules({
254
+ from: s({ opacity: 0 }),
255
+ to: s({ opacity: 1 })
256
+ })
257
+ }))
258
+ .apply();
259
+ ```
260
+
261
+ To reference an identifier in the view layer, use the `identifiers` function:
262
+
263
+ ```tsx
264
+ import C from './card.ts';
265
+ import { identifiers } from 'ruscus';
266
+
267
+ const ids = identifiers(C);
268
+
269
+ export function Card() {
270
+ return (
271
+ <article className={C.root} style={{ [ids.spacing]: '0.75rem' }}>
272
+ <div className={C.items}>
273
+ <div className={C.body}>A card</div>
274
+ </div>
275
+ </article>
276
+ );
277
+ }
278
+ ```
279
+
280
+ ## Traits
281
+
282
+ Traits provide a way to share styles across components and elements. They are defined once using the `trait` function, and can be applied to components and elements with the `.is` method:
283
+
284
+ ```ts
285
+ import { component, trait } from 'ruscus';
286
+
287
+ const interactive = trait(s =>
288
+ s({ cursor: 'pointer' }).nested({
289
+ '&:hover': s({ opacity: '0.8' })
290
+ })
291
+ );
292
+
293
+ export default component('link')
294
+ .is(interactive)
295
+ .apply();
296
+ ```
297
+
298
+ ## Queries
299
+
300
+ The `queries` function maps internal labels to CSS at-rule queries:
301
+
302
+ ```ts
303
+ import { queries } from 'ruscus';
304
+
305
+ export const responsive = queries({
306
+ narrow: '@container card (min-width: 400px)',
307
+ wide: '@media (min-width: 768px)',
308
+ });
309
+ ```
310
+
311
+ To use queries to style a component, apply them in a `.global` block:
312
+
313
+ ```ts
314
+ import { component } from 'ruscus';
315
+ import { responsive } from './helpers.ts';
316
+
317
+ export default component('card')
318
+ .elements(e => ({
319
+ body: e(),
320
+ title: e()
321
+ }))
322
+ .global((s, { els }) => responsive({
323
+ narrow: {
324
+ [els.title]: s({ fontSize: '0.8em' }),
325
+ },
326
+ wide: {
327
+ [els.body]: s({ padding: '2rem' })
328
+ }
329
+ }))
330
+ .apply();
331
+ ```
332
+
333
+ Each key from the initial `queries` call can be provided to the applicator function. Queries may be omitted, and any unknown queries will result in a type error.
334
+
335
+ ## Integration
336
+
337
+ Ruscus provides a framework for defining component styles and structure without taking a stance on how those styles are applied to your app. Integrations connect the generated CSS to a build tool or framework.
338
+
339
+ ### Vite
340
+
341
+ Install Vite alongside Ruscus:
342
+
343
+ ```sh
344
+ npm install vite
345
+ ```
346
+
347
+ Add the Ruscus plugin to serve CSS during development and include it in production builds to your Vite config:
348
+
349
+ ```ts
350
+ import { defineConfig } from 'vite';
351
+ import ruscus from 'ruscus/vite';
352
+
353
+ export default defineConfig({
354
+ plugins: [ruscus()]
355
+ });
356
+ ```
357
+
358
+ All style files that define a default export of an applied component and are included in the module graph for your entry point will be used to generate component CSS.
359
+
360
+ ## Why the Name?
361
+
362
+ In [floristry](https://www.instagram.com/justinlocsei/), ruscus is a common foliage that provides structure without calling too much attention to itself.