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,294 +1,294 @@
1
- //
2
- // KeyframeKit
3
- // Ben Hatsor
4
- //
5
- // See README.md for usage.
6
- //
7
- const CHARS = {
8
- PERCENT_SIGN: '%',
9
- HYPHEN_MINUS: '-',
10
- DOUBLE_HYPHEN_MINUS: '--',
11
- WEBKIT_PREFIX: '-webkit-'
12
- };
13
- class KeyframesFactory {
14
- Error = {
15
- KeyframesRuleNameTypeError: class KeyframesRuleNameTypeError extends TypeError {
16
- message = `Keyframes rule name must be a string.`;
17
- },
18
- SourceTypeError: class SourceTypeError extends TypeError {
19
- message = `Source must be either a Document, a ShadowRoot or a CSSStyleSheet instance.`;
20
- },
21
- StyleSheetImportError: class StyleSheetImportError extends Error {
22
- message = `The stylesheet could not be imported.`;
23
- }
24
- };
25
- async getDocumentStyleSheetsOnLoad({ document = window.document } = {}) {
26
- await waitForDocumentLoad({
27
- document: document
28
- });
29
- return document.styleSheets;
30
- }
31
- /** @remarks
32
- * Note: `@import` rules won't be resolved in imported stylesheets.
33
- * See https://github.com/WICG/construct-stylesheets/issues/119#issuecomment-588352418. */
34
- async importStyleSheet(url) {
35
- const resp = await fetch(url);
36
- if (!resp.ok) {
37
- throw new this.Error.StyleSheetImportError();
38
- }
39
- const respText = await resp.text();
40
- // remove file name from URL to get base URL
41
- const baseURL = url.split('/').slice(0, -1).join('/');
42
- const styleSheet = new CSSStyleSheet({
43
- baseURL: baseURL
44
- });
45
- await styleSheet.replace(respText);
46
- return styleSheet;
47
- }
48
- /** @param obj.of The name of the `@keyframes` rule to get keyframes from. */
49
- getStyleSheetKeyframes({ of: ruleName, in: source }) {
50
- if (typeof ruleName !== 'string') {
51
- throw new this.Error.KeyframesRuleNameTypeError();
52
- }
53
- if (source instanceof StyleSheetList) {
54
- return this.#getStyleSheetKeyframesInStyleSheetList({
55
- of: ruleName,
56
- styleSheetList: source
57
- });
58
- }
59
- else if (source instanceof CSSStyleSheet) {
60
- return this.#getStyleSheetKeyframesInStyleSheet({
61
- of: ruleName,
62
- styleSheet: source
63
- });
64
- }
65
- else {
66
- throw new this.Error.SourceTypeError();
67
- }
68
- }
69
- #getStyleSheetKeyframesInStyleSheetList({ of: ruleName, styleSheetList }) {
70
- for (const styleSheet of styleSheetList) {
71
- const keyframesRule = this.#getStyleSheetKeyframesInStyleSheet({
72
- of: ruleName,
73
- styleSheet: styleSheet
74
- });
75
- if (keyframesRule !== undefined) {
76
- return keyframesRule;
77
- }
78
- }
79
- }
80
- #getStyleSheetKeyframesInStyleSheet({ of: ruleName, styleSheet }) {
81
- for (const rule of styleSheet.cssRules) {
82
- if (!(rule instanceof CSSKeyframesRule)) {
83
- continue;
84
- }
85
- if (rule.name === ruleName) {
86
- const keyframes = this.parseKeyframesRule({
87
- rule: rule
88
- });
89
- return keyframes;
90
- }
91
- }
92
- }
93
- getAllStyleSheetKeyframesRules({ in: source }) {
94
- if (source instanceof StyleSheetList) {
95
- return this.#getAllStyleSheetKeyframesRulesInStyleSheetList({
96
- styleSheetList: source
97
- });
98
- }
99
- else if (source instanceof CSSStyleSheet) {
100
- return this.#getAllStyleSheetKeyframesRulesInStyleSheet({
101
- styleSheet: source
102
- });
103
- }
104
- else {
105
- throw new this.Error.SourceTypeError();
106
- }
107
- }
108
- #getAllStyleSheetKeyframesRulesInStyleSheetList({ styleSheetList }) {
109
- let keyframesRules = {};
110
- for (const styleSheet of styleSheetList) {
111
- const styleSheetKeyframesRules = this.#getAllStyleSheetKeyframesRulesInStyleSheet({
112
- styleSheet: styleSheet
113
- });
114
- keyframesRules = {
115
- ...keyframesRules,
116
- ...styleSheetKeyframesRules
117
- };
118
- }
119
- return keyframesRules;
120
- }
121
- #getAllStyleSheetKeyframesRulesInStyleSheet({ styleSheet }) {
122
- let keyframesRules = {};
123
- for (const rule of styleSheet.cssRules) {
124
- if (!(rule instanceof CSSKeyframesRule)) {
125
- continue;
126
- }
127
- const keyframes = this.parseKeyframesRule({
128
- rule: rule
129
- });
130
- keyframesRules[rule.name] = keyframes;
131
- }
132
- return keyframesRules;
133
- }
134
- parseKeyframesRule({ rule: keyframes }) {
135
- let parsedKeyframes = [];
136
- for (const keyframe of keyframes) {
137
- // remove trailing '%'
138
- /// https://drafts.csswg.org/css-animations/#dom-csskeyframerule-keytext
139
- const percentString = removeSuffix({
140
- of: keyframe.keyText,
141
- suffix: CHARS.PERCENT_SIGN
142
- });
143
- const percent = Number(percentString);
144
- const offset = percent / 100;
145
- let parsedProperties = {};
146
- for (const propertyName of keyframe.style) {
147
- /// https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleDeclaration/getPropertyValue
148
- const propertyValue = keyframe.style.getPropertyValue(propertyName);
149
- /// https://drafts.csswg.org/web-animations-1/#ref-for-animation-property-name-to-idl-attribute-name%E2%91%A0
150
- const attributeName = this.#animationPropertyNameToIDLAttributeName(propertyName);
151
- parsedProperties[attributeName] = propertyValue;
152
- }
153
- const parsedKeyframe = {
154
- ...parsedProperties,
155
- offset: offset
156
- };
157
- parsedKeyframes.push(parsedKeyframe);
158
- }
159
- const parsedKeyframesInstance = new ParsedKeyframes(parsedKeyframes);
160
- return parsedKeyframesInstance;
161
- }
162
- /** https://drafts.csswg.org/web-animations-1/#animation-property-name-to-idl-attribute-name */
163
- #animationPropertyNameToIDLAttributeName(property) {
164
- if (this.#isCustomPropertyName(property))
165
- return property;
166
- if (property === 'float')
167
- return 'cssFloat';
168
- if (property === 'offset')
169
- return 'cssOffset';
170
- // https://drafts.csswg.org/cssom/#ref-for-supported-css-property%E2%91%A2
171
- const lowercaseFirst = this.#isWebkitCasedAttribute(property);
172
- return this.#cssPropertyToIDLAttribute(property, lowercaseFirst);
173
- }
174
- /** https://drafts.csswg.org/cssom/#css-property-to-idl-attribute */
175
- #cssPropertyToIDLAttribute(property, lowercaseFirst = false) {
176
- let output = '';
177
- let uppercaseNext = false;
178
- if (lowercaseFirst) {
179
- property = property.slice(1);
180
- }
181
- for (const c of property) {
182
- if (c === CHARS.HYPHEN_MINUS) {
183
- uppercaseNext = true;
184
- }
185
- else if (uppercaseNext) {
186
- uppercaseNext = false;
187
- output += c.toUpperCase();
188
- }
189
- else {
190
- output += c;
191
- }
192
- }
193
- return output;
194
- }
195
- /** https://drafts.csswg.org/css-variables-2/#typedef-custom-property-name */
196
- #isCustomPropertyName(property) {
197
- return property.startsWith(CHARS.DOUBLE_HYPHEN_MINUS) &&
198
- property !== CHARS.DOUBLE_HYPHEN_MINUS;
199
- }
200
- /** https://drafts.csswg.org/cssom/#ref-for-supported-css-property%E2%91%A2 */
201
- #isWebkitCasedAttribute(property) {
202
- return property.startsWith(CHARS.WEBKIT_PREFIX);
203
- }
204
- }
205
- export default new KeyframesFactory();
206
- /** https://drafts.csswg.org/web-animations-1/#the-keyframeeffect-interface */
207
- export class KeyframeEffectParameters {
208
- keyframes;
209
- options;
210
- /**
211
- * @param obj.keyframes [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API/Keyframe_Formats)
212
- * @param obj.options [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/KeyframeEffect#options)
213
- */
214
- constructor({ keyframes, options = {} }) {
215
- this.keyframes = keyframes;
216
- this.options = this.#parseOptionsArg(options);
217
- }
218
- /**
219
- * @param obj.target An element to attach the animation to.
220
- * @param obj.options Additional keyframe effect options. Can override existing keys.
221
- * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/KeyframeEffect#options)
222
- *
223
- * @see Specifications:
224
- * - https://drafts.csswg.org/web-animations-1/#the-keyframeeffect-interface
225
- * - https://drafts.csswg.org/web-animations-1/#the-animation-interface
226
- */
227
- toAnimation({ target, options: additionalOptions = {}, timeline = document.timeline }) {
228
- additionalOptions = this.#parseOptionsArg(additionalOptions);
229
- // override existing option keys with additional options
230
- const options = {
231
- ...this.options, ...additionalOptions
232
- };
233
- const keyframeEffect = new KeyframeEffect(target, this.keyframes, options);
234
- const animation = new Animation(keyframeEffect, timeline);
235
- return animation;
236
- }
237
- /** https://drafts.csswg.org/web-animations-1/#dom-keyframeeffect-keyframeeffect-target-keyframes-options-options
238
- https://drafts.csswg.org/web-animations-1/#dom-effecttiming-duration */
239
- #parseOptionsArg(options) {
240
- if (typeof options === 'number') {
241
- return { duration: options };
242
- }
243
- return options;
244
- }
245
- }
246
- export class ParsedKeyframes {
247
- keyframes;
248
- constructor(keyframes) {
249
- this.keyframes = keyframes;
250
- }
251
- /**
252
- * @param options
253
- * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/KeyframeEffect#options)
254
- */
255
- toKeyframeEffect(options) {
256
- let keyframeEffect;
257
- // convert (required) nullable to optional
258
- if (options !== null) {
259
- keyframeEffect = new KeyframeEffectParameters({
260
- keyframes: this.keyframes,
261
- options: options
262
- });
263
- }
264
- else {
265
- keyframeEffect = new KeyframeEffectParameters({
266
- keyframes: this.keyframes
267
- });
268
- }
269
- return keyframeEffect;
270
- }
271
- }
272
- // MARK: - Util
273
- function removeSuffix({ of: string, suffix }) {
274
- return string.slice(0, -suffix.length);
275
- }
276
- async function waitForDocumentLoad({ document }) {
277
- if (document.readyState === 'complete') {
278
- return;
279
- }
280
- const { promise, resolve } = Promise.withResolvers();
281
- function onReadyStateChange() {
282
- if (document.readyState === 'complete') {
283
- resolve(null);
284
- }
285
- }
286
- const listener = [
287
- 'readystatechange',
288
- onReadyStateChange
289
- ];
290
- document.addEventListener(...listener);
291
- await promise;
292
- document.removeEventListener(...listener);
293
- }
1
+ //
2
+ // KeyframeKit
3
+ // Ben Hatsor
4
+ //
5
+ // See README.md for usage.
6
+ //
7
+ const CHARS = {
8
+ PERCENT_SIGN: '%',
9
+ HYPHEN_MINUS: '-',
10
+ DOUBLE_HYPHEN_MINUS: '--',
11
+ WEBKIT_PREFIX: '-webkit-'
12
+ };
13
+ class KeyframesFactory {
14
+ Error = {
15
+ KeyframesRuleNameTypeError: class KeyframesRuleNameTypeError extends TypeError {
16
+ message = `Keyframes rule name must be a string.`;
17
+ },
18
+ SourceTypeError: class SourceTypeError extends TypeError {
19
+ message = `Source must be either a Document, a ShadowRoot or a CSSStyleSheet instance.`;
20
+ },
21
+ StyleSheetImportError: class StyleSheetImportError extends Error {
22
+ message = `The stylesheet could not be imported.`;
23
+ }
24
+ };
25
+ async getDocumentStyleSheetsOnLoad({ document = window.document } = {}) {
26
+ await waitForDocumentLoad({
27
+ document: document
28
+ });
29
+ return document.styleSheets;
30
+ }
31
+ /** @remarks
32
+ * Note: `@import` rules won't be resolved in imported stylesheets.
33
+ * See https://github.com/WICG/construct-stylesheets/issues/119#issuecomment-588352418. */
34
+ async importStyleSheet(url) {
35
+ const resp = await fetch(url);
36
+ if (!resp.ok) {
37
+ throw new this.Error.StyleSheetImportError();
38
+ }
39
+ const respText = await resp.text();
40
+ // remove file name from URL to get base URL
41
+ const baseURL = url.split('/').slice(0, -1).join('/');
42
+ const styleSheet = new CSSStyleSheet({
43
+ baseURL: baseURL
44
+ });
45
+ await styleSheet.replace(respText);
46
+ return styleSheet;
47
+ }
48
+ /** @param obj.of The name of the `@keyframes` rule to get keyframes from. */
49
+ getStyleSheetKeyframes({ of: ruleName, in: source }) {
50
+ if (typeof ruleName !== 'string') {
51
+ throw new this.Error.KeyframesRuleNameTypeError();
52
+ }
53
+ if (source instanceof StyleSheetList) {
54
+ return this.#getStyleSheetKeyframesInStyleSheetList({
55
+ of: ruleName,
56
+ styleSheetList: source
57
+ });
58
+ }
59
+ else if (source instanceof CSSStyleSheet) {
60
+ return this.#getStyleSheetKeyframesInStyleSheet({
61
+ of: ruleName,
62
+ styleSheet: source
63
+ });
64
+ }
65
+ else {
66
+ throw new this.Error.SourceTypeError();
67
+ }
68
+ }
69
+ #getStyleSheetKeyframesInStyleSheetList({ of: ruleName, styleSheetList }) {
70
+ for (const styleSheet of styleSheetList) {
71
+ const keyframesRule = this.#getStyleSheetKeyframesInStyleSheet({
72
+ of: ruleName,
73
+ styleSheet: styleSheet
74
+ });
75
+ if (keyframesRule !== undefined) {
76
+ return keyframesRule;
77
+ }
78
+ }
79
+ }
80
+ #getStyleSheetKeyframesInStyleSheet({ of: ruleName, styleSheet }) {
81
+ for (const rule of styleSheet.cssRules) {
82
+ if (!(rule instanceof CSSKeyframesRule)) {
83
+ continue;
84
+ }
85
+ if (rule.name === ruleName) {
86
+ const keyframes = this.parseKeyframesRule({
87
+ rule: rule
88
+ });
89
+ return keyframes;
90
+ }
91
+ }
92
+ }
93
+ getAllStyleSheetKeyframesRules({ in: source }) {
94
+ if (source instanceof StyleSheetList) {
95
+ return this.#getAllStyleSheetKeyframesRulesInStyleSheetList({
96
+ styleSheetList: source
97
+ });
98
+ }
99
+ else if (source instanceof CSSStyleSheet) {
100
+ return this.#getAllStyleSheetKeyframesRulesInStyleSheet({
101
+ styleSheet: source
102
+ });
103
+ }
104
+ else {
105
+ throw new this.Error.SourceTypeError();
106
+ }
107
+ }
108
+ #getAllStyleSheetKeyframesRulesInStyleSheetList({ styleSheetList }) {
109
+ let keyframesRules = {};
110
+ for (const styleSheet of styleSheetList) {
111
+ const styleSheetKeyframesRules = this.#getAllStyleSheetKeyframesRulesInStyleSheet({
112
+ styleSheet: styleSheet
113
+ });
114
+ keyframesRules = {
115
+ ...keyframesRules,
116
+ ...styleSheetKeyframesRules
117
+ };
118
+ }
119
+ return keyframesRules;
120
+ }
121
+ #getAllStyleSheetKeyframesRulesInStyleSheet({ styleSheet }) {
122
+ let keyframesRules = {};
123
+ for (const rule of styleSheet.cssRules) {
124
+ if (!(rule instanceof CSSKeyframesRule)) {
125
+ continue;
126
+ }
127
+ const keyframes = this.parseKeyframesRule({
128
+ rule: rule
129
+ });
130
+ keyframesRules[rule.name] = keyframes;
131
+ }
132
+ return keyframesRules;
133
+ }
134
+ parseKeyframesRule({ rule: keyframes }) {
135
+ let parsedKeyframes = [];
136
+ for (const keyframe of keyframes) {
137
+ // remove trailing '%'
138
+ /// https://drafts.csswg.org/css-animations/#dom-csskeyframerule-keytext
139
+ const percentString = removeSuffix({
140
+ of: keyframe.keyText,
141
+ suffix: CHARS.PERCENT_SIGN
142
+ });
143
+ const percent = Number(percentString);
144
+ const offset = percent / 100;
145
+ let parsedProperties = {};
146
+ for (const propertyName of keyframe.style) {
147
+ /// https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleDeclaration/getPropertyValue
148
+ const propertyValue = keyframe.style.getPropertyValue(propertyName);
149
+ /// https://drafts.csswg.org/web-animations-1/#ref-for-animation-property-name-to-idl-attribute-name%E2%91%A0
150
+ const attributeName = this.#animationPropertyNameToIDLAttributeName(propertyName);
151
+ parsedProperties[attributeName] = propertyValue;
152
+ }
153
+ const parsedKeyframe = {
154
+ ...parsedProperties,
155
+ offset: offset
156
+ };
157
+ parsedKeyframes.push(parsedKeyframe);
158
+ }
159
+ const parsedKeyframesInstance = new ParsedKeyframes(parsedKeyframes);
160
+ return parsedKeyframesInstance;
161
+ }
162
+ /** https://drafts.csswg.org/web-animations-1/#animation-property-name-to-idl-attribute-name */
163
+ #animationPropertyNameToIDLAttributeName(property) {
164
+ if (this.#isCustomPropertyName(property))
165
+ return property;
166
+ if (property === 'float')
167
+ return 'cssFloat';
168
+ if (property === 'offset')
169
+ return 'cssOffset';
170
+ // https://drafts.csswg.org/cssom/#ref-for-supported-css-property%E2%91%A2
171
+ const lowercaseFirst = this.#isWebkitCasedAttribute(property);
172
+ return this.#cssPropertyToIDLAttribute(property, lowercaseFirst);
173
+ }
174
+ /** https://drafts.csswg.org/cssom/#css-property-to-idl-attribute */
175
+ #cssPropertyToIDLAttribute(property, lowercaseFirst = false) {
176
+ let output = '';
177
+ let uppercaseNext = false;
178
+ if (lowercaseFirst) {
179
+ property = property.slice(1);
180
+ }
181
+ for (const c of property) {
182
+ if (c === CHARS.HYPHEN_MINUS) {
183
+ uppercaseNext = true;
184
+ }
185
+ else if (uppercaseNext) {
186
+ uppercaseNext = false;
187
+ output += c.toUpperCase();
188
+ }
189
+ else {
190
+ output += c;
191
+ }
192
+ }
193
+ return output;
194
+ }
195
+ /** https://drafts.csswg.org/css-variables-2/#typedef-custom-property-name */
196
+ #isCustomPropertyName(property) {
197
+ return property.startsWith(CHARS.DOUBLE_HYPHEN_MINUS) &&
198
+ property !== CHARS.DOUBLE_HYPHEN_MINUS;
199
+ }
200
+ /** https://drafts.csswg.org/cssom/#ref-for-supported-css-property%E2%91%A2 */
201
+ #isWebkitCasedAttribute(property) {
202
+ return property.startsWith(CHARS.WEBKIT_PREFIX);
203
+ }
204
+ }
205
+ export default new KeyframesFactory();
206
+ /** https://drafts.csswg.org/web-animations-1/#the-keyframeeffect-interface */
207
+ export class KeyframeEffectParameters {
208
+ keyframes;
209
+ options;
210
+ /**
211
+ * @param obj.keyframes [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API/Keyframe_Formats)
212
+ * @param obj.options [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/KeyframeEffect#options)
213
+ */
214
+ constructor({ keyframes, options = {} }) {
215
+ this.keyframes = keyframes;
216
+ this.options = this.#parseOptionsArg(options);
217
+ }
218
+ /**
219
+ * @param obj.target An element to attach the animation to.
220
+ * @param obj.options Additional keyframe effect options. Can override existing keys.
221
+ * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/KeyframeEffect#options)
222
+ *
223
+ * @see Specifications:
224
+ * - https://drafts.csswg.org/web-animations-1/#the-keyframeeffect-interface
225
+ * - https://drafts.csswg.org/web-animations-1/#the-animation-interface
226
+ */
227
+ toAnimation({ target, options: additionalOptions = {}, timeline = document.timeline }) {
228
+ additionalOptions = this.#parseOptionsArg(additionalOptions);
229
+ // override existing option keys with additional options
230
+ const options = {
231
+ ...this.options, ...additionalOptions
232
+ };
233
+ const keyframeEffect = new KeyframeEffect(target, this.keyframes, options);
234
+ const animation = new Animation(keyframeEffect, timeline);
235
+ return animation;
236
+ }
237
+ /** https://drafts.csswg.org/web-animations-1/#dom-keyframeeffect-keyframeeffect-target-keyframes-options-options
238
+ https://drafts.csswg.org/web-animations-1/#dom-effecttiming-duration */
239
+ #parseOptionsArg(options) {
240
+ if (typeof options === 'number') {
241
+ return { duration: options };
242
+ }
243
+ return options;
244
+ }
245
+ }
246
+ export class ParsedKeyframes {
247
+ keyframes;
248
+ constructor(keyframes) {
249
+ this.keyframes = keyframes;
250
+ }
251
+ /**
252
+ * @param options
253
+ * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/KeyframeEffect#options)
254
+ */
255
+ toKeyframeEffect(options) {
256
+ let keyframeEffect;
257
+ // convert (required) nullable to optional
258
+ if (options !== null) {
259
+ keyframeEffect = new KeyframeEffectParameters({
260
+ keyframes: this.keyframes,
261
+ options: options
262
+ });
263
+ }
264
+ else {
265
+ keyframeEffect = new KeyframeEffectParameters({
266
+ keyframes: this.keyframes
267
+ });
268
+ }
269
+ return keyframeEffect;
270
+ }
271
+ }
272
+ // MARK: - Util
273
+ function removeSuffix({ of: string, suffix }) {
274
+ return string.slice(0, -suffix.length);
275
+ }
276
+ async function waitForDocumentLoad({ document }) {
277
+ if (document.readyState === 'complete') {
278
+ return;
279
+ }
280
+ const { promise, resolve } = Promise.withResolvers();
281
+ function onReadyStateChange() {
282
+ if (document.readyState === 'complete') {
283
+ resolve(null);
284
+ }
285
+ }
286
+ const listener = [
287
+ 'readystatechange',
288
+ onReadyStateChange
289
+ ];
290
+ document.addEventListener(...listener);
291
+ await promise;
292
+ document.removeEventListener(...listener);
293
+ }
294
294
  //# sourceMappingURL=KeyframeKit.js.map
@@ -1,21 +1,21 @@
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.
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.