@mochi-css/vanilla 0.1.0 → 1.1.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/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Mochi-CSS/vanilla
2
2
 
3
- This package is part of the [Mochi-CSS project](https://github.com/Niikelion/mochi-css). It provides type-safe CSS-in-JS styling functions with static extraction support, allowing you to write styles in TypeScript that get extracted to plain CSS at build time.
3
+ This package is part of the [Mochi-CSS project](https://github.com/Niikelion/mochi-css).
4
+ It provides type-safe CSS-in-JS styling functions with static extraction support, allowing you to write styles in TypeScript that get extracted to plain CSS at build time.
4
5
 
5
6
  ## Functions
6
7
 
@@ -18,7 +19,7 @@ const buttonStyles = css({
18
19
  })
19
20
 
20
21
  // Use in JSX
21
- <button className={buttonStyles}>Click me</button>
22
+ const button = <button className={buttonStyles}>Click me</button>
22
23
  ```
23
24
 
24
25
  Output of the `css` function is also a valid style definition, so you can split your styles:
@@ -358,3 +359,63 @@ const buttonStyle = css({
358
359
  Tokens can be used in two ways:
359
360
  - **As values**: Use the token directly (e.g., `backgroundColor: buttonColor`) to reference the CSS variable
360
361
  - **As keys**: Use `token.variable` (e.g., `[buttonColor.variable]: primaryColor`) to assign a value to the CSS variable
362
+
363
+ ## Keyframes
364
+
365
+ The `keyframes` function lets you define CSS animations using the same type-safe syntax as style definitions.
366
+
367
+ ### Basic Usage
368
+
369
+ Define animation stops using `from`/`to` or percentage keys:
370
+
371
+ ```ts
372
+ import { keyframes, css } from "@mochi-css/vanilla"
373
+
374
+ const fadeIn = keyframes({
375
+ from: { opacity: 0 },
376
+ to: { opacity: 1 }
377
+ })
378
+
379
+ const fadeInStyle = css({
380
+ animation: `${fadeIn} 0.3s ease`
381
+ })
382
+ ```
383
+
384
+ ### Percentage Stops
385
+
386
+ For more control over animation timing, use percentage-based stops:
387
+
388
+ ```ts
389
+ import { keyframes, css } from "@mochi-css/vanilla"
390
+
391
+ const bounce = keyframes({
392
+ "0%": { transform: "translateY(0)" },
393
+ "50%": { transform: "translateY(-20px)" },
394
+ "100%": { transform: "translateY(0)" }
395
+ })
396
+
397
+ const bouncingElement = css({
398
+ animation: `${bounce} 1s ease-in-out infinite`
399
+ })
400
+ ```
401
+
402
+ ### Multiple Properties
403
+
404
+ Each stop can contain multiple CSS properties with auto-units:
405
+
406
+ ```ts
407
+ import { keyframes } from "@mochi-css/vanilla"
408
+
409
+ const grow = keyframes({
410
+ from: {
411
+ opacity: 0,
412
+ transform: "scale(0.5)",
413
+ fontSize: 12 // becomes 12px
414
+ },
415
+ to: {
416
+ opacity: 1,
417
+ transform: "scale(1)",
418
+ fontSize: 24 // becomes 24px
419
+ }
420
+ })
421
+ ```