Skip to content

Commit 8610365

Browse files
docs(spark_css): update README with undocumented features
Add documentation for filters, transforms, shadows, gradients, backgrounds, border radius shorthand, flex shorthand, font stacks, outlines, cursors, global keywords, transitions, modern viewport units, and component style registry. Also fix incorrect borderRadius type in the example (CssLength -> CssBorderRadius).
1 parent 25ba555 commit 8610365

1 file changed

Lines changed: 277 additions & 3 deletions

File tree

packages/spark_css/README.md

Lines changed: 277 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ A type-safe CSS style system for the Spark framework.
66

77
## Features
88

9-
- **Type-Safe CSS Values**: Sealed classes for colors, lengths, spacing, display, position, flexbox, typography, borders, transitions, and more.
9+
- **Type-Safe CSS Values**: Sealed classes for colors, lengths, spacing, display, position, flexbox, typography, borders, transitions, filters, transforms, shadows, cursors, backgrounds, and more.
1010
- **Stylesheet API**: `Style.typed` for individual rule sets and `css()` helper for multi-selector stylesheets.
11-
- **CSS Shorthand Support**: `CssSpacing` handles 1, 2, 3, or 4 value shorthand for margin and padding.
11+
- **CSS Shorthand Support**: `CssSpacing` and `CssBorderRadius` handle 1–4 value shorthand for margin, padding, and border-radius.
1212
- **CSS Functions**: Support for `calc()`, `min()`, `max()`, `clamp()`, and `fit-content()`.
1313
- **CSS Variables**: Every value type supports `variable()` for CSS custom properties.
14+
- **Global Keywords**: Every value type supports `global()` for `inherit`, `initial`, `unset`, `revert`, and `revert-layer`.
15+
- **Filters & Transforms**: Full `CssFilter` and `CssTransform` APIs with composition support.
16+
- **Gradients & Backgrounds**: Linear and radial gradients, plus typed background-size, position, repeat, clip, origin, and attachment.
17+
- **Shadows**: `CssBoxShadow` and `CssTextShadow` with multi-shadow support.
1418
- **Automatic Minification**: CSS output is minified in production builds via the `dart.vm.product` flag.
19+
- **Component Style Registry**: Server-side style deduplication via `componentStyles`.
1520
- **Escape Hatches**: `raw()` factories and `.add()` method for properties not yet covered by typed constructors.
1621
- **Zero Dependencies**: Pure Dart package with no runtime dependencies.
1722

@@ -38,7 +43,7 @@ final style = Style.typed(
3843
display: CssDisplay.flex,
3944
padding: CssSpacing.all(CssLength.px(16)),
4045
backgroundColor: CssColor.hex('f5f5f5'),
41-
borderRadius: CssLength.px(8),
46+
borderRadius: CssBorderRadius.all(CssLength.px(8)),
4247
);
4348
4449
print(style.toCss());
@@ -85,6 +90,29 @@ margin: CssSpacing.trbl(
8590
CssLength.px(30),
8691
CssLength.px(40),
8792
),
93+
94+
// Named parameters for specific sides
95+
margin: CssSpacing.sides(top: CssLength.px(10), left: CssLength.px(20)),
96+
```
97+
98+
### Border Radius Shorthand
99+
100+
`CssBorderRadius` follows the same shorthand pattern:
101+
102+
```dart
103+
// Single value (all corners)
104+
borderRadius: CssBorderRadius.all(CssLength.px(8)),
105+
106+
// Two values (topLeft+bottomRight | topRight+bottomLeft)
107+
borderRadius: CssBorderRadius.symmetric(CssLength.px(8), CssLength.px(4)),
108+
109+
// Four values (topLeft | topRight | bottomRight | bottomLeft)
110+
borderRadius: CssBorderRadius.trbl(
111+
CssLength.px(8),
112+
CssLength.px(4),
113+
CssLength.px(8),
114+
CssLength.px(4),
115+
),
88116
```
89117

90118
### CSS Variables
@@ -98,6 +126,241 @@ Style.typed(
98126
)
99127
```
100128

129+
### Global Keywords
130+
131+
Every value type supports CSS global keywords via `CssGlobal`:
132+
133+
```dart
134+
Style.typed(
135+
display: CssDisplay.global(CssGlobal.inherit),
136+
color: CssColor.global(CssGlobal.unset),
137+
)
138+
```
139+
140+
Available globals: `inherit`, `initial`, `unset`, `revert`, `revertLayer`.
141+
142+
### Filters
143+
144+
`CssFilter` supports all CSS filter functions:
145+
146+
```dart
147+
Style.typed(
148+
filter: CssFilter.blur(CssLength.px(4)),
149+
)
150+
151+
// Compose multiple filters
152+
Style.typed(
153+
filter: CssFilter.compose([
154+
CssFilter.grayscalePercent(50),
155+
CssFilter.blur(CssLength.px(2)),
156+
]),
157+
)
158+
159+
// Backdrop filter
160+
Style.typed(
161+
backdropFilter: CssFilter.blur(CssLength.px(10)),
162+
)
163+
```
164+
165+
Available filters: `blur`, `brightness`, `contrast`, `dropShadow`, `grayscale`, `hueRotate`, `invert`, `opacity`, `saturate`, `sepia`. Each has both unitless and percent variants (e.g. `brightness` / `brightnessPercent`).
166+
167+
### Transforms
168+
169+
`CssTransform` supports all 2D transform functions:
170+
171+
```dart
172+
Style.typed(
173+
transform: CssTransform.rotate(CssAngle.deg(45)),
174+
)
175+
176+
// Compose multiple transforms
177+
Style.typed(
178+
transform: CssTransform.list([
179+
CssTransform.translate(CssLength.px(10), CssLength.px(20)),
180+
CssTransform.scale(1.5),
181+
CssTransform.rotate(CssAngle.deg(45)),
182+
]),
183+
)
184+
```
185+
186+
Available transforms: `translate`, `translateX`, `translateY`, `scale`, `scaleX`, `scaleY`, `rotate`, `skew`, `skewX`, `skewY`, `matrix`.
187+
188+
### Shadows
189+
190+
`CssBoxShadow` and `CssTextShadow` support single and multiple shadows:
191+
192+
```dart
193+
// Box shadow
194+
Style.typed(
195+
boxShadow: CssBoxShadow(
196+
x: CssLength.px(0),
197+
y: CssLength.px(4),
198+
blur: CssLength.px(8),
199+
color: CssColor.rgba(0, 0, 0, 0.1),
200+
),
201+
)
202+
203+
// Multiple box shadows
204+
Style.typed(
205+
boxShadow: CssBoxShadow.multiple([
206+
CssBoxShadow(
207+
x: CssLength.px(0),
208+
y: CssLength.px(2),
209+
blur: CssLength.px(4),
210+
color: CssColor.rgba(0, 0, 0, 0.1),
211+
),
212+
CssBoxShadow(
213+
x: CssLength.px(0),
214+
y: CssLength.px(8),
215+
blur: CssLength.px(16),
216+
color: CssColor.rgba(0, 0, 0, 0.1),
217+
inset: true,
218+
),
219+
]),
220+
)
221+
222+
// Text shadow
223+
Style.typed(
224+
textShadow: CssTextShadow(
225+
x: CssLength.px(1),
226+
y: CssLength.px(1),
227+
blur: CssLength.px(2),
228+
color: CssColor.rgba(0, 0, 0, 0.3),
229+
),
230+
)
231+
```
232+
233+
### Gradients & Backgrounds
234+
235+
`CssBackgroundImage` supports linear and radial gradients:
236+
237+
```dart
238+
// Linear gradient
239+
Style.typed(
240+
backgroundImage: CssBackgroundImage.linearGradient(
241+
direction: CssGradientDirection.toRight,
242+
stops: [
243+
CssGradientStop(CssColor.hex('ff0000')),
244+
CssGradientStop(CssColor.hex('0000ff')),
245+
],
246+
),
247+
)
248+
249+
// Radial gradient with stop offsets
250+
Style.typed(
251+
backgroundImage: CssBackgroundImage.radialGradient(
252+
shape: CssRadialShape.circle,
253+
stops: [
254+
CssGradientStop(CssColor.hex('ff0000'), CssLength.percent(0)),
255+
CssGradientStop(CssColor.hex('0000ff'), CssLength.percent(100)),
256+
],
257+
),
258+
)
259+
```
260+
261+
Typed background properties: `backgroundSize`, `backgroundPosition`, `backgroundRepeat`, `backgroundClip`, `backgroundOrigin`, `backgroundAttachment`.
262+
263+
### Transitions
264+
265+
`CssTransition` supports single and multiple transitions:
266+
267+
```dart
268+
Style.typed(
269+
transition: CssTransition.simple('opacity', '200ms', CssTimingFunction.easeInOut),
270+
)
271+
272+
// Multiple transitions
273+
Style.typed(
274+
transition: CssTransition.multiple([
275+
CssTransition.simple('opacity', '200ms', CssTimingFunction.ease),
276+
CssTransition.simple('transform', '300ms', CssTimingFunction.easeOut),
277+
]),
278+
)
279+
280+
// Custom timing function
281+
CssTimingFunction.cubicBezier(0.4, 0, 0.2, 1)
282+
```
283+
284+
### Flex Shorthand
285+
286+
`CssFlexShorthand` provides the `flex` shorthand with smart validation:
287+
288+
```dart
289+
// flex: auto
290+
Style.typed(flex: CssFlexShorthand.auto)
291+
292+
// flex: 1 (grow only)
293+
Style.typed(flex: CssFlexShorthand(grow: 1))
294+
295+
// flex: 1 0 auto (grow, shrink, basis)
296+
Style.typed(flex: CssFlexShorthand(grow: 1, shrink: 0, basis: CssLength.auto))
297+
```
298+
299+
### Font Families
300+
301+
`CssFontFamily` supports named fonts, generic families, and font stacks:
302+
303+
```dart
304+
// Generic family
305+
Style.typed(fontFamily: CssFontFamily.sansSerif)
306+
307+
// Named font
308+
Style.typed(fontFamily: CssFontFamily.named('Inter'))
309+
310+
// Font stack with fallbacks
311+
Style.typed(
312+
fontFamily: CssFontFamily.stack([
313+
CssFontFamily.named('Inter'),
314+
CssFontFamily.named('Helvetica'),
315+
CssFontFamily.sansSerif,
316+
]),
317+
)
318+
```
319+
320+
### Outline
321+
322+
`CssOutline` provides the outline shorthand:
323+
324+
```dart
325+
Style.typed(
326+
outline: CssOutline(
327+
width: CssLength.px(2),
328+
style: CssBorderStyle.solid,
329+
color: CssColor.hex('0066ff'),
330+
),
331+
outlineOffset: CssLength.px(2),
332+
)
333+
```
334+
335+
### Cursors
336+
337+
`CssCursor` covers all standard CSS cursors plus custom URL cursors:
338+
339+
```dart
340+
Style.typed(cursor: CssCursor.pointer)
341+
342+
// Custom cursor with fallback
343+
Style.typed(
344+
cursor: CssCursor.url('custom.cur', fallback: CssCursor.pointer),
345+
)
346+
```
347+
348+
### Modern Viewport Units
349+
350+
`CssLength` supports modern viewport units alongside classic ones:
351+
352+
```dart
353+
// Dynamic viewport units
354+
height: CssLength.dvh(100),
355+
width: CssLength.dvw(100),
356+
357+
// Small viewport units
358+
height: CssLength.svh(100),
359+
360+
// Large viewport units
361+
height: CssLength.lvh(100),
362+
```
363+
101364
### Custom Properties
102365

103366
For properties not covered by the typed constructors, use `.add()`:
@@ -109,6 +372,17 @@ final style = Style.typed(
109372
style.add('grid-template-columns', 'repeat(3, 1fr)');
110373
```
111374

375+
### Component Style Registry
376+
377+
For server-side rendering, `componentStyles` provides style deduplication:
378+
379+
```dart
380+
componentStyles.register('my-button', buttonStyles.toCss());
381+
382+
// Later, retrieve registered CSS
383+
final css = componentStyles.get('my-button');
384+
```
385+
112386
## Contributing
113387

114388
This package is part of the Spark framework. Contributions are welcome at [https://github.com/KLEAK-Development/spark](https://github.com/KLEAK-Development/spark).

0 commit comments

Comments
 (0)