keyframekit 1.0.7 → 1.0.9

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.
Files changed (36) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +129 -126
  3. package/dist/KeyframeKit.d.ts +138 -138
  4. package/dist/KeyframeKit.js +293 -293
  5. package/docs/.vitepress/components/Playground/Playground.js +242 -242
  6. package/docs/.vitepress/components/Playground/Playground.vue +206 -206
  7. package/docs/.vitepress/components/Playground/defaultExample.js +175 -175
  8. package/docs/.vitepress/components/Playground/interFont.js +14 -14
  9. package/docs/.vitepress/components/Playground/themes/githubDark.js +401 -401
  10. package/docs/.vitepress/components/Playground/themes/githubLight.js +398 -398
  11. package/docs/.vitepress/components/Playground/themes.js +24 -24
  12. package/docs/.vitepress/config.ts +84 -69
  13. package/docs/.vitepress/referenceNavigation.ts +37 -37
  14. package/docs/.vitepress/theme/base-styles.css +100 -91
  15. package/docs/.vitepress/theme/env.d.ts +5 -5
  16. package/docs/.vitepress/theme/index.ts +39 -39
  17. package/docs/docs/index.md +142 -141
  18. package/docs/docs/public/playground/KeyframeKit/dist/KeyframeKit.d.ts +138 -138
  19. package/docs/docs/public/playground/KeyframeKit/dist/KeyframeKit.js +293 -293
  20. package/docs/docs/reference/_media/LICENSE +21 -21
  21. package/docs/docs/reference/classes/KeyframeEffectParameters.md +95 -95
  22. package/docs/docs/reference/classes/ParsedKeyframes.md +49 -49
  23. package/docs/docs/reference/index.md +20 -20
  24. package/docs/docs/reference/interfaces/KeyframesFactory.md +151 -151
  25. package/docs/docs/reference/navigation.json +63 -63
  26. package/docs/docs/reference/type-aliases/KeyframeArgument.md +9 -9
  27. package/docs/docs/reference/type-aliases/KeyframesFactorySource.md +9 -9
  28. package/docs/docs/reference/type-aliases/ParsedKeyframesRules.md +15 -15
  29. package/docs/docs/reference/variables/default.md +7 -7
  30. package/docs/package.json +25 -25
  31. package/docs/typedoc/plugin-param-names.js +51 -51
  32. package/docs/typedoc.json +62 -62
  33. package/package.json +37 -37
  34. package/src/KeyframeKit.ts +508 -508
  35. package/tsconfig.json +47 -47
  36. package/vercel.json +12 -12
