keyframekit 1.1.3 → 1.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/README.md +6 -3
- package/docs/.vitepress/components/Playground/Playground.vue +3 -1
- package/docs/.vitepress/config.ts +3 -0
- package/docs/docs/get-started.md +127 -0
- package/docs/docs/index.md +1 -126
- package/docs/docs/public/og-image.png +0 -0
- package/package.json +1 -1
- package/vercel.json +1 -0
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Unlock fine-grained control over your CSS animations with JavaScript.
|
|
4
4
|
|
|
5
|
+
[](/LICENSE) [](https://www.npmjs.com/package/keyframekit)
|
|
6
|
+
|
|
5
7
|
## About
|
|
6
8
|
|
|
7
9
|
The [Web Animations API][2] opens the browser's animation engine to developers and provides unprecedented control and performance when animating on the web. But confusingly, it provides no easy way to use your existing CSS animations with the API. So I wrote a lightweight, typed, spec-compliant library to convert stylesheet keyframes to Web Animations API-compatible animations, letting you play your CSS-defined animations right in JS. [Read more.][3]
|
|
@@ -77,7 +79,7 @@ const rotateSmallAnimKeyframes = KeyframeKit.getStyleSheetKeyframes({
|
|
|
77
79
|
|
|
78
80
|
### Defining animations in JS
|
|
79
81
|
|
|
80
|
-
The `KeyframeEffectParameters` class provides a more convenient way to define your animations in JS than is offered natively.
|
|
82
|
+
The [`KeyframeEffectParameters`][6] class provides a more convenient way to define your animations in JS than is offered natively.
|
|
81
83
|
It's useful for when you want to have all your animation code in one place.
|
|
82
84
|
|
|
83
85
|
```js
|
|
@@ -110,7 +112,7 @@ attachedAnim.play();
|
|
|
110
112
|
```
|
|
111
113
|
|
|
112
114
|
### Full reference
|
|
113
|
-
[See here.][
|
|
115
|
+
[See here.][7]
|
|
114
116
|
|
|
115
117
|
## Typing
|
|
116
118
|
|
|
@@ -126,4 +128,5 @@ This library is fully compatable with native JS, but it also has full spec-compl
|
|
|
126
128
|
[3]: https://benhatsor.medium.com/99573ef4738b
|
|
127
129
|
[4]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API/Using_the_Web_Animations_API
|
|
128
130
|
[5]: https://github.com/WICG/construct-stylesheets/issues/119#issuecomment-588352418
|
|
129
|
-
[6]: https://keyframekit.berryscript.com/reference
|
|
131
|
+
[6]: https://keyframekit.berryscript.com/reference/classes/KeyframeEffectParameters
|
|
132
|
+
[7]: https://keyframekit.berryscript.com/reference
|
|
@@ -62,7 +62,7 @@ const { tabs, activeTab, isLoaded, setEditorRef } = playground(props, previewFra
|
|
|
62
62
|
--border-radius: 8px;
|
|
63
63
|
border-radius: var(--border-radius);
|
|
64
64
|
overflow: hidden;
|
|
65
|
-
margin-bottom: 48px;
|
|
65
|
+
/* margin-bottom: 48px; */
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
@media (max-width: 1000px) {
|
|
@@ -88,11 +88,13 @@ const { tabs, activeTab, isLoaded, setEditorRef } = playground(props, previewFra
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
/*
|
|
91
92
|
@media (min-width: 640px) {
|
|
92
93
|
.playground {
|
|
93
94
|
margin-bottom: 64px;
|
|
94
95
|
}
|
|
95
96
|
}
|
|
97
|
+
*/
|
|
96
98
|
|
|
97
99
|
.editor-pane {
|
|
98
100
|
display: flex;
|
|
@@ -11,6 +11,8 @@ export default defineConfig({
|
|
|
11
11
|
//'reference/:slug*': ':slug*'
|
|
12
12
|
},
|
|
13
13
|
|
|
14
|
+
cleanUrls: true,
|
|
15
|
+
|
|
14
16
|
head: [
|
|
15
17
|
['link', { rel: 'icon', href: '/icon.png' }],
|
|
16
18
|
['meta', { property: 'og:image', content: '/og-image.png' }],
|
|
@@ -41,6 +43,7 @@ export default defineConfig({
|
|
|
41
43
|
// https://vitepress.dev/reference/default-theme-config
|
|
42
44
|
nav: [
|
|
43
45
|
{ text: 'Home', link: '/' },
|
|
46
|
+
{ text: 'Get Started', link: '/get-started' },
|
|
44
47
|
{ text: 'Reference', link: '/reference' }
|
|
45
48
|
],
|
|
46
49
|
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
|
|
2
|
+
# Get Started
|
|
3
|
+
|
|
4
|
+
## About
|
|
5
|
+
|
|
6
|
+
The [Web Animations API][1] opens the browser's animation engine to developers and provides unprecedented control and performance when animating on the web. But confusingly, it provides no easy way to use your existing CSS animations with the API. So I wrote a lightweight, typed, spec-compliant library to convert stylesheet keyframes to Web Animations API-compatible animations, letting you play your CSS-defined animations right in JS. [Read more.][2]
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
::: code-group
|
|
11
|
+
```sh [npm]
|
|
12
|
+
npm install keyframekit
|
|
13
|
+
```
|
|
14
|
+
:::
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
### Playing CSS-defined animations with JS
|
|
19
|
+
|
|
20
|
+
In your CSS:
|
|
21
|
+
```css
|
|
22
|
+
@keyframes rotate-small { ... }
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Then, in JS:
|
|
26
|
+
```js
|
|
27
|
+
import KeyframeKit from 'keyframekit';
|
|
28
|
+
|
|
29
|
+
const documentStyleSheets = await KeyframeKit.getDocumentStyleSheetsOnLoad();
|
|
30
|
+
|
|
31
|
+
// get animation keyframes from the document's stylesheets
|
|
32
|
+
const rotateSmallAnimKeyframes = KeyframeKit.getStyleSheetKeyframes({
|
|
33
|
+
of: 'rotate-small',
|
|
34
|
+
in: documentStyleSheets
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// then, define your animation
|
|
38
|
+
const rotateSmallAnim = rotateSmallAnimKeyframes.toKeyframeEffect({
|
|
39
|
+
duration: 700,
|
|
40
|
+
easing: 'ease'
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// finally, attach it to an element:
|
|
44
|
+
const attachedAnim = rotateSmallAnim.toAnimation({
|
|
45
|
+
target: document.querySelector('.el')
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
attachedAnim.play();
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The primary reason to play your animation with JS is because you get way more control over its playback:
|
|
52
|
+
```js
|
|
53
|
+
attachedAnim.pause();
|
|
54
|
+
attachedAnim.playbackRate = -1;
|
|
55
|
+
const progress = attachedAnim.overallProgress; // 0 to 1 (Baseline newly available)
|
|
56
|
+
await attachedAnim.finished;
|
|
57
|
+
```
|
|
58
|
+
[...and more.][3]
|
|
59
|
+
|
|
60
|
+
### Importing animations directly from a CSS file
|
|
61
|
+
|
|
62
|
+
Instead of getting an animation from the document's stylesheets, you can also import it directly from a CSS file.
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
import KeyframeKit from 'keyframekit';
|
|
66
|
+
|
|
67
|
+
const styleSheet = await KeyframeKit.importStyleSheet('./styles.css');
|
|
68
|
+
|
|
69
|
+
// get animation keyframes from stylesheet
|
|
70
|
+
const rotateSmallAnimKeyframes = KeyframeKit.getStyleSheetKeyframes({
|
|
71
|
+
of: 'rotate-small',
|
|
72
|
+
in: styleSheet
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
> Note: This won't resolve any `@import` rules in the stylesheet. [See more.][4]
|
|
77
|
+
|
|
78
|
+
### Defining animations in JS
|
|
79
|
+
|
|
80
|
+
The [`KeyframeEffectParameters`](reference/classes/KeyframeEffectParameters.md) class provides a more convenient way to define your animations in JS than is offered natively.
|
|
81
|
+
It's useful for when you want to have all your animation code in one place.
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
import { KeyframeEffectParameters } from 'keyframekit';
|
|
85
|
+
|
|
86
|
+
// define your animation
|
|
87
|
+
const linkTextHoverAnim = new KeyframeEffectParameters({
|
|
88
|
+
|
|
89
|
+
keyframes: {
|
|
90
|
+
// 0 to 1. equivalent to CSS keyframe percentage values:
|
|
91
|
+
offset: [0, 0.499, 0.5, 1],
|
|
92
|
+
// respective CSS property keyframes:
|
|
93
|
+
clipPath: ['inset(0 0 0 0)', 'inset(100% 0 0 0)', 'inset(0 0 100% 0)', 'inset(0 0 0 0)'],
|
|
94
|
+
top: ['0', '-20px', '20px', '0']
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
options: {
|
|
98
|
+
duration: 700,
|
|
99
|
+
easing: 'ease'
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// then, attach it to an element:
|
|
105
|
+
const attachedAnim = linkTextHoverAnim.toAnimation({
|
|
106
|
+
target: document.querySelector('.link')
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
attachedAnim.play();
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Full reference
|
|
113
|
+
[See here.](/reference/index.md)
|
|
114
|
+
|
|
115
|
+
## Typing
|
|
116
|
+
|
|
117
|
+
This library is fully compatable with native JS, but it also has full spec-compliant type support, including declaration files and source maps.
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
[MIT](https://github.com/benhatsor/KeyframeKit/blob/main/LICENSE)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
[1]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API
|
|
125
|
+
[2]: https://benhatsor.medium.com/99573ef4738b
|
|
126
|
+
[3]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API/Using_the_Web_Animations_API
|
|
127
|
+
[4]: https://github.com/WICG/construct-stylesheets/issues/119#issuecomment-588352418
|
package/docs/docs/index.md
CHANGED
|
@@ -8,135 +8,10 @@ hero:
|
|
|
8
8
|
actions:
|
|
9
9
|
- theme: brand
|
|
10
10
|
text: Get Started
|
|
11
|
-
link:
|
|
11
|
+
link: /get-started
|
|
12
12
|
- theme: alt
|
|
13
13
|
text: Reference
|
|
14
14
|
link: /reference
|
|
15
15
|
---
|
|
16
16
|
|
|
17
17
|
<Playground/>
|
|
18
|
-
|
|
19
|
-
## About
|
|
20
|
-
|
|
21
|
-
The [Web Animations API][2] opens the browser's animation engine to developers and provides unprecedented control and performance when animating on the web. But confusingly, it provides no easy way to use your existing CSS animations with the API. So I wrote a lightweight, typed, spec-compliant library to convert stylesheet keyframes to Web Animations API-compatible animations, letting you play your CSS-defined animations right in JS. [Read more.][3]
|
|
22
|
-
|
|
23
|
-
## Installation
|
|
24
|
-
|
|
25
|
-
::: code-group
|
|
26
|
-
```sh [npm]
|
|
27
|
-
npm install keyframekit
|
|
28
|
-
```
|
|
29
|
-
:::
|
|
30
|
-
|
|
31
|
-
## Usage
|
|
32
|
-
|
|
33
|
-
### Playing CSS-defined animations with JS
|
|
34
|
-
|
|
35
|
-
In your CSS:
|
|
36
|
-
```css
|
|
37
|
-
@keyframes rotate-small { ... }
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
Then, in JS:
|
|
41
|
-
```js
|
|
42
|
-
import KeyframeKit from 'keyframekit';
|
|
43
|
-
|
|
44
|
-
const documentStyleSheets = await KeyframeKit.getDocumentStyleSheetsOnLoad();
|
|
45
|
-
|
|
46
|
-
// get animation keyframes from the document's stylesheets
|
|
47
|
-
const rotateSmallAnimKeyframes = KeyframeKit.getStyleSheetKeyframes({
|
|
48
|
-
of: 'rotate-small',
|
|
49
|
-
in: documentStyleSheets
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
// then, define your animation
|
|
53
|
-
const rotateSmallAnim = rotateSmallAnimKeyframes.toKeyframeEffect({
|
|
54
|
-
duration: 700,
|
|
55
|
-
easing: 'ease'
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// finally, attach it to an element:
|
|
59
|
-
const attachedAnim = rotateSmallAnim.toAnimation({
|
|
60
|
-
target: document.querySelector('.el')
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
attachedAnim.play();
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
The primary reason to play your animation with JS is because you get way more control over its playback:
|
|
67
|
-
```js
|
|
68
|
-
attachedAnim.pause();
|
|
69
|
-
attachedAnim.playbackRate = -1;
|
|
70
|
-
const progress = attachedAnim.overallProgress; // 0 to 1 (Baseline newly available)
|
|
71
|
-
await attachedAnim.finished;
|
|
72
|
-
```
|
|
73
|
-
[...and more.][3]
|
|
74
|
-
|
|
75
|
-
### Importing animations directly from a CSS file
|
|
76
|
-
|
|
77
|
-
Instead of getting an animation from the document's stylesheets, you can also import it directly from a CSS file.
|
|
78
|
-
|
|
79
|
-
```js
|
|
80
|
-
import KeyframeKit from 'keyframekit';
|
|
81
|
-
|
|
82
|
-
const styleSheet = await KeyframeKit.importStyleSheet('./styles.css');
|
|
83
|
-
|
|
84
|
-
// get animation keyframes from stylesheet
|
|
85
|
-
const rotateSmallAnimKeyframes = KeyframeKit.getStyleSheetKeyframes({
|
|
86
|
-
of: 'rotate-small',
|
|
87
|
-
in: styleSheet
|
|
88
|
-
});
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
> Note: This won't resolve any `@import` rules in the stylesheet. [See more.][4]
|
|
92
|
-
|
|
93
|
-
### Defining animations in JS
|
|
94
|
-
|
|
95
|
-
The `KeyframeEffectParameters` class provides a more convenient way to define your animations in JS than is offered natively.
|
|
96
|
-
It's useful for when you want to have all your animation code in one place.
|
|
97
|
-
|
|
98
|
-
```js
|
|
99
|
-
import { KeyframeEffectParameters } from 'keyframekit';
|
|
100
|
-
|
|
101
|
-
// define your animation
|
|
102
|
-
const linkTextHoverAnim = new KeyframeEffectParameters({
|
|
103
|
-
|
|
104
|
-
keyframes: {
|
|
105
|
-
// 0 to 1. equivalent to CSS keyframe percentage values:
|
|
106
|
-
offset: [0, 0.499, 0.5, 1],
|
|
107
|
-
// respective CSS property keyframes:
|
|
108
|
-
clipPath: ['inset(0 0 0 0)', 'inset(100% 0 0 0)', 'inset(0 0 100% 0)', 'inset(0 0 0 0)'],
|
|
109
|
-
top: ['0', '-20px', '20px', '0']
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
options: {
|
|
113
|
-
duration: 700,
|
|
114
|
-
easing: 'ease'
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
// then, attach it to an element:
|
|
120
|
-
const attachedAnim = linkTextHoverAnim.toAnimation({
|
|
121
|
-
target: document.querySelector('.link')
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
attachedAnim.play();
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
### Full reference
|
|
128
|
-
[See here.](/reference/index.md)
|
|
129
|
-
|
|
130
|
-
## Typing
|
|
131
|
-
|
|
132
|
-
This library is fully compatable with native JS, but it also has full spec-compliant type support, including declaration files and source maps.
|
|
133
|
-
|
|
134
|
-
## License
|
|
135
|
-
|
|
136
|
-
[MIT](https://github.com/benhatsor/KeyframeKit/blob/main/LICENSE)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
[1]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API
|
|
140
|
-
[2]: https://benhatsor.medium.com/99573ef4738b
|
|
141
|
-
[3]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API/Using_the_Web_Animations_API
|
|
142
|
-
[4]: https://github.com/WICG/construct-stylesheets/issues/119#issuecomment-588352418
|
|
Binary file
|
package/package.json
CHANGED