@weser/keyframes 0.0.8 → 0.0.10
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/dist/createKeyframe.d.ts +4 -4
- package/dist/createKeyframe.js +5 -19
- package/dist/createKeyframes.d.ts +5 -0
- package/dist/createKeyframes.js +14 -0
- package/dist/createStyleNode.d.ts +9 -0
- package/dist/createStyleNode.js +9 -0
- package/dist/getAnimationName.d.ts +2 -0
- package/dist/getAnimationName.js +4 -0
- package/dist/getValueFromCache.d.ts +2 -0
- package/dist/getValueFromCache.js +10 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.js +1 -0
- package/package.json +2 -2
package/dist/createKeyframe.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export default function createKeyframe(style: T_Keyframe, nonce?: string): [string,
|
|
1
|
+
import createStyleNode from './createStyleNode.js';
|
|
2
|
+
import { T_Keyframe } from './types.js';
|
|
3
|
+
type Node = ReturnType<typeof createStyleNode>;
|
|
4
|
+
export default function createKeyframe(style: T_Keyframe, nonce?: string): [string, Node];
|
|
5
5
|
export {};
|
package/dist/createKeyframe.js
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
const cache = new Map();
|
|
1
|
+
import getValueFromCache from './getValueFromCache.js';
|
|
2
|
+
import createStyleNode from './createStyleNode.js';
|
|
3
|
+
import getAnimationName from './getAnimationName.js';
|
|
5
4
|
export default function createKeyframe(style, nonce) {
|
|
6
|
-
const animationName =
|
|
5
|
+
const animationName = getAnimationName(style);
|
|
7
6
|
const css = getValueFromCache(animationName, style);
|
|
8
|
-
const node =
|
|
9
|
-
dangerouslySetInnerHTML: { __html: css },
|
|
10
|
-
precedence: 'low',
|
|
11
|
-
href: animationName,
|
|
12
|
-
nonce,
|
|
13
|
-
});
|
|
7
|
+
const node = createStyleNode(animationName, css, nonce);
|
|
14
8
|
return [animationName, node];
|
|
15
9
|
}
|
|
16
|
-
function getValueFromCache(animationName, style) {
|
|
17
|
-
if (!cache.has(animationName)) {
|
|
18
|
-
const keyframe = Object.entries(style).reduce((keyframe, [key, declaration = {}]) => keyframe + key + '{' + cssifyObject(declaration) + '}', '');
|
|
19
|
-
const css = `@keyframes ${animationName}{${keyframe}}`;
|
|
20
|
-
cache.set(animationName, css);
|
|
21
|
-
}
|
|
22
|
-
return cache.get(animationName);
|
|
23
|
-
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import createStyleNode from './createStyleNode.js';
|
|
2
|
+
import { T_Keyframe } from './types.js';
|
|
3
|
+
type Node = ReturnType<typeof createStyleNode>;
|
|
4
|
+
export default function createKeyframes<T extends string>(keyframes: Record<T, T_Keyframe>, nonce?: string): [Record<T, string>, Node];
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import getValueFromCache from './getValueFromCache.js';
|
|
2
|
+
import createStyleNode from './createStyleNode.js';
|
|
3
|
+
import getAnimationName from './getAnimationName.js';
|
|
4
|
+
export default function createKeyframes(keyframes, nonce) {
|
|
5
|
+
const animationNameMap = {};
|
|
6
|
+
let css = '';
|
|
7
|
+
for (const key in keyframes) {
|
|
8
|
+
const animationName = getAnimationName(keyframes[key]);
|
|
9
|
+
css += getValueFromCache(animationName, keyframes[key]);
|
|
10
|
+
animationNameMap[key] = animationName;
|
|
11
|
+
}
|
|
12
|
+
const node = createStyleNode(Object.keys(keyframes).join('-'), css, nonce);
|
|
13
|
+
return [animationNameMap, node];
|
|
14
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export default function createStyleNode(animationName: string, css: string, nonce?: string): import("react").DetailedReactHTMLElement<{
|
|
3
|
+
dangerouslySetInnerHTML: {
|
|
4
|
+
__html: string;
|
|
5
|
+
};
|
|
6
|
+
precedence: string;
|
|
7
|
+
href: string;
|
|
8
|
+
nonce: string | undefined;
|
|
9
|
+
}, HTMLElement>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { cssifyObject } from 'css-in-js-utils';
|
|
2
|
+
const cache = new Map();
|
|
3
|
+
export default function getValueFromCache(animationName, style) {
|
|
4
|
+
if (!cache.has(animationName)) {
|
|
5
|
+
const keyframe = Object.entries(style).reduce((keyframe, [key, declaration = {}]) => keyframe + key + '{' + cssifyObject(declaration) + '}', '');
|
|
6
|
+
const css = `@keyframes ${animationName}{${keyframe}}`;
|
|
7
|
+
cache.set(animationName, css);
|
|
8
|
+
}
|
|
9
|
+
return cache.get(animationName);
|
|
10
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weser/keyframes",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "Tiny helpers for CSS keyframes in React",
|
|
5
5
|
"author": "Robin Weser <robin@weser.io>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"rimraf": "^3.0.2",
|
|
54
54
|
"typescript": "^5.4.5"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "6dd1ad00ab8dacea2878edc99085324ea5d03588"
|
|
57
57
|
}
|