keyframekit 1.1.3 → 1.1.5
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 +7 -4
- package/dist/KeyframeKit.d.ts +41 -8
- package/dist/KeyframeKit.d.ts.map +1 -1
- package/dist/KeyframeKit.js +38 -5
- package/dist/KeyframeKit.js.map +1 -1
- package/docs/.vitepress/components/Playground/Playground.vue +3 -1
- package/docs/.vitepress/config.ts +5 -2
- package/docs/.vitepress/theme/base-styles.css +4 -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/docs/docs/public/playground/KeyframeKit/dist/KeyframeKit.d.ts +41 -8
- package/docs/docs/public/playground/KeyframeKit/dist/KeyframeKit.d.ts.map +1 -1
- package/docs/docs/public/playground/KeyframeKit/dist/KeyframeKit.js +38 -5
- package/docs/docs/public/playground/KeyframeKit/dist/KeyframeKit.js.map +1 -1
- package/docs/docs/reference/classes/KeyframeEffectParameters.md +5 -3
- package/docs/docs/reference/index.md +1 -1
- package/docs/docs/reference/interfaces/KeyframesFactory.md +33 -4
- package/docs/docs/reference/navigation.json +4 -4
- package/docs/docs/reference/type-aliases/CSSStyleSheetSource.md +7 -0
- package/docs/package.json +3 -6
- package/docs/typedoc/plugin-markdown-fix.js +43 -0
- package/docs/typedoc/plugin-param-names.js +10 -45
- package/docs/{typedoc.json → typedoc.config.js} +25 -10
- package/package.json +1 -1
- package/src/KeyframeKit.ts +42 -10
- package/vercel.json +1 -0
- package/docs/docs/reference/_media/LICENSE +0 -21
- package/docs/docs/reference/type-aliases/KeyframesFactorySource.md +0 -9
package/src/KeyframeKit.ts
CHANGED
|
@@ -14,23 +14,32 @@ const CHARS = {
|
|
|
14
14
|
} as const;
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
export type
|
|
17
|
+
export type CSSStyleSheetSource = CSSStyleSheet | StyleSheetList;
|
|
18
18
|
|
|
19
19
|
class KeyframesFactory {
|
|
20
20
|
|
|
21
21
|
readonly Error = {
|
|
22
|
+
/** Keyframes rule name must be a string. */
|
|
22
23
|
KeyframesRuleNameTypeError: class KeyframesRuleNameTypeError extends TypeError {
|
|
23
24
|
message = `Keyframes rule name must be a string.`;
|
|
24
25
|
},
|
|
26
|
+
/** Source must be either a `CSSStyleSheet` or a `StyleSheetList`. */
|
|
25
27
|
SourceTypeError: class SourceTypeError extends TypeError {
|
|
26
|
-
message = `Source must be either a
|
|
28
|
+
message = `Source must be either a CSSStyleSheet or a StyleSheetList.`;
|
|
27
29
|
},
|
|
30
|
+
/** The stylesheet could not be imported. */
|
|
28
31
|
StyleSheetImportError: class StyleSheetImportError extends Error {
|
|
29
32
|
message = `The stylesheet could not be imported.`;
|
|
30
33
|
}
|
|
31
34
|
} as const;
|
|
32
35
|
|
|
33
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Gets a document's stylesheets when it loads,
|
|
39
|
+
* or immediately returns them if it's already loaded.
|
|
40
|
+
* @param obj
|
|
41
|
+
* @param obj.document The document to get stylesheets from.
|
|
42
|
+
*/
|
|
34
43
|
async getDocumentStyleSheetsOnLoad({ document = window.document }: {
|
|
35
44
|
document?: Document
|
|
36
45
|
} = {}) {
|
|
@@ -44,9 +53,13 @@ class KeyframesFactory {
|
|
|
44
53
|
}
|
|
45
54
|
|
|
46
55
|
|
|
47
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* Imports a stylesheet from a URL.
|
|
58
|
+
* @param url The URL of the stylesheet to import.
|
|
59
|
+
* @remarks
|
|
48
60
|
* Note: `@import` rules won't be resolved in imported stylesheets.
|
|
49
|
-
* See https://github.com/WICG/construct-stylesheets/issues/119#issuecomment-588352418.
|
|
61
|
+
* See https://github.com/WICG/construct-stylesheets/issues/119#issuecomment-588352418.
|
|
62
|
+
*/
|
|
50
63
|
async importStyleSheet(url: string) {
|
|
51
64
|
|
|
52
65
|
const resp = await fetch(url);
|
|
@@ -71,10 +84,16 @@ class KeyframesFactory {
|
|
|
71
84
|
}
|
|
72
85
|
|
|
73
86
|
|
|
74
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* Gets a CSS keyframes rule from a stylesheet or stylesheet list,
|
|
89
|
+
* then converts it to Web Animations API keyframes.
|
|
90
|
+
* @param obj
|
|
91
|
+
* @param obj.of The name of the `@keyframes` rule to get keyframes from.
|
|
92
|
+
* @param obj.in The stylesheet or stylesheet list where the rule resides.
|
|
93
|
+
*/
|
|
75
94
|
getStyleSheetKeyframes({ of: ruleName, in: source }: {
|
|
76
95
|
of: string,
|
|
77
|
-
in:
|
|
96
|
+
in: CSSStyleSheetSource
|
|
78
97
|
}): ParsedKeyframes | undefined {
|
|
79
98
|
|
|
80
99
|
if (typeof ruleName !== 'string') {
|
|
@@ -149,8 +168,14 @@ class KeyframesFactory {
|
|
|
149
168
|
}
|
|
150
169
|
|
|
151
170
|
|
|
171
|
+
/**
|
|
172
|
+
* Gets all the CSS keyframes rules in a stylesheet or stylesheet list,
|
|
173
|
+
* then converts them to Web Animations API keyframes.
|
|
174
|
+
* @param obj
|
|
175
|
+
* @param obj.in The style sheet or style sheet list to get keyframes from.
|
|
176
|
+
*/
|
|
152
177
|
getAllStyleSheetKeyframesRules({ in: source }: {
|
|
153
|
-
in:
|
|
178
|
+
in: CSSStyleSheetSource
|
|
154
179
|
}): ParsedKeyframesRules {
|
|
155
180
|
|
|
156
181
|
if (source instanceof StyleSheetList) {
|
|
@@ -221,6 +246,11 @@ class KeyframesFactory {
|
|
|
221
246
|
}
|
|
222
247
|
|
|
223
248
|
|
|
249
|
+
/**
|
|
250
|
+
* Converts a CSS keyframes rule to Web Animations API keyframes.
|
|
251
|
+
* @param obj
|
|
252
|
+
* @param obj.rule The rule to convert.
|
|
253
|
+
*/
|
|
224
254
|
parseKeyframesRule({ rule: keyframes }: {
|
|
225
255
|
rule: CSSKeyframesRule
|
|
226
256
|
}): ParsedKeyframes {
|
|
@@ -355,6 +385,7 @@ export class KeyframeEffectParameters {
|
|
|
355
385
|
options: KeyframeEffectOptions;
|
|
356
386
|
|
|
357
387
|
/**
|
|
388
|
+
* @param obj
|
|
358
389
|
* @param obj.keyframes [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API/Keyframe_Formats)
|
|
359
390
|
* @param obj.options [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/KeyframeEffect#options)
|
|
360
391
|
*/
|
|
@@ -367,9 +398,11 @@ export class KeyframeEffectParameters {
|
|
|
367
398
|
}
|
|
368
399
|
|
|
369
400
|
/**
|
|
401
|
+
* @param obj
|
|
370
402
|
* @param obj.target An element to attach the animation to.
|
|
371
403
|
* @param obj.options Additional keyframe effect options. Can override existing keys.
|
|
372
|
-
*
|
|
404
|
+
* [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/KeyframeEffect#options)
|
|
405
|
+
* @param obj.timeline [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Animation/Animation#timeline)
|
|
373
406
|
*
|
|
374
407
|
* @see Specifications:
|
|
375
408
|
* - https://drafts.csswg.org/web-animations-1/#the-keyframeeffect-interface
|
|
@@ -378,7 +411,7 @@ export class KeyframeEffectParameters {
|
|
|
378
411
|
toAnimation({ target, options: additionalOptions = {}, timeline = document.timeline }: {
|
|
379
412
|
target: Element | null,
|
|
380
413
|
options?: number | KeyframeEffectOptions,
|
|
381
|
-
timeline?: AnimationTimeline
|
|
414
|
+
timeline?: AnimationTimeline | null
|
|
382
415
|
}): Animation {
|
|
383
416
|
|
|
384
417
|
additionalOptions = this.#parseOptionsArg(additionalOptions);
|
|
@@ -477,7 +510,6 @@ function removeSuffix({ of: string, suffix }: {
|
|
|
477
510
|
|
|
478
511
|
}
|
|
479
512
|
|
|
480
|
-
|
|
481
513
|
async function waitForDocumentLoad({ document }: {
|
|
482
514
|
document: Document
|
|
483
515
|
}) {
|
package/vercel.json
CHANGED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Ben Hatsor
|
|
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.
|