@@ -1,141 +1,142 @@
1
- ---
2
- # https://vitepress.dev/reference/default-theme-home-page
3
- layout: home
4
-
5
- hero:
6
- name: KeyframeKit
7
- tagline: Intuitive, powerful and performant tools for working with CSS animations in JavaScript.
8
- actions:
9
- - theme: brand
10
- text: Get Started
11
- link: /#installation
12
- - theme: alt
13
- text: Reference
14
- link: /reference
15
- ---
16
-
17
- <Playground/>
18
-
19
- ## About
20
-
21
- While working with the [Web Animations API][1], I was surprised there wasn't an easy way to import animation keyframes directly from your CSS. You had to re-define them in JS, using a completely different format. So I wrote a typed, spec-compliant library to convert from one to the other, letting you play your CSS-defined animations right in JS. Along the way, I also added some other useful utilities for working with the API.
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.][2]
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 here.][3]
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://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API/Using_the_Web_Animations_API
141
- [3]: https://github.com/WICG/construct-stylesheets/issues/119#issuecomment-588352418
1
+ ---
2
+ # https://vitepress.dev/reference/default-theme-home-page
3
+ layout: home
4
+
5
+ hero:
6
+ name: KeyframeKit
7
+ tagline: Intuitive, powerful and lightweight tools for working with CSS animations in JavaScript.
8
+ actions:
9
+ - theme: brand
10
+ text: Get Started
11
+ link: /#installation
12
+ - theme: alt
13
+ text: Reference
14
+ link: /reference
15
+ ---
16
+
17
+ <Playground/>
18
+
19
+ ## About
20
+
21
+ While working with the [Web Animations API][1], I was surprised there wasn't an easy way to import animation keyframes directly from your CSS. You had to re-define them in JS, using a completely different format. So I wrote a typed, spec-compliant library to convert from one to the other, letting you play your CSS-defined animations right in JS. Along the way, I also added some other useful utilities for working with the API. [Read more.][2]
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
@@ -1,139 +1,139 @@
1
- export type KeyframesFactorySource = StyleSheetList | CSSStyleSheet;
2
- declare class KeyframesFactory {
3
- #private;
4
- readonly Error: {
5
- readonly KeyframesRuleNameTypeError: {
6
- new (message?: string): {
7
- message: string;
8
- name: string;
9
- stack?: string;
10
- cause?: unknown;
11
- };
12
- new (message?: string, options?: ErrorOptions): {
13
- message: string;
14
- name: string;
15
- stack?: string;
16
- cause?: unknown;
17
- };
18
- new (message?: string): {
19
- message: string;
20
- name: string;
21
- stack?: string;
22
- cause?: unknown;
23
- };
24
- new (message?: string, options?: ErrorOptions): {
25
- message: string;
26
- name: string;
27
- stack?: string;
28
- cause?: unknown;
29
- };
30
- isError(error: unknown): error is Error;
31
- };
32
- readonly SourceTypeError: {
33
- new (message?: string): {
34
- message: string;
35
- name: string;
36
- stack?: string;
37
- cause?: unknown;
38
- };
39
- new (message?: string, options?: ErrorOptions): {
40
- message: string;
41
- name: string;
42
- stack?: string;
43
- cause?: unknown;
44
- };
45
- new (message?: string): {
46
- message: string;
47
- name: string;
48
- stack?: string;
49
- cause?: unknown;
50
- };
51
- new (message?: string, options?: ErrorOptions): {
52
- message: string;
53
- name: string;
54
- stack?: string;
55
- cause?: unknown;
56
- };
57
- isError(error: unknown): error is Error;
58
- };
59
- readonly StyleSheetImportError: {
60
- new (message?: string): {
61
- message: string;
62
- name: string;
63
- stack?: string;
64
- cause?: unknown;
65
- };
66
- new (message?: string, options?: ErrorOptions): {
67
- message: string;
68
- name: string;
69
- stack?: string;
70
- cause?: unknown;
71
- };
72
- isError(error: unknown): error is Error;
73
- };
74
- };
75
- getDocumentStyleSheetsOnLoad({ document }?: {
76
- document?: Document;
77
- }): Promise<StyleSheetList>;
78
- /** @remarks
79
- * Note: `@import` rules won't be resolved in imported stylesheets.
80
- * See https://github.com/WICG/construct-stylesheets/issues/119#issuecomment-588352418. */
81
- importStyleSheet(url: string): Promise<CSSStyleSheet>;
82
- /** @param obj.of The name of the `@keyframes` rule to get keyframes from. */
83
- getStyleSheetKeyframes({ of: ruleName, in: source }: {
84
- of: string;
85
- in: KeyframesFactorySource;
86
- }): ParsedKeyframes | undefined;
87
- getAllStyleSheetKeyframesRules({ in: source }: {
88
- in: KeyframesFactorySource;
89
- }): ParsedKeyframesRules;
90
- parseKeyframesRule({ rule: keyframes }: {
91
- rule: CSSKeyframesRule;
92
- }): ParsedKeyframes;
93
- }
94
- declare const _default: KeyframesFactory;
95
- export default _default;
96
- export type { KeyframesFactory };
97
- /** https://drafts.csswg.org/web-animations-1/#processing-a-keyframes-argument */
98
- export type KeyframeArgument = Keyframe[] | PropertyIndexedKeyframes;
99
- /** https://drafts.csswg.org/web-animations-1/#the-keyframeeffect-interface */
100
- export declare class KeyframeEffectParameters {
101
- #private;
102
- keyframes: KeyframeArgument;
103
- options: KeyframeEffectOptions;
104
- /**
105
- * @param obj.keyframes [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API/Keyframe_Formats)
106
- * @param obj.options [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/KeyframeEffect#options)
107
- */
108
- constructor({ keyframes, options }: {
109
- keyframes: KeyframeArgument;
110
- options?: number | KeyframeEffectOptions;
111
- });
112
- /**
113
- * @param obj.target An element to attach the animation to.
114
- * @param obj.options Additional keyframe effect options. Can override existing keys.
115
- * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/KeyframeEffect#options)
116
- *
117
- * @see Specifications:
118
- * - https://drafts.csswg.org/web-animations-1/#the-keyframeeffect-interface
119
- * - https://drafts.csswg.org/web-animations-1/#the-animation-interface
120
- */
121
- toAnimation({ target, options: additionalOptions, timeline }: {
122
- target: Element | null;
123
- options?: number | KeyframeEffectOptions;
124
- timeline?: AnimationTimeline;
125
- }): Animation;
126
- }
127
- export declare class ParsedKeyframes {
128
- keyframes: Keyframe[];
129
- constructor(keyframes: Keyframe[]);
130
- /**
131
- * @param options
132
- * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/KeyframeEffect#options)
133
- */
134
- toKeyframeEffect(options: number | KeyframeEffectOptions | null): KeyframeEffectParameters;
135
- }
136
- export type ParsedKeyframesRules = {
137
- [ruleName: string]: ParsedKeyframes;
138
- };
1
+ export type KeyframesFactorySource = StyleSheetList | CSSStyleSheet;
2
+ declare class KeyframesFactory {
3
+ #private;
4
+ readonly Error: {
5
+ readonly KeyframesRuleNameTypeError: {
6
+ new (message?: string): {
7
+ message: string;
8
+ name: string;
9
+ stack?: string;
10
+ cause?: unknown;
11
+ };
12
+ new (message?: string, options?: ErrorOptions): {
13
+ message: string;
14
+ name: string;
15
+ stack?: string;
16
+ cause?: unknown;
17
+ };
18
+ new (message?: string): {
19
+ message: string;
20
+ name: string;
21
+ stack?: string;
22
+ cause?: unknown;
23
+ };
24
+ new (message?: string, options?: ErrorOptions): {
25
+ message: string;
26
+ name: string;
27
+ stack?: string;
28
+ cause?: unknown;
29
+ };
30
+ isError(error: unknown): error is Error;
31
+ };
32
+ readonly SourceTypeError: {
33
+ new (message?: string): {
34
+ message: string;
35
+ name: string;
36
+ stack?: string;
37
+ cause?: unknown;
38
+ };
39
+ new (message?: string, options?: ErrorOptions): {
40
+ message: string;
41
+ name: string;
42
+ stack?: string;
43
+ cause?: unknown;
44
+ };
45
+ new (message?: string): {
46
+ message: string;
47
+ name: string;
48
+ stack?: string;
49
+ cause?: unknown;
50
+ };
51
+ new (message?: string, options?: ErrorOptions): {
52
+ message: string;
53
+ name: string;
54
+ stack?: string;
55
+ cause?: unknown;
56
+ };
57
+ isError(error: unknown): error is Error;
58
+ };
59
+ readonly StyleSheetImportError: {
60
+ new (message?: string): {
61
+ message: string;
62
+ name: string;
63
+ stack?: string;
64
+ cause?: unknown;
65
+ };
66
+ new (message?: string, options?: ErrorOptions): {
67
+ message: string;
68
+ name: string;
69
+ stack?: string;
70
+ cause?: unknown;
71
+ };
72
+ isError(error: unknown): error is Error;
73
+ };
74
+ };
75
+ getDocumentStyleSheetsOnLoad({ document }?: {
76
+ document?: Document;
77
+ }): Promise<StyleSheetList>;
78
+ /** @remarks
79
+ * Note: `@import` rules won't be resolved in imported stylesheets.
80
+ * See https://github.com/WICG/construct-stylesheets/issues/119#issuecomment-588352418. */
81
+ importStyleSheet(url: string): Promise<CSSStyleSheet>;
82
+ /** @param obj.of The name of the `@keyframes` rule to get keyframes from. */
83
+ getStyleSheetKeyframes({ of: ruleName, in: source }: {
84
+ of: string;
85
+ in: KeyframesFactorySource;
86
+ }): ParsedKeyframes | undefined;
87
+ getAllStyleSheetKeyframesRules({ in: source }: {
88
+ in: KeyframesFactorySource;
89
+ }): ParsedKeyframesRules;
90
+ parseKeyframesRule({ rule: keyframes }: {
91
+ rule: CSSKeyframesRule;
92
+ }): ParsedKeyframes;
93
+ }
94
+ declare const _default: KeyframesFactory;
95
+ export default _default;
96
+ export type { KeyframesFactory };
97
+ /** https://drafts.csswg.org/web-animations-1/#processing-a-keyframes-argument */
98
+ export type KeyframeArgument = Keyframe[] | PropertyIndexedKeyframes;
99
+ /** https://drafts.csswg.org/web-animations-1/#the-keyframeeffect-interface */
100
+ export declare class KeyframeEffectParameters {
101
+ #private;
102
+ keyframes: KeyframeArgument;
103
+ options: KeyframeEffectOptions;
104
+ /**
105
+ * @param obj.keyframes [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API/Keyframe_Formats)
106
+ * @param obj.options [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/KeyframeEffect#options)
107
+ */
108
+ constructor({ keyframes, options }: {
109
+ keyframes: KeyframeArgument;
110
+ options?: number | KeyframeEffectOptions;
111
+ });
112
+ /**
113
+ * @param obj.target An element to attach the animation to.
114
+ * @param obj.options Additional keyframe effect options. Can override existing keys.
115
+ * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/KeyframeEffect#options)
116
+ *
117
+ * @see Specifications:
118
+ * - https://drafts.csswg.org/web-animations-1/#the-keyframeeffect-interface
119
+ * - https://drafts.csswg.org/web-animations-1/#the-animation-interface
120
+ */
121
+ toAnimation({ target, options: additionalOptions, timeline }: {
122
+ target: Element | null;
123
+ options?: number | KeyframeEffectOptions;
124
+ timeline?: AnimationTimeline;
125
+ }): Animation;
126
+ }
127
+ export declare class ParsedKeyframes {
128
+ keyframes: Keyframe[];
129
+ constructor(keyframes: Keyframe[]);
130
+ /**
131
+ * @param options
132
+ * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/KeyframeEffect#options)
133
+ */
134
+ toKeyframeEffect(options: number | KeyframeEffectOptions | null): KeyframeEffectParameters;
135
+ }
136
+ export type ParsedKeyframesRules = {
137
+ [ruleName: string]: ParsedKeyframes;
138
+ };
139
139
  //# sourceMappingURL=KeyframeKit.d.ts.